distroquery: favicon management and some other output data improvements

This commit is contained in:
Silvan Calarco 2013-10-13 14:45:56 +02:00
parent 9c1d4b1547
commit 0610ab9760
5 changed files with 135 additions and 84 deletions

View File

@ -163,6 +163,23 @@ int find_query_arch(char* arch) {
return -1; return -1;
} }
void printRPMFlags(int flags) {
if (flags & RPMSENSE_LESS) printf("<");
if (flags & RPMSENSE_GREATER) printf(">");
if (flags & RPMSENSE_EQUAL) printf("=");
}
void printTagsLine(const char* arch, const char* tag, const char* group, const char* license) {
if (!arch)
printf("<div style='display:inline;color:white;background-color:red'> Source </div>&nbsp;");
else
printf("<div style='display:inline;color:white;background-color:green'> %s </div>&nbsp;", arch);
printf("<div style='display:inline;color:black;background-color:yellow'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div>&nbsp;"
"<div style='display:inline;color:black;background-color:orange'>&nbsp%s&nbsp;</div>",
tag, group, license);
}
void printInputForm() { void printInputForm() {
struct configTag *ct = firstconfigtag; struct configTag *ct = firstconfigtag;
@ -207,8 +224,9 @@ void printQueryData() {
int a, i, j, k, numresults = 0; int a, i, j, k, numresults = 0;
char dbname[PATH_MAX]; char dbname[PATH_MAX];
sqlite3_stmt *statement; sqlite3_stmt *statement, *stmt1;
char sql[PATH_MAX]; char sql[PATH_MAX];
char buffer[PATH_MAX];
printf("<queryreply><![CDATA["); printf("<queryreply><![CDATA[");
for (i = 0; i < strlen(query); i++) { for (i = 0; i < strlen(query); i++) {
@ -238,6 +256,15 @@ void printQueryData() {
fprintf(stderr, "ERROR: unable to open sqlite3 db %s; ignoring.\n", dbname); fprintf(stderr, "ERROR: unable to open sqlite3 db %s; ignoring.\n", dbname);
} }
} }
if (!query_repositories[i]->db[ARCHS_MAX]) {
snprintf(dbname, PATH_MAX, "%s%s-sources.db",
query_repositories[i]->repository_dir, query_repositories[i]->tag);
if (sqlite3_open_v2(dbname, (sqlite3**)&query_repositories[i]->db[ARCHS_MAX], SQLITE_OPEN_READONLY, NULL)) {
query_repositories[i]->db[ARCHS_MAX] = NULL;
fprintf(stderr, "ERROR: unable to open sqlite3 db %s; ignoring.\n", dbname);
}
}
if (query_repositories[i]->db[a]) { if (query_repositories[i]->db[a]) {
snprintf(sql, PATH_MAX, snprintf(sql, PATH_MAX,
"SELECT * FROM packages WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%' OR version LIKE '%%%s%%' " "SELECT * FROM packages WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%' OR version LIKE '%%%s%%' "
@ -249,20 +276,29 @@ void printQueryData() {
if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[a], sql, strlen(sql), &statement, NULL) == SQLITE_OK) { if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[a], sql, strlen(sql), &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) { while (sqlite3_step(statement) == SQLITE_ROW) {
numresults++; numresults++;
printf("<div style='position:relative'><hr><br><div style='display:inline;color:white;background-color:green'>&nbsp;%s&nbsp;</div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'>&nbsp;%s&nbsp;</div>&nbsp;" snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE id=%d",
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp;%s&nbsp;</div><br>" sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source")));
"<b>%s</b> %s-%s<br>%s", if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
query_repositories[i]->arch[a], sqlite3_step(stmt1);
query_repositories[i]->tag, get_favicon_from_url(sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "url")),buffer,PATH_MAX);
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), } else buffer[0]='\0';
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), printf("<div style='position:relative'><hr><br>");
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")), printTagsLine(query_repositories[i]->arch[a],
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary"))); query_repositories[i]->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")),
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "license")));
printf("<br><img src=\"%s\" width\"16\" height=\"16\">&nbsp;", buffer);
printf("<b>%s</b> %s-%s<br>%s",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")),
htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),buffer,PATH_MAX));
printf("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div>", printf("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description"))); htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX));
/* install */ /* install */
/* printf("<div align=right style='position:absolute;top:5px;right:0;padding:5px;'>" /* printf("<div align=right style='position:absolute;top:5px;right:0;padding:5px;'>"
@ -277,7 +313,7 @@ void printQueryData() {
printf("<div style='display:inline;background-color:green'>" printf("<div style='display:inline;background-color:green'>"
"&nbsp;<a href=\"%s%s/SRPMS.base/%s-%s-%s.src.rpm\" style=\"color:white\">Download</a>&nbsp;</div>", "&nbsp;<a href=\"%s%s/SRPMS.base/%s-%s-%s.src.rpm\" style=\"color:white\">Download</a>&nbsp;</div>",
query_repositories[i]->download_prefix, query_repositories[i]->download_prefix,
query_repositories[i]->download_dir, query_repositories[i]->download_dir,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release"))); sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")));
@ -316,26 +352,33 @@ void printQueryData() {
(sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
while (sqlite3_step(statement) == SQLITE_ROW) { while (sqlite3_step(statement) == SQLITE_ROW) {
numresults++; numresults++;
printf("<hr><br><div style='display:inline;color:black;background-color:red'>&nbsp;Source&nbsp;</div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'>&nbsp;%s&nbsp;</div>&nbsp;" get_favicon_from_url(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")),buffer,PATH_MAX);
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div><br>"
"<b>%s</b> %s-%s<br>%s<br>License: %s</br>URL: %s<br><br>" printf("<hr><br>");
"<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
query_repositories[i]->tag, printTagsLine(NULL,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), query_repositories[i]->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "license")));
printf("<br><img src=\"%s\" width\"16\" height=\"16\">&nbsp;", buffer);
printf("<b>%s</b> %s-%s<br>%s<br><br>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),buffer,PATH_MAX));
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "license")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")), printf("<div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description"))); htmlcleanNoBr(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX));
printf("&nbsp;<div style='display:inline;background-color:lightblue;font-weight:strong'>" printf("<div style='display:inline;background-color:lightblue;font-weight:strong'>"
"<a href='javascript:distroquery_request(" "&nbsp;<a href='javascript:distroquery_request("
"\"repository=%s&package=%s\")' style=\"color:black\">&nbsp;Details&nbsp;</a></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")));
} }
} else {
fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(query_repositories[i]->db[ARCHS_MAX]), sql);
} }
} }
} }
@ -354,12 +397,6 @@ void printQueryData() {
} }
} }
void printRPMFlags(int flags) {
if (flags & RPMSENSE_LESS) printf("<");
if (flags & RPMSENSE_GREATER) printf(">");
if (flags & RPMSENSE_EQUAL) printf("=");
}
void printPackageData() { void printPackageData() {
int a, i, j, k; int a, i, j, k;
@ -369,6 +406,7 @@ void printPackageData() {
char sql[PATH_MAX]; char sql[PATH_MAX];
char buffer[PATH_MAX]; char buffer[PATH_MAX];
struct configTag* ct = findRepositoryByTag(query_repository); struct configTag* ct = findRepositoryByTag(query_repository);
humanDate strdate;
sizeString strsize; sizeString strsize;
printf("<queryreply><![CDATA["); printf("<queryreply><![CDATA[");
@ -388,20 +426,25 @@ void printPackageData() {
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, &dbs, SQLITE_OPEN_READONLY, NULL)) { if (!sqlite3_open_v2(dbname, &dbs, SQLITE_OPEN_READONLY, NULL)) {
snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE id=%d",
snprintf(sql, PATH_MAX,
"SELECT * FROM sources,packagers WHERE sources.id=%d AND sources.id_packager=packagers.id",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source")));
if (sqlite3_prepare_v2(dbs, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) sqlite3_step(stmt1); if (sqlite3_prepare_v2(dbs, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) sqlite3_step(stmt1);
} }
printf("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div>&nbsp;" printf("<hr><br>");
"<div style='display:inline;color:black;background-color:yellow'> %s </div>&nbsp;" printTagsLine(query_arch,
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div>&nbsp;" ct->tag,
"<div style='display:inline;color:black;background-color:orange'>&nbsp%s&nbsp;</div><br><br>" sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")),
"<h1>%s - %s</h1>Version: %s-%s<br>URL: <a href=\"%s\" target=_new>%s</a><br>Size: %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "license")));
query_arch,
ct->tag, get_favicon_from_url(sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "url")),buffer,PATH_MAX);
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")),
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "license")), printf("<br><br>"
"<h1><img src=\"%s\" width\"16\" height=\"16\">&nbsp;"
"%s - %s</h1>Version: %s-%s<br>URL: <a href=\"%s\" target=_new>%s</a><br>Size: %s",
buffer,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
@ -445,6 +488,10 @@ void printPackageData() {
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")));
printf("<br>Maintainer: %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, "packagers", "name")));
printf("<br>Build date: %s",
simpleTimeToHuman(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildtime")), (humanDate *) & strdate));
printf("<br><br>Obsoletes:"); printf("<br><br>Obsoletes:");
snprintf(sql, PATH_MAX, "SELECT * FROM obsoletes WHERE id_package=%d", snprintf(sql, PATH_MAX, "SELECT * FROM obsoletes WHERE id_package=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
@ -496,7 +543,7 @@ void printPackageData() {
void printSourcePackageData() { void printSourcePackageData() {
int a, i, j, k, numresults = 0; int a, i, j, k;
char dbname[PATH_MAX]; char dbname[PATH_MAX];
sqlite3 *db, *dba; sqlite3 *db, *dba;
sqlite3_stmt *statement, *stmt1; sqlite3_stmt *statement, *stmt1;
@ -521,15 +568,19 @@ void printSourcePackageData() {
if (db && if (db &&
(sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { (sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
while (sqlite3_step(statement) == SQLITE_ROW) { while (sqlite3_step(statement) == SQLITE_ROW) {
numresults++;
printf("<hr><br><div style='display:inline;color:white;background-color:red'> Source </div>&nbsp;" printf("<hr><br>");
"<div style='display:inline;color:black;background-color:yellow'> %s </div>&nbsp;" printTagsLine(NULL,
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div>&nbsp;" ct->tag,
"<div style='display:inline;color:black;background-color:orange'>&nbsp%s&nbsp;</div><br><br>" sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")),
"<h1>%s - %s</h1>Version: %s-%s<br>URL: <a href=\"%s\" target=_new>%s</a><br>Size: %s", sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "license")));
ct->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), get_favicon_from_url(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")),buffer,PATH_MAX);
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "license")),
printf("<br><br>"
"<h1><img src=\"%s\" width\"16\" height=\"16\">&nbsp;"
"%s - %s</h1>Version: %s-%s<br>URL: <a href=\"%s\" target=_new>%s</a><br>Size: %s",
buffer,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
@ -560,7 +611,7 @@ void printSourcePackageData() {
htmlclean(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX)); htmlclean(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX));
/* download */ /* download */
printf("<div style='display:inline;background-color:green'>" printf("<div style='display:inline;background-color:red'>"
"&nbsp;<a href=\"%s%s/SRPMS.base/%s-%s-%s.src.rpm\" style=\"color:white\">Download</a>&nbsp;</div>", "&nbsp;<a href=\"%s%s/SRPMS.base/%s-%s-%s.src.rpm\" style=\"color:white\">Download</a>&nbsp;</div>",
ct->download_prefix, ct->download_prefix,
ct->download_dir, ct->download_dir,

View File

@ -626,3 +626,27 @@ int scansdir(const char *dir, struct dirent ***namelist,
return(i); return(i);
} }
int
get_favicon_from_url(const char* url,char *buf,int bufsize) {
int i=0,l=0;
/* expecting urls in the form http://address/... */
if (url) {
while ((i<bufsize) && url[i]) {
buf[i]=url[i];
if (buf[i] == '/') {
l++;
if (l == 3) break;
}
i++;
}
buf[i]='\0';
} else {
/* use current site as default icon */
buf[0]='\0';
}
strcat(buf,"/favicon.ico");
return 0;
}

View File

@ -39,5 +39,5 @@ int scansdir(const char *dir, struct dirent ***namelist,
int (*select)(const struct dirent *), int (*select)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **)); int (*compar)(const struct dirent **, const struct dirent **));
void backtraceHandler(int sig); void backtraceHandler(int sig);
int get_favicon_from_url(const char* url,char *buf,int bufsize);
#endif /* FUNCTIONS_H */ #endif /* FUNCTIONS_H */

