aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_address_to_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_address_to_string.c')
-rw-r--r--src/transport/transport_api_address_to_string.c59
1 files changed, 50 insertions, 9 deletions
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c
index 0cf0111b3..8a0db240f 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -55,7 +55,7 @@ struct GNUNET_TRANSPORT_AddressToStringContext
55/** 55/**
56 * Function called with responses from the service. 56 * Function called with responses from the service.
57 * 57 *
58 * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*' 58 * @param cls our 'struct GNUNET_TRANSPORT_AddressToStringContext*'
59 * @param msg NULL on timeout or error, otherwise presumably a 59 * @param msg NULL on timeout or error, otherwise presumably a
60 * message with the human-readable address 60 * message with the human-readable address
61 */ 61 */
@@ -63,41 +63,82 @@ static void
63address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) 63address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
64{ 64{
65 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 65 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
66 struct AddressToStringResultMessage *atsm;
66 const char *address; 67 const char *address;
67 uint16_t size; 68 uint16_t size;
69 uint32_t result;
70 uint32_t addr_len;
71 char *empty_str = "";
68 72
69 if (msg == NULL) 73 if (msg == NULL)
70 { 74 {
71 alucb->cb (alucb->cb_cls, NULL); 75 alucb->cb (alucb->cb_cls, NULL, GNUNET_OK);
72 GNUNET_CLIENT_disconnect (alucb->client); 76 GNUNET_CLIENT_disconnect (alucb->client);
73 GNUNET_free (alucb); 77 GNUNET_free (alucb);
74 return; 78 return;
75 } 79 }
76 GNUNET_break (ntohs (msg->type) == 80 GNUNET_break (ntohs (msg->type) ==
77 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 81 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
82
78 size = ntohs (msg->size); 83 size = ntohs (msg->size);
79 if (size == sizeof (struct GNUNET_MessageHeader)) 84 if (size < sizeof (struct AddressToStringResultMessage))
80 { 85 {
81 /* done! */ 86 alucb->cb (alucb->cb_cls, NULL, GNUNET_OK);
82 alucb->cb (alucb->cb_cls, NULL);
83 GNUNET_CLIENT_disconnect (alucb->client); 87 GNUNET_CLIENT_disconnect (alucb->client);
84 GNUNET_free (alucb); 88 GNUNET_free (alucb);
85 return; 89 return;
86 } 90 }
87 address = (const char *) &msg[1]; 91 atsm = (struct AddressToStringResultMessage *) msg;
88 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 92
93 result = ntohl (atsm->res);
94 addr_len = ntohl (atsm->addr_len);
95
96 if (size == (sizeof (struct AddressToStringResultMessage)))
97 {
98 /* done, success depends on result */
99 alucb->cb (alucb->cb_cls, NULL, result);
100 GNUNET_CLIENT_disconnect (alucb->client);
101 GNUNET_free (alucb);
102 return;
103 }
104
105 if (GNUNET_NO == result)
106 {
107 alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR);
108
109 /* expect more replies */
110 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
111 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
112 return;
113 }
114
115
116 address = (const char *) &atsm[1];
117 if ( (addr_len > (size - (sizeof (struct AddressToStringResultMessage)))) ||
118 (address[addr_len -1] != '\0') )
89 { 119 {
90 /* invalid reply */ 120 /* invalid reply */
91 GNUNET_break (0); 121 GNUNET_break (0);
92 alucb->cb (alucb->cb_cls, NULL); 122 alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR);
93 GNUNET_CLIENT_disconnect (alucb->client); 123 GNUNET_CLIENT_disconnect (alucb->client);
94 GNUNET_free (alucb); 124 GNUNET_free (alucb);
95 return; 125 return;
96 } 126 }
127
128 result = GNUNET_NO;
129
97 /* expect more replies */ 130 /* expect more replies */
98 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, 131 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
99 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 132 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
100 alucb->cb (alucb->cb_cls, address); 133
134 if (GNUNET_NO == result)
135 {
136 alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR);
137 }
138 else
139 {
140 alucb->cb (alucb->cb_cls, address, GNUNET_OK);
141 }
101} 142}
102 143
103 144