Modifying version number for building on tizen 3.0
[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 /**
27  * The signature of the internal call back functions to handle responses from entity handler
28  */
29 typedef OCStackResult (* OCEHResponseHandler)(OCEntityHandlerResponse * ehResponse);
30 OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse);
31 OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse);
32
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
36     OCMethod method;
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];
41
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;
47     uint8_t numResponses;
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;
57     uint8_t secured;
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
65     uint8_t slowFlag;
66     uint8_t notificationFlag;
67     // reqJSON is retrieved from the payload of the received request PDU
68     unsigned char reqJSONPayload[1];
69 } OCServerRequest;
70
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;
78 } OCServerResponse;
79
80 OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token);
81
82 OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
83
84 OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
85
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);
93
94 OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
95
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);
101
102 void FindAndDeleteServerRequest(OCServerRequest * serverRequest);
103
104 void DeleteServerRequest(OCServerRequest * serverRequest);
105
106 void FindAndDeleteServerResponse(OCServerResponse * serverResponse);
107
108 void DeleteServerResponse(OCServerResponse * serverResponse);
109
110 #endif //OC_SERVER_REQUEST_H