Use different paths for the 0.4 database and the afs socket.
[paraslash.git] / dccp_send.c
1 /*
2  * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file dccp_send.c Paraslash's dccp sender. */
8
9 /*
10  * based on server.c of dccp-cs-0.01.tar.bz2,
11  * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
12  */
13
14 #include <sys/types.h>
15 #include <dirent.h>
16 #include <osl.h>
17
18 #include "para.h"
19 #include "error.h"
20 #include "string.h"
21 #include "afh.h"
22 #include "afs.h"
23 #include "server.h"
24 #include "net.h"
25 #include "list.h"
26 #include "vss.h"
27 #include "send.h"
28 #include "fd.h"
29 #include "close_on_fork.h"
30 #include "chunk_queue.h"
31 #include "server.cmdline.h"
32 #include "acl.h"
33
34 /** Do not write more than that many bytes at once. */
35 #define DCCP_MAX_BYTES_PER_WRITE 1024
36
37 static struct sender_status dccp_sender_status, *dss = &dccp_sender_status;
38
39 static void dccp_pre_select(int *max_fileno, fd_set *rfds,
40                 __a_unused fd_set *wfds)
41 {
42         if (dss->listen_fd >= 0)
43                 para_fd_set(dss->listen_fd, rfds, max_fileno);
44 }
45
46 static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds)
47 {
48         struct sender_client *sc;
49
50         if (dss->listen_fd < 0 || !FD_ISSET(dss->listen_fd, rfds))
51                 return;
52         sc = accept_sender_client(dss);
53         if (!sc)
54                 return;
55         /*
56          * Bypass unused CCID paths: the sender does not receive application data
57          * from the client; by shutting down this unused communication path we can
58          * reduce processing costs a bit. See analogous comment in dccp_recv.c.
59          */
60         if (shutdown(sc->fd, SHUT_RD) >= 0)
61                 return;
62         PARA_WARNING_LOG("%s\n", strerror(errno));
63         shutdown_client(sc, dss);
64 }
65
66 static void dccp_send(long unsigned current_chunk,
67                 __a_unused long unsigned chunks_sent, const char *buf,
68                 size_t len, const char *header_buf, size_t header_len)
69 {
70         struct sender_client *sc, *tmp;
71
72         list_for_each_entry_safe(sc, tmp, &dss->client_list, node)
73                 send_chunk(sc, dss, DCCP_MAX_BYTES_PER_WRITE, current_chunk, buf,
74                         len, header_buf, header_len);
75 }
76
77 static void dccp_shutdown_clients(void)
78 {
79         shutdown_clients(dss);
80 }
81
82 static int dccp_com_on(__a_unused struct sender_command_data *scd)
83 {
84         return generic_com_on(dss, IPPROTO_DCCP);
85 }
86
87 static int dccp_com_off(__a_unused struct sender_command_data *scd)
88 {
89         generic_com_off(dss);
90         return 1;
91 }
92
93
94 static int dccp_com_deny(struct sender_command_data *scd)
95 {
96         generic_com_deny(scd, dss);
97         return 1;
98 }
99
100 static int dccp_com_allow(struct sender_command_data *scd)
101 {
102         generic_com_allow(scd, dss);
103         return 1;
104 }
105
106 static char *dccp_info(void)
107 {
108         return get_sender_info(dss, "dccp");
109 }
110
111 /**
112  * The init function of the dccp sender.
113  *
114  * \param s pointer to the dccp sender struct.
115  *
116  * It initializes all function pointers of \a s and starts
117  * listening on the given port.
118  */
119 void dccp_send_init(struct sender *s)
120 {
121         int ret;
122
123         s->info = dccp_info;
124         s->send = dccp_send;
125         s->pre_select = dccp_pre_select;
126         s->post_select = dccp_post_select;
127         s->shutdown_clients = dccp_shutdown_clients;
128         s->help = generic_sender_help;
129         s->client_cmds[SENDER_ON] = dccp_com_on;
130         s->client_cmds[SENDER_OFF] = dccp_com_off;
131         s->client_cmds[SENDER_DENY] = dccp_com_deny;
132         s->client_cmds[SENDER_ALLOW] = dccp_com_allow;
133         s->client_cmds[SENDER_ADD] = NULL;
134         s->client_cmds[SENDER_DELETE] = NULL;
135
136         init_sender_status(dss, conf.dccp_access_arg, conf.dccp_access_given,
137                 conf.dccp_port_arg, conf.dccp_max_clients_arg,
138                 conf.dccp_default_deny_given);
139         ret = generic_com_on(dss, IPPROTO_DCCP);
140         if (ret < 0)
141                 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
142 }