Integrated WIFI/ETHERNET adapters to single IPAdapter.
[platform/upstream/iotivity.git] / resource / csdk / stack / include / internal / ocresourcehandler.h
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
21 #ifndef OC_RESOURCEHANDLER_H
22 #define OC_RESOURCEHANDLER_H
23
24 #include "ocstack.h"
25 #include "ocstackinternal.h"
26 #include "ocserverrequest.h"
27
28 /**
29  * Attributes used to form a proper OIC conforming JSON message.
30  */
31 #define OC_RSRVD_OC                     "oc"
32 #define OC_RSRVD_PAYLOAD                "payload"
33 #define OC_RSRVD_HREF                   "href"
34 #define OC_RSRVD_PROPERTY               "prop"
35 #define OC_RSRVD_REPRESENTATION         "rep"
36 #define OC_RSRVD_CONTENT_TYPE           "ct"
37 #define OC_RSRVD_RESOURCE_TYPE          "rt"
38 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "core.presence"
39 #define OC_RSRVD_INTERFACE              "if"
40 #define OC_RSRVD_DEVICE_ID              "di"
41 #define OC_RSRVD_DEVICE_NAME            "dn"
42 #define OC_RSRVD_INTERFACE_DEFAULT      "oc.mi.def"
43 #define OC_RSRVD_INTERFACE_LL           "oc.mi.ll"
44 #define OC_RSRVD_INTERFACE_BATCH        "oc.mi.b"
45 #define OC_RSRVD_INTERFACE_GROUP        "oc.mi.grp"
46 #define OC_RSRVD_MFG_DATE               "mndt"
47 #define OC_RSRVD_FW_VERSION             "mnfv"
48 #define OC_RSRVD_HOST_NAME              "hn"
49 #define OC_RSRVD_MFG_NAME               "mnmn"
50 #define OC_RSRVD_MFG_URL                "mnml"
51 #define OC_RSRVD_MODEL_NUM              "mnmo"
52 #define OC_RSRVD_PLATFORM_VERSION       "mnpv"
53 #define OC_RSRVD_SUPPORT_URL            "mnsl"
54 #define OC_RSRVD_VERSION                "icv"
55 #define OC_RSRVD_OBSERVABLE             "obs"
56 #define OC_RSRVD_SECURE                 "sec"
57 #define OC_RSRVD_HOSTING_PORT           "port"
58 #define OC_RSRVD_SERVER_INSTANCE_ID     "sid"
59
60 /**
61  * Common JSON string components used by the stack to build JSON strings.
62  * These details are exposed in ocstackconfig.h file in the form of documentation.
63  * Remember to update the documentation there if these are changed.
64  */
65 #define OC_JSON_PREFIX                     "{\"oc\":["
66 #define OC_JSON_PREFIX_LEN                 (sizeof(OC_JSON_PREFIX) - 1)
67 #define OC_JSON_SUFFIX                     "]}"
68 #define OC_JSON_SUFFIX_LEN                 (sizeof(OC_JSON_SUFFIX) - 1)
69 #define OC_JSON_SEPARATOR                  ','
70 #define OC_JSON_SEPARATOR_STR              ","
71
72 /**
73  * Static values for various JSON attributes.
74  */
75 #define OC_RESOURCE_OBSERVABLE   1
76 #define OC_RESOURCE_SECURE       1
77
78 /**
79  * The type of query a request/response message is.
80  */
81 typedef enum
82 {
83     STACK_RES_DISCOVERY_NOFILTER = 0,
84     STACK_RES_DISCOVERY_IF_FILTER,
85     STACK_RES_DISCOVERY_RT_FILTER,
86     STACK_DEVICE_DISCOVERY_DI_FILTER,
87     STACK_DEVICE_DISCOVERY_DN_FILTER
88 } StackQueryTypes;
89
90 /**
91  * The type of handling required to handle a request.
92  */
93 typedef enum
94 {
95     OC_RESOURCE_VIRTUAL = 0,
96     OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER,
97     OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER,
98     OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER,
99     OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER,
100     OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER,
101     OC_RESOURCE_NOT_SPECIFIED
102 } ResourceHandling;
103
104 /**
105  * Default entity handler (ie. callback) to be used for resources with
106  * no entity handler.
107  */
108 OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
109         OCEntityHandlerRequest * request);
110
111 /**
112  * Get string value associated with a virtual resource type.
113  */
114 const char * GetVirtualResourceUri(OCVirtualResources resource);
115
116 /**
117  * Find and retrieve pointer to a resource associated with a specific resource
118  * URI.
119  */
120 OCResource *FindResourceByUri(const char* resourceUri);
121
122 /**
123  * Returns true if the specificed resource URI aligns with a pre-existing
124  * virtual resource; returns false otherwise.
125  */
126 bool IsVirtualResource(const char* resourceUri);
127
128 /**
129  * Parameter @ref handling returns by-reference the type of resource handling
130  * required by the internal stack based on the specified @ref request.
131  */
132 OCStackResult DetermineResourceHandling (const OCServerRequest *request,
133                                          ResourceHandling *handling,
134                                          OCResource **resource);
135
136 /**
137  * Processes the specified @ref request based on the type of resource handling
138  * @ref resHandling.
139  */
140 OCStackResult ProcessRequest(ResourceHandling resHandling,
141                              OCResource *resource,
142                              OCServerRequest *request);
143
144 /**
145  * Internal API used to save all of the device's information for use in device
146  * discovery requests.
147  */
148 OCStackResult SaveDeviceInfo(OCDeviceInfo deviceInfo);
149
150 /**
151  * Internal API used to clear the device information.
152  */
153 void DeleteDeviceInfo();
154
155 /**
156  * Prepares a JSON string for response.
157  */
158 OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
159                                            uint8_t filterOn,
160                                            const char *filterValue,
161                                            char * out,
162                                            uint16_t *remaining,
163                                            CATransportType_t connType);
164
165 /**
166  * A helper function that Maps an @ref OCEntityHandlerResult type to an
167  * @ref OCStackResult type.
168  */
169 OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult);
170
171 #endif //OC_RESOURCEHANDLER_H
172