/*
- * Copyright (C) 2006-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
-/** \file dccp_send.c paraslash's dccp sender */
+/** \file dccp_send.c Paraslash's dccp sender. */
/*
* based on server.c of dccp-cs-0.01.tar.bz2,
#include "close_on_fork.h"
#include "chunk_queue.h"
#include "server.cmdline.h"
-
-/** the list of connected clients **/
-static struct list_head clients;
-static int listen_fd = -1;
-
-/** Maximal number of bytes in a chunk queue. */
-#define DCCP_MAX_PENDING_BYTES 40000
+#include "acl.h"
/** Do not write more than that many bytes at once. */
#define DCCP_MAX_BYTES_PER_WRITE 1024
+static struct sender_status dccp_sender_status, *dss = &dccp_sender_status;
+
static void dccp_pre_select(int *max_fileno, fd_set *rfds,
__a_unused fd_set *wfds)
{
- if (listen_fd >= 0)
- para_fd_set(listen_fd, rfds, max_fileno);
+ if (dss->listen_fd >= 0)
+ para_fd_set(dss->listen_fd, rfds, max_fileno);
}
static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds)
{
struct sender_client *sc;
- int ret, fd;
- if (listen_fd < 0 || !FD_ISSET(listen_fd, rfds))
+ if (dss->listen_fd < 0 || !FD_ISSET(dss->listen_fd, rfds))
return;
- ret = para_accept(listen_fd, NULL, 0);
- if (ret < 0) {
- PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ sc = accept_sender_client(dss);
+ if (!sc)
return;
- }
- fd = ret;
/*
* Bypass unused CCID paths: the sender does not receive application data
* from the client; by shutting down this unused communication path we can
* reduce processing costs a bit. See analogous comment in dccp_recv.c.
*/
- if (shutdown(fd, SHUT_RD) < 0) {
- ret = -ERRNO_TO_PARA_ERROR(errno);
- goto err;
- }
- ret = mark_fd_nonblocking(fd);
- if (ret < 0)
- goto err;
- sc = para_calloc(sizeof(*sc));
- sc->fd = fd;
- sc->name = make_message("%s", remote_name(sc->fd));
- PARA_NOTICE_LOG("connection from %s\n", sc->name);
- para_list_add(&sc->node, &clients);
- add_close_on_fork_list(sc->fd);
- sc->cq = cq_new(DCCP_MAX_PENDING_BYTES);
- return;
-err:
- PARA_ERROR_LOG("%s\n", para_strerror(-ret));
- close(fd);
+ if (shutdown(sc->fd, SHUT_RD) >= 0)
+ return;
+ PARA_WARNING_LOG("%s\n", strerror(errno));
+ shutdown_client(sc, dss);
}
static void dccp_send(long unsigned current_chunk,
- __a_unused long unsigned chunks_sent, const char *buf, size_t len)
+ __a_unused long unsigned chunks_sent, const char *buf,
+ size_t len, const char *header_buf, size_t header_len)
{
struct sender_client *sc, *tmp;
- list_for_each_entry_safe(sc, tmp, &clients, node)
- send_chunk(sc, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf,
- len);
+ list_for_each_entry_safe(sc, tmp, &dss->client_list, node)
+ send_chunk(sc, dss, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf,
+ len, header_buf, header_len);
}
static void dccp_shutdown_clients(void)
{
- struct sender_client *sc, *tmp;
+ shutdown_clients(dss);
+}
- list_for_each_entry_safe(sc, tmp, &clients, node)
- shutdown_client(sc);
+static int dccp_com_on(__a_unused struct sender_command_data *scd)
+{
+ return generic_com_on(dss, IPPROTO_DCCP);
}
-static char *dccp_info(void)
+static int dccp_com_off(__a_unused struct sender_command_data *scd)
{
- static char *buf;
- int num_clients = 0;
- struct sender_client *sc, *tmp;
+ generic_com_off(dss);
+ return 1;
+}
+
- free(buf);
- list_for_each_entry_safe(sc, tmp, &clients, node)
- num_clients++;
- buf = make_message("dccp connected clients: %d\n", num_clients);
- return buf;
+static int dccp_com_deny(struct sender_command_data *scd)
+{
+ generic_com_deny(scd, dss);
+ return 1;
}
-static char *dccp_help(void)
+static int dccp_com_allow(struct sender_command_data *scd)
{
- return make_message("no help available\n");
+ generic_com_allow(scd, dss);
+ return 1;
+}
+
+static char *dccp_info(void)
+{
+ return get_sender_info(dss, "dccp");
}
/**
{
int ret;
- INIT_LIST_HEAD(&clients);
s->info = dccp_info;
s->send = dccp_send;
s->pre_select = dccp_pre_select;
s->post_select = dccp_post_select;
s->shutdown_clients = dccp_shutdown_clients;
- s->help = dccp_help;
- s->client_cmds[SENDER_ON] = NULL;
- s->client_cmds[SENDER_OFF] = NULL;
- s->client_cmds[SENDER_DENY] = NULL;
- s->client_cmds[SENDER_ALLOW] = NULL;
+ s->help = generic_sender_help;
+ s->client_cmds[SENDER_ON] = dccp_com_on;
+ s->client_cmds[SENDER_OFF] = dccp_com_off;
+ s->client_cmds[SENDER_DENY] = dccp_com_deny;
+ s->client_cmds[SENDER_ALLOW] = dccp_com_allow;
s->client_cmds[SENDER_ADD] = NULL;
s->client_cmds[SENDER_DELETE] = NULL;
- ret = open_sender(IPPROTO_DCCP, conf.dccp_port_arg);
+
+ init_sender_status(dss, conf.dccp_access_arg, conf.dccp_access_given,
+ conf.dccp_port_arg, conf.dccp_max_clients_arg,
+ conf.dccp_default_deny_given);
+ ret = generic_com_on(dss, IPPROTO_DCCP);
if (ret < 0)
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
- else
- listen_fd = ret;
}