Placate a trivial compiler warning.
[u/mdw/putty] / proxy.c
diff --git a/proxy.c b/proxy.c
index 9e3684c..83bb19f 100644 (file)
--- a/proxy.c
+++ b/proxy.c
@@ -5,9 +5,9 @@
  * code and the higher level backend.
  */
 
-#include <windows.h>
-
 #include <assert.h>
+#include <ctype.h>
+#include <string.h>
 
 #define DEFINE_PLUG_METHOD_MACROS
 #include "putty.h"
@@ -153,7 +153,7 @@ static void sk_proxy_set_frozen (Socket s, int is_frozen)
         * so we have to check each time.
         */
         while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) {
-           char * data;
+           void *data;
            int len;
            bufchain_prefix(&ps->pending_input_data, &data, &len);
            plug_receive(ps->plug, 0, data, len);
@@ -312,7 +312,7 @@ Socket new_connection(SockAddr addr, char *hostname,
                      int port, int privport,
                      int oobinline, int nodelay, Plug plug)
 {
-    static struct socket_function_table socket_fn_table = {
+    static const struct socket_function_table socket_fn_table = {
        sk_proxy_plug,
        sk_proxy_close,
        sk_proxy_write,
@@ -324,7 +324,7 @@ Socket new_connection(SockAddr addr, char *hostname,
        sk_proxy_socket_error
     };
 
-    static struct plug_function_table plug_fn_table = {
+    static const struct plug_function_table plug_fn_table = {
        plug_proxy_closing,
        plug_proxy_receive,
        plug_proxy_sent,
@@ -404,13 +404,13 @@ Socket new_connection(SockAddr addr, char *hostname,
     return sk_new(addr, port, privport, oobinline, nodelay, plug);
 }
 
-Socket new_listener(int port, Plug plug, int local_host_only)
+Socket new_listener(char *srcaddr, int port, Plug plug, int local_host_only)
 {
     /* TODO: SOCKS (and potentially others) support inbound
      * TODO: connections via the proxy. support them.
      */
 
-    return sk_newlistener(port, plug, local_host_only);
+    return sk_newlistener(srcaddr, port, plug, local_host_only);
 }
 
 /* ----------------------------------------------------------------------
@@ -459,13 +459,14 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
         * for this proxy method, it's just a simple HTTP
         * request
         */
-       char buf[256], dest[64];
+       char *buf, dest[64];
 
        sk_getaddr(p->remote_addr, dest, 64);
 
-       sprintf(buf, "CONNECT %s:%i HTTP/1.1\r\nHost: %s:%i\r\n",
-               dest, p->remote_port, dest, p->remote_port);
+       buf = dupprintf("CONNECT %s:%i HTTP/1.1\r\nHost: %s:%i\r\n",
+                       dest, p->remote_port, dest, p->remote_port);
        sk_write(p->sub_socket, buf, strlen(buf));
+       sfree(buf);
 
        if (cfg.proxy_username[0] || cfg.proxy_password[0]) {
            char buf[sizeof(cfg.proxy_username)+sizeof(cfg.proxy_password)];
@@ -480,8 +481,7 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
            sk_write(p->sub_socket, buf2, strlen(buf2));
        }
 
-       sprintf(buf, "\r\n");
-       sk_write(p->sub_socket, buf, strlen(buf));
+       sk_write(p->sub_socket, "\r\n", 2);
 
        p->state = 1;
        return 0;
@@ -556,14 +556,14 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
            bufchain_consume(&p->pending_input_data, eol);
            if (data[status] != '2') {
                /* error */
-               char buf[1024];
+               char *buf;
                data[eol] = '\0';
                while (eol > status &&
                       (data[eol-1] == '\r' || data[eol-1] == '\n'))
                    data[--eol] = '\0';
-               sprintf(buf, "Proxy error: %.900s",
-                       data+status);
+               buf = dupprintf("Proxy error: %s", data+status);
                plug_closing(p->plug, buf, PROXY_ERROR_GENERAL, 0);
+               sfree(buf);
                sfree(data);
                return 1;
            }
@@ -594,6 +594,7 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
            {
                bufchain_consume(&p->pending_input_data, eol);
                datap += eol;
+               len   -= eol;
                eol = get_line_end(datap, len);
            }
 
@@ -639,14 +640,14 @@ int proxy_socks4_negotiate (Proxy_Socket p, int change)
        int length;
        char * command;
 
-       if (sk_addrtype(p->remote_addr) != AF_INET) {
+       if (sk_addrtype(p->remote_addr) != ADDRTYPE_IPV4) {
            plug_closing(p->plug, "Proxy error: SOCKS version 4 does"
                         " not support IPv6", PROXY_ERROR_GENERAL, 0);
            return 1;
        }
 
        length = strlen(cfg.proxy_username) + 9;
-       command = (char*) malloc(length);
+       command = (char*) smalloc(length);
        strcpy(command + 8, cfg.proxy_username);
 
        command[0] = 4; /* version 4 */
@@ -660,7 +661,7 @@ int proxy_socks4_negotiate (Proxy_Socket p, int change)
        sk_addrcopy(p->remote_addr, command + 4);
 
        sk_write(p->sub_socket, command, length);
-       free(command);
+       sfree(command);
 
        p->state = 1;
        return 0;
@@ -929,7 +930,7 @@ int proxy_socks5_negotiate (Proxy_Socket p, int change)
            char command[22];
            int len;
 
-           if (sk_addrtype(p->remote_addr) == AF_INET) {
+           if (sk_addrtype(p->remote_addr) == ADDRTYPE_IPV4) {
                len = 10;
                command[3] = 1; /* IPv4 */
            } else {