2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file identity/identity_api_lookup.c
21 * @brief api to lookup an ego
22 * @author Christian Grothoff
25 #include "gnunet_util_lib.h"
26 #include "gnunet_identity_service.h"
28 #define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__)
32 * Handle for ego lookup.
34 struct GNUNET_IDENTITY_EgoLookup
38 * Handle to the identity service.
40 struct GNUNET_IDENTITY_Handle *identity;
43 * Name of the ego we are looking up.
48 * Function to call with the result.
50 GNUNET_IDENTITY_EgoCallback cb;
60 * Method called to inform about the egos of this peer.
62 * When used with #GNUNET_IDENTITY_connect, this function is
63 * initially called for all egos and then again whenever a
64 * ego's name changes or if it is deleted. At the end of
65 * the initial pass over all egos, the function is once called
66 * with 'NULL' for @a ego. That does NOT mean that the callback won't
67 * be invoked in the future or that there was an error.
69 * If the @a name matches the name from @a cls, we found the zone
70 * for our computation and will invoke the callback.
71 * If we have iterated over all egos and not found the name, we
72 * invoke the callback with NULL.
74 * @param cls closure with the `struct GNUNET_IDENTITY_EgoLookup`
75 * @param ego ego handle
76 * @param ctx context for application to store data for this ego
77 * (during the lifetime of this process, initially NULL)
78 * @param name name assigned by the user for this ego,
79 * NULL if the user just deleted the ego and it
80 * must thus no longer be used
83 identity_cb (void *cls,
84 struct GNUNET_IDENTITY_Ego *ego,
88 struct GNUNET_IDENTITY_EgoLookup *el = cls;
90 if ( (NULL != name) &&
96 GNUNET_IDENTITY_ego_lookup_cancel (el);
104 GNUNET_IDENTITY_ego_lookup_cancel (el);
111 * Lookup an ego by name.
113 * @param cfg configuration to use
114 * @param name name to look up
115 * @param cb callback to invoke with the result
116 * @param cb_cls closure for @a cb
117 * @return NULL on error
119 struct GNUNET_IDENTITY_EgoLookup *
120 GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
122 GNUNET_IDENTITY_EgoCallback cb,
125 struct GNUNET_IDENTITY_EgoLookup *el;
127 el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup);
128 el->name = GNUNET_strdup (name);
131 el->identity = GNUNET_IDENTITY_connect (cfg,
134 if (NULL == el->identity)
136 GNUNET_free (el->name);
145 * Abort ego lookup attempt.
147 * @param el handle for lookup to abort
150 GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el)
152 GNUNET_IDENTITY_disconnect (el->identity);
153 GNUNET_free (el->name);
158 /* end of identity_api_lookup.c */