distroquery: support for entering the page with a query passed from QUERY_STRING for homepage website integration
This commit is contained in:
parent
0610ab9760
commit
c872356be3
@ -75,16 +75,16 @@
|
||||
const char* ARCHS[ARCHS_MAX] = { "i586" , "x86_64" , "arm" , "", ""};
|
||||
|
||||
static struct configTag *firstconfigtag = NULL, *configtag = NULL;
|
||||
char *query;
|
||||
char *query = "";
|
||||
char *query_package;
|
||||
char *query_repository;
|
||||
char *query_arch = NULL;
|
||||
int query_archs[ARCHS_MAX];
|
||||
int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 };
|
||||
|
||||
struct configTag *query_repositories[100];
|
||||
|
||||
int search_milestone1 = 0, search_milestone2 = 1, search_devel = 1;
|
||||
int search_sources = 0;
|
||||
int search_sources = 0, searchbox = 0;
|
||||
|
||||
/* Converts a hex character to its integer value */
|
||||
char from_hex(char ch) {
|
||||
@ -153,7 +153,6 @@ int sqlite3_find_column_id(sqlite3_stmt *stmt, const char* table, const char* na
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int find_query_arch(char* arch) {
|
||||
int i;
|
||||
|
||||
@ -196,7 +195,7 @@ void printInputForm() {
|
||||
")";
|
||||
|
||||
printf("<queryform><![CDATA[");
|
||||
printf("<input id=query onkeyup=if(checkMinLength(this.value,3))%s>", ajax_call);
|
||||
printf("<input id=query onkeyup=if(checkMinLength(this.value,3))%s value=\"%s\">", ajax_call, query);
|
||||
printf("<button onclick=%s>Cerca</button>", ajax_call);
|
||||
/* printf(" Repository: <select id=repository>");
|
||||
while (ct) {
|
||||
@ -204,13 +203,35 @@ void printInputForm() {
|
||||
ct = ct->next;
|
||||
}
|
||||
printf("</select>");*/
|
||||
printf("<input type=checkbox id=\"search_devel\" checked=checked onclick=%s>devel ", ajax_call);
|
||||
printf("<input type=checkbox id=\"search_milestone2\" checked=checked onclick=%s>milestone2 ", ajax_call);
|
||||
printf("<input type=checkbox id=\"search_milestone1\" onclick=%s>milestone1 ", ajax_call);
|
||||
printf(" <input type=checkbox id=\"search_i586\" checked=checked onclick=%s>i586 ", ajax_call);
|
||||
printf("<input type=checkbox id=\"search_x86_64\" onclick=%s>x86_64 ", ajax_call);
|
||||
printf("<input type=checkbox id=\"search_arm\" onclick=%s>arm ", ajax_call);
|
||||
printf("<input type=checkbox id=\"search_sources\" onclick=%s>sources ", ajax_call);
|
||||
|
||||
printf("<input type=checkbox id=\"search_devel\" ");
|
||||
if (search_devel) printf("checked=checked ");
|
||||
printf("onclick=%s>devel ", ajax_call);
|
||||
|
||||
printf("<input type=checkbox id=\"search_milestone2\" ");
|
||||
if (search_milestone2) printf("checked=checked ");
|
||||
printf("onclick=%s>milestone2 ", ajax_call);
|
||||
|
||||
printf("<input type=checkbox id=\"search_milestone1\" ");
|
||||
if (search_milestone1) printf("checked=checked ");
|
||||
printf("onclick=%s>milestone1 ", ajax_call);
|
||||
|
||||
printf(" <input type=checkbox id=\"search_i586\" ");
|
||||
if (query_archs[0]) printf("checked=checked ");
|
||||
printf("onclick=%s>i586 ", ajax_call);
|
||||
|
||||
printf("<input type=checkbox id=\"search_x86_64\" ");
|
||||
if (query_archs[1]) printf("checked=checked ");
|
||||
printf("onclick=%s>x86_64 ", ajax_call);
|
||||
|
||||
printf("<input type=checkbox id=\"search_arm\" ");
|
||||
if (query_archs[2]) printf("checked=checked ");
|
||||
printf("onclick=%s>arm ", ajax_call);
|
||||
|
||||
printf("<input type=checkbox id=\"search_sources\" ");
|
||||
if (search_sources) printf("checked=checked ");
|
||||
printf("onclick=%s>sources ", ajax_call);
|
||||
|
||||
printf("<br>");
|
||||
/* ct = firstconfigtag;
|
||||
while (ct) {
|
||||
@ -218,6 +239,9 @@ void printInputForm() {
|
||||
ct = ct->next;
|
||||
}*/
|
||||
printf("]]></queryform>");
|
||||
|
||||
printf("<title><![CDATA[Search software packages :: %s]]></title>",
|
||||
ct->configdefaults->distribution_name);
|
||||
}
|
||||
|
||||
void printQueryData() {
|
||||
@ -227,10 +251,12 @@ void printQueryData() {
|
||||
sqlite3_stmt *statement, *stmt1;
|
||||
char sql[PATH_MAX];
|
||||
char buffer[PATH_MAX];
|
||||
char queryenc[PATH_MAX];
|
||||
|
||||
printf("<queryreply><![CDATA[");
|
||||
for (i = 0; i < strlen(query); i++) {
|
||||
if (query[i] == ' ') query[i] = '%';
|
||||
strncpy(queryenc, query, PATH_MAX);
|
||||
for (i = 0; i < strlen(queryenc); i++) {
|
||||
if (queryenc[i] == ' ') queryenc[i] = '%';
|
||||
}
|
||||
|
||||
/* for (i = 0; query_repositories[i] != NULL; i++) {
|
||||
@ -272,7 +298,7 @@ void printQueryData() {
|
||||
"groupdescr LIKE 'Graphical Desktop/%%' DESC, groupdescr LIKE 'Applications/%%' DESC, "
|
||||
"groupdescr LIKE 'Development/%%' ASC, groupdescr LIKE 'Documentation%%' ASC, groupdescr LIKE 'System/Libraries%%' ASC, "
|
||||
"name LIKE '%%-devel' ASC, name LIKE '%%-debug' ASC "
|
||||
"LIMIT 100", query, query, query, query, query, query);
|
||||
"LIMIT 100", queryenc, queryenc, queryenc, queryenc, queryenc, queryenc);
|
||||
if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[a], sql, strlen(sql), &statement, NULL) == SQLITE_OK) {
|
||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
numresults++;
|
||||
@ -338,7 +364,7 @@ void printQueryData() {
|
||||
snprintf(sql, PATH_MAX,
|
||||
"SELECT * FROM sources WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%' OR version LIKE '%%%s%%'"
|
||||
"ORDER BY name = '%s' DESC, name LIKE '%s%%' DESC, name LIKE '%%%s%%' DESC LIMIT 100",
|
||||
query, query, query, query, query, query);
|
||||
queryenc, queryenc, queryenc, queryenc, queryenc);
|
||||
for (i = 0; query_repositories[i] != NULL; i++) {
|
||||
if (!query_repositories[i]->db[ARCHS_MAX]) {
|
||||
snprintf(dbname, PATH_MAX, "%s%s-sources.db", query_repositories[i]->repository_dir, query_repositories[i]->tag);
|
||||
@ -387,6 +413,10 @@ void printQueryData() {
|
||||
printf("]]></queryreply>");
|
||||
printf("<querystatus><![CDATA[%d result(s) shown.]]></querystatus>", numresults);
|
||||
|
||||
printf("<title><![CDATA[Search results for '%s' :: %s]]></title>",
|
||||
query,
|
||||
firstconfigtag->configdefaults->distribution_name);
|
||||
|
||||
for (i = 0; query_repositories[i] != NULL; i++) {
|
||||
for (a = 0; a <= ARCHS_MAX && query_repositories[i]->arch[a]; a++) {
|
||||
if (query_repositories[i]->db[a]) {
|
||||
@ -422,7 +452,7 @@ void printPackageData() {
|
||||
snprintf(sql, PATH_MAX, "SELECT * FROM packages WHERE name = '%s'", query_package);
|
||||
if (db &&
|
||||
(sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
if (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
|
||||
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
|
||||
if (!sqlite3_open_v2(dbname, &dbs, SQLITE_OPEN_READONLY, NULL)) {
|
||||
@ -536,6 +566,10 @@ void printPackageData() {
|
||||
}
|
||||
}
|
||||
printf("]]></queryreply>");
|
||||
printf("<title><![CDATA[%s - %s :: %s]]></title>",
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),
|
||||
firstconfigtag->configdefaults->distribution_name);
|
||||
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
@ -567,7 +601,7 @@ void printSourcePackageData() {
|
||||
"SELECT * FROM sources,packagers WHERE sources.name = '%s' AND sources.id_packager=packagers.id", query_package);
|
||||
if (db &&
|
||||
(sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
if (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
|
||||
printf("<hr><br>");
|
||||
printTagsLine(NULL,
|
||||
@ -672,6 +706,10 @@ void printSourcePackageData() {
|
||||
}
|
||||
}
|
||||
printf("]]></queryreply>");
|
||||
printf("<title><![CDATA[%s - %s :: %s]]></title>",
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),
|
||||
firstconfigtag->configdefaults->distribution_name);
|
||||
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
@ -696,11 +734,11 @@ void parse_request_variables(char *data) {
|
||||
} else if (!strcmp(vartok, "query")) {
|
||||
query = url_decode(valuetok);
|
||||
} else if (!strcmp(vartok, "search_milestone2")) {
|
||||
search_milestone2 = (strstr(valuetok, "false") != valuetok);
|
||||
search_milestone2 = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "search_milestone1")) {
|
||||
search_milestone1 = (strstr(valuetok, "false") != valuetok);
|
||||
search_milestone1 = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "search_devel")) {
|
||||
search_devel = (strstr(valuetok, "false") != valuetok);
|
||||
search_devel = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "search_i586")) {
|
||||
query_archs[0] = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "search_x86_64")) {
|
||||
@ -708,7 +746,9 @@ void parse_request_variables(char *data) {
|
||||
} else if (!strcmp(vartok, "search_arm")) {
|
||||
query_archs[2] = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "search_sources")) {
|
||||
search_sources = (strstr(valuetok, "false") != valuetok);
|
||||
search_sources = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "searchbox")) {
|
||||
searchbox = strstr(valuetok, "false") != valuetok;
|
||||
}
|
||||
}
|
||||
|
||||
@ -759,8 +799,10 @@ main(int argc, char *argv[])
|
||||
printPackageData();
|
||||
else
|
||||
printSourcePackageData();
|
||||
if (searchbox) printInputForm();
|
||||
} else if (query && strlen(query)) {
|
||||
printQueryData();
|
||||
if (searchbox) printInputForm();
|
||||
} else {
|
||||
printInputForm();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user