当前位置: 首页>>代码示例>>C++>>正文


C++ db_func_t::free_result方法代码示例

本文整理汇总了C++中db_func_t::free_result方法的典型用法代码示例。如果您正苦于以下问题:C++ db_func_t::free_result方法的具体用法?C++ db_func_t::free_result怎么用?C++ db_func_t::free_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db_func_t的用法示例。


在下文中一共展示了db_func_t::free_result方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: icscf_db_get_capabilities

/**
 *  Get the S-CSCF capabilities from the database and fill the S-CSCF set.
 * @param cap - array of scscf_capabilities to fill with capabilities
 * @returns 1 on success, 0 on error 
 */
int icscf_db_get_capabilities(scscf_capabilities *cap[],int cap_cnt)
{
//	db_key_t   keys_cmp[] = {"icscf"};
	db_key_t   keys_ret[] = {"id_s_cscf","capability"};
	db_key_t   key_ord = "id_s_cscf";
	db_res_t   * res = 0 ;	
	int i,j;
	int ccnt=0;
	int cnt;


	if (!icscf_db_check_init(hdl_capabilities))
		goto error;

	DBG("DBG:"M_NAME":icscf_db_get_capabilities: fetching list of Capabilities for I-CSCF\n");


	if (dbf.query(hdl_capabilities, 0, 0, 0, keys_ret, 0, 2, key_ord, & res) < 0) {
		LOG(L_ERR, "ERR:"M_NAME":icscf_db_get_capabilities: db_query failed\n");
		goto error;
	}

	if (res->n == 0) {
		DBG("DBG:"M_NAME":icscf_db_get_capabilities: No Capabilites found... not critical...\n");
		return 1;
	}
	else {
		for(i=0;i<cap_cnt;i++){
			cnt = 0;
			for(j=0;j<res->n;j++)
				if (res->rows[j].values[0].val.int_val == (*cap)[i].id_s_cscf)
					cnt++;
			(*cap)[i].capabilities = shm_malloc(sizeof(int)*cnt);
			if (!(*cap)[i].capabilities) {
				LOG(L_ERR,"ERR:"M_NAME":icscf_db_get_capabilities: Error allocating %d bytes\n",
					sizeof(int)*cnt);
				(*cap)[i].cnt=0;
					goto error;
			}			
			cnt=0;
			for(j=0;j<res->n;j++)
				if (res->rows[j].values[0].val.int_val == (*cap)[i].id_s_cscf) {
					(*cap)[i].capabilities[cnt++]=res->rows[j].values[1].val.int_val;
					ccnt++;
				}
			(*cap)[i].cnt=cnt;					
		}
			
	} 
	LOG(L_INFO, "INF:"M_NAME":icscf_db_get_capabilities: Loaded %d capabilities for %d S-CSCFs (%d invalid entries in db)\n",
		ccnt,cap_cnt,res->n-ccnt);
	dbf.free_result( hdl_capabilities, res);
	return 1;
	
error:
	if (res)
		dbf.free_result( hdl_capabilities, res);
	return 0;
}
开发者ID:asyn,项目名称:openvims,代码行数:64,代码来源:db.c

示例2: icscf_db_get_scscf

/**
 *  Get the S-CSCF names from the database and create the S-CSCF set.
 * @param cap - array of scscf_capabilities to fill with the db contents for the S-CSCF names
 * @returns 1 on success, 0 on error 
 */
int icscf_db_get_scscf(scscf_capabilities *cap[])
{
	db_key_t   keys_ret[] = {"id","s_cscf_uri"};
	db_key_t   key_ord = "id";
	db_res_t   * res = 0 ;	
	int i;

	*cap = 0;
		
	if (!icscf_db_check_init(hdl_scscf))
		goto error;

	DBG("DBG:"M_NAME":icscf_db_get_scscf: fetching S-CSCFs \n");

	if (dbf.query(hdl_scscf, 0, 0, 0, keys_ret, 0, 2, key_ord, & res) < 0) {
		LOG(L_ERR, "ERR:"M_NAME":icscf_db_get_scscf: db_query failed\n");
		goto error;
	}

	if (res->n == 0) {
		LOG(L_ERR,"ERR:"M_NAME":icscf_db_get_scscf:  no S-CSCFs found\n");
		goto error;
	}
	else {
		*cap = shm_malloc(sizeof(scscf_capabilities)*res->n);
		if (!(*cap)) {
			LOG(L_ERR,"ERR:"M_NAME":icscf_db_get_scscf: Error allocating %d bytes\n",
				sizeof(scscf_capabilities)*res->n);
			goto error;
		}
		memset((*cap),0,sizeof(scscf_capabilities)*res->n);
		for(i=0;i<res->n;i++){
			(*cap)[i].id_s_cscf = res->rows[i].values[0].val.int_val;
			(*cap)[i].scscf_name.len = strlen(res->rows[i].values[1].val.string_val);
			(*cap)[i].scscf_name.s = shm_malloc((*cap)[i].scscf_name.len);
			if (!(*cap)[i].scscf_name.s){
				LOG(L_ERR,"ERR:"M_NAME":icscf_db_get_scscf: Error allocating %d bytes\n",
					(*cap)[i].scscf_name.len);
				(*cap)[i].scscf_name.len=0;
				goto error;
			}
			memcpy((*cap)[i].scscf_name.s,res->rows[i].values[1].val.string_val,
				(*cap)[i].scscf_name.len);
		}
	}

	dbf.free_result( hdl_scscf, res);
	
	// return the size of scscf set  
	return i;
	
error:
	if (res)
		dbf.free_result( hdl_scscf, res);
	return 0;
}
开发者ID:asyn,项目名称:openvims,代码行数:61,代码来源:db.c

