1/*
2 This file is part of Mtproto-proxy Library.
3
4 Mtproto-proxy Library is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 Mtproto-proxy Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mtproto-proxy Library. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright 2009-2013 Vkontakte Ltd
18 2008-2013 Nikolai Durov
19 2008-2013 Andrey Lopatin
20 2011-2013 Oleg Davydov
21 2012-2013 Arseny Smirnov
22 2012-2013 Aliaksei Levin
23 2012-2013 Anton Maydell
24 2013 Vitaliy Valtman
25
26 Copyright 2014-2018 Telegram Messenger Inc
27 2014-2018 Vitaly Valtman
28*/
29
30#pragma once
31
32#include <getopt.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#ifdef __LP64__
39# define PTR_BITS 64
40# define BITS_STR "64"
41#else
42# define PTR_BITS 32
43# define BITS_STR "32"
44#endif
45
46#define MAX_ENGINE_OPTIONS 1000
47extern int engine_options_num;
48extern char *engine_options[MAX_ENGINE_OPTIONS];
49
50int change_user (const char *username);
51int change_user_group (const char *username, const char *groupname);
52int raise_file_rlimit (int maxfiles);
53
54int fast_backtrace (void **buffer, int size);
55
56void print_backtrace (void);
57void ksignal (int sig, void (*handler) (int));
58void set_debug_handlers (void);
59
60int adjust_oom_score (int oom_score_adj);
61
62extern int allow_core_dump;
63extern int quit_steps, start_time;
64extern int daemonize;
65extern const char *username, *progname, *groupname;
66
67/* keep mask defines */
68#define LONGOPT_JOBS_SET 0x00000400
69#define LONGOPT_COMMON_SET 0x00001000
70#define LONGOPT_NET_SET (LONGOPT_TCP_SET)
71#define LONGOPT_TCP_SET 0x00002000
72
73#define LONGOPT_CUSTOM_SET 0x10000000
74
75struct engine_parse_option {
76 int *vals;
77 int val_cnt;
78 int base_val;
79 int smallest_val;
80 const char **longopts;
81 int longopts_cnt;
82 int (*func)(int);
83 char *help;
84 unsigned flags;
85 int arg;
86};
87
88/* init_parse_option should be called before parse_option and parse_option_alias */
89//void init_parse_options (int keep_mask, const unsigned char *keep_options_custom_list);
90void init_parse_options (unsigned keep_mask, const unsigned *keep_options_custom_list);
91
92int parse_engine_options_long (int argc, char **argv);
93int parse_usage (void);
94void parse_option (const char *name, int arg, int *var, int val, const char *help, ...) __attribute__ ((format (printf, 5, 6)));
95void parse_option_ex (const char *name, int arg, int *var, int val, unsigned flags, int (*func)(int), const char *help, ...) __attribute__ ((format (printf, 7, 8)));
96
97void parse_option_alias (const char *name, int val);
98void parse_option_long_alias (const char *name, const char *alias_name);
99void remove_parse_option (int val);
100//void set_backlog (const char *arg);
101//void set_maxconn (const char *arg);
102long long parse_memory_limit (const char *s);
103
104void add_builtin_parse_options (void);
105
106typedef void (*extra_debug_handler_t)(void);
107extern extra_debug_handler_t extra_debug_handler;
108
109static inline void barrier (void) {
110 asm volatile("": : :"memory");
111}
112
113static inline void mfence (void) {
114 asm volatile ("mfence": : :"memory");
115}
116
117//extern struct multicast_host multicast_hosts[];
118//extern int multicast_hosts_num;
119
120#define DEFAULT_BACKLOG 8192
121#define DEFAULT_ENGINE_USER "mtproxy"
122
123#ifdef __cplusplus
124}
125#endif
126