distroquery: base search on milestone2, milestone1 and devel groups of repositories
This commit is contained in:
parent
f50ba2ab52
commit
f93e2c7c81
@ -74,35 +74,55 @@
|
|||||||
static struct configTag *firstconfigtag = NULL, *configtag = NULL;
|
static struct configTag *firstconfigtag = NULL, *configtag = NULL;
|
||||||
char *repository_tag = NULL;
|
char *repository_tag = NULL;
|
||||||
char *query;
|
char *query;
|
||||||
|
struct configTag *query_repositories[100];
|
||||||
|
int search_milestone1 = 0, search_milestone2 = 1, search_devel = 1;
|
||||||
|
|
||||||
void printInputForm(char *data) {
|
void printInputForm(char *data) {
|
||||||
struct configTag *ct = firstconfigtag;
|
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("<queryform><![CDATA[");
|
||||||
printf("<input id=query onkeypress=if(checkEnter(event))ajax_getvalues('repository='+getElementById('repository').value+'&query='+getElementById('query').value);>");
|
printf("<input id=query onkeypress=if(checkEnter(event))%s>", ajax_call);
|
||||||
printf("<button onclick=ajax_getvalues('repository='+getElementById('repository').value+'&query='+getElementById('query').value);>Cerca</button>");
|
printf("<button onclick=%s>Cerca</button>", ajax_call);
|
||||||
printf(" Repository: <select id=repository>");
|
/* printf(" Repository: <select id=repository>");
|
||||||
while (ct) {
|
while (ct) {
|
||||||
printf("<option>%s</option>",ct->tag);
|
printf("<option>%s</option>",ct->tag);
|
||||||
ct = ct->next;
|
ct = ct->next;
|
||||||
}
|
}*/
|
||||||
|
printf("<input type=checkbox id=\"search_devel\" checked=checked>devel ");
|
||||||
|
printf("<input type=checkbox id=\"search_milestone2\" checked=checked>milestone2 ");
|
||||||
|
printf("<input type=checkbox id=\"search_milestone1\">milestone1 ");
|
||||||
printf("</select>");
|
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>");
|
printf("]]></queryform>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printQueryData(char* repository_tag, char* query) {
|
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) {
|
if (!configtag) {
|
||||||
fprintf(stderr, "Fatal error: configuration missing for given tag\n");
|
fprintf(stderr, "Fatal error: configuration missing for given tag\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char dbname[PATH_MAX];
|
|
||||||
|
|
||||||
for (i = 0; i <= configtag->repository_level; i++) {
|
for (i = 0; i <= configtag->repository_level; i++) {
|
||||||
snprintf(dbname, PATH_MAX, "%sdistromatic.db", configtag->repository[i]->repository_dir);
|
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 (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;
|
configtag->repository[i]->db = NULL;
|
||||||
fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname);
|
fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
sqlite3_stmt *statement;
|
|
||||||
char sql[PATH_MAX];
|
|
||||||
int j;
|
|
||||||
|
|
||||||
printf("<queryreply><![CDATA[");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int a;
|
int a;
|
||||||
for (a = 0; a < ARCHS_MAX && configtag->arch[a]; a++) {
|
for (i = 0; query_repositories[i] != NULL; i++) {
|
||||||
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 (a = 0; a < ARCHS_MAX && query_repositories[i]->arch[a]; a++) {
|
||||||
for (i = 0; i <= configtag->repository_level; i++) {
|
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 (configtag->repository[i]->db &&
|
if (query_repositories[i]->db &&
|
||||||
(sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
(sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
|
numresults++;
|
||||||
printf("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div> "
|
printf("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div> "
|
||||||
"<div style='display:inline;color:black;background-color:yellow'> %s </div><br>"
|
"<div style='display:inline;color:black;background-color:yellow'> %s </div><br>"
|
||||||
"<b>%s</b> %s-%s<br>%s<br>Group: %s<br><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>",
|
"<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
|
||||||
configtag->arch[a],
|
query_repositories[i]->arch[a],
|
||||||
configtag->repository[i]->tag,
|
query_repositories[i]->tag,
|
||||||
sqlite3_column_text(statement,1),
|
sqlite3_column_text(statement,1),
|
||||||
sqlite3_column_text(statement,4),
|
sqlite3_column_text(statement,4),
|
||||||
sqlite3_column_text(statement,5),
|
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++) {
|
for (i = 0; i <= configtag->repository_level; i++) {
|
||||||
if (configtag->repository[i]->db &&
|
if (configtag->repository[i]->db &&
|
||||||
(sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
(sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
|
numresults++;
|
||||||
printf("<hr><br><div style='display:inline;color:black;background-color:red'> Source </div> "
|
printf("<hr><br><div style='display:inline;color:black;background-color:red'> Source </div> "
|
||||||
"<div style='display:inline;color:black;background-color:yellow'> %s </div><br>"
|
"<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>"
|
"<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("\n");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
printf("<hr><br>%d result(s) found.", numresults);
|
||||||
printf("]]></queryreply>");
|
printf("]]></queryreply>");
|
||||||
for (i = 0; i <= configtag->repository_level; i++) {
|
|
||||||
sqlite3_close((sqlite3*)configtag->repository[i]->db);
|
for (i = 0; query_repositories[i] != NULL; i++) {
|
||||||
|
sqlite3_close((sqlite3*)query_repositories[i]->db);
|
||||||
|
query_repositories[i]->db = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_request_variables(char *data) {
|
||||||
void print_xml_reply(char *data) {
|
|
||||||
char *vartok, *valuetok;
|
char *vartok, *valuetok;
|
||||||
|
struct configTag *ct = firstconfigtag;
|
||||||
|
int i;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
vartok = (char *) strtok(data, "=");
|
vartok = (char *) strtok(data, "=");
|
||||||
@ -186,11 +216,25 @@ void print_xml_reply(char *data) {
|
|||||||
repository_tag = valuetok;
|
repository_tag = valuetok;
|
||||||
} else if (strstr(vartok, "query")) {
|
} else if (strstr(vartok, "query")) {
|
||||||
query = valuetok;
|
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
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -209,7 +253,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
data = getenv("QUERY_STRING");
|
data = getenv("QUERY_STRING");
|
||||||
if (data && strlen(data)) {
|
if (data && strlen(data)) {
|
||||||
print_xml_reply(data);
|
parse_request_variables(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query && strlen(query)) {
|
||||||
|
printQueryData(repository_tag, query);
|
||||||
printf("</distroquery>\n");
|
printf("</distroquery>\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user