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 #ifndef OC_SERVER_REQUEST_H
22 #define OC_SERVER_REQUEST_H
27 #include "cainterface.h"
29 * The signature of the internal call back functions to handle responses from entity handler
31 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
32 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
33 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
35 // following structure will be created in occoap and passed up the stack on the server side
36 typedef struct OCServerRequest {
37 // the REST method retrieved from received request PDU
39 // resourceUrl will be filled in occoap using the path options in received request PDU
40 unsigned char resourceUrl[MAX_URI_LENGTH];
41 // resource query send by client
42 unsigned char query[MAX_QUERY_LENGTH];
44 // qos is indicating if the request is CON or NON
45 OCQualityOfService qos;
46 // Observe option field
47 uint32_t observationOption;
48 OCStackResult observeResult;
50 OCEHResponseHandler ehResponseHandler;
51 /** Remote Endpoint address **/
52 CAAddress_t addressInfo;
53 /** Connectivity of the endpoint**/
54 CAConnectivityType_t connectivityType;
55 //////////////////////////////////////////////////////////
56 // IP address & port of client registered for observe //These
57 OCDevAddr requesterAddr; //Members
58 // token for the observe request
59 CAToken_t requestToken;
60 // The ID of CoAP pdu //Kept in
61 uint16_t coapID; //CoAP
62 uint8_t delayedResNeeded;
64 //////////////////////////////////////////////////////////
65 // An array of the received vendor specific header options
66 uint8_t numRcvdVendorSpecificHeaderOptions;
67 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
68 uint8_t requestComplete;
69 struct OCServerRequest * next;
70 // Flag indicating slow response
72 uint8_t notificationFlag;
73 // reqJSON is retrieved from the payload of the received request PDU
74 unsigned char reqJSONPayload[1];
77 // following structure will be created in ocstack to aggregate responses (in future: for block transfer)
78 typedef struct OCServerResponse {
79 struct OCServerResponse * next;
80 // this is the pointer to server payload data to be transferred
81 unsigned char *payload;
82 uint16_t remainingPayloadSize;
83 OCRequestHandle requestHandle;
86 OCServerRequest * GetServerRequestUsingToken (const CAToken_t token);
88 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
90 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
92 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
93 uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
94 uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
95 OCQualityOfService qos, unsigned char * query,
96 OCHeaderOption * rcvdVendorSpecificHeaderOptions,
97 unsigned char * reqJSONPayload, CAToken_t * requestToken,
98 OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize,
99 CAAddress_t *addressInfo, CAConnectivityType_t connectivityType);
101 OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
103 // Internal function to create OCEntityHandlerRequest at the server from a received coap pdu
104 OCStackResult FormOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest, OCRequestHandle request,
105 OCMethod method, OCResourceHandle resource, unsigned char * queryBuf, unsigned char * bufReqPayload,
106 uint8_t numVendorOptions, OCHeaderOption * vendorOptions, OCObserveAction observeAction,
107 OCObservationId observeID);
109 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
111 void DeleteServerRequest(OCServerRequest * serverRequest);
113 void FindAndDeleteServerResponse(OCServerResponse * serverResponse);
115 void DeleteServerResponse(OCServerResponse * serverResponse);
117 #endif //OC_SERVER_REQUEST_H