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 * The signature of the internal call back functions to handle responses from entity handler
29 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
30 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
31 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
33 // following structure will be created in occoap and passed up the stack on the server side
34 typedef struct OCServerRequest {
35 // the REST method retrieved from received request PDU
37 // resourceUrl will be filled in occoap using the path options in received request PDU
38 unsigned char resourceUrl[MAX_URI_LENGTH];
39 // resource query send by client
40 unsigned char query[MAX_QUERY_LENGTH];
42 // qos is indicating if the request is CON or NON
43 OCQualityOfService qos;
44 // Observe option field
45 uint32_t observationOption;
46 OCStackResult observeResult;
48 OCEHResponseHandler ehResponseHandler;
49 //////////////////////////////////////////////////////////
50 // IP address & port of client registered for observe //These
51 OCDevAddr requesterAddr; //Members
52 // CoAP token for the observe request //Might
53 OCCoAPToken requestToken; //Be
54 // The ID of CoAP pdu //Kept in
55 uint16_t coapID; //CoAP
56 uint8_t delayedResNeeded;
58 //////////////////////////////////////////////////////////
59 // An array of the received vendor specific header options
60 uint8_t numRcvdVendorSpecificHeaderOptions;
61 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
62 uint8_t requestComplete;
63 struct OCServerRequest * next;
64 // Flag indicating slow response
66 uint8_t notificationFlag;
67 // reqJSON is retrieved from the payload of the received request PDU
68 unsigned char reqJSONPayload[1];
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
75 unsigned char *payload;
76 uint16_t remainingPayloadSize;
77 OCRequestHandle requestHandle;
80 OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token);
82 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
84 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
86 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
87 uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
88 uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
89 OCQualityOfService qos, unsigned char * query,
90 OCHeaderOption * rcvdVendorSpecificHeaderOptions,
91 unsigned char * reqJSONPayload, OCCoAPToken * requestToken,
92 OCDevAddr * requesterAddr, unsigned char * resourceUrl, uint32_t reqTotalSize);
94 OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
96 // Internal function to create OCEntityHandlerRequest at the server from a received coap pdu
97 OCStackResult FormOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest, OCRequestHandle request,
98 OCMethod method, OCResourceHandle resource, unsigned char * queryBuf, unsigned char * bufReqPayload,
99 uint8_t numVendorOptions, OCHeaderOption * vendorOptions, OCObserveAction observeAction,
100 OCObservationId observeID);
102 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
104 void DeleteServerRequest(OCServerRequest * serverRequest);
106 void FindAndDeleteServerResponse(OCServerResponse * serverResponse);
108 void DeleteServerResponse(OCServerResponse * serverResponse);
110 #endif //OC_SERVER_REQUEST_H