[Win32] Modify SConscripts to prepare for VS
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / secure / common.cpp
index 16dd8a8..6eb7521 100644 (file)
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "common.h"
 
-#include <ocstack.h>
-#include <ocsecurity.h>
-#include <logger.h>
+#include "ocstack.h"
+#include "logger.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 
 #define TAG "sample-common"
 
-OCStackResult SetCredentials(const char* filename) {
-
-    FILE *fp = NULL;
-    uint8_t *data = NULL;
-    struct stat st;
-    OCStackResult ret = OC_STACK_ERROR;
-
-    fp = fopen(filename, "rb");
-    if (fp)
-    {
-        if (stat(filename, &st) == 0)
-        {
-            data = (uint8_t*)malloc(st.st_size);
-            if (data)
-            {
-                if (fread(data, 1, st.st_size, fp) == (size_t)st.st_size)
-                {
-                    // Provide credentials to OC Stack
-                    ret = OCSetDtlsPskCredentials((OCDtlsPskCredsBlob *)data,
-                            st.st_size);
-                }
-                else
-                {
-                    OC_LOG_V(FATAL, TAG, "Error in reading file %s", filename);
-                }
-            }
-        }
-        fclose(fp);
-    }
-    else
-    {
-        OC_LOG_V(FATAL, TAG, "Unable to open %s file", filename);
-    }
-
-    free(data);
-
-    return ret;
-}
-
 const char *getResult(OCStackResult result) {
     switch (result) {
     case OC_STACK_OK:
@@ -103,9 +64,9 @@ const char *getResult(OCStackResult result) {
         return "OC_STACK_SLOW_RESOURCE";
     case OC_STACK_NO_OBSERVERS:
         return "OC_STACK_NO_OBSERVERS";
+    case OC_STACK_UNAUTHORIZED_REQ:
+        return "OC_STACK_UNAUTHORIZED_REQ";
     #ifdef WITH_PRESENCE
-    case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
-        return "OC_STACK_VIRTUAL_DO_NOT_HANDLE";
     case OC_STACK_PRESENCE_STOPPED:
         return "OC_STACK_PRESENCE_STOPPED";
     #endif
@@ -128,3 +89,4 @@ void StripNewLineChar(char* str) {
         }
     }
 }
+