gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20171 - in gnunet: doc/man src/arm src/include


From: gnunet
Subject: [GNUnet-SVN] r20171 - in gnunet: doc/man src/arm src/include
Date: Thu, 1 Mar 2012 14:59:23 +0100

Author: grothoff
Date: 2012-03-01 14:59:23 +0100 (Thu, 01 Mar 2012)
New Revision: 20171

Modified:
   gnunet/doc/man/gnunet-arm.1
   gnunet/src/arm/arm_api.c
   gnunet/src/arm/gnunet-arm.c
   gnunet/src/include/gnunet_arm_service.h
Log:
-minor fixes to arm service list API (#2141)

Modified: gnunet/doc/man/gnunet-arm.1
===================================================================
--- gnunet/doc/man/gnunet-arm.1 2012-03-01 12:55:50 UTC (rev 20170)
+++ gnunet/doc/man/gnunet-arm.1 2012-03-01 13:59:23 UTC (rev 20171)
@@ -34,6 +34,9 @@
 .IP "\-s, \-\-start"
 Start all GNUnet default services on this system (and also ARM).  Naturally, 
if a service is demanded by a default service, it will then also be started.  
Running "gnunet-arm -s" is the usual way to start a GNUnet peer.
 .B
+.IP "\-I, \-\-info"
+List all running services.
+.B
 .IP "\-v, \-\-version"
 Print GNUnet version number.
 

Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c    2012-03-01 12:55:50 UTC (rev 20170)
+++ gnunet/src/arm/arm_api.c    2012-03-01 13:59:23 UTC (rev 20171)
@@ -486,96 +486,8 @@
   GNUNET_free (sc);
 }
 
-/**
- * Internal state for a list request with ARM.
- */
-struct ListRequestContext
-{
 
-  /**
-   * Pointer to our handle with ARM.
-   */
-  struct GNUNET_ARM_Handle *h;
-
-  /**
-   * Function to call with a status code for the requested operation.
-   */
-  GNUNET_ARM_List_Callback callback;
-
-  /**
-   * Closure for "callback".
-   */
-  void *cls;
-
-  /**
-   * Timeout for the operation.
-   */
-  struct GNUNET_TIME_Absolute timeout;
-};
-
 /**
- * Process a response from ARM for the list request.
- *
- * @param cls the list request context
- * @param msg the response
- */
-static void
-handle_list_response (void *cls, const struct GNUNET_MessageHeader *msg)
-{
-  struct ListRequestContext *sc = cls;
-  const struct GNUNET_ARM_ListResultMessage *res;
-  int success;
-  
-   if (msg == NULL)
-   {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-           "Error receiving response to LIST request from ARM\n");
-      GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
-      sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
-      GNUNET_assert (NULL != sc->h->client);
-      if (sc->callback != NULL)
-        sc->callback (sc->cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR, 0, 
NULL);
-      GNUNET_free (sc);
-      return;
-   }
-   
-   if (sc->callback != NULL) 
-   {
-     char **list;
-     const char *pos;
-     uint16_t size_check;
-     
-     size_check = 0;
-     res = (const struct GNUNET_ARM_ListResultMessage *) msg;
-     success = (ntohs (res->header.type) 
-                == GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT ? 
-                GNUNET_YES : GNUNET_NO);
-     list = GNUNET_malloc (ntohs (res->count) * sizeof (char *));
-     pos = (const char *)&res[1];
-     
-     int i;
-     for (i=0; i<ntohs (res->count); i++)
-     {
-       list[i] = GNUNET_malloc (strlen (pos) + 1);
-       memcpy (list[i], pos, strlen (pos) + 1);
-       pos += strlen (pos) + 1;
-       size_check += strlen (pos) +1;
-       
-       if (size_check > ntohs (res->header.size))
-       {
-          GNUNET_free (list);
-          GNUNET_free (sc);
-          sc->callback (sc->cls, GNUNET_NO, 0, NULL);
-          return;
-       }
-     }
-     
-     sc->callback (sc->cls, success, ntohs (res->count), (const char**)list);
-   }
-   GNUNET_free (sc);
-}
-
-/**
  * Start or stop a service.
  *
  * @param h handle to ARM
@@ -764,7 +676,108 @@
                  GNUNET_MESSAGE_TYPE_ARM_STOP);
 }
 
+
 /**
+ * Internal state for a list request with ARM.
+ */
+struct ListRequestContext
+{
+
+  /**
+   * Pointer to our handle with ARM.
+   */
+  struct GNUNET_ARM_Handle *h;
+
+  /**
+   * Function to call with a status code for the requested operation.
+   */
+  GNUNET_ARM_List_Callback callback;
+
+  /**
+   * Closure for "callback".
+   */
+  void *cls;
+
+  /**
+   * Timeout for the operation.
+   */
+  struct GNUNET_TIME_Absolute timeout;
+};
+
+
+/**
+ * Process a response from ARM for the list request.
+ *
+ * @param cls the list request context
+ * @param msg the response
+ */
+static void
+handle_list_response (void *cls, const struct GNUNET_MessageHeader *msg)
+{
+  struct ListRequestContext *sc = cls;
+  const struct GNUNET_ARM_ListResultMessage *res;
+  const char *pos;
+  uint16_t size_check;
+  uint16_t rcount;
+  uint16_t msize;
+  
+  if (NULL == msg)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        "Error receiving response to LIST request from ARM\n");
+    GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
+    sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
+    GNUNET_assert (NULL != sc->h->client);
+    if (sc->callback != NULL)
+      sc->callback (sc->cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR, 0, NULL);
+    GNUNET_free (sc);
+    return;
+  }
+   
+  if (NULL == sc->callback) 
+  {
+    GNUNET_break (0);
+    GNUNET_free (sc);
+    return;
+  }  
+  msize = ntohs (msg->size);
+  if ( (msize < sizeof ( struct GNUNET_ARM_ListResultMessage)) ||
+       (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT) )
+  {
+    GNUNET_break (0);
+    sc->callback (sc->cls, GNUNET_NO, 0, NULL);
+    GNUNET_free (sc);
+    return;
+  }
+  size_check = 0;
+  res = (const struct GNUNET_ARM_ListResultMessage *) msg;
+  rcount = ntohs (res->count);
+  {
+    const char *list[rcount];
+    unsigned int i;
+    
+    pos = (const char *)&res[1];   
+    for (i=0; i<rcount; i++)
+    {
+      const char *end = memchr (pos, 0, msize - size_check);
+      if (NULL == end)
+      {
+       GNUNET_break (0);
+       GNUNET_free (sc);
+       sc->callback (sc->cls, GNUNET_NO, 0, NULL);
+       return;
+      }
+      list[i] = pos;
+      size_check += (end - pos) + 1;
+      pos = end + 1;
+    }
+    sc->callback (sc->cls, GNUNET_YES, rcount, list);
+  }
+  GNUNET_free (sc);
+}
+
+
+/**
  * List all running services.
  * 
  * @param h handle to ARM
@@ -778,7 +791,7 @@
                                   GNUNET_ARM_List_Callback cb, void *cb_cls)
 {
   struct ListRequestContext *sctx;
-  struct GNUNET_MessageHeader *msg;
+  struct GNUNET_MessageHeader msg;
   struct GNUNET_CLIENT_Connection *client;
   
     if (h->client == NULL)
@@ -801,17 +814,16 @@
   sctx->callback = cb;
   sctx->cls = cb_cls;
   sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-  msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
-  msg->size = htons (sizeof (struct GNUNET_MessageHeader));
-  msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_LIST);
+  msg.size = htons (sizeof (struct GNUNET_MessageHeader));
+  msg.type = htons (GNUNET_MESSAGE_TYPE_ARM_LIST);
   
-  LOG(GNUNET_ERROR_TYPE_DEBUG, 
-      "Requesting LIST from ARM service with timeout: %llu ms\n", 
-      (unsigned long long)timeout.rel_value);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, 
+       "Requesting LIST from ARM service with timeout: %llu ms\n", 
+       (unsigned long long)timeout.rel_value);
   
     if (GNUNET_OK !=
       GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, 
-                                               msg,
+                                               &msg,
                                                
GNUNET_TIME_absolute_get_remaining
                                                (sctx->timeout), 
                                                GNUNET_YES,
@@ -823,10 +835,8 @@
       if (cb != NULL)
         cb (cb_cls, GNUNET_SYSERR, 0, NULL);
       GNUNET_free (sctx);
-      GNUNET_free (msg);
       return;
     }
-  GNUNET_free (msg);
 }
 
 /* end of arm_api.c */

