Beispiel #1
0
mi_response_t *refreshXcapDoc(const mi_params_t *params,
								struct mi_handler *async_hdl)
{
	str doc_url;
	xcap_doc_sel_t doc_sel;
	char* serv_addr;
	str stream= {0, 0};
	int type;
	int xcap_port;
	char* etag= NULL;

	if (get_mi_string_param(params, "doc_uri", &doc_url.s, &doc_url.len) < 0)
		return init_mi_param_error();

	if(doc_url.s == NULL || doc_url.len== 0)
	{
		LM_ERR("empty uri\n");
		return init_mi_error(404, MI_SSTR("Empty document URL"));
	}

	if (get_mi_int_param(params, "port", &xcap_port) < 0)
		return init_mi_param_error();

	/* send GET HTTP request to the server */
	stream.s = send_http_get(doc_url.s, xcap_port, NULL, 0, &etag, &stream.len);
	if(stream.s== NULL)
	{
		LM_ERR("in http get\n");
		return 0;
	}

	/* call registered functions with document argument */
	if(parse_doc_url(doc_url, &serv_addr, &doc_sel)< 0)
	{
		LM_ERR("parsing document url\n");
		return 0;
	}

	type = xcap_doc_type(&doc_sel.auid);
	if (type < 0)
	{
		LM_ERR("incorect auid: %.*s\n",
				doc_sel.auid.len, doc_sel.auid.s);
		goto error;
	}

	run_xcap_update_cb(type, doc_sel.xid, stream.s);
	pkg_free(stream.s);

	return init_mi_result_ok();

error:
	if(stream.s)
		pkg_free(stream.s);
	return 0;
}
Beispiel #2
0
/*
 * rpc cmd: refreshXcapDoc
 *			<document uri>
 *			<xcap_port>
 * */