示例3: allow_trusted

/*
 * Checks based on given source IP address and protocol, and From URI
 * of request if request can be trusted without authentication.
 */
int allow_trusted(struct sip_msg* msg, char *src_ip, int proto) 
{
	int result;
	db1_res_t* res = NULL;
	
	db_key_t keys[1];
	db_val_t vals[1];
	db_key_t cols[4];

	if (db_mode == DISABLE_CACHE) {
		db_key_t order = &priority_col;
	
	        if (db_handle == 0) {
		    LM_ERR("no connection to database\n");
		    return -1;
	        }

		keys[0] = &source_col;
		cols[0] = &proto_col;
		cols[1] = &from_col;
		cols[2] = &ruri_col;
		cols[3] = &tag_col;

		if (perm_dbf.use_table(db_handle, &trusted_table) < 0) {
			LM_ERR("failed to use trusted table\n");
			return -1;
		}
		
		VAL_TYPE(vals) = DB1_STRING;
		VAL_NULL(vals) = 0;
		VAL_STRING(vals) = src_ip;

		if (perm_dbf.query(db_handle, keys, 0, vals, cols, 1, 4, order,
				   &res) < 0){
			LM_ERR("failed to query database\n");
			return -1;
		}

		if (RES_ROW_N(res) == 0) {
			perm_dbf.free_result(db_handle, res);
			return -1;
		}
		
		result = match_res(msg, proto, res);
		perm_dbf.free_result(db_handle, res);
		return result;
	} else {
		return match_hash_table(*hash_table, msg, src_ip, proto);
	}
}
开发者ID:AndreiPlesa,项目名称:kamailio,代码行数:54,代码来源:trusted.c

示例4: load_user_carrier

int load_user_carrier(str * user, str * domain) {
	db_res_t * res;
	db_key_t cols[1];
	db_key_t keys[2];
	db_val_t vals[2];
	db_op_t op[2];
	int id;
	if (!user || (use_domain && !domain)) {
		LM_ERR("NULL pointer in parameter\n");
		return -1;
	}

	cols[0] = subscriber_columns[SUBSCRIBER_CARRIER_COL];

	keys[0] = subscriber_columns[SUBSCRIBER_USERNAME_COL];
	op[0] = OP_EQ;
	vals[0].type = DB_STR;
	vals[0].nul = 0;
	vals[0].val.str_val = *user;

	keys[1] = subscriber_columns[SUBSCRIBER_DOMAIN_COL];
	op[1] = OP_EQ;
	vals[1].type = DB_STR;
	vals[1].nul = 0;
	vals[1].val.str_val = *domain;

	if (dbf.use_table(dbh, &subscriber_table) < 0) {
		LM_ERR("can't use table\n");
		return -1;
	}

	if (dbf.query(dbh, keys, op, vals, cols, use_domain ? 2 : 1, 1, NULL, &res) < 0) {
		LM_ERR("can't query database\n");
		return -1;
	}

	if (RES_ROW_N(res) == 0) {
		dbf.free_result(dbh, res);
		return 0;
	}

	if (VAL_NULL(ROW_VALUES(RES_ROWS(res)))) {
		dbf.free_result(dbh, res);
		return 0;
	}

	id = VAL_INT(ROW_VALUES(RES_ROWS(res)));
	dbf.free_result(dbh, res);
	return id;
}
开发者ID:Enigmedia,项目名称:opensips,代码行数:50,代码来源:route_db.c

示例5: does_uri_exist

/*
 * Check if uri belongs to a local user
 */
