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 **/
50 // token for the request
51 CAToken_t requestToken;
52 // token length the request
54 // The ID of CoAP pdu //Kept in
55 uint16_t coapID; //CoAP
56 uint8_t delayedResNeeded;
57 //////////////////////////////////////////////////////////
58 // An array of the received vendor specific header options
59 uint8_t numRcvdVendorSpecificHeaderOptions;
60 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
61 uint8_t requestComplete;
62 struct OCServerRequest * next;
63 // Flag indicating slow response
65 uint8_t notificationFlag;
67 // payload is retrieved from the payload of the received request PDU
71 // following structure will be created in ocstack to aggregate responses (in future: for block transfer)
72 typedef struct OCServerResponse {
73 struct OCServerResponse * next;
74 // this is the pointer to server payload data to be transferred
76 OCRequestHandle requestHandle;
80 * Handler function for sending a response from a single resource
82 * @param ehResponse - pointer to the response from the resource
87 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
90 * Handler function for sending a response from multiple resources, such as a collection.
91 * Aggregates responses from multiple resource until all responses are received then sends the
92 * concatenated response
94 * TODO: Need to add a timeout in case a (remote?) resource does not respond
96 * @param ehResponse - pointer to the response from the resource
101 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
104 * Get a server request from the server request list using the specified token.
106 * @param token - token of server request
107 * @param tokenLength - length of token
112 OCServerRequest * GetServerRequestUsingToken (const CAToken_t token, uint8_t tokenLength);
115 * Get a server request from the server request list using the specified handle
117 * @param handle - handle of server request
121 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
124 * Get a server response from the server response list using the specified handle
126 * @param handle - handle of server response
131 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
134 * Add a server request to the server request list
136 * @param request - initialized server request that is created by this function
137 * @param coapID - ID of CoAP pdu
138 * @param delayedResNeeded - delayed response required 0=no 1=yes
139 * @param secured - secure endpoint 0=no 1=yes
140 * @param notificationFlag - //TODO: remove - does not appear to be used any longer
141 * @param method - RESTful method
142 * @param numRcvdVendorSpecificHeaderOptions - number of received vendor specific header options
143 * @param observationOption - value of observation option
144 * @param qos - request QOS
145 * @param query - request query
146 * @param rcvdVendorSpecificHeaderOptions - received vendor specific header options
147 * @param reqJSONPayload - request JSON payload
148 * @param requestToken - request token
149 * @param tokenLength - request token length
150 * @param resourceUrl - URL of resource
151 * @param reqTotalSize - total size of the request
152 * @param devAddr - OCDevAddr
157 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
158 uint8_t delayedResNeeded, uint8_t notificationFlag, OCMethod method,
159 uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
160 OCQualityOfService qos, char * query,
161 OCHeaderOption * rcvdVendorSpecificHeaderOptions,
162 uint8_t * payload, CAToken_t requestToken,
164 char * resourceUrl, size_t reqTotalSize,
165 const OCDevAddr *devAddr);
168 * Form the OCEntityHandlerRequest struct that is passed to a resource's entity handler
170 * @param entityHandlerRequest - pointer to the OCEntityHandlerRequest struct that is created
171 * @param request - request handle
172 * @param method - RESTful method
173 * @param endpoint - requesting endpoint
174 * @param resource - resource handle
175 * @param queryBuf - resource query of request
176 * @param payload - payload of request
177 * @param payloadSize - size of the payload request
178 * @param numVendorOptions - number of vendor options
179 * @param vendorOptions - vendor options
180 * @param observeAction - observe action flag
181 * @param observeID - observe ID
186 OCStackResult FormOCEntityHandlerRequest(
187 OCEntityHandlerRequest *entityHandlerRequest,
188 OCRequestHandle request,
191 OCResourceHandle resource,
195 uint8_t numVendorOptions,
196 OCHeaderOption *vendorOptions,
197 OCObserveAction observeAction,
198 OCObservationId observeID);
201 * Find a server request in the server request list and delete
203 * @param serverRequest - server request to find and delete
205 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
207 #endif //OC_SERVER_REQUEST_H