diff --git a/trunk/tinyXCAP/test/stdafx.c b/trunk/tinyXCAP/test/stdafx.c new file mode 100644 index 00000000..e1063fc4 --- /dev/null +++ b/trunk/tinyXCAP/test/stdafx.c @@ -0,0 +1,31 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/trunk/tinyXCAP/test/stdafx.h b/trunk/tinyXCAP/test/stdafx.h new file mode 100644 index 00000000..b8959668 --- /dev/null +++ b/trunk/tinyXCAP/test/stdafx.h @@ -0,0 +1,38 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#pragma once + +#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. +#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/trunk/tinyXCAP/test/targetver.h b/trunk/tinyXCAP/test/targetver.h new file mode 100644 index 00000000..a38195a4 --- /dev/null +++ b/trunk/tinyXCAP/test/targetver.h @@ -0,0 +1,13 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + diff --git a/trunk/tinyXCAP/test/test.c b/trunk/tinyXCAP/test/test.c new file mode 100644 index 00000000..dfe05a3d --- /dev/null +++ b/trunk/tinyXCAP/test/test.c @@ -0,0 +1,100 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "stdafx.h" +#include "xdm_api.h" + +/* +* These AUID are supported: +- xcap-caps +- resource-lists +- rls-services +- pres-rules +- directory +- org.openmobilealliance.conv-history +- org.openmobilealliance.pres-rules +- org.openmobilealliance.xdm-directory +- org.openmobilealliance.deferred-list +- org.openmobilealliance.pres-content +- org.openmobilealliance.groups + +* Both HTTPS and HTTP are supported +* Automatic Url encoding/decoding +*/ + +#include + +#include "test_selector.h" +#include "test_xcap-caps.h" +#include "test_rlist.h" +#include "test_oma-directory.h" +#include "test_oma-pres-cont.h" +#include "test_rls.h" +#include "test_xcap.h" +#include "test_gsma_rcs.h" + +/* http://curl.haxx.se/libcurl/c/libcurl-tutorial.html */ + +int _tmain(int argc, _TCHAR* argv[]) +{ +#if 0 //uncomment to test memory leaks + while(1) +#endif + { + /* test xcap selector */ + //test_selector(); + + /* test xcap-caps */ + //test_xcap_caps(); + + /* test resource-lists */ + //test_rlist(); + + /* test resource-lists 2 */ + //test_rlist2(); + + /* test oma xcap-directory*/ + //test_oma_directory(); + + /* test oma-pres-content */ + //test_oma_pres_cont(); + + /* test rls-services */ + //test_rls_services(); + + /* test xcap */ + test_xcap(); + + /* test gsma rcs */ + //test_gsma_rcs(); + } + + getchar(); + + return 0; +} + diff --git a/trunk/tinyXCAP/test/test.vcproj b/trunk/tinyXCAP/test/test.vcproj new file mode 100644 index 00000000..37d557a8 --- /dev/null +++ b/trunk/tinyXCAP/test/test.vcproj @@ -0,0 +1,406 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/tinyXCAP/test/test_gsma_rcs.h b/trunk/tinyXCAP/test/test_gsma_rcs.h new file mode 100644 index 00000000..d0561c34 --- /dev/null +++ b/trunk/tinyXCAP/test/test_gsma_rcs.h @@ -0,0 +1,72 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TEST_GSMA_RCS_H_ +#define _TEST_GSMA_RCS_H_ + +#include "xdm_api.h" + +/* test gsma rcs */ +void test_gsma_rcs() +{ + xdm_context_t* context = 0; + xdm_list_t *rlist2 = 0, *services; + char *rlist2_str = 0, *rls_str = 0, *oma_presrules_str = 0; + + /* create our xdm context */ + XDM_CONTEXT_CREATE(context); + + context->user_agent = xdm_strdup("XDM-client/OMA1.1"); + context->xdm_root = xdm_strdup("http://xcap.example.com/services"); + context->password = xdm_strdup("mysecret"); + context->xui = xdm_strdup("sip:doubango@example.com"); + + /* get rcs lists */ + rlist2 = xdm_gsmarcs_create_rlist2(context); + rlist2_str = xdm_rlist_rlist2_serialize(rlist2); + printf("rcs resource-lists: %s\n", rlist2_str); + XDM_SAFE_FREE(rlist2_str); + XDM_LIST_SAFE_FREE(rlist2); + + /* get rls services */ + services = xdm_gsmarcs_create_rls(context); + rls_str = xdm_rls_rls_serialize(services); + printf("rcs rls-services: %s\n", rls_str); + XDM_SAFE_FREE(rls_str); + XDM_LIST_SAFE_FREE(services); + + /* get oma pres-rules */ + oma_presrules_str = xdm_gsmarcs_create_oma_presrules(context); + printf("rcs oma pres-rules: %s\n", oma_presrules_str); + XDM_SAFE_FREE(oma_presrules_str); + + /* free context */ + XDM_CONTEXT_SAFE_FREE(context); +} + + +#endif /* _TEST_GSMA_RCS_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_oma-directory.h b/trunk/tinyXCAP/test/test_oma-directory.h new file mode 100644 index 00000000..6603f00e --- /dev/null +++ b/trunk/tinyXCAP/test/test_oma-directory.h @@ -0,0 +1,85 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_api.h" + +/* test OMA directory (urn:oma:xml:xdm:xcap-directory) */ +void test_oma_directory() +{ + char* entry_str = 0; + xdm_omadir_t* omadir = 0; + xdm_list_t* list = 0; + xdm_list_item_t* item = 0; + // http://www.openmobilealliance.com/technical/release_program/docs/XDM/V2_0-20070724-C/OMA-TS-XDM_Core-V2_0-20070724-C.pdf subclause C.3 + const char* omadir_str = "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; + printf("\n---\nTEST OMA XCAP-DIRECTORY\n---\n"); + { + /* create rlist context */ + omadir = xdm_omadir_create(omadir_str, strlen(omadir_str)); + + /* get all folders */ + printf("\nget all folders\n"); + if(list = xdm_omadir_get_all_folders(omadir)) + { + xdm_list_foreach(item, list) + { + xdm_omadir_folder_t *folder = ((xdm_omadir_folder_t*)item->data); + printf("auid: \"%s\"\n", folder->auid); + } + XDM_LIST_SAFE_FREE(list); + } + + /* get all entries in the folder with auid 'groups' */ + printf("\nget all entries in the folder with auid 'groups'\n"); + if(list = xdm_omadir_get_entries_by_folder(omadir, "groups")) + { + xdm_list_foreach(item, list) + { + xdm_rlist_entry_t *entry = ((xdm_rlist_entry_t*)item->data); + printf("folder's auid:\"%s\" uri:\"%s\" display-name=\"%s\" etag\"%s\"\n", entry->list, entry->uri, entry->display_name, entry->etag); + entry_str = xdm_rlist_entry_serialize(entry); + printf("serialized entry: \n%s\n", entry_str); + XDM_SAFE_FREE(entry_str); + } + XDM_LIST_SAFE_FREE(list); + } + + /* free omadir */ + xdm_omadir_free(&omadir); + } +} \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_oma-pres-cont.h b/trunk/tinyXCAP/test/test_oma-pres-cont.h new file mode 100644 index 00000000..01bd8972 --- /dev/null +++ b/trunk/tinyXCAP/test/test_oma-pres-cont.h @@ -0,0 +1,93 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_api.h" + +/* test OMA directory (urn:oma:xml:xdm:xcap-directory) */ +void test_oma_pres_cont() +{ + char* entry_str = 0; + xdm_oma_prescont_t* omaprescont = 0; + xdm_list_t* list = 0; + xdm_list_item_t* item = 0; + // http://www.openmobilealliance.org/technical/release_program/docs/PresenceSIMPLE/V2_0-20081223-C/OMA-TS-Presence_SIMPLE_Content_XDM-V1_0-20081223-C.pdf subclause C.1.1 + const char* omaprescont_str = "" + "" + "image/png" + "base64" + "Attending OMA Meeting" + "iVBORw0KGgoAAAANSUhEUgAAAI8AAAAtCAMAAACgachEAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQW" + "RvYmUgSW1hZ2VSZWFkeXHJZTwAAAGAUExURazWxbm7uzAzMgAUbqOnpnV5efzlx5aamfPz84WIiLWrzgUKCdHP5WZoaPvZr/" + "S0aOvt7e/WzNjr41VYWAQuf8DDw8lyYf3+/uHi4u+cN93e3sTi1ToTbPjKkUVJSMnLynBzr0VQl+a+tuyIE9LT07A5Mkcjdv" + "3x5IbErvKoVna7o5nMuItzrePx7IzHsZWayFY1gaQGFHNWmejp9Oz28vn5+teVh/Xm30plomBkZKsXJfPy+TJAi6uZxM3F3u" + "6ULI6Kvb1aScS82nB0c50AApCTk857c6KPvPGfR7VJPGu3m56hoH+Dg/v6/eDa633Ap///+9+roPL39eTh7+2PILGzs/z38+" + "2ONMzPz/b39/737uTm5dnZ2j5CQfr7+1BUU/77+ebo5/Dv8lldofz9/Ht+fcXHx6utrV1gYPb292lvbhUXFzk8PIuPjiUoJ+" + "+WNR0fHoyOjmxvb1ldXIGOvenp6ep9AJ+kzfa9ec/R0aQlJEtPTk5OT9XW1gAAAP///8goVXMAAAcgSURBVHja7JjrV9pIFM" + "AFCSRGFEEqooIKRYoVtfWFz9aIjxKlalEQkUp5BEEErFtZhfnXd2YSQggg7na3x7On91Pmlfnlzn1NOsDLko7fPL95/gOer4" + "t9feOHh30vg2fxcPvj3uvl2dnl7c8vgKdv4ePrP2eRbG1tP7E4HaC0XNFrbBgwe6+4osYktFIJj4dVNExKehmPh9Ak2/IsHr" + "6CPMtYtpbHW9GUtXm6goTOJWLSAdNtBvdnbhFRIc9PUqqkc3REjl+MVuue5ulbqPHMbi20wCH4TXnJSzYL5MXunBVwtUna2h" + "xNXrK4kvH9PI+lUi9UdcAo5cxFxUeojqL4LbLFFe+TPMiaq+c1i89rf142J4o3yHGUN2HgFV/gB+IRrK+EhoqIymO81AOeL1" + "gahRsVS+L6uhjhUVNP8EyML7za+xPaMrLnV8huD7rXu+tMhP/AArbYuF2LW7zFqtCjBQ2EhG2zqHHhxf28BnF/VHGEGqQRaz" + "pjbuRZmV5a+v4eGTQC2tt7Pbu1vH0CwHx319raTtdxbWYQvTFT8ysNPps0ekT2krHz3bdoWr4sNip0GD1l0WwmXl0cusLtBp" + "73Y51QVtG2ZzAaLsYWx8dxPDzu2nkLZU18A2+kUg/Gr1RVN7sSehVSK7aiRpJ/oAVNCfKIvsYs51nq7Ozv7+xc2pcd3/76zt" + "t3SDarPZe0/I0h5C8P0MgGlBLrDOdg41pozKOzQypNIDCTdLUCDQVkPAcIBwF1y3jimxBnBspb0aMrFdE2BSmiYzIJPBqhM4" + "aMVfTljKAfJfyYaP0OWdEfajw/MA4E6pLb9yamcTjeVS2IQqZQPydACyco5dFlq6eIhOZ5SKTcVP1qAxxKyHi+8zyN+gEH7x" + "wOBDTTJSqDruTq5wQzgira8uiQcs/rVyNbJ2Q8owLP6lFDAPgw7MAaqh6YFvIoZckjI3C05BmQ8uga9SPjSX9rdVzwwBw8z8" + "zxv6AfEvGY2/K8H+Nx+mONPOuOYd6CulraT6qt/VT1c4HIU215jsdWV1f7V/vHVtrzBOThhw9AyL/a6wemGrl/NeUZHRtbhU" + "yjTXiOZzDP8MxBq/hzVI0/7fXDB/NwO56VD6PfkEwPNMloa8PDDsfw8M4z4nN7/YRxfK5to7vD75P71+b3USgfuptWFzvwsG" + "ZEHFBCr6RrQDhZKkPgWfoBOP1eVd04bWFxj5wntvljevrH+nzzcuegq0tKyuIUzZovUK6wcpJior1+gA4dd+VRgTznovQAI2" + "EzHrBysN59cPHMutuAETJRgmIsNH4WktYz9ANSQiFSpBJRnO6a8sDMud9q+0ajemxRHz5DP9CkaenSQiseKCcTZ400R1NTU3" + "NxWWdC+s58oJrFpSn9Ugp3IfUBSY1doZOo2hSKFBlPz5vB3ZET2c76oaEhvX5OriOzNifeL8SxkAUeRRUhDBtirR7K0zQtFg" + "Wh6v2CNsBY7aHpCtuE595m+2L7o7deRUOTkx0dkKgxr30NXF/Jb1Dn1pJVDPHmZLBEVhv2YMkq9RYFXowzh8katF428qhtXw" + "YHBzdsvRM1w5nq8LvcCEg/98vvp/e2m0EMtDsiECEav9/lREC/nqeX5xk8td3cq78iHOcnv9Pt9vvdkKf+vOLkP9jtIv23eE" + "ZsG5hn43S3d0T9GY5+gjRut9Pvn+zQ1627K3h8TYhI7zkwenF1E0/aMUE8KRYXMYq5BEYyWAK6Z/GcDNo2kIZOb970jvScgT" + "m3y40F8gzVRUqdkvNlLXEwgF48j8BIkr9RJGCxpwAhHbzGoIhi1YAr6GHYwuPMA2sZuLUnWECEQPwOOmUaL4VaI+PN7oPqQd" + "uXjZvT09039yM9EyKP0++uxwHELbrapABh0ACS4jTgsmgIottghghr81bAPqZAwUJ4wbkGsApAeQoXyP0VsVyaMBe8gAVkIu" + "oFJBG1gjKXiqs4Ntws/pyN7GKcXswDOlxOjDOpl9mBBRVURIrSpix2hlFmgTah5aDHehMU40soClqfx6cpBqKqJAeuFapsNA" + "+3u7MQRH6AMF1rgAUQHkW2zBY5xmzgSJ/Hkg80vy9PjOzyOGoYFvVOl9Ppd002uJYGVj+xbBlq6VploIypMqdLe2CRziS9FW" + "OKYgLAx3h9wMcai8AbIDxJVQDpxw4iJIP0Y4hzQcAGimaSSt2WAXurSAXSLe7v6nuMgz1e73a5/B3xJvlUyeQJcEVwSlIV0T" + "6YtcES4omUFJmyilUZIgZTMmKJmqwcPC97jnmAmcKcPQdZ3dU5dQ31k8oykQBhtBOmRF5RejRYNK3/j6l71GohRg/om8RlnK" + "NZGPsNmgKEMBZMoJxOl2HwTZLABMImYKSgUyXZc0CWgTkGggV0iZ+3hkASnM+bTMAKTV+TTJvJEFyvUgBz9Sfbz/1f9dy9rP" + "+9sf/9/+e/BBgA4y6iYV7kockAAAAASUVORK5CYII=" + ""; + + printf("\n---\nTEST OMA PRES-CONTENT\n---\n"); + { + /* create oma-prescontent */ + omaprescont = xdm_oma_prescont_create(omaprescont_str, strlen(omaprescont_str)); + + /* dump */ + printf("\ndump pres-content\n"); + if(omaprescont) + { + printf("mime-type: \"%s\" encoding: \"%s\" description: \"%s\" data: \"%s\"\n", + omaprescont->mime_type, omaprescont->encoding, omaprescont->description, omaprescont->data); + } + /* free omaprescontent */ + xdm_oma_prescont_free(&omaprescont); + } +} \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_rlist.h b/trunk/tinyXCAP/test/test_rlist.h new file mode 100644 index 00000000..41878a16 --- /dev/null +++ b/trunk/tinyXCAP/test/test_rlist.h @@ -0,0 +1,176 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef TEST_RLIST_H +#define TEST_RLIST_H + +#include "xdm_api.h" + +/* http://www.gsmworld.com/documents/rcs/rcs2_june09/R2_090831_RCS_Release_2_Technical_Realisation_v1_0.pdf subclause 11.2*/ + const char* rlist_str0 = ""/*//xmnls:xd=\"urn:oma:xml:xdm:xcap-directory\"*/ + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "My presence buddies" + "" + "" + "" + "" + "" + "My blocked contacts" + "" + "" + "" + "My revoked contacts" + "" + "123457's display name" + "" + "" + "" + ""; + +/* test rlist (resource-lists) */ +void test_rlist(const char* rlist_str, size_t size) +{ + char* entry_str = 0; + xdm_rlist_t* rlist = 0; + xdm_list_t* list = 0; + xdm_list_item_t* item = 0; + + printf("\n---\nTEST RESOURCE-LISTS\n---\n"); + { + /* create rlist context */ + rlist = xdm_rlist_create(rlist_str, size); + + /* get all lists */ + printf("\nget all lists\n"); + if(list = xdm_rlist_get_all_lists(rlist, 0)) + { + xdm_list_foreach(item, list) + { + xdm_rlist_list_t *rlist_list = ((xdm_rlist_list_t*)item->data); + printf("name\"%s\" display-name=\"%s\"\n", rlist_list->name, rlist_list->display_name); + } + XDM_LIST_SAFE_FREE(list); + } + + /* get all entries in the list named 'ennemies' */ + printf("\nget all entries in the list named 'rcs_revokedcontacts'\n"); + if(list = xdm_rlist_get_entries_by_list(rlist, "rcs_revokedcontacts")) + { + xdm_list_foreach(item, list) + { + xdm_rlist_entry_t *entry = ((xdm_rlist_entry_t*)item->data); + printf("list:\"%s\" uri:\"%s\" display-name=\"%s\" last-modified\"%s\"\n", entry->list, entry->uri, entry->display_name, entry->last_modified); + entry_str = xdm_rlist_entry_serialize(entry); + printf("serialized entry: \n%s\n", entry_str); + XDM_SAFE_FREE(entry_str); + } + XDM_LIST_SAFE_FREE(list); + } + + /* get all externals in the list named 'friends' */ + printf("\nget all externals in the list named 'oma_blockedcontacts'\n"); + if(list = xdm_rlist_get_externals_by_list(rlist, "oma_blockedcontacts")) + { + xdm_list_foreach(item, list) + { + xdm_rlist_external_t *external = ((xdm_rlist_external_t*)item->data); + printf("list:\"%s\" anchor:\"%s\"\n", external->list, external->anchor); + } + XDM_LIST_SAFE_FREE(list); + } + + /* free rlist */ + xdm_rlist_free(&rlist); + } +} + +void test_rlist2(const char* rlist_str, size_t size) +{ + char* entry_str = 0; + xdm_rlist_t* rlist = 0; + xdm_list_t* list = 0; + xdm_list_item_t *item1 = 0, *item2 = 0, *item3 = 0; + + printf("\n---\nTEST RESOURCE-LISTS-2\n---\n"); + { + /* create rlist context */ + rlist = xdm_rlist_create(rlist_str, size); + + /* get all lists */ + printf("\nget all lists\n"); + if(1 && (list = xdm_rlist_get_all_lists(rlist, 1))) + { + xdm_list_foreach(item1, list) + { + xdm_rlist_list2_t *rlist_list2 = ((xdm_rlist_list2_t*)item1->data); + + /* name and display-name */ + printf("name\"%s\" display-name=\"%s\"\n", rlist_list2->name, rlist_list2->display_name); + + /* entries */ + xdm_list_foreach(item2, rlist_list2->entries) + { + xdm_rlist_entry_t *entry = ((xdm_rlist_entry_t*)item2->data); + char* entry_str = xdm_rlist_entry_serialize(entry); + printf("\n%s\n", entry_str); + XDM_FREE(entry_str); + } + + /*externals*/ + xdm_list_foreach(item3, rlist_list2->externals) + { + xdm_rlist_external_t *external = ((xdm_rlist_external_t*)item3->data); + char* external_str = xdm_rlist_external_serialize(external); + printf("\n%s\n", external_str); + XDM_FREE(external_str); + } + + } + XDM_LIST_SAFE_FREE(list); + } + + /* free rlist */ + xdm_rlist_free(&rlist); + } +} + +#endif /* TEST_RLIST_H */ \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_rls.h b/trunk/tinyXCAP/test/test_rls.h new file mode 100644 index 00000000..8fadcda4 --- /dev/null +++ b/trunk/tinyXCAP/test/test_rls.h @@ -0,0 +1,80 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_api.h" + +#ifndef TEST_RLS_SERVICES +#define TEST_RLS_SERVICES + +const char* rls_str0 = "" + "" + "" + "http://xcap1.gsma.com/services/resource-lists/users/sip:1234578901@gsma.org/index/~~/resource-lists/list%5B@name=%22rcs%22%5D" + "" + "presence" + "" + "" + "" + "http://xcap2.gsma.com/services/resource-lists/users/sip:1234578901@gsma.org/index/~~/resource-lists/list%5B@name=%22rcs%22%5D" + "" + "mypackage" + "" + "" + ""; + +/* test rls-services */ +void test_rls_services(const char* buffer, size_t size) +{ + xdm_rls_t* rls = 0; + xdm_list_item_t* item = 0; + xdm_list_t *list = 0; + printf("\n---\nTEST RLS-SERVICES\n---\n"); + { + /* create rls context */ + rls = xdm_rls_create(buffer, size); + + /* get all services */ + list = xdm_rls_get_all_services(rls); + + /* dump services */ + xdm_list_foreach(item, list) + { + xdm_rls_service_t *rls_service = ((xdm_rls_service_t*)item->data); + char* rls_service_str = xdm_rls_service_serialize(rls_service); + printf("\n%s\n", rls_service_str); + XDM_SAFE_FREE(rls_service_str); + } + + /* free services */ + XDM_LIST_SAFE_FREE(list); + + /* free rls context */ + xdm_rls_free(&rls); + } +} + +#endif /* TEST_RLS_SERVICES */ \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_selector.h b/trunk/tinyXCAP/test/test_selector.h new file mode 100644 index 00000000..0d540ffe --- /dev/null +++ b/trunk/tinyXCAP/test/test_selector.h @@ -0,0 +1,137 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef TEST_SELECTOR_H +#define TEST_SELECTOR_H + +#include "xdm_api.h" + +/* test xcap selector */ +void test_selector() +{ + xdm_context_t* context; + xdm_request_t* request; + + /* create our xdm context */ + XDM_CONTEXT_CREATE(context); + + printf("---\nTEST XCAP SELECTOR\n---\n"); + + context->user_agent = xdm_strdup("XDM-client/OMA1.1"); + context->xdm_root = xdm_strdup("http://xcap.example.com:8080/services"); + context->password = xdm_strdup("mysecret"); + context->xui = xdm_strdup("sip:doubango@example.com"); + + /* IETF server capabilities */ + request = xdm_doc_get_sel(context, ietf_xcap_caps); + printf("Server capabilities url: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* IETF resource-list */ + request = xdm_doc_get_sel(context, ietf_resource_lists); + printf("IETF resource-list: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve list named 'Default' in the resource list */ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "Default"), //==> /resource-lists/list[@name="Default"] + XDM_NODE_SELECT_END() + ); + printf("Retrieve list named 'Default' in the resource list: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve the second list in the resource list */ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_POS("list", 2), //==> /resource-lists/list[2] + XDM_NODE_SELECT_END() + ); + printf("Retrieve the second list in the resource list: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve the fourth list in the resource list(using wildcard!!!)*/ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_POS("*", 4), //==> /resource-lists/*[4] + XDM_NODE_SELECT_END() + ); + printf("Retrieve the fourth list in the resource list(using wildcard!!!): \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve an entry with uri equals to 'sip:doubango@example.com' into a list named 'Ennemies' in the resource list */ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "Ennemies"),//==> /resource-lists/list[@name="Ennemies"] + XDM_NODE_SELECT_BY_ATTR("entry", "uri", "sip:doubango@example.com"),//==> /resource-lists/list[@name="Ennemies"]/entry[@uri="sip:doubango@example.com"] + XDM_NODE_SELECT_END() + ); + printf("Retrieve an entry with an uri equals to 'sip:doubango@example.com' into a list named 'Ennemies': \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve doubango's display-name (we suppose doubango is a friend) */ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "Friends"),//==> /resource-lists/list[@name="Friends"] + XDM_NODE_SELECT_BY_ATTR("entry", "uri", "sip:doubango@example.com"),//==> /resource-lists/list[@name="Friends"]/entry[@uri="sip:doubango@example.com"] + XDM_NODE_SELECT_BY_NAME("display-name"),//==> /resource-lists/list[@name="Friends"]/entry[@uri="sip:doubango@example.com"]/display-name + XDM_NODE_SELECT_END() + ); + printf("Retrieve doubango's display-name (we suppose doubango is a friend): \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve the display-name of the first entry in the list of the Ennemies*/ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "Friends"),//==> /resource-lists/list[@name="Friends"] + XDM_NODE_SELECT_BY_POS("entry", 1),//==> /resource-lists/list[@name="Friends"]/entry[1] + XDM_NODE_SELECT_BY_NAME("display-name"),//==> /resource-lists/list[@name="Friends"]/entry[1]/display-name + XDM_NODE_SELECT_END() + ); + printf("Retrieve the display-name of the first entry in the list of the Ennemies: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Retrieve an entry with uri equals to 'sip:doubango@example.com' at position 23 into a list named 'Ennemies' in the resource list */ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "Ennemies"),//==> /resource-lists/list[@name="Ennemies"] + XDM_NODE_SELECT_BY_POS_ATTR("entry", 23, "uri", "sip:doubango@example.com"),//==> /resource-lists/list[@name="Ennemies"]/entry[23][@uri="sip:doubango@example.com"] + XDM_NODE_SELECT_END() + ); + printf("Retrieve an entry with uri equals to 'sip:doubango@example.com' at position 23 into a list named 'Ennemies' in the resource list: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* Namespace test */ + /* /foo/a:bar/b:baz?xmlns(a=urn:test:namespace1-uri)xmlns(b=urn:test:namespace2-uri)*/ + request = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_NAME("foo"),//==> /foo + XDM_NODE_SELECT_BY_NAME("a:bar"),//==> /foo/a:bar + XDM_NODE_SELECT_BY_NAME("b:baz"),//==> /foo/a:bar/b:baz + XDM_NODE_ADD_NAMESPACE("a", "urn:test:namespace1-uri"),//==>/foo/a:bar/b:baz?xmlns(a=urn:test:namespace1-uri) + XDM_NODE_ADD_NAMESPACE("b", "urn:test:namespace2-uri"),//==>/foo/a:bar/b:baz?xmlns(a=urn:test:namespace1-uri)xmlns(b=urn:test:namespace2-uri) + XDM_NODE_SELECT_END() + ); + printf("Namespace test: \n%s\n***\n", request->url); + XDM_REQUEST_SAFE_FREE(request); + + /* free allocated memory*/ + XDM_REQUEST_SAFE_FREE(request); + XDM_CONTEXT_SAFE_FREE(context); +} +#endif /* TEST_SELECTOR_H */ \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_xcap-caps.h b/trunk/tinyXCAP/test/test_xcap-caps.h new file mode 100644 index 00000000..d449b03c --- /dev/null +++ b/trunk/tinyXCAP/test/test_xcap-caps.h @@ -0,0 +1,76 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_api.h" + +#ifndef TEST_XCAP_CAPS +#define TEST_XCAP_CAPS +const char* xcap_caps_str0 = "" + "" + " " + " xcap-caps" + " resource-lists" + " rls-services" + " org.openmobilealliance.xcap-directory" + " " + "" + " " + " " + "" + " urn:ietf:params:xml:ns:xcap-caps" + " urn:ietf:params:xml:ns:xcap-error" + " urn:ietf:params:xml:ns:resource-lists" + " urn:ietf:params:xml:ns:rls-services" + " urn:oma:params:ns:resource-list:oma-uriusage" + " " + ""; + +/* test xcap-caps */ +void test_xcap_caps(const char* buffer, size_t size) +{ + xcap_caps_t* xcap_caps = 0; + xdm_list_item_t* item = 0; + printf("\n---\nTEST XCAP-CAPS\n---\n"); + { + xcap_caps = xdm_xcap_caps_create(buffer, size); + + /* dump namespaces */ + xdm_list_foreach(item, xcap_caps->namespaces) + printf("namespace: %s\n", ((char*)item->data)); + /* dump extensions */ + xdm_list_foreach(item, xcap_caps->extensions) + printf("extension: %s\n", ((char*)item->data)); + /* dump auids */ + xdm_list_foreach(item, xcap_caps->auids) + printf("auid: %s\n", ((char*)item->data)); + + xdm_xcap_caps_free(&xcap_caps); + } +} +#endif \ No newline at end of file diff --git a/trunk/tinyXCAP/test/test_xcap.h b/trunk/tinyXCAP/test/test_xcap.h new file mode 100644 index 00000000..a43c2508 --- /dev/null +++ b/trunk/tinyXCAP/test/test_xcap.h @@ -0,0 +1,305 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_api.h" + +#include "test_xcap-caps.h" +#include "test_rls.h" +#include "test_rlist.h" +#include "test_gsma_rcs.h" + +#ifndef TEST_XCAP +#define TEST_XCAP + +#define TEST_XCAP_CONTEXT_INIT(context) \ + context->user_agent = xdm_strdup("XDM-client/OMA1.1"); \ + context->xdm_root = xdm_strdup("http://192.168.0.14:8080/services"); \ + context->password = xdm_strdup("doubango"); \ + context->xui = xdm_strdup("sip:doubango@example.com"); \ + context->pragma = xdm_strdup("keep-alive"); + +/* delete all documents */ +void testxcap_deleteall(xdm_context_t *context) +{ + xdm_list_item_t* item = 0; + + xdm_list_foreach(item, context->auids) + { + xdm_auid_t *auid = ((xdm_auid_t*)item->data); + if(auid->available && auid->type != ietf_xcap_caps) + { + xdm_request_t *request= xdm_doc_get_sel(context, auid->type); + xdm_xcap_perform(context, request, op_delete, sl_document); + XDM_REQUEST_SAFE_FREE(request); + } + } +} + +/* test xcap-caps + - get xcap-caps documents + - update available auids +*/ +int testxcap_xcap_caps(xdm_context_t *context) +{ + xdm_request_t* request = 0; + xcap_caps_t* xcap_caps = 0; + int ret = 0, error = 0; + + /* create request */ + request= xdm_doc_get_sel(context, ietf_xcap_caps); + + /* ge content from the xdms */ + if((error = xdm_xcap_perform(context, request, op_fetch, sl_document)) || !XDM_HTTP_SUCCESS(request)) + { + printf("xcap-caps error:%d status:%d\n", error, request->status); + goto bail; /* xcap-caps is mandatory */ + } + else if(request->content) + { + /* update available auids */ + xcap_caps = xdm_xcap_caps_create(request->content->data, request->content->size); + xdm_conttext_update_available_auids(context, xcap_caps->auids); + + ret = 1; + } + else goto bail; + +bail: + /* free request */ + XDM_REQUEST_SAFE_FREE(request); + + /* free xcap-caps */ + xdm_xcap_caps_free(&xcap_caps); + + return ret; +} + +/* test oma directory + - get oma dir document if supported + - update documents names +*/ +int testxcap_omadir(xdm_context_t *context) +{ + xdm_request_t* request = 0; + xdm_omadir_t* omadir = 0; + int ret = 0, error = 0; + + /* check if oma-dir is supported by the xdms */ + if(!xdm_auid_is_available(context->auids, oma_directory)) + { + printf("oma-directory not available\n"); + return 0; + } + + /* create request */ + request= xdm_doc_get_sel(context, oma_directory); + + /* ge content from the xdms */ + if((error = xdm_xcap_perform(context, request, op_fetch, sl_document)) || !XDM_HTTP_SUCCESS(request)) + { + printf("oma-directory error:%d status:%d\n", error, request->status); + goto bail; /* xcap-caps is mandatory */ + } + else if(request->content) + { + /* update document names */ + omadir = xdm_omadir_create(request->content->data, request->content->size); + /* TODO */ + ret = 1; + } + else goto bail; + +bail: + /* free request */ + XDM_REQUEST_SAFE_FREE(request); + + /* free omadir */ + xdm_omadir_free(&omadir); + + return ret; +} + +/* test resource-lists + - get resource-lists document or create it if does not exist + - add an entry + - modify the entry display-name + - delete the entry +*/ +int testxcap_rlist(xdm_context_t *context) +{ + xdm_request_t* request = 0; + int ret = 0, error = 0; + + /* check resource-lists availability*/ + if(!xdm_auid_is_available(context->auids, ietf_resource_lists)) + { + printf("\nresource-lists not available\n"); + return 0; + } + + /* create our request */ + request = xdm_doc_get_sel(context, ietf_resource_lists); + + /* get document from the xdms */ + if((error = xdm_xcap_perform(context, request, op_fetch, sl_document)) || !XDM_HTTP_SUCCESS(request)) + { + if(request->status == 404) + { + /* create new resource-lists document as per gsma rcs specs */ + xdm_rlist_list2_L_t* rlist2 = xdm_gsmarcs_create_rlist2(context); + char *rlist2_str = xdm_rlist_rlist2_serialize(rlist2); + xdm_content_set(request->content, (const char*)rlist2_str, strlen(rlist2_str), 0);/* set content */ + XDM_SAFE_FREE(rlist2_str); + XDM_LIST_SAFE_FREE(rlist2); + + /* send content to the xdms */ + if((error = xdm_xcap_perform(context, request, op_create, sl_document)) || !XDM_HTTP_SUCCESS(request)) + { + /* we cannot create the document ==> set the corresponding auid as unavailable */ + // xdm_auid_set_availability(context->auids, ietf_resource_lists, 0); + goto bail; + } + } + else + { + printf("resource-lists error:%d status:%d\n", error, request->status); + goto bail; + } + } + else if(request->content) + { + /* deserialize and dump */ + //test_rlist2(request->content->data, request->content->size); + + /** add entry **/ + { + xdm_request_t *r1 = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "all"), + XDM_NODE_SELECT_BY_ATTR("entry", "uri", "sip:doubango@example.com"), + XDM_NODE_SELECT_END() + ); + char* entry_str = xdm_rlist_entry_serialize2("sip:doubango@example.com", "doubango"); + xdm_content_set(r1->content, entry_str, strlen(entry_str), 0); + XDM_SAFE_FREE(entry_str); + + /* send the request to the server */ + if((error = xdm_xcap_perform(context, r1, op_create, sl_element)) || !XDM_HTTP_SUCCESS(r1)) + { + printf("failed to add an entry error:%d status:%d\n", error, request->status); + XDM_REQUEST_SAFE_FREE(r1); + goto bail; + } + XDM_REQUEST_SAFE_FREE(r1); + } + + /** change the entry's display-name **/ + { + xdm_request_t *r1 = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "all"), + XDM_NODE_SELECT_BY_ATTR("entry", "uri", "sip:doubango@example.com"), + //XDM_NODE_SELECT_BY_NAME("display-name"), + XDM_NODE_SELECT_END() + ); + char* entry_str = xdm_rlist_entry_serialize2("sip:doubango@example.com", "doubango2"); + xdm_content_set(r1->content, entry_str, strlen(entry_str), 0); + XDM_SAFE_FREE(entry_str); + + /* send the request to the server */ + if((error = xdm_xcap_perform(context, r1, op_replace, sl_element)) || !XDM_HTTP_SUCCESS(r1)) + { + printf("failed to update an entry error:%d status:%d\n", error, request->status); + XDM_REQUEST_SAFE_FREE(r1); + goto bail; + } + XDM_REQUEST_SAFE_FREE(r1); + } + + /** delete the entry **/ + { + xdm_request_t *r1 = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "all"), + XDM_NODE_SELECT_BY_ATTR("entry", "uri", "sip:doubango@example.com"), + XDM_NODE_SELECT_END() + ); + /* send the request to the server */ + if((error = xdm_xcap_perform(context, r1, op_delete, sl_element)) || !XDM_HTTP_SUCCESS(r1)) + { + printf("failed to delete an entry error:%d status:%d\n", error, request->status); + XDM_REQUEST_SAFE_FREE(r1); + goto bail; + } + XDM_REQUEST_SAFE_FREE(r1); + } + + /** add list **/ + { + xdm_request_t *r1 = xdm_node_get_sel(context, ietf_resource_lists, + XDM_NODE_SELECT_BY_ATTR("list", "name", "newlist"), + XDM_NODE_SELECT_END() + ); + char* list_str = xdm_rlist_list_serialize2("newlist", "newlist"); + xdm_content_set(r1->content, list_str, strlen(list_str), 0); + XDM_SAFE_FREE(list_str); + + /* send the request to the server */ + if((error = xdm_xcap_perform(context, r1, op_create, sl_element)) || !XDM_HTTP_SUCCESS(r1)) + { + printf("failed to add a list error:%d status:%d\n", error, request->status); + XDM_REQUEST_SAFE_FREE(r1); + goto bail; + } + XDM_REQUEST_SAFE_FREE(r1); + } + + } + else goto bail; + +bail: + + /* free request */ + XDM_REQUEST_SAFE_FREE(request); + + return ret; +} + +/* testing xcap*/ +void test_xcap() +{ + xdm_context_t *context = 0; + XDM_CONTEXT_CREATE(context); + TEST_XCAP_CONTEXT_INIT(context); + context->reuse_http_connection = 1; + + testxcap_xcap_caps(context); + //testxcap_deleteall(context); + //testxcap_omadir(context); + testxcap_rlist(context); + + XDM_CONTEXT_SAFE_FREE(context); +} + +#endif /* TEST_XCAP */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP.sln b/trunk/tinyXCAP/tinyXCAP.sln new file mode 100644 index 00000000..ec960413 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyXCAP", "tinyXCAP\tinyXCAP.vcproj", "{1D1FA376-E30F-40B0-99FF-CF305A1D380C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcproj", "{7925B577-FB9B-44E4-B21C-200411298AB7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + Release|Win32 = Release|Win32 + Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Debug|Win32.ActiveCfg = Debug|Win32 + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Debug|Win32.Build.0 = Debug|Win32 + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Build.0 = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Deploy.0 = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Release|Win32.ActiveCfg = Release|Win32 + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Release|Win32.Build.0 = Release|Win32 + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Build.0 = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {1D1FA376-E30F-40B0-99FF-CF305A1D380C}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Deploy.0 = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {7925B577-FB9B-44E4-B21C-200411298AB7}.Debug|Win32.ActiveCfg = Debug|Win32 + {7925B577-FB9B-44E4-B21C-200411298AB7}.Debug|Win32.Build.0 = Debug|Win32 + {7925B577-FB9B-44E4-B21C-200411298AB7}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {7925B577-FB9B-44E4-B21C-200411298AB7}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Build.0 = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {7925B577-FB9B-44E4-B21C-200411298AB7}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Deploy.0 = Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {7925B577-FB9B-44E4-B21C-200411298AB7}.Release|Win32.ActiveCfg = Release|Win32 + {7925B577-FB9B-44E4-B21C-200411298AB7}.Release|Win32.Build.0 = Release|Win32 + {7925B577-FB9B-44E4-B21C-200411298AB7}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {7925B577-FB9B-44E4-B21C-200411298AB7}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Build.0 = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + {7925B577-FB9B-44E4-B21C-200411298AB7}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Deploy.0 = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I) + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/trunk/tinyXCAP/tinyXCAP/src/tinyxcap_config.h b/trunk/tinyXCAP/tinyXCAP/src/tinyxcap_config.h new file mode 100644 index 00000000..711c42a0 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/tinyxcap_config.h @@ -0,0 +1,46 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef TINYXCAP_CONFIG_H +#define TINYXCAP_CONFIG_H + +#if (defined(WIN32) || defined(__SYMBIAN32__)) && defined(TINYXCAP_EXPORTS) +# define TINYXCAP_API __declspec(dllexport) +#elif (defined(WIN32) || defined(__SYMBIAN32__)) && defined(TINYXCAP_IMPORTS) +# define TINYXCAP_API __declspec(dllimport) +#else +# define TINYXCAP_API +#endif + +// +// Disable some well-known warnings +// +#ifdef _MSC_VER +# define _CRT_SECURE_NO_WARNINGS +#endif + +#endif // TINYXCAP_CONFIG_H diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm.c b/trunk/tinyXCAP/tinyXCAP/src/xdm.c new file mode 100644 index 00000000..35e68a97 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm.c @@ -0,0 +1,498 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm.h" +#include "xdm_utils.h" + +#define PANIC_AND_JUMP(code, request)\ + {\ + request->panic = code; \ + goto bail;\ + } + +/* get content type */ +static const char* get_mime_type(const xdm_context_t* context, const xdm_request_t* request, xdm_selection_type_t sel) +{ + /* return the user provided content type */ + if(request && request->content && request->content->type) return request->content->type; + + switch(sel) + { + case sl_element:return XDM_MIME_TYPE_ELEMENT; + case sl_document: + { + const xdm_auid_t* auid = xdm_auid_findby_name(context->auids, request->auid); + return auid?auid->content_type:"application/unknown+xml"; + } + case sl_attribute:return XDM_MIME_TYPE_ATTRIBUTE; + default: return "application/unknown+xml"; + }/* switch */ +} + +/* init content */ +void xdm_content_init(xdm_content_t *content) +{ + memset(content, 0, sizeof(xdm_content_t)); +} + +/* set content values */ +void xdm_content_set(xdm_content_t* content, const char *data, size_t size, const char *type) +{ + if(content) + { + xdm_strupdate(&(content->data), data); + xdm_strupdate(&(content->type), type); + content->size = size; + } +} + +/* free content */ +void xdm_content_free(xdm_content_t** content) +{ + if(*content) + { + XDM_FREE((*content)->data); + XDM_FREE((*content)->type); + + free(*content); + (*content) = 0; + } +} + +/* init auid */ +void xdm_auid_init(xdm_auid_t *auid) +{ + memset(auid, 0, sizeof(xdm_auid_t)); +} + +/* find auid object by type */ +xdm_auid_t* xdm_auid_findby_type(const xdm_auid_L_t* auids, xcap_auid_type_t auid_type) +{ + xdm_list_item_t* item = 0; + + if(!auids) return 0; + + xdm_list_foreach(item, auids) + { + xdm_auid_t *auid = ((xdm_auid_t*)item->data); + if(auid->type == auid_type) + { + return auid; + } + } + return 0; +} + +/* find auid object by type */ +xdm_auid_t* xdm_auid_findby_name(const xdm_auid_L_t* auids, const char* name) +{ + xdm_list_item_t* item = 0; + + if(!auids) return 0; + + xdm_list_foreach(item, auids) + { + xdm_auid_t *auid = ((xdm_auid_t*)item->data); + if(!xdm_stricmp(auid->name, name)) + { + return auid; + } + } + return 0; +} + +/* returns 1 if availabe and 0 otherwise */ +int xdm_auid_is_available(const xdm_auid_L_t* auids, xcap_auid_type_t type) +{ + const xdm_auid_t *auid = xdm_auid_findby_type(auids, type); + return (auid && auid->available) ? 1 : 0; +} + +/* change auid availability */ +void xdm_auid_set_availability(const xdm_auid_L_t* auids, xcap_auid_type_t type, int avail) +{ + xdm_auid_t* auid = xdm_auid_findby_type(auids, type); + if(auid) + { + auid->available = avail; + } +} + +/* change the document name of the auid with type=@type */ +void xdm_auid_update(xdm_context_t* context, xcap_auid_type_t type, const char* document) +{ + xdm_auid_t* auid = xdm_auid_findby_type(context->auids, type); + if(auid) + { + xdm_strupdate(&(auid->document), document); + } +} + +/* free auid */ +void xdm_auid_free(void **_auid) +{ + xdm_auid_t **auid = (xdm_auid_t **)_auid; + XDM_FREE((*auid)->name); + XDM_FREE((*auid)->description); + XDM_FREE((*auid)->content_type); + XDM_FREE((*auid)->document); + + free(*_auid); + (*_auid) = 0; +} + +/* initialize xdm context */ +/* ATTENTION: context MUST be initialized before use*/ +void xdm_context_init(xdm_context_t* context) +{ + int i; + + memset(context, 0, sizeof(xdm_context_t)); + + /* copy all default auids */ + XDM_LIST_CREATE(context->auids); + for(i = 0; i< (sizeof(xdm_auids)/sizeof(xdm_auid_t)); i++) + { + xdm_auid_t* auid = 0; + XDM_AUID_CREATE(auid); + + auid->type = xdm_auids[i].type; + auid->available = xdm_auids[i].available; + auid->content_type = xdm_strdup(xdm_auids[i].content_type); + auid->description = xdm_strdup(xdm_auids[i].description); + auid->document = xdm_strdup(xdm_auids[i].document); + auid->name = xdm_strdup(xdm_auids[i].name); + + xdm_list_add_data((context->auids), ((void**)&auid), xdm_auid_free); + } + + /* initialize libcurl */ +#ifdef WIN32 + curl_global_init(CURL_GLOBAL_WIN32); +#else + curl_global_init(); +#endif +} + +/* update available auids using those provided by the xdms */ +void xdm_conttext_update_available_auids(xdm_context_t *context, const xdm_list_t* avail_auids) +{ + xdm_list_item_t *item = 0; + + if(!context || !avail_auids) return; + + /* avail auids */ + xdm_list_foreach(item, avail_auids) + { + /* context auids */ + xdm_auid_t* auid = xdm_auid_findby_name(context->auids, ((const char*)item->data)); + if(auid && !(auid->available)) auid->available = 1; + } +} + +/* free a previously initialized context */ +void xdm_context_free(xdm_context_t** context) +{ + XDM_FREE((*context)->xdm_root); + XDM_FREE((*context)->xui); + XDM_FREE((*context)->password); + XDM_FREE((*context)->proxy_host); + XDM_FREE((*context)->proxy_usr); + XDM_FREE((*context)->proxy_pwd); + XDM_FREE((*context)->user_agent); + XDM_FREE((*context)->pragma); + XDM_LIST_SAFE_FREE((*context)->auids); + XDM_EASYHANDLE_SAFE_FREE((*context)->easyhandle); + + free(*context); + (*context) = 0; + + /* cleanup libcurl */ + curl_global_cleanup(); +} + +/* initialize xdm request */ +/* ATTENTION: request MUST be initialized before use*/ +void xdm_request_init(xdm_request_t* request) +{ + memset(request, 0, sizeof(xdm_request_t)); + XDM_CONTENT_CREATE(request->content); + + request->status = 0; + request->panic = xpa_success; + request->timeout = XDM_HTTP_DEFAULT_TIMEOUT; +} + +/* free a previously initialized request */ +void xdm_request_free(xdm_request_t** request) +{ + XDM_FREE((*request)->auid); + XDM_FREE((*request)->url); + XDM_FREE((*request)->http_accept); + XDM_FREE((*request)->http_expect); + XDM_CONTENT_SAFE_FREE((*request)->content); + + free(*request); + (*request) = 0; +} + +/* libcurl write callback */ +size_t write_data(void *buffer, size_t size, size_t nmemb, xdm_content_t *userp) +{ + size_t total_size = (size * nmemb); + if(!userp) return -1; + + /* new chinck ==> realloc */ + userp->data = (char *)realloc(userp->data, (1 + userp->size + total_size)); + if (userp->data) + { /* append new chunck */ + memcpy(userp->data + userp->size, buffer, total_size); + userp->size += total_size; + userp->data[userp->size] = '\0'; + } + return total_size; +} + +/* libcurl read callback */ +size_t read_data(void *buffer, size_t size, size_t nmemb, xdm_content_t *userp) +{ + size_t bytes_to_copy = 0; + if(!userp) return -1; + + if(userp->cursor >= userp->size) return 0; + + bytes_to_copy = nmemb < userp->size ? nmemb : userp->size; + memcpy(buffer, userp->data, bytes_to_copy); + userp->cursor += bytes_to_copy; + return bytes_to_copy; +} + +/* ioctl function to handle HTTP PUT or POST with a multi-pass authentication method */ +curlioerr ioctl_callback(CURL *handle, int cmd, xdm_content_t *userp) +{ + switch (cmd) + { + case CURLIOCMD_NOP: return CURLIOE_OK; + case CURLIOCMD_RESTARTREAD: + { + userp->cursor = 0; + return CURLIOE_OK; + } + default: return CURLIOE_UNKNOWNCMD; + } +} + +/* perform xcap operation */ +/* returns 0 if success and false otherwise. check request panic code for more information */ +/* if request panic code is equal to 'xpa_libcurl_error', then you should check the return code*/ +int xdm_xcap_perform(xdm_context_t* context, xdm_request_t* request, xdm_oper_type_t oper, xdm_selection_type_t sel) +{ + struct curl_slist *headers = 0; + CURLcode code = CURLE_OK; + char* temp_str = 0; + + /* check context */ + XDM_CONTEXT_CHECK(context, request->panic); + + /* Get an easy handle */ + if(!context->easyhandle) context->easyhandle = curl_easy_init(); + else if(!(context->reuse_http_connection)){ + curl_easy_cleanup(context->easyhandle); + context->easyhandle = curl_easy_init(); + } + if(!context->easyhandle) PANIC_AND_JUMP(xpa_libcurl_error, request) + +#if DEBUG || _DEBUG + curl_easy_setopt(context->easyhandle, CURLOPT_VERBOSE, 1); +#endif + + /* set xcap URL */ + if(request->url && (code=curl_easy_setopt(context->easyhandle, CURLOPT_URL, request->url))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set request timeout */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_TIMEOUT, request->timeout/1000)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + switch(oper) + { + case op_fetch: + { /* GET */ + curl_easy_setopt(context->easyhandle, CURLOPT_CUSTOMREQUEST, "GET"); + + /* tell libcurl to pass all data to this function */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_WRITEFUNCTION, write_data)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set data for our callback */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_WRITEDATA, (request->content))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + break; + } + + case op_create: + case op_replace: + { /* PUT */ + curl_easy_setopt(context->easyhandle, CURLOPT_CUSTOMREQUEST, "PUT"); + + /* read callback */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_READFUNCTION, read_data)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_UPLOAD, 1L)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* content */ + if(request->content && request->content->data && request->content->size) + { + /* content data*/ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_READDATA , (request->content))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* content length */ + xdm_sprintf(&temp_str, "Content-Length: %u", request->content->size); + headers = curl_slist_append(headers, temp_str); + XDM_SAFE_FREE(temp_str); + + /* ioctl function callback */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_IOCTLFUNCTION , ioctl_callback)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* ioctl data */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_IOCTLDATA , (request->content))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + } + break; + } + + case op_delete: + { /* DELETE */ + curl_easy_setopt(context->easyhandle, CURLOPT_CUSTOMREQUEST, "DELETE"); + break; + } + }/* switch */ + + /* set user name */ + if(context->xui && (code=curl_easy_setopt(context->easyhandle, CURLOPT_USERNAME, context->xui))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set user password */ + if(context->password && (code=curl_easy_setopt(context->easyhandle, CURLOPT_PASSWORD, context->password))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* authentication type */ + if((code=curl_easy_setopt(context->easyhandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY)) || + (code=curl_easy_setopt(context->easyhandle, CURLOPT_PROXYAUTH, CURLAUTH_ANY))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set user-agent */ + if(context->user_agent && (code=curl_easy_setopt(context->easyhandle, CURLOPT_USERAGENT, context->user_agent))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* X-3GPP-Intended-Identity */ + xdm_sprintf(&temp_str, "X-3GPP-Intended-Identity: \"%s\"", context->xui); + headers = curl_slist_append(headers, temp_str); + XDM_SAFE_FREE(temp_str); + + /* Content-Type */ + xdm_sprintf(&temp_str, "Content-Type: %s", get_mime_type(context, request, sel)); + headers = curl_slist_append(headers, temp_str); + XDM_SAFE_FREE(temp_str); + + /* set proxy host */ + if(context->proxy_host && (code=curl_easy_setopt(context->easyhandle, CURLOPT_PROXY, context->proxy_host))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set proxy port */ + if(context->proxy_port && (code=curl_easy_setopt(context->easyhandle, CURLOPT_PROXYPORT, context->proxy_port))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set proxy usr*/ + if(context->proxy_usr && (code=curl_easy_setopt(context->easyhandle, CURLOPT_PROXYUSERNAME, context->proxy_usr))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* set proxy pwd */ + if(context->proxy_pwd && (code=curl_easy_setopt(context->easyhandle, CURLOPT_PROXYPASSWORD, context->proxy_pwd))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* http proxy tunneling? */ + if(context->proxy_tunneling && (code=curl_easy_setopt(context->easyhandle, CURLOPT_HTTPPROXYTUNNEL, 1L))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* Pragma */ + if(context->pragma) + { + xdm_sprintf(&temp_str, "Pragma: %s", context->pragma); + headers = curl_slist_append(headers, temp_str); + XDM_SAFE_FREE(temp_str); + } + + /* Accept */ + if(request->http_accept) + { + xdm_sprintf(&temp_str, "Accept: \"%s\"", request->http_accept); + headers = curl_slist_append(headers, temp_str); + XDM_SAFE_FREE(temp_str); + } + else headers = curl_slist_append(headers, "Accept:"); + + + /* Expect */ + if(request->http_expect) + { + xdm_sprintf(&temp_str, "Expect: %s", request->http_expect); + headers = curl_slist_append(headers, temp_str); + XDM_SAFE_FREE(temp_str); + } + + /* pass our list of custom made headers */ + if(code=curl_easy_setopt(context->easyhandle, CURLOPT_HTTPHEADER, headers)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /*** perform operation ***/ + if(code=curl_easy_perform(context->easyhandle)) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* get response code */ + if(code=curl_easy_getinfo(context->easyhandle, CURLINFO_RESPONSE_CODE, &(request->status))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + + /* get response content-type */ + if(code=curl_easy_getinfo(context->easyhandle, CURLINFO_CONTENT_TYPE, (&temp_str))) + PANIC_AND_JUMP(xpa_libcurl_error, request) + else request->content->type = xdm_strdup((const char*)temp_str); + +bail: + + /* free the header list */ + curl_slist_free_all(headers); + + /* cleanup libcurl handle if !stateful*/ + if(!(context->reuse_http_connection)) + XDM_EASYHANDLE_SAFE_FREE(context->easyhandle); + + return code; +} \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm.h b/trunk/tinyXCAP/tinyXCAP/src/xdm.h new file mode 100644 index 00000000..86af7bcd --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm.h @@ -0,0 +1,281 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_H_ +#define _TINYXCAP_XDM_H_ + +#include "tinyxcap_config.h" +#include "xdm_list.h" + +#include +#include + +#include + +#define XDM_HTTP_DEFAULT_TIMEOUT 30000 +#define XDM_HTTP_SUCCESS(request) (200==request->status || 202==request->status) + +#define XDM_SAFE_FREE(ptr) if(ptr) {(void)free(ptr); ptr=0;} +#define XDM_FREE(ptr) if(ptr)free(ptr); +#define XDM_IS_EMPTY_STRING(str) (!str || !strlen(str)) + +#define XDM_DOCUMENT_GLOBAL(auid_type) (auid_type == ietf_xcap_caps) +#define XDM_MIME_TYPE_ELEMENT "application/xcap-el+xml" /* as per rfc 4825 subclause 15.2.1 */ +#define XDM_MIME_TYPE_ATTRIBUTE "application/xcap-att+xml" /* as per rfc 4825 subclause 15.2.2 */ +#define XDM_MIME_TYPE_NS "application/xcap-ns+xml" /* as per rfc 4825 subclause 15.2.3 */ +#define XDM_MIME_TYPE_ERROR "application/xcap-error+xml" /* as per rfc 4825 subclause 15.2.4 */ +#define XDM_MIME_TYPE_CAPS "application/xcap-caps+xml" /* as per rfc 4825 subclause 15.2.5 */ + +/* macro helpers to create/free structures */ +#define XDM_XXX_CREATE(xxx, prefix)\ + xxx = (xdm_##prefix##_t*)malloc(sizeof(xdm_##prefix##_t)); \ + xdm_##prefix##_init(xxx); +#define XDM_XXX_SAFE_FREE(xxx, prefix)\ + if(xxx) { xdm_##prefix##_free(&(xxx)); xxx = 0; } + +/* check context validity */ +#define XDM_CONTEXT_CHECK(context, panic) \ + if(!context->xdm_root) panic = xpa_invalid_root; \ + else if(!context->xui) panic = xpa_invalid_xui; \ + else panic = xpa_success; + +/* context */ +#define XDM_CONTEXT_CREATE(_context) XDM_XXX_CREATE(_context, context) +#define XDM_CONTEXT_SAFE_FREE(_context) XDM_XXX_SAFE_FREE(_context, context) + +/* request */ +#define XDM_REQUEST_CREATE(_request) XDM_XXX_CREATE(_request, request) +#define XDM_REQUEST_SAFE_FREE(_request) XDM_XXX_SAFE_FREE(_request, request) +#define XDM_REQUEST_RETURN_IF_PANIC(request)\ + if(!XDM_PANIC_SUCCESS(request->panic)) return request; + +/* content */ +#define XDM_CONTENT_CREATE(_content) XDM_XXX_CREATE(_content, content) +#define XDM_CONTENT_SAFE_FREE(_content) XDM_XXX_SAFE_FREE(_content, content) + +/* easyhandle */ +#define XDM_EASYHANDLE_SAFE_FREE(easyhandle) \ + if(easyhandle) { curl_easy_cleanup(easyhandle); easyhandle = 0; } + +/* auid */ +#define XDM_AUID_CHECK(auid, panic)\ + if(!auid) panic = xpa_unsupported_auid; +#define XDM_AUID_CREATE(_auid) XDM_XXX_CREATE(_auid, auid) +#define XDM_AUID_SAFE_FREE(_auid) XDM_XXX_SAFE_FREE(_auid, auid) + +#define XDM_PANIC_SUCCESS(panic) ( (panic == xpa_success) ) + + +/*Node Selector as per rfc 4825 subclause 6.3 +node-selector = element-selector ["/" terminal-selector] +terminal-selector = attribute-selector / namespace-selector / +extension-selector +element-selector = step *( "/" step) +step = by-name / by-pos / by-attr / by-pos-attr / +extension-selector +by-name = NameorAny +by-pos = NameorAny "[" position "]" +position = 1*DIGIT +attr-test = "@" att-name "=" att-value +by-attr = NameorAny "[" attr-test "]" +by-pos-attr = NameorAny "[" position "]" "[" attr-test "]" +NameorAny = QName / "*" ; QName from XML Namespaces +att-name = QName +att-value = AttValue ; from XML specification +attribute-selector = "@" att-name +namespace-selector = "namespace::*" +extension-selector = 1*( %x00-2e / %x30-ff ) ; anything but "/" +*/ +#define XDM_NODE_SELECT_BY_NAME(qname) by_name, qname +#define XDM_NODE_SELECT_BY_POS(qname, position) by_pos, qname, position +#define XDM_NODE_SELECT_BY_ATTR(qname, att_name, att_value) by_attr, qname, att_name, att_value +#define XDM_NODE_SELECT_BY_POS_ATTR(qname, position, att_name, att_value) by_pos_attr, qname, position, att_name, att_value +#define XDM_NODE_ADD_NAMESPACE(prefix, ns) 0xF0, prefix, ns +#define XDM_NODE_SELECT_END() 0xFF + +/* listing all possible xdm panic codes */ +typedef enum xdm_panic_e +{ + xpa_success = 0x00, + xpa_unsupported_auid = -0xFF, + xpa_invalid_root, + xpa_invalid_xui, + xpa_invalid_doc_name, + xpa_invalid_url, + xpa_invalid_proxy, + xpa_invalid_authtype, + xpa_libcurl_error, + xpa_func_not_implemented, + xpa_func_obsolete +} +xdm_panic_t; + +/* xdm buffer */ +typedef struct xdm_content_s +{ + char *data; + char *type; + size_t cursor; + size_t size; +} +xdm_content_t; + +/* xdm operation */ +typedef enum xdm_oper_type_e +{ + op_create, + op_replace, + op_fetch, + op_delete +} +xdm_oper_type_t; + +/* xdm selection type */ +typedef enum xdm_selection_type_e +{ + sl_element, + sl_document, + sl_attribute +} +xdm_selection_type_t; + +/* xdm node selector step as per rfc 4825 subclause 6.3 */ +typedef enum xdm_node_step_e +{ + by_name, + by_pos, + by_attr, + by_pos_attr +} +xdm_node_step_t; + +/* supported AUIDs */ +typedef enum xcap_auid_type_e +{ + ietf_xcap_caps, /* RFC 4825 sublause 12 */ + ietf_resource_lists, /* RFC 4825 sublause ... */ + ietf_rls_services, /* */ + ietf_pres_rules, /* */ + ietf_directory, /* */ + + oma_conv_history, /* */ + oma_pres_rules, /* */ + oma_directory, /* */ + oma_deferred_list, /* */ + oma_pres_content, /* */ + oma_shared_groups /* */ +} +xcap_auid_type_t; + +/* [auid<->content type] mapping */ +typedef struct xdm_auid_s +{ + xcap_auid_type_t type; + char* name; + char* description; + char* content_type; + char* document; + int available; +} +xdm_auid_t; +typedef xdm_list_t xdm_auid_L_t; /* contains 'xdm_auid_t' elements */ + +/* all supported auids */ +static const xdm_auid_t xdm_auids[11] = +{ + {ietf_xcap_caps, "xcap-caps", "IETF server capabilities", XDM_MIME_TYPE_CAPS, "index", 1}, + {ietf_resource_lists, "resource-lists", "IETF resource-list", "application/resource-lists+xml", "index", 0}, + {ietf_rls_services, "rls-services", "IETF RLS service", "application/rls-services+xml", "index", 0}, + {ietf_pres_rules, "pres-rules", "IETF pres-rules", "application/auth-policy+xml", "pres-rules", 0}, + {ietf_directory, "directory", "IETF xdm directory", "application/directory+xml", "directory.xml", 0}, + + {oma_conv_history, "org.openmobilealliance.conv-history", "OMA conversation history", "application/vnd.oma.im.history-list+xml", "conv-history", 0}, + {oma_pres_rules, "org.openmobilealliance.pres-rules", "OMA presence rules", "application/auth-policy+xml", "pres-rules", 0}, + {oma_directory, "org.openmobilealliance.xdm-directory", "OMA xdm directory", "application/vnd.oma.xdm-directory+xml", "directory.xml", 0}, + {oma_deferred_list, "org.openmobilealliance.deferred-list", "OMA deferred list", "application/vnd.oma.im.deferred-list+xml", "deferred-list", 0}, + {oma_pres_content, "org.openmobilealliance.pres-content", "OMA presence content", "application/vnd.oma.pres-content+xml", "oma_status-icon", 0}, + {oma_shared_groups, "org.openmobilealliance.groups", "OMA shared groups", "application/vnd.oma.poc.groups+xml", "index"} +}; + +/* xdm request */ +typedef struct xdm_request_s +{ + char* auid; + xdm_content_t* content; + char* url; + char* http_accept; + char* http_expect; + //char http_error[CURL_ERROR_SIZE]; + xdm_panic_t panic; + + long status; + long timeout; +} +xdm_request_t; + +typedef struct xdm_context_s +{ + char* xui; /* RFC 4825 subclause 4: username*/ + char* password; /* user password */ + char* proxy_host; /* proxy host */ + int proxy_port; /* proxy port */ + char* proxy_usr; /* proxy user name */ + char* proxy_pwd; /* proxy password */ + int proxy_tunneling; /* use proxy tunneling, default is false*/ + char* xdm_root; /* RFC 4825 subclause 6.1 */ + char* pragma; /* HTTP pragma */ + char* user_agent; + xdm_auid_L_t* auids; /* contains list of all default auids */ + + CURL* easyhandle; /* curl handle */ + int reuse_http_connection; /* reuse the same easyhandle to send/receive data */ +} +xdm_context_t; + +TINYXCAP_API void xdm_content_init(xdm_content_t *content); +TINYXCAP_API void xdm_content_set(xdm_content_t* content, const char *data, size_t size, const char *type); +TINYXCAP_API void xdm_content_free(xdm_content_t** content); + +void xdm_auid_init(xdm_auid_t *auid); +TINYXCAP_API xdm_auid_t* xdm_auid_findby_type(const xdm_auid_L_t* auids, xcap_auid_type_t type); +TINYXCAP_API xdm_auid_t* xdm_auid_findby_name(const xdm_auid_L_t* auids, const char* name); +TINYXCAP_API int xdm_auid_is_available(const xdm_auid_L_t* auids, xcap_auid_type_t type); +TINYXCAP_API void xdm_auid_set_availability(const xdm_auid_L_t* auids, xcap_auid_type_t type, int avail); +TINYXCAP_API void xdm_auid_update(xdm_context_t* context, xcap_auid_type_t type, const char* document); +void xdm_auid_free(void **auid); + +TINYXCAP_API void xdm_context_init(xdm_context_t* context); +TINYXCAP_API void xdm_conttext_update_available_auids(xdm_context_t *context, const xdm_list_t* avail_auids); +TINYXCAP_API void xdm_context_free(xdm_context_t** context); + +TINYXCAP_API void xdm_request_init(xdm_request_t* request); +TINYXCAP_API void xdm_request_free(xdm_request_t** request); + + +TINYXCAP_API int xdm_xcap_perform(xdm_context_t* context, xdm_request_t* request, xdm_oper_type_t oper, xdm_selection_type_t sel); + +#endif /* _TINYXCAP_XDM_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_api.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_api.h new file mode 100644 index 00000000..f3d891e1 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_api.h @@ -0,0 +1,44 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_API_H_ +#define _TINYXCAP_XDM_API_H_ + +#include "xdm.h" +#include "xdm_utils.h" /* utilities */ +#include "xdm_document.h" +#include "xdm_node.h" +#include "xdm_xcap-caps.h" /* urn:ietf:params:xml:ns:xcap-caps */ +#include "xdm_rlist.h" /* urn:ietf:params:xml:ns:resource-lists */ +#include "xdm_rls.h" /* urn:ietf:params:xml:ns:rls-services */ +#include "xdm_oma-directory.h" /* urn:oma:xml:xdm:xcap-directory */ +#include "xdm_oma-prescont.h" /* urn:oma:xml:prs:pres-content */ +#include "xdm_gsma_rcs.h" /* both gsma rcs phase 1 and 2 */ +#include "xdm_oma.h" /* OMA functionalities */ +#include "xdm_oma-presrules.h" /* urn:ietf:params:xml:ns:pres-rules + urn:ietf:params:xml:ns:pres-rules*/ + +#endif /* _TINYXCAP_XDM_API_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_client.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_client.c new file mode 100644 index 00000000..001e9c25 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_client.c @@ -0,0 +1,27 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_client.h" \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_client.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_client.h new file mode 100644 index 00000000..1c3d7fd4 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_client.h @@ -0,0 +1,36 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_CLIENT_H_ +#define _TINYXCAP_XDM_CLIENT_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + + + +#endif /* _TINYXCAP_XDM_CLIENT_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_document.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_document.c new file mode 100644 index 00000000..4cf12ad6 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_document.c @@ -0,0 +1,83 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_document.h" +#include "xdm_utils.h" + +/* create document selector as per rfc 4825 subclause 6.2*/ +/* ATTENTION: the @context MUST be initialized using 'xdm_context_init' or created using 'XDM_CONTEXT_CREATE' macro*/ +/* ATTENTION: use 'XDM_REQUEST_SAFE_FREE' macro to free the returned object */ +xdm_request_t* xdm_doc_get_sel(const xdm_context_t* context, const xcap_auid_type_t auid_type) +{ + xdm_request_t* request = 0; + const xdm_auid_t* auid = 0; + + /* create request and check context validity*/ + XDM_REQUEST_CREATE(request); + XDM_CONTEXT_CHECK(context, request->panic); + XDM_REQUEST_RETURN_IF_PANIC(request); + + /* get associated auid object*/ + auid = xdm_auid_findby_type(context->auids, auid_type); + XDM_AUID_CHECK(auid, request->panic); + XDM_REQUEST_RETURN_IF_PANIC(request); + + /* auid */ + request->auid = xdm_strdup(auid->name); + + /* url */ + if(XDM_DOCUMENT_GLOBAL(auid_type)) + { /* xdm-root/auid-name/global/doc-name */ + xdm_sprintf(&(request->url), "%s/%s/global/%s", context->xdm_root, auid->name, auid->document); + } + else + { /* xdm-root/auid-name/users/xui/doc-name */ + xdm_sprintf(&(request->url), "%s/%s/users/%s/%s", context->xdm_root, auid->name, context->xui, auid->document); + } + + /* content type */ + //request->content_type = xdm_strdup(auid->content_type); + + return request; +} + + +/* create document selector as per rfc 4825 subclause 6.2*/ +/* ATTENTION: the @context MUST be initialized using 'xdm_context_init' or created using 'XDM_CONTEXT_CREATE' macro*/ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_doc_get_sel2(const xdm_context_t* context, const xcap_auid_type_t auid_type) +{ + char* sel = 0; + xdm_request_t* request = 0; + if((request = xdm_doc_get_sel(context, auid_type)) && (XDM_PANIC_SUCCESS(request->panic))) + { + sel = xdm_strdup(request->url); + } + + XDM_REQUEST_SAFE_FREE(request); + return sel; +} \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_document.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_document.h new file mode 100644 index 00000000..f6ad4b97 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_document.h @@ -0,0 +1,37 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_DOCUMENT_H_ +#define _TINYXCAP_XDM_DOCUMENT_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +TINYXCAP_API xdm_request_t* xdm_doc_get_sel(const xdm_context_t* context, const xcap_auid_type_t auid_type); +TINYXCAP_API char* xdm_doc_get_sel2(const xdm_context_t* context, const xcap_auid_type_t auid_type); + +#endif /* _TINYXCAP_XDM_DOCUMENT_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_gsma_rcs.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_gsma_rcs.c new file mode 100644 index 00000000..0edbea47 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_gsma_rcs.c @@ -0,0 +1,162 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +/* both gsma rcs1 and rcs2 */ +/* GSMA RCS2: http://www.gsmworld.com/documents/rcs/rcs2_june09/R2_090831_RCS_Release_2_Technical_Realisation_v1_0.pdf */ +/* GSMA RCS1: http://www.gsmworld.com/documents/rcs/rcs1_updates/R1_090831_RCS_Release_1_Technical_Realisation_v1_1.pdf */ +#include "xdm_gsma_rcs.h" +#include "xdm_oma.h" +#include "xdm_document.h" +#include "xdm_oma-presrules.h" + +#include "xdm_utils.h" + +#define GSME_RCS_RLIST_ADD_ANCHOR(lname)\ + xdm_sprintf(&anchor, \ + "%s/~~/resource-lists/list%%5B@name=%%22%s%%22%%5D", \ + doc_sel, lname); \ + xdm_rlist_list2_add_external(list2, anchor); \ + XDM_SAFE_FREE(anchor); + +#define GSMA_RCS_ADD_SERVICE(lname, package)\ + xdm_sprintf(&uri, "%s;pres-list=%s", \ + context->xui, lname);\ + xdm_sprintf(&resource_list, \ + "%s/~~/resource-lists/list%%5B@name=%%22%s%%22%%5D", \ + doc_sel, lname); \ + xdm_rls_service_set(service, uri, resource_list); \ + xdm_rls_service_add_package(service, package); \ + xdm_list_add_data(services, ((void**) &service), xdm_rls_service_free); \ + XDM_SAFE_FREE(resource_list); \ + XDM_SAFE_FREE(uri); + +/* create default list2 with all mandatory list as per GSMA RCS2. this include oma lists */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_rlist_list2_L_t* xdm_gsmarcs_create_rlist2(const xdm_context_t* context) +{ + xdm_rlist_list2_L_t* rlist = 0; + xdm_rlist_list2_t *list2 = 0; + char* anchor = 0, *doc_sel = 0; + + /* get document selector */ + if( !context || !(doc_sel = xdm_doc_get_sel2(context, ietf_resource_lists)) ) + { + goto bail; + } + + /* create list to be returned */ + XDM_LIST_CREATE(rlist); + + /* list containing all contacts and named 'all' */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, "all", "all contacts"); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + + /* rcs */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, XDM_RNAME_GSMA_RCS_RCS, XDM_RNAME_GSMA_RCS_RCS); + xdm_rlist_list2_add_entry(list2, context->xui, "own"); /* RCS 2 */ + GSME_RCS_RLIST_ADD_ANCHOR("all"); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + + /* rcs_blockedcontacts */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, XDM_RNAME_GSMA_RCS_BLOCKEDCONTACTS, XDM_RNAME_GSMA_RCS_BLOCKEDCONTACTS); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + + /* rcs_revokedcontacts” */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, XDM_RNAME_GSMA_RCS_REVOKEDCONTACTS, XDM_RNAME_GSMA_RCS_REVOKEDCONTACTS); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + + /* oma_buddylist */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, XDM_RNAME_OMA_BUDDYLIST, XDM_RNAME_OMA_BUDDYLIST); + GSME_RCS_RLIST_ADD_ANCHOR(XDM_RNAME_GSMA_RCS_RCS); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + + /* oma_grantedcontacts */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, XDM_RNAME_OMA_GRANTEDCONTACTS, XDM_RNAME_OMA_GRANTEDCONTACTS); + GSME_RCS_RLIST_ADD_ANCHOR(XDM_RNAME_GSMA_RCS_RCS); + GSME_RCS_RLIST_ADD_ANCHOR(XDM_RNAME_OMA_BUDDYLIST); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + + /* oma_blockedcontacts */ + XDM_RLIST_LIST2_CREATE(list2); + xdm_rlist_list2_set(list2, XDM_RNAME_OMA_BLOCKEDCONTACTS, XDM_RNAME_OMA_BLOCKEDCONTACTS); + GSME_RCS_RLIST_ADD_ANCHOR(XDM_RNAME_GSMA_RCS_BLOCKEDCONTACTS); + GSME_RCS_RLIST_ADD_ANCHOR(XDM_RNAME_GSMA_RCS_REVOKEDCONTACTS); + xdm_list_add_data(rlist, ((void**) &list2), xdm_rlist_list2_free); + +bail: + /* free doc sel */ + XDM_FREE(doc_sel); + + return rlist; +} + +/* create default rls with all mandatory services as per GSMA RCS1 */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_rls_service_L_t* xdm_gsmarcs_create_rls(const xdm_context_t* context) +{ + xdm_rls_service_t *service = 0; + xdm_rls_service_L_t* services = 0; + char *uri = 0, *resource_list = 0, *doc_sel = 0; + + /* get document selector */ + if( !context || !(doc_sel = xdm_doc_get_sel2(context, ietf_resource_lists)) ) + { + goto bail; + } + + /* create list to be returned */ + XDM_LIST_CREATE(services); + + /* rcs */ + XDM_RLS_SERVICE_CREATE(service); + GSMA_RCS_ADD_SERVICE(XDM_RNAME_GSMA_RCS_RCS, "presence"); + + /* oma buddy list */ + XDM_RLS_SERVICE_CREATE(service); + GSMA_RCS_ADD_SERVICE(XDM_RNAME_OMA_BUDDYLIST, "presence"); + + bail: + /* free doc sel */ + XDM_FREE(doc_sel); + + return services; +} + +/* create default oma pres-rules document */ +/* ATTENTION: use 'XDM_SAFE_FREE' function to free the returned string */ +char* xdm_gsmarcs_create_oma_presrules(const xdm_context_t* context) +{ + return xdm_oma_presrules_serialize(context); +} + +#undef GSME_RCS_LIST_ADD \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_gsma_rcs.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_gsma_rcs.h new file mode 100644 index 00000000..9c4337ae --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_gsma_rcs.h @@ -0,0 +1,48 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef _TINYXCAP_XDM_GSMA_RCS_H_ +#define _TINYXCAP_XDM_GSMA_RCS_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +#include "xdm_rlist.h" +#include "xdm_rls.h" + +/* GSMA RCS2: http://www.gsmworld.com/documents/rcs/rcs2_june09/R2_090831_RCS_Release_2_Technical_Realisation_v1_0.pdf */ +/* GSMA RCS1: http://www.gsmworld.com/documents/rcs/rcs1_updates/R1_090831_RCS_Release_1_Technical_Realisation_v1_1.pdf */ + +/* GSMA RCS1 subclause 4.4.2 */ +#define XDM_RNAME_GSMA_RCS_RCS "rcs" +#define XDM_RNAME_GSMA_RCS_BLOCKEDCONTACTS "rcs_blockedcontacts" +#define XDM_RNAME_GSMA_RCS_REVOKEDCONTACTS "rcs_revokedcontacts" + +TINYXCAP_API xdm_rlist_list2_L_t* xdm_gsmarcs_create_rlist2(const xdm_context_t* context); +TINYXCAP_API xdm_rls_service_L_t* xdm_gsmarcs_create_rls(const xdm_context_t* context); +TINYXCAP_API char* xdm_gsmarcs_create_oma_presrules(const xdm_context_t* context); + +#endif /* _TINYXCAP_XDM_GSMA_RCS_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-directory.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-directory.c new file mode 100644 index 00000000..f9649e3b --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-directory.c @@ -0,0 +1,29 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_ietf-directory.h" + +//static const char* xdm_ietf_directory_ns = "urn:ietf:params:xml:ns:resource-lists"; \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-directory.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-directory.h new file mode 100644 index 00000000..47ec86f2 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-directory.h @@ -0,0 +1,34 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_IETF_DIRECTORY_H_ +#define _TINYXCAP_XDM_IETF_DIRECTORY_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +#endif /* _TINYXCAP_XDM_IETF_DIRECTORY_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-pres-rules.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-pres-rules.h new file mode 100644 index 00000000..bc06ca3b --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-pres-rules.h @@ -0,0 +1,38 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "tinyxcap_config.h" +#include "xdm.h" + +#ifndef _TINYXCAP_IETF_PRES_RULES_H_ +#define _TINYXCAP_IETF_PRES_RULES_H_ + +/* urn:ietf:params:xml:ns:pres-rules */ + +char* xdm_ietf_presrules_serialize(const xdm_context_t *context); + +#endif /* _TINYXCAP_IETF_PRES_RULES_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-presrules.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-presrules.c new file mode 100644 index 00000000..6a133b39 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_ietf-presrules.c @@ -0,0 +1,164 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +/* + RFC 5025 - Presence Authorization Rules +*/ + +#include "xdm_ietf-pres-rules.h" +#include "xdm_document.h" +#include "xdm_oma.h" +#include "xdm_utils.h" + +//static const char* xdm_ietf_pres_rules_ns = "urn:ietf:params:xml:ns:pres-rules"; + +/* 1= owner uri ; 2=oma_grantedcontacts uri; 3=oma_blockedcontacts*/ +#define XDM_IETF_PRESRULES_TEMPLATE "" \ + "" \ + /* wp_prs_allow_own */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "allow" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + /* rcs_allow_services_anonymous */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "allow" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + /* wp_prs_unlisted */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "confirm" \ + "" \ + "" \ + /* wp_prs_grantedcontacts */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "allow" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + /* wp_prs_blockedcontacts */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "block" \ + "" \ + "" \ + "" \ + +/* will serialize a complete pres-rules whith xml header*/ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_ietf_presrules_serialize(const xdm_context_t *context) +{ + char *ietf_presrules_str = 0, *oma_grantedcontacts = 0, *oma_blockedcontacts = 0, *doc_sel = 0; + + /* get document selector */ + if( !context || !(doc_sel = xdm_doc_get_sel2(context, ietf_resource_lists)) ) + { + goto bail; + } + + /* oma granted contacts */ + xdm_sprintf(&oma_grantedcontacts, + "%s/~~/resource-lists/list%%5B@name=%%22%s%%22%%5D", + doc_sel, XDM_RNAME_OMA_GRANTEDCONTACTS); + + /* oma blocked contacts */ + xdm_sprintf(&oma_blockedcontacts, + "%s/~~/resource-lists/list%%5B@name=%%22%s%%22%%5D", + doc_sel, XDM_RNAME_OMA_BLOCKEDCONTACTS); + + /* append all */ + xdm_sprintf(&ietf_presrules_str, XDM_IETF_PRESRULES_TEMPLATE, + context->xui, oma_grantedcontacts, oma_blockedcontacts); + +bail: + XDM_FREE(doc_sel); + XDM_FREE(oma_grantedcontacts); + XDM_FREE(oma_blockedcontacts); + + return ietf_presrules_str; +} + +#undef XDM_IETF_PRESRULES_TEMPLATE \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_list.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_list.c new file mode 100644 index 00000000..5ce5446f --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_list.c @@ -0,0 +1,123 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_list.h" +#include "xdm_utils.h" + +/* initialize the list */ +void xdm_list_init(xdm_list_t* list) +{ + memset(list, 0, sizeof(xdm_list_t)); +} + +/* add an item to the list */ +void xdm_list_add_item(xdm_list_t* list, xdm_list_item_t** item) +{ + (*item)->next = list->head; + list->head = *item; + + list->count++; + (*item) = 0; +} + +/* add a list to the list */ +void xdm_list_add_list(xdm_list_t* destination, xdm_list_t** source) +{ + xdm_list_item_t* next = 0; + xdm_list_item_t* curr = (*source)->head; + + while(curr) + { + next = curr->next; + xdm_list_add_item(destination, &curr); + curr = next->next; + } + (*source) = 0; +} + +/* add data to the list */ +void xdm_list_add_data(xdm_list_t* destination, void** data, xdm_list_item_func_free item_func_free) +{ + if(data) + { + xdm_list_item_t *item = 0; + XDM_LIST_ITEM_CREATE(item); + item->data = *data; + item->func_free = item_func_free; + + xdm_list_add_item(destination, &item); + (*data) = 0; + } +} + +/* remove item by position */ +void xdm_list_remove_at(int position) +{ +} + +/* free the list */ +void xdm_list_free(xdm_list_t** list) +{ + if(*list) + { + xdm_list_item_t* next = 0; + xdm_list_item_t* curr = (*list)->head; + + while(curr) + { + next = curr->next; + xdm_list_item_free(&curr); + curr = next; + } + free(*list); + (*list) = 0; + } +} + +/* initialize an item */ +void xdm_list_item_init(xdm_list_item_t* item) +{ + memset(item, 0, sizeof(xdm_list_item_t)); +} + +/* free item */ +void xdm_list_item_free(xdm_list_item_t** item) +{ + if(*item) + { + if((*item)->func_free) + { + (*item)->func_free(&((*item)->data)); + } + else if((*item)->data) + { + free((*item)->data); + } + + free(*item); + (*item) = 0; + } +} \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_list.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_list.h new file mode 100644 index 00000000..acf04fc3 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_list.h @@ -0,0 +1,69 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef _TINYXCAP_XDM_LIST_H_ +#define _TINYXCAP_XDM_LIST_H_ + +#include "tinyxcap_config.h" + +#define XDM_LIST_CREATE(l) XDM_XXX_CREATE(l, list) +#define XDM_LIST_SAFE_FREE(l) XDM_XXX_SAFE_FREE(l, list) + +#define XDM_LIST_ITEM_CREATE(item) XDM_XXX_CREATE(item, list_item) +#define XDM_LIST_ITEM_SAFE_FREE(item) XDM_XXX_SAFE_FREE(item, list_item) + +#define xdm_list_foreach(item, list) for(item = list?list->head:0; item; item= item->next) + +/* function pointer ... */ +typedef void (*xdm_list_item_func_free)(void** item); + +typedef struct xdm_list_item_s +{ + void* data; + xdm_list_item_func_free func_free; + struct xdm_list_item_s* next; +} +xdm_list_item_t; + +typedef struct xdm_list_s +{ + xdm_list_item_t* head; + int count; +} +xdm_list_t; + +TINYXCAP_API void xdm_list_init(xdm_list_t* list); +TINYXCAP_API void xdm_list_add_item(xdm_list_t* list, xdm_list_item_t** item); +TINYXCAP_API void xdm_list_add_list(xdm_list_t* destination, xdm_list_t** source); +TINYXCAP_API void xdm_list_add_data(xdm_list_t* destination, void** data, xdm_list_item_func_free item_func_free); +TINYXCAP_API void xdm_list_remove_at(int position); +TINYXCAP_API void xdm_list_free(xdm_list_t** list); + +TINYXCAP_API void xdm_list_item_init(xdm_list_item_t* item); +TINYXCAP_API void xdm_list_item_free(xdm_list_item_t** item); + + +#endif /* _TINYXCAP_XDM_LIST_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_node.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_node.c new file mode 100644 index 00000000..77f2c3a5 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_node.c @@ -0,0 +1,137 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_node.h" +#include "xdm_utils.h" +#include "xdm_document.h" + +#include + +#define XDM_ELEMENT_CONTENT_TYPE "application/xcap-el+xml" /* RFC 4825 subclause 15.2.1 */ + +/* create node selector as per rcf 4825 subclause 6.3 */ +/* ATTENTION: use 'XDM_REQUEST_SAFE_FREE' macro to free the returned object */ +xdm_request_t* xdm_node_get_sel(const xdm_context_t* context, const xcap_auid_type_t auid_type, ...) +{ + xdm_request_t* request = 0; + const xdm_auid_t* auid = 0; + + va_list list; + int step; + char *result=0, *node_root = 0, *_namespace=0; + + /* get document selector */ + request = xdm_doc_get_sel(context, auid_type); + XDM_REQUEST_RETURN_IF_PANIC(request); + + /* append not root*/ + xdm_sprintf(&node_root, "/~~/%s", request->auid); + xdm_strcat(&(request->url), node_root); + XDM_SAFE_FREE(node_root); + + /* initialize variable arguments */ + va_start(list, auid_type); + + while( (step=va_arg(list, xdm_node_step_t)) != 0xFF) + { + switch(step) + { + case by_name: + { /* qname */ + const char* qname = va_arg(list, const char*); + char* selector = 0; + xdm_sprintf(&selector, "/%s", qname); + xdm_strcat(&(request->url), (const char*)selector); + free(selector); + break; + } + + case by_pos: + { /* qname, position */ + const char* qname = va_arg(list, const char*); + int position = va_arg(list, int); + char* selector = 0; + xdm_sprintf(&selector, "/%s%%5B%d%%5D", qname, position); + xdm_strcat(&(request->url), (const char*)selector); + free(selector); + break; + } + + case by_attr: + { /* qname, att_name, att_value */ + const char* qname = va_arg(list, const char*); + char* att_name = xdm_url_encode(va_arg(list, const char*)); + char* att_value = xdm_url_encode(va_arg(list, const char*)); + char* selector = 0; + xdm_sprintf(&selector, "/%s%%5B@%s=%%22%s%%22%%5D", qname, att_name, att_value); + xdm_strcat(&(request->url), (const char*)selector); + free(selector), free(att_name), free(att_value); + break; + } + + case by_pos_attr: + { /* qname, position, att_name, att_value */ + const char* qname = va_arg(list, const char*); + int position = va_arg(list, int); + char* att_name = xdm_url_encode(va_arg(list, const char*)); + char* att_value = xdm_url_encode(va_arg(list, const char*)); + char* selector = 0; + xdm_sprintf(&selector, "/%s%%5B%d%%5D%%5B@%s=%%22%s%%22%%5D", qname, position, att_name, att_value); + xdm_strcat(&(request->url), (const char*)selector); + free(selector), free(att_name), free(att_value); + break; + } + + case 0xF0: + { /* prefix ns */ + const char* prefix = va_arg(list, const char*); + const char* ns = va_arg(list, const char*); + char* selector = 0; + xdm_sprintf(&selector, "%sxmlns(%s=%%22%s%%22)", _namespace?"":"%3F",prefix, ns); + xdm_strcat(&_namespace, (const char*)selector); + free(selector); + break; + } + default: break; + + }/* switch */ + } + + /* reset variable arguments */ + va_end(list); + + /* add namespace and free it*/ + xdm_strcat(&(request->url), (const char*)_namespace); + XDM_FREE(_namespace); + + /* content type */ + //XDM_SAFE_FREE(request->content_type); + //request->content_type = xdm_strdup(XDM_ELEMENT_CONTENT_TYPE); + + return request; +} + diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_node.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_node.h new file mode 100644 index 00000000..f309aa03 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_node.h @@ -0,0 +1,36 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_ELEMENT_H_ +#define _TINYXCAP_XDM_ELEMENT_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +TINYXCAP_API xdm_request_t* xdm_node_get_sel(const xdm_context_t* context, const xcap_auid_type_t auid_type, ...); + +#endif /* _TINYXCAP_XDM_ELEMENT_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-directory.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-directory.c new file mode 100644 index 00000000..a1f46f5f --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-directory.c @@ -0,0 +1,167 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_oma-directory.h" +#include "xdm_utils.h" + +//static const char* xdm_oma_directory_ns = "urn:oma:xml:xdm:xcap-directory"; + +#define OMADIR_RETURN_IF_INVALID(omadir) if(!omadir || !(omadir->docPtr)) return 0; + +#define OMADIR_SELECT_FOLDER_BY_AUID(fo_auid)\ + xdm_xml_select_node(omadir->docPtr->children, \ + XDM_XML_NODE_SELECT_BY_NAME("xcap-directory"), \ + XDM_XML_NODE_SELECT_BY_ATT("folder", "auid", fo_auid), \ + XDM_XML_NODE_SELECT_CONTENT(), \ + XDM_XML_NODE_SELECT_END()) + + +/* init folder */ +void xdm_omadir_folder_init(xdm_omadir_folder_t *folder) +{ + memset(folder, 0, sizeof(xdm_omadir_folder_t)); +} + +/* free folder */ +void xdm_omadir_folder_free(void **_folder) +{ + xdm_omadir_folder_t **folder = ((xdm_omadir_folder_t**)_folder); + + XDM_SAFE_FREE((*folder)->auid); + + free(*_folder); + (*_folder) = 0; +} + +/* xml<->folder binding*/ +/* ATTENTION: use 'XDM_OMADIR_FOLDER_SAFE_FREE' function to free the returned object */ +xdm_omadir_folder_t* xdm_omadir_folder_from_xml(xmlNodePtr node) +{ + xmlNodePtr node2 = 0; + xdm_omadir_folder_t *folder = 0; + + if(node = xdm_xml_find_node(node, "folder", nft_none)) + { + XDM_OMADIR_FOLDER_CREATE(folder); + + /* auid */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("folder", "auid"), XDM_XML_NODE_SELECT_END()); + folder->auid = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + } + else return 0; + + return folder; +} + +/* create oma xcap-directory context */ +xdm_omadir_t* xdm_omadir_create(const char* buffer, size_t size) +{ + if(buffer && size) + { + xdm_omadir_t* omadir = (xdm_omadir_t*)malloc(sizeof(xdm_omadir_t)); + memset(omadir, 0, sizeof(xdm_omadir_t)); + omadir->docPtr = xmlParseMemory(buffer, (int)size); + + return omadir; + } + + return 0; +} + +/* get all folders in the oma xcap-directory document */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_omadir_folder_L_t* xdm_omadir_get_all_folders(const xdm_omadir_t* omadir) +{ + xdm_omadir_folder_t* folder = 0; + xdm_omadir_folder_L_t* list = 0; + xmlNodePtr node = 0; + + OMADIR_RETURN_IF_INVALID(omadir); + + /* root */ + node = xdm_xml_select_node(omadir->docPtr->children, + XDM_XML_NODE_SELECT_BY_NAME("xcap-directory"), + XDM_XML_NODE_SELECT_END()); + + /* select first folder */ + if(!xdm_xml_find_node(node, "folder", nft_none)) node = xdm_xml_find_node(node, "folder", nft_next); + if(node) + { + XDM_LIST_CREATE(list); + do + { + folder = xdm_omadir_folder_from_xml(node); + xdm_list_add_data(list, ((void**) &folder), xdm_omadir_folder_free); + } + while(node = xdm_xml_find_node(node, "folder", nft_next)); + } + + return list; +} + +/* get all entries in the folder */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_rlist_entry_L_t* xdm_omadir_get_entries_by_folder(const xdm_omadir_t* omadir, const char* fo_auid) +{ + xdm_rlist_entry_t *rlist_entry = 0; + xdm_list_t* list = 0; + xmlNodePtr node = 0; + + OMADIR_RETURN_IF_INVALID(omadir); + + node = OMADIR_SELECT_FOLDER_BY_AUID(fo_auid); + if(!node) return 0; + + /* select first entry */ + if(!xdm_xml_find_node(node, "entry", nft_none)) node = xdm_xml_find_node(node, "entry", nft_next); + if(node) + { + XDM_LIST_CREATE(list); + do + { + rlist_entry = xdm_rlist_entry_from_xml(node, fo_auid); + xdm_list_add_data(list, ((void**) &rlist_entry), xdm_rlist_entry_free); + } + while(node = xdm_xml_find_node(node, "entry", nft_next)); + } + + return list; +} + +/* free oma dir context */ +void xdm_omadir_free(xdm_omadir_t **omadir) +{ + if(*omadir) + { + xmlFreeDoc((*omadir)->docPtr); + + free(*omadir); + (*omadir)=0; + } +} + +#undef OMADIR_RETURN_IF_INVALID \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-directory.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-directory.h new file mode 100644 index 00000000..1d00f605 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-directory.h @@ -0,0 +1,65 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_OMA_DIRECTORY_H_ +#define _TINYXCAP_XDM_OMA_DIRECTORY_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" +#include "xdm_rlist.h" + +/* urn:oma:xml:xdm:xcap-directory */ + +#define XDM_OMADIR_FOLDER_CREATE(folder) XDM_XXX_CREATE(folder, omadir_folder) +#define XDM_OMADIR_FOLDER_SAFE_FREE(folder) XDM_XXX_SAFE_FREE(folder, omadir_folder) + +/* folder */ +typedef struct xdm_omadir_folder_s +{ + char* auid; +} +xdm_omadir_folder_t; +typedef xdm_list_t xdm_omadir_folder_L_t; /* contains xdm_omadir_folder_t elements */ + +/* oma xcap-directory */ +typedef struct xdm_omadir_s +{ + xmlDocPtr docPtr; +} +xdm_omadir_t; + +void xdm_omadir_folder_init(xdm_omadir_folder_t *folder); +void xdm_omadir_folder_free(void **folder); + +xdm_omadir_folder_t* xdm_omadir_folder_from_xml(xmlNodePtr node); + +TINYXCAP_API xdm_omadir_t* xdm_omadir_create(const char* buffer, size_t size); +TINYXCAP_API xdm_omadir_folder_L_t* xdm_omadir_get_all_folders(const xdm_omadir_t* omadir); +TINYXCAP_API xdm_rlist_entry_L_t* xdm_omadir_get_entries_by_folder(const xdm_omadir_t* omadir, const char* fo_auid); +TINYXCAP_API void xdm_omadir_free(xdm_omadir_t **omadir); + +#endif /* _TINYXCAP_XDM_OMA_DIRECTORY_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-prescont.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-prescont.c new file mode 100644 index 00000000..88afa2a7 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-prescont.c @@ -0,0 +1,93 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +/* implements [OMA-TS-Presence-SIMPLE_Content_XDM-V1_0-20081223-C] */ +#include "xdm_oma-prescont.h" +#include "xdm_utils.h" + + +//static const char* xdm_oma_prescont_ns = "urn:oma:xml:prs:pres-content"; + +/* create oma pres-content object */ +/* ATTENTION: use 'xdm_oma_pres_cont_free' function to free the returned object*/ +xdm_oma_prescont_t* xdm_oma_prescont_create(const char* buffer, size_t size) +{ + xmlNodePtr node = 0; + xmlDocPtr docPtr = 0; + xdm_oma_prescont_t* pres_cont = 0; + + /* parse xml document */ + docPtr = xmlParseMemory(buffer, (int)size); + if(!docPtr || !docPtr->children) return 0; + + node = xdm_xml_select_node(docPtr->children, + XDM_XML_NODE_SELECT_BY_NAME("content"), + XDM_XML_NODE_SELECT_END()); + + /* select content */ + if(node) + { + /* init pres-cont object */ + pres_cont = (xdm_oma_prescont_t*)malloc(sizeof(xdm_oma_prescont_t)); + memset(pres_cont, 0, sizeof(xdm_oma_prescont_t)); + do + { + if( !xdm_stricmp(node->name, "mime-Type") ) + { + pres_cont->mime_type = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node->children)); + } + else if(!xdm_stricmp(node->name, "encoding") ) + { + pres_cont->encoding = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node->children)); + } + else if( !xdm_stricmp(node->name, "description") ) + { + pres_cont->description = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node->children)); + } + else if( !xdm_stricmp(node->name, "data") ) + { + pres_cont->data = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node->children)); + } + } + while(node = xdm_xml_find_node(node, 0, nft_next)); + } + + + xmlFreeDoc(docPtr); + return pres_cont; +} + +/* init oma pres-content object */ +void xdm_oma_prescont_free(xdm_oma_prescont_t **pres_cont) +{ + XDM_SAFE_FREE((*pres_cont)->mime_type); + XDM_SAFE_FREE((*pres_cont)->encoding); + XDM_SAFE_FREE((*pres_cont)->description); + XDM_SAFE_FREE((*pres_cont)->data); + + free(*pres_cont); + (*pres_cont) = 0; +} diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-prescont.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-prescont.h new file mode 100644 index 00000000..a4bd2b4a --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-prescont.h @@ -0,0 +1,49 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef _TINYXCAP_XDM_OMA_PRESCONT_H_ +#define _TINYXCAP_XDM_OMA_PRESCONT_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" +#include "xdm_xml.h" + +/* urn:oma:xml:prs:pres-content */ + +/* oma pres-content */ +typedef struct xdm_oma_prescont_s +{ + char* mime_type; + char* encoding; + char* description; + char* data; +} +xdm_oma_prescont_t; + +TINYXCAP_API xdm_oma_prescont_t* xdm_oma_prescont_create(const char* buffer, size_t size); +TINYXCAP_API void xdm_oma_prescont_free(xdm_oma_prescont_t **pres_cont); + +#endif /* _TINYXCAP_XDM_OMA_PRESCONT_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-presrules.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-presrules.c new file mode 100644 index 00000000..44c003d1 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-presrules.c @@ -0,0 +1,162 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +/* as per RCS1: http://www.gsmworld.com/documents/rcs/rcs1_updates/R1_090831_RCS_Release_1_Technical_Realisation_v1_1.pdf subclause 4.4*/ +#include "xdm_oma-presrules.h" +#include "xdm_document.h" +#include "xdm_oma.h" +#include "xdm_utils.h" + +/* 1= owner uri ; 2=oma_grantedcontacts uri; 3=oma_blockedcontacts*/ +#define XDM_OMA_PRESRULES_TEMPLATE "" \ + "" \ + /* wp_prs_allow_own */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "allow" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + /* */ \ + /* */ \ + /* */ \ + /* */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "allow" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + /* wp_prs_unlisted */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "confirm" \ + "" \ + "" \ + /* wp_prs_grantedcontacts */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "allow" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + /* wp_prs_blockedcontacts */ \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "" \ + "block" \ + "" \ + "" \ + "" \ + "" + + +/* will serialize a complete pres-rules whith xml header*/ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_oma_presrules_serialize(const xdm_context_t *context) +{ + char *oma_presrules_str = 0, *oma_grantedcontacts = 0, *oma_blockedcontacts = 0, *doc_sel = 0; + + /* get document selector */ + if( !context || !(doc_sel = xdm_doc_get_sel2(context, ietf_resource_lists)) ) + { + goto bail; + } + + /* oma granted contacts */ + xdm_sprintf(&oma_grantedcontacts, + "%s/~~/resource-lists/list%%5B@name=%%22%s%%22%%5D", + doc_sel, XDM_RNAME_OMA_GRANTEDCONTACTS); + + /* oma blocked contacts */ + xdm_sprintf(&oma_blockedcontacts, + "%s/~~/resource-lists/list%%5B@name=%%22%s%%22%%5D", + doc_sel, XDM_RNAME_OMA_BLOCKEDCONTACTS); + + /* append all */ + xdm_sprintf(&oma_presrules_str, XDM_OMA_PRESRULES_TEMPLATE, + context->xui, oma_grantedcontacts, oma_blockedcontacts); + +bail: + XDM_FREE(doc_sel); + XDM_FREE(oma_grantedcontacts); + XDM_FREE(oma_blockedcontacts); + + return oma_presrules_str; +} + +#undef XDM_OMA_PRESRULES_TEMPLATE \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-presrules.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-presrules.h new file mode 100644 index 00000000..2d0263e1 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma-presrules.h @@ -0,0 +1,39 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +/* as per RCS1: http://www.gsmworld.com/documents/rcs/rcs1_updates/R1_090831_RCS_Release_1_Technical_Realisation_v1_1.pdf subclause 4.4*/ +#ifndef _TINYXCAP_XDM_OMA_PRESRULES_H_ +#define _TINYXCAP_XDM_OMA_PRESRULES_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +/* urn:ietf:params:xml:ns:pres-rules */ + +TINYXCAP_API char* xdm_oma_presrules_serialize(const xdm_context_t *context); + +#endif /* _TINYXCAP_XDM_OMA_PRESRULES_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma.c new file mode 100644 index 00000000..1b2e2e86 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma.c @@ -0,0 +1,27 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_oma.h" \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_oma.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma.h new file mode 100644 index 00000000..79c9b277 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_oma.h @@ -0,0 +1,42 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_OMA_H_ +#define _TINYXCAP_XDM_OMA_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +/* GSMA RCS2: http://www.gsmworld.com/documents/rcs/rcs2_june09/R2_090831_RCS_Release_2_Technical_Realisation_v1_0.pdf */ +/* GSMA RCS1: http://www.gsmworld.com/documents/rcs/rcs1_updates/R1_090831_RCS_Release_1_Technical_Realisation_v1_1.pdf */ + +/* GSMA RCS1 subclause 4.4.2 */ +#define XDM_RNAME_OMA_BUDDYLIST "oma_buddylist" +#define XDM_RNAME_OMA_GRANTEDCONTACTS "oma_grantedcontacts" +#define XDM_RNAME_OMA_BLOCKEDCONTACTS "oma_blockedcontacts" + +#endif /* _TINYXCAP_XDM_OMA_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_rlist.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_rlist.c new file mode 100644 index 00000000..9fcbef4b --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_rlist.c @@ -0,0 +1,617 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +/* +RFC 4826 - Extensible Markup Language (XML) Formats for Representing Resource Lists + + resource-lists + ->list-1(name) + ->entry-1(uri, display-name) + ->entry-2(uri, display-name) + ->list-2(name) + ->list-3(name) +*/ +#include "xdm_rlist.h" +#include "xdm_utils.h" + +#define RLIST_SELECT_LIST_BY_NAME(lname)\ + xdm_xml_select_node(rlist->docPtr->children, \ + XDM_XML_NODE_SELECT_BY_NAME("resource-lists"), \ + XDM_XML_NODE_SELECT_BY_ATT("list", "name", lname), \ + XDM_XML_NODE_SELECT_CONTENT(), \ + XDM_XML_NODE_SELECT_END()) + +#define RLIST_XML_HEADER "" \ + "" +#define RLIST_XML_FOOTER "" + +#define RLIST_RETURN_IF_INVALID(rlist) if(!rlist || !(rlist->docPtr)) return 0; + +//static const char* xdm_rlist_ns = "urn:ietf:params:xml:ns:resource-lists"; + +/* init entry*/ +void xdm_rlist_entry_init(xdm_rlist_entry_t *entry) +{ + memset(entry, 0, sizeof(xdm_rlist_entry_t)); +} + +/* set entry's uri and display-name */ +void xdm_rlist_entry_set(xdm_rlist_entry_t *entry, const char* uri, const char* display_name) +{ + if(entry) + { + xdm_strupdate(&(entry->uri), uri); + xdm_strupdate(&(entry->display_name), display_name); + } +} + +/* free entry */ +void xdm_rlist_entry_free(void **_entry) +{ + xdm_rlist_entry_t **entry = ((xdm_rlist_entry_t**)_entry); + + XDM_SAFE_FREE((*entry)->uri); + XDM_SAFE_FREE((*entry)->display_name); + XDM_SAFE_FREE((*entry)->list); + XDM_SAFE_FREE((*entry)->last_modified); + XDM_SAFE_FREE((*entry)->etag); + + free(*_entry); + (*_entry) = 0; +} + +/* init list */ +void xdm_rlist_list_init(xdm_rlist_list_t *list) +{ + memset(list, 0, sizeof(xdm_rlist_list_t)); +} + +/* set list's name and display-name */ +void xdm_rlist_list_set(xdm_rlist_list_t *list, const char* name, const char* display_name) +{ + if(list) + { + xdm_strupdate(&(list->name), name); + xdm_strupdate(&(list->display_name), display_name); + } +} + +/* free list */ +void xdm_rlist_list_free(void **_list) +{ + xdm_rlist_list_t **list = ((xdm_rlist_list_t**)_list); + + XDM_SAFE_FREE((*list)->display_name); + XDM_SAFE_FREE((*list)->name); + + free(*_list); + (*_list) = 0; +} + +/* init list2 */ +void xdm_rlist_list2_init(xdm_rlist_list2_t *list2) +{ + memset(list2, 0, sizeof(xdm_rlist_list2_t)); +} + +/* set list2's name and display-name */ +void xdm_rlist_list2_set(xdm_rlist_list2_t *list2, const char* name, const char* display_name) +{ + if(list2) + { + xdm_strupdate(&(list2->name), name); + xdm_strupdate(&(list2->display_name),display_name); + } +} +/* add external eement to the list2 */ +void xdm_rlist_list2_add_external(xdm_rlist_list2_t *list2, const char* anchor) +{ + if(list2) + { + xdm_rlist_external_t *external = 0; + if(!(list2->externals)) + { + XDM_LIST_CREATE(list2->externals); + } + + XDM_RLIST_EXTERNAL_CREATE(external); + xdm_rlist_external_set(external, anchor); + xdm_list_add_data(list2->externals, ((void**)&external), xdm_rlist_external_free); + } +} + +/* and an entry to the list */ +void xdm_rlist_list2_add_entry(xdm_rlist_list2_t *list2, const char* uri, const char* display_name) +{ + if(list2) + { + xdm_rlist_entry_t *entry = 0; + XDM_RLIST_ENTRY_CREATE(entry); + xdm_rlist_entry_set(entry, uri, display_name); + + if(!(list2->entries)) + { + XDM_LIST_CREATE(list2->entries); + } + xdm_list_add_data(list2->entries, ((void**)&entry), xdm_rlist_entry_free); + } +} + +/* free list2 */ +void xdm_rlist_list2_free(void **_list2) +{ + xdm_rlist_list2_t **list2 = ((xdm_rlist_list2_t**)_list2); + + XDM_SAFE_FREE((*list2)->display_name); + XDM_SAFE_FREE((*list2)->name); + XDM_LIST_SAFE_FREE((*list2)->externals); + XDM_LIST_SAFE_FREE((*list2)->entries); + + free(*_list2); + (*_list2) = 0; +} + +/* init external */ +void xdm_rlist_external_init(xdm_rlist_external_t *external) +{ + memset(external, 0, sizeof(xdm_rlist_external_t)); +} + +/* set external's anchor */ +void xdm_rlist_external_set(xdm_rlist_external_t *external, const char* anchor) +{ + if(external) + { + xdm_strupdate(&(external->anchor), anchor); + } +} + +/* free external */ +void xdm_rlist_external_free(void **_external) +{ + xdm_rlist_external_t **external = ((xdm_rlist_external_t**)_external); + + XDM_SAFE_FREE((*external)->anchor); + XDM_SAFE_FREE((*external)->list); + + free(*_external); + (*_external) = 0; +} + +/* xml<->entry binding*/ +/* ATTENTION: use 'XDM_RLIST_ENTRY_SAFE_FREE' function to free the returned object */ +xdm_rlist_entry_t* xdm_rlist_entry_from_xml(const xmlNodePtr node, const char* lname) +{ + xmlNodePtr node2 = 0; + xdm_rlist_entry_t *rlist_entry = 0; + + if(xdm_xml_find_node(node, "entry", nft_none)) + { + XDM_RLIST_ENTRY_CREATE(rlist_entry); + rlist_entry->list = xdm_strdup(lname); + + /* display-name */ + node2 = xdm_xml_select_node(node, XDM_XML_NODE_SELECT_BY_NAME("entry"), + XDM_XML_NODE_SELECT_BY_NAME("display-name"), XDM_XML_NODE_SELECT_END()); + rlist_entry->display_name = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /* uri */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("entry", "uri"), XDM_XML_NODE_SELECT_END()); + rlist_entry->uri = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /* last-modified */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("entry", "last-modified"), XDM_XML_NODE_SELECT_END()); + rlist_entry->last_modified = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /* etag */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("entry", "etag"), XDM_XML_NODE_SELECT_END()); + rlist_entry->etag = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + } + else return 0; + + return rlist_entry; +} + +/* xml<->entry binding*/ +/* ATTENTION: use 'XDM_RLIST_EXTERNAL_SAFE_FREE' function to free the returned object */ +xdm_rlist_external_t* xdm_rlist_external_from_xml(const xmlNodePtr node, const char* lname) +{ + xmlNodePtr node2 = 0; + xdm_rlist_external_t *rlist_external = 0; + + if(xdm_xml_find_node(node, "external", nft_none)) + { + XDM_RLIST_EXTERNAL_CREATE(rlist_external); + rlist_external->list = xdm_strdup(lname); + + /* anchor */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("external", "anchor"), + XDM_XML_NODE_SELECT_END()); + rlist_external->anchor = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + }else return 0; + + return rlist_external; +} + +/* xml<->list binding*/ +/* ATTENTION: use 'XDM_RLIST_LIST_SAFE_FREE' function to free the returned object */ +xdm_rlist_list_t* xdm_rlist_list_from_xml(const xmlNodePtr node) +{ + xmlNodePtr node2 = 0; + xdm_rlist_list_t *rlist_list = 0; + + if(xdm_xml_find_node(node, "list", nft_none)) + { + XDM_RLIST_LIST_CREATE(rlist_list); + + /* name */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("list", "name"), + XDM_XML_NODE_SELECT_END()); + rlist_list->name = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /* display-name */ + node2 = xdm_xml_select_node(node, XDM_XML_NODE_SELECT_BY_NAME("list"), + XDM_XML_NODE_SELECT_BY_NAME("display-name"), + XDM_XML_NODE_SELECT_END()); + rlist_list->display_name = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + }else return 0; + + return rlist_list; +} + +/* xml<->list binding*/ +/* ATTENTION: use 'XDM_RLIST_LIST2_SAFE_FREE' function to free the returned object */ +xdm_rlist_list2_t* xdm_rlist_list2_from_xml(const xmlNodePtr node) +{ + xmlNodePtr node2 = 0; + xdm_rlist_list2_t *rlist_list2 = 0; + + if(xdm_xml_find_node(node, "list", nft_none)) + { + XDM_RLIST_LIST_CREATE(rlist_list2); + + /** name **/ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("list", "name"), + XDM_XML_NODE_SELECT_END()); + rlist_list2->name = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /** display-name **/ + node2 = xdm_xml_select_node(node, XDM_XML_NODE_SELECT_BY_NAME("list"), + XDM_XML_NODE_SELECT_BY_NAME("display-name"), + XDM_XML_NODE_SELECT_END()); + rlist_list2->display_name = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /** externals **/ + /* select first external */ + if(! (node2 = xdm_xml_find_node(node->children, "external", nft_none)) ) node2 = xdm_xml_find_node(node->children, "external", nft_next); + if(node2) + { + xdm_rlist_external_t *rlist_external = 0; + XDM_LIST_CREATE(rlist_list2->externals); + do + { + rlist_external = xdm_rlist_external_from_xml(node2, rlist_list2->name); + xdm_list_add_data(rlist_list2->externals, ((void**) &rlist_external), xdm_rlist_external_free); + } + while(node2 = xdm_xml_find_node(node2, "external", nft_next)); + } + + /** entries **/ + /* select first entry */ + if(!(node2 = xdm_xml_find_node(node->children, "entry", nft_none))) node2 = xdm_xml_find_node(node->children, "entry", nft_next); + if(node2) + { + xdm_rlist_entry_t *rlist_entry = 0; + XDM_LIST_CREATE(rlist_list2->entries); + do + { + rlist_entry = xdm_rlist_entry_from_xml(node2, rlist_list2->name); + xdm_list_add_data(rlist_list2->entries, ((void**) &rlist_entry), xdm_rlist_entry_free); + } + while(node2 = xdm_xml_find_node(node2, "entry", nft_next)); + } + }else return 0; + + return rlist_list2; +} + +/* create resource-lists document */ +xdm_rlist_t* xdm_rlist_create(const char* buffer, size_t size) +{ + if(buffer && size) + { + xdm_rlist_t* rlist = (xdm_rlist_t*)malloc(sizeof(xdm_rlist_t)); + memset(rlist, 0, sizeof(xdm_rlist_t)); + rlist->docPtr = xmlParseMemory(buffer, (int)size); + + return rlist; + } + + return 0; +} + +/* get all lists(xdm_rlist_list_t or xdm_rlist_list2_t) */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_rlist_listx_L_t* xdm_rlist_get_all_lists(const xdm_rlist_t* rlist, int type2) +{ + xdm_rlist_listx_L_t* list = 0; + xmlNodePtr node = 0; + + RLIST_RETURN_IF_INVALID(rlist); + + /* root */ + node = xdm_xml_select_node(rlist->docPtr->children, + XDM_XML_NODE_SELECT_BY_NAME("resource-lists"), + XDM_XML_NODE_SELECT_END()); + + /* select first list */ + if(!xdm_xml_find_node(node, "list", nft_none)) node = xdm_xml_find_node(node, "list", nft_next); + if(node) + { + XDM_LIST_CREATE(list); + do + { + if(type2) + { + xdm_rlist_list2_t* rlist_list2 = xdm_rlist_list2_from_xml(node); + xdm_list_add_data(list, ((void**) &rlist_list2), xdm_rlist_list2_free); + } + else + { + xdm_rlist_list_t* rlist_list = xdm_rlist_list_from_xml(node); + xdm_list_add_data(list, ((void**) &rlist_list), xdm_rlist_list_free); + } + } + while(node = xdm_xml_find_node(node, "list", nft_next)); + } + + return list; +} + +/* returns all entries into the list named @lname */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_rlist_entry_L_t* xdm_rlist_get_entries_by_list(const xdm_rlist_t* rlist, const char* lname) +{ + xdm_rlist_entry_t *rlist_entry = 0; + xdm_rlist_entry_L_t* list = 0; + xmlNodePtr node = 0; + + RLIST_RETURN_IF_INVALID(rlist); + + node = RLIST_SELECT_LIST_BY_NAME(lname); + if(!node) return 0; + + XDM_LIST_CREATE(list); + + /* select first entry */ + if(!xdm_xml_find_node(node, "entry", nft_none)) node = xdm_xml_find_node(node, "entry", nft_next); + if(node) + { + do + { + rlist_entry = xdm_rlist_entry_from_xml(node, lname); + xdm_list_add_data(list, ((void**) &rlist_entry), xdm_rlist_entry_free); + } + while(node = xdm_xml_find_node(node, "entry", nft_next)); + } + + return list; +} + +/* returns a list of externals by list name (xdm_rlist_external_t) */ +/* ATTENTION: use 'XDM_LIST_SAFE_FREE' function to free the returned object */ +xdm_rlist_external_L_t* xdm_rlist_get_externals_by_list(const xdm_rlist_t* rlist, const char* lname) +{ + xdm_rlist_external_t *rlist_external = 0; + xdm_rlist_external_L_t* list = 0; + xmlNodePtr node = 0; + + RLIST_RETURN_IF_INVALID(rlist); + + node = RLIST_SELECT_LIST_BY_NAME(lname); + if(!node) return 0; + + /* select first external */ + if(!xdm_xml_find_node(node, "external", nft_none)) node = xdm_xml_find_node(node, "external", nft_next); + if(node) + { + XDM_LIST_CREATE(list); + do + { + rlist_external = xdm_rlist_external_from_xml(node, lname); + xdm_list_add_data(list, ((void**) &rlist_external), xdm_rlist_external_free); + } + while(node = xdm_xml_find_node(node, "external", nft_next)); + } + + return list; +} + +/* serialize an external */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_external_serialize(const xdm_rlist_external_t *external) +{ + char* external_str = 0; + if(!external) return 0; + + xdm_sprintf(&external_str, "", external->anchor); + return external_str; +} + +/* serialize an entry */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_entry_serialize(const xdm_rlist_entry_t *entry) +{ + return entry ? xdm_rlist_entry_serialize2(entry->uri, entry->display_name) : 0; +} + +/* serialize an entry */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_entry_serialize2(const char* uri, const char* displayname) +{ + char* entry_str = 0; + if(!uri || !displayname) return 0; + + xdm_sprintf(&entry_str, + "" + "%s" + "", + uri, displayname); + return entry_str; +} + +/* serialize list */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_list_serialize(const xdm_rlist_list_t *list) +{ + return list ? xdm_rlist_list_serialize2(list->name, list->display_name) : 0; +} + +/* serialize list */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_list_serialize2(const char* name, const char* displayname) +{ + char* list_str = 0; + + if(!name || !displayname) return 0; + + /* serialize */ + xdm_sprintf(&list_str, + "" + "%s" + "", + name, displayname); + return list_str; +} + +/* serialize list2 */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_list2_serialize(const xdm_rlist_list2_t *list2) +{ + char* list2_str = 0; + xdm_list_item_t *item = 0; + + /* check validity */ + if(!list2) return 0; + + /* name and display-name */ + xdm_sprintf(&list2_str, + "" + "%s", + list2->name, list2->display_name); + + /* entries */ + xdm_list_foreach(item, list2->entries) + { + xdm_rlist_entry_t *entry = ((xdm_rlist_entry_t*)item->data); + char* entry_str = xdm_rlist_entry_serialize(entry); + xdm_strcat(&list2_str, (const char*)entry_str); + XDM_FREE(entry_str); + } + + /*externals*/ + xdm_list_foreach(item, list2->externals) + { + xdm_rlist_external_t *external = ((xdm_rlist_external_t*)item->data); + char* external_str = xdm_rlist_external_serialize(external); + xdm_strcat(&list2_str, (const char*)external_str); + XDM_FREE(external_str); + } + + /* close list */ + xdm_strcat(&list2_str, ""); + + return list2_str; +} + +/* will serialize a complete resource-lists whith xml header*/ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_rlist2_serialize(const xdm_list_t *rlist2) +{ + xdm_list_item_t* item = 0; + char* rlist2_str = 0; + + if(!rlist2) return 0; + + /* xml header */ + xdm_strcat(&rlist2_str, RLIST_XML_HEADER); + + xdm_list_foreach(item, rlist2) + { + /* get list2 */ + xdm_rlist_list2_t *list2 = ((xdm_rlist_list2_t*)item->data); + char* list2_str = xdm_rlist_list2_serialize(list2); + xdm_strcat(&rlist2_str, list2_str); + XDM_FREE(list2_str); + } + + /* xml footer */ + xdm_strcat(&rlist2_str, RLIST_XML_FOOTER); + + return rlist2_str; +} + +/* add xml header to the content */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rlist_add_xml_header(const char* xml_content) +{ + char* xml = 0; + + /* append xml header */ + xdm_sprintf(&xml, + "%s%s%s", + RLIST_XML_HEADER, xml_content, RLIST_XML_FOOTER); + return xml; +} + +/* free resource-lists document */ +void xdm_rlist_free(xdm_rlist_t **rlist ) +{ + if(*rlist) + { + xmlFreeDoc((*rlist)->docPtr); + + free(*rlist); + (*rlist)=0; + } +} + +#undef RLIST_SELECT_LIST_BY_NAME +#undef RLIST_RETURN_IF_INVALID + +#undef RLIST_XML_HEADER +#undef RLIST_XML_FOOTER \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_rlist.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_rlist.h new file mode 100644 index 00000000..89e37430 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_rlist.h @@ -0,0 +1,134 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef _TINYXCAP_XDM_RLIST_H_ +#define _TINYXCAP_XDM_RLIST_H_ + +#include "tinyxcap_config.h" +#include "xdm_xml.h" + +/* urn:ietf:params:xml:ns:resource-lists */ + +#define XDM_RLIST_ENTRY_CREATE(entry) XDM_XXX_CREATE(entry, rlist_entry) +#define XDM_RLIST_ENTRY_SAFE_FREE(entry) XDM_XXX_SAFE_FREE(entry, rlist_entry) + +#define XDM_RLIST_LIST_CREATE(rlist_list) XDM_XXX_CREATE(rlist_list, rlist_list) +#define XDM_RLIST_LIST_SAFE_FREE(rlist_list) XDM_XXX_SAFE_FREE(rlist_list, rlist_list) + +#define XDM_RLIST_LIST2_CREATE(list2) XDM_XXX_CREATE(list2, rlist_list2) +#define XDM_RLIST_LIST2_SAFE_FREE(list2) XDM_XXX_SAFE_FREE(list2, rlist_list2) + +#define XDM_RLIST_EXTERNAL_CREATE(external) XDM_XXX_CREATE(external, rlist_external) +#define XDM_RLIST_EXTERNAL_SAFE_FREE(external) XDM_XXX_SAFE_FREE(external, rlist_external) + +/* entry */ +typedef struct xdm_rlist_entry_s +{ + char* uri; + char* display_name; + char* last_modified; + char* etag; + char* list; +} +xdm_rlist_entry_t; +typedef xdm_list_t xdm_rlist_entry_L_t; /* contains xdm_rlist_entry_t elements */ + +/* list */ +typedef struct xdm_rlist_list_s +{ + char* display_name; + char* name; +} +xdm_rlist_list_t; +typedef xdm_list_t xdm_rlist_list_L_t; /* contains 'xdm_rlist_list_t' elements*/ +typedef xdm_list_t xdm_rlist_listx_L_t; /* contains 'xdm_rlist_list_t' or 'xdm_rlist_list2_t' elements*/ + +/* external */ +typedef struct xdm_rlist_external_s +{ + char* anchor; + char* list; +} +xdm_rlist_external_t; +typedef xdm_list_t xdm_rlist_external_L_t; /* contains 'xdm_rlist_external_t' elements*/ + +/* list2 */ +typedef struct xdm_rlist_list2_s +{ + char* display_name; + char* name; + xdm_rlist_entry_L_t* entries; + xdm_rlist_external_L_t* externals; +} +xdm_rlist_list2_t; +typedef xdm_list_t xdm_rlist_list2_L_t; /* contains 'xdm_rlist_list2_t' elements*/ + + +/* resource-lists */ +typedef struct xdm_rlist_s +{ + xmlDocPtr docPtr; +} +xdm_rlist_t; + +void xdm_rlist_list_init(xdm_rlist_list_t *list); +void xdm_rlist_list_set(xdm_rlist_list_t *list, const char* name, const char* display_name); +void xdm_rlist_list_free(void **list); + +void xdm_rlist_list2_init(xdm_rlist_list2_t *list2); +void xdm_rlist_list2_set(xdm_rlist_list2_t *list2, const char* name, const char* display_name); +void xdm_rlist_list2_add_external(xdm_rlist_list2_t *list2, const char* anchor); +void xdm_rlist_list2_add_entry(xdm_rlist_list2_t *list2, const char* uri, const char* display_name); +void xdm_rlist_list2_free(void **list2); + +void xdm_rlist_entry_init(xdm_rlist_entry_t *entry); +void xdm_rlist_entry_set(xdm_rlist_entry_t *entry, const char* uri, const char* display_name); +void xdm_rlist_entry_free(void **entry); + +void xdm_rlist_external_init(xdm_rlist_external_t *external); +void xdm_rlist_external_set(xdm_rlist_external_t *external, const char* anchor); +void xdm_rlist_external_free(void **external); + +xdm_rlist_entry_t* xdm_rlist_entry_from_xml(const xmlNodePtr node, const char* lname); +xdm_rlist_external_t* xdm_rlist_external_from_xml(const xmlNodePtr node, const char* lname); +xdm_rlist_list_t* xdm_rlist_list_from_xml(const xmlNodePtr node); +xdm_rlist_list2_t* xdm_rlist_list2_from_xml(const xmlNodePtr node); + +TINYXCAP_API xdm_rlist_t* xdm_rlist_create(const char* buffer, size_t size); +TINYXCAP_API xdm_rlist_listx_L_t* xdm_rlist_get_all_lists(const xdm_rlist_t* rlist, int type2); +TINYXCAP_API xdm_rlist_entry_L_t* xdm_rlist_get_entries_by_list(const xdm_rlist_t* rlist, const char* lname); +TINYXCAP_API xdm_rlist_external_L_t* xdm_rlist_get_externals_by_list(const xdm_rlist_t* rlist, const char* lname); +TINYXCAP_API char* xdm_rlist_entry_serialize(const xdm_rlist_entry_t *entry); +TINYXCAP_API char* xdm_rlist_entry_serialize2(const char* uri, const char* displayname); +TINYXCAP_API char* xdm_rlist_external_serialize(const xdm_rlist_external_t *external); +TINYXCAP_API char* xdm_rlist_list_serialize(const xdm_rlist_list_t *list); +TINYXCAP_API char* xdm_rlist_list_serialize2(const char* name, const char* displayname); +TINYXCAP_API char* xdm_rlist_list2_serialize(const xdm_rlist_list2_t *list2); +TINYXCAP_API char* xdm_rlist_rlist2_serialize(const xdm_list_t *rlist2); +TINYXCAP_API char* xdm_rlist_add_xml_header(const char* xml_content); +TINYXCAP_API void xdm_rlist_free(xdm_rlist_t **rlist); + +#endif /* _TINYXCAP_XDM_RLIST_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_rls.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_rls.c new file mode 100644 index 00000000..ecbcda0d --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_rls.c @@ -0,0 +1,249 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_rls.h" +#include "xdm_utils.h" + +#define RLS_RETURN_IF_INVALID(rls) if(!rls || !(rls->docPtr)) return 0; + +//static const char* xdm_rls_ns = "urn:ietf:params:xml:ns:rls-services"; + +#define RLS_XML_HEADER "" \ + "" +#define RLS_XML_FOOTER "" + +/* init service */ +void xdm_rls_service_init(xdm_rls_service_t *service) +{ + memset(service, 0, sizeof(xdm_rls_service_t)); +} + + +/* set service's uri and resource-list */ +void xdm_rls_service_set(xdm_rls_service_t *service, const char* uri, const char* resource_list) +{ + if(service) + { + xdm_strupdate(&(service->uri), uri); + xdm_strupdate(&(service->resource_list), resource_list); + } +} + +/* add package to the existing list */ +void xdm_rls_service_add_package(xdm_rls_service_t *service, const char* package) +{ + xdm_list_item_t *item = 0; + if(service) + { + if(!(service->packages)) + { + XDM_LIST_CREATE(service->packages); + } + + XDM_LIST_ITEM_CREATE(item); + item->data = (void*)xdm_strdup(package); + xdm_list_add_item(service->packages, &item); + } +} + +/* free service */ +void xdm_rls_service_free(void **_service) +{ + xdm_rls_service_t **service = ((xdm_rls_service_t**)_service); + + XDM_SAFE_FREE((*service)->uri); + XDM_SAFE_FREE((*service)->resource_list); + XDM_LIST_SAFE_FREE((*service)->packages); + + free(*_service); + (*_service) = 0; +} + +/* xml<->service binding*/ +/* ATTENTION: use 'XDM_RLS_SERVICE_SAFE_FREE' function to free the returned object */ +xdm_rls_service_t* xdm_rls_service_from_xml(const xmlNodePtr node) +{ + xmlNodePtr node2 = 0; + xdm_rls_service_t *rls_service = 0; + xdm_list_item_t* item = 0; + + if(xdm_xml_find_node(node, "service", nft_none)) + { + XDM_RLS_SERVICE_CREATE(rls_service); + + /* uri */ + node2 = xdm_xml_select_node(node, + XDM_XML_NODE_SELECT_ATT_VALUE("service", "uri"), + XDM_XML_NODE_SELECT_END()); + rls_service->uri = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /* resource-list */ + node2 = xdm_xml_select_node(node, XDM_XML_NODE_SELECT_BY_NAME("service"), + XDM_XML_NODE_SELECT_BY_NAME("resource-list"), + XDM_XML_NODE_SELECT_END()); + rls_service->resource_list = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2)); + + /* packages */ + node2 = xdm_xml_select_node(node, XDM_XML_NODE_SELECT_BY_NAME("service"), + XDM_XML_NODE_SELECT_BY_NAME("packages"), + XDM_XML_NODE_SELECT_CONTENT(), + XDM_XML_NODE_SELECT_END()); + /* select first package */ + if(!xdm_xml_find_node(node2, "package", nft_none)) node2 = xdm_xml_find_node(node2, "package", nft_next); + if(node2) + { + XDM_LIST_CREATE(rls_service->packages); + do + { + XDM_LIST_ITEM_CREATE(item); + item->data = xdm_strdup(XDM_XML_NODE_SAFE_GET_TEXTVALUE(node2->children)); + xdm_list_add_item(rls_service->packages, &item); + } + while(node2 = xdm_xml_find_node(node2, "service", nft_next)); + } + }else return 0; + + return rls_service; +} + +/* create rls context */ +xdm_rls_t* xdm_rls_create(const char* buffer, size_t size) +{ + if(buffer && size) + { + xdm_rls_t* rls = (xdm_rls_t*)malloc(sizeof(xdm_rls_t)); + memset(rls, 0, sizeof(xdm_rls_t)); + rls->docPtr = xmlParseMemory(buffer, (int)size); + + return rls; + } + + return 0; +} + +/* get all services (xdm_rls_service_t)*/ +xdm_rls_service_L_t* xdm_rls_get_all_services(const xdm_rls_t* rls) +{ + xdm_rls_service_t* rls_service = 0; + xdm_rls_service_L_t* list = 0; + xmlNodePtr node = 0; + + RLS_RETURN_IF_INVALID(rls); + + /* root */ + node = xdm_xml_select_node(rls->docPtr->children, + XDM_XML_NODE_SELECT_BY_NAME("rls-services"), + XDM_XML_NODE_SELECT_END()); + + /* select first service */ + if(!xdm_xml_find_node(node, "service", nft_none)) node = xdm_xml_find_node(node, "service", nft_next); + if(node) + { + XDM_LIST_CREATE(list); + do + { + rls_service = xdm_rls_service_from_xml(node); + xdm_list_add_data(list, ((void**) &rls_service), xdm_rls_service_free); + } + while(node = xdm_xml_find_node(node, "service", nft_next)); + } + return list; +} + +/* serialize service */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rls_service_serialize(const xdm_rls_service_t *service) +{ + char* service_str = 0; + char* package_str = 0; + xdm_list_item_t* item = 0; + + if(!service) return 0; + + /* packages */ + xdm_list_foreach(item, service->packages) + { + char* curr = 0; + xdm_sprintf(&curr, "%s", ((char*)item->data)); + xdm_strcat(&package_str, curr); + XDM_SAFE_FREE(curr); + } + /* service */ + xdm_sprintf(&service_str, + "" + "%s" + "" + "%s" + "" + "", + service->uri, service->resource_list, package_str); + XDM_SAFE_FREE(package_str); + return service_str; +} + +/* serialize services with xml header */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_rls_rls_serialize(const xdm_list_t *services) +{ + xdm_list_item_t* item = 0; + char* services_str = 0; + + if(!services) return 0; + + /* xml header */ + xdm_strcat(&services_str, RLS_XML_HEADER); + + xdm_list_foreach(item, services) + { + /* get service */ + xdm_rls_service_t *service = ((xdm_rls_service_t*)item->data); + char* service_str = xdm_rls_service_serialize(service); + xdm_strcat(&services_str, service_str); + XDM_FREE(service_str); + } + + /* xml footer */ + xdm_strcat(&services_str, RLS_XML_FOOTER); + + return services_str; +} + +/* free rls context */ +void xdm_rls_free(xdm_rls_t **rls) +{ + if(*rls) + { + xmlFreeDoc((*rls)->docPtr); + + free(*rls); + (*rls)=0; + } +} + +#undef RLS_RETURN_IF_INVALID + +#undef RLS_XML_HEADER +#undef RLS_XML_FOOTER \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_rls.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_rls.h new file mode 100644 index 00000000..dd179b3e --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_rls.h @@ -0,0 +1,68 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef _TINYXCAP_XDM_RLS_H_ +#define _TINYXCAP_XDM_RLS_H_ + +#include "tinyxcap_config.h" +#include "xdm_xml.h" + +/* urn:ietf:params:xml:ns:rls-services */ + +#define XDM_RLS_SERVICE_CREATE(service) XDM_XXX_CREATE(service, rls_service) +#define XDM_RLS_SERVICE_SAFE_FREE(service) XDM_XXX_SAFE_FREE(service, rls_service) + +/* service */ +typedef struct xdm_rls_service_s +{ + char* uri; + char* resource_list; + xdm_list_t* packages; +} +xdm_rls_service_t; +typedef xdm_list_t xdm_rls_service_L_t; /* contains 'xdm_rls_service_t' elements */ + +/* rls-service */ +typedef struct xdm_rls_s +{ + xmlDocPtr docPtr; +} +xdm_rls_t; + +void xdm_rls_service_init(xdm_rls_service_t *service); +void xdm_rls_service_set(xdm_rls_service_t *service, const char* uri, const char* resource_list); +void xdm_rls_service_add_package(xdm_rls_service_t *service, const char* package); +void xdm_rls_service_free(void **service); + +xdm_rls_service_t* xdm_rls_service_from_xml(const xmlNodePtr node); + +TINYXCAP_API xdm_rls_t* xdm_rls_create(const char* buffer, size_t size); +TINYXCAP_API xdm_rls_service_L_t* xdm_rls_get_all_services(const xdm_rls_t* rls); +TINYXCAP_API char* xdm_rls_service_serialize(const xdm_rls_service_t *service); +TINYXCAP_API char* xdm_rls_rls_serialize(const xdm_list_t *services); +TINYXCAP_API void xdm_rls_free(xdm_rls_t **rls); + +#endif /* _TINYXCAP_XDM_RLS_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_utils.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_utils.c new file mode 100644 index 00000000..ee674745 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_utils.c @@ -0,0 +1,147 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#include "xdm_utils.h" +#include +#include +#include + +#if defined(_MSC_VER) || defined(WIN32) +# define snprintf _snprintf +# define vsnprintf _vsnprintf +# define strdup _strdup +# define stricmp _stricmp +#endif + +/* Converts a hex character to its integer value */ +char from_hex(char ch) { + return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; +} + +/* Converts an integer value to its hex character*/ +char to_hex(char code) { + static char hex[] = "0123456789ABCDEF"; + return hex[code & 15]; +} + +/* Returns a url-encoded version of str */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_url_encode(const char* url) { + char *purl = (char*)url, *buf = malloc(strlen(url) * 3 + 1), *pbuf = buf; + while (*purl) { + if (isalnum(*purl) || *purl == '-' || *purl == '_' || *purl == '.' || *purl == '~') + *pbuf++ = *purl; + else if (*purl == ' ') + *pbuf++ = '+'; + else + *pbuf++ = '%', *pbuf++ = to_hex(*purl >> 4), *pbuf++ = to_hex(*purl & 15); + purl++; + } + *pbuf = '\0'; + return buf; +} + +/* Returns a url-decoded version of str */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string*/ +char* xdm_url_decode(const char* url) { + char *purl = (char*)url, *buf = malloc(strlen(url) + 1), *pbuf = buf; + while (*purl) { + if (*purl == '%') { + if (purl[1] && purl[2]) { + *pbuf++ = from_hex(purl[1]) << 4 | from_hex(purl[2]); + purl += 2; + } + } else if (*purl == '+') { + *pbuf++ = ' '; + } else { + *pbuf++ = *purl; + } + purl++; + } + *pbuf = '\0'; + return buf; +} + +/* My own sprintf implementation */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +void xdm_strcat(char** destination, const char* source) +{ + size_t index = 0; + + if(!source) return; + + if(!*destination){ + *destination = (char*)malloc(strlen(source)+1); + strncpy(*destination, source, strlen(source)+1); + }else{ + index = strlen(*destination); + *destination = realloc(*destination, index + strlen(source)+1); + strncpy(((*destination)+index), source, strlen(source)+1); + } +} + +/* My own sprintf implementation */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +int xdm_sprintf(char** str, const char* format, ...) +{ + int len = 0; + va_list list; + + /* initialize variable arguments */ + va_start(list, format); + + /* compute destination len */ + len = vsnprintf(0, 0, format, list); + *str = (char*)malloc(len+1); + vsnprintf(*str, len, format, list); + (*str)[len] = '\0'; + + /* reset variable arguments */ + va_end( list ); + + return len; +} + +/* My own strdup implementation */ +/* ATTENTION: use 'XDM_SAFE_FREE' macro to free the returned string */ +char* xdm_strdup(const char *s1) +{ + return strdup(s1); +} + +/* update @str value with @newval */ +void xdm_strupdate(char** str, const char* newval) +{ + XDM_FREE(*str); + *str = xdm_strdup(newval); +} + +/* My own stricmp implementation */ +int xdm_stricmp(const char* s1, const char* s2) +{ + return stricmp(s1, s2); +} \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_utils.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_utils.h new file mode 100644 index 00000000..b256beb5 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_utils.h @@ -0,0 +1,43 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_UTILS_H_ +#define _TINYXCAP_XDM_UTILS_H_ + +#include "tinyxcap_config.h" +#include "xdm.h" + +char* xdm_url_encode(const char* url); +char* xdm_url_decode(const char* url); + +TINYXCAP_API void xdm_strcat(char** destination, const char* source); +TINYXCAP_API int xdm_sprintf(char** str, const char* format, ...); +TINYXCAP_API char* xdm_strdup(const char* s1); +TINYXCAP_API void xdm_strupdate(char** str, const char* newval); +TINYXCAP_API int xdm_stricmp(const char* s1, const char* s2); + +#endif /* _TINYXCAP_XDM_UTILS_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_xcap-caps.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_xcap-caps.c new file mode 100644 index 00000000..86835965 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_xcap-caps.c @@ -0,0 +1,223 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +/* + xcap-caps + ->namespaces + ->namespace-1 + -> ... + ->namespace-2 + ->extensions + ->extension-1 + ->... + ->extension-n + ->auids + ->auid-1 + ->... + ->auid-n + +*/ + +#include "xdm_xcap-caps.h" +#include "xdm_utils.h" + +#define CAPS_RETURN_IF_INVALID(caps) if(!caps || !caps->docPtr || !caps->root) return 0; + +//static const char* xdm_xcap_caps_ns = "urn:ietf:params:xml:ns:xcap-caps "; + +/* get xxx(auids, namespaces or extensions) */ +static xdm_list_t* xdm_xcap_caps_xxx(xmlNodePtr rootNode, const char* root, const char* name1, const char* name2) +{ + xdm_list_t *xxx = 0; + xdm_list_item_t* item = 0; + xmlNodePtr node = 0; + + XDM_LIST_CREATE(xxx); + + node = xdm_xml_select_node(rootNode, + XDM_XML_NODE_SELECT_BY_NAME(root), + XDM_XML_NODE_SELECT_BY_NAME(name1), + XDM_XML_NODE_SELECT_CONTENT(), + XDM_XML_NODE_SELECT_END()); + + while(node = xdm_xml_find_node(node, name2, nft_next)) + { + if(node->children && node->children->type == XML_TEXT_NODE) + { + XDM_LIST_ITEM_CREATE(item); + item->data = xdm_strdup((const char*)node->children->content); + xdm_list_add_item(xxx, &item); + } + } + + return xxx; +} + +/* create xcap-caps context */ +/* ATTENTION: use 'xdm_xcap_caps_free' function to free the returned object*/ +xcap_caps_t* xdm_xcap_caps_create(const char* buffer, size_t size) +{ + xmlNodePtr root = 0; + xmlDocPtr docPtr = 0; + xcap_caps_t* caps = (xcap_caps_t*)malloc(sizeof(xcap_caps_t)); + memset(caps, 0, sizeof(xcap_caps_t)); + + docPtr = xmlParseMemory(buffer, (int)size); + if(docPtr) root = docPtr->children; + if(root) + { + caps->auids = xdm_xcap_caps_xxx(root, "xcap-caps", "auids", "auid"); + caps->extensions = xdm_xcap_caps_xxx(root, "xcap-caps", "extensions", "extension"); + caps->namespaces = xdm_xcap_caps_xxx(root, "xcap-caps", "namespaces", "namespace"); + } + + xmlFreeDoc(docPtr); + + return caps; +} + +/* free data (xcap_caps_t) */ +void xdm_xcap_caps_free(xcap_caps_t** caps) +{ + if(*caps) + { + XDM_LIST_SAFE_FREE((*caps)->auids); + XDM_LIST_SAFE_FREE((*caps)->namespaces); + XDM_LIST_SAFE_FREE((*caps)->extensions); + + free(*caps); + (*caps)=0; + } +} + +#undef CAPS_RETURN_IF_INVALID + +//xcap_caps_t* xdm_xcap_caps_create() +//{ +// int i; +// xdm_xml_element_t *auids = 0, *namespaces = 0, *elt; +// +// xcap_caps_t* caps = (xcap_caps_t*)malloc(sizeof(xcap_caps_t)); +// memset(caps, 0, sizeof(xcap_caps_t)); +// XDM_LIST_CREATE(caps->root); +// +// +// +// +// +// +// +// // +// // auids +// // +// xdm_xml_element_init_set(&auids, "auids", "", xt_none); /*auids root*/ +// for(i=0; i<4;i++) +// { +// switch(i) +// { +// case 0: +// { /* xcap-caps */ +// xdm_xml_element_init_set(&elt, "auid", "xcap-caps", xt_string); +// xdm_xml_elements_add(auids->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 1: +// { /* resource-lists */ +// xdm_xml_element_init_set(&elt, "auid", "resource-lists", xt_string); +// xdm_xml_elements_add(auids->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 2: +// { /* rls-services */ +// xdm_xml_element_init_set(&elt, "auid", "rls-services", xt_string); +// xdm_xml_elements_add(auids->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 3: +// { /* org.openmobilealliance.xcap-directory */ +// xdm_xml_element_init_set(&elt, "auid", "org.openmobilealliance.xcap-directory", xt_string); +// xdm_xml_elements_add(auids->elements, &elt, xdm_xml_element_free); +// break; +// } +// } +// } +// +// // +// // namespaces +// // +// xdm_xml_element_init_set(&namespaces, "namespaces", "", xt_none); /*namespaces root*/ +// for(i=0; i<5;i++) +// { +// switch(i) +// { +// case 0: +// { /* urn:ietf:params:xml:ns:xcap-caps */ +// xdm_xml_element_init_set(&elt, "namespace", "urn:ietf:params:xml:ns:xcap-caps", xt_string); +// xdm_xml_elements_add(namespaces->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 1: +// { /* urn:ietf:params:xml:ns:xcap-error */ +// xdm_xml_element_init_set(&elt, "namespace", "urn:ietf:params:xml:ns:xcap-error", xt_string); +// xdm_xml_elements_add(namespaces->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 2: +// { /* urn:ietf:params:xml:ns:resource-lists */ +// xdm_xml_element_init_set(&elt, "namespace", "urn:ietf:params:xml:ns:resource-lists", xt_string); +// xdm_xml_elements_add(namespaces->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 3: +// { /* urn:ietf:params:xml:ns:rls-services */ +// xdm_xml_element_init_set(&elt, "namespace", "urn:ietf:params:xml:ns:rls-services", xt_string); +// xdm_xml_elements_add(namespaces->elements, &elt, xdm_xml_element_free); +// break; +// } +// +// case 4: +// { /* urn:oma:params:ns:resource-list:oma-uriusage */ +// xdm_xml_element_init_set(&elt, "namespace", "urn:oma:params:ns:resource-list:oma-uriusage", xt_string); +// xdm_xml_elements_add(namespaces->elements, &elt, xdm_xml_element_free); +// break; +// } +// } +// } +// +// /* add auids */ +// xdm_list_add_data(caps->root, ((void**) &auids), xdm_xml_element_free); +// +// /* add namespaces */ +// xdm_list_add_data(caps->root, ((void**) &namespaces), xdm_xml_element_free); +// +// return caps; +//} diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_xcap-caps.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_xcap-caps.h new file mode 100644 index 00000000..d9fe7d73 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_xcap-caps.h @@ -0,0 +1,48 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ + +#ifndef _TINYXCAP_XDM_XCAP_CAPS_H_ +#define _TINYXCAP_XDM_XCAP_CAPS_H_ + +#include "tinyxcap_config.h" +#include "xdm_xml.h" + +/* urn:ietf:params:xml:ns:xcap-caps */ + +/* xcap-caps document */ +typedef struct xcap_caps_s +{ + xdm_list_t* auids; + xdm_list_t* extensions; + xdm_list_t* namespaces; +} +xcap_caps_t; + +TINYXCAP_API xcap_caps_t* xdm_xcap_caps_create(const char* buffer, size_t size); +TINYXCAP_API void xdm_xcap_caps_free(xcap_caps_t** caps); + +#endif /* _TINYXCAP_XDM_XCAP_CAPS_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_xml.c b/trunk/tinyXCAP/tinyXCAP/src/xdm_xml.c new file mode 100644 index 00000000..feb40f03 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_xml.c @@ -0,0 +1,241 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#include "xdm_xml.h" +#include "xdm_utils.h" + + +/* init namespace */ +void xdm_xml_namespace_init(xdm_xml_namespace_t* namespace) +{ + memset(namespace, 0, sizeof(xdm_xml_namespace_t)); +} + +/* free namespace */ +void xdm_xml_namespace_free(xdm_xml_namespace_t** namespace) +{ + XDM_SAFE_FREE((*namespace)->prefix); + XDM_SAFE_FREE((*namespace)->value); + free(*namespace); + + (*namespace) = 0; +} + +/* init element */ +void xdm_xml_element_init(xdm_xml_element_t* element) +{ + memset(element, 0, sizeof(xdm_xml_element_t)); +} + +/* init element and set values*/ +void xdm_xml_element_init_set(xdm_xml_element_t** element, const char* name, const char* value, xdm_xml_type_t type) +{ + XDM_XML_ELEMENT_CREATE((*element)); + XDM_LIST_CREATE((*element)->elements); + XDM_LIST_CREATE((*element)->attributes); + XDM_LIST_CREATE((*element)->namespaces); + (*element)->name = xdm_strdup(name); + (*element)->value = xdm_strdup(value); + (*element)->type = type; +} + +/* free element */ +void xdm_xml_element_free(void** _element) +{ + xdm_xml_element_t** element = (xdm_xml_element_t**)_element; + + XDM_SAFE_FREE((*element)->name); + XDM_SAFE_FREE((*element)->value); + XDM_LIST_SAFE_FREE((*element)->elements); + XDM_LIST_SAFE_FREE((*element)->attributes); + XDM_LIST_SAFE_FREE((*element)->namespaces); + + free(*element); + (*element) = 0; +} + +/* init attribute */ +void xdm_xml_attribute_init(xdm_xml_attribute_t* attribute) +{ + memset(attribute, 0, sizeof(xdm_xml_attribute_t)); +} + +/* free attribute */ +void xdm_xml_attribute_free(xdm_xml_attribute_t** attribute) +{ + XDM_SAFE_FREE((*attribute)->name); + XDM_SAFE_FREE((*attribute)->value); + + free(*attribute); + (*attribute) = 0; +} + +/* get namespace from xml document */ +xmlNsPtr xdm_xml_get_namespace(xmlDocPtr docPtr, xmlNodePtr node, const char *href) +{ + xmlNs *ns = *xmlGetNsList(docPtr, node); + while (ns) + { + if (!strcmp(ns->href, href)) return ns; + else ns = ns->next; + } + + return 0; +} + +/* find node by name */ +xmlNodePtr xdm_xml_find_node(const xmlNodePtr curr, const char* name, xdm_xml_node_find_type_t ftype) +{ + xmlNodePtr node = curr; + + while(node) + { + switch(ftype) + { + case nft_none: return (!xdm_stricmp(node->name, name))? node : 0; + case nft_children: node = node->children; break; + case nft_parent: node = node->parent; break; + case nft_next: node = node->next; break; + case nft_prev: node = node->prev; break; + default: return 0; + } /* switch */ + + /* check and return value if match */ + if( node && (!name || !xdm_stricmp(node->name, name)) ) return node; + } + + return 0; +} + +/* select node */ +xmlNodePtr xdm_xml_select_node(const xmlNodePtr root, ...) +{ + va_list list; + int step; + char* root_name = 0; + xmlNodePtr node = root; + + if(!node || !(node->name)) return 0; + + /* initialize variable arguments */ + va_start(list, root); + + while( node && (step=va_arg(list, xdm_xml_node_select_type_t)) != nst_end) + { + switch(step) + { + case nst_by_name: + { /* name */ + const char* qname = va_arg(list, const char*); + if(!xdm_stricmp(root->name, qname)){ + node = xdm_xml_find_node(node, 0, nft_children); + } + else{ + if(xdm_stricmp(node->name, qname)) + { /* do not match */ + node = xdm_xml_find_node(node, qname, nft_next); + } + else + { /* already match */ + node = node->children; + } + } + break; + } + + case nst_content: + { /**/ + node = xdm_xml_find_node(node, 0, nft_children); + break; + } + + case nst_att_value: + { /* qname, att_name */ + xmlAttrPtr attrPtr = 0; + int found = 0; + const char* qname = va_arg(list, const char*); + const char* att_name = va_arg(list, const char*); + node = xdm_xml_find_node(node, qname, nft_none); + while( node && !found ) + { + attrPtr = node->properties; + while(attrPtr) + { + if(attrPtr->type == XML_ATTRIBUTE_NODE && attrPtr->children) + { + if( !xdm_stricmp(attrPtr->name, att_name) ){ + node = attrPtr->children; + found = 1; + } + } + attrPtr = attrPtr->next; + } + if(!found) node = xdm_xml_find_node(node, 0, nft_next); + } + break; + } + + case nst_by_att: + { /* qname att_name att_value */ + xmlAttrPtr attrPtr = 0; + int found = 0; + const char* qname = va_arg(list, const char*); + const char* att_name = va_arg(list, const char*); + const char* att_value = va_arg(list, const char*); + node = xdm_xml_find_node(node, qname, nft_none); + while( node && !found ) + { + attrPtr = node->properties; + while(attrPtr) + { + if(attrPtr->type == XML_ATTRIBUTE_NODE && attrPtr->children) + { + if( !xdm_stricmp(attrPtr->name, att_name) + && ( (attrPtr->children->content && !xdm_stricmp(attrPtr->children->content, att_value)) || !att_value ) + ){ + found = 1; + } + } + attrPtr = attrPtr->next; + } + if(!found) node = xdm_xml_find_node(node, 0, nft_next); + } + + if(found && node) break; + else return 0; + + break; + } + default: return 0; + } /* switch */ + + /* skip all comments */ + XDM_XML_NODE_SKIP_COMMENTS(node); + + } /* while*/ + + return node; +} \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/src/xdm_xml.h b/trunk/tinyXCAP/tinyXCAP/src/xdm_xml.h new file mode 100644 index 00000000..4871b557 --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/src/xdm_xml.h @@ -0,0 +1,154 @@ +/**************************************************************************** + _ _ + | | | | + _ | | ___ _ _| | _ ____ ____ ____ ___ + / || |/ _ \| | | | || \ / _ | _ \ / _ |/ _ \ + ( (_| | |_| | |_| | |_) | ( | | | | ( ( | | |_| | + \____|\___/ \____|____/ \_||_|_| |_|\_|| |\___/ + (_____| + + Copyright (C) 2009 xxxyyyzzz + + This file is part of Open Source Doubango IMS Client Framework project. + + DOUBANGO 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 3 of the License, or + (at your option) any later version. + + DOUBANGO 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DOUBANGO. +****************************************************************************/ +#ifndef _TINYXCAP_XDM_XML_H_ +#define _TINYXCAP_XDM_XML_H_ + +#include "tinyxcap_config.h" +#include "xdm_list.h" +#include + +#define XDM_XML_NODE_IS_TEXTVALUE(node) (node && node->type==XML_TEXT_NODE) +#define XDM_XML_NODE_SAFE_GET_TEXTVALUE(node) XDM_XML_NODE_IS_TEXTVALUE(node)?(node->content):0 +#define XDM_XML_NODE_SKIP_COMMENTS(node) while(node && (node->type==XML_COMMENT_NODE)) node = xdm_xml_find_node(node, 0, nft_next); + + +#define XDM_XML_NODE_SELECT_BY_NAME(qname) nst_by_name, qname +#define XDM_XML_NODE_SELECT_BY_ATT(qname, att_name, att_value) nst_by_att, qname, att_name, att_value +#define XDM_XML_NODE_SELECT_ATT_VALUE(qname, att_name) nst_att_value, qname, att_name +#define XDM_XML_NODE_SELECT_CONTENT() nst_content +#define XDM_XML_NODE_SELECT_END() nst_end + +#define XDM_XML_NAMESPACE_CREATE(namespace) XDM_XXX_CREATE(namespace, xml_namespace) +#define XDM_XML_NAMESPACE_FREE(namespace) XDM_XXX_SAFE_FREE(namespace, xml_namespace) + +#define XDM_XML_ELEMENT_CREATE(element) XDM_XXX_CREATE(element, xml_element) +#define XDM_XML_ELEMENT_FREE(element) XDM_XXX_SAFE_FREE(element, xml_element) + +#define XDM_XML_ATTRIBUTE_CREATE(attribute) XDM_XXX_CREATE(attribute, xml_attribute) +#define XDM_XML_ATTRIBUTE_FREE(attribute) XDM_XXX_SAFE_FREE(attribute, xml_attribute) + +/* C and XML Schema mapping */ +typedef enum xdm_xml_type_e +{ + xt_none, + xt_string, /* xsd:string */ + xt_byte, /* xsd:byte */ + xt_unsignedByte, /* xsd:unsignedByte */ + xt_short, /* xsd:short */ + xt_unsignedShort, /* xsd:unsignedShort */ + xt_int, /* xsd:int */ + xt_unsignedInt, /* xsd:unsignedInt */ + xt_long, /* xsd:long */ + xt_boolean, /* xsd:boolean */ + xt_float, /* xsd:float */ + xt_double /* xsd:double */ +} +xdm_xml_type_t; + +/* node finding types */ +typedef enum xdm_xml_node_find_type_s +{ + nft_none, + nft_children, + nft_parent, + nft_next, + nft_prev +} +xdm_xml_node_find_type_t; + +/* elt selection types */ +typedef enum xdm_xml_node_select_type_s +{ + nst_by_name, + nst_by_att, + nst_att_value, + nst_content, + nst_end +} +xdm_xml_node_select_type_t; + +/* xml namespace */ +typedef struct xdm_xml_namespace_s +{ + char* prefix; + char* value; +} +xdm_xml_namespace_t; + +/* xml attribute */ +typedef struct xdm_xml_attribute_s +{ + char* name; + void* value; + xdm_xml_type_t type; +} +xdm_xml_attribute_t; + +/* xml element */ +typedef struct xdm_xml_element_s +{ + char* name; + void* value; + xdm_list_t* elements; + xdm_list_t* attributes; + xdm_list_t* namespaces; + xdm_xml_type_t type; +} +xdm_xml_element_t; + +typedef xdm_list_t xdm_xml_elements_t; +typedef xdm_list_t xdm_xml_attributes_t; +typedef xdm_list_t xdm_xml_namespaces_t; + +#define xdm_xml_elements_init xdm_list_init +#define xdm_xml_attributes_init xdm_list_init +#define xdm_xml_namespaces_init xdm_list_init + +#define xdm_xml_elements_add xdm_list_add_data +#define xdm_xml_attributes_add xdm_list_add_data +#define xdm_xml_namespaces_add xdm_list_add_data + +#define xdm_xml_elements_free xdm_list_free +#define xdm_xml_attributes_free xdm_list_free +#define xdm_xml_namespaces_free xdm_list_free + +void xdm_xml_namespace_init(xdm_xml_namespace_t* namespace); +void xdm_xml_namespace_free(xdm_xml_namespace_t** namespace); + +void xdm_xml_element_init(xdm_xml_element_t* element); +void xdm_xml_element_init_set(xdm_xml_element_t** element, const char* name, const char* value, xdm_xml_type_t type); +void xdm_xml_element_free(void** element); + +void xdm_xml_attribute_init(xdm_xml_attribute_t* attribute); +void xdm_xml_attribute_free(xdm_xml_attribute_t** attribute); + +xmlNsPtr xdm_xml_get_namespace(xmlDocPtr docPtr, xmlNodePtr node, const char *href); +xmlNodePtr xdm_xml_find_node(const xmlNodePtr curr, const char* name, xdm_xml_node_find_type_t ftype); +xmlNodePtr xdm_xml_select_node(const xmlNodePtr root, ...); + + +#endif /* _TINYXCAP_XDM_XML_H_ */ \ No newline at end of file diff --git a/trunk/tinyXCAP/tinyXCAP/tinyXCAP.vcproj b/trunk/tinyXCAP/tinyXCAP/tinyXCAP.vcproj new file mode 100644 index 00000000..4d5fe96e --- /dev/null +++ b/trunk/tinyXCAP/tinyXCAP/tinyXCAP.vcproj @@ -0,0 +1,494 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +