// Author: Robert Rusecki // Company: Kolmisoft // Year: 2020 // About: MNP module for m2. #define M2_MNP_VERSION "0.2" #define TEST 0 #define SIP_HEADER "x-M2-cip" #define SHOW_SQL 0 #define ANELEMS(x) (sizeof(x) / sizeof((x)[0])) // STRUCTS typedef struct prefix_struct { int number; int exist; struct main_node_struct *child; } prefix_t; typedef struct main_node_struct { prefix_t *sub_node[10]; } main_t; typedef struct shared_data_struct { main_t *main_n; } shd_t; // FUNCTIONS static int mod_init(void); static int child_init(int rank); void mod_destroy(void); int load_prefixes(); int get_mnp_credentials(); int mnp_mysql_query(char *query, MYSQL *con); int open_gui_mysql_connection(); int open_mnp_mysql_connection(); MYSQL *open_mysql_connection(char *dbhost, char *dbuser, char *dbpass, char *dbname, int dbport, int local); int init_locks(); void destroy_locks(); int validate_params(); static int m2_mnp(struct sip_msg *msg); hdr_field_t *get_to_header(struct sip_msg *msg); int get_cip_from_mnp(char *dst); int get_prefixes_from_gui(main_t *node); void trie_free(main_t *node); void insert_prefix(char *prefix, main_t* node); prefix_t *add_subnode(); main_t *initialize_main_node(); void null_subnodes(main_t *node); int add_mnp_header(struct sip_msg *msg, char *value); int is_prefix_in_trie(char *prefix); int is_allowed_number(int n); int parse_header_number_part(char *header, char *number); void get_supported_prefixes_status(); void get_mnp_status(); /* the parameters are not used, they are only meant as an example*/ // MYSQL variables str guidb_host = STR_NULL; str guidb_user = STR_NULL; str guidb_pass = STR_NULL; str guidb_name = STR_NULL; int guidb_port = 0; char *mnpdb_host = NULL; char *mnpdb_user = NULL; char *mnpdb_pass = NULL; char *mnpdb_name = NULL; char *search_field = NULL; char *result_field = NULL; char *table_name = NULL; int *mnpdb_port = NULL; int *mnp_supported_prefixes = NULL; int *use_mnp = NULL; // static cmd_export_t cmds[]={ {"m2_mnp", (cmd_function)m2_mnp, 0, 0, 0, REQUEST_ROUTE}, {0, 0, 0, 0, 0, 0} }; static param_export_t params[]={ {"guidb_host", PARAM_STR, &guidb_host}, {"guidb_user", PARAM_STR, &guidb_user}, {"guidb_pass", PARAM_STR, &guidb_pass}, {"guidb_name", PARAM_STR, &guidb_name}, {"guidb_port", INT_PARAM, &guidb_port}, {0,0,0} }; void update_rpc(rpc_t* rpc, void* ctx); static const char* update_rpc_doc[] = { "Update mnp prefix list", 0 }; static rpc_export_t mnp_rpc[]={ {"m2_mnp.update", update_rpc, update_rpc_doc, 0}, {0,0,0,0} }; struct module_exports exports = { "m2_mnp", /* module name */ DEFAULT_DLFLAGS, /* dlopen flags */ cmds, /* exported functions */ params, /* exported parameters */ mnp_rpc, /* RPC method exports */ 0, /* exported pseudo-variables */ 0, /* response handling function */ mod_init, /* module initialization function */ child_init, /* per-child init function */ mod_destroy /* module destroy function */ };