diff options
Diffstat (limited to 'src/lib/daemon_ip_limit.h')
-rw-r--r-- | src/lib/daemon_ip_limit.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/daemon_ip_limit.h b/src/lib/daemon_ip_limit.h new file mode 100644 index 00000000..5f22db05 --- /dev/null +++ b/src/lib/daemon_ip_limit.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | /** | ||
20 | * @file lib/daemon_ip_limit.h | ||
21 | * @brief counting of connections per IP | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | |||
25 | #ifndef DAEMON_IP_LIMIT_H | ||
26 | #define DAEMON_IP_LIMIT_H | ||
27 | |||
28 | /** | ||
29 | * Check if IP address is over its limit in terms of the number | ||
30 | * of allowed concurrent connections. If the IP is still allowed, | ||
31 | * increments the connection counter. | ||
32 | * | ||
33 | * @param daemon handle to daemon where connection counts are tracked | ||
34 | * @param addr address to add (or increment counter) | ||
35 | * @param addrlen number of bytes in @a addr | ||
36 | * @return Return #MHD_YES if IP below limit, #MHD_NO if IP has surpassed limit. | ||
37 | * Also returns #MHD_NO if fails to allocate memory. | ||
38 | */ | ||
39 | int | ||
40 | MHD_ip_limit_add (struct MHD_Daemon *daemon, | ||
41 | const struct sockaddr *addr, | ||
42 | socklen_t addrlen) | ||
43 | MHD_NONNULL (1,2); | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Decrement connection count for IP address, removing from table | ||
48 | * count reaches 0. | ||
49 | * | ||
50 | * @param daemon handle to daemon where connection counts are tracked | ||
51 | * @param addr address to remove (or decrement counter) | ||
52 | * @param addrlen number of bytes in @a addr | ||
53 | */ | ||
54 | void | ||
55 | MHD_ip_limit_del (struct MHD_Daemon *daemon, | ||
56 | const struct sockaddr *addr, | ||
57 | socklen_t addrlen) | ||
58 | MHD_NONNULL (1,2); | ||
59 | |||
60 | #endif | ||