Example #1
0
static int mod_init(void)
{
	LM_DBG("Initializing...\n");

	connection_timeout_ms = connection_timeout * 1000L;

	if (connect_poll_interval < 0) {
		LM_ERR("Bad connect_poll_interval (%ldms), setting to 20ms\n",
		       connect_poll_interval);
		connect_poll_interval = 20;
	}

	if (connection_timeout > curl_timeout) {
		LM_WARN("'connection_timeout' must be less than or equal "
		        "to 'curl_timeout'! setting it to %ld...\n", curl_timeout);
		connection_timeout = curl_timeout;
	}

	lock_init(&thread_lock);

	curl_global_init_mem(CURL_GLOBAL_ALL,
						 osips_malloc,
						 osips_free,
						 osips_realloc,
						 osips_strdup,
						 osips_calloc);

	INIT_LIST_HEAD(&multi_pool);

	/* try loading the trace api */
	if (register_trace_type) {
		rest_proto_id = register_trace_type(rest_id_s);
		if ( global_trace_api ) {
			memcpy(&tprot, global_trace_api, sizeof tprot);
		} else {
			memset(&tprot, 0, sizeof tprot);
			if (trace_prot_bind( REST_TRACE_API_MODULE, &tprot))
				LM_DBG("Can't bind <%s>!\n", REST_TRACE_API_MODULE);
		}
	} else {
		memset(&tprot, 0, sizeof tprot);
	}

	if (is_script_func_used("rest_init_client_tls", -1)) {
		if (load_tls_mgm_api(&tls_api) != 0) {
			LM_ERR("failed to load the tls_mgm API! "
			       "Is the tls_mgm module loaded?\n");
			return -1;
		}
	}

	if (!validate_curl_http_version(&curl_http_version))
		return -1;

	LM_INFO("Module initialized!\n");

	return 0;
}
Example #2
0
static int cfg_validate(void)
{
	/* if the 'uac_auth' func is used, be sure the uac_auth API was loaded */
	if ( is_script_func_used("uac_auth", -1) ) {
		if (uac_auth_api._do_uac_auth==NULL) {
			LM_ERR("uac_auth() was found, but module started without support "
				"for it, better restart\n");
			return 0;
		}
	}

	/* if the 'uac_replace_*' funcs are used, be sure the support for
	 * replacing was initialized */
	if ( is_script_func_used("uac_replace_from", -1) ||
	is_script_func_used("uac_replace_to", -1) ) {
		if (!uac_does_replace) {
			LM_ERR("uac_replace_*() was found, but module started without "
				"support for replacing, better restart\n");
			return 0;
		}
	}

	return 1;
}
Example #3
0
static int mod_init(void)
{
	LM_INFO("initializing...\n");
	int rr_api_loaded=0;

	if ( is_script_func_used("uac_auth", -1) ) {
		/* load the UAC_AUTH API as uac_auth() is invoked from script */
		if(load_uac_auth_api(&uac_auth_api)<0){
			LM_ERR("can't load UAC_AUTH API, needed for uac_auth()\n");
			goto error;
		}
	}

	/* load the TM API - FIXME it should be loaded only
	 * if NO_RESTORE and AUTH */
	if (load_tm_api(&uac_tmb)!=0) {
		LM_ERR("can't load TM API\n");
		goto error;
	}

	if (restore_mode_str && *restore_mode_str) {
		if (strcasecmp(restore_mode_str,"none")==0) {
			restore_mode = UAC_NO_RESTORE;
		} else if (strcasecmp(restore_mode_str,"manual")==0) {
			restore_mode = UAC_MANUAL_RESTORE;
		} else if (strcasecmp(restore_mode_str,"auto")==0) {
			restore_mode = UAC_AUTO_RESTORE;
		} else {
			LM_ERR("unsupported value '%s' for restore_mode\n",
				restore_mode_str);
			goto error;
		}
	}

	if ( is_script_func_used("uac_replace_from", -1) ||
	is_script_func_used("uac_replace_to", -1) ) {

		/* replace TO/FROM stuff is used, get prepared */

		rr_from_param.len = strlen(rr_from_param.s);
		rr_to_param.len = strlen(rr_to_param.s);
		if ( (rr_from_param.len==0 || rr_to_param.len==0) &&
		restore_mode!=UAC_NO_RESTORE) {
			LM_ERR("rr_store_param cannot be empty if FROM is restoreable\n");
			goto error;
		}

		uac_passwd.len = strlen(uac_passwd.s);

		if (restore_mode!=UAC_NO_RESTORE) {
			/* load the RR API */
			if (load_rr_api(&uac_rrb)!=0) {
				LM_ERR("can't load RR API\n");
				goto error;
			}
			rr_api_loaded=1;

			if (restore_mode==UAC_AUTO_RESTORE) {
				/* we need the append_fromtag on in RR */
				if (!force_dialog && !uac_rrb.append_fromtag) {
					LM_ERR("'append_fromtag' RR param is not enabled!"
						" - required by AUTO restore mode\n");
					goto error;
				}

				/* trying to load dialog module */
				memset(&dlg_api, 0, sizeof(struct dlg_binds));
				if (load_dlg_api(&dlg_api)!=0) {
					if (force_dialog) {
						LM_ERR("cannot force dialog. dialog module not loaded\n");
						goto error;
					}
					LM_DBG("failed to find dialog API - is dialog module loaded?\n");
				} else {
					if ( (parse_store_bavp(&store_to_bavp, &to_bavp_spec) ||
					parse_store_bavp(&store_from_bavp, &from_bavp_spec))) {
						LM_ERR("cannot set correct store parameters\n");
						goto error;
					}
					/* install calback to catch all loaded dialogs */
					if ( dlg_api.register_dlgcb( NULL, DLGCB_LOADED,
					dlg_restore_callback, NULL, NULL) != 0 ) {
						LM_ERR("failed to install dialog restore callback\n");
						goto error;
					}
				}

				/* get all requests doing loose route */
				if (uac_rrb.register_rrcb( rr_checker, 0, 2)!=0) {
					LM_ERR("failed to install RR callback\n");
					goto error;
				}
			}
		}

		/* init from replacer */
		init_from_replacer();
	}

	if (is_script_func_used("uac_auth", -1)) {
		if (!rr_api_loaded) {
			if (load_rr_api(&uac_rrb)!=0) {
				LM_ERR("can't load RR API\n");
				goto error;
			}
		}
		if (!uac_rrb.append_fromtag) {
			LM_ERR("'append_fromtag' RR param is not enabled!"
			" - required by uac_auth() restore mode\n");
			goto error;
		}

		if (uac_rrb.register_rrcb( rr_uac_auth_checker, 0, 2)!=0) {
			LM_ERR("failed to install RR callback\n");
			goto error;
		}
	}

	return 0;
error:
	return -1;
}
Example #4
0
static int avpops_init(void)
{
	int i;

	LM_INFO("initializing...\n");

	if (db_table.s)
		db_table.len = strlen(db_table.s);
	uuid_col.len = strlen(uuid_col.s);
	attribute_col.len = strlen(attribute_col.s);
	value_col.len = strlen(value_col.s);
	type_col.len = strlen(type_col.s);
	username_col.len = strlen(username_col.s);
	domain_col.len = strlen(domain_col.s);

	/* search if any avp_db_* function is used */
	for (i=0; cmds[i].name != NULL; i++) {
		if (strncasecmp(cmds[i].name, AVPDB, sizeof(AVPDB)-1) == 0 &&
				(is_script_func_used(cmds[i].name, cmds[i].param_no))) {
			need_db=1;
		}
	}

	for (i=0; acmds[i].name != NULL; i++) {
		if (strncasecmp(acmds[i].name, AVPDB, sizeof(AVPDB)-1) == 0 &&
				(is_script_async_func_used(acmds[i].name, acmds[i].param_no))) {
			need_db=1;
		}
	}

	if (need_db) {
		default_db_url = get_default_db_url();
		if (default_db_url==NULL) {
			if (db_default_url==NULL) {
				LM_ERR("no DB URL provision into the module!\n");
				return -1;
			}
			/* if nothing explicitly set as DB URL, add automatically
			 * the default DB URL */
			if (add_db_url(STR_PARAM, db_default_url)!=0) {
				LM_ERR("failed to use the default DB URL!\n");
				return -1;
			}
			default_db_url = get_default_db_url();
			if (default_db_url==NULL) {
				LM_BUG("Really ?!\n");
				return -1;
			}
		}

		/* bind to the DB module */
		if (avpops_db_bind()<0)
			goto error;

		init_store_avps(db_columns);
	}

	printbuf = (char*)pkg_malloc((buf_size+1)*sizeof(char));
	if(printbuf==NULL) {
		LM_ERR("no pkg memory left\n");
		return -1;
	}

	return 0;
error:
	return -1;
}