- fix error messages
[oweals/gnunet.git] / src / transport / transport_api_address_to_string.c
index 2e5a34ce22e6f79da5a3cb097080f228747ed9eb..0cf0111b3bd44bca0877fdb71f32b03da4d7748b 100644 (file)
      Boston, MA 02111-1307, USA.
 */
 #include "platform.h"
-#include "gnunet_client_lib.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_arm_service.h"
 #include "gnunet_hello_lib.h"
 #include "gnunet_protocols.h"
-#include "gnunet_server_lib.h"
-#include "gnunet_time_lib.h"
 #include "gnunet_transport_service.h"
 #include "transport.h"
 
@@ -71,18 +69,18 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
   if (msg == NULL)
   {
     alucb->cb (alucb->cb_cls, NULL);
-    GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (alucb->client);
     GNUNET_free (alucb);
     return;
   }
   GNUNET_break (ntohs (msg->type) ==
-      GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
   size = ntohs (msg->size);
   if (size == sizeof (struct GNUNET_MessageHeader))
   {
     /* done! */
     alucb->cb (alucb->cb_cls, NULL);
-    GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (alucb->client);
     GNUNET_free (alucb);
     return;
   }
@@ -92,7 +90,7 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
     /* invalid reply */
     GNUNET_break (0);
     alucb->cb (alucb->cb_cls, NULL);
-    GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (alucb->client);
     GNUNET_free (alucb);
     return;
   }
@@ -116,43 +114,45 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
  * @return handle to cancel the operation, NULL on error
  */
 struct GNUNET_TRANSPORT_AddressToStringContext *
-GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                 const struct GNUNET_HELLO_Address *address,
-                                 int numeric,
-                                 struct GNUNET_TIME_Relative timeout,
-                                 GNUNET_TRANSPORT_AddressToStringCallback aluc,
-                                 void *aluc_cls)
+GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
+                                    *cfg,
+                                    const struct GNUNET_HELLO_Address *address,
+                                    int numeric,
+                                    struct GNUNET_TIME_Relative timeout,
+                                    GNUNET_TRANSPORT_AddressToStringCallback
+                                    aluc, void *aluc_cls)
 {
   size_t len;
   size_t alen;
+  size_t slen;
   struct AddressLookupMessage *msg;
   struct GNUNET_TRANSPORT_AddressToStringContext *alc;
   struct GNUNET_CLIENT_Connection *client;
   char *addrbuf;
 
   GNUNET_assert (address != NULL);
-  alen = GNUNET_HELLO_address_get_size (address);
-  len = sizeof (struct AddressLookupMessage) + alen;
+  alen = address->address_length;
+  slen = strlen (address->transport_name) + 1;
+  len = sizeof (struct AddressLookupMessage) + alen + slen;
   if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
     return NULL;
   }
-
   client = GNUNET_CLIENT_connect ("transport", cfg);
-  if (client == NULL)
+  if (NULL == client)
     return NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "GNUNET_TRANSPORT_address_to_string\n");
   msg = GNUNET_malloc (len);
   msg->header.size = htons (len);
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
-  msg->numeric_only = htonl (numeric);
+  msg->numeric_only = htons ((int16_t) numeric);
+  msg->addrlen = htons ((uint16_t) alen);
   msg->timeout = GNUNET_TIME_relative_hton (timeout);
-  msg->addrlen = htonl (alen);
   addrbuf = (char *) &msg[1];
-  memcpy (addrbuf, address, alen);
-  alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext));
+  memcpy (addrbuf, address->address, alen);
+  memcpy (&addrbuf[alen], address->transport_name, slen);
+
+  alc = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext);
   alc->cb = aluc;
   alc->cb_cls = aluc_cls;
   alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -170,17 +170,17 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
 /**
  * Cancel request for address conversion.
  *
- * @param alc handle for the request to cancel
+ * @param pic the context handle
  */
 void
 GNUNET_TRANSPORT_address_to_string_cancel (struct
-                                        GNUNET_TRANSPORT_AddressToStringContext
-                                        *alc)
+                                           GNUNET_TRANSPORT_AddressToStringContext
+                                           *pic)
 {
-  GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
-  GNUNET_free (alc);
+  GNUNET_CLIENT_disconnect (pic->client);
+  GNUNET_free (pic);
 }
 
 
 
-/* end of transport_api_address_lookup.c */
+/* end of transport_api_address_to_string.c */