distroquery: add reply_plain and reply_xmltag options for webbuild integration
This commit is contained in:
parent
7d2a532478
commit
790de907fe
@ -86,6 +86,8 @@ char *query_arch = NULL;
|
||||
int query_limit = 10;
|
||||
int query_offset = 0;
|
||||
char query_next[PATH_MAX] = "";
|
||||
char *reply_xmltag = "queryreply";
|
||||
int reply_plain = 0;
|
||||
char *lang = "";
|
||||
int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 };
|
||||
|
||||
@ -222,7 +224,7 @@ void printInputForm() {
|
||||
"'&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("<button onclick=%s>%s</button>", ajax_call, _("Search"));
|
||||
/* printf(" 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);
|
||||
ct = ct->next;
|
||||
}*/
|
||||
printf("]]></queryform>");
|
||||
if (!reply_plain) printf("]]></queryform>");
|
||||
|
||||
printf("<title><![CDATA[%s :: %s]]></title>",
|
||||
_("Search software packages"),
|
||||
ct->configdefaults->distribution_name);
|
||||
if (!reply_plain) {
|
||||
printf("<title><![CDATA[");
|
||||
printf("%s :: %s", _("Search software packages"), ct->configdefaults->distribution_name);
|
||||
printf("]]></title>");
|
||||
}
|
||||
}
|
||||
|
||||
void printQueryData() {
|
||||
@ -287,7 +291,7 @@ void printQueryData() {
|
||||
char buffer[PATH_MAX];
|
||||
char queryenc[PATH_MAX];
|
||||
|
||||
printf("<queryreply><![CDATA[");
|
||||
if (!reply_plain) printf("<%s><![CDATA[", reply_xmltag);
|
||||
strncpy(queryenc, query, PATH_MAX);
|
||||
for (i = 0; i < strlen(queryenc); i++) {
|
||||
if (queryenc[i] == ' ') queryenc[i] = '%';
|
||||
@ -381,14 +385,14 @@ void printQueryData() {
|
||||
|
||||
/* details */
|
||||
printf(" <div style='display:inline;background-color:lightblue;font-weight:strong'>"
|
||||
" <a href='javascript:distroquery_request("
|
||||
" <a href=#reply onclick='distroquery_request("
|
||||
"\"repository=%s&package=%s&arch=%s\")' style=\"color:black\">%s</a> </div>",
|
||||
query_repositories[i]->tag,
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
|
||||
query_repositories[i]->arch[a],
|
||||
_("Details"));
|
||||
|
||||
printf("</div></div><br>");
|
||||
printf("</div><br>");
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
@ -411,7 +415,7 @@ void printQueryData() {
|
||||
_("for arch "),
|
||||
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>",
|
||||
query_repositories[i]->tag,
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, "packages", "name")),
|
||||
@ -447,7 +451,7 @@ void printQueryData() {
|
||||
_("for arch "),
|
||||
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>",
|
||||
query_repositories[i]->tag,
|
||||
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>",
|
||||
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'>"
|
||||
" <a href='javascript:distroquery_request("
|
||||
" <a href=#reply onclick='distroquery_request("
|
||||
"\"repository=%s&package=%s\")' style=\"color:black\">Details</a> </div>",
|
||||
query_repositories[i]->tag,
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")));
|
||||
@ -524,12 +528,12 @@ void printQueryData() {
|
||||
} /* search_sources */
|
||||
printf("<hr>");
|
||||
|
||||
printf("]]></queryreply>");
|
||||
if (!reply_plain) printf("]]></%s><querystatus><![CDATA[", reply_xmltag);
|
||||
k = query_offset / query_limit + 1; /* k = current shown page */
|
||||
if (otherresults || k > 1)
|
||||
printf("<querystatus><![CDATA[%d %s.", numresults, _("result(s) shown"));
|
||||
printf("%d %s.", numresults, _("result(s) shown"));
|
||||
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 (!otherresults) {
|
||||
/* current page is last available */
|
||||
@ -540,19 +544,20 @@ void printQueryData() {
|
||||
if (a > 1) {
|
||||
printf(" [ ");
|
||||
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));
|
||||
printf("%d", i);
|
||||
printf("</a> ");
|
||||
}
|
||||
printf("]");
|
||||
}
|
||||
printf("]]></querystatus>");
|
||||
if (!reply_plain) printf("]]></querystatus>");
|
||||
|
||||
printf("<title><![CDATA[%s '%s' :: %s]]></title>",
|
||||
_("Search results for"),
|
||||
query,
|
||||
firstconfigtag->configdefaults->distribution_name);
|
||||
if (!reply_plain) {
|
||||
printf("<title><![CDATA[");
|
||||
printf("%s '%s' :: %s", _("Search results for"), query, firstconfigtag->configdefaults->distribution_name);
|
||||
printf("]]></title>");
|
||||
}
|
||||
|
||||
for (i = 0; query_repositories[i] != NULL; i++) {
|
||||
for (a = 0; a <= ARCHS_MAX && query_repositories[i]->arch[a]; a++) {
|
||||
@ -577,7 +582,7 @@ void printPackageData() {
|
||||
sizeString strsize;
|
||||
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);
|
||||
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")));
|
||||
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt2, NULL) == SQLITE_OK) {
|
||||
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,
|
||||
sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")),
|
||||
query_arch,
|
||||
@ -661,7 +666,7 @@ void printPackageData() {
|
||||
printf("<hr><br><b>%s:</b>",_("Developers details"));
|
||||
|
||||
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,
|
||||
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_finalize(statement);
|
||||
}
|
||||
printf("]]></queryreply>");
|
||||
printf("<title><![CDATA[%s :: %s]]></title>",
|
||||
buffer,
|
||||
firstconfigtag->configdefaults->distribution_name);
|
||||
|
||||
if (!reply_plain) printf("]]></%s>", reply_xmltag);
|
||||
if (!reply_plain) {
|
||||
printf("<title><![CDATA[");
|
||||
printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name);
|
||||
printf("]]></title>");
|
||||
}
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
}
|
||||
@ -766,7 +772,7 @@ void printSourcePackageData() {
|
||||
sizeString strsize;
|
||||
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);
|
||||
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")));
|
||||
if (sqlite3_prepare_v2(dba, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
|
||||
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,
|
||||
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
|
||||
ct->arch[a],
|
||||
@ -897,11 +903,12 @@ void printSourcePackageData() {
|
||||
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
printf("]]></queryreply>");
|
||||
printf("<title><![CDATA[%s :: %s]]></title>",
|
||||
buffer,
|
||||
firstconfigtag->configdefaults->distribution_name);
|
||||
|
||||
if (!reply_plain) printf("]]></%s>", reply_xmltag);
|
||||
if (!reply_plain) {
|
||||
printf("<title><![CDATA[");
|
||||
printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name);
|
||||
printf("]]></title>");
|
||||
}
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
}
|
||||
@ -933,6 +940,10 @@ void parse_request_variables(char *data) {
|
||||
searchbox = strstr(valuetok, "false") != valuetok;
|
||||
} else if (!strcmp(vartok, "lang")) {
|
||||
lang = valuetok;
|
||||
} else if (!strcmp(vartok, "replytag")) {
|
||||
reply_xmltag = valuetok;
|
||||
} else if (!strcmp(vartok, "replyplain")) {
|
||||
reply_plain = strstr(valuetok, "true") == valuetok;
|
||||
} else {
|
||||
/* fields to make reusable query string for next pages */
|
||||
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';
|
||||
|
||||
ct = firstconfigtag;
|
||||
i = 0;
|
||||
while (ct) {
|
||||
@ -995,8 +1005,6 @@ main(int argc, char *argv[])
|
||||
signal(SIGSEGV, backtraceHandler);
|
||||
|
||||
|
||||
printf("Content-Type: text/xml;charset=utf-8\n\n<distroquery>");
|
||||
|
||||
firstconfigtag = read_configuration(DEFAULT_CONFIGFILE);
|
||||
if (!firstconfigtag) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
@ -1025,6 +1038,6 @@ main(int argc, char *argv[])
|
||||
printInputForm();
|
||||
}
|
||||
|
||||
printf("</distroquery>\n");
|
||||
if (!reply_plain) printf("</distroquery>\n");
|
||||
exit(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user