cloud fix #1 27/24727/4
authorAleksey Volkov <a.volkov@samsung.com>
Wed, 18 Apr 2018 13:30:26 +0000 (16:30 +0300)
committerAleksey Volkov <a.volkov@samsung.com>
Thu, 19 Apr 2018 08:03:59 +0000 (08:03 +0000)
a) mandatory fixed
b) apn param usage in signup
c) clean

Change-Id: I615432439a68600f00d7335d3641c7d7499c8955
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
Signed-off-by: Aleksey Volkov <a.volkov@samsung.com>
build_common/SConscript
resource/csdk/security/provisioning/src/cloud/auth.c
resource/csdk/security/provisioning/src/cloud/cloudresource.c
resource/csdk/security/provisioning/unittest/cloudresource.cpp

index 9ff8216..9dfc22e 100644 (file)
@@ -194,8 +194,11 @@ help_vars.AddVariables(
                  validator=PathVariable.PathAccept),
     EnumVariable('OIC_SUPPORT_TIZEN_TRACE',
                  'Tizen Trace(T-trace) api availability',
-                 default='False',
+                 default=False,
                  allowed_values=('True', 'False')),
+    BoolVariable('MANDATORY',
+                 'Enable/disable(default) mandatory',
+                 default=False)
 )
 
 ######################################################################
@@ -327,6 +330,9 @@ if not env.get('VERBOSE'):
     env['ARCOMSTR'] = "Archiving $TARGET"
     env['RANLIBCOMSTR'] = "Indexing Archive $TARGET"
 
+if env.get('MANDATORY'):
+    env.AppendUnique(CPPDEFINES=['__MANDATORY__'])
+
 tc_set_msg = '''
 ************************************ Warning **********************************
 * Warning: TC_PREFIX and/or TC_PATH is set in the environment.
index 4d60756..d219003 100644 (file)
@@ -57,7 +57,6 @@ const char *OIC_JSON_CLOUD_SESSION_UID = "uid";
 
 #if !defined(__MANDATORY__)
 #define SESSION_CBOR_CLOUD_MAP_SIZE 4
-const char *OIC_JSON_CLOUD_SESSION_TOKEN_TYPE = "tokentype";
 const char *OIC_JSON_CLOUD_SESSION_REDIRECT_URL = "redirecturl";
 #else
 #define SESSION_CBOR_CLOUD_MAP_SIZE 3
@@ -204,9 +203,14 @@ OCStackResult CloudSessionToCBORPayload(const session_t *session, CborEncoder *m
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: uid");
 
 #if !defined(__MANDATORY__)
-    cbor_encode_text_string(map, OIC_JSON_CLOUD_SESSION_REDIRECT_URL,
+    if (session->redirectUri)
+    {
+        cbor_encode_text_string(map, OIC_JSON_CLOUD_SESSION_REDIRECT_URL,
                             sizeof(OIC_JSON_CLOUD_SESSION_REDIRECT_URL) + 1);
-    cbor_encode_text_string(map, session->redirectUri, strnlen(session->redirectUri, MAX_STR_LEN));
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add tag: redirect uri");
+        cbor_encode_text_string(map, session->redirectUri, strnlen(session->redirectUri, MAX_STR_LEN));
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed add value: redirect uri");
+    }
 #endif // __MANDATORY__
 
     ret = OC_STACK_OK;
@@ -514,9 +518,10 @@ OCStackResult CBORPayloadToCloud(const uint8_t *cborPayload, size_t size, OicClo
                     goto next;
                 }
 #if !defined(__MANDATORY__)
-                else if (strncmp(name, OIC_JSON_CLOUD_SESSION_REDIRECT_URL, len)  == 0 && cloud->session)
+                else if (strncmp(name, OIC_JSON_CLOUD_SESSION_REDIRECT_URL, len)  == 0)
                 {
-                    cbor_value_dup_text_string(&map, &cloud->session->redirectUri, &len, NULL);
+                    cborError = cbor_value_dup_text_string(&map, &cloud->session->redirectUri, &len, NULL);
+                    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed get redirect uri");
                     goto next;
                 }
 #endif // __MANDATORY__
@@ -1002,7 +1007,6 @@ OCStackResult OCCloudSignUp(OicCloud_t *cloud)
 
     VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_INVALID_PARAM);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->apn, ERROR, OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, cloud->at, ERROR, OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, cloud->sid, ERROR, OC_STACK_INVALID_PARAM);
 
@@ -1022,7 +1026,10 @@ OCStackResult OCCloudSignUp(OicCloud_t *cloud)
 
     OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
 #if !defined(__MANDATORY__)
-    OCRepPayloadSetPropString(payload, OC_RSRVD_AUTHPROVIDER, cloud->apn);
+    if (cloud->apn)
+    {
+        OCRepPayloadSetPropString(payload, OC_RSRVD_AUTHPROVIDER, cloud->apn);
+    }
 #endif // __MANDATORY__
     OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN, cloud->at);
     OCRepPayloadSetPropString(payload, OC_RSRVD_SUBJECT_ID, cloud->sid);
index b6ae73b..f283b3e 100644 (file)
@@ -175,8 +175,7 @@ static OCEntityHandlerResult HandleCloudPostRequest(OCEntityHandlerRequest *ehRe
 
     if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_APN, &newCloud->apn))
     {
-        OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_APN);
-        goto exit;
+        OIC_LOG_V(WARNING, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_APN);
     }
     if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &newCloud->cis))
     {
index 521df66..82b61aa 100644 (file)
@@ -73,16 +73,14 @@ void sessionInit(session_t *ses)
     ses->uid = (char *)OICCalloc(STR_LEN, sizeof(char));
 #if !defined(__MANDATORY__)
     ses->redirectUri = (char *)OICCalloc(STR_LEN, sizeof(char));
+    snprintf(ses->redirectUri, STR_LEN, "coaps+tcp://127.0.0.1:80");
 #endif // __MANDATORY__
     for (int i = 0; i < STR_LEN; i++)
     {
         ses->accessToken[i] = sample[rand() % STR_LEN];
         ses->refreshToken[i] = sample[rand() % STR_LEN];
         ses->uid[i] = sample[rand() % STR_LEN];
-#if !defined(__MANDATORY__)
-        ses->redirectUri[i] = sample[rand() % STR_LEN];
-#endif // __MANDATORY__
-    }
+   }
 }
 
 OicCloud_t *getCloud()