distroquery: support for selecting search archs / sources

This commit is contained in:
Silvan Calarco 2013-10-07 22:21:36 +02:00
parent 23622c1981
commit ce9c01a844

View File

@ -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("<queryform><![CDATA[");
@ -95,11 +101,15 @@ void printInputForm(char *data) {
while (ct) {
printf("<option>%s</option>",ct->tag);
ct = ct->next;
}*/
}
printf("</select>");*/
printf("<input type=checkbox id=\"search_devel\" checked=checked>devel&nbsp;");
printf("<input type=checkbox id=\"search_milestone2\" checked=checked>milestone2&nbsp;");
printf("<input type=checkbox id=\"search_milestone1\">milestone1&nbsp;");
printf("</select>");
printf("&nbsp;<input type=checkbox id=\"search_i586\" checked=checked>i586&nbsp;");
printf("<input type=checkbox id=\"search_x86_64\">x86_64&nbsp;");
printf("<input type=checkbox id=\"search_arm\">arm&nbsp;");
printf("<input type=checkbox id=\"search_sources\">sources&nbsp;");
printf("<br>");
/* 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("<queryreply><![CDATA[");
@ -143,15 +137,17 @@ void printQueryData(char* repository_tag, char* query) {
}
}
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("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div>&nbsp;"
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("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'> %s </div><br>"
"<b>%s</b> %s-%s<br>%s<br>Group: %s<br><br>"
"<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
@ -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("<hr><br><div style='display:inline;color:black;background-color:red'> Source </div>&nbsp;"
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("<hr><br><div style='display:inline;color:black;background-color:red'> Source </div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'> %s </div><br>"
"<b>%s</b> %s-%s<br>%s<br>Group: %s<br>License: %s</br>URL: %s<br><br>"
"<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
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("<hr><br>%d result(s) found.", numresults);
printf("]]></queryreply>");
@ -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);
}
}