From ce9c01a84418d7267963ce69976c7ae2b300f6da Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Mon, 7 Oct 2013 22:21:36 +0200 Subject: [PATCH] distroquery: support for selecting search archs / sources --- src/distroquery.c | 83 +++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/src/distroquery.c b/src/distroquery.c index 48dab01..544b56d 100644 --- a/src/distroquery.c +++ b/src/distroquery.c @@ -75,7 +75,9 @@ static struct configTag *firstconfigtag = NULL, *configtag = NULL; char *repository_tag = NULL; char *query; struct configTag *query_repositories[100]; + int search_milestone1 = 0, search_milestone2 = 1, search_devel = 1; +int search_arm = 0, search_x86_64 = 0, search_i586 = 1, search_sources = 0; void printInputForm(char *data) { struct configTag *ct = firstconfigtag; @@ -85,7 +87,11 @@ void printInputForm(char *data) { "'query='+getElementById('query').value+" "'&search_devel='+getElementById('search_devel').checked+" "'&search_milestone2='+getElementById('search_milestone2').checked+" - "'&search_milestone1='+getElementById('search_milestone1').checked" + "'&search_milestone1='+getElementById('search_milestone1').checked+" + "'&search_i586='+getElementById('search_i586').checked+" + "'&search_x86_64='+getElementById('search_x86_64').checked+" + "'&search_arm='+getElementById('search_arm').checked+" + "'&search_sources='+getElementById('search_sources').checked" ")"; printf("%s",ct->tag); ct = ct->next; - }*/ + } + printf("");*/ printf("devel "); printf("milestone2 "); printf("milestone1 "); - printf(""); + printf(" i586 "); + printf("x86_64 "); + printf("arm "); + printf("sources "); printf("
"); /* ct = firstconfigtag; while (ct) { @@ -111,26 +121,10 @@ void printInputForm(char *data) { void printQueryData(char* repository_tag, char* query) { - int i, numresults = 0; + int a, i, j, k, numresults = 0; char dbname[PATH_MAX]; sqlite3_stmt *statement; char sql[PATH_MAX]; - int j; - -/* configtag = findRepositoryByTag(repository_tag); - if (!configtag) { - fprintf(stderr, "Fatal error: configuration missing for given tag\n"); - exit(1); - } - - for (i = 0; i <= configtag->repository_level; i++) { - snprintf(dbname, PATH_MAX, "%sdistromatic.db", configtag->repository[i]->repository_dir); - if (sqlite3_open_v2(dbname, (sqlite3**)&configtag->repository[i]->db, SQLITE_OPEN_READONLY, NULL)) { - if (configtag->repository[i]->db) sqlite3_close(configtag->repository[i]->db); - configtag->repository[i]->db = NULL; - fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname); - } - }*/ printf("arch[a]; a++) { - snprintf(sql, PATH_MAX, "SELECT * FROM packages_%s WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", query_repositories[i]->arch[a], query, query, query); - if (query_repositories[i]->db && - (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { - while (sqlite3_step(statement) == SQLITE_ROW) { - numresults++; - printf("

%s
 " + if ((search_i586 && !strcmp(query_repositories[i]->arch[a],"i586")) || + (search_arm && !strcmp(query_repositories[i]->arch[a],"arm")) || + (search_x86_64 && !strcmp(query_repositories[i]->arch[a],"x86_64"))) { + snprintf(sql, PATH_MAX, "SELECT * FROM packages_%s WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", query_repositories[i]->arch[a], query, query, query); + if (query_repositories[i]->db && + (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { + while (sqlite3_step(statement) == SQLITE_ROW) { + numresults++; + printf("

%s
 " "
%s

" "%s %s-%s
%s
Group: %s

" "
%s

", @@ -163,23 +159,25 @@ void printQueryData(char* repository_tag, char* query) { sqlite3_column_text(statement,6), sqlite3_column_text(statement,7), sqlite3_column_text(statement,8)); + } } } printf("\n"); } } -/* snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", query, query, query); - for (i = 0; i <= configtag->repository_level; i++) { - if (configtag->repository[i]->db && - (sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { - while (sqlite3_step(statement) == SQLITE_ROW) { - numresults++; - printf("

Source
 " + if (search_sources) { + snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", query, query, query); + for (i = 0; query_repositories[i] != NULL; i++) { + if (query_repositories[i]->db && + (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { + while (sqlite3_step(statement) == SQLITE_ROW) { + numresults++; + printf("

Source
 " "
%s

" "%s %s-%s
%s
Group: %s
License: %s
URL: %s

" "
%s

", - configtag->repository[i]->tag, + query_repositories[i]->tag, sqlite3_column_text(statement,1), sqlite3_column_text(statement,4), sqlite3_column_text(statement,5), @@ -188,11 +186,12 @@ void printQueryData(char* repository_tag, char* query) { sqlite3_column_text(statement,11), sqlite3_column_text(statement,10), sqlite3_column_text(statement,9)); + } } + printf("\n"); } - printf("\n"); - } -*/ + } + printf("

%d result(s) found.", numresults); printf("]]>
"); @@ -222,6 +221,14 @@ void parse_request_variables(char *data) { search_milestone1 = (strstr(valuetok, "false") != valuetok); } else if (strstr(vartok, "search_devel")) { search_devel = (strstr(valuetok, "false") != valuetok); + } else if (strstr(vartok, "search_i586")) { + search_i586 = (strstr(valuetok, "false") != valuetok); + } else if (strstr(vartok, "search_x86_64")) { + search_x86_64 = (strstr(valuetok, "false") != valuetok); + } else if (strstr(vartok, "search_arm")) { + search_arm = (strstr(valuetok, "false") != valuetok); + } else if (strstr(vartok, "search_sources")) { + search_sources = (strstr(valuetok, "false") != valuetok); } }