| 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 |
| 35 | extern "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 |
| 47 | extern int engine_options_num; |
| 48 | extern char *engine_options[MAX_ENGINE_OPTIONS]; |
| 49 | |
| 50 | int change_user (const char *username); |
| 51 | int change_user_group (const char *username, const char *groupname); |
| 52 | int raise_file_rlimit (int maxfiles); |
| 53 | |
| 54 | int fast_backtrace (void **buffer, int size); |
| 55 | |
| 56 | void print_backtrace (void); |
| 57 | void ksignal (int sig, void (*handler) (int)); |
| 58 | void set_debug_handlers (void); |
| 59 | |
| 60 | int adjust_oom_score (int oom_score_adj); |
| 61 | |
| 62 | extern int allow_core_dump; |
| 63 | extern int quit_steps, start_time; |
| 64 | extern int daemonize; |
| 65 | extern 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 | |
| 75 | struct 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); |
| 90 | void init_parse_options (unsigned keep_mask, const unsigned *keep_options_custom_list); |
| 91 | |
| 92 | int parse_engine_options_long (int argc, char **argv); |
| 93 | int parse_usage (void); |
| 94 | void parse_option (const char *name, int arg, int *var, int val, const char *help, ...) __attribute__ ((format (printf, 5, 6))); |
| 95 | void 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 | |
| 97 | void parse_option_alias (const char *name, int val); |
| 98 | void parse_option_long_alias (const char *name, const char *alias_name); |
| 99 | void remove_parse_option (int val); |
| 100 | //void set_backlog (const char *arg); |
| 101 | //void set_maxconn (const char *arg); |
| 102 | long long parse_memory_limit (const char *s); |
| 103 | |
| 104 | void add_builtin_parse_options (void); |
| 105 | |
| 106 | typedef void (*extra_debug_handler_t)(void); |
| 107 | extern extra_debug_handler_t extra_debug_handler; |
| 108 | |
| 109 | static inline void barrier (void) { |
| 110 | asm volatile("" : : :"memory" ); |
| 111 | } |
| 112 | |
| 113 | static 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 | |