/** * init module function */ static int mod_init(void) { if (load_tm_api( &tmb ) == -1) { LM_ERR("cannot load the TM-functions. Missing TM module?\n"); return -1; } if(async_workers<=0) return 0; if(async_init_timer_list()<0) { LM_ERR("cannot initialize internal structure\n"); return -1; } register_dummy_timers(async_workers); return 0; }
static int sca_mod_init(void) { sca = (sca_mod *) shm_malloc(sizeof(sca_mod)); if (sca == NULL) { LM_ERR("Failed to shm_malloc module object\n"); return (-1); } memset(sca, 0, sizeof(sca_mod)); if (sca_set_config(sca) != 0) { LM_ERR("Failed to set configuration\n"); goto error; } if (rpc_register_array(sca_rpc) != 0) { LM_ERR("Failed to register RPC commands\n"); goto error; } if (sca_bind_srdb1(sca, &dbf) != 0) { LM_ERR("Failed to initialize required DB API\n"); goto error; } if (load_tm_api(&tmb) != 0) { LM_ERR("Failed to initialize required tm API. Check that the \"tm\" module is loaded before this module.\n"); goto error; } sca->tm_api = &tmb; if (sca_bind_sl(sca, &slb) != 0) { LM_ERR("Failed to initialize required sl API. Check that the \"sl\" module is loaded before this module.\n"); goto error; } if (sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size) != 0) { LM_ERR("Failed to create subscriptions hash table\n"); goto error; } if (sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size) != 0) { LM_ERR("Failed to create appearances hash table\n"); goto error; } sca_subscriptions_restore_from_db(sca); register_timer(sca_subscription_purge_expired, sca, sca->cfg->purge_expired_interval); register_timer(sca_appearance_purge_stale, sca, sca->cfg->purge_expired_interval); // register separate timer process to write subscriptions to DB. // move to 3.3+ timer API (register_basic_timer) at some point. // timer process forks in sca_child_init, above. register_dummy_timers(1); LM_INFO("SCA initialized \n"); return (0); error: if (sca != NULL) { if (sca->cfg != NULL) { shm_free(sca->cfg); } if (sca->subscriptions != NULL) { sca_hash_table_free(sca->subscriptions); } if (sca->appearances != NULL) { sca_hash_table_free(sca->appearances); } shm_free(sca); sca = NULL; } return (-1); }