distroquery: base search on milestone2, milestone1 and devel groups of repositories

This commit is contained in:
Silvan Calarco 2013-10-07 18:14:53 +02:00
parent f50ba2ab52
commit f93e2c7c81

View File

@ -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("<queryform><![CDATA[");
printf("<input id=query onkeypress=if(checkEnter(event))ajax_getvalues('repository='+getElementById('repository').value+'&query='+getElementById('query').value);>");
printf("<button onclick=ajax_getvalues('repository='+getElementById('repository').value+'&query='+getElementById('query').value);>Cerca</button>");
printf("&nbsp;Repository: <select id=repository>");
printf("<input id=query onkeypress=if(checkEnter(event))%s>", ajax_call);
printf("<button onclick=%s>Cerca</button>", ajax_call);
/* printf("&nbsp;Repository: <select id=repository>");
while (ct) {
printf("<option>%s</option>",ct->tag);
ct = ct->next;
}
}*/
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("<br>");
/* ct = firstconfigtag;
while (ct) {
printf("<div width=150px style=\"display:inline\"><input name=\"%s\" type=checkbox value=\"%s\">%s</div>",ct->tag, ct->tag, ct->tag);
ct = ct->next;
}*/
printf("]]></queryform>");
}
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("<queryreply><![CDATA[");
for (i = 0; query_repositories[i] != NULL; i++) {
snprintf(dbname, PATH_MAX, "%sdistromatic.db", query_repositories[i]->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("<queryreply><![CDATA[");
int a;
for (a = 0; a < ARCHS_MAX && configtag->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("<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>",
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("<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>"
@ -164,18 +192,20 @@ void printQueryData(char* repository_tag, char* query) {
}
printf("\n");
}
printf("]]></queryreply>");
for (i = 0; i <= configtag->repository_level; i++) {
sqlite3_close((sqlite3*)configtag->repository[i]->db);
}
*/
printf("<hr><br>%d result(s) found.", numresults);
printf("]]></queryreply>");
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("</distroquery>\n");
exit(0);
}