-renaming gnunet-gns to gnunet-namestore
[oweals/gnunet.git] / src / namestore / gnunet-service-namestore.c
index 8734ee34a64d57ba5b0a028b8c2b7040f6064904..600965e8a9d8229afe9dd8c7cf1b4a8fb15ca831 100644 (file)
@@ -215,7 +215,6 @@ void drop_iterator (void *cls,
   else
   {
     (*stop) = GNUNET_YES;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NULL \n");
   }
 }
 
@@ -226,6 +225,7 @@ void drop_iterator (void *cls,
  *
  * @param cls closure
  * @param client identification of the client
+ * @param message the stop message
  */
 static void handle_stop (void *cls,
                           struct GNUNET_SERVER_Client * client,
@@ -261,7 +261,6 @@ static void handle_stop (void *cls,
     while (stop == GNUNET_NO)
     {
       GSN_database->iterate_records (GSN_database->cls, NULL, NULL, offset, &drop_iterator, &stop);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STOP %u \n");
       offset ++;
     }
   }
@@ -291,8 +290,6 @@ handle_lookup_name_it (void *cls,
   size_t rd_ser_len;
   struct GNUNET_CRYPTO_RsaSignature *signature_tmp;
 
-
-
   size_t r_size = 0;
 
   size_t name_len = 0;
@@ -312,6 +309,8 @@ handle_lookup_name_it (void *cls,
       for (c = 0; c < rd_count; c ++)
         if (rd[c].record_type == lnc->record_type)
           copied_elements++; /* found matching record */
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records with type %u for name `%s' in zone `%s'\n",
+          copied_elements, lnc->record_type, lnc->name, GNUNET_h2s(lnc->zone));
       rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData));
       copied_elements = 0;
       for (c = 0; c < rd_count; c ++)
@@ -338,8 +337,6 @@ handle_lookup_name_it (void *cls,
     expire = GNUNET_TIME_UNIT_ZERO_ABS;
   }
 
-
-
   rd_ser_len = GNUNET_NAMESTORE_records_get_size(copied_elements, rd_selected);
   char rd_ser[rd_ser_len];
   GNUNET_NAMESTORE_records_serialize(copied_elements, rd_selected, rd_ser_len, rd_ser);
@@ -366,7 +363,7 @@ handle_lookup_name_it (void *cls,
   lnr_msg->gns_header.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
   lnr_msg->gns_header.header.size = ntohs (r_size);
   lnr_msg->gns_header.r_id = htonl (lnc->request_id);
-  lnr_msg->rd_count = htons (rd_count);
+  lnr_msg->rd_count = htons (copied_elements);
   lnr_msg->rd_len = htons (rd_ser_len);
   lnr_msg->name_len = htons (name_len);
   lnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
@@ -443,8 +440,10 @@ static void handle_lookup_name (void *cls,
     return;
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up record for name `%s' in zone `%s'\n", name, GNUNET_h2s(&ln_msg->zone));
-
+  if (0 == type)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up all records for name `%s' in zone `%s'\n", name, GNUNET_h2s(&ln_msg->zone));
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up records with type %u for name `%s' in zone `%s'\n", type, name, GNUNET_h2s(&ln_msg->zone));
   /* do the actual lookup */
   lnc.request_id = rid;
   lnc.nc = nc;
@@ -622,11 +621,9 @@ handle_create_record_it (void *cls,
         (crc->rd->data_size == rd[c].data_size) &&
         (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update!\n", crc->name);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update expiration date!\n", crc->name);
       exist = c;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "exp %llu %llu!\n", rd[c].expiration.abs_value, crc->rd->expiration.abs_value);
       if (crc->rd->expiration.abs_value != rd[c].expiration.abs_value)
-
         update = GNUNET_YES;
        break;
     }
@@ -664,6 +661,7 @@ handle_create_record_it (void *cls,
     rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData));
     memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
     rd_count_new = rd_count;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration from %llu to %llu!\n", rd_new[exist].expiration.abs_value, crc->rd->expiration.abs_value);
     rd_new[exist].expiration = crc->rd->expiration;
     signature_new = GNUNET_NAMESTORE_create_signature (crc->pkey, crc->name, rd_new, rd_count_new);
     if (NULL == signature_new)
@@ -689,8 +687,30 @@ end:
   GNUNET_free_non_null (rd_new);
   GNUNET_free_non_null (signature_new);
 
+  switch (res) {
+    case GNUNET_SYSERR:
+       /* failed to create the record */
+       crc->res = GNUNET_SYSERR;
+      break;
+    case GNUNET_YES:
+      /* database operations OK */
+      if (GNUNET_YES == update)
+        /* we updated an existing record */
+        crc->res = GNUNET_NO;
+      else
+        /* we created a new record */
+        crc->res = GNUNET_YES;
+      break;
+    case GNUNET_NO:
+        /* identical entry existed, so we did nothing */
+        crc->res = GNUNET_NO;
+      break;
+    default:
+      break;
+  }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res);
-  crc->res = res;
+
 }
 
 static void handle_record_create (void *cls,