ZenLib
|
00001 00002 #ifndef _HTTP_CLIENT 00003 #define _HTTP_CLIENT 00004 00005 #include "HTTPClientWrapper.h" 00006 #include "HTTPClientCommon.h" 00007 00008 #ifdef __cplusplus 00009 extern "C" { 00010 #endif 00011 00012 /////////////////////////////////////////////////////////////////////////////// 00013 // 00014 // Section : HTTP API global definitions 00015 // Last updated : 01/09/2005 00016 // 00017 /////////////////////////////////////////////////////////////////////////////// 00018 #ifdef _HTTP_BUILD_AMT 00019 #define CMSI_HTTPCLIENT_PROTOCOL_GUID {0x471b2c0e, 0x6137, 0x4d55, 0x92, 0x36, 0xdd, 0x0f, 0xdb, 0xc2, 0x52, 0xfb} 00020 #endif 00021 00022 // Debug hook 00023 // #define _HTTP_DEBUGGING_ // Simply dumps more debugging data to the console 00024 00025 // API Version 00026 #define HTTP_CLIENT_VERSION_MINOR 0 00027 #define HTTP_CLIENT_VERSION_MAJOR 1 00028 00029 // Global default sizes 00030 #define HTTP_CLIENT_MAX_SEND_RECV_HEADERS 1024 // Maximum Send and receive buffers size 00031 #define HTTP_CLIENT_INIT_SEND_RECV_HEADERS 2048 // If we can resize the buffers this would be the initial size 00032 00033 #define HTTP_CLIENT_MAX_USERNAME_LENGTH 16 // Maximum length the user name (host and proxy authentication) 00034 #define HTTP_CLIENT_MAX_PASSWORD_LENGTH 16 // Maximum length for the password 00035 // Maximum length for the base 64 encoded credentials (twice the size of the user name and password max parameters) 00036 #define HTTP_CLIENT_MAX_64_ENCODED_CRED ((HTTP_CLIENT_MAX_USERNAME_LENGTH + HTTP_CLIENT_MAX_PASSWORD_LENGTH) * 2) + 4 00037 #define HTTP_CLIENT_MAX_CHUNK_HEADER 64 // Maximum length for the received chunk header (hex - string) size 00038 #define HTTP_CLIENT_MAX_PROXY_HOST_LENGTH 64 // Maximum length for the proxy host name 00039 #define HTTP_CLIENT_MAX_TOKEN_LENGTH 512 // Maximum length for an HTTP token data (authentication header elements) 00040 #define HTTP_CLIENT_MAX_TOKEN_NAME_LENGTH 32 // Maximum length for an HTTP authorization token name ("qop") 00041 #define HTTP_CLIENT_MAX_HEADER_SEARCH_CLUE 1024 // Maximum length for a search clue string (Headers searching) 00042 #define HTTP_CLIENT_ALLOW_HEAD_VERB 0 // Can we use the HTTP HEAD verb in our outgoing requests? 00043 00044 #define HTTP_CLIENT_MEMORY_RESIZABLE FALSE // Permission to dynamically resize the headers buffer 00045 #define HTTP_CLIENT_MEMORY_RESIZE_FACTOR 16 // Factor for memory resizing operation 00046 00047 #define HTTP_CLIENT_DEFAULT_PORT 80 // Default HTTP port 00048 #define HTTP_CLIENT_DEFAULT_SSL_PORT 443 // Default HTTPS port 00049 #define HTTP_CLIENT_DEFAULT_VERB 0 // GET 00050 #define HTTP_CLIENT_DEFAULT_VER "HTTP/1.1" // We will send this in the outgoing header 00051 #define HTTP_CLIENT_DEFAULT_PROXY_VER "HTTP/1.0" // We will send this in the outgoing header (proxy) 00052 #define HTTP_CLIENT_DEFAULT_AGENT "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)" 00053 #define HTTP_CLIENT_DEFAULT_TIMEOUT 30 // Default timeout in seconds 00054 #define HTTP_CLIENT_DEFAULT_KEEP_ALIVE 30 // Default Keep-alive value in seconds 00055 #define HTTP_CLIENT_DEFAULT_DIGEST_AUTH "MD5" // This is for bypassing a known bug in AMT05.. 00056 #define HTTP_CLIENT_DEFAULT_PROXY_AUTH 1 // Basic 00057 00058 #define HTTP_CLIENT_CRLF "\r\n" // End of line macro 00059 #define HTTP_CLIENT_CRLFX2 "\r\n\r\n" // Double End of line macro 00060 00061 // HTTP Session internal API flags 00062 // Note: Not intended to be set the by the API user 00063 #define HTTP_CLIENT_FLAG_SECURE 0x00000010 // The session is secured using TLS 00064 #define HTTP_CLIENT_FLAG_URLANDPORT 0x00000020 // Url has a port within 00065 #define HTTP_CLIENT_FLAG_URLHTTPS 0x00000040 // Url has a https prefix 00066 #define HTTP_CLIENT_FLAG_USINGPROXY 0x00000080 // Operation will be performed using a proxy server 00067 #define HTTP_CLIENT_FLAG_CHUNKED 0x00000100 // The incoming data is chunked 00068 00069 // HTTP Status codes 00070 #define HTTP_STATUS_OK 200 // The request has succeeded 00071 #define HTTP_STATUS_UNAUTHORIZED 401 // The request requires user authentic 00072 #define HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED 407 // The client must first authenticate itself with the proxy 00073 00074 // Redirection (Note: there are more 30x codes, those are the most popular) 00075 #define HTTP_STATUS_OBJECT_MOVED 302 // Page redirection notification 00076 #define HTTP_STATUS_OBJECT_MOVED_PERMANENTLY 301 // Page redirection notification 00077 #define HTTP_STATUS_CONTINUE 100 // Page continue message 00078 00079 00080 // MIN AMX macro 00081 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 00082 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 00083 // HTTP timeout macro for selecting the default value if the caller passed 0 (no timeout) to the function 00084 #define HTTP_TIMEOUT(nTimeout) (((nTimeout) > (0)) ? (nTimeout) : (HTTP_CLIENT_DEFAULT_TIMEOUT)) 00085 00086 // 32 bit alignment macro 00087 #define ALIGN(size) ((size & 0xfffffffc) + ((size & 3) ? 4 : 0)) 00088 00089 00090 #ifdef _HTTP_DEBUGGING_ 00091 typedef VOID _stdcall E_HTTPDebug(const char *,const char*,UINT32,char *,...); // HTTPDebug hook function 00092 #endif 00093 00094 00095 /////////////////////////////////////////////////////////////////////////////// 00096 // 00097 // Section : HTTP API internals structures 00098 // Last updated : 01/09/2005 00099 // 00100 /////////////////////////////////////////////////////////////////////////////// 00101 00102 // Generic parameter structure contains a pointer to the buffer and its length 00103 00104 typedef struct _HTTP_PARAM 00105 { 00106 00107 CHAR *pParam; 00108 UINT32 nLength; 00109 00110 } HTTP_PARAM; 00111 00112 // HTTP socket events 00113 typedef struct _HTTP_CONNECTION 00114 { 00115 00116 fd_set FDRead; // socket read event 00117 fd_set FDWrite; // socket write event 00118 fd_set FDError; // socket error event 00119 INT32 HttpSocket; // The underling socket 00120 UINT32 HttpStartTime; // Time stamp for the session 00121 UINT32 HttpClientPort; // For client side binding 00122 BOOL TlsNego; // TLS negotiation flag 00123 00124 } HTTP_CONNECTION; 00125 00126 // Request URL 00127 typedef struct _HTTP_URL 00128 { 00129 00130 HTTP_PARAM UrlBsee; // a pointer and length to the "http" section of the URL 00131 HTTP_PARAM UrlHost; // a pointer and length to the host section of the URL 00132 HTTP_PARAM UrlPort; // a pointer and length to the PORT (if was specified section) 00133 HTTP_PARAM UrlRequest; // a pointer and length of the request section of the URL 00134 UINT16 nPort; // the PORT that we should use (could be default or the one found within the URL) 00135 CHAR Url[HTTP_CLIENT_MAX_URL_LENGTH]; // a buffer for the URL 00136 00137 }HTTP_URL; 00138 // HTTP headers (incoming and outgoing) 00139 typedef struct _HTTP_HEADERS 00140 { 00141 00142 HTTP_PARAM HeadersBuffer; // a pointer and length of the complete Headers (in\out) buffer 00143 HTTP_PARAM HeadersOut; // a pointer and length of the outgoing HTTP headers 00144 HTTP_PARAM HeadersIn; // a pointer and length of the incoming headers 00145 HTTP_PARAM HeaderSearch; // Index and pointer for the header search functions 00146 HTTP_VERB HttpVerb; // the HTTP verb that was used in the session 00147 HTTP_VERB HttpLastVerb; // the HTTP verb that was last transmited to the server 00148 CHAR SearchClue[HTTP_CLIENT_MAX_HEADER_SEARCH_CLUE]; 00149 CHAR Verb[16]; // the actual string buffer of the HTTP verb 00150 00151 00152 }HTTP_HEADERS; 00153 00154 // HTTP headers (parsed headers information) 00155 typedef struct _HTTP_HEADERS_INFO 00156 { 00157 HTTP_PARAM HttpRedirectURL; // Stores the redirection URL if we got a 301 or 303 return code 00158 UINT32 nHTTPStatus; // the HTTP status code (200 401 407 act') 00159 UINT32 nHTTPContentLength; // the Content length if specified of the returned data 00160 UINT32 nHTTPPostContentLength;// the Content-Length of the POSTed data (if known) 00161 BOOL Connection; // True = Keep alive or undefined, False = Closed 00162 BOOL ValidHeaders; // a flag that indicates if the incoming header ware parsed OK and found to be valid 00163 BOOL HaveCredentials; // a flag that indicates if we have credentials for the session 00164 CHAR HTTPVersion[16]; // HTTP version string buffer (for example: "HTTP 1.1") 00165 00166 }HTTP_HEADERS_INFO; 00167 00168 // Authentication parameters that ware extracted from the incoming headers 00169 typedef struct _HTTP_AUTH_HEADER 00170 { 00171 00172 HTTP_PARAM AuthHeader; // the pointer and length of the authentication header 00173 UINT32 HTTP_AUTH_SCHEMA; // Its schema (could be any of the supported) 00174 00175 }HTTP_AUTH_HEADER; 00176 // Proxy related data 00177 typedef struct _HTTP_PROXY 00178 { 00179 CHAR ProxyHost[HTTP_CLIENT_MAX_PROXY_HOST_LENGTH]; 00180 CHAR ProxtUser[HTTP_CLIENT_MAX_USERNAME_LENGTH]; 00181 CHAR ProxyPassword[HTTP_CLIENT_MAX_PASSWORD_LENGTH]; 00182 UINT16 nProxyPort; 00183 CHAR AuthSchemaName[16]; // The authentication schema name (for string comperission) 00184 HTTP_AUTH_SCHEMA ProxyAuthSchema; 00185 00186 }HTTP_PROXY; 00187 00188 // HTTP User credentials 00189 typedef struct _HTTP_CREDENTIALS 00190 { 00191 00192 CHAR CredUser[HTTP_CLIENT_MAX_USERNAME_LENGTH]; 00193 CHAR CredPassword[HTTP_CLIENT_MAX_PASSWORD_LENGTH]; 00194 CHAR AuthSchemaName[16]; // The authentication schema name (for string comperission) 00195 HTTP_AUTH_SCHEMA CredAuthSchema; // The schema that calle has selected for the session 00196 BOOL Authentication; // a flag that indicates that this session has requested a user authentication 00197 00198 }HTTP_CREDENTIALS; 00199 // HTTP Counters 00200 typedef struct _HTTP_COUNTERS 00201 { 00202 00203 UINT32 nRecivedHeaderLength; // Bytes count of the incoming header 00204 UINT32 nRecivedBodyLength; // Bytes count of the incoming body length 00205 UINT32 nRecivedChunkLength; // The next chunk length in bytes 00206 UINT32 nBytesToNextChunk; // How many bytes we have to read until we can expect the next chunk 00207 UINT32 nActionStartTime; // Operation start time 00208 UINT32 nActionTimeout; // Timeout for the session 00209 UINT32 nSentChunks; // Count of sent chunks 00210 UINT32 nSentBodyBytes; // Count of body bytes that ware sent 00211 UINT32 nSentHeaderBytes; // Count of header bytes thhat ware sent 00212 00213 }HTTP_COUNTERS; 00214 00215 // HTTP Client Session data 00216 typedef struct _HTTP_REQUEST 00217 { 00218 00219 HTTP_URL HttpUrl; 00220 HTTP_HEADERS HttpHeaders; 00221 HTTP_HEADERS_INFO HttpHeadersInfo; 00222 HTTP_AUTH_HEADER HttpAuthHeader; 00223 HTTP_PROXY HttpProxy; 00224 HTTP_CREDENTIALS HttpCredentials; 00225 HTTP_CONNECTION HttpConnection; 00226 HTTP_COUNTERS HttpCounters; 00227 UINT32 HttpState; 00228 UINT32 HttpFlags; 00229 #ifdef _HTTP_DEBUGGING_ 00230 E_HTTPDebug *pDebug; 00231 #endif 00232 } HTTP_SESSION, *P_HTTP_SESSION; 00233 00234 00235 // HTTP Type Definitions 00236 typedef UINT32 HTTP_SESSION_HANDLE; 00237 typedef UINT32 HTTP_CLIENT_SESSION_FLAGS; 00238 00239 00240 /////////////////////////////////////////////////////////////////////////////// 00241 // 00242 // Section : HTTP API public interface 00243 // Last updated : 01/09/2005 00244 // 00245 /////////////////////////////////////////////////////////////////////////////// 00246 00247 00248 HTTP_SESSION_HANDLE HTTPClientOpenRequest (HTTP_CLIENT_SESSION_FLAGS Flags); 00249 UINT32 HTTPClientCloseRequest (HTTP_SESSION_HANDLE *pSession); 00250 UINT32 HTTPClientSetLocalConnection (HTTP_SESSION_HANDLE pSession, UINT32 nPort); 00251 UINT32 HTTPClientSetAuth (HTTP_SESSION_HANDLE pSession, HTTP_AUTH_SCHEMA AuthSchema, void *pReserved); 00252 UINT32 HTTPClientSetCredentials (HTTP_SESSION_HANDLE pSession, CHAR *pUserName, CHAR *pPassword); 00253 UINT32 HTTPClientSetProxy (HTTP_SESSION_HANDLE pSession, CHAR *pProxyName, UINT16 nPort, CHAR *pUserName, CHAR *pPassword); 00254 UINT32 HTTPClientSetVerb (HTTP_SESSION_HANDLE pSession, HTTP_VERB HttpVerb); 00255 UINT32 HTTPClientAddRequestHeaders (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderName, CHAR *pHeaderData, BOOL nInsert); 00256 UINT32 HTTPClientSendRequest (HTTP_SESSION_HANDLE pSession, CHAR *pUrl, VOID *pData, UINT32 nDataLength, BOOL TotalLength, UINT32 nTimeout,UINT32 nClientPort); 00257 UINT32 HTTPClientWriteData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBufferLength, UINT32 nTimeout); 00258 UINT32 HTTPClientRecvResponse (HTTP_SESSION_HANDLE pSession, UINT32 nTimeout); 00259 UINT32 HTTPClientReadData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBytesToRead, UINT32 nTimeout, UINT32 *nBytesRecived); 00260 UINT32 HTTPClientGetInfo (HTTP_SESSION_HANDLE pSession, HTTP_CLIENT *HTTPClient); 00261 00262 UINT32 HTTPClientFindFirstHeader (HTTP_SESSION_HANDLE pSession, CHAR *pSearchClue,CHAR *pHeaderBuffer, UINT32 *nLength); 00263 UINT32 HTTPClientGetNextHeader (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderBuffer, UINT32 *nLength); 00264 UINT32 HTTPClientFindCloseHeader (HTTP_SESSION_HANDLE pSession); 00265 00266 00267 #ifdef _HTTP_DEBUGGING_ 00268 UINT32 HTTPClientSetDebugHook (HTTP_SESSION_HANDLE pSession,E_HTTPDebug *pDebug); 00269 #endif 00270 00271 00272 /////////////////////////////////////////////////////////////////////////////// 00273 // 00274 // Section : HTTP API private function 00275 // Last updated : 01/09/2005 00276 // 00277 /////////////////////////////////////////////////////////////////////////////// 00278 00279 UINT32 HTTPIntrnResizeBuffer (P_HTTP_SESSION pHTTPSession, UINT32 nNewSize); 00280 UINT32 HTTPIntrnSetURL (P_HTTP_SESSION pHTTPSession, CHAR *pUrl,UINT32 nUrlLength); 00281 UINT32 HTTPIntrnConnectionClose (P_HTTP_SESSION pHTTPSession); 00282 UINT32 HTTPIntrnConnectionOpen (P_HTTP_SESSION pHTTPSession); 00283 UINT32 HTTPIntrnGetRemoteHeaders (P_HTTP_SESSION pHTTPSession); 00284 UINT32 HTTPIntrnGetRemoteChunkLength (P_HTTP_SESSION pHTTPSession); 00285 UINT32 HTTPIntrnSend (P_HTTP_SESSION pHTTPSession, CHAR *pData,UINT32 *nLength); 00286 UINT32 HTTPIntrnRecv (P_HTTP_SESSION pHTTPSession, CHAR *pData,UINT32 *nLength,BOOL PeekOnly); 00287 UINT32 HTTPIntrnParseAuthHeader (P_HTTP_SESSION pHTTPSession); 00288 UINT32 HTTPIntrnAuthHandler (P_HTTP_SESSION pHTTPSession); 00289 UINT32 HTTPIntrnAuthSendDigest (P_HTTP_SESSION pHTTPSession); 00290 UINT32 HTTPIntrnAuthSendBasic (P_HTTP_SESSION pHTTPSession); 00291 UINT32 HTTPIntrnAuthenticate (P_HTTP_SESSION pHTTPSession); 00292 UINT32 HTTPIntrnHeadersAdd (P_HTTP_SESSION pHTTPSession, CHAR *pHeaderName, UINT32 nNameLength, CHAR *pHeaderData, UINT32 nDataLength); 00293 UINT32 HTTPIntrnHeadersRemove (P_HTTP_SESSION pHTTPSession, CHAR *pHeaderName); 00294 UINT32 HTTPIntrnHeadersReceive (P_HTTP_SESSION pHTTPSession, UINT32 nTimeout); 00295 UINT32 HTTPIntrnHeadersSend (P_HTTP_SESSION pHTTPSession, HTTP_VERB HttpVerb); 00296 UINT32 HTTPIntrnHeadersParse (P_HTTP_SESSION pHTTPSession); 00297 UINT32 HTTPIntrnHeadersFind (P_HTTP_SESSION pHTTPSession, CHAR *pHeaderName, HTTP_PARAM *pParam,BOOL IncommingHeaders,UINT32 nOffset); 00298 UINT32 HTTPIntrnSessionReset (P_HTTP_SESSION pHTTPSession, BOOL EntireSession); 00299 UINT32 HTTPIntrnSessionGetUpTime (VOID); 00300 BOOL HTTPIntrnSessionEvalTimeout (P_HTTP_SESSION pHTTPSession); 00301 00302 #ifdef __cplusplus 00303 } 00304 #endif 00305 00306 #endif //_HTTP_CLIENT