1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
24 #include "occoaphelper.h"
25 #include "ocstackconfig.h"
27 #include "coap_time.h"
32 //-----------------------------------------------------------------------------
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;} }
38 //=============================================================================
40 //=============================================================================
42 OCStackResult isVendorSpecific(uint16_t optionID)
44 if(optionID >= COAP_VENDOR_OPT_START && optionID <= COAP_MAX_OPT)
48 return OC_STACK_INVALID_OPTION;
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)
55 OCResponse * response = (OCResponse *) OCMalloc(sizeof(OCResponse));
58 return OC_STACK_NO_MEMORY;
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;
68 *responseLoc = response;
72 OCStackResult FormOCClientResponse(OCClientResponse * clientResponse,
73 OCStackResult result, OCDevAddr * remote, uint32_t seqNum,
74 const unsigned char * resJSONPayload)
76 clientResponse->sequenceNumber = seqNum;
77 clientResponse->result = result;
78 clientResponse->addr = remote;
79 clientResponse->resJSONPayload = resJSONPayload;