示例#1
0
文件: mi.c 项目: UIKit0/OpenSIPS
/*
 * MI function to reload domain table
 */
struct mi_root* mi_domain_reload(struct mi_root *cmd_tree, void *param)
{
	if(db_mode==0)
		return init_mi_tree( 500, "command not activated", 21);

	if (reload_domain_table () == 1) {
		return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
	} else {
		return init_mi_tree( 500, "Domain table reload failed", 26);
	}
}
示例#2
0
static int mod_init(void)
{
	int i, ver;

	DBG("domain - initializing\n");
	
	db_url.len = strlen(db_url.s);
	domain_table.len = strlen(domain_table.s);
	domain_col.len = strlen(domain_col.s);

	/* Check if database module has been loaded */
	if (domain_db_bind(db_url.s)<0)  return -1;

	/* Check if cache needs to be loaded from domain table */
	if (db_mode != 0) {
		if (domain_db_init(db_url.s)<0) return -1;
		     /* Check table version */
		ver = domain_db_ver(&domain_table);
		if (ver < 0) {
			LOG(L_ERR, "ERROR: domain:mod_init(): "
					"error while querying table version\n");
			domain_db_close();
			return -1;
		} else if (ver < TABLE_VERSION) {
			LOG(L_ERR, "ERROR: domain:mod_init(): invalid table"
					" version (use ser_mysql.sh reinstall)\n");
			domain_db_close();
			return -1;
		}		

		/* Initialize fifo interface */
		(void)init_domain_fifo();

		if (init_domain_unixsock() < 0) {
			LOG(L_ERR, "ERROR: domain:mod_init(): error while initializing"
					" unix socket interface\n");
			domain_db_close();
			return -1;
		}

		/* Initializing hash tables and hash table variable */
		hash_table_1 = (struct domain_list **)shm_malloc(sizeof(struct domain_list *) * HASH_SIZE);
		if (hash_table_1 == 0) {
			LOG(L_ERR, "ERROR: domain: mod_init(): "
					"No memory for hash table\n");
		}

		hash_table_2 = (struct domain_list **)shm_malloc(sizeof(struct domain_list *) * HASH_SIZE);
		if (hash_table_2 == 0) {
			LOG(L_ERR, "ERROR: domain: mod_init():"
					" No memory for hash table\n");
		}
		for (i = 0; i < HASH_SIZE; i++) {
			hash_table_1[i] = hash_table_2[i] = (struct domain_list *)0;
		}

		hash_table = (struct domain_list ***)shm_malloc(sizeof(struct domain_list *));
		*hash_table = hash_table_1;

		if (reload_domain_table() == -1) {
			LOG(L_CRIT, "ERROR: domain:mod_init():"
					" Domain table reload failed\n");
			return -1;
		}
			
		domain_db_close();
	}

	return 0;
}
示例#3
0
static int mod_init(void)
{
	int i;

	LM_DBG("Initializing\n");

	init_db_url( db_url , 0 /*cannot be null*/);
	domain_table.len = strlen(domain_table.s);
	domain_col.len = strlen(domain_col.s);
	domain_attrs_col.len = strlen(domain_attrs_col.s);

	/* Check if database module has been loaded */
	if (domain_db_bind(&db_url) < 0)  return -1;

	/* Check if cache needs to be loaded from domain table */
	if (db_mode != 0) {

		if (domain_db_init(&db_url)<0) return -1;

		/* Check table version */
		if (domain_db_ver(&domain_table, TABLE_VERSION) < 0) {
		    LM_ERR("error during check of domain table version\n");
		    goto error;
		}

		/* Initializing hash tables and hash table variable */
		hash_table_1 = (struct domain_list **)shm_malloc
			(sizeof(struct domain_list *) * DOM_HASH_SIZE);
		if (hash_table_1 == 0) {
			LM_ERR("No memory for hash table\n");
			goto error;
		}

		hash_table_2 = (struct domain_list **)shm_malloc
			(sizeof(struct domain_list *) * DOM_HASH_SIZE);
		if (hash_table_2 == 0) {
			LM_ERR("No memory for hash table\n");
			goto error;
		}
		for (i = 0; i < DOM_HASH_SIZE; i++) {
			hash_table_1[i] = hash_table_2[i] = (struct domain_list *)0;
		}

		hash_table = (struct domain_list ***)shm_malloc
			(sizeof(struct domain_list *));
		*hash_table = hash_table_1;

		if (reload_domain_table() == -1) {
			LM_ERR("Domain table reload failed\n");
			goto error;
		}

		domain_db_close();
	}

	/* register the alias check function to core */
	if (register_alias_fct(is_domain_alias)!=0) {
		LM_ERR("failed to register the alias check function\n");
		goto error;
	}

	return 0;
error:
	domain_db_close();
	return -1;
}