int does_uri_exist(struct sip_msg* _msg, char* _s1, char* _s2)
{
	static db_ps_t my_ps = NULL;
	db_key_t keys[2];
	db_val_t vals[2];
	db_key_t cols[1];
	db_res_t* res = NULL;

	if (parse_sip_msg_uri(_msg) < 0) {
		LM_ERR("Error while parsing URI\n");
		return ERR_INTERNAL;
	}

	if (use_uri_table != 0) {
		uridb_dbf.use_table(db_handle, &db_table);
		keys[0] = &uridb_uriuser_col;
		keys[1] = &uridb_domain_col;
		cols[0] = &uridb_uriuser_col;
	} else {
		uridb_dbf.use_table(db_handle, &db_table);
		keys[0] = &uridb_user_col;
		keys[1] = &uridb_domain_col;
		cols[0] = &uridb_user_col;
	}

	VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;
	VAL_NULL(vals) = VAL_NULL(vals + 1) = 0;
	VAL_STR(vals) = _msg->parsed_uri.user;
	VAL_STR(vals + 1) = _msg->parsed_uri.host;

	CON_PS_REFERENCE(db_handle) = &my_ps;

	if (uridb_dbf.query(db_handle, keys, 0, vals, cols, (use_domain ? 2 : 1),
				1, 0, &res) < 0) {
		LM_ERR("Error while querying database\n");
		return ERR_USERNOTFOUND;
	}

	if (RES_ROW_N(res) == 0) {
		LM_DBG("User in request uri does not exist\n");
		uridb_dbf.free_result(db_handle, res);
		return ERR_DBEMTPYRES;
	} else {
		LM_DBG("User in request uri does exist\n");
		uridb_dbf.free_result(db_handle, res);
		return OK;
	}
}
开发者ID:KISSMonX,项目名称:opensips,代码行数:51,代码来源:db_checks.c

示例6: is_domain_local

/*
 * Check if domain is local
 */
int is_domain_local(str* _host)
{
	if (db_mode == 0) {
		db_key_t keys[1];
		db_val_t vals[1];
		db_key_t cols[1]; 
		db_res_t* res;

		keys[0]=domain_col.s;
		cols[0]=domain_col.s;
		
		if (domain_dbf.use_table(db_handle, domain_table.s) < 0) {
			LOG(L_ERR, "is_local(): Error while trying to use domain table\n");
			return -1;
		}

		VAL_TYPE(vals) = DB_STR;
		VAL_NULL(vals) = 0;
		
		VAL_STR(vals).s = _host->s;
		VAL_STR(vals).len = _host->len;

		if (domain_dbf.query(db_handle, keys, 0, vals, cols, 1, 1, 0, &res) < 0
				) {
			LOG(L_ERR, "is_local(): Error while querying database\n");
			return -1;
		}

		if (RES_ROW_N(res) == 0) {
			DBG("is_local(): Realm '%.*s' is not local\n", 
			    _host->len, ZSW(_host->s));
			domain_dbf.free_result(db_handle, res);
			return -1;
		} else {
			DBG("is_local(): Realm '%.*s' is local\n", 
			    _host->len, ZSW(_host->s));
			domain_dbf.free_result(db_handle, res);
			return 1;
		}
	} else {
		return hash_table_lookup (_host);
	}
			
}
开发者ID:OPSF,项目名称:uClinux,代码行数:47,代码来源:domain.c

示例7: store_carriers

static int store_carriers(struct carrier ** start){
	db_res_t * res = NULL;
	int i;
	int count;
	struct carrier * nc;
	if(!start){
		LM_ERR("invalid parameter\n");
		return -1;
	}
	if (dbf.use_table(dbh, &carrier_table) < 0) {
		LM_ERR("couldn't use table\n");
		return -1;
	}

	if (dbf.query(dbh, 0, 0, 0, (db_key_t *)carrier_columns, 0, CARRIER_COLUMN_NUM, 0, &res) < 0) {
		LM_ERR("couldn't query table\n");
		return -1;
	}
	count = RES_ROW_N(res);
	for(i=0; i<RES_ROW_N(res); i++){
		if((nc = pkg_malloc(sizeof(struct carrier))) == NULL){
			LM_ERR("out of private memory\n");
			return -1;
		}
		nc->id = res->rows[i].values[0].val.int_val;
		if((nc->name = pkg_malloc(strlen(res->rows[i].values[1].val.string_val) + 1)) == NULL){
			LM_ERR("out of private memory\n");
			pkg_free(nc);
			goto errout;
		}
		strcpy(nc->name, res->rows[i].values[1].val.string_val);
		nc->next = *start;
		*start = nc;
	}
	dbf.free_result(dbh, res);
	return count;
errout:
if(res){
	dbf.free_result(dbh, res);
}
	return -1;
}
开发者ID:Enigmedia,项目名称:opensips,代码行数:42,代码来源:route_db.c

示例8: db_build_userbl_tree

/**
 * Builds a d-tree using database entries.
 * \return negative on failure, postive on success, indicating the number of d-tree entries
 */
