distroquery: implement specialQueryResponse function starting with %latest%<repository> special command
This commit is contained in:
parent
43fb6825f8
commit
2707361aaa
@ -130,6 +130,7 @@ char *url_encode(char *str) {
|
|||||||
/* Returns a url-decoded version of str */
|
/* Returns a url-decoded version of str */
|
||||||
/* IMPORTANT: be sure to free() the returned string after use */
|
/* IMPORTANT: be sure to free() the returned string after use */
|
||||||
char *url_decode(char *str) {
|
char *url_decode(char *str) {
|
||||||
|
if (!str) { char *buf=malloc(1); buf[0]=0; return buf; }
|
||||||
char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf;
|
char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf;
|
||||||
while (*pstr) {
|
while (*pstr) {
|
||||||
if (*pstr == '%') {
|
if (*pstr == '%') {
|
||||||
@ -236,16 +237,19 @@ void attachCtDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
|
|
||||||
while (ct->repository[i]) {
|
while (ct->repository[i]) {
|
||||||
|
if (arch) {
|
||||||
snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository[i]->repository_dir, ct->repository[i]->tag, arch);
|
snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository[i]->repository_dir, ct->repository[i]->tag, arch);
|
||||||
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s'", dbname, ct->repository[i]->tag);
|
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s'", dbname, ct->repository[i]->tag);
|
||||||
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
||||||
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository[i]->repository_dir, ct->repository[i]->tag);
|
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository[i]->repository_dir, ct->repository[i]->tag);
|
||||||
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s_sources'", dbname, ct->repository[i]->tag);
|
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s_sources'", dbname, ct->repository[i]->tag);
|
||||||
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
||||||
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,13 +264,11 @@ void attachRepositoryDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
|
|||||||
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
||||||
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"ATTACHED DATABASE %s\n", ct->tag);
|
|
||||||
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);
|
||||||
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s_sources'", dbname, ct->tag);
|
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s_sources'", dbname, ct->tag);
|
||||||
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
|
||||||
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"ATTACHED DATABASE %s_sources\n", ct->tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void detachRepositoryDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
|
void detachRepositoryDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
|
||||||
@ -540,7 +542,7 @@ void printQueryResponse() {
|
|||||||
sqlite3_finalize(stmt1);
|
sqlite3_finalize(stmt1);
|
||||||
}
|
}
|
||||||
if (query_compact) {
|
if (query_compact) {
|
||||||
printf("<b><a href='http://www.openmamba.org/distribution/search.html?"
|
printf("<b><a href='/distribution/search.html?"
|
||||||
"repository=%s&package=%s&arch=%s&searchbox=true' style=\"color:black\" target='distroquery'>"
|
"repository=%s&package=%s&arch=%s&searchbox=true' style=\"color:black\" target='distroquery'>"
|
||||||
"%s</a></b> %s-%s - %s<br>",
|
"%s</a></b> %s-%s - %s<br>",
|
||||||
query_repositories[i]->tag,
|
query_repositories[i]->tag,
|
||||||
@ -615,7 +617,7 @@ void printQueryResponse() {
|
|||||||
|
|
||||||
|
|
||||||
if (query_compact) {
|
if (query_compact) {
|
||||||
printf("<a href='http://www.openmamba.org/distribution/search.html?"
|
printf("<a href='/distribution/search.html?"
|
||||||
"repository=%s&package=%s&arch=%s&searchbox=true' style=\"color:black\" target='distroquery'>"
|
"repository=%s&package=%s&arch=%s&searchbox=true' style=\"color:black\" target='distroquery'>"
|
||||||
"%s</a> (%s-%s) %s %s<br>",
|
"%s</a> (%s-%s) %s %s<br>",
|
||||||
query_repositories[i]->tag,
|
query_repositories[i]->tag,
|
||||||
@ -730,7 +732,7 @@ void printQueryResponse() {
|
|||||||
|
|
||||||
printf("<br><img src=\"%s\" width\"16\" height=\"16\"> ", buffer);
|
printf("<br><img src=\"%s\" width\"16\" height=\"16\"> ", buffer);
|
||||||
if (query_compact) {
|
if (query_compact) {
|
||||||
printf("<b><a href='http://www.openmamba.org/distribution/search.html?"
|
printf("<b><a href='/distribution/search.html?"
|
||||||
"repository=%s&package=%s&searchbox=true' style=\"color:black\" target='distroquery'>"
|
"repository=%s&package=%s&searchbox=true' style=\"color:black\" target='distroquery'>"
|
||||||
"%s</a></b> %s-%s - %s<br>",
|
"%s</a></b> %s-%s - %s<br>",
|
||||||
query_repositories[i]->tag,
|
query_repositories[i]->tag,
|
||||||
@ -806,6 +808,83 @@ void printQueryResponse() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printSpecialQueryResponse() {
|
||||||
|
char *repository;
|
||||||
|
char sql[PATH_MAX];
|
||||||
|
char dbname[PATH_MAX];
|
||||||
|
char buffer[PATH_MAX];
|
||||||
|
sqlite3 *db;
|
||||||
|
sqlite3_stmt *statement, *stmt1;
|
||||||
|
struct configTag* ct;
|
||||||
|
int i;
|
||||||
|
char updates[PATH_MAX];
|
||||||
|
|
||||||
|
if (strstr(query, "$latest$") == query) {
|
||||||
|
repository = query + 8;
|
||||||
|
ct = findRepositoryByTag(repository);
|
||||||
|
if (!ct) return;
|
||||||
|
/* latest packages in a repository */
|
||||||
|
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
|
||||||
|
if (sqlite3_open_v2(dbname, (sqlite3**)&db, SQLITE_OPEN_READONLY, NULL)) {
|
||||||
|
if (db) sqlite3_close(db);
|
||||||
|
fprintf(stderr, "ERROR: unable to open sqlite3 db %s\n", dbname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
attachCtDatabases(ct, db, NULL);
|
||||||
|
if (!reply_plain) printf("<%s><![CDATA[", reply_xmltag);
|
||||||
|
snprintf(sql, PATH_MAX, "SELECT * FROM sources ORDER BY buildtime DESC LIMIT 100");
|
||||||
|
if (db && (sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
|
||||||
|
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
|
i=0;
|
||||||
|
updates[0]=0;
|
||||||
|
while (ct->repository[i]) {
|
||||||
|
if (ct->repository[i] == ct) break;
|
||||||
|
snprintf(sql, PATH_MAX, "SELECT * FROM '%s_sources'.sources WHERE name='%s'",
|
||||||
|
ct->repository[i]->tag,
|
||||||
|
(const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")));
|
||||||
|
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
|
||||||
|
if (sqlite3_step(stmt1) == SQLITE_ROW) {
|
||||||
|
snprintf(updates, PATH_MAX, "%s %s(%s,%s-%s)", _("Updates"),
|
||||||
|
(const char*)sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
|
||||||
|
ct->repository[i]->tag,
|
||||||
|
(const char*)sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "version")),
|
||||||
|
(const char*)sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "release")));
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt1);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
get_favicon_from_url((const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")),buffer,PATH_MAX);
|
||||||
|
if (updates[0] != 0) {
|
||||||
|
printf("<img src=\"/pub/openmamba/distromatic/pkgup.png\" title=\"%s\" width\"14\" height=\"14\"> ", updates);
|
||||||
|
} else {
|
||||||
|
printf("<img src=\"/pub/openmamba/distromatic/pkg.png\" width\"14\" height=\"14\"> ");
|
||||||
|
}
|
||||||
|
printf("<img src=\"%s\" width\"12\" height=\"12\"> ", buffer);
|
||||||
|
printf("<b><a href='/distribution/search.html?"
|
||||||
|
"repository=%s&package=%s&searchbox=true' style=\"color:black\" target='distroquery' title=\"%s\">"
|
||||||
|
"%s</a></b> %s-%s<br>",
|
||||||
|
ct->tag,
|
||||||
|
(const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
|
||||||
|
htmlcleanNoBr((const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),buffer,PATH_MAX),
|
||||||
|
(const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
|
||||||
|
(const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
|
||||||
|
(const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")));
|
||||||
|
}
|
||||||
|
sqlite3_finalize(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reply_plain) printf("]]></%s>", reply_xmltag);
|
||||||
|
if (!reply_plain) {
|
||||||
|
printf("<title><![CDATA[");
|
||||||
|
printf("%s :: %s", buffer, firstconfigtag->configdefaults->distribution_name);
|
||||||
|
printf("]]></title>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printQueryResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void printPackageData() {
|
void printPackageData() {
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -1382,6 +1461,9 @@ main(int argc, char *argv[])
|
|||||||
printSourcePackageData();
|
printSourcePackageData();
|
||||||
responsed = 1;
|
responsed = 1;
|
||||||
} else if (query && strlen(query)) {
|
} else if (query && strlen(query)) {
|
||||||
|
if (query[0] == '$')
|
||||||
|
printSpecialQueryResponse();
|
||||||
|
else
|
||||||
printQueryResponse();
|
printQueryResponse();
|
||||||
responsed = 1;
|
responsed = 1;
|
||||||
} else if (query_path) {
|
} else if (query_path) {
|
||||||
|
Loading…
Reference in New Issue
Block a user