comparison src/smtp_out.c @ 366:41958685480d

Switched to `type *name' style Andrew Koenig's ``C Traps and Pitfalls'' (Ch.2.1) convinced me that it is best to go with the way C had been designed. The ``declaration reflects use'' concept conflicts with a ``type* name'' notation. Hence I switched.
author markus schnalke <meillo@marmaro.de>
date Thu, 22 Sep 2011 15:07:40 +0200
parents 02bc0331e390
children b27f66555ba8
comparison
equal deleted inserted replaced
365:934a223e4ee8 366:41958685480d
35 #include "md5/hmac_md5.h" 35 #include "md5/hmac_md5.h"
36 #include "base64/base64.h" 36 #include "base64/base64.h"
37 #endif 37 #endif
38 38
39 void 39 void
40 destroy_smtpbase(smtp_base * psb) 40 destroy_smtpbase(smtp_base *psb)
41 { 41 {
42 fclose(psb->in); 42 fclose(psb->in);
43 fclose(psb->out); 43 fclose(psb->out);
44 44
45 close(psb->sock); 45 close(psb->sock);
58 if (psb->auth_secret) 58 if (psb->auth_secret)
59 g_free(psb->auth_secret); 59 g_free(psb->auth_secret);
60 } 60 }
61 61
62 gchar* 62 gchar*
63 set_heloname(smtp_base * psb, gchar * default_name, gboolean do_correct) 63 set_heloname(smtp_base *psb, gchar *default_name, gboolean do_correct)
64 { 64 {
65 struct sockaddr_in sname; 65 struct sockaddr_in sname;
66 int len = sizeof(struct sockaddr_in); 66 int len = sizeof(struct sockaddr_in);
67 struct hostent *host_entry; 67 struct hostent *host_entry;
68 68
88 } 88 }
89 89
90 #ifdef ENABLE_AUTH 90 #ifdef ENABLE_AUTH
91 91
92 gboolean 92 gboolean
93 set_auth(smtp_base * psb, gchar * name, gchar * login, gchar * secret) 93 set_auth(smtp_base *psb, gchar *name, gchar *login, gchar *secret)
94 { 94 {
95 if ((strcasecmp(name, "CRAM-MD5") == 0) || (strcasecmp(name, "LOGIN") == 0)) { 95 if ((strcasecmp(name, "CRAM-MD5") == 0) || (strcasecmp(name, "LOGIN") == 0)) {
96 psb->auth_name = g_strdup(name); 96 psb->auth_name = g_strdup(name);
97 psb->auth_login = g_strdup(login); 97 psb->auth_login = g_strdup(login);
98 psb->auth_secret = g_strdup(secret); 98 psb->auth_secret = g_strdup(secret);
134 134
135 return psb; 135 return psb;
136 } 136 }
137 137
138 static gboolean 138 static gboolean
139 read_response(smtp_base * psb, int timeout) 139 read_response(smtp_base *psb, int timeout)
140 { 140 {
141 gint buf_pos = 0; 141 gint buf_pos = 0;
142 gchar code[5]; 142 gchar code[5];
143 gint i, len; 143 gint i, len;
144 144
168 168
169 return TRUE; 169 return TRUE;
170 } 170 }
171 171
172 static gboolean 172 static gboolean
173 check_response(smtp_base * psb, gboolean after_data) 173 check_response(smtp_base *psb, gboolean after_data)
174 { 174 {
175 char c = psb->buffer[0]; 175 char c = psb->buffer[0];
176 176
177 if (((c == '2') && !after_data) || ((c == '3') && after_data)) { 177 if (((c == '2') && !after_data) || ((c == '3') && after_data)) {
178 psb->error = smtp_ok; 178 psb->error = smtp_ok;
189 return FALSE; 189 return FALSE;
190 } 190 }
191 } 191 }
192 192
193 static gchar* 193 static gchar*
194 get_response_arg(gchar * response) 194 get_response_arg(gchar *response)
195 { 195 {
196 gchar buf[SMTP_BUF_LEN]; 196 gchar buf[SMTP_BUF_LEN];
197 gchar *p = response, *q = buf; 197 gchar *p = response, *q = buf;
198 198
199 while (*p && (*p != '\n') && isspace(*p)) 199 while (*p && (*p != '\n') && isspace(*p))
206 } 206 }
207 return NULL; 207 return NULL;
208 } 208 }
209 209
210 static gboolean 210 static gboolean
211 check_helo_response(smtp_base * psb) 211 check_helo_response(smtp_base *psb)
212 { 212 {
213 gchar *ptr; 213 gchar *ptr;
214 214
215 if (!check_response(psb, FALSE)) 215 if (!check_response(psb, FALSE))
216 return FALSE; 216 return FALSE;
290 string ``ESMTP'' appeared within the server's greeting message. This 290 string ``ESMTP'' appeared within the server's greeting message. This
291 made it impossible to use AUTH with servers that would send odd 291 made it impossible to use AUTH with servers that would send odd
292 greeting messages. 292 greeting messages.
293 */ 293 */
294 static gboolean 294 static gboolean
295 smtp_helo(smtp_base * psb, gchar * helo) 295 smtp_helo(smtp_base *psb, gchar *helo)
296 { 296 {
297 fprintf(psb->out, "EHLO %s\r\n", helo); 297 fprintf(psb->out, "EHLO %s\r\n", helo);
298 fflush(psb->out); 298 fflush(psb->out);
299 DEBUG(4) debugf("C: EHLO %s\r\n", helo); 299 DEBUG(4) debugf("C: EHLO %s\r\n", helo);
300 300
328 /* what sort of server ist THAT ?! give up... */ 328 /* what sort of server ist THAT ?! give up... */
329 return FALSE; 329 return FALSE;
330 } 330 }
331 331
332 static void 332 static void
333 smtp_cmd_mailfrom(smtp_base * psb, address * return_path, guint size) 333 smtp_cmd_mailfrom(smtp_base *psb, address *return_path, guint size)
334 { 334 {
335 if (psb->use_size) { 335 if (psb->use_size) {
336 fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size); 336 fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n", addr_string(return_path), size);
337 fflush(psb->out); 337 fflush(psb->out);
338 338
345 DEBUG(4) debugf("C: MAIL FROM:%s\r\n", addr_string(return_path)); 345 DEBUG(4) debugf("C: MAIL FROM:%s\r\n", addr_string(return_path));
346 } 346 }
347 } 347 }
348 348
349 static void 349 static void
350 smtp_cmd_rcptto(smtp_base * psb, address * rcpt) 350 smtp_cmd_rcptto(smtp_base *psb, address *rcpt)
351 { 351 {
352 fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt)); 352 fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
353 fflush(psb->out); 353 fflush(psb->out);
354 DEBUG(4) debugf("C: RCPT TO:%s\n", addr_string(rcpt)); 354 DEBUG(4) debugf("C: RCPT TO:%s\n", addr_string(rcpt));
355 } 355 }
356 356
357 static void 357 static void
358 send_data_line(smtp_base * psb, gchar * data) 358 send_data_line(smtp_base *psb, gchar *data)
359 { 359 {
360 /* According to RFC 821 each line should be terminated with CRLF. 360 /* According to RFC 821 each line should be terminated with CRLF.
361 Since a dot on a line itself marks the end of data, each line 361 Since a dot on a line itself marks the end of data, each line
362 beginning with a dot is prepended with another dot. 362 beginning with a dot is prepended with another dot.
363 */ 363 */
384 ptr++; 384 ptr++;
385 } 385 }
386 } 386 }
387 387
388 static void 388 static void
389 send_header(smtp_base * psb, GList * hdr_list) 389 send_header(smtp_base *psb, GList *hdr_list)
390 { 390 {
391 GList *node; 391 GList *node;
392 gint num_hdrs = 0; 392 gint num_hdrs = 0;
393 393
394 /* header */ 394 /* header */
410 410
411 DEBUG(4) debugf("sent %d headers\n", num_hdrs); 411 DEBUG(4) debugf("sent %d headers\n", num_hdrs);
412 } 412 }
413 413
414 static void 414 static void
415 send_data(smtp_base * psb, message * msg) 415 send_data(smtp_base *psb, message *msg)
416 { 416 {
417 GList *node; 417 GList *node;
418 gint num_lines = 0; 418 gint num_lines = 0;
419 419
420 /* data */ 420 /* data */
433 fflush(psb->out); 433 fflush(psb->out);
434 DEBUG(4) debugf("C: .\n"); 434 DEBUG(4) debugf("C: .\n");
435 } 435 }
436 436
437 void 437 void
438 smtp_out_mark_rcpts(smtp_base * psb, GList * rcpt_list) 438 smtp_out_mark_rcpts(smtp_base *psb, GList *rcpt_list)
439 { 439 {
440 GList *rcpt_node; 440 GList *rcpt_node;
441 for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) { 441 for (rcpt_node = g_list_first(rcpt_list); rcpt_node; rcpt_node = g_list_next(rcpt_node)) {
442 address *rcpt = (address *) (rcpt_node->data); 442 address *rcpt = (address *) (rcpt_node->data);
443 443
450 } 450 }
451 } 451 }
452 } 452 }
453 453
454 void 454 void
455 smtp_out_log_failure(smtp_base * psb, message * msg) 455 smtp_out_log_failure(smtp_base *psb, message *msg)
456 { 456 {
457 gchar *err_str; 457 gchar *err_str;
458 458
459 if (psb->error == smtp_timeout) 459 if (psb->error == smtp_timeout)
460 err_str = g_strdup("connection timed out."); 460 err_str = g_strdup("connection timed out.");
475 475
476 g_free(err_str); 476 g_free(err_str);
477 } 477 }
478 478
479 smtp_base* 479 smtp_base*
480 smtp_out_open(gchar * host, gint port, GList * resolve_list) 480 smtp_out_open(gchar *host, gint port, GList *resolve_list)
481 { 481 {
482 smtp_base *psb; 482 smtp_base *psb;
483 gint sock; 483 gint sock;
484 mxip_addr *addr; 484 mxip_addr *addr;
485 485
503 503
504 return NULL; 504 return NULL;
505 } 505 }
506 506
507 smtp_base* 507 smtp_base*
508 smtp_out_open_child(gchar * cmd, char* host) 508 smtp_out_open_child(gchar *cmd, char *host)
509 { 509 {
510 smtp_base *psb; 510 smtp_base *psb;
511 gint sock; 511 gint sock;
512 512
513 DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd); 513 DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd);
522 522
523 return NULL; 523 return NULL;
524 } 524 }
525 525
526 gboolean 526 gboolean
527 smtp_out_rset(smtp_base * psb) 527 smtp_out_rset(smtp_base *psb)
528 { 528 {
529 gboolean ok; 529 gboolean ok;
530 530
531 fprintf(psb->out, "RSET\r\n"); 531 fprintf(psb->out, "RSET\r\n");
532 fflush(psb->out); 532 fflush(psb->out);
542 } 542 }
543 543
544 #ifdef ENABLE_AUTH 544 #ifdef ENABLE_AUTH
545 545
546 static gboolean 546 static gboolean
547 smtp_out_auth_cram_md5(smtp_base * psb) 547 smtp_out_auth_cram_md5(smtp_base *psb)
548 { 548 {
549 gboolean ok = FALSE; 549 gboolean ok = FALSE;
550 550
551 fprintf(psb->out, "C: AUTH CRAM-MD5\r\n"); 551 fprintf(psb->out, "C: AUTH CRAM-MD5\r\n");
552 fflush(psb->out); 552 fflush(psb->out);
594 } 594 }
595 return ok; 595 return ok;
596 } 596 }
597 597
598 static gboolean 598 static gboolean
599 smtp_out_auth_login(smtp_base * psb) 599 smtp_out_auth_login(smtp_base *psb)
600 { 600 {
601 gboolean ok = FALSE; 601 gboolean ok = FALSE;
602 fprintf(psb->out, "AUTH LOGIN\r\n"); 602 fprintf(psb->out, "AUTH LOGIN\r\n");
603 fflush(psb->out); 603 fflush(psb->out);
604 DEBUG(4) debugf("C: AUTH LOGIN\r\n"); 604 DEBUG(4) debugf("C: AUTH LOGIN\r\n");
642 } 642 }
643 return ok; 643 return ok;
644 } 644 }
645 645
646 gboolean 646 gboolean
647 smtp_out_auth(smtp_base * psb) 647 smtp_out_auth(smtp_base *psb)
648 { 648 {
649 gboolean ok = FALSE; 649 gboolean ok = FALSE;
650 gint i = 0; 650 gint i = 0;
651 while (psb->auth_names[i]) { 651 while (psb->auth_names[i]) {
652 if (strcasecmp(psb->auth_names[i], psb->auth_name) == 0) 652 if (strcasecmp(psb->auth_names[i], psb->auth_name) == 0)
668 } 668 }
669 669
670 #endif 670 #endif
671 671
672 gboolean 672 gboolean
673 smtp_out_init(smtp_base * psb, gboolean instant_helo) 673 smtp_out_init(smtp_base *psb, gboolean instant_helo)
674 { 674 {
675 gboolean ok; 675 gboolean ok;
676 676
677 logwrite(LOG_INFO, "smtp_out_init(): instant_helo:%d\n", instant_helo); 677 logwrite(LOG_INFO, "smtp_out_init(): instant_helo:%d\n", instant_helo);
678 678
700 smtp_out_log_failure(psb, NULL); 700 smtp_out_log_failure(psb, NULL);
701 return ok; 701 return ok;
702 } 702 }
703 703
704 gint 704 gint
705 smtp_out_msg(smtp_base * psb, message * msg, address * return_path, GList * rcpt_list, GList * hdr_list) 705 smtp_out_msg(smtp_base *psb, message *msg, address *return_path, GList *rcpt_list, GList *hdr_list)
706 { 706 {
707 gint i, size; 707 gint i, size;
708 gboolean ok = TRUE; 708 gboolean ok = TRUE;
709 int rcpt_cnt; 709 int rcpt_cnt;
710 int rcpt_accept = 0; 710 int rcpt_accept = 0;
880 } 880 }
881 return rcpt_accept; 881 return rcpt_accept;
882 } 882 }
883 883
884 gboolean 884 gboolean
885 smtp_out_quit(smtp_base * psb) 885 smtp_out_quit(smtp_base *psb)
886 { 886 {
887 fprintf(psb->out, "QUIT\r\n"); 887 fprintf(psb->out, "QUIT\r\n");
888 fflush(psb->out); 888 fflush(psb->out);
889 889
890 DEBUG(4) debugf("C: QUIT\n"); 890 DEBUG(4) debugf("C: QUIT\n");
893 893
894 return TRUE; 894 return TRUE;
895 } 895 }
896 896
897 gint 897 gint
898 smtp_deliver(gchar * host, gint port, GList * resolve_list, message * msg, address * return_path, GList * rcpt_list) 898 smtp_deliver(gchar *host, gint port, GList *resolve_list, message *msg, address *return_path, GList *rcpt_list)
899 { 899 {
900 smtp_base *psb; 900 smtp_base *psb;
901 smtp_error err; 901 smtp_error err;
902 902
903 DEBUG(5) debugf("smtp_deliver entered\n"); 903 DEBUG(5) debugf("smtp_deliver entered\n");