- fix warnings
[oweals/gnunet.git] / src / identity-provider / gnunet-service-identity-provider.c
index 05b73db1aa385ad8c8d105ceae7affd87c398041..0a690e2d3a2e05ec237b9d41cb7b852113156f66 100644 (file)
@@ -35,6 +35,7 @@
 #include "gnunet_signatures.h"
 #include "identity_provider.h"
 #include "identity_token.h"
+#include <inttypes.h>
 
 /**
  * First pass state
@@ -104,13 +105,12 @@ static struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
 /**
  * Timeout task
  */
-static struct GNUNET_SCHEDULER_Task * timeout_task;
-
+static struct GNUNET_SCHEDULER_Task *timeout_task;
 
 /**
  * Update task
  */
-static struct GNUNET_SCHEDULER_Task * update_task;
+static struct GNUNET_SCHEDULER_Task *update_task;
 
 /**
  * Timeout for next update pass
@@ -181,7 +181,7 @@ struct ExchangeHandle
    * LookupRequest
    */
   struct GNUNET_GNS_LookupRequest *lookup_request;
-  
+
   /**
    * Audience Key
    */
@@ -323,11 +323,9 @@ store_token_cont (void *cls,
  * removes deleted attributes and expiration times.
  *
  * @param cls the ego entry
- * @param tc task context
  */
 static void
-handle_token_update (void *cls,
-                     const struct GNUNET_SCHEDULER_TaskContext *tc)
+handle_token_update (void *cls)
 {
   char *token_metadata;
   char *write_ptr;
@@ -368,11 +366,11 @@ handle_token_update (void *cls,
     if (0 == strcmp (attr->name, "exp"))
     {
       sscanf (attr->val_head->value,
-              "%lu",
+              "%"SCNu64,
               &token_exp.abs_value_us);
     } else if (0 == strcmp (attr->name, "nbf")) {
       sscanf (attr->val_head->value,
-              "%lu",
+              "%"SCNu64,
               &token_nbf.abs_value_us);
     }
   }
@@ -427,13 +425,13 @@ handle_token_update (void *cls,
                       attr->name,
                       attr->val_head->value);
     }
-    else 
+    else
     {
       GNUNET_CRYPTO_hash (attr->name,
                           strlen (attr->name),
                           &key_hash);
       //Check if attr still exists. omit of not
-      if (GNUNET_NO != 
+      if (GNUNET_NO !=
           GNUNET_CONTAINER_multihashmap_contains (ego_entry->attr_map,
                                                   &key_hash))
       {
@@ -483,7 +481,6 @@ handle_token_update (void *cls,
                                           token_record,
                                           &store_token_cont,
                                           ego_entry);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, ">>> Updating Token w/ %s\n", new_token);
   token_destroy (new_token);
   token_destroy (token);
   GNUNET_free (new_ecdhe_privkey);
@@ -495,9 +492,10 @@ handle_token_update (void *cls,
   scopes = NULL;
 }
 
+
 static void
-update_identities(void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc);
+update_identities(void *cls);
+
 
 /**
  *
@@ -506,7 +504,7 @@ update_identities(void *cls,
  * @param cls NULL
  * @param key the key
  * @param value the json_t attribute value
- * @return GNUNET_YES
+ * @return #GNUNET_YES
  */
 static int
 clear_ego_attrs (void *cls,
@@ -532,6 +530,7 @@ clear_ego_attrs (void *cls,
   return GNUNET_YES;
 }
 
+
 /**
  *
  * Update all ID_TOKEN records for an identity and store them
@@ -541,7 +540,6 @@ clear_ego_attrs (void *cls,
  * @param lbl the name of the record
  * @param rd_count number of records
  * @param rd record data
- *
  */
 static void
 token_collect (void *cls,
@@ -567,7 +565,7 @@ token_collect (void *cls,
     GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
     update_task = GNUNET_SCHEDULER_add_now (&update_identities,
                                             ego_entry->next);
-    return; 
+    return;
   }
 
   //There should be only a single record for a token under a label
@@ -581,7 +579,9 @@ token_collect (void *cls,
   {
     token_metadata_record = &rd[0];
     token_record = &rd[1];
-  } else {
+  }
+  else
+  {
     token_record = &rd[0];
     token_metadata_record = &rd[1];
   }
@@ -606,10 +606,11 @@ token_collect (void *cls,
                 aud_key,
                 &token);
 
-  label = GNUNET_strdup (lbl); 
+  label = GNUNET_strdup (lbl);
   rd_exp = token_record->expiration_time;
 
-  GNUNET_SCHEDULER_add_now (&handle_token_update, ego_entry);
+  GNUNET_SCHEDULER_add_now (&handle_token_update,
+                           ego_entry);
 }
 
 
@@ -644,7 +645,8 @@ attribute_collect (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 ">>> Updating Attributes finished\n");
     ego_entry->attributes_dirty = GNUNET_NO;
-    update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_entry);
+    update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+                                           ego_entry);
     return;
   }
 
@@ -710,12 +712,9 @@ attribute_collect (void *cls,
  * dirty, first update the attributes.
  *
  * @param cls the ego to update
- * param tc task context
- *
  */
 static void
-update_identities(void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_identities(void *cls)
 {
   struct EgoEntry *next_ego = cls;
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
@@ -725,7 +724,7 @@ update_identities(void *cls,
     if (min_rel_exp.rel_value_us < MIN_WAIT_TIME.rel_value_us)
       min_rel_exp = MIN_WAIT_TIME;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                ">>> Finished. Rescheduling in %d\n",
+                ">>> Finished. Rescheduling in %lu\n",
                 min_rel_exp.rel_value_us);
     ns_it = NULL;
     //finished -> reschedule
@@ -757,7 +756,6 @@ update_identities(void *cls,
 }
 
 
-
 /**
  * Function called initially to start update task
  */
@@ -766,9 +764,11 @@ init_cont ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, ">>> Starting Service\n");
   //Initially iterate all itenties and refresh all tokens
-  update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_head);
+  update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+                                         ego_head);
 }
 
+
 /**
  * Initial ego collection function.
  *
@@ -865,8 +865,7 @@ cleanup()
  * @param tc task context
  */
 static void
-do_shutdown (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutting down...\n");
@@ -881,10 +880,10 @@ create_exchange_result_message (const char* token,
 {
   struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage *erm;
   uint16_t token_len = strlen (token) + 1;
-  erm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage) 
+  erm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage)
                        + token_len);
   erm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_EXCHANGE_RESULT);
