Link libgnunetblockgroup to libgnunetblock
[oweals/gnunet.git] / src / social / social_api.c
index 583ce6d1e7889ad1b28ef85f32c92fb9bded745c..a7fe0916f5609e743f39679279c1ffbbffdfcedb 100644 (file)
@@ -657,10 +657,17 @@ check_place_state_result (void *cls,
                           const struct GNUNET_OperationResultMessage *res)
 {
   const struct GNUNET_MessageHeader *mod = GNUNET_MQ_extract_nested_mh (res);
-  uint16_t mod_size = ntohs (mod->size);
-  uint16_t size = ntohs (res->header.size);
+  if (NULL == mod)
+  {
+    GNUNET_break_op (0);
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Invalid modifier in state result\n");
+    return GNUNET_SYSERR;
+  }
 
-  if (NULL == mod || size - sizeof (*res) != mod_size)
+  uint16_t size = ntohs (res->header.size);
+  uint16_t mod_size = ntohs (mod->size);
+  if (size - sizeof (*res) != mod_size)
   {
     GNUNET_break_op (0);
     LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -700,7 +707,9 @@ handle_place_state_result (void *cls,
 
     const char *name = (const char *) &pmod[1];
     uint16_t name_size = ntohs (pmod->name_size);
-    if ('\0' != name[name_size - 1])
+    if (0 == name_size
+        || mod_size - sizeof (*pmod) < name_size
+        || '\0' != name[name_size - 1])
     {
       GNUNET_break_op (0);
       LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -884,7 +893,7 @@ handle_guest_enter_decision (void *cls,
   struct GNUNET_SOCIAL_Guest *gst = cls;
 
   struct GNUNET_PSYC_Message *pmsg = NULL;
-  if (ntohs (dcsn->header.size) <= sizeof (*dcsn) + sizeof (*pmsg))
+  if (ntohs (dcsn->header.size) > sizeof (*dcsn))
     pmsg = (struct GNUNET_PSYC_Message *) GNUNET_MQ_extract_nested_mh (dcsn);
 
   if (NULL != gst->entry_dcsn_cb)
@@ -1067,19 +1076,18 @@ place_cleanup (struct GNUNET_SOCIAL_Place *plc)
 
 void
 place_disconnect (struct GNUNET_SOCIAL_Place *plc,
-                  GNUNET_ContinuationCallback disconnect_cb,
-                  void *disconnect_cls)
+                  GNUNET_ContinuationCallback cb,
+                  void *cls)
 {
-  plc->disconnect_cb = disconnect_cb;
-  plc->disconnect_cls = disconnect_cls;
+  plc->disconnect_cb = cb;
+  plc->disconnect_cls = cls;
 
   if (NULL != plc->mq)
   {
-    struct GNUNET_MQ_Envelope *last = GNUNET_MQ_get_last_envelope (plc->mq);
-    if (NULL != last)
+    struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (plc->mq);
+    if (NULL != env)
     {
-      GNUNET_MQ_notify_sent (last,
-                             (GNUNET_MQ_NotifyCallback) place_cleanup, plc);
+      GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) place_cleanup, plc);
     }
     else
     {
@@ -1132,16 +1140,16 @@ host_disconnected (void *cls, enum GNUNET_MQ_Error error)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Host client disconnected (%d), re-connecting\n",
        (int) error);
-  if (NULL != plc->mq)
-  {
-    GNUNET_MQ_destroy (plc->mq);
-    plc->mq = NULL;
-  }
   if (NULL != plc->tmit)
   {
     GNUNET_PSYC_transmit_destroy (plc->tmit);
     plc->tmit = NULL;
   }
+  if (NULL != plc->mq)
+  {
+    GNUNET_MQ_destroy (plc->mq);
+    plc->mq = NULL;
+  }
 
   plc->reconnect_task = GNUNET_SCHEDULER_add_delayed (plc->reconnect_delay,
                                                       host_reconnect,
@@ -1187,7 +1195,7 @@ host_connect (struct GNUNET_SOCIAL_Host *hst)
     GNUNET_MQ_handler_end ()
   };
 
-  plc->mq = GNUNET_CLIENT_connecT (plc->cfg, "social",
+  plc->mq = GNUNET_CLIENT_connect (plc->cfg, "social",
                                    handlers, host_disconnected, hst);
   GNUNET_assert (NULL != plc->mq);
   plc->tmit = GNUNET_PSYC_transmit_create (plc->mq);
@@ -1634,16 +1642,16 @@ guest_disconnected (void *cls, enum GNUNET_MQ_Error error)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Guest client disconnected (%d), re-connecting\n",
        (int) error);
-  if (NULL != plc->mq)
-  {
-    GNUNET_MQ_destroy (plc->mq);
-    plc->mq = NULL;
-  }
   if (NULL != plc->tmit)
   {
     GNUNET_PSYC_transmit_destroy (plc->tmit);
     plc->tmit = NULL;
   }
+  if (NULL != plc->mq)
+  {
+    GNUNET_MQ_destroy (plc->mq);
+    plc->mq = NULL;
+  }
 
   plc->reconnect_task = GNUNET_SCHEDULER_add_delayed (plc->reconnect_delay,
                                                       guest_reconnect,
@@ -1689,7 +1697,7 @@ guest_connect (struct GNUNET_SOCIAL_Guest *gst)
     GNUNET_MQ_handler_end ()
   };
 
-  plc->mq = GNUNET_CLIENT_connecT (plc->cfg, "social",
+  plc->mq = GNUNET_CLIENT_connect (plc->cfg, "social",
                                    handlers, guest_disconnected, gst);
   GNUNET_assert (NULL != plc->mq);
   plc->tmit = GNUNET_PSYC_transmit_create (plc->mq);
@@ -2589,7 +2597,7 @@ app_connect (struct GNUNET_SOCIAL_App *app)
     GNUNET_MQ_handler_end ()
   };
 
-  app->mq = GNUNET_CLIENT_connecT (app->cfg, "social",
+  app->mq = GNUNET_CLIENT_connect (app->cfg, "social",
                                    handlers, app_disconnected, app);
   GNUNET_assert (NULL != app->mq);
   GNUNET_MQ_send_copy (app->mq, app->connect_env);
@@ -2690,11 +2698,10 @@ GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app,
 
   if (NULL != app->mq)
   {
-    struct GNUNET_MQ_Envelope *last = GNUNET_MQ_get_last_envelope (app->mq);
-    if (NULL != last)
+    struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (app->mq);
+    if (NULL != env)
     {
-      GNUNET_MQ_notify_sent (last,
-                             (GNUNET_MQ_NotifyCallback) app_cleanup, app);
+      GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) app_cleanup, app);
     }
     else
     {
@@ -2729,6 +2736,7 @@ GNUNET_SOCIAL_app_detach (struct GNUNET_SOCIAL_App *app,
   struct GNUNET_MQ_Envelope *
     env = GNUNET_MQ_msg (dreq, GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH);
   dreq->place_pub_key = plc->pub_key;
+  dreq->ego_pub_key = plc->ego_pub_key;
 
   GNUNET_MQ_send (app->mq, env);
 }