summaryrefslogtreecommitdiff
path: root/src/nat-auto/nat_auto_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat-auto/nat_auto_api.c')
-rw-r--r--src/nat-auto/nat_auto_api.c239
1 files changed, 121 insertions, 118 deletions
diff --git a/src/nat-auto/nat_auto_api.c b/src/nat-auto/nat_auto_api.c
index ae7bb6514..f7a821a82 100644
--- a/src/nat-auto/nat_auto_api.c
+++ b/src/nat-auto/nat_auto_api.c
@@ -35,7 +35,8 @@
35/** 35/**
36 * Handle to auto-configuration in progress. 36 * Handle to auto-configuration in progress.
37 */ 37 */
38struct GNUNET_NAT_AUTO_AutoHandle { 38struct GNUNET_NAT_AUTO_AutoHandle
39{
39 /** 40 /**
40 * Configuration we use. 41 * Configuration we use.
41 */ 42 */
@@ -65,70 +66,71 @@ struct GNUNET_NAT_AUTO_AutoHandle {
65 * @return point to a static string containing the error code 66 * @return point to a static string containing the error code
66 */ 67 */
67const char * 68const char *
68GNUNET_NAT_AUTO_status2string(enum GNUNET_NAT_StatusCode err) 69GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err)
69{ 70{
70 switch (err) 71 switch (err)
71 { 72 {
72 case GNUNET_NAT_ERROR_SUCCESS: 73 case GNUNET_NAT_ERROR_SUCCESS:
73 return _("Operation Successful"); 74 return _ ("Operation Successful");
74 75
75 case GNUNET_NAT_ERROR_IPC_FAILURE: 76 case GNUNET_NAT_ERROR_IPC_FAILURE:
76 return _("IPC failure"); 77 return _ ("IPC failure");
77 78
78 case GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR: 79 case GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR:
79 return _("Failure in network subsystem, check permissions."); 80 return _ ("Failure in network subsystem, check permissions.");
80 81
81 case GNUNET_NAT_ERROR_TIMEOUT: 82 case GNUNET_NAT_ERROR_TIMEOUT:
82 return _("Encountered timeout while performing operation"); 83 return _ ("Encountered timeout while performing operation");
83 84
84 case GNUNET_NAT_ERROR_NOT_ONLINE: 85 case GNUNET_NAT_ERROR_NOT_ONLINE:
85 return _("detected that we are offline"); 86 return _ ("detected that we are offline");
86 87
87 case GNUNET_NAT_ERROR_UPNPC_NOT_FOUND: 88 case GNUNET_NAT_ERROR_UPNPC_NOT_FOUND:
88 return _("`upnpc` command not found"); 89 return _ ("`upnpc` command not found");
89 90
90 case GNUNET_NAT_ERROR_UPNPC_FAILED: 91 case GNUNET_NAT_ERROR_UPNPC_FAILED:
91 return _("Failed to run `upnpc` command"); 92 return _ ("Failed to run `upnpc` command");
92 93
93 case GNUNET_NAT_ERROR_UPNPC_TIMEOUT: 94 case GNUNET_NAT_ERROR_UPNPC_TIMEOUT:
94 return _("`upnpc' command took too long, process killed"); 95 return _ ("`upnpc' command took too long, process killed");
95 96
96 case GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED: 97 case GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED:
97 return _("`upnpc' command failed to establish port mapping"); 98 return _ ("`upnpc' command failed to establish port mapping");
98 99
99 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND: 100 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND:
100 return _("`external-ip' command not found"); 101 return _ ("`external-ip' command not found");
101 102
102 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED: 103 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED:
103 return _("Failed to run `external-ip` command"); 104 return _ ("Failed to run `external-ip` command");
104 105
105 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID: 106 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID:
106 return _("`external-ip' command output invalid"); 107 return _ ("`external-ip' command output invalid");
107 108
108 case GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID: 109 case GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID:
109 return _("no valid address was returned by `external-ip'"); 110 return _ ("no valid address was returned by `external-ip'");
110 111
111 case GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO: 112 case GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO:
112 return _("Could not determine interface with internal/local network address"); 113 return _ (
114 "Could not determine interface with internal/local network address");
113 115
114 case GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND: 116 case GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND:
115 return _("No functioning gnunet-helper-nat-server installation found"); 117 return _ ("No functioning gnunet-helper-nat-server installation found");
116 118
117 case GNUNET_NAT_ERROR_NAT_TEST_START_FAILED: 119 case GNUNET_NAT_ERROR_NAT_TEST_START_FAILED:
118 return _("NAT test could not be initialized"); 120 return _ ("NAT test could not be initialized");
119 121
120 case GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT: 122 case GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT:
121 return _("NAT test timeout reached"); 123 return _ ("NAT test timeout reached");
122 124
123 case GNUNET_NAT_ERROR_NAT_REGISTER_FAILED: 125 case GNUNET_NAT_ERROR_NAT_REGISTER_FAILED:
124 return _("could not register NAT"); 126 return _ ("could not register NAT");
125 127
126 case GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND: 128 case GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND:
127 return _("No working gnunet-helper-nat-client installation found"); 129 return _ ("No working gnunet-helper-nat-client installation found");
128 130
129 default: 131 default:
130 return "unknown status code"; 132 return "unknown status code";
131 } 133 }
132} 134}
133 135
134 136
@@ -140,8 +142,8 @@ GNUNET_NAT_AUTO_status2string(enum GNUNET_NAT_StatusCode err)
140 * @return #GNUNET_OK if @a res is well-formed (always for now) 142 * @return #GNUNET_OK if @a res is well-formed (always for now)
141 */ 143 */
142static int 144static int
143check_auto_result(void *cls, 145check_auto_result (void *cls,
144 const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res) 146 const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res)
145{ 147{
146 return GNUNET_OK; 148 return GNUNET_OK;
147} 149}
@@ -154,40 +156,40 @@ check_auto_result(void *cls,
154 * @param res the result 156 * @param res the result
155 */ 157 */
156static void 158static void
157handle_auto_result(void *cls, 159handle_auto_result (void *cls,
158 const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res) 160 const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res)
159{ 161{
160 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls; 162 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
161 size_t left; 163 size_t left;
162 struct GNUNET_CONFIGURATION_Handle *cfg; 164 struct GNUNET_CONFIGURATION_Handle *cfg;
163 enum GNUNET_NAT_Type type 165 enum GNUNET_NAT_Type type
164 = (enum GNUNET_NAT_Type)ntohl(res->type); 166 = (enum GNUNET_NAT_Type) ntohl (res->type);
165 enum GNUNET_NAT_StatusCode status 167 enum GNUNET_NAT_StatusCode status
166 = (enum GNUNET_NAT_StatusCode)ntohl(res->status_code); 168 = (enum GNUNET_NAT_StatusCode) ntohl (res->status_code);
167 169
168 left = ntohs(res->header.size) - sizeof(*res); 170 left = ntohs (res->header.size) - sizeof(*res);
169 cfg = GNUNET_CONFIGURATION_create(); 171 cfg = GNUNET_CONFIGURATION_create ();
170 if (GNUNET_OK != 172 if (GNUNET_OK !=
171 GNUNET_CONFIGURATION_deserialize(cfg, 173 GNUNET_CONFIGURATION_deserialize (cfg,
172 (const char *)&res[1], 174 (const char *) &res[1],
173 left, 175 left,
174 NULL)) 176 NULL))
175 { 177 {
176 GNUNET_break(0); 178 GNUNET_break (0);
177 ah->arc(ah->arc_cls, 179 ah->arc (ah->arc_cls,
178 NULL, 180 NULL,
179 GNUNET_NAT_ERROR_IPC_FAILURE, 181 GNUNET_NAT_ERROR_IPC_FAILURE,
180 type); 182 type);
181 } 183 }
182 else 184 else
183 { 185 {
184 ah->arc(ah->arc_cls, 186 ah->arc (ah->arc_cls,
185 cfg, 187 cfg,
186 status, 188 status,
187 type); 189 type);
188 } 190 }
189 GNUNET_CONFIGURATION_destroy(cfg); 191 GNUNET_CONFIGURATION_destroy (cfg);
190 GNUNET_NAT_AUTO_autoconfig_cancel(ah); 192 GNUNET_NAT_AUTO_autoconfig_cancel (ah);
191} 193}
192 194
193 195
@@ -198,16 +200,16 @@ handle_auto_result(void *cls,
198 * @param error details about the error 200 * @param error details about the error
199 */ 201 */
200static void 202static void
201ah_error_handler(void *cls, 203ah_error_handler (void *cls,
202 enum GNUNET_MQ_Error error) 204 enum GNUNET_MQ_Error error)
203{ 205{
204 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls; 206 struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
205 207
206 ah->arc(ah->arc_cls, 208 ah->arc (ah->arc_cls,
207 NULL, 209 NULL,
208 GNUNET_NAT_ERROR_IPC_FAILURE, 210 GNUNET_NAT_ERROR_IPC_FAILURE,
209 GNUNET_NAT_TYPE_UNKNOWN); 211 GNUNET_NAT_TYPE_UNKNOWN);
210 GNUNET_NAT_AUTO_autoconfig_cancel(ah); 212 GNUNET_NAT_AUTO_autoconfig_cancel (ah);
211} 213}
212 214
213 215
@@ -221,55 +223,56 @@ ah_error_handler(void *cls,
221 * @return handle to cancel operation 223 * @return handle to cancel operation
222 */ 224 */
223struct GNUNET_NAT_AUTO_AutoHandle * 225struct GNUNET_NAT_AUTO_AutoHandle *
224GNUNET_NAT_AUTO_autoconfig_start(const struct GNUNET_CONFIGURATION_Handle *cfg, 226GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
225 GNUNET_NAT_AUTO_AutoResultCallback cb, 227 GNUNET_NAT_AUTO_AutoResultCallback cb,
226 void *cb_cls) 228 void *cb_cls)
227{ 229{
228 struct GNUNET_NAT_AUTO_AutoHandle *ah = GNUNET_new(struct GNUNET_NAT_AUTO_AutoHandle); 230 struct GNUNET_NAT_AUTO_AutoHandle *ah = GNUNET_new (struct
231 GNUNET_NAT_AUTO_AutoHandle);
229 struct GNUNET_MQ_MessageHandler handlers[] = { 232 struct GNUNET_MQ_MessageHandler handlers[] = {
230 GNUNET_MQ_hd_var_size(auto_result, 233 GNUNET_MQ_hd_var_size (auto_result,
231 GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT, 234 GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT,
232 struct GNUNET_NAT_AUTO_AutoconfigResultMessage, 235 struct GNUNET_NAT_AUTO_AutoconfigResultMessage,
233 ah), 236 ah),
234 GNUNET_MQ_handler_end() 237 GNUNET_MQ_handler_end ()
235 }; 238 };
236 struct GNUNET_MQ_Envelope *env; 239 struct GNUNET_MQ_Envelope *env;
237 struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *req; 240 struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *req;
238 char *buf; 241 char *buf;
239 size_t size; 242 size_t size;
240 243
241 buf = GNUNET_CONFIGURATION_serialize(cfg, 244 buf = GNUNET_CONFIGURATION_serialize (cfg,
242 &size); 245 &size);
243 if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req)) 246 if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req))
244 { 247 {
245 GNUNET_break(0); 248 GNUNET_break (0);
246 GNUNET_free(buf); 249 GNUNET_free (buf);
247 GNUNET_free(ah); 250 GNUNET_free (ah);
248 return NULL; 251 return NULL;
249 } 252 }
250 ah->arc = cb; 253 ah->arc = cb;
251 ah->arc_cls = cb_cls; 254 ah->arc_cls = cb_cls;
252 ah->mq = GNUNET_CLIENT_connect(cfg, 255 ah->mq = GNUNET_CLIENT_connect (cfg,
253 "nat", 256 "nat",
254 handlers, 257 handlers,
255 &ah_error_handler, 258 &ah_error_handler,
256 ah); 259 ah);
257 if (NULL == ah->mq) 260 if (NULL == ah->mq)
258 { 261 {
259 GNUNET_break(0); 262 GNUNET_break (0);
260 GNUNET_free(buf); 263 GNUNET_free (buf);
261 GNUNET_free(ah); 264 GNUNET_free (ah);
262 return NULL; 265 return NULL;
263 } 266 }
264 env = GNUNET_MQ_msg_extra(req, 267 env = GNUNET_MQ_msg_extra (req,
265 size, 268 size,
266 GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG); 269 GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG);
267 GNUNET_memcpy(&req[1], 270 GNUNET_memcpy (&req[1],
268 buf, 271 buf,
269 size); 272 size);
270 GNUNET_free(buf); 273 GNUNET_free (buf);
271 GNUNET_MQ_send(ah->mq, 274 GNUNET_MQ_send (ah->mq,
272 env); 275 env);
273 return ah; 276 return ah;
274} 277}
275 278
@@ -280,10 +283,10 @@ GNUNET_NAT_AUTO_autoconfig_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
280 * @param ah handle for operation to abort 283 * @param ah handle for operation to abort
281 */ 284 */
282void 285void
283GNUNET_NAT_AUTO_autoconfig_cancel(struct GNUNET_NAT_AUTO_AutoHandle *ah) 286GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah)
284{ 287{
285 GNUNET_MQ_destroy(ah->mq); 288 GNUNET_MQ_destroy (ah->mq);
286 GNUNET_free(ah); 289 GNUNET_free (ah);
287} 290}
288 291
289/* end of nat_api_auto.c */ 292/* end of nat_api_auto.c */