gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r28849 - in gnunet/src: identity include


From: gnunet
Subject: [GNUnet-SVN] r28849 - in gnunet/src: identity include
Date: Sat, 24 Aug 2013 17:54:21 +0200

Author: grothoff
Date: 2013-08-24 17:54:21 +0200 (Sat, 24 Aug 2013)
New Revision: 28849

Added:
   gnunet/src/identity/identity_api_lookup.c
Modified:
   gnunet/src/identity/Makefile.am
   gnunet/src/identity/identity_api.c
   gnunet/src/include/gnunet_identity_service.h
Log:
-more convenient API to lookup egos

Modified: gnunet/src/identity/Makefile.am
===================================================================
--- gnunet/src/identity/Makefile.am     2013-08-24 15:53:58 UTC (rev 28848)
+++ gnunet/src/identity/Makefile.am     2013-08-24 15:54:21 UTC (rev 28849)
@@ -20,7 +20,9 @@
 lib_LTLIBRARIES = libgnunetidentity.la
 
 libgnunetidentity_la_SOURCES = \
-  identity_api.c identity.h
+  identity_api.c \
+  identity_api_lookup.c \
+  identity.h
 libgnunetidentity_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL) $(XLIB)

Modified: gnunet/src/identity/identity_api.c
===================================================================
--- gnunet/src/identity/identity_api.c  2013-08-24 15:53:58 UTC (rev 28848)
+++ gnunet/src/identity/identity_api.c  2013-08-24 15:54:21 UTC (rev 28849)
@@ -24,14 +24,9 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
-#include "gnunet_client_lib.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_constants.h"
-#include "gnunet_container_lib.h"
-#include "gnunet_arm_service.h"
-#include "gnunet_hello_lib.h"
 #include "gnunet_protocols.h"
-#include "gnunet_server_lib.h"
-#include "gnunet_time_lib.h"
 #include "gnunet_identity_service.h"
 #include "identity.h"
 
@@ -292,6 +287,8 @@
     GNUNET_CONTAINER_DLL_remove (h->op_head,
                                 h->op_tail,
                                 op);
+    GNUNET_CLIENT_receive (h->client, &message_handler, h,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
     if (NULL != op->cont)
       op->cont (op->cls,
                str);
@@ -321,6 +318,8 @@
     if (GNUNET_YES == ntohs (um->end_of_list))
     {
       /* end of initial list of data */
+      GNUNET_CLIENT_receive (h->client, &message_handler, h,
+                            GNUNET_TIME_UNIT_FOREVER_REL);
       if (NULL != h->cb)
        h->cb (h->cb_cls, NULL, NULL, NULL);
       break;
@@ -355,12 +354,6 @@
                                                        ego,
                                                        
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
     }
-    /* inform application about change */
-    if (NULL != h->cb)
-      h->cb (h->cb_cls,
-            ego,
-            &ego->ctx,
-            str);
     if (NULL == str)
     {
       /* ego was deleted */
@@ -368,16 +361,27 @@
                     GNUNET_CONTAINER_multihashmap_remove (h->egos,
                                                           &ego->id,
                                                           ego));
-      GNUNET_free (ego->pk);
-      GNUNET_free (ego->name);
-      GNUNET_free (ego);
     }
     else
