aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_smtp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_smtp.c')
-rw-r--r--src/transport/plugin_transport_smtp.c568
1 files changed, 282 insertions, 286 deletions
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index 9c0ac5ea5..074bc16fc 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -146,7 +146,7 @@ static GNUNET_CronTime last_transmission;
146 146
147#define FILLCHAR '=' 147#define FILLCHAR '='
148static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 148static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
149 "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; 149 "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
150 150
151/** 151/**
152 * Encode into Base64. 152 * Encode into Base64.
@@ -179,41 +179,41 @@ base64_encode (const char *data, unsigned int len, char **output)
179 opt[1] = '\n'; 179 opt[1] = '\n';
180 ret += 2; 180 ret += 2;
181 for (i = 0; i < len; ++i) 181 for (i = 0; i < len; ++i)
182 {
183 c = (data[i] >> 2) & 0x3f;
184 opt[ret++] = cvt[(int) c];
185 CHECKLINE;
186 c = (data[i] << 4) & 0x3f;
187 if (++i < len)
188 c |= (data[i] >> 4) & 0x0f;
189 opt[ret++] = cvt[(int) c];
190 CHECKLINE;
191 if (i < len)
182 { 192 {
183 c = (data[i] >> 2) & 0x3f; 193 c = (data[i] << 2) & 0x3f;
194 if (++i < len)
195 c |= (data[i] >> 6) & 0x03;
184 opt[ret++] = cvt[(int) c]; 196 opt[ret++] = cvt[(int) c];
185 CHECKLINE; 197 CHECKLINE;
186 c = (data[i] << 4) & 0x3f; 198 }
187 if (++i < len) 199 else
188 c |= (data[i] >> 4) & 0x0f; 200 {
201 ++i;
202 opt[ret++] = FILLCHAR;
203 CHECKLINE;
204 }
205 if (i < len)
206 {
207 c = data[i] & 0x3f;
189 opt[ret++] = cvt[(int) c]; 208 opt[ret++] = cvt[(int) c];
190 CHECKLINE; 209 CHECKLINE;
191 if (i < len)
192 {
193 c = (data[i] << 2) & 0x3f;
194 if (++i < len)
195 c |= (data[i] >> 6) & 0x03;
196 opt[ret++] = cvt[(int) c];
197 CHECKLINE;
198 }
199 else
200 {
201 ++i;
202 opt[ret++] = FILLCHAR;
203 CHECKLINE;
204 }
205 if (i < len)
206 {
207 c = data[i] & 0x3f;
208 opt[ret++] = cvt[(int) c];
209 CHECKLINE;
210 }
211 else
212 {
213 opt[ret++] = FILLCHAR;
214 CHECKLINE;
215 }
216 } 210 }
211 else
212 {
213 opt[ret++] = FILLCHAR;
214 CHECKLINE;
215 }
216 }
217 opt[ret++] = FILLCHAR; 217 opt[ret++] = FILLCHAR;
218 return ret; 218 return ret;
219} 219}
@@ -252,38 +252,38 @@ base64_decode (const char *data, unsigned int len, char **output)
252 "base64_decode decoding len=%d\n", len); 252 "base64_decode decoding len=%d\n", len);
253#endif 253#endif
254 for (i = 0; i < len; ++i) 254 for (i = 0; i < len; ++i)
255 {
256 CHECK_CRLF;
257 if (data[i] == FILLCHAR)
258 break;
259 c = (char) cvtfind (data[i]);
260 ++i;
261 CHECK_CRLF;
262 c1 = (char) cvtfind (data[i]);
263 c = (c << 2) | ((c1 >> 4) & 0x3);
264 (*output)[ret++] = c;
265 if (++i < len)
255 { 266 {
256 CHECK_CRLF; 267 CHECK_CRLF;
257 if (data[i] == FILLCHAR) 268 c = data[i];
269 if (FILLCHAR == c)
258 break; 270 break;
259 c = (char) cvtfind (data[i]); 271 c = (char) cvtfind (c);
260 ++i; 272 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
273 (*output)[ret++] = c1;
274 }
275 if (++i < len)
276 {
261 CHECK_CRLF; 277 CHECK_CRLF;
262 c1 = (char) cvtfind (data[i]); 278 c1 = data[i];
263 c = (c << 2) | ((c1 >> 4) & 0x3); 279 if (FILLCHAR == c1)
280 break;
281
282 c1 = (char) cvtfind (c1);
283 c = ((c << 6) & 0xc0) | c1;
264 (*output)[ret++] = c; 284 (*output)[ret++] = c;
265 if (++i < len)
266 {
267 CHECK_CRLF;
268 c = data[i];
269 if (FILLCHAR == c)
270 break;
271 c = (char) cvtfind (c);
272 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
273 (*output)[ret++] = c1;
274 }
275 if (++i < len)
276 {
277 CHECK_CRLF;
278 c1 = data[i];
279 if (FILLCHAR == c1)
280 break;
281
282 c1 = (char) cvtfind (c1);
283 c = ((c << 6) & 0xc0) | c1;
284 (*output)[ret++] = c;
285 }
286 } 285 }
286 }
287END: 287END:
288 return ret; 288 return ret;
289} 289}
@@ -323,83 +323,83 @@ listenAndDistribute (void *unused)
323 323
324 324
325 while (smtp_shutdown == GNUNET_NO) 325 while (smtp_shutdown == GNUNET_NO)
326 {
327 fd = OPEN (pipename, O_RDONLY | O_ASYNC);
328 if (fd == -1)
326 { 329 {
327 fd = OPEN (pipename, O_RDONLY | O_ASYNC); 330 if (smtp_shutdown == GNUNET_NO)
328 if (fd == -1) 331 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
329 { 332 continue;
330 if (smtp_shutdown == GNUNET_NO) 333 }
331 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); 334 fdes = fdopen (fd, "r");
332 continue; 335 while (smtp_shutdown == GNUNET_NO)
333 } 336 {
334 fdes = fdopen (fd, "r"); 337 /* skip until end of header */
335 while (smtp_shutdown == GNUNET_NO) 338 do
336 { 339 {
337 /* skip until end of header */ 340 READLINE (line, linesize);
338 do 341 }
339 { 342 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */
340 READLINE (line, linesize); 343 READLINE (line, linesize); /* read base64 encoded message; decode, process */
341 } 344 pos = 0;
342 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ 345 while (1)
343 READLINE (line, linesize); /* read base64 encoded message; decode, process */ 346 {
344 pos = 0; 347 pos = strlen (line) - 1; /* ignore new line */
345 while (1) 348 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */
346 { 349 if ((line[pos] == '\r') || (line[pos] == '\n'))
347 pos = strlen (line) - 1; /* ignore new line */ 350 break; /* empty line => end of message! */
348 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ 351 }
349 if ((line[pos] == '\r') || (line[pos] == '\n')) 352 size = base64_decode (line, pos, &out);
350 break; /* empty line => end of message! */ 353 if (size < sizeof (SMTPMessage))
351 } 354 {
352 size = base64_decode (line, pos, &out); 355 GNUNET_GE_BREAK (ectx, 0);
353 if (size < sizeof (SMTPMessage)) 356 GNUNET_free (out);
354 { 357 goto END;
355 GNUNET_GE_BREAK (ectx, 0); 358 }
356 GNUNET_free (out); 359
357 goto END; 360 mp = (SMTPMessage *) &out[size - sizeof (SMTPMessage)];
358 } 361 if (ntohs (mp->header.size) != size)
359 362 {
360 mp = (SMTPMessage *) & out[size - sizeof (SMTPMessage)]; 363 GNUNET_GE_LOG (ectx,
361 if (ntohs (mp->header.size) != size) 364 GNUNET_GE_WARNING | GNUNET_GE_BULK |
362 { 365 GNUNET_GE_USER,
363 GNUNET_GE_LOG (ectx, 366 _
364 GNUNET_GE_WARNING | GNUNET_GE_BULK | 367 ("Received malformed message via %s. Ignored.\n"),
365 GNUNET_GE_USER, 368 "SMTP");
366 _
367 ("Received malformed message via %s. Ignored.\n"),
368 "SMTP");
369#if DEBUG_SMTP
370 GNUNET_GE_LOG (ectx,
371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
372 GNUNET_GE_USER,
373 "Size returned by base64=%d, in the msg=%d.\n",
374 size, ntohl (mp->size));
375#endif
376 GNUNET_free (out);
377 goto END;
378 }
379 if (stats != NULL)
380 stats->change (stat_bytesReceived, size);
381 coreMP = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
382 coreMP->msg = out;
383 coreMP->size = size - sizeof (SMTPMessage);
384 coreMP->tsession = NULL;
385 coreMP->sender = mp->sender;
386#if DEBUG_SMTP 369#if DEBUG_SMTP
387 GNUNET_GE_LOG (ectx, 370 GNUNET_GE_LOG (ectx,
388 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
389 "SMTP message passed to the core.\n"); 372 GNUNET_GE_USER,
373 "Size returned by base64=%d, in the msg=%d.\n",
374 size, ntohl (mp->size));
390#endif 375#endif
391 376 GNUNET_free (out);
392 coreAPI->receive (coreMP); 377 goto END;
393 } 378 }
394 END: 379 if (stats != NULL)
380 stats->change (stat_bytesReceived, size);
381 coreMP = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
382 coreMP->msg = out;
383 coreMP->size = size - sizeof (SMTPMessage);
384 coreMP->tsession = NULL;
385 coreMP->sender = mp->sender;
395#if DEBUG_SMTP 386#if DEBUG_SMTP
396 GNUNET_GE_LOG (ectx, 387 GNUNET_GE_LOG (ectx,
397 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 388 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
398 "SMTP message processed.\n"); 389 "SMTP message passed to the core.\n");
399#endif 390#endif
400 if (fdes != NULL) 391
401 fclose (fdes); 392 coreAPI->receive (coreMP);
402 } 393 }
394END:
395#if DEBUG_SMTP
396 GNUNET_GE_LOG (ectx,
397 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
398 "SMTP message processed.\n");
399#endif
400 if (fdes != NULL)
401 fclose (fdes);
402 }
403 GNUNET_free (line); 403 GNUNET_free (line);
404 return NULL; 404 return NULL;
405} 405}
@@ -425,10 +425,10 @@ api_verify_hello (const GNUNET_MessageHello * hello)
425 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) || 425 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
426 (maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 - 426 (maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 -
427 FILTER_STRING_SIZE] != '\0')) 427 FILTER_STRING_SIZE] != '\0'))
428 { 428 {
429 GNUNET_GE_BREAK (ectx, 0); 429 GNUNET_GE_BREAK (ectx, 0);
430 return GNUNET_SYSERR; /* obviously invalid */ 430 return GNUNET_SYSERR; /* obviously invalid */
431 } 431 }
432 if (NULL == strstr (maddr->filter, ": ")) 432 if (NULL == strstr (maddr->filter, ": "))
433 return GNUNET_SYSERR; 433 return GNUNET_SYSERR;
434 return GNUNET_OK; 434 return GNUNET_OK;
@@ -453,27 +453,26 @@ api_create_hello ()
453 "SMTP", "FILTER", 453 "SMTP", "FILTER",
454 "X-mailer: GNUnet", &filter); 454 "X-mailer: GNUnet", &filter);
455 if (NULL == strstr (filter, ": ")) 455 if (NULL == strstr (filter, ": "))
456 { 456 {
457 GNUNET_GE_LOG (ectx, 457 GNUNET_GE_LOG (ectx,
458 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 458 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
459 _("SMTP filter string to invalid, lacks ': '\n")); 459 _("SMTP filter string to invalid, lacks ': '\n"));
460 GNUNET_free (filter); 460 GNUNET_free (filter);
461 return NULL; 461 return NULL;
462 } 462 }
463 463
464 if (strlen (filter) > FILTER_STRING_SIZE) 464 if (strlen (filter) > FILTER_STRING_SIZE)
465 { 465 {
466 filter[FILTER_STRING_SIZE] = '\0'; 466 filter[FILTER_STRING_SIZE] = '\0';
467 GNUNET_GE_LOG (ectx, 467 GNUNET_GE_LOG (ectx,
468 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 468 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
469 _("SMTP filter string to long, capped to `%s'\n"), 469 _("SMTP filter string to long, capped to `%s'\n"), filter);
470 filter); 470 }
471 }
472 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */ 471 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
473 msg = 472 msg =
474 GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i); 473 GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
475 memset (msg, 0, sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i); 474 memset (msg, 0, sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
476 haddr = (EmailAddress *) & msg[1]; 475 haddr = (EmailAddress *) &msg[1];
477 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE); 476 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE);
478 strcpy (&haddr->filter[0], filter); 477 strcpy (&haddr->filter[0], filter);
479 memcpy (&haddr->senderAddress[0], email, strlen (email) + 1); 478 memcpy (&haddr->senderAddress[0], email, strlen (email) + 1);
@@ -501,10 +500,10 @@ get_message (void **buf, int *len, void *cls)
501 500
502 *buf = NULL; 501 *buf = NULL;
503 if (len == NULL) 502 if (len == NULL)
504 { 503 {
505 gmc->pos = 0; 504 gmc->pos = 0;
506 return NULL; 505 return NULL;
507 } 506 }
508 if (gmc->pos == gmc->esize) 507 if (gmc->pos == gmc->esize)
509 return NULL; /* done */ 508 return NULL; /* done */
510 *len = gmc->esize; 509 *len = gmc->esize;
@@ -535,6 +534,7 @@ api_send (GNUNET_TSession * tsession,
535 smtp_session_t session; 534 smtp_session_t session;
536 smtp_message_t message; 535 smtp_message_t message;
537 smtp_recipient_t recipient; 536 smtp_recipient_t recipient;
537
538#define EBUF_LEN 128 538#define EBUF_LEN 128
539 char ebuf[EBUF_LEN]; 539 char ebuf[EBUF_LEN];
540 GNUNET_CronTime now; 540 GNUNET_CronTime now;
@@ -542,10 +542,10 @@ api_send (GNUNET_TSession * tsession,
542 if (smtp_shutdown == GNUNET_YES) 542 if (smtp_shutdown == GNUNET_YES)
543 return GNUNET_SYSERR; 543 return GNUNET_SYSERR;
544 if ((size == 0) || (size > smtpAPI.mtu)) 544 if ((size == 0) || (size > smtpAPI.mtu))
545 { 545 {
546 GNUNET_GE_BREAK (ectx, 0); 546 GNUNET_GE_BREAK (ectx, 0);
547 return GNUNET_SYSERR; 547 return GNUNET_SYSERR;
548 } 548 }
549 now = GNUNET_get_time (); 549 now = GNUNET_get_time ();
550 if ((important != GNUNET_YES) && 550 if ((important != GNUNET_YES) &&
551 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) 551 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS)
@@ -558,42 +558,42 @@ api_send (GNUNET_TSession * tsession,
558 GNUNET_mutex_lock (lock); 558 GNUNET_mutex_lock (lock);
559 session = smtp_create_session (); 559 session = smtp_create_session ();
560 if (session == NULL) 560 if (session == NULL)
561 { 561 {
562 GNUNET_GE_LOG (ectx, 562 GNUNET_GE_LOG (ectx,
563 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 563 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
564 GNUNET_GE_IMMEDIATE, 564 GNUNET_GE_IMMEDIATE,
565 _("SMTP: `%s' failed: %s.\n"), 565 _("SMTP: `%s' failed: %s.\n"),
566 "smtp_create_session", 566 "smtp_create_session",
567 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 567 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
568 GNUNET_mutex_unlock (lock); 568 GNUNET_mutex_unlock (lock);
569 return GNUNET_SYSERR; 569 return GNUNET_SYSERR;
570 } 570 }
571 if (0 == smtp_set_server (session, smtp_server_name)) 571 if (0 == smtp_set_server (session, smtp_server_name))
572 { 572 {
573 GNUNET_GE_LOG (ectx, 573 GNUNET_GE_LOG (ectx,
574 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 574 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
575 GNUNET_GE_IMMEDIATE, 575 GNUNET_GE_IMMEDIATE,
576 _("SMTP: `%s' failed: %s.\n"), 576 _("SMTP: `%s' failed: %s.\n"),
577 "smtp_set_server", 577 "smtp_set_server",
578 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 578 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
579 smtp_destroy_session (session); 579 smtp_destroy_session (session);
580 GNUNET_mutex_unlock (lock); 580 GNUNET_mutex_unlock (lock);
581 return GNUNET_SYSERR; 581 return GNUNET_SYSERR;
582 } 582 }
583 haddr = (const EmailAddress *) &hello[1]; 583 haddr = (const EmailAddress *) &hello[1];
584 message = smtp_add_message (session); 584 message = smtp_add_message (session);
585 if (message == NULL) 585 if (message == NULL)
586 { 586 {
587 GNUNET_GE_LOG (ectx, 587 GNUNET_GE_LOG (ectx,
588 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 588 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
589 GNUNET_GE_BULK, 589 GNUNET_GE_BULK,
590 _("SMTP: `%s' failed: %s.\n"), 590 _("SMTP: `%s' failed: %s.\n"),
591 "smtp_add_message", 591 "smtp_add_message",
592 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 592 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
593 smtp_destroy_session (session); 593 smtp_destroy_session (session);
594 GNUNET_mutex_unlock (lock); 594 GNUNET_mutex_unlock (lock);
595 return GNUNET_SYSERR; 595 return GNUNET_SYSERR;
596 } 596 }
597 smtp_set_header (message, "To", NULL, haddr->senderAddress); 597 smtp_set_header (message, "To", NULL, haddr->senderAddress);
598 smtp_set_header (message, "From", NULL, email); 598 smtp_set_header (message, "From", NULL, email);
599 599
@@ -603,84 +603,82 @@ api_send (GNUNET_TSession * tsession,
603 fvalue[0] = '\0'; 603 fvalue[0] = '\0';
604 fvalue += 2; 604 fvalue += 2;
605 if (0 == smtp_set_header (message, filter, fvalue)) 605 if (0 == smtp_set_header (message, filter, fvalue))
606 { 606 {
607 GNUNET_GE_LOG (ectx, 607 GNUNET_GE_LOG (ectx,
608 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 608 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
609 GNUNET_GE_BULK, 609 GNUNET_GE_BULK,
610 _("SMTP: `%s' failed: %s.\n"), 610 _("SMTP: `%s' failed: %s.\n"),
611 "smtp_set_header", 611 "smtp_set_header",
612 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 612 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
613 smtp_destroy_session (session); 613 smtp_destroy_session (session);
614 GNUNET_mutex_unlock (lock); 614 GNUNET_mutex_unlock (lock);
615 GNUNET_free (filter); 615 GNUNET_free (filter);
616 return GNUNET_SYSERR; 616 return GNUNET_SYSERR;
617 } 617 }
618 GNUNET_free (filter); 618 GNUNET_free (filter);
619 m = GNUNET_malloc (size + sizeof (SMTPMessage)); 619 m = GNUNET_malloc (size + sizeof (SMTPMessage));
620 memcpy (m, msg, size); 620 memcpy (m, msg, size);
621 mp = (SMTPMessage *) & m[size]; 621 mp = (SMTPMessage *) &m[size];
622 mp->header.size = htons (size + sizeof (SMTPMessage)); 622 mp->header.size = htons (size + sizeof (SMTPMessage));
623 mp->header.type = htons (0); 623 mp->header.type = htons (0);
624 mp->sender = *coreAPI->my_identity; 624 mp->sender = *coreAPI->my_identity;
625 gm_cls.ebody = NULL; 625 gm_cls.ebody = NULL;
626 gm_cls.pos = 0; 626 gm_cls.pos = 0;
627 gm_cls.esize = 627 gm_cls.esize = base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody);
628 base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody);
629 GNUNET_free (m); 628 GNUNET_free (m);
630 if (0 == smtp_size_set_estimate (message, gm_cls.esize)) 629 if (0 == smtp_size_set_estimate (message, gm_cls.esize))
631 { 630 {
632 GNUNET_GE_LOG (ectx, 631 GNUNET_GE_LOG (ectx,
633 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 632 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
634 GNUNET_GE_BULK, 633 GNUNET_GE_BULK,
635 _("SMTP: `%s' failed: %s.\n"), 634 _("SMTP: `%s' failed: %s.\n"),
636 "smtp_size_set_estimate", 635 "smtp_size_set_estimate",
637 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 636 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
638 } 637 }
639 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls)) 638 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
640 { 639 {
641 GNUNET_GE_LOG (ectx, 640 GNUNET_GE_LOG (ectx,
642 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 641 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
643 GNUNET_GE_BULK, 642 GNUNET_GE_BULK,
644 _("SMTP: `%s' failed: %s.\n"), 643 _("SMTP: `%s' failed: %s.\n"),
645 "smtp_set_messagecb", 644 "smtp_set_messagecb",
646 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 645 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
647 smtp_destroy_session (session); 646 smtp_destroy_session (session);
648 GNUNET_mutex_unlock (lock); 647 GNUNET_mutex_unlock (lock);
649 GNUNET_free (gm_cls.ebody); 648 GNUNET_free (gm_cls.ebody);
650 return GNUNET_SYSERR; 649 return GNUNET_SYSERR;
651 } 650 }
652 recipient = smtp_add_recipient (message, haddr->senderAddress); 651 recipient = smtp_add_recipient (message, haddr->senderAddress);
653 if (recipient == NULL) 652 if (recipient == NULL)
654 { 653 {
655 GNUNET_GE_LOG (ectx, 654 GNUNET_GE_LOG (ectx,
656 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 655 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
657 GNUNET_GE_BULK, 656 GNUNET_GE_BULK,
658 _("SMTP: `%s' failed: %s.\n"), 657 _("SMTP: `%s' failed: %s.\n"),
659 "smtp_add_recipient", 658 "smtp_add_recipient",
660 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 659 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
661 smtp_destroy_session (session); 660 smtp_destroy_session (session);
662 GNUNET_mutex_unlock (lock); 661 GNUNET_mutex_unlock (lock);
663 return GNUNET_SYSERR; 662 return GNUNET_SYSERR;
664 } 663 }
665 if (0 == smtp_start_session (session)) 664 if (0 == smtp_start_session (session))
666 { 665 {
667 GNUNET_GE_LOG (ectx, 666 GNUNET_GE_LOG (ectx,
668 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 667 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
669 GNUNET_GE_BULK, 668 GNUNET_GE_BULK,
670 _("SMTP: `%s' failed: %s.\n"), 669 _("SMTP: `%s' failed: %s.\n"),
671 "smtp_start_session", 670 "smtp_start_session",
672 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 671 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
673 smtp_destroy_session (session); 672 smtp_destroy_session (session);
674 GNUNET_mutex_unlock (lock); 673 GNUNET_mutex_unlock (lock);
675 GNUNET_free (gm_cls.ebody); 674 GNUNET_free (gm_cls.ebody);
676 return GNUNET_SYSERR; 675 return GNUNET_SYSERR;
677 } 676 }
678 if (stats != NULL) 677 if (stats != NULL)
679 stats->change (stat_bytesSent, size); 678 stats->change (stat_bytesSent, size);
680 if (coreAPI->load_monitor != NULL) 679 if (coreAPI->load_monitor != NULL)
681 GNUNET_network_monitor_notify_transmission (coreAPI->load_monitor, 680 GNUNET_network_monitor_notify_transmission (coreAPI->load_monitor,
682 GNUNET_ND_UPLOAD, 681 GNUNET_ND_UPLOAD, gm_cls.esize);
683 gm_cls.esize);
684 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ 682 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */
685 smtp_destroy_session (session); 683 smtp_destroy_session (session);
686 GNUNET_mutex_unlock (lock); 684 GNUNET_mutex_unlock (lock);
@@ -720,11 +718,11 @@ static int
720api_disconnect (GNUNET_TSession * tsession) 718api_disconnect (GNUNET_TSession * tsession)
721{ 719{
722 if (tsession != NULL) 720 if (tsession != NULL)
723 { 721 {
724 if (tsession->internal != NULL) 722 if (tsession->internal != NULL)
725 GNUNET_free (tsession->internal); 723 GNUNET_free (tsession->internal);
726 GNUNET_free (tsession); 724 GNUNET_free (tsession);
727 } 725 }
728 return GNUNET_OK; 726 return GNUNET_OK;
729} 727}
730 728
@@ -737,15 +735,14 @@ api_start_transport_server ()
737{ 735{
738 smtp_shutdown = GNUNET_NO; 736 smtp_shutdown = GNUNET_NO;
739 /* initialize SMTP network */ 737 /* initialize SMTP network */
740 dispatchThread = 738 dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
741 GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
742 if (dispatchThread == NULL) 739 if (dispatchThread == NULL)
743 { 740 {
744 GNUNET_GE_DIE_STRERROR (ectx, 741 GNUNET_GE_DIE_STRERROR (ectx,
745 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 742 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
746 GNUNET_GE_FATAL, "pthread_create"); 743 GNUNET_GE_FATAL, "pthread_create");
747 return GNUNET_SYSERR; 744 return GNUNET_SYSERR;
748 } 745 }
749 return GNUNET_OK; 746 return GNUNET_OK;
750} 747}
751 748
@@ -809,13 +806,13 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
809 coreAPI = core; 806 coreAPI = core;
810 ectx = core->ectx; 807 ectx = core->ectx;
811 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL")) 808 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL"))
812 { 809 {
813 GNUNET_GE_LOG (ectx, 810 GNUNET_GE_LOG (ectx,
814 GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, 811 GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
815 _ 812 _
816 ("No email-address specified, can not start SMTP transport.\n")); 813 ("No email-address specified, can not start SMTP transport.\n"));
817 return NULL; 814 return NULL;
818 } 815 }
819 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, 816 GNUNET_GC_get_configuration_value_number (coreAPI->cfg,
820 "SMTP", 817 "SMTP",
821 "MTU", 818 "MTU",
@@ -828,13 +825,13 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
828 0, 0, 1024 * 1024, &rate_limit); 825 0, 0, 1024 * 1024, &rate_limit);
829 stats = coreAPI->service_request ("stats"); 826 stats = coreAPI->service_request ("stats");
830 if (stats != NULL) 827 if (stats != NULL)
831 { 828 {
832 stat_bytesReceived 829 stat_bytesReceived
833 = stats->create (gettext_noop ("# bytes received via SMTP")); 830 = stats->create (gettext_noop ("# bytes received via SMTP"));
834 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP")); 831 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
835 stat_bytesDropped 832 stat_bytesDropped
836 = stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); 833 = stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
837 } 834 }
838 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg, 835 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg,
839 "SMTP", 836 "SMTP",
840 "PIPE", 837 "PIPE",
@@ -842,17 +839,17 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
842 "/smtp-pipe", &pipename); 839 "/smtp-pipe", &pipename);
843 UNLINK (pipename); 840 UNLINK (pipename);
844 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 841 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
845 { 842 {
846 GNUNET_GE_LOG_STRERROR (ectx, 843 GNUNET_GE_LOG_STRERROR (ectx,
847 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 844 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
848 GNUNET_GE_FATAL, "mkfifo"); 845 GNUNET_GE_FATAL, "mkfifo");
849 GNUNET_free (pipename); 846 GNUNET_free (pipename);
850 coreAPI->service_release (stats); 847 coreAPI->service_release (stats);
851 stats = NULL; 848 stats = NULL;
852 return NULL; 849 return NULL;
853 } 850 }
854 /* we need to allow the mailer program to send us messages; 851 /* we need to allow the mailer program to send us messages;
855 easiest done by giving it write permissions (see Mantis #1142) */ 852 * easiest done by giving it write permissions (see Mantis #1142) */
856 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 853 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
857 GNUNET_GE_LOG_STRERROR (ectx, 854 GNUNET_GE_LOG_STRERROR (ectx,
858 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 855 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
@@ -863,8 +860,7 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
863 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 860 GNUNET_GC_get_configuration_value_string (coreAPI->cfg,
864 "SMTP", 861 "SMTP",
865 "SERVER", 862 "SERVER",
866 "localhost:25", 863 "localhost:25", &smtp_server_name);
867 &smtp_server_name);
868 sa.sa_handler = SIG_IGN; 864 sa.sa_handler = SIG_IGN;
869 sigemptyset (&sa.sa_mask); 865 sigemptyset (&sa.sa_mask);
870 sa.sa_flags = 0; 866 sa.sa_flags = 0;
@@ -892,10 +888,10 @@ donetransport_smtp ()
892 sigaction (SIGPIPE, &old_handler, NULL); 888 sigaction (SIGPIPE, &old_handler, NULL);
893 GNUNET_free (smtp_server_name); 889 GNUNET_free (smtp_server_name);
894 if (stats != NULL) 890 if (stats != NULL)
895 { 891 {
896 coreAPI->service_release (stats); 892 coreAPI->service_release (stats);
897 stats = NULL; 893 stats = NULL;
898 } 894 }
899 GNUNET_mutex_destroy (lock); 895 GNUNET_mutex_destroy (lock);
900 lock = NULL; 896 lock = NULL;
901 UNLINK (pipename); 897 UNLINK (pipename);