/* * Register domain fifo functions */ int init_lcr_fifo( void ) { if (register_fifo_cmd(lcr_reload, LCR_RELOAD, 0) < 0) { LOG(L_CRIT, "Cannot register lcr_reload\n"); return -1; } if (register_fifo_cmd(lcr_dump, LCR_DUMP, 0) < 0) { LOG(L_CRIT, "Cannot register lcr_dump\n"); return -1; } return 1; }
int init_tm_stats(void) { int size; tm_stats=shm_malloc(sizeof(struct t_stats)); if (tm_stats==0) { LOG(L_ERR, "ERROR: init_tm_stats: no mem for stats\n"); goto error0; } memset(tm_stats, 0, sizeof(struct t_stats) ); size=sizeof(stat_counter)*process_count(); tm_stats->s_waiting=shm_malloc(size); if (tm_stats->s_waiting==0) { LOG(L_ERR, "ERROR: init_tm_stats: no mem for stats\n"); goto error1; } memset(tm_stats->s_waiting, 0, size ); tm_stats->s_transactions=shm_malloc(size); if (tm_stats->s_transactions==0) { LOG(L_ERR, "ERROR: init_tm_stats: no mem for stats\n"); goto error2; } memset(tm_stats->s_transactions, 0, size ); tm_stats->s_client_transactions=shm_malloc(size); if (tm_stats->s_client_transactions==0) { LOG(L_ERR, "ERROR: init_tm_stats: no mem for stats\n"); goto error3; } memset(tm_stats->s_client_transactions, 0, size ); if (register_fifo_cmd(fifo_stats, "t_stats", 0)<0) { LOG(L_CRIT, "cannot register fifo stats\n"); goto error4; } if (unixsock_register_cmd("t_stats", unixsock_stats) < 0) { LOG(L_CRIT, "cannot register fifo stats\n"); goto error4; } return 1; error4: shm_free(tm_stats->s_client_transactions); tm_stats->s_client_transactions=0; error3: shm_free(tm_stats->s_transactions); tm_stats->s_transactions=0; error2: shm_free(tm_stats->s_waiting); tm_stats->s_waiting=0; error1: shm_free(tm_stats); error0: return -1; }
static int mod_init(void) { gflags=(unsigned int *) shm_malloc(sizeof(unsigned int)); if (!gflags) { LOG(L_ERR, "Error: gflags/mod_init: no shmem\n"); return -1; } *gflags=initial; if (register_fifo_cmd(fifo_set_gflag, FIFO_SET_GFLAG, 0) < 0) { LOG(L_CRIT, "Cannot register FIFO_SET_GFLAG\n"); return -1; } if (register_fifo_cmd(fifo_reset_gflag, FIFO_RESET_GFLAG, 0) < 0) { LOG(L_CRIT, "Cannot register FIFO_RESET_GFLAG\n"); return -1; } if (register_fifo_cmd(fifo_is_gflag, FIFO_IS_GFLAG, 0) < 0) { LOG(L_CRIT, "Cannot register FIFO_SET_GFLAG\n"); return -1; } return 0; }
int register_core_fifo() { if (register_fifo_cmd(print_fifo_cmd, FIFO_PRINT, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PRINT); return -1; } if (register_fifo_cmd(uptime_fifo_cmd, FIFO_UPTIME, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_UPTIME); return -1; } if (register_fifo_cmd(print_version_cmd, FIFO_VERSION, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_VERSION); return -1; } if (register_fifo_cmd(pwd_cmd, FIFO_PWD, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PWD); return -1; } if (register_fifo_cmd(arg_cmd, FIFO_ARG, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_ARG); return -1; } if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_WHICH); return -1; } if (register_fifo_cmd(ps_fifo_cmd, FIFO_PS, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PS); return -1; } if (register_fifo_cmd(kill_fifo_cmd, FIFO_KILL, 0)<0) { LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_KILL); return -1; } return 1; }
int init_ul_fifo( void ) { if (register_fifo_cmd(ul_stats_cmd, UL_STATS, 0) < 0) { LOG(L_CRIT, "cannot register ul_stats\n"); return -1; } if (register_fifo_cmd(ul_rm, UL_RM, 0) < 0) { LOG(L_CRIT, "cannot register ul_rm\n"); return -1; } if (register_fifo_cmd(ul_rm_contact, UL_RM_CONTACT, 0) < 0) { LOG(L_CRIT, "cannot register ul_rm_contact\n"); return -1; } if (register_fifo_cmd(ul_dump, UL_DUMP, 0) < 0) { LOG(L_CRIT, "cannot register ul_dump\n"); return -1; } if (register_fifo_cmd(ul_flush, UL_FLUSH, 0) < 0) { LOG(L_CRIT, "cannot register ul_flush\n"); return -1; } if (register_fifo_cmd(ul_add, UL_ADD, 0) < 0) { LOG(L_CRIT, "cannot register ul_add\n"); return -1; } if (register_fifo_cmd(ul_show_contact, UL_SHOW_CONTACT, 0) < 0) { LOG(L_CRIT, "cannot register ul_show_contact\n"); return -1; } return 1; }
static int pa_mod_init(void) { DBG("Presence Agent - initializing\n"); test_mimetype_parser(); /* load the TM API */ if (load_tm_api(&tmb)!=0) { LOG(L_ERR, "ERROR:acc:mod_init: can't load TM API\n"); return -1; } if (register_fifo_cmd(fifo_pa_publish, "pa_publish", 0) < 0) { LOG(L_CRIT, "cannot register fifo pa_publish\n"); return -1; } if (register_fifo_cmd(fifo_pa_presence, "pa_presence", 0) < 0) { LOG(L_CRIT, "cannot register fifo pa_presence\n"); return -1; } if (register_fifo_cmd(fifo_pa_location, "pa_location", 0) < 0) { LOG(L_CRIT, "cannot register fifo pa_location\n"); return -1; } if (register_fifo_cmd(fifo_pa_location_contact, "pa_location_contact", 0) < 0) { LOG(L_CRIT, "cannot register fifo pa_location_contact\n"); return -1; } if (register_fifo_cmd(fifo_pa_watcherinfo, "pa_watcherinfo", 0) < 0) { LOG(L_CRIT, "cannot register fifo pa_watcherinfo\n"); return -1; } if (init_unixsock_iface() < 0) { LOG(L_ERR, "pa_mod_init: Error while initializing unix socket interface\n"); return -1; } /* Register cache timer */ register_timer(timer, 0, timer_interval); LOG(L_CRIT, "db_url=%p\n", db_url.s); LOG(L_CRIT, "db_url=%s\n", ZSW(db_url.s)); db_url.len = db_url.s ? strlen(db_url.s) : 0; LOG(L_CRIT, "db_url.len=%d\n", db_url.len); #ifdef HAVE_LOCATION_PACKAGE if (pa_domain.len == 0) { LOG(L_ERR, "pa_mod_init(): pa_domain must be specified\n"); return -1; } LOG(L_CRIT, "pa_mod: pa_mod=%s\n", ZSW(pa_domain.s)); #endif /* HAVE_LOCATION_PACKAGE */ LOG(L_CRIT, "pa_mod: use_db=%d db_url.s=%s\n", use_db, ZSW(db_url.s)); if (use_db) { if (!db_url.len) { LOG(L_ERR, "pa_mod_init(): no db_url specified but use_db=1\n"); return -1; } if (bind_dbmod(db_url.s, &pa_dbf) < 0) { /* Find database module */ LOG(L_ERR, "pa_mod_init(): Can't bind database module via url %s\n", db_url.s); return -1; } if (!DB_CAPABILITY(pa_dbf, DB_CAP_ALL)) { LOG(L_ERR, "pa_mod_init(): Database module does not implement all functions needed by the module\n"); return -1; } } default_priority = ((double)default_priority_percentage) / 100.0; LOG(L_CRIT, "pa_mod_init done\n"); return 0; }
/** * init module function */ static int mod_init(void) { db_res_t* db_res = NULL; code_t i, code; dc_t* cell; DBG("PDT: initializing...\n"); if(hs_two_pow<0) { LOG(L_ERR, "PDT: mod_init: hash_size_two_pow must be" " positive and less than %d\n", MAX_HSIZE_TWO_POW); return -1; } if(code_terminator>9 || code_terminator<0) { LOG(L_ERR, "PDT: mod_init: code_terminator must be a digit\n"); return -1; } if(!prefix_valid()) return -1; next_code = (code_t*)shm_malloc(sizeof(code_t)); if(!next_code) { LOG(L_ERR, "PDT: mod_init: cannot allocate next_code!\n"); return -1; } if(lock_init(&l) == 0) { shm_free(next_code); LOG(L_ERR, "PDT: mod_init: cannot init the lock\n"); return -1; } if(register_fifo_cmd(get_domainprefix, "get_domainprefix", 0)<0) { LOG(L_ERR, "PDT: mod_init: cannot register fifo command 'get_domaincode'\n"); goto error1; } /* binding to mysql module */ if(bind_dbmod()) { LOG(L_ERR, "PDT: mod_init: Database module not found\n"); goto error1; } /* open a connection with the database */ db_con = db_init(db_url); if(!db_con) { LOG(L_ERR, "PDT: mod_init: Error while connecting to database\n"); goto error1; } else { db_use_table(db_con, db_table); DBG("PDT: mod_init: Database connection opened successfully\n"); } /* init hashes in share memory */ if( (hash = init_double_hash(hs_two_pow)) == NULL) { LOG(L_ERR, "PDT: mod_init: hash could not be allocated\n"); goto error2; } /* loading all information from database */ *next_code = 0; if(db_query(db_con, NULL, NULL, NULL, NULL, 0, 0, "code", &db_res)==0) { for(i=0; i<RES_ROW_N(db_res); i++) { code = RES_ROWS(db_res)[i].values[0].val.int_val; if (!code_valid(code)) { LOG(L_ERR, "PDT: mod_init: existing code contains the terminator\n"); goto error; } if (*next_code < code) *next_code = code; cell=new_cell( (char*)(RES_ROWS(db_res)[i].values[1].val.string_val), code); if(cell == NULL) goto error; if(add_to_double_hash(hash, cell)<0) { LOG(L_ERR, "PDT: mod_init: could not add information from database" " into shared-memory hashes\n"); goto error; } } // clear up here //print_hash(hash->dhash, hash->hash_size); //print_hash(hash->chash, hash->hash_size); (*next_code)++; if (*next_code < start_range) *next_code = start_range; *next_code = apply_correction(*next_code); DBG("PDT: mod_init: next_code:%d\n", *next_code); /* free up the space allocated for response */ if(db_free_query(db_con, db_res)<0) { LOG(L_ERR, "PDT: mod_init: error when freeing" " up the response space\n"); } } else { /* query to database failed */ LOG(L_ERR, "PDT: mod_init: query to database failed\n"); goto error; } db_close(db_con); /* janakj - close the connection */ /* success code */ return 0; error: free_double_hash(hash); error2: db_close(db_con); error1: shm_free(next_code); lock_destroy(&l); return -1; }
static int mod_init(void) { DBG( "TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializin Call-ID generator\n"); return -1; } if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac\n"); return -1; } if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { LOG(L_CRIT, "cannot register hash\n"); return -1; } if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* register the timer function */ register_timer( timer_routine , 0 /* empty attr */, 1 ); /* init_tm_stats calls process_count, which should * NOT be called from mod_init, because one does not * now, if a timer is used and thus how many processes * will be started; however we started already our * timers, so we know and process_count should not * change any more */ if (init_tm_stats()<0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } /* building the hash table*/ if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } /* register post-script clean-up function */ register_script_cb( w_t_unref, POST_SCRIPT_CB, 0 /* empty param */ ); register_script_cb( script_init, PRE_SCRIPT_CB , 0 /* empty param */ ); tm_init_tags(); return 0; }
static int mod_init(void) { DBG( "TM - (size of cell=%ld, sip_msg=%ld) initializing...\n", (long)sizeof(struct cell), (long)sizeof(struct sip_msg)); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LOG(L_CRIT, "Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } if (init_callid() < 0) { LOG(L_CRIT, "Error while initializing Call-ID generator\n"); return -1; } if (register_fifo_cmd(fifo_uac, "t_uac_dlg", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac\n"); return -1; } if (register_fifo_cmd(fifo_uac_cancel, "t_uac_cancel", 0) < 0) { LOG(L_CRIT, "cannot register fifo t_uac_cancel\n"); return -1; } if (register_fifo_cmd(fifo_hash, "t_hash", 0)<0) { LOG(L_CRIT, "cannot register hash\n"); return -1; } if (register_fifo_cmd(fifo_t_reply, "t_reply", 0)<0) { LOG(L_CRIT, "cannot register t_reply\n"); return -1; } if (unixsock_register_cmd("t_uac_dlg", unixsock_uac) < 0) { LOG(L_CRIT, "cannot register t_uac with the unix server\n"); return -1; } if (unixsock_register_cmd("t_uac_cancel", unixsock_uac_cancel) < 0) { LOG(L_CRIT, "cannot register t_uac_cancel with the unix server\n"); return -1; } if (unixsock_register_cmd("t_hash", unixsock_hash) < 0) { LOG(L_CRIT, "cannot register t_hash with the unix server\n"); return -1; } if (unixsock_register_cmd("t_reply", unixsock_t_reply) < 0) { LOG(L_CRIT, "cannot register t_reply with the unix server\n"); return -1; } /* building the hash table*/ if (!init_hash_table()) { LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers()) { LOG(L_ERR, "ERROR: mod_init: timer init failed\n"); return -1; } /* register the timer function */ register_timer( timer_routine , 0 /* empty attr */, 1 ); /* init_tm_stats calls process_count, which should * NOT be called from mod_init, because one does not * now, if a timer is used and thus how many processes * will be started; however we started already our * timers, so we know and process_count should not * change any more */ if (init_tm_stats()<0) { LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n"); return -1; } if (uac_init()==-1) { LOG(L_ERR, "ERROR: mod_init: uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LOG(L_CRIT, "ERROR:tm:mod_init: failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LOG(L_ERR, "ERROR:tm:mod_init: Unable to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; } if ( init_avp_params( fr_timer_param, fr_inv_timer_param)<0 ){ LOG(L_ERR,"ERROR:tm:mod_init: failed to process timer AVPs\n"); return -1; } if ( init_gf_mask( bf_mask_param )<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to process " "\"branch_flag_mask\" param\n"); return -1; } return 0; }