From: K.J. Kao Date: Thu, 24 Sep 2015 02:14:29 +0000 (+0800) Subject: Merge branch 'remote-access2' X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01be9765a95ede47003777ee576fe9a4de4229e5;p=contrib%2Fiotivity.git Merge branch 'remote-access2' Signed-off-by: K.J. Kao Conflicts: build_common/SConscript resource/csdk/SConscript Change Set 4: print build libstrophe and wksxmppxep messages. Change Set 5: update wksxmppxep, 'add build flag -Wno-unused' Change Set 6: correct check path Change-Id: I73960aba41495c5ef6f0f227d093fb1cb4f3bf92 Signed-off-by: Mandeep Shetty Signed-off-by: Sakthivel Samidurai Signed-off-by: K.J. Kao --- 01be9765a95ede47003777ee576fe9a4de4229e5 diff --cc auto_build.sh index 2a09953,2a09953..4218173 --- a/auto_build.sh +++ b/auto_build.sh @@@ -49,13 -49,13 +49,13 @@@ function build_linux_unsecured_with_ra( { echo "*********** Build for linux With Remote Access *************" -- scons RELEASE=$1 WITH_RA=1 $2 ++ scons RELEASE=$1 WITH_RA=1 WITH_RA_IBB=1 $2 } function build_linux_secured_with_ra() { echo "*********** Build for linux With Remote Access & Security ************" -- scons RELEASE=$1 WITH_RA=1 SECURED=1 $2 ++ scons RELEASE=$1 WITH_RA=1 WITH_RA_IBB=1 SECURED=1 $2 } function build_android() diff --cc build_common/SConscript index 5d71984,9c0b73e..2fbc863 --- a/build_common/SConscript +++ b/build_common/SConscript @@@ -79,8 -79,8 +79,12 @@@ help_vars.Add(EnumVariable('TARGET_OS' help_vars.Add(BoolVariable('WITH_RA', 'Build with Remote Access module', False)) ++ +help_vars.Add(BoolVariable('SIMULATOR', 'Build with simulator module', False)) + + help_vars.Add(BoolVariable('WITH_RA_IBB', 'Build with Remote Access module(workssys)', False)) + ++ if target_os in targets_disallow_multitransport: help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP'])) else: diff --cc build_common/external_libs.scons index 8ab0cd4,65c25ec..2e28220 --- a/build_common/external_libs.scons +++ b/build_common/external_libs.scons @@@ -134,6 -138,3 +138,6 @@@ env.AddMethod(__configure, "Configure" env.AddMethod(__download, "Download") env.AddMethod(__install_head_file, "InstallHeadFile") env.AddMethod(__install_lib, "InstallLib") + +if env.get('SECURED') == '1': - SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript')) ++ SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'sqlite3', 'SConscript')) diff --cc extlibs/libstrophe/SConscript index 0000000,55871d6..a5b18a2 mode 000000,100644..100644 --- a/extlibs/libstrophe/SConscript +++ b/extlibs/libstrophe/SConscript @@@ -1,0 -1,75 +1,75 @@@ + ###################################################################### + # ref. raxmpp library build script + # + ###################################################################### + import os + import commands + + Import('env') + + base_dir = env.get('SRC_DIR') + target_os = env.get('TARGET_OS') + target_arch = env.get('TARGET_ARCH') + build_path = Dir('.').abspath + + with_ra_ibb = env.get('WITH_RA_IBB') + PKG_NAME = 'strophe' + SRC_NAME = 'libstrophe' + EXT_NAME = 'libstrophe' + EXT_BASE = 'extlibs/' + EXT_NAME + EXT_PATH = EXT_BASE + '/' + SRC_NAME + SRC_PATH = base_dir + '/' + EXT_PATH + INC_PATH = SRC_PATH + LIB_PATH = SRC_PATH + '/' + '.libs' + + if with_ra_ibb: + # check 'libstrophe' library, if it doesn't exits, ask user to download it + if not os.path.exists(SRC_NAME): + raxmpp_env = Environment(ENV = os.environ) + c = raxmpp_env.Action(['git clone https://github.com/strophe/libstrophe.git ' + SRC_NAME, + 'cd ' + SRC_NAME + ' && git checkout 527bc0573a52f2af3ecad5b9ef39aeec7b669f77' + ]) + + print 'Downloading xmpp library ...' + if raxmpp_env.Execute(c): + print ''' + *********************************** Error: *********************************************** + * Please download ra_xmpp as following: + * $ git clone https://github.com/strophe/libstrophe.git extlibs/libstrophe/libstrophe + * $ cd extlibs/libstrophe/libstrophe + * $ git checkout 527bc0573a52f2af3ecad5b9ef39aeec7b669f77 + ****************************************************************************************** + ''' + Exit(1) + else: + print 'Download xmpp library complete' + + print 'Building with ' + SRC_NAME + #print 'base_dir', base_dir + #print 'target_os', target_os + #print 'target_arch', target_arch + + foo=commands.getoutput('patch -N -p1 -d libstrophe < strophe-xmpp_conn_is_secured.patch') + print foo + + os.chdir(SRC_NAME) + #sconsflags = ' RELEASE=true' if env['RELEASE'] else ' RELEASE=false' + if not os.path.exists('configure') : + foo=commands.getoutput('./bootstrap.sh') - #print foo ++ print foo + if not os.path.exists('config.status') : + foo=commands.getoutput('./configure') - #print foo ++ print foo + if not os.path.exists('.libs/libstrophe.a') : + foo=commands.getoutput('make libstrophe.la') - #print foo ++ print foo + if not os.path.exists('.libs/libstrophe.a') : + print 'Building with ' + SRC_NAME + ' failed.' + Exit(2) + + print 'Building with ' + SRC_NAME + ' Completely.' + env.AppendUnique(CPPPATH = [INC_PATH], RALIBS = ['strophe', 'ssl', 'crypto', 'resolv', 'expat'], RALIBPATH = [LIB_PATH], RARPATH = [LIB_PATH]) + + if env.GetOption('clean') : + act = env.Action(['cd ' + SRC_PATH, 'make clean']) + env.Execute(act) diff --cc extlibs/wksxmppxep/SConscript index 0000000,f30b3cd..c6bb6ce mode 000000,100644..100644 --- a/extlibs/wksxmppxep/SConscript +++ b/extlibs/wksxmppxep/SConscript @@@ -1,0 -1,55 +1,63 @@@ + ###################################################################### + # Ref. libstrophe library build script + # + ###################################################################### + import os + import commands + + Import('env') + + base_dir = env.get('SRC_DIR') + target_os = env.get('TARGET_OS') + target_arch = env.get('TARGET_ARCH') + + with_ra_ibb = env.get('WITH_RA_IBB') + + SRC_NAME = 'wks_xep0047' + EXT_NAME = 'wksxmppxep' + EXT_BASE = 'extlibs/' + EXT_NAME + EXT_PATH = EXT_BASE + '/' + SRC_NAME + SRC_PATH = base_dir + '/' + EXT_PATH + INC_PATH = SRC_PATH + '/include' + LIB_PATH = SRC_PATH + + if with_ra_ibb: + env.SConscript(base_dir + '/extlibs/libstrophe/SConscript') + if not os.path.exists(SRC_NAME): + raxmpp_env = Environment(ENV = os.environ) + c = raxmpp_env.Action(['git clone https://github.com/WorksSystems/wks_xep0047.git ' + SRC_NAME, - 'cd ' + SRC_NAME + ' && git checkout 1d2edd460c0e85e2b647176e74ebbe519e6019de' ++ 'cd ' + SRC_NAME + ' && git checkout 8e9f42d02a0f416001065d1cddc1ab07974cef14' + ]) + + print 'Downloading', SRC_NAME ,'library ...' + if raxmpp_env.Execute(c): + print ''' + *********************************** Error: *********************************************** + * Please download ra_xmpp as following: + * $ git clone https://github.com/WorksSystems/wksxmpp_chat.git extlibs/wksxmppxep/wksxmpp_chat + * $ cd extlibs/wksxmppxep/wksxmpp_chat - * $ git checkout 9f5d726df9779bec5d3036acfbca70c97958921d ++ * $ git checkout 8e9f42d02a0f416001065d1cddc1ab07974cef14 + ****************************************************************************************** + ''' + Exit(1) + else: + print 'Download', SRC_NAME, 'library complete' + ++ print 'Building with ' + SRC_NAME + os.chdir(SRC_NAME) - if not os.path.exists(SRC_NAME + '/libwksxmppxep.so') : ++ if not os.path.exists('libwksxmppxep.so') : + LIBSTROPHE_BASE=base_dir + '/extlibs/libstrophe/libstrophe' + foo=commands.getoutput('make LIBSTROPHE_BASE=' + LIBSTROPHE_BASE + ' libraries') - #print foo ++ print foo ++ ++ if not os.path.exists('libwksxmppxep.so') : ++ print 'Building with ' + SRC_NAME + ' failed.' ++ Exit(2) ++ ++ print 'Building with ' + SRC_NAME + ' Completely.' ++ + env.PrependUnique(CPPPATH = [INC_PATH], RALIBS = ['wksxmppxep', 'm', 'crypto'], RALIBPATH = [LIB_PATH], RARPATH = [LIB_PATH]) + + if env.GetOption('clean') : + act = env.Action(['cd ' + SRC_PATH, 'make clean']) + env.Execute(act) diff --cc resource/csdk/SConscript index 63b12c9,e0f0651..3ec7d08 --- a/resource/csdk/SConscript +++ b/resource/csdk/SConscript @@@ -73,10 -69,11 +74,13 @@@ liboctbstack_env.AppendUnique(LIBPATH if target_os in ['android', 'linux', 'tizen']: liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction']) + - if with_ra: - liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp']) + if with_ra_ibb: + liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH']) + else : + if with_ra: + liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp']) + liboctbstack_env.AppendUnique(LIBS = ['coap', 'm']) if target_os == 'tizen': diff --cc resource/csdk/connectivity/src/ra_adapter/caraadapter.c index 4ae741f,a5bea52..5bc7d37 --- a/resource/csdk/connectivity/src/ra_adapter/caraadapter.c +++ b/resource/csdk/connectivity/src/ra_adapter/caraadapter.c @@@ -34,7 -34,571 +34,572 @@@ #include "caremotehandler.h" #include "cacommon.h" + #ifdef RA_ADAPTER_IBB + #include "caprotocolmessage.h" + #include "xmpp_helper.h" + #include "xmpp_utils.h" + #include "xmpp_ibb.h" + #include "xmpp_utils.h" + #else + #include "ra_xmpp.h" + #endif + + #ifdef RA_ADAPTER_IBB + #define SET_BUT_NOT_USED(x) (void) x + /** + * Logging tag for module name. + */ + #define RA_ADAPTER_TAG "RA_ADAP_IBB" + + /** + * Network Packet Received Callback to CA. + */ + static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; + + /** + * Network Changed Callback to CA. + */ + static CANetworkChangeCallback g_networkChangeCallback = NULL; + + /** + * Holds XMPP data information. + */ + #define RA_MAX_HOSTNAME_LENGTH 256 + #define RA_MAX_PASSWORD_LENGTH 64 + typedef struct + { + xmpp_t *xmpp; + int port; + char hostName[RA_MAX_HOSTNAME_LENGTH]; + char password[RA_MAX_PASSWORD_LENGTH]; + char jid[CA_RAJABBERID_SIZE]; + CANetworkStatus_t connectionStatus; + CAJidBoundCallback jidBoundCallback; + } CARAXmppData_t; + + static ca_mutex g_raadapterMutex = NULL; + + static CARAXmppData_t g_xmppData = {.xmpp = NULL, .port = 5222, .hostName = {0}, + .password = {0}, .jid = {0}, .connectionStatus = CA_INTERFACE_DOWN, + .jidBoundCallback = NULL}; + + static void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status); + + void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status) + { + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange IN"); + + g_xmppData.connectionStatus = status; + + CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, + CA_ADAPTER_REMOTE_ACCESS, + address, 0); + if (!localEndpoint) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!"); + return; + } + CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback; + if (networkChangeCallback) + { + networkChangeCallback(localEndpoint, status); + } + else + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL"); + } + + CAFreeEndpoint(localEndpoint); + + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT"); + } + + #define MAX_IBB_SESSION_ID_LENGTH 32 + /* Ref. octypes.h */ + #define OBSERVE_REGISTER 0 + #define OBSERVE_DEREGISTER 1 + /* Ref. octypes.h */ + + static ilist_t * g_observerList = NULL; + + typedef struct _obs_item_t + { + char sessid[MAX_IBB_SESSION_ID_LENGTH + 1]; + int option; + } obs_item_t; + + static bool CARAFindSessID(obs_item_t *item, char *key) + { + if (item == NULL || key == NULL) + { + return false; + } + if (strcmp(item->sessid, key) == 0) + { + return true; + } + else + { + return false; + } + } + + static bool CARAPDUIsRequest(uint32_t x) + { + return (x == CA_GET || x == CA_POST || x == CA_PUT || x == CA_DELETE); + } + + static void CARAUpdateObsList(int option, char *sid) + { + if (option == OBSERVE_REGISTER) + { + obs_item_t *item = (obs_item_t *) OICMalloc(sizeof(*item)); + OICStrcpy(item->sessid, sizeof(item->sessid), sid); + item->option = OBSERVE_REGISTER; + ilist_add(g_observerList, item); + } + else if (option == OBSERVE_DEREGISTER) + { + obs_item_t *item = ilist_finditem_func(g_observerList, (find_fp) CARAFindSessID, sid); + if (item != NULL) + { + item->option = OBSERVE_DEREGISTER; + } + } + } + -static int CARAGetReqObsOption(coap_pdu_t *pdu) ++static int CARAGetReqObsOption(coap_pdu_t *pdu, const CAEndpoint_t *endPoint) + { + uint32_t obsopt = -1; + + CARequestInfo_t *reqInfo = (CARequestInfo_t *) OICMalloc(sizeof(*reqInfo)); + VERIFY_NON_NULL_RET(reqInfo, RA_ADAPTER_TAG, "Memory alloc of CARequestInfo_t failed!", -1); + - CAResult_t result = CAGetRequestInfoFromPDU(pdu, reqInfo); ++ CAResult_t result = CAGetRequestInfoFromPDU(pdu, endPoint, reqInfo); + if (CA_STATUS_OK != result) + { + OICFree(reqInfo); + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Get Request Info failed!"); + return -1; + } + if (!CARAPDUIsRequest(reqInfo->method)) + { + OICFree(reqInfo); + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "It is not a request data."); + return -1; + } + + uint8_t numOpt = reqInfo->info.numOptions; + CAHeaderOption_t *options = reqInfo->info.options; + for (uint8_t i = 0; i < numOpt; i++) + { + if(options[i].protocolID == CA_COAP_ID && + options[i].optionID == COAP_OPTION_OBSERVE) + { + obsopt = options[i].optionData[0]; + break; + } + } + OICFree(reqInfo); + return obsopt; + } + + static int CARAErrorCB(xmpp_ibb_session_t *sess, xmpperror_t *xerr) + { + OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "%s(): code(%d) tyep'%s' mesg'%s'", + __FUNCTION__, xerr->code, xerr->type, xerr->mesg); + SET_BUT_NOT_USED(sess); + SET_BUT_NOT_USED(xerr); + return 0; + } + + static int CARAOpenCB(xmpp_ibb_session_t *sess, char *type) + { + OIC_LOG_V(DEBUG, RA_ADAPTER_TAG, "%s(): set type '%s'", __FUNCTION__, type); + SET_BUT_NOT_USED(sess); + SET_BUT_NOT_USED(type); + return 0; + } + + static int CARACloseCB(xmpp_ibb_session_t *sess, char *type) + { + OIC_LOG_V(DEBUG, RA_ADAPTER_TAG, "%s(): set type '%s'", __FUNCTION__, type); + char *sid = xmpp_ibb_get_sid(sess); + obs_item_t *item = ilist_finditem_func(g_observerList, (find_fp) CARAFindSessID, sid); + if (item != NULL) + { + ilist_remove(g_observerList, item); + OICFree(item); + } + SET_BUT_NOT_USED(type); + return 0; + } + + static char *CARAGetSIDFromPDU(coap_pdu_t *pdu) + { + static char s_sid[MAX_IBB_SESSION_ID_LENGTH + 1] = {0}; + + VERIFY_NON_NULL_RET(pdu, RA_ADAPTER_TAG, "Invalid parameter!", NULL); + - if (pdu->hdr->token_length * 2 > MAX_IBB_SESSION_ID_LENGTH) ++ if (pdu->hdr->coap_hdr_udp_t.token_length * 2 > MAX_IBB_SESSION_ID_LENGTH) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Token length more than expected!"); + return NULL; + } + + char hex[3] = {0}; - for (int i = 0; i < pdu->hdr->token_length; i++) ++ for (int i = 0; i < pdu->hdr->coap_hdr_udp_t.token_length; i++) + { - snprintf(hex, 3, "%02x", pdu->hdr->token[i]); ++ snprintf(hex, 3, "%02x", pdu->hdr->coap_hdr_udp_t.token[i]); + OICStrcat(s_sid, sizeof(s_sid), hex); + } + + return s_sid; + } + + static int CARARecvCB(xmpp_ibb_session_t *sess, xmppdata_t *xdata) + { + if (xdata == NULL) + { + /* xdata == NULL, send ack result */ + return 0; + } + + char *msg = xdata->data; + char *from = xmpp_ibb_get_remote_jid(sess); + if (g_networkPacketCallback) + { + VERIFY_NON_NULL_RET(from, RA_ADAPTER_TAG, "from sender is NULL", -1); + VERIFY_NON_NULL_RET(msg, RA_ADAPTER_TAG, "message is NULL", -1); + + OIC_LOG_V (DEBUG, RA_ADAPTER_TAG, "Message received from %s", from); + + CAEndpoint_t *endPoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, + CA_ADAPTER_REMOTE_ACCESS, from, 0); + if (!endPoint) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "EndPoint creation failed!"); + return -1; + } + uint32_t code = CA_NOT_FOUND; - coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU(xdata->data, xdata->size, &code); ++ coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU(xdata->data, xdata->size, &code, ++ endPoint); + char *sid = CARAGetSIDFromPDU(pdu); - int obsopt = CARAGetReqObsOption(pdu); ++ int obsopt = CARAGetReqObsOption(pdu, endPoint); + coap_delete_pdu(pdu); + + if (CARAPDUIsRequest(code)) + { + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "this is a request data"); + if (obsopt == OBSERVE_DEREGISTER || obsopt == OBSERVE_REGISTER) + { + CARAUpdateObsList(obsopt, sid); + } + } + else + { + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "this is a response data"); + obs_item_t *item = ilist_finditem_func(g_observerList, (find_fp) CARAFindSessID, sid); + if (item != NULL) + { + if (item->option == OBSERVE_DEREGISTER) + { + xmpp_ibb_close(sess); + ilist_remove(g_observerList, item); + OICFree(item); + } + } + else + { + xmpp_ibb_close(sess); + } + } + + void *buf = NULL; + xmpp_ibb_userdata_alloc(sess, &buf, xdata->size); + if (!buf) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Memory alloc of message failed!"); + CAFreeEndpoint(endPoint); + return -1; + } + memcpy(buf, xdata->data, xdata->size); + CASecureEndpoint_t sep = + {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = CA_DEFAULT_FLAGS}}; + memcpy(&sep.endpoint, endPoint, sizeof(sep.endpoint)); + g_networkPacketCallback(&sep, buf, xdata->size); + + CAFreeEndpoint (endPoint); + } + else + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "No callback for RA received message found"); + } + return 0; + } + + static int CARAConnHandler(xmpp_t *xmpp, xmppconn_info_t *conninfo, void *udata) + { + if (conninfo->connevent != 0) + { + OIC_LOG_V(ERROR, RA_ADAPTER_TAG, " status(%d) error(%d) errorType(%d) errorText '%s'\n", + conninfo->connevent, conninfo->error, conninfo->errortype, + conninfo->errortext); + CARANotifyNetworkChange(g_xmppData.jid, CA_INTERFACE_DOWN); + return -1; + } + OIC_LOG_V(DEBUG, RA_ADAPTER_TAG, "Bound JID: '%s'", xmpphelper_get_bound_jid(xmpp)); + if (g_xmppData.jidBoundCallback != NULL) + { + g_xmppData.jidBoundCallback((char *) xmpphelper_get_bound_jid(xmpp)); + } + CARANotifyNetworkChange(xmpphelper_get_bound_jid(xmpp), CA_INTERFACE_UP); + VERIFY_NON_NULL_RET(udata, RA_ADAPTER_TAG, "Invalid parameter!", 0); + return 0; + } + + CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, + CANetworkPacketReceivedCallback networkPacketCallback, + CANetworkChangeCallback netCallback, ca_thread_pool_t handle) + { + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN"); + if (!registerCallback || !networkPacketCallback || !netCallback || !handle) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); + return CA_STATUS_INVALID_PARAM; + } + + g_networkChangeCallback = netCallback; + g_networkPacketCallback = networkPacketCallback; + + CAConnectivityHandler_t raHandler = { + .startAdapter = CAStartRA, + .startListenServer = CAStartRAListeningServer, + .startDiscoveryServer = CAStartRADiscoveryServer, + .sendData = CASendRAUnicastData, + .sendDataToAll = CASendRAMulticastData, + .GetnetInfo = CAGetRAInterfaceInformation, + .readData = CAReadRAData, + .stopAdapter = CAStopRA, + .terminate = CATerminateRA}; + registerCallback(raHandler, CA_ADAPTER_REMOTE_ACCESS); + #ifdef NDEBUG + xmpp_log_t *log = xmpp_get_default_logger(XMPP_LEVEL_ERROR); + #else + xmpp_log_t *log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); + #endif + g_xmppData.xmpp = xmpphelper_new(CARAConnHandler, NULL, log, NULL); + xmpphelper_force_tls(g_xmppData.xmpp); + g_observerList = ilist_new(); + + return CA_STATUS_OK; + } + + CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo) + { + if (!caraInfo) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); + return CA_STATUS_INVALID_PARAM; + } + if (caraInfo->hostName != NULL) + { + OICStrcpy(g_xmppData.hostName, sizeof(g_xmppData.hostName), caraInfo->hostName); + } + else + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); + return CA_STATUS_INVALID_PARAM; + } + if (caraInfo->userName != NULL && strlen(caraInfo->userName) != 0) + { + OICStrcpy(g_xmppData.jid, sizeof(g_xmppData.jid), caraInfo->userName); + } + else + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); + return CA_STATUS_INVALID_PARAM; + } + if (caraInfo->xmppDomain != NULL && strlen(caraInfo->xmppDomain) != 0) + { + OICStrcat(g_xmppData.jid, sizeof(g_xmppData.jid), "@"); + OICStrcat(g_xmppData.jid, sizeof(g_xmppData.jid), caraInfo->xmppDomain); + if (caraInfo->resource != NULL && strlen(caraInfo->resource) != 0) + { + OICStrcat(g_xmppData.jid, sizeof(g_xmppData.jid), "/"); + OICStrcat(g_xmppData.jid, sizeof(g_xmppData.jid), caraInfo->resource); + } + } + if (caraInfo->password != NULL) + { + OICStrcpy(g_xmppData.password, sizeof(g_xmppData.password), caraInfo->password); + } + g_xmppData.port = caraInfo->port; + g_xmppData.jidBoundCallback = caraInfo->jidBoundCallback; + + return CA_STATUS_OK; + } + + void CATerminateRA() + { + CAStopRA(); + ilist_destroy(g_observerList); + xmpphelper_join(g_xmppData.xmpp); + xmpphelper_release(g_xmppData.xmpp); + g_xmppData.xmpp = NULL; + } + + CAResult_t CAStartRA() + { + OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Starting RA adapter")); + + if (!g_xmppData.xmpp) + { + OIC_LOG (ERROR, RA_ADAPTER_TAG, "CAStartRA(): g_xmppData.xmpp == NULL"); + return CA_STATUS_FAILED; + } + + g_raadapterMutex = ca_mutex_new (); + if (!g_raadapterMutex) + { + OIC_LOG (ERROR, RA_ADAPTER_TAG, PCF("Memory allocation for mutex failed.")); + return CA_MEMORY_ALLOC_FAILED; + } + + ca_mutex_lock (g_raadapterMutex); + + xmpphelper_connect(g_xmppData.xmpp, g_xmppData.hostName, g_xmppData.port, + g_xmppData.jid, g_xmppData.password); + xmpp_ibb_reg_funcs_t regfuncs; + regfuncs.open_cb = CARAOpenCB; + regfuncs.close_cb = CARACloseCB; + regfuncs.recv_cb = CARARecvCB; + regfuncs.error_cb = CARAErrorCB; + xmpp_ibb_register(xmpphelper_get_conn(g_xmppData.xmpp), ®funcs); + + xmpphelper_run(g_xmppData.xmpp); + + ca_mutex_unlock (g_raadapterMutex); + + OIC_LOG(DEBUG, RA_ADAPTER_TAG, "RA adapter started succesfully"); + return CA_STATUS_OK; + } + + CAResult_t CAStopRA() + { + OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Stopping RA adapter")); + + xmpphelper_stop(g_xmppData.xmpp); + xmpp_ibb_unregister(xmpphelper_get_conn(g_xmppData.xmpp)); + if (!g_raadapterMutex) + { + ca_mutex_free (g_raadapterMutex); + g_raadapterMutex = NULL; + } + OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Stopped RA adapter successfully")); + return CA_STATUS_OK; + } + + int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data, + uint32_t dataLength) + { + if (!remoteEndpoint || !data) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); + return -1; + } + + if (0 == dataLength) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Data length is 0!"); + return 0; + } + OIC_LOG_V(DEBUG, RA_ADAPTER_TAG, "Sending unicast data to %s", remoteEndpoint->addr); + + uint32_t code = CA_NOT_FOUND; - coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU(data, dataLength, &code); ++ coap_pdu_t *pdu = (coap_pdu_t *) CAParsePDU(data, dataLength, &code, remoteEndpoint); + char *sid = CARAGetSIDFromPDU(pdu); - int obsopt = CARAGetReqObsOption(pdu); ++ int obsopt = CARAGetReqObsOption(pdu, remoteEndpoint); + coap_delete_pdu(pdu); + + ca_mutex_lock (g_raadapterMutex); + if (CA_INTERFACE_UP != g_xmppData.connectionStatus) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, RA not connected"); + ca_mutex_unlock (g_raadapterMutex); + return -1; + } + + xmpp_ibb_session_t *sess = xmpp_ibb_get_session_by_sid(sid); + if (sess == NULL) + { + sess = xmpp_ibb_open(xmpphelper_get_conn(g_xmppData.xmpp), (char * const) remoteEndpoint->addr, sid); + if (sess == NULL) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "IBB session establish failed!"); + ca_mutex_unlock (g_raadapterMutex); + return -1; + } + } + if (CARAPDUIsRequest(code)) + { + if (obsopt == OBSERVE_REGISTER || obsopt == OBSERVE_DEREGISTER) + { + CARAUpdateObsList(obsopt, sid); + } + } + xmppdata_t xdata = {.data = (char *) data, .size = dataLength}; + int rc = xmpp_ibb_send_data(sess, &xdata); + ca_mutex_unlock (g_raadapterMutex); + if (rc < 0) + { + OIC_LOG(ERROR, RA_ADAPTER_TAG, "IBB send data failed!"); + return -1; + } + + OIC_LOG_V(INFO, RA_ADAPTER_TAG, "Successfully dispatched bytes[%d] to addr[%s]", + dataLength, remoteEndpoint->addr); + + return dataLength; + } + + CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, uint32_t *size) + { + VERIFY_NON_NULL(info, RA_ADAPTER_TAG, "info is NULL"); + VERIFY_NON_NULL(size, RA_ADAPTER_TAG, "size is NULL"); + return CA_STATUS_OK; + } + + int32_t CASendRAMulticastData(const CAEndpoint_t *endpoint, + const void *data, uint32_t dataLength) + { + OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support sending multicast data"); + SET_BUT_NOT_USED(endpoint); + SET_BUT_NOT_USED(data); + SET_BUT_NOT_USED(dataLength); + return 0; + } + + CAResult_t CAStartRAListeningServer() + { + OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support listening for multicast data"); + return CA_NOT_SUPPORTED; + } + + CAResult_t CAStartRADiscoveryServer() + { + OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support discovery of multicast servers"); + return CA_NOT_SUPPORTED; + } + + CAResult_t CAReadRAData() + { + OIC_LOG(INFO, RA_ADAPTER_TAG, "Read data is not implemented for the RA adapter"); + return CA_NOT_SUPPORTED; + } + + #else /* #ifdef RA_ADAPTER_IBB */ + /** * Logging tag for module name. */ diff --cc resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp index 918d3e0,a5633ac..94a8ad3 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp @@@ -454,9 -450,16 +450,23 @@@ static void jidbound(char *jid int main(int argc, char* argv[]) { - int opt; + char host[] = "localhost"; + char user[] = "test1"; + char pass[] = "intel123"; + char empstr[] = ""; - OCRAInfo_t rainfo = {.hostname = host, .port = 5222, - .xmpp_domain = host, .username = user, .password = pass, - .resource = empstr, .user_jid = empstr, .jidbound = jidbound}; ++ OCRAInfo_t rainfo = {}; ++ ++ rainfo.hostname = host; ++ rainfo.port = 5222; ++ rainfo.xmpp_domain = host; ++ rainfo.username = user; ++ rainfo.password = pass; ++ rainfo.resource = empstr; ++ rainfo.user_jid = empstr; ++ rainfo.jidbound = jidbound; - while ((opt = getopt(argc, argv, "t:")) != -1) + int opt = 0; + while ((opt = getopt(argc, argv, "t:s:p:d:u:w:r:j:")) != -1) { switch(opt) { diff --cc resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp index 65d7075,26c0ed8..abdd9ac --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp @@@ -932,9 -939,19 +939,26 @@@ int main(int argc, char* argv[] { pthread_t threadId; pthread_t threadId_presence; - int opt; - while ((opt = getopt(argc, argv, "o:")) != -1) + #ifdef RA_ADAPTER + char host[] = "localhost"; + char user[] = "test1"; + char pass[] = "intel123"; + char empstr[] = ""; - OCRAInfo_t rainfo = {.hostname = host, .port = 5222, - .xmpp_domain = host, .username = user, .password = pass, - .resource = empstr, .user_jid = empstr, .jidbound = jidbound}; ++ OCRAInfo_t rainfo = {}; ++ ++ rainfo.hostname = host; ++ rainfo.port = 5222; ++ rainfo.xmpp_domain = host; ++ rainfo.username = user; ++ rainfo.password = pass; ++ rainfo.resource = empstr; ++ rainfo.user_jid = empstr; ++ rainfo.jidbound = jidbound; + #endif + + int opt = 0; + while ((opt = getopt(argc, argv, "o:s:p:d:u:w:r:j:")) != -1) { switch(opt) {