📄 httport.pas
字号:
unit HTTPortDLLDefs;
interface
uses Windows, Winsock, Classes, SysUtils, HTTPortGlobalsU, HTTPortQueueU,
HTTPortMappingU, HTTPortHTTPU, HTTPortBase64U;
//------------------------------------------------------------------------------
// retcode constants
const H_SUCCESS = 0;
const H_ERROR_BASE = $10000;
const H_ERROR_WINSOCK_FAILED = H_ERROR_BASE;
const H_ERROR_ALREADY_STARTED = H_ERROR_BASE + 1;
const H_ERROR_NOT_STARTED = H_ERROR_BASE + 2;
const H_ERROR_NO_FREE_SLOTS = H_ERROR_BASE + 3;
const H_ERROR_UNKNOWN_OPTION = H_ERROR_BASE + 4;
const H_ERROR_INVALID_PARAMETER = H_ERROR_BASE + 5;
// h_setoption constants
const H_OPTION_BASE = $20000;
const H_OPTION_HOST_LIST = H_OPTION_BASE;
const H_OPTION_USER_INFO = H_OPTION_BASE + 1;
const H_OPTION_PROXY = H_OPTION_BASE + 2;
const H_OPTION_DATA_OVERRIDE = H_OPTION_BASE + 3;
// connection mode constants
const CONN_USE_AUTO = 0;
const CONN_USE_CONNECT = 1;
const CONN_USE_REMOTE = 2;
//------------------------------------------------------------------------------
// type definitions
type TRetCode = Cardinal;
type TMappingParameters = record // this structure is passed to H_CreateMapping
intStrucSize: Integer;
// [in] Must be set to sizeof(TMappingParameters)
wLocalPort: Word;
// [in] Local port to listen.
ptrRemoteHost: PChar;
// [in] Pointer to ASCIIZ string with mapped host name or IP.
wRemotePort: Word;
// [in] Mapped host port.
intAllowLocalOnly: Integer;
// [in] If not zero, the listening port will be bound to 127.0.0.1.
intMode: Integer;
// [in] Proxy bypass mode, one of CONN_USE_... constants.
intMappingId: Integer;
// [out] Returns the index for the newly created mapping.
// Pass this value later to H_GetMappingStats and H_DestroyMapping.
end;
type PMappingParameters = ^TMappingParameters;
type TOptions = array [0..$ffff] of Pointer; // structure for passing list of pointers to ASCIIZ strings to H_SetOption
POptions = ^TOptions;
type TMappingStats = record // this structure is passed to H_GetMappingStats
intStrucSize: Integer;
// [in] Must be set to sizeof(TMappingStats).
intConnections: Integer;
// [out] Current number of open connections to this tunnel.
intKBytesTransferred: Integer;
// [out] KBytes transferred through this tunnel since it's been created.
intSockErrors: Integer;
// [out] WinSock errors returned from send(), recv() etc.
// Results in single client disconnect.
// Severity: Low
intHostErrors: Integer;
// [out] HTTHost reported the internal protocol error.
// This happens all the time, so this field may safely be ignored.
// Severity: Very Low
intTimeoutErrors: Integer;
// [out] Client or proxy timed out on send() or recv().
// Default timeout to wait on sending or receiving WinSock data is 30 sec.
// Results in single client disconnect.
// Severity: Medium
intProtocolErrors: Integer;
// [out] HTTHost protocol errors.
// Should never happen.
// Severity: Unknown
intMemoryErrors: Integer;
// [out] Memory allocation failed.
// Should normally not happen.
// Severity: High
intConnectErrors: Integer;
// [out] Proxy returned something else other than "200 OK" on CONNECT.
// CONNECT is assumed to be not supported.
// In case the mapping was created with Auto mode,
// it automatically switches to "Remote Host" mode,
// and retries the connection attempt via the HTTHost.
// In case the mapping was created with CONNECT mode,
// the connection is closed.
// Severity: Medium
intOtherErrors: Integer;
// [out] Miscellaneous errors, like proxy responded
// with something incompatible with HTTP, etc.
// Should not normally happen.
// Severity: Unknown
intFatalErrors: Integer;
// [out] socket(), bind(), listen(), or accept() failed,
// proxy was not resolved or connect() to proxy failed.
// This basically means the mapping was not properly
// initialized. This will happen in case somebody
// is already listening the specified local port,
// or the proxy is unavailable.
// Severity: High
end;
type PMappingStats = ^TMappingStats;
type TProxyStats = record // this structure is passed to H_GetHTTPStats
intStrucSize: Integer;
// [in] Must be set to sizeof(TProxyStats).
intProxyFaults: Integer;
// [out] The proxy was unavailable or failed or whatever.
// This field only makes sense if CONN_USE_REMOTE is used.
// Otherwise it's zero.
// Severity: Medium to High
intHostFaults: Integer;
// [out] Proxy reported that HTTHost was not found where specified.
// This field only makes sense if CONN_USE_REMOTE is used.
// Otherwise it's zero.
// Severity: High
intCurrentMode: Integer;
// [out] The bypass mode currently in use.
// This will return the common denominator for the modes used
// by all mappings - that is, if any of the mapping uses
// "remote host" mode, the result returned in this field
// will be CONN_USE_REMOTE.
// This is only of use when you specify CONN_USE_AUTO with
// mappings you create. In that case check this field on
// shutdown to see which mode is actually supported. In case
// the mapping is created with CONN_USE_AUTO against the
// proxy which does not support CONNECT, it will be switched to
// CONN_USE_REMOTE automatically. Otherwise it will remain CONN_USE_AUTO.
// Use it on shutdown and save the value, so next time you
// pass it to H_CreateMapping(TMappingParameters.intMode) so that the
// mappings will not even try CONNECT attempts.
intDataOverride: Integer;
// [out] This will most probably contain 0, which means that the proxy
// is HTTP compatible enough, and the default method of sending
// data along with GET request is used, which is adding a separate
// request header field.
// In case the proxy (like eServ) is not fully HTTP compatible or
// just blocks unknown request header fields for some reason, this will contain
// a value > 0 which is a number of bytes to be sent within an URL
// as an alternative way of sending data.
// Use it on shutdown and save the value, so next time you
// pass it to H_SetOption(H_OPTION_DATA_OVERRIDE) and the
// library won't even try the default way of sending data.
// In case you start with H_SetOption(H_OPTION_DATA_OVERRIDE = 0),
// the attempt to use header fields will be taken, for it allows
// to send more data with a single request. If this attempt fails,
// the library will switch to default non-zero value (256 bytes).
// If possible, data override should be zero. If not, it's not
// recommended to set it to values higher than 512, because
// the URL will just be too long, and the proxy may block it.
end;
type PProxyStats = ^TProxyStats;
//------------------------------------------------------------------------------
// function declarations
type PCardinal = ^Cardinal;
function H_Start: TRetCode; stdcall;
function H_SetOption(const intOption: Integer; const intCount: Integer; const ptrParams: POptions): TRetCode; stdcall;
function H_CreateMapping(const ptrParams: PMappingParameters): TRetCode; stdcall;
function H_GetListeningPort(const intIndex: Integer; const ptrResult: PCardinal): TRetCode; stdcall;
function H_GetMappingStats(const intIndex: Integer; const ptrStats: PMappingStats): TRetCode; stdcall;
function H_GetProxyStats(const ptrStats: PProxyStats): TRetCode; stdcall;
function H_DestroyMapping(const intIndex: Integer): TRetCode; stdcall;
function H_Stop: TRetCode; stdcall;
//------------------------------------------------------------------------------
implementation
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -