From 8a46f4b2e4794df5c70712a98304dc067ebf1a75 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 12:48:45 +1000 Subject: [PATCH 01/10] Highly experimental file search and listing --- src/files.c | 579 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 403 insertions(+), 176 deletions(-) diff --git a/src/files.c b/src/files.c index 0ba1d98..1eb604c 100644 --- a/src/files.c +++ b/src/files.c @@ -27,6 +27,8 @@ extern time_t userlaston; extern struct user_record *gUser; struct file_entry { + int dir; + int sub; char *filename; char *description; int size; @@ -853,6 +855,403 @@ void download(struct user_record *user) { tagged_count = 0; } +void do_list_files(struct file_entry **files_e, int files_c) { + int file_size; + char file_unit; + int lines = 0; + int i; + int j; + int z; + int k; + int match; + char buffer[6]; + + s_printf("\r\n"); + + for (i=0;isize; + if (file_size > 1024 * 1024 * 1024) { + file_size = file_size / 1024 / 1024 / 1024; + file_unit = 'G'; + } else if (file_size > 1024 * 1024) { + file_size = file_size / 1024 / 1024; + file_unit = 'M'; + } else if (file_size > 1024) { + file_size = file_size / 1024; + file_unit = 'K'; + } else { + file_unit = 'b'; + } + if (files_e[i]->uploaddate > userlaston) { + s_printf(get_string(231), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); + } else { + s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); + } + lines+=3; + for (j=0;jdescription);j++) { + if (files_e[i]->description[j] == '\n') { + s_printf("\r\n"); + lines++; + if (lines >= 18) { + lines = 0; + while (1) { + s_printf(get_string(70)); + s_readstring(buffer, 5); + if (strlen(buffer) == 0) { + s_printf("\r\n"); + break; + } else if (tolower(buffer[0]) == 'q') { + for (z=0;zfilename); + free(files_e[z]->description); + free(files_e[z]); + } + free(files_e); + s_printf("\r\n"); + return; + } else { + z = atoi(buffer); + if (z >= 0 && z < files_c) { + if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { + match = 0; + for (k=0;kfilename) == 0) { + match = 1; + break; + } + } + if (match == 0) { + if (tagged_count == 0) { + tagged_files = (char **)malloc(sizeof(char *)); + } else { + tagged_files = (char **)realloc(tagged_files, sizeof(char *) * (tagged_count + 1)); + } + tagged_files[tagged_count] = strdup(files_e[z]->filename); + tagged_count++; + s_printf(get_string(71), basename(files_e[z]->filename)); + } else { + s_printf(get_string(72)); + } + } else { + s_printf(get_string(73)); + } + } + } + } + } + if (strlen(&(files_e[i]->description[j])) > 1) { + s_printf(get_string(74)); + } + } else { + s_putchar(files_e[i]->description[j]); + } + } + if (lines >= 18) { + lines = 0; + while (1) { + s_printf(get_string(70)); + s_readstring(buffer, 5); + if (strlen(buffer) == 0) { + s_printf("\r\n"); + break; + } else if (tolower(buffer[0]) == 'q') { + for (z=0;zfilename); + free(files_e[z]->description); + free(files_e[z]); + } + free(files_e); + s_printf("\r\n"); + return; + } else { + z = atoi(buffer); + if (z >= 0 && z < files_c) { + if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { + match = 0; + for (k=0;kfilename) == 0) { + match = 1; + break; + } + } + if (match == 0) { + if (tagged_count == 0) { + tagged_files = (char **)malloc(sizeof(char *)); + } else { + tagged_files = (char **)realloc(tagged_files, sizeof(char *) * (tagged_count + 1)); + } + tagged_files[tagged_count] = strdup(files_e[z]->filename); + tagged_count++; + s_printf(get_string(71), basename(files_e[z]->filename)); + } else { + s_printf(get_string(72)); + } + } else { + s_printf(get_string(73)); + } + } + } + } + } + } + while (1) { + s_printf(get_string(75)); + s_readstring(buffer, 5); + if (strlen(buffer) == 0) { + for (z=0;zfilename); + free(files_e[z]->description); + free(files_e[z]); + } + free(files_e); + s_printf("\r\n"); + return; + } else { + z = atoi(buffer); + if (z >= 0 && z < files_c) { + if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { + match = 0; + for (k=0;kfilename) == 0) { + match = 1; + break; + } + } + if (match == 0) { + if (tagged_count == 0) { + tagged_files = (char **)malloc(sizeof(char *)); + } else { + tagged_files = (char **)realloc(tagged_files, sizeof(char *) * (tagged_count + 1)); + } + tagged_files[tagged_count] = strdup(files_e[z]->filename); + tagged_count++; + s_printf(get_string(71), basename(files_e[z]->filename)); + } else { + s_printf(get_string(72)); + } + } else { + s_printf(get_string(73)); + } + } + } + } +} + +void file_search() { + char ch; + int all = 0; + int stype = 0; + char buffer[PATH_MAX]; + char sqlbuffer[1024]; + char **searchterms; + int searchterm_count = 0; + char *ptr; + int i; + int j; + int search_dir; + int search_sub; + sqlite3 *db; + sqlite3_stmt *res; + int rc; + int files_c; + struct file_entry **files_e; + + if (!sqlite3_compileoption_used("SQLITE_ENABLE_FTS3")) { + s_printf("\r\nSorry, search is unavailable. Please recompile sqlite3 with FTS3 support.\r\n"); + return; + } + + s_printf("\r\nSearch by (F)ilename, (D)escription or (B)oth: "); + ch = s_getc(); + + switch(tolower(ch)) { + case 'd': + stype = 1; + break; + case 'b': + stype = 2; + break; + } + + s_printf("\r\nSearch in (C)urrent area or (A)ll areas: "); + + ch = s_getc(); + if (tolower(ch) == 'a') { + all = 1; + } + + s_printf("\r\nKeywords: "); + + s_readstring(buffer, 128); + + if (strlen(buffer) == 0) { + s_printf("\r\nPlease enter at least one keyword.\r\n"); + return; + } + ptr = strtok(buffer, " "); + while (ptr != NULL) { + if (searchterm_count == 0) { + searchterms = (char **)malloc(sizeof(char *)); + } else { + searchterms = (char **)realloc(searchterms, sizeof(char *) * (searchterm_count + 1)); + } + + searchterms[searchterm_count] = strdup(ptr); + searchterm_count++; + ptr = strtok(NULL, " "); + } + if (stype == 0) { + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND filename MATCH(?"); + for (i=1; i < searchterm_count; i++) { + strncat(sqlbuffer, ",?", 1024); + } + strncat(sqlbuffer, ")", 1024); + } + if (stype == 1) { + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND description MATCH(?"); + for (i=1; i < searchterm_count; i++) { + strncat(sqlbuffer, ",?", 1024); + } + strncat(sqlbuffer, ")", 1024); + } + if (stype == 2) { + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename MATCH(?"); + for (i=1; i < searchterm_count; i++) { + strncat(sqlbuffer, ",?", 1024); + } + strncat(sqlbuffer, ") OR description MATCH(", 1024); + for (i=1; i < searchterm_count; i++) { + strncat(sqlbuffer, ",?", 1024); + } + strncat(sqlbuffer, "))", 1024); + } + + if (!all) { + files_c = 0; + snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->database); + + rc = sqlite3_open(buffer, &db); + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + + exit(1); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sqlbuffer, -1, &res, 0); + + if (rc != SQLITE_OK) { + sqlite3_finalize(res); + sqlite3_close(db); + for (i=0;ifilename = strdup((char *)sqlite3_column_text(res, 0)); + files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 1)); + files_e[files_c]->size = sqlite3_column_int(res, 2); + files_e[files_c]->dlcount = sqlite3_column_int(res, 3); + files_e[files_c]->uploaddate = sqlite3_column_int(res, 4); + files_e[files_c]->dir = gUser->cur_file_dir; + files_e[files_c]->sub = gUser->cur_file_sub; + files_c++; + } + sqlite3_finalize(res); + sqlite3_close(db); + + if (files_c != 0) { + do_list_files(files_e, files_c); + } + } else { + files_c = 0; + for (search_dir = 0; search_dir < conf.file_directory_count; search_dir++) { + if (conf.file_directories[search_dir]->sec_level < gUser->sec_level) { + continue; + } + for (search_sub = 0; search_sub < conf.file_directories[search_dir]->file_sub_count; search_sub++) { + if (conf.file_directories[search_dir]->file_subs[search_sub]->download_sec_level < gUser->sec_level) { + continue; + } + snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[search_dir]->file_subs[search_sub]->database); + + rc = sqlite3_open(buffer, &db); + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + exit(1); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sqlbuffer, -1, &res, 0); + + if (rc != SQLITE_OK) { + sqlite3_finalize(res); + sqlite3_close(db); + continue; + } + if (stype == 2) { + for (j=0;j<2;j++) { + for (i=0;ifilename = strdup((char *)sqlite3_column_text(res, 0)); + files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 1)); + files_e[files_c]->size = sqlite3_column_int(res, 2); + files_e[files_c]->dlcount = sqlite3_column_int(res, 3); + files_e[files_c]->uploaddate = sqlite3_column_int(res, 4); + files_e[files_c]->dir = gUser->cur_file_dir; + files_e[files_c]->sub = gUser->cur_file_sub; + files_c++; + } + sqlite3_finalize(res); + sqlite3_close(db); + } + } + + if (files_c != 0) { + do_list_files(files_e, files_c); + } + } + for (i=0;isize = sqlite3_column_int(res, 2); files_e[files_c]->dlcount = sqlite3_column_int(res, 3); files_e[files_c]->uploaddate = sqlite3_column_int(res, 4); + files_e[files_c]->dir = user->cur_file_dir; + files_e[files_c]->sub = user->cur_file_sub; files_c++; } sqlite3_finalize(res); @@ -934,174 +1327,8 @@ void list_files(struct user_record *user) { s_printf(get_string(68)); return; } - s_printf("\r\n"); - for (i=0;isize; - if (file_size > 1024 * 1024 * 1024) { - file_size = file_size / 1024 / 1024 / 1024; - file_unit = 'G'; - } else if (file_size > 1024 * 1024) { - file_size = file_size / 1024 / 1024; - file_unit = 'M'; - } else if (file_size > 1024) { - file_size = file_size / 1024; - file_unit = 'K'; - } else { - file_unit = 'b'; - } - if (files_e[i]->uploaddate > userlaston) { - s_printf(get_string(231), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); - } else { - s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); - } - lines+=3; - for (j=0;jdescription);j++) { - if (files_e[i]->description[j] == '\n') { - s_printf("\r\n"); - lines++; - if (lines >= 18) { - lines = 0; - while (1) { - s_printf(get_string(70)); - s_readstring(buffer, 5); - if (strlen(buffer) == 0) { - s_printf("\r\n"); - break; - } else if (tolower(buffer[0]) == 'q') { - for (z=0;zfilename); - free(files_e[z]->description); - free(files_e[z]); - } - free(files_e); - s_printf("\r\n"); - return; - } else { - z = atoi(buffer); - if (z >= 0 && z < files_c) { - if (conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->download_sec_level <= user->sec_level) { - match = 0; - for (k=0;kfilename) == 0) { - match = 1; - break; - } - } - if (match == 0) { - if (tagged_count == 0) { - tagged_files = (char **)malloc(sizeof(char *)); - } else { - tagged_files = (char **)realloc(tagged_files, sizeof(char *) * (tagged_count + 1)); - } - tagged_files[tagged_count] = strdup(files_e[z]->filename); - tagged_count++; - s_printf(get_string(71), basename(files_e[z]->filename)); - } else { - s_printf(get_string(72)); - } - } else { - s_printf(get_string(73)); - } - } - } - } - } - if (strlen(&(files_e[i]->description[j])) > 1) { - s_printf(get_string(74)); - } - } else { - s_putchar(files_e[i]->description[j]); - } - } - if (lines >= 18) { - lines = 0; - while (1) { - s_printf(get_string(70)); - s_readstring(buffer, 5); - if (strlen(buffer) == 0) { - s_printf("\r\n"); - break; - } else if (tolower(buffer[0]) == 'q') { - for (z=0;zfilename); - free(files_e[z]->description); - free(files_e[z]); - } - free(files_e); - s_printf("\r\n"); - return; - } else { - z = atoi(buffer); - if (z >= 0 && z < files_c) { - if (conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->download_sec_level <= user->sec_level) { - match = 0; - for (k=0;kfilename) == 0) { - match = 1; - break; - } - } - if (match == 0) { - if (tagged_count == 0) { - tagged_files = (char **)malloc(sizeof(char *)); - } else { - tagged_files = (char **)realloc(tagged_files, sizeof(char *) * (tagged_count + 1)); - } - tagged_files[tagged_count] = strdup(files_e[z]->filename); - tagged_count++; - s_printf(get_string(71), basename(files_e[z]->filename)); - } else { - s_printf(get_string(72)); - } - } else { - s_printf(get_string(73)); - } - } - } - } - } - } - while (1) { - s_printf(get_string(75)); - s_readstring(buffer, 5); - if (strlen(buffer) == 0) { - for (z=0;zfilename); - free(files_e[z]->description); - free(files_e[z]); - } - free(files_e); - s_printf("\r\n"); - return; - } else { - z = atoi(buffer); - if (z >= 0 && z < files_c) { - if (conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->download_sec_level <= user->sec_level) { - match = 0; - for (k=0;kfilename) == 0) { - match = 1; - break; - } - } - if (match == 0) { - if (tagged_count == 0) { - tagged_files = (char **)malloc(sizeof(char *)); - } else { - tagged_files = (char **)realloc(tagged_files, sizeof(char *) * (tagged_count + 1)); - } - tagged_files[tagged_count] = strdup(files_e[z]->filename); - tagged_count++; - s_printf(get_string(71), basename(files_e[z]->filename)); - } else { - s_printf(get_string(72)); - } - } else { - s_printf(get_string(73)); - } - } - } - } + + do_list_files(files_e, files_c); } void choose_subdir(struct user_record *user) { From 237d27fe7a5264aff17194b71dddedf90e61c3e3 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 12:54:20 +1000 Subject: [PATCH 02/10] Enable file search --- src/bbs.h | 1 + src/menus.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/bbs.h b/src/bbs.h index 8c45566..b539d82 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -315,6 +315,7 @@ extern void prev_file_dir(struct user_record *user); extern void next_file_sub(struct user_record *user); extern void prev_file_sub(struct user_record *user); extern void file_scan(); +extern void file_search(); extern void lua_push_cfunctions(lua_State *L); extern void do_lua_script(char *script); diff --git a/src/menus.c b/src/menus.c index 5f7af12..8c7e561 100644 --- a/src/menus.c +++ b/src/menus.c @@ -51,6 +51,7 @@ #define MENU_RESETALLPOINTERS 41 #define MENU_FILESCAN 42 #define MENU_FULLMAILSCAN 43 +#define MENU_FILESEARCH 44 extern struct bbs_config conf; extern struct user_record *gUser; @@ -203,6 +204,8 @@ int menu_system(char *menufile) { menu[menu_items-1]->command = MENU_FILESCAN; } else if (strncasecmp(&buffer[8], "FULLMAILSCAN", 12) == 0) { menu[menu_items-1]->command = MENU_FULLMAILSCAN; + } else if (strncasecmp(&buffer[8], "FILESEARCH", 10) == 0) { + menu[menu_items-1]->command = MENU_FILESEARCH; } } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { menu[menu_items-1]->seclevel = atoi(&buffer[9]); @@ -507,6 +510,9 @@ int menu_system(char *menufile) { case MENU_FULLMAILSCAN: full_mail_scan(gUser); break; + case MENU_FILESEARCH: + file_search(); + break; default: break; } From 6b4cf60c7b7e18d1935bd5e1429826dd6cf19d1f Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:01:10 +1000 Subject: [PATCH 03/10] Add diagnostics --- src/files.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/files.c b/src/files.c index 1eb604c..c165b7e 100644 --- a/src/files.c +++ b/src/files.c @@ -1141,6 +1141,7 @@ void file_search() { rc = sqlite3_prepare_v2(db, sqlbuffer, -1, &res, 0); if (rc != SQLITE_OK) { + s_printf("%s\n", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); for (i=0;i Date: Thu, 19 Oct 2017 13:03:52 +1000 Subject: [PATCH 04/10] change commas to OR --- src/files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/files.c b/src/files.c index c165b7e..2b38a60 100644 --- a/src/files.c +++ b/src/files.c @@ -1103,25 +1103,25 @@ void file_search() { if (stype == 0) { snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND filename MATCH(?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, ",?", 1024); + strncat(sqlbuffer, " OR ?", 1024); } strncat(sqlbuffer, ")", 1024); } if (stype == 1) { snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND description MATCH(?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, ",?", 1024); + strncat(sqlbuffer, " OR ?", 1024); } strncat(sqlbuffer, ")", 1024); } if (stype == 2) { snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename MATCH(?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, ",?", 1024); + strncat(sqlbuffer, " OR ?", 1024); } strncat(sqlbuffer, ") OR description MATCH(", 1024); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, ",?", 1024); + strncat(sqlbuffer, " OR ?", 1024); } strncat(sqlbuffer, "))", 1024); } From bbf067d53a4a8f37532db3ca0168f5afda951df7 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:10:42 +1000 Subject: [PATCH 05/10] More diagnostics --- src/files.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/files.c b/src/files.c index 2b38a60..afa7590 100644 --- a/src/files.c +++ b/src/files.c @@ -1162,6 +1162,8 @@ void file_search() { } } + s_printf("%s\n", sqlite3_errmsg(db)); + while (sqlite3_step(res) == SQLITE_ROW) { if (files_c == 0) { files_e = (struct file_entry **)malloc(sizeof(struct file_entry *)); From 0edc68105bc1f74ed3ad69b0cd8548afb0beae7b Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:13:52 +1000 Subject: [PATCH 06/10] MOre diagnostics --- src/files.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index afa7590..8b8a462 100644 --- a/src/files.c +++ b/src/files.c @@ -1162,7 +1162,7 @@ void file_search() { } } - s_printf("%s\n", sqlite3_errmsg(db)); + while (sqlite3_step(res) == SQLITE_ROW) { if (files_c == 0) { @@ -1180,6 +1180,9 @@ void file_search() { files_e[files_c]->sub = gUser->cur_file_sub; files_c++; } + + s_printf("%s\n", sqlite3_errmsg(db)); + sqlite3_finalize(res); sqlite3_close(db); From 7eb58c4dbd2f64baaa6ba58549ce39b4d8a4a922 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:24:21 +1000 Subject: [PATCH 07/10] Change to LIKE --- src/files.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/files.c b/src/files.c index 8b8a462..b094866 100644 --- a/src/files.c +++ b/src/files.c @@ -1096,34 +1096,35 @@ void file_search() { searchterms = (char **)realloc(searchterms, sizeof(char *) * (searchterm_count + 1)); } - searchterms[searchterm_count] = strdup(ptr); + searchterms[searchterm_count] = malloc(strlen(ptr) + 3); + sprintf(searchterms[searchterm_count], "%%%s%%", ptr); searchterm_count++; ptr = strtok(NULL, " "); } if (stype == 0) { - snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND filename MATCH(?"); + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, " OR ?", 1024); + strncat(sqlbuffer, " OR filename LIKE ?", 1024); } strncat(sqlbuffer, ")", 1024); } if (stype == 1) { - snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND description MATCH(?"); + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND description (filename LIKE ?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, " OR ?", 1024); + strncat(sqlbuffer, " OR filename LIKE ?", 1024); } strncat(sqlbuffer, ")", 1024); } if (stype == 2) { - snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename MATCH(?"); + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND (filename LIKE ?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, " OR ?", 1024); + strncat(sqlbuffer, " OR filename LIKE ?", 1024); } - strncat(sqlbuffer, ") OR description MATCH(", 1024); + strncat(sqlbuffer, " OR description LIKE ?", 1024); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, " OR ?", 1024); + strncat(sqlbuffer, " OR description LIKE ?", 1024); } - strncat(sqlbuffer, "))", 1024); + strncat(sqlbuffer, ")", 1024); } if (!all) { @@ -1181,8 +1182,6 @@ void file_search() { files_c++; } - s_printf("%s\n", sqlite3_errmsg(db)); - sqlite3_finalize(res); sqlite3_close(db); From 7743d6551399fed3035d859d7a7eca519b93c58d Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:27:33 +1000 Subject: [PATCH 08/10] Fix seclevel checking --- src/files.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/files.c b/src/files.c index b094866..42a327f 100644 --- a/src/files.c +++ b/src/files.c @@ -1142,7 +1142,6 @@ void file_search() { rc = sqlite3_prepare_v2(db, sqlbuffer, -1, &res, 0); if (rc != SQLITE_OK) { - s_printf("%s\n", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); for (i=0;isec_level < gUser->sec_level) { + if (conf.file_directories[search_dir]->sec_level > gUser->sec_level) { continue; } for (search_sub = 0; search_sub < conf.file_directories[search_dir]->file_sub_count; search_sub++) { - if (conf.file_directories[search_dir]->file_subs[search_sub]->download_sec_level < gUser->sec_level) { + if (conf.file_directories[search_dir]->file_subs[search_sub]->download_sec_level > gUser->sec_level) { continue; } snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[search_dir]->file_subs[search_sub]->database); From b24034fc528fa70caea4db17c063c8f222ec9f38 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:34:16 +1000 Subject: [PATCH 09/10] fix a typo --- src/files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/files.c b/src/files.c index 42a327f..15968fb 100644 --- a/src/files.c +++ b/src/files.c @@ -1109,9 +1109,9 @@ void file_search() { strncat(sqlbuffer, ")", 1024); } if (stype == 1) { - snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND description (filename LIKE ?"); + snprintf(sqlbuffer, 1024, "select filename, description, size, dlcount, uploaddate from files where approved=1 AND (description LIKE ?"); for (i=1; i < searchterm_count; i++) { - strncat(sqlbuffer, " OR filename LIKE ?", 1024); + strncat(sqlbuffer, " OR description LIKE ?", 1024); } strncat(sqlbuffer, ")", 1024); } From cf4e5826bfa4ea0717f7b2ddae218b861dae181e Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 19 Oct 2017 13:40:42 +1000 Subject: [PATCH 10/10] Finish work on file search --- magicka.strings | 4 ++++ src/files.c | 13 ++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/magicka.strings b/magicka.strings index d063443..2ce054c 100644 --- a/magicka.strings +++ b/magicka.strings @@ -234,3 +234,7 @@ File exists!\r\n \r\n\e[1;37mOrder by (\e[1;32mF\e[1;37m)ilename, (\e[1;32mU\e[1;37m)pload Date, (\e[1;32mP\e[1;37m)opularity : \e[0m \e[24;1H\e[1;32mUp / Down\e[1;37m to Scroll, \e[1;32mLeft / Right \e[1;37mChange Message, \e[1;32mR \e[1;37mReply, \e[1;32mJ \e[1;37mNext Area, \e[1;32mQ \e[1;37mQuit\e[K\e[0m \e[0;36mB. \e[1;37mBluewave Packet Style (\e[1;33m%s\e[1;37m)\r\n +\r\n\e[1;37mSearch by (\e[1;32mF\e[1;37m)ilename, (\e[1;32mD\e[1;37m)escription or (\e[1;32mB\e[1;37m)oth:\e[0m +\r\n\e[1;37mSearch in (\e[1;32C\e[1;37m)urrent area or (\e[1;32A\e[1;37m)ll areas:\e[0m +\r\n\e[1;31mPlease enter at least one keyword.\e[0m\r\n +\r\n\e[1;37mKeywords:\e[0m diff --git a/src/files.c b/src/files.c index 15968fb..f8bde6d 100644 --- a/src/files.c +++ b/src/files.c @@ -1056,12 +1056,7 @@ void file_search() { int files_c; struct file_entry **files_e; - if (!sqlite3_compileoption_used("SQLITE_ENABLE_FTS3")) { - s_printf("\r\nSorry, search is unavailable. Please recompile sqlite3 with FTS3 support.\r\n"); - return; - } - - s_printf("\r\nSearch by (F)ilename, (D)escription or (B)oth: "); + s_printf(get_string(236)); ch = s_getc(); switch(tolower(ch)) { @@ -1073,19 +1068,19 @@ void file_search() { break; } - s_printf("\r\nSearch in (C)urrent area or (A)ll areas: "); + s_printf(get_string(237)); ch = s_getc(); if (tolower(ch) == 'a') { all = 1; } - s_printf("\r\nKeywords: "); + s_printf(get_string(239)); s_readstring(buffer, 128); if (strlen(buffer) == 0) { - s_printf("\r\nPlease enter at least one keyword.\r\n"); + s_printf(get_string(238)); return; } ptr = strtok(buffer, " ");