diff options
author | Mukund Sivaraman <muks@banu.com> | 2009-09-15 01:11:25 +0530 |
---|---|---|
committer | Mukund Sivaraman <muks@banu.com> | 2009-09-15 01:11:25 +0530 |
commit | 7b9234f394b688991a5b601ff1e487a19de29870 (patch) | |
tree | ccdb923e457666c174311bdf0f2ca4370e27e70c /src/transparent-proxy.c | |
parent | 2cb677759236fe54c24c1ce099a61f54bace3f73 (diff) |
Indent code to Tinyproxy coding style
The modified files were indented with GNU indent using the
following command:
indent -npro -kr -i8 -ts8 -sob -l80 -ss -cs -cp1 -bs -nlps -nprs -pcs \
-saf -sai -saw -sc -cdw -ce -nut -il0
No other changes of any sort were made.
Diffstat (limited to 'src/transparent-proxy.c')
-rw-r--r-- | src/transparent-proxy.c | 129 |
1 files changed, 62 insertions, 67 deletions
diff --git a/src/transparent-proxy.c b/src/transparent-proxy.c index 7318697..81c35ef 100644 --- a/src/transparent-proxy.c +++ b/src/transparent-proxy.c @@ -35,87 +35,82 @@ /* * Build a URL from parts. */ -static int -build_url (char **url, const char *host, int port, const char *path) +static int build_url (char **url, const char *host, int port, const char *path) { - int len; + int len; - assert (url != NULL); - assert (host != NULL); - assert (port > 0 && port < 32768); - assert (path != NULL); + assert (url != NULL); + assert (host != NULL); + assert (port > 0 && port < 32768); + assert (path != NULL); - len = strlen (host) + strlen (path) + 14; - *url = safemalloc (len); - if (*url == NULL) - return -1; + len = strlen (host) + strlen (path) + 14; + *url = safemalloc (len); + if (*url == NULL) + return -1; - return snprintf (*url, len, "http://%s:%d%s", host, port, path); + return snprintf (*url, len, "http://%s:%d%s", host, port, path); } - int do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders, struct request_s *request, struct config_s *conf, char *url) { - socklen_t length; - char *data; + socklen_t length; + char *data; - length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data); - if (length <= 0) - { - struct sockaddr_in dest_addr; + length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data); + if (length <= 0) { + struct sockaddr_in dest_addr; - if (getsockname - (connptr->client_fd, (struct sockaddr *) &dest_addr, &length) < 0) - { - log_message (LOG_ERR, - "process_request: cannot get destination IP for %d", - connptr->client_fd); - indicate_http_error (connptr, 400, "Bad Request", - "detail", - "Unknown destination", "url", url, NULL); - return 0; + if (getsockname + (connptr->client_fd, (struct sockaddr *) &dest_addr, + &length) < 0) { + log_message (LOG_ERR, + "process_request: cannot get destination IP for %d", + connptr->client_fd); + indicate_http_error (connptr, 400, "Bad Request", + "detail", "Unknown destination", + "url", url, NULL); + return 0; + } + request->host = safemalloc (17); + strcpy (request->host, inet_ntoa (dest_addr.sin_addr)); + request->port = ntohs (dest_addr.sin_port); + request->path = safemalloc (strlen (url) + 1); + strcpy (request->path, url); + safefree (url); + build_url (&url, request->host, request->port, request->path); + log_message (LOG_INFO, + "process_request: trans IP %s %s for %d", + request->method, url, connptr->client_fd); + } else { + request->host = safemalloc (length + 1); + if (sscanf (data, "%[^:]:%hu", request->host, &request->port) != + 2) { + strcpy (request->host, data); + request->port = HTTP_PORT; + } + request->path = safemalloc (strlen (url) + 1); + strcpy (request->path, url); + safefree (url); + build_url (&url, request->host, request->port, request->path); + log_message (LOG_INFO, + "process_request: trans Host %s %s for %d", + request->method, url, connptr->client_fd); } - request->host = safemalloc (17); - strcpy (request->host, inet_ntoa (dest_addr.sin_addr)); - request->port = ntohs (dest_addr.sin_port); - request->path = safemalloc (strlen (url) + 1); - strcpy (request->path, url); - safefree (url); - build_url (&url, request->host, request->port, request->path); - log_message (LOG_INFO, - "process_request: trans IP %s %s for %d", - request->method, url, connptr->client_fd); - } - else - { - request->host = safemalloc (length + 1); - if (sscanf (data, "%[^:]:%hu", request->host, &request->port) != 2) - { - strcpy (request->host, data); - request->port = HTTP_PORT; + if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) { + log_message (LOG_ERR, + "process_request: destination IP is localhost %d", + connptr->client_fd); + indicate_http_error (connptr, 400, "Bad Request", + "detail", + "You tried to connect to the machine " + "the proxy is running on", "url", url, + NULL); + return 0; } - request->path = safemalloc (strlen (url) + 1); - strcpy (request->path, url); - safefree (url); - build_url (&url, request->host, request->port, request->path); - log_message (LOG_INFO, - "process_request: trans Host %s %s for %d", - request->method, url, connptr->client_fd); - } - if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) - { - log_message (LOG_ERR, - "process_request: destination IP is localhost %d", - connptr->client_fd); - indicate_http_error (connptr, 400, "Bad Request", - "detail", - "You tried to connect to the machine " - "the proxy is running on", "url", url, NULL); - return 0; - } - return 1; + return 1; } |