summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeffschroed <jeffschroed@c587cffe-e639-0410-9787-d7902ae8ed56>2008-01-08 23:34:19 +0000
committerjeffschroed <jeffschroed@c587cffe-e639-0410-9787-d7902ae8ed56>2008-01-08 23:34:19 +0000
commit5319f53f8acf2d53600cd49b8af9d1fc6a3af7c0 (patch)
tree4bf55706b346f3cc5fff1c1ead3d5b5bddff3e99
parent88c5009c016ab61d079feecc52dc68f687062784 (diff)
downloadlibproxy-git-5319f53f8acf2d53600cd49b8af9d1fc6a3af7c0.tar.gz
Convert all comments over to C89 style closing issue 2
-rw-r--r--src/bin/proxy.c26
-rw-r--r--src/lib/array.c7
-rw-r--r--src/lib/config_file.c18
-rw-r--r--src/lib/misc.c24
-rw-r--r--src/lib/misc.h2
-rw-r--r--src/lib/pac.c34
-rw-r--r--src/lib/proxy_factory.c155
-rw-r--r--src/lib/proxy_factory.h16
-rw-r--r--src/lib/strdict.c2
-rw-r--r--src/lib/url.c46
-rw-r--r--src/lib/url.h2
-rw-r--r--src/lib/wpad.c2
-rw-r--r--src/lib/wpad_dns.c40
13 files changed, 193 insertions, 181 deletions
diff --git a/src/bin/proxy.c b/src/bin/proxy.c
index b980a48..0a5b5d4 100644
--- a/src/bin/proxy.c
+++ b/src/bin/proxy.c
@@ -23,7 +23,7 @@
#include <unistd.h>
#include <string.h>
-// Import libproxy API
+/* Import libproxy API */
#include <proxy.h>
#define STDIN fileno(stdin)
@@ -45,20 +45,20 @@ strdup(char *string)
static char *
readline(int fd)
{
- // Verify we have an open socket
+ /* Verify we have an open socket */
if (fd < 0) return NULL;
- // For each character received add it to the buffer unless it is a newline
+ /* For each character received add it to the buffer unless it is a newline */
char *buffer = NULL;
for (int i=1; i > 0 ; i++)
{
char c;
- // Receive a single character, check for newline or EOF
+ /* Receive a single character, check for newline or EOF */
if (read(fd, &c, 1) != 1) return buffer;
if (c == '\n') return buffer ? buffer : strdup("");
- // Allocate new buffer if we need
+ /* Allocate new buffer if we need */
if (i % 1024 == 1)
{
char *tmp = buffer;
@@ -67,7 +67,7 @@ readline(int fd)
if (tmp) { strcpy(buffer, tmp); free(tmp); }
}
- // Add new character
+ /* Add new character */
buffer[i-1] = c;
}
return buffer;
@@ -76,7 +76,7 @@ readline(int fd)
int
main(int argc, char **argv)
{
- // Create the proxy factory object
+ /* Create the proxy factory object */
pxProxyFactory *pf = px_proxy_factory_new();
if (!pf)
{
@@ -84,12 +84,14 @@ main(int argc, char **argv)
return 1;
}
- // For each URL we read on STDIN, get the proxies to use
+ /* For each URL we read on STDIN, get the proxies to use */
for (char *url = NULL ; url = readline(STDIN) ; free(url))
{
- // Get an array of proxies to use. These should be used
- // in the order returned. Only move on to the next proxy
- // if the first one fails (etc).
+ /*
+ * Get an array of proxies to use. These should be used
+ * in the order returned. Only move on to the next proxy
+ * if the first one fails (etc).
+ */
char **proxies = px_proxy_factory_get_proxies(pf, url);
for (int i = 0 ; proxies[i] ; i++)
{
@@ -103,7 +105,7 @@ main(int argc, char **argv)
free(proxies);
}
- // Destantiate the proxy factory object
+ /* Destantiate the proxy factory object */
px_proxy_factory_free(pf);
return 0;
}
diff --git a/src/lib/array.c b/src/lib/array.c
index 107a4df..5441d9e 100644
--- a/src/lib/array.c
+++ b/src/lib/array.c
@@ -60,11 +60,10 @@ px_array_new(pxArrayItemsEqual equals, pxArrayItemCallback free, bool unique, bo
bool
px_array_add(pxArray *self, void *item)
{
- // Verify some basic stuff
+ /* Verify some basic stuff */
if (!self || !item) return false;
- // If we are a unique array and a dup is found,
- // either bail or replace the item
+ /* If we are a unique array and a dup is found, either bail or replace the item */
if (self->unique && px_array_find(self, item) >= 0)
{
if (!self->replace)
@@ -90,7 +89,7 @@ px_array_del(pxArray *self, const void *item)
unsigned int index = px_array_find(self, item);
if (index < 0) return false;
- // Free the old one and shift elements down
+ /* Free the old one and shift elements down */
self->free(self->data[index]);
memmove(self->data+index,
self->data+index+1,
diff --git a/src/lib/config_file.c b/src/lib/config_file.c
index aafbf62..8e32cab 100644
--- a/src/lib/config_file.c
+++ b/src/lib/config_file.c
@@ -36,36 +36,36 @@ struct _pxConfigFile {
pxConfigFile *
px_config_file_new(char *filename)
{
- // Open the file and stat it
+ /* Open the file and stat it */
struct stat st;
int fd = open(filename, O_RDONLY);
if (fd < 0) return NULL;
fstat(fd, &st);
- // Allocate our structure; get mtime and filename
+ /* Allocate our structure; get mtime and filename */
pxConfigFile *self = px_malloc0(sizeof(pxConfigFile));
self->filename = px_strdup(filename);
self->mtime = st.st_mtime;
self->sections = px_strdict_new((void *) px_strdict_free);
- // Add one section (PX_CONFIG_FILE_DEFAULT_SECTION)
+ /* Add one section (PX_CONFIG_FILE_DEFAULT_SECTION) */
px_strdict_set(self->sections, PX_CONFIG_FILE_DEFAULT_SECTION, px_strdict_new(free));
pxStrDict *current = (pxStrDict *) px_strdict_get(self->sections, PX_CONFIG_FILE_DEFAULT_SECTION);
- // Parse our file
+ /* Parse our file */
for (char *line=NULL ; (line = px_readline(fd)) ; px_free(line))
{
- // Strip
+ /* Strip */
char *tmp = px_strstrip(line);
px_free(line); line = tmp;
- // Check for comment and/or empty line
+ /* Check for comment and/or empty line */
if (*line == '#' || !strcmp(line, "")) continue;
- // If we have a new section
+ /* If we have a new section */
if (*line == '[' || line[strlen(line)-1] == ']')
{
- // Get just the section name
+ /* Get just the section name */
memmove(line, line+1, strlen(line)-1);
line[strlen(line)-2] = '\0';
@@ -75,7 +75,7 @@ px_config_file_new(char *filename)
px_strdict_set(self->sections, line, px_strdict_new(free));
}
- // If this is a key/val line, get the key/val.
+ /* If this is a key/val line, get the key/val. */
else if ((tmp = strchr(line, '=')) && tmp[1])
{
*tmp = '\0';
diff --git a/src/lib/misc.c b/src/lib/misc.c
index 40f7886..358d1c0 100644
--- a/src/lib/misc.c
+++ b/src/lib/misc.c
@@ -110,13 +110,13 @@ px_strcat(const char *s, ...)
{
va_list args;
- // Count the number of characters to concatentate
+ /* Count the number of characters to concatentate */
va_start(args, s);
int count = strlen(s);
for (char *tmp = NULL ; (tmp = va_arg(args, char *)) ; count += strlen(tmp));
va_end(args);
- // Build our output string
+ /* Build our output string */
char *output = px_malloc0(count + 1);
strcat(output, s);
va_start(args, s);
@@ -139,13 +139,13 @@ px_strjoin(const char **strv, const char *delimiter)
if (!strv) return NULL;
if (!delimiter) return NULL;
- // Count up the length we need
+ /* Count up the length we need */
size_t length = 0;
for (int i=0 ; strv[i]; i++)
length += strlen(strv[i]) + strlen(delimiter);
if (!length) return NULL;
- // Do the join
+ /* Do the join */
char *str = px_malloc0(length);
for (int i=0 ; strv[i]; i++)
{
@@ -164,15 +164,15 @@ px_strjoin(const char **strv, const char *delimiter)
char **
px_strsplit(const char *string, const char *delimiter)
{
- // Count how many times the delimiter appears
+ /* Count how many times the delimiter appears */
int count = 1;
for (const char *tmp = string ; (tmp = strstr(tmp, delimiter)) ; tmp += strlen(delimiter))
count++;
- // Allocate the vector
+ /* Allocate the vector */
char **strv = px_malloc0(sizeof(char *) * (count + 1));
- // Fill the vector
+ /* Fill the vector */
const char *last = string;
for (int i=0 ; i < count ; i++)
{
@@ -210,20 +210,20 @@ px_strfreev(char **strv)
char *
px_readline(int fd)
{
- // Verify we have an open socket
+ /* Verify we have an open socket */
if (fd < 0) return NULL;
- // For each character received add it to the buffer unless it is a newline
+ /* For each character received add it to the buffer unless it is a newline */
char *buffer = NULL;
for (int i=1; i > 0 ; i++)
{
char c;
- // Receive a single character, check for newline or EOF
+ /* Receive a single character, check for newline or EOF */
if (read(fd, &c, 1) != 1) return buffer;
if (c == '\n') return buffer ? buffer : px_strdup("");
- // Allocate new buffer if we need
+ /* Allocate new buffer if we need */
if (i % 1024 == 1)
{
char *tmp = buffer;
@@ -231,7 +231,7 @@ px_readline(int fd)
if (tmp) { strcpy(buffer, tmp); px_free(tmp); }
}
- // Add new character
+ /* Add new character */
buffer[i-1] = c;
}
return buffer;
diff --git a/src/lib/misc.h b/src/lib/misc.h
index bee77ac..b1e45e6 100644
--- a/src/lib/misc.h
+++ b/src/lib/misc.h
@@ -20,7 +20,7 @@
#ifndef MISC_H_
#define MISC_H_
-#include <stdlib.h> // For type size_t
+#include <stdlib.h> /* For type size_t */
/**
* Allocates memory and always returns valid memory.
diff --git a/src/lib/pac.c b/src/lib/pac.c
index 9403d39..ca32ede 100644
--- a/src/lib/pac.c
+++ b/src/lib/pac.c
@@ -70,13 +70,13 @@ px_pac_new(pxURL *url)
{
if (!url) return NULL;
- // Allocate the object
+ /* Allocate the object */
pxPAC *self = px_malloc0(sizeof(pxPAC));
- // Copy the given URL
- self->url = px_url_new(px_url_to_string(url)); // Always returns valid value
+ /* Copy the given URL */
+ self->url = px_url_new(px_url_to_string(url)); /* Always returns valid value */
- // Make sure we have a real pxPAC
+ /* Make sure we have a real pxPAC */
if (!px_pac_reload(self)) { px_pac_free(self); return NULL; }
return self;
@@ -90,13 +90,13 @@ px_pac_new(pxURL *url)
pxPAC *
px_pac_new_from_string(char *url)
{
- // Create temporary URL
+ /* Create temporary URL */
pxURL *tmpurl = px_url_new(url);
if (!tmpurl) return NULL;
- // Create pac
+ /* Create pac */
pxPAC *self = px_pac_new(tmpurl);
- px_url_free(tmpurl); // Free no longer used URL
+ px_url_free(tmpurl); /* Free no longer used URL */
if (!self) return NULL;
return self;
}
@@ -124,33 +124,33 @@ px_pac_reload(pxPAC *self)
bool correct_mime_type;
unsigned long int content_length = 0;
- // Get the pxPAC
+ /* Get the pxPAC */
sock = px_url_get(self->url, headers);
if (sock < 0) return false;
- // Verify status line
+ /* Verify status line */
line = px_readline(sock);
if (!line) goto error;
- if (strncmp(line, "HTTP", strlen("HTTP"))) goto error; // Check valid HTTP response
- if (!strchr(line, ' ') || atoi(strchr(line, ' ') + 1) != 200) goto error; // Check status code
+ if (strncmp(line, "HTTP", strlen("HTTP"))) goto error; /* Check valid HTTP response */
+ if (!strchr(line, ' ') || atoi(strchr(line, ' ') + 1) != 200) goto error; /* Check status code */
- // Check for correct mime type and content length
+ /* Check for correct mime type and content length */
while (strcmp(line, "\r")) {
- // Check for content type
+ /* Check for content type */
if (strstr(line, "Content-Type: ") == line && strstr(line, PAC_MIME_TYPE))
correct_mime_type = true;
- // Check for content length
+ /* Check for content length */
else if (strstr(line, "Content-Length: ") == line)
content_length = atoi(line + strlen("Content-Length: "));
- // Get new line
+ /* Get new line */
px_free(line);
line = px_readline(sock);
if (!line) goto error;
}
- // Get content
+ /* Get content */
if (!content_length || !correct_mime_type) goto error;
px_free(line); line = NULL;
px_free(self->cache);
@@ -158,7 +158,7 @@ px_pac_reload(pxPAC *self)
for (int recvd=0 ; recvd != content_length ; )
recvd += recv(sock, self->cache + recvd, content_length - recvd, 0);
- // Clean up
+ /* Clean up */
close(sock);
return true;
diff --git a/src/lib/proxy_factory.c b/src/lib/proxy_factory.c
index 5fd3f28..0ff7c0d 100644
--- a/src/lib/proxy_factory.c
+++ b/src/lib/proxy_factory.c
@@ -58,7 +58,7 @@ struct _pxProxyFactory {
pxConfigFile *cf;
};
-// Convert the PAC formatted response into our proxy URL array response
+/* Convert the PAC formatted response into our proxy URL array response */
static char **
_format_pac_response(char *response)
{
@@ -107,7 +107,7 @@ _sockaddr_equals(const struct sockaddr *ip_a, const struct sockaddr *ip_b, const
if (ip_a->sa_family != ip_b->sa_family) return false;
if (nm && ip_a->sa_family != nm->sa_family) return false;
- // Setup the arrays
+ /* Setup the arrays */
uint8_t bytes = 0, *a_data = NULL, *b_data = NULL, *nm_data = NULL;
if (ip_a->sa_family == AF_INET)
{
@@ -142,26 +142,26 @@ _sockaddr_from_string(const char *ip, int len)
if (!ip) return NULL;
struct sockaddr *result = NULL;
- // Copy the string
+ /* Copy the string */
if (len >= 0)
ip = px_strndup(ip, len);
else
ip = px_strdup(ip);
- // Try to parse IPv4
+ /* Try to parse IPv4 */
result = px_malloc0(sizeof(struct sockaddr_in));
result->sa_family = AF_INET;
if (inet_pton(AF_INET, ip, &((struct sockaddr_in *) result)->sin_addr) > 0)
goto out;
- // Try to parse IPv6
+ /* Try to parse IPv6 */
px_free(result);
result = px_malloc0(sizeof(struct sockaddr_in6));
result->sa_family = AF_INET6;
if (inet_pton(AF_INET6, ip, &((struct sockaddr_in6 *) result)->sin6_addr) > 0)
goto out;
- // No address found
+ /* No address found */
px_free(result);
result = NULL;
out:
@@ -172,7 +172,7 @@ _sockaddr_from_string(const char *ip, int len)
static struct sockaddr *
_sockaddr_from_cidr(int af, int cidr)
{
- // TODO: Support CIDR notation
+ /* TODO: Support CIDR notation */
return NULL;
}
@@ -186,21 +186,25 @@ _ip_ignore(pxURL *url, char *ignore)
const struct sockaddr *dst_ip = px_url_get_ip_no_dns(url);
struct sockaddr *ign_ip = NULL, *net_ip = NULL;
- // IPv4
- // IPv6
+ /*
+ * IPv4
+ * IPv6
+ */
if ((ign_ip = _sockaddr_from_string(ignore, -1)))
goto out;
- // IPv4/CIDR
- // IPv4/IPv4
- // IPv6/CIDR
- // IPv6/IPv6
+ /*
+ * IPv4/CIDR
+ * IPv4/IPv4
+ * IPv6/CIDR
+ * IPv6/IPv6
+ */
if (strchr(ignore, '/'))
{
ign_ip = _sockaddr_from_string(ignore, strchr(ignore, '/') - ignore);
net_ip = _sockaddr_from_string(strchr(ignore, '/') + 1, -1);
- // If CIDR notation was used, get the netmask
+ /* If CIDR notation was used, get the netmask */
if (ign_ip && !net_ip)
{
uint32_t cidr = 0;
@@ -217,13 +221,15 @@ _ip_ignore(pxURL *url, char *ignore)
net_ip = NULL;
}
- // IPv4:port
- // [IPv6]:port
+ /*
+ * IPv4:port
+ * [IPv6]:port
+ */
if (strrchr(ignore, ':') && sscanf(strrchr(ignore, ':'), ":%u", &port) == 1 && port > 0)
{
ign_ip = _sockaddr_from_string(ignore, strrchr(ignore, ':') - ignore);
- // Make sure this really is just a port and not just an IPv6 address
+ /* Make sure this really is just a port and not just an IPv6 address */
if (ign_ip && (ign_ip->sa_family != AF_INET6 || ignore[0] == '['))
goto out;
@@ -245,11 +251,11 @@ _domain_ignore(pxURL *url, char *ignore)
if (!url || !ignore)
return false;
- // Get our URL's hostname and port
+ /* Get our URL's hostname and port */
char *host = px_strdup(px_url_get_host(url));
int port = px_url_get_port(url);
- // Get our ignore pattern's hostname and port
+ /* Get our ignore pattern's hostname and port */
char *ihost = px_strdup(ignore);
int iport = 0;
if (strchr(ihost, ':'))
@@ -261,27 +267,27 @@ _domain_ignore(pxURL *url, char *ignore)
iport = 0;
}
- // Hostname match (domain.com or domain.com:80)
+ /* Hostname match (domain.com or domain.com:80) */
if (!strcmp(host, ihost))
if (!iport || port == iport)
goto match;
- // Endswith (.domain.com or .domain.com:80)
+ /* Endswith (.domain.com or .domain.com:80) */
if (ihost[0] == '.' && _endswith(host, ihost))
if (!iport || port == iport)
goto match;
- // Glob (*.domain.com or *.domain.com:80)
+ /* Glob (*.domain.com or *.domain.com:80) */
if (ihost[0] == '*' && _endswith(host, ihost+1))
if (!iport || port == iport)
goto match;
- // No match was found
+ /* No match was found */
px_free(host);
px_free(ihost);
return false;
- // A match was found
+ /* A match was found */
match:
px_free(host);
px_free(ihost);
@@ -291,7 +297,7 @@ _domain_ignore(pxURL *url, char *ignore)
static void
destantiate_plugins(void *item, void *self)
{
- // Call the destantiation hook
+ /* Call the destantiation hook */
pxProxyFactoryVoidCallback destantiate;
destantiate = dlsym(item, "on_proxy_factory_destantiate");
if (destantiate)
@@ -318,22 +324,22 @@ px_proxy_factory_new ()
self->misc = px_strdict_new(NULL);
self->on_get_proxies = px_array_new(NULL, NULL, true, false);
- // Open the plugin dir
+ /* Open the plugin dir */
DIR *plugindir = opendir(PLUGINDIR);
if (!plugindir) return self;
- // For each plugin...
+ /* For each plugin... */
struct dirent *ent;
for (int i=0 ; (ent = readdir(plugindir)) ; i++)
{
- // Load the plugin
+ /* Load the plugin */
char *tmp = px_strcat(PLUGINDIR, "/", ent->d_name, NULL);
void *plugin = dlopen(tmp, RTLD_LOCAL);
px_free(tmp);
if (!plugin)
continue;
- // Call the instantiation hook
+ /* Call the instantiation hook */
pxProxyFactoryBoolCallback instantiate;
instantiate = dlsym(plugin, "on_proxy_factory_instantiate");
if (instantiate && !instantiate(self))
@@ -352,27 +358,29 @@ px_proxy_factory_config_add(pxProxyFactory *self, const char *name, pxConfigCate
int count;
pxProxyFactoryConfig **tmp;
- // Verify some basic stuff
+ /* Verify some basic stuff */
if (!self) return false;
if (!callback) return false;
if (!name || !strcmp(name, "")) return false;
- // Allocate an empty config array if there is none
+ /* Allocate an empty config array if there is none */
if (!self->configs) self->configs = px_malloc0(sizeof(pxProxyFactoryConfig *));
- // Make sure that 'name' is unique
- // Also, get a count of how many configs we have
+ /*
+ * Make sure that 'name' is unique
+ * Also, get a count of how many configs we have
+ */
for (count=0 ; self->configs[count] ; count++)
if (!strcmp(self->configs[count]->name, name))
return false;
- // Allocate new array, copy old values into it and free old array
+ /* Allocate new array, copy old values into it and free old array */
tmp = px_malloc0(sizeof(pxProxyFactoryConfig *) * (count + 2));
memcpy(tmp, self->configs, sizeof(pxProxyFactoryConfig *) * count);
px_free(self->configs);
self->configs = tmp;
- // Add the new callback to the end
+ /* Add the new callback to the end */
self->configs[count] = px_malloc0(sizeof(pxProxyFactoryConfig));
self->configs[count]->category = category;
self->configs[count]->name = px_strdup(name);
@@ -386,12 +394,12 @@ px_proxy_factory_config_del(pxProxyFactory *self, const char *name)
{
int i,j;
- // Verify some basic stuff
+ /* Verify some basic stuff */
if (!self) return false;
if (!name || !strcmp(name, "")) return false;
if (!self->configs) return false;
- // Remove and shift all configs down (if found)
+ /* Remove and shift all configs down (if found) */
for (i=0,j=0 ; self->configs[j]; i++,j++)
{
if (i != j)
@@ -403,7 +411,7 @@ px_proxy_factory_config_del(pxProxyFactory *self, const char *name)
}
}
- // If we have an empty array, free it
+ /* If we have an empty array, free it */
if (!self->configs[0])
{
px_free(self->configs);
@@ -416,7 +424,7 @@ px_proxy_factory_config_del(pxProxyFactory *self, const char *name)
bool
px_proxy_factory_misc_set(pxProxyFactory *self, const char *key, const void *value)
{
- // Verify some basic stuff
+ /* Verify some basic stuff */
if (!self) return false;
if (!key || !strcmp(key, "")) return false;
@@ -426,7 +434,7 @@ px_proxy_factory_misc_set(pxProxyFactory *self, const char *key, const void *val
void *
px_proxy_factory_misc_get(pxProxyFactory *self, const char *key)
{
- // Verify some basic stuff
+ /* Verify some basic stuff */
if (!self) return NULL;
if (!key || !strcmp(key, "")) return NULL;
@@ -454,47 +462,47 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
char **response = px_strsplit("direct://", ";");
char *tmp = NULL, *order = NULL, **orderv = NULL;
- // Verify some basic stuff
+ /* Verify some basic stuff */
if (!self) goto do_return;
if (!url || !strcmp(url, "")) goto do_return;
if (!realurl) goto do_return;
- // Lock mutex
+ /* Lock mutex */
pthread_mutex_lock(&self->mutex);
- // Call the events
+ /* Call the events */
px_array_foreach(self->on_get_proxies, call_on_proxy_factory_get_proxies, self);
- // If our config file is stale, close it
+ /* If our config file is stale, close it */
if (self->cf && px_config_file_is_stale(self->cf))
{
px_config_file_free(self->cf);
self->cf = NULL;
}
- // Try to open our config file if we don't have one
+ /* Try to open our config file if we don't have one */
if (!self->cf)
self->cf = px_config_file_new(SYSCONFDIR "/proxy.conf");
- // If we have a config file, load the order from it
+ /* If we have a config file, load the order from it */
if (self->cf)
tmp = px_config_file_get_value(self->cf, PX_CONFIG_FILE_DEFAULT_SECTION, "config_order");
- // Attempt to get info from the environment
+ /* Attempt to get info from the environment */
order = getenv("PX_CONFIG_ORDER");
- // Create the config order
+ /* Create the config order */
order = px_strcat(tmp ? tmp : "", ",", order ? order : "", ",", DEFAULT_CONFIG_ORDER, NULL);
px_free(tmp); tmp = NULL;
- // Create the config plugin order vector
+ /* Create the config plugin order vector */
orderv = px_strsplit(order, ",");
px_free(order);
- // Get the config by searching the config order
+ /* Get the config by searching the config order */
for (int i=0 ; orderv[i] && !config ; i++)
{
- // Get the category (if applicable)
+ /* Get the category (if applicable) */
pxConfigCategory category;
if (!strcmp(orderv[i], "USER"))
category = PX_CONFIG_CATEGORY_USER;
@@ -515,11 +523,11 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
}
px_strfreev(orderv);
- // No config was found via search order, call all plugins
+ /* No config was found via search order, call all plugins */
for (int i=0 ; self->configs && self->configs[i] && !config ; i++)
config = self->configs[i]->callback(self);
- // No plugin returned a valid config, fall back to 'wpad://'
+ /* No plugin returned a valid config, fall back to 'wpad://' */
if (!config)
{
fprintf(stderr, "*** Unable to locate valid config! Falling back to auto-detection...\n");
@@ -528,7 +536,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
config->ignore = px_strdup("");
}
- // If the config plugin returned an invalid config type or malformed URL, fall back to 'wpad://'
+ /* If the config plugin returned an invalid config type or malformed URL, fall back to 'wpad://' */
if (!(!strncmp(config->url, "http://", 7) ||
!strncmp(config->url, "socks://", 8) ||
!strncmp(config->url, "pac+", 4) ||
@@ -553,7 +561,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
config->url = px_strdup("wpad://");
}
- // Check our ignore patterns
+ /* Check our ignore patterns */
char **ignores = px_strsplit(config->ignore, ",");
for (int i=0 ; ignores[i] ; i++)
{
@@ -565,10 +573,10 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
}
px_strfreev(ignores);
- // If we have a wpad config
+ /* If we have a wpad config */
if (!strcmp(config->url, "wpad://"))
{
- // Get the WPAD object if needed
+ /* Get the WPAD object if needed */
if (!self->wpad)
{
if (self->pac) px_pac_free(self->pac);
@@ -581,45 +589,46 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
}
}
- // If we have no PAC, get one
- // If getting the PAC fails, but the WPAD cycle worked, restart the cycle
+ /*
+ * If we have no PAC, get one
+ * If getting the PAC fails, but the WPAD cycle worked, restart the cycle
+ */
if (!self->pac && !(self->pac = px_wpad_next(self->wpad)) && px_wpad_pac_found(self->wpad))
{
px_wpad_rewind(self->wpad);
self->pac = px_wpad_next(self->wpad);
}
- // If the WPAD cycle failed, fall back to direct
+ /* If the WPAD cycle failed, fall back to direct */
if (!self->pac)
{
fprintf(stderr, "*** Unable to locate PAC! Falling back to direct...\n");
goto do_return;
}
- // Run the PAC
+ /* Run the PAC */
if (self->pac_runner)
{
px_strfreev(response);
response = _format_pac_response(self->pac_runner(self, self->pac, realurl));
}
- // No PAC runner found, fall back to direct
+ /* No PAC runner found, fall back to direct */
else
fprintf(stderr, "*** PAC found, but no active PAC runner! Falling back to direct...\n");
}
- // If we have a PAC config
+ /* If we have a PAC config */
else if (!strncmp(config->url, "pac+", 4))
{
- // Clear WPAD to indicate that this is a non-WPAD PAC
+ /* Clear WPAD to indicate that this is a non-WPAD PAC */
if (self->wpad)
{
px_wpad_free(self->wpad);
self->wpad = NULL;
}
- // If a PAC alread exists, but comes from a different URL than the one
- // specified, remove it
+ /* If a PAC already exists, but came from a different URL than the one specified, remove it */
if (self->pac)
{
pxURL *urltmp = px_url_new(config->url + 4);
@@ -636,14 +645,14 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
px_url_free(urltmp);
}
- // Try to load the PAC if it is not already loaded
+ /* Try to load the PAC if it is not already loaded */
if (!self->pac && !(self->pac = px_pac_new_from_string(config->url + 4)))
{
fprintf(stderr, "*** Invalid PAC URL! Falling back to direct...\n");
goto do_return;
}
- // Run the PAC
+ /* Run the PAC */
if (self->pac_runner)
{
px_strfreev(response);
@@ -653,7 +662,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
fprintf(stderr, "*** PAC found, but no active PAC runner! Falling back to direct...\n");
}
- // If we have a manual config (http://..., socks://...)
+ /* If we have a manual config (http://..., socks://...) */
else if (!strncmp(config->url, "http://", 7) || !strncmp(config->url, "socks://", 8))
{
if (self->wpad) { px_wpad_free(self->wpad); self->wpad = NULL; }
@@ -662,7 +671,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, char *url)
response = px_strsplit(config->url, ";");
}
- // Actually return, freeing misc stuff
+ /* Actually return, freeing misc stuff */
do_return:
if (config) { px_free(config->url); px_free(config->ignore); px_free(config); }
if (realurl) px_url_free(realurl);
@@ -710,14 +719,14 @@ px_proxy_factory_free (pxProxyFactory *self)
pthread_mutex_lock(&self->mutex);
- // Free the plugins
+ /* Free the plugins */
px_array_foreach(self->plugins, destantiate_plugins, self);
px_array_free(self->plugins);
- // Free misc
+ /* Free misc */
px_strdict_free(self->misc);
- // Free everything else
+ /* Free everything else */
px_pac_free(self->pac);
px_wpad_free(self->wpad);
px_config_file_free(self->cf);
diff --git a/src/lib/proxy_factory.h b/src/lib/proxy_factory.h
index a613ebd..c73dad7 100644
--- a/src/lib/proxy_factory.h
+++ b/src/lib/proxy_factory.h
@@ -35,13 +35,15 @@ enum _pxConfigCategory {
};
typedef enum _pxConfigCategory pxConfigCategory;
-// URLs look like this:
-// http://host:port
-// socks://host:port
-// pac+http://pac_host:port/path/to/pac
-// wpad://
-// direct://
-// TODO: ignore syntax TBD
+/*
+ * URLs look like this:
+ * http://host:port
+ * socks://host:port
+ * pac+http://pac_host:port/path/to/pac
+ * wpad://
+ * direct://
+ */
+ /* TODO: ignore syntax TBD */
struct _pxConfig {
char *url;
char *ignore;
diff --git a/src/lib/strdict.c b/src/lib/strdict.c
index b24ce00..3157e65 100644
--- a/src/lib/strdict.c
+++ b/src/lib/strdict.c
@@ -78,7 +78,7 @@ px_strdict_set(pxStrDict *self, const char *key, void *value)
{
if (!self || !key) return false;
- // We are unseting the value
+ /* We are unseting the value */
if (!value)
{
void *item[3] = { (void *) key, value, self->free };
diff --git a/src/lib/url.c b/src/lib/url.c
index 3eb0e35..ba156e4 100644
--- a/src/lib/url.c
+++ b/src/lib/url.c
@@ -87,10 +87,10 @@ px_url_get(pxURL *self, const char **headers)
char *joined_headers = NULL;
int sock = -1;
- // DNS lookup of host
+ /* DNS lookup of host */
if (!px_url_get_ips(self)) goto error;
- // Iterate through each pxIP trying to make a connection
+ /* Iterate through each pxIP trying to make a connection */
for (int i = 0 ; self->ips && self->ips[i] && sock < 0 ; i++)
{
sock = socket(self->ips[i]->sa_family, SOCK_STREAM, 0);
@@ -108,7 +108,7 @@ px_url_get(pxURL *self, const char **headers)
}
if (sock < 0) goto error;
- // Merge optional headers
+ /* Merge optional headers */
if (headers)
{
joined_headers = px_strjoin(headers, "\r\n");
@@ -117,17 +117,17 @@ px_url_get(pxURL *self, const char **headers)
else
joined_headers = px_strdup("");
- // Create request header
+ /* Create request header */
request = px_strcat("GET ", px_url_get_path(self),
" HTTP/1.1\r\nHost: ", px_url_get_host(self),
"\r\n", joined_headers, "\r\n\r\n", NULL);
px_free(joined_headers);
- // Send HTTP request
+ /* Send HTTP request */
if (send(sock, request, strlen(request), 0) != strlen(request)) goto error;
px_free(request); request = NULL;
- // Return the socket, which is ready for reading the response
+ /* Return the socket, which is ready for reading the response */
return sock;
error:
@@ -166,12 +166,12 @@ px_url_get_ip_no_dns(pxURL *self)
{
if (!self) return NULL;
- // Check the cache
+ /* Check the cache */
if (self->ips && self->ips[0])
return (const struct sockaddr *) self->ips[0];
px_free(self->ips);
- // Try for IPv4 first
+ /* Try for IPv4 first */
struct sockaddr *ip = px_malloc0(sizeof(struct sockaddr_in));
if (inet_pton(AF_INET, px_url_get_host(self), &((struct sockaddr_in *) ip)->sin_addr) > 0)
{
@@ -182,7 +182,7 @@ px_url_get_ip_no_dns(pxURL *self)
}
px_free(ip);
- // Try for IPv6 next
+ /* Try for IPv6 next */
ip = px_malloc0(sizeof(struct sockaddr_in6));
if (inet_pton(AF_INET6, px_url_get_host(self), &((struct sockaddr_in6 *) ip)->sin6_addr) > 0)
{
@@ -193,7 +193,7 @@ px_url_get_ip_no_dns(pxURL *self)
}
px_free(ip);
- // The hostname was not an IP address
+ /* The hostname was not an IP address */
return NULL;
}
@@ -206,24 +206,24 @@ px_url_get_ips(pxURL *self)
{
if (!self) return NULL;
- // Check the cache
+ /* Check the cache */
if (self->ips) return (const struct sockaddr **) self->ips;
- // Check without DNS first
+ /* Check without DNS first */
if (px_url_get_ip_no_dns(self)) return (const struct sockaddr **) self->ips;
- // Check DNS for IPs
+ /* Check DNS for IPs */
struct addrinfo *info;
if (!getaddrinfo(px_url_get_host(self), NULL, NULL, &info))
{
struct addrinfo *first = info;
int count;
- // Count how many IPs we got back
+ /* Count how many IPs we got back */
for (count=0 ; info ; info = info->ai_next)
count++;
- // Copy the sockaddr's into self->ips
+ /* Copy the sockaddr's into self->ips */
info = first;
self->ips = px_malloc0(sizeof(struct sockaddr *) * ++count);
for (int i=0 ; info ; info = info->ai_next)
@@ -246,7 +246,7 @@ px_url_get_ips(pxURL *self)
return (const struct sockaddr **) self->ips;
}
- // No addresses found
+ /* No addresses found */
return NULL;
}
@@ -287,24 +287,24 @@ px_url_get_scheme(pxURL *self)
pxURL *
px_url_new(const char *url)
{
- // Allocate pxURL
+ /* Allocate pxURL */
pxURL *self = px_malloc0(sizeof(pxURL));
- // Get scheme
+ /* Get scheme */
if (!strstr(url, "://")) goto error;
self->scheme = px_strndup(url, strstr(url, "://") - url);
- // Get host
+ /* Get host */
self->host = px_strdup(strstr(url, "://") + strlen("://"));
- // Get path
+ /* Get path */
self->path = px_strdup(strchr(self->host, '/'));
if (self->path)
self->host[strlen(self->host) - strlen(self->path)] = 0;
else
self->path = px_strdup("");
- // Get the port
+ /* Get the port */
bool port_specified = false;
if (strchr(self->host, ':')) {
if (!atoi(strchr(self->host, ':')+1)) goto error;
@@ -315,10 +315,10 @@ px_url_new(const char *url)
else
self->port = px_url_get_default_port(self);
- // Make sure we have a real host
+ /* Make sure we have a real host */
if (!strcmp(self->host, "")) goto error;
- // Verify by re-assembly
+ /* Verify by re-assembly */
self->url = px_malloc0(strlen(url) + 1);
if (!port_specified)
snprintf(self->url, strlen(url) + 1, "%s://%s%s", self->scheme, self->host, self->path);
diff --git a/src/lib/url.h b/src/lib/url.h
index 3e1b667..bf2fd68 100644
--- a/src/lib/url.h
+++ b/src/lib/url.h
@@ -20,7 +20,7 @@
#ifndef URL_H_
#define URL_H_
-#include "stdbool.h" // For type bool
+#include "stdbool.h" /* For type bool */
/**
* WPAD object. All fields are private.
diff --git a/src/lib/wpad.c b/src/lib/wpad.c
index 1d82dd6..7c18ef4 100644
--- a/src/lib/wpad.c
+++ b/src/lib/wpad.c
@@ -71,7 +71,7 @@ px_wpad_next(pxWPAD *self)
{
if (!self) return NULL;
- // Check all the detectors for a PAC
+ /* Check all the detectors for a PAC */
pxPAC *pac = NULL;
if (!(pac = px_dhcp_next(self->dhcp)))
if (!(pac = px_slp_next(self->slp)))
diff --git a/src/lib/wpad_dns.c b/src/lib/wpad_dns.c
index 960b5ec..8bf4576 100644
--- a/src/lib/wpad_dns.c
+++ b/src/lib/wpad_dns.c
@@ -34,13 +34,13 @@ struct _pxDNS {
char *domain;
};
-// The top-level domain blacklist
+/* The top-level domain blacklist */
static char *tld[] = {
- // General top-level domains
+ /* General top-level domains */
"arpa", "root", "aero", "biz", "cat", "com", "coop", "edu", "gov", "info",
"int", "jobs", "mil", "mobi", "museum", "name", "net", "org", "pro", "travel",
- // Country codes
+ /* Country codes */
"ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar",
"as", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be", "bf", "bg",
"bh", "bi", "bj", "bm", "bn", "bo", "br", "bs", "bt", "bv", "bw", "by",
@@ -63,23 +63,23 @@ static char *tld[] = {
"uy", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "ye",
"yt", "yu", "za", "zm", "zw",
- // Other domains to blacklist
+ /* Other domains to blacklist */
"co.uk", "com.au",
- // Terminator
+ /* Terminator */
NULL
};
static char *
get_domain_name()
{
- // Get the hostname
+ /* Get the hostname */
char *hostname = px_malloc0(128);
for (int i = 0 ; gethostname(hostname, (i + 1) * 128) && errno == ENAMETOOLONG ; )
hostname = px_malloc0((++i + 1) * 128);
- // Lookup the hostname
- // TODO: Make this whole process not suck
+ /* Lookup the hostname */
+ /* TODO: Make this whole process not suck */
struct hostent *host_info = gethostbyname(hostname);
if (host_info)
{
@@ -87,7 +87,7 @@ get_domain_name()
hostname = px_strdup(host_info->h_name);
}
- // Get domain portion
+ /* Get domain portion */
if (!strchr(hostname, '.')) return NULL;
if (!strcmp(".", strchr(hostname, '.'))) return NULL;
char *tmp = px_strdup(strchr(hostname, '.') + 1);
@@ -107,29 +107,29 @@ get_urls(const char *domain)
return urls;
}
- // Split up the domain
+ /* Split up the domain */
char **domainv = px_strsplit(domain, ".");
if (!domainv) return NULL;
- // Count the number of domain blocks
+ /* Count the number of domain blocks */
int count = 0;
for (int i=0 ; *(domainv + i) ; i++)
count++;
- // Allocate our URL array
+ /* Allocate our URL array */
urls = px_malloc0(sizeof(pxURL *) * (count + 2));
- // Create the URLs
+ /* Create the URLs */
urls[0] = px_url_new("http://wpad/wpad.dat");
char *url = px_malloc0(strlen("http://wpad./wpad.dat") + strlen(domain) + 1);
for (int i=0, j=1 ; domainv[i] ; i++) {
- // Check the domain against the blacklist
+ /* Check the domain against the blacklist */
char *tmp = px_strjoin((const char **) (domainv + i), ".");
for (int k=0; tld[k] ; k++)
if (!strcmp(tmp, tld[k])) { px_free(tmp); tmp = NULL; break; }
if (!tmp) continue;
- // Create the URL
+ /* Create the URL */
sprintf(url, "http://wpad.%s/wpad.dat", tmp);
px_free(tmp); tmp = NULL;
urls[j] = px_url_new(url);
@@ -176,25 +176,25 @@ px_dns_next(pxDNS *self)
if (!self->urls) {
char *domain;
- // Reset the counter
+ /* Reset the counter */
self->next = 0;
- // Get the domain name
+ /* Get the domain name */
if (self->domain)
domain = px_strdup(self->domain);
else
domain = get_domain_name();
- // Get the URLs
+ /* Get the URLs */
self->urls = get_urls(domain);
px_free(domain);
- // Make sure we have more than one URL
+ /* Make sure we have more than one URL */
if (!self->urls || !self->urls[0])
return NULL;
}
- // Try to find a PAC at each URL
+ /* Try to find a PAC at each URL */
for (pxPAC *pac = NULL ; self->urls[self->next] ; )
if ((pac = px_pac_new(self->urls[self->next++])))
return pac;