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

  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_http_h
 26           #define _omi_http_http_h
 27           
 28           #include "config.h"
 29           #include <common.h>
 30           #include <base/batch.h>
 31           #include <sock/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               /* Enable tracing of HTTP input and output */
 80               MI_Boolean enableTracing;
 81           }
 82           HttpOptions;
 83           
 84           /* 60 sec timeout */
 85 mike  1.1 #define DEFAULT_HTTP_OPTIONS  { (60 * 1000000), MI_FALSE }
 86           
 87           /* ************************************************ */
 88           /*                  callbacks                       */
 89           /* ************************************************ */
 90           /* invoked by http server when new connection is established
 91               this callback is called once before any 'OnRequest' calls
 92               and allows next stack layer to allocate connection-specific context
 93               */
 94           typedef void (*HttpCallbackOnNewConnection)(
 95               Http* http,
 96               void* callbackData,
 97               void* httpConnectionHandle,
 98               void** connectionData);
 99           
100           /* invoked by http server when new request received
101               (data contains the entire buffer);
102               if user wants to keep 'data' buffer, it has to take ownership
103               of the buffer by assigning *data = 0;
104               headers has to be consumed within callback (either process or make a copy)
105               */
106 mike  1.1 typedef void (*HttpCallbackOnRequest)(
107               Http* http,
108               void* callbackData,
109               void* connectionData,
110               void* httpConnectionHandle,
111               const HttpHeaders* headers,
112               Page** data);
113           
114           /* invoked by http server when exisiting connection is closed
115               this callback is called once 
116               and allows next stack layer to free connection-specific context
117               */
118           typedef void (*HttpCallbackOnCloseConnection)(
119               Http* http,
120               void* callbackData,
121               void* connectionData);
122           
123           MI_Result Http_New_Server(
124               Http** selfOut,
125               Selector* selector, /*optional, maybe NULL*/
126               unsigned short http_port,   /* 0 to disable */
127 mike  1.1     unsigned short https_port,  /* 0 to disable */
128               HttpCallbackOnNewConnection callbackOnNewConnection,
129               HttpCallbackOnCloseConnection callbackOnCloseConnection,
130               HttpCallbackOnRequest callbackOnRequest,
131               void* callbackData);
132           
133           MI_Result Http_Delete(
134               Http* self);
135           
136           MI_Result Http_Run(
137               Http* self,
138               MI_Uint64 timeoutUsec);
139           
140           /* sends http response with given error code and provided content;
141            if message is accepted to be sent, on return *data == null (taking memory ownership)*/
142           MI_Result Http_SendResponse(
143               Http* self,
144               void* httpConnectionHanlde,
145               int httpErrorCode,
146               Page** data);
147           
148 mike  1.1 MI_INLINE MI_Result Http_SendErrorResponse(
149               Http* self,
150               void* httpConnectionHanlde,
151               int httpErrorCode)
152           {
153               return Http_SendResponse(self, httpConnectionHanlde, httpErrorCode, 0);
154           }
155           
156           /* Sets http options (mostly unit-test support) */
157           MI_Result Http_SetOptions(
158               Http* self,
159               const HttpOptions* options);
160           
161           END_EXTERNC
162           
163           #endif /* _omi_http_http_h */

ViewCVS 0.9.2