コード例 #1
0
ファイル: flatstore.c プロジェクト: OpenSIPS/opensips
/*
 * Initialize database module
 * No function should be called before this
 */
db_con_t* flat_db_init(const str* url)
{
	db_con_t* res;
	str* path;

	if (!url || !url->s) {
		LM_ERR("invalid parameter value\n");
		return 0;
	}

	/* We do not know the name of the table (and the name of the corresponding
	 * file) at this point, we will simply store the path taken from the url
	 * parameter in the table variable, flat_use_table will then pick that
	 * value and open the file
	 */
	/* as the table (path) is a substring of the received str, we need to
	 * allocate a separate str struct for it -bogdan
	 */
	res = pkg_malloc(sizeof(db_con_t)+sizeof(struct flat_con*)+sizeof(str));
	if (!res) {
		LM_ERR("no pkg memory left\n");
		return 0;
	}
	memset(res, 0, sizeof(db_con_t) + sizeof(struct flat_con*) + sizeof(str));
	path = (str*)(((char*)res) + sizeof(db_con_t) + sizeof(struct flat_con*));

	if (parse_flat_url(url, path) < 0) {
		pkg_free(res);
		return 0;
	}
	res->table = path;

	return res;
}
コード例 #2
0
/*
 * Initialize database module
 * No function should be called before this
 */
db_con_t* flat_db_init(const char* url)
{
	db_con_t* res;

	if (!url) {
		LOG(L_ERR, "flat_db_init: Invalid parameter value\n");
		return 0;
	}

	     /* We do not know the name of the table (and the name of the corresponding file)
	      * at this point, we will simply store the path taken from url parameter in the
	      * table variable, flat_use_table will then pick that value and open file
	      */
	res = pkg_malloc(sizeof(db_con_t) + sizeof(struct flat_con*));
	if (!res) {
		LOG(L_ERR, "flat_db_init: No memory left\n");
		return 0;
	}
	memset(res, 0, sizeof(db_con_t) + sizeof(struct flat_con*));

	if (parse_flat_url(url, &res->table) < 0) {
		pkg_free(res);
		return 0;
	}

	return res;
}