aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gns_tld_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/gns/gns_tld_api.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/gns/gns_tld_api.c')
-rw-r--r--src/gns/gns_tld_api.c233
1 files changed, 117 insertions, 116 deletions
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c
index 0692199e3..e646efc3e 100644
--- a/src/gns/gns_tld_api.c
+++ b/src/gns/gns_tld_api.c
@@ -35,13 +35,14 @@
35#include "gns_api.h" 35#include "gns_api.h"
36 36
37 37
38#define LOG(kind, ...) GNUNET_log_from(kind, "gns-tld-api", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "gns-tld-api", __VA_ARGS__)
39 39
40 40
41/** 41/**
42 * Handle to a lookup request 42 * Handle to a lookup request
43 */ 43 */
44struct GNUNET_GNS_LookupWithTldRequest { 44struct GNUNET_GNS_LookupWithTldRequest
45{
45 /** 46 /**
46 * handle to gns 47 * handle to gns
47 */ 48 */
@@ -103,11 +104,11 @@ struct GNUNET_GNS_LookupWithTldRequest {
103 * or @a name if @a name does not contain a "." 104 * or @a name if @a name does not contain a "."
104 */ 105 */
105static const char * 106static const char *
106get_tld(const char *name) 107get_tld (const char *name)
107{ 108{
108 const char *tld; 109 const char *tld;
109 110
110 tld = strrchr(name, (unsigned char)'.'); 111 tld = strrchr (name, (unsigned char) '.');
111 if (NULL == tld) 112 if (NULL == tld)
112 tld = name; 113 tld = name;
113 else 114 else
@@ -123,18 +124,18 @@ get_tld(const char *name)
123 * @param tld what to eat (can be more than just the tld) 124 * @param tld what to eat (can be more than just the tld)
124 */ 125 */
125static void 126static void
126eat_tld(char *name, const char *tld) 127eat_tld (char *name, const char *tld)
127{ 128{
128 GNUNET_assert(0 < strlen(name)); 129 GNUNET_assert (0 < strlen (name));
129 if ((NULL == tld) || (strlen(name) == strlen(tld))) 130 if ((NULL == tld) || (strlen (name) == strlen (tld)))
130 { 131 {
131 strcpy(name, GNUNET_GNS_EMPTY_LABEL_AT); 132 strcpy (name, GNUNET_GNS_EMPTY_LABEL_AT);
132 } 133 }
133 else 134 else
134 { 135 {
135 GNUNET_assert(strlen(tld) < strlen(name)); 136 GNUNET_assert (strlen (tld) < strlen (name));
136 name[strlen(name) - strlen(tld) - 1] = '\0'; 137 name[strlen (name) - strlen (tld) - 1] = '\0';
137 } 138 }
138} 139}
139 140
140 141
@@ -146,15 +147,15 @@ eat_tld(char *name, const char *tld)
146 * @param rd array of @a rd_count records with the results 147 * @param rd array of @a rd_count records with the results
147 */ 148 */
148static void 149static void
149process_lookup_result(void *cls, 150process_lookup_result (void *cls,
150 uint32_t rd_count, 151 uint32_t rd_count,
151 const struct GNUNET_GNSRECORD_Data *rd) 152 const struct GNUNET_GNSRECORD_Data *rd)
152{ 153{
153 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; 154 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
154 155
155 ltr->lr = NULL; 156 ltr->lr = NULL;
156 ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd); 157 ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd);
157 GNUNET_GNS_lookup_with_tld_cancel(ltr); 158 GNUNET_GNS_lookup_with_tld_cancel (ltr);
158} 159}
159 160
160 161
@@ -165,16 +166,16 @@ process_lookup_result(void *cls,
165 * @param pkey public key to use for the zone, can be NULL 166 * @param pkey public key to use for the zone, can be NULL
166 */ 167 */
167static void 168static void
168lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr, 169lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr,
169 const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) 170 const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
170{ 171{
171 ltr->lr = GNUNET_GNS_lookup(ltr->gns_handle, 172 ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle,
172 ltr->name, 173 ltr->name,
173 pkey, 174 pkey,
174 ltr->type, 175 ltr->type,
175 ltr->options, 176 ltr->options,
176 &process_lookup_result, 177 &process_lookup_result,
177 ltr); 178 ltr);
178} 179}
179 180
180 181
@@ -188,38 +189,38 @@ lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr,
188 * @param name name of the ego 189 * @param name name of the ego
189 */ 190 */
190static void 191static void
191identity_zone_cb(void *cls, 192identity_zone_cb (void *cls,
192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 193 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
193 const char *ego_name) 194 const char *ego_name)
194{ 195{
195 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; 196 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
196 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 197 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
197 198
198 ltr->id_co = NULL; 199 ltr->id_co = NULL;
199 if (NULL == priv) 200 if (NULL == priv)
200 { 201 {
201 /* no matching ego found */ 202 /* no matching ego found */
202 ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); 203 ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL);
203 return; 204 return;
204 } 205 }
205 /* Final case: TLD matches one of our egos */ 206 /* Final case: TLD matches one of our egos */
206 if (0 == strcmp(ltr->name, ego_name)) 207 if (0 == strcmp (ltr->name, ego_name))
207 { 208 {
208 /* name matches ego name perfectly, only "@" remains */ 209 /* name matches ego name perfectly, only "@" remains */
209 strcpy(ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); 210 strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT);
210 } 211 }
211 else 212 else
212 { 213 {
213 GNUNET_assert(strlen(ego_name) < strlen(ltr->name)); 214 GNUNET_assert (strlen (ego_name) < strlen (ltr->name));
214 ltr->name[strlen(ltr->name) - strlen(ego_name) - 1] = '\0'; 215 ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0';
215 } 216 }
216 /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ 217 /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */
217 if (NULL == strchr(ltr->name, (unsigned char)'.')) 218 if (NULL == strchr (ltr->name, (unsigned char) '.'))
218 ltr->options = GNUNET_GNS_LO_NO_DHT; 219 ltr->options = GNUNET_GNS_LO_NO_DHT;
219 else 220 else
220 ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; 221 ltr->options = GNUNET_GNS_LO_LOCAL_MASTER;
221 GNUNET_CRYPTO_ecdsa_key_get_public(priv, &pkey); 222 GNUNET_CRYPTO_ecdsa_key_get_public (priv, &pkey);
222 lookup_with_public_key(ltr, &pkey); 223 lookup_with_public_key (ltr, &pkey);
223} 224}
224 225
225 226
@@ -237,12 +238,12 @@ identity_zone_cb(void *cls,
237 * @return handle to the get request, NULL on error (i.e. bad configuration) 238 * @return handle to the get request, NULL on error (i.e. bad configuration)
238 */ 239 */
239struct GNUNET_GNS_LookupWithTldRequest * 240struct GNUNET_GNS_LookupWithTldRequest *
240GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, 241GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
241 const char *name, 242 const char *name,
242 uint32_t type, 243 uint32_t type,
243 enum GNUNET_GNS_LocalOptions options, 244 enum GNUNET_GNS_LocalOptions options,
244 GNUNET_GNS_LookupResultProcessor2 proc, 245 GNUNET_GNS_LookupResultProcessor2 proc,
245 void *proc_cls) 246 void *proc_cls)
246{ 247{
247 struct GNUNET_GNS_LookupWithTldRequest *ltr; 248 struct GNUNET_GNS_LookupWithTldRequest *ltr;
248 const char *tld; 249 const char *tld;
@@ -250,70 +251,70 @@ GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle,
250 char *zonestr; 251 char *zonestr;
251 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 252 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
252 253
253 ltr = GNUNET_new(struct GNUNET_GNS_LookupWithTldRequest); 254 ltr = GNUNET_new (struct GNUNET_GNS_LookupWithTldRequest);
254 ltr->gns_handle = handle; 255 ltr->gns_handle = handle;
255 ltr->name = GNUNET_strdup(name); 256 ltr->name = GNUNET_strdup (name);
256 ltr->type = type; 257 ltr->type = type;
257 ltr->options = options; 258 ltr->options = options;
258 ltr->lookup_proc = proc; 259 ltr->lookup_proc = proc;
259 ltr->lookup_proc_cls = proc_cls; 260 ltr->lookup_proc_cls = proc_cls;
260 /* start with trivial case: TLD is zkey */ 261 /* start with trivial case: TLD is zkey */
261 tld = get_tld(ltr->name); 262 tld = get_tld (ltr->name);
262 if (GNUNET_OK == 263 if (GNUNET_OK ==
263 GNUNET_CRYPTO_ecdsa_public_key_from_string(tld, strlen(tld), &pkey)) 264 GNUNET_CRYPTO_ecdsa_public_key_from_string (tld, strlen (tld), &pkey))
264 { 265 {
265 eat_tld(ltr->name, tld); 266 eat_tld (ltr->name, tld);
266 lookup_with_public_key(ltr, &pkey); 267 lookup_with_public_key (ltr, &pkey);
267 return ltr; 268 return ltr;
268 } 269 }
269 270
270 /* second case: domain is mapped in our configuration file */ 271 /* second case: domain is mapped in our configuration file */
271 for (const char *domain = name; NULL != domain; 272 for (const char *domain = name; NULL != domain;
272 domain = strchr(domain, (unsigned char)'.')) 273 domain = strchr (domain, (unsigned char) '.'))
274 {
275 if ('.' == domain[0])
276 domain++;
277 GNUNET_asprintf (&dot_tld, ".%s", domain);
278 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (handle->cfg,
279 "gns",
280 dot_tld,
281 &zonestr))
273 { 282 {
274 if ('.' == domain[0]) 283 if (GNUNET_OK !=
275 domain++; 284 GNUNET_CRYPTO_ecdsa_public_key_from_string (zonestr,
276 GNUNET_asprintf(&dot_tld, ".%s", domain); 285 strlen (zonestr),
277 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(handle->cfg, 286 &pkey))
278 "gns", 287 {
279 dot_tld, 288 GNUNET_log_config_invalid (
280 &zonestr)) 289 GNUNET_ERROR_TYPE_ERROR,
281 { 290 "gns",
282 if (GNUNET_OK != 291 dot_tld,
283 GNUNET_CRYPTO_ecdsa_public_key_from_string(zonestr, 292 _ ("Expected a base32-encoded public zone key\n"));
284 strlen(zonestr), 293 GNUNET_free (zonestr);
285 &pkey)) 294 GNUNET_free (dot_tld);
286 { 295 GNUNET_free (ltr->name);
287 GNUNET_log_config_invalid( 296 GNUNET_free (ltr);
288 GNUNET_ERROR_TYPE_ERROR, 297 return NULL;
289 "gns", 298 }
290 dot_tld, 299 eat_tld (ltr->name, &dot_tld[1]);
291 _("Expected a base32-encoded public zone key\n")); 300 GNUNET_free (zonestr);
292 GNUNET_free(zonestr); 301 GNUNET_free (dot_tld);
293 GNUNET_free(dot_tld); 302 lookup_with_public_key (ltr, &pkey);
294 GNUNET_free(ltr->name); 303 return ltr;
295 GNUNET_free(ltr);
296 return NULL;
297 }
298 eat_tld(ltr->name, &dot_tld[1]);
299 GNUNET_free(zonestr);
300 GNUNET_free(dot_tld);
301 lookup_with_public_key(ltr, &pkey);
302 return ltr;
303 }
304 GNUNET_free(dot_tld);
305 } 304 }
305 GNUNET_free (dot_tld);
306 }
306 ltr->id_co = 307 ltr->id_co =
307 GNUNET_IDENTITY_ego_lookup_by_suffix(ltr->gns_handle->cfg, 308 GNUNET_IDENTITY_ego_lookup_by_suffix (ltr->gns_handle->cfg,
308 ltr->name, 309 ltr->name,
309 &identity_zone_cb, 310 &identity_zone_cb,
310 ltr); 311 ltr);
311 if (NULL == ltr->id_co) 312 if (NULL == ltr->id_co)
312 { 313 {
313 GNUNET_free(ltr->name); 314 GNUNET_free (ltr->name);
314 GNUNET_free(ltr); 315 GNUNET_free (ltr);
315 return NULL; 316 return NULL;
316 } 317 }
317 return ltr; 318 return ltr;
318} 319}
319 320
@@ -325,23 +326,23 @@ GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle,
325 * @return closure from the lookup result processor 326 * @return closure from the lookup result processor
326 */ 327 */
327void * 328void *
328GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr) 329GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr)
329{ 330{
330 void *ret = ltr->lookup_proc_cls; 331 void *ret = ltr->lookup_proc_cls;
331 332
332 if (NULL != ltr->id_co) 333 if (NULL != ltr->id_co)
333 { 334 {
334 GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(ltr->id_co); 335 GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (ltr->id_co);
335 ltr->id_co = NULL; 336 ltr->id_co = NULL;
336 } 337 }
337 if (NULL != ltr->lr) 338 if (NULL != ltr->lr)
338 { 339 {
339 GNUNET_GNS_lookup_cancel(ltr->lr); 340 GNUNET_GNS_lookup_cancel (ltr->lr);
340 ltr->lr = NULL; 341 ltr->lr = NULL;
341 } 342 }
342 GNUNET_free_non_null(ltr->longest_match); 343 GNUNET_free_non_null (ltr->longest_match);
343 GNUNET_free(ltr->name); 344 GNUNET_free (ltr->name);
344 GNUNET_free(ltr); 345 GNUNET_free (ltr);
345 return ret; 346 return ret;
346} 347}
347 348