Removed #ifdef CA_INTs and other code cleanup.
[platform/upstream/iotivity.git] / resource / csdk / stack / include / internal / ocserverrequest.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OC_SERVER_REQUEST_H
22 #define OC_SERVER_REQUEST_H
23
24 #include "occoap.h"
25
26 #include "cacommon.h"
27 #include "cainterface.h"
28 /**
29  * The signature of the internal call back functions to handle responses from entity handler
30  */
31 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
32 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
33 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
34
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
38     OCMethod method;
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];
43
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;
49     uint8_t numResponses;
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;
63     uint8_t secured;
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
71     uint8_t slowFlag;
72     uint8_t notificationFlag;
73     // reqJSON is retrieved from the payload of the received request PDU
74     unsigned char reqJSONPayload[1];
75 } OCServerRequest;
76
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;
84 } OCServerResponse;
85
86 OCServerRequest * GetServerRequestUsingToken (const CAToken_t token);
87
88 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
89
90 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
91
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);
100
101 OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
102
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);
108
109 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
110
111 void DeleteServerRequest(OCServerRequest * serverRequest);
112
113 void FindAndDeleteServerResponse(OCServerResponse * serverResponse);
114
115 void DeleteServerResponse(OCServerResponse * serverResponse);
116
117 #endif //OC_SERVER_REQUEST_H