#ifndef COMMON_H #define COMMON_H 1 #define TPROXY_IPTABLS_START "sh /usr/share/cgproxy/scripts/cgroup-tproxy.sh" #define TPROXY_IPTABLS_CLEAN "sh /usr/share/cgproxy/scripts/cgroup-tproxy.sh stop" #define SOCKET_PATH "/tmp/cgproxy_unix_socket" #define LISTEN_BACKLOG 64 #define DEFAULT_CONFIG_FILE "/etc/cgproxy/config.json" #define CGROUP_PROXY_PRESVERED "/proxy.slice" #define CGROUP_NOPROXY_PRESVERED "/noproxy.slice" #define MSG_TYPE_JSON 1 #define MSG_TYPE_CONFIG_PATH 2 #define MSG_TYPE_PROXY_PID 3 #define MSG_TYPE_NOPROXY_PID 4 #define UNKNOWN_ERROR 99 #define ERROR -1 #define SUCCESS 0 #define CONN_ERROR 1 #define MSG_ERROR 2 #define PARSE_ERROR 3 #define PARAM_ERROR 4 #define APPLY_ERROR 5 #define CGROUP_ERROR 6 #define FILE_ERROR 7 #include #include #include #include using namespace std; static bool enable_debug=false; static bool print_help=false; #define error(...) {fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n");} #define debug(...) if (enable_debug) {fprintf(stdout, __VA_ARGS__);fprintf(stdout, "\n");} #define return_error return -1; #define return_success return 0; void processArgs(const int argc, char *argv[], int &shift){ for (int i=1;i string to_str(T... args) { stringstream ss; ss.clear(); ss << std::boolalpha; (ss << ... << args); return ss.str(); } string join2str(const vector t, const char delm=' '){ string s; for (const auto &e : t) e!=*(t.end()-1)?s+=e+delm:s+=e; return s; } string join2str(const int argc,char** argv, const char delm=' '){ string s; for (int i=0;i cgroup){ for (auto &e:cgroup){ if (!regex_match(e, regex("^/[a-zA-Z0-9\\-_./@]*$"))){ return false; } } return true; } bool validPid(const string pid){ return regex_match(pid, regex("^[0-9]+$")); } bool validPort(const int port){ return port>0; } #endif