diff options
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r-- | src/gns/gnunet-gns.c | 250 |
1 files changed, 125 insertions, 125 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index d795f89fc..352ccce04 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.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 | * @file gnunet-gns.c | 21 | * @file gnunet-gns.c |
22 | * @brief command line tool to access distributed GNS | 22 | * @brief command line tool to access distributed GNS |
@@ -90,24 +90,24 @@ static int global_ret; | |||
90 | * @param cls unused | 90 | * @param cls unused |
91 | */ | 91 | */ |
92 | static void | 92 | static void |
93 | do_shutdown (void *cls) | 93 | do_shutdown(void *cls) |
94 | { | 94 | { |
95 | (void) cls; | 95 | (void)cls; |
96 | if (NULL != to_task) | 96 | if (NULL != to_task) |
97 | { | 97 | { |
98 | GNUNET_SCHEDULER_cancel (to_task); | 98 | GNUNET_SCHEDULER_cancel(to_task); |
99 | to_task = NULL; | 99 | to_task = NULL; |
100 | } | 100 | } |
101 | if (NULL != lr) | 101 | if (NULL != lr) |
102 | { | 102 | { |
103 | GNUNET_GNS_lookup_with_tld_cancel (lr); | 103 | GNUNET_GNS_lookup_with_tld_cancel(lr); |
104 | lr = NULL; | 104 | lr = NULL; |
105 | } | 105 | } |
106 | if (NULL != gns) | 106 | if (NULL != gns) |
107 | { | 107 | { |
108 | GNUNET_GNS_disconnect (gns); | 108 | GNUNET_GNS_disconnect(gns); |
109 | gns = NULL; | 109 | gns = NULL; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | /** | 113 | /** |
@@ -116,11 +116,11 @@ do_shutdown (void *cls) | |||
116 | * @param cls unused | 116 | * @param cls unused |
117 | */ | 117 | */ |
118 | static void | 118 | static void |
119 | do_timeout (void* cls) | 119 | do_timeout(void* cls) |
120 | { | 120 | { |
121 | to_task = NULL; | 121 | to_task = NULL; |
122 | global_ret = 3; //Timeout | 122 | global_ret = 3; //Timeout |
123 | GNUNET_SCHEDULER_shutdown (); | 123 | GNUNET_SCHEDULER_shutdown(); |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
@@ -132,10 +132,10 @@ do_timeout (void* cls) | |||
132 | * @param rd array of @a rd_count records with the results | 132 | * @param rd array of @a rd_count records with the results |
133 | */ | 133 | */ |
134 | static void | 134 | static void |
135 | process_lookup_result (void *cls, | 135 | process_lookup_result(void *cls, |
136 | int was_gns, | 136 | int was_gns, |
137 | uint32_t rd_count, | 137 | uint32_t rd_count, |
138 | const struct GNUNET_GNSRECORD_Data *rd) | 138 | const struct GNUNET_GNSRECORD_Data *rd) |
139 | { | 139 | { |
140 | const char *name = cls; | 140 | const char *name = cls; |
141 | const char *typename; | 141 | const char *typename; |
@@ -143,41 +143,41 @@ process_lookup_result (void *cls, | |||
143 | 143 | ||
144 | lr = NULL; | 144 | lr = NULL; |
145 | if (GNUNET_NO == was_gns) | 145 | if (GNUNET_NO == was_gns) |
146 | { | 146 | { |
147 | global_ret = 4; /* not for GNS */ | 147 | global_ret = 4; /* not for GNS */ |
148 | GNUNET_SCHEDULER_shutdown (); | 148 | GNUNET_SCHEDULER_shutdown(); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | if (! raw) | 151 | if (!raw) |
152 | { | 152 | { |
153 | if (0 == rd_count) | 153 | if (0 == rd_count) |
154 | printf ("No results.\n"); | 154 | printf("No results.\n"); |
155 | else | 155 | else |
156 | printf ("%s:\n", name); | 156 | printf("%s:\n", name); |
157 | } | 157 | } |
158 | for (uint32_t i = 0; i < rd_count; i++) | 158 | for (uint32_t i = 0; i < rd_count; i++) |
159 | { | ||
160 | if ((rd[i].record_type != rtype) && (GNUNET_GNSRECORD_TYPE_ANY != rtype)) | ||
161 | continue; | ||
162 | typename = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
163 | string_val = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
164 | rd[i].data, | ||
165 | rd[i].data_size); | ||
166 | if (NULL == string_val) | ||
167 | { | 159 | { |
168 | fprintf (stderr, | 160 | if ((rd[i].record_type != rtype) && (GNUNET_GNSRECORD_TYPE_ANY != rtype)) |
169 | "Record %u of type %d malformed, skipping\n", | 161 | continue; |
170 | (unsigned int) i, | 162 | typename = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type); |
171 | (int) rd[i].record_type); | 163 | string_val = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, |
172 | continue; | 164 | rd[i].data, |
165 | rd[i].data_size); | ||
166 | if (NULL == string_val) | ||
167 | { | ||
168 | fprintf(stderr, | ||
169 | "Record %u of type %d malformed, skipping\n", | ||
170 | (unsigned int)i, | ||
171 | (int)rd[i].record_type); | ||
172 | continue; | ||
173 | } | ||
174 | if (raw) | ||
175 | printf("%s\n", string_val); | ||
176 | else | ||
177 | printf("Got `%s' record: %s\n", typename, string_val); | ||
178 | GNUNET_free(string_val); | ||
173 | } | 179 | } |
174 | if (raw) | 180 | GNUNET_SCHEDULER_shutdown(); |
175 | printf ("%s\n", string_val); | ||
176 | else | ||
177 | printf ("Got `%s' record: %s\n", typename, string_val); | ||
178 | GNUNET_free (string_val); | ||
179 | } | ||
180 | GNUNET_SCHEDULER_shutdown (); | ||
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
@@ -190,53 +190,53 @@ process_lookup_result (void *cls, | |||
190 | * @param c configuration | 190 | * @param c configuration |
191 | */ | 191 | */ |
192 | static void | 192 | static void |
193 | run (void *cls, | 193 | run(void *cls, |
194 | char *const *args, | 194 | char *const *args, |
195 | const char *cfgfile, | 195 | const char *cfgfile, |
196 | const struct GNUNET_CONFIGURATION_Handle *c) | 196 | const struct GNUNET_CONFIGURATION_Handle *c) |
197 | { | 197 | { |
198 | (void) cls; | 198 | (void)cls; |
199 | (void) args; | 199 | (void)args; |
200 | (void) cfgfile; | 200 | (void)cfgfile; |
201 | 201 | ||
202 | cfg = c; | 202 | cfg = c; |
203 | to_task = NULL; | 203 | to_task = NULL; |
204 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (lookup_name)) | 204 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name(lookup_name)) |
205 | { | 205 | { |
206 | fprintf (stderr, _ ("`%s' is not a valid domain name\n"), lookup_name); | 206 | fprintf(stderr, _("`%s' is not a valid domain name\n"), lookup_name); |
207 | global_ret = 3; | 207 | global_ret = 3; |
208 | return; | 208 | return; |
209 | } | 209 | } |
210 | to_task = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, NULL); | 210 | to_task = GNUNET_SCHEDULER_add_delayed(timeout, &do_timeout, NULL); |
211 | gns = GNUNET_GNS_connect (cfg); | 211 | gns = GNUNET_GNS_connect(cfg); |
212 | if (NULL == gns) | 212 | if (NULL == gns) |
213 | { | 213 | { |
214 | fprintf (stderr, _ ("Failed to connect to GNS\n")); | 214 | fprintf(stderr, _("Failed to connect to GNS\n")); |
215 | global_ret = 2; | 215 | global_ret = 2; |
216 | return; | 216 | return; |
217 | } | 217 | } |
218 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 218 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
219 | if (NULL != lookup_type) | 219 | if (NULL != lookup_type) |
220 | rtype = GNUNET_GNSRECORD_typename_to_number (lookup_type); | 220 | rtype = GNUNET_GNSRECORD_typename_to_number(lookup_type); |
221 | else | 221 | else |
222 | rtype = GNUNET_DNSPARSER_TYPE_A; | 222 | rtype = GNUNET_DNSPARSER_TYPE_A; |
223 | if (UINT32_MAX == rtype) | 223 | if (UINT32_MAX == rtype) |
224 | { | 224 | { |
225 | fprintf (stderr, _ ("Invalid typename specified, assuming `ANY'\n")); | 225 | fprintf(stderr, _("Invalid typename specified, assuming `ANY'\n")); |
226 | rtype = GNUNET_GNSRECORD_TYPE_ANY; | 226 | rtype = GNUNET_GNSRECORD_TYPE_ANY; |
227 | } | 227 | } |
228 | lr = GNUNET_GNS_lookup_with_tld (gns, | 228 | lr = GNUNET_GNS_lookup_with_tld(gns, |
229 | lookup_name, | 229 | lookup_name, |
230 | rtype, | 230 | rtype, |
231 | GNUNET_GNS_LO_DEFAULT, | 231 | GNUNET_GNS_LO_DEFAULT, |
232 | &process_lookup_result, | 232 | &process_lookup_result, |
233 | lookup_name); | 233 | lookup_name); |
234 | if (NULL == lr) | 234 | if (NULL == lr) |
235 | { | 235 | { |
236 | global_ret = 2; | 236 | global_ret = 2; |
237 | GNUNET_SCHEDULER_shutdown (); | 237 | GNUNET_SCHEDULER_shutdown(); |
238 | return; | 238 | return; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
@@ -248,48 +248,48 @@ run (void *cls, | |||
248 | * @return 0 ok, 1 on error | 248 | * @return 0 ok, 1 on error |
249 | */ | 249 | */ |
250 | int | 250 | int |
251 | main (int argc, char *const *argv) | 251 | main(int argc, char *const *argv) |
252 | { | 252 | { |
253 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 253 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
254 | struct GNUNET_GETOPT_CommandLineOption options[] = | 254 | struct GNUNET_GETOPT_CommandLineOption options[] = |
255 | {GNUNET_GETOPT_option_mandatory ( | 255 | { GNUNET_GETOPT_option_mandatory( |
256 | GNUNET_GETOPT_option_string ('u', | 256 | GNUNET_GETOPT_option_string('u', |
257 | "lookup", | 257 | "lookup", |
258 | "NAME", | 258 | "NAME", |
259 | gettext_noop ( | 259 | gettext_noop( |
260 | "Lookup a record for the given name"), | 260 | "Lookup a record for the given name"), |
261 | &lookup_name)), | 261 | &lookup_name)), |
262 | GNUNET_GETOPT_option_string ('t', | 262 | GNUNET_GETOPT_option_string('t', |
263 | "type", | 263 | "type", |
264 | "TYPE", | 264 | "TYPE", |
265 | gettext_noop ( | 265 | gettext_noop( |
266 | "Specify the type of the record to lookup"), | 266 | "Specify the type of the record to lookup"), |
267 | &lookup_type), | 267 | &lookup_type), |
268 | GNUNET_GETOPT_option_relative_time ('T', | 268 | GNUNET_GETOPT_option_relative_time('T', |
269 | "timeout", | 269 | "timeout", |
270 | "TIMEOUT", | 270 | "TIMEOUT", |
271 | gettext_noop ( | 271 | gettext_noop( |
272 | "Specify a timeout for the lookup"), | 272 | "Specify a timeout for the lookup"), |
273 | &timeout), | 273 | &timeout), |
274 | GNUNET_GETOPT_option_flag ('r', | 274 | GNUNET_GETOPT_option_flag('r', |
275 | "raw", | 275 | "raw", |
276 | gettext_noop ("No unneeded output"), | 276 | gettext_noop("No unneeded output"), |
277 | &raw), | 277 | &raw), |
278 | GNUNET_GETOPT_OPTION_END}; | 278 | GNUNET_GETOPT_OPTION_END }; |
279 | int ret; | 279 | int ret; |
280 | 280 | ||
281 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 281 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
282 | return 2; | 282 | return 2; |
283 | 283 | ||
284 | GNUNET_log_setup ("gnunet-gns", "WARNING", NULL); | 284 | GNUNET_log_setup("gnunet-gns", "WARNING", NULL); |
285 | ret = GNUNET_PROGRAM_run (argc, | 285 | ret = GNUNET_PROGRAM_run(argc, |
286 | argv, | 286 | argv, |
287 | "gnunet-gns", | 287 | "gnunet-gns", |
288 | _ ("GNUnet GNS resolver tool"), | 288 | _("GNUnet GNS resolver tool"), |
289 | options, | 289 | options, |
290 | &run, | 290 | &run, |
291 | NULL); | 291 | NULL); |
292 | GNUNET_free ((void *) argv); | 292 | GNUNET_free((void *)argv); |
293 | if (GNUNET_OK != ret) | 293 | if (GNUNET_OK != ret) |
294 | return 1; | 294 | return 1; |
295 | return global_ret; | 295 | return global_ret; |