Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / secure / common.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #include "common.h"
21
22 #include "ocstack.h"
23 #include "logger.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28
29 #define TAG "sample-common"
30
31 const char *getResult(OCStackResult result) {
32     switch (result) {
33     case OC_STACK_OK:
34         return "OC_STACK_OK";
35     case OC_STACK_RESOURCE_CREATED:
36         return "OC_STACK_RESOURCE_CREATED";
37     case OC_STACK_RESOURCE_DELETED:
38         return "OC_STACK_RESOURCE_DELETED";
39     case OC_STACK_INVALID_URI:
40         return "OC_STACK_INVALID_URI";
41     case OC_STACK_INVALID_QUERY:
42         return "OC_STACK_INVALID_QUERY";
43     case OC_STACK_INVALID_IP:
44         return "OC_STACK_INVALID_IP";
45     case OC_STACK_INVALID_PORT:
46         return "OC_STACK_INVALID_PORT";
47     case OC_STACK_INVALID_CALLBACK:
48         return "OC_STACK_INVALID_CALLBACK";
49     case OC_STACK_INVALID_METHOD:
50         return "OC_STACK_INVALID_METHOD";
51     case OC_STACK_NO_MEMORY:
52         return "OC_STACK_NO_MEMORY";
53     case OC_STACK_COMM_ERROR:
54         return "OC_STACK_COMM_ERROR";
55     case OC_STACK_INVALID_PARAM:
56         return "OC_STACK_INVALID_PARAM";
57     case OC_STACK_NOTIMPL:
58         return "OC_STACK_NOTIMPL";
59     case OC_STACK_NO_RESOURCE:
60         return "OC_STACK_NO_RESOURCE";
61     case OC_STACK_RESOURCE_ERROR:
62         return "OC_STACK_RESOURCE_ERROR";
63     case OC_STACK_SLOW_RESOURCE:
64         return "OC_STACK_SLOW_RESOURCE";
65     case OC_STACK_NO_OBSERVERS:
66         return "OC_STACK_NO_OBSERVERS";
67     case OC_STACK_UNAUTHORIZED_REQ:
68         return "OC_STACK_UNAUTHORIZED_REQ";
69     #ifdef WITH_PRESENCE
70     case OC_STACK_PRESENCE_STOPPED:
71         return "OC_STACK_PRESENCE_STOPPED";
72     #endif
73     case OC_STACK_ERROR:
74         return "OC_STACK_ERROR";
75     default:
76         return "UNKNOWN";
77     }
78 }
79
80 void StripNewLineChar(char* str) {
81     int i = 0;
82     if (str)
83     {
84         while( str[i])
85         {
86             if (str[i] == '\n')
87                 str[i] = '\0';
88             i++;
89         }
90     }
91 }
92