Merge branch '1.3-rel' (3040a9e) 23/22723/3
authorGeorge Nash <george.nash@intel.com>
Fri, 6 Oct 2017 18:36:47 +0000 (11:36 -0700)
committerGeorge Nash <george.nash@intel.com>
Wed, 11 Oct 2017 19:05:00 +0000 (12:05 -0700)
Relate-to:
https://gerrit.iotivity.org/gerrit/22689/
https://gerrit.iotivity.org/gerrit/22385/
https://gerrit.iotivity.org/gerrit/22665/
https://gerrit.iotivity.org/gerrit/22529/
https://gerrit.iotivity.org/gerrit/22535/
https://gerrit.iotivity.org/gerrit/22403/
https://gerrit.iotivity.org/gerrit/21939/
https://gerrit.iotivity.org/gerrit/22671/
https://gerrit.iotivity.org/gerrit/22393/
https://gerrit.iotivity.org/gerrit/22597/
https://gerrit.iotivity.org/gerrit/22473/

Conflicts:
  auto_build.py
  resource/csdk/connectivity/src/camessagehandler.c
  resource/csdk/stack/src/ocobserve.c
  resource/csdk/stack/src/ocstack.c
  resource/provisioning/unittests/SConscript

Bug: https://jira.iotivity.org/browse/IOT-2453
Change-Id: I7db07ad3da8305aac3bf5d958b2ea3889b1106e7
Signed-off-by: George Nash <george.nash@intel.com>
16 files changed:
1  2 
auto_build.py
build_common/SConscript
java/jni/JniOcPlatform.h
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/security/src/credresource.c
resource/csdk/security/tool/json2cbor.c
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocpayloadparse.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/provisioning/unittests/SConscript
resource/src/InProcClientWrapper.cpp
service/easy-setup/enrollee/unittests/SConscript
service/easy-setup/mediator/richsdk/unittests/SConscript
service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/SConscript

diff --cc auto_build.py
@@@ -12,9 -12,9 +12,9 @@@ def helpmsg(script)
  Usage:
      build:
          python %s <targetbuild>
-         Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_full, linux_unsecured_with_ra, linux_secured_with_ra, linux_unsecured_with_rd, linux_secured_with_rd,
 -        Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_rd, linux_secured_with_rd,
++        Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_full, linux_unsecured_with_rd, linux_secured_with_rd,
          android, android_unsecured, android_secured, arduino, tizen, tizen_unsecured, tizen_secured, simulator, darwin, windows, msys
-         Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\", \"linux_unsecured_with_mq\", \"linux_secured_with_tcp\" & \"linux_unsecured_with_tcp\" & \"linux_unsecured_with_rd\".
+         Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_secured_with_rd\", \"linux_unsecured_with_mq\", \"linux_secured_with_tcp\" & \"linux_unsecured_with_tcp\" & \"linux_unsecured_with_rd\".
          Any selection will build both debug and release versions of all available targets in the scope you've selected.
          To choose any specific command, please use the SCons commandline directly. Please refer to [IOTIVITY_REPO]/Readme.scons.txt.
      clean:
@@@ -138,38 -136,6 +136,19 @@@ def build_linux_secured(flag, extra_opt
                      }
      call_scons(build_options, extra_option_str)
  
