examples: Add notice about using experimental API
[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 <stdio.h>
24 #include <stdlib.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27
28
29 /// This example is using experimental API, so there is no guarantee of support for future release,
30 /// nor any there any guarantee that breaking changes will not occur across releases.
31 #include "experimental/logger.h"
32
33 #define TAG "sample-common"
34
35 const char *getResult(OCStackResult result) {
36     switch (result) {
37     case OC_STACK_OK:
38         return "OC_STACK_OK";
39     case OC_STACK_RESOURCE_CREATED:
40         return "OC_STACK_RESOURCE_CREATED";
41     case OC_STACK_RESOURCE_DELETED:
42         return "OC_STACK_RESOURCE_DELETED";
43     case OC_STACK_CONTINUE:
44         return "OC_STACK_CONTINUE";
45     case OC_STACK_RESOURCE_CHANGED:
46         return "OC_STACK_RESOURCE_CHANGED";
47     case OC_STACK_INVALID_URI:
48         return "OC_STACK_INVALID_URI";
49     case OC_STACK_INVALID_QUERY:
50         return "OC_STACK_INVALID_QUERY";
51     case OC_STACK_INVALID_IP:
52         return "OC_STACK_INVALID_IP";
53     case OC_STACK_INVALID_PORT:
54         return "OC_STACK_INVALID_PORT";
55     case OC_STACK_INVALID_CALLBACK:
56         return "OC_STACK_INVALID_CALLBACK";
57     case OC_STACK_INVALID_METHOD:
58         return "OC_STACK_INVALID_METHOD";
59     case OC_STACK_INVALID_PARAM:
60         return "OC_STACK_INVALID_PARAM";
61     case OC_STACK_INVALID_OBSERVE_PARAM:
62         return "OC_STACK_INVALID_OBSERVE_PARAM";
63     case OC_STACK_NO_MEMORY:
64         return "OC_STACK_NO_MEMORY";
65     case OC_STACK_COMM_ERROR:
66         return "OC_STACK_COMM_ERROR";
67     case OC_STACK_TIMEOUT:
68         return "OC_STACK_TIMEOUT";
69     case OC_STACK_ADAPTER_NOT_ENABLED:
70         return "OC_STACK_ADAPTER_NOT_ENABLED";
71     case OC_STACK_NOTIMPL:
72         return "OC_STACK_NOTIMPL";
73     case OC_STACK_NO_RESOURCE:
74         return "OC_STACK_NO_RESOURCE";
75     case OC_STACK_RESOURCE_ERROR:
76         return "OC_STACK_RESOURCE_ERROR";
77     case OC_STACK_SLOW_RESOURCE:
78         return "OC_STACK_SLOW_RESOURCE";
79     case OC_STACK_DUPLICATE_REQUEST:
80         return "OC_STACK_DUPLICATE_REQUEST";
81     case OC_STACK_NO_OBSERVERS:
82         return "OC_STACK_NO_OBSERVERS";
83     case OC_STACK_OBSERVER_NOT_FOUND:
84         return "OC_STACK_OBSERVER_NOT_FOUND";
85     case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
86         return "OC_STACK_VIRTUAL_DO_NOT_HANDLE";
87     case OC_STACK_INVALID_OPTION:
88         return "OC_STACK_INVALID_OPTION";
89     case OC_STACK_MALFORMED_RESPONSE:
90         return "OC_STACK_MALFORMED_RESPONSE";
91     case OC_STACK_INVALID_REQUEST_HANDLE:
92         return "OC_STACK_INVALID_REQUEST_HANDLE";
93     case OC_STACK_INVALID_DEVICE_INFO:
94         return "OC_STACK_INVALID_DEVICE_INFO";
95     case OC_STACK_INVALID_JSON:
96         return "OC_STACK_INVALID_JSON";
97     case OC_STACK_UNAUTHORIZED_REQ:
98         return "OC_STACK_UNAUTHORIZED_REQ";
99     case OC_STACK_TOO_LARGE_REQ:
100         return "OC_STACK_TOO_LARGE_REQ";
101     #ifdef WITH_PRESENCE
102     case OC_STACK_PRESENCE_STOPPED:
103         return "OC_STACK_PRESENCE_STOPPED";
104     case OC_STACK_PRESENCE_TIMEOUT:
105         return "OC_STACK_PRESENCE_TIMEOUT";
106     case OC_STACK_PRESENCE_DO_NOT_HANDLE:
107         return "OC_STACK_PRESENCE_DO_NOT_HANDLE";
108     #endif
109     case OC_STACK_USER_DENIED_REQ:
110         return "OC_STACK_USER_DENIED_REQ";
111     case OC_STACK_NOT_ACCEPTABLE:
112         return "OC_STACK_NOT_ACCEPTABLE";
113     case OC_STACK_FORBIDDEN_REQ:
114         return "OC_STACK_FORBIDDEN_REQ";
115     case OC_STACK_INTERNAL_SERVER_ERROR:
116         return "OC_STACK_INTERNAL_SERVER_ERROR";
117     case OC_STACK_GATEWAY_TIMEOUT:
118         return "OC_STACK_GATEWAY_TIMEOUT";
119     case OC_STACK_SERVICE_UNAVAILABLE:
120         return "OC_STACK_SERVICE_UNAVAILABLE";
121     case OC_STACK_ERROR:
122         return "OC_STACK_ERROR";
123     default:
124         return "UNKNOWN";
125     }
126 }
127
128 void StripNewLineChar(char* str) {
129     int i = 0;
130     if (str)
131     {
132         while( str[i])
133         {
134             if (str[i] == '\n')
135                 str[i] = '\0';
136             i++;
137         }
138     }
139 }
140