-  erm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage) 
+  erm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage)
                             + token_len);
   erm->ticket_nonce = htonl (ticket_nonce);
   memcpy (&erm[1], token, token_len);
@@ -900,12 +899,12 @@ create_issue_result_message (const char* label,
   struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
   char *tmp_str;
 
-  irm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage) 
+  irm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage)
                        + strlen (label) + 1
                        + strlen (ticket) + 1
                        + strlen (token) + 1);
   irm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_RESULT);
-  irm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage) 
+  irm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage)
                             + strlen (label) + 1
                             + strlen (ticket) + 1
                             + strlen (token) + 1);
@@ -940,6 +939,7 @@ store_token_issue_cont (void *cls,
   struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
   char *ticket_str;
   char *token_str;
+  
   handle->ns_qe = NULL;
   if (GNUNET_SYSERR == success)
   {
@@ -956,7 +956,7 @@ store_token_issue_cont (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n",
                 "Error serializing ticket\n");
     cleanup_issue_handle (handle);
-    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
     return;
   }
   if (GNUNET_OK != token_to_string (handle->token,
@@ -967,10 +967,12 @@ store_token_issue_cont (void *cls,
                 "Error serializing token\n");
     GNUNET_free (ticket_str);
     cleanup_issue_handle (handle);
-    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
     return;
   }
-  irm = create_issue_result_message (handle->label, ticket_str, token_str);
+  irm = create_issue_result_message (handle->label,
+                                    ticket_str,
+                                    token_str);
   GNUNET_SERVER_notification_context_unicast (nc,
                                               handle->client,
                                               &irm->header,
@@ -982,8 +984,12 @@ store_token_issue_cont (void *cls,
   GNUNET_free (token_str);
 }
 
+
 /**
  * Build a GNUid token for identity
+ *
+ * FIXME: doxygen is very wrong here!
+ *
  * @param handle the handle
  * @param ego_entry the ego to build the token for
  * @param name name of the ego
@@ -992,8 +998,7 @@ store_token_issue_cont (void *cls,
  * @return identifier string of token (label)
  */
 static void
-sign_and_return_token (void *cls,
-                       const struct GNUNET_SCHEDULER_TaskContext *tc)
+sign_and_return_token (void *cls)
 {
   struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
   struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
@@ -1007,7 +1012,7 @@ sign_and_return_token (void *cls,
   uint64_t exp_time;
   size_t token_metadata_len;
 
-  //Remote nonce 
+  //Remote nonce
   nonce_str = NULL;
   GNUNET_asprintf (&nonce_str, "%lu", handle->nonce);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request nonce: %s\n", nonce_str);
@@ -1027,7 +1032,7 @@ sign_and_return_token (void *cls,
   token_add_attr_int (handle->token, "exp", exp_time);
   token_add_attr (handle->token, "nonce", nonce_str);
 
-  //Token in a serialized encrypted format 
+  //Token in a serialized encrypted format
   GNUNET_assert (token_serialize (handle->token,
                                   &handle->iss_key,
                                   &ecdhe_privkey,
@@ -1149,7 +1154,7 @@ attr_collect (void *cls,
 static void
 cleanup_exchange_handle (struct ExchangeHandle *handle)
 {
-  if (NULL != handle->ticket) 
+  if (NULL != handle->ticket)
     ticket_destroy (handle->ticket);
   if (NULL != handle->token)
     token_destroy (handle->token);
@@ -1176,7 +1181,7 @@ process_lookup_result (void *cls, uint32_t rd_count,
     return;
   }
 
-  record_str = 
+  record_str =
     GNUNET_GNSRECORD_value_to_string (GNUNET_GNSRECORD_TYPE_ID_TOKEN,
                                       rd->data,
                                       rd->data_size);
@@ -1306,7 +1311,7 @@ find_existing_token (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 ">>> No existing token found\n");
     //Label
-    rnd_key = 
+    rnd_key =
       GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
                                 UINT64_MAX);
     GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
@@ -1317,7 +1322,7 @@ find_existing_token (void *cls,
                                                            &handle->iss_key,
                                                            &attr_collect,
                                                            handle);
-    return; 
+    return;
   }
 
   //There should be only a single record for a token under a label
@@ -1339,7 +1344,7 @@ find_existing_token (void *cls,
     return;
   }
   ecdhe_privkey = *((struct GNUNET_CRYPTO_EcdhePrivateKey *)token_metadata_record->data);
-  aud_key = 
+  aud_key =
     (struct GNUNET_CRYPTO_EcdsaPublicKey *)(token_metadata_record->data+sizeof(struct GNUNET_CRYPTO_EcdhePrivateKey));
   tmp_scopes = GNUNET_strdup ((char*) aud_key+sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
 
@@ -1434,12 +1439,11 @@ handle_issue_message (void *cls,
   }
   im = (const struct GNUNET_IDENTITY_PROVIDER_IssueMessage *) message;
   scopes = (const char *) &im[1];
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received ISSUE of `%s' from client\n",
-              scope);
   issue_handle = GNUNET_malloc (sizeof (struct IssueHandle));
   issue_handle->attr_map = GNUNET_CONTAINER_multihashmap_create (5,
                                                                  GNUNET_NO);
+  /* FIXME: check that scopes is 0-termianted, Out-of-bounds access
+     possible here!!! */
   scopes_tmp = GNUNET_strdup (scopes);
   scope = strtok(scopes_tmp, ",");
   for (; NULL != scope; scope = strtok (NULL, ","))
@@ -1483,7 +1487,7 @@ handle_issue_message (void *cls,
  * @param c configuration
  */
 static void
-run (void *cls, 
+run (void *cls,
      struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
@@ -1518,7 +1522,7 @@ run (void *cls,
                                              &list_ego,
                                              NULL);
 
-  if (GNUNET_OK == 
+  if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_time (cfg,
                                            "identity-provider",
                                            "TOKEN_EXPIRATION_INTERVAL",
@@ -1532,19 +1536,16 @@ run (void *cls,
     token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL;
   }
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
 }
 
 
 /**
- *
  * The main function
  *
  * @param argc number of arguments from the cli
  * @param argv command line arguments
  * @return 0 ok, 1 on error
- *
  */
 int
 main (int argc, char *const *argv)
@@ -1555,4 +1556,4 @@ main (int argc, char *const *argv)
                                &run, NULL)) ? 0 : 1;
 }
 
-/* end of gnunet-rest-server.c */
+/* end of gnunet-service-identity-provider.c */