distroquery: add reply_plain and reply_xmltag options for webbuild integration

This commit is contained in:
Silvan Calarco 2013-10-17 02:29:56 +02:00
parent 7d2a532478
commit 790de907fe

View File

@ -86,6 +86,8 @@ char *query_arch = NULL;
int query_limit = 10; int query_limit = 10;
int query_offset = 0; int query_offset = 0;
char query_next[PATH_MAX] = ""; char query_next[PATH_MAX] = "";
char *reply_xmltag = "queryreply";
int reply_plain = 0;
char *lang = ""; char *lang = "";
int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 }; int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 };
@ -222,7 +224,7 @@ void printInputForm() {
"'&search_files='+getElementById('search_files').checked" "'&search_files='+getElementById('search_files').checked"
")"; ")";
printf("<queryform><![CDATA["); if (!reply_plain) printf("<queryform><![CDATA[");
printf("<input id=query onkeyup=if(checkMinLength(this.value,3))%s value=\"%s\">", ajax_call, query); printf("<input id=query onkeyup=if(checkMinLength(this.value,3))%s value=\"%s\">", ajax_call, query);
printf("<button onclick=%s>%s</button>", ajax_call, _("Search")); printf("<button onclick=%s>%s</button>", ajax_call, _("Search"));
/* printf("&nbsp;Repository: <select id=repository>"); /* printf("&nbsp;Repository: <select id=repository>");
@ -270,11 +272,13 @@ void printInputForm() {
printf("<div width=150px style=\"display:inline\"><input name=\"%s\" type=checkbox value=\"%s\">%s</div>",ct->tag, ct->tag, ct->tag); 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; ct = ct->next;
}*/ }*/
printf("]]></queryform>"); if (!reply_plain) printf("]]></queryform>");
printf("<title><![CDATA[%s :: %s]]></title>", if (!reply_plain) {
_("Search software packages"), printf("<title><![CDATA[");
ct->configdefaults->distribution_name); printf("%s :: %s", _("Search software packages"), ct->configdefaults->distribution_name);
printf("]]></title>");
}
} }
void printQueryData() { void printQueryData() {
@ -287,7 +291,7 @@ void printQueryData() {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char queryenc[PATH_MAX]; char queryenc[PATH_MAX];
printf("<queryreply><![CDATA["); if (!reply_plain) printf("<%s><![CDATA[", reply_xmltag);
strncpy(queryenc, query, PATH_MAX); strncpy(queryenc, query, PATH_MAX);
for (i = 0; i < strlen(queryenc); i++) { for (i = 0; i < strlen(queryenc); i++) {
if (queryenc[i] == ' ') queryenc[i] = '%'; if (queryenc[i] == ' ') queryenc[i] = '%';
@ -381,14 +385,14 @@ void printQueryData() {
/* details */ /* details */
printf("&nbsp;<div style='display:inline;background-color:lightblue;font-weight:strong'>" printf("&nbsp;<div style='display:inline;background-color:lightblue;font-weight:strong'>"
"&nbsp;<a href='javascript:distroquery_request(" "&nbsp;<a href=#reply onclick='distroquery_request("
"\"repository=%s&package=%s&arch=%s\")' style=\"color:black\">%s</a>&nbsp;</div>", "\"repository=%s&package=%s&arch=%s\")' style=\"color:black\">%s</a>&nbsp;</div>",
query_repositories[i]->tag, query_repositories[i]->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
query_repositories[i]->arch[a], query_repositories[i]->arch[a],
_("Details")); _("Details"));
printf("</div></div><br>"); printf("</div><br>");
} }
} }
sqlite3_finalize(statement); sqlite3_finalize(statement);
@ -411,7 +415,7 @@ void printQueryData() {
_("for arch "), _("for arch "),
query_repositories[i]->arch[a]); query_repositories[i]->arch[a]);
} }
printf("<a href='javascript:distroquery_request(" printf("<a href=#reply onclick='distroquery_request("
"\"repository=%s&package=%s&arch=%s\")' style=\"color:black;background-color:lightblue\">%s</a> %s %s<br>", "\"repository=%s&package=%s&arch=%s\")' style=\"color:black;background-color:lightblue\">%s</a> %s %s<br>",
query_repositories[i]->tag, query_repositories[i]->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, "packages", "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, "packages", "name")),
@ -447,7 +451,7 @@ void printQueryData() {
_("for arch "), _("for arch "),
query_repositories[i]->arch[a]); query_repositories[i]->arch[a]);
} }
printf("<a href='javascript:distroquery_request(" printf("<a href=#reply onclick='distroquery_request("
"\"repository=%s&package=%s&arch=%s\")' style=\"color:black;background-color:lightblue\">%s</a> %s %s<br>", "\"repository=%s&package=%s&arch=%s\")' style=\"color:black;background-color:lightblue\">%s</a> %s %s<br>",
query_repositories[i]->tag, query_repositories[i]->tag,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, "packages_files_rel", "name")), sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, "packages_files_rel", "name")),
@ -510,7 +514,7 @@ void printQueryData() {
printf("<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div>", printf("<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div>",
htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX)); htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX));
printf("<div style='display:inline;background-color:lightblue;font-weight:strong'>" printf("<div style='display:inline;background-color:lightblue;font-weight:strong'>"
"&nbsp;<a href='javascript:distroquery_request(" "&nbsp;<a href=#reply onclick='distroquery_request("
"\"repository=%s&package=%s\")' style=\"color:black\">Details</a>&nbsp;</div>", "\"repository=%s&package=%s\")' style=\"color:black\">Details</a>&nbsp;</div>",
query_repositories[i]->tag, query_repositories[i]->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name"))); sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")));
@ -524,12 +528,12 @@ void printQueryData() {
} /* search_sources */ } /* search_sources */
printf("<hr>"); printf("<hr>");
printf("]]></queryreply>"); if (!reply_plain) printf("]]></%s><querystatus><![CDATA[", reply_xmltag);
k = query_offset / query_limit + 1; /* k = current shown page */ k = query_offset / query_limit + 1; /* k = current shown page */
if (otherresults || k > 1) if (otherresults || k > 1)
printf("<querystatus><![CDATA[%d %s.", numresults, _("result(s) shown")); printf("%d %s.", numresults, _("result(s) shown"));
else else
printf("<querystatus><![CDATA[%d %s.", numresults, _("result(s) found")); printf("%d %s.", numresults, _("result(s) found"));
if (k < 7) j=1; else j=k-5; /* j = start pages list from */ if (k < 7) j=1; else j=k-5; /* j = start pages list from */
if (!otherresults) { if (!otherresults) {
/* current page is last available */ /* current page is last available */
@ -540,19 +544,20 @@ void printQueryData() {
if (a > 1) { if (a > 1) {
printf("&nbsp;[&nbsp;"); printf("&nbsp;[&nbsp;");
for (i = j; i <= a; i++) { for (i = j; i <= a; i++) {
if (i != k) printf("<a href='javascript:distroquery_request(\"%s&limit=%d&offset=%d\")'>", if (i != k) printf("<a href=#reply onclick='distroquery_request(\"%s&limit=%d&offset=%d\")'>",
query_next, query_limit, query_limit * (i-1)); query_next, query_limit, query_limit * (i-1));
printf("%d", i); printf("%d", i);
printf("</a>&nbsp"); printf("</a>&nbsp");
} }
printf("]"); printf("]");
} }
printf("]]></querystatus>"); if (!reply_plain) printf("]]></querystatus>");
printf("<title><![CDATA[%s '%s' :: %s]]></title>", if (!reply_plain) {
_("Search results for"), printf("<title><![CDATA[");
query, printf("%s '%s' :: %s", _("Search results for"), query, firstconfigtag->configdefaults->distribution_name);
firstconfigtag->configdefaults->distribution_name); printf("]]></title>");
}
for (i = 0; query_repositories[i] != NULL; i++) { for (i = 0; query_repositories[i] != NULL; i++) {
for (a = 0; a <= ARCHS_MAX && query_repositories[i]->arch[a]; a++) { for (a = 0; a <= ARCHS_MAX && query_repositories[i]->arch[a]; a++) {
@ -577,7 +582,7 @@ void printPackageData() {
sizeString strsize; sizeString strsize;
FILE *file; FILE *file;
printf("<queryreply><![CDATA["); if (!reply_plain) printf("<%s><![CDATA[", reply_xmltag);
snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository_dir, ct->tag, query_arch); snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository_dir, ct->tag, query_arch);
if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READONLY, NULL)) { if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READONLY, NULL)) {
@ -635,7 +640,7 @@ void printPackageData() {
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt2, NULL) == SQLITE_OK) { if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt2, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt2) == SQLITE_ROW) while (sqlite3_step(stmt2) == SQLITE_ROW)
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>", printf(" <a href=#reply onclick='distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>",
ct->tag, ct->tag,
sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")), sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")),
query_arch, query_arch,
@ -661,7 +666,7 @@ void printPackageData() {
printf("<hr><br><b>%s:</b>",_("Developers details")); printf("<hr><br><b>%s:</b>",_("Developers details"));
printf("<br>%s:", _("Source package")); printf("<br>%s:", _("Source package"));
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s\")'>%s</a>", printf(" <a href=#reply onclick='distroquery_request(\"repository=%s&package=%s\")'>%s</a>",
ct->tag, ct->tag,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")), sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")));
@ -744,11 +749,12 @@ void printPackageData() {
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary"))); sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
printf("]]></queryreply>"); if (!reply_plain) printf("]]></%s>", reply_xmltag);
printf("<title><![CDATA[%s :: %s]]></title>", if (!reply_plain) {
buffer, printf("<title><![CDATA[");
firstconfigtag->configdefaults->distribution_name); printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name);
printf("]]></title>");
}
sqlite3_close(db); sqlite3_close(db);
db = NULL; db = NULL;
} }
@ -766,7 +772,7 @@ void printSourcePackageData() {
sizeString strsize; sizeString strsize;
FILE *file; FILE *file;
printf("<queryreply><![CDATA["); if (!reply_plain) printf("<%s><![CDATA[", reply_xmltag);
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag); snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READONLY, NULL)) { if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READONLY, NULL)) {
@ -811,7 +817,7 @@ void printSourcePackageData() {
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(dba, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) { if (sqlite3_prepare_v2(dba, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) while (sqlite3_step(stmt1) == SQLITE_ROW)
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>", printf(" <a href=#reply onclick='distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>",
ct->tag, ct->tag,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")), sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
ct->arch[a], ct->arch[a],
@ -897,11 +903,12 @@ void printSourcePackageData() {
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary"))); sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
printf("]]></queryreply>"); if (!reply_plain) printf("]]></%s>", reply_xmltag);
printf("<title><![CDATA[%s :: %s]]></title>", if (!reply_plain) {
buffer, printf("<title><![CDATA[");
firstconfigtag->configdefaults->distribution_name); printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name);
printf("]]></title>");
}
sqlite3_close(db); sqlite3_close(db);
db = NULL; db = NULL;
} }
@ -933,6 +940,10 @@ void parse_request_variables(char *data) {
searchbox = strstr(valuetok, "false") != valuetok; searchbox = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "lang")) { } else if (!strcmp(vartok, "lang")) {
lang = valuetok; lang = valuetok;
} else if (!strcmp(vartok, "replytag")) {
reply_xmltag = valuetok;
} else if (!strcmp(vartok, "replyplain")) {
reply_plain = strstr(valuetok, "true") == valuetok;
} else { } else {
/* fields to make reusable query string for next pages */ /* fields to make reusable query string for next pages */
if (!strcmp(vartok, "query")) { if (!strcmp(vartok, "query")) {
@ -963,7 +974,6 @@ void parse_request_variables(char *data) {
} }
} }
if (query_next[strlen(query_next)] == '&') query_next[strlen(query_next)] = '\0'; if (query_next[strlen(query_next)] == '&') query_next[strlen(query_next)] = '\0';
ct = firstconfigtag; ct = firstconfigtag;
i = 0; i = 0;
while (ct) { while (ct) {
@ -995,8 +1005,6 @@ main(int argc, char *argv[])
signal(SIGSEGV, backtraceHandler); signal(SIGSEGV, backtraceHandler);
printf("Content-Type: text/xml;charset=utf-8\n\n<distroquery>");
firstconfigtag = read_configuration(DEFAULT_CONFIGFILE); firstconfigtag = read_configuration(DEFAULT_CONFIGFILE);
if (!firstconfigtag) { if (!firstconfigtag) {
fprintf(stderr, "Fatal error while parsing config file " DEFAULT_CONFIGFILE "; aborting.\n"); fprintf(stderr, "Fatal error while parsing config file " DEFAULT_CONFIGFILE "; aborting.\n");
@ -1008,6 +1016,11 @@ main(int argc, char *argv[])
parse_request_variables(data); parse_request_variables(data);
} }
if (!reply_plain)
printf("Content-Type: text/xml;charset=utf-8\n\n<distroquery>");
else
printf("Content-Type: text/html;charset=utf-8\n\n");
setlocale(LC_ALL, lang); setlocale(LC_ALL, lang);
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -1025,6 +1038,6 @@ main(int argc, char *argv[])
printInputForm(); printInputForm();
} }
printf("</distroquery>\n"); if (!reply_plain) printf("</distroquery>\n");
exit(0); exit(0);
} }