Merge "[CA] [All] URI support , Optimization , License verification" into connectivit...
[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 #ifdef CA_INT
27     #include "cacommon.h"
28     #include "cainterface.h"
29 #endif
30 /**
31  * The signature of the internal call back functions to handle responses from entity handler
32  */
33 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
34 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
35 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
36
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
40     OCMethod method;
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];
45
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;
51     uint8_t numResponses;
52     OCEHResponseHandler ehResponseHandler;
53 #ifdef CA_INT
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
59 #endif
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;
68     uint8_t secured;
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
76     uint8_t slowFlag;
77     uint8_t notificationFlag;
78     // reqJSON is retrieved from the payload of the received request PDU
79     unsigned char reqJSONPayload[1];
80 } OCServerRequest;
81
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;
89 } OCServerResponse;
90
91 OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token);
92
93 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
94
95 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
96
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);
104
105 #ifdef CA_INT
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);
114 #endif
115
116 OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
117
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);
123
124 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
125
126 void DeleteServerRequest(OCServerRequest * serverRequest);
127
128 void FindAndDeleteServerResponse(OCServerResponse * serverResponse);
129
130 void DeleteServerResponse(OCServerResponse * serverResponse);
131
132 #endif //OC_SERVER_REQUEST_H