- def build_linux_unsecured_with_ra(flag, extra_option_str):
-     print ("*********** Build for linux With Remote Access *************")
-     build_options = {
-                         'RELEASE':flag,
-                         'WITH_RA':1,
-                         'WITH_RA_IBB':1,
-                         'SECURED':0,
-                     }
-     call_scons(build_options, extra_option_str)
- def build_linux_secured_with_ra(flag, extra_option_str):
-     print ("*********** Build for linux With Remote Access & Security ************")
-     build_options = {
-                         'RELEASE':flag,
-                         'WITH_RA':1,
-                         'WITH_RA_IBB':1,
-                     }
-     call_scons(build_options, extra_option_str)
 +def build_linux_full(flag, extra_option_str):
 +    print ("*********** Build for linux with Security *************")
 +    build_options = {
 +                        'MULTIPLE_OWNER':1,
 +                        'RELEASE':flag,
 +                        'SECURED':1,
 +                        'WITH_CLOUD':1,
 +                        'WITH_RA':1,
 +                        'WITH_RA_IBB':1,
 +                        'WITH_TCP':1,
 +                    }
 +    call_scons(build_options, extra_option_str)
 +
  def build_linux_unsecured_with_rd(flag, extra_option_str):
      print ("*********** Build for linux With Resource Directory *************")
      build_options = {
@@@ -592,18 -556,6 +569,10 @@@ elif arg_num == 2
          build_linux_secured("true", "")
          build_linux_secured("false", "")
  
-     elif str(sys.argv[1]) == "linux_unsecured_with_ra":
-         build_linux_unsecured_with_ra("true", "")
-         build_linux_unsecured_with_ra("false", "")
-     elif str(sys.argv[1]) == "linux_secured_with_ra":
-         build_linux_secured_with_ra("true", "")
-         build_linux_secured_with_ra("false", "")
 +    elif str(sys.argv[1]) == "linux_full":
 +        build_linux_full("true", "")
 +        build_linux_full("false", "")
 +
      elif str(sys.argv[1]) == "linux_unsecured_with_rd":
          build_linux_unsecured_with_rd("true", "")
          build_linux_unsecured_with_rd("false", "")
Simple merge
Simple merge
@@@ -1255,10 -1255,20 +1255,20 @@@ OicSecCred_t *JSONToCredBin(const char 
                  cJSON *jsonPriv = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
                  VERIFY_NOT_NULL(TAG, jsonPriv, ERROR);
                  jsonObjLen = strlen(jsonPriv->valuestring);
-                 cred->privateData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
+                 ret = (jsonObjLen % 2 == 0) ? ret : OC_STACK_ERROR;
 -                char tmp[2];
++                char tmp[3];
+                 char *buf = (char *)OICCalloc(1, jsonObjLen/2);
+                 for(size_t i = 0, p = 0 ; i < jsonObjLen; i+=2, ++p)
+                 {
+                     sprintf(tmp, "%c%c", jsonPriv->valuestring[i], jsonPriv->valuestring[i+1]);
+                     buf[p] = (char)strtol(tmp, NULL, 16);
+                 }
+                 cred->privateData.len = jsonObjLen/2;
+                 cred->privateData.data = (uint8_t *)OICCalloc(1, cred->privateData.len);
                  VERIFY_NOT_NULL(TAG, (cred->privateData.data), ERROR);
-                 memcpy(cred->privateData.data, jsonPriv->valuestring, jsonObjLen);
-                 cred->privateData.len = jsonObjLen;
+                 memcpy(cred->privateData.data, buf, cred->privateData.len);
  
                  cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                  VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
                  cJSON *jsonPub = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
                  VERIFY_NOT_NULL(TAG, jsonPub, ERROR);
                  jsonObjLen = strlen(jsonPub->valuestring);
-                 cred->publicData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
+                 ret = (jsonObjLen % 2 == 0) ? ret : OC_STACK_ERROR;
 -                char tmp[2];
++                char tmp[3];
+                 char *buf = (char *)OICCalloc(1, jsonObjLen/2);
+                 for(size_t i = 0, p = 0 ; i < jsonObjLen; i+=2, ++p)
+                 {
+                     sprintf(tmp, "%c%c", jsonPub->valuestring[i], jsonPub->valuestring[i+1]);
+                     buf[p] = (char)strtol(tmp, NULL, 16);
+                 }
+                 cred->publicData.len = jsonObjLen/2;
+                 cred->publicData.data = (uint8_t *)OICCalloc(1, cred->publicData.len);
                  VERIFY_NOT_NULL(TAG, (cred->publicData.data), ERROR);
-                 memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen);
-                 cred->publicData.len = jsonObjLen;
+                 memcpy(cred->publicData.data, buf, cred->publicData.len);
  
                  cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                  VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
                  cred->publicData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
              }
                  cJSON *jsonOpt = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
                  VERIFY_NOT_NULL(TAG, jsonOpt, ERROR);
                  jsonObjLen = strlen(jsonOpt->valuestring);
-                 cred->optionalData.data =  (uint8_t *)OICCalloc(1, jsonObjLen);
+                 ret = (jsonObjLen % 2 == 0) ? ret : OC_STACK_ERROR;
 -                char tmp[2];
++                char tmp[3];
+                 char *buf = (char *)OICCalloc(1, jsonObjLen/2);
+                 for(size_t i = 0, p = 0; i < jsonObjLen; i+=2, ++p)
+                 {
+                     sprintf(tmp, "%c%c", jsonOpt->valuestring[i], jsonOpt->valuestring[i+1]);
+                     buf[p] = (char)strtol(tmp, NULL, 16);
+                 }
+                 cred->optionalData.len = jsonObjLen/2;
+                 cred->optionalData.data =  (uint8_t *)OICCalloc(1, cred->optionalData.len);
                  VERIFY_NOT_NULL(TAG, (cred->optionalData.data), ERROR);
