-finishing monitor API on client-side
authorChristian Grothoff <christian@grothoff.org>
Mon, 8 Jul 2013 22:42:13 +0000 (22:42 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 8 Jul 2013 22:42:13 +0000 (22:42 +0000)
src/namestore/namestore.h
src/namestore/namestore_api_monitor.c

index 8e2625c109cbfa5a07270df4bbb1b376471653c3..7245e163195c7946dcfb58542c3196443bfe3e23 100644 (file)
@@ -321,6 +321,7 @@ struct ZoneToNameMessage
   struct GNUNET_CRYPTO_ShortHashCode value_zone;
 };
 
+
 /**
  * Respone for zone to name lookup
  */
index e2caea8a575428e732d09f24abe2f94dd76c2bb2..5eb3e6803b8f742dde183b1527e306805abba576 100644 (file)
@@ -127,20 +127,73 @@ handle_updates (void *cls,
                const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
+  const struct LookupNameResponseMessage *lrm;
+  size_t lrm_len;
+  size_t exp_lrm_len;
+  size_t name_len;
+  size_t rd_len;
+  unsigned rd_count;
+  const char *name_tmp;
+  const char *rd_ser_tmp;
+  struct GNUNET_TIME_Absolute expire;
 
   if (NULL == msg)
   {
     reconnect (zm);
     return;
   }
-  // FIXME: parse, validate
+  if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) ||
+       (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs (msg->type) ) )
+  {
+    GNUNET_break (0);
+    reconnect (zm);
+    return;
+  }
+  lrm = (const struct LookupNameResponseMessage *) msg;
+  lrm_len = ntohs (lrm->gns_header.header.size);
+  rd_len = ntohs (lrm->rd_len);
+  rd_count = ntohs (lrm->rd_count);
+  name_len = ntohs (lrm->name_len);
+  expire = GNUNET_TIME_absolute_ntoh (lrm->expire);
+  exp_lrm_len = sizeof (struct LookupNameResponseMessage) + name_len + rd_len;
+  if (lrm_len != exp_lrm_len)
+  {
+    GNUNET_break (0);
+    reconnect (zm);
+    return;
+  }
+  if (0 == name_len)
+  {
+    GNUNET_break (0);
+    reconnect (zm);
+    return;
+  }
+  name_tmp = (const char *) &lrm[1];
+  if ((name_tmp[name_len -1] != '\0') || (name_len > MAX_NAME_LEN))
+  {
+    GNUNET_break (0);
+    reconnect (zm);
+    return;
+  }
+  rd_ser_tmp = (const char *) &name_tmp[name_len];
+  {
+    struct GNUNET_NAMESTORE_RecordData rd[rd_count];
 
-  GNUNET_CLIENT_receive (zm->h,
-                        &handle_updates,
-                        zm,
-                        GNUNET_TIME_UNIT_FOREVER_REL);
-  // FIXME: call 'monitor'.
-  // zm->monitor (zm->monitor_cls, ...);
+    if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
+    {
+      GNUNET_break (0);
+      reconnect (zm);
+      return;
+    }  
+    GNUNET_CLIENT_receive (zm->h,
+                          &handle_updates,
+                          zm,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
+    zm->monitor(zm->monitor_cls, 
+               &lrm->public_key, expire, 
+               name_tmp, 
+               rd_count, rd, &lrm->signature);
+  }
 }