BG
This commit is contained in:
278
hpsocket/GlobalDef.h
Normal file
278
hpsocket/GlobalDef.h
Normal file
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
|
||||
*
|
||||
* Author : Bruce Liang
|
||||
* Website : https://github.com/ldcsaa
|
||||
* Project : https://github.com/ldcsaa/HP-Socket
|
||||
* Blog : http://www.cnblogs.com/ldcsaa
|
||||
* Wiki : http://www.oschina.net/p/hp-socket
|
||||
* QQ Group : 44636872, 75375912
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef int BOOL;
|
||||
typedef float FLOAT;
|
||||
typedef FLOAT *PFLOAT, *LPFLOAT;
|
||||
typedef double DOUBLE;
|
||||
typedef DOUBLE *PDOUBLE, *LPDOUBLE;
|
||||
typedef short SHORT, INT16;
|
||||
typedef SHORT *PSHORT, *LPSHORT;
|
||||
typedef unsigned short USHORT, UINT16;
|
||||
typedef USHORT *PUSHORT, *LPUSHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef WORD *PWORD, *LPWORD;
|
||||
typedef unsigned int DWORD;
|
||||
typedef DWORD *PDWORD, *LPDWORD;
|
||||
typedef long LONG, LID;
|
||||
typedef LONG *PLONG, *LPLONG;
|
||||
typedef unsigned long ULONG, ULID;
|
||||
typedef ULONG *PULONG, *LPULONG;
|
||||
typedef long long LONGLONG, LLONG, INT64;
|
||||
typedef LONGLONG *PLONGLONG, *LPLONGLONG, *PLLONG, *LPLLONG;
|
||||
typedef unsigned long long ULONGLONG, ULLONG, UINT64;
|
||||
typedef ULONGLONG *PULONGLONG, *LPULONGLONG, *PULLONG, *LPULLONG;
|
||||
typedef int INT, IID, INT32;
|
||||
typedef INT *PINT, *LPINT;
|
||||
typedef unsigned int UINT, UIID, UINT32;
|
||||
typedef UINT *PUINT, *LPUINT;
|
||||
typedef void VOID;
|
||||
typedef VOID *PVOID, *LPVOID;
|
||||
typedef char CHAR, INT8;
|
||||
typedef CHAR *PCHAR, *LPCHAR, *PSTR, *LPSTR;
|
||||
typedef const char *PCSTR, *LPCSTR;
|
||||
typedef unsigned char BYTE, UINT8;
|
||||
typedef BYTE *PBYTE, *LPBYTE;
|
||||
typedef const BYTE *PCBYTE, *LPCBYTE;
|
||||
typedef wchar_t WCHAR;
|
||||
typedef WCHAR *PWSTR, *LPWSTR;
|
||||
typedef const WCHAR *PCWSTR, *LPCWSTR;
|
||||
typedef LONG INT_PTR, LONG_PTR, LPARAM;
|
||||
typedef ULONG UINT_PTR, ULONG_PTR, DWORD_PTR, WPARAM;
|
||||
|
||||
typedef IID FD, HANDLE, SOCKET;
|
||||
typedef INT LRESULT, HRESULT;
|
||||
|
||||
typedef LLONG __time64_t;
|
||||
typedef INT __time32_t;
|
||||
|
||||
typedef LID NTHR_ID;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
typedef LID THR_ID;
|
||||
#else
|
||||
typedef ULID THR_ID;
|
||||
#endif
|
||||
|
||||
typedef size_t SIZE_T;
|
||||
typedef ssize_t SSIZE_T;
|
||||
|
||||
#ifdef _UNICODE
|
||||
typedef WCHAR TCHAR;
|
||||
#else
|
||||
typedef CHAR TCHAR;
|
||||
#endif
|
||||
|
||||
typedef TCHAR *PTSTR, *LPTSTR;
|
||||
typedef const TCHAR *PCTSTR, *LPCTSTR;
|
||||
|
||||
#define MAXUINT8 ((UINT8)~((UINT8)0))
|
||||
#define MAXINT8 ((INT8)(MAXUINT8 >> 1))
|
||||
#define MININT8 ((INT8)~MAXINT8)
|
||||
|
||||
#define MAXUINT16 ((UINT16)~((UINT16)0))
|
||||
#define MAXINT16 ((INT16)(MAXUINT16 >> 1))
|
||||
#define MININT16 ((INT16)~MAXINT16)
|
||||
|
||||
#define MAXUINT32 ((UINT32)~((UINT32)0))
|
||||
#define MAXINT32 ((INT32)(MAXUINT32 >> 1))
|
||||
#define MININT32 ((INT32)~MAXINT32)
|
||||
|
||||
#define MAXUINT64 ((UINT64)~((UINT64)0))
|
||||
#define MAXINT64 ((INT64)(MAXUINT64 >> 1))
|
||||
#define MININT64 ((INT64)~MAXINT64)
|
||||
|
||||
#define MAXULONG ((ULONG)~((ULONG)0))
|
||||
#define MAXLONG ((LONG)(MAXULONG >> 1))
|
||||
#define MINLONG ((LONG)~MAXLONG)
|
||||
|
||||
#define MAXULONGLONG ((ULONGLONG)~((ULONGLONG)0))
|
||||
#define MINLONGLONG ((LONGLONG)~MAXLONGLONG)
|
||||
|
||||
#define MAXSIZE_T ((SIZE_T)~((SIZE_T)0))
|
||||
#define MAXSSIZE_T ((SSIZE_T)(MAXSIZE_T >> 1))
|
||||
#define MINSSIZE_T ((SSIZE_T)~MAXSSIZE_T)
|
||||
|
||||
#define MAXUINT ((UINT)~((UINT)0))
|
||||
#define MAXINT ((INT)(MAXUINT >> 1))
|
||||
#define MININT ((INT)~MAXINT)
|
||||
|
||||
#define MAXDWORD32 ((DWORD32)~((DWORD32)0))
|
||||
#define MAXDWORD64 ((DWORD64)~((DWORD64)0))
|
||||
|
||||
#define MINBYTE 0x00
|
||||
#define MAXBYTE 0xFF
|
||||
#define MINCHAR 0x80
|
||||
#define MAXCHAR 0x7F
|
||||
#define MINSHORT 0x8000
|
||||
#define MAXSHORT 0x7FFF
|
||||
#define MINUSHORT 0x0000
|
||||
#define MAXUSHORT 0xFFFF
|
||||
#define MINWORD 0x0000
|
||||
#define MAXWORD 0xFFFF
|
||||
#define MINDWORD 0x00000000
|
||||
#define MAXDWORD 0xFFFFFFFF
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define __T(x) L ## x
|
||||
#else
|
||||
#define __T(x) x
|
||||
#define T2A(p) (p)
|
||||
#define A2T(p) (p)
|
||||
#define A2CT(p) (p)
|
||||
#define T2CA(p) (p)
|
||||
#define CT2A(p) (p)
|
||||
#define CA2T(p) (p)
|
||||
#define CA2CT(p) (p)
|
||||
#endif
|
||||
|
||||
#define _T(x) __T(x)
|
||||
#define _TEXT(x) __T(x)
|
||||
|
||||
#define _In_
|
||||
#define _Out_
|
||||
#define _Inout_
|
||||
#define _In_opt_
|
||||
#define _Out_opt_
|
||||
#define _Inout_opt_
|
||||
#define USES_CONVERSION
|
||||
|
||||
#define INFINITE -1
|
||||
#define NO_ERROR 0
|
||||
#define HAS_ERROR -1
|
||||
#define TIMEOUT 0
|
||||
#define RS_OK NO_ERROR
|
||||
#define RS_FAIL HAS_ERROR
|
||||
#define RS_TIMEOUT TIMEOUT
|
||||
#define INVALID_FD -1
|
||||
#define INVALID_HANDLE_VALUE INVALID_FD
|
||||
#define INVALID_PVOID ((PVOID)-1)
|
||||
#define _MAX_PATH 256
|
||||
#define MAX_PATH _MAX_PATH
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define CONST const
|
||||
|
||||
#define MAKEWORD(a, b) ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
|
||||
#define MAKELONG(a, b) ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
|
||||
#define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
|
||||
#define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
|
||||
#define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
|
||||
#define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
|
||||
|
||||
#if !defined(MAX)
|
||||
#define MAX(a,b) (((a) >= (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#if !defined(MIN)
|
||||
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#if !defined(_max)
|
||||
#define _max(a,b) MAX(a,b)
|
||||
#endif
|
||||
|
||||
#if !defined(_min)
|
||||
#define _min(a,b) MIN(a,b)
|
||||
#endif
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#if !defined(_NDEBUG)
|
||||
#define _NDEBUG
|
||||
#endif
|
||||
#if defined(DEBUG)
|
||||
#undef DEBUG
|
||||
#endif
|
||||
#if defined(_DEBUG)
|
||||
#undef _DEBUG
|
||||
#endif
|
||||
#if defined(DEBUG_TRACE)
|
||||
#undef DEBUG_TRACE
|
||||
#endif
|
||||
#else
|
||||
#if defined(_NDEBUG)
|
||||
#undef _NDEBUG
|
||||
#endif
|
||||
#if !defined(DEBUG)
|
||||
#define DEBUG
|
||||
#endif
|
||||
#if !defined(_DEBUG)
|
||||
#define _DEBUG
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__arm64__) && !defined(__aarch64__)
|
||||
#define __aarch64__ __arm64__
|
||||
#elif defined(__aarch64__) && !defined(__arm64__)
|
||||
#define __arm64__ __aarch64__
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN_C extern "C"
|
||||
#define EXTERN_C_BEGIN EXTERN_C {
|
||||
#define EXTERN_C_END }
|
||||
#else
|
||||
#define EXTERN_C extern
|
||||
#define EXTERN_C_BEGIN
|
||||
#define EXTERN_C_END
|
||||
#endif
|
||||
|
||||
#if !defined(__stdcall)
|
||||
#define __stdcall __attribute__ ((__stdcall__))
|
||||
#endif
|
||||
|
||||
#if !defined(__cdecl)
|
||||
#define __cdecl __attribute__ ((__cdecl__))
|
||||
#endif
|
||||
|
||||
#if !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#if !defined(CALLBACK)
|
||||
#define CALLBACK
|
||||
#endif
|
||||
|
||||
#if !defined(WINAPI)
|
||||
#define WINAPI
|
||||
#endif
|
||||
|
||||
#if !defined(FORCEINLINE)
|
||||
#ifdef __GNUC__
|
||||
#define FORCEINLINE __attribute__ ((always_inline))
|
||||
#else
|
||||
#define FORCEINLINE inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(STATIC_FORCEINLINE)
|
||||
#define STATIC_FORCEINLINE static FORCEINLINE
|
||||
#endif
|
||||
|
||||
#if !defined(EXTERN_FORCEINLINE)
|
||||
#define EXTERN_FORCEINLINE extern FORCEINLINE
|
||||
#endif
|
||||
252
hpsocket/GlobalErrno.h
Normal file
252
hpsocket/GlobalErrno.h
Normal file
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
|
||||
*
|
||||
* Author : Bruce Liang
|
||||
* Website : https://github.com/ldcsaa
|
||||
* Project : https://github.com/ldcsaa/HP-Socket
|
||||
* Blog : http://www.cnblogs.com/ldcsaa
|
||||
* Wiki : http://www.oschina.net/p/hp-socket
|
||||
* QQ Group : 44636872, 75375912
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GlobalDef.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <sysexits.h>
|
||||
|
||||
#define ERROR_INVALID_STATE EPERM
|
||||
#define ERROR_INVALID_PARAMETER EINVAL
|
||||
#define ERROR_BROKEN_PIPE EPIPE
|
||||
#define ERROR_AGAIN EAGAIN
|
||||
#define ERROR_WOULDBLOCK EAGAIN
|
||||
#define ERROR_READ_FAULT EFAULT
|
||||
#define ERROR_WRITE_FAULT EFAULT
|
||||
#define ERROR_HANDLES_CLOSED EBADFD
|
||||
#define ERROR_IO_PENDING EINPROGRESS
|
||||
#define ERROR_INTR EINTR
|
||||
#define ERROR_EMPTY ENODATA
|
||||
#define ERROR_NO_DATA ENODATA
|
||||
#define ERROR_FILE_TOO_LARGE EFBIG
|
||||
#define ERROR_INVALID_OPERATION EPERM
|
||||
#define ERROR_CANCELLED ECANCELED
|
||||
#define ERROR_UNKNOWN ENOMSG
|
||||
#define ERROR_OBJECT_NOT_FOUND EBADSLT
|
||||
#define ERROR_NOT_FOUND EBADSLT
|
||||
#define ERROR_INVALID_INDEX ENOANO
|
||||
#define ERROR_OPERATION_ABORTED ECANCELED
|
||||
#define ERROR_CONNABORTED ECONNABORTED
|
||||
#define ERROR_ADDRNOTAVAIL EADDRNOTAVAIL
|
||||
#define ERROR_INCORRECT_ADDRESS EADDRNOTAVAIL
|
||||
#define ERROR_PFNOSUPPORT EPFNOSUPPORT
|
||||
#define ERROR_AFNOSUPPORT EAFNOSUPPORT
|
||||
#define ERROR_TIMEOUT ETIMEDOUT
|
||||
#define ERROR_TIMEDOUT ETIMEDOUT
|
||||
#define ERROR_PROTO EPROTO
|
||||
#define ERROR_CONNECTION_COUNT_LIMIT ENOSR
|
||||
#define ERROR_VERIFY_CHECK EBADRQC
|
||||
#define ERROR_CREATE_FAILED EMFILE
|
||||
#define ERROR_INVALID_DATA EBADMSG
|
||||
#define ERROR_BAD_LENGTH EMSGSIZE
|
||||
#define ERROR_CALL_NOT_IMPLEMENTED EPERM
|
||||
#define ERROR_INCORRECT_SIZE EMSGSIZE
|
||||
#define ERROR_CONNRESET ECONNRESET
|
||||
#define ERROR_CONNREFUSED ECONNREFUSED
|
||||
#define ERROR_HOSTUNREACH EHOSTUNREACH
|
||||
#define ERROR_INVALID_NAME ENOENT
|
||||
#define ERROR_BAD_FILE_TYPE EBADF
|
||||
#define ERROR_FILE_NOT_FOUND ENOENT
|
||||
#define ERROR_FUNCTION_FAILED EFAULT
|
||||
#define ERROR_INVALID_PASSWORD EACCES
|
||||
#define ERROR_INVALID_ACCESS EACCES
|
||||
#define ERROR_NOT_READY EPERM
|
||||
#define ERROR_NOT_SUPPORTED EPERM
|
||||
#define ERROR_BAD_FORMAT EBADMSG
|
||||
#define ERROR_BUFFER_OVERFLOW E2BIG
|
||||
#define ERROR_OUT_OF_RANGE ERANGE
|
||||
#define ERROR_DESTINATION_ELEMENT_FULL EXFULL
|
||||
#define ERROR_ALREADY_INITIALIZED EALREADY
|
||||
#define ERROR_CANT_WAIT EIO
|
||||
|
||||
#define EXIT_CODE_OK EX_OK
|
||||
#define EXIT_CODE_CONFIG EX_CONFIG
|
||||
#define EXIT_CODE_SOFTWARE EX_SOFTWARE
|
||||
|
||||
/*
|
||||
* Socket error codes.
|
||||
*/
|
||||
#ifndef WSABASEERR
|
||||
|
||||
/*
|
||||
* All Sockets error constants are biased by WSABASEERR from
|
||||
* the "normal"
|
||||
*/
|
||||
#define WSABASEERR 10000
|
||||
|
||||
/*
|
||||
* Sockets definitions of regular Microsoft C error constants
|
||||
*/
|
||||
#define WSAEINTR (WSABASEERR+4)
|
||||
#define WSAEBADF (WSABASEERR+9)
|
||||
#define WSAEACCES (WSABASEERR+13)
|
||||
#define WSAEFAULT (WSABASEERR+14)
|
||||
#define WSAEINVAL (WSABASEERR+22)
|
||||
#define WSAEMFILE (WSABASEERR+24)
|
||||
|
||||
/*
|
||||
* Sockets definitions of regular Berkeley error constants
|
||||
*/
|
||||
#define WSAEWOULDBLOCK (WSABASEERR+35)
|
||||
#define WSAEINPROGRESS (WSABASEERR+36)
|
||||
#define WSAEALREADY (WSABASEERR+37)
|
||||
#define WSAENOTSOCK (WSABASEERR+38)
|
||||
#define WSAEDESTADDRREQ (WSABASEERR+39)
|
||||
#define WSAEMSGSIZE (WSABASEERR+40)
|
||||
#define WSAEPROTOTYPE (WSABASEERR+41)
|
||||
#define WSAENOPROTOOPT (WSABASEERR+42)
|
||||
#define WSAEPROTONOSUPPORT (WSABASEERR+43)
|
||||
#define WSAESOCKTNOSUPPORT (WSABASEERR+44)
|
||||
#define WSAEOPNOTSUPP (WSABASEERR+45)
|
||||
#define WSAEPFNOSUPPORT (WSABASEERR+46)
|
||||
#define WSAEAFNOSUPPORT (WSABASEERR+47)
|
||||
#define WSAEADDRINUSE (WSABASEERR+48)
|
||||
#define WSAEADDRNOTAVAIL (WSABASEERR+49)
|
||||
#define WSAENETDOWN (WSABASEERR+50)
|
||||
#define WSAENETUNREACH (WSABASEERR+51)
|
||||
#define WSAENETRESET (WSABASEERR+52)
|
||||
#define WSAECONNABORTED (WSABASEERR+53)
|
||||
#define WSAECONNRESET (WSABASEERR+54)
|
||||
#define WSAENOBUFS (WSABASEERR+55)
|
||||
#define WSAEISCONN (WSABASEERR+56)
|
||||
#define WSAENOTCONN (WSABASEERR+57)
|
||||
#define WSAESHUTDOWN (WSABASEERR+58)
|
||||
#define WSAETOOMANYREFS (WSABASEERR+59)
|
||||
#define WSAETIMEDOUT (WSABASEERR+60)
|
||||
#define WSAECONNREFUSED (WSABASEERR+61)
|
||||
#define WSAELOOP (WSABASEERR+62)
|
||||
#define WSAENAMETOOLONG (WSABASEERR+63)
|
||||
#define WSAEHOSTDOWN (WSABASEERR+64)
|
||||
#define WSAEHOSTUNREACH (WSABASEERR+65)
|
||||
#define WSAENOTEMPTY (WSABASEERR+66)
|
||||
#define WSAEPROCLIM (WSABASEERR+67)
|
||||
#define WSAEUSERS (WSABASEERR+68)
|
||||
#define WSAEDQUOT (WSABASEERR+69)
|
||||
#define WSAESTALE (WSABASEERR+70)
|
||||
#define WSAEREMOTE (WSABASEERR+71)
|
||||
|
||||
/*
|
||||
* Extended Sockets error constant definitions
|
||||
*/
|
||||
#define WSASYSNOTREADY (WSABASEERR+91)
|
||||
#define WSAVERNOTSUPPORTED (WSABASEERR+92)
|
||||
#define WSANOTINITIALISED (WSABASEERR+93)
|
||||
#define WSAEDISCON (WSABASEERR+101)
|
||||
#define WSAENOMORE (WSABASEERR+102)
|
||||
#define WSAECANCELLED (WSABASEERR+103)
|
||||
#define WSAEINVALIDPROCTABLE (WSABASEERR+104)
|
||||
#define WSAEINVALIDPROVIDER (WSABASEERR+105)
|
||||
#define WSAEPROVIDERFAILEDINIT (WSABASEERR+106)
|
||||
#define WSASYSCALLFAILURE (WSABASEERR+107)
|
||||
#define WSASERVICE_NOT_FOUND (WSABASEERR+108)
|
||||
#define WSATYPE_NOT_FOUND (WSABASEERR+109)
|
||||
#define WSA_E_NO_MORE (WSABASEERR+110)
|
||||
#define WSA_E_CANCELLED (WSABASEERR+111)
|
||||
#define WSAEREFUSED (WSABASEERR+112)
|
||||
|
||||
/*
|
||||
* Error return codes from gethostbyname() and gethostbyaddr()
|
||||
* (when using the resolver). Note that these errors are
|
||||
* retrieved via WSAGetLastError() and must therefore follow
|
||||
* the rules for avoiding clashes with error numbers from
|
||||
* specific implementations or language run-time systems.
|
||||
* For this reason the codes are based at WSABASEERR+1001.
|
||||
* Note also that [WSA]NO_ADDRESS is defined only for
|
||||
* compatibility purposes.
|
||||
*/
|
||||
|
||||
/* Authoritative Answer: Host not found */
|
||||
#define WSAHOST_NOT_FOUND (WSABASEERR+1001)
|
||||
|
||||
/* Non-Authoritative: Host not found, or SERVERFAIL */
|
||||
#define WSATRY_AGAIN (WSABASEERR+1002)
|
||||
|
||||
/* Non-recoverable errors, FORMERR, REFUSED, NOTIMP */
|
||||
#define WSANO_RECOVERY (WSABASEERR+1003)
|
||||
|
||||
/* Valid name, no data record of requested type */
|
||||
#define WSANO_DATA (WSABASEERR+1004)
|
||||
|
||||
/*
|
||||
* Define QOS related error return codes
|
||||
*
|
||||
*/
|
||||
#define WSA_QOS_RECEIVERS (WSABASEERR + 1005)
|
||||
/* at least one Reserve has arrived */
|
||||
#define WSA_QOS_SENDERS (WSABASEERR + 1006)
|
||||
/* at least one Path has arrived */
|
||||
#define WSA_QOS_NO_SENDERS (WSABASEERR + 1007)
|
||||
/* there are no senders */
|
||||
#define WSA_QOS_NO_RECEIVERS (WSABASEERR + 1008)
|
||||
/* there are no receivers */
|
||||
#define WSA_QOS_REQUEST_CONFIRMED (WSABASEERR + 1009)
|
||||
/* Reserve has been confirmed */
|
||||
#define WSA_QOS_ADMISSION_FAILURE (WSABASEERR + 1010)
|
||||
/* error due to lack of resources */
|
||||
#define WSA_QOS_POLICY_FAILURE (WSABASEERR + 1011)
|
||||
/* rejected for administrative reasons - bad credentials */
|
||||
#define WSA_QOS_BAD_STYLE (WSABASEERR + 1012)
|
||||
/* unknown or conflicting style */
|
||||
#define WSA_QOS_BAD_OBJECT (WSABASEERR + 1013)
|
||||
/* problem with some part of the filterspec or providerspecific
|
||||
* buffer in general */
|
||||
#define WSA_QOS_TRAFFIC_CTRL_ERROR (WSABASEERR + 1014)
|
||||
/* problem with some part of the flowspec */
|
||||
#define WSA_QOS_GENERIC_ERROR (WSABASEERR + 1015)
|
||||
/* general error */
|
||||
#define WSA_QOS_ESERVICETYPE (WSABASEERR + 1016)
|
||||
/* invalid service type in flowspec */
|
||||
#define WSA_QOS_EFLOWSPEC (WSABASEERR + 1017)
|
||||
/* invalid flowspec */
|
||||
#define WSA_QOS_EPROVSPECBUF (WSABASEERR + 1018)
|
||||
/* invalid provider specific buffer */
|
||||
#define WSA_QOS_EFILTERSTYLE (WSABASEERR + 1019)
|
||||
/* invalid filter style */
|
||||
#define WSA_QOS_EFILTERTYPE (WSABASEERR + 1020)
|
||||
/* invalid filter type */
|
||||
#define WSA_QOS_EFILTERCOUNT (WSABASEERR + 1021)
|
||||
/* incorrect number of filters */
|
||||
#define WSA_QOS_EOBJLENGTH (WSABASEERR + 1022)
|
||||
/* invalid object length */
|
||||
#define WSA_QOS_EFLOWCOUNT (WSABASEERR + 1023)
|
||||
/* incorrect number of flows */
|
||||
#define WSA_QOS_EUNKOWNPSOBJ (WSABASEERR + 1024)
|
||||
/* unknown object in provider specific buffer */
|
||||
#define WSA_QOS_EPOLICYOBJ (WSABASEERR + 1025)
|
||||
/* invalid policy object in provider specific buffer */
|
||||
#define WSA_QOS_EFLOWDESC (WSABASEERR + 1026)
|
||||
/* invalid flow descriptor in the list */
|
||||
#define WSA_QOS_EPSFLOWSPEC (WSABASEERR + 1027)
|
||||
/* inconsistent flow spec in provider specific buffer */
|
||||
#define WSA_QOS_EPSFILTERSPEC (WSABASEERR + 1028)
|
||||
/* invalid filter spec in provider specific buffer */
|
||||
#define WSA_QOS_ESDMODEOBJ (WSABASEERR + 1029)
|
||||
/* invalid shape discard mode object in provider specific buffer */
|
||||
#define WSA_QOS_ESHAPERATEOBJ (WSABASEERR + 1030)
|
||||
/* invalid shaping rate object in provider specific buffer */
|
||||
#define WSA_QOS_RESERVED_PETYPE (WSABASEERR + 1031)
|
||||
/* reserved policy element in provider specific buffer */
|
||||
|
||||
#endif /* ifdef WSABASEERR */
|
||||
338
hpsocket/HPSocket-SSL.h
Normal file
338
hpsocket/HPSocket-SSL.h
Normal file
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
|
||||
*
|
||||
* Author : Bruce Liang
|
||||
* Website : https://github.com/ldcsaa
|
||||
* Project : https://github.com/ldcsaa/HP-Socket
|
||||
* Blog : http://www.cnblogs.com/ldcsaa
|
||||
* Wiki : http://www.oschina.net/p/hp-socket
|
||||
* QQ Group : 44636872, 75375912
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HPSocket.h"
|
||||
|
||||
#ifdef _SSL_SUPPORT
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/******************************************************************** SSL Exports ********************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/**************************************************/
|
||||
/************** HPSocket-SSL 导出函数 **************/
|
||||
|
||||
// 创建 SSL ITcpServer 对象
|
||||
HPSOCKET_API ITcpServer* HP_Create_SSLServer(ITcpServerListener* pListener);
|
||||
// 创建 SSL ITcpAgent 对象
|
||||
HPSOCKET_API ITcpAgent* HP_Create_SSLAgent(ITcpAgentListener* pListener);
|
||||
// 创建 SSL ITcpClient 对象
|
||||
HPSOCKET_API ITcpClient* HP_Create_SSLClient(ITcpClientListener* pListener);
|
||||
// 创建 SSL ITcpPullServer 对象
|
||||
HPSOCKET_API ITcpPullServer* HP_Create_SSLPullServer(ITcpServerListener* pListener);
|
||||
// 创建 SSL ITcpPullAgent 对象
|
||||
HPSOCKET_API ITcpPullAgent* HP_Create_SSLPullAgent(ITcpAgentListener* pListener);
|
||||
// 创建 SSL ITcpPullClient 对象
|
||||
HPSOCKET_API ITcpPullClient* HP_Create_SSLPullClient(ITcpClientListener* pListener);
|
||||
// 创建 SSL ITcpPackServer 对象
|
||||
HPSOCKET_API ITcpPackServer* HP_Create_SSLPackServer(ITcpServerListener* pListener);
|
||||
// 创建 SSL ITcpPackAgent 对象
|
||||
HPSOCKET_API ITcpPackAgent* HP_Create_SSLPackAgent(ITcpAgentListener* pListener);
|
||||
// 创建 SSL ITcpPackClient 对象
|
||||
HPSOCKET_API ITcpPackClient* HP_Create_SSLPackClient(ITcpClientListener* pListener);
|
||||
|
||||
// 销毁 SSL ITcpServer 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLServer(ITcpServer* pServer);
|
||||
// 销毁 SSL ITcpAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLAgent(ITcpAgent* pAgent);
|
||||
// 销毁 SSL ITcpClient 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLClient(ITcpClient* pClient);
|
||||
// 销毁 SSL ITcpPullServer 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLPullServer(ITcpPullServer* pServer);
|
||||
// 销毁 SSL ITcpPullAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLPullAgent(ITcpPullAgent* pAgent);
|
||||
// 销毁 SSL ITcpPullClient 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLPullClient(ITcpPullClient* pClient);
|
||||
// 销毁 SSL ITcpPackServer 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLPackServer(ITcpPackServer* pServer);
|
||||
// 销毁 SSL ITcpPackAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLPackAgent(ITcpPackAgent* pAgent);
|
||||
// 销毁 SSL ITcpPackClient 对象
|
||||
HPSOCKET_API void HP_Destroy_SSLPackClient(ITcpPackClient* pClient);
|
||||
|
||||
// SSL ITcpServer 对象创建器
|
||||
struct SSLServer_Creator
|
||||
{
|
||||
static ITcpServer* Create(ITcpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpServer* pServer)
|
||||
{
|
||||
HP_Destroy_SSLServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpAgent 对象创建器
|
||||
struct SSLAgent_Creator
|
||||
{
|
||||
static ITcpAgent* Create(ITcpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_SSLAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpClient 对象创建器
|
||||
struct SSLClient_Creator
|
||||
{
|
||||
static ITcpClient* Create(ITcpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpClient* pClient)
|
||||
{
|
||||
HP_Destroy_SSLClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpPullServer 对象创建器
|
||||
struct SSLPullServer_Creator
|
||||
{
|
||||
static ITcpPullServer* Create(ITcpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLPullServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPullServer* pServer)
|
||||
{
|
||||
HP_Destroy_SSLPullServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpPullAgent 对象创建器
|
||||
struct SSLPullAgent_Creator
|
||||
{
|
||||
static ITcpPullAgent* Create(ITcpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLPullAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPullAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_SSLPullAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpPullClient 对象创建器
|
||||
struct SSLPullClient_Creator
|
||||
{
|
||||
static ITcpPullClient* Create(ITcpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLPullClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPullClient* pClient)
|
||||
{
|
||||
HP_Destroy_SSLPullClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpPackServer 对象创建器
|
||||
struct SSLPackServer_Creator
|
||||
{
|
||||
static ITcpPackServer* Create(ITcpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLPackServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPackServer* pServer)
|
||||
{
|
||||
HP_Destroy_SSLPackServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpPackAgent 对象创建器
|
||||
struct SSLPackAgent_Creator
|
||||
{
|
||||
static ITcpPackAgent* Create(ITcpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLPackAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPackAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_SSLPackAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpPackClient 对象创建器
|
||||
struct SSLPackClient_Creator
|
||||
{
|
||||
static ITcpPackClient* Create(ITcpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_SSLPackClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPackClient* pClient)
|
||||
{
|
||||
HP_Destroy_SSLPackClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// SSL ITcpServer 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpServer, ITcpServerListener, SSLServer_Creator> CSSLServerPtr;
|
||||
// SSL ITcpAgent 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpAgent, ITcpAgentListener, SSLAgent_Creator> CSSLAgentPtr;
|
||||
// SSL ITcpClient 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpClient, ITcpClientListener, SSLClient_Creator> CSSLClientPtr;
|
||||
// SSL ITcpPullServer 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPullServer, ITcpServerListener, SSLPullServer_Creator> CSSLPullServerPtr;
|
||||
// SSL ITcpPullAgent 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPullAgent, ITcpAgentListener, SSLPullAgent_Creator> CSSLPullAgentPtr;
|
||||
// SSL ITcpPullClient 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPullClient, ITcpClientListener, SSLPullClient_Creator> CSSLPullClientPtr;
|
||||
// SSL ITcpPackServer 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPackServer, ITcpServerListener, SSLPackServer_Creator> CSSLPackServerPtr;
|
||||
// SSL ITcpPackAgent 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPackAgent, ITcpAgentListener, SSLPackAgent_Creator> CSSLPackAgentPtr;
|
||||
// SSL ITcpPackClient 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPackClient, ITcpClientListener, SSLPackClient_Creator> CSSLPackClientPtr;
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/*************************************************************** Global Function Exports *************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/*
|
||||
* 名称:SNI 默认回调函数
|
||||
* 描述:SSL Server 的 SetupSSLContext 方法中如果不指定 SNI 回调函数则使用此 SNI 默认回调函数
|
||||
*
|
||||
* 参数: lpszServerName -- 请求域名
|
||||
* pContext -- SSL Context 对象
|
||||
*
|
||||
* 返回值:SNI 主机证书对应的索引
|
||||
*/
|
||||
HPSOCKET_API int __HP_CALL HP_SSL_DefaultServerNameCallback(LPCTSTR lpszServerName, PVOID pContext);
|
||||
|
||||
/*
|
||||
* 名称:清理线程局部环境 SSL 资源
|
||||
* 描述:任何一个操作 SSL 的线程,通信结束时都需要清理线程局部环境 SSL 资源
|
||||
* 1、主线程和 HP-Socket 工作线程在通信结束时会自动清理线程局部环境 SSL 资源。因此,一般情况下不必手工调用本方法
|
||||
* 2、特殊情况下,当自定义线程参与 HP-Socket 通信操作并检查到 SSL 内存泄漏时,需在每次通信结束时自定义线程调用本方法
|
||||
*
|
||||
* 参数: dwThreadID -- 线程 ID(0:当前线程)
|
||||
*
|
||||
* 返回值:无
|
||||
*/
|
||||
HPSOCKET_API void HP_SSL_RemoveThreadLocalState(THR_ID dwThreadID);
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/******************************************************************** HTTPS Exports ******************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
#ifdef _HTTP_SUPPORT
|
||||
|
||||
// 创建 IHttpsServer 对象
|
||||
HPSOCKET_API IHttpServer* HP_Create_HttpsServer(IHttpServerListener* pListener);
|
||||
// 创建 IHttpsAgent 对象
|
||||
HPSOCKET_API IHttpAgent* HP_Create_HttpsAgent(IHttpAgentListener* pListener);
|
||||
// 创建 IHttpsClient 对象
|
||||
HPSOCKET_API IHttpClient* HP_Create_HttpsClient(IHttpClientListener* pListener);
|
||||
// 创建 IHttpsSyncClient 对象
|
||||
HPSOCKET_API IHttpSyncClient* HP_Create_HttpsSyncClient(IHttpClientListener* pListener = nullptr);
|
||||
|
||||
// 销毁 IHttpsServer 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpsServer(IHttpServer* pServer);
|
||||
// 销毁 IHttpsAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpsAgent(IHttpAgent* pAgent);
|
||||
// 销毁 IHttpsClient 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpsClient(IHttpClient* pClient);
|
||||
// 销毁 IHttpsSyncClient 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpsSyncClient(IHttpSyncClient* pClient);
|
||||
|
||||
// IHttpsServer 对象创建器
|
||||
struct HttpsServer_Creator
|
||||
{
|
||||
static IHttpServer* Create(IHttpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_HttpsServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpServer* pServer)
|
||||
{
|
||||
HP_Destroy_HttpsServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpsAgent 对象创建器
|
||||
struct HttpsAgent_Creator
|
||||
{
|
||||
static IHttpAgent* Create(IHttpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_HttpsAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_HttpsAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpsClient 对象创建器
|
||||
struct HttpsClient_Creator
|
||||
{
|
||||
static IHttpClient* Create(IHttpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_HttpsClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpClient* pClient)
|
||||
{
|
||||
HP_Destroy_HttpsClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpsSyncClient 对象创建器
|
||||
struct HttpsSyncClient_Creator
|
||||
{
|
||||
static IHttpSyncClient* Create(IHttpClientListener* pListener = nullptr)
|
||||
{
|
||||
return HP_Create_HttpsSyncClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpSyncClient* pClient)
|
||||
{
|
||||
HP_Destroy_HttpsSyncClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpsServer 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpServer, IHttpServerListener, HttpsServer_Creator> CHttpsServerPtr;
|
||||
// IHttpsAgent 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpAgent, IHttpAgentListener, HttpsAgent_Creator> CHttpsAgentPtr;
|
||||
// IHttpsClient 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpClient, IHttpClientListener, HttpsClient_Creator> CHttpsClientPtr;
|
||||
// IHttpsSyncClient 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpSyncClient, IHttpClientListener, HttpsSyncClient_Creator> CHttpsSyncClientPtr;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
818
hpsocket/HPSocket.h
Normal file
818
hpsocket/HPSocket.h
Normal file
@@ -0,0 +1,818 @@
|
||||
/*
|
||||
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
|
||||
*
|
||||
* Author : Bruce Liang
|
||||
* Website : https://github.com/ldcsaa
|
||||
* Project : https://github.com/ldcsaa/HP-Socket
|
||||
* Blog : http://www.cnblogs.com/ldcsaa
|
||||
* Wiki : http://www.oschina.net/p/hp-socket
|
||||
* QQ Group : 44636872, 75375912
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
Module: HPSocket
|
||||
|
||||
Usage:
|
||||
方法一:
|
||||
--------------------------------------------------------------------------------------
|
||||
0. 应用程序包含 HPTypeDef.h / SocketInterface.h / HPSocket.h 头文件
|
||||
1. 调用 HP_Create_Xxx() 函数创建 HPSocket 对象
|
||||
2. 使用完毕后调用 HP_Destroy_Xxx() 函数销毁 HPSocket 对象
|
||||
|
||||
方法二:
|
||||
--------------------------------------------------------------------------------------
|
||||
0. 应用程序包含 SocketInterface.h 和 HPSocket.h 头文件
|
||||
1. 创建 CXxxPtr 智能指针,通过智能指针使用 HPSocket 对象
|
||||
|
||||
Release:
|
||||
<-- 动态链接库 -->
|
||||
1. x86/libhpsocket.so - (32位/MBCS/Release)
|
||||
2. x86/libhpsocket_d.so - (32位/MBCS/DeBug)
|
||||
3. x64/libhpsocket.so - (64位/MBCS/Release)
|
||||
4. x64/libhpsocket_d.so - (64位/MBCS/DeBug)
|
||||
|
||||
<-- 静态链接库 -->
|
||||
1. x86/static/libhpsocket.a - (32位/MBCS/Release)
|
||||
2. x86/static/libhpsocket_d.a - (32位/MBCS/DeBug)
|
||||
3. x64/static/libhpsocket.a - (64位/MBCS/Release)
|
||||
4. x64/static/libhpsocket_d.a - (64位/MBCS/DeBug)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SocketInterface.h"
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/****************************************************************** TCP/UDP Exports ******************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/**************************************************/
|
||||
/************** HPSocket 对象智能指针 **************/
|
||||
|
||||
template<class T, class _Listener, class _Creator> class CHPObjectPtr
|
||||
{
|
||||
public:
|
||||
CHPObjectPtr& Reset(T* pObj = nullptr)
|
||||
{
|
||||
if(pObj != m_pObj)
|
||||
{
|
||||
if(m_pObj)
|
||||
_Creator::Destroy(m_pObj);
|
||||
|
||||
m_pObj = pObj;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CHPObjectPtr& Attach(T* pObj)
|
||||
{
|
||||
return Reset(pObj);
|
||||
}
|
||||
|
||||
T* Detach()
|
||||
{
|
||||
T* pObj = m_pObj;
|
||||
m_pObj = nullptr;
|
||||
|
||||
return pObj;
|
||||
}
|
||||
|
||||
BOOL IsValid () const {return m_pObj != nullptr ;}
|
||||
T* Get () const {return m_pObj ;}
|
||||
T* operator -> () const {return m_pObj ;}
|
||||
operator T* () const {return m_pObj ;}
|
||||
|
||||
CHPObjectPtr& operator = (T* pObj) {return Reset(pObj) ;}
|
||||
|
||||
public:
|
||||
CHPObjectPtr(_Listener* pListener = nullptr)
|
||||
{
|
||||
m_pObj = _Creator::Create(pListener);
|
||||
}
|
||||
|
||||
CHPObjectPtr(BOOL bCreate, _Listener* pListener = nullptr)
|
||||
{
|
||||
m_pObj = bCreate ? _Creator::Create(pListener) : nullptr;
|
||||
}
|
||||
|
||||
virtual ~CHPObjectPtr()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
private:
|
||||
CHPObjectPtr(const CHPObjectPtr&) = delete;
|
||||
CHPObjectPtr& operator = (const CHPObjectPtr&) = delete;
|
||||
|
||||
protected:
|
||||
T* m_pObj;
|
||||
};
|
||||
|
||||
/**************************************************/
|
||||
/**************** HPSocket 导出函数 ****************/
|
||||
|
||||
// 创建 ITcpServer 对象
|
||||
HPSOCKET_API ITcpServer* HP_Create_TcpServer(ITcpServerListener* pListener);
|
||||
// 创建 ITcpAgent 对象
|
||||
HPSOCKET_API ITcpAgent* HP_Create_TcpAgent(ITcpAgentListener* pListener);
|
||||
// 创建 ITcpClient 对象
|
||||
HPSOCKET_API ITcpClient* HP_Create_TcpClient(ITcpClientListener* pListener);
|
||||
// 创建 ITcpPullServer 对象
|
||||
HPSOCKET_API ITcpPullServer* HP_Create_TcpPullServer(ITcpServerListener* pListener);
|
||||
// 创建 ITcpPullAgent 对象
|
||||
HPSOCKET_API ITcpPullAgent* HP_Create_TcpPullAgent(ITcpAgentListener* pListener);
|
||||
// 创建 ITcpPullClient 对象
|
||||
HPSOCKET_API ITcpPullClient* HP_Create_TcpPullClient(ITcpClientListener* pListener);
|
||||
// 创建 ITcpPackServer 对象
|
||||
HPSOCKET_API ITcpPackServer* HP_Create_TcpPackServer(ITcpServerListener* pListener);
|
||||
// 创建 ITcpPackAgent 对象
|
||||
HPSOCKET_API ITcpPackAgent* HP_Create_TcpPackAgent(ITcpAgentListener* pListener);
|
||||
// 创建 ITcpPackClient 对象
|
||||
HPSOCKET_API ITcpPackClient* HP_Create_TcpPackClient(ITcpClientListener* pListener);
|
||||
|
||||
// 销毁 ITcpServer 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpServer(ITcpServer* pServer);
|
||||
// 销毁 ITcpAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpAgent(ITcpAgent* pAgent);
|
||||
// 销毁 ITcpClient 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpClient(ITcpClient* pClient);
|
||||
// 销毁 ITcpPullServer 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpPullServer(ITcpPullServer* pServer);
|
||||
// 销毁 ITcpPullAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpPullAgent(ITcpPullAgent* pAgent);
|
||||
// 销毁 ITcpPullClient 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpPullClient(ITcpPullClient* pClient);
|
||||
// 销毁 ITcpPackServer 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpPackServer(ITcpPackServer* pServer);
|
||||
// 销毁 ITcpPackAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpPackAgent(ITcpPackAgent* pAgent);
|
||||
// 销毁 ITcpPackClient 对象
|
||||
HPSOCKET_API void HP_Destroy_TcpPackClient(ITcpPackClient* pClient);
|
||||
|
||||
#ifdef _UDP_SUPPORT
|
||||
|
||||
// 创建 IUdpServer 对象
|
||||
HPSOCKET_API IUdpServer* HP_Create_UdpServer(IUdpServerListener* pListener);
|
||||
// 创建 IUdpClient 对象
|
||||
HPSOCKET_API IUdpClient* HP_Create_UdpClient(IUdpClientListener* pListener);
|
||||
// 创建 IUdpCast 对象
|
||||
HPSOCKET_API IUdpCast* HP_Create_UdpCast(IUdpCastListener* pListener);
|
||||
// 创建 IUdpNode 对象
|
||||
HPSOCKET_API IUdpNode* HP_Create_UdpNode(IUdpNodeListener* pListener);
|
||||
// 创建 IUdpArqServer 对象
|
||||
HPSOCKET_API IUdpArqServer* HP_Create_UdpArqServer(IUdpServerListener* pListener);
|
||||
// 创建 IUdpArqClient 对象
|
||||
HPSOCKET_API IUdpArqClient* HP_Create_UdpArqClient(IUdpClientListener* pListener);
|
||||
|
||||
// 销毁 IUdpServer 对象
|
||||
HPSOCKET_API void HP_Destroy_UdpServer(IUdpServer* pServer);
|
||||
// 销毁 IUdpClient 对象
|
||||
HPSOCKET_API void HP_Destroy_UdpClient(IUdpClient* pClient);
|
||||
// 销毁 IUdpCast 对象
|
||||
HPSOCKET_API void HP_Destroy_UdpCast(IUdpCast* pCast);
|
||||
// 销毁 IUdpNode 对象
|
||||
HPSOCKET_API void HP_Destroy_UdpNode(IUdpNode* pNode);
|
||||
// 销毁 IUdpArqServer 对象
|
||||
HPSOCKET_API void HP_Destroy_UdpArqServer(IUdpArqServer* pServer);
|
||||
// 销毁 IUdpArqClient 对象
|
||||
HPSOCKET_API void HP_Destroy_UdpArqClient(IUdpArqClient* pClient);
|
||||
|
||||
#endif
|
||||
|
||||
// ITcpServer 对象创建器
|
||||
struct TcpServer_Creator
|
||||
{
|
||||
static ITcpServer* Create(ITcpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpServer* pServer)
|
||||
{
|
||||
HP_Destroy_TcpServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpAgent 对象创建器
|
||||
struct TcpAgent_Creator
|
||||
{
|
||||
static ITcpAgent* Create(ITcpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_TcpAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpClient 对象创建器
|
||||
struct TcpClient_Creator
|
||||
{
|
||||
static ITcpClient* Create(ITcpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpClient* pClient)
|
||||
{
|
||||
HP_Destroy_TcpClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpPullServer 对象创建器
|
||||
struct TcpPullServer_Creator
|
||||
{
|
||||
static ITcpPullServer* Create(ITcpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpPullServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPullServer* pServer)
|
||||
{
|
||||
HP_Destroy_TcpPullServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpPullAgent 对象创建器
|
||||
struct TcpPullAgent_Creator
|
||||
{
|
||||
static ITcpPullAgent* Create(ITcpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpPullAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPullAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_TcpPullAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpPullClient 对象创建器
|
||||
struct TcpPullClient_Creator
|
||||
{
|
||||
static ITcpPullClient* Create(ITcpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpPullClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPullClient* pClient)
|
||||
{
|
||||
HP_Destroy_TcpPullClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpPackServer 对象创建器
|
||||
struct TcpPackServer_Creator
|
||||
{
|
||||
static ITcpPackServer* Create(ITcpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpPackServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPackServer* pServer)
|
||||
{
|
||||
HP_Destroy_TcpPackServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpPackAgent 对象创建器
|
||||
struct TcpPackAgent_Creator
|
||||
{
|
||||
static ITcpPackAgent* Create(ITcpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpPackAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPackAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_TcpPackAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpPackClient 对象创建器
|
||||
struct TcpPackClient_Creator
|
||||
{
|
||||
static ITcpPackClient* Create(ITcpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_TcpPackClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(ITcpPackClient* pClient)
|
||||
{
|
||||
HP_Destroy_TcpPackClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// ITcpServer 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpServer, ITcpServerListener, TcpServer_Creator> CTcpServerPtr;
|
||||
// ITcpAgent 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpAgent, ITcpAgentListener, TcpAgent_Creator> CTcpAgentPtr;
|
||||
// ITcpClient 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpClient, ITcpClientListener, TcpClient_Creator> CTcpClientPtr;
|
||||
// ITcpPullServer 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPullServer, ITcpServerListener, TcpPullServer_Creator> CTcpPullServerPtr;
|
||||
// ITcpPullAgent 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPullAgent, ITcpAgentListener, TcpPullAgent_Creator> CTcpPullAgentPtr;
|
||||
// ITcpPullClient 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPullClient, ITcpClientListener, TcpPullClient_Creator> CTcpPullClientPtr;
|
||||
// ITcpPackServer 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPackServer, ITcpServerListener, TcpPackServer_Creator> CTcpPackServerPtr;
|
||||
// ITcpPackAgent 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPackAgent, ITcpAgentListener, TcpPackAgent_Creator> CTcpPackAgentPtr;
|
||||
// ITcpPackClient 对象智能指针
|
||||
typedef CHPObjectPtr<ITcpPackClient, ITcpClientListener, TcpPackClient_Creator> CTcpPackClientPtr;
|
||||
|
||||
#ifdef _UDP_SUPPORT
|
||||
|
||||
// IUdpServer 对象创建器
|
||||
struct UdpServer_Creator
|
||||
{
|
||||
static IUdpServer* Create(IUdpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_UdpServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IUdpServer* pServer)
|
||||
{
|
||||
HP_Destroy_UdpServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// IUdpClient 对象创建器
|
||||
struct UdpClient_Creator
|
||||
{
|
||||
static IUdpClient* Create(IUdpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_UdpClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IUdpClient* pClient)
|
||||
{
|
||||
HP_Destroy_UdpClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// IUdpCast 对象创建器
|
||||
struct UdpCast_Creator
|
||||
{
|
||||
static IUdpCast* Create(IUdpCastListener* pListener)
|
||||
{
|
||||
return HP_Create_UdpCast(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IUdpCast* pCast)
|
||||
{
|
||||
HP_Destroy_UdpCast(pCast);
|
||||
}
|
||||
};
|
||||
|
||||
// IUdpNode 对象创建器
|
||||
struct UdpNode_Creator
|
||||
{
|
||||
static IUdpNode* Create(IUdpNodeListener* pListener)
|
||||
{
|
||||
return HP_Create_UdpNode(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IUdpNode* pNode)
|
||||
{
|
||||
HP_Destroy_UdpNode(pNode);
|
||||
}
|
||||
};
|
||||
|
||||
// IUdpArqServer 对象创建器
|
||||
struct UdpArqServer_Creator
|
||||
{
|
||||
static IUdpArqServer* Create(IUdpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_UdpArqServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IUdpArqServer* pServer)
|
||||
{
|
||||
HP_Destroy_UdpArqServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// IUdpArqClient 对象创建器
|
||||
struct UdpArqClient_Creator
|
||||
{
|
||||
static IUdpArqClient* Create(IUdpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_UdpArqClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IUdpArqClient* pClient)
|
||||
{
|
||||
HP_Destroy_UdpArqClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// IUdpServer 对象智能指针
|
||||
typedef CHPObjectPtr<IUdpServer, IUdpServerListener, UdpServer_Creator> CUdpServerPtr;
|
||||
// IUdpClient 对象智能指针
|
||||
typedef CHPObjectPtr<IUdpClient, IUdpClientListener, UdpClient_Creator> CUdpClientPtr;
|
||||
// IUdpCast 对象智能指针
|
||||
typedef CHPObjectPtr<IUdpCast, IUdpCastListener, UdpCast_Creator> CUdpCastPtr;
|
||||
// IUdpNode 对象智能指针
|
||||
typedef CHPObjectPtr<IUdpNode, IUdpNodeListener, UdpNode_Creator> CUdpNodePtr;
|
||||
// IUdpArqServer 对象智能指针
|
||||
typedef CHPObjectPtr<IUdpArqServer, IUdpServerListener, UdpArqServer_Creator> CUdpArqServerPtr;
|
||||
// IUdpArqClient 对象智能指针
|
||||
typedef CHPObjectPtr<IUdpArqClient, IUdpClientListener, UdpArqClient_Creator> CUdpArqClientPtr;
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/*************************************************************** Global Function Exports *************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
// 获取 HPSocket 版本号(4 个字节分别为:主版本号,子版本号,修正版本号,构建编号)
|
||||
HPSOCKET_API DWORD HP_GetHPSocketVersion();
|
||||
|
||||
// 获取错误描述文本
|
||||
HPSOCKET_API LPCTSTR HP_GetSocketErrorDesc(EnSocketError enCode);
|
||||
// 调用系统的 errno 方法获取系统错误代码
|
||||
HPSOCKET_API DWORD SYS_GetLastError();
|
||||
// 调用系统的 strerror() 方法获取系统错误代码描述
|
||||
HPSOCKET_API LPCSTR SYS_GetLastErrorStr();
|
||||
// 调用系统的 setsockopt()
|
||||
HPSOCKET_API int SYS_SetSocketOption(SOCKET sock, int level, int name, LPVOID val, int len);
|
||||
// 调用系统的 getsockopt()
|
||||
HPSOCKET_API int SYS_GetSocketOption(SOCKET sock, int level, int name, LPVOID val, int* len);
|
||||
// 调用系统的 ioctlsocket()
|
||||
HPSOCKET_API int SYS_IoctlSocket(SOCKET sock, long cmd, ULONG* arg);
|
||||
|
||||
// 调用系统的 fcntl() 设置 F_SETFL 属性
|
||||
HPSOCKET_API BOOL SYS_fcntl_SETFL(FD fd, INT fl, BOOL bSet = TRUE);
|
||||
|
||||
// 设置 FD 选项:O_NONBLOCK
|
||||
HPSOCKET_API int SYS_SSO_NoBlock(SOCKET sock, BOOL bNoBlock = TRUE);
|
||||
// 设置 socket 选项:IPPROTO_TCP -> TCP_NODELAY
|
||||
HPSOCKET_API int SYS_SSO_NoDelay(SOCKET sock, BOOL bNoDelay = TRUE);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_DONTLINGER
|
||||
HPSOCKET_API int SYS_SSO_DontLinger(SOCKET sock, BOOL bDont = TRUE);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_LINGER
|
||||
HPSOCKET_API int SYS_SSO_Linger(SOCKET sock, USHORT l_onoff, USHORT l_linger);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_RCVBUF
|
||||
HPSOCKET_API int SYS_SSO_RecvBuffSize(SOCKET sock, int size);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_SNDBUF
|
||||
HPSOCKET_API int SYS_SSO_SendBuffSize(SOCKET sock, int size);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_RCVTIMEO
|
||||
HPSOCKET_API int SYS_SSO_RecvTimeOut(SOCKET sock, int ms);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_SNDTIMEO
|
||||
HPSOCKET_API int SYS_SSO_SendTimeOut(SOCKET sock, int ms);
|
||||
// 设置 socket 选项:SOL_SOCKET -> SO_REUSEADDR / SO_REUSEPORT
|
||||
HPSOCKET_API int SYS_SSO_ReuseAddress(SOCKET sock, EnReuseAddressPolicy opt);
|
||||
|
||||
// 获取 SOCKET 本地地址信息
|
||||
HPSOCKET_API BOOL SYS_GetSocketLocalAddress(SOCKET socket, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort);
|
||||
// 获取 SOCKET 远程地址信息
|
||||
HPSOCKET_API BOOL SYS_GetSocketRemoteAddress(SOCKET socket, TCHAR lpszAddress[], int& iAddressLen, USHORT& usPort);
|
||||
|
||||
/* 枚举主机 IP 地址 */
|
||||
HPSOCKET_API BOOL SYS_EnumHostIPAddresses(LPCTSTR lpszHost, EnIPAddrType enType, LPTIPAddr** lpppIPAddr, int& iIPAddrCount);
|
||||
/* 释放 LPTIPAddr* */
|
||||
HPSOCKET_API BOOL SYS_FreeHostIPAddresses(LPTIPAddr* lppIPAddr);
|
||||
/* 检查字符串是否符合 IP 地址格式 */
|
||||
HPSOCKET_API BOOL SYS_IsIPAddress(LPCTSTR lpszAddress, EnIPAddrType* penType = nullptr);
|
||||
/* 通过主机名获取 IP 地址 */
|
||||
HPSOCKET_API BOOL SYS_GetIPAddress(LPCTSTR lpszHost, TCHAR lpszIP[], int& iIPLenth, EnIPAddrType& enType);
|
||||
|
||||
/* 64 位网络字节序转主机字节序 */
|
||||
HPSOCKET_API ULONGLONG SYS_NToH64(ULONGLONG value);
|
||||
/* 64 位主机字节序转网络字节序 */
|
||||
HPSOCKET_API ULONGLONG SYS_HToN64(ULONGLONG value);
|
||||
/* 短整型高低字节交换 */
|
||||
HPSOCKET_API USHORT SYS_SwapEndian16(USHORT value);
|
||||
/* 长整型高低字节交换 */
|
||||
HPSOCKET_API DWORD SYS_SwapEndian32(DWORD value);
|
||||
/* 检查是否小端字节序 */
|
||||
HPSOCKET_API BOOL SYS_IsLittleEndian();
|
||||
|
||||
/* 分配内存 */
|
||||
HPSOCKET_API LPBYTE SYS_Malloc(int size);
|
||||
/* 重新分配内存 */
|
||||
HPSOCKET_API LPBYTE SYS_Realloc(LPBYTE p, int size);
|
||||
/* 释放内存 */
|
||||
HPSOCKET_API VOID SYS_Free(LPBYTE p);
|
||||
/* 分配内存块 */
|
||||
HPSOCKET_API LPVOID SYS_Calloc(int number, int size);
|
||||
|
||||
// 计算 Base64 编码后长度
|
||||
HPSOCKET_API DWORD SYS_GuessBase64EncodeBound(DWORD dwSrcLen);
|
||||
// 计算 Base64 解码后长度
|
||||
HPSOCKET_API DWORD SYS_GuessBase64DecodeBound(const BYTE* lpszSrc, DWORD dwSrcLen);
|
||||
// Base64 编码(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_Base64Encode(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Base64 解码(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_Base64Decode(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
|
||||
// 计算 URL 编码后长度
|
||||
HPSOCKET_API DWORD SYS_GuessUrlEncodeBound(const BYTE* lpszSrc, DWORD dwSrcLen);
|
||||
// 计算 URL 解码后长度
|
||||
HPSOCKET_API DWORD SYS_GuessUrlDecodeBound(const BYTE* lpszSrc, DWORD dwSrcLen);
|
||||
// URL 编码(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_UrlEncode(BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// URL 解码(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_UrlDecode(BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
|
||||
#ifdef _ZLIB_SUPPORT
|
||||
|
||||
// 普通压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
// (默认参数:iLevel -> -1,iMethod -> 8,iWindowBits -> 15,iMemLevel -> 8,iStrategy -> 0)
|
||||
HPSOCKET_API int SYS_Compress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// 高级压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
//(默认参数:iLevel -> -1,iMethod -> 8,iWindowBits -> 15,iMemLevel -> 8,iStrategy -> 0)
|
||||
HPSOCKET_API int SYS_CompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iLevel = -1, int iMethod = 8, int iWindowBits = 15, int iMemLevel = 8, int iStrategy = 0);
|
||||
// 普通解压(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
//(默认参数:iWindowBits -> 15)
|
||||
HPSOCKET_API int SYS_Uncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// 高级解压(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
//(默认参数:iWindowBits -> 15)
|
||||
HPSOCKET_API int SYS_UncompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iWindowBits = 15);
|
||||
// 推测压缩结果长度
|
||||
HPSOCKET_API DWORD SYS_GuessCompressBound(DWORD dwSrcLen, BOOL bGZip = FALSE);
|
||||
|
||||
// Gzip 压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_GZipCompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Gzip 解压(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_GZipUncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// 推测 Gzip 解压结果长度(如果返回 0 或不合理值则说明输入内容并非有效的 Gzip 格式)
|
||||
HPSOCKET_API DWORD SYS_GZipGuessUncompressBound(const BYTE* lpszSrc, DWORD dwSrcLen);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _BROTLI_SUPPORT
|
||||
|
||||
// Brotli 压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
// (默认参数:iQuality -> 11,iWindow -> 22,iMode -> 0)
|
||||
HPSOCKET_API int SYS_BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Brotli 高级压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
//(默认参数:iQuality -> 11,iWindow -> 22,iMode -> 0)
|
||||
HPSOCKET_API int SYS_BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality = 11, int iWindow = 22, int iMode = 0);
|
||||
// Brotli 解压(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
HPSOCKET_API int SYS_BrotliUncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Brotli 推测压缩结果长度
|
||||
HPSOCKET_API DWORD SYS_BrotliGuessCompressBound(DWORD dwSrcLen);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _ICONV_SUPPORT
|
||||
|
||||
// Charset A -> Charset B
|
||||
HPSOCKET_API BOOL SYS_CharsetConvert(LPCSTR lpszFromCharset, LPCSTR lpszToCharset, LPCSTR lpszInBuf, int iInBufLen, LPSTR lpszOutBuf, int& iOutBufLen);
|
||||
|
||||
// GBK -> UNICODE
|
||||
HPSOCKET_API BOOL SYS_GbkToUnicodeEx(const char szSrc[], int iSrcLength, WCHAR szDest[], int& iDestLength);
|
||||
// UNICODE -> GBK
|
||||
HPSOCKET_API BOOL SYS_UnicodeToGbkEx(const WCHAR szSrc[], int iSrcLength, char szDest[], int& iDestLength);
|
||||
// UTF8 -> UNICODE
|
||||
HPSOCKET_API BOOL SYS_Utf8ToUnicodeEx(const char szSrc[], int iSrcLength, WCHAR szDest[], int& iDestLength);
|
||||
// UNICODE -> UTF8
|
||||
HPSOCKET_API BOOL SYS_UnicodeToUtf8Ex(const WCHAR szSrc[], int iSrcLength, char szDest[], int& iDestLength);
|
||||
// GBK -> UTF8
|
||||
HPSOCKET_API BOOL SYS_GbkToUtf8Ex(const char szSrc[], int iSrcLength, char szDest[], int& iDestLength);
|
||||
// UTF8 -> GBK
|
||||
HPSOCKET_API BOOL SYS_Utf8ToGbkEx(const char szSrc[], int iSrcLength, char szDest[], int& iDestLength);
|
||||
|
||||
// GBK -> UNICODE
|
||||
HPSOCKET_API BOOL SYS_GbkToUnicode(const char szSrc[], WCHAR szDest[], int& iDestLength);
|
||||
// UNICODE -> GBK
|
||||
HPSOCKET_API BOOL SYS_UnicodeToGbk(const WCHAR szSrc[], char szDest[], int& iDestLength);
|
||||
// UTF8 -> UNICODE
|
||||
HPSOCKET_API BOOL SYS_Utf8ToUnicode(const char szSrc[], WCHAR szDest[], int& iDestLength);
|
||||
// UNICODE -> UTF8
|
||||
HPSOCKET_API BOOL SYS_UnicodeToUtf8(const WCHAR szSrc[], char szDest[], int& iDestLength);
|
||||
// GBK -> UTF8
|
||||
HPSOCKET_API BOOL SYS_GbkToUtf8(const char szSrc[], char szDest[], int& iDestLength);
|
||||
// UTF8 -> GBK
|
||||
HPSOCKET_API BOOL SYS_Utf8ToGbk(const char szSrc[], char szDest[], int& iDestLength);
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/******************************************************************** HTTP Exports *******************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
#ifdef _HTTP_SUPPORT
|
||||
|
||||
// 创建 IHttpServer 对象
|
||||
HPSOCKET_API IHttpServer* HP_Create_HttpServer(IHttpServerListener* pListener);
|
||||
// 创建 IHttpAgent 对象
|
||||
HPSOCKET_API IHttpAgent* HP_Create_HttpAgent(IHttpAgentListener* pListener);
|
||||
// 创建 IHttpClient 对象
|
||||
HPSOCKET_API IHttpClient* HP_Create_HttpClient(IHttpClientListener* pListener);
|
||||
// 创建 IHttpSyncClient 对象
|
||||
HPSOCKET_API IHttpSyncClient* HP_Create_HttpSyncClient(IHttpClientListener* pListener = nullptr);
|
||||
|
||||
// 销毁 IHttpServer 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpServer(IHttpServer* pServer);
|
||||
// 销毁 IHttpAgent 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpAgent(IHttpAgent* pAgent);
|
||||
// 销毁 IHttpClient 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpClient(IHttpClient* pClient);
|
||||
// 销毁 IHttpSyncClient 对象
|
||||
HPSOCKET_API void HP_Destroy_HttpSyncClient(IHttpSyncClient* pClient);
|
||||
|
||||
// IHttpServer 对象创建器
|
||||
struct HttpServer_Creator
|
||||
{
|
||||
static IHttpServer* Create(IHttpServerListener* pListener)
|
||||
{
|
||||
return HP_Create_HttpServer(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpServer* pServer)
|
||||
{
|
||||
HP_Destroy_HttpServer(pServer);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpAgent 对象创建器
|
||||
struct HttpAgent_Creator
|
||||
{
|
||||
static IHttpAgent* Create(IHttpAgentListener* pListener)
|
||||
{
|
||||
return HP_Create_HttpAgent(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpAgent* pAgent)
|
||||
{
|
||||
HP_Destroy_HttpAgent(pAgent);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpClient 对象创建器
|
||||
struct HttpClient_Creator
|
||||
{
|
||||
static IHttpClient* Create(IHttpClientListener* pListener)
|
||||
{
|
||||
return HP_Create_HttpClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpClient* pClient)
|
||||
{
|
||||
HP_Destroy_HttpClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpSyncClient 对象创建器
|
||||
struct HttpSyncClient_Creator
|
||||
{
|
||||
static IHttpSyncClient* Create(IHttpClientListener* pListener = nullptr)
|
||||
{
|
||||
return HP_Create_HttpSyncClient(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHttpSyncClient* pClient)
|
||||
{
|
||||
HP_Destroy_HttpSyncClient(pClient);
|
||||
}
|
||||
};
|
||||
|
||||
// IHttpServer 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpServer, IHttpServerListener, HttpServer_Creator> CHttpServerPtr;
|
||||
// IHttpAgent 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpAgent, IHttpAgentListener, HttpAgent_Creator> CHttpAgentPtr;
|
||||
// IHttpClient 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpClient, IHttpClientListener, HttpClient_Creator> CHttpClientPtr;
|
||||
// IHttpSyncClient 对象智能指针
|
||||
typedef CHPObjectPtr<IHttpSyncClient, IHttpClientListener, HttpSyncClient_Creator> CHttpSyncClientPtr;
|
||||
|
||||
/**************************************************************************/
|
||||
/*************************** HTTP Cookie 管理方法 **************************/
|
||||
|
||||
/* 从文件加载 Cookie */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_LoadFromFile(LPCSTR lpszFile, BOOL bKeepExists = TRUE);
|
||||
/* 保存 Cookie 到文件 */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_SaveToFile(LPCSTR lpszFile, BOOL bKeepExists = TRUE);
|
||||
/* 清理 Cookie */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_ClearCookies(LPCSTR lpszDomain = nullptr, LPCSTR lpszPath = nullptr);
|
||||
/* 清理过期 Cookie */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_RemoveExpiredCookies(LPCSTR lpszDomain = nullptr, LPCSTR lpszPath = nullptr);
|
||||
/* 设置 Cookie */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_SetCookie(LPCSTR lpszName, LPCSTR lpszValue, LPCSTR lpszDomain, LPCSTR lpszPath, int iMaxAge = -1, BOOL bHttpOnly = FALSE, BOOL bSecure = FALSE, int enSameSite = 0, BOOL bOnlyUpdateValueIfExists = TRUE);
|
||||
/* 删除 Cookie */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_DeleteCookie(LPCSTR lpszDomain, LPCSTR lpszPath, LPCSTR lpszName);
|
||||
/* 设置是否允许第三方 Cookie */
|
||||
HPSOCKET_API void HP_HttpCookie_MGR_SetEnableThirdPartyCookie(BOOL bEnableThirdPartyCookie = TRUE);
|
||||
/* 检查是否允许第三方 Cookie */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_MGR_IsEnableThirdPartyCookie();
|
||||
|
||||
/* Cookie expires 字符串转换为整数 */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_HLP_ParseExpires(LPCSTR lpszExpires, __time64_t& tmExpires);
|
||||
/* 整数转换为 Cookie expires 字符串 */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_HLP_MakeExpiresStr(char lpszBuff[], int& iBuffLen, __time64_t tmExpires);
|
||||
/* 生成 Cookie 字符串 */
|
||||
HPSOCKET_API BOOL HP_HttpCookie_HLP_ToString(char lpszBuff[], int& iBuffLen, LPCSTR lpszName, LPCSTR lpszValue, LPCSTR lpszDomain, LPCSTR lpszPath, int iMaxAge /*= -1*/, BOOL bHttpOnly /*= FALSE*/, BOOL bSecure /*= FALSE*/, int enSameSite /*= 0*/);
|
||||
/* 获取当前 UTC 时间 */
|
||||
HPSOCKET_API __time64_t HP_HttpCookie_HLP_CurrentUTCTime();
|
||||
/* Max-Age -> expires */
|
||||
HPSOCKET_API __time64_t HP_HttpCookie_HLP_MaxAgeToExpires(int iMaxAge);
|
||||
/* expires -> Max-Age */
|
||||
HPSOCKET_API int HP_HttpCookie_HLP_ExpiresToMaxAge(__time64_t tmExpires);
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/************************************************************* HTTP Global Function Exports **********************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/**************************************************************** Thread Pool Exports ****************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
// 创建 IHPThreadPool 对象
|
||||
HPSOCKET_API IHPThreadPool* HP_Create_ThreadPool(IHPThreadPoolListener* pListener = nullptr);
|
||||
// 销毁 IHPThreadPool 对象
|
||||
HPSOCKET_API void HP_Destroy_ThreadPool(IHPThreadPool* pThreadPool);
|
||||
|
||||
/*
|
||||
* 名称:创建 TSocketTask 对象
|
||||
* 描述:创建任务对象,该对象最终需由 HP_Destroy_SocketTaskObj() 销毁
|
||||
*
|
||||
* 参数: fnTaskProc -- 任务处理函数
|
||||
* pSender -- 发起对象
|
||||
* dwConnID -- 连接 ID
|
||||
* pBuffer -- 数据缓冲区
|
||||
* iBuffLen -- 数据缓冲区长度
|
||||
* enBuffType -- 数据缓冲区类型(默认:TBT_COPY)
|
||||
* TBT_COPY :(深拷贝)pBuffer 复制到 TSocketTask 对象。此后 TSocketTask 对象与 pBuffer 不再有任何关联
|
||||
* -> 适用于 pBuffer 不大或 pBuffer 生命周期不受控的场景
|
||||
* TBT_REFER :(浅拷贝)pBuffer 不复制到 TSocketTask 对象,需确保 TSocketTask 对象生命周期内 pBuffer 必须有效
|
||||
* -> 适用于 pBuffer 较大或 pBuffer 可重用,并且 pBuffer 生命周期受控的场景
|
||||
* TBT_ATTACH :(附属)执行浅拷贝,但 TSocketTask 对象会获得 pBuffer 的所有权,并负责释放 pBuffer,避免多次缓冲区拷贝
|
||||
* -> 注意:pBuffer 必须由 SYS_Malloc()/SYS_Calloc() 函数分配才能使用本类型,否则可能会发生内存访问错误
|
||||
* wParam -- 自定义参数
|
||||
* lParam -- 自定义参数
|
||||
* 返回值: LPTSocketTask
|
||||
*/
|
||||
HPSOCKET_API LPTSocketTask HP_Create_SocketTaskObj(Fn_SocketTaskProc fnTaskProc, PVOID pSender, CONNID dwConnID, LPCBYTE pBuffer, INT iBuffLen, EnTaskBufferType enBuffType = TBT_COPY, WPARAM wParam = 0, LPARAM lParam = 0);
|
||||
|
||||
// 销毁 TSocketTask 对象
|
||||
HPSOCKET_API void HP_Destroy_SocketTaskObj(LPTSocketTask pTask);
|
||||
|
||||
// IHPThreadPool 对象创建器
|
||||
struct HPThreadPool_Creator
|
||||
{
|
||||
static IHPThreadPool* Create(IHPThreadPoolListener* pListener = nullptr)
|
||||
{
|
||||
return HP_Create_ThreadPool(pListener);
|
||||
}
|
||||
|
||||
static void Destroy(IHPThreadPool* pThreadPool)
|
||||
{
|
||||
HP_Destroy_ThreadPool(pThreadPool);
|
||||
}
|
||||
};
|
||||
|
||||
// IHPThreadPool 对象智能指针
|
||||
typedef CHPObjectPtr<IHPThreadPool, IHPThreadPoolListener, HPThreadPool_Creator> CHPThreadPoolPtr;
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/********************************************************* Compressor / Decompressor Exports *********************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/* 销毁压缩器对象 */
|
||||
HPSOCKET_API void HP_Destroy_Compressor(IHPCompressor* pCompressor);
|
||||
/* 销毁解压器对象 */
|
||||
HPSOCKET_API void HP_Destroy_Decompressor(IHPDecompressor* pDecompressor);
|
||||
|
||||
#ifdef _ZLIB_SUPPORT
|
||||
|
||||
/* 创建 ZLib 压缩器对象 */
|
||||
HPSOCKET_API IHPCompressor* HP_Create_ZLibCompressor(Fn_CompressDataCallback fnCallback, int iWindowBits = 15, int iLevel = -1, int iMethod = 8, int iMemLevel = 8, int iStrategy = 0, DWORD dwBuffSize = 16 * 1024);
|
||||
/* 创建 GZip 压缩器对象 */
|
||||
HPSOCKET_API IHPCompressor* HP_Create_GZipCompressor(Fn_CompressDataCallback fnCallback, int iLevel = -1, int iMethod = 8, int iMemLevel = 8, int iStrategy = 0, DWORD dwBuffSize = 16 * 1024);
|
||||
/* 创建 ZLib 解压器对象 */
|
||||
HPSOCKET_API IHPDecompressor* HP_Create_ZLibDecompressor(Fn_DecompressDataCallback fnCallback, int iWindowBits = 15, DWORD dwBuffSize = 16 * 1024);
|
||||
/* 创建 GZip 解压器对象 */
|
||||
HPSOCKET_API IHPDecompressor* HP_Create_GZipDecompressor(Fn_DecompressDataCallback fnCallback, DWORD dwBuffSize = 16 * 1024);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _BROTLI_SUPPORT
|
||||
|
||||
/* 创建 Brotli 压缩器对象 */
|
||||
HPSOCKET_API IHPCompressor* HP_Create_BrotliCompressor(Fn_CompressDataCallback fnCallback, int iQuality = 11, int iWindow = 22, int iMode = 0, DWORD dwBuffSize = 16 * 1024);
|
||||
/* 创建 Brotli 解压器对象 */
|
||||
HPSOCKET_API IHPDecompressor* HP_Create_BrotliDecompressor(Fn_DecompressDataCallback fnCallback, DWORD dwBuffSize = 16 * 1024);
|
||||
|
||||
#endif
|
||||
411
hpsocket/HPSocket4C-SSL.h
Normal file
411
hpsocket/HPSocket4C-SSL.h
Normal file
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
|
||||
*
|
||||
* Author : Bruce Liang
|
||||
* Website : https://github.com/ldcsaa
|
||||
* Project : https://github.com/ldcsaa/HP-Socket
|
||||
* Blog : http://www.cnblogs.com/ldcsaa
|
||||
* Wiki : http://www.oschina.net/p/hp-socket
|
||||
* QQ Group : 44636872, 75375912
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HPSocket4C.h"
|
||||
|
||||
#ifdef _SSL_SUPPORT
|
||||
|
||||
/************************************************************************
|
||||
名称:定义 SSL Socket 对象指针类型别名
|
||||
描述:把 SSL Socket 对象指针定义为更直观的别名
|
||||
************************************************************************/
|
||||
|
||||
typedef HP_Object HP_SSLServer;
|
||||
typedef HP_Object HP_SSLAgent;
|
||||
typedef HP_Object HP_SSLClient;
|
||||
typedef HP_Object HP_SSLPullServer;
|
||||
typedef HP_Object HP_SSLPullAgent;
|
||||
typedef HP_Object HP_SSLPullClient;
|
||||
typedef HP_Object HP_SSLPackServer;
|
||||
typedef HP_Object HP_SSLPackAgent;
|
||||
typedef HP_Object HP_SSLPackClient;
|
||||
|
||||
typedef HP_Object HP_HttpsServer;
|
||||
typedef HP_Object HP_HttpsAgent;
|
||||
typedef HP_Object HP_HttpsClient;
|
||||
typedef HP_Object HP_HttpsSyncClient;
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/******************************************************************** SSL Exports ********************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/********************************************************/
|
||||
/************** HPSocket4C-SSL 对象创建函数 **************/
|
||||
|
||||
// 创建 HP_SSLServer 对象
|
||||
HPSOCKET_API HP_SSLServer __HP_CALL Create_HP_SSLServer(HP_TcpServerListener pListener);
|
||||
// 创建 HP_SSLAgent 对象
|
||||
HPSOCKET_API HP_SSLAgent __HP_CALL Create_HP_SSLAgent(HP_TcpAgentListener pListener);
|
||||
// 创建 HP_SSLClient 对象
|
||||
HPSOCKET_API HP_SSLClient __HP_CALL Create_HP_SSLClient(HP_TcpClientListener pListener);
|
||||
// 创建 HP_SSLPullServer 对象
|
||||
HPSOCKET_API HP_SSLPullServer __HP_CALL Create_HP_SSLPullServer(HP_TcpPullServerListener pListener);
|
||||
// 创建 HP_SSLPullAgent 对象
|
||||
HPSOCKET_API HP_SSLPullAgent __HP_CALL Create_HP_SSLPullAgent(HP_TcpPullAgentListener pListener);
|
||||
// 创建 HP_SSLPullClient 对象
|
||||
HPSOCKET_API HP_SSLPullClient __HP_CALL Create_HP_SSLPullClient(HP_TcpPullClientListener pListener);
|
||||
// 创建 HP_SSLPackServer 对象
|
||||
HPSOCKET_API HP_SSLPackServer __HP_CALL Create_HP_SSLPackServer(HP_TcpServerListener pListener);
|
||||
// 创建 HP_SSLPackAgent 对象
|
||||
HPSOCKET_API HP_SSLPackAgent __HP_CALL Create_HP_SSLPackAgent(HP_TcpAgentListener pListener);
|
||||
// 创建 HP_SSLPackClient 对象
|
||||
HPSOCKET_API HP_SSLPackClient __HP_CALL Create_HP_SSLPackClient(HP_TcpClientListener pListener);
|
||||
|
||||
// 销毁 HP_SSLServer 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLServer(HP_SSLServer pServer);
|
||||
// 销毁 HP_SSLAgent 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLAgent(HP_SSLAgent pAgent);
|
||||
// 销毁 HP_SSLClient 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLClient(HP_SSLClient pClient);
|
||||
// 销毁 HP_SSLPullServer 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLPullServer(HP_SSLPullServer pServer);
|
||||
// 销毁 HP_SSLPullAgent 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLPullAgent(HP_SSLPullAgent pAgent);
|
||||
// 销毁 HP_SSLPullClient 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLPullClient(HP_SSLPullClient pClient);
|
||||
// 销毁 HP_SSLPackServer 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLPackServer(HP_SSLPackServer pServer);
|
||||
// 销毁 HP_SSLPackAgent 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLPackAgent(HP_SSLPackAgent pAgent);
|
||||
// 销毁 HP_SSLPackClient 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_SSLPackClient(HP_SSLPackClient pClient);
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/*************************************************************** Global Function Exports *************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/***************************************************************************************/
|
||||
/************************************ SSL 初始化方法 ************************************/
|
||||
|
||||
/*
|
||||
* 名称:SNI 默认回调函数
|
||||
* 描述:HP_SSLServer_SetupSSLContext 方法中如果不指定 SNI 回调函数则使用此 SNI 默认回调函数
|
||||
*
|
||||
* 参数: lpszServerName -- 请求域名
|
||||
* pContext -- SSL Context 对象
|
||||
*
|
||||
* 返回值:SNI 主机证书对应的索引
|
||||
*/
|
||||
HPSOCKET_API int __HP_CALL HP_SSL_DefaultServerNameCallback(LPCTSTR lpszServerName, PVOID pContext);
|
||||
|
||||
/*
|
||||
* 名称:清理线程局部环境 SSL 资源
|
||||
* 描述:任何一个操作 SSL 的线程,通信结束时都需要清理线程局部环境 SSL 资源
|
||||
* 1、主线程和 HP-Socket 工作线程在通信结束时会自动清理线程局部环境 SSL 资源。因此,一般情况下不必手工调用本方法
|
||||
* 2、特殊情况下,当自定义线程参与 HP-Socket 通信操作并检查到 SSL 内存泄漏时,需在每次通信结束时自定义线程调用本方法
|
||||
*
|
||||
* 参数: dwThreadID -- 线程 ID(0:当前线程)
|
||||
*
|
||||
* 返回值:无
|
||||
*/
|
||||
HPSOCKET_API void __HP_CALL HP_SSL_RemoveThreadLocalState(THR_ID dwThreadID);
|
||||
|
||||
/*
|
||||
* 名称:初始化通信组件 SSL 环境参数
|
||||
* 描述:SSL 环境参数必须在 SSL 通信组件启动前完成初始化,否则启动失败
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCertFile -- 证书文件
|
||||
* lpszPemKeyFile -- 私钥文件
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCertFileOrPath -- CA 证书文件或目录(单向验证或客户端可选)
|
||||
* fnServerNameCallback -- SNI 回调函数指针(可选,如果为 nullptr 则使用 SNI 默认回调函数)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLServer_SetupSSLContext(HP_SSLServer pServer, int iVerifyMode /* SSL_VM_NONE */, LPCTSTR lpszPemCertFile /* nullptr */, LPCTSTR lpszPemKeyFile /* nullptr */, LPCTSTR lpszKeyPassword /* nullptr */, LPCTSTR lpszCAPemCertFileOrPath /* nullptr */, HP_Fn_SNI_ServerNameCallback fnServerNameCallback /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:初始化通信组件 SSL 环境参数(通过内存加载证书)
|
||||
* 描述:SSL 环境参数必须在 SSL 通信组件启动前完成初始化,否则启动失败
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCert -- 证书内容
|
||||
* lpszPemKey -- 私钥内容
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCert -- CA 证书内容(单向验证或客户端可选)
|
||||
* fnServerNameCallback -- SNI 回调函数指针(可选,如果为 nullptr 则使用 SNI 默认回调函数)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLServer_SetupSSLContextByMemory(HP_SSLServer pServer, int iVerifyMode /* SSL_VM_NONE */, LPCSTR lpszPemCert /* nullptr */, LPCSTR lpszPemKey /* nullptr */, LPCSTR lpszKeyPassword /* nullptr */, LPCSTR lpszCAPemCert /* nullptr */, HP_Fn_SNI_ServerNameCallback fnServerNameCallback /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:增加 SNI 主机证书
|
||||
* 描述:SSL 服务端在 SetupSSLContext() 成功后可以调用本方法增加多个 SNI 主机证书
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCertFile -- 证书文件
|
||||
* lpszPemKeyFile -- 私钥文件
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCertFileOrPath -- CA 证书文件或目录(单向验证可选)
|
||||
*
|
||||
* 返回值: 正数 -- 成功,并返回 SNI 主机证书对应的索引,该索引用于在 SNI 回调函数中定位 SNI 主机
|
||||
* 负数 -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API int __HP_CALL HP_SSLServer_AddSSLContext(HP_SSLServer pServer, int iVerifyMode, LPCTSTR lpszPemCertFile, LPCTSTR lpszPemKeyFile, LPCTSTR lpszKeyPassword /* nullptr */, LPCTSTR lpszCAPemCertFileOrPath /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:增加 SNI 主机证书(通过内存加载证书)
|
||||
* 描述:SSL 服务端在 SetupSSLContext() 成功后可以调用本方法增加多个 SNI 主机证书
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCert -- 证书内容
|
||||
* lpszPemKey -- 私钥内容
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCert -- CA 证书内容(单向验证可选)
|
||||
*
|
||||
* 返回值: 正数 -- 成功,并返回 SNI 主机证书对应的索引,该索引用于在 SNI 回调函数中定位 SNI 主机
|
||||
* 负数 -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API int __HP_CALL HP_SSLServer_AddSSLContextByMemory(HP_SSLServer pServer, int iVerifyMode, LPCSTR lpszPemCert, LPCSTR lpszPemKey, LPCSTR lpszKeyPassword /* nullptr */, LPCSTR lpszCAPemCert /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:绑定 SNI 主机域名
|
||||
* 描述:SSL 服务端在 AddSSLContext() 成功后可以调用本方法绑定主机域名到 SNI 主机证书
|
||||
*
|
||||
* 参数: lpszServerName -- 主机域名
|
||||
* iContextIndex -- SNI 主机证书对应的索引
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLServer_BindSSLServerName(HP_SSLServer pServer, LPCTSTR lpszServerName, int iContextIndex);
|
||||
|
||||
/*
|
||||
* 名称:清理通信组件 SSL 运行环境
|
||||
* 描述:清理通信组件 SSL 运行环境,回收 SSL 相关内存
|
||||
* 1、通信组件析构时会自动调用本方法
|
||||
* 2、当要重新设置通信组件 SSL 环境参数时,需要先调用本方法清理原先的环境参数
|
||||
*
|
||||
* 参数: 无
|
||||
*
|
||||
* 返回值:无
|
||||
*/
|
||||
HPSOCKET_API void __HP_CALL HP_SSLServer_CleanupSSLContext(HP_SSLServer pServer);
|
||||
|
||||
/*
|
||||
* 名称:初始化通信组件 SSL 环境参数
|
||||
* 描述:SSL 环境参数必须在 SSL 通信组件启动前完成初始化,否则启动失败
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCertFile -- 证书文件(客户端可选)
|
||||
* lpszPemKeyFile -- 私钥文件(客户端可选)
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCertFileOrPath -- CA 证书文件或目录(单向验证或客户端可选)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLAgent_SetupSSLContext(HP_SSLAgent pAgent, int iVerifyMode /* SSL_VM_NONE */, LPCTSTR lpszPemCertFile /* nullptr */, LPCTSTR lpszPemKeyFile /* nullptr */, LPCTSTR lpszKeyPassword /* nullptr */, LPCTSTR lpszCAPemCertFileOrPath /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:初始化通信组件 SSL 环境参数(通过内存加载证书)
|
||||
* 描述:SSL 环境参数必须在 SSL 通信组件启动前完成初始化,否则启动失败
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCert -- 证书内容
|
||||
* lpszPemKey -- 私钥内容
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCert -- CA 证书内容(单向验证或客户端可选)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLAgent_SetupSSLContextByMemory(HP_SSLAgent pAgent, int iVerifyMode /* SSL_VM_NONE */, LPCSTR lpszPemCert /* nullptr */, LPCSTR lpszPemKey /* nullptr */, LPCSTR lpszKeyPassword /* nullptr */, LPCSTR lpszCAPemCert /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:清理通信组件 SSL 运行环境
|
||||
* 描述:清理通信组件 SSL 运行环境,回收 SSL 相关内存
|
||||
* 1、通信组件析构时会自动调用本方法
|
||||
* 2、当要重新设置通信组件 SSL 环境参数时,需要先调用本方法清理原先的环境参数
|
||||
*
|
||||
* 参数: 无
|
||||
*
|
||||
* 返回值:无
|
||||
*/
|
||||
HPSOCKET_API void __HP_CALL HP_SSLAgent_CleanupSSLContext(HP_SSLAgent pAgent);
|
||||
|
||||
/*
|
||||
* 名称:初始化通信组件 SSL 环境参数
|
||||
* 描述:SSL 环境参数必须在 SSL 通信组件启动前完成初始化,否则启动失败
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCertFile -- 证书文件(客户端可选)
|
||||
* lpszPemKeyFile -- 私钥文件(客户端可选)
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCertFileOrPath -- CA 证书文件或目录(单向验证或客户端可选)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLClient_SetupSSLContext(HP_SSLClient pClient, int iVerifyMode /* SSL_VM_NONE */, LPCTSTR lpszPemCertFile /* nullptr */, LPCTSTR lpszPemKeyFile /* nullptr */, LPCTSTR lpszKeyPassword /* nullptr */, LPCTSTR lpszCAPemCertFileOrPath /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:初始化通信组件 SSL 环境参数(通过内存加载证书)
|
||||
* 描述:SSL 环境参数必须在 SSL 通信组件启动前完成初始化,否则启动失败
|
||||
*
|
||||
* 参数: iVerifyMode -- SSL 验证模式(参考 En_HP_SSLVerifyMode)
|
||||
* lpszPemCert -- 证书内容
|
||||
* lpszPemKey -- 私钥内容
|
||||
* lpszKeyPassword -- 私钥密码(没有密码则为空)
|
||||
* lpszCAPemCert -- CA 证书内容(单向验证或客户端可选)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLClient_SetupSSLContextByMemory(HP_SSLClient pClient, int iVerifyMode /* SSL_VM_NONE */, LPCSTR lpszPemCert /* nullptr */, LPCSTR lpszPemKey /* nullptr */, LPCSTR lpszKeyPassword /* nullptr */, LPCSTR lpszCAPemCert /* nullptr */);
|
||||
|
||||
/*
|
||||
* 名称:清理通信组件 SSL 运行环境
|
||||
* 描述:清理通信组件 SSL 运行环境,回收 SSL 相关内存
|
||||
* 1、通信组件析构时会自动调用本方法
|
||||
* 2、当要重新设置通信组件 SSL 环境参数时,需要先调用本方法清理原先的环境参数
|
||||
*
|
||||
* 参数: 无
|
||||
*
|
||||
* 返回值:无
|
||||
*/
|
||||
HPSOCKET_API void __HP_CALL HP_SSLClient_CleanupSSLContext(HP_SSLClient pClient);
|
||||
|
||||
/***************************************************************************************/
|
||||
/************************************* SSL 操作方法 ************************************/
|
||||
|
||||
/*
|
||||
* 名称:启动 SSL 握手
|
||||
* 描述:当通信组件设置为非自动握手时,需要调用本方法启动 SSL 握手
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLServer_StartSSLHandShake(HP_SSLServer pServer, HP_CONNID dwConnID);
|
||||
|
||||
/* 设置通信组件握手方式(默认:TRUE,自动握手) */
|
||||
HPSOCKET_API void __HP_CALL HP_SSLServer_SetSSLAutoHandShake(HP_SSLServer pServer, BOOL bAutoHandShake);
|
||||
/* 获取通信组件握手方式 */
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLServer_IsSSLAutoHandShake(HP_SSLServer pServer);
|
||||
|
||||
/* 设置 SSL 加密算法列表 */
|
||||
HPSOCKET_API void __HP_CALL HP_SSLServer_SetSSLCipherList(HP_SSLServer pServer, LPCTSTR lpszCipherList);
|
||||
/* 获取 SSL 加密算法列表 */
|
||||
HPSOCKET_API LPCTSTR __HP_CALL HP_SSLServer_GetSSLCipherList(HP_SSLServer pServer);
|
||||
|
||||
/*
|
||||
* 名称:获取 SSL Session 信息
|
||||
* 描述:获取指定类型的 SSL Session 信息(输出类型参考:En_HP_SSLSessionInfo)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLServer_GetSSLSessionInfo(HP_SSLServer pServer, HP_CONNID dwConnID, En_HP_SSLSessionInfo enInfo, LPVOID* lppInfo);
|
||||
|
||||
/*
|
||||
* 名称:启动 SSL 握手
|
||||
* 描述:当通信组件设置为非自动握手时,需要调用本方法启动 SSL 握手
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLAgent_StartSSLHandShake(HP_SSLAgent pAgent, HP_CONNID dwConnID);
|
||||
|
||||
/* 设置通信组件握手方式(默认:TRUE,自动握手) */
|
||||
HPSOCKET_API void __HP_CALL HP_SSLAgent_SetSSLAutoHandShake(HP_SSLAgent pAgent, BOOL bAutoHandShake);
|
||||
/* 获取通信组件握手方式 */
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLAgent_IsSSLAutoHandShake(HP_SSLAgent pAgent);
|
||||
|
||||
/* 设置 SSL 加密算法列表 */
|
||||
HPSOCKET_API void __HP_CALL HP_SSLAgent_SetSSLCipherList(HP_SSLAgent pAgent, LPCTSTR lpszCipherList);
|
||||
/* 获取 SSL 加密算法列表 */
|
||||
HPSOCKET_API LPCTSTR __HP_CALL HP_SSLAgent_GetSSLCipherList(HP_SSLAgent pAgent);
|
||||
|
||||
/*
|
||||
* 名称:获取 SSL Session 信息
|
||||
* 描述:获取指定类型的 SSL Session 信息(输出类型参考:En_HP_SSLSessionInfo)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLAgent_GetSSLSessionInfo(HP_SSLAgent pAgent, HP_CONNID dwConnID, En_HP_SSLSessionInfo enInfo, LPVOID* lppInfo);
|
||||
|
||||
/*
|
||||
* 名称:启动 SSL 握手
|
||||
* 描述:当通信组件设置为非自动握手时,需要调用本方法启动 SSL 握手
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLClient_StartSSLHandShake(HP_SSLClient pClient);
|
||||
|
||||
/* 设置通信组件握手方式(默认:TRUE,自动握手) */
|
||||
HPSOCKET_API void __HP_CALL HP_SSLClient_SetSSLAutoHandShake(HP_SSLClient pClient, BOOL bAutoHandShake);
|
||||
/* 获取通信组件握手方式 */
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLClient_IsSSLAutoHandShake(HP_SSLClient pClient);
|
||||
|
||||
/* 设置 SSL 加密算法列表 */
|
||||
HPSOCKET_API void __HP_CALL HP_SSLClient_SetSSLCipherList(HP_SSLClient pClient, LPCTSTR lpszCipherList);
|
||||
/* 获取 SSL 加密算法列表 */
|
||||
HPSOCKET_API LPCTSTR __HP_CALL HP_SSLClient_GetSSLCipherList(HP_SSLClient pClient);
|
||||
|
||||
/*
|
||||
* 名称:获取 SSL Session 信息
|
||||
* 描述:获取指定类型的 SSL Session 信息(输出类型参考:En_HP_SSLSessionInfo)
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取失败原因
|
||||
*/
|
||||
HPSOCKET_API BOOL __HP_CALL HP_SSLClient_GetSSLSessionInfo(HP_SSLClient pClient, En_HP_SSLSessionInfo enInfo, LPVOID* lppInfo);
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/******************************************************************** HTTPS Exports ******************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
#ifdef _HTTP_SUPPORT
|
||||
|
||||
/****************************************************/
|
||||
/**************** HTTPS 对象创建函数 *****************/
|
||||
|
||||
// 创建 HP_HttpsServer 对象
|
||||
HPSOCKET_API HP_HttpsServer __HP_CALL Create_HP_HttpsServer(HP_HttpServerListener pListener);
|
||||
// 创建 HP_HttpsAgent 对象
|
||||
HPSOCKET_API HP_HttpsAgent __HP_CALL Create_HP_HttpsAgent(HP_HttpAgentListener pListener);
|
||||
// 创建 HP_HttpsClient 对象
|
||||
HPSOCKET_API HP_HttpsClient __HP_CALL Create_HP_HttpsClient(HP_HttpClientListener pListener);
|
||||
// 创建 HP_HttpsSyncClient 对象(pListener 参数可传入 nullptr)
|
||||
HPSOCKET_API HP_HttpsSyncClient __HP_CALL Create_HP_HttpsSyncClient(HP_HttpClientListener pListener /*= nullptr*/);
|
||||
|
||||
// 销毁 HP_HttpsServer 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_HttpsServer(HP_HttpsServer pServer);
|
||||
// 销毁 HP_HttpsAgent 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_HttpsAgent(HP_HttpsAgent pAgent);
|
||||
// 销毁 HP_HttpsClient 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_HttpsClient(HP_HttpsClient pClient);
|
||||
// 销毁 HP_HttpsSyncClient 对象
|
||||
HPSOCKET_API void __HP_CALL Destroy_HP_HttpsSyncClient(HP_HttpsSyncClient pClient);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
2833
hpsocket/HPSocket4C.h
Normal file
2833
hpsocket/HPSocket4C.h
Normal file
File diff suppressed because it is too large
Load Diff
600
hpsocket/HPTypeDef.h
Normal file
600
hpsocket/HPTypeDef.h
Normal file
@@ -0,0 +1,600 @@
|
||||
/*
|
||||
* Copyright: JessMA Open Source (ldcsaa@gmail.com)
|
||||
*
|
||||
* Author : Bruce Liang
|
||||
* Website : https://github.com/ldcsaa
|
||||
* Project : https://github.com/ldcsaa/HP-Socket
|
||||
* Blog : http://www.cnblogs.com/ldcsaa
|
||||
* Wiki : http://www.oschina.net/p/hp-socket
|
||||
* QQ Group : 44636872, 75375912
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GlobalDef.h"
|
||||
|
||||
/* HP-Socket 版本号 */
|
||||
#define HP_VERSION_MAJOR 6 // 主版本号
|
||||
#define HP_VERSION_MINOR 0 // 子版本号
|
||||
#define HP_VERSION_REVISE 3 // 修正版本号
|
||||
#define HP_VERSION_BUILD 1 // 构建编号
|
||||
|
||||
//#define _UDP_DISABLED // 禁用 UDP
|
||||
//#define _SSL_DISABLED // 禁用 SSL
|
||||
//#define _HTTP_DISABLED // 禁用 HTTP
|
||||
//#define _ZLIB_DISABLED // 禁用 ZLIB
|
||||
//#define _ICONV_DISABLED // 禁用 ICONV
|
||||
//#define _BROTLI_DISABLED // 禁用 BROTLI
|
||||
|
||||
/* 是否启用 UDP,如果定义了 _UDP_DISABLED 则禁用(默认:启用) */
|
||||
#if !defined(_UDP_DISABLED)
|
||||
#ifndef _UDP_SUPPORT
|
||||
#define _UDP_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 是否启用 SSL,如果定义了 _SSL_DISABLED 则禁用(默认:启用) */
|
||||
#if !defined(_SSL_DISABLED)
|
||||
#ifndef _SSL_SUPPORT
|
||||
#define _SSL_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 是否启用 HTTP,如果定义了 _HTTP_DISABLED 则禁用(默认:启用) */
|
||||
#if !defined(_HTTP_DISABLED)
|
||||
#ifndef _HTTP_SUPPORT
|
||||
#define _HTTP_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 是否启用 ZLIB,如果定义了 _ZLIB_DISABLED 则禁用(默认:启用) */
|
||||
#if !defined(_ZLIB_DISABLED)
|
||||
#ifndef _ZLIB_SUPPORT
|
||||
#define _ZLIB_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 是否启用 BROTLI,如果定义了 _BROTLI_DISABLED 则禁用(默认:启用) */
|
||||
#if !defined(_BROTLI_DISABLED)
|
||||
#ifndef _BROTLI_SUPPORT
|
||||
#define _BROTLI_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 是否启用 ICONV,如果定义了 _ICONV_DISABLED 则禁用(默认:启用) */
|
||||
#if !defined(_ICONV_DISABLED)
|
||||
#ifndef _ICONV_SUPPORT
|
||||
#define _ICONV_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define HPSOCKET_API EXTERN_C __attribute__ ((__visibility__("default")))
|
||||
|
||||
#define __HP_CALL
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/**************************************************************** Base Type Definitions **************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
名称:连接 ID 数据类型
|
||||
描述:应用程序可以把 CONNID 定义为自身需要的类型(如:ULONG / ULONGLONG)
|
||||
************************************************************************/
|
||||
typedef ULID CONNID, HP_CONNID;
|
||||
|
||||
/************************************************************************
|
||||
名称:通信组件服务状态
|
||||
描述:应用程序可以通过通信组件的 GetState() 方法获取组件当前服务状态
|
||||
************************************************************************/
|
||||
typedef enum EnServiceState
|
||||
{
|
||||
SS_STARTING = 0, // 正在启动
|
||||
SS_STARTED = 1, // 已经启动
|
||||
SS_STOPPING = 2, // 正在停止
|
||||
SS_STOPPED = 3, // 已经停止
|
||||
} En_HP_ServiceState;
|
||||
|
||||
/************************************************************************
|
||||
名称:Socket 操作类型
|
||||
描述:应用程序的 OnClose() 事件中通过该参数标识是哪种操作导致的错误
|
||||
************************************************************************/
|
||||
typedef enum EnSocketOperation
|
||||
{
|
||||
SO_UNKNOWN = 0, // Unknown
|
||||
SO_ACCEPT = 1, // Acccept
|
||||
SO_CONNECT = 2, // Connect
|
||||
SO_SEND = 3, // Send
|
||||
SO_RECEIVE = 4, // Receive
|
||||
SO_CLOSE = 5, // Close
|
||||
} En_HP_SocketOperation;
|
||||
|
||||
/************************************************************************
|
||||
名称:事件处理结果
|
||||
描述:事件的返回值,不同的返回值会影响通信组件的后续行为
|
||||
************************************************************************/
|
||||
typedef enum EnHandleResult
|
||||
{
|
||||
HR_OK = 0, // 成功
|
||||
HR_IGNORE = 1, // 忽略
|
||||
HR_ERROR = 2, // 错误
|
||||
} En_HP_HandleResult;
|
||||
|
||||
/************************************************************************
|
||||
名称:数据抓取结果
|
||||
描述:数据抓取操作的返回值
|
||||
************************************************************************/
|
||||
typedef enum EnFetchResult
|
||||
{
|
||||
FR_OK = 0, // 成功
|
||||
FR_LENGTH_TOO_LONG = 1, // 抓取长度过大
|
||||
FR_DATA_NOT_FOUND = 2, // 找不到 ConnID 对应的数据
|
||||
} En_HP_FetchResult;
|
||||
|
||||
/************************************************************************
|
||||
名称:数据发送策略
|
||||
描述:Server 组件和 Agent 组件的数据发送策略
|
||||
|
||||
* 打包发送策略(默认) :尽量把多个发送操作的数据组合在一起发送,增加传输效率
|
||||
* 安全发送策略 :尽量把多个发送操作的数据组合在一起发送,并控制传输速度,避免缓冲区溢出
|
||||
* 直接发送策略 :对每一个发送操作都直接投递,适用于负载不高但要求实时性较高的场合
|
||||
************************************************************************/
|
||||
typedef enum EnSendPolicy
|
||||
{
|
||||
SP_PACK = 0, // 打包模式(默认)
|
||||
SP_SAFE = 1, // 安全模式
|
||||
SP_DIRECT = 2, // 直接模式
|
||||
} En_HP_SendPolicy;
|
||||
|
||||
/************************************************************************
|
||||
名称:OnSend 事件同步策略
|
||||
描述:Server 组件和 Agent 组件的 OnSend 事件同步策略
|
||||
|
||||
* 不同步(默认) :不同步 OnSend 事件,可能同时触发 OnReceive 和 OnClose 事件
|
||||
* 同步 OnClose :只同步 OnClose 事件,可能同时触发 OnReceive 事件
|
||||
* 同步 OnReceive :(只用于 TCP 组件)同步 OnReceive 和 OnClose 事件,不可能同时触发 OnReceive 或 OnClose 事件
|
||||
************************************************************************/
|
||||
typedef enum EnOnSendSyncPolicy
|
||||
{
|
||||
OSSP_NONE = 0, // 不同步(默认)
|
||||
OSSP_CLOSE = 1, // 同步 OnClose
|
||||
OSSP_RECEIVE = 2, // 同步 OnReceive(只用于 TCP 组件)
|
||||
} En_HP_OnSendSyncPolicy;
|
||||
|
||||
/************************************************************************
|
||||
名称:地址重用选项
|
||||
描述:通信组件底层 socket 的地址重用选项
|
||||
************************************************************************/
|
||||
typedef enum EnReuseAddressPolicy
|
||||
{
|
||||
RAP_NONE = 0, // 不重用
|
||||
RAP_ADDR_ONLY = 1, // 仅重用地址
|
||||
RAP_ADDR_AND_PORT = 2, // 重用地址和端口
|
||||
} En_HP_ReuseAddressPolicy;
|
||||
|
||||
/************************************************************************
|
||||
名称:操作结果代码
|
||||
描述:组件 Start() / Stop() 方法执行失败时,可通过 GetLastError() 获取错误代码
|
||||
************************************************************************/
|
||||
typedef enum EnSocketError
|
||||
{
|
||||
SE_OK = NO_ERROR, // 成功
|
||||
SE_ILLEGAL_STATE = 1, // 当前状态不允许操作
|
||||
SE_INVALID_PARAM = 2, // 非法参数
|
||||
SE_SOCKET_CREATE = 3, // 创建 SOCKET 失败
|
||||
SE_SOCKET_BIND = 4, // 绑定 SOCKET 失败
|
||||
SE_SOCKET_PREPARE = 5, // 设置 SOCKET 失败
|
||||
SE_SOCKET_LISTEN = 6, // 监听 SOCKET 失败
|
||||
SE_CP_CREATE = 7, // 创建完成端口失败
|
||||
SE_WORKER_THREAD_CREATE = 8, // 创建工作线程失败
|
||||
SE_DETECT_THREAD_CREATE = 9, // 创建监测线程失败
|
||||
SE_SOCKE_ATTACH_TO_CP = 10, // 绑定完成端口失败
|
||||
SE_CONNECT_SERVER = 11, // 连接服务器失败
|
||||
SE_NETWORK = 12, // 网络错误
|
||||
SE_DATA_PROC = 13, // 数据处理错误
|
||||
SE_DATA_SEND = 14, // 数据发送失败
|
||||
SE_GC_START = 15, // 垃圾回收启动失败
|
||||
|
||||
/***** SSL Socket 扩展操作结果代码 *****/
|
||||
SE_SSL_ENV_NOT_READY = 101, // SSL 环境未就绪
|
||||
} En_HP_SocketError;
|
||||
|
||||
/************************************************************************
|
||||
名称:播送模式
|
||||
描述:UDP 组件的播送模式(组播或广播)
|
||||
************************************************************************/
|
||||
typedef enum EnCastMode
|
||||
{
|
||||
CM_UNICAST = -1, // 单播
|
||||
CM_MULTICAST = 0, // 组播
|
||||
CM_BROADCAST = 1, // 广播
|
||||
} En_HP_CastMode;
|
||||
|
||||
/************************************************************************
|
||||
名称:IP 地址类型
|
||||
描述:IP 地址类型枚举值
|
||||
************************************************************************/
|
||||
typedef enum EnIPAddrType
|
||||
{
|
||||
IPT_ALL = 0, // 所有
|
||||
IPT_IPV4 = 1, // IPv4
|
||||
IPT_IPV6 = 2, // IPv6
|
||||
} En_HP_IPAddrType;
|
||||
|
||||
/************************************************************************
|
||||
名称:IP 地址条目结构体
|
||||
描述:IP 地址的地址簇/地址值结构体
|
||||
************************************************************************/
|
||||
typedef struct TIPAddr
|
||||
{
|
||||
En_HP_IPAddrType type;
|
||||
LPCTSTR address;
|
||||
} *LPTIPAddr, HP_TIPAddr, *HP_LPTIPAddr;
|
||||
|
||||
/************************************************************************
|
||||
名称:缓冲区结构体
|
||||
描述:数据缓冲区
|
||||
************************************************************************/
|
||||
typedef struct _WSABUF
|
||||
{
|
||||
UINT len;
|
||||
LPBYTE buf;
|
||||
} WSABUF, *PWSABUF, *LPWSABUF;
|
||||
|
||||
/************************************************************************
|
||||
名称:拒绝策略
|
||||
描述:调用被拒绝后的处理策略
|
||||
************************************************************************/
|
||||
typedef enum EnRejectedPolicy
|
||||
{
|
||||
TRP_CALL_FAIL = 0, // 立刻返回失败
|
||||
TRP_WAIT_FOR = 1, // 等待(直到成功、超时或线程池关闭等原因导致失败)
|
||||
TRP_CALLER_RUN = 2, // 调用者线程直接执行
|
||||
} En_HP_RejectedPolicy;
|
||||
|
||||
/************************************************************************
|
||||
名称:任务缓冲区类型
|
||||
描述:TSockeTask 对象创建和销毁时,根据不同类型的缓冲区类型作不同的处理
|
||||
************************************************************************/
|
||||
typedef enum EnTaskBufferType
|
||||
{
|
||||
TBT_COPY = 0, // 深拷贝
|
||||
TBT_REFER = 1, // 浅拷贝
|
||||
TBT_ATTACH = 2, // 附属(不负责创建,但负责销毁)
|
||||
} En_HP_TaskBufferType;
|
||||
|
||||
/************************************************************************
|
||||
名称:任务处理函数
|
||||
描述:任务处理入口函数
|
||||
参数:pvArg -- 自定义参数
|
||||
返回值:(无)
|
||||
************************************************************************/
|
||||
typedef VOID (__HP_CALL *Fn_TaskProc)(PVOID pvArg);
|
||||
typedef Fn_TaskProc HP_Fn_TaskProc;
|
||||
|
||||
struct TSocketTask;
|
||||
|
||||
/************************************************************************
|
||||
名称:Socket 任务处理函数
|
||||
描述:Socket 任务处理入口函数
|
||||
参数:pTask -- Socket 任务结构体指针
|
||||
返回值:(无)
|
||||
************************************************************************/
|
||||
typedef VOID (__HP_CALL *Fn_SocketTaskProc)(struct TSocketTask* pTask);
|
||||
typedef Fn_SocketTaskProc HP_Fn_SocketTaskProc;
|
||||
|
||||
/************************************************************************
|
||||
名称:Socket 任务结构体
|
||||
描述:封装 Socket 任务相关数据结构
|
||||
************************************************************************/
|
||||
typedef struct TSocketTask
|
||||
{
|
||||
HP_Fn_SocketTaskProc fn; // 任务处理函数
|
||||
PVOID sender; // 发起对象
|
||||
CONNID connID; // 连接 ID
|
||||
LPCBYTE buf; // 数据缓冲区
|
||||
INT bufLen; // 数据缓冲区长度
|
||||
En_HP_TaskBufferType bufType; // 缓冲区类型
|
||||
WPARAM wparam; // 自定义参数
|
||||
LPARAM lparam; // 自定义参数
|
||||
} *LPTSocketTask, HP_TSocketTask, *HP_LPTSocketTask;
|
||||
|
||||
/************************************************************************
|
||||
名称:获取 HPSocket 版本号
|
||||
描述:版本号(4 个字节分别为:主版本号,子版本号,修正版本号,构建编号)
|
||||
************************************************************************/
|
||||
inline DWORD GetHPSocketVersion()
|
||||
{
|
||||
return (HP_VERSION_MAJOR << 24) | (HP_VERSION_MINOR << 16) | (HP_VERSION_REVISE << 8) | HP_VERSION_BUILD;
|
||||
}
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/**************************************************************** SSL Type Definitions ***************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
#ifdef _SSL_SUPPORT
|
||||
|
||||
/************************************************************************
|
||||
名称:SSL 工作模式
|
||||
描述:标识 SSL 的工作模式,客户端模式或服务端模式
|
||||
************************************************************************/
|
||||
typedef enum EnSSLSessionMode
|
||||
{
|
||||
SSL_SM_CLIENT = 0, // 客户端模式
|
||||
SSL_SM_SERVER = 1, // 服务端模式
|
||||
} En_HP_SSLSessionMode;
|
||||
|
||||
/************************************************************************
|
||||
名称:SSL 验证模式
|
||||
描述:SSL 验证模式选项,SSL_VM_PEER 可以和后面两个选项组合一起
|
||||
************************************************************************/
|
||||
typedef enum EnSSLVerifyMode
|
||||
{
|
||||
SSL_VM_NONE = 0x00, // SSL_VERIFY_NONE
|
||||
SSL_VM_PEER = 0x01, // SSL_VERIFY_PEER
|
||||
SSL_VM_FAIL_IF_NO_PEER_CERT = 0x02, // SSL_VERIFY_FAIL_IF_NO_PEER_CERT
|
||||
SSL_VM_CLIENT_ONCE = 0x04, // SSL_VERIFY_CLIENT_ONCE
|
||||
} En_HP_SSLVerifyMode;
|
||||
|
||||
/************************************************************************
|
||||
名称:SSL Session 信息类型
|
||||
描述:用于 GetSSLSessionInfo(),标识输出的 Session 信息类型
|
||||
************************************************************************/
|
||||
typedef enum EnSSLSessionInfo
|
||||
{
|
||||
SSL_SSI_MIN = 0, //
|
||||
SSL_SSI_CTX = 0, // SSL CTX (输出类型:SSL_CTX*)
|
||||
SSL_SSI_CTX_METHOD = 1, // SSL CTX Mehtod (输出类型:SSL_METHOD*)
|
||||
SSL_SSI_CTX_CIPHERS = 2, // SSL CTX Ciphers (输出类型:STACK_OF(SSL_CIPHER)*)
|
||||
SSL_SSI_CTX_CERT_STORE = 3, // SSL CTX Cert Store (输出类型:X509_STORE*)
|
||||
SSL_SSI_SERVER_NAME_TYPE = 4, // Server Name Type (输出类型:int)
|
||||
SSL_SSI_SERVER_NAME = 5, // Server Name (输出类型:LPCSTR)
|
||||
SSL_SSI_VERSION = 6, // SSL Version (输出类型:LPCSTR)
|
||||
SSL_SSI_METHOD = 7, // SSL Method (输出类型:SSL_METHOD*)
|
||||
SSL_SSI_CERT = 8, // SSL Cert (输出类型:X509*)
|
||||
SSL_SSI_PKEY = 9, // SSL Private Key (输出类型:EVP_PKEY*)
|
||||
SSL_SSI_CURRENT_CIPHER = 10, // SSL Current Cipher (输出类型:SSL_CIPHER*)
|
||||
SSL_SSI_CIPHERS = 11, // SSL Available Ciphers(输出类型:STACK_OF(SSL_CIPHER)*)
|
||||
SSL_SSI_CLIENT_CIPHERS = 12, // SSL Client Ciphers (输出类型:STACK_OF(SSL_CIPHER)*)
|
||||
SSL_SSI_PEER_CERT = 13, // SSL Peer Cert (输出类型:X509*)
|
||||
SSL_SSI_PEER_CERT_CHAIN = 14, // SSL Peer Cert Chain (输出类型:STACK_OF(X509)*)
|
||||
SSL_SSI_VERIFIED_CHAIN = 15, // SSL Verified Chain (输出类型:STACK_OF(X509)*)
|
||||
SSL_SSI_MAX = 15, //
|
||||
} En_HP_SSLSessionInfo;
|
||||
|
||||
/************************************************************************
|
||||
名称:SNI 服务名称回调函数
|
||||
描述:根据服务器名称选择 SSL 证书
|
||||
参数:
|
||||
lpszServerName -- 服务器名称(域名)
|
||||
|
||||
返回值:
|
||||
0 -- 成功,使用默认 SSL 证书索引
|
||||
正数 -- 成功,使用返回值对应的 SNI 主机证书索引
|
||||
负数 -- 失败,中断 SSL 握手
|
||||
|
||||
************************************************************************/
|
||||
typedef int (__HP_CALL *Fn_SNI_ServerNameCallback)(LPCTSTR lpszServerName, PVOID pContext);
|
||||
typedef Fn_SNI_ServerNameCallback HP_Fn_SNI_ServerNameCallback;
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/**************************************************************** HTTP Type Definitions **************************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
#ifdef _HTTP_SUPPORT
|
||||
|
||||
/************************************************************************
|
||||
名称:HTTP 版本
|
||||
描述:低字节:主版本号,高字节:次版本号
|
||||
************************************************************************/
|
||||
|
||||
typedef enum EnHttpVersion
|
||||
{
|
||||
HV_1_0 = MAKEWORD(1, 0), // HTTP/1.0
|
||||
HV_1_1 = MAKEWORD(1, 1) // HTTP/1.1
|
||||
} En_HP_HttpVersion;
|
||||
|
||||
/************************************************************************
|
||||
名称:URL 域
|
||||
描述:HTTP 请求行中 URL 段位的域定义
|
||||
************************************************************************/
|
||||
typedef enum EnHttpUrlField
|
||||
{
|
||||
HUF_SCHEMA = 0, // Schema
|
||||
HUF_HOST = 1, // Host
|
||||
HUF_PORT = 2, // Port
|
||||
HUF_PATH = 3, // Path
|
||||
HUF_QUERY = 4, // Query String
|
||||
HUF_FRAGMENT = 5, // Fragment
|
||||
HUF_USERINFO = 6, // User Info
|
||||
HUF_MAX = 7, // (Field Count)
|
||||
} En_HP_HttpUrlField;
|
||||
|
||||
/************************************************************************
|
||||
名称:HTTP 解析结果标识
|
||||
描述:指示 HTTP 解析器是否继续执行解析操作
|
||||
************************************************************************/
|
||||
typedef enum EnHttpParseResult
|
||||
{
|
||||
HPR_OK = 0, // 解析成功
|
||||
HPR_SKIP_BODY = 1, // 跳过当前请求 BODY(仅用于 OnHeadersComplete 事件)
|
||||
HPR_UPGRADE = 2, // 升级协议(仅用于 OnHeadersComplete 事件)
|
||||
HPR_ERROR = -1, // 解析错误,终止解析,断开连接
|
||||
} En_HP_HttpParseResult;
|
||||
|
||||
/************************************************************************
|
||||
名称:HTTP 协议升级类型
|
||||
描述:标识 HTTP 升级为哪种协议
|
||||
************************************************************************/
|
||||
typedef enum EnHttpUpgradeType
|
||||
{
|
||||
HUT_NONE = 0, // 没有升级
|
||||
HUT_WEB_SOCKET = 1, // WebSocket
|
||||
HUT_HTTP_TUNNEL = 2, // HTTP 隧道
|
||||
HUT_UNKNOWN = -1, // 未知类型
|
||||
} En_HP_HttpUpgradeType;
|
||||
|
||||
/************************************************************************
|
||||
名称:HTTP 状态码
|
||||
描述:HTTP 标准状态码
|
||||
************************************************************************/
|
||||
typedef enum EnHttpStatusCode
|
||||
{
|
||||
HSC_CONTINUE = 100,
|
||||
HSC_SWITCHING_PROTOCOLS = 101,
|
||||
HSC_PROCESSING = 102,
|
||||
HSC_EARLY_HINTS = 103,
|
||||
HSC_RESPONSE_IS_STALE = 110,
|
||||
HSC_REVALIDATION_FAILED = 111,
|
||||
HSC_DISCONNECTED_OPERATION = 112,
|
||||
HSC_HEURISTIC_EXPIRATION = 113,
|
||||
HSC_MISCELLANEOUS_WARNING = 199,
|
||||
|
||||
HSC_OK = 200,
|
||||
HSC_CREATED = 201,
|
||||
HSC_ACCEPTED = 202,
|
||||
HSC_NON_AUTHORITATIVE_INFORMATION = 203,
|
||||
HSC_NO_CONTENT = 204,
|
||||
HSC_RESET_CONTENT = 205,
|
||||
HSC_PARTIAL_CONTENT = 206,
|
||||
HSC_MULTI_STATUS = 207,
|
||||
HSC_ALREADY_REPORTED = 208,
|
||||
HSC_TRANSFORMATION_APPLIED = 214,
|
||||
HSC_IM_USED = 226,
|
||||
HSC_MISCELLANEOUS_PERSISTENT_WARNING = 299,
|
||||
|
||||
HSC_MULTIPLE_CHOICES = 300,
|
||||
HSC_MOVED_PERMANENTLY = 301,
|
||||
HSC_MOVED_TEMPORARILY = 302,
|
||||
HSC_SEE_OTHER = 303,
|
||||
HSC_NOT_MODIFIED = 304,
|
||||
HSC_USE_PROXY = 305,
|
||||
HSC_SWITCH_PROXY = 306,
|
||||
HSC_TEMPORARY_REDIRECT = 307,
|
||||
HSC_PERMANENT_REDIRECT = 308,
|
||||
|
||||
HSC_BAD_REQUEST = 400,
|
||||
HSC_UNAUTHORIZED = 401,
|
||||
HSC_PAYMENT_REQUIRED = 402,
|
||||
HSC_FORBIDDEN = 403,
|
||||
HSC_NOT_FOUND = 404,
|
||||
HSC_METHOD_NOT_ALLOWED = 405,
|
||||
HSC_NOT_ACCEPTABLE = 406,
|
||||
HSC_PROXY_AUTHENTICATION_REQUIRED = 407,
|
||||
HSC_REQUEST_TIMEOUT = 408,
|
||||
HSC_CONFLICT = 409,
|
||||
HSC_GONE = 410,
|
||||
HSC_LENGTH_REQUIRED = 411,
|
||||
HSC_PRECONDITION_FAILED = 412,
|
||||
HSC_REQUEST_ENTITY_TOO_LARGE = 413,
|
||||
HSC_REQUEST_URI_TOO_LONG = 414,
|
||||
HSC_UNSUPPORTED_MEDIA_TYPE = 415,
|
||||
HSC_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
||||
HSC_EXPECTATION_FAILED = 417,
|
||||
HSC_IM_A_TEAPOT = 418,
|
||||
HSC_PAGE_EXPIRED = 419,
|
||||
HSC_ENHANCE_YOUR_CALM = 420,
|
||||
HSC_MISDIRECTED_REQUEST = 421,
|
||||
HSC_UNPROCESSABLE_ENTITY = 422,
|
||||
HSC_LOCKED = 423,
|
||||
HSC_FAILED_DEPENDENCY = 424,
|
||||
HSC_UNORDERED_COLLECTION = 425,
|
||||
HSC_UPGRADE_REQUIRED = 426,
|
||||
HSC_PRECONDITION_REQUIRED = 428,
|
||||
HSC_TOO_MANY_REQUESTS = 429,
|
||||
HSC_REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL = 430,
|
||||
HSC_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
||||
HSC_LOGIN_TIMEOUT = 440,
|
||||
HSC_NO_RESPONSE = 444,
|
||||
HSC_RETRY_WITH = 449,
|
||||
HSC_BLOCKED_BY_PARENTAL_CONTROL = 450,
|
||||
HSC_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
||||
HSC_CLIENT_CLOSED_LOAD_BALANCED_REQUEST = 460,
|
||||
HSC_INVALID_X_FORWARDED_FOR = 463,
|
||||
HSC_REQUEST_HEADER_TOO_LARGE = 494,
|
||||
HSC_SSL_CERTIFICATE_ERROR = 495,
|
||||
HSC_SSL_CERTIFICATE_REQUIRED = 496,
|
||||
HSC_HTTP_REQUEST_SENT_TO_HTTPS_PORT = 497,
|
||||
HSC_INVALID_TOKEN = 498,
|
||||
HSC_CLIENT_CLOSED_REQUEST = 499,
|
||||
|
||||
HSC_INTERNAL_SERVER_ERROR = 500,
|
||||
HSC_NOT_IMPLEMENTED = 501,
|
||||
HSC_BAD_GATEWAY = 502,
|
||||
HSC_SERVICE_UNAVAILABLE = 503,
|
||||
HSC_GATEWAY_TIMEOUT = 504,
|
||||
HSC_HTTP_VERSION_NOT_SUPPORTED = 505,
|
||||
HSC_VARIANT_ALSO_NEGOTIATES = 506,
|
||||
HSC_INSUFFICIENT_STORAGE = 507,
|
||||
HSC_LOOP_DETECTED = 508,
|
||||
HSC_BANDWIDTH_LIMIT_EXCEEDED = 509,
|
||||
HSC_NOT_EXTENDED = 510,
|
||||
HSC_NETWORK_AUTHENTICATION_REQUIRED = 511,
|
||||
HSC_WEB_SERVER_UNKNOWN_ERROR = 520,
|
||||
HSC_WEB_SERVER_IS_DOWN = 521,
|
||||
HSC_CONNECTION_TIMEOUT = 522,
|
||||
HSC_ORIGIN_IS_UNREACHABLE = 523,
|
||||
HSC_TIMEOUT_OCCURED = 524,
|
||||
HSC_SSL_HANDSHAKE_FAILED = 525,
|
||||
HSC_INVALID_SSL_CERTIFICATE = 526,
|
||||
HSC_RAILGUN_ERROR = 527,
|
||||
HSC_SITE_IS_OVERLOADED = 529,
|
||||
HSC_SITE_IS_FROZEN = 530,
|
||||
HSC_IDENTITY_PROVIDER_AUTHENTICATION_ERROR = 561,
|
||||
HSC_NETWORK_READ_TIMEOUT = 598,
|
||||
HSC_NETWORK_CONNECT_TIMEOUT = 599,
|
||||
|
||||
HSC_UNPARSEABLE_RESPONSE_HEADERS = 600
|
||||
} En_HP_HttpStatusCode;
|
||||
|
||||
/************************************************************************
|
||||
名称:Name/Value 结构体
|
||||
描述:字符串名值对结构体
|
||||
************************************************************************/
|
||||
typedef struct TNVPair
|
||||
{
|
||||
LPCSTR name;
|
||||
LPCSTR value;
|
||||
} HP_TNVPair,
|
||||
TParam, HP_TParam, *LPPARAM, *HP_LPPARAM,
|
||||
THeader, HP_THeader, *LPHEADER, *HP_LPHEADER,
|
||||
TCookie, HP_TCookie, *LPCOOKIE, *HP_LPCOOKIE;
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************************************************************************************/
|
||||
/********************************************************** Compress / Decompress Definitions ********************************************************/
|
||||
/*****************************************************************************************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
名称:数据回调函数
|
||||
描述:回调处理过程中产生的数据输出
|
||||
参数:
|
||||
pData -- 数据缓冲区
|
||||
iLength -- 数据长度
|
||||
pContext -- 回调上下文
|
||||
|
||||
返回值:
|
||||
TRUE -- 成功
|
||||
FALSE -- 失败
|
||||
|
||||
************************************************************************/
|
||||
typedef BOOL (__HP_CALL *Fn_DataCallback)(const BYTE* pData, int iLength, PVOID pContext);
|
||||
typedef Fn_DataCallback Fn_CompressDataCallback;
|
||||
typedef Fn_DataCallback Fn_DecompressDataCallback;
|
||||
typedef Fn_DataCallback HP_Fn_DataCallback;
|
||||
typedef Fn_DataCallback HP_Fn_CompressDataCallback;
|
||||
typedef Fn_DataCallback HP_Fn_DecompressDataCallback;
|
||||
3114
hpsocket/SocketInterface.h
Normal file
3114
hpsocket/SocketInterface.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user