diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-23 21:39:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-23 21:39:07 +0000 |
commit | 6b1c16cc8dc30d1718d9bb2c8ad262c24dc41073 (patch) | |
tree | f3929377c47a57d4e519cd31c6f1b6aabd21d5e2 /src/util/resolver_api.c | |
parent | 0853cb6f86c1c5e3c48520089d7a274aadb7fade (diff) | |
download | gnunet-6b1c16cc8dc30d1718d9bb2c8ad262c24dc41073.tar.gz gnunet-6b1c16cc8dc30d1718d9bb2c8ad262c24dc41073.zip |
-fix tiny leak, doxygen
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r-- | src/util/resolver_api.c | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 46ac52586..d097cd6a5 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -139,9 +139,9 @@ struct GNUNET_RESOLVER_RequestHandle | |||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Has this request been transmitted to the service? | 141 | * Has this request been transmitted to the service? |
142 | * GNUNET_YES if transmitted | 142 | * #GNUNET_YES if transmitted |
143 | * GNUNET_YES if not transmitted | 143 | * #GNUNET_YES if not transmitted |
144 | * GNUNET_SYSERR when request was canceled | 144 | * #GNUNET_SYSERR when request was canceled |
145 | */ | 145 | */ |
146 | int was_transmitted; | 146 | int was_transmitted; |
147 | 147 | ||
@@ -156,7 +156,7 @@ struct GNUNET_RESOLVER_RequestHandle | |||
156 | int direction; | 156 | int direction; |
157 | 157 | ||
158 | /** | 158 | /** |
159 | * GNUNET_YES if a response was received | 159 | * #GNUNET_YES if a response was received |
160 | */ | 160 | */ |
161 | int received_response; | 161 | int received_response; |
162 | 162 | ||
@@ -245,7 +245,8 @@ GNUNET_RESOLVER_disconnect () | |||
245 | GNUNET_assert (NULL == req_tail); | 245 | GNUNET_assert (NULL == req_tail); |
246 | if (NULL != client) | 246 | if (NULL != client) |
247 | { | 247 | { |
248 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n"); | 248 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
249 | "Disconnecting from DNS service\n"); | ||
249 | GNUNET_CLIENT_disconnect (client); | 250 | GNUNET_CLIENT_disconnect (client); |
250 | client = NULL; | 251 | client = NULL; |
251 | } | 252 | } |
@@ -284,7 +285,8 @@ no_resolve (int af, | |||
284 | if (NULL == | 285 | if (NULL == |
285 | inet_ntop (AF_INET, ip, buf, sizeof (buf))) | 286 | inet_ntop (AF_INET, ip, buf, sizeof (buf))) |
286 | { | 287 | { |
287 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 288 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
289 | "inet_ntop"); | ||
288 | return NULL; | 290 | return NULL; |
289 | } | 291 | } |
290 | break; | 292 | break; |
@@ -294,7 +296,8 @@ no_resolve (int af, | |||
294 | if (NULL == | 296 | if (NULL == |
295 | inet_ntop (AF_INET6, ip, buf, sizeof (buf))) | 297 | inet_ntop (AF_INET6, ip, buf, sizeof (buf))) |
296 | { | 298 | { |
297 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 299 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
300 | "inet_ntop"); | ||
298 | return NULL; | 301 | return NULL; |
299 | } | 302 | } |
300 | break; | 303 | break; |
@@ -323,14 +326,16 @@ process_requests (); | |||
323 | /** | 326 | /** |
324 | * Process response with a hostname for a DNS lookup. | 327 | * Process response with a hostname for a DNS lookup. |
325 | * | 328 | * |
326 | * @param cls our "struct GNUNET_RESOLVER_RequestHandle" context | 329 | * @param cls our `struct GNUNET_RESOLVER_RequestHandle` context |
327 | * @param msg message with the hostname, NULL on error | 330 | * @param msg message with the hostname, NULL on error |
328 | */ | 331 | */ |
329 | static void | 332 | static void |
330 | handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | 333 | handle_response (void *cls, |
334 | const struct GNUNET_MessageHeader *msg) | ||
331 | { | 335 | { |
332 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 336 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
333 | uint16_t size; | 337 | uint16_t size; |
338 | char *nret; | ||
334 | 339 | ||
335 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 340 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
336 | "Receiving response from DNS service\n"); | 341 | "Receiving response from DNS service\n"); |
@@ -354,7 +359,9 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
354 | /* no reverse lookup was successful, return ip as string */ | 359 | /* no reverse lookup was successful, return ip as string */ |
355 | if (rh->received_response == GNUNET_NO) | 360 | if (rh->received_response == GNUNET_NO) |
356 | { | 361 | { |
357 | rh->name_callback (rh->cls, no_resolve (rh->af, &rh[1], rh->data_len)); | 362 | nret = no_resolve (rh->af, &rh[1], rh->data_len); |
363 | rh->name_callback (rh->cls, nret); | ||
364 | GNUNET_free (nret); | ||
358 | rh->name_callback (rh->cls, NULL); | 365 | rh->name_callback (rh->cls, NULL); |
359 | } | 366 | } |
360 | /* at least one reverse lookup was successful */ | 367 | /* at least one reverse lookup was successful */ |
@@ -384,7 +391,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
384 | if (size == sizeof (struct GNUNET_MessageHeader)) | 391 | if (size == sizeof (struct GNUNET_MessageHeader)) |
385 | { | 392 | { |
386 | /* check if request was canceled */ | 393 | /* check if request was canceled */ |
387 | if (rh->was_transmitted != GNUNET_SYSERR) | 394 | if (GNUNET_SYSERR != rh->was_transmitted) |
388 | { | 395 | { |
389 | if (NULL != rh->name_callback) | 396 | if (NULL != rh->name_callback) |
390 | rh->name_callback (rh->cls, NULL); | 397 | rh->name_callback (rh->cls, NULL); |
@@ -414,8 +421,11 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
414 | reconnect (); | 421 | reconnect (); |
415 | return; | 422 | return; |
416 | } | 423 | } |
417 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for IP `%s'.\n", | 424 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
418 | hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); | 425 | "Resolver returns `%s' for IP `%s'.\n", |
426 | hostname, | ||
427 | GNUNET_a2s ((const void *) &rh[1], | ||
428 | rh->data_len)); | ||
419 | if (rh->was_transmitted != GNUNET_SYSERR) | 429 | if (rh->was_transmitted != GNUNET_SYSERR) |
420 | rh->name_callback (rh->cls, hostname); | 430 | rh->name_callback (rh->cls, hostname); |
421 | rh->received_response = GNUNET_YES; | 431 | rh->received_response = GNUNET_YES; |
@@ -480,11 +490,12 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
480 | * given a valid numeric string. Perform the callbacks for the | 490 | * given a valid numeric string. Perform the callbacks for the |
481 | * numeric addresses. | 491 | * numeric addresses. |
482 | * | 492 | * |
483 | * @param cls struct GNUNET_RESOLVER_RequestHandle for the request | 493 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request |
484 | * @param tc unused scheduler context | 494 | * @param tc unused scheduler context |
485 | */ | 495 | */ |
486 | static void | 496 | static void |
487 | numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 497 | numeric_resolution (void *cls, |
498 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
488 | { | 499 | { |
489 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 500 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
490 | struct sockaddr_in v4; | 501 | struct sockaddr_in v4; |
@@ -535,11 +546,12 @@ numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
535 | * given a variant of "loopback". Perform the callbacks for the | 546 | * given a variant of "loopback". Perform the callbacks for the |
536 | * respective loopback numeric addresses. | 547 | * respective loopback numeric addresses. |
537 | * | 548 | * |
538 | * @param cls struct GNUNET_RESOLVER_RequestHandle for the request | 549 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request |
539 | * @param tc unused scheduler context | 550 | * @param tc unused scheduler context |
540 | */ | 551 | */ |
541 | static void | 552 | static void |
542 | loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 553 | loopback_resolution (void *cls, |
554 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
543 | { | 555 | { |
544 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 556 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
545 | struct sockaddr_in v4; | 557 | struct sockaddr_in v4; |
@@ -650,7 +662,8 @@ process_requests () | |||
650 | * @param tc scheduler context | 662 | * @param tc scheduler context |
651 | */ | 663 | */ |
652 | static void | 664 | static void |
653 | reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 665 | reconnect_task (void *cls, |
666 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
654 | { | 667 | { |
655 | r_task = GNUNET_SCHEDULER_NO_TASK; | 668 | r_task = GNUNET_SCHEDULER_NO_TASK; |
656 | if (NULL == req_head) | 669 | if (NULL == req_head) |
@@ -718,7 +731,7 @@ reconnect () | |||
718 | * @param hostname the hostname to resolve | 731 | * @param hostname the hostname to resolve |
719 | * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" | 732 | * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" |
720 | * @param callback function to call with addresses | 733 | * @param callback function to call with addresses |
721 | * @param callback_cls closure for callback | 734 | * @param callback_cls closure for @a callback |
722 | * @param timeout how long to try resolving | 735 | * @param timeout how long to try resolving |
723 | * @return handle that can be used to cancel the request, NULL on error | 736 | * @return handle that can be used to cancel the request, NULL on error |
724 | */ | 737 | */ |
@@ -782,18 +795,21 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int af, | |||
782 | * We've been asked to convert an address to a string without | 795 | * We've been asked to convert an address to a string without |
783 | * a reverse lookup. Do it. | 796 | * a reverse lookup. Do it. |
784 | * | 797 | * |
785 | * @param cls struct GNUNET_RESOLVER_RequestHandle for the request | 798 | * @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request |
786 | * @param tc unused scheduler context | 799 | * @param tc unused scheduler context |
787 | */ | 800 | */ |
788 | static void | 801 | static void |
789 | numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 802 | numeric_reverse (void *cls, |
803 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
790 | { | 804 | { |
791 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 805 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
792 | char *result; | 806 | char *result; |
793 | 807 | ||
794 | result = no_resolve (rh->af, &rh[1], rh->data_len); | 808 | result = no_resolve (rh->af, &rh[1], rh->data_len); |
795 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s'.\n", result); | 809 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
796 | if (result != NULL) | 810 | "Resolver returns `%s'.\n", |
811 | result); | ||
812 | if (NULL != result) | ||
797 | { | 813 | { |
798 | rh->name_callback (rh->cls, result); | 814 | rh->name_callback (rh->cls, result); |
799 | GNUNET_free (result); | 815 | GNUNET_free (result); |
@@ -807,16 +823,17 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
807 | * Get an IP address as a string. | 823 | * Get an IP address as a string. |
808 | * | 824 | * |
809 | * @param sa host address | 825 | * @param sa host address |
810 | * @param salen length of host address | 826 | * @param salen length of host address in @a sa |
811 | * @param do_resolve use GNUNET_NO to return numeric hostname | 827 | * @param do_resolve use #GNUNET_NO to return numeric hostname |
812 | * @param timeout how long to try resolving | 828 | * @param timeout how long to try resolving |
813 | * @param callback function to call with hostnames | 829 | * @param callback function to call with hostnames |
814 | * last callback is NULL when finished | 830 | * last callback is NULL when finished |
815 | * @param cls closure for callback | 831 | * @param cls closure for @a callback |
816 | * @return handle that can be used to cancel the request | 832 | * @return handle that can be used to cancel the request |
817 | */ | 833 | */ |
818 | struct GNUNET_RESOLVER_RequestHandle * | 834 | struct GNUNET_RESOLVER_RequestHandle * |
819 | GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, | 835 | GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, |
836 | socklen_t salen, | ||
820 | int do_resolve, | 837 | int do_resolve, |
821 | struct GNUNET_TIME_Relative timeout, | 838 | struct GNUNET_TIME_Relative timeout, |
822 | GNUNET_RESOLVER_HostnameCallback callback, | 839 | GNUNET_RESOLVER_HostnameCallback callback, |
@@ -901,7 +918,7 @@ GNUNET_RESOLVER_local_fqdn_get () | |||
901 | * | 918 | * |
902 | * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" | 919 | * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" |
903 | * @param callback function to call with addresses | 920 | * @param callback function to call with addresses |
904 | * @param cls closure for callback | 921 | * @param cls closure for @a callback |
905 | * @param timeout how long to try resolving | 922 | * @param timeout how long to try resolving |
906 | * @return handle that can be used to cancel the request, NULL on error | 923 | * @return handle that can be used to cancel the request, NULL on error |
907 | */ | 924 | */ |