Hi all,
I appreciate very much to help solve some problems in the clearance of a function to perform a query Mysql .... created the function based on documentation of asipto / kamailio devel which is great ... but I did not want to create a new module used the module in domain ... whose goal is a proxy to receive SIP msg should validate the realm with what is in a table (Trustee) was created through a query ... it should be used for the config file to declare of the table created in the Mysql: modparam ( "domain", "trusdomain_table," trusdomain) the table version updated with the creation of this table (trusdomain) and create the own function in the file: domain.c / h part to be exported in domain_mod.c / h....but on the tests a call SIP to proxy kills a openser's pid ...
Sep 5 06:32:21 notehome openser[7962]: INFO:core:handle_sigs: child process 7964 exited by a signal 11 Sep 5 06:32:21 notehome openser[7962]: INFO:core:handle_sigs: core was generated Sep 5 06:32:21 notehome openser[7962]: INFO:core:handle_sigs: terminating due to SIGCHLD Sep 5 06:32:21 notehome openser[7967]: INFO:core:sig_usr: signal 15 received Sep 5 06:32:21 notehome openser[7963]: INFO:core:sig_usr: signal 15 received Sep 5 06:32:21 notehome openser[7968]: INFO:core:sig_usr: signal 15 received Sep 5 06:32:21 notehome openser[7966]: INFO:core:sig_usr: signal 15 received Sep 5 06:32:21 notehome openser[7965]: INFO:core:sig_usr: signal 15 received
*The function created in domain.c:* int is_from_trusted(struct sip_msg* _msg, char* _s1, char* _s2) { struct sip_uri *puri; /* struct str* _host; */ /* str table_trus; str col_id; str col_dom; str col_lastmod; */
str* _host = (str*)(&(puri->host)); char* db_url = DEFAULT_RODB_URL;
db_key_t keys[1]; /* Tipo da coluna .. Nome das colunas */ db_val_t vals[1]; db_key_t cols[1]; db_res_t* res = NULL;
if ((puri=parse_from_uri(_msg))==NULL){ LM_ERR("Error while parsing From header\n"); return -2; }
/* Bind the database module */ if (bind_dbmod(db_url, &domain_dbf )) { LM_ERR("Cannot bind to database module!\n"); return -1; }
/* Check for SELECT capability */ if (!DB_CAPABILITY(domain_dbf, DB_CAP_QUERY)){ LM_ERR("Database modules does not provide all functions needed\n"); return -1; }
/* Connect to DB */ db_handle = domain_dbf.init(db_url); if (!db_handle){ LM_ERR("failed to connect database\n"); return -1; }
keys[0]=trusdomain_col.s; cols[0]=trusdomain_col.s;
LM_INFO(">>domain.c>>-2-IF RES_ROW_N(res)=>%d\n",RES_ROW_N(res)); /* Estrutura dos vls das colunas - arq. db/db_val.h */ VAL_TYPE(vals) = DB_STR; VAL_NULL(vals) = 0;
VAL_STR(vals).s = _host->s; VAL_STR(vals).len = _host->len;
/* LM_INFO(">>domain.c>>-1-connector=%d and tab=%s\n",db_handle,trusdomain_table.s); */ if (domain_dbf.use_table(db_handle, trusdomain_table.s) < 0) { LM_ERR("Error while trying to use trusdomain table\n"); return -1; }
if (domain_dbf.query(db_handle, keys, NULL, vals, cols, 1, 1, 0, &res) < 0) { LM_ERR("Error while querying database\n"); domain_dbf.close(db_handle); return -1; }
/* RES_ROW_N(res) Num. de linhas no fetch */ if (RES_ROW_N(res) <= 0 || RES_ROWS(res)[0].values[0].nul != 0){ LM_DBG("no value found\n"); if (res != NULL && domain_dbf.free_result(db_handle, res) < 0) LM_DBG("failed to free the result\n"); domain_dbf.close(db_handle); } else if (RES_ROW_N(res) >= 1) { /* Teste do que estah na tab. trusdomain com o que vem na URI */ LM_DBG("Realm '%.*s' is trusted\n",_host->len, ZSW(_host->s)); }
/* Free the result */ domain_dbf.free_result(db_handle, res); domain_dbf.close(db_handle);
return 0; }
*And declaration in domain_mod.c :* ... /* by mrg */ #define TRUSDOMAIN_TABLE "trusdomain" #define TRUSDOMAIN_TABLE_LEN (sizeof(TRUSDOMAIN_TABLE) - 1) #define TRUSDOMAIN_COL "trusdomain" #define TRUSDOMAIN_COL_LEN (sizeof(TRUSDOMAIN_COL) - 1) ... ... str trusdomain_table = {TRUSDOMAIN_TABLE, TRUSDOMAIN_TABLE_LEN}; /* Name of trusted table */ str trusdomain_col = {TRUSDOMAIN_COL, TRUSDOMAIN_COL_LEN}; /* Name of trusted column */ ... ... /* * * Exported functions */ static cmd_export_t cmds[] = { {"is_from_local", is_from_local, 0, 0, 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, {"is_uri_host_local", is_uri_host_local, 0, 0, 0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, {"is_domain_local", w_is_domain_local, 1, parameter_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, {"is_from_trusted", is_from_trusted, 0, 0, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, {0, 0, 0, 0, 0, 0} }; .../* * Exported parameters */ static param_export_t params[] = { {"db_url", STR_PARAM, &db_url.s }, {"db_mode", INT_PARAM, &db_mode }, {"domain_table", STR_PARAM, &domain_table.s}, {"domain_col", STR_PARAM, &domain_col.s }, {"trusdomain_table", STR_PARAM, &trusdomain_table.s}, {"trusdomain_col", STR_PARAM, &trusdomain_col.s}, {0, 0, 0} }; ... ... static int mod_init(void) { int vertr....; ..... trusdomain_table.len = strlen(trusdomain_table.s); trusdomain_col.len = strlen(trusdomain_col.s); ..... if (db_mode != 0) { if (domain_db_init(db_url.s)<0) return -1;
/* Check table version */ ver = domain_db_ver(&domain_table); vertr = domain_db_ver(&trusdomain_table);
if ((ver < 0) && (vertr < 0)) { LM_ERR("Error while querying table version\n"); goto error; } else if ((ver < TABLE_VERSION) && (vertr < TABLE_VERSION)) { LM_ERR("Invalid table version <%d> trustable version <%d> (should be %d)\n", ver, vertr, TABLE_VERSION); goto error; } ....... ....... /* Initializing hash tables and hash table variable */ ........ domain_db_close(); }
return 0; error: domain_db_close(); return -1; }
So I think I must be doing everything wrong ..... as would be the right and as I could learn so fast as this error debugging of pID of Openser is dead...???
Any help would be greatly appreciated...
thx Marcio