aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_smtp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/plugin_transport_smtp.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/plugin_transport_smtp.c')
-rw-r--r--src/transport/plugin_transport_smtp.c638
1 files changed, 324 insertions, 314 deletions
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index d7b87e7b1..7fbbc9126 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -53,7 +53,8 @@
53/** 53/**
54 * Host-Address in a SMTP network. 54 * Host-Address in a SMTP network.
55 */ 55 */
56typedef struct { 56typedef struct
57{
57 /** 58 /**
58 * Filter line that every sender must include in the E-mails such 59 * Filter line that every sender must include in the E-mails such
59 * that the receiver can effectively filter out the GNUnet traffic 60 * that the receiver can effectively filter out the GNUnet traffic
@@ -75,7 +76,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
75 * Encapsulation of a GNUnet message in the SMTP mail body (before 76 * Encapsulation of a GNUnet message in the SMTP mail body (before
76 * base64 encoding). 77 * base64 encoding).
77 */ 78 */
78typedef struct { 79typedef struct
80{
79 GNUNET_MessageHeader header; 81 GNUNET_MessageHeader header;
80 82
81 /** 83 /**
@@ -143,13 +145,13 @@ static GNUNET_CronTime last_transmission;
143 145
144/* ********************* the real stuff ******************* */ 146/* ********************* the real stuff ******************* */
145 147
146#define strAUTOncmp(a, b) strncmp(a, b, strlen(b)) 148#define strAUTOncmp(a, b) strncmp (a, b, strlen (b))
147 149
148/** 150/**
149 * Listen to the pipe, decode messages and send to core. 151 * Listen to the pipe, decode messages and send to core.
150 */ 152 */
151static void * 153static void *
152listenAndDistribute(void *unused) 154listenAndDistribute (void *unused)
153{ 155{
154 char *line; 156 char *line;
155 unsigned int linesize; 157 unsigned int linesize;
@@ -162,93 +164,96 @@ listenAndDistribute(void *unused)
162 int fd; 164 int fd;
163 unsigned int pos; 165 unsigned int pos;
164 166
165 linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2) / MAX_CHAR_PER_LINE; /* maximum size of a line supported */ 167 linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2)
166 line = GNUNET_malloc(linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */ 168 / MAX_CHAR_PER_LINE; /* maximum size of a line supported */
169 line = GNUNET_malloc (linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */
167 170
168#define READLINE(l, limit) \ 171#define READLINE(l, limit) \
169 do { retl = fgets(l, (limit), fdes); \ 172 do { retl = fgets (l, (limit), fdes); \
170 if ((retl == NULL) || (smtp_shutdown == GNUNET_YES)) { \ 173 if ((retl == NULL) || (smtp_shutdown == GNUNET_YES)) { \
171 goto END; \ 174 goto END; \
172 } \ 175 } \
173 if (core_api->load_monitor != NULL) \ 176 if (core_api->load_monitor != NULL) \
174 GNUNET_network_monitor_notify_transmission (core_api->load_monitor, GNUNET_ND_DOWNLOAD, strlen(retl)); \ 177 GNUNET_network_monitor_notify_transmission (core_api->load_monitor, \
175 } while (0) 178 GNUNET_ND_DOWNLOAD, \
179 strlen (retl)); \
180 } while (0)
176 181
177 182
178 while (smtp_shutdown == GNUNET_NO) 183 while (smtp_shutdown == GNUNET_NO)
184 {
185 fd = OPEN (pipename, O_RDONLY | O_ASYNC);
186 if (fd == -1)
187 {
188 if (smtp_shutdown == GNUNET_NO)
189 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
190 continue;
191 }
192 fdes = fdopen (fd, "r");
193 while (smtp_shutdown == GNUNET_NO)
179 { 194 {
180 fd = OPEN(pipename, O_RDONLY | O_ASYNC); 195 /* skip until end of header */
181 if (fd == -1) 196 do
182 { 197 {
183 if (smtp_shutdown == GNUNET_NO) 198 READLINE (line, linesize);
184 GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS); 199 }
185 continue; 200 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */
186 } 201 READLINE (line, linesize); /* read base64 encoded message; decode, process */
187 fdes = fdopen(fd, "r"); 202 pos = 0;
188 while (smtp_shutdown == GNUNET_NO) 203 while (1)
189 { 204 {
190 /* skip until end of header */ 205 pos = strlen (line) - 1; /* ignore new line */
191 do 206 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */
192 { 207 if ((line[pos] == '\r') || (line[pos] == '\n'))
193 READLINE(line, linesize); 208 break; /* empty line => end of message! */
194 } 209 }
195 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ 210 size = GNUNET_STRINGS_base64_decode (line, pos, &out);
196 READLINE(line, linesize); /* read base64 encoded message; decode, process */ 211 if (size < sizeof(SMTPMessage))
197 pos = 0; 212 {
198 while (1) 213 GNUNET_GE_BREAK (ectx, 0);
199 { 214 GNUNET_free (out);
200 pos = strlen(line) - 1; /* ignore new line */ 215 goto END;
201 READLINE(&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ 216 }
202 if ((line[pos] == '\r') || (line[pos] == '\n')) 217
203 break; /* empty line => end of message! */ 218 mp = (SMTPMessage *) &out[size - sizeof(SMTPMessage)];
204 } 219 if (ntohs (mp->header.size) != size)
205 size = GNUNET_STRINGS_base64_decode(line, pos, &out); 220 {
206 if (size < sizeof(SMTPMessage)) 221 GNUNET_GE_LOG (ectx,
207 { 222 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
208 GNUNET_GE_BREAK(ectx, 0); 223 _ ("Received malformed message via %s. Ignored.\n"),
209 GNUNET_free(out); 224 "SMTP");
210 goto END;
211 }
212
213 mp = (SMTPMessage *)&out[size - sizeof(SMTPMessage)];
214 if (ntohs(mp->header.size) != size)
215 {
216 GNUNET_GE_LOG(ectx,
217 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
218 _("Received malformed message via %s. Ignored.\n"),
219 "SMTP");
220#if DEBUG_SMTP 225#if DEBUG_SMTP
221 GNUNET_GE_LOG(ectx, 226 GNUNET_GE_LOG (ectx,
222 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 227 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
223 "Size returned by base64=%d, in the msg=%d.\n", size, 228 "Size returned by base64=%d, in the msg=%d.\n", size,
224 ntohl(mp->size)); 229 ntohl (mp->size));
225#endif 230#endif
226 GNUNET_free(out); 231 GNUNET_free (out);
227 goto END; 232 goto END;
228 } 233 }
229 if (stats != NULL) 234 if (stats != NULL)
230 stats->change(stat_bytesReceived, size); 235 stats->change (stat_bytesReceived, size);
231 coreMP = GNUNET_new(GNUNET_TransportPacket); 236 coreMP = GNUNET_new (GNUNET_TransportPacket);
232 coreMP->msg = out; 237 coreMP->msg = out;
233 coreMP->size = size - sizeof(SMTPMessage); 238 coreMP->size = size - sizeof(SMTPMessage);
234 coreMP->tsession = NULL; 239 coreMP->tsession = NULL;
235 coreMP->sender = mp->sender; 240 coreMP->sender = mp->sender;
236#if DEBUG_SMTP 241#if DEBUG_SMTP
237 GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 242 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
238 "SMTP message passed to the core.\n"); 243 "SMTP message passed to the core.\n");
239#endif 244#endif
240 245
241 core_api->receive(coreMP); 246 core_api->receive (coreMP);
242 } 247 }
243END: 248END:
244#if DEBUG_SMTP 249#if DEBUG_SMTP
245 GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 250 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
246 "SMTP message processed.\n"); 251 "SMTP message processed.\n");
247#endif 252#endif
248 if (fdes != NULL) 253 if (fdes != NULL)
249 fclose(fdes); 254 fclose (fdes);
250 } 255 }
251 GNUNET_free(line); 256 GNUNET_free (line);
252 return NULL; 257 return NULL;
253} 258}
254 259
@@ -264,20 +269,20 @@ END:
264 * @return GNUNET_OK on success, GNUNET_SYSERR on error 269 * @return GNUNET_OK on success, GNUNET_SYSERR on error
265 */ 270 */
266static int 271static int
267api_verify_hello(const GNUNET_MessageHello * hello) 272api_verify_hello (const GNUNET_MessageHello *hello)
268{ 273{
269 const EmailAddress *maddr; 274 const EmailAddress *maddr;
270 275
271 maddr = (const EmailAddress *)&hello[1]; 276 maddr = (const EmailAddress *) &hello[1];
272 if ((ntohs(hello->header.size) != 277 if ((ntohs (hello->header.size) !=
273 sizeof(GNUNET_MessageHello) + ntohs(hello->senderAddressSize)) || 278 sizeof(GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
274 (maddr->senderAddress 279 (maddr->senderAddress
275 [ntohs(hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0')) 280 [ntohs (hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0'))
276 { 281 {
277 GNUNET_GE_BREAK(ectx, 0); 282 GNUNET_GE_BREAK (ectx, 0);
278 return GNUNET_SYSERR; /* obviously invalid */ 283 return GNUNET_SYSERR; /* obviously invalid */
279 } 284 }
280 if (NULL == strstr(maddr->filter, ": ")) 285 if (NULL == strstr (maddr->filter, ": "))
281 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
282 return GNUNET_OK; 287 return GNUNET_OK;
283} 288}
@@ -290,64 +295,65 @@ api_verify_hello(const GNUNET_MessageHello * hello)
290 * @return hello on success, NULL on error 295 * @return hello on success, NULL on error
291 */ 296 */
292static GNUNET_MessageHello * 297static GNUNET_MessageHello *
293api_create_hello() 298api_create_hello ()
294{ 299{
295 GNUNET_MessageHello *msg; 300 GNUNET_MessageHello *msg;
296 char *filter; 301 char *filter;
297 EmailAddress *haddr; 302 EmailAddress *haddr;
298 int i; 303 int i;
299 304
300 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "FILTER", 305 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "FILTER",
301 "X-mailer: GNUnet", &filter); 306 "X-mailer: GNUnet", &filter);
302 if (NULL == strstr(filter, ": ")) 307 if (NULL == strstr (filter, ": "))
303 { 308 {
304 GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 309 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
305 _("SMTP filter string to invalid, lacks ': '\n")); 310 _ ("SMTP filter string to invalid, lacks ': '\n"));
306 GNUNET_free(filter); 311 GNUNET_free (filter);
307 return NULL; 312 return NULL;
308 } 313 }
309 314
310 if (strlen(filter) > FILTER_STRING_SIZE) 315 if (strlen (filter) > FILTER_STRING_SIZE)
311 { 316 {
312 filter[FILTER_STRING_SIZE] = '\0'; 317 filter[FILTER_STRING_SIZE] = '\0';
313 GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 318 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
314 _("SMTP filter string to long, capped to `%s'\n"), filter); 319 _ ("SMTP filter string to long, capped to `%s'\n"), filter);
315 } 320 }
316 i = (strlen(email) + 8) & (~7); /* make multiple of 8 */ 321 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
317 msg = 322 msg =
318 GNUNET_malloc(sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); 323 GNUNET_malloc (sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i);
319 memset(msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i); 324 memset (msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i);
320 haddr = (EmailAddress *)&msg[1]; 325 haddr = (EmailAddress *) &msg[1];
321 memset(&haddr->filter[0], 0, FILTER_STRING_SIZE); 326 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE);
322 strcpy(&haddr->filter[0], filter); 327 strcpy (&haddr->filter[0], filter);
323 GNUNET_memcpy(&haddr->senderAddress[0], email, strlen(email) + 1); 328 GNUNET_memcpy (&haddr->senderAddress[0], email, strlen (email) + 1);
324 msg->senderAddressSize = htons(strlen(email) + 1 + sizeof(EmailAddress)); 329 msg->senderAddressSize = htons (strlen (email) + 1 + sizeof(EmailAddress));
325 msg->protocol = htons(GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP); 330 msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP);
326 msg->MTU = htonl(smtpAPI.mtu); 331 msg->MTU = htonl (smtpAPI.mtu);
327 msg->header.size = htons(GNUNET_sizeof_hello(msg)); 332 msg->header.size = htons (GNUNET_sizeof_hello (msg));
328 if (api_verify_hello(msg) == GNUNET_SYSERR) 333 if (api_verify_hello (msg) == GNUNET_SYSERR)
329 GNUNET_GE_ASSERT(ectx, 0); 334 GNUNET_GE_ASSERT (ectx, 0);
330 GNUNET_free(filter); 335 GNUNET_free (filter);
331 return msg; 336 return msg;
332} 337}
333 338
334struct GetMessageClosure { 339struct GetMessageClosure
340{
335 unsigned int esize; 341 unsigned int esize;
336 unsigned int pos; 342 unsigned int pos;
337 char *ebody; 343 char *ebody;
338}; 344};
339 345
340static const char * 346static const char *
341get_message(void **buf, int *len, void *cls) 347get_message (void **buf, int *len, void *cls)
342{ 348{
343 struct GetMessageClosure *gmc = cls; 349 struct GetMessageClosure *gmc = cls;
344 350
345 *buf = NULL; 351 *buf = NULL;
346 if (len == NULL) 352 if (len == NULL)
347 { 353 {
348 gmc->pos = 0; 354 gmc->pos = 0;
349 return NULL; 355 return NULL;
350 } 356 }
351 if (gmc->pos == gmc->esize) 357 if (gmc->pos == gmc->esize)
352 return NULL; /* done */ 358 return NULL; /* done */
353 *len = gmc->esize; 359 *len = gmc->esize;
@@ -365,8 +371,8 @@ get_message(void **buf, int *len, void *cls)
365 * @return GNUNET_SYSERR on error, GNUNET_OK on success 371 * @return GNUNET_SYSERR on error, GNUNET_OK on success
366 */ 372 */
367static int 373static int
368api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size, 374api_send (GNUNET_TSession *tsession, const void *msg, const unsigned int size,
369 int important) 375 int important)
370{ 376{
371 const GNUNET_MessageHello *hello; 377 const GNUNET_MessageHello *hello;
372 const EmailAddress *haddr; 378 const EmailAddress *haddr;
@@ -386,139 +392,140 @@ api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size,
386 if (smtp_shutdown == GNUNET_YES) 392 if (smtp_shutdown == GNUNET_YES)
387 return GNUNET_SYSERR; 393 return GNUNET_SYSERR;
388 if ((size == 0) || (size > smtpAPI.mtu)) 394 if ((size == 0) || (size > smtpAPI.mtu))
389 { 395 {
390 GNUNET_GE_BREAK(ectx, 0); 396 GNUNET_GE_BREAK (ectx, 0);
391 return GNUNET_SYSERR; 397 return GNUNET_SYSERR;
392 } 398 }
393 now = GNUNET_get_time(); 399 now = GNUNET_get_time ();
394 if ((important != GNUNET_YES) && 400 if ((important != GNUNET_YES) &&
395 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) 401 ( ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) )
396 return GNUNET_NO; /* rate too high */ 402 return GNUNET_NO; /* rate too high */
397 last_transmission = now; 403 last_transmission = now;
398 404
399 hello = (const GNUNET_MessageHello *)tsession->internal; 405 hello = (const GNUNET_MessageHello *) tsession->internal;
400 if (hello == NULL) 406 if (hello == NULL)
401 return GNUNET_SYSERR; 407 return GNUNET_SYSERR;
402 GNUNET_mutex_lock(lock); 408 GNUNET_mutex_lock (lock);
403 session = smtp_create_session(); 409 session = smtp_create_session ();
404 if (session == NULL) 410 if (session == NULL)
405 { 411 {
406 GNUNET_GE_LOG(ectx, 412 GNUNET_GE_LOG (ectx,
407 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 413 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER
408 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), 414 | GNUNET_GE_IMMEDIATE, _ ("SMTP: `%s' failed: %s.\n"),
409 "smtp_create_session", smtp_strerror(smtp_errno(), ebuf, 415 "smtp_create_session", smtp_strerror (smtp_errno (), ebuf,
410 EBUF_LEN)); 416 EBUF_LEN));
411 GNUNET_mutex_unlock(lock); 417 GNUNET_mutex_unlock (lock);
412 return GNUNET_SYSERR; 418 return GNUNET_SYSERR;
413 } 419 }
414 if (0 == smtp_set_server(session, smtp_server_name)) 420 if (0 == smtp_set_server (session, smtp_server_name))
415 { 421 {
416 GNUNET_GE_LOG(ectx, 422 GNUNET_GE_LOG (ectx,
417 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 423 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER
418 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), 424 | GNUNET_GE_IMMEDIATE, _ ("SMTP: `%s' failed: %s.\n"),
419 "smtp_set_server", smtp_strerror(smtp_errno(), ebuf, 425 "smtp_set_server", smtp_strerror (smtp_errno (), ebuf,
420 EBUF_LEN)); 426 EBUF_LEN));
421 smtp_destroy_session(session); 427 smtp_destroy_session (session);
422 GNUNET_mutex_unlock(lock); 428 GNUNET_mutex_unlock (lock);
423 return GNUNET_SYSERR; 429 return GNUNET_SYSERR;
424 } 430 }
425 haddr = (const EmailAddress *)&hello[1]; 431 haddr = (const EmailAddress *) &hello[1];
426 message = smtp_add_message(session); 432 message = smtp_add_message (session);
427 if (message == NULL) 433 if (message == NULL)
428 { 434 {
429 GNUNET_GE_LOG(ectx, 435 GNUNET_GE_LOG (ectx,
430 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 436 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
431 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 437 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
432 "smtp_add_message", smtp_strerror(smtp_errno(), ebuf, 438 "smtp_add_message", smtp_strerror (smtp_errno (), ebuf,
433 EBUF_LEN)); 439 EBUF_LEN));
434 smtp_destroy_session(session); 440 smtp_destroy_session (session);
435 GNUNET_mutex_unlock(lock); 441 GNUNET_mutex_unlock (lock);
436 return GNUNET_SYSERR; 442 return GNUNET_SYSERR;
437 } 443 }
438 smtp_set_header(message, "To", NULL, haddr->senderAddress); 444 smtp_set_header (message, "To", NULL, haddr->senderAddress);
439 smtp_set_header(message, "From", NULL, email); 445 smtp_set_header (message, "From", NULL, email);
440 446
441 filter = GNUNET_strdup(haddr->filter); 447 filter = GNUNET_strdup (haddr->filter);
442 fvalue = strstr(filter, ": "); 448 fvalue = strstr (filter, ": ");
443 GNUNET_GE_ASSERT(NULL, NULL != fvalue); 449 GNUNET_GE_ASSERT (NULL, NULL != fvalue);
444 fvalue[0] = '\0'; 450 fvalue[0] = '\0';
445 fvalue += 2; 451 fvalue += 2;
446 if (0 == smtp_set_header(message, filter, fvalue)) 452 if (0 == smtp_set_header (message, filter, fvalue))
447 { 453 {
448 GNUNET_GE_LOG(ectx, 454 GNUNET_GE_LOG (ectx,
449 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 455 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
450 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 456 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
451 "smtp_set_header", smtp_strerror(smtp_errno(), ebuf, 457 "smtp_set_header", smtp_strerror (smtp_errno (), ebuf,
452 EBUF_LEN)); 458 EBUF_LEN));
453 smtp_destroy_session(session); 459 smtp_destroy_session (session);
454 GNUNET_mutex_unlock(lock); 460 GNUNET_mutex_unlock (lock);
455 GNUNET_free(filter); 461 GNUNET_free (filter);
456 return GNUNET_SYSERR; 462 return GNUNET_SYSERR;
457 } 463 }
458 GNUNET_free(filter); 464 GNUNET_free (filter);
459 m = GNUNET_malloc(size + sizeof(SMTPMessage)); 465 m = GNUNET_malloc (size + sizeof(SMTPMessage));
460 GNUNET_memcpy(m, msg, size); 466 GNUNET_memcpy (m, msg, size);
461 mp = (SMTPMessage *)&m[size]; 467 mp = (SMTPMessage *) &m[size];
462 mp->header.size = htons(size + sizeof(SMTPMessage)); 468 mp->header.size = htons (size + sizeof(SMTPMessage));
463 mp->header.type = htons(0); 469 mp->header.type = htons (0);
464 mp->sender = *core_api->my_identity; 470 mp->sender = *core_api->my_identity;
465 gm_cls.ebody = NULL; 471 gm_cls.ebody = NULL;
466 gm_cls.pos = 0; 472 gm_cls.pos = 0;
467 gm_cls.esize = GNUNET_STRINGS_base64_encode(m, size + sizeof(SMTPMessage), &gm_cls.ebody); 473 gm_cls.esize = GNUNET_STRINGS_base64_encode (m, size + sizeof(SMTPMessage),
468 GNUNET_free(m); 474 &gm_cls.ebody);
469 if (0 == smtp_size_set_estimate(message, gm_cls.esize)) 475 GNUNET_free (m);
470 { 476 if (0 == smtp_size_set_estimate (message, gm_cls.esize))
471 GNUNET_GE_LOG(ectx, 477 {
472 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 478 GNUNET_GE_LOG (ectx,
473 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 479 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
474 "smtp_size_set_estimate", smtp_strerror(smtp_errno(), ebuf, 480 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
481 "smtp_size_set_estimate", smtp_strerror (smtp_errno (), ebuf,
475 EBUF_LEN)); 482 EBUF_LEN));
476 } 483 }
477 if (0 == smtp_set_messagecb(message, &get_message, &gm_cls)) 484 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
478 { 485 {
479 GNUNET_GE_LOG(ectx, 486 GNUNET_GE_LOG (ectx,
480 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 487 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
481 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 488 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
482 "smtp_set_messagecb", smtp_strerror(smtp_errno(), ebuf, 489 "smtp_set_messagecb", smtp_strerror (smtp_errno (), ebuf,
483 EBUF_LEN)); 490 EBUF_LEN));
484 smtp_destroy_session(session); 491 smtp_destroy_session (session);
485 GNUNET_mutex_unlock(lock); 492 GNUNET_mutex_unlock (lock);
486 GNUNET_free(gm_cls.ebody); 493 GNUNET_free (gm_cls.ebody);
487 return GNUNET_SYSERR; 494 return GNUNET_SYSERR;
488 } 495 }
489 recipient = smtp_add_recipient(message, haddr->senderAddress); 496 recipient = smtp_add_recipient (message, haddr->senderAddress);
490 if (recipient == NULL) 497 if (recipient == NULL)
491 { 498 {
492 GNUNET_GE_LOG(ectx, 499 GNUNET_GE_LOG (ectx,
493 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 500 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
494 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 501 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
495 "smtp_add_recipient", smtp_strerror(smtp_errno(), ebuf, 502 "smtp_add_recipient", smtp_strerror (smtp_errno (), ebuf,
496 EBUF_LEN)); 503 EBUF_LEN));
497 smtp_destroy_session(session); 504 smtp_destroy_session (session);
498 GNUNET_mutex_unlock(lock); 505 GNUNET_mutex_unlock (lock);
499 return GNUNET_SYSERR; 506 return GNUNET_SYSERR;
500 } 507 }
501 if (0 == smtp_start_session(session)) 508 if (0 == smtp_start_session (session))
502 { 509 {
503 GNUNET_GE_LOG(ectx, 510 GNUNET_GE_LOG (ectx,
504 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 511 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
505 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 512 | GNUNET_GE_BULK, _ ("SMTP: `%s' failed: %s.\n"),
506 "smtp_start_session", smtp_strerror(smtp_errno(), ebuf, 513 "smtp_start_session", smtp_strerror (smtp_errno (), ebuf,
507 EBUF_LEN)); 514 EBUF_LEN));
508 smtp_destroy_session(session); 515 smtp_destroy_session (session);
509 GNUNET_mutex_unlock(lock); 516 GNUNET_mutex_unlock (lock);
510 GNUNET_free(gm_cls.ebody); 517 GNUNET_free (gm_cls.ebody);
511 return GNUNET_SYSERR; 518 return GNUNET_SYSERR;
512 } 519 }
513 if (stats != NULL) 520 if (stats != NULL)
514 stats->change(stat_bytesSent, size); 521 stats->change (stat_bytesSent, size);
515 if (core_api->load_monitor != NULL) 522 if (core_api->load_monitor != NULL)
516 GNUNET_network_monitor_notify_transmission(core_api->load_monitor, 523 GNUNET_network_monitor_notify_transmission (core_api->load_monitor,
517 GNUNET_ND_UPLOAD, gm_cls.esize); 524 GNUNET_ND_UPLOAD, gm_cls.esize);
518 smtp_message_reset_status(message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ 525 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */
519 smtp_destroy_session(session); 526 smtp_destroy_session (session);
520 GNUNET_mutex_unlock(lock); 527 GNUNET_mutex_unlock (lock);
521 GNUNET_free(gm_cls.ebody); 528 GNUNET_free (gm_cls.ebody);
522 return GNUNET_OK; 529 return GNUNET_OK;
523} 530}
524 531
@@ -530,15 +537,15 @@ api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size,
530 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 537 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
531 */ 538 */
532static int 539static int
533api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr, 540api_connect (const GNUNET_MessageHello *hello, GNUNET_TSession **tsessionPtr,
534 int may_reuse) 541 int may_reuse)
535{ 542{
536 GNUNET_TSession *tsession; 543 GNUNET_TSession *tsession;
537 544
538 tsession = GNUNET_new(GNUNET_TSession); 545 tsession = GNUNET_new (GNUNET_TSession);
539 tsession->internal = GNUNET_malloc(GNUNET_sizeof_hello(hello)); 546 tsession->internal = GNUNET_malloc (GNUNET_sizeof_hello (hello));
540 tsession->peer = hello->senderIdentity; 547 tsession->peer = hello->senderIdentity;
541 GNUNET_memcpy(tsession->internal, hello, GNUNET_sizeof_hello(hello)); 548 GNUNET_memcpy (tsession->internal, hello, GNUNET_sizeof_hello (hello));
542 tsession->ttype = smtpAPI.protocol_number; 549 tsession->ttype = smtpAPI.protocol_number;
543 (*tsessionPtr) = tsession; 550 (*tsessionPtr) = tsession;
544 return GNUNET_OK; 551 return GNUNET_OK;
@@ -551,14 +558,14 @@ api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
551 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 558 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
552 */ 559 */
553static int 560static int
554api_disconnect(GNUNET_TSession * tsession) 561api_disconnect (GNUNET_TSession *tsession)
555{ 562{
556 if (tsession != NULL) 563 if (tsession != NULL)
557 { 564 {
558 if (tsession->internal != NULL) 565 if (tsession->internal != NULL)
559 GNUNET_free(tsession->internal); 566 GNUNET_free (tsession->internal);
560 GNUNET_free(tsession); 567 GNUNET_free (tsession);
561 } 568 }
562 return GNUNET_OK; 569 return GNUNET_OK;
563} 570}
564 571
@@ -567,18 +574,18 @@ api_disconnect(GNUNET_TSession * tsession)
567 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 574 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
568 */ 575 */
569static int 576static int
570api_start_transport_server() 577api_start_transport_server ()
571{ 578{
572 smtp_shutdown = GNUNET_NO; 579 smtp_shutdown = GNUNET_NO;
573 /* initialize SMTP network */ 580 /* initialize SMTP network */
574 dispatchThread = GNUNET_thread_create(&listenAndDistribute, NULL, 1024 * 4); 581 dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
575 if (dispatchThread == NULL) 582 if (dispatchThread == NULL)
576 { 583 {
577 GNUNET_GE_DIE_STRERROR(ectx, 584 GNUNET_GE_DIE_STRERROR (ectx,
578 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, 585 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
579 "pthread_create"); 586 "pthread_create");
580 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
581 } 588 }
582 return GNUNET_OK; 589 return GNUNET_OK;
583} 590}
584 591
@@ -587,13 +594,13 @@ api_start_transport_server()
587 * restarted later! 594 * restarted later!
588 */ 595 */
589static int 596static int
590api_stop_transport_server() 597api_stop_transport_server ()
591{ 598{
592 void *unused; 599 void *unused;
593 600
594 smtp_shutdown = GNUNET_YES; 601 smtp_shutdown = GNUNET_YES;
595 GNUNET_thread_stop_sleep(dispatchThread); 602 GNUNET_thread_stop_sleep (dispatchThread);
596 GNUNET_thread_join(dispatchThread, &unused); 603 GNUNET_thread_join (dispatchThread, &unused);
597 return GNUNET_OK; 604 return GNUNET_OK;
598} 605}
599 606
@@ -601,8 +608,8 @@ api_stop_transport_server()
601 * Convert SMTP hello to an IP address (always fails). 608 * Convert SMTP hello to an IP address (always fails).
602 */ 609 */
603static int 610static int
604api_hello_to_address(const GNUNET_MessageHello * hello, void **sa, 611api_hello_to_address (const GNUNET_MessageHello *hello, void **sa,
605 unsigned int *sa_len) 612 unsigned int *sa_len)
606{ 613{
607 return GNUNET_SYSERR; 614 return GNUNET_SYSERR;
608} 615}
@@ -611,7 +618,7 @@ api_hello_to_address(const GNUNET_MessageHello * hello, void **sa,
611 * Always fails. 618 * Always fails.
612 */ 619 */
613static int 620static int
614api_associate(GNUNET_TSession * tsession) 621api_associate (GNUNET_TSession *tsession)
615{ 622{
616 return GNUNET_SYSERR; /* SMTP connections can never be associated */ 623 return GNUNET_SYSERR; /* SMTP connections can never be associated */
617} 624}
@@ -621,8 +628,8 @@ api_associate(GNUNET_TSession * tsession)
621 * frequency limits to SMTP in the future!). 628 * frequency limits to SMTP in the future!).
622 */ 629 */
623static int 630static int
624api_test_would_try(GNUNET_TSession * tsession, unsigned int size, 631api_test_would_try (GNUNET_TSession *tsession, unsigned int size,
625 int important) 632 int important)
626{ 633{
627 return GNUNET_OK; /* we always try... */ 634 return GNUNET_OK; /* we always try... */
628} 635}
@@ -632,61 +639,64 @@ api_test_would_try(GNUNET_TSession * tsession, unsigned int size,
632 * returns the smtp transport API. 639 * returns the smtp transport API.
633 */ 640 */
634GNUNET_TransportAPI * 641GNUNET_TransportAPI *
635inittransport_smtp(struct GNUNET_CoreAPIForTransport * core) 642inittransport_smtp (struct GNUNET_CoreAPIForTransport *core)
636{ 643{
637 unsigned long long mtu; 644 unsigned long long mtu;
638 struct sigaction sa; 645 struct sigaction sa;
639 646
640 core_api = core; 647 core_api = core;
641 ectx = core->ectx; 648 ectx = core->ectx;
642 if (!GNUNET_GC_have_configuration_value(core_api->cfg, "SMTP", "EMAIL")) 649 if (! GNUNET_GC_have_configuration_value (core_api->cfg, "SMTP", "EMAIL"))
643 { 650 {
644 GNUNET_GE_LOG(ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, 651 GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
645 _ 652 _
646 ("No email-address specified, can not start SMTP transport.\n")); 653 (
647 return NULL; 654 "No email-address specified, can not start SMTP transport.\n"));
648 } 655 return NULL;
649 GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "MTU", 1200, 656 }
650 SMTP_MESSAGE_SIZE, 657 GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "MTU", 1200,
651 SMTP_MESSAGE_SIZE, &mtu); 658 SMTP_MESSAGE_SIZE,
652 GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "RATELIMIT", 659 SMTP_MESSAGE_SIZE, &mtu);
653 0, 0, 1024 * 1024, &rate_limit); 660 GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "RATELIMIT",
654 stats = core_api->service_request("stats"); 661 0, 0, 1024 * 1024, &rate_limit);
662 stats = core_api->service_request ("stats");
655 if (stats != NULL) 663 if (stats != NULL)
656 { 664 {
657 stat_bytesReceived = 665 stat_bytesReceived =
658 stats->create(gettext_noop("# bytes received via SMTP")); 666 stats->create (gettext_noop ("# bytes received via SMTP"));
659 stat_bytesSent = stats->create(gettext_noop("# bytes sent via SMTP")); 667 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
660 stat_bytesDropped = 668 stat_bytesDropped =
661 stats->create(gettext_noop("# bytes dropped by SMTP (outgoing)")); 669 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
662 } 670 }
663 GNUNET_GC_get_configuration_value_filename(core_api->cfg, "SMTP", "PIPE", &pipename); 671 GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE",
664 unlink(pipename); 672 &pipename);
665 if (0 != mkfifo(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 673 unlink (pipename);
666 { 674 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
667 GNUNET_GE_LOG_STRERROR(ectx, 675 {
668 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, 676 GNUNET_GE_LOG_STRERROR (ectx,
669 "mkfifo"); 677 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
670 GNUNET_free(pipename); 678 "mkfifo");
671 core_api->service_release(stats); 679 GNUNET_free (pipename);
672 stats = NULL; 680 core_api->service_release (stats);
673 return NULL; 681 stats = NULL;
674 } 682 return NULL;
683 }
675 /* we need to allow the mailer program to send us messages; 684 /* we need to allow the mailer program to send us messages;
676 * easiest done by giving it write permissions (see Mantis #1142) */ 685 * easiest done by giving it write permissions (see Mantis #1142) */
677 if (0 != chmod(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 686 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
678 GNUNET_GE_LOG_STRERROR(ectx, 687 GNUNET_GE_LOG_STRERROR (ectx,
679 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 688 GNUNET_GE_ADMIN | GNUNET_GE_BULK
680 GNUNET_GE_WARNING, "chmod"); 689 | GNUNET_GE_WARNING, "chmod");
681 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "EMAIL", NULL, 690 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "EMAIL",
682 &email); 691 NULL,
683 lock = GNUNET_mutex_create(GNUNET_NO); 692 &email);
684 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "SERVER", 693 lock = GNUNET_mutex_create (GNUNET_NO);
685 "localhost:25", &smtp_server_name); 694 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "SERVER",
695 "localhost:25", &smtp_server_name);
686 sa.sa_handler = SIG_IGN; 696 sa.sa_handler = SIG_IGN;
687 sigemptyset(&sa.sa_mask); 697 sigemptyset (&sa.sa_mask);
688 sa.sa_flags = 0; 698 sa.sa_flags = 0;
689 sigaction(SIGPIPE, &sa, &old_handler); 699 sigaction (SIGPIPE, &sa, &old_handler);
690 700
691 smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP; 701 smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP;
692 smtpAPI.mtu = mtu - sizeof(SMTPMessage); 702 smtpAPI.mtu = mtu - sizeof(SMTPMessage);
@@ -705,21 +715,21 @@ inittransport_smtp(struct GNUNET_CoreAPIForTransport * core)
705} 715}
706 716
707void 717void
708donetransport_smtp() 718donetransport_smtp ()
709{ 719{
710 sigaction(SIGPIPE, &old_handler, NULL); 720 sigaction (SIGPIPE, &old_handler, NULL);
711 GNUNET_free(smtp_server_name); 721 GNUNET_free (smtp_server_name);
712 if (stats != NULL) 722 if (stats != NULL)
713 { 723 {
714 core_api->service_release(stats); 724 core_api->service_release (stats);
715 stats = NULL; 725 stats = NULL;
716 } 726 }
717 GNUNET_mutex_destroy(lock); 727 GNUNET_mutex_destroy (lock);
718 lock = NULL; 728 lock = NULL;
719 unlink(pipename); 729 unlink (pipename);
720 GNUNET_free(pipename); 730 GNUNET_free (pipename);
721 pipename = NULL; 731 pipename = NULL;
722 GNUNET_free(email); 732 GNUNET_free (email);
723 email = NULL; 733 email = NULL;
724} 734}
725 735