-                 memcpy(cred->optionalData.data, jsonOpt->valuestring, jsonObjLen);
-                 cred->optionalData.len = jsonObjLen;
+                 memcpy(cred->optionalData.data, buf, cred->optionalData.len);
  
                  cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                  VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
      ret = ConvertStrToUuid(jsonCredObj->valuestring, &headCred->rownerID);
      VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
      ret = OC_STACK_OK;
--*/  
++*/
  exit:
      cJSON_Delete(jsonRoot);
      if (OC_STACK_OK != ret)
@@@ -623,3 -663,95 +623,98 @@@ GetObserveHeaderOption (uint32_t * obse
      }
      return OC_STACK_OK;
  }
 -        ResourceObserver *obs = GetObserverUsingToken (request->requestToken,
+ OCStackResult
+ HandleVirtualObserveRequest(OCServerRequest *request)
+ {
+     OCStackResult result = OC_STACK_OK;
+     if (request->notificationFlag)
+     {
+         // The request is to send an observe payload, not register/deregister an observer
+         goto exit;
+     }
+     OCVirtualResources virtualUriInRequest = OC_UNKNOWN_URI;
+     virtualUriInRequest = GetTypeOfVirtualURI(request->resourceUrl);
+     if (virtualUriInRequest != OC_WELL_KNOWN_URI)
+     {
+         // OC_WELL_KNOWN_URI is currently the only virtual resource that may be observed
+         goto exit;
+     }
+     OCResource *resourcePtr = NULL;
+     resourcePtr = FindResourceByUri(OC_RSRVD_WELL_KNOWN_URI);
+     if (NULL == resourcePtr)
+     {
+         OIC_LOG(FATAL, TAG, "Well-known URI not found.");
+         result = OC_STACK_ERROR;
+         goto exit;
+     }
+     if (request->observationOption == OC_OBSERVE_REGISTER)
+     {
+         OIC_LOG(INFO, TAG, "Observation registration requested");
 -        result = DeleteObserverUsingToken (request->requestToken, request->tokenLength);
++        ResourceObserver *obs = GetObserverUsingToken (resourcePtr,
++                                                       request->requestToken,
+                                                        request->tokenLength);
+         if (obs)
+         {
+             OIC_LOG (INFO, TAG, "Observer with this token already present");
+             OIC_LOG (INFO, TAG, "Possibly re-transmitted CON OBS request");
+             OIC_LOG (INFO, TAG, "Not adding observer. Not responding to client");
+             OIC_LOG (INFO, TAG, "The first request for this token is already ACKED.");
+             result = OC_STACK_DUPLICATE_REQUEST;
+             goto exit;
+         }
+         OCObservationId obsId;
+         result = GenerateObserverId(&obsId);
+         if (result == OC_STACK_OK)
+         {
+             result = AddObserver ((const char*)(request->resourceUrl),
+                                   (const char *)(request->query),
+                                   obsId, request->requestToken, request->tokenLength,
+                                   resourcePtr, request->qos, request->acceptFormat,
+                                   request->acceptVersion, &request->devAddr);
+         }
+         if (result == OC_STACK_OK)
+         {
+             OIC_LOG(INFO, TAG, "Added observer successfully");
+             request->observeResult = OC_STACK_OK;
+         }
+         else if (result == OC_STACK_RESOURCE_ERROR)
+         {
+             OIC_LOG(INFO, TAG, "The Resource is not active, discoverable or observable");
+             request->observeResult = OC_STACK_ERROR;
+         }
+         else
+         {
+             // The error in observeResult for the request will be used when responding to this
+             // request by omitting the observation option/sequence number.
+             request->observeResult = OC_STACK_ERROR;
+             OIC_LOG(ERROR, TAG, "Observer Addition failed");
+         }
+     }
+     else if (request->observationOption == OC_OBSERVE_DEREGISTER)
+     {
+         OIC_LOG(INFO, TAG, "Deregistering observation requested");
++        result = DeleteObserverUsingToken (resourcePtr,
++                                           request->requestToken,
++                                           request->tokenLength);
+         if (result == OC_STACK_OK)
+         {
+             OIC_LOG(INFO, TAG, "Removed observer successfully");
+             request->observeResult = OC_STACK_OK;
+             // There should be no observe option header for de-registration response.
+             // Set as an invalid value here so we can detect it later and remove the field in response.
+             request->observationOption = MAX_SEQUENCE_NUMBER + 1;
+         }
+         else
+         {
+             request->observeResult = OC_STACK_ERROR;
+             OIC_LOG(ERROR, TAG, "Observer Removal failed");
+         }
+     }
+     // Whether the observe request succeeded or failed, the request is processed as normal
+     // and excludes/includes the OBSERVE option depending on request->observeResult
+     result = OC_STACK_OK;
+ exit:
+     return result;
+ }
Simple merge
@@@ -2126,7 -2150,11 +2126,11 @@@ void HandleCAErrorResponse(const CAEndp
          response->identity.id_length = errorInfo->info.identity.id_length;
          response->result = CAResultToOCResult(errorInfo->result);
  
-         cbNode->callBack(cbNode->context, cbNode->handle, response);
+         OCStackApplicationResult cbResult = cbNode->callBack(cbNode->context, cbNode->handle, response);
+         if (cbResult == OC_STACK_DELETE_TRANSACTION)
+         {
 -            FindAndDeleteClientCB(cbNode);
++            DeleteClientCB(cbNode);
+         }
          OICFree(response);
      }
  
@@@ -123,15 -114,15 +123,16 @@@ if provisiontests_env.get('TEST') == '1
      # Workaround for IOT-2038: don't run this test on Windows yet, because Jenkins times out.
      if target_os in ['linux']:
          out_dir = provisiontests_env.get('BUILD_DIR')
 -        result_dir = os.path.join(provisiontests_env.get('BUILD_DIR'), 'test_out') + os.sep
 +        result_dir = os.path.join(
 +            provisiontests_env.get('BUILD_DIR'), 'test_out') + os.sep
          if not os.path.isdir(result_dir):
              os.makedirs(result_dir)
 -        provisiontests_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
 +        provisiontests_env.AppendENVPath('GTEST_OUTPUT', ['xml:' + result_dir])
          provisiontests_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
          run_test(provisiontests_env,
-                  'resource_provisioning_unittests_provisiontests.memcheck',
-                  'resource/provisioning/unittests/provisiontests', unittests)
+                    'resource_provisioning_unittests_provisiontests.memcheck',
+                    'resource/provisioning/unittests/provisiontests',
+                     unittests)
  
  src_dir = provisiontests_env.get('SRC_DIR')
  svr_db_src_dir = src_dir + '/resource/provisioning/examples/'
