Merge RA branch to master
authorSakthivel Samidurai <sakthivel.samidurai@intel.com>
Tue, 15 Sep 2015 18:34:33 +0000 (11:34 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Thu, 17 Sep 2015 16:12:51 +0000 (16:12 +0000)
fix build break

Patch Set 2:
  fix some casting warning.
  do not build raxmpp if WITH_RA_IBB is set.

Patch Set 3:
  fix set but not used warning.

Patch Set 4:
. update wksxmppxep version for support disable libstrophe debug
  messages.
. disable libstrophe debug message in RELEASE build, but still print
  error level messages.

Patch Set 5:
  add bound jid callback function for reporting bound full JID to
  application.

Patch Set 6:
  update for comments.

Patch Set 7:
   address code review comments.

Patch Set 8:
   update jidBoudCallback.

Change-Id: Ie7944c9e19697748b1d716c91ea6841ba0629531
Signed-off-by: K.J. Kao <jeremyk@workssys.com>
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2460
Reviewed-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Daniel Liu <daniell@workssys.com>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
Tested-by: Patrick Lankswert <patrick.lankswert@intel.com>
extlibs/raxmpp/SConscript
extlibs/wksxmppxep/SConscript
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/api/cainterface.h
resource/csdk/connectivity/inc/cainterfacecontroller.h
resource/csdk/connectivity/inc/caraadapter.h
resource/csdk/connectivity/src/ra_adapter/caraadapter.c
resource/csdk/stack/include/octypes.h
resource/csdk/stack/samples/linux/SimpleClientServer/ocremoteaccessclient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp

index 29d5cad..6db32f5 100644 (file)
@@ -31,7 +31,8 @@ src_dir = env.get('SRC_DIR')
 target_os = env.get('TARGET_OS')
 target_arch = env.get('TARGET_ARCH')
 with_ra = env.get('WITH_RA')
-if with_ra:
+with_ra_ibb = env.get('WITH_RA_IBB')
+if with_ra and not with_ra_ibb :
        # check 'raxmppl' library, if it doesn't exits, ask user to download it
        if not os.path.exists('raxmpp'):
                print '''
index 9dc9833..f30b3cd 100644 (file)
@@ -26,7 +26,7 @@ if with_ra_ibb:
        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 b95f22064241d1319c4dc967878706b4a446d186'
+                       'cd ' + SRC_NAME + ' && git checkout 1d2edd460c0e85e2b647176e74ebbe519e6019de'
         ])
 
                print 'Downloading', SRC_NAME ,'library ...'
index 2a952e5..f0f6880 100644 (file)
@@ -407,22 +407,6 @@ typedef struct
 } CAErrorInfo_t;
 
 /**
- * CA Remote Access information for XMPP Client
- *
- */
-typedef struct
-{
-    char *hostname;     /**< XMPP server hostname */
-    uint16_t port;      /**< XMPP server serivce port */
-    char *xmpp_domain;  /**< XMPP login domain */
-    char *username;     /**< login username */
-    char *password;     /**< login password */
-    char *resource;     /**< specific resource for login */
-    char *user_jid;     /**< specific JID for login */
-} CARAInfo_t;
-
-
-/**
  * Hold global variables for CA layer (also used by RI layer)
  */
 typedef struct
index 9499cf4..f5a85bc 100644 (file)
@@ -64,6 +64,31 @@ typedef void (*CAResponseCallback)(const CAEndpoint_t *object,
  */
 typedef void (*CAErrorCallback)(const CAEndpoint_t *object,
                                 const CAErrorInfo_t *errorInfo);
+#ifdef RA_ADAPTER
+
+/**
+ * Callback for bound JID
+ * @param[out]   jid           Boud Jabber Identifier.
+ */
+typedef void (*CAJidBoundCallback)(char *jid);
+
+/**
+ * CA Remote Access information for XMPP Client
+ *
+ */
+typedef struct
+{
+    char *hostName;     /**< XMPP server hostname */
+    uint16_t port;      /**< XMPP server serivce port */
+    char *xmppDomain;  /**< XMPP login domain */
+    char *userName;     /**< login username */
+    char *password;     /**< login password */
+    char *resource;     /**< specific resource for login */
+    char *userJid;     /**< specific JID for login */
+    CAJidBoundCallback jidBoundCallback;  /**< callback when JID bound */
+} CARAInfo_t;
+
+#endif //RA_ADAPTER
 
 #ifdef __WITH_DTLS__
 
index 94216d8..a0cd2f0 100644 (file)
@@ -28,6 +28,7 @@
 #define CA_INTERFACE_CONTROLLER_H_
 
 #include "caadapterinterface.h"
+#include "cainterface.h"
 
 #ifndef SINGLE_THREAD
 #include "cathreadpool.h" /* for thread pool */
index 32656ba..deec368 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "cacommon.h"
 #include "caadapterinterface.h"
+#include "cainterface.h"
 #include "cathreadpool.h"
 
 #ifdef __cplusplus
index 4ace491..a5bea52 100644 (file)
@@ -45,6 +45,7 @@
 #endif
 
 #ifdef RA_ADAPTER_IBB
+#define SET_BUT_NOT_USED(x) (void) x
 /**
  * Logging tag for module name.
  */
@@ -69,16 +70,18 @@ typedef struct
 {
     xmpp_t     *xmpp;
     int         port;
-    char        hostname[RA_MAX_HOSTNAME_LENGTH];
+    char        hostName[RA_MAX_HOSTNAME_LENGTH];
     char        password[RA_MAX_PASSWORD_LENGTH];
     char        jid[CA_RAJABBERID_SIZE];
-    CANetworkStatus_t connection_status;
+    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}, .connection_status = CA_INTERFACE_DOWN};
+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);
 
@@ -86,7 +89,7 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange IN");
 
-    g_xmppData.connection_status = status;
+    g_xmppData.connectionStatus = status;
 
     CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
                                 CA_ADAPTER_REMOTE_ACCESS,
@@ -157,7 +160,7 @@ static void CARAUpdateObsList(int option, char *sid)
     }
     else if (option == OBSERVE_DEREGISTER)
     {
-        obs_item_t *item = ilist_finditem_func(g_observerList, CARAFindSessID, sid);
+        obs_item_t *item = ilist_finditem_func(g_observerList, (find_fp) CARAFindSessID, sid);
         if (item != NULL)
         {
             item->option = OBSERVE_DEREGISTER;
@@ -203,14 +206,18 @@ static int CARAGetReqObsOption(coap_pdu_t *pdu)
 
 static int CARAErrorCB(xmpp_ibb_session_t *sess, xmpperror_t *xerr)
 {
-    OIC_LOG_V(DEBUG, RA_ADAPTER_TAG, "%s(): code(%d) tyep'%s' mesg'%s'",
+    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;
 }
 
@@ -218,12 +225,13 @@ 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, CARAFindSessID, sid);
+    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;
 }
 
@@ -290,7 +298,7 @@ static int CARARecvCB(xmpp_ibb_session_t *sess, xmppdata_t *xdata)
         else
         {
             OIC_LOG(DEBUG, RA_ADAPTER_TAG, "this is a response data");
-            obs_item_t *item = ilist_finditem_func(g_observerList, CARAFindSessID, sid);
+            obs_item_t *item = ilist_finditem_func(g_observerList, (find_fp) CARAFindSessID, sid);
             if (item != NULL)
             {
                 if (item->option == OBSERVE_DEREGISTER)
@@ -315,7 +323,10 @@ static int CARARecvCB(xmpp_ibb_session_t *sess, xmppdata_t *xdata)
             return -1;
         }
         memcpy(buf, xdata->data, xdata->size);
-        g_networkPacketCallback(endPoint, buf, 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);
     }
@@ -330,14 +341,19 @@ static int CARAConnHandler(xmpp_t *xmpp, xmppconn_info_t *conninfo, void *udata)
 {
     if (conninfo->connevent != 0)
     {
-        OIC_LOG_V(DEBUG, RA_ADAPTER_TAG, " status(%d) error(%d) errorType(%d) errorText '%s'\n",
+        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, "\n\n  Bound JID: '%s'\n\n\n", xmpphelper_get_bound_jid(xmpp));
+    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;
 }
 
@@ -366,8 +382,12 @@ CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback,
         .stopAdapter = CAStopRA,
         .terminate = CATerminateRA};
     registerCallback(raHandler, CA_ADAPTER_REMOTE_ACCESS);
-
-    g_xmppData.xmpp = xmpphelper_new(CARAConnHandler, NULL);
+#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();
 
@@ -381,28 +401,28 @@ CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo)
         OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!");
         return CA_STATUS_INVALID_PARAM;
     }
-    if (caraInfo->hostname != NULL)
+    if (caraInfo->hostName != NULL)
     {
-        OICStrcpy(g_xmppData.hostname, sizeof(g_xmppData.hostname), caraInfo->hostname);
+        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)
+    if (caraInfo->userName != NULL && strlen(caraInfo->userName) != 0)
     {
-        OICStrcpy(g_xmppData.jid, sizeof(g_xmppData.jid), caraInfo->username);
+        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->xmpp_domain != NULL && strlen(caraInfo->xmpp_domain) != 0)
+    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->xmpp_domain);
+        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), "/");
@@ -414,6 +434,7 @@ CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo)
         OICStrcpy(g_xmppData.password, sizeof(g_xmppData.password), caraInfo->password);
     }
     g_xmppData.port = caraInfo->port;
+    g_xmppData.jidBoundCallback = caraInfo->jidBoundCallback;
 
     return CA_STATUS_OK;
 }
@@ -446,7 +467,7 @@ CAResult_t CAStartRA()
 
     ca_mutex_lock (g_raadapterMutex);
 
-    xmpphelper_connect(g_xmppData.xmpp, g_xmppData.hostname, g_xmppData.port,
+    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;
@@ -501,7 +522,7 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data
     coap_delete_pdu(pdu);
 
     ca_mutex_lock (g_raadapterMutex);
-    if (CA_INTERFACE_UP != g_xmppData.connection_status)
+    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);
@@ -511,7 +532,7 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data
     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), remoteEndpoint->addr, sid);
+        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!");
@@ -526,7 +547,7 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data
             CARAUpdateObsList(obsopt, sid);
         }
     }
-    xmppdata_t xdata = {.data = data, .size = dataLength};
+    xmppdata_t xdata = {.data = (char *) data, .size = dataLength};
     int rc = xmpp_ibb_send_data(sess, &xdata);
     ca_mutex_unlock (g_raadapterMutex);
     if (rc < 0)
@@ -552,6 +573,9 @@ 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;
 }
 
index ea0df8d..53ba952 100644 (file)
@@ -826,6 +826,11 @@ typedef struct
 
 #ifdef RA_ADAPTER
 /**
+ * callback for bound JID
+ */
+typedef void (*jid_bound_cb)(char *jid);
+
+/**
  * CA Remote Access information for XMPP Client
  *
  */
@@ -838,6 +843,7 @@ typedef struct
     char *password;     /**< login password */
     char *resource;     /**< specific resource for login */
     char *user_jid;     /**< specific JID for login */
+    jid_bound_cb jidbound;  /**< callback when JID bound */
 } OCRAInfo_t;
 #endif  /* RA_ADAPTER */
 
index 9f1c672..a5633ac 100644 (file)
 #include "payload_logging.h"
 #include "ocremoteaccessclient.h"
 
+#define SET_BUT_NOT_USED(x) (void) x
 // Tracking user input
 static int TEST_CASE = 0;
 
-static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/d";
-static const char * MULTICAST_PLATFORM_DISCOVERY_QUERY = "/oic/p";
 static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
 
 static std::string coapServerIP = "255.255.255.255";
@@ -162,6 +161,7 @@ OCStackApplicationResult restRequestCB(void* ctx,
     {
         OC_LOG (INFO, TAG, "Received vendor specific options. Ignoring");
     }
+    SET_BUT_NOT_USED(handle);
     return OC_STACK_DELETE_TRANSACTION;
 }
 
@@ -211,6 +211,7 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse
         return OC_STACK_DELETE_TRANSACTION;
     }
 
+    SET_BUT_NOT_USED(handle);
     return OC_STACK_KEEP_TRANSACTION;
 }
 #ifdef WITH_PRESENCE
@@ -243,6 +244,7 @@ OCStackApplicationResult presenceCB(void* ctx,
     {
         OC_LOG_V(INFO, TAG, "presenceCB received Null clientResponse");
     }
+    SET_BUT_NOT_USED(handle);
     return OC_STACK_KEEP_TRANSACTION;
 }
 #endif
@@ -289,6 +291,7 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
             PrintUsage();
             break;
     }
+    SET_BUT_NOT_USED(handle);
     return OC_STACK_KEEP_TRANSACTION;
 }
 
@@ -309,6 +312,7 @@ OCStackApplicationResult PlatformDiscoveryReqCB (void* ctx, OCDoHandle handle,
         OC_LOG_V(INFO, TAG, "PlatformDiscoveryReqCB received Null clientResponse");
     }
 
+    SET_BUT_NOT_USED(handle);
     return OC_STACK_DELETE_TRANSACTION;
 }
 
@@ -329,6 +333,7 @@ OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle handle,
         OC_LOG_V(INFO, TAG, "PlatformDiscoveryReqCB received Null clientResponse");
     }
 
+    SET_BUT_NOT_USED(handle);
     return OC_STACK_DELETE_TRANSACTION;
 }
 
@@ -438,11 +443,20 @@ int InitDiscovery(OCQualityOfService qos)
     return ret;
 }
 
+static void jidbound(char *jid)
+{
+    OC_LOG_V(INFO, TAG, "\n\n    Bound JID: %s\n\n", jid);
+}
+
 int main(int argc, char* argv[])
 {
-    OCRAInfo_t rainfo = {.hostname = "localhost", .port = 5222,
-        .xmpp_domain = "localhost", .username = "test1", .password = "intel123",
-        .resource = "", .user_jid = ""};
+    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};
 
     int opt = 0;
     while ((opt = getopt(argc, argv, "t:s:p:d:u:w:r:j:")) != -1)
index d8908ba..26c0ed8 100644 (file)
@@ -928,15 +928,26 @@ static void PrintUsage()
     OC_LOG(INFO, TAG, "-o 1 : Notify list of observers");
 }
 
+#ifdef RA_ADAPTER
+static void jidbound(char *jid)
+{
+    OC_LOG_V(INFO, TAG, "\n\n    Bound JID: %s\n\n", jid);
+}
+#endif
+
 int main(int argc, char* argv[])
 {
     pthread_t threadId;
     pthread_t threadId_presence;
 
 #ifdef RA_ADAPTER
-    OCRAInfo_t rainfo = {.hostname = "localhost", .port = 5222,
-        .xmpp_domain = "localhost", .username = "test1", .password = "intel123",
-        .resource = "", .user_jid = ""};
+    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};
 #endif
 
     int opt = 0;
@@ -983,15 +994,6 @@ int main(int argc, char* argv[])
     }
 
 #ifdef RA_ADAPTER
-    OCRAInfo_t rainfo;
-    rainfo.hostname = "localhost";
-    rainfo.port = 5222;
-    rainfo.xmpp_domain = "localhost";
-    rainfo.username = "test1";
-    rainfo.password = "intel123";
-    rainfo.resource = "";
-    rainfo.user_jid = "";
-
     OCSetRAInfo(&rainfo);
 #endif