コード例 #1
0
ファイル: my_con.c プロジェクト: BackupTheBerlios/ser
int my_con(db_con_t* con)
{
	struct my_con* ptr;
	struct my_uri* uri;

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	ptr = (struct my_con*)db_pool_get(con->uri);
	if (ptr) {
		DBG("mysql: Connection to %.*s:%.*s found in connection pool\n",
			con->uri->scheme.len, ZSW(con->uri->scheme.s),
			con->uri->body.len, ZSW(con->uri->body.s));
		goto found;
	}

	ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
	if (!ptr) {
		LOG(L_ERR, "mysql: No memory left\n");
		goto error;
	}
	memset(ptr, '\0', sizeof(struct my_con));
	if (db_pool_entry_init(&ptr->gen, my_con_free, con->uri) < 0) goto error;

	ptr->con = (MYSQL*)pkg_malloc(sizeof(MYSQL));
	if (!ptr->con) {
		LOG(L_ERR, "mysql: No enough memory\n");
		goto error;
	}
	mysql_init(ptr->con);

	uri = DB_GET_PAYLOAD(con->uri);
	DBG("mysql: Creating new connection to: %.*s:%.*s\n",
		con->uri->scheme.len, ZSW(con->uri->scheme.s),
		con->uri->body.len, ZSW(con->uri->body.s));

	/* Put the newly created mysql connection into the pool */
	db_pool_put((struct db_pool_entry*)ptr);
	DBG("mysql: Connection stored in connection pool\n");

 found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, ptr);
	con->connect = my_con_connect;
	con->disconnect = my_con_disconnect;
	return 0;

 error:
	if (ptr) {
		db_pool_entry_free(&ptr->gen);
		if (ptr->con) pkg_free(ptr->con);
		pkg_free(ptr);
	}
	return 0;
}
コード例 #2
0
ファイル: bdb_con.c プロジェクト: 4N7HR4X/kamailio
int bdb_con(db_con_t* con)
{
	bdb_con_t* bcon;
	bdb_uri_t* buri;

	buri = DB_GET_PAYLOAD(con->uri);

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	bcon = (bdb_con_t*)db_pool_get(con->uri);
	if (bcon) {
		DBG("bdb: Connection to %s found in connection pool\n",
			buri->uri);
		goto found;
	}

	bcon = (bdb_con_t*)pkg_malloc(sizeof(bdb_con_t));
	if (!bcon) {
		ERR("bdb: No memory left\n");
		goto error;
	}
	memset(bcon, '\0', sizeof(bdb_con_t));
	if (db_pool_entry_init(&bcon->gen, bdb_con_free, con->uri) < 0) goto error;

	DBG("bdb: Preparing new connection to %s\n", buri->uri);
	if(bdb_is_database(buri->path.s)!=0)
	{	
		ERR("bdb: database [%.*s] does not exists!\n",
				buri->path.len, buri->path.s);
		goto error;
	}

	/* Put the newly created BDB connection into the pool */
	db_pool_put((struct db_pool_entry*)bcon);
	DBG("bdb: Connection stored in connection pool\n");

found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, bcon);
	con->connect = bdb_con_connect;
	con->disconnect = bdb_con_disconnect;
	return 0;

error:
	if (bcon) {
		db_pool_entry_free(&bcon->gen);
		pkg_free(bcon);
	}
	return -1;
}
コード例 #3
0
ファイル: pg_con.c プロジェクト: GreenfieldTech/kamailio
int pg_con(db_con_t *con)
{
	struct pg_con *pcon;

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	pcon = (struct pg_con *)db_pool_get(con->uri);
	if(pcon) {
		DBG("postgres: Connection to %.*s:%.*s found in connection pool\n",
				con->uri->scheme.len, ZSW(con->uri->scheme.s),
				con->uri->body.len, ZSW(con->uri->body.s));
		goto found;
	}

	pcon = (struct pg_con *)pkg_malloc(sizeof(struct pg_con));
	if(!pcon) {
		LOG(L_ERR, "postgres: No memory left\n");
		goto error;
	}
	memset(pcon, '\0', sizeof(struct pg_con));
	if(db_pool_entry_init(&pcon->gen, pg_con_free, con->uri) < 0)
		goto error;

	DBG("postgres: Preparing new connection to: %.*s:%.*s\n",
			con->uri->scheme.len, ZSW(con->uri->scheme.s), con->uri->body.len,
			ZSW(con->uri->body.s));

	/* Put the newly created postgres connection into the pool */
	db_pool_put((struct db_pool_entry *)pcon);
	DBG("postgres: Connection stored in connection pool\n");

found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, pcon);
	con->connect = pg_con_connect;
	con->disconnect = pg_con_disconnect;
	return 0;

error:
	if(pcon) {
		db_pool_entry_free(&pcon->gen);
		pkg_free(pcon);
	}
	return -1;
}
コード例 #4
0
ファイル: ld_con.c プロジェクト: 2pac/kamailio
int ld_con(db_con_t* con)
{
	struct ld_con* lcon;
	struct ld_uri* luri;

	luri = DB_GET_PAYLOAD(con->uri);

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	lcon = (struct ld_con*)db_pool_get(con->uri);
	if (lcon) {
		DBG("ldap: Connection to %s found in connection pool\n",
			luri->uri);
		goto found;
	}

	lcon = (struct ld_con*)pkg_malloc(sizeof(struct ld_con));
	if (!lcon) {
		ERR("ldap: No memory left\n");
		goto error;
	}
	memset(lcon, '\0', sizeof(struct ld_con));
	if (db_pool_entry_init(&lcon->gen, ld_con_free, con->uri) < 0) goto error;

	DBG("ldap: Preparing new connection to %s\n", luri->uri);

	/* Put the newly created LDAP connection into the pool */
	db_pool_put((struct db_pool_entry*)lcon);
	DBG("ldap: Connection stored in connection pool\n");

 found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, lcon);
	con->connect = ld_con_connect;
	con->disconnect = ld_con_disconnect;
	return 0;

 error:
	if (lcon) {
		db_pool_entry_free(&lcon->gen);
		pkg_free(lcon);
	}
	return -1;
}