Change regex combination, allow hex
[oweals/gnunet.git] / src / psycstore / psycstore_api.c
index 89be19a4259161522548701f516b47be16cc5253..d79daa35774906a65f2fd6b3a4a1ca27b3586180 100644 (file)
@@ -122,7 +122,7 @@ check_result_code (void *cls, const struct OperationResult *opres)
 {
   uint16_t size = ntohs (opres->header.size);
   const char *str = (const char *) &opres[1];
-  if ( (sizeof (struct OperationResult) < size) &&
+  if ( (sizeof (*opres) < size) &&
        ('\0' != str[size - sizeof (*opres) - 1]) )
   {
     GNUNET_break (0);
@@ -244,9 +244,12 @@ static int
 check_result_state (void *cls, const struct StateResult *sres)
 {
   const char *name = (const char *) &sres[1];
+  uint16_t size = ntohs (sres->header.size);
   uint16_t name_size = ntohs (sres->name_size);
 
-  if (name_size <= 2 || '\0' != name[name_size - 1])
+  if (name_size <= 2
+      || size - sizeof (*sres) < name_size
+      || '\0' != name[name_size - 1])
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "check_result_state: Received state result message with invalid name.\n");
@@ -323,33 +326,29 @@ do_connect (struct GNUNET_PSYCSTORE_Handle *h)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connecting to PSYCstore service.\n");
 
-  GNUNET_MQ_hd_var_size (result_code,
-                         GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE,
-                         struct OperationResult);
-
-  GNUNET_MQ_hd_fixed_size (result_counters,
-                           GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS,
-                           struct CountersResult);
-
-  GNUNET_MQ_hd_var_size (result_fragment,
-                         GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT,
-                         struct FragmentResult);
-
-  GNUNET_MQ_hd_var_size (result_state,
-                         GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE,
-                         struct StateResult);
-
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    make_result_code_handler (h),
-    make_result_counters_handler (h),
-    make_result_fragment_handler (h),
-    make_result_state_handler (h),
+    GNUNET_MQ_hd_var_size (result_code,
+                           GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE,
+                           struct OperationResult,
+                           h),
+    GNUNET_MQ_hd_fixed_size (result_counters,
+                             GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS,
+                             struct CountersResult,
+                             h),
+    GNUNET_MQ_hd_var_size (result_fragment,
+                           GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT,
+                           struct FragmentResult,
+                           h),
+    GNUNET_MQ_hd_var_size (result_state,
+                           GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE,
+                           struct StateResult,
+                           h),
     GNUNET_MQ_handler_end ()
   };
 
   h->op = GNUNET_OP_create ();
   GNUNET_assert (NULL == h->mq);
-  h->mq = GNUNET_CLIENT_connecT (h->cfg, "psycstore",
+  h->mq = GNUNET_CLIENT_connect (h->cfg, "psycstore",
                                  handlers, disconnected, h);
   GNUNET_assert (NULL != h->mq);
 }
@@ -810,7 +809,7 @@ GNUNET_PSYCSTORE_message_get (struct GNUNET_PSYCSTORE_Handle *h,
   if (NULL == method_prefix)
     method_prefix = "";
   uint16_t method_size = strnlen (method_prefix,
-                                  GNUNET_SERVER_MAX_MESSAGE_SIZE
+                                  GNUNET_MAX_MESSAGE_SIZE
                                   - sizeof (*req)) + 1;
 
   struct GNUNET_MQ_Envelope *
@@ -876,7 +875,7 @@ GNUNET_PSYCSTORE_message_get_latest (struct GNUNET_PSYCSTORE_Handle *h,
   if (NULL == method_prefix)
     method_prefix = "";
   uint16_t method_size = strnlen (method_prefix,
-                                  GNUNET_SERVER_MAX_MESSAGE_SIZE
+                                  GNUNET_MAX_MESSAGE_SIZE
                                   - sizeof (*req)) + 1;
   GNUNET_assert ('\0' == method_prefix[method_size - 1]);