-only trigger check config if we actually need it
[oweals/gnunet.git] / src / psycutil / psyc_message.c
index 62a5b8f1425292b80d42b33bd6a3b6e7ebab1b3a..9f0a0c7da1e70dd6be8ec658bfd0cb610edcb9da 100644 (file)
@@ -267,38 +267,54 @@ GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
 {
   uint16_t size = ntohs (msg->size);
   uint16_t type = ntohs (msg->type);
-  GNUNET_log (kind, "Message of type %d and size %u:\n", type, size);
+
+  GNUNET_log (kind,
+              "Message of type %d and size %u:\n",
+              type,
+              size);
   switch (type)
   {
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE:
   {
-    struct GNUNET_PSYC_MessageHeader *pmsg
-      = (struct GNUNET_PSYC_MessageHeader *) msg;
-    GNUNET_log (kind, "\tID: %" PRIu64 "\tflags: %x" PRIu32 "\n",
-                GNUNET_ntohll (pmsg->message_id), ntohl (pmsg->flags));
+    const struct GNUNET_PSYC_MessageHeader *pmsg
+      = (const struct GNUNET_PSYC_MessageHeader *) msg;
+    GNUNET_log (kind,
+                "\tID: %" PRIu64 "\tflags: %x" PRIu32 "\n",
+                GNUNET_ntohll (pmsg->message_id),
+                ntohl (pmsg->flags));
     break;
   }
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
   {
-    struct GNUNET_PSYC_MessageMethod *meth
-      = (struct GNUNET_PSYC_MessageMethod *) msg;
-    GNUNET_log (kind, "\t%.*s\n", size - sizeof (*meth), &meth[1]);
+    const struct GNUNET_PSYC_MessageMethod *meth
+      = (const struct GNUNET_PSYC_MessageMethod *) msg;
+    GNUNET_log (kind,
+                "\t%.*s\n",
+                (int) (size - sizeof (*meth)),
+                (const char *) &meth[1]);
     break;
   }
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
   {
-    struct GNUNET_PSYC_MessageModifier *mod
-      = (struct GNUNET_PSYC_MessageModifier *) msg;
+    const struct GNUNET_PSYC_MessageModifier *mod
+      = (const struct GNUNET_PSYC_MessageModifier *) msg;
     uint16_t name_size = ntohs (mod->name_size);
     char oper = ' ' < mod->oper ? mod->oper : ' ';
-    GNUNET_log (kind, "\t%c%.*s\t%.*s\n", oper, name_size, &mod[1],
-                size - sizeof (*mod) - name_size,
-                ((char *) &mod[1]) + name_size);
+    GNUNET_log (kind,
+                "\t%c%.*s\t%.*s\n",
+                oper,
+                (int) name_size,
+                (const char *) &mod[1],
+                (int) (size - sizeof (*mod) - name_size),
+                ((const char *) &mod[1]) + name_size);
     break;
   }
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA:
-    GNUNET_log (kind, "\t%.*s\n", size - sizeof (*msg), &msg[1]);
+    GNUNET_log (kind,
+                "\t%.*s\n",
+                (int) (size - sizeof (*msg)),
+                (const char *) &msg[1]);
     break;
   }
 }
@@ -313,7 +329,8 @@ GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
 struct GNUNET_PSYC_TransmitHandle *
 GNUNET_PSYC_transmit_create (struct GNUNET_CLIENT_MANAGER_Connection *client)
 {
-  struct GNUNET_PSYC_TransmitHandle *tmit = GNUNET_malloc (sizeof (*tmit));
+  struct GNUNET_PSYC_TransmitHandle *tmit = GNUNET_new (struct GNUNET_PSYC_TransmitHandle);
+
   tmit->client = client;
   return tmit;
 }
