From 790de907fe3f5c9b445cfc289a8562cc38607dcf Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Thu, 17 Oct 2013 02:29:56 +0200 Subject: [PATCH] distroquery: add reply_plain and reply_xmltag options for webbuild integration --- src/distroquery.c | 91 +++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/src/distroquery.c b/src/distroquery.c index b4f47c3..f2d342b 100644 --- a/src/distroquery.c +++ b/src/distroquery.c @@ -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("", ajax_call, query); printf("", ajax_call, _("Search")); /* printf(" Repository: %s",ct->tag, ct->tag, ct->tag); ct = ct->next; }*/ - printf("]]>"); + if (!reply_plain) printf("]]>"); - printf("<![CDATA[%s :: %s]]>", - _("Search software packages"), - ct->configdefaults->distribution_name); + if (!reply_plain) { + printf("<![CDATA["); + printf("%s :: %s", _("Search software packages"), ct->configdefaults->distribution_name); + printf("]]>"); + } } void printQueryData() { @@ -287,7 +291,7 @@ void printQueryData() { char buffer[PATH_MAX]; char queryenc[PATH_MAX]; - printf("" - " %s ", query_repositories[i]->tag, sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), query_repositories[i]->arch[a], _("Details")); - printf("
"); + printf("
"); } } sqlite3_finalize(statement); @@ -411,7 +415,7 @@ void printQueryData() { _("for arch "), query_repositories[i]->arch[a]); } - printf("%s %s %s
", 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("%s %s %s
", query_repositories[i]->tag, sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, "packages_files_rel", "name")), @@ -510,7 +514,7 @@ void printQueryData() { printf("
%s
", htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX)); printf("
" - " Details 
", query_repositories[i]->tag, sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name"))); @@ -524,12 +528,12 @@ void printQueryData() { } /* search_sources */ printf("
"); - printf("]]>
"); + if (!reply_plain) printf("]]> 1) - printf(" 1) { printf(" [ "); for (i = j; i <= a; i++) { - if (i != k) printf("", + if (i != k) printf("", query_next, query_limit, query_limit * (i-1)); printf("%d", i); printf(" "); } printf("]"); } - printf("]]>"); + if (!reply_plain) printf("]]>"); - printf("<![CDATA[%s '%s' :: %s]]>", - _("Search results for"), - query, - firstconfigtag->configdefaults->distribution_name); + if (!reply_plain) { + printf("<![CDATA["); + printf("%s '%s' :: %s", _("Search results for"), query, firstconfigtag->configdefaults->distribution_name); + printf("]]>"); + } 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("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(" %s(%s)", + printf(" %s(%s)", ct->tag, sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")), query_arch, @@ -661,7 +666,7 @@ void printPackageData() { printf("

%s:",_("Developers details")); printf("
%s:", _("Source package")); - printf(" %s", + printf(" %s", 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("]]>
"); - printf("<![CDATA[%s :: %s]]>", - buffer, - firstconfigtag->configdefaults->distribution_name); - + if (!reply_plain) printf("]]>", reply_xmltag); + if (!reply_plain) { + printf("<![CDATA["); + printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name); + printf("]]>"); + } sqlite3_close(db); db = NULL; } @@ -766,7 +772,7 @@ void printSourcePackageData() { sizeString strsize; FILE *file; - printf("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(" %s(%s)", + printf(" %s(%s)", 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("]]>"); - printf("<![CDATA[%s :: %s]]>", - buffer, - firstconfigtag->configdefaults->distribution_name); - + if (!reply_plain) printf("]]>", reply_xmltag); + if (!reply_plain) { + printf("<![CDATA["); + printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name); + printf("]]>"); + } 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"); - 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"); + 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("\n"); + if (!reply_plain) printf("\n"); exit(0); }