[Kamailio-Users] help to query a table with new function in core

Marcio mrgalhan at gmail.com
Mon Sep 15 16:34:27 CEST 2008


Hi all,

I need a help to solve some problems in the clearance of a function to
perform a query Mysql....I created a function based on documentation of
asipto / kamailio devel which is very good... But as I did not want to
create a new module I'm trying to use the module domain... whose goal a
proxy SIP receive msg that will should validate the realm comparing with a
table set up in MySQL(trusdomain)... it should be used into config file to
to declare of the table created in the Mysql: modparam ( "domain",
"trusdomain_table," trusdomain)
the version table of the openser has updated with the creation of this new
table (trusdomain) and created a function into file: domain.c / h and a part
was need be exported to config file in domain_mod.c / h....but on the tests
a call..this proxy kills the pid openser ...

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_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[] = {
    ............
    {"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 that I must be something doing wrong  ..... as would be the right
and as I could learn fast to resolve error debugging of pID of Openser that
has been deads...???

thx
Marcio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kamailio.org/pipermail/users/attachments/20080915/dad1a670/attachment.htm 


More information about the Users mailing list