summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pacredir.c33
-rw-r--r--pacredir.h2
2 files changed, 31 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;
diff --git a/pacredir.h b/pacredir.h
index 6922f0d..f5107ec 100644
--- a/pacredir.h
+++ b/pacredir.h
@@ -55,6 +55,8 @@ struct request {
int write_log(FILE *stream, const char *format, ...);
/* get_fqdn */
char * get_fqdn(const char * hostname, const char * domainname);
+/* get_url */
+char * get_url(const char * hostname, const uint16_t port, const char * uri);
/* add_host */
int add_host(const char * host, const char * type);