minor fix
[oweals/gnunet.git] / src / reclaim / plugin_rest_openid_connect.c
index 345dbeed6323d2b7bfd83b11e40364db94d492d7..09b3c8248a2de75894e3c494f51a292a09069f30 100644 (file)
@@ -32,7 +32,7 @@
 #include "gnunet_gnsrecord_lib.h"
 #include "gnunet_identity_service.h"
 #include "gnunet_namestore_service.h"
-#include "gnunet_reclaim_attribute_lib.h"
+#include "gnunet_reclaim_lib.h"
 #include "gnunet_reclaim_service.h"
 #include "gnunet_rest_lib.h"
 #include "gnunet_rest_plugin.h"
@@ -536,7 +536,6 @@ static void
 cleanup_handle (struct RequestHandle *handle)
 {
   struct EgoEntry *ego_entry;
-  struct EgoEntry *ego_tmp;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
   if (NULL != handle->timeout_task)
@@ -549,6 +548,8 @@ cleanup_handle (struct RequestHandle *handle)
     GNUNET_RECLAIM_get_attestations_stop (handle->attest_it);
   if (NULL != handle->ticket_it)
     GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
+  if (NULL != handle->idp_op)
+    GNUNET_RECLAIM_cancel (handle->idp_op);
   if (NULL != handle->idp)
     GNUNET_RECLAIM_disconnect (handle->idp);
   GNUNET_free_non_null (handle->url);
@@ -576,16 +577,19 @@ cleanup_handle (struct RequestHandle *handle)
     json_decref (handle->oidc->response);
     GNUNET_free (handle->oidc);
   }
-  GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list);
-  GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list);
+  if (NULL!=handle->attr_list)
+    GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list);
+  if (NULL!=handle->attests_list)
+    GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list);
 
-  for (ego_entry = handle->ego_head; NULL != ego_entry;)
+  while (NULL != (ego_entry = handle->ego_head))
   {
-    ego_tmp = ego_entry;
-    ego_entry = ego_entry->next;
-    GNUNET_free (ego_tmp->identifier);
-    GNUNET_free (ego_tmp->keystring);
-    GNUNET_free (ego_tmp);
+    GNUNET_CONTAINER_DLL_remove (handle->ego_head,
+                                 handle->ego_tail,
+                                 ego_entry);
+    GNUNET_free_non_null (ego_entry->identifier);
+    GNUNET_free_non_null (ego_entry->keystring);
+    GNUNET_free (ego_entry);
   }
   GNUNET_free (handle);
 }
@@ -929,7 +933,6 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
   ticket_str =
     GNUNET_STRINGS_data_to_string_alloc (&handle->ticket,
                                          sizeof(struct GNUNET_RECLAIM_Ticket));
-  // TODO change if more attributes are needed (see max_age)
   code_string = OIDC_build_authz_code (&handle->priv_key,
                                        &handle->ticket,
                                        handle->attr_list,
@@ -1529,8 +1532,7 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
     }
   }
   handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scope: %s\n",GNUNET_strdup (
-                handle->oidc->scope));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scope: %s\n", handle->oidc->scope);
   if (NULL == handle->tld)
     GNUNET_CONFIGURATION_iterate_section_values (cfg, "gns", tld_iter, handle);
   if (NULL == handle->tld)
@@ -1782,8 +1784,8 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
   struct RequestHandle *handle = cls;
   const struct EgoEntry *ego_entry;
   struct GNUNET_TIME_Relative expiration_time;
-  struct GNUNET_RECLAIM_AttributeList *cl;
-  struct GNUNET_RECLAIM_AttestationList *al;
+  struct GNUNET_RECLAIM_AttributeList *cl = NULL;
+  struct GNUNET_RECLAIM_AttestationList *al = NULL;
   struct GNUNET_RECLAIM_Ticket ticket;
   struct GNUNET_CRYPTO_EcdsaPublicKey cid;
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
@@ -1946,6 +1948,8 @@ consume_ticket (void *cls,
                 const struct GNUNET_RECLAIM_Attestation *attest)
 {
   struct RequestHandle *handle = cls;
+  handle->idp_op = NULL;
+
   if (NULL == identity)
   {
     GNUNET_SCHEDULER_add_now (&return_userinfo_response, handle);
@@ -2257,13 +2261,16 @@ list_ego (void *cls,
     for (ego_entry = handle->ego_head; NULL != ego_entry;
          ego_entry = ego_entry->next)
     {
-      if (ego_entry->ego == ego)
-        break;
-    }
-    if (NULL != ego_entry)
+      if (ego_entry->ego != ego)
+        continue;
       GNUNET_CONTAINER_DLL_remove (handle->ego_head,
                                    handle->ego_tail,
                                    ego_entry);
+      GNUNET_free (ego_entry->identifier);
+      GNUNET_free (ego_entry->keystring);
+      GNUNET_free (ego_entry);
+      return;
+    }
   }
 }
 
@@ -2277,7 +2284,8 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
 
   handle->oidc = GNUNET_new (struct OIDC_Variables);
   if (NULL == OIDC_cookie_jar_map)
-    OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
+    OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10,
+                                                                GNUNET_NO);
   if (NULL == OIDC_access_token_map)
     OIDC_access_token_map =
       GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
@@ -2302,11 +2310,11 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
 
 
 /**
- * Entry point for the plugin.
- *
- * @param cls Config info
- * @return NULL on error, otherwise the plugin context
- */
  * Entry point for the plugin.
  *
  * @param cls Config info
  * @return NULL on error, otherwise the plugin context
  */
 void *
 libgnunet_plugin_rest_openid_connect_init (void *cls)
 {
@@ -2315,7 +2323,7 @@ libgnunet_plugin_rest_openid_connect_init (void *cls)
 
   cfg = cls;
   if (NULL != plugin.cfg)
-    return NULL; /* can only initialize once! */
+    return NULL;     /* can only initialize once! */
   memset (&plugin, 0, sizeof(struct Plugin));
   plugin.cfg = cfg;
   api = GNUNET_new (struct GNUNET_REST_Plugin);
@@ -2337,11 +2345,11 @@ libgnunet_plugin_rest_openid_connect_init (void *cls)
 
 
 /**
- * Exit point from the plugin.
- *
- * @param cls the plugin context (as returned by "init")
- * @return always NULL
- */
  * Exit point from the plugin.
  *
  * @param cls the plugin context (as returned by "init")
  * @return always NULL
  */
 void *
 libgnunet_plugin_rest_openid_connect_done (void *cls)
 {
@@ -2355,7 +2363,8 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
   hashmap_it =
     GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_cookie_jar_map);
   while (GNUNET_YES ==
-         GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value))
+         GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL,
+                                                      value))
     GNUNET_free_non_null (value);
   GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
   GNUNET_CONTAINER_multihashmap_destroy (OIDC_cookie_jar_map);
@@ -2363,7 +2372,8 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
   hashmap_it =
     GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_access_token_map);
   while (GNUNET_YES ==
-         GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value))
+         GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL,
+                                                      value))
     GNUNET_free_non_null (value);
   GNUNET_CONTAINER_multihashmap_destroy (OIDC_access_token_map);
   GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);