Simple merge
  ##
  
  from tools.scons.RunTest import run_test
  Import('env')
  
- if env.get('RELEASE'):
-     env.AppendUnique(CCFLAGS=['-Os'])
-     env.AppendUnique(CPPDEFINES=['NDEBUG'])
- else:
-     env.AppendUnique(CCFLAGS=['-g'])
- if env.get('LOGGING'):
-     env.AppendUnique(CPPDEFINES=['TB_LOG'])
- lib_env = SConscript('#extlibs/gtest/SConscript')
+ gtest_env = SConscript('#extlibs/gtest/SConscript')
+ lib_env = gtest_env.Clone()
  rd_mode = env.get('RD_MODE')
  
 -SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
 +SConscript('#service/third_party_libs.scons', 'lib_env')
  
+ if lib_env.get('RELEASE'):
+     lib_env.AppendUnique(CCFLAGS = ['-Os'])
+ else:
+     lib_env.AppendUnique(CCFLAGS = ['-g'])
  ######################################################################
  #unit test setting
  ######################################################################
@@@ -87,11 -86,13 +84,11 @@@ easysetup_mediator_test_env = easysetup
  easysetup_mediator_test_env.AppendUnique(
      LIBS=['ESEnrolleeSDK', 'ESMediatorRich'])
  
 -easysetup_mediator_test_src = env.Glob(
 -    src_dir +
 -    '/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp')
 +src_files = ['ESMediatorTest.cpp']
  easysetup_mediator_test = easysetup_mediator_test_env.Program(
 -    'easysetup_mediator_test', easysetup_mediator_test_src)
 +    'easysetup_mediator_test', src_files)
  Alias("easysetup_mediator_test", easysetup_mediator_test)
- env.AppendTarget('easysetup_mediator_test')
+ easysetup_mediator_test_env.AppendTarget('easysetup_mediator_test')
  
  if env.get('TEST') == '1':
      if target_os in ['linux'] and env.get('SECURED') != '1':