-remove trailing whitespace
[oweals/gnunet.git] / src / gns / gns_api.c
index de5c6062adda9676093e015f683a2bed0d4a3518..75c2f95301cecb05366b23f521f18d5b3e295216 100644 (file)
@@ -34,6 +34,8 @@
 #include "gnunet_gns_service.h"
 
 
+#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
+
 /**
  * Handle to a lookup request
  */
@@ -44,32 +46,32 @@ struct GNUNET_GNS_LookupRequest
    * DLL
    */
   struct GNUNET_GNS_LookupRequest *next;
-  
+
   /**
    * DLL
    */
   struct GNUNET_GNS_LookupRequest *prev;
-  
+
   /**
-   * handle to gns 
+   * handle to gns
    */
   struct GNUNET_GNS_Handle *gns_handle;
-  
+
   /**
-   * processor to call on lookup result 
+   * processor to call on lookup result
    */
   GNUNET_GNS_LookupResultProcessor lookup_proc;
 
   /**
-   * processor closure 
+   * processor closure
    */
   void *proc_cls;
+
   /**
-   * request id 
+   * request id
    */
   uint32_t r_id;
+
 };
 
 
@@ -128,7 +130,7 @@ struct GNUNET_GNS_Handle
    * Currently pending transmission request (or NULL).
    */
   struct GNUNET_CLIENT_TransmitHandle *th;
-  
+
   /**
    * Head of linked list of shorten messages we would like to transmit.
    */
@@ -138,7 +140,7 @@ struct GNUNET_GNS_Handle
    * Tail of linked list of shorten messages we would like to transmit.
    */
   struct PendingMessage *pending_tail;
-  
+
   /**
    * Head of linked list of lookup messages we would like to transmit.
    */
@@ -153,7 +155,7 @@ struct GNUNET_GNS_Handle
    * Reconnect task
    */
   GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
-  
+
   /**
    * How long do we wait until we try to reconnect?
    */
@@ -163,7 +165,7 @@ struct GNUNET_GNS_Handle
    * Request Id generator.  Incremented by one for each request.
    */
   uint32_t r_id_gen;
-  
+
   /**
    * Did we start our receive loop yet?
    */
@@ -189,8 +191,8 @@ static void
 reconnect (struct GNUNET_GNS_Handle *handle)
 {
   GNUNET_assert (NULL == handle->client);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Trying to connect to GNS\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Trying to connect to GNS\n");
   handle->client = GNUNET_CLIENT_connect ("gns", handle->cfg);
   GNUNET_assert (NULL != handle->client);
   process_pending_messages (handle);
@@ -235,7 +237,7 @@ force_reconnect (struct GNUNET_GNS_Handle *handle)
     p->transmitted = GNUNET_NO;
     GNUNET_CONTAINER_DLL_insert (handle->pending_head,
                                 handle->pending_tail,
-                                p);  
+                                p);
   }
   handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
   handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
@@ -277,18 +279,18 @@ process_pending_messages (struct GNUNET_GNS_Handle *handle)
   struct PendingMessage *p = handle->pending_head;
 
   if (NULL == handle->client)
-    return; /* wait for reconnect */ 
+    return; /* wait for reconnect */
   if (NULL != handle->th)
-    return; /* transmission request already pending */ 
+    return; /* transmission request already pending */
 
   while ((NULL != p) && (p->transmitted == GNUNET_YES))
     p = p->next;
   if (NULL == p)
     return; /* no messages pending */
-  
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Trying to transmit %u bytes\n", 
-             (unsigned int) p->size);
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Trying to transmit %u bytes\n",
+       (unsigned int) p->size);
   handle->th =
     GNUNET_CLIENT_notify_transmit_ready (handle->client,
                                          p->size,
@@ -318,11 +320,11 @@ transmit_pending (void *cls, size_t size, void *buf)
   handle->th = NULL;
   if ((0 == size) || (NULL == buf))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Transmission to GNS service failed!\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Transmission to GNS service failed!\n");
     force_reconnect (handle);
     return 0;
-  }  
+  }
   if (NULL == (p = handle->pending_head))
     return 0;
 
@@ -343,9 +345,9 @@ transmit_pending (void *cls, size_t size, void *buf)
       handle->in_receive = GNUNET_YES;
     }
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending %u bytes\n",
-             (unsigned int) tsize);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Sending %u bytes\n",
+       (unsigned int) tsize);
   process_pending_messages (handle);
   return tsize;
 }
@@ -381,15 +383,15 @@ process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe,
                                                              rd_count,
                                                              rd))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Failed to serialize lookup reply from GNS service!\n"));
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        _("Failed to serialize lookup reply from GNS service!\n"));
     qe->lookup_proc (qe->proc_cls, 0, NULL);
   }
   else
-  { 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Received lookup reply from GNS service (%u records)\n",
-                (unsigned int) rd_count);
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Received lookup reply from GNS service (%u records)\n",
+        (unsigned int) rd_count);
     qe->lookup_proc (qe->proc_cls, rd_count, rd);
   }
   GNUNET_CONTAINER_DLL_remove (handle->lookup_head, handle->lookup_tail, qe);
@@ -410,7 +412,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
   struct GNUNET_GNS_LookupRequest *lr;
   const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
   uint32_t r_id;
-  
+
   if (NULL == msg)
   {
     force_reconnect (handle);
@@ -419,8 +421,8 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
   switch (ntohs (msg->type))
   {
   case GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Got LOOKUP_RESULT msg\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Got LOOKUP_RESULT msg\n");
     if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
     {
       GNUNET_break (0);
@@ -428,11 +430,11 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
       return;
     }
     lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
-    r_id = ntohl (lookup_msg->id);   
-    for (lr = handle->lookup_head; NULL != lr; lr = lr->next)    
+    r_id = ntohl (lookup_msg->id);
+    for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
       if (lr->r_id == r_id)
       {
-       process_lookup_reply(lr, lookup_msg);    
+       process_lookup_reply(lr, lookup_msg);
        break;
       }
     break;
@@ -472,7 +474,11 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 void
 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
 {
-  GNUNET_CLIENT_disconnect (handle->client);
+  if (NULL != handle->client)
+  {
+    GNUNET_CLIENT_disconnect (handle->client);
+    handle->client = NULL;
+  }
   if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
   {
     GNUNET_SCHEDULER_cancel (handle->reconnect_task);
@@ -493,7 +499,7 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr)
 {
   struct PendingMessage *p = (struct PendingMessage*) &lr[1];
 
-  GNUNET_assert (NULL != lr->gns_handle); 
+  GNUNET_assert (NULL != lr->gns_handle);
   if (GNUNET_NO == p->transmitted)
     GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head,
                                  lr->gns_handle->pending_tail,
@@ -538,10 +544,10 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
   {
     GNUNET_break (0);
     return NULL;
-  } 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Trying to lookup `%s' in GNS\n", 
-             name);
+  }
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Trying to lookup `%s' in GNS\n",
+       name);
   msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
     + strlen (name) + 1;
   if (msize > UINT16_MAX)
@@ -570,7 +576,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
   lookup_msg->type = htonl (type);
   if (NULL != shorten_zone_key)
   {
-    lookup_msg->have_key = htonl (GNUNET_YES);
+    lookup_msg->have_key = htons (GNUNET_YES);
     lookup_msg->shorten_key = *shorten_zone_key;
   }
   memcpy (&lookup_msg[1], name, strlen (name) + 1);