6912e5deb9d888d72f7860d0dbe9d7f9bb9fd429
[platform/upstream/iotivity.git] / service / coap-http-proxy / include / CoapHttpMap.h
1 /* ****************************************************************
2  *
3  * Copyright 2016 Samsung Electronics 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 /**
22  * @file
23  * This file contains CoAP to HTTP mapping
24  */
25
26 #ifndef COAP_HTTP_MAP_H_
27 #define COAP_HTTP_MAP_H_
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33
34 #include "CoapHttpParser.h"
35 #if defined (__TIZENRT__)
36 #include <apps/netutils/cJSON.h>
37 #else
38 #include "cJSON.h"
39 #endif
40
41 /**
42  * Function to get CoAP code for an HTTP code.
43  * @param[in]   httpCode            HTTP Code.
44  * @param[in]   method              Request Method type
45  * @param[out]  ocfCode             Corresponding OCF code.
46  * @return ::OC_STACK_OK or appropriate error code.
47  */
48 OCStackResult CHPGetOCCode(const HttpResponseResult_t httpCode, const OCMethod method,
49                            OCEntityHandlerResult *ocfCode);
50
51 /**
52  * Function to get CoAP option for an HTTP option.
53  * @param[in]   httpOption        HTTP Option.
54  * @param[out]  ret               Corresponding CoAP option.
55  * @return ::OC_STACK_OK or appropriate error code.
56  */
57 OCStackResult CHPGetOCOption(const HttpHeaderOption_t *httpOption, OCHeaderOption *ret);
58
59 /**
60  * Function to get CoAP payload format for HTTP payload format.
61  * @param[in]   httpContentType   HTTP payload format.
62  * @return CoAP payload format.
63  */
64 OCPayloadFormat CHPGetOCContentType(const char *httpContentType);
65
66 /**
67  * Function to get HTTP method for OCF method.
68  * @param[in]   method            OCF method.
69  * @param[out]  httpMethod        Corresponding HTTP method.
70  * @return ::OC_STACK_OK or appropriate error code.
71  */
72 OCStackResult CHPGetHttpMethod(const OCMethod method, HttpMethod_t *httpMethod);
73
74 /**
75  * Function to get HTTP option for OCF option.
76  * @param[in]   option            OCF option.
77  * @param[out]  ret               Corresponding HTTP option.
78  * @return ::OC_STACK_OK or appropriate error code.
79  */
80 OCStackResult CHPGetHttpOption(const OCHeaderOption* option, HttpHeaderOption_t **ret);
81
82 /**
83  * Function to convert Json payload to CBOR representational payload.
84  * @param[in]   rootJSon          Json payload.
85  * @param[out]  payload           CBor representational payload.
86  */
87 void CHPJsonToRepPayload(cJSON* rootJSon, OCRepPayload* payload);
88
89 /**
90  * Function to convert CBOR representational payload to Json payload.
91  * @param[in]   repData           Cbor representational payload.
92  * @return CJson payload.
93  */
94 cJSON* CHPRepPayloadToJson(OCRepPayload* repData);
95 #ifdef __cplusplus
96 }
97 #endif
98 #endif