Commit 8f95e358 8f95e3582c89689599c7e5a0496d4f9fc2cc4e06 by Sergey Poznyakoff

Fixes: port cfg statement, listen cfg statement in maidag, final dot recognition in maidag.

* include/mailutils/server.h (mu_m_server_listen)
(mu_m_server_parse_url): New protos.
* libmailutils/server/msrv.c (add_server): Rename to
mu_m_server_listen (now extern). All uses updated.
(get_port): Bugfix: return port in server byte order.
This fixes the use of the "port" configuration statement.
* maidag/lmtp.c (cfun_data): Don't switch to full buffering.
This makes it impossible to note the final dot in time.
* maidag/maidag.c (cb_listen): New callback.
(maidag_cfg_param): Attach cb_listen to the "listen" statement.
1 parent 8ef7c0ad
...@@ -119,6 +119,11 @@ void mu_m_server_set_strexit (mu_m_server_t srv, const char *(*fun) (int)); ...@@ -119,6 +119,11 @@ void mu_m_server_set_strexit (mu_m_server_t srv, const char *(*fun) (int));
119 void mu_m_server_set_app_data_size (mu_m_server_t srv, size_t size); 119 void mu_m_server_set_app_data_size (mu_m_server_t srv, size_t size);
120 int mu_m_server_set_config_size (mu_m_server_t srv, size_t size); 120 int mu_m_server_set_config_size (mu_m_server_t srv, size_t size);
121 121
122 struct mu_srv_config *mu_m_server_listen (mu_m_server_t msrv,
123 struct mu_sockaddr *s, int type);
124 int mu_m_server_parse_url (mu_m_server_t msrv, const char *arg,
125 struct mu_sockaddr **psa);
126
122 int mu_m_server_mode (mu_m_server_t srv); 127 int mu_m_server_mode (mu_m_server_t srv);
123 int mu_m_server_foreground (mu_m_server_t srv); 128 int mu_m_server_foreground (mu_m_server_t srv);
124 time_t mu_m_server_timeout (mu_m_server_t srv); 129 time_t mu_m_server_timeout (mu_m_server_t srv);
......
...@@ -453,8 +453,8 @@ static int m_srv_conn (int fd, struct sockaddr *sa, int salen, ...@@ -453,8 +453,8 @@ static int m_srv_conn (int fd, struct sockaddr *sa, int salen,
453 void *server_data, void *call_data, 453 void *server_data, void *call_data,
454 mu_ip_server_t srv); 454 mu_ip_server_t srv);
455 455
456 static struct mu_srv_config * 456 struct mu_srv_config *
457 add_server (mu_m_server_t msrv, struct mu_sockaddr *s, int type) 457 mu_m_server_listen (mu_m_server_t msrv, struct mu_sockaddr *s, int type)
458 { 458 {
459 mu_ip_server_t tcpsrv; 459 mu_ip_server_t tcpsrv;
460 struct mu_srv_config *pconf; 460 struct mu_srv_config *pconf;
...@@ -505,7 +505,7 @@ mu_m_server_begin (mu_m_server_t msrv) ...@@ -505,7 +505,7 @@ mu_m_server_begin (mu_m_server_t msrv)
505 { 505 {
506 struct mu_sockaddr *next = ta->next; 506 struct mu_sockaddr *next = ta->next;
507 ta->next = ta->prev = NULL; 507 ta->next = ta->prev = NULL;
508 add_server (msrv, ta, msrv->deftype); 508 mu_m_server_listen (msrv, ta, msrv->deftype);
509 ta = next; 509 ta = next;
510 } 510 }
511 } 511 }
...@@ -789,7 +789,7 @@ server_block_begin (const char *arg, mu_m_server_t msrv, void **pdata) ...@@ -789,7 +789,7 @@ server_block_begin (const char *arg, mu_m_server_t msrv, void **pdata)
789 "only the first is used"), arg); 789 "only the first is used"), arg);
790 mu_sockaddr_free (s->next); 790 mu_sockaddr_free (s->next);
791 } 791 }
792 *pdata = add_server (msrv, s, msrv->deftype); 792 *pdata = mu_m_server_listen (msrv, s, msrv->deftype);
793 return 0; 793 return 0;
794 } 794 }
795 795
...@@ -858,14 +858,14 @@ get_port (const char *p) ...@@ -858,14 +858,14 @@ get_port (const char *p)
858 return 1; 858 return 1;
859 } 859 }
860 860
861 return htons (n); 861 return n;
862 } 862 }
863 else 863 else
864 { 864 {
865 struct servent *sp = getservbyname (p, "tcp"); 865 struct servent *sp = getservbyname (p, "tcp");
866 if (!sp) 866 if (!sp)
867 return 0; 867 return 0;
868 return sp->s_port; 868 return ntohs (sp->s_port);
869 } 869 }
870 } 870 }
871 return 0; 871 return 0;
......
...@@ -346,8 +346,7 @@ cfun_data (mu_stream_t iostr, char *arg) ...@@ -346,8 +346,7 @@ cfun_data (mu_stream_t iostr, char *arg)
346 mu_stream_t flt, tempstr; 346 mu_stream_t flt, tempstr;
347 time_t t; 347 time_t t;
348 struct tm *tm; 348 struct tm *tm;
349 int xlev = MU_XSCRIPT_PAYLOAD, xlev_switch = 0, buf_switch = 0; 349 int xlev = MU_XSCRIPT_PAYLOAD, xlev_switch = 0;
350 struct mu_buffer_query oldbuf;
351 350
352 if (*arg) 351 if (*arg)
353 { 352 {
...@@ -389,19 +388,6 @@ cfun_data (mu_stream_t iostr, char *arg) ...@@ -389,19 +388,6 @@ cfun_data (mu_stream_t iostr, char *arg)
389 388
390 lmtp_reply (iostr, "354", NULL, "Go ahead"); 389 lmtp_reply (iostr, "354", NULL, "Go ahead");
391 390
392 if (mu_stream_ioctl (iostr, MU_IOCTL_TRANSPORT_BUFFER,
393 MU_IOCTL_OP_GET, &oldbuf) == 0)
394 {
395 struct mu_buffer_query newbuf;
396
397 newbuf.type = MU_TRANSPORT_OUTPUT;
398 newbuf.buftype = mu_buffer_full;
399 newbuf.bufsize = 64*1024;
400 if (mu_stream_ioctl (iostr, MU_IOCTL_TRANSPORT_BUFFER, MU_IOCTL_OP_SET,
401 &newbuf))
402 buf_switch = 1;
403 }
404
405 if (mu_stream_ioctl (iostr, MU_IOCTL_XSCRIPTSTREAM, 391 if (mu_stream_ioctl (iostr, MU_IOCTL_XSCRIPTSTREAM,
406 MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev) == 0) 392 MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev) == 0)
407 xlev_switch = 1; 393 xlev_switch = 1;
...@@ -410,9 +396,6 @@ cfun_data (mu_stream_t iostr, char *arg) ...@@ -410,9 +396,6 @@ cfun_data (mu_stream_t iostr, char *arg)
410 if (xlev_switch) 396 if (xlev_switch)
411 mu_stream_ioctl (iostr, MU_IOCTL_XSCRIPTSTREAM, 397 mu_stream_ioctl (iostr, MU_IOCTL_XSCRIPTSTREAM,
412 MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev); 398 MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev);
413 if (buf_switch)
414 mu_stream_ioctl (iostr, MU_IOCTL_TRANSPORT_BUFFER, MU_IOCTL_OP_SET,
415 &oldbuf);
416 if (rc) 399 if (rc)
417 { 400 {
418 maidag_error (_("copy error: %s"), mu_strerror (rc)); 401 maidag_error (_("copy error: %s"), mu_strerror (rc));
......
...@@ -415,6 +415,19 @@ cb_delivery_mode (void *data, mu_config_value_t *val) ...@@ -415,6 +415,19 @@ cb_delivery_mode (void *data, mu_config_value_t *val)
415 return 0; 415 return 0;
416 } 416 }
417 417
418 static int
419 cb_listen (void *data, mu_config_value_t *val)
420 {
421 struct mu_sockaddr *s;
422
423 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
424 return 1;
425 if (mu_m_server_parse_url (server, val->v.string, &s))
426 return 1;
427 mu_m_server_listen (server, s, MU_IP_TCP);
428 return 0;
429 }
430
418 struct mu_cfg_param maidag_cfg_param[] = { 431 struct mu_cfg_param maidag_cfg_param[] = {
419 { "delivery-mode", mu_cfg_callback, NULL, 0, cb_delivery_mode, 432 { "delivery-mode", mu_cfg_callback, NULL, 0, cb_delivery_mode,
420 N_("Set delivery mode"), 433 N_("Set delivery mode"),
...@@ -458,7 +471,7 @@ struct mu_cfg_param maidag_cfg_param[] = { ...@@ -458,7 +471,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
458 { "group", mu_cfg_callback, &lmtp_groups, 0, cb_group, 471 { "group", mu_cfg_callback, &lmtp_groups, 0, cb_group,
459 N_("In LMTP mode, retain these supplementary groups."), 472 N_("In LMTP mode, retain these supplementary groups."),
460 N_("groups: list of string") }, 473 N_("groups: list of string") },
461 { "listen", mu_cfg_string, &lmtp_url_string, 0, NULL, 474 { "listen", mu_cfg_callback, NULL, 0, cb_listen,
462 N_("In LMTP mode, listen on the given URL. Valid URLs are:\n" 475 N_("In LMTP mode, listen on the given URL. Valid URLs are:\n"
463 " tcp://<address: string>:<port: number> (note that port is " 476 " tcp://<address: string>:<port: number> (note that port is "
464 "mandatory)\n" 477 "mandatory)\n"
......