diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-10-26 22:13:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-10-26 22:13:01 +0000 |
commit | 64d3e46cfb99a711e500fa1f114e7c44bdf10040 (patch) | |
tree | 83093d92761d5c1b8b2fded713adaa19af29274c /src/gns/gnunet-gns.c | |
parent | ef6f05f63769263a5201636c4b7f71eaa455cdf3 (diff) | |
download | gnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.tar.gz gnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.zip |
-bugfixes, code cleanup
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r-- | src/gns/gnunet-gns.c | 84 |
1 files changed, 62 insertions, 22 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 068a9266e..ba30b56fb 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -44,7 +44,6 @@ static char *shorten_name; | |||
44 | */ | 44 | */ |
45 | static char *lookup_name; | 45 | static char *lookup_name; |
46 | 46 | ||
47 | |||
48 | /** | 47 | /** |
49 | * record type to look up (-t option) | 48 | * record type to look up (-t option) |
50 | */ | 49 | */ |
@@ -60,15 +59,24 @@ static char *auth_name; | |||
60 | */ | 59 | */ |
61 | static int raw; | 60 | static int raw; |
62 | 61 | ||
62 | /** | ||
63 | * Requested record type. | ||
64 | */ | ||
63 | static enum GNUNET_GNS_RecordType rtype; | 65 | static enum GNUNET_GNS_RecordType rtype; |
64 | 66 | ||
65 | /* Handle to lookup request */ | 67 | /** |
68 | * Handle to lookup request | ||
69 | */ | ||
66 | static struct GNUNET_GNS_LookupRequest *lookup_request; | 70 | static struct GNUNET_GNS_LookupRequest *lookup_request; |
67 | 71 | ||
68 | /* Handle to shorten request */ | 72 | /** |
73 | * Handle to shorten request | ||
74 | */ | ||
69 | static struct GNUNET_GNS_ShortenRequest *shorten_request; | 75 | static struct GNUNET_GNS_ShortenRequest *shorten_request; |
70 | 76 | ||
71 | /* Handle to get authority request */ | 77 | /** |
78 | * Handle to get authority request | ||
79 | */ | ||
72 | static struct GNUNET_GNS_GetAuthRequest *getauth_request; | 80 | static struct GNUNET_GNS_GetAuthRequest *getauth_request; |
73 | 81 | ||
74 | 82 | ||
@@ -83,21 +91,37 @@ do_shutdown (void *cls, | |||
83 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 91 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
84 | { | 92 | { |
85 | if (NULL != lookup_request) | 93 | if (NULL != lookup_request) |
94 | { | ||
86 | GNUNET_GNS_cancel_lookup_request (lookup_request); | 95 | GNUNET_GNS_cancel_lookup_request (lookup_request); |
87 | 96 | lookup_request = NULL; | |
97 | } | ||
88 | if (NULL != shorten_request) | 98 | if (NULL != shorten_request) |
99 | { | ||
89 | GNUNET_GNS_cancel_shorten_request (shorten_request); | 100 | GNUNET_GNS_cancel_shorten_request (shorten_request); |
90 | 101 | shorten_request = NULL; | |
102 | } | ||
91 | if (NULL != getauth_request) | 103 | if (NULL != getauth_request) |
104 | { | ||
92 | GNUNET_GNS_cancel_get_auth_request (getauth_request); | 105 | GNUNET_GNS_cancel_get_auth_request (getauth_request); |
93 | 106 | getauth_request = NULL; | |
107 | } | ||
94 | if (NULL != gns) | 108 | if (NULL != gns) |
109 | { | ||
95 | GNUNET_GNS_disconnect (gns); | 110 | GNUNET_GNS_disconnect (gns); |
111 | gns = NULL; | ||
112 | } | ||
96 | } | 113 | } |
97 | 114 | ||
98 | 115 | ||
116 | /** | ||
117 | * Function called with the result of a shorten operation. | ||
118 | * Prints the result. | ||
119 | * | ||
120 | * @param cls a 'const char *' with the original (long) name | ||
121 | * @param nshort the shortened name | ||
122 | */ | ||
99 | static void | 123 | static void |
100 | process_shorten_result (void* cls, const char* nshort) | 124 | process_shorten_result (void* cls, const char *nshort) |
101 | { | 125 | { |
102 | const char *original_name = cls; | 126 | const char *original_name = cls; |
103 | 127 | ||
@@ -110,6 +134,13 @@ process_shorten_result (void* cls, const char* nshort) | |||
110 | } | 134 | } |
111 | 135 | ||
112 | 136 | ||
137 | /** | ||
138 | * Function called with the result of a GADS lookup. | ||
139 | * | ||
140 | * @param cls the 'const char *' name that was resolved | ||
141 | * @param rd_count number of records returned | ||
142 | * @param rd array of 'rd_count' records with the results | ||
143 | */ | ||
113 | static void | 144 | static void |
114 | process_lookup_result (void* cls, uint32_t rd_count, | 145 | process_lookup_result (void* cls, uint32_t rd_count, |
115 | const struct GNUNET_NAMESTORE_RecordData *rd) | 146 | const struct GNUNET_NAMESTORE_RecordData *rd) |
@@ -122,7 +153,7 @@ process_lookup_result (void* cls, uint32_t rd_count, | |||
122 | lookup_request = NULL; | 153 | lookup_request = NULL; |
123 | if (!raw) | 154 | if (!raw) |
124 | { | 155 | { |
125 | if (rd_count == 0) | 156 | if (0 == rd_count) |
126 | printf("No results.\n"); | 157 | printf("No results.\n"); |
127 | else | 158 | else |
128 | printf("%s:\n", name); | 159 | printf("%s:\n", name); |
@@ -143,8 +174,16 @@ process_lookup_result (void* cls, uint32_t rd_count, | |||
143 | } | 174 | } |
144 | 175 | ||
145 | 176 | ||
177 | /** | ||
178 | * Function called with the result of an authority lookup. | ||
179 | * | ||
180 | * @param cls the 'const char *' with the name for which the | ||
181 | * authority was resolved | ||
182 | * @param auth name of the authority | ||
183 | */ | ||
146 | static void | 184 | static void |
147 | process_auth_result (void* cls, const char* auth) | 185 | process_auth_result (void* cls, |
186 | const char *auth) | ||
148 | { | 187 | { |
149 | getauth_request = NULL; | 188 | getauth_request = NULL; |
150 | printf ("%s\n", auth); | 189 | printf ("%s\n", auth); |
@@ -254,14 +293,16 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
254 | else | 293 | else |
255 | rtype = GNUNET_GNS_RECORD_A; | 294 | rtype = GNUNET_GNS_RECORD_A; |
256 | 295 | ||
257 | if ((NULL != shorten_name) && (NULL != shorten_zone) && (NULL != private_zone)) | 296 | if ( (NULL != shorten_name) && |
297 | (NULL != shorten_zone) && | ||
298 | (NULL != private_zone) ) | ||
258 | { | 299 | { |
259 | shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name, | 300 | shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name, |
260 | private_zone, | 301 | private_zone, |
261 | shorten_zone, | 302 | shorten_zone, |
262 | zone, | 303 | zone, |
263 | &process_shorten_result, | 304 | &process_shorten_result, |
264 | shorten_name); | 305 | shorten_name); |
265 | } | 306 | } |
266 | if (NULL != lookup_name) | 307 | if (NULL != lookup_name) |
267 | { | 308 | { |
@@ -270,7 +311,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
270 | rtype, | 311 | rtype, |
271 | GNUNET_NO, /* Use DHT */ | 312 | GNUNET_NO, /* Use DHT */ |
272 | shorten_key, | 313 | shorten_key, |
273 | &process_lookup_result, lookup_name); | 314 | &process_lookup_result, |
315 | lookup_name); | ||
274 | } | 316 | } |
275 | if (NULL != auth_name) | 317 | if (NULL != auth_name) |
276 | { | 318 | { |
@@ -285,16 +327,15 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
285 | if (NULL != private_zone) | 327 | if (NULL != private_zone) |
286 | GNUNET_free (private_zone); | 328 | GNUNET_free (private_zone); |
287 | 329 | ||
288 | if ((NULL == auth_name) && | 330 | if ( (NULL == auth_name) && |
289 | (NULL == shorten_name) && | 331 | (NULL == shorten_name) && |
290 | (NULL == lookup_name)) | 332 | (NULL == lookup_name)) |
291 | { | 333 | { |
292 | fprintf (stderr, | 334 | fprintf (stderr, |
293 | _("Please specify lookup, shorten or authority operation!\n")); | 335 | _("Please specify lookup, shorten or authority operation!\n")); |
294 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 336 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
295 | return; | 337 | return; |
296 | } | 338 | } |
297 | |||
298 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 339 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
299 | &do_shutdown, NULL); | 340 | &do_shutdown, NULL); |
300 | } | 341 | } |
@@ -328,7 +369,6 @@ main (int argc, char *const *argv) | |||
328 | &GNUNET_GETOPT_set_one, &raw}, | 369 | &GNUNET_GETOPT_set_one, &raw}, |
329 | GNUNET_GETOPT_OPTION_END | 370 | GNUNET_GETOPT_OPTION_END |
330 | }; | 371 | }; |
331 | |||
332 | int ret; | 372 | int ret; |
333 | 373 | ||
334 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 374 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |