chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,335 @@
#ifndef _HTTP_CLIENT
#define _HTTP_CLIENT
#include "HTTPClientWrapper.h"
#include "HTTPClientCommon.h"
#include "HTTPClientPlatform.h"
#ifdef __cplusplus
extern "C" {//}
#endif
///////////////////////////////////////////////////////////////////////////////
//
// Section : HTTP API global definitions
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
#ifdef _HTTP_BUILD_AMT
#define CMSI_HTTPCLIENT_PROTOCOL_GUID {0x471b2c0e, 0x6137, 0x4d55, 0x92, 0x36, 0xdd, 0x0f, 0xdb, 0xc2, 0x52, 0xfb}
#endif
// Debug hook
//#define _HTTP_DEBUGGING_ // Simply dumps more debugging data to the console
// API Version
#define HTTP_CLIENT_VERSION_MINOR 1
#define HTTP_CLIENT_VERSION_MAJOR 1
// Global default sizes
#define HTTP_CLIENT_MAX_SEND_RECV_HEADERS 2048 // Maximum Send and receive buffers size
#define HTTP_CLIENT_INIT_SEND_RECV_HEADERS 1024 // If we can resize the buffers this would be the initial size
#define HTTP_CLIENT_MAX_USERNAME_LENGTH 16 // Maximum length the user name (host and proxy authentication)
#define HTTP_CLIENT_MAX_PASSWORD_LENGTH 16 // Maximum length for the password
// Maximum length for the base 64 encoded credentials (twice the size of the user name and password max parameters)
#define HTTP_CLIENT_MAX_64_ENCODED_CRED ((HTTP_CLIENT_MAX_USERNAME_LENGTH + HTTP_CLIENT_MAX_PASSWORD_LENGTH) * 2) + 4
#define HTTP_CLIENT_MAX_CHUNK_HEADER 64 // Maximum length for the received chunk header (hex - string) size
#define HTTP_CLIENT_MAX_PROXY_HOST_LENGTH 64 // Maximum length for the proxy host name
#define HTTP_CLIENT_MAX_TOKEN_LENGTH 512 // Maximum length for an HTTP token data (authentication header elements)
#define HTTP_CLIENT_MAX_TOKEN_NAME_LENGTH 32 // Maximum length for an HTTP authorization token name ("qop")
#define HTTP_CLIENT_MAX_HEADER_SEARCH_CLUE 1024 // Maximum length for a search clue string (Headers searching)
#define HTTP_CLIENT_ALLOW_HEAD_VERB 1 // Can we use the HTTP HEAD verb in our outgoing requests?
#define HTTP_CLIENT_MEMORY_RESIZABLE TRUE // Permission to dynamically resize the headers buffer
#define HTTP_CLIENT_MEMORY_RESIZE_FACTOR 16 // Factor for memory resizing operation
#define HTTP_CLIENT_DEFAULT_PORT 80 // Default HTTP port
#define HTTP_CLIENT_DEFAULT_SSL_PORT 443 // Default HTTPS port
#define HTTP_CLIENT_DEFAULT_VERB 0 // GET
#define HTTP_CLIENT_DEFAULT_VER "HTTP/1.1" // We will send this in the outgoing header
#define HTTP_CLIENT_DEFAULT_PROXY_VER "HTTP/1.0" // We will send this in the outgoing header (proxy)
//#define HTTP_CLIENT_DEFAULT_AGENT "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"
#define HTTP_CLIENT_DEFAULT_AGENT "IOT CLINET 1.0"
#define HTTP_CLIENT_DEFAULT_TIMEOUT 180 // Default timeout in seconds
#define HTTP_CLIENT_DEFAULT_KEEP_ALIVE 180 // Default Keep-alive value in seconds
#define HTTP_CLIENT_DEFAULT_DIGEST_AUTH "MD5" // This is for bypassing a known bug in AMT05..
#define HTTP_CLIENT_DEFAULT_PROXY_AUTH 1 // Basic
#define HTTP_CLIENT_CRLF "\r\n" // End of line macro
#define HTTP_CLIENT_CRLFX2 "\r\n\r\n" // Double End of line macro
// HTTP Session internal API flags
// Note: Not intended to be set the by the API user
#define HTTP_CLIENT_FLAG_SECURE 0x00000010 // The session is secured using TLS
#define HTTP_CLIENT_FLAG_URLANDPORT 0x00000020 // Url has a port within
#define HTTP_CLIENT_FLAG_URLHTTPS 0x00000040 // Url has a https prefix
#define HTTP_CLIENT_FLAG_USINGPROXY 0x00000080 // Operation will be performed using a proxy server
#define HTTP_CLIENT_FLAG_CHUNKED 0x00000100 // The incoming data is chunked
// HTTP Status codes
#define HTTP_STATUS_OK 200 // The request has succeeded
#define HTTP_STATUS_UNAUTHORIZED 401 // The request requires user authentic
#define HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED 407 // The client must first authenticate itself with the proxy
// Redirection (Note: there are more 30x codes, those are the most popular)
#define HTTP_STATUS_OBJECT_MOVED 302 // Page redirection notification
#define HTTP_STATUS_OBJECT_MOVED_PERMANENTLY 301 // Page redirection notification
#define HTTP_STATUS_CONTINUE 100 // Page continue message
// MIN AMX macro
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
// HTTP timeout macro for selecting the default value if the caller passed 0 (no timeout) to the function
#define HTTP_TIMEOUT(nTimeout) (((nTimeout) > (0)) ? (nTimeout) : (HTTP_CLIENT_DEFAULT_TIMEOUT))
// 32 bit alignment macro
#define ALIGN(size) ((size & 0xfffffffc) + ((size & 3) ? 4 : 0))
#ifdef _HTTP_DEBUGGING_
// typedef VOID _stdcall E_HTTPDebug(const char *,const char*,UINT32,char *,...); // HTTPDebug hook function
typedef VOID E_HTTPDebug(const char *,const char*,UINT32,char *,...);
#endif
///////////////////////////////////////////////////////////////////////////////
//
// Section : HTTP API internals structures
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
// Generic parameter structure contains a pointer to the buffer and its length
typedef struct _HTTP_PARAM
{
CHAR *pParam;
UINT32 nLength;
} HTTP_PARAM;
// HTTP socket events
typedef struct _HTTP_CONNECTION
{
fd_set FDRead; // socket read event
fd_set FDWrite; // socket write event
fd_set FDError; // socket error event
INT32 HttpSocket; // The underling socket
UINT32 HttpStartTime; // Time stamp for the session
UINT32 HttpClientPort; // For client side binding
BOOL TlsNego; // TLS negotiation flag
} HTTP_CONNECTION;
// Request URL
typedef struct _HTTP_URL
{
HTTP_PARAM UrlBsee; // a pointer and length to the "http" section of the URL
HTTP_PARAM UrlHost; // a pointer and length to the host section of the URL
HTTP_PARAM UrlPort; // a pointer and length to the PORT (if was specified section)
HTTP_PARAM UrlRequest; // a pointer and length of the request section of the URL
UINT16 nPort; // the PORT that we should use (could be default or the one found within the URL)
CHAR Url[HTTP_CLIENT_MAX_URL_LENGTH]; // a buffer for the URL
}HTTP_URL;
// HTTP headers (incoming and outgoing)
typedef struct _HTTP_HEADERS
{
HTTP_PARAM HeadersBuffer; // a pointer and length of the complete Headers (in\out) buffer
HTTP_PARAM HeadersOut; // a pointer and length of the outgoing HTTP headers
HTTP_PARAM HeadersIn; // a pointer and length of the incoming headers
HTTP_PARAM HeaderSearch; // Index and pointer for the header search functions
HTTP_VERB HttpVerb; // the HTTP verb that was used in the session
HTTP_VERB HttpLastVerb; // the HTTP verb that was last transmited to the server
CHAR SearchClue[HTTP_CLIENT_MAX_HEADER_SEARCH_CLUE];
CHAR Verb[16]; // the actual string buffer of the HTTP verb
}HTTP_HEADERS;
// HTTP headers (parsed headers information)
typedef struct _HTTP_HEADERS_INFO
{
HTTP_PARAM HttpRedirectURL; // Stores the redirection URL if we got a 301 or 303 return code
UINT32 nHTTPStatus; // the HTTP status code (200 401 407 act')
UINT32 nHTTPContentLength; // the Content length if specified of the returned data
UINT32 nHTTPPostContentLength;// the Content-Length of the POSTed data (if known)
BOOL Connection; // True = Keep alive or undefined, False = Closed
BOOL ValidHeaders; // a flag that indicates if the incoming header ware parsed OK and found to be valid
BOOL HaveCredentials; // a flag that indicates if we have credentials for the session
CHAR HTTPVersion[16]; // HTTP version string buffer (for example: "HTTP 1.1")
}HTTP_HEADERS_INFO;
// Authentication parameters that ware extracted from the incoming headers
typedef struct _HTTP_AUTH_HEADER
{
HTTP_PARAM AuthHeader; // the pointer and length of the authentication header
UINT32 HTTP_AUTH_SCHEMA; // Its schema (could be any of the supported)
}HTTP_AUTH_HEADER;
#ifdef HTTPC_PROXY
// Proxy related data
typedef struct _HTTP_PROXY
{
CHAR ProxyHost[HTTP_CLIENT_MAX_PROXY_HOST_LENGTH];
CHAR ProxtUser[HTTP_CLIENT_MAX_USERNAME_LENGTH];
CHAR ProxyPassword[HTTP_CLIENT_MAX_PASSWORD_LENGTH];
UINT16 nProxyPort;
CHAR AuthSchemaName[16]; // The authentication schema name (for string comperission)
HTTP_AUTH_SCHEMA ProxyAuthSchema;
}HTTP_PROXY;
#endif
// HTTP User credentials
typedef struct _HTTP_CREDENTIALS
{
CHAR CredUser[HTTP_CLIENT_MAX_USERNAME_LENGTH];
CHAR CredPassword[HTTP_CLIENT_MAX_PASSWORD_LENGTH];
CHAR AuthSchemaName[16]; // The authentication schema name (for string comperission)
HTTP_AUTH_SCHEMA CredAuthSchema; // The schema that calle has selected for the session
BOOL Authentication; // a flag that indicates that this session has requested a user authentication
#ifdef HTTPC_SEND_TOGTHER
HTTP_PARAM ToSendAuthInfo;
#endif
}HTTP_CREDENTIALS;
// HTTP Counters
typedef struct _HTTP_COUNTERS
{
UINT32 nRecivedHeaderLength; // Bytes count of the incoming header
UINT32 nRecivedBodyLength; // Bytes count of the incoming body length
UINT32 nRecivedChunkLength; // The next chunk length in bytes
UINT32 nBytesToNextChunk; // How many bytes we have to read until we can expect the next chunk
UINT32 nActionStartTime; // Operation start time
UINT32 nActionTimeout; // Timeout for the session
UINT32 nSentChunks; // Count of sent chunks
UINT32 nSentBodyBytes; // Count of body bytes that ware sent
UINT32 nSentHeaderBytes; // Count of header bytes thhat ware sent
}HTTP_COUNTERS;
// HTTP Client Session data
typedef struct _HTTP_REQUEST
{
HTTP_URL HttpUrl;
HTTP_HEADERS HttpHeaders;
HTTP_HEADERS_INFO HttpHeadersInfo;
HTTP_AUTH_HEADER HttpAuthHeader;
#ifdef HTTPC_PROXY
HTTP_PROXY HttpProxy;
#endif
HTTP_CREDENTIALS HttpCredentials;
HTTP_CONNECTION HttpConnection;
HTTP_COUNTERS HttpCounters;
UINT32 HttpState;
UINT32 HttpFlags;
#ifdef _HTTP_DEBUGGING_
E_HTTPDebug *pDebug;
#endif
HTTP_SSL HttpSSL;
} HTTP_SESSION, *P_HTTP_SESSION;
// HTTP Type Definitions
typedef UINT32 HTTP_SESSION_HANDLE;
typedef UINT32 HTTP_CLIENT_SESSION_FLAGS;
typedef struct _PostData
{
VOID *pData;
INT32 pLength;
} PostData;
typedef void* (*HTTP_CLIENT_GET_HEADER)();
typedef PostData (*HTTP_CLIENT_GET_POST_DATA)();
typedef struct HTTP_CLIENT_CALLBACK_FUNC {
void *ClientParams;
HTTP_CLIENT_GET_HEADER HttpcGetHeader;
HTTP_CLIENT_GET_POST_DATA HttpcGetPostData;
} HTTP_CLIENT_CALLBACK_FUNC;
///////////////////////////////////////////////////////////////////////////////
//
// Section : HTTP API public interface
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
HTTP_SESSION_HANDLE HTTPClientOpenRequest (HTTP_CLIENT_SESSION_FLAGS Flags);
UINT32 HTTPClientCloseRequest (HTTP_SESSION_HANDLE *pSession);
UINT32 HTTPClientSetLocalConnection (HTTP_SESSION_HANDLE pSession, UINT32 nPort);
UINT32 HTTPClientSetAuth (HTTP_SESSION_HANDLE pSession, HTTP_AUTH_SCHEMA AuthSchema, void *pReserved);
UINT32 HTTPClientSetCredentials (HTTP_SESSION_HANDLE pSession, CHAR *pUserName, CHAR *pPassword);
UINT32 HTTPClientSetProxy (HTTP_SESSION_HANDLE pSession, CHAR *pProxyName, UINT16 nPort, CHAR *pUserName, CHAR *pPassword);
UINT32 HTTPClientSetVerb (HTTP_SESSION_HANDLE pSession, HTTP_VERB HttpVerb);
UINT32 HTTPClientAddRequestHeaders (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderName, CHAR *pHeaderData, BOOL nInsert);
UINT32 HTTPClientSendRequest (HTTP_SESSION_HANDLE pSession, CHAR *pUrl, VOID *pData, UINT32 nDataLength, BOOL TotalLength, UINT32 nTimeout, UINT32 nClientPort, HTTP_CLIENT_GET_HEADER GetHeader, HTTP_CLIENT_GET_POST_DATA GetPostData);
UINT32 HTTPClientWriteData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBufferLength, UINT32 nTimeout);
UINT32 HTTPClientRecvResponse (HTTP_SESSION_HANDLE pSession, UINT32 nTimeout);
UINT32 HTTPClientReadData (HTTP_SESSION_HANDLE pSession, VOID *pBuffer, UINT32 nBytesToRead, UINT32 nTimeout, UINT32 *nBytesRecived);
UINT32 HTTPClientGetInfo (HTTP_SESSION_HANDLE pSession, HTTP_CLIENT *HTTPClient);
UINT32 HTTPClientFindFirstHeader (HTTP_SESSION_HANDLE pSession, CHAR *pSearchClue,CHAR *pHeaderBuffer, UINT32 *nLength);
UINT32 HTTPClientGetNextHeader (HTTP_SESSION_HANDLE pSession, CHAR *pHeaderBuffer, UINT32 *nLength);
UINT32 HTTPClientFindCloseHeader (HTTP_SESSION_HANDLE pSession);
UINT32 HTTPClientReset (HTTP_SESSION_HANDLE pSession);
#ifdef _HTTP_DEBUGGING_
UINT32 HTTPClientSetDebugHook (HTTP_SESSION_HANDLE pSession,E_HTTPDebug *pDebug);
#endif
///////////////////////////////////////////////////////////////////////////////
//
// Section : HTTP API private function
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
UINT32 HTTPIntrnResizeBuffer (P_HTTP_SESSION pHTTPSession, UINT32 nNewSize);
UINT32 HTTPIntrnSetURL (P_HTTP_SESSION pHTTPSession, CHAR *pUrl,UINT32 nUrlLength);
UINT32 HTTPIntrnConnectionClose (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnConnectionOpen (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnGetRemoteHeaders (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnGetRemoteChunkLength (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnSend (P_HTTP_SESSION pHTTPSession, CHAR *pData,UINT32 *nLength);
UINT32 HTTPIntrnRecv (P_HTTP_SESSION pHTTPSession, CHAR *pData,UINT32 *nLength,BOOL PeekOnly);
UINT32 HTTPIntrnParseAuthHeader (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnAuthHandler (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnAuthSendDigest (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnAuthSendBasic (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnAuthenticate (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnHeadersAdd (P_HTTP_SESSION pHTTPSession, CHAR *pHeaderName, UINT32 nNameLength, CHAR *pHeaderData, UINT32 nDataLength);
UINT32 HTTPIntrnHeadersRemove (P_HTTP_SESSION pHTTPSession, CHAR *pHeaderName);
UINT32 HTTPIntrnHeadersReceive (P_HTTP_SESSION pHTTPSession, UINT32 nTimeout);
UINT32 HTTPIntrnHeadersSend (P_HTTP_SESSION pHTTPSession, HTTP_VERB HttpVerb);
UINT32 HTTPIntrnHeadersParse (P_HTTP_SESSION pHTTPSession);
UINT32 HTTPIntrnHeadersFind (P_HTTP_SESSION pHTTPSession, CHAR *pHeaderName, HTTP_PARAM *pParam,BOOL IncommingHeaders,UINT32 nOffset);
UINT32 HTTPIntrnSessionReset (P_HTTP_SESSION pHTTPSession, BOOL EntireSession);
UINT32 HTTPIntrnSessionGetUpTime (VOID);
BOOL HTTPIntrnSessionEvalTimeout (P_HTTP_SESSION pHTTPSession);
#ifdef __cplusplus
}
#endif
#endif //_HTTP_CLIENT

View File

@@ -0,0 +1,90 @@
#ifndef HTTP_CLIENT_AUTH_H
#define HTTP_CLIENT_AUTH_H
#include "HTTPClientWrapper.h" // Cross platform support
#define HASHLEN 16
#define HASHHEXLEN 32
#define IN
#define OUT
typedef char HASH[HASHLEN];
typedef char HASHHEX[HASHHEXLEN+1];
typedef unsigned long uint32;
// Base 64 Related
#define DECODE64(c) (isascii(c) ? base64val[c] : BAD)
#define BAD -1
static const char base64digits[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char base64val[] = {
BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD, BAD,BAD,BAD,BAD,
BAD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,BAD, BAD,BAD,BAD,BAD,
BAD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,BAD, BAD,BAD,BAD,BAD
};
void HTTPBase64Encoder(unsigned char *out, const unsigned char *in, int inlen);
int HTTPBase64Decoder(char *out, const char *in);
// Digest Related
// Generates a 32 byte random hexadecimal string such as "4f6ba982..."
void HTTPDigestGenerateCNonce(char *outbuff);
// Calculate H(A1) as per HTTP Digest spec
void HTTPDigestCalcHA1(
IN int nAlg, /* 0 = MD5, 1 = MD5-Sess */
IN char * pszUserName,
IN char * pszRealm,
IN int nRealmLength,
IN char * pszPassword,
IN char * pszNonce,
IN int nNonceLength,
IN char * pszCNonce,
OUT HASHHEX SessionKey
);
// Calculate request-digest/response-digest as per HTTP Digest spec
void HTTPDigestCalcResponse(
IN HASHHEX HA1, // H(A1)
IN char * pszNonce, // nonce from server
IN int nNonceLength, // Length of nonce
IN char * pszNonceCount, // 8 hex digits
IN char * pszCNonce, // client nonce
IN char * pszQop, // qop-value: "", "auth", "auth-int"
IN int nQopLength, // qop param length
IN char * pszMethod, // method from the request
IN char * pszDigestUri, // requested URL
IN int nDigestUriLebgth, // Uri Length
IN HASHHEX HEntity, // H(entity body) if qop="auth-int"
OUT HASHHEX Response // request-digest or response-digest
);
// MD5 structures and functions
struct MD5Context
{
uint32 buf[4];
uint32 bits[2];
unsigned char in[64];
};
void HTTPMD5Init (struct MD5Context *context);
void HTTPMD5Update (struct MD5Context *context, unsigned char const *buf,unsigned len);
void HTTPMD5Final (unsigned char digest[16], struct MD5Context *context);
void HTTPMD5Transform (uint32 buf[4], uint32 const in[16]);
// This is needed to make RSAREF happy on some MS-DOS compilers.
typedef struct MD5Context MD5_CTX;
#endif

View File

@@ -0,0 +1,132 @@
///////////////////////////////////////////////////////////////////////////////
//
// Module Name:
// CmsiHTTPClientCommon.h
//
// Abstract: Coomon structs and types for the HTTP protocol API
// Author: Eitan Michaelso
// Version: 1.0
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _HTTPCLIENT_PROTOCOL_H_
#define _HTTPCLIENT_PROTOCOL_H_
#ifdef __cplusplus
extern "C" {
#endif
// Global default sizes
#define HTTP_CLIENT_MAX_URL_LENGTH 512 // Maximum length for an HTTP Url parameter
#define HTTP_CLIENT_CALLBACK_FUNC_MAX_SIZE (5)
// HTTP Session flags (Public flags)
#define HTTP_CLIENT_FLAG_KEEP_ALIVE 0x00000001 // Set the keep alive header
#define HTTP_CLIENT_FLAG_SEND_CHUNKED 0x00000002 // The outgoing should chunked
#define HTTP_CLIENT_FLAG_NO_CACHE 0x00000004 // Set the no cache header
#define HTTP_CLIENT_FLAG_ASYNC 0x00000008 // Currently not implemented
#define HTTP_CLIENT_FLAG_HEADER_EXTENSION 0x10000000 // Currently not implemented
// HTTP status internal flags
#define HTTP_CLIENT_STATE_PRE_INIT 0x00000000 // Starting stage
#define HTTP_CLIENT_STATE_INIT 0x00000001 // API was initialized (memory was allocated)
#define HTTP_CLIENT_STATE_URL_PARSED 0x00000002 // Url was parsed
#define HTTP_CLIENT_STATE_HOST_CONNECTED 0x00000004 // HEAD verb was sent
#define HTTP_CLIENT_STATE_HEAD_SENT 0x00000008 // Post verb was sent
#define HTTP_CLIENT_STATE_POST_SENT 0x00000010 // HTTP requet was sent
#define HTTP_CLIENT_STATE_REQUEST_SENT 0x00000020 // HTTP request was sent
#define HTTP_CLIENT_STATE_HEADERS_RECIVED 0x00000040 // Headers ware recived from the server
#define HTTP_CLIENT_STATE_HEADERS_PARSED 0x00000080 // HTTP headers ware parsed
#define HTTP_CLIENT_STATE_HEADERS_OK 0x00000100 // Headers status was OK
// HTTP Return codes
#define HTTP_CLIENT_SUCCESS 0 // HTTP Success status
#define HTTP_CLIENT_UNKNOWN_ERROR 1 // Unknown error
#define HTTP_CLIENT_ERROR_INVALID_HANDLE 2 // an Invalid handle or possible bad pointer was passed to a function
#define HTTP_CLIENT_ERROR_NO_MEMORY 3 // Buffer too small or a failure while in memory allocation
#define HTTP_CLIENT_ERROR_SOCKET_INVALID 4 // an attempt to use an invalid socket handle was made
#define HTTP_CLIENT_ERROR_SOCKET_CANT_SET 5 // Can't send socket parameters
#define HTTP_CLIENT_ERROR_SOCKET_RESOLVE 6 // Error while resolving host name
#define HTTP_CLIENT_ERROR_SOCKET_CONNECT 7 // Error while connecting to the remote server
#define HTTP_CLIENT_ERROR_SOCKET_TIME_OUT 8 // socket time out error
#define HTTP_CLIENT_ERROR_SOCKET_RECV 9 // Error while receiving data
#define HTTP_CLIENT_ERROR_SOCKET_SEND 10 // Error while sending data
#define HTTP_CLIENT_ERROR_HEADER_RECV 11 // Error while receiving the remote HTTP headers
#define HTTP_CLIENT_ERROR_HEADER_NOT_FOUND 12 // Could not find element within header
#define HTTP_CLIENT_ERROR_HEADER_BIG_CLUE 13 // The headers search clue was too large for the internal API buffer
#define HTTP_CLIENT_ERROR_HEADER_NO_LENGTH 14 // No content length was specified for the outgoing data. the caller should specify chunking mode in the session creation
#define HTTP_CLIENT_ERROR_CHUNK_TOO_BIG 15 // The HTTP chunk token that was received from the server was too big and possibly wrong
#define HTTP_CLIENT_ERROR_AUTH_HOST 16 // Could not authenticate with the remote host
#define HTTP_CLIENT_ERROR_AUTH_PROXY 17 // Could not authenticate with the remote proxy
#define HTTP_CLIENT_ERROR_BAD_VERB 18 // Bad or not supported HTTP verb was passed to a function
#define HTTP_CLIENT_ERROR_LONG_INPUT 19 // a function received a parameter that was too large
#define HTTP_CLIENT_ERROR_BAD_STATE 20 // The session state prevents the current function from proceeding
#define HTTP_CLIENT_ERROR_CHUNK 21 // Could not parse the chunk length while in chunked transfer
#define HTTP_CLIENT_ERROR_BAD_URL 22 // Could not parse curtail elements from the URL (such as the host name, HTTP prefix act')
#define HTTP_CLIENT_ERROR_BAD_HEADER 23 // Could not detect key elements in the received headers
#define HTTP_CLIENT_ERROR_BUFFER_RSIZE 24 // Error while attempting to resize a buffer
#define HTTP_CLIENT_ERROR_BAD_AUTH 25 // Authentication schema is not supported
#define HTTP_CLIENT_ERROR_AUTH_MISMATCH 26 // The selected authentication schema does not match the server response
#define HTTP_CLIENT_ERROR_NO_DIGEST_TOKEN 27 // an element was missing while parsing the digest authentication challenge
#define HTTP_CLIENT_ERROR_NO_DIGEST_ALG 28 // Digest algorithem could be MD5 or MD5-sess other types are not supported
#define HTTP_CLIENT_ERROR_SOCKET_BIND 29 // Binding error
#define HTTP_CLIENT_ERROR_TLS_NEGO 30 // Tls negotiation error
#define HTTP_CLIENT_ERROR_NOT_IMPLEMENTED 64 // Feature is not (yet) implemented
#define HTTP_CLIENT_EOS 1000 // HTTP end of stream message
///////////////////////////////////////////////////////////////////////////////
//
// Section : HTTP API structures
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
// HTTP Supported authentication methods
typedef enum _HTTP_AUTH_SCHEMA
{
AuthSchemaNone = 0,
AuthSchemaBasic,
AuthSchemaDigest,
AuthSchemaKerberos,
AuthNotSupported
} HTTP_AUTH_SCHEMA;
// HTTP supported verbs
typedef enum _HTTP_VERB
{
VerbGet = 0,
VerbHead,
VerbPost,
VerbNotSupported
// Note: others verb such as connect and put are currently not supported
} HTTP_VERB;
#ifdef HTTP_GET_REDIRECT_URL
typedef struct _HTTP_REDIRECT_PARAM
{
CHAR *pParam;
UINT32 nLength;
} HTTP_REDIRECT_PARAM;
#endif
// Data structure that the caller can request at any time that will include some information regarding the session
typedef struct _HTTP_CLIENT
{
UINT32 HTTPStatusCode; // HTTP Status code (200 OK)
UINT32 RequestBodyLengthSent; // Total bytes sent (body only)
UINT32 ResponseBodyLengthReceived; // Total bytes received (body only)
UINT32 TotalResponseBodyLength; // as extracted from the content-length" header
UINT32 HttpState;
#ifdef HTTP_GET_REDIRECT_URL
HTTP_REDIRECT_PARAM *RedirectUrl;
#endif
#ifdef HTTP_GET_HANDLE_FLAGS
UINT32 HttpFlags;
#endif
} HTTP_CLIENT;
#endif // _HTTPCLIENT_PROTOCOL_H_

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 XRADIO TECHNOLOGY CO., LTD. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of XRADIO TECHNOLOGY CO., LTD. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HTTPCLIENTPLATFORM_H
#define __HTTPCLIENTPLATFORM_H
#include "sysheap.h"
#define HTTPC_MALLOC(l) psram_malloc(l)
#define HTTPC_FREE(p) psram_free(p)
#endif

View File

@@ -0,0 +1,23 @@
#ifndef _HTTP_CLIENT_STRING
#define _HTTP_CLIENT_STRING
#include "HTTPClientWrapper.h" // Cross platform support
#include "HTTPClient.h"
///////////////////////////////////////////////////////////////////////////////
//
// Section : HTTP Api global definitions
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
BOOL HTTPStrInsensitiveCompare (CHAR *pSrc, CHAR* pDest, UINT32 nLength);
BOOL HTTPStrSearch (CHAR *pSrc, CHAR *pSearched, UINT32 nOffset, UINT32 nScope,HTTP_PARAM *HttpParam);
CHAR HTTPStrExtract (CHAR *pParam,UINT32 nOffset,CHAR Restore);
CHAR* HTTPStrCaseStr (CHAR *pSrc, UINT32 nSrcLength, CHAR *pFind);
CHAR* HTTPStrGetToken (CHAR *pSrc, UINT32 nSrcLength, CHAR *pDest, UINT32 *nDestLength);
UINT32 HTTPStrGetDigestToken (HTTP_PARAM pParamSrc, CHAR *pSearched, HTTP_PARAM *pParamDest);
UINT32 HTTPStrHToL (CHAR * s);
CHAR* HTTPStrLToH (CHAR * dest,UINT32 nSrc);
#endif

View File

@@ -0,0 +1,191 @@
#ifndef HTTP_CLIENT_WRAPPER
#define HTTP_CLIENT_WRAPPER
///////////////////////////////////////////////////////////////////////////////
//
// Section : Microsoft Windows Support
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
#pragma warning (disable: 4996) // 'function': was declared deprecated (VS 2005)
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <winsock.h>
// Sockets (Winsock wrapper)
#define HTTP_ECONNRESET (WSAECONNRESET)
#define HTTP_EINPROGRESS (WSAEINPROGRESS)
#define HTTP_EWOULDBLOCK (WSAEWOULDBLOCK)
// Kluge alert: redefining strncasecmp() as memicmp() for Windows.
//
#define strncasecmp memicmp
#define strcasecmp stricmp
#elif defined _LINUX // Non Win32 : GCC Linux
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <stdarg.h>
#define SOCKET_ERROR -1
#define HTTP_EINPROGRESS (EINPROGRESS)
#define HTTP_EWOULDBLOCK (EWOULDBLOCK)
typedef unsigned long UINT32;
typedef long INT32;
#else
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "lwip/sockets.h"
// #include "lwip/netdb.h"
// #include <errno.h>
#include <stdarg.h>
#include "debug.h"
#include "ze_tls.h"
#define SOCKET_ERROR -1
#define HTTP_EINPROGRESS (EINPROGRESS)
#define HTTP_EWOULDBLOCK (EWOULDBLOCK)
// #define HTTPC_SSL
// Generic types
typedef unsigned long UINT32;
typedef long INT32;
#ifndef BOOL
#define BOOL int
#endif
#define HTTPC_ERRNO errno
#define HTTPC_AUTH_CLOSE_CONNEC
#define HTTPC_LWIP
#define HTTPC_LITTLE_STACK
#define HTTPC_SEND_TOGTHER // send http request header together, this will malloc an additional buffer
#define HTTP_GET_REDIRECT_URL
#define HTTP_GET_HANDLE_FLAGS
#endif
// Note: define this to prevent timeouts while debugging.
// #define NO_TIMEOUTS
///////////////////////////////////////////////////////////////////////////////
//
// Section : Functions that are not supported by the AMT stdc framework
// So they had to be specificaly added.
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _HTTP_SSL
{
security_client m_client_param;
mbedtls_context *m_context;
mbedtls_sock m_httpc_net_fd;
} HTTP_SSL;
// STDC Wrapper implimentation
int HTTPWrapperIsAscii (int c);
int HTTPWrapperToUpper (int c);
int HTTPWrapperToLower (int c);
int HTTPWrapperIsAlpha (int c);
int HTTPWrapperIsAlNum (int c);
char* HTTPWrapperItoa (char *buff,int i);
void HTTPWrapperInitRandomeNumber ();
long HTTPWrapperGetUpTime ();
int HTTPWrapperGetRandomeNumber ();
int HTTPWrapperGetSocketError (int s);
unsigned long HTTPWrapperGetHostByName (char *name,unsigned long *address);
int HTTPWrapperShutDown (int s,int in);
// SSL Wrapper prototypes
int HTTPWrapperSSLConnect (HTTP_SSL *handle, int s,const struct sockaddr *name,int namelen,char *hostname);
int HTTPWrapperSSLNegotiate (HTTP_SSL *handle, int s,const struct sockaddr *name,int namelen,char *hostname);
int HTTPWrapperSSLSend (HTTP_SSL *handle, int s,char *buf, int len,int flags);
int HTTPWrapperSSLRecv (HTTP_SSL *handle, int s,char *buf, int len,int flags);
int HTTPWrapperSSLClose (HTTP_SSL *handle, int s);
int HTTPWrapperSSLRecvPending (HTTP_SSL *handle, int s);
void HTTPWrapperSSLSetRecvTimeout (HTTP_SSL *handle, int s);
typedef void* (*HTTPC_USR_CERTS)(void);
void* HTTPC_obtain_user_certs();
void HTTPC_set_ssl_verify_mode(unsigned char mode);
unsigned char HTTPC_get_ssl_verify_mode();
// Global wrapper Functions
#define IToA HTTPWrapperItoa
#define GetUpTime HTTPWrapperGetUpTime
#define SocketGetErr HTTPWrapperGetSocketError
#define HostByName HTTPWrapperGetHostByName
#define InitRandomeNumber HTTPWrapperInitRandomeNumber
#define GetRandomeNumber HTTPWrapperGetRandomeNumber
#ifdef __cplusplus
}
#endif
///////////////////////////////////////////////////////////////////////////////
//
// Section : Global type definitions
// Last updated : 01/09/2005
//
///////////////////////////////////////////////////////////////////////////////
#define VOID void
#ifndef NULL
#define NULL 0
#endif
#define TRUE 1
#define FALSE 0
typedef char CHAR;
typedef unsigned short UINT16;
//typedef int BOOL;
//typedef unsigned long ULONG;
// Global socket structures and definitions
#define HTTP_INVALID_SOCKET (-1)
typedef struct sockaddr_in HTTP_SOCKADDR_IN;
typedef struct timeval HTTP_TIMEVAL;
typedef struct hostent HTTP_HOSTNET;
typedef struct sockaddr HTTP_SOCKADDR;
typedef struct in_addr HTTP_INADDR;
#endif // HTTP_CLIENT_WRAPPER

View File

@@ -0,0 +1,20 @@
#ifndef __HTTPC_H_H
#define __HTTPC_H_H
#include "HTTPClientWrapper.h"
//#define _HTTP_DEBUGGING_
// #define HTTPCLIENT_DEBUG
#define HC_LOGD(fmt, arg...) logDbg("[HTTPC]"fmt"\n", ##arg)
#define HC_LOGE(fmt, arg...) logDbg("[HTTPC][ERR]"fmt"\n", ##arg)
#ifdef HTTPCLIENT_DEBUG
#define HC_DBG(x) do { HC_LOGD x; } while (0)
#else
#define HC_DBG(x) do { } while (0)
#endif /* HTTPCLIENT_DEBUG */
#define HC_ERR(x) do { HC_LOGE x; } while (0)
#endif /* __HTTPC_H_H */