static int mod_init(void) { LM_INFO("Load-Balancer module - initializing\n"); init_db_url( db_url , 0 /*cannot be null*/); /* Load dialog API */ if (load_dlg_api(&lb_dlg_binds) != 0) { LM_ERR("Can't load dialog hooks\n"); return -1; } if (fetch_freeswitch_stats) { if (load_fs_api(&fs_api) == -1) { LM_ERR("failed to load the FS API!\n"); return -1; } } /* data pointer in shm */ curr_data = (struct lb_data**)shm_malloc( sizeof(struct lb_data*) ); if (curr_data==0) { LM_CRIT("failed to get shm mem for data ptr\n"); return -1; } *curr_data = 0; /* create & init lock */ if ((ref_lock = lock_init_rw()) == NULL) { LM_CRIT("failed to init lock\n"); return -1; } if (init_lb_bls()) { LM_ERR("BL INIT failed\n"); return -1; } /* init and open DB connection */ if (init_lb_db(&db_url, table_name)!=0) { LM_ERR("failed to initialize the DB support\n"); return -1; } /* load data */ if ( lb_reload_data()!=0 ) { LM_CRIT("failed to load load-balancing data\n"); return -1; } /* close DB connection */ lb_close_db(); /* arm a function for probing */ if (lb_prob_interval) { /* load TM API */ if (load_tm_api(&lb_tmb)!=0) { LM_ERR("can't load TM API\n"); return -1; } /* probing method */ lb_probe_method.len = strlen(lb_probe_method.s); lb_probe_from.len = strlen(lb_probe_from.s); if (lb_probe_replies.s) lb_probe_replies.len = strlen(lb_probe_replies.s); /* register pinger function */ if (register_timer( "lb-pinger", lb_prob_handler , NULL, lb_prob_interval, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register probing handler\n"); return -1; } /* Register the max load recalculation timer */ if (fetch_freeswitch_stats && register_timer("lb-update-max-load", lb_update_max_loads, NULL, fs_api.stats_update_interval, TIMER_FLAG_SKIP_ON_DELAY)<0) { LM_ERR("failed to register timer for max load recalc!\n"); return -1; } if (lb_probe_replies.s) { lb_probe_replies.len = strlen(lb_probe_replies.s); if(parse_reply_codes( &lb_probe_replies, &probing_reply_codes, &probing_codes_no )< 0) { LM_ERR("Bad format for options_reply_code parameter" " - Need a code list separated by commas\n"); return -1; } } } /* parse avps */ if (parse_avp_spec(&group_avp_name_s, &group_avp_name)) { LM_ERR("cannot parse group avp\n"); return -1; } if (parse_avp_spec(&flags_avp_name_s, &flags_avp_name)) { LM_ERR("cannot parse flags avp\n"); return -1; } if (parse_avp_spec(&mask_avp_name_s, &mask_avp_name)) { LM_ERR("cannot parse mask avp\n"); return -1; } if (parse_avp_spec(&id_avp_name_s, &id_avp_name)) { LM_ERR("cannot parse id avp\n"); return -1; } if (parse_avp_spec(&res_avp_name_s, &res_avp_name)) { LM_ERR("cannot parse resources avp\n"); return -1; } if (lb_init_event() < 0) { LM_ERR("cannot init event\n"); return -1; } if (lb_repl_cluster < 0) { LM_ERR("Invalid replication_cluster, must be 0 or " "a positive cluster id\n"); return -1; } if (lb_repl_cluster && load_clusterer_api(&clusterer_api)!=0) { LM_DBG("failed to find clusterer API - is clusterer module loaded?\n"); return -1; } /* register handler for processing load_balancer replication packets to the clusterer module */ if (lb_repl_cluster > 0 && clusterer_api.register_capability(&status_repl_cap, receive_lb_binary_packet, NULL, lb_repl_cluster, 0, NODE_CMP_ANY) < 0) { LM_ERR("cannot register binary packet callback to clusterer module!\n"); return -1; } return 0; }
static int mod_init(void) { LM_INFO("Load-Balancer module - initializing\n"); init_db_url( db_url , 0 /*cannot be null*/); /* Load dialog API */ if (load_dlg_api(&lb_dlg_binds) != 0) { LM_ERR("Can't load dialog hooks"); return -1; } /* data pointer in shm */ curr_data = (struct lb_data**)shm_malloc( sizeof(struct lb_data*) ); if (curr_data==0) { LM_CRIT("failed to get shm mem for data ptr\n"); return -1; } *curr_data = 0; /* create & init lock */ if ((ref_lock = lock_init_rw()) == NULL) { LM_CRIT("failed to init lock\n"); return -1; } if (init_lb_bls()) { LM_ERR("BL INIT failed\n"); return -1; } /* init and open DB connection */ if (init_lb_db(&db_url, table_name)!=0) { LM_ERR("failed to initialize the DB support\n"); return -1; } /* load data */ if ( lb_reload_data()!=0 ) { LM_CRIT("failed to load load-balancing data\n"); return -1; } /* close DB connection */ lb_close_db(); /* arm a function for probing */ if (lb_prob_interval) { /* load TM API */ if (load_tm_api(&lb_tmb)!=0) { LM_ERR("can't load TM API\n"); return -1; } /* probing method */ lb_probe_method.len = strlen(lb_probe_method.s); lb_probe_from.len = strlen(lb_probe_from.s); if (lb_probe_replies.s) lb_probe_replies.len = strlen(lb_probe_replies.s); /* register pinger function */ if (register_timer( "lb-pinger", lb_prob_handler , NULL, lb_prob_interval)<0) { LM_ERR("failed to register probing handler\n"); return -1; } if (lb_probe_replies.s) { lb_probe_replies.len = strlen(lb_probe_replies.s); if(parse_reply_codes( &lb_probe_replies, &probing_reply_codes, &probing_codes_no )< 0) { LM_ERR("Bad format for options_reply_code parameter" " - Need a code list separated by commas\n"); return -1; } } } /* parse avps */ if (parse_avp_spec(&grp_avp_name_s, &grp_avp_name)) { LM_ERR("cannot parse group avp\n"); return -1; } if (parse_avp_spec(&mask_avp_name_s, &mask_avp_name)) { LM_ERR("cannot parse mask avp\n"); return -1; } if (parse_avp_spec(&id_avp_name_s, &id_avp_name)) { LM_ERR("cannot parse id avp\n"); return -1; } return 0; }