123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- /*
- * Copyright (C) 2009 Mamadou Diop.
- *
- * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
- *
- * This file is part of Open Source Doubango Framework.
- *
- * 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_STACK_H
- #define _TEST_STACK_H
- #define PAYLOAD_LIST "<list name=\"newlist\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" \
- "<display-name>newlist</display-name>" \
- "</list>"
- #define PAYLOAD_ENTRY "<entry uri=\""XUI"\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" \
- "<display-name>"XUI"</display-name>" \
- "</entry>"
- int test_stack_callback(const thttp_event_t *httpevent)
- {
- switch(httpevent->type) {
- case thttp_event_message: { /* New HTTP message */
- if(THTTP_MESSAGE_IS_RESPONSE(httpevent->message)) {
- const thttp_header_ETag_t* etag;
- TSK_DEBUG_INFO("=== %d ==> %s", THTTP_RESPONSE_CODE(httpevent->message), THTTP_MESSAGE_CONTENT(httpevent->message));
- // You can use
- if((etag = (const thttp_header_ETag_t*)thttp_message_get_header(httpevent->message, thttp_htype_ETag))) {
- TSK_DEBUG_INFO("Etag=%s", etag->value);
- }
- }
- else {
- }
- break;
- }
- case thttp_event_auth_failed: {
- TSK_DEBUG_INFO("=== auth failed.");
- break;
- }
- case thttp_event_closed: { /* HTTP connection closed (informational) */
- TSK_DEBUG_INFO("=== closed.");
- break;
- }
- default: {
- break;
- }
- }
- return 0;
- }
- void test_stack()
- {
- txcap_stack_handle_t* stack = tsk_null;
- int ret;
- stack = txcap_stack_create(test_stack_callback, XUI, PASSWORD, XCAP_ROOT,
- #if defined(ANDROID)
- TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_LOCAL_IP, "10.0.2.15"),
- #endif
- // stack-level options
- TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_TIMEOUT, "6000"),
- // stack-level headers
- TXCAP_STACK_SET_HEADER("Connection", "Keep-Alive"),
- TXCAP_STACK_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
- TXCAP_STACK_SET_HEADER("X-3GPP-Intended-Identity", XUI),
- TXCAP_STACK_SET_NULL());
- if((ret = txcap_stack_start(stack))) {
- goto bail;
- }
- /* add user auids */
- txcap_stack_set(stack,
- // add new AUIDs
- TXCAP_STACK_SET_AUID("xcap-caps2", "application/xcap-caps2+xml", "urn:ietf:params:xml:ns:xcap-caps2", "index2", tsk_true),
- TXCAP_STACK_SET_AUID("resource-lists2", "application/resource-lists+xml2", "urn:ietf:params:xml:ns:resource-lists2", "index2", tsk_false),
- TXCAP_STACK_SET_NULL()); /* mandatory */
- //== get xcap-caps document
- ret = txcap_action_fetch_document(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // action-level headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // selector
- TXCAP_ACTION_SET_SELECTOR("xcap-caps",
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- /*
- //== get resource-lists document
- ret = txcap_action_fetch_document(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- //action-level headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== get 'rcs' list
- ret = txcap_action_fetch_element(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // action-level headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Retrieve the 2nd list
- ret = txcap_action_fetch_element(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // action-level selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_POS("list", 2),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Retrieve the 4th list (wildcard)
- ret = txcap_action_fetch_element(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // action-level selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_POS("*", 4),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Retrieve the entry with: uri=XUI and list='rcs'
- ret = txcap_action_fetch_element(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // action-level selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Retrieve XUI's display-name ==> 404
- ret = txcap_action_fetch_attribute(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // action-level selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
- TXCAP_SELECTOR_NODE_SET_NAME("display-name"),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Retrieve the display-name of the fisrt entry from the 'rcs' list ==> 404
- ret = txcap_action_fetch_attribute(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // action-level selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
- TXCAP_SELECTOR_NODE_SET_POS("entry", 1),
- TXCAP_SELECTOR_NODE_SET_NAME("display-name"),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Retrieve the entry with: uri='XUI' from position 1 from 'rcs' list
- ret = txcap_action_fetch_element(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- // headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // action-level selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
- TXCAP_SELECTOR_NODE_SET_POS_ATTRIBUTE("entry", 1, "uri", XUI),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Add newlist
- ret = txcap_action_create_element(stack,
- // selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "newlist"),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // payload
- TXCAP_ACTION_SET_PAYLOAD(PAYLOAD_LIST, strlen(PAYLOAD_LIST)),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Add entry
- ret = txcap_action_create_element(stack,
- // selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "newlist"),
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // payload
- TXCAP_ACTION_SET_PAYLOAD(PAYLOAD_ENTRY, strlen(PAYLOAD_ENTRY)),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Add entry using dummy URI
- ret = txcap_action_create_element(stack,
- // dummy uri
- TXCAP_ACTION_SET_REQUEST_URI("http://doubango.org/services/dummy/"XUI),
- // payload
- TXCAP_ACTION_SET_PAYLOAD(PAYLOAD_ENTRY, strlen(PAYLOAD_ENTRY)),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- //== Delete entry
- ret = txcap_action_delete_element(stack,
- // selector
- TXCAP_ACTION_SET_SELECTOR("resource-lists",
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "newlist"),
- TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- getchar();
- ret = txcap_action_fetch_document(stack,
- // action-level options
- TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
- //action-level headers
- TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
- // selector
- TXCAP_ACTION_SET_SELECTOR("org.openmobilealliance.pres-content",
- TXCAP_SELECTOR_NODE_SET_NULL()),
- // ends parameters
- TXCAP_ACTION_SET_NULL()
- );
- */
- bail:
- getchar();
- TSK_OBJECT_SAFE_FREE(stack);
- }
- #endif /* _TEST_STACK_H */
|