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
28 #include "cainterface.h"
31 * The signature of the internal call back functions to handle responses from entity handler
33 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
34 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
35 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
37 // following structure will be created in occoap and passed up the stack on the server side
38 typedef struct OCServerRequest {
39 // the REST method retrieved from received request PDU
41 // resourceUrl will be filled in occoap using the path options in received request PDU
42 unsigned char resourceUrl[MAX_URI_LENGTH];
43 // resource query send by client
44 unsigned char query[MAX_QUERY_LENGTH];
46 // qos is indicating if the request is CON or NON
47 OCQualityOfService qos;
48 // Observe option field
49 uint32_t observationOption;
50 OCStackResult observeResult;
52 OCEHResponseHandler ehResponseHandler;
54 /** Remote Endpoint address **/
55 CAAddress_t addressInfo;
56 /** Connectivity of the endpoint**/
57 CAConnectivityType_t connectivityType;
58 char token[32]; // TODO-CA: What is max CAToken_t length? Get rid of magic number
60 //////////////////////////////////////////////////////////
61 // IP address & port of client registered for observe //These
62 OCDevAddr requesterAddr; //Members
63 // CoAP token for the observe request //Might
64 OCCoAPToken requestToken; //Be
65 // The ID of CoAP pdu //Kept in
66 uint16_t coapID; //CoAP
67 uint8_t delayedResNeeded;
69 //////////////////////////////////////////////////////////
70 // An array of the received vendor specific header options
71 uint8_t numRcvdVendorSpecificHeaderOptions;
72 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
73 uint8_t requestComplete;
74 struct OCServerRequest * next;
75 // Flag indicating slow response
77 uint8_t notificationFlag;
78 // reqJSON is retrieved from the payload of the received request PDU
79 unsigned char reqJSONPayload[1];
82 // following structure will be created in ocstack to aggregate responses (in future: for block transfer)
83 typedef struct OCServerResponse {
84 struct OCServerResponse * next;
85 // this is the pointer to server payload data to be transferred
86 unsigned char *payload;
87 uint16_t remainingPayloadSize;
88 OCRequestHandle requestHandle;
91 OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token);
93 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
95 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
97 OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
98 uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
99 uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
100 OCQualityOfService qos, unsigned char * query,
101 OCHeaderOption * rcvdVendorSpecificHeaderOptions,
102 unsigned char * reqJSONPayload, OCCoAPToken * requestToken,
103 OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize);
106 OCStackResult AddServerCARequest (OCServerRequest ** request, uint16_t coapID,
107 uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
108 uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
109 OCQualityOfService qos, unsigned char * query,
110 OCHeaderOption * rcvdVendorSpecificHeaderOptions,
111 unsigned char * reqJSONPayload, OCCoAPToken * requestToken,
112 OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize,
113 CAAddress_t *addressInfo, CAConnectivityType_t connectivityType, char *token);
116 OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
118 // Internal function to create OCEntityHandlerRequest at the server from a received coap pdu
119 OCStackResult FormOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest, OCRequestHandle request,
120 OCMethod method, OCResourceHandle resource, unsigned char * queryBuf, unsigned char * bufReqPayload,
121 uint8_t numVendorOptions, OCHeaderOption * vendorOptions, OCObserveAction observeAction,
122 OCObservationId observeID);
124 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
126 void DeleteServerRequest(OCServerRequest * serverRequest);
128 void FindAndDeleteServerResponse(OCServerResponse * serverResponse);
130 void DeleteServerResponse(OCServerResponse * serverResponse);
132 #endif //OC_SERVER_REQUEST_H