-indentation
[oweals/gnunet.git] / src / transport / plugin_transport_bluetooth.c
index 8d751f443e07b7e46074b41e6ddf15c0e136f1b3..8ab64b15ccf0d911e6edb4bc7369a0b216f650e7 100644 (file)
@@ -504,7 +504,9 @@ struct MacAndSession
  * @return string representing the same address
  */
 static const char *
-bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen);
+bluetooth_plugin_address_to_string (void *cls,
+                                    const void *addr,
+                                    size_t addrlen);
 
 /**
  * Print MAC addresses nicely.
@@ -661,7 +663,7 @@ free_session (struct Session *session)
   struct PendingMessage *pm;
 
   endpoint->plugin->env->session_end (endpoint->plugin->env->cls,
-                                     &session->target,
+                                     session->address,
                                      session);
   while (NULL != (pm = session->pending_message_head))
   {
@@ -1055,7 +1057,9 @@ create_macendpoint (struct Plugin *plugin,
                            1, GNUNET_NO);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "New MAC endpoint `%s'\n",
-       bluetooth_plugin_address_to_string(NULL, addr, sizeof (struct WlanAddress)));
+       bluetooth_plugin_address_to_string(NULL,
+                                          addr,
+                                          sizeof (struct WlanAddress)));
   return pos;
 }
 
@@ -1119,8 +1123,11 @@ bluetooth_plugin_get_session (void *cls,
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Service asked to create session for peer `%s' with MAC `%s'\n",
        GNUNET_i2s (&address->peer),
-       bluetooth_plugin_address_to_string(NULL, address->address, address->address_length));
-  endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address);
+       bluetooth_plugin_address_to_string(NULL,
+                                          address->address,
+                                          address->address_length));
+  endpoint = create_macendpoint (plugin,
+                                 (struct WlanAddress *) address->address);
   return get_session (endpoint, &address->peer);
 }
 
@@ -1300,8 +1307,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
         "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
         (unsigned int) msize,
         GNUNET_i2s (&tmpsource),
-        bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr,
-            sizeof (mas->endpoint->addr)));
+        bluetooth_plugin_address_to_string (NULL,
+                                             &mas->endpoint->addr,
+                                             sizeof (mas->endpoint->addr)));
 
     GNUNET_STATISTICS_update (plugin->env->stats,
                              _("# HELLO messages received via Bluetooth"), 1,
@@ -1325,10 +1333,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Processing %u bytes of FRAGMENT from MAC %s\n",
         (unsigned int) msize,
-        bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr,
-             sizeof (mas->endpoint->addr)));
+        bluetooth_plugin_address_to_string (NULL,
+                                             &mas->endpoint->addr,
+                                             sizeof (mas->endpoint->addr)));
     GNUNET_STATISTICS_update (plugin->env->stats,
-                              _("# fragments received via Bluetooth"), 1, GNUNET_NO);
+                              _("# fragments received via Bluetooth"),
+                              1,
+                              GNUNET_NO);
     (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
                                              hdr);
     break;
@@ -1347,8 +1358,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
       {
         LOG (GNUNET_ERROR_TYPE_DEBUG,
             "Got last ACK, finished message transmission to `%s' (%p)\n",
-            bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr,
-                         sizeof (mas->endpoint->addr)),
+            bluetooth_plugin_address_to_string (NULL,
+                                                 &mas->endpoint->addr,
+                                                 sizeof (mas->endpoint->addr)),
             fm);
        mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
        if (NULL != fm->cont)
@@ -1363,15 +1375,17 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
       {
         LOG (GNUNET_ERROR_TYPE_DEBUG,
             "Got an ACK, message transmission to `%s' not yet finished\n",
-            bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr,
-                         sizeof (mas->endpoint->addr)));
+            bluetooth_plugin_address_to_string (NULL,
+                                                 &mas->endpoint->addr,
+                                                 sizeof (mas->endpoint->addr)));
         break;
       }
     }
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "ACK not matched against any active fragmentation with MAC `%s'\n",
-        bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr,
-                     sizeof (mas->endpoint->addr)));
+        bluetooth_plugin_address_to_string (NULL,
+                                             &mas->endpoint->addr,
+                                             sizeof (mas->endpoint->addr)));
     break;
   case GNUNET_MESSAGE_TYPE_WLAN_DATA:
     if (NULL == mas->endpoint)
@@ -1675,7 +1689,9 @@ bluetooth_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
  * @return string representing the same address
  */
 static const char *
-bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
+bluetooth_plugin_address_to_string (void *cls,
+                                    const void *addr,
+                                    size_t addrlen)
 {
   const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
   static char macstr[36];
@@ -1686,9 +1702,12 @@ bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
     return NULL;
   }
   mac = &((struct WlanAddress *) addr)->mac;
-  GNUNET_snprintf (macstr, sizeof (macstr), "%s.%u.%s",
-               PLUGIN_NAME, ntohl (((struct WlanAddress *) addr)->options),
-               mac_to_string (mac));
+  GNUNET_snprintf (macstr,
+                   sizeof (macstr),
+                   "%s.%u.%s",
+                   PLUGIN_NAME,
+                   ntohl (((struct WlanAddress *) addr)->options),
+                   mac_to_string (mac));
   return macstr;
 }
 
@@ -1704,7 +1723,7 @@ bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
  * @param numeric should (IP) addresses be displayed in numeric form?
  * @param timeout after how long should we give up?
  * @param asc function to call on each string
- * @param asc_cls closure for asc
+ * @param asc_cls closure for @a asc
  */
 static void
 bluetooth_plugin_address_pretty_printer (void *cls, const char *type,
@@ -1714,20 +1733,16 @@ bluetooth_plugin_address_pretty_printer (void *cls, const char *type,
                                     GNUNET_TRANSPORT_AddressStringCallback asc,
                                     void *asc_cls)
 {
-  char *ret;
+  const char *ret;
 
-  if (sizeof (struct WlanAddress) != addrlen)
-  {
-    /* invalid address  */
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        _("Bluetooth address with invalid size encountered\n"));
-    asc (asc_cls, NULL);
-    return;
-  }
-  ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, addrlen));
-  asc (asc_cls, ret);
-  GNUNET_free (ret);
-  asc (asc_cls, NULL);
+  if (sizeof (struct WlanAddress) == addrlen)
+    ret = bluetooth_plugin_address_to_string(NULL, addr, addrlen);
+  else
+    ret = NULL;
+  asc (asc_cls,
+       ret,
+       (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
+  asc (asc_cls, NULL, GNUNET_OK);
 }
 
 
@@ -1943,7 +1958,7 @@ libgnunet_plugin_transport_bluetooth_init (void *cls)
                          0, GNUNET_NO);
   GNUNET_STATISTICS_set (plugin->env->stats, _("# Bluetooth MAC endpoints allocated"),
                          0, 0);
-  GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
+  GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL,
                                  GNUNET_BANDWIDTH_value_init (100 * 1024 *
                                                               1024 / 8), 100);
   plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);