Use url in FAVICON_SEARCH_PREFIX to get favicon url for sites

Default configuration pointing to google service
Fallfack to <url>/favicon.ico if FAVICON_SEARCH_PREFIX is not set
This commit is contained in:
Silvan Calarco 2015-05-16 13:04:12 +02:00
parent 4199fc7d62
commit 49b2967e9b
3 changed files with 20 additions and 11 deletions

View File

@ -34,6 +34,10 @@ URL_PREFIX="/distromatic/index.html?"
# (default: ARCHS=i586) # (default: ARCHS=i586)
# #
#ARCHS = i586 #ARCHS = i586
#
# FAVICON_SEARCH_PREFIX:
# external prefix url to service providing sites favicons
FAVICON_SEARCH_PREFIX="http://www.google.com/s2/favicons?domain="
#[maintainers] #[maintainers]
# put maintainer list with aliases here # put maintainer list with aliases here

View File

@ -255,6 +255,9 @@ struct configTag* read_configuration(const char *confFile)
} else if (!strcmp(vartok, "URL_DIR")) { } else if (!strcmp(vartok, "URL_DIR")) {
configdefaults.url_dir = configdefaults.url_dir =
(char *) strdup(valuetok); (char *) strdup(valuetok);
} else if (!strcmp(vartok, "FAVICON_SEARCH_PREFIX")) {
configdefaults.favicon_search_prefix =
(char *) strdup(valuetok);
} else if (!strcmp(vartok, "ARCHS")) { } else if (!strcmp(vartok, "ARCHS")) {
vartok = (char *) strtok(valuetok, " "); vartok = (char *) strtok(valuetok, " ");
i = 0; i = 0;
@ -621,25 +624,26 @@ int scansdir(const char *dir, struct dirent ***namelist,
return(i); return(i);
} }
#define favicon_url_prefix "http://g.etfv.co/"
int int
get_favicon_from_url(const char* url,char *buf,int bufsize) { get_favicon_from_url(const char* url,char *buf,int bufsize) {
int i=0,l=0; int i=0,l=0;
strncpy(buf, favicon_url_prefix, bufsize); if (configdefaults.favicon_search_prefix != NULL) {
snprintf(buf, bufsize, "%s%s", configdefaults.favicon_search_prefix, url);
} else {
snprintf(buf, bufsize, "%s", url);
/* expecting urls in the form http://address/... */ /* expecting urls in the form http://address/... */
if (url) { while ((i<bufsize) && buf[i]) {
while ((i<bufsize) && url[i]) { if (buf[i] == '/') {
if (url[i] == '/') {
l++; l++;
if (l == 3) break; if (l == 3) break;
} }
i++; i++;
} }
buf[i] = 0;
snprintf(&buf[i], bufsize - l, "/favicon.ico");
} }
strncpy(&buf[strlen(buf)], url, i);
return 0; return 0;
} }

View File

@ -18,6 +18,7 @@ struct configDefaults {
char *url_prefix; char *url_prefix;
char *url_search_prefix; char *url_search_prefix;
char *url_dir; char *url_dir;
char *favicon_search_prefix;
char *arch[ARCHS_MAX]; char *arch[ARCHS_MAX];
}; };