瀏覽代碼

- changed parameters of XCAP queries in PA, RLS and libs
- changed processing of nested resource list (more efficient)

Vaclav Kubart 19 年之前
父節點
當前提交
5bb441231d
共有 8 個文件被更改,包括 105 次插入102 次删除
  1. 7 12
      lib/xcap/pres_rules.c
  2. 1 1
      lib/xcap/pres_rules.h
  3. 42 70
      lib/xcap/resource_list.c
  4. 3 3
      lib/xcap/resource_list.h
  5. 1 1
      lib/xcap/test_pres_rules.c
  6. 1 1
      lib/xcap/test_rls.c
  7. 44 10
      lib/xcap/xcap_client.c
  8. 6 4
      lib/xcap/xcap_client.h

+ 7 - 12
lib/xcap/pres_rules.c

@@ -60,27 +60,22 @@ char *xcap_uri_for_pres_rules(const char *xcap_root, const str_t *uri)
 	return dst;
 	return dst;
 }
 }
 
 
-int get_pres_rules(const char *xcap_root, const str_t *uri, xcap_query_t *xcap_params, cp_ruleset_t **dst)
+int get_pres_rules(const char *xcap_root, const str_t *uri, xcap_query_params_t *xcap_params, cp_ruleset_t **dst)
 {
 {
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
-	xcap_query_t xcap;
+	char *xcap_uri;
 	int res = RES_OK;
 	int res = RES_OK;
 	
 	
-	if (xcap_params) {
-		xcap = *xcap_params;
-	}
-	else memset(&xcap, 0, sizeof(xcap));
-	
-	xcap.uri = xcap_uri_for_pres_rules(xcap_root, uri);
-	res = xcap_query(&xcap, &data, &dsize);
+	xcap_uri = xcap_uri_for_pres_rules(xcap_root, uri);
+	res = xcap_query(xcap_uri, xcap_params, &data, &dsize);
 	if (res != RES_OK) {
 	if (res != RES_OK) {
-		DEBUG_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+		DEBUG_LOG("XCAP problems for uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
 		if (data) cds_free(data);
 		if (data) cds_free(data);
-		if (xcap.uri) cds_free(xcap.uri);
+		if (xcap_uri) cds_free(xcap_uri);
 		return RES_XCAP_QUERY_ERR;
 		return RES_XCAP_QUERY_ERR;
 	}
 	}
-	if (xcap.uri) cds_free(xcap.uri);
+	if (xcap_uri) cds_free(xcap_uri);
 	
 	
 	/* parse input data */
 	/* parse input data */
 	res = parse_pres_rules(data, dsize, dst);
 	res = parse_pres_rules(data, dsize, dst);

+ 1 - 1
lib/xcap/pres_rules.h

@@ -41,7 +41,7 @@ typedef enum {
 } sub_handling_t;
 } sub_handling_t;
 
 
 char *xcap_uri_for_pres_rules(const char *xcap_root, const str_t *uri);
 char *xcap_uri_for_pres_rules(const char *xcap_root, const str_t *uri);
-int get_pres_rules(const char *xcap_root, const str_t *uri, xcap_query_t *xcap_params, cp_ruleset_t **dst);
+int get_pres_rules(const char *xcap_root, const str_t *uri, xcap_query_params_t *xcap_params, cp_ruleset_t **dst);
 void free_pres_rules(cp_ruleset_t *r);
 void free_pres_rules(cp_ruleset_t *r);
 void free_rule(cp_rule_t *r);
 void free_rule(cp_rule_t *r);
 
 

+ 42 - 70
lib/xcap/resource_list.c

@@ -46,7 +46,7 @@ typedef struct _traversed_list_t {
 
 
 typedef struct {
 typedef struct {
 	const str_t *xcap_root;
 	const str_t *xcap_root;
-	xcap_query_t *xcap_params;
+	xcap_query_params_t *xcap_params;
 	traversed_list_t *traversed;
 	traversed_list_t *traversed;
 	traversed_list_t *traversed_last;
 	traversed_list_t *traversed_last;
 	flat_list_t *flat;
 	flat_list_t *flat;
@@ -282,7 +282,7 @@ static int process_entry_ref(entry_ref_t *entry_ref, process_params_t *params)
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
 	entry_t *entry = NULL;
 	entry_t *entry = NULL;
-	xcap_query_t xcap;
+	char *xcap_uri;
 	int res;
 	int res;
 	
 	
 	/* DEBUG_LOG("processing entry-ref with ref \'%s\'\n", STR_OK(entry_ref->ref)); */
 	/* DEBUG_LOG("processing entry-ref with ref \'%s\'\n", STR_OK(entry_ref->ref)); */
@@ -297,19 +297,15 @@ static int process_entry_ref(entry_ref_t *entry_ref, process_params_t *params)
 	}
 	}
 
 
 	/* XCAP query for the ref uri */
 	/* XCAP query for the ref uri */
-	if (params->xcap_params) {
-		xcap = *params->xcap_params;
-	}
-	else memset(&xcap, 0, sizeof(xcap));
-	xcap.uri = relative2absolute_uri(params->xcap_root, entry_ref->ref);
-	res = xcap_query(&xcap, &data, &dsize);
+	xcap_uri = relative2absolute_uri(params->xcap_root, entry_ref->ref);
+	res = xcap_query(xcap_uri, params->xcap_params, &data, &dsize);
 	if (res != 0) {
 	if (res != 0) {
-		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
 		if (data) cds_free(data);
 		if (data) cds_free(data);
-		if (xcap.uri) cds_free(xcap.uri);
+		if (xcap_uri) cds_free(xcap_uri);
 		return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
 		return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
 	}
 	}
-	if (xcap.uri) cds_free(xcap.uri);
+	if (xcap_uri) cds_free(xcap_uri);
 
 
 	/* parse document as an entry element */
 	/* parse document as an entry element */
 	if (parse_entry_xml(data, dsize, &entry) != 0) {
 	if (parse_entry_xml(data, dsize, &entry) != 0) {
@@ -331,7 +327,6 @@ static int process_external(external_t *external, process_params_t *params)
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
 	list_t *list = NULL;
 	list_t *list = NULL;
-	xcap_query_t xcap;
 	int res;
 	int res;
 	
 	
 	/* DEBUG_LOG("processing external with anchor \'%s\'\n", STR_OK(external->anchor)); */
 	/* DEBUG_LOG("processing external with anchor \'%s\'\n", STR_OK(external->anchor)); */
@@ -346,14 +341,9 @@ static int process_external(external_t *external, process_params_t *params)
 	}
 	}
 
 
 	/* XCAP query for the ref uri */
 	/* XCAP query for the ref uri */
-	if (params->xcap_params) {
-		xcap = *params->xcap_params;
-	}
-	else memset(&xcap, 0, sizeof(xcap));
-	xcap.uri = external->anchor;
-	res = xcap_query(&xcap, &data, &dsize);
+	res = xcap_query(external->anchor, params->xcap_params, &data, &dsize);
 	if (res != 0) {
 	if (res != 0) {
-		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+		ERROR_LOG("XCAP problems for uri \'%s\'\n", external->anchor ? external->anchor: "???");
 		if (data) cds_free(data);
 		if (data) cds_free(data);
 		return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
 		return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
 	}
 	}
@@ -411,17 +401,13 @@ static int process_resource_list(const char *rl_uri, process_params_t *params)
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
 	int res = 0;
 	int res = 0;
-	xcap_query_t xcap;
 	list_t *list = NULL;
 	list_t *list = NULL;
 
 
 	/* DEBUG_LOG("processing resource list\n"); */
 	/* DEBUG_LOG("processing resource list\n"); */
 
 
 	/* do an xcap query */
 	/* do an xcap query */
-	if (params->xcap_params) xcap = *params->xcap_params;
-	else memset(&xcap, 0, sizeof(xcap));
-	xcap.uri = (char*)rl_uri;
-	if (xcap_query(&xcap, &data, &dsize) != 0) {
-		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+	if (xcap_query(rl_uri, params->xcap_params, &data, &dsize) != 0) {
+		ERROR_LOG("XCAP problems for uri \'%s\'\n", rl_uri ? rl_uri: "???");
 		if (data) cds_free(data);
 		if (data) cds_free(data);
 		return RES_BAD_GATEWAY_ERR; /* -> 502 Bad GW */
 		return RES_BAD_GATEWAY_ERR; /* -> 502 Bad GW */
 	}
 	}
@@ -444,7 +430,7 @@ static int process_resource_list(const char *rl_uri, process_params_t *params)
 	return res;
 	return res;
 }
 }
 
 
-static int create_flat_list(service_t *srv, xcap_query_t *xcap_params, const str_t *xcap_root, flat_list_t **dst)
+static int create_flat_list(service_t *srv, xcap_query_params_t *xcap_params, const str_t *xcap_root, flat_list_t **dst)
 {
 {
 	process_params_t params;
 	process_params_t params;
 	int res = -1;
 	int res = -1;
@@ -532,35 +518,30 @@ static service_t *find_service(rls_services_t *rls, const str_t *uri)
 
 
 /* ------- rls examining ------- */
 /* ------- rls examining ------- */
 
 
-int get_rls(const str_t *xcap_root, const str_t *uri, xcap_query_t *xcap_params, const str_t *package, flat_list_t **dst)
+int get_rls(const str_t *xcap_root, const str_t *uri, xcap_query_params_t *xcap_params, const str_t *package, flat_list_t **dst)
 {
 {
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
 	service_t *service = NULL;
 	service_t *service = NULL;
-	xcap_query_t xcap;
+	char *xcap_uri;
 	int res;
 	int res;
 
 
 	if (!dst) return RES_INTERNAL_ERR;
 	if (!dst) return RES_INTERNAL_ERR;
 	
 	
-	if (xcap_params) {
-		xcap = *xcap_params;
-	}
-	else memset(&xcap, 0, sizeof(xcap));
-
 	/* get basic document */
 	/* get basic document */
-	xcap.uri = xcap_uri_for_rls_resource(xcap_root, uri);
-	/* DEBUG_LOG("XCAP uri \'%s\'\n", xcap.uri ? xcap.uri: "???"); */
-	res = xcap_query(&xcap, &data, &dsize);
+	xcap_uri = xcap_uri_for_rls_resource(xcap_root, uri);
+	/* DEBUG_LOG("XCAP uri \'%s\'\n", xcap_uri ? xcap_uri: "???"); */
+	res = xcap_query(xcap_uri, xcap_params, &data, &dsize);
 	if (res != 0) {
 	if (res != 0) {
-		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
 		if (data) {
 		if (data) {
 			cds_free(data);
 			cds_free(data);
 		}
 		}
-		if (xcap.uri) cds_free(xcap.uri);
+		if (xcap_uri) cds_free(xcap_uri);
 		return RES_XCAP_QUERY_ERR;
 		return RES_XCAP_QUERY_ERR;
 	}
 	}
-	if (xcap.uri) cds_free(xcap.uri);
-	xcap.uri = NULL;
+	if (xcap_uri) cds_free(xcap_uri);
+	xcap_uri = NULL;
 	
 	
 	/* parse document as a service element in rls-sources */
 	/* parse document as a service element in rls-sources */
 	if (parse_service(data, dsize, &service) != 0) {
 	if (parse_service(data, dsize, &service) != 0) {
@@ -586,7 +567,7 @@ int get_rls(const str_t *xcap_root, const str_t *uri, xcap_query_t *xcap_params,
 	}
 	}
 	
 	
 	/* create flat document */
 	/* create flat document */
-	res = create_flat_list(service, &xcap, xcap_root, dst);
+	res = create_flat_list(service, xcap_params, xcap_root, dst);
 	if (res != RES_OK) {
 	if (res != RES_OK) {
 		ERROR_LOG("Flat list creation error\n");
 		ERROR_LOG("Flat list creation error\n");
 		free_service(service);
 		free_service(service);
@@ -599,37 +580,33 @@ int get_rls(const str_t *xcap_root, const str_t *uri, xcap_query_t *xcap_params,
 	return RES_OK;
 	return RES_OK;
 }
 }
 
 
-int get_rls_from_full_doc(const str_t *xcap_root, const str_t *uri, xcap_query_t *xcap_params, const str_t *package, flat_list_t **dst)
+int get_rls_from_full_doc(const str_t *xcap_root, const str_t *uri, xcap_query_params_t *xcap_params, const str_t *package, flat_list_t **dst)
 {
 {
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
 	rls_services_t *rls = NULL;
 	rls_services_t *rls = NULL;
 	service_t *service = NULL;
 	service_t *service = NULL;
-	xcap_query_t xcap;
 	str_t curi;
 	str_t curi;
 	int res;
 	int res;
+	char *xcap_uri;
 
 
 	if (!dst) return RES_INTERNAL_ERR;
 	if (!dst) return RES_INTERNAL_ERR;
 	
 	
-	if (xcap_params) {
-		xcap = *xcap_params;
-	}
-	else memset(&xcap, 0, sizeof(xcap));
 
 
 	/* get basic document */
 	/* get basic document */
-	xcap.uri = xcap_uri_for_rls_services(xcap_root);
-	DEBUG_LOG("XCAP uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
-	res = xcap_query(&xcap, &data, &dsize);
+	xcap_uri = xcap_uri_for_rls_services(xcap_root);
+	DEBUG_LOG("XCAP uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
+	res = xcap_query(xcap_uri, xcap_params, &data, &dsize);
 	if (res != 0) {
 	if (res != 0) {
-		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
 		if (data) {
 		if (data) {
 			cds_free(data);
 			cds_free(data);
 		}
 		}
-		if (xcap.uri) cds_free(xcap.uri);
+		if (xcap_uri) cds_free(xcap_uri);
 		return RES_XCAP_QUERY_ERR;
 		return RES_XCAP_QUERY_ERR;
 	}
 	}
-	if (xcap.uri) cds_free(xcap.uri);
-	xcap.uri = NULL;
+	if (xcap_uri) cds_free(xcap_uri);
+	xcap_uri = NULL;
 	
 	
 	/* parse document as a service element in rls-sources */
 	/* parse document as a service element in rls-sources */
 	if (parse_rls_services_xml(data, dsize, &rls) != 0) {
 	if (parse_rls_services_xml(data, dsize, &rls) != 0) {
@@ -661,7 +638,7 @@ int get_rls_from_full_doc(const str_t *xcap_root, const str_t *uri, xcap_query_t
 	}
 	}
 	
 	
 	/* create flat document */
 	/* create flat document */
-	res = create_flat_list(service, &xcap, xcap_root, dst);
+	res = create_flat_list(service, xcap_params, xcap_root, dst);
 	if (res != RES_OK) {
 	if (res != RES_OK) {
 		ERROR_LOG("Flat list creation error\n");
 		ERROR_LOG("Flat list creation error\n");
 		free_rls_services(rls);
 		free_rls_services(rls);
@@ -726,37 +703,32 @@ static list_t *find_list(list_t *root, const char *name)
 
 
 /* catches and processes user's resource list as rls-services document */
 /* catches and processes user's resource list as rls-services document */
 int get_resource_list_from_full_doc(const str_t *xcap_root, 
 int get_resource_list_from_full_doc(const str_t *xcap_root, 
-		const str_t *user, xcap_query_t *xcap_params, 
+		const str_t *user, xcap_query_params_t *xcap_params, 
 		const char *list_name, flat_list_t **dst)
 		const char *list_name, flat_list_t **dst)
 {
 {
 	char *data = NULL;
 	char *data = NULL;
 	int dsize = 0;
 	int dsize = 0;
 	service_t *service = NULL; 
 	service_t *service = NULL; 
 	list_t *list = NULL, *right = NULL;
 	list_t *list = NULL, *right = NULL;
-	xcap_query_t xcap;
 	int res;
 	int res;
+	char *xcap_uri;
 
 
 	if (!dst) return RES_INTERNAL_ERR;
 	if (!dst) return RES_INTERNAL_ERR;
 	
 	
-	if (xcap_params) {
-		xcap = *xcap_params;
-	}
-	else memset(&xcap, 0, sizeof(xcap));
-
 	/* get basic document */
 	/* get basic document */
-	xcap.uri = xcap_uri_for_resource_list(xcap_root, user);
-	DEBUG_LOG("XCAP uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
-	res = xcap_query(&xcap, &data, &dsize);
+	xcap_uri = xcap_uri_for_resource_list(xcap_root, user);
+	DEBUG_LOG("XCAP uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
+	res = xcap_query(xcap_uri, xcap_params, &data, &dsize);
 	if (res != 0) {
 	if (res != 0) {
-		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
+		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap_uri ? xcap_uri: "???");
 		if (data) {
 		if (data) {
 			cds_free(data);
 			cds_free(data);
 		}
 		}
-		if (xcap.uri) cds_free(xcap.uri);
+		if (xcap_uri) cds_free(xcap_uri);
 		return RES_XCAP_QUERY_ERR;
 		return RES_XCAP_QUERY_ERR;
 	}
 	}
-	if (xcap.uri) cds_free(xcap.uri);
-	xcap.uri = NULL;
+	if (xcap_uri) cds_free(xcap_uri);
+	xcap_uri = NULL;
 	
 	
 	/* parse document as a list element in resource-lists */
 	/* parse document as a list element in resource-lists */
 	if (parse_as_list_content_xml(data, dsize, &list) != 0) {
 	if (parse_as_list_content_xml(data, dsize, &list) != 0) {
@@ -791,7 +763,7 @@ int get_resource_list_from_full_doc(const str_t *xcap_root,
 	/*service->uri = ??? */
 	/*service->uri = ??? */
 
 
 	/* create flat document */
 	/* create flat document */
-	res = create_flat_list(service, &xcap, xcap_root, dst);
+	res = create_flat_list(service, xcap_params, xcap_root, dst);
 
 
 	service->content.list = list; /* free whole document not only "right" list */
 	service->content.list = list; /* free whole document not only "right" list */
 	free_service(service);
 	free_service(service);

+ 3 - 3
lib/xcap/resource_list.h

@@ -42,9 +42,9 @@ typedef struct _flat_list_t {
 
 
 char *xcap_uri_for_rls_resource(const str_t *xcap_root, const str_t *uri);
 char *xcap_uri_for_rls_resource(const str_t *xcap_root, const str_t *uri);
 void canonicalize_uri(const str_t *uri, str_t *dst);
 void canonicalize_uri(const str_t *uri, str_t *dst);
-int get_rls(const str_t *xcap_root, const str_t *uri, xcap_query_t *xcap_params, const str_t *package, flat_list_t **dst);
-int get_rls_from_full_doc(const str_t *xcap_root, const str_t *uri, xcap_query_t *xcap_params, const str_t *package, flat_list_t **dst);
-int get_resource_list_from_full_doc(const str_t *xcap_root, const str_t *user, xcap_query_t *xcap_params, const char *list_name, flat_list_t **dst);
+int get_rls(const str_t *xcap_root, const str_t *uri, xcap_query_params_t *xcap_params, const str_t *package, flat_list_t **dst);
+int get_rls_from_full_doc(const str_t *xcap_root, const str_t *uri, xcap_query_params_t *xcap_params, const str_t *package, flat_list_t **dst);
+int get_resource_list_from_full_doc(const str_t *xcap_root, const str_t *user, xcap_query_params_t *xcap_params, const char *list_name, flat_list_t **dst);
 /* TODO: int get_resource_list(const str_t *xcap_root, const str_t *user, xcap_query_t *xcap_params, const str_t *list_name, flat_list_t **dst); */
 /* TODO: int get_resource_list(const str_t *xcap_root, const str_t *user, xcap_query_t *xcap_params, const str_t *list_name, flat_list_t **dst); */
 void free_flat_list(flat_list_t *list);
 void free_flat_list(flat_list_t *list);
 
 

+ 1 - 1
lib/xcap/test_pres_rules.c

@@ -157,7 +157,7 @@ void test_rules(cp_ruleset_t *pres_rules, const char *uri)
 int pres_rules_test(const char *xcap_root, const char *uri)
 int pres_rules_test(const char *xcap_root, const char *uri)
 {
 {
 	cp_ruleset_t *pres_rules = NULL;
 	cp_ruleset_t *pres_rules = NULL;
-	xcap_query_t xcap;
+	xcap_query_params_t xcap;
 	int res;
 	int res;
 	str_t u;
 	str_t u;
 	
 	

+ 1 - 1
lib/xcap/test_rls.c

@@ -243,7 +243,7 @@ static int xcap_test(const char *xcap_root, const char *uri)
 int test_flat(const str_t *xcap_root, const char *uri)
 int test_flat(const str_t *xcap_root, const char *uri)
 {
 {
 	str_t u = zt2str((char *)uri);
 	str_t u = zt2str((char *)uri);
-	xcap_query_t xcap;
+	xcap_query_params_t xcap;
 	flat_list_t *list = NULL;
 	flat_list_t *list = NULL;
 	str_t p = zt2str("presence");
 	str_t p = zt2str("presence");
 	
 	

+ 44 - 10
lib/xcap/xcap_client.c

@@ -42,7 +42,7 @@ static size_t write_data_func(void *ptr, size_t size, size_t nmemb, void *stream
 	return s;
 	return s;
 }
 }
 
 
-int xcap_query(xcap_query_t *query, char **buf, int *bsize)
+int xcap_query(const char *uri, xcap_query_params_t *params, char **buf, int *bsize)
 {
 {
 	CURLcode res = -1;
 	CURLcode res = -1;
 	CURL *handle;
 	CURL *handle;
@@ -51,18 +51,20 @@ int xcap_query(xcap_query_t *query, char **buf, int *bsize)
 	int i;
 	int i;
 	long auth_methods;
 	long auth_methods;
 	
 	
-	if (!query) return -1;
+	if (!uri) return -1;
 	if (!buf) return -1;
 	if (!buf) return -1;
 
 
 	i = 0;
 	i = 0;
-	if (query->auth_user) i += strlen(query->auth_user);
-	if (query->auth_pass) i += strlen(query->auth_pass);
+	if (params) {
+		if (params->auth_user) i += strlen(params->auth_user);
+		if (params->auth_pass) i += strlen(params->auth_pass);
+	}
 	if (i > 0) {
 	if (i > 0) {
 		/* do authentication */
 		/* do authentication */
 		auth = (char *)cds_malloc(i + 2);
 		auth = (char *)cds_malloc(i + 2);
 		if (!auth) return -1;
 		if (!auth) return -1;
-		sprintf(auth, "%s:%s", query->auth_user ? query->auth_user: "",
-				query->auth_pass ? query->auth_pass: "");
+		sprintf(auth, "%s:%s", params->auth_user ? params->auth_user: "",
+				params->auth_pass ? params->auth_pass: "");
 	}
 	}
 
 
 	auth_methods = CURLAUTH_BASIC | CURLAUTH_DIGEST;
 	auth_methods = CURLAUTH_BASIC | CURLAUTH_DIGEST;
@@ -71,7 +73,7 @@ int xcap_query(xcap_query_t *query, char **buf, int *bsize)
 	
 	
 	handle = curl_easy_init();
 	handle = curl_easy_init();
 	if (handle) {
 	if (handle) {
-		curl_easy_setopt(handle, CURLOPT_URL, query->uri);
+		curl_easy_setopt(handle, CURLOPT_URL, uri);
 		
 		
 		/* do not store data into a file - store them in memory */
 		/* do not store data into a file - store them in memory */
 		curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data_func);
 		curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data_func);
@@ -89,9 +91,11 @@ int xcap_query(xcap_query_t *query, char **buf, int *bsize)
 		curl_easy_setopt(handle, CURLOPT_USERPWD, auth);
 		curl_easy_setopt(handle, CURLOPT_USERPWD, auth);
 
 
 		/* SSL */
 		/* SSL */
-		if (query->enable_unverified_ssl_peer) {
-			curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
-			curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0);
+		if (params) {
+			if (params->enable_unverified_ssl_peer) {
+				curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
+				curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0);
+			}
 		}
 		}
 		
 		
 		/* follow redirects (needed for apache mod_speling - case insesitive names) */
 		/* follow redirects (needed for apache mod_speling - case insesitive names) */
@@ -118,3 +122,33 @@ int xcap_query(xcap_query_t *query, char **buf, int *bsize)
 	return res;
 	return res;
 }
 }
 
 
+void free_xcap_params_content(xcap_query_params_t *params)
+{
+	if (params) {
+		if (params->auth_user) cds_free(params->auth_user);
+		if (params->auth_pass) cds_free(params->auth_pass);
+		memset(params, 0, sizeof(*params));
+	}
+}
+
+int dup_xcap_params(xcap_query_params_t *dst, xcap_query_params_t *src)
+{
+	if (dst) memset(dst, 0, sizeof(*dst));
+	
+	if (src && dst) {
+		if (src->auth_user) {
+			dst->auth_user = zt_strdup(src->auth_user);
+			if (!dst->auth_user) return -1;
+		}
+		if (src->auth_pass) {
+			dst->auth_pass = zt_strdup(src->auth_pass);
+			if (!dst->auth_pass) {
+				free_xcap_params_content(dst);
+				return -2;
+			}
+		}
+	}
+	
+	return 0;
+}
+

+ 6 - 4
lib/xcap/xcap_client.h

@@ -27,8 +27,6 @@
 #define __XCAP_CLIENT_H
 #define __XCAP_CLIENT_H
 
 
 typedef struct {
 typedef struct {
-	/** full HTTP/HTTPS uri for the query */
-	char *uri;
 	/** username for authentication */
 	/** username for authentication */
 	char *auth_user;
 	char *auth_user;
 	/** password used for authentication */
 	/** password used for authentication */
@@ -37,11 +35,15 @@ typedef struct {
 	 * stored in certificate and trust a certificate
 	 * stored in certificate and trust a certificate
 	 * without know CA). */
 	 * without know CA). */
 	int enable_unverified_ssl_peer;
 	int enable_unverified_ssl_peer;
-} xcap_query_t;
+} xcap_query_params_t;
 
 
 /** Sends a XCAP query to the destination and using parameters from 
 /** Sends a XCAP query to the destination and using parameters from 
  * query variable a returns received data in output variables buf
  * query variable a returns received data in output variables buf
  * and bsize. */
  * and bsize. */
-int xcap_query(xcap_query_t *query, char **buf, int *bsize);
+/* URI is full HTTP/HTTPS uri for the query */
+int xcap_query(const char *uri, xcap_query_params_t *params, char **buf, int *bsize);
+
+void free_xcap_params_content(xcap_query_params_t *params);
+int dup_xcap_params(xcap_query_params_t *dst, xcap_query_params_t *src);
 
 
 #endif
 #endif