|
@@ -0,0 +1,562 @@
|
|
|
+/*
|
|
|
+ * Copyright (C) 2005 iptelorg GmbH
|
|
|
+ *
|
|
|
+ * This file is part of ser, a free SIP server.
|
|
|
+ *
|
|
|
+ * ser is free software; you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
+ * (at your option) any later version
|
|
|
+ *
|
|
|
+ * For a license to use the ser software under conditions
|
|
|
+ * other than those described here, or to purchase support for this
|
|
|
+ * software, please contact iptel.org by e-mail at the following addresses:
|
|
|
+ * [email protected]
|
|
|
+ *
|
|
|
+ * ser is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
+ */
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+#include <cds/dstring.h>
|
|
|
+#include <xcap/xcap_client.h>
|
|
|
+#include <xcap/resource_list.h>
|
|
|
+#include <xcap/resource_lists_parser.h>
|
|
|
+#include <xcap/rls_services_parser.h>
|
|
|
+#include <xcap/xcap_result_codes.h>
|
|
|
+#include <libxml/parser.h>
|
|
|
+#include <cds/logger.h>
|
|
|
+
|
|
|
+#define STR_OK(s) (s)?(s):""
|
|
|
+
|
|
|
+typedef struct _traversed_list_t {
|
|
|
+ struct _traversed_list_t *next;
|
|
|
+ char *uri;
|
|
|
+} traversed_list_t;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ const char *xcap_root;
|
|
|
+ xcap_query_t *xcap_params;
|
|
|
+ traversed_list_t *traversed;
|
|
|
+ traversed_list_t *traversed_last;
|
|
|
+ flat_list_t *flat;
|
|
|
+ flat_list_t *flat_last;
|
|
|
+} process_params_t;
|
|
|
+
|
|
|
+void canonicalize_uri(const str_t *uri, str_t *dst)
|
|
|
+{
|
|
|
+ /* TODO: do the operation according to draft-ietf-simple-xcap-list-usage-05.txt */
|
|
|
+
|
|
|
+ if (!dst) return;
|
|
|
+ if (!uri) {
|
|
|
+ dst->len = 0;
|
|
|
+ dst->s = NULL;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (uri->len > 0) {
|
|
|
+ dst->s = (char*)cds_malloc(uri->len);
|
|
|
+ if (!dst->s) dst->len = 0;
|
|
|
+ else {
|
|
|
+ memcpy(dst->s, uri->s, uri->len);
|
|
|
+ dst->len = uri->len;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dst->len = 0;
|
|
|
+ dst->s = NULL;
|
|
|
+ }
|
|
|
+ /* DEBUG_LOG("canonicalized uri: \'%.*s\'\n", dst->len, dst->s); */
|
|
|
+}
|
|
|
+
|
|
|
+char *xcap_uri_for_rls_resource(const char *xcap_root, const str_t *uri)
|
|
|
+{
|
|
|
+ dstring_t s;
|
|
|
+ int l;
|
|
|
+ str_t c_uri;
|
|
|
+ char *dst = NULL;
|
|
|
+
|
|
|
+ if (!xcap_root) return NULL;
|
|
|
+ l = strlen(xcap_root);
|
|
|
+ dstr_init(&s, 2 * l + 32);
|
|
|
+ dstr_append(&s, xcap_root, l);
|
|
|
+ if (xcap_root[l - 1] != '/') dstr_append(&s, "/", 1);
|
|
|
+ dstr_append_zt(&s, "rls-services/global/index/~~/rls-services/service[@uri=%22");
|
|
|
+ canonicalize_uri(uri, &c_uri);
|
|
|
+ dstr_append_str(&s, &c_uri);
|
|
|
+ if (c_uri.s) cds_free(c_uri.s);
|
|
|
+
|
|
|
+ dstr_append_zt(&s, "%22]");
|
|
|
+ l = dstr_get_data_length(&s);
|
|
|
+ if (l > 0) {
|
|
|
+ dst = (char *)cds_malloc(l + 1);
|
|
|
+ if (dst) {
|
|
|
+ dstr_get_data(&s, dst);
|
|
|
+ dst[l] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dstr_destroy(&s);
|
|
|
+ return dst;
|
|
|
+}
|
|
|
+
|
|
|
+void free_flat_list(flat_list_t *list)
|
|
|
+{
|
|
|
+ flat_list_t *f, *e;
|
|
|
+ e = list;
|
|
|
+ while (e) {
|
|
|
+ f = e->next;
|
|
|
+ if (e->uri) cds_free(e->uri);
|
|
|
+ free_display_names(e->names);
|
|
|
+ cds_free(e);
|
|
|
+ e = f;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void free_traversed_list(traversed_list_t *list)
|
|
|
+{
|
|
|
+ traversed_list_t *f, *e;
|
|
|
+ e = list;
|
|
|
+ while (e) {
|
|
|
+ f = e->next;
|
|
|
+ if (e->uri) cds_free(e->uri);
|
|
|
+ cds_free(e);
|
|
|
+ e = f;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* ------- helper functions (doing flat list) ------- */
|
|
|
+
|
|
|
+static char *relative2absolute_uri(const char *xcap_root, const char *relative)
|
|
|
+{
|
|
|
+ /* FIXME: do absolute uri from ref (RFC 3986, section 5.2) */
|
|
|
+ int len;
|
|
|
+ int root_len = 0;
|
|
|
+ int rel_len = 0;
|
|
|
+ int slash_len = 0;
|
|
|
+ char *dst = NULL;
|
|
|
+
|
|
|
+ if (xcap_root) {
|
|
|
+ root_len = strlen(xcap_root);
|
|
|
+ len += root_len;
|
|
|
+ if (xcap_root[root_len - 1] != '/') slash_len = 1;
|
|
|
+ }
|
|
|
+ if (relative) rel_len = strlen(relative);
|
|
|
+ len = root_len + slash_len + rel_len + 1;
|
|
|
+
|
|
|
+ dst = (char *)cds_malloc(len);
|
|
|
+ if (!dst) return NULL;
|
|
|
+
|
|
|
+ if (xcap_root) memcpy(dst, xcap_root, root_len);
|
|
|
+ if (slash_len) dst[root_len] = '/';
|
|
|
+ if (relative) memcpy(dst + root_len + slash_len, relative, rel_len);
|
|
|
+ dst[len - 1] = 0;
|
|
|
+
|
|
|
+ return dst;
|
|
|
+}
|
|
|
+
|
|
|
+static display_name_t *duplicate_display_name(display_name_t *src)
|
|
|
+{
|
|
|
+ display_name_t *n;
|
|
|
+ if (!src) return NULL;
|
|
|
+ n = (display_name_t*)cds_malloc(sizeof(*n));
|
|
|
+ if (!n) return NULL;
|
|
|
+ memset(n, 0, sizeof(*n));
|
|
|
+ if (src->name) n->name = zt_strdup(src->name);
|
|
|
+ if (src->lang) n->lang = zt_strdup(src->lang);
|
|
|
+ return n;
|
|
|
+}
|
|
|
+
|
|
|
+int add_entry_to_flat(process_params_t *params, entry_t *entry)
|
|
|
+{
|
|
|
+ flat_list_t *f;
|
|
|
+ display_name_t *d, *n, *last;
|
|
|
+ char *uri;
|
|
|
+
|
|
|
+ if (!entry) return -1;
|
|
|
+ uri = entry->uri;
|
|
|
+ if (!uri) return -1; /* can't be added */
|
|
|
+
|
|
|
+ /* try to find the uri in the flat list first */
|
|
|
+ f = params->flat;
|
|
|
+ while (f) {
|
|
|
+ if (strcmp(f->uri, uri) == 0) return 1; /* not significant for the caller */
|
|
|
+ f = f->next;
|
|
|
+ }
|
|
|
+
|
|
|
+ f = (flat_list_t*)cds_malloc(sizeof(flat_list_t));
|
|
|
+ if (!f) return -1;
|
|
|
+ memset(f, 0, sizeof(*f));
|
|
|
+ f->uri = zt_strdup(uri);
|
|
|
+ f->next = NULL;
|
|
|
+
|
|
|
+ if (params->flat_last) params->flat_last->next = f;
|
|
|
+ else params->flat = f;
|
|
|
+ params->flat_last = f;
|
|
|
+
|
|
|
+ /* add all entry's names */
|
|
|
+ last = NULL;
|
|
|
+ d = SEQUENCE_FIRST(entry->display_names);
|
|
|
+ while (d) {
|
|
|
+ n = duplicate_display_name(d);
|
|
|
+ if (n) SEQUENCE_ADD(f->names, last, n);
|
|
|
+ d = SEQUENCE_NEXT(d);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int add_uri_to_traversed(process_params_t *params, const char *uri)
|
|
|
+{
|
|
|
+ traversed_list_t *f;
|
|
|
+
|
|
|
+ if (!uri) return -1; /* can't be added */
|
|
|
+
|
|
|
+ /* try to find the uri in the flat list first */
|
|
|
+ f = params->traversed;
|
|
|
+ while (f) {
|
|
|
+ if (!f->uri) continue;
|
|
|
+ if (strcmp(f->uri, uri) == 0) return 1; /* this should be taken as an error */
|
|
|
+ f = f->next;
|
|
|
+ }
|
|
|
+
|
|
|
+ f = (traversed_list_t*)cds_malloc(sizeof(traversed_list_t));
|
|
|
+ if (!f) return -1;
|
|
|
+ f->uri = zt_strdup(uri);
|
|
|
+ f->next = NULL;
|
|
|
+
|
|
|
+ if (params->traversed_last) params->traversed_last->next = f;
|
|
|
+ else params->traversed = f;
|
|
|
+ params->traversed_last = f;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/* ------- processing functions (doing flat list) ------- */
|
|
|
+
|
|
|
+static int process_list(list_t *list, process_params_t *params);
|
|
|
+
|
|
|
+static int process_entry(entry_t *entry, process_params_t *params)
|
|
|
+{
|
|
|
+ if (!entry) return RES_OK;
|
|
|
+ if (!entry->uri) return RES_OK;
|
|
|
+
|
|
|
+ /* DEBUG_LOG("processing entry with uri \'%s\'\n", STR_OK(entry->uri)); */
|
|
|
+
|
|
|
+ add_entry_to_flat(params, entry);
|
|
|
+ return RES_OK;
|
|
|
+}
|
|
|
+
|
|
|
+static int process_entry_ref(entry_ref_t *entry_ref, process_params_t *params)
|
|
|
+{
|
|
|
+ char *data = NULL;
|
|
|
+ int dsize = 0;
|
|
|
+ entry_t *entry = NULL;
|
|
|
+ xcap_query_t xcap;
|
|
|
+ int res;
|
|
|
+
|
|
|
+ /* DEBUG_LOG("processing entry-ref with ref \'%s\'\n", STR_OK(entry_ref->ref)); */
|
|
|
+
|
|
|
+ if (!entry_ref) return RES_OK;
|
|
|
+ if (!entry_ref->ref) return RES_OK;
|
|
|
+
|
|
|
+ if (add_uri_to_traversed(params, entry_ref->ref) != 0) {
|
|
|
+ /* It is existing yet? */
|
|
|
+ ERROR_LOG("Duplicate URI in traversed set\n");
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 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);
|
|
|
+ if (res != 0) {
|
|
|
+ ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
|
|
|
+ if (data) cds_free(data);
|
|
|
+ if (xcap.uri) cds_free(xcap.uri);
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
|
|
|
+ }
|
|
|
+ if (xcap.uri) cds_free(xcap.uri);
|
|
|
+
|
|
|
+ /* parse document as an entry element */
|
|
|
+ if (parse_entry_xml(data, dsize, &entry) != 0) {
|
|
|
+ ERROR_LOG("Parsing problems!\n");
|
|
|
+ if (entry) free_entry(entry);
|
|
|
+ if (data) cds_free(data);
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
|
|
|
+ }
|
|
|
+ if (data) cds_free(data);
|
|
|
+ if (!entry) return RES_INTERNAL_ERR; /* ??? */
|
|
|
+
|
|
|
+ res = process_entry(entry, params);
|
|
|
+ free_entry(entry);
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+static int process_external(external_t *external, process_params_t *params)
|
|
|
+{
|
|
|
+ char *data = NULL;
|
|
|
+ int dsize = 0;
|
|
|
+ list_t *list = NULL;
|
|
|
+ xcap_query_t xcap;
|
|
|
+ int res;
|
|
|
+
|
|
|
+ /* DEBUG_LOG("processing external with anchor \'%s\'\n", STR_OK(external->anchor)); */
|
|
|
+
|
|
|
+ if (!external) return RES_OK;
|
|
|
+ if (!external->anchor) return RES_OK;
|
|
|
+
|
|
|
+ if (add_uri_to_traversed(params, external->anchor) != 0) {
|
|
|
+ /* It is existing yet? */
|
|
|
+ ERROR_LOG("Duplicate URI in traversed set\n");
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 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);
|
|
|
+ if (res != 0) {
|
|
|
+ ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
|
|
|
+ if (data) cds_free(data);
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
|
|
|
+ }
|
|
|
+
|
|
|
+ /* parse document as an entry element */
|
|
|
+ if (parse_list_xml(data, dsize, &list) != 0) {
|
|
|
+ ERROR_LOG("Parsing problems!\n");
|
|
|
+ if (list) free_list(list);
|
|
|
+ if (data) cds_free(data);
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* 502 Bad GW */
|
|
|
+ }
|
|
|
+ if (data) cds_free(data);
|
|
|
+ if (!list) return RES_INTERNAL_ERR; /* ??? */
|
|
|
+
|
|
|
+ res = process_list(list, params);
|
|
|
+
|
|
|
+ free_list(list);
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+static int process_list(list_t *list, process_params_t *params)
|
|
|
+{
|
|
|
+ list_content_t *e;
|
|
|
+ int res = 0;
|
|
|
+
|
|
|
+ if (!list) return RES_INTERNAL_ERR;
|
|
|
+ /* DEBUG_LOG("processing list \'%s\'\n", STR_OK(list->name)); */
|
|
|
+
|
|
|
+ e = SEQUENCE_FIRST(list->content);
|
|
|
+
|
|
|
+ while (e) {
|
|
|
+ switch (e->type) {
|
|
|
+ case lct_list:
|
|
|
+ res = process_list(e->u.list, params);
|
|
|
+ break;
|
|
|
+ case lct_entry:
|
|
|
+ res = process_entry(e->u.entry, params);
|
|
|
+ break;
|
|
|
+ case lct_entry_ref:
|
|
|
+ res = process_entry_ref(e->u.entry_ref, params);
|
|
|
+ break;
|
|
|
+ case lct_external:
|
|
|
+ res = process_external(e->u.external, params);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (res != 0) break;
|
|
|
+ e = SEQUENCE_NEXT(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+static int process_resource_list(const char *rl_uri, process_params_t *params)
|
|
|
+{
|
|
|
+ char *data = NULL;
|
|
|
+ int dsize = 0;
|
|
|
+ int res = 0;
|
|
|
+ xcap_query_t xcap;
|
|
|
+ list_t *list = NULL;
|
|
|
+
|
|
|
+ /* DEBUG_LOG("processing resource list\n"); */
|
|
|
+
|
|
|
+ /* 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 (data) cds_free(data);
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* -> 502 Bad GW */
|
|
|
+ }
|
|
|
+
|
|
|
+ /* parse query result */
|
|
|
+ if (parse_list_xml(data, dsize, &list) != 0) {
|
|
|
+ if (data) cds_free(data);
|
|
|
+ return RES_BAD_GATEWAY_ERR; /* -> 502 Bad GW */
|
|
|
+ }
|
|
|
+ if (data) {
|
|
|
+ cds_free(data);
|
|
|
+ }
|
|
|
+ if (!list) return RES_INTERNAL_ERR; /* ??? */
|
|
|
+
|
|
|
+ res = process_list(list, params);
|
|
|
+ if (list) {
|
|
|
+ free_list(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+static int create_flat_list(service_t *srv, xcap_query_t *xcap_params, const char *xcap_root, flat_list_t **dst)
|
|
|
+{
|
|
|
+ process_params_t params;
|
|
|
+ int res = -1;
|
|
|
+ if (!srv) return RES_INTERNAL_ERR;
|
|
|
+
|
|
|
+ params.xcap_root = xcap_root;
|
|
|
+ params.xcap_params = xcap_params;
|
|
|
+ params.flat = NULL;
|
|
|
+ params.flat_last = NULL;
|
|
|
+ params.traversed = NULL;
|
|
|
+ params.traversed_last = NULL;
|
|
|
+
|
|
|
+ if (srv->content_type == stc_list) {
|
|
|
+ res = process_list(srv->content.list, ¶ms);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ res = process_resource_list(srv->content.resource_list, ¶ms);
|
|
|
+ }
|
|
|
+ if (dst) *dst = params.flat;
|
|
|
+
|
|
|
+ free_traversed_list(params.traversed);
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+/* ------- helper functions for rls examining ------- */
|
|
|
+
|
|
|
+/** compare str_t and zero terminated string */
|
|
|
+int str_strcmp(const str_t *a, const char *b)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+
|
|
|
+ if (!a) {
|
|
|
+ if (!b) return 0;
|
|
|
+ else return 1;
|
|
|
+ }
|
|
|
+ if (!a->s) {
|
|
|
+ if (!b) return 0;
|
|
|
+ else return 1;
|
|
|
+ }
|
|
|
+ if (!b) return -1;
|
|
|
+ for (i = 0; i < a->len; i++) {
|
|
|
+ if (a->s[i] != b[i]) return -1;
|
|
|
+ if (b[i] == 0) break;
|
|
|
+ }
|
|
|
+ if (i == a->len) return 0;
|
|
|
+ else return 1;
|
|
|
+}
|
|
|
+
|
|
|
+static int verify_package(service_t *srv, const str_t *package)
|
|
|
+{
|
|
|
+ package_t *e;
|
|
|
+
|
|
|
+ if (!package) return 0;
|
|
|
+ if (!package->len) return 0;
|
|
|
+ if (!package->s) return 0;
|
|
|
+ if (!srv) return 1;
|
|
|
+
|
|
|
+ if (srv->packages) {
|
|
|
+ e = SEQUENCE_FIRST(srv->packages->package);
|
|
|
+ while (e) {
|
|
|
+ if (str_strcmp(package, e->name) == 0) return 0;
|
|
|
+ e = SEQUENCE_NEXT(e);
|
|
|
+ }
|
|
|
+ ERROR_LOG("Unsupported package \"%.*s\"\n", package->len, package->s);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/* ------- rls examining ------- */
|
|
|
+
|
|
|
+int get_rls(const char *xcap_root, const str_t *uri, xcap_query_t *xcap_params, const str_t *package, flat_list_t **dst)
|
|
|
+{
|
|
|
+ char *data = NULL;
|
|
|
+ int dsize = 0;
|
|
|
+ service_t *service = NULL;
|
|
|
+ xcap_query_t xcap;
|
|
|
+ int res;
|
|
|
+
|
|
|
+ if (!dst) return RES_INTERNAL_ERR;
|
|
|
+
|
|
|
+ if (xcap_params) {
|
|
|
+ xcap = *xcap_params;
|
|
|
+ }
|
|
|
+ else memset(&xcap, 0, sizeof(xcap));
|
|
|
+
|
|
|
+ /* 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);
|
|
|
+ if (res != 0) {
|
|
|
+ ERROR_LOG("get_rls(): XCAP problems for uri \'%s\'\n", xcap.uri ? xcap.uri: "???");
|
|
|
+ if (data) {
|
|
|
+ cds_free(data);
|
|
|
+ }
|
|
|
+ if (xcap.uri) cds_free(xcap.uri);
|
|
|
+ return RES_XCAP_QUERY_ERR;
|
|
|
+ }
|
|
|
+ if (xcap.uri) cds_free(xcap.uri);
|
|
|
+ xcap.uri = NULL;
|
|
|
+
|
|
|
+ /* parse document as a service element in rls-sources */
|
|
|
+ if (parse_service(data, dsize, &service) != 0) {
|
|
|
+ ERROR_LOG("Parsing problems!\n");
|
|
|
+ if (service) free_service(service);
|
|
|
+ if (data) {
|
|
|
+ cds_free(data);
|
|
|
+ }
|
|
|
+ return RES_XCAP_PARSE_ERR;
|
|
|
+ }
|
|
|
+/* DEBUG_LOG("%.*s\n", dsize, data);*/
|
|
|
+ if (data) cds_free(data);
|
|
|
+
|
|
|
+ if (!service) {
|
|
|
+ ERROR_LOG("Empty service!\n");
|
|
|
+ return RES_INTERNAL_ERR;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* verify the package */
|
|
|
+ if (verify_package(service, package) != 0) {
|
|
|
+ cds_free(service);
|
|
|
+ return RES_BAD_EVENT_PACKAGE_ERR;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* create flat document */
|
|
|
+ res = create_flat_list(service, &xcap, xcap_root, dst);
|
|
|
+ if (res != RES_OK) {
|
|
|
+ ERROR_LOG("Flat list creation error\n");
|
|
|
+ free_service(service);
|
|
|
+ free_flat_list(*dst);
|
|
|
+ *dst = NULL;
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ free_service(service);
|
|
|
+
|
|
|
+ return RES_OK;
|
|
|
+}
|