-      {
+    {
       /* ego changed name */
       GNUNET_free (ego->name);
       ego->name = GNUNET_strdup (str);
     }    
+    GNUNET_CLIENT_receive (h->client, &message_handler, h,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
+    /* inform application about change */
+    if (NULL != h->cb)
+      h->cb (h->cb_cls,
+            ego,
+            &ego->ctx,
+            str);
+    if (NULL == str)
+    {
+      GNUNET_free (ego->pk);
+      GNUNET_free (ego->name);
+      GNUNET_free (ego);
+    }
     break;
   case GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT:
     if (size < sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
@@ -416,6 +420,8 @@
                                 h->op_tail,
                                 op);
     GNUNET_free (ego->name);
+    GNUNET_CLIENT_receive (h->client, &message_handler, h,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
     if (NULL != op->cb)
       op->cb (op->cls,
              ego,
@@ -428,8 +434,6 @@
     reschedule_connect (h);
     return;
   }
-  GNUNET_CLIENT_receive (h->client, &message_handler, h,
-                         GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 
@@ -565,7 +569,7 @@
 {
   struct GNUNET_IDENTITY_Handle *h;
 
-  h = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Handle));
+  h = GNUNET_new (struct GNUNET_IDENTITY_Handle);
   h->cfg = cfg;
   h->cb = cb;
   h->cb_cls = cb_cls;
@@ -821,7 +825,7 @@
  * @param id identity service to use
  * @param name name of the identity to delete
  * @param cb function to call with the result (will only be called once)
- * @param cb_cls closure for cb
+ * @param cb_cls closure for @a cb
  * @return handle to abort the operation
  */
 struct GNUNET_IDENTITY_Operation *
@@ -910,7 +914,7 @@
  * @param cls identity service handle
  * @param key unused
  * @param value ego to free
- * @return GNUNET_OK (continue to iterate)
+ * @return #GNUNET_OK (continue to iterate)
  */
 static int
 free_ego (void *cls,

Added: gnunet/src/identity/identity_api_lookup.c
===================================================================
--- gnunet/src/identity/identity_api_lookup.c                           (rev 0)
+++ gnunet/src/identity/identity_api_lookup.c   2013-08-24 15:54:21 UTC (rev 
28849)
@@ -0,0 +1,154 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public Liceidentity as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public Liceidentity for more details.
+
+     You should have received a copy of the GNU General Public Liceidentity
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file identity/identity_api_lookup.c
+ * @brief api to lookup an ego
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_identity_service.h"
+
+#define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
+
+
+/**
+ * Handle for ego lookup.
+ */ 
+struct GNUNET_IDENTITY_EgoLookup
+{
+  
+  /**
+   * Handle to the identity service.
+   */
+  struct GNUNET_IDENTITY_Handle *identity;
+  
+  /**
+   * Name of the ego we are looking up.
+   */
+  char *name;
+  
+  /**
+   * Function to call with the result.
+   */
+  GNUNET_IDENTITY_EgoCallback cb;
+  
+  /**
+   * Closure for @e cb
+   */
+  void *cb_cls;
+};
+
+
+/** 
+ * Method called to inform about the egos of this peer.
+ *
+ * When used with #GNUNET_IDENTITY_connect, this function is
+ * initially called for all egos and then again whenever a
+ * ego's name changes or if it is deleted.  At the end of
+ * the initial pass over all egos, the function is once called
+ * with 'NULL' for @a ego. That does NOT mean that the callback won't
+ * be invoked in the future or that there was an error.
+ *
+ * If the @a name matches the name from @a cls, we found the zone
+ * for our computation and will invoke the callback.
+ * If we have iterated over all egos and not found the name, we
+ * invoke the callback with NULL.
+ *
+ * @param cls closure with the `struct GNUNET_IDENTITY_EgoLookup`
+ * @param ego ego handle
+ * @param ego_ctx context for application to store data for this ego
+ *                 (during the lifetime of this process, initially NULL)
+ * @param name name assigned by the user for this ego,
+ *                   NULL if the user just deleted the ego and it
+ *                   must thus no longer be used
+ */
+static void 
+identity_cb (void *cls,
+            struct GNUNET_IDENTITY_Ego *ego,
+            void **ctx,
+            const char *name)
+{
+  struct GNUNET_IDENTITY_EgoLookup *el = cls;
+
+  if ( (NULL != name) &&
+       (0 == strcmp (name,
+                    el->name)) )
+  {
+    el->cb (el->cb_cls,
+           ego);
+    GNUNET_IDENTITY_ego_lookup_cancel (el);
+    return;
+  }
+  if (NULL == ego) 
+  {
+    /* not found */
+    el->cb (el->cb_cls,
+           NULL);
+    GNUNET_IDENTITY_ego_lookup_cancel (el);
+    return;
+  }
+}
+
+
+/**
+ * Lookup an ego by name.
+ *
+ * @param cfg configuration to use
+ * @param name name to look up
+ * @param cb callback to invoke with the result
+ * @param cb_cls closure for @a cb
+ * @return NULL on error
+ */
+struct GNUNET_IDENTITY_EgoLookup *
+GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                           const char *name,
+                           GNUNET_IDENTITY_EgoCallback cb,
+                           void *cb_cls)
+{
+  struct GNUNET_IDENTITY_EgoLookup *el;
+
+  el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup);
+  el->name = GNUNET_strdup (name);
+  el->cb = cb;
+  el->cb_cls = cb_cls;
+  el->identity = GNUNET_IDENTITY_connect (cfg,
+                                         &identity_cb,
+                                         el);
+  return el;
+}
+
+
+/**
+ * Abort ego lookup attempt.
+ *
+ * @param el handle for lookup to abort
+ */
+void
+GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el)
+{
+  GNUNET_IDENTITY_disconnect (el->identity);
+  GNUNET_free (el->name);
+  GNUNET_free (el);
+}
+
+
+/* end of identity_api_lookup.c */

Modified: gnunet/src/include/gnunet_identity_service.h
===================================================================
--- gnunet/src/include/gnunet_identity_service.h        2013-08-24 15:53:58 UTC 
(rev 28848)
+++ gnunet/src/include/gnunet_identity_service.h        2013-08-24 15:54:21 UTC 
(rev 28849)
@@ -272,6 +272,48 @@
 GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
 
 
+/* ************* convenience API to lookup an ego ***************** */
+
+/**
+ * Function called with the result.
+ *
+ * @param cls closure
+ * @param ego NULL on error / ego not found
+ */ 
+typedef void (*GNUNET_IDENTITY_EgoCallback)(void *cls,
+                                           const struct GNUNET_IDENTITY_Ego 
*ego);
+
+/**
+ * Handle for ego lookup.
+ */ 
+struct GNUNET_IDENTITY_EgoLookup;
+
+
+/**
+ * Lookup an ego by name.
+ *
+ * @param cfg configuration to use
+ * @param name name to look up
+ * @param cb callback to invoke with the result
+ * @param cb_cls closure for @a cb
+ * @return NULL on error
+ */
+struct GNUNET_IDENTITY_EgoLookup *
+GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                           const char *name,
+                           GNUNET_IDENTITY_EgoCallback cb,
+                           void *cb_cls);
+
+
+/**
+ * Abort ego lookup attempt.
+ *
+ * @param el handle for lookup to abort
+ */
+void
+GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el);
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]