home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / Vcl / psock.hpp < prev    next >
C/C++ Source or Header  |  2000-02-01  |  16KB  |  473 lines

  1. // Borland C++ Builder
  2. // Copyright (c) 1995, 1999 by Borland International
  3. // All rights reserved
  4.  
  5. // (DO NOT EDIT: machine generated header) 'Psock.pas' rev: 5.00
  6.  
  7. #ifndef PsockHPP
  8. #define PsockHPP
  9.  
  10. #pragma delphiheader begin
  11. #pragma option push -w-
  12. #pragma option push -Vx
  13. #include <NMConst.hpp>    // Pascal unit
  14. #include <Windows.hpp>    // Pascal unit
  15. #include <StdCtrls.hpp>    // Pascal unit
  16. #include <Forms.hpp>    // Pascal unit
  17. #include <Messages.hpp>    // Pascal unit
  18. #include <ExtCtrls.hpp>    // Pascal unit
  19. #include <SysUtils.hpp>    // Pascal unit
  20. #include <Classes.hpp>    // Pascal unit
  21. #include <WinSock.hpp>    // Pascal unit
  22. #include <SysInit.hpp>    // Pascal unit
  23. #include <System.hpp>    // Pascal unit
  24.  
  25. //-- user supplied -----------------------------------------------------------
  26.  
  27. namespace Psock
  28. {
  29. //-- type declarations -------------------------------------------------------
  30. typedef Word TSocket;
  31.  
  32. struct TErrorMessage
  33. {
  34.     int ErrorCode;
  35.     System::SmallString<50>  Text;
  36. } ;
  37.  
  38. class DELPHICLASS TNMReg;
  39. class PASCALIMPLEMENTATION TNMReg : public System::TObject 
  40. {
  41.     typedef System::TObject inherited;
  42.     
  43. public:
  44.     #pragma option push -w-inl
  45.     /* TObject.Create */ inline __fastcall TNMReg(void) : System::TObject() { }
  46.     #pragma option pop
  47.     #pragma option push -w-inl
  48.     /* TObject.Destroy */ inline __fastcall virtual ~TNMReg(void) { }
  49.     #pragma option pop
  50.     
  51. };
  52.  
  53.  
  54. typedef void __fastcall (__closure *TOnErrorEvent)(Classes::TComponent* Sender, Word Errno, AnsiString 
  55.     Errmsg);
  56.  
  57. typedef void __fastcall (__closure *TOnHostResolved)(Classes::TComponent* Sender);
  58.  
  59. typedef void __fastcall (__closure *TOnStatus)(Classes::TComponent* Sender, AnsiString Status);
  60.  
  61. typedef void __fastcall (__closure *THandlerEvent)(bool &Handled);
  62.  
  63. typedef int *PLongint;
  64.  
  65. typedef PLongint *PPLongInt;
  66.  
  67. typedef char * *PPChar;
  68.  
  69. typedef Windows::PInteger *PINT;
  70.  
  71. struct THostInfo
  72. {
  73.     char *name;
  74.     char * *AliasList;
  75.     int AddressType;
  76.     int AddressSize;
  77.     PLongint *AddressList;
  78.     char Reserved[1024];
  79. } ;
  80.  
  81. struct TServerInfo
  82. {
  83.     char *name;
  84.     char * *Aliases;
  85.     int PORT;
  86.     char *Protocol;
  87.     char Reserved[1024];
  88. } ;
  89.  
  90. struct TProtocolInfo
  91. {
  92.     char *name;
  93.     char * *Aliases;
  94.     int ProtocolID;
  95.     char Reserved[1024];
  96. } ;
  97.  
  98. struct TSocketAddress
  99. {
  100.     int Family;
  101.     Word PORT;
  102.     int Address;
  103.     char Unused[8];
  104. } ;
  105.  
  106. struct TSocketList
  107. {
  108.     int Count;
  109.     int DescriptorList[64];
  110. } ;
  111.  
  112. struct TTimeValue
  113. {
  114.     int Sec;
  115.     int uSec;
  116. } ;
  117.  
  118. typedef WSAData *PWSAData;
  119.  
  120. typedef THostInfo *PHostInfo;
  121.  
  122. typedef TServerInfo *PServerInfo;
  123.  
  124. typedef TProtocolInfo *PProtocolInfo;
  125.  
  126. typedef TSocketAddress *PSocketAddress;
  127.  
  128. typedef TSocketList *PSocketList;
  129.  
  130. typedef TTimeValue *PTimeValue;
  131.  
  132. class DELPHICLASS ESockError;
  133. class PASCALIMPLEMENTATION ESockError : public Sysutils::Exception 
  134. {
  135.     typedef Sysutils::Exception inherited;
  136.     
  137. public:
  138.     #pragma option push -w-inl
  139.     /* Exception.Create */ inline __fastcall ESockError(const AnsiString Msg) : Sysutils::Exception(Msg
  140.         ) { }
  141.     #pragma option pop
  142.     #pragma option push -w-inl
  143.     /* Exception.CreateFmt */ inline __fastcall ESockError(const AnsiString Msg, const System::TVarRec 
  144.         * Args, const int Args_Size) : Sysutils::Exception(Msg, Args, Args_Size) { }
  145.     #pragma option pop
  146.     #pragma option push -w-inl
  147.     /* Exception.CreateRes */ inline __fastcall ESockError(int Ident)/* overload */ : Sysutils::Exception(
  148.         Ident) { }
  149.     #pragma option pop
  150.     #pragma option push -w-inl
  151.     /* Exception.CreateResFmt */ inline __fastcall ESockError(int Ident, const System::TVarRec * Args, 
  152.         const int Args_Size)/* overload */ : Sysutils::Exception(Ident, Args, Args_Size) { }
  153.     #pragma option pop
  154.     #pragma option push -w-inl
  155.     /* Exception.CreateHelp */ inline __fastcall ESockError(const AnsiString Msg, int AHelpContext) : Sysutils::Exception(
  156.         Msg, AHelpContext) { }
  157.     #pragma option pop
  158.     #pragma option push -w-inl
  159.     /* Exception.CreateFmtHelp */ inline __fastcall ESockError(const AnsiString Msg, const System::TVarRec 
  160.         * Args, const int Args_Size, int AHelpContext) : Sysutils::Exception(Msg, Args, Args_Size, AHelpContext
  161.         ) { }
  162.     #pragma option pop
  163.     #pragma option push -w-inl
  164.     /* Exception.CreateResHelp */ inline __fastcall ESockError(int Ident, int AHelpContext)/* overload */
  165.          : Sysutils::Exception(Ident, AHelpContext) { }
  166.     #pragma option pop
  167.     #pragma option push -w-inl
  168.     /* Exception.CreateResFmtHelp */ inline __fastcall ESockError(System::PResStringRec ResStringRec, const 
  169.         System::TVarRec * Args, const int Args_Size, int AHelpContext)/* overload */ : Sysutils::Exception(
  170.         ResStringRec, Args, Args_Size, AHelpContext) { }
  171.     #pragma option pop
  172.     
  173. public:
  174.     #pragma option push -w-inl
  175.     /* TObject.Destroy */ inline __fastcall virtual ~ESockError(void) { }
  176.     #pragma option pop
  177.     
  178. };
  179.  
  180.  
  181. class DELPHICLASS EAbortError;
  182. class PASCALIMPLEMENTATION EAbortError : public ESockError 
  183. {
  184.     typedef ESockError inherited;
  185.     
  186. public:
  187.     #pragma option push -w-inl
  188.     /* Exception.Create */ inline __fastcall EAbortError(const AnsiString Msg) : ESockError(Msg) { }
  189.     #pragma option pop
  190.     #pragma option push -w-inl
  191.     /* Exception.CreateFmt */ inline __fastcall EAbortError(const AnsiString Msg, const System::TVarRec 
  192.         * Args, const int Args_Size) : ESockError(Msg, Args, Args_Size) { }
  193.     #pragma option pop
  194.     #pragma option push -w-inl
  195.     /* Exception.CreateRes */ inline __fastcall EAbortError(int Ident)/* overload */ : ESockError(Ident
  196.         ) { }
  197.     #pragma option pop
  198.     #pragma option push -w-inl
  199.     /* Exception.CreateResFmt */ inline __fastcall EAbortError(int Ident, const System::TVarRec * Args, 
  200.         const int Args_Size)/* overload */ : ESockError(Ident, Args, Args_Size) { }
  201.     #pragma option pop
  202.     #pragma option push -w-inl
  203.     /* Exception.CreateHelp */ inline __fastcall EAbortError(const AnsiString Msg, int AHelpContext) : 
  204.         ESockError(Msg, AHelpContext) { }
  205.     #pragma option pop
  206.     #pragma option push -w-inl
  207.     /* Exception.CreateFmtHelp */ inline __fastcall EAbortError(const AnsiString Msg, const System::TVarRec 
  208.         * Args, const int Args_Size, int AHelpContext) : ESockError(Msg, Args, Args_Size, AHelpContext) { }
  209.         
  210.     #pragma option pop
  211.     #pragma option push -w-inl
  212.     /* Exception.CreateResHelp */ inline __fastcall EAbortError(int Ident, int AHelpContext)/* overload */
  213.          : ESockError(Ident, AHelpContext) { }
  214.     #pragma option pop
  215.     #pragma option push -w-inl
  216.     /* Exception.CreateResFmtHelp */ inline __fastcall EAbortError(System::PResStringRec ResStringRec, 
  217.         const System::TVarRec * Args, const int Args_Size, int AHelpContext)/* overload */ : ESockError(ResStringRec
  218.         , Args, Args_Size, AHelpContext) { }
  219.     #pragma option pop
  220.     
  221. public:
  222.     #pragma option push -w-inl
  223.     /* TObject.Destroy */ inline __fastcall virtual ~EAbortError(void) { }
  224.     #pragma option pop
  225.     
  226. };
  227.  
  228.  
  229. class DELPHICLASS TThreadTimer;
  230. class PASCALIMPLEMENTATION TThreadTimer : public Classes::TComponent 
  231. {
  232.     typedef Classes::TComponent inherited;
  233.     
  234. private:
  235.     unsigned FInterval;
  236.     HWND FWindowHandle;
  237.     Classes::TNotifyEvent FOnTimer;
  238.     bool FEnabled;
  239.     void __fastcall UpdateTimer(void);
  240.     void __fastcall SetEnabled(bool Value);
  241.     void __fastcall SetInterval(unsigned Value);
  242.     void __fastcall SetOnTimer(Classes::TNotifyEvent Value);
  243.     void __fastcall Wndproc(Messages::TMessage &Msg);
  244.     
  245. protected:
  246.     DYNAMIC void __fastcall Timer(void);
  247.     
  248. public:
  249.     __fastcall virtual TThreadTimer(Classes::TComponent* AOwner);
  250.     __fastcall virtual ~TThreadTimer(void);
  251.     
  252. __published:
  253.     __property bool Enabled = {read=FEnabled, write=SetEnabled, default=1};
  254.     __property unsigned Interval = {read=FInterval, write=SetInterval, default=1000};
  255.     __property Classes::TNotifyEvent OnTimer = {read=FOnTimer, write=SetOnTimer};
  256. };
  257.  
  258.  
  259. class DELPHICLASS TPowersock;
  260. class PASCALIMPLEMENTATION TPowersock : public Classes::TComponent 
  261. {
  262.     typedef Classes::TComponent inherited;
  263.     
  264. private:
  265.     char Buf[65537];
  266.     TNMReg* FAbout;
  267.     Classes::TNotifyEvent FOnReadEvent;
  268.     Classes::TNotifyEvent FOnAcceptEvent;
  269.     Classes::TNotifyEvent FOnConnect;
  270.     Classes::TNotifyEvent FOnDisconnect;
  271.     TOnErrorEvent FOnErrorEvent;
  272.     THandlerEvent FInvalidHost;
  273.     TOnHostResolved FOnHostResolved;
  274.     THandlerEvent FOnConnectionRequired;
  275.     TOnStatus FOnStatus;
  276.     Classes::TNotifyEvent FOnConnectionFailed;
  277.     Classes::TStringList* FWSAInfo;
  278.     int FBytesSent;
  279.     bool Canceled;
  280.     bool DestroySocket;
  281.     int FLastErrorno;
  282.     int FTimeOut;
  283.     int FReportLevel;
  284.     AnsiString _Status;
  285.     AnsiString FProxy;
  286.     int FProxyPort;
  287.     TThreadTimer* Timer;
  288.     void __fastcall TimerFired(System::TObject* Sender);
  289.     void __fastcall Wndproc(Messages::TMessage &message);
  290.     
  291. protected:
  292.     bool Succeed;
  293.     bool TimedOut;
  294.     int FPort;
  295.     int FBytesTotal;
  296.     int FBytesRecvd;
  297.     Classes::TNotifyEvent FPacketRecvd;
  298.     Classes::TNotifyEvent FPacketSent;
  299.     bool Wait_Flag;
  300.     WSAData MyWSAData;
  301.     sockaddr_in RemoteAddress;
  302.     AnsiString ServerName;
  303.     hostent *RemoteHost;
  304.     AnsiString FTransactionReply;
  305.     short FReplyNumber;
  306.     bool DataGate;
  307.     bool AbortGate;
  308.     bool StrmType;
  309.     Classes::TNotifyEvent OnAbortrestart;
  310.     void __fastcall TimerOn(void);
  311.     void __fastcall TimerOff(void);
  312.     void __fastcall InitWinsock(void);
  313.     void __fastcall SetLastErrorNo(int Value);
  314.     AnsiString __fastcall SocketErrorStr(Word Errno);
  315.     int __fastcall GetLastErrorNo(void);
  316.     AnsiString __fastcall ErrorManager(Word Ignore);
  317.     void __fastcall SetWSAError(Word ErrorNo, AnsiString ErrorMsg);
  318.     void __fastcall StatusMessage(Byte Level, AnsiString Value);
  319.     AnsiString __fastcall GetRemoteIP();
  320.     AnsiString __fastcall GetLocalIP();
  321.     __property Classes::TNotifyEvent OnAccept = {read=FOnAcceptEvent, write=FOnAcceptEvent};
  322.     __property TOnErrorEvent OnError = {read=FOnErrorEvent, write=FOnErrorEvent};
  323.     __property THandlerEvent OnConnectionRequired = {read=FOnConnectionRequired, write=FOnConnectionRequired
  324.         };
  325.     __property AnsiString Proxy = {read=FProxy, write=FProxy};
  326.     __property int ProxyPort = {read=FProxyPort, write=FProxyPort, nodefault};
  327.     
  328. public:
  329.     Word ThisSocket;
  330.     HWND FSocketWindow;
  331.     bool FConnected;
  332.     __fastcall virtual TPowersock(Classes::TComponent* AOwner);
  333.     __fastcall virtual ~TPowersock(void);
  334.     virtual Word __fastcall Accept(void);
  335.     void __fastcall Cancel(void);
  336.     virtual void __fastcall Connect(void);
  337.     virtual void __fastcall Disconnect(void);
  338.     void __fastcall Listen(bool sync);
  339.     void __fastcall SendBuffer(char * Value, Word BufLen);
  340.     void __fastcall Write(AnsiString Value);
  341.     void __fastcall Writeln(AnsiString Value);
  342.     AnsiString __fastcall Read(Word Value);
  343.     AnsiString __fastcall ReadLn();
  344.     virtual AnsiString __fastcall Transaction(const AnsiString CommandString);
  345.     void __fastcall SendFile(AnsiString Filename);
  346.     void __fastcall SendStream(Classes::TStream* MainStream);
  347.     void __fastcall CaptureFile(AnsiString Filename);
  348.     void __fastcall AppendFile(AnsiString Filename);
  349.     void __fastcall CaptureStream(Classes::TStream* MainStream, int Size);
  350.     void __fastcall CaptureString(AnsiString &AString, int Size);
  351.     void __fastcall FilterHeader(Classes::TFileStream* HeaderStream);
  352.     void __fastcall ResolveRemoteHost(void);
  353.     void __fastcall RequestCloseSocket(void);
  354.     void __fastcall Close(unsigned Socket);
  355.     virtual void __fastcall Abort(void);
  356.     void __fastcall CertifyConnect(void);
  357.     bool __fastcall DataAvailable(void);
  358.     void __fastcall ClearInput(void);
  359.     AnsiString __fastcall GetLocalAddress();
  360.     AnsiString __fastcall GetPortString();
  361.     __property Classes::TStringList* WSAInfo = {read=FWSAInfo};
  362.     __property bool Connected = {read=FConnected, nodefault};
  363.     __property int LastErrorNo = {read=GetLastErrorNo, write=SetLastErrorNo, nodefault};
  364.     __property bool BeenCanceled = {read=Canceled, write=Canceled, nodefault};
  365.     __property bool BeenTimedOut = {read=TimedOut, nodefault};
  366.     __property short ReplyNumber = {read=FReplyNumber, nodefault};
  367.     __property AnsiString RemoteIP = {read=GetRemoteIP};
  368.     __property AnsiString LocalIP = {read=GetLocalIP};
  369.     __property AnsiString TransactionReply = {read=FTransactionReply};
  370.     __property int BytesTotal = {read=FBytesTotal, nodefault};
  371.     __property int BytesSent = {read=FBytesSent, nodefault};
  372.     __property int BytesRecvd = {read=FBytesRecvd, nodefault};
  373.     __property Word Handle = {read=ThisSocket, nodefault};
  374.     __property AnsiString Status = {read=_Status};
  375.     __property Classes::TNotifyEvent OnRead = {read=FOnReadEvent, write=FOnReadEvent};
  376.     __property Classes::TNotifyEvent OnPacketRecvd = {read=FPacketRecvd, write=FPacketRecvd};
  377.     __property Classes::TNotifyEvent OnPacketSent = {read=FPacketSent, write=FPacketSent};
  378.     
  379. __published:
  380.     __property AnsiString Host = {read=ServerName, write=ServerName};
  381.     __property int Port = {read=FPort, write=FPort, nodefault};
  382.     __property int TimeOut = {read=FTimeOut, write=FTimeOut, default=0};
  383.     __property int ReportLevel = {read=FReportLevel, write=FReportLevel, default=1};
  384.     __property Classes::TNotifyEvent OnDisconnect = {read=FOnDisconnect, write=FOnDisconnect};
  385.     __property Classes::TNotifyEvent OnConnect = {read=FOnConnect, write=FOnConnect};
  386.     __property THandlerEvent OnInvalidHost = {read=FInvalidHost, write=FInvalidHost};
  387.     __property TOnHostResolved OnHostResolved = {read=FOnHostResolved, write=FOnHostResolved};
  388.     __property TOnStatus OnStatus = {read=FOnStatus, write=FOnStatus};
  389.     __property Classes::TNotifyEvent OnConnectionFailed = {read=FOnConnectionFailed, write=FOnConnectionFailed
  390.         };
  391.     __property TNMReg* About = {read=FAbout, write=FAbout};
  392. };
  393.  
  394.  
  395. class DELPHICLASS TNMGeneralServer;
  396. typedef TNMGeneralServer* *PTNMGeneralServer;
  397.  
  398. class PASCALIMPLEMENTATION TNMGeneralServer : public TPowersock 
  399. {
  400.     typedef TPowersock inherited;
  401.     
  402. private:
  403.     Classes::TThreadList* ATlist;
  404.     Classes::TNotifyEvent FOnClientContact;
  405.     
  406. protected:
  407.     TNMGeneralServer* Chief;
  408.     
  409. public:
  410.     Classes::TThread* ItsThread;
  411.     __fastcall virtual TNMGeneralServer(Classes::TComponent* AOwner);
  412.     virtual void __fastcall Connect(void);
  413.     virtual void __fastcall Loaded(void);
  414.     virtual void __fastcall Serve(void);
  415.     virtual void __fastcall Abort(void);
  416.     __fastcall virtual ~TNMGeneralServer(void);
  417.     void __fastcall ServerAccept(System::TObject* Sender);
  418.     
  419. __published:
  420.     __property Classes::TNotifyEvent OnClientContact = {read=FOnClientContact, write=FOnClientContact};
  421.         
  422. };
  423.  
  424.  
  425. class DELPHICLASS InstantiateServethread;
  426. class PASCALIMPLEMENTATION InstantiateServethread : public Classes::TThread 
  427. {
  428.     typedef Classes::TThread inherited;
  429.     
  430. private:
  431.     TNMGeneralServer* ServSock;
  432.     
  433. protected:
  434.     virtual void __fastcall Execute(void);
  435.     
  436. public:
  437.     __fastcall InstantiateServethread(Classes::TComponent* Owner, Word ItsSocket);
  438.     __fastcall virtual ~InstantiateServethread(void);
  439. };
  440.  
  441.  
  442. //-- var, const, procedure ---------------------------------------------------
  443. static const Shortint FD_ALL = 0x3f;
  444. static const int MAX_RECV_BUF = 0x10000;
  445. static const Shortint Status_None = 0x0;
  446. static const Shortint Status_Informational = 0x1;
  447. static const Shortint Status_Basic = 0x2;
  448. static const Shortint Status_Routines = 0x4;
  449. static const Shortint Status_Debug = 0x8;
  450. static const Shortint Status_Trace = 0x10;
  451. static const char CR = '\xd';
  452. static const char LF = '\xa';
  453. #define CRLF "\r\n"
  454. static const Word WM_ASYNCHRONOUSPROCESS = 0x465;
  455. static const Word WM_WAITFORRESPONSE = 0x466;
  456. extern PACKAGE TErrorMessage WinsockMessage[51];
  457. extern PACKAGE AnsiString __fastcall NthWord(AnsiString InputString, char Delimiter, int Number);
  458. extern PACKAGE int __fastcall NthPos(AnsiString InputString, char Delimiter, int Number);
  459. extern PACKAGE void __fastcall StreamLn(Classes::TStream* AStream, AnsiString AString);
  460. extern PACKAGE HWND __fastcall PsockAllocateHWnd(System::TObject* Obj);
  461. extern PACKAGE HWND __fastcall TmrAllocateHWnd(System::TObject* Obj);
  462.  
  463. }    /* namespace Psock */
  464. #if !defined(NO_IMPLICIT_NAMESPACE_USE)
  465. using namespace Psock;
  466. #endif
  467. #pragma option pop    // -w-
  468. #pragma option pop    // -Vx
  469.  
  470. #pragma delphiheader end.
  471. //-- end unit ----------------------------------------------------------------
  472. #endif    // Psock
  473.