void xcap_client_rpc_refreshXcapDoc(rpc_t* rpc, void* ctx)
{
	str doc_url;
	xcap_doc_sel_t doc_sel;
	char* serv_addr;
	char* stream= NULL;
	int type;
	unsigned int xcap_port;
	char* etag= NULL;

	if(rpc->scan(ctx, "S", &doc_url, (int*)(&xcap_port))<1) {
		LM_WARN("not enough parameters\n");
		rpc->fault(ctx, 500, "Not enough parameters");
		return;
	}
	/* send GET HTTP request to the server */
	stream=	send_http_get(doc_url.s, xcap_port, NULL, 0, &etag);
	if(stream== NULL) {
		LM_ERR("in http get\n");
		rpc->fault(ctx, 500, "Failed http get");
		return;
	}

	/* call registered functions with document argument */
	if(parse_doc_url(doc_url, &serv_addr, &doc_sel)< 0) {
		LM_ERR("parsing document url\n");
		if(stream) pkg_free(stream);
		rpc->fault(ctx, 500, "Failed parsing url");
		return;
	}

	type= get_auid_flag(doc_sel.auid);
	if(type<0) {
		LM_ERR("incorrect auid: %.*s\n",
				doc_sel.auid.len, doc_sel.auid.s);
		if(stream) pkg_free(stream);
		rpc->fault(ctx, 500, "Invalid auid");
		return;
	}

	run_xcap_update_cb(type, doc_sel.xid, stream);
	if(stream) pkg_free(stream);
}
Beispiel #3
0
struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param)
{
	struct mi_node* node= NULL;
	str doc_url;
	xcap_doc_sel_t doc_sel;
	char* serv_addr;
	char* stream= NULL;
	int type;
	unsigned int xcap_port;
	char* etag= NULL;

	node = cmd->node.kids;
	if(node == NULL)
		return 0;

	doc_url = node->value;
	if(doc_url.s == NULL || doc_url.len== 0)
	{
		LM_ERR("empty uri\n");
		return init_mi_tree(404, "Empty document URL", 20);
	}
	node= node->next;
	if(node== NULL)
		return 0;
	if(node->value.s== NULL || node->value.len== 0)
	{
		LM_ERR("port number\n");
		return init_mi_tree(404, "Empty document URL", 20);
	}
	if(str2int(&node->value, &xcap_port)< 0)
	{
		LM_ERR("while converting string to int\n");
		goto error;
	}

	if(node->next!= NULL)
		return 0;

	/* send GET HTTP request to the server */
	stream=	send_http_get(doc_url.s, xcap_port, NULL, 0, &etag);
	if(stream== NULL)
	{
		LM_ERR("in http get\n");
		return 0;
	}
	
	/* call registered functions with document argument */
	if(parse_doc_url(doc_url, &serv_addr, &doc_sel)< 0)
	{
		LM_ERR("parsing document url\n");
		return 0;
	}

	type= get_auid_flag(doc_sel.auid);
	if(type< 0)
	{
		LM_ERR("incorect auid: %.*s\n",
				doc_sel.auid.len, doc_sel.auid.s);
		goto error;
	}

	run_xcap_update_cb(type, doc_sel.xid, stream);

	return init_mi_tree(200, "OK", 2);

error:
	if(stream)
		pkg_free(stream);
	return 0;
}
Beispiel #4
0
void query_xcap_update(unsigned int ticks, void* param)
{
	db_key_t query_cols[3], update_cols[3];
	db_val_t query_vals[3], update_vals[3];
	db_key_t result_cols[7];
	int n_result_cols = 0, n_query_cols= 0, n_update_cols= 0;
	db_res_t* result= NULL;
	int user_col, domain_col, doc_type_col, etag_col, doc_uri_col, port_col; 
	db_row_t *row ;	
	db_val_t *row_vals ;
	unsigned int port;
	char* etag, *path, *new_etag= NULL, *doc= NULL;
	int u_doc_col, u_etag_col;
	str user, domain, uri;
	int i;

	/* query the ones I have to handle */
	query_cols[n_query_cols] = "source";
	query_vals[n_query_cols].type = DB_INT;
	query_vals[n_query_cols].nul = 0;
	query_vals[n_query_cols].val.int_val= XCAP_CL_MOD;
	n_query_cols++;

	query_cols[n_query_cols] = "path";
	query_vals[n_query_cols].type = DB_STR;
	query_vals[n_query_cols].nul = 0;

	update_cols[u_doc_col=n_update_cols] = "doc";
	update_vals[n_update_cols].type = DB_STRING;
	update_vals[n_update_cols].nul = 0;
	n_update_cols++;

	update_cols[u_etag_col=n_update_cols] = "etag";
	update_vals[n_update_cols].type = DB_STRING;
	update_vals[n_update_cols].nul = 0;
	n_update_cols++;

	result_cols[user_col= n_result_cols++]     = "username";
	result_cols[domain_col=n_result_cols++]    = "domain";
	result_cols[doc_type_col=n_result_cols++]  = "doc_type";
	result_cols[etag_col=n_result_cols++]      = "etag";
	result_cols[doc_uri_col= n_result_cols++]  = "doc_uri";
	result_cols[port_col= n_result_cols++]     = "port";
	
	if (xcap_dbf.use_table(xcap_db, xcap_db_table) < 0) 
	{
		LM_ERR("in use_table-[table]= %s\n", xcap_db_table);
		goto error;
	}

	if(xcap_dbf.query(xcap_db, query_cols, 0, query_vals, result_cols, 1,
				n_result_cols, 0, &result)< 0)
	{
		LM_ERR("in sql query\n");
		goto error;
	}
	if(result== NULL)
	{
		LM_ERR("in sql query- null result\n");
		return;
	}
	if(result->n<= 0)
	{
		xcap_dbf.free_result(xcap_db, result);
		return;
	}
	n_query_cols++;
	
	/* ask if updated */
	for(i= 0; i< result->n; i++)
	{
		row = &result->rows[i];
		row_vals = ROW_VALUES(row);
	
		path= (char*)row_vals[doc_uri_col].val.string_val;
		port= row_vals[port_col].val.int_val;
		etag= (char*)row_vals[etag_col].val.string_val;	

		user.s= (char*)row_vals[user_col].val.string_val;
		user.len= strlen(user.s);

		domain.s= (char*)row_vals[domain_col].val.string_val;
		domain.len= strlen(domain.s);

		/* send HTTP request */
		doc= send_http_get(path, port, etag, IF_NONE_MATCH, &new_etag);
		if(doc== NULL)
		{
			LM_DBG("document not update\n");
			continue;
		}
		if(new_etag== NULL)
		{
			LM_ERR("etag not found\n");
			pkg_free(doc);
			goto error;
		}
		/* update in xcap db table */
		update_vals[u_doc_col].val.string_val= doc;
		update_vals[u_etag_col].val.string_val= etag;
		
		if(xcap_dbf.update(xcap_db, query_cols, 0, query_vals, update_cols,
					update_vals, n_query_cols, n_update_cols)< 0)
		{
			LM_ERR("in sql update\n");
			pkg_free(doc);
			goto error;
		}
		/* call registered callbacks */
		if(uandd_to_uri(user, domain, &uri)< 0)
		{
			LM_ERR("converting user and domain to uri\n");
			pkg_free(doc);
			goto error;
		}
		run_xcap_update_cb(row_vals[doc_type_col].val.int_val, uri, doc);
		pkg_free(doc);

	}

	xcap_dbf.free_result(xcap_db, result);
	return;

error:
	if(result)
		xcap_dbf.free_result(xcap_db, result);
}