Commit 0aed0d58 0aed0d5832e76d20f2ea560293955214cb182553 by Sergey Poznyakoff

Minor fixes

* libproto/mailer/smtp.c: fix indentation
1 parent 496bdf72
...@@ -95,6 +95,7 @@ static struct _mu_record _smtp_record = { ...@@ -95,6 +95,7 @@ static struct _mu_record _smtp_record = {
95 NULL, /* _get_mailer method. */ 95 NULL, /* _get_mailer method. */
96 NULL /* _get_folder method. */ 96 NULL /* _get_folder method. */
97 }; 97 };
98
98 /* We export : url parsing and the initialisation of 99 /* We export : url parsing and the initialisation of
99 the mailbox, via the register entry/record. */ 100 the mailbox, via the register entry/record. */
100 mu_record_t mu_smtp_record = &_smtp_record; 101 mu_record_t mu_smtp_record = &_smtp_record;
...@@ -163,19 +164,20 @@ typedef struct _smtp *smtp_t; ...@@ -163,19 +164,20 @@ typedef struct _smtp *smtp_t;
163 #define AUTH_GSSAPI 0x00000010 164 #define AUTH_GSSAPI 0x00000010
164 #define AUTH_EXTERNAL 0x00000020 165 #define AUTH_EXTERNAL 0x00000020
165 166
166 struct auth_mech_record { 167 struct auth_mech_record
168 {
167 unsigned long id; 169 unsigned long id;
168 char *name; 170 char *name;
169 }; 171 };
170 172
171 static struct auth_mech_record auth_mech_list[] = { 173 static struct auth_mech_record auth_mech_list[] = {
172 { AUTH_LOGIN, "login" }, 174 {AUTH_LOGIN, "login"},
173 { AUTH_PLAIN, "plain" }, 175 {AUTH_PLAIN, "plain"},
174 { AUTH_CRAM_MD5, "cram-md5" }, 176 {AUTH_CRAM_MD5, "cram-md5"},
175 { AUTH_DIGEST_MD5, "digest-md5" }, 177 {AUTH_DIGEST_MD5, "digest-md5"},
176 { AUTH_GSSAPI, "gssapi" }, 178 {AUTH_GSSAPI, "gssapi"},
177 { AUTH_EXTERNAL, "external" }, 179 {AUTH_EXTERNAL, "external"},
178 { 0, NULL }, 180 {0, NULL},
179 }; 181 };
180 182
181 static void smtp_destroy (mu_mailer_t); 183 static void smtp_destroy (mu_mailer_t);
...@@ -238,7 +240,8 @@ CLEAR_STATE (smtp_t smtp) ...@@ -238,7 +240,8 @@ CLEAR_STATE (smtp_t smtp)
238 as that which is ongoing. Check this. */ 240 as that which is ongoing. Check this. */
239 static int 241 static int
240 smtp_check_send_resumption (smtp_t smtp, 242 smtp_check_send_resumption (smtp_t smtp,
241 mu_message_t msg, mu_address_t from, mu_address_t to) 243 mu_message_t msg, mu_address_t from,
244 mu_address_t to)
242 { 245 {
243 if (smtp->state == SMTP_NO_STATE) 246 if (smtp->state == SMTP_NO_STATE)
244 return 0; 247 return 0;
...@@ -324,6 +327,7 @@ _mailer_smtp_init (mu_mailer_t mailer) ...@@ -324,6 +327,7 @@ _mailer_smtp_init (mu_mailer_t mailer)
324 /* Set our properties. */ 327 /* Set our properties. */
325 { 328 {
326 mu_property_t property = NULL; 329 mu_property_t property = NULL;
330
327 mu_mailer_get_property (mailer, &property); 331 mu_mailer_get_property (mailer, &property);
328 mu_property_set_value (property, "TYPE", "SMTP", 1); 332 mu_property_set_value (property, "TYPE", "SMTP", 1);
329 } 333 }
...@@ -429,8 +433,7 @@ smtp_open (mu_mailer_t mailer, int flags) ...@@ -429,8 +433,7 @@ smtp_open (mu_mailer_t mailer, int flags)
429 433
430 case SMTP_OPEN: 434 case SMTP_OPEN:
431 MU_DEBUG2 (mailer->debug, MU_DEBUG_PROT, 435 MU_DEBUG2 (mailer->debug, MU_DEBUG_PROT,
432 "smtp_open (host: %s port: %ld)\n", 436 "smtp_open (host: %s port: %ld)\n", smtp->mailhost, port);
433 smtp->mailhost, port);
434 status = mu_stream_open (mailer->stream); 437 status = mu_stream_open (mailer->stream);
435 CHECK_EAGAIN (smtp, status); 438 CHECK_EAGAIN (smtp, status);
436 smtp->state = SMTP_GREETINGS; 439 smtp->state = SMTP_GREETINGS;
...@@ -446,7 +449,7 @@ smtp_open (mu_mailer_t mailer, int flags) ...@@ -446,7 +449,7 @@ smtp_open (mu_mailer_t mailer, int flags)
446 return EACCES; 449 return EACCES;
447 } 450 }
448 451
449 ehlo: 452 ehlo:
450 status = smtp_writeline (smtp, "EHLO %s\r\n", smtp->localhost); 453 status = smtp_writeline (smtp, "EHLO %s\r\n", smtp->localhost);
451 CHECK_ERROR (smtp, status); 454 CHECK_ERROR (smtp, status);
452 455
...@@ -475,7 +478,8 @@ ehlo: ...@@ -475,7 +478,8 @@ ehlo:
475 478
476 if (smtp->capa & CAPA_STARTTLS) 479 if (smtp->capa & CAPA_STARTTLS)
477 smtp->state = SMTP_STARTTLS; 480 smtp->state = SMTP_STARTTLS;
478 else if (smtp->capa & CAPA_AUTH && mailer->url->user) { 481 else if (smtp->capa & CAPA_AUTH && mailer->url->user)
482 {
479 smtp->state = SMTP_AUTH; 483 smtp->state = SMTP_AUTH;
480 } 484 }
481 else 485 else
...@@ -484,14 +488,16 @@ ehlo: ...@@ -484,14 +488,16 @@ ehlo:
484 488
485 case SMTP_STARTTLS: 489 case SMTP_STARTTLS:
486 case SMTP_STARTTLS_ACK: 490 case SMTP_STARTTLS_ACK:
487 if (smtp->capa & CAPA_STARTTLS) { 491 if (smtp->capa & CAPA_STARTTLS)
492 {
488 smtp_starttls (smtp); 493 smtp_starttls (smtp);
489 goto ehlo; 494 goto ehlo;
490 } 495 }
491 496
492 case SMTP_AUTH: 497 case SMTP_AUTH:
493 case SMTP_AUTH_ACK: 498 case SMTP_AUTH_ACK:
494 if (smtp->capa & CAPA_AUTH) { 499 if (smtp->capa & CAPA_AUTH)
500 {
495 smtp_auth (smtp); 501 smtp_auth (smtp);
496 break; 502 break;
497 } 503 }
...@@ -532,6 +538,7 @@ smtp_close (mu_mailer_t mailer) ...@@ -532,6 +538,7 @@ smtp_close (mu_mailer_t mailer)
532 { 538 {
533 smtp_t smtp = mailer->data; 539 smtp_t smtp = mailer->data;
534 int status; 540 int status;
541
535 switch (smtp->state) 542 switch (smtp->state)
536 { 543 {
537 case SMTP_NO_STATE: 544 case SMTP_NO_STATE:
...@@ -565,6 +572,7 @@ smtp_reader (void *iodata) ...@@ -565,6 +572,7 @@ smtp_reader (void *iodata)
565 { 572 {
566 int status = 0; 573 int status = 0;
567 smtp_t iop = iodata; 574 smtp_t iop = iodata;
575
568 status = smtp_read_ack (iop); 576 status = smtp_read_ack (iop);
569 CHECK_EAGAIN (iop, status); 577 CHECK_EAGAIN (iop, status);
570 return status; 578 return status;
...@@ -575,6 +583,7 @@ smtp_writer (void *iodata, char *buf) ...@@ -575,6 +583,7 @@ smtp_writer (void *iodata, char *buf)
575 { 583 {
576 smtp_t iop = iodata; 584 smtp_t iop = iodata;
577 int status; 585 int status;
586
578 if (mu_c_strncasecmp (buf, "EHLO", 4) == 0) 587 if (mu_c_strncasecmp (buf, "EHLO", 4) == 0)
579 status = smtp_writeline (iop, "%s %s\r\n", buf, iop->localhost); 588 status = smtp_writeline (iop, "%s %s\r\n", buf, iop->localhost);
580 else 589 else
...@@ -586,9 +595,10 @@ smtp_writer (void *iodata, char *buf) ...@@ -586,9 +595,10 @@ smtp_writer (void *iodata, char *buf)
586 } 595 }
587 596
588 static void 597 static void
589 smtp_stream_ctl (void *iodata, mu_stream_t *pold, mu_stream_t new) 598 smtp_stream_ctl (void *iodata, mu_stream_t * pold, mu_stream_t new)
590 { 599 {
591 smtp_t iop = iodata; 600 smtp_t iop = iodata;
601
592 if (pold) 602 if (pold)
593 *pold = iop->mailer->stream; 603 *pold = iop->mailer->stream;
594 if (new) 604 if (new)
...@@ -642,7 +652,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) ...@@ -642,7 +652,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest)
642 if (secret_len > 64) 652 if (secret_len > 64)
643 { 653 {
644 mu_md5_init_ctx (&context); 654 mu_md5_init_ctx (&context);
645 mu_md5_process_bytes ((unsigned char *)secret, secret_len, &context); 655 mu_md5_process_bytes ((unsigned char *) secret, secret_len, &context);
646 mu_md5_finish_ctx (&context, ipad); 656 mu_md5_finish_ctx (&context, ipad);
647 mu_md5_finish_ctx (&context, opad); 657 mu_md5_finish_ctx (&context, opad);
648 } 658 }
...@@ -660,7 +670,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest) ...@@ -660,7 +670,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest)
660 670
661 mu_md5_init_ctx (&context); 671 mu_md5_init_ctx (&context);
662 mu_md5_process_bytes (ipad, sizeof (ipad), &context); 672 mu_md5_process_bytes (ipad, sizeof (ipad), &context);
663 mu_md5_process_bytes ((unsigned char *)challenge, challenge_len, &context); 673 mu_md5_process_bytes ((unsigned char *) challenge, challenge_len, &context);
664 mu_md5_finish_ctx (&context, digest); 674 mu_md5_finish_ctx (&context, digest);
665 675
666 mu_md5_init_ctx (&context); 676 mu_md5_init_ctx (&context);
...@@ -725,6 +735,7 @@ smtp_auth (smtp_t smtp) ...@@ -725,6 +735,7 @@ smtp_auth (smtp_t smtp)
725 unsigned char *b64buf = NULL; 735 unsigned char *b64buf = NULL;
726 unsigned char digest[16]; 736 unsigned char digest[16];
727 static char ascii_digest[33]; 737 static char ascii_digest[33];
738
728 memset (digest, 0, 16); 739 memset (digest, 0, 16);
729 740
730 status = mu_url_sget_user (mailer->url, &user); 741 status = mu_url_sget_user (mailer->url, &user);
...@@ -757,7 +768,7 @@ smtp_auth (smtp_t smtp) ...@@ -757,7 +768,7 @@ smtp_auth (smtp_t smtp)
757 mu_rtrim_cset (p, "\r\n"); 768 mu_rtrim_cset (p, "\r\n");
758 mu_base64_decode (p, strlen (p), &chl, &chlen); 769 mu_base64_decode (p, strlen (p), &chl, &chlen);
759 770
760 cram_md5 ((char *)mu_secret_password (secret), chl, digest); 771 cram_md5 ((char *) mu_secret_password (secret), chl, digest);
761 mu_secret_password_unref (secret); 772 mu_secret_password_unref (secret);
762 free (chl); 773 free (chl);
763 774
...@@ -825,7 +836,8 @@ smtp_auth (smtp_t smtp) ...@@ -825,7 +836,8 @@ smtp_auth (smtp_t smtp)
825 } 836 }
826 837
827 static int 838 static int
828 message_set_header_value (mu_message_t msg, const char *field, const char *value) 839 message_set_header_value (mu_message_t msg, const char *field,
840 const char *value)
829 { 841 {
830 int status = 0; 842 int status = 0;
831 mu_header_t hdr = NULL; 843 mu_header_t hdr = NULL;
...@@ -895,8 +907,8 @@ The correct algorithm is ...@@ -895,8 +907,8 @@ The correct algorithm is
895 */ 907 */
896 908
897 static int 909 static int
898 smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom, 910 smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg,
899 mu_address_t argto) 911 mu_address_t argfrom, mu_address_t argto)
900 { 912 {
901 smtp_t smtp = NULL; 913 smtp_t smtp = NULL;
902 int status; 914 int status;
...@@ -1168,7 +1180,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom ...@@ -1168,7 +1180,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom
1168 } 1180 }
1169 1181
1170 int 1182 int
1171 smtp_address_add (mu_address_t *paddr, const char *value) 1183 smtp_address_add (mu_address_t * paddr, const char *value)
1172 { 1184 {
1173 mu_address_t addr = NULL; 1185 mu_address_t addr = NULL;
1174 int status; 1186 int status;
...@@ -1300,6 +1312,7 @@ smtp_writeline (smtp_t smtp, const char *format, ...) ...@@ -1300,6 +1312,7 @@ smtp_writeline (smtp_t smtp, const char *format, ...)
1300 { 1312 {
1301 char *buffer = NULL; 1313 char *buffer = NULL;
1302 size_t buflen = smtp->buflen * 2; 1314 size_t buflen = smtp->buflen * 2;
1315
1303 buffer = realloc (smtp->buffer, buflen); 1316 buffer = realloc (smtp->buffer, buflen);
1304 if (smtp->buffer == NULL) 1317 if (smtp->buffer == NULL)
1305 return ENOMEM; 1318 return ENOMEM;
...@@ -1333,6 +1346,7 @@ smtp_write (smtp_t smtp) ...@@ -1333,6 +1346,7 @@ smtp_write (smtp_t smtp)
1333 { 1346 {
1334 int status = 0; 1347 int status = 0;
1335 size_t len; 1348 size_t len;
1349
1336 if (smtp->ptr > smtp->buffer) 1350 if (smtp->ptr > smtp->buffer)
1337 { 1351 {
1338 len = smtp->ptr - smtp->buffer; 1352 len = smtp->ptr - smtp->buffer;
...@@ -1386,7 +1400,8 @@ smtp_parse_ehlo_ack (smtp_t smtp) ...@@ -1386,7 +1400,8 @@ smtp_parse_ehlo_ack (smtp_t smtp)
1386 status = smtp_readline (smtp); 1400 status = smtp_readline (smtp);
1387 if ((smtp->ptr - smtp->buffer) > 4 && smtp->buffer[3] == '-') 1401 if ((smtp->ptr - smtp->buffer) > 4 && smtp->buffer[3] == '-')
1388 multi = 1; 1402 multi = 1;
1389 if (status == 0) { 1403 if (status == 0)
1404 {
1390 smtp->ptr = smtp->buffer; 1405 smtp->ptr = smtp->buffer;
1391 1406
1392 if (!mu_c_strncasecmp (smtp->buffer, "250-STARTTLS", 12)) 1407 if (!mu_c_strncasecmp (smtp->buffer, "250-STARTTLS", 12))
...@@ -1398,6 +1413,7 @@ smtp_parse_ehlo_ack (smtp_t smtp) ...@@ -1398,6 +1413,7 @@ smtp_parse_ehlo_ack (smtp_t smtp)
1398 { 1413 {
1399 char *p; 1414 char *p;
1400 size_t n = strtoul (smtp->buffer + 9, &p, 10); 1415 size_t n = strtoul (smtp->buffer + 9, &p, 10);
1416
1401 if (*p != '\n') 1417 if (*p != '\n')
1402 MU_DEBUG1 (smtp->mailer->debug, MU_DEBUG_ERROR, 1418 MU_DEBUG1 (smtp->mailer->debug, MU_DEBUG_ERROR,
1403 "suspicious size declaration: %s", 1419 "suspicious size declaration: %s",
...@@ -1409,12 +1425,14 @@ smtp_parse_ehlo_ack (smtp_t smtp) ...@@ -1409,12 +1425,14 @@ smtp_parse_ehlo_ack (smtp_t smtp)
1409 else if (!mu_c_strncasecmp (smtp->buffer, "250-AUTH", 8)) 1425 else if (!mu_c_strncasecmp (smtp->buffer, "250-AUTH", 8))
1410 { 1426 {
1411 char *name, *s; 1427 char *name, *s;
1428
1412 smtp->capa |= CAPA_AUTH; 1429 smtp->capa |= CAPA_AUTH;
1413 1430
1414 for (name = strtok_r (smtp->buffer + 8, " ", &s); name; 1431 for (name = strtok_r (smtp->buffer + 8, " ", &s); name;
1415 name = strtok_r (NULL, " ", &s)) 1432 name = strtok_r (NULL, " ", &s))
1416 { 1433 {
1417 struct auth_mech_record *mechs = auth_mech_list; 1434 struct auth_mech_record *mechs = auth_mech_list;
1435
1418 for (; mechs->name; mechs++) 1436 for (; mechs->name; mechs++)
1419 { 1437 {
1420 mu_rtrim_cset (name, "\r\n"); 1438 mu_rtrim_cset (name, "\r\n");
......