int db_build_userbl_tree(const str *username, const str *domain, const str *table, struct dt_node_t *root, int use_domain)
{
	db_key_t columns[2] = { &prefix_col, &whitelist_col };
	db_key_t key[2] = { &username_key, &domain_key };

	db_val_t val[2];
	VAL_TYPE(val) = VAL_TYPE(val + 1) = DB_STR;
	VAL_NULL(val) = VAL_NULL(val + 1) = 0;
	VAL_STR(val).s = username->s;
	VAL_STR(val).len = username->len;
	VAL_STR(val + 1).s = domain->s;
	VAL_STR(val + 1).len = domain->len;

	db_res_t *res;
	int i;
	int n = 0;
	
	if (dbf.use_table(dbc, table) < 0) {
		LM_ERR("cannot use table '%.*s'.\n", table->len, table->s);
		return -1;
	}
	if (dbf.query(dbc, key, 0, val, columns, (!use_domain) ? (1) : (2), 2, 0, &res) < 0) {
		LM_ERR("error while executing query.\n");
		return -1;
	}

	dt_clear(root);

	if (RES_COL_N(res) > 1) {
		for(i = 0; i < RES_ROW_N(res); i++) {
			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
				if ((RES_ROWS(res)[i].values[0].type == DB_STRING) &&
					(RES_ROWS(res)[i].values[1].type == DB_INT)) {

					/* LM_DBG("insert into tree prefix %s, whitelist %d",
						RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val); */
					dt_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val);
					n++;
				}
				else {
					LM_ERR("got invalid result type from query.\n");
				}
			}
		}
	}
	dbf.free_result(dbc, res);

	return n;
}
开发者ID:UIKit0,项目名称:OpenSIPS,代码行数:55,代码来源:db.c

示例9: db_reload_source

/**
 * Rebuild d-tree using database entries
 * \return negative on failure, positive on success, indicating the number of d-tree entries
 */
int db_reload_source(const str *table, struct dt_node_t *root)
{
	db_key_t columns[2] = { &prefix_col, &whitelist_col };
	db_res_t *res;
	int i;
	int n = 0;
	
	if (dbf.use_table(dbc, table) < 0) {
		LM_ERR("cannot use table '%.*s'.\n", table->len, table->s);
		return -1;
	}
	if (dbf.query(dbc, NULL, NULL, NULL, columns, 0, 2, NULL, &res) < 0) {
		LM_ERR("error while executing query.\n");
		return -1;
	}

	dt_clear(root);

	if (RES_COL_N(res) > 1) {
		for(i = 0; i < RES_ROW_N(res); i++) {
			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
				if ((RES_ROWS(res)[i].values[0].type == DB_STRING) &&
					(RES_ROWS(res)[i].values[1].type == DB_INT)) {

					/* LM_DBG("insert into tree prefix %s, whitelist %d",
						RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val); */
					dt_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val);
					n++;
				}
				else {
					LM_ERR("got invalid result type from query.\n");
				}
			}
		}
	}
	dbf.free_result(dbc, res);

	return n;
}
开发者ID:UIKit0,项目名称:OpenSIPS,代码行数:45,代码来源:db.c

示例10: reload_trusted_table

/*
 * Reload trusted table to new hash table and when done, make new hash table
 * current one.
 */
