summaryrefslogtreecommitdiff
path: root/src/identity/identity_api_lookup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/identity_api_lookup.c')
-rw-r--r--src/identity/identity_api_lookup.c122
1 files changed, 60 insertions, 62 deletions
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c
index 56ebf6f47..faf647c07 100644
--- a/src/identity/identity_api_lookup.c
+++ b/src/identity/identity_api_lookup.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file identity/identity_api_lookup.c 22 * @file identity/identity_api_lookup.c
@@ -28,15 +28,13 @@
28#include "gnunet_identity_service.h" 28#include "gnunet_identity_service.h"
29#include "identity.h" 29#include "identity.h"
30 30
31#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__)
32 32
33 33
34/** 34/**
35 * Handle for ego lookup. 35 * Handle for ego lookup.
36 */ 36 */
37struct GNUNET_IDENTITY_EgoLookup 37struct GNUNET_IDENTITY_EgoLookup {
38{
39
40 /** 38 /**
41 * Connection to service. 39 * Connection to service.
42 */ 40 */
@@ -68,10 +66,10 @@ struct GNUNET_IDENTITY_EgoLookup
68 * @return #GNUNET_OK if the message is well-formed 66 * @return #GNUNET_OK if the message is well-formed
69 */ 67 */
70static int 68static int
71check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) 69check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
72{ 70{
73 if (sizeof (*rcm) != htons (rcm->header.size)) 71 if (sizeof(*rcm) != htons(rcm->header.size))
74 GNUNET_MQ_check_zero_termination (rcm); 72 GNUNET_MQ_check_zero_termination(rcm);
75 return GNUNET_OK; 73 return GNUNET_OK;
76} 74}
77 75
@@ -83,12 +81,12 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
83 * @param rcm result message received 81 * @param rcm result message received
84 */ 82 */
85static void 83static void
86handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) 84handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
87{ 85{
88 struct GNUNET_IDENTITY_EgoLookup *el = cls; 86 struct GNUNET_IDENTITY_EgoLookup *el = cls;
89 87
90 el->cb (el->cb_cls, NULL); 88 el->cb(el->cb_cls, NULL);
91 GNUNET_IDENTITY_ego_lookup_cancel (el); 89 GNUNET_IDENTITY_ego_lookup_cancel(el);
92} 90}
93 91
94 92
@@ -100,18 +98,18 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
100 * @return #GNUNET_OK if the message is well-formed 98 * @return #GNUNET_OK if the message is well-formed
101 */ 99 */
102static int 100static int
103check_identity_update (void *cls, const struct UpdateMessage *um) 101check_identity_update(void *cls, const struct UpdateMessage *um)
104{ 102{
105 uint16_t size = ntohs (um->header.size); 103 uint16_t size = ntohs(um->header.size);
106 uint16_t name_len = ntohs (um->name_len); 104 uint16_t name_len = ntohs(um->name_len);
107 const char *str = (const char *) &um[1]; 105 const char *str = (const char *)&um[1];
108 106
109 if ((size != name_len + sizeof (struct UpdateMessage)) || 107 if ((size != name_len + sizeof(struct UpdateMessage)) ||
110 ((0 != name_len) && ('\0' != str[name_len - 1]))) 108 ((0 != name_len) && ('\0' != str[name_len - 1])))
111 { 109 {
112 GNUNET_break (0); 110 GNUNET_break(0);
113 return GNUNET_SYSERR; 111 return GNUNET_SYSERR;
114 } 112 }
115 return GNUNET_OK; 113 return GNUNET_OK;
116} 114}
117 115
@@ -123,23 +121,23 @@ check_identity_update (void *cls, const struct UpdateMessage *um)
123 * @param um message received 121 * @param um message received
124 */ 122 */
125static void 123static void
126handle_identity_update (void *cls, const struct UpdateMessage *um) 124handle_identity_update(void *cls, const struct UpdateMessage *um)
127{ 125{
128 struct GNUNET_IDENTITY_EgoLookup *el = cls; 126 struct GNUNET_IDENTITY_EgoLookup *el = cls;
129 uint16_t name_len = ntohs (um->name_len); 127 uint16_t name_len = ntohs(um->name_len);
130 const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; 128 const char *str = (0 == name_len) ? NULL : (const char *)&um[1];
131 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 129 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
132 struct GNUNET_HashCode id; 130 struct GNUNET_HashCode id;
133 struct GNUNET_IDENTITY_Ego ego; 131 struct GNUNET_IDENTITY_Ego ego;
134 132
135 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); 133 GNUNET_break(GNUNET_YES != ntohs(um->end_of_list));
136 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); 134 GNUNET_CRYPTO_ecdsa_key_get_public(&um->private_key, &pub);
137 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); 135 GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id);
138 ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key; 136 ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *)&um->private_key;
139 ego.name = (char *) str; 137 ego.name = (char *)str;
140 ego.id = id; 138 ego.id = id;
141 el->cb (el->cb_cls, &ego); 139 el->cb(el->cb_cls, &ego);
142 GNUNET_IDENTITY_ego_lookup_cancel (el); 140 GNUNET_IDENTITY_ego_lookup_cancel(el);
143} 141}
144 142
145 143
@@ -152,11 +150,11 @@ handle_identity_update (void *cls, const struct UpdateMessage *um)
152 * @param error error code 150 * @param error error code
153 */ 151 */
154static void 152static void
155mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 153mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
156{ 154{
157 struct GNUNET_IDENTITY_EgoLookup *el = cls; 155 struct GNUNET_IDENTITY_EgoLookup *el = cls;
158 156
159 el->cb (el->cb_cls, NULL); 157 el->cb(el->cb_cls, NULL);
160} 158}
161 159
162 160
@@ -170,46 +168,46 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
170 * @return NULL on error 168 * @return NULL on error
171 */ 169 */
172struct GNUNET_IDENTITY_EgoLookup * 170struct GNUNET_IDENTITY_EgoLookup *
173GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, 171GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg,
174 const char *name, 172 const char *name,
175 GNUNET_IDENTITY_EgoCallback cb, 173 GNUNET_IDENTITY_EgoCallback cb,
176 void *cb_cls) 174 void *cb_cls)
177{ 175{
178 struct GNUNET_IDENTITY_EgoLookup *el; 176 struct GNUNET_IDENTITY_EgoLookup *el;
179 struct GNUNET_MQ_Envelope *env; 177 struct GNUNET_MQ_Envelope *env;
180 struct GNUNET_MessageHeader *req; 178 struct GNUNET_MessageHeader *req;
181 size_t nlen; 179 size_t nlen;
182 180
183 GNUNET_assert (NULL != cb); 181 GNUNET_assert(NULL != cb);
184 el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup); 182 el = GNUNET_new(struct GNUNET_IDENTITY_EgoLookup);
185 el->cb = cb; 183 el->cb = cb;
186 el->cb_cls = cb_cls; 184 el->cb_cls = cb_cls;
187 { 185 {
188 struct GNUNET_MQ_MessageHandler handlers[] = 186 struct GNUNET_MQ_MessageHandler handlers[] =
189 {GNUNET_MQ_hd_var_size (identity_result_code, 187 { GNUNET_MQ_hd_var_size(identity_result_code,
190 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, 188 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
191 struct ResultCodeMessage, 189 struct ResultCodeMessage,
192 el), 190 el),
193 GNUNET_MQ_hd_var_size (identity_update, 191 GNUNET_MQ_hd_var_size(identity_update,
194 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, 192 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
195 struct UpdateMessage, 193 struct UpdateMessage,
196 el), 194 el),
197 GNUNET_MQ_handler_end ()}; 195 GNUNET_MQ_handler_end() };
198 196
199 el->mq = 197 el->mq =
200 GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); 198 GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el);
201 } 199 }
202 if (NULL == el->mq) 200 if (NULL == el->mq)
203 { 201 {
204 GNUNET_break (0); 202 GNUNET_break(0);
205 GNUNET_free (el); 203 GNUNET_free(el);
206 return NULL; 204 return NULL;
207 } 205 }
208 el->name = GNUNET_strdup (name); 206 el->name = GNUNET_strdup(name);
209 nlen = strlen (name) + 1; 207 nlen = strlen(name) + 1;
210 env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP); 208 env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP);
211 memcpy (&req[1], name, nlen); 209 memcpy(&req[1], name, nlen);
212 GNUNET_MQ_send (el->mq, env); 210 GNUNET_MQ_send(el->mq, env);
213 return el; 211 return el;
214} 212}
215 213
@@ -220,11 +218,11 @@ GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
220 * @param el handle for lookup to abort 218 * @param el handle for lookup to abort
221 */ 219 */
222void 220void
223GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el) 221GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
224{ 222{
225 GNUNET_MQ_destroy (el->mq); 223 GNUNET_MQ_destroy(el->mq);
226 GNUNET_free (el->name); 224 GNUNET_free(el->name);
227 GNUNET_free (el); 225 GNUNET_free(el);
228} 226}
229 227
230 228