diff --git a/src/distroquery.c b/src/distroquery.c index 4622127..48dab01 100644 --- a/src/distroquery.c +++ b/src/distroquery.c @@ -74,35 +74,55 @@ 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; void printInputForm(char *data) { struct configTag *ct = firstconfigtag; + const char ajax_call[] = "ajax_getvalues(" +// "'repository='+getElementById('repository').value" + "'query='+getElementById('query').value+" + "'&search_devel='+getElementById('search_devel').checked+" + "'&search_milestone2='+getElementById('search_milestone2').checked+" + "'&search_milestone1='+getElementById('search_milestone1').checked" + ")"; + printf(""); - printf(""); - printf(" Repository: ", ajax_call); + printf("", ajax_call); +/* printf(" Repository: devel "); + printf("milestone2 "); + printf("milestone1 "); printf(""); + printf("
"); +/* ct = firstconfigtag; + while (ct) { + printf("
%s
",ct->tag, ct->tag, ct->tag); + ct = ct->next; + }*/ printf("]]>
"); } - void printQueryData(char* repository_tag, char* query) { - int i; + int i, numresults = 0; + char dbname[PATH_MAX]; + sqlite3_stmt *statement; + char sql[PATH_MAX]; + int j; - configtag = findRepositoryByTag(repository_tag); +/* configtag = findRepositoryByTag(repository_tag); if (!configtag) { fprintf(stderr, "Fatal error: configuration missing for given tag\n"); exit(1); } - char dbname[PATH_MAX]; - 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)) { @@ -110,26 +130,33 @@ void printQueryData(char* repository_tag, char* query) { configtag->repository[i]->db = NULL; fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname); } + }*/ + + printf("repository_dir); + if (sqlite3_open_v2(dbname, (sqlite3**)&query_repositories[i]->db, SQLITE_OPEN_READONLY, NULL)) { + if (query_repositories[i]->db) sqlite3_close(query_repositories[i]->db); + query_repositories[i]->db = NULL; + fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname); + } } - - sqlite3_stmt *statement; - char sql[PATH_MAX]; - int j; - - printf("arch[a]; a++) { - snprintf(sql, PATH_MAX, "SELECT * FROM packages_%s WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", configtag->arch[a], 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)) { + + int a; + for (i = 0; query_repositories[i] != NULL; i++) { + for (a = 0; a < ARCHS_MAX && query_repositories[i]->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
 " "
%s

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

" "
%s

", - configtag->arch[a], - configtag->repository[i]->tag, + query_repositories[i]->arch[a], + query_repositories[i]->tag, sqlite3_column_text(statement,1), sqlite3_column_text(statement,4), sqlite3_column_text(statement,5), @@ -142,11 +169,12 @@ void printQueryData(char* repository_tag, char* query) { } } - snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", query, query, query); +/* 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
 " "
%s

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

" @@ -164,18 +192,20 @@ void printQueryData(char* repository_tag, char* query) { } printf("\n"); } - - printf("]]>
"); - for (i = 0; i <= configtag->repository_level; i++) { - sqlite3_close((sqlite3*)configtag->repository[i]->db); - } - - +*/ + printf("

%d result(s) found.", numresults); + printf("]]>
"); + + for (i = 0; query_repositories[i] != NULL; i++) { + sqlite3_close((sqlite3*)query_repositories[i]->db); + query_repositories[i]->db = NULL; + } } - -void print_xml_reply(char *data) { +void parse_request_variables(char *data) { char *vartok, *valuetok; + struct configTag *ct = firstconfigtag; + int i; while (1) { vartok = (char *) strtok(data, "="); @@ -186,11 +216,25 @@ void print_xml_reply(char *data) { repository_tag = valuetok; } else if (strstr(vartok, "query")) { query = valuetok; + } else if (strstr(vartok, "search_milestone2")) { + search_milestone2 = (strstr(valuetok, "false") != valuetok); + } else if (strstr(vartok, "search_milestone1")) { + search_milestone1 = (strstr(valuetok, "false") != valuetok); + } else if (strstr(vartok, "search_devel")) { + search_devel = (strstr(valuetok, "false") != valuetok); } } - printQueryData(repository_tag, query); -} + ct = firstconfigtag; + i = 0; + while (ct) { + if ((strstr(ct->tag, "milestone1") == ct->tag) && search_milestone1) query_repositories[i++] = ct; + else if ((strstr(ct->tag, "milestone2") == ct->tag) && search_milestone2) query_repositories[i++] = ct; + else if ((strstr(ct->tag, "devel") == ct->tag) && search_devel) query_repositories[i++] = ct; + ct = ct->next; + } + query_repositories[i++] = NULL; +} int main(int argc, char *argv[]) @@ -209,7 +253,11 @@ main(int argc, char *argv[]) data = getenv("QUERY_STRING"); if (data && strlen(data)) { - print_xml_reply(data); + parse_request_variables(data); + } + + if (query && strlen(query)) { + printQueryData(repository_tag, query); printf("\n"); exit(0); }