2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public Liceidentity as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public Liceidentity for more details.
15 You should have received a copy of the GNU General Public Liceidentity
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file identity/identity_api_lookup.c
23 * @brief api to lookup an ego
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_identity_service.h"
30 #define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
34 * Handle for ego lookup.
36 struct GNUNET_IDENTITY_EgoLookup
40 * Handle to the identity service.
42 struct GNUNET_IDENTITY_Handle *identity;
45 * Name of the ego we are looking up.
50 * Function to call with the result.
52 GNUNET_IDENTITY_EgoCallback cb;
62 * Method called to inform about the egos of this peer.
64 * When used with #GNUNET_IDENTITY_connect, this function is
65 * initially called for all egos and then again whenever a
66 * ego's name changes or if it is deleted. At the end of
67 * the initial pass over all egos, the function is once called
68 * with 'NULL' for @a ego. That does NOT mean that the callback won't
69 * be invoked in the future or that there was an error.
71 * If the @a name matches the name from @a cls, we found the zone
72 * for our computation and will invoke the callback.
73 * If we have iterated over all egos and not found the name, we
74 * invoke the callback with NULL.
76 * @param cls closure with the `struct GNUNET_IDENTITY_EgoLookup`
77 * @param ego ego handle
78 * @param ctx context for application to store data for this ego
79 * (during the lifetime of this process, initially NULL)
80 * @param name name assigned by the user for this ego,
81 * NULL if the user just deleted the ego and it
82 * must thus no longer be used
85 identity_cb (void *cls,
86 struct GNUNET_IDENTITY_Ego *ego,
90 struct GNUNET_IDENTITY_EgoLookup *el = cls;
92 if ( (NULL != name) &&
98 GNUNET_IDENTITY_ego_lookup_cancel (el);
106 GNUNET_IDENTITY_ego_lookup_cancel (el);
113 * Lookup an ego by name.
115 * @param cfg configuration to use
116 * @param name name to look up
117 * @param cb callback to invoke with the result
118 * @param cb_cls closure for @a cb
119 * @return NULL on error
121 struct GNUNET_IDENTITY_EgoLookup *
122 GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
124 GNUNET_IDENTITY_EgoCallback cb,
127 struct GNUNET_IDENTITY_EgoLookup *el;
129 el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup);
130 el->name = GNUNET_strdup (name);
133 el->identity = GNUNET_IDENTITY_connect (cfg,
141 * Abort ego lookup attempt.
143 * @param el handle for lookup to abort
146 GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el)
148 GNUNET_IDENTITY_disconnect (el->identity);
149 GNUNET_free (el->name);
154 /* end of identity_api_lookup.c */