getting service_new.c to compile, albeit it is not yet complete
[oweals/gnunet.git] / src / util / socks.c
index cc59858dd3b2d023887f3277eaba628a86d966cf..30a430fbe8f9dd544a6ca22666901fff539abef1 100644 (file)
@@ -296,7 +296,7 @@ reciever (void *cls,
 {
   struct GNUNET_SOCKS_Handshake * ih = cls;
   GNUNET_assert (&ih->inend[available] < &ih->inbuf[1024]);
-  memcpy(ih->inend, buf, available);
+  GNUNET_memcpy(ih->inend, buf, available);
   ih->inend += available;
   SOCKS5_handshake_step (ih);
 }
@@ -328,7 +328,6 @@ register_reciever (struct GNUNET_SOCKS_Handshake *ih, int want)
  * @param buf where the callee should write the message
  * @return number of bytes written to @a buf
  */
-
 size_t
 transmit_ready (void *cls,
                 size_t size,
@@ -353,29 +352,19 @@ transmit_ready (void *cls,
    * successful operations, including DNS resolution, do not use this.  */
   if (NULL == buf)
   {
-    const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-    tc = GNUNET_SCHEDULER_get_task_context ();
-    if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-      return 0;
-    if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) {
-      if (0==ih->step)
-      {
-        LOG (GNUNET_ERROR_TYPE_WARNING,
-             "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
-        register_sender (ih);
-      }
-      else
-      {
-        LOG (GNUNET_ERROR_TYPE_ERROR,
-             "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
-             ih->step);
-        GNUNET_break (0);
-      }
-      return 0;
+    if (0 == ih->step)
+    {
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+          "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
+      register_sender (ih);
+    }
+    else
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+          "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
+          ih->step);
+      GNUNET_break (0);
     }
-    /* if (reason == 48) register_sender (ih); */
-    /* GNUNET_break(0); */
     return 0;
   }
 
@@ -386,7 +375,7 @@ transmit_ready (void *cls,
   GNUNET_assert (e <= &ih->outbuf[1024]);
   unsigned l = e - b;
   GNUNET_assert (size >= l && l >= 0);
-  memcpy(buf, b, l);
+  GNUNET_memcpy(buf, b, l);
   register_reciever (ih, register_reciever_wants(ih));
   return l;
 }
@@ -508,11 +497,11 @@ GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih,
   /* Specify destination */
   if (1 == inet_pton(AF_INET,host,&ia.in4)) {
     *(b++)= 1;  /* IPv4 */
-    memcpy (b, &ia.in4, sizeof(struct in_addr));
+    GNUNET_memcpy (b, &ia.in4, sizeof(struct in_addr));
     b += sizeof(struct in_addr);  /* 4 */
   } else if (1 == inet_pton(AF_INET6,host,&ia.in6)) {
     *(b++)= 4;  /* IPv6 */
-    memcpy (b, &ia.in6, sizeof(struct in6_addr));
+    GNUNET_memcpy (b, &ia.in6, sizeof(struct in6_addr));
     b += sizeof(struct in6_addr);  /* 16 */
   } else {
     *(b++)= 3;  /* hostname */
@@ -586,10 +575,7 @@ GNUNET_SOCKS_do_connect (const char *service_name,
       GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "SOCKSPORT", &port0))
     port0 = 9050;
   /* A typical Tor client should usually try port 9150 for the TBB too, but
-   * GUNNet can probably assume a system Tor instalation. */
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSHOST", &host0))
-    host0 = "127.0.0.1";
+   * GUNNet can probably assume a system Tor installation. */
   if (port0 > 65535 || port0 <= 0)
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -598,7 +584,6 @@ GNUNET_SOCKS_do_connect (const char *service_name,
         port0,service_name);
     return NULL;
   }
-
   if ((GNUNET_OK !=
        GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port1))
       || (port1 > 65535) || (port1 <= 0) ||
@@ -611,13 +596,17 @@ GNUNET_SOCKS_do_connect (const char *service_name,
         service_name,port1,host1);
     return NULL;
   }
-
-  socks5 = GNUNET_CONNECTION_create_from_connect (cfg, host0, port0);
-  GNUNET_free (host0);
+  /* Appeared to still work after host0 corrupted, so either test case is broken, or 
+     this whole routine is not being called. */
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSHOST", &host0))
+    host0 = NULL; 
+  socks5 = GNUNET_CONNECTION_create_from_connect (cfg, (host0 != NULL)? host0:"127.0.0.1", port0);
+  GNUNET_free_non_null (host0);
 
   /* Sets to NULL if they do not exist */
-  GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSUSER", &user);
-  GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSPASS", &pass);
+  (void)GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSUSER", &user);
+  (void)GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSPASS", &pass);
   ih = GNUNET_SOCKS_init_handshake(user,pass);
   if (NULL != user) GNUNET_free (user);
   if (NULL != pass) GNUNET_free (pass);