Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/lml.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

extern clock_t lml_total_exec_duration; // For testing purpose

extern int lml_init(void);
extern void lml_cleanup(void);

extern int lml_render(const char *str_in, char *str_out, int buf_len, int width, int quote_mode);

#endif //_LML_H_
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bbsd_LDFLAGS=-export-dynamic
test_trie_dict_SOURCES = log.c test_trie_dict.c trie_dict.c
test_file_loader_SOURCES = file_loader.c log.c str_process.c test_file_loader.c
test_section_list_SOURCES = bbs.c common.c database.c log.c section_list.c test_section_list.c trie_dict.c user_list.c user_priv.c user_stat.c
test_lml_SOURCES = lml.c log.c str_process.c test_lml.c
test_lml_SOURCES = lml.c log.c str_process.c test_lml.c trie_dict.c
test_ssh_server_SOURCES = log.c test_ssh_server.c
test_article_favor_SOURCES = article_favor.c bbs.c common.c database.c log.c section_list.c test_article_favor.c trie_dict.c \
user_list.c user_priv.c user_stat.c
Expand Down
42 changes: 21 additions & 21 deletions src/article_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ inline static int article_cache_path(char *file_path, size_t buf_len, const char
{
if (file_path == NULL || cache_dir == NULL || p_article == NULL)
{
log_error("NULL pointer error\n");
log_error("NULL pointer error");
return -1;
}

Expand Down Expand Up @@ -76,19 +76,19 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons

if (cache_dir == NULL || p_article == NULL || content == NULL)
{
log_error("NULL pointer error\n");
log_error("NULL pointer error");
return -1;
}

if (content_f == NULL && (content_f = malloc(ARTICLE_CONTENT_MAX_LEN)) == NULL)
{
log_error("malloc(content_f) error: OOM\n");
log_error("malloc(content_f) error: OOM");
return -1;
}

if (article_cache_path(data_file, sizeof(data_file), cache_dir, p_article) < 0)
{
log_error("article_cache_path(dir=%s, cid=%d) error\n", cache_dir, p_article->cid);
log_error("article_cache_path(dir=%s, cid=%d) error", cache_dir, p_article->cid);
return -1;
}

Expand All @@ -103,7 +103,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons

if ((fd = open(data_file, O_WRONLY | O_CREAT | O_TRUNC, 0640)) == -1)
{
log_error("open(%s) error (%d)\n", data_file, errno);
log_error("open(%s) error (%d)", data_file, errno);
return -2;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons

if (body_len != (size_t)cache.line_offsets[cache.line_total])
{
log_debug("Body of article(aid=%d) is truncated from %ld to %ld, body_line=%ld, body_line_limit=%ld\n",
log_debug("Body of article(aid=%d) is truncated from %ld to %ld, body_line=%ld, body_line_limit=%ld",
p_article->aid, body_len, cache.line_offsets[cache.line_total],
body_line_cnt, MAX_SPLIT_FILE_LINES - header_line_cnt);
cache.data_len = header_len + (size_t)(cache.line_offsets[cache.line_total]);
Expand All @@ -161,7 +161,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons

if (footer_len != cache.line_offsets[cache.line_total + footer_line_cnt])
{
log_debug("Footer of article(aid=%d) is truncated from %ld to %ld, footer_line=%ld, footer_line_limit=%ld\n",
log_debug("Footer of article(aid=%d) is truncated from %ld to %ld, footer_line=%ld, footer_line_limit=%ld",
p_article->aid, footer_len, cache.line_offsets[cache.line_total + footer_line_cnt],
footer_line_cnt, MAX_SPLIT_FILE_LINES - cache.line_total);
footer_len = (size_t)(cache.line_offsets[cache.line_total + footer_line_cnt]);
Expand All @@ -178,32 +178,32 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons

if (write(fd, &cache, cache.mmap_len - cache.data_len) == -1)
{
log_error("write(%s, cache) error (%d)\n", data_file, errno);
log_error("write(%s, cache) error (%d)", data_file, errno);
close(fd);
return -3;
}
if (write(fd, header, header_len) == -1)
{
log_error("write(%s, header) error (%d)\n", data_file, errno);
log_error("write(%s, header) error (%d)", data_file, errno);
close(fd);
return -3;
}
if (write(fd, content_f, cache.data_len - header_len - footer_len) == -1)
{
log_error("write(%s, content) error (%d)\n", data_file, errno);
log_error("write(%s, content) error (%d)", data_file, errno);
close(fd);
return -3;
}
if (write(fd, footer, footer_len) == -1)
{
log_error("write(%s, footer) error (%d)\n", data_file, errno);
log_error("write(%s, footer) error (%d)", data_file, errno);
close(fd);
return -3;
}

if (close(fd) == -1)
{
log_error("close(%s) error (%d)\n", data_file, errno);
log_error("close(%s) error (%d)", data_file, errno);
return -2;
}

Expand All @@ -229,25 +229,25 @@ int article_cache_load(ARTICLE_CACHE *p_cache, const char *cache_dir, const ARTI

if (p_cache == NULL || cache_dir == NULL || p_article == NULL)
{
log_error("NULL pointer error\n");
log_error("NULL pointer error");
return -1;
}

if (article_cache_path(data_file, sizeof(data_file), cache_dir, p_article) < 0)
{
log_error("article_cache_path(dir=%s, cid=%d) error\n", cache_dir, p_article->cid);
log_error("article_cache_path(dir=%s, cid=%d) error", cache_dir, p_article->cid);
return -1;
}

if ((fd = open(data_file, O_RDONLY)) == -1)
{
log_error("open(%s) error (%d)\n", data_file, errno);
log_error("open(%s) error (%d)", data_file, errno);
return -2;
}

if (fstat(fd, &sb) < 0)
{
log_error("fstat(fd) error (%d)\n", errno);
log_error("fstat(fd) error (%d)", errno);
return -2;
}

Expand All @@ -256,19 +256,19 @@ int article_cache_load(ARTICLE_CACHE *p_cache, const char *cache_dir, const ARTI
p_mmap = mmap(NULL, mmap_len, PROT_READ, MAP_SHARED, fd, 0L);
if (p_mmap == MAP_FAILED)
{
log_error("mmap(%s) error (%d)\n", data_file, errno);
log_error("mmap(%s) error (%d)", data_file, errno);
return -2;
}

if (close(fd) == -1)
{
log_error("close(%s) error (%d)\n", data_file, errno);
log_error("close(%s) error (%d)", data_file, errno);
return -2;
}

if (((ARTICLE_CACHE *)p_mmap)->mmap_len != mmap_len)
{
log_error("Inconsistent mmap len of article (cid=%d), %ld != %ld\n", p_article->cid, p_cache->mmap_len, mmap_len);
log_error("Inconsistent mmap len of article (cid=%d), %ld != %ld", p_article->cid, p_cache->mmap_len, mmap_len);
return -3;
}

Expand All @@ -285,13 +285,13 @@ int article_cache_unload(ARTICLE_CACHE *p_cache)
{
if (p_cache == NULL || p_cache->p_mmap == NULL)
{
log_error("NULL pointer error\n");
log_error("NULL pointer error");
return -1;
}

if (munmap(p_cache->p_mmap, p_cache->mmap_len) < 0)
{
log_error("munmap() error (%d)\n", errno);
log_error("munmap() error (%d)", errno);
return -2;
}

Expand Down
22 changes: 11 additions & 11 deletions src/article_del.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)

if (p_section == NULL || p_article == NULL)
{
log_error("NULL pointer error\n");
log_error("NULL pointer error");
}

if (p_article->excerption) // Delete is not allowed
Expand Down Expand Up @@ -79,22 +79,22 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)
db = db_open();
if (db == NULL)
{
log_error("db_open() error: %s\n", mysql_error(db));
log_error("db_open() error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}

// Begin transaction
if (mysql_query(db, "SET autocommit=0") != 0)
{
log_error("SET autocommit=0 error: %s\n", mysql_error(db));
log_error("SET autocommit=0 error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}

if (mysql_query(db, "BEGIN") != 0)
{
log_error("Begin transaction error: %s\n", mysql_error(db));
log_error("Begin transaction error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
Expand All @@ -105,13 +105,13 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)

if (mysql_query(db, sql) != 0)
{
log_error("Query article status error: %s\n", mysql_error(db));
log_error("Query article status error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
if ((rs = mysql_use_result(db)) == NULL)
{
log_error("Get article status data failed\n");
log_error("Get article status data failed");
ret = -1;
goto cleanup;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)

if (mysql_query(db, sql) != 0)
{
log_error("Update article status error: %s\n", mysql_error(db));
log_error("Update article status error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
Expand All @@ -177,7 +177,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)

if (mysql_query(db, sql) != 0)
{
log_error("Update exp error: %s\n", mysql_error(db));
log_error("Update exp error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
Expand All @@ -192,7 +192,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)

if (mysql_query(db, sql) != 0)
{
log_error("Add log error: %s\n", mysql_error(db));
log_error("Add log error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
Expand All @@ -206,7 +206,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)

if (mysql_query(db, sql) != 0)
{
log_error("Update article error: %s\n", mysql_error(db));
log_error("Update article error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
Expand All @@ -215,7 +215,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article)
// Commit transaction
if (mysql_query(db, "COMMIT") != 0)
{
log_error("Commit transaction error: %s\n", mysql_error(db));
log_error("Commit transaction error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}
Expand Down
Loading