diff options
Diffstat (limited to 'src/identity/identity_api_suffix_lookup.c')
-rw-r--r-- | src/identity/identity_api_suffix_lookup.c | 120 |
1 files changed, 62 insertions, 58 deletions
diff --git a/src/identity/identity_api_suffix_lookup.c b/src/identity/identity_api_suffix_lookup.c index 51d8f39a6..2667ddbc8 100644 --- a/src/identity/identity_api_suffix_lookup.c +++ b/src/identity/identity_api_suffix_lookup.c | |||
@@ -28,13 +28,14 @@ | |||
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 | */ |
37 | struct GNUNET_IDENTITY_EgoSuffixLookup { | 37 | struct GNUNET_IDENTITY_EgoSuffixLookup |
38 | { | ||
38 | /** | 39 | /** |
39 | * Connection to service. | 40 | * Connection to service. |
40 | */ | 41 | */ |
@@ -66,11 +67,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup { | |||
66 | * @return #GNUNET_OK if the message is well-formed | 67 | * @return #GNUNET_OK if the message is well-formed |
67 | */ | 68 | */ |
68 | static int | 69 | static int |
69 | check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) | 70 | check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) |
70 | { | 71 | { |
71 | (void)cls; | 72 | (void) cls; |
72 | if (sizeof(*rcm) != htons(rcm->header.size)) | 73 | if (sizeof(*rcm) != htons (rcm->header.size)) |
73 | GNUNET_MQ_check_zero_termination(rcm); | 74 | GNUNET_MQ_check_zero_termination (rcm); |
74 | return GNUNET_OK; | 75 | return GNUNET_OK; |
75 | } | 76 | } |
76 | 77 | ||
@@ -82,13 +83,13 @@ check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) | |||
82 | * @param rcm result message received | 83 | * @param rcm result message received |
83 | */ | 84 | */ |
84 | static void | 85 | static void |
85 | handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) | 86 | handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) |
86 | { | 87 | { |
87 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 88 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
88 | 89 | ||
89 | (void)rcm; | 90 | (void) rcm; |
90 | el->cb(el->cb_cls, NULL, NULL); | 91 | el->cb (el->cb_cls, NULL, NULL); |
91 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); | 92 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); |
92 | } | 93 | } |
93 | 94 | ||
94 | 95 | ||
@@ -100,19 +101,19 @@ handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) | |||
100 | * @return #GNUNET_OK if the message is well-formed | 101 | * @return #GNUNET_OK if the message is well-formed |
101 | */ | 102 | */ |
102 | static int | 103 | static int |
103 | check_identity_update(void *cls, const struct UpdateMessage *um) | 104 | check_identity_update (void *cls, const struct UpdateMessage *um) |
104 | { | 105 | { |
105 | uint16_t size = ntohs(um->header.size); | 106 | uint16_t size = ntohs (um->header.size); |
106 | uint16_t name_len = ntohs(um->name_len); | 107 | uint16_t name_len = ntohs (um->name_len); |
107 | const char *str = (const char *)&um[1]; | 108 | const char *str = (const char *) &um[1]; |
108 | 109 | ||
109 | (void)cls; | 110 | (void) cls; |
110 | if ((size != name_len + sizeof(struct UpdateMessage)) || | 111 | if ((size != name_len + sizeof(struct UpdateMessage)) || |
111 | ((0 != name_len) && ('\0' != str[name_len - 1]))) | 112 | ((0 != name_len) && ('\0' != str[name_len - 1]))) |
112 | { | 113 | { |
113 | GNUNET_break(0); | 114 | GNUNET_break (0); |
114 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
115 | } | 116 | } |
116 | return GNUNET_OK; | 117 | return GNUNET_OK; |
117 | } | 118 | } |
118 | 119 | ||
@@ -124,14 +125,14 @@ check_identity_update(void *cls, const struct UpdateMessage *um) | |||
124 | * @param um message received | 125 | * @param um message received |
125 | */ | 126 | */ |
126 | static void | 127 | static void |
127 | handle_identity_update(void *cls, const struct UpdateMessage *um) | 128 | handle_identity_update (void *cls, const struct UpdateMessage *um) |
128 | { | 129 | { |
129 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 130 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
130 | uint16_t name_len = ntohs(um->name_len); | 131 | uint16_t name_len = ntohs (um->name_len); |
131 | const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; | 132 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; |
132 | 133 | ||
133 | el->cb(el->cb_cls, &um->private_key, str); | 134 | el->cb (el->cb_cls, &um->private_key, str); |
134 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); | 135 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); |
135 | } | 136 | } |
136 | 137 | ||
137 | 138 | ||
@@ -144,13 +145,13 @@ handle_identity_update(void *cls, const struct UpdateMessage *um) | |||
144 | * @param error error code | 145 | * @param error error code |
145 | */ | 146 | */ |
146 | static void | 147 | static void |
147 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 148 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
148 | { | 149 | { |
149 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 150 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
150 | 151 | ||
151 | (void)error; | 152 | (void) error; |
152 | el->cb(el->cb_cls, NULL, NULL); | 153 | el->cb (el->cb_cls, NULL, NULL); |
153 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); | 154 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
@@ -164,46 +165,48 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
164 | * @return NULL on error | 165 | * @return NULL on error |
165 | */ | 166 | */ |
166 | struct GNUNET_IDENTITY_EgoSuffixLookup * | 167 | struct GNUNET_IDENTITY_EgoSuffixLookup * |
167 | GNUNET_IDENTITY_ego_lookup_by_suffix(const struct GNUNET_CONFIGURATION_Handle *cfg, | 168 | GNUNET_IDENTITY_ego_lookup_by_suffix (const struct |
168 | const char *suffix, | 169 | GNUNET_CONFIGURATION_Handle *cfg, |
169 | GNUNET_IDENTITY_EgoSuffixCallback cb, | 170 | const char *suffix, |
170 | void *cb_cls) | 171 | GNUNET_IDENTITY_EgoSuffixCallback cb, |
172 | void *cb_cls) | ||
171 | { | 173 | { |
172 | struct GNUNET_IDENTITY_EgoSuffixLookup *el; | 174 | struct GNUNET_IDENTITY_EgoSuffixLookup *el; |
173 | struct GNUNET_MQ_Envelope *env; | 175 | struct GNUNET_MQ_Envelope *env; |
174 | struct GNUNET_MessageHeader *req; | 176 | struct GNUNET_MessageHeader *req; |
175 | size_t nlen; | 177 | size_t nlen; |
176 | 178 | ||
177 | GNUNET_assert(NULL != cb); | 179 | GNUNET_assert (NULL != cb); |
178 | el = GNUNET_new(struct GNUNET_IDENTITY_EgoSuffixLookup); | 180 | el = GNUNET_new (struct GNUNET_IDENTITY_EgoSuffixLookup); |
179 | el->cb = cb; | 181 | el->cb = cb; |
180 | el->cb_cls = cb_cls; | 182 | el->cb_cls = cb_cls; |
181 | { | 183 | { |
182 | struct GNUNET_MQ_MessageHandler handlers[] = | 184 | struct GNUNET_MQ_MessageHandler handlers[] = |
183 | { GNUNET_MQ_hd_var_size(identity_result_code, | 185 | { GNUNET_MQ_hd_var_size (identity_result_code, |
184 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, | 186 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, |
185 | struct ResultCodeMessage, | 187 | struct ResultCodeMessage, |
186 | el), | 188 | el), |
187 | GNUNET_MQ_hd_var_size(identity_update, | 189 | GNUNET_MQ_hd_var_size (identity_update, |
188 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, | 190 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, |
189 | struct UpdateMessage, | 191 | struct UpdateMessage, |
190 | el), | 192 | el), |
191 | GNUNET_MQ_handler_end() }; | 193 | GNUNET_MQ_handler_end () }; |
192 | 194 | ||
193 | el->mq = | 195 | el->mq = |
194 | GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el); | 196 | GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); |
195 | } | 197 | } |
196 | if (NULL == el->mq) | 198 | if (NULL == el->mq) |
197 | { | 199 | { |
198 | GNUNET_break(0); | 200 | GNUNET_break (0); |
199 | GNUNET_free(el); | 201 | GNUNET_free (el); |
200 | return NULL; | 202 | return NULL; |
201 | } | 203 | } |
202 | el->suffix = GNUNET_strdup(suffix); | 204 | el->suffix = GNUNET_strdup (suffix); |
203 | nlen = strlen(suffix) + 1; | 205 | nlen = strlen (suffix) + 1; |
204 | env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); | 206 | env = GNUNET_MQ_msg_extra (req, nlen, |
205 | memcpy(&req[1], suffix, nlen); | 207 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); |
206 | GNUNET_MQ_send(el->mq, env); | 208 | memcpy (&req[1], suffix, nlen); |
209 | GNUNET_MQ_send (el->mq, env); | ||
207 | return el; | 210 | return el; |
208 | } | 211 | } |
209 | 212 | ||
@@ -214,11 +217,12 @@ GNUNET_IDENTITY_ego_lookup_by_suffix(const struct GNUNET_CONFIGURATION_Handle *c | |||
214 | * @param el handle for lookup to abort | 217 | * @param el handle for lookup to abort |
215 | */ | 218 | */ |
216 | void | 219 | void |
217 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(struct GNUNET_IDENTITY_EgoSuffixLookup *el) | 220 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (struct |
221 | GNUNET_IDENTITY_EgoSuffixLookup *el) | ||
218 | { | 222 | { |
219 | GNUNET_MQ_destroy(el->mq); | 223 | GNUNET_MQ_destroy (el->mq); |
220 | GNUNET_free(el->suffix); | 224 | GNUNET_free (el->suffix); |
221 | GNUNET_free(el); | 225 | GNUNET_free (el); |
222 | } | 226 | } |
223 | 227 | ||
224 | 228 | ||