speeling and coverity fix
[oweals/gnunet.git] / src / transport / transport_api.c
index 4d7825701fec1faa2725ceeda5219f178a2df253..ca2f2cc609444135d1915835509fbd76c2dbabc9 100644 (file)
@@ -1634,6 +1634,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
   struct NeighbourList *n;
   struct GNUNET_PeerIdentity me;
   uint16_t size;
+  uint32_t ats_count;
 
   if (h->client == NULL)
     {
@@ -1695,12 +1696,20 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
         }
       break;
     case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
-      if (size != sizeof (struct ConnectInfoMessage))
+
+      if (size < sizeof (struct ConnectInfoMessage))
         {
           GNUNET_break (0);
           break;
         }
       cim = (const struct ConnectInfoMessage *) msg;
+      ats_count = ntohl (cim->ats_count);
+      if (size != sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))
+        {
+          GNUNET_break (0);
+          break;
+        }
+
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Receiving `%s' message for `%4s'.\n",
@@ -1708,29 +1717,16 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
 #endif
       n = neighbour_find (h, &cim->id);
       if (n == NULL)
-       n = neighbour_add (h,
-                          &cim->id);
+         n = neighbour_add (h, &cim->id);
       if (n == NULL)
-       {
-         GNUNET_break (0);
-         return;
-       }
+                return;
       GNUNET_break (n->is_connected == GNUNET_NO);
-      if (ntohl ((&cim->ats)[ntohl (cim->ats_count)].type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
-       {
-         GNUNET_break (0);
-         return;
-       }
-      fprintf(stderr,"transport_api GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT ats_count %u\n",ntohl (cim->ats_count));
-     n->is_connected = GNUNET_YES;
+      n->is_connected = GNUNET_YES;
+      /* FIXME */
       if (h->nc_cb != NULL)
-                 h->nc_cb (h->cls, &n->id,
-                   NULL,
-                   0);
-     /*  if (h->nc_cb != NULL)
          h->nc_cb (h->cls, &n->id,
-                   &(cim->ats), 
-                   ntohl (cim->ats_count));*/
+                 &cim->ats,ats_count);
+      /* FIXEND */
       break;
     case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
       if (size != sizeof (struct DisconnectInfoMessage))
@@ -1798,9 +1794,11 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
         }
       im = (const struct InboundMessage *) msg;
       GNUNET_break (0 == ntohl (im->reserved));
-      GNUNET_assert(sizeof (struct InboundMessage) + ntohl(im->ats_count) * sizeof(struct GNUNET_TRANSPORT_ATS_Information) + sizeof (struct GNUNET_MessageHeader) <= size);
-      imm = (const struct GNUNET_MessageHeader *) &((&im->ats)[ntohl(im->ats_count)+1]);
-      if (ntohs (imm->size) + sizeof (struct InboundMessage) + ntohl(im->ats_count) * sizeof(struct GNUNET_TRANSPORT_ATS_Information) != size)
+      ats_count = ntohl(im->ats_count);
+      //imm = (const struct GNUNET_MessageHeader *) &im[1];
+      imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count+1]);
+
+      if (ntohs (imm->size) + sizeof (struct InboundMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size)
         {
           GNUNET_break (0);
           break;
@@ -1821,22 +1819,11 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
          GNUNET_break (0);
          break;
        }
-      if (ntohl ((&im->ats)[ntohl(im->ats_count)].type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
-       {
-         GNUNET_break (0);
-         return;
-       }
-      fprintf(stderr,"transport_api GNUNET_MESSAGE_TYPE_TRANSPORT_RECV ats_count %u\n",ntohl (im->ats_count));
-    if (h->rec != NULL)
-               h->rec (h->cls, &im->peer,
-                       imm,
-                       NULL,
-                       0);
-
-       /*h->rec (h->cls, &im->peer,
-               imm, 
-               &im->ats, 
-               ntohl (im->ats_count));*/
+      /* FIXME: */
+      if (h->rec != NULL)
+               h->rec (h->cls, &im->peer, imm,
+                       &im->ats, ats_count);
+      /* ENDFIX */
       break;
     default:
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,