View File

@ -34,7 +34,6 @@ void print_contents_subtree(FILE *f,
struct fileTree* ft, struct fileTree* ft,
struct configTag* ct, struct configTag* ct,
char* buf, int bufsize); char* buf, int bufsize);
int get_pkg_icon(struct headerSourceList *h,char *buf,int bufsize);
int generatePkgList(struct configTag *ct, int arch); int generatePkgList(struct configTag *ct, int arch);
int generateSrcPkgList(struct configTag *ct); int generateSrcPkgList(struct configTag *ct);

View File

@ -838,29 +838,6 @@ generateHTMLMainIndex(struct configTag *configtag)
return 0; return 0;
} }
int
get_pkg_icon(struct headerSourceList *h,char *buf,int bufsize) {
int i=0,l=0;
/* expecting urls in the form http://address/... */
if (h->url) {
while ((i<bufsize) && h->url[i]) {
buf[i]=h->url[i];
if (buf[i] == '/') {
l++;
if (l == 3) break;
}
i++;
}
buf[i]='\0';
} else {
/* use current site as default icon */
strcat(buf,"/");
}
return 0;
}
int int
generateHTML_SRPMSFiles(struct configTag *configtag) generateHTML_SRPMSFiles(struct configTag *configtag)
{ {
@ -978,10 +955,10 @@ generateHTML_SRPMSFiles(struct configTag *configtag)
return 1; return 1;
} }
get_pkg_icon(currheadersourcelist,buffer2,1024); get_favicon_from_url(currheadersourcelist->url,buffer2,1024);
fprintf(fout, fprintf(fout,
"<h1><img src=\"%s/favicon.ico\" width=\"16\" height=\"16\">" "<h1><img src=\"%s\" width=\"16\" height=\"16\">"
"&nbsp;%s: %s (source)</h1><table class=\"pkgpage\" width=\"100%%\">\n", "&nbsp;%s: %s (source)</h1><table class=\"pkgpage\" width=\"100%%\">\n",
buffer2, buffer2,
currheadersourcelist->name, currheadersourcelist->name,
@ -1449,10 +1426,10 @@ generateHTMLFiles(struct configTag *ct, int arch)
perror(htmlfile); perror(htmlfile);
return 1; return 1;
} }
get_pkg_icon(currheaderlist->sourceheader,buffer,1024); get_favicon_from_url(currheaderlist->sourceheader->url,buffer,1024);
fprintf(fout, fprintf(fout,
"<h1><img src=\"%s/favicon.ico\" width=\"16\" height=\"16\">" "<h1><img src=\"%s\" width=\"16\" height=\"16\">"
"&nbsp;%s: %s</h1><table class=\"pkgpage\" width=\"100%%\">", "&nbsp;%s: %s</h1><table class=\"pkgpage\" width=\"100%%\">",
buffer, buffer,
currheaderlist->name, currheaderlist->name,