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
25 #include "cainterface.h"
27 * The signature of the internal call back functions to handle responses from entity handler
29 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
31 // following structure will be created in occoap and passed up the stack on the server side
32 typedef struct OCServerRequest
34 // the REST method retrieved from received request PDU
36 // resourceUrl will be filled in occoap using the path options in received request PDU
37 char resourceUrl[MAX_URI_LENGTH];
38 // resource query send by client
39 char query[MAX_QUERY_LENGTH];
41 // qos is indicating if the request is CON or NON
42 OCQualityOfService qos;
43 // Observe option field
44 uint32_t observationOption;
45 OCStackResult observeResult;
47 OCEHResponseHandler ehResponseHandler;
48 /** Remote Endpoint address **/
49 CAAddress_t addressInfo;
50 /** Connectivity of the endpoint**/
51 CAConnectivityType_t connectivityType;
52 // token for the request
53 CAToken_t requestToken;
54 // token length the request
56 // The ID of CoAP pdu //Kept in
57 uint16_t coapID; //CoAP
58 uint8_t delayedResNeeded;
60 //////////////////////////////////////////////////////////
61 // An array of the received vendor specific header options
62 uint8_t numRcvdVendorSpecificHeaderOptions;
63 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
64 uint8_t requestComplete;
65 struct OCServerRequest * next;
66 // Flag indicating slow response
68 uint8_t notificationFlag;
69 // reqJSON is retrieved from the payload of the received request PDU
70 char reqJSONPayload[1];
73 // following structure will be created in ocstack to aggregate responses (in future: for block transfer)
74 typedef struct OCServerResponse {
75 struct OCServerResponse * next;
76 // this is the pointer to server payload data to be transferred
78 uint16_t remainingPayloadSize;
79 OCRequestHandle requestHandle;
83 * Handler function for sending a response from a single resource
85 * @param ehResponse - pointer to the response from the resource
90 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
93 * Handler function for sending a response from multiple resources, such as a collection.
94 * Aggregates responses from multiple resource until all responses are received then sends the
95 * concatenated response
97 * TODO: Need to add a timeout in case a (remote?) resource does not respond
99 * @param ehResponse - pointer to the response from the resource
104 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
107 * Get a server request from the server request list using the specified token.
109 * @param token - token of server request
110 * @param tokenLength - length of token
115 OCServerRequest * GetServerRequestUsingToken (const CAToken_t token, uint8_t tokenLength);
118 * Get a server request from the server request list using the specified handle
120 * @param handle - handle of server request
124 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
127 * Get a server response from the server response list using the specified handle
129 * @param handle - handle of server response
134 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
137 * Add a server request to the server request list
139 * @param request - initialized server request that is created by this function
140 * @param coapID - ID of CoAP pdu
141 * @param delayedResNeeded - delayed response required 0=no 1=yes
142 * @param secured - secure endpoint 0=no 1=yes
143 * @param notificationFlag - //TODO: remove - does not appear to be used any longer
144 * @param method - RESTful method
145 * @param numRcvdVendorSpecificHeaderOptions - number of received vendor specific header options
146 * @param observationOption - value of observation option
147 * @param qos - request QOS
148 * @param query - request query
149 * @param rcvdVendorSpecificHeaderOptions - received vendor specific header options
150 * @param reqJSONPayload - request JSON payload
151 * @param requestToken - request token
152 * @param tokenLength - request token length
153 * @param resourceUrl - URL of resource
154 * @param reqTotalSize - total size of the request
155 * @param addressInfo - CA Address
156 * @param connectivityType - connection type
161 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
162 uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
163 uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
164 OCQualityOfService qos, char * query,
165 OCHeaderOption * rcvdVendorSpecificHeaderOptions,
166 char * reqJSONPayload, CAToken_t * requestToken,
168 char * resourceUrl, size_t reqTotalSize,
169 CAAddress_t *addressInfo, CAConnectivityType_t connectivityType);
172 * Form the OCEntityHandlerRequest struct that is passed to a resource's entity handler
174 * @param entityHandlerRequest - pointer to the OCEntityHandlerRequest struct that is created
175 * @param request - request handle
176 * @param method - RESTful method
177 * @param resource - resource handle
178 * @param queryBuf - resource query of request
179 * @param bufReqPayload - JSON payload of request
180 * @param numVendorOptions - number of vendor options
181 * @param vendorOptions - vendor options
182 * @param observeAction - observe action flag
183 * @param observeID - observe ID
188 OCStackResult FormOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest, OCRequestHandle request,
189 OCMethod method, OCResourceHandle resource, char * queryBuf, char * bufReqPayload,
190 uint8_t numVendorOptions, OCHeaderOption * vendorOptions, OCObserveAction observeAction,
191 OCObservationId observeID);
194 * Find a server request in the server request list and delete
196 * @param serverRequest - server request to find and delete
198 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
200 #endif //OC_SERVER_REQUEST_H