summaryrefslogtreecommitdiffstats
path: root/pacredir.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-11-14 22:14:57 +0100
committerGravatar Christian Hesse <mail@eworm.de>2013-11-14 22:14:57 +0100
commit013a1a1451196cf32485058802354b349afc3bb7 (patch)
tree7d165c1d8fd58c1aa3153189f550758f217b9b89 /pacredir.c
parent86dea85287ab34cf67e5b69a8d1af53c5fbc325b (diff)
downloadpacredir-013a1a1451196cf32485058802354b349afc3bb7.tar.gz
pacredir-013a1a1451196cf32485058802354b349afc3bb7.tar.zst
do a request as soon as host is up to check bad status
Diffstat (limited to 'pacredir.c')
-rw-r--r--pacredir.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/pacredir.c b/pacredir.c
index 62e3b04..5b5a456 100644
--- a/pacredir.c
+++ b/pacredir.c
@@ -57,12 +57,28 @@ char * get_fqdn(const char * hostname, const char * domainname) {
name = malloc(strlen(hostname) + strlen(domainname) + 2 /* '.' and null char */);
sprintf(name, "%s.%s", hostname, domainname);
+
return name;
}
+/*** get_url ***/
+char * get_url(const char * hostname, const uint16_t port, const char * uri) {
+ char * url;
+
+ url = malloc(10 /* static chars of an url & null char */
+ + strlen(hostname)
+ + 5 /* max strlen of decimal 16bit value */
+ + strlen(uri));
+ sprintf(url, "http://%s:%d/%s",
+ hostname, port, uri);
+
+ return url;
+}
+
/*** add_host ***/
int add_host(const char * host, const char * type) {
struct hosts * tmphosts = hosts;
+ struct request request;
while (tmphosts->host != NULL) {
if (strcmp(tmphosts->host, host) == 0) {
@@ -86,12 +102,22 @@ int add_host(const char * host, const char * type) {
update:
if (strcmp(type, PACSERVE) == 0) {
tmphosts->pacserve.online = 1;
- tmphosts->pacserve.bad = 0;
+ request.port = PORT_PACSERVE;
+ request.bad = &tmphosts->pacserve.bad;
} else if (strcmp(type, PACDBSERVE) == 0) {
tmphosts->pacdbserve.online = 1;
- tmphosts->pacdbserve.bad = 0;
+ request.port = PORT_PACDBSERVE;
+ request.bad = &tmphosts->pacdbserve.bad;
}
+ /* do a first request and let get_http_code() set the bad status */
+ request.host = tmphosts->host;
+ request.url = get_url(request.host, request.port, "");
+ request.http_code = 0;
+ request.last_modified = 0;
+ get_http_code(&request);
+ free(request.url);
+
return EXIT_SUCCESS;
}
@@ -336,8 +362,7 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char *
request->port = PORT_PACSERVE;
request->bad = &(tmphosts->pacserve.bad);
}
- request->url = malloc(10 + strlen(tmphosts->host) + 5 /* max strlen of decimal 16bit value */ + strlen(basename));
- sprintf(request->url, "http://%s:%d/%s", tmphosts->host, dbfile == 1 ? PORT_PACDBSERVE : PORT_PACSERVE, basename);
+ request->url = get_url(tmphosts->host, dbfile == 1 ? PORT_PACDBSERVE : PORT_PACSERVE, basename);
request->http_code = 0;
request->last_modified = 0;