Removed #ifdef CA_INTs and other code cleanup.
[platform/upstream/iotivity.git] / resource / csdk / occoap / src / occoaphelper.c
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 //-----------------------------------------------------------------------------
22 // Includes
23 //-----------------------------------------------------------------------------
24 #include "occoaphelper.h"
25 #include "ocstackconfig.h"
26 #include "logger.h"
27 #include "coap_time.h"
28 #include "ocmalloc.h"
29
30 #include "cacommon.h"
31
32 //-----------------------------------------------------------------------------
33 // Macros
34 //-----------------------------------------------------------------------------
35 #define TAG    PCF("OCCoAPHelper")
36 #define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG_V(FATAL, TAG, "%s is NULL", #arg); goto exit;} }
37
38 //=============================================================================
39 // Helper Functions
40 //=============================================================================
41
42 OCStackResult isVendorSpecific(uint16_t optionID)
43 {
44     if(optionID >= COAP_VENDOR_OPT_START && optionID <= COAP_MAX_OPT)
45     {
46         return OC_STACK_OK;
47     }
48     return OC_STACK_INVALID_OPTION;
49 }
50
51 OCStackResult FormOCResponse(OCResponse * * responseLoc,  ClientCB * cbNode, uint32_t maxAge,
52         unsigned char * fullUri, unsigned char * rcvdUri, CAToken_t * rcvdToken,
53         OCClientResponse * clientResponse, unsigned char * bufRes)
54 {
55     OCResponse * response = (OCResponse *) OCMalloc(sizeof(OCResponse));
56     if (!response)
57     {
58         return OC_STACK_NO_MEMORY;
59     }
60     response->cbNode = cbNode;
61     response->maxAge = maxAge;
62     response->fullUri = fullUri;
63     response->rcvdUri = rcvdUri;
64     response->rcvdToken = rcvdToken;
65     response->clientResponse = clientResponse;
66     response->bufRes = bufRes;
67
68     *responseLoc = response;
69     return OC_STACK_OK;
70 }
71
72 OCStackResult FormOCClientResponse(OCClientResponse * clientResponse,
73         OCStackResult result, OCDevAddr * remote, uint32_t seqNum,
74         const unsigned char * resJSONPayload)
75 {
76     clientResponse->sequenceNumber = seqNum;
77     clientResponse->result = result;
78     clientResponse->addr = remote;
79     clientResponse->resJSONPayload = resJSONPayload;
80
81     return OC_STACK_OK;
82 }
83