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));
void mu_m_server_set_app_data_size (mu_m_server_t srv, size_t size);
int mu_m_server_set_config_size (mu_m_server_t srv, size_t size);
struct mu_srv_config *mu_m_server_listen (mu_m_server_t msrv,
struct mu_sockaddr *s, int type);
int mu_m_server_parse_url (mu_m_server_t msrv, const char *arg,
struct mu_sockaddr **psa);
int mu_m_server_mode (mu_m_server_t srv);
int mu_m_server_foreground (mu_m_server_t srv);
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,
void *server_data, void *call_data,
mu_ip_server_t srv);
static struct mu_srv_config *
add_server (mu_m_server_t msrv, struct mu_sockaddr *s, int type)
struct mu_srv_config *
mu_m_server_listen (mu_m_server_t msrv, struct mu_sockaddr *s, int type)
{
mu_ip_server_t tcpsrv;
struct mu_srv_config *pconf;
......@@ -505,7 +505,7 @@ mu_m_server_begin (mu_m_server_t msrv)
{
struct mu_sockaddr *next = ta->next;
ta->next = ta->prev = NULL;
add_server (msrv, ta, msrv->deftype);
mu_m_server_listen (msrv, ta, msrv->deftype);
ta = next;
}
}
......@@ -789,7 +789,7 @@ server_block_begin (const char *arg, mu_m_server_t msrv, void **pdata)
"only the first is used"), arg);
mu_sockaddr_free (s->next);
}
*pdata = add_server (msrv, s, msrv->deftype);
*pdata = mu_m_server_listen (msrv, s, msrv->deftype);
return 0;
}
......@@ -858,14 +858,14 @@ get_port (const char *p)
return 1;
}
return htons (n);
return n;
}
else
{
struct servent *sp = getservbyname (p, "tcp");
if (!sp)
return 0;
return sp->s_port;
return ntohs (sp->s_port);
}
}
return 0;
......
......@@ -346,8 +346,7 @@ cfun_data (mu_stream_t iostr, char *arg)
mu_stream_t flt, tempstr;
time_t t;
struct tm *tm;
int xlev = MU_XSCRIPT_PAYLOAD, xlev_switch = 0, buf_switch = 0;
struct mu_buffer_query oldbuf;
int xlev = MU_XSCRIPT_PAYLOAD, xlev_switch = 0;
if (*arg)
{
......@@ -389,19 +388,6 @@ cfun_data (mu_stream_t iostr, char *arg)
lmtp_reply (iostr, "354", NULL, "Go ahead");
if (mu_stream_ioctl (iostr, MU_IOCTL_TRANSPORT_BUFFER,
MU_IOCTL_OP_GET, &oldbuf) == 0)
{
struct mu_buffer_query newbuf;
newbuf.type = MU_TRANSPORT_OUTPUT;
newbuf.buftype = mu_buffer_full;
newbuf.bufsize = 64*1024;
if (mu_stream_ioctl (iostr, MU_IOCTL_TRANSPORT_BUFFER, MU_IOCTL_OP_SET,
&newbuf))
buf_switch = 1;
}
if (mu_stream_ioctl (iostr, MU_IOCTL_XSCRIPTSTREAM,
MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev) == 0)
xlev_switch = 1;
......@@ -410,9 +396,6 @@ cfun_data (mu_stream_t iostr, char *arg)
if (xlev_switch)
mu_stream_ioctl (iostr, MU_IOCTL_XSCRIPTSTREAM,
MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev);
if (buf_switch)
mu_stream_ioctl (iostr, MU_IOCTL_TRANSPORT_BUFFER, MU_IOCTL_OP_SET,
&oldbuf);
if (rc)
{
maidag_error (_("copy error: %s"), mu_strerror (rc));
......
......@@ -415,6 +415,19 @@ cb_delivery_mode (void *data, mu_config_value_t *val)
return 0;
}
static int
cb_listen (void *data, mu_config_value_t *val)
{
struct mu_sockaddr *s;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_m_server_parse_url (server, val->v.string, &s))
return 1;
mu_m_server_listen (server, s, MU_IP_TCP);
return 0;
}
struct mu_cfg_param maidag_cfg_param[] = {
{ "delivery-mode", mu_cfg_callback, NULL, 0, cb_delivery_mode,
N_("Set delivery mode"),
......@@ -458,7 +471,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
{ "group", mu_cfg_callback, &lmtp_groups, 0, cb_group,
N_("In LMTP mode, retain these supplementary groups."),
N_("groups: list of string") },
{ "listen", mu_cfg_string, &lmtp_url_string, 0, NULL,
{ "listen", mu_cfg_callback, NULL, 0, cb_listen,
N_("In LMTP mode, listen on the given URL. Valid URLs are:\n"
" tcp://<address: string>:<port: number> (note that port is "
"mandatory)\n"
......