Modified: gnunet/src/arm/gnunet-arm.c
===================================================================
--- gnunet/src/arm/gnunet-arm.c 2012-03-01 12:55:50 UTC (rev 20170)
+++ gnunet/src/arm/gnunet-arm.c 2012-03-01 13:59:23 UTC (rev 20171)
@@ -213,20 +213,18 @@
  * @param list copy of the list of running services
  */
 static void
-list_cb (void *cls, int result, uint16_t count, const char **list)
+list_cb (void *cls, int result, unsigned int count, const char *const*list)
 {
-  if (result == GNUNET_YES && list != NULL)
+  unsigned int i;
+
+  if ( (result != GNUNET_YES) || (NULL == list) )
   {
-    FPRINTF (stdout, "%s", _("Running services:\n-----------------\n"));
-    int i;
-    for (i=0; i<count; i++)
-    {
-      FPRINTF (stdout, "%s\n", list[i]);
-    }
-    GNUNET_free (list);
-  } else {
     FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not 
running?\n"));
+    return;
   }
+  FPRINTF (stdout, "%s", _("Running services:\n"));
+  for (i=0; i<count; i++)
+    FPRINTF (stdout, "%s\n", list[i]);
 }
 
 /**
@@ -353,7 +351,7 @@
              start = 1;
              restart = 0;
              h = GNUNET_ARM_connect (cfg, NULL);
-             if (h == NULL)
+             if (NULL == h)
                {
                  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                              _("Fatal error initializing ARM API.\n"));
@@ -368,7 +366,7 @@
               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Going to list all running services controlled by ARM.\n");
   
-              if (h == NULL) 
+              if (NULL == h) 
               {
                GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                               _("Fatal error initializing ARM API.\n"));

Modified: gnunet/src/include/gnunet_arm_service.h
===================================================================
--- gnunet/src/include/gnunet_arm_service.h     2012-03-01 12:55:50 UTC (rev 
20170)
+++ gnunet/src/include/gnunet_arm_service.h     2012-03-01 13:59:23 UTC (rev 
20171)
@@ -121,8 +121,8 @@
  */
 typedef void (*GNUNET_ARM_List_Callback) (void *cls, 
                                           int result,
-                                          uint16_t count,
-                                          const char **list);
+                                          unsigned int count,
+                                          const char *const *list);
 
 
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]