int reload_trusted_table(void)
{
	db_key_t cols[6];
	db1_res_t* res = NULL;
	db_row_t* row;
	db_val_t* val;

	struct trusted_list **new_hash_table;
	struct trusted_list **old_hash_table;
	int i;
	int priority;

	char *pattern, *ruri_pattern, *tag;

	if (hash_table == 0) {
	    LM_ERR("in-memory hash table not initialized\n");
	    return -1;
	}

	if (db_handle == 0) {
	    LM_ERR("no connection to database\n");
	    return -1;
	}

	cols[0] = &source_col;
	cols[1] = &proto_col;
	cols[2] = &from_col;
	cols[3] = &ruri_col;
	cols[4] = &tag_col;
	cols[5] = &priority_col;

	if (perm_dbf.use_table(db_handle, &trusted_table) < 0) {
		LM_ERR("failed to use trusted table\n");
		return -1;
	}

	if (perm_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 6, 0, &res) < 0) {
		LM_ERR("failed to query database\n");
		return -1;
	}

	/* Choose new hash table and free its old contents */
	if (*hash_table == hash_table_1) {
		new_hash_table = hash_table_2;
	} else {
		new_hash_table = hash_table_1;
	}
	empty_hash_table(new_hash_table);

	row = RES_ROWS(res);

	LM_DBG("number of rows in trusted table: %d\n", RES_ROW_N(res));
		
	for (i = 0; i < RES_ROW_N(res); i++) {
	    val = ROW_VALUES(row + i);
	    if ((ROW_N(row + i) == 6) &&
		((VAL_TYPE(val) == DB1_STRING) || (VAL_TYPE(val) == DB1_STR) ) && 
		!VAL_NULL(val) &&
		((VAL_TYPE(val + 1) == DB1_STRING) || (VAL_TYPE(val + 1) == DB1_STR))
		&& !VAL_NULL(val + 1) &&
		(VAL_NULL(val + 2) ||
		 (((VAL_TYPE(val + 2) == DB1_STRING) || (VAL_TYPE(val + 2) == DB1_STR)) &&
		!VAL_NULL(val + 2))) && (VAL_NULL(val + 3) ||
		 (((VAL_TYPE(val + 3) == DB1_STRING) || (VAL_TYPE(val + 3) == DB1_STR) )&&
		!VAL_NULL(val + 3))) && (VAL_NULL(val + 4) ||
		 (((VAL_TYPE(val + 4) == DB1_STRING) || (VAL_TYPE(val + 4) == DB1_STR) )&&
		!VAL_NULL(val + 4)))) {
		if (VAL_NULL(val + 2)) {
		    pattern = 0;
		} else {
		    pattern = (char *)VAL_STRING(val + 2);
		}
		if (VAL_NULL(val + 3)) {
		    ruri_pattern = 0;
		} else {
		    ruri_pattern = (char *)VAL_STRING(val + 3);
		}
		if (VAL_NULL(val + 4)) {
		    tag = 0;
		} else {
		    tag = (char *)VAL_STRING(val + 4);
		}
		if (VAL_NULL(val + 5)) {
		    priority = 0;
		} else {
		    priority = (int)VAL_INT(val + 5);
		}
		if (hash_table_insert(new_hash_table,
				      (char *)VAL_STRING(val),
				      (char *)VAL_STRING(val + 1),
				      pattern, ruri_pattern, tag, priority) == -1) {
		    LM_ERR("hash table problem\n");
		    perm_dbf.free_result(db_handle, res);
		    empty_hash_table(new_hash_table);
		    return -1;
		}
//.........这里部分代码省略.........
开发者ID:AndreiPlesa,项目名称:kamailio,代码行数:101,代码来源:trusted.c

示例11: db_update


//.........这里部分代码省略.........

							q_vals[totag_col].val.str_val = p->to_tag;
							n_query_update++;

							q_vals[fromtag_col].val.str_val = p->from_tag;
							n_query_update++;
						}

						db_vals[0].val.int_val= p->expires;
						n_update_cols++;

						db_vals[1].val.int_val= p->cseq	;
						n_update_cols++;

						db_vals[2].val.str_val= p->etag	;
						n_update_cols++;

						db_vals[3].val.int_val= p->desired_expires;
						n_update_cols++;

						db_vals[4].val.int_val= p->version;
						n_update_cols++;

						LM_DBG("Updating:n_query_update= %d\tn_update_cols= %d\n",
								n_query_update, n_update_cols);

						if(pua_dbf.query(pua_db, q_cols, 0, q_vals,
									result_cols, n_query_update, 1, 0, &res)< 0)
						{
							LM_ERR("while querying db table pua\n");
							if(!no_lock)
								lock_release(&HashT->p_records[i].lock);
							if(res)
								pua_dbf.free_result(pua_db, res);	
							return ;
						}
						if(res && res->n> 0)
						{																				
							if(pua_dbf.update(pua_db, q_cols, 0, q_vals, db_cols, 
										db_vals, n_query_update, n_update_cols)<0)
							{
								LM_ERR("while updating in database\n");
								if(!no_lock)
									lock_release(&HashT->p_records[i].lock);	
								pua_dbf.free_result(pua_db, res);
								res= NULL;
								return ;
							}
							pua_dbf.free_result(pua_db, res);
							res= NULL;		
						}
						else
						{
							if(res)
							{	
								pua_dbf.free_result(pua_db, res);
								res= NULL;
							}
							LM_DBG("UPDATEDB_FLAG and no record found\n");
							//	p->db_flag= INSERTDB_FLAG;
						}	
						break;	
					}
				case INSERTDB_FLAG:
					{	
						LM_DBG("INSERTDB_FLAG\n");
开发者ID:kiryu,项目名称:kamailio,代码行数:67,代码来源:pua.c

示例12: db_restore

static int db_restore(void)
{
	ua_pres_t* p= NULL;
	db_key_t result_cols[19]; 
	db1_res_t *res= NULL;
	db_row_t *row = NULL;	
	db_val_t *row_vals= NULL;
	str pres_uri, pres_id;
	str etag, tuple_id;
	str watcher_uri, call_id;
	str to_tag, from_tag, remote_contact;
	str record_route, contact, extra_headers;
	int size= 0, i;
	int n_result_cols= 0;
	int puri_col,pid_col,expires_col,flag_col,etag_col, desired_expires_col;
	int watcher_col,callid_col,totag_col,fromtag_col,cseq_col,remote_contact_col;
	int event_col,contact_col,tuple_col,record_route_col, extra_headers_col;
	int version_col;

	if (dbmode==PUA_DB_ONLY)
	{
		LM_ERR( "db_restore shouldn't be called in PUA_DB_ONLY mode\n" );
		return(-1);
	}

	result_cols[puri_col=n_result_cols++]	= &str_pres_uri_col;
	result_cols[pid_col=n_result_cols++]	= &str_pres_id_col;
	result_cols[expires_col=n_result_cols++]= &str_expires_col;
	result_cols[flag_col=n_result_cols++]	= &str_flag_col;
	result_cols[etag_col=n_result_cols++]	= &str_etag_col;
	result_cols[tuple_col=n_result_cols++]	= &str_tuple_id_col;
	result_cols[watcher_col=n_result_cols++]= &str_watcher_uri_col;
	result_cols[callid_col=n_result_cols++] = &str_call_id_col;
	result_cols[totag_col=n_result_cols++]	= &str_to_tag_col;
	result_cols[fromtag_col=n_result_cols++]= &str_from_tag_col;
	result_cols[cseq_col= n_result_cols++]	= &str_cseq_col;
	result_cols[event_col= n_result_cols++]	= &str_event_col;
	result_cols[record_route_col= n_result_cols++]	= &str_record_route_col;
	result_cols[contact_col= n_result_cols++]	= &str_contact_col;
	result_cols[remote_contact_col= n_result_cols++]	= &str_remote_contact_col;
	result_cols[extra_headers_col= n_result_cols++]	= &str_extra_headers_col;
	result_cols[desired_expires_col= n_result_cols++]	= &str_desired_expires_col;
	result_cols[version_col= n_result_cols++]	= &str_version_col;

	if(!pua_db)
	{
		LM_ERR("null database connection\n");
		return -1;
	}

	if(pua_dbf.use_table(pua_db, &db_table)< 0)
	{
		LM_ERR("in use table\n");
		return -1;
	}

	if(db_fetch_query(&pua_dbf, pua_fetch_rows, pua_db, 0, 0, 0, result_cols,
				0, n_result_cols, 0, &res)< 0)
	{
		LM_ERR("while querrying table\n");
		if(res)
		{
			pua_dbf.free_result(pua_db, res);
			res = NULL;
		}
		return -1;
	}
	if(res==NULL)
		return -1;

	if(res->n<=0)
	{
		LM_INFO("the query returned no result\n");
		pua_dbf.free_result(pua_db, res);
		res = NULL;
		return 0;
	}

	do {
		LM_DBG("found %d db entries\n", res->n);

		for(i =0 ; i< res->n ; i++)
		{
			row = &res->rows[i];
			row_vals = ROW_VALUES(row);

			pres_uri.s= (char*)row_vals[puri_col].val.string_val;
			pres_uri.len = strlen(pres_uri.s);

			LM_DBG("pres_uri= %.*s\n", pres_uri.len, pres_uri.s);

			memset(&etag,			 0, sizeof(str));
			memset(&tuple_id,		 0, sizeof(str));
			memset(&watcher_uri,	 0, sizeof(str));
			memset(&call_id,		 0, sizeof(str));
			memset(&to_tag,			 0, sizeof(str));
			memset(&from_tag,		 0, sizeof(str));
			memset(&record_route,	 0, sizeof(str));
			memset(&pres_id,         0, sizeof(str));
			memset(&contact,         0, sizeof(str));
//.........这里部分代码省略.........
开发者ID:kiryu,项目名称:kamailio,代码行数:101,代码来源:pua.c

示例13: load_info


//.........这里部分代码省略.........
	}

	clusterer_cluster_id_key = pkg_realloc(clusterer_cluster_id_key,
		RES_ROW_N(res) * sizeof(db_key_t));
	if (!clusterer_cluster_id_key) {
		LM_ERR("no more pkg memory\n");
		goto error;
	}

	for (i = 0; i < RES_ROW_N(res); i++)
		clusterer_cluster_id_key[i] = &cluster_id_col;

	clusterer_cluster_id_value = pkg_realloc(clusterer_cluster_id_value,
		RES_ROW_N(res) * sizeof(db_val_t));

	if (!clusterer_cluster_id_value) {
		LM_ERR("no more pkg memory\n");
		goto error;
	}

	for (i = 0; i < RES_ROW_N(res); i++) {
		VAL_TYPE(clusterer_cluster_id_value + i) = DB_INT;
		VAL_NULL(clusterer_cluster_id_value + i) = 0;
	}

	for (i = 0; i < RES_ROW_N(res); i++) {
		row = RES_ROWS(res) + i;

		check_val(cluster_id_col, ROW_VALUES(row), DB_INT, 1, 0);
		VAL_INT(clusterer_cluster_id_value + i) = VAL_INT(ROW_VALUES(row));
	}

	no_of_results = RES_ROW_N(res);
	dr_dbf->free_result(db_hdl, res);
	res = 0;

	LM_DBG("DB query - retrieve valid connections\n");

	/* fetch is the best strategy */
	CON_USE_OR_OP(db_hdl);
	if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {

		if (dr_dbf->query(db_hdl, clusterer_cluster_id_key, 0,
			clusterer_cluster_id_value, columns, no_of_results, db_cols, 0, 0) < 0) {
			LM_ERR("DB query failed - retrieve valid connections \n");
			goto error;
		}
		no_rows = estimate_available_rows(4 + 4 + 4 + 64 + 4 + 45 + 4 + 8 + 4 + 4, db_cols);
		if (no_rows == 0) no_rows = 5;
		if (dr_dbf->fetch_result(db_hdl, &res, no_rows) < 0) {
			LM_ERR("Error fetching rows\n");
			goto error;
		}
	} else {
		if (dr_dbf->query(db_hdl, clusterer_cluster_id_key, 0,
			clusterer_cluster_id_value, columns, no_of_results, db_cols, 0, &res) < 0) {
			LM_ERR("DB query failed - retrieve valid connections\n");
			goto error;
		}
	}

	LM_DBG("%d rows found in %.*s\n",
		RES_ROW_N(res), db_table->len, db_table->s);

	n = 0;
	do {
开发者ID:Danfx,项目名称:opensips,代码行数:67,代码来源:clusterer.c

示例14: alias_db_query


//.........这里部分代码省略.........
	if(adbf.query( db_handle, db_keys, NULL, db_vals, db_cols,
			(flags&ALIAS_DOMAIN_FLAG)?2:1 /*no keys*/, 2 /*no cols*/,
			NULL, &db_res)!=0 || db_res==NULL)
	{
		LM_ERR("failed to query database\n");
		goto err_server;
	}

	if (RES_ROW_N(db_res)<=0 || RES_ROWS(db_res)[0].values[0].nul != 0)
	{
		LM_DBG("no alias found for R-URI\n");
		goto err_server;
	}

	memcpy(useruri_buf, "sip:", 4);
	for(i=0; i<RES_ROW_N(db_res); i++)
	{
		user_s.len = 4;
		user_s.s = useruri_buf+4;
		switch(RES_ROWS(db_res)[i].values[0].type)
		{ 
			case DB1_STRING:
				strcpy(user_s.s, 
					(char*)RES_ROWS(db_res)[i].values[0].val.string_val);
				user_s.len += strlen(user_s.s);
			break;
			case DB1_STR:
				strncpy(user_s.s, 
					(char*)RES_ROWS(db_res)[i].values[0].val.str_val.s,
					RES_ROWS(db_res)[i].values[0].val.str_val.len);
				user_s.len += RES_ROWS(db_res)[i].values[0].val.str_val.len;
			break;
			case DB1_BLOB:
				strncpy(user_s.s, 
					(char*)RES_ROWS(db_res)[i].values[0].val.blob_val.s,
					RES_ROWS(db_res)[i].values[0].val.blob_val.len);
				user_s.len += RES_ROWS(db_res)[i].values[0].val.blob_val.len;
			break;
			default:
				LM_ERR("unknown type of DB user column\n");
				goto err_server;
		}
	
		/* add the @*/
		useruri_buf[user_s.len] = '@';
		user_s.len++;
	
		/* add the domain */
		user_s.s = useruri_buf+user_s.len;
		switch(RES_ROWS(db_res)[i].values[1].type)
		{ 
			case DB1_STRING:
				strcpy(user_s.s, 
					(char*)RES_ROWS(db_res)[i].values[1].val.string_val);
				user_s.len += strlen(user_s.s);
			break;
			case DB1_STR:
				strncpy(user_s.s, 
					(char*)RES_ROWS(db_res)[i].values[1].val.str_val.s,
					RES_ROWS(db_res)[i].values[1].val.str_val.len);
				user_s.len += RES_ROWS(db_res)[i].values[1].val.str_val.len;
				useruri_buf[user_s.len] = '\0';
			break;
			case DB1_BLOB:
				strncpy(user_s.s, 
					(char*)RES_ROWS(db_res)[i].values[1].val.blob_val.s,
					RES_ROWS(db_res)[i].values[1].val.blob_val.len);
				user_s.len += RES_ROWS(db_res)[i].values[1].val.blob_val.len;
				useruri_buf[user_s.len] = '\0';
			break;
			default:
				LM_ERR("unknown type of DB user column\n");
				goto err_server;
		}
		user_s.s = useruri_buf;
		/* set the URI */
		LM_DBG("new URI [%d] is [%.*s]\n", i, user_s.len ,user_s.s );
		if (set_alias(_msg, &user_s, i, param)!=0) {
			LM_ERR("error while setting alias\n");
			goto err_server;
		}
	}

	/**
	 * Free the DB result
	 */
	if (adbf.free_result(db_handle, db_res) < 0) {
		LM_DBG("failed to freeing result of query\n");
	}

	return 1;

err_server:
	if (db_res!=NULL) {
		if(adbf.free_result(db_handle, db_res) < 0) {
			LM_DBG("failed to freeing result of query\n");
		}
	}
	return -1;
}
开发者ID:GreenfieldTech,项目名称:kamailio,代码行数:101,代码来源:alookup.c

示例15: update_pw_dialogs_dbonlymode

static int update_pw_dialogs_dbonlymode(subs_t* subs, subs_t** subs_array)
{
	db_key_t query_cols[5], db_cols[3];
	db_val_t query_vals[5], db_vals[3];
	db_key_t result_cols[24];
	int n_query_cols=0, n_result_cols=0, n_update_cols=0;
	int event_col, pres_uri_col, watcher_user_col, watcher_domain_col;
	int r_pres_uri_col,r_to_user_col,r_to_domain_col;
	int r_from_user_col,r_from_domain_col,r_callid_col;
	int r_to_tag_col,r_from_tag_col,r_sockinfo_col;
	int r_event_id_col,r_local_contact_col,r_contact_col;
	int r_record_route_col, r_reason_col;
	int r_event_col, r_local_cseq_col, r_remote_cseq_col;
	int r_status_col, r_version_col;
	int r_expires_col, r_watcher_user_col, r_watcher_domain_col;
	db1_res_t *result= NULL;
 	db_val_t *row_vals;
	db_row_t *rows;
	int nr_rows, loop;
	subs_t s, *cs;
	str ev_sname;

	if(pa_db == NULL)
	{
		LM_ERR("null database connection\n");
		return(-1);
	}

	if (pa_dbf.use_table(pa_db, &active_watchers_table) < 0) 
	{
		LM_ERR("use table failed\n");
		return(-1);
	}

	query_cols[event_col=n_query_cols]= &str_event_col;
	query_vals[event_col].nul= 0;
	query_vals[event_col].type= DB1_STR;
	query_vals[event_col].val.str_val= subs->event->name ;
	n_query_cols++;

	query_cols[pres_uri_col=n_query_cols]= &str_presentity_uri_col;
	query_vals[pres_uri_col].nul= 0;
	query_vals[pres_uri_col].type= DB1_STR;
	query_vals[pres_uri_col].val.str_val= subs->pres_uri;
	n_query_cols++;

	query_cols[watcher_user_col=n_query_cols]= &str_watcher_username_col;
	query_vals[watcher_user_col].nul= 0;
	query_vals[watcher_user_col].type= DB1_STR;
	query_vals[watcher_user_col].val.str_val= subs->watcher_user;
	n_query_cols++;

	query_cols[watcher_domain_col=n_query_cols]= &str_watcher_domain_col;
	query_vals[watcher_domain_col].nul= 0;
	query_vals[watcher_domain_col].type= DB1_STR;
	query_vals[watcher_domain_col].val.str_val= subs->watcher_domain;
	n_query_cols++;


	result_cols[r_to_user_col=n_result_cols++] = &str_to_user_col;
	result_cols[r_to_domain_col=n_result_cols++] = &str_to_domain_col;
	result_cols[r_from_user_col=n_result_cols++] = &str_from_user_col;
	result_cols[r_from_domain_col=n_result_cols++] = &str_from_domain_col;
	result_cols[r_watcher_user_col=n_result_cols++] = &str_watcher_username_col;
	result_cols[r_watcher_domain_col=n_result_cols++] = &str_watcher_domain_col;
	result_cols[r_callid_col=n_result_cols++] = &str_callid_col;
	result_cols[r_to_tag_col=n_result_cols++] = &str_to_tag_col;
	result_cols[r_from_tag_col=n_result_cols++] = &str_from_tag_col;
	result_cols[r_sockinfo_col=n_result_cols++] = &str_socket_info_col;
	result_cols[r_event_id_col=n_result_cols++] = &str_event_id_col;
	result_cols[r_local_contact_col=n_result_cols++] = &str_local_contact_col;
	result_cols[r_record_route_col=n_result_cols++] = &str_record_route_col;
	result_cols[r_reason_col=n_result_cols++] = &str_reason_col;
	result_cols[r_local_cseq_col=n_result_cols++] = &str_local_cseq_col;
	result_cols[r_version_col=n_result_cols++] = &str_version_col;
	result_cols[r_expires_col=n_result_cols++] = &str_expires_col;
	result_cols[r_event_col=n_result_cols++] = &str_event_col;
	result_cols[r_pres_uri_col=n_result_cols++] = &str_presentity_uri_col;
	result_cols[r_contact_col=n_result_cols++] = &str_contact_col;

	/* these ones are unused for some reason !!! */
	result_cols[r_remote_cseq_col=n_result_cols++] = &str_remote_cseq_col;
	result_cols[r_status_col=n_result_cols++] = &str_status_col;
	/*********************************************/

	if(pa_dbf.query(pa_db, query_cols, 0, query_vals, result_cols, 
				n_query_cols, n_result_cols, 0, &result )< 0)
	{
		LM_ERR("Can't query db\n");
		if(result) pa_dbf.free_result(pa_db, result);
		return(-1);
	}

	if(result == NULL) return(-1);

	nr_rows = RES_ROW_N(result);

	LM_DBG("found %d matching dialogs\n", nr_rows);

	if (nr_rows <= 0)
//.........这里部分代码省略.........
开发者ID:AlessioCasco,项目名称:kamailio,代码行数:101,代码来源:presence.c


注:本文中的db_func_t::free_result方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。