rls.c

Go to the documentation of this file.
00001 /*
00002  * $Id: rls.c 2230 2007-06-06 07:13:20Z anca_vamanu $
00003  *
00004  * rls module - resource list server
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2007-09-11  initial version (anca)
00027  */
00028 
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <stdlib.h>
00032 #include <sys/types.h>
00033 #include <sys/ipc.h>
00034 #include <unistd.h>
00035 #include <fcntl.h>
00036 #include <time.h>
00037 
00038 #include "../../pt.h"
00039 #include "../../db/db.h"
00040 #include "../../sr_module.h"
00041 #include "../../dprint.h"
00042 #include "../../error.h"
00043 #include "../../ut.h"
00044 #include "../../mem/mem.h"
00045 #include "../../mem/shm_mem.h"
00046 #include "../tm/tm_load.h"
00047 #include "../sl/sl_api.h"
00048 #include "../presence/bind_presence.h"
00049 #include "../presence/hash.h"
00050 #include "../pua/pua_bind.h"
00051 #include "../pua/pidf.h"
00052 #include "../xcap_client/xcap_functions.h"
00053 #include "rls.h"
00054 #include "notify.h"
00055 #include "resource_notify.h"
00056 
00057 MODULE_VERSION
00058 
00059 #define P_TABLE_VERSION 0
00060 #define W_TABLE_VERSION 1
00061 
00062 /** database connection */
00063 db_con_t *rls_db = NULL;
00064 db_func_t rls_dbf;
00065 
00066 /** modules variables */
00067 str server_address= {0, 0};
00068 int waitn_time= 10;
00069 str rlsubs_table= str_init("rls_watchers");
00070 str rlpres_table= str_init("rls_presentity");
00071 str rls_xcap_table= str_init("xcap");
00072 
00073 str db_url= str_init(DEFAULT_DB_URL);
00074 int hash_size= 512;
00075 shtable_t rls_table;
00076 int pid;
00077 contains_event_t pres_contains_event;
00078 search_event_t pres_search_event;
00079 get_event_list_t pres_get_ev_list;
00080 int clean_period= 100;
00081 char* xcap_root;
00082 unsigned int xcap_port= 8000;
00083 int rls_restore_db_subs(void);
00084 int rls_integrated_xcap_server= 0;
00085 
00086 /** libxml api */
00087 xmlDocGetNodeByName_t XMLDocGetNodeByName;
00088 xmlNodeGetNodeByName_t XMLNodeGetNodeByName;
00089 xmlNodeGetNodeContentByName_t XMLNodeGetNodeContentByName;
00090 xmlNodeGetAttrContentByName_t XMLNodeGetAttrContentByName;
00091 
00092 /* functions imported from presence to handle subscribe hash table */
00093 new_shtable_t pres_new_shtable;
00094 insert_shtable_t pres_insert_shtable;
00095 search_shtable_t pres_search_shtable;
00096 update_shtable_t pres_update_shtable;
00097 delete_shtable_t pres_delete_shtable;
00098 destroy_shtable_t pres_destroy_shtable;
00099 mem_copy_subs_t  pres_copy_subs;
00100 update_db_subs_t pres_update_db_subs;
00101 extract_sdialog_info_t pres_extract_sdialog_info;
00102 int rls_events= EVENT_PRESENCE;
00103 int to_presence_code= 1;
00104 int rls_max_expires= 7200;
00105 
00106 /* functions imported from xcap_client module */
00107 xcapGetNewDoc_t xcap_GetNewDoc= 0;
00108 
00109 /* functions imported from pua module*/
00110 send_subscribe_t pua_send_subscribe;
00111 get_record_id_t pua_get_record_id;
00112 
00113 /* TM bind */
00114 struct tm_binds tmb;
00115 /* SL bind */
00116 struct sl_binds slb;
00117 
00118 str str_rlsubs_did_col = str_init("rlsubs_did");
00119 str str_resource_uri_col = str_init("resource_uri");
00120 str str_updated_col = str_init("updated");
00121 str str_auth_state_col = str_init("auth_state");
00122 str str_reason_col = str_init("reason");
00123 str str_content_type_col = str_init("content_type");
00124 str str_presence_state_col = str_init("presence_state");
00125 str str_expires_col = str_init("expires");
00126 str str_presentity_uri_col = str_init("presentity_uri");
00127 str str_event_col = str_init("event");
00128 str str_event_id_col = str_init("event_id");
00129 str str_to_user_col = str_init("to_user");
00130 str str_to_domain_col = str_init("to_domain");
00131 str str_watcher_username_col = str_init("watcher_username");
00132 str str_watcher_domain_col = str_init("watcher_domain");
00133 str str_callid_col = str_init("callid");
00134 str str_to_tag_col = str_init("to_tag");
00135 str str_from_tag_col = str_init("from_tag");
00136 str str_local_cseq_col = str_init("local_cseq");
00137 str str_remote_cseq_col = str_init("remote_cseq");
00138 str str_record_route_col = str_init("record_route");
00139 str str_socket_info_col = str_init("socket_info");
00140 str str_contact_col = str_init("contact");
00141 str str_local_contact_col = str_init("local_contact");
00142 str str_version_col = str_init("version");
00143 str str_status_col = str_init("status");
00144 str str_username_col = str_init("username");
00145 str str_domain_col = str_init("domain");
00146 str str_doc_type_col = str_init("doc_type");
00147 str str_etag_col = str_init("etag");
00148 str str_doc_col = str_init("doc");
00149 
00150 
00151 /** module functions */
00152 
00153 static int mod_init(void);
00154 static int child_init(int);
00155 int rls_handle_subscribe(struct sip_msg*, char*, char*);
00156 void destroy(void);
00157 int rlsubs_table_restore();
00158 void rlsubs_table_update(unsigned int ticks,void *param);
00159 int add_rls_event(modparam_t type, void* val);
00160 
00161 static cmd_export_t cmds[]=
00162 {
00163    {"rls_handle_subscribe",  (cmd_function)rls_handle_subscribe,   0,
00164          0, 0, REQUEST_ROUTE},
00165    {"rls_handle_notify",     (cmd_function)rls_handle_notify,      0,
00166          0, 0, REQUEST_ROUTE},
00167    {0, 0, 0, 0, 0, 0 }
00168 };
00169 
00170 static param_export_t params[]={
00171    { "server_address",         STR_PARAM,   &server_address.s             },
00172    { "db_url",             STR_PARAM,   &db_url.s                   },
00173    { "rlsubs_table",         STR_PARAM,   &rlsubs_table.s              },
00174    { "rlpres_table",       STR_PARAM,   &rlpres_table.s             },
00175    { "xcap_table",            STR_PARAM,   &rls_xcap_table.s              },
00176    { "waitn_time",            INT_PARAM,   &waitn_time                 },
00177    { "clean_period",       INT_PARAM,   &clean_period               },
00178    { "max_expires",        INT_PARAM,   &rls_max_expires            },
00179    { "hash_size",           INT_PARAM,   &hash_size                      },
00180    { "integrated_xcap_server",   INT_PARAM,   &rls_integrated_xcap_server     }, 
00181    { "to_presence_code",       INT_PARAM,   &to_presence_code               },
00182    { "xcap_root",              STR_PARAM,   &xcap_root                      },
00183    /*address and port(default: 80):"http://192.168.2.132:8000/xcap-root"*/
00184    { "rls_event",              STR_PARAM|USE_FUNC_PARAM,(void*)add_rls_event},
00185    {0,                     0,          0                      }
00186 };
00187 
00188 /** module exports */
00189 struct module_exports exports= {
00190    "rls",               /* module name */
00191    DEFAULT_DLFLAGS,        /* dlopen flags */
00192    cmds,                /* exported functions */
00193    params,                 /* exported parameters */
00194    0,                   /* exported statistics */
00195    0,                   /* exported MI functions */
00196    0,                   /* exported pseudo-variables */
00197    0,                   /* extra processes */
00198    mod_init,               /* module initialization function */
00199    0,                   /* response handling function */
00200    (destroy_function) destroy, /* destroy function */
00201    child_init                  /* per-child init function */
00202 };
00203 
00204 /**
00205  * init module function
00206  */
00207 static int mod_init(void)
00208 {
00209    bind_presence_t bind_presence;
00210    presence_api_t pres;
00211    bind_pua_t bind_pua;
00212    pua_api_t pua;
00213    bind_libxml_t bind_libxml;
00214    libxml_api_t libxml_api;
00215    bind_xcap_t bind_xcap;
00216    xcap_api_t xcap_api;
00217    char* sep;
00218 
00219    LM_DBG("start\n");
00220 
00221    if(!server_address.s)
00222    {
00223       LM_DBG("server_address parameter not set in configuration file\n");
00224    }  
00225    else
00226       server_address.len= strlen(server_address.s);
00227    
00228    if(!rls_integrated_xcap_server && xcap_root== NULL)
00229    {
00230       LM_ERR("xcap_root parameter not set\n");
00231       return -1;
00232    }
00233    /* extract port if any */
00234    if(xcap_root)
00235     {
00236         sep= strchr(xcap_root, ':');
00237         if(sep)
00238         {
00239             char* sep2= NULL;
00240             sep2= strchr(sep+ 1, ':');
00241             if(sep2)
00242                 sep= sep2;
00243 
00244             str port_str;
00245 
00246             port_str.s= sep+ 1;
00247             port_str.len= strlen(xcap_root)- (port_str.s-xcap_root);
00248 
00249             if(str2int(&port_str, &xcap_port)< 0)
00250             {
00251                 LM_ERR("converting string to int [port]= %.*s\n",port_str.len,
00252                         port_str.s);
00253                 return -1;
00254             }
00255             if(xcap_port< 0 || xcap_port> 65535)
00256             {
00257                 LM_ERR("wrong xcap server port\n");
00258                 return -1;
00259             }
00260             *sep= '\0';
00261         }
00262     }
00263 
00264    /* load SL API */
00265    if(load_sl_api(&slb)==-1)
00266    {
00267       LM_ERR("can't load sl functions\n");
00268       return -1;
00269    }
00270 
00271    /* load all TM stuff */
00272    if(load_tm_api(&tmb)==-1)
00273    {
00274       LM_ERR("can't load tm functions\n");
00275       return -1;
00276    }
00277    bind_presence= (bind_presence_t)find_export("bind_presence", 1,0);
00278    if (!bind_presence)
00279    {
00280       LM_ERR("Can't bind presence\n");
00281       return -1;
00282    }
00283    if (bind_presence(&pres) < 0)
00284    {
00285       LM_ERR("Can't bind presence\n");
00286       return -1;
00287    }
00288    pres_contains_event = pres.contains_event;
00289    pres_search_event   = pres.search_event;
00290    pres_get_ev_list    = pres.get_event_list;
00291    pres_new_shtable    = pres.new_shtable;
00292    pres_destroy_shtable= pres.destroy_shtable;
00293    pres_insert_shtable = pres.insert_shtable;
00294    pres_delete_shtable = pres.delete_shtable;
00295    pres_update_shtable = pres.update_shtable;
00296    pres_search_shtable = pres.search_shtable;
00297    pres_copy_subs      = pres.mem_copy_subs;
00298    pres_update_db_subs = pres.update_db_subs;
00299    pres_extract_sdialog_info= pres.extract_sdialog_info;
00300 
00301    if(!pres_contains_event || !pres_get_ev_list || !pres_new_shtable ||
00302       !pres_destroy_shtable || !pres_insert_shtable || !pres_delete_shtable
00303        || !pres_update_shtable || !pres_search_shtable || !pres_copy_subs
00304        || !pres_extract_sdialog_info)
00305    {
00306       LM_ERR("importing functions from presence module\n");
00307       return -1;
00308    }
00309 
00310    rlsubs_table.len= strlen(rlsubs_table.s);
00311    rlpres_table.len= strlen(rlpres_table.s);
00312    rls_xcap_table.len= strlen(rls_xcap_table.s);
00313    db_url.len = db_url.s ? strlen(db_url.s) : 0;
00314    LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s);
00315    
00316    /* binding to mysql module  */
00317    if (db_bind_mod(&db_url, &rls_dbf))
00318    {
00319       LM_ERR("Database module not found\n");
00320       return -1;
00321    }
00322    
00323    if (!DB_CAPABILITY(rls_dbf, DB_CAP_ALL)) {
00324       LM_ERR("Database module does not implement all functions"
00325             " needed by the module\n");
00326       return -1;
00327    }
00328 
00329    rls_db = rls_dbf.init(&db_url);
00330    if (!rls_db)
00331    {
00332       LM_ERR("while connecting database\n");
00333       return -1;
00334    }
00335    /* verify table version */
00336    if((db_check_table_version(&rls_dbf, rls_db, &rlsubs_table, W_TABLE_VERSION) < 0) ||
00337       (db_check_table_version(&rls_dbf, rls_db, &rlpres_table, P_TABLE_VERSION) < 0)) {
00338          LM_ERR("error during table version check.\n");
00339          return -1;
00340    }
00341    
00342    if(hash_size<=1)
00343       hash_size= 512;
00344    else
00345       hash_size = 1<<hash_size;
00346 
00347    rls_table= pres_new_shtable(hash_size);
00348    if(rls_table== NULL)
00349    {
00350       LM_ERR("while creating new hash table\n");
00351       return -1;
00352    }
00353    if(rls_restore_db_subs()< 0)
00354    {
00355       LM_ERR("while restoring rl watchers table\n");
00356       return -1;
00357    }
00358 
00359    if(rls_db)
00360       rls_dbf.close(rls_db);
00361    rls_db = NULL;
00362 
00363    if(waitn_time<= 0)
00364       waitn_time= 5;
00365    
00366    if(waitn_time<= 0)
00367       waitn_time= 100;
00368 
00369    /* bind libxml wrapper functions */
00370 
00371    if((bind_libxml=(bind_libxml_t)find_export("bind_libxml_api", 1, 0))== NULL)
00372    {
00373       LM_ERR("can't import bind_libxml_api\n");
00374       return -1;
00375    }
00376    if(bind_libxml(&libxml_api)< 0)
00377    {
00378       LM_ERR("can not bind libxml api\n");
00379       return -1;
00380    }
00381    XMLNodeGetAttrContentByName= libxml_api.xmlNodeGetAttrContentByName;
00382    XMLDocGetNodeByName= libxml_api.xmlDocGetNodeByName;
00383    XMLNodeGetNodeByName= libxml_api.xmlNodeGetNodeByName;
00384     XMLNodeGetNodeContentByName= libxml_api.xmlNodeGetNodeContentByName;
00385 
00386    if(XMLNodeGetAttrContentByName== NULL || XMLDocGetNodeByName== NULL ||
00387          XMLNodeGetNodeByName== NULL || XMLNodeGetNodeContentByName== NULL)
00388    {
00389       LM_ERR("libxml wrapper functions could not be bound\n");
00390       return -1;
00391    }
00392 
00393    /* bind pua */
00394    bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00395    if (!bind_pua)
00396    {
00397       LM_ERR("Can't bind pua\n");
00398       return -1;
00399    }
00400    
00401    if (bind_pua(&pua) < 0)
00402    {
00403       LM_ERR("mod_init Can't bind pua\n");
00404       return -1;
00405    }
00406    if(pua.send_subscribe == NULL)
00407    {
00408       LM_ERR("Could not import send_subscribe\n");
00409       return -1;
00410    }
00411    pua_send_subscribe= pua.send_subscribe;
00412    
00413    if(pua.get_record_id == NULL)
00414    {
00415       LM_ERR("Could not import send_subscribe\n");
00416       return -1;
00417    }
00418    pua_get_record_id= pua.get_record_id;
00419 
00420    if(!rls_integrated_xcap_server)
00421    {
00422       /* bind xcap */
00423       bind_xcap= (bind_xcap_t)find_export("bind_xcap", 1, 0);
00424       if (!bind_xcap)
00425       {
00426          LM_ERR("Can't bind xcap_client\n");
00427          return -1;
00428       }
00429    
00430       if (bind_xcap(&xcap_api) < 0)
00431       {
00432          LM_ERR("Can't bind xcap\n");
00433          return -1;
00434       }
00435       xcap_GetNewDoc= xcap_api.getNewDoc;
00436       if(xcap_GetNewDoc== NULL)
00437       {
00438          LM_ERR("Can't import xcap_client functions\n");
00439          return -1;
00440       }
00441    }
00442    register_timer(timer_send_notify,0, waitn_time);
00443    
00444    register_timer(rls_presentity_clean, 0, clean_period);
00445    
00446    register_timer(rlsubs_table_update, 0, clean_period);
00447    
00448    return 0;
00449 }
00450 
00451 /**
00452  * Initialize children
00453  */
00454 static int child_init(int rank)
00455 {
00456    LM_DBG("child [%d]  pid [%d]\n", rank, getpid());
00457    if (rls_dbf.init==0)
00458    {
00459       LM_CRIT("database not bound\n");
00460       return -1;
00461    }
00462    rls_db = rls_dbf.init(&db_url);
00463    if (!rls_db)
00464    {
00465       LM_ERR("child %d: Error while connecting database\n",
00466             rank);
00467       return -1;
00468    }
00469    else
00470    {
00471       if (rls_dbf.use_table(rls_db, &rlsubs_table) < 0)  
00472       {
00473          LM_ERR("child %d: Error in use_table rlsubs_table\n", rank);
00474          return -1;
00475       }
00476       if (rls_dbf.use_table(rls_db, &rlpres_table) < 0)  
00477       {
00478          LM_ERR("child %d: Error in use_table rlpres_table\n", rank);
00479          return -1;
00480       }
00481 
00482       LM_DBG("child %d: Database connection opened successfully\n", rank);
00483    }
00484 
00485    pid= my_pid();
00486    return 0;
00487 }
00488 
00489 /*
00490  * destroy function
00491  */
00492 void destroy(void)
00493 {
00494    LM_DBG("start\n");
00495    
00496    if(rls_table)
00497    {
00498       if(rls_db)
00499          rlsubs_table_update(0, 0);
00500       pres_destroy_shtable(rls_table, hash_size);
00501    }
00502    if(rls_db && rls_dbf.close)
00503       rls_dbf.close(rls_db);
00504 }
00505 
00506 int handle_expired_record(subs_t* s)
00507 {
00508    /* send Notify with state terminated*/ 
00509    if( rls_send_notify(s, NULL, NULL, NULL)< 0)
00510    {
00511       LM_ERR("in function send_notify\n");
00512       return -1;
00513    }
00514    
00515    return 0;
00516 }
00517 
00518 void rlsubs_table_update(unsigned int ticks,void *param)
00519 {
00520    int no_lock= 0;
00521 
00522    if(ticks== 0 && param == NULL)
00523       no_lock= 1;
00524    
00525    if(rls_dbf.use_table(rls_db, &rlsubs_table)< 0)
00526    {
00527       LM_ERR("sql use table failed\n");
00528       return;
00529    }
00530    pres_update_db_subs(rls_db, rls_dbf, rls_table, hash_size, 
00531          no_lock, handle_expired_record);
00532 
00533 }
00534 
00535 int rls_restore_db_subs(void)
00536 {
00537    db_key_t result_cols[22]; 
00538    db_res_t *res= NULL;
00539    db_row_t *row = NULL;   
00540    db_val_t *row_vals= NULL;
00541    int i;
00542    int n_result_cols= 0;
00543    int pres_uri_col, expires_col, from_user_col, from_domain_col,to_user_col; 
00544    int callid_col,totag_col,fromtag_col,to_domain_col,sockinfo_col,reason_col;
00545    int event_col,contact_col,record_route_col, event_id_col, status_col;
00546    int remote_cseq_col, local_cseq_col, local_contact_col, version_col;
00547    subs_t s;
00548    str ev_sname;
00549    pres_ev_t* event= NULL;
00550    event_t parsed_event;
00551    unsigned int expires;
00552    unsigned int hash_code;
00553 
00554    result_cols[pres_uri_col=n_result_cols++] = &str_presentity_uri_col;
00555    result_cols[expires_col=n_result_cols++] = &str_expires_col;
00556    result_cols[event_col=n_result_cols++] = &str_event_col;
00557    result_cols[event_id_col=n_result_cols++] = &str_event_id_col;
00558    result_cols[to_user_col=n_result_cols++] = &str_to_user_col;
00559    result_cols[to_domain_col=n_result_cols++] = &str_to_domain_col;
00560    result_cols[from_user_col=n_result_cols++] = &str_watcher_username_col;
00561    result_cols[from_domain_col=n_result_cols++] = &str_watcher_domain_col;
00562    result_cols[callid_col=n_result_cols++] = &str_callid_col;
00563    result_cols[totag_col=n_result_cols++] = &str_to_tag_col;
00564    result_cols[fromtag_col=n_result_cols++] = &str_from_tag_col;
00565    result_cols[local_cseq_col= n_result_cols++] = &str_local_cseq_col;
00566    result_cols[remote_cseq_col= n_result_cols++] = &str_remote_cseq_col;
00567    result_cols[record_route_col= n_result_cols++] = &str_record_route_col;
00568    result_cols[sockinfo_col= n_result_cols++] = &str_socket_info_col;
00569    result_cols[contact_col= n_result_cols++] = &str_contact_col;
00570    result_cols[local_contact_col= n_result_cols++] = &str_local_contact_col;
00571    result_cols[version_col= n_result_cols++] = &str_version_col;
00572    result_cols[status_col= n_result_cols++] = &str_status_col;
00573    result_cols[reason_col= n_result_cols++] = &str_reason_col;
00574    
00575    if(!rls_db)
00576    {
00577       LM_ERR("null database connection\n");
00578       return -1;
00579    }
00580    if(rls_dbf.use_table(rls_db, &rlsubs_table)< 0)
00581    {
00582       LM_ERR("in use table\n");
00583       return -1;
00584    }
00585 
00586    if(rls_dbf.query(rls_db,0, 0, 0, result_cols,0, n_result_cols, 0,&res)< 0)
00587    {
00588       LM_ERR("while querrying table\n");
00589       if(res)
00590       {
00591          rls_dbf.free_result(rls_db, res);
00592          res = NULL;
00593       }
00594       return -1;
00595    }
00596    if(res== NULL)
00597       return -1;
00598 
00599    if(res->n<=0)
00600    {
00601       LM_INFO("The query returned no result\n");
00602       rls_dbf.free_result(rls_db, res);
00603       res = NULL;
00604       return 0;
00605    }
00606 
00607    LM_DBG("found %d db entries\n", res->n);
00608 
00609    for(i =0 ; i< res->n ; i++)
00610    {
00611       row = &res->rows[i];
00612       row_vals = ROW_VALUES(row);
00613       memset(&s, 0, sizeof(subs_t));
00614 
00615       expires= row_vals[expires_col].val.int_val;
00616       
00617       if(expires< (int)time(NULL))
00618          continue;
00619    
00620       s.pres_uri.s= (char*)row_vals[pres_uri_col].val.string_val;
00621       s.pres_uri.len= strlen(s.pres_uri.s);
00622       
00623       s.to_user.s=(char*)row_vals[to_user_col].val.string_val;
00624       s.to_user.len= strlen(s.to_user.s);
00625 
00626       s.to_domain.s=(char*)row_vals[to_domain_col].val.string_val;
00627       s.to_domain.len= strlen(s.to_domain.s);
00628 
00629       s.from_user.s=(char*)row_vals[from_user_col].val.string_val;
00630       s.from_user.len= strlen(s.from_user.s);
00631       
00632       s.from_domain.s=(char*)row_vals[from_domain_col].val.string_val;
00633       s.from_domain.len= strlen(s.from_domain.s);
00634 
00635       s.to_tag.s=(char*)row_vals[totag_col].val.string_val;
00636       s.to_tag.len= strlen(s.to_tag.s);
00637 
00638       s.from_tag.s=(char*)row_vals[fromtag_col].val.string_val;
00639       s.from_tag.len= strlen(s.from_tag.s);
00640 
00641       s.callid.s=(char*)row_vals[callid_col].val.string_val;
00642       s.callid.len= strlen(s.callid.s);
00643 
00644       ev_sname.s= (char*)row_vals[event_col].val.string_val;
00645       ev_sname.len= strlen(ev_sname.s);
00646       
00647       event= pres_contains_event(&ev_sname, &parsed_event);
00648       if(event== NULL)
00649       {
00650          LM_ERR("event not found in list\n");
00651          goto error;
00652       }
00653       s.event= event;
00654 
00655       s.event_id.s=(char*)row_vals[event_id_col].val.string_val;
00656       if(s.event_id.s)
00657          s.event_id.len= strlen(s.event_id.s);
00658 
00659       s.remote_cseq= row_vals[remote_cseq_col].val.int_val;
00660       s.local_cseq= row_vals[local_cseq_col].val.int_val;
00661       s.version= row_vals[version_col].val.int_val;
00662       
00663       s.expires= expires- (int)time(NULL);
00664       s.status= row_vals[status_col].val.int_val;
00665 
00666       s.reason.s= (char*)row_vals[reason_col].val.string_val;
00667       if(s.reason.s)
00668          s.reason.len= strlen(s.reason.s);
00669 
00670       s.contact.s=(char*)row_vals[contact_col].val.string_val;
00671       s.contact.len= strlen(s.contact.s);
00672 
00673       s.local_contact.s=(char*)row_vals[local_contact_col].val.string_val;
00674       s.local_contact.len= strlen(s.local_contact.s);
00675    
00676       s.record_route.s=(char*)row_vals[record_route_col].val.string_val;
00677       if(s.record_route.s)
00678          s.record_route.len= strlen(s.record_route.s);
00679    
00680       s.sockinfo_str.s=(char*)row_vals[sockinfo_col].val.string_val;
00681       s.sockinfo_str.len= strlen(s.sockinfo_str.s);
00682 
00683       hash_code= core_hash(&s.pres_uri, &s.event->name, hash_size);
00684       if(pres_insert_shtable(rls_table, hash_code, &s)< 0)
00685       {
00686          LM_ERR("adding new record in hash table\n");
00687          goto error;
00688       }
00689    }
00690 
00691    rls_dbf.free_result(rls_db, res);
00692 
00693    /* delete all records */
00694    if(rls_dbf.delete(rls_db, 0,0,0,0)< 0)
00695    {
00696       LM_ERR("deleting all records from database table\n");
00697       return -1;
00698    }
00699 
00700    return 0;
00701 
00702 error:
00703    if(res)
00704       rls_dbf.free_result(rls_db, res);
00705    return -1;
00706 
00707 }
00708 
00709 int add_rls_event(modparam_t type, void* val)
00710 {
00711    char* event= (char*)val;
00712    event_t e;
00713 
00714    if(event_parser(event, strlen(event), &e)< 0)
00715    {
00716       LM_ERR("while parsing event = %s\n", event);
00717       return -1;
00718    }
00719    if(e.parsed & EVENT_OTHER)
00720    {
00721       LM_ERR("wrong event= %s\n", event);
00722       return -1;
00723    }
00724 
00725    rls_events|= e.parsed;
00726 
00727    return 0;
00728 
00729 }

Generated on Thu May 24 12:00:30 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6