(file) Return to http.h CVS log (file) (dir) Up to [OMI] / omi / protocol

  1 mike  1.1 /*
  2           **==============================================================================
  3           **
  4           ** Open Management Infrastructure (OMI)
  5           **
  6           ** Copyright (c) Microsoft Corporation
  7           ** 
  8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9           ** use this file except in compliance with the License. You may obtain a copy 
 10           ** of the License at 
 11           **
 12           **     http://www.apache.org/licenses/LICENSE-2.0 
 13           **
 14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18           **
 19           ** See the Apache 2 License for the specific language governing permissions 
 20           ** and limitations under the License.
 21           **
 22 mike  1.1 **==============================================================================
 23           */
 24           
 25           #ifndef _omi_http_h
 26           #define _omi_http_h
 27           
 28           #include "config.h"
 29           #include <common.h>
 30           #include <base/batch.h>
 31           #include "selector.h"
 32           
 33           BEGIN_EXTERNC
 34           
 35           /* HTTP Error codes */
 36           #define HTTP_ERROR_CODE_OK      200
 37           #define HTTP_ERROR_CODE_BAD_REQUEST                 400
 38           #define HTTP_ERROR_CODE_UNAUTHORIZED                401
 39           #define HTTP_ERROR_CODE_INTERNAL_SERVER_ERROR       500
 40           #define HTTP_ERROR_CODE_NOT_SUPPORTED               501
 41           
 42           /* ************************************************ */
 43 mike  1.1 /*                  Datatypes                       */
 44           /* ************************************************ */
 45           typedef struct _Http Http;
 46           
 47           /* Headers strucutre is creaetd provided by http module 
 48               and has several pre-parsed values from http headers */
 49           typedef struct _HttpHeaders
 50           {
 51               /* required fields */
 52               /* content type is pre-parsed: <content-type>;charset=<charset>*/
 53               const char* contentType;
 54               const char* charset;
 55           
 56               /* Authorization field: */
 57               /* for Basic, serer decodes username/pwd */
 58               const char* username;
 59               const char* password;
 60           
 61               /* for other than basci, server provides entire field: */
 62               const char* authorization;
 63           
 64 mike  1.1     /* length of http payload */
 65               size_t  contentLength;
 66           }
 67           HttpHeaders;
 68           
 69           /* HTTP options.
 70               mostly used for unit-testing; default values
 71               are hard-coded but can be overwritten by 
 72               unit-tests/config modules   */
 73           typedef struct _HttpOptions
 74           {
 75               /* timeout for network delays and keep-alive;
 76               note: http does not have timeout for server/provider processing */
 77               MI_Uint64   timeoutUsec;
 78           }
 79           HttpOptions;
 80           
 81           /* 60 sec timeout */
 82           #define DEFAULT_HTTP_OPTIONS  {60 * 1000000}
 83           
 84           /* ************************************************ */
 85 mike  1.1 /*                  callbacks                       */
 86           /* ************************************************ */
 87           /* invoked by http server when new connection is established
 88               this callback is called once before any 'OnRequest' calls
 89               and allows next stack layer to allocate connection-specific context
 90               */
 91           typedef void (*HttpCallbackOnNewConnection)(
 92               Http* http,
 93               void* callbackData,
 94               void* httpConnectionHandle,
 95               void** connectionData);
 96           
 97           /* invoked by http server when new request received
 98               (data contains the entire buffer);
 99               if user wants to keep 'data' buffer, it has to take ownership
100               of the buffer by assigning *data = 0;
101               headers has to be consumed within callback (either process or make a copy)
102               */
103           typedef void (*HttpCallbackOnRequest)(
104               Http* http,
105               void* callbackData,
106 mike  1.1     void* connectionData,
107               void* httpConnectionHandle,
108               const HttpHeaders* headers,
109               Page** data);
110           
111           /* invoked by http server when exisiting connection is closed
112               this callback is called once 
113               and allows next stack layer to free connection-specific context
114               */
115           typedef void (*HttpCallbackOnCloseConnection)(
116               Http* http,
117               void* callbackData,
118               void* connectionData);
119           
120           MI_Result Http_New_Server(
121               Http** selfOut,
122               Selector* selector, /*optional, maybe NULL*/
123               unsigned short http_port,   /* 0 to disable */
124               unsigned short https_port,  /* 0 to disable */
125               HttpCallbackOnNewConnection callbackOnNewConnection,
126               HttpCallbackOnCloseConnection callbackOnCloseConnection,
127 mike  1.1     HttpCallbackOnRequest callbackOnRequest,
128               void* callbackData);
129           
130           MI_Result Http_Delete(
131               Http* self);
132           
133           MI_Result Http_Run(
134               Http* self,
135               MI_Uint64 timeoutUsec);
136           
137           /* sends http response with given error code and provided content;
138            if message is accepted to be sent, on return *data == null (taking memory ownership)*/
139           MI_Result Http_SendResponse(
140               Http* self,
141               void* httpConnectionHanlde,
142               int httpErrorCode,
143               Page** data);
144           
145           MI_INLINE MI_Result Http_SendErrorResponse(
146               Http* self,
147               void* httpConnectionHanlde,
148 mike  1.1     int httpErrorCode)
149           {
150               return Http_SendResponse(self, httpConnectionHanlde, httpErrorCode, 0);
151           }
152           
153           /* Sets http options (mostly unit-test support) */
154           MI_Result Http_SetOptions(
155               Http* self,
156               const HttpOptions* options);
157           
158           END_EXTERNC
159           
160           #endif /* _omi_http_h */

ViewCVS 0.9.2