@@ -879,11 +896,10 @@ static void
 recv_error (struct GNUNET_PSYC_ReceiveHandle *recv)
 {
   if (NULL != recv->message_part_cb)
-    recv->message_part_cb (recv->cb_cls, NULL, recv->message_id, recv->flags,
-                           0, NULL);
+    recv->message_part_cb (recv->cb_cls, NULL, NULL);
 
   if (NULL != recv->message_cb)
-    recv->message_cb (recv->cb_cls, recv->message_id, recv->flags, NULL);
+    recv->message_cb (recv->cb_cls, NULL);
 
   GNUNET_PSYC_receive_reset (recv);
 }
@@ -904,7 +920,6 @@ GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
 {
   uint16_t size = ntohs (msg->header.size);
   uint32_t flags = ntohl (msg->flags);
-  uint64_t message_id;
 
   GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG,
                            (struct GNUNET_MessageHeader *) msg);
@@ -936,7 +951,6 @@ GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
     recv_error (recv);
     return GNUNET_SYSERR;
   }
-  message_id = recv->message_id;
 
   uint16_t pos = 0, psize = 0, ptype, size_eq, size_min;
 
@@ -1099,10 +1113,7 @@ GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
     }
 
     if (NULL != recv->message_part_cb)
-      recv->message_part_cb (recv->cb_cls, &recv->slave_pub_key,
-                             recv->message_id, recv->flags,
-                             0, // FIXME: data_offset
-                             pmsg);
+      recv->message_part_cb (recv->cb_cls, msg, pmsg);
 
     switch (ptype)
     {
@@ -1114,7 +1125,7 @@ GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
   }
 
   if (NULL != recv->message_cb)
-    recv->message_cb (recv->cb_cls, message_id, flags, msg);
+    recv->message_cb (recv->cb_cls, msg);
   return GNUNET_OK;
 }
 
@@ -1180,23 +1191,22 @@ struct ParseMessageClosure
 
 static void
 parse_message_part_cb (void *cls,
-                       const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key,
-                       uint64_t message_id, uint32_t flags, uint64_t data_offset,
-                       const struct GNUNET_MessageHeader *msg)
+                       const struct GNUNET_PSYC_MessageHeader *msg,
+                       const struct GNUNET_MessageHeader *pmsg)
 {
   struct ParseMessageClosure *pmc = cls;
-  if (NULL == msg)
+  if (NULL == pmsg)
   {
     pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
     return;
   }
 
-  switch (ntohs (msg->type))
+  switch (ntohs (pmsg->type))
   {
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
   {
     struct GNUNET_PSYC_MessageMethod *
-      pmeth = (struct GNUNET_PSYC_MessageMethod *) msg;
+      pmeth = (struct GNUNET_PSYC_MessageMethod *) pmsg;
     *pmc->method_name = (const char *) &pmeth[1];
     pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_METHOD;
     break;
@@ -1205,7 +1215,7 @@ parse_message_part_cb (void *cls,
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
   {
     struct GNUNET_PSYC_MessageModifier *
-      pmod = (struct GNUNET_PSYC_MessageModifier *) msg;
+      pmod = (struct GNUNET_PSYC_MessageModifier *) pmsg;
 
     const char *name = (const char *) &pmod[1];
     const void *value = name + ntohs (pmod->name_size);
@@ -1216,8 +1226,8 @@ parse_message_part_cb (void *cls,
   }
 
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA:
-    *pmc->data = &msg[1];
-    *pmc->data_size = ntohs (msg->size) - sizeof (*msg);
+    *pmc->data = &pmsg[1];
+    *pmc->data_size = ntohs (pmsg->size) - sizeof (*pmsg);
     pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_DATA;
     break;
 
@@ -1241,7 +1251,7 @@ parse_message_part_cb (void *cls,
  * @param env
  *        The environment for the message with a list of modifiers.
  * @param[out] data
- *        Pointer to data inside @a pmsg.
+ *        Pointer to data inside @a msg.
  * @param[out] data_size
  *        Size of @data is written here.
  *