static int mod_init(void) { #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, imc_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif if(imc_rpc_init()<0) { LM_ERR("failed to register RPC commands\n"); return -1; } if(imc_hash_size <= 0) { LM_ERR("invalid hash size\n"); return -1; } imc_hash_size = 1 << imc_hash_size; if(imc_htable_init() < 0) { LM_ERR("initializing hash table\n"); return -1; } if (extra_hdrs.s) { if (extra_hdrs.len + imc_hdr_ctype.len > 1024) { LM_ERR("extra_hdrs too long\n"); return -1; } all_hdrs.s = &(hdr_buf[0]); memcpy(all_hdrs.s, imc_hdr_ctype.s, imc_hdr_ctype.len); memcpy(all_hdrs.s + imc_hdr_ctype.len, extra_hdrs.s, extra_hdrs.len); all_hdrs.len = extra_hdrs.len + imc_hdr_ctype.len; } else { all_hdrs = imc_hdr_ctype; } /* binding to mysql module */ LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s); if (db_bind_mod(&db_url, &imc_dbf)) { LM_DBG("database module not found\n"); return -1; } imc_db = imc_dbf.init(&db_url); if (!imc_db) { LM_ERR("failed to connect to the database\n"); return -1; } /* read the informations stored in db */ if(add_from_db() <0) { LM_ERR("failed to get information from db\n"); return -1; } /* load TM API */ if (load_tm_api(&tmb)!=0) { LM_ERR("unable to load tm api\n"); return -1; } imc_cmd_start_char = imc_cmd_start_str.s[0]; if(imc_db) imc_dbf.close(imc_db); imc_db = NULL; return 0; }
static int mod_init(void) { LM_INFO("initializing ...\n"); if(imc_hash_size <= 0) { LM_ERR("invalid hash size\n"); return -1; } imc_hash_size = 1 << imc_hash_size; if(imc_htable_init() < 0) { LM_ERR("initializing hash table\n"); return -1; } imc_cmd_start_str.len = strlen(imc_cmd_start_str.s); if(outbound_proxy.s) outbound_proxy.len = strlen(outbound_proxy.s); rooms_table.len = strlen(rooms_table.s); members_table.len = strlen(members_table.s); /* binding to mysql module */ init_db_url( db_url , 0 /*cannot be null*/); LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s); if (db_bind_mod(&db_url, &imc_dbf)) { LM_DBG("database module not found\n"); return -1; } imc_db = imc_dbf.init(&db_url); if (!imc_db) { LM_ERR("failed to connect to the database\n"); return -1; } /* read the informations stored in db */ if(add_from_db() <0) { LM_ERR("failed to get information from db\n"); return -1; } /* load TM API */ if (load_tm_api(&tmb)!=0) { LM_ERR("unable to load tm api\n"); return -1; } imc_cmd_start_char = imc_cmd_start_str.s[0]; if(imc_db) imc_dbf.close(imc_db); imc_db = NULL; return 0; }