-cleanup
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.c
index b02abb46fc3f7cda00ec7fb83daa1c5439ed8edf..7258f97a145db1d532cbae4ff7b4955ebdffe7c2 100644 (file)
@@ -19,8 +19,6 @@
 */
 
 /**
- *
- *
  * @file gns/gnunet-service-gns_resolver.c
  * @brief GNUnet GNS resolver logic
  * @author Martin Schanzenbach
@@ -143,28 +141,36 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
  */
 static unsigned long long rid = 0;
 
+/*
+ * Check if name is in srv format (_x._y.xxx)
+ *
+ * @param name
+ * @return GNUNET_YES if true
+ */
 static int
 is_srv (char* name)
 {
   char* ndup;
-  int ret = 1;
+  int ret = GNUNET_YES;
 
   if (*name != '_')
-    return 0;
+    return GNUNET_NO;
   if (NULL == strstr (name, "._"))
-    return 0;
+    return GNUNET_NO;
 
   ndup = GNUNET_strdup (name);
   strtok (ndup, ".");
 
   if (NULL == strtok (NULL, "."))
-    ret = 0;
+    ret = GNUNET_NO;
 
   if (NULL == strtok (NULL, "."))
-    ret = 0;
+    ret = GNUNET_NO;
 
   if (NULL != strtok (NULL, "."))
-    ret = 0;
+    ret = GNUNET_NO;
+
+  GNUNET_free (ndup);
 
   return ret;
 }
@@ -176,10 +182,10 @@ is_srv (char* name)
  * a           = canonical
  *
  * @param name the name to test
- * @return 1 if canonical
+ * @return GNUNET_YES if canonical
  */
 static int
-is_canonical(char* name)
+is_canonical (char* name)
 {
   char* ndup;
   char* tok;
@@ -195,10 +201,10 @@ is_canonical(char* name)
     if (*tok == '_')
       continue;
     GNUNET_free (ndup);
-    return 0;
+    return GNUNET_NO;
   }
   GNUNET_free (ndup);
-  return 1;
+  return GNUNET_YES;
 }
 
 
@@ -1881,7 +1887,8 @@ resolve_record_dns (struct ResolverHandle *rh,
     rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   }
   /* Start shortening */
-  if ((rh->priv_key != NULL) && is_canonical (rh->name))
+  if ((rh->priv_key != NULL) &&
+      (is_canonical (rh->name) == GNUNET_YES))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_REC_DNS-%llu: Trying to shorten authority chain\n",
@@ -2000,7 +2007,8 @@ resolve_record_vpn (struct ResolverHandle *rh,
     rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   }
   /* Start shortening */
-  if ((rh->priv_key != NULL) && is_canonical (rh->name))
+  if ((rh->priv_key != NULL) &&
+      (is_canonical (rh->name) == GNUNET_YES))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_REC_VPN-%llu: Trying to shorten authority chain\n",
@@ -2086,7 +2094,8 @@ resolve_record_ns(struct ResolverHandle *rh)
     rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   }
   /* Start shortening */
-  if ((rh->priv_key != NULL) && is_canonical (rh->name))
+  if ((rh->priv_key != NULL) &&
+     (is_canonical (rh->name) == GNUNET_YES))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_REC-%llu: Trying to shorten authority chain\n",
@@ -2520,7 +2529,8 @@ process_delegation_result_dht(void* cls,
     if (strcmp(rh->name, "") == 0)
     {
       /* Start shortening */
-      if ((rh->priv_key != NULL) && is_canonical (rh->name))
+      if ((rh->priv_key != NULL) &&
+          (is_canonical (rh->name) == GNUNET_YES))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_DELEGATE_DHT-%llu: Trying to shorten authority chain\n",
@@ -2808,7 +2818,7 @@ handle_record_ns (void* cls, struct ResolverHandle *rh,
                                           &rh->private_local_zone))
       check_dht = GNUNET_NO;
     
-    if ((strcmp (rh->name, "+") != 0) && (is_srv (rh->name) != 0))
+    if ((strcmp (rh->name, "+") != 0) && (is_srv (rh->name) == GNUNET_YES))
         check_dht = GNUNET_NO;
 
 
@@ -2848,7 +2858,7 @@ pop_tld(char* name, char* dest)
 {
   uint32_t len;
 
-  if (is_canonical (name))
+  if (is_canonical (name) == GNUNET_YES)
   {
     strcpy(dest, name);
     strcpy(name, "");
@@ -2937,7 +2947,7 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh,
   /**
    * we still have some left
    **/
-  if (is_canonical(rh->name))
+  if (is_canonical (rh->name) == GNUNET_YES)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_DELEGATE_DHT-%llu: Resolving canonical record %s in ns\n",
@@ -3216,7 +3226,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
 
   if (check_dht == GNUNET_NO)
   {
-    if (is_canonical(rh->name))
+    if (is_canonical (rh->name) == GNUNET_YES)
     {
       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                  "GNS_PHASE_DELEGATE_NS-%llu: Resolving canonical record %s\n",
@@ -3474,7 +3484,8 @@ process_delegation_result_ns (void* cls,
   if (strcmp (rh->name, "") == 0)
   {
     /* Start shortening */
-    if ((rh->priv_key != NULL) && is_canonical (rh->name))
+    if ((rh->priv_key != NULL) &&
+        (is_canonical (rh->name) == GNUNET_YES))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "GNS_PHASE_DELEGATE_NS-%llu: Trying to shorten authority chain\n",
@@ -3557,7 +3568,8 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
               name, record_type);
 
   
-  if (is_canonical((char*)name) && (strcmp(GNUNET_GNS_TLD, name) != 0))
+  if ((is_canonical ((char*)name) == GNUNET_YES) &&
+      (strcmp(GNUNET_GNS_TLD, name) != 0))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "%s is canonical and not gnunet -> cannot resolve!\n", name);
@@ -4290,7 +4302,7 @@ gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Starting shorten for %s!\n", name);
   
-  if (is_canonical ((char*)name))
+  if (is_canonical ((char*)name) == GNUNET_YES)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "%s is canonical. Returning verbatim\n", name);
@@ -4448,7 +4460,7 @@ handle_delegation_result_ns_get_auth(void* cls,
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
              "Building response!\n");
-  if (is_canonical(rh->name))
+  if (is_canonical (rh->name) == GNUNET_YES)
   {
     /**
      * We successfully resolved the authority in the ns