* Added wxsocket lib and sample (I hope I don't forget some file)
* Updated some wx data and makefiles * Updates on wxStream (reorganization) makefile for Windows will nearly follow wxSocket should work on wxGTK (I've tested it) * IPC over Network is included git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@684 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <wx/stream.h>
|
||||
|
||||
class wxDataInputStream: public wxFilterInputStream {
|
||||
class wxDataInputStream: virtual public wxFilterInputStream {
|
||||
public:
|
||||
wxDataInputStream(wxInputStream& s);
|
||||
virtual ~wxDataInputStream();
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
wxString ReadString();
|
||||
};
|
||||
|
||||
class wxDataOutputStream: public wxFilterOutputStream {
|
||||
class wxDataOutputStream: virtual public wxFilterOutputStream {
|
||||
public:
|
||||
wxDataOutputStream(wxOutputStream& s);
|
||||
virtual ~wxDataOutputStream();
|
||||
@@ -44,5 +44,11 @@ class wxDataOutputStream: public wxFilterOutputStream {
|
||||
void WriteString(const wxString& string);
|
||||
};
|
||||
|
||||
class wxDataStream: public wxDataInputStream, public wxDataOutputStream,
|
||||
public wxFilterStream {
|
||||
public:
|
||||
wxDataStream(wxStream& stream);
|
||||
};
|
||||
|
||||
#endif
|
||||
// _WX_DATSTREAM_H_
|
||||
|
||||
@@ -22,7 +22,8 @@ protected:
|
||||
bool m_file_destroy;
|
||||
};
|
||||
|
||||
class wxFileInputStream: public wxInputStream, virtual public wxFileStreamBase {
|
||||
class wxFileInputStream: virtual public wxInputStream,
|
||||
virtual public wxFileStreamBase {
|
||||
public:
|
||||
wxFileInputStream(const wxString& fileName);
|
||||
virtual ~wxFileInputStream();
|
||||
@@ -39,7 +40,8 @@ class wxFileInputStream: public wxInputStream, virtual public wxFileStreamBase {
|
||||
off_t DoTellInput() const;
|
||||
};
|
||||
|
||||
class wxFileOutputStream: public wxOutputStream, virtual public wxFileStreamBase {
|
||||
class wxFileOutputStream: virtual public wxOutputStream,
|
||||
virtual public wxFileStreamBase {
|
||||
public:
|
||||
wxFileOutputStream(const wxString& fileName);
|
||||
virtual ~wxFileOutputStream();
|
||||
@@ -60,7 +62,8 @@ class wxFileOutputStream: public wxOutputStream, virtual public wxFileStreamBase
|
||||
off_t DoTellOutput() const;
|
||||
};
|
||||
|
||||
class wxFileStream: public wxFileInputStream, public wxFileOutputStream {
|
||||
class wxFileStream: public wxStream,
|
||||
public wxFileInputStream, public wxFileOutputStream {
|
||||
public:
|
||||
wxFileStream(const wxString& fileName);
|
||||
virtual ~wxFileStream();
|
||||
|
||||
35
include/wx/protocol/file.h
Normal file
35
include/wx/protocol/file.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: file.h
|
||||
// Purpose: File protocol
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __WX_PROTO_FILE_H__
|
||||
#define __WX_PROTO_FILE_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sckfile.h"
|
||||
#endif
|
||||
|
||||
#include "wx/protocol/protocol.h"
|
||||
#include "wx/url.h"
|
||||
|
||||
class WXDLLEXPORT wxFileProto: public wxProtocol {
|
||||
DECLARE_DYNAMIC_CLASS(wxFileProto)
|
||||
DECLARE_PROTOCOL(wxFileProto)
|
||||
protected:
|
||||
wxProtocolError m_error;
|
||||
public:
|
||||
wxFileProto();
|
||||
~wxFileProto();
|
||||
|
||||
wxProtocolError GetError() { return m_error; }
|
||||
bool Abort() { return TRUE; }
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
};
|
||||
|
||||
#endif
|
||||
74
include/wx/protocol/ftp.h
Normal file
74
include/wx/protocol/ftp.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: ftp.h
|
||||
// Purpose: FTP protocol
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 07/07/1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __WX_FTP_H__
|
||||
#define __WX_FTP_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/object.h"
|
||||
#include "wx/sckaddr.h"
|
||||
#include "wx/protocol/protocol.h"
|
||||
#include "wx/url.h"
|
||||
|
||||
class WXDLLEXPORT wxFTP : public wxProtocol {
|
||||
DECLARE_DYNAMIC_CLASS(wxFTP)
|
||||
DECLARE_PROTOCOL(wxFTP)
|
||||
public:
|
||||
typedef enum { ASCII, BINARY } wxFTPmode;
|
||||
|
||||
wxFTP();
|
||||
~wxFTP();
|
||||
|
||||
bool Close();
|
||||
bool Connect(wxSockAddress& addr);
|
||||
bool Connect(const wxString& host);
|
||||
|
||||
void SetUser(const wxString& user) { m_user = user; }
|
||||
void SetPassword(const wxString& passwd) { m_passwd = passwd; }
|
||||
|
||||
// Low-level methods
|
||||
bool SendCommand(const wxString& command, char exp_ret);
|
||||
inline virtual wxProtocolError GetError()
|
||||
{ return m_lastError; }
|
||||
const wxString& GetLastResult(); // Get the complete return
|
||||
|
||||
// Filesystem commands
|
||||
bool ChDir(const wxString& dir);
|
||||
bool MkDir(const wxString& dir);
|
||||
bool RmDir(const wxString& dir);
|
||||
wxString Pwd();
|
||||
bool Rename(const wxString& src, const wxString& dst);
|
||||
bool RmFile(const wxString& path);
|
||||
|
||||
// Download methods
|
||||
bool Abort();
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
wxOutputStream *GetOutputStream(const wxString& path);
|
||||
|
||||
// List method
|
||||
wxList *GetList(const wxString& wildcard);
|
||||
|
||||
protected:
|
||||
wxString m_user, m_passwd;
|
||||
wxString m_lastResult;
|
||||
wxProtocolError m_lastError;
|
||||
bool m_streaming;
|
||||
|
||||
friend class wxInputFTPStream;
|
||||
friend class wxOutputFTPStream;
|
||||
|
||||
wxSocketClient *GetPort();
|
||||
bool GetResult(char exp);
|
||||
};
|
||||
|
||||
#endif
|
||||
48
include/wx/protocol/http.h
Normal file
48
include/wx/protocol/http.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: http.h
|
||||
// Purpose: HTTP protocol
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: August 1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_HTTP_H
|
||||
#define _WX_HTTP_H
|
||||
|
||||
#include "wx/list.h"
|
||||
#include "wx/protocol/protocol.h"
|
||||
|
||||
class WXDLLEXPORT wxHTTP : public wxProtocol {
|
||||
DECLARE_DYNAMIC_CLASS(wxHTTP)
|
||||
DECLARE_PROTOCOL(wxHTTP)
|
||||
protected:
|
||||
wxProtocolError m_perr;
|
||||
wxList m_headers;
|
||||
bool m_read;
|
||||
wxSockAddress *m_addr;
|
||||
public:
|
||||
wxHTTP();
|
||||
~wxHTTP();
|
||||
|
||||
bool Connect(const wxString& host);
|
||||
bool Connect(wxSockAddress& addr);
|
||||
bool Abort();
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
inline wxProtocolError GetError() { return m_perr; }
|
||||
wxString GetContentType();
|
||||
|
||||
void SetHeader(const wxString& header, const wxString& h_data);
|
||||
wxString GetHeader(const wxString& header);
|
||||
|
||||
protected:
|
||||
typedef enum {
|
||||
wxHTTP_GET
|
||||
} wxHTTP_Req;
|
||||
bool BuildRequest(const wxString& path, wxHTTP_Req req);
|
||||
void SendHeaders();
|
||||
bool ParseHeaders();
|
||||
};
|
||||
|
||||
#endif
|
||||
79
include/wx/protocol/protocol.h
Normal file
79
include/wx/protocol/protocol.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: protocol.h
|
||||
// Purpose: Protocol base class
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 10/07/1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_PROTOCOL_PROTOCOL_H
|
||||
#define _WX_PROTOCOL_PROTOCOL_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/object.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/stream.h"
|
||||
#include "wx/socket.h"
|
||||
|
||||
typedef enum {
|
||||
wxPROTO_NOERR = 0,
|
||||
wxPROTO_NETERR,
|
||||
wxPROTO_PROTERR,
|
||||
wxPROTO_CONNERR,
|
||||
wxPROTO_INVVAL,
|
||||
wxPROTO_NOHNDLR,
|
||||
wxPROTO_NOFILE,
|
||||
wxPROTO_ABRT,
|
||||
wxPROTO_RCNCT,
|
||||
wxPROTO_STREAMING
|
||||
} wxProtocolError;
|
||||
|
||||
// For protocols
|
||||
#define DECLARE_PROTOCOL(class) \
|
||||
public: \
|
||||
static wxProtoInfo g_proto_##class;
|
||||
|
||||
#define IMPLEMENT_PROTOCOL(class, name, serv, host) \
|
||||
wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class));
|
||||
|
||||
class WXDLLEXPORT wxProtoInfo : public wxObject {
|
||||
DECLARE_DYNAMIC_CLASS(wxProtoInfo)
|
||||
protected:
|
||||
wxProtoInfo *next;
|
||||
wxString m_protoname;
|
||||
wxString prefix;
|
||||
wxString m_servname;
|
||||
wxClassInfo *m_cinfo;
|
||||
bool m_needhost;
|
||||
|
||||
friend class wxURL;
|
||||
public:
|
||||
wxProtoInfo(const char *name, const char *serv_name, const bool need_host1,
|
||||
wxClassInfo *info);
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxProtocol : public wxSocketClient {
|
||||
DECLARE_ABSTRACT_CLASS(wxProtocol)
|
||||
public:
|
||||
wxProtocol();
|
||||
|
||||
bool Reconnect();
|
||||
virtual bool Connect(const wxString& host) { return FALSE; }
|
||||
virtual bool Connect(wxSockAddress& addr) { return wxSocketClient::Connect(addr); }
|
||||
|
||||
virtual bool Abort() = 0;
|
||||
virtual wxInputStream *GetInputStream(const wxString& path) = 0;
|
||||
virtual wxProtocolError GetError() = 0;
|
||||
virtual wxString GetContentType() { return (char *)NULL; }
|
||||
virtual void SetUser(const wxString& user) {}
|
||||
virtual void SetPassword(const wxString& passwd) {}
|
||||
};
|
||||
|
||||
wxProtocolError WXDLLEXPORT GetLine(wxSocketBase *sock, wxString& result);
|
||||
|
||||
#endif
|
||||
136
include/wx/sckaddr.h
Normal file
136
include/wx/sckaddr.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sckaddr.h
|
||||
// Purpose: Network address classes
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 26/04/1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_NETWORK_ADDRESS_H
|
||||
#define _WX_NETWORK_ADDRESS_H
|
||||
|
||||
#if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
|
||||
#include <winsock.h>
|
||||
|
||||
#elif defined(__UNIX__) && defined(WXSOCK_INTERNAL)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#ifdef WXPREC
|
||||
#include <wx/wxprec.h>
|
||||
#else
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
class WXDLLEXPORT wxSockAddress : public wxObject {
|
||||
DECLARE_ABSTRACT_CLASS(wxSockAddress)
|
||||
public:
|
||||
typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr;
|
||||
|
||||
wxSockAddress() {};
|
||||
virtual ~wxSockAddress() {};
|
||||
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual void Build(struct sockaddr*& addr, size_t& len) = 0;
|
||||
virtual void Disassemble(struct sockaddr *addr, size_t len) = 0;
|
||||
virtual int SockAddrLen() = 0;
|
||||
|
||||
virtual int GetFamily() = 0;
|
||||
virtual int Type() = 0;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxIPV4address : public wxSockAddress {
|
||||
DECLARE_DYNAMIC_CLASS(wxIPV4address)
|
||||
private:
|
||||
struct sockaddr_in *m_addr;
|
||||
public:
|
||||
wxIPV4address();
|
||||
virtual ~wxIPV4address();
|
||||
|
||||
virtual void Clear();
|
||||
// const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
virtual bool Hostname(const wxString& name);
|
||||
virtual bool Hostname(unsigned long addr);
|
||||
virtual bool Service(const wxString& name);
|
||||
virtual bool Service(unsigned short port);
|
||||
virtual bool LocalHost();
|
||||
|
||||
wxString Hostname();
|
||||
unsigned short Service();
|
||||
|
||||
void Build(struct sockaddr*& addr, size_t& len);
|
||||
void Disassemble(struct sockaddr *addr, size_t len);
|
||||
|
||||
inline int SockAddrLen();
|
||||
inline int GetFamily();
|
||||
inline int Type() { return wxSockAddress::IPV4; }
|
||||
};
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
class WXDLLEXPORT wxIPV6address : public wxSockAddress {
|
||||
DECLARE_DYNAMIC_CLASS(wxIPV6address)
|
||||
private:
|
||||
struct sockaddr_in6 *m_addr;
|
||||
public:
|
||||
wxIPV6address();
|
||||
~wxIPV6address();
|
||||
|
||||
void Clear();
|
||||
// const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
bool Hostname(const wxString& name);
|
||||
bool Hostname(unsigned char addr[16]);
|
||||
bool Service(const wxString& name);
|
||||
bool Service(unsigned short port);
|
||||
bool LocalHost();
|
||||
|
||||
wxString Hostname() const;
|
||||
unsigned short Service() const;
|
||||
|
||||
void Build(struct sockaddr*& addr, size_t& len);
|
||||
void Disassemble(struct sockaddr *addr, size_t len);
|
||||
|
||||
inline int SockAddrLen();
|
||||
inline int GetFamily();
|
||||
inline int Type() { return wxSockAddress::IPV6; }
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __UNIX__
|
||||
#include <sys/un.h>
|
||||
|
||||
class WXDLLEXPORT wxUNIXaddress : public wxSockAddress {
|
||||
DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
|
||||
private:
|
||||
struct sockaddr_un *m_addr;
|
||||
public:
|
||||
wxUNIXaddress();
|
||||
~wxUNIXaddress();
|
||||
|
||||
void Clear();
|
||||
// const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
void Filename(const wxString& name);
|
||||
wxString Filename();
|
||||
|
||||
void Build(struct sockaddr*& addr, size_t& len);
|
||||
void Disassemble(struct sockaddr *addr, size_t len);
|
||||
|
||||
inline int SockAddrLen();
|
||||
inline int GetFamily();
|
||||
inline int Type() { return wxSockAddress::UNIX; }
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
132
include/wx/sckipc.h
Normal file
132
include/wx/sckipc.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sckipc.h
|
||||
// Purpose: Interprocess communication
|
||||
// Author: Julian Smart/Guilhem Lavaux (big rewrite)
|
||||
// Modified by: Guilhem Lavaux 1997
|
||||
// Created: 1993
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1993 Julian Smart
|
||||
// (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_SCKIPC_H
|
||||
#define _WX_SCKIPC_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/setup.h"
|
||||
#include "wx/ipcbase.h"
|
||||
#include "wx/socket.h"
|
||||
#include "wx/sckstrm.h"
|
||||
#include "wx/datstrm.h"
|
||||
|
||||
/*
|
||||
* Mini-DDE implementation
|
||||
|
||||
Most transactions involve a topic name and an item name (choose these
|
||||
as befits your application).
|
||||
|
||||
A client can:
|
||||
|
||||
- ask the server to execute commands (data) associated with a topic
|
||||
- request data from server by topic and item
|
||||
- poke data into the server
|
||||
- ask the server to start an advice loop on topic/item
|
||||
- ask the server to stop an advice loop
|
||||
|
||||
A server can:
|
||||
|
||||
- respond to execute, request, poke and advice start/stop
|
||||
- send advise data to client
|
||||
|
||||
Note that this limits the server in the ways it can send data to the
|
||||
client, i.e. it can't send unsolicited information.
|
||||
*
|
||||
*/
|
||||
|
||||
class wxTCPServer;
|
||||
class wxTCPClient;
|
||||
class wxTCPConnection: public wxConnectionBase
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxTCPConnection)
|
||||
|
||||
protected:
|
||||
wxSocketBase *m_sock;
|
||||
wxSocketStream *m_sockstrm;
|
||||
wxDataStream *m_codec;
|
||||
wxString m_topic;
|
||||
|
||||
friend class wxTCPServer;
|
||||
friend class wxTCPClient;
|
||||
friend void Client_OnRequest(wxSocketBase&,
|
||||
wxSocketBase::wxRequestEvent, char *);
|
||||
friend void Server_OnRequest(wxSocketServer&,
|
||||
wxSocketBase::wxRequestEvent, char *);
|
||||
public:
|
||||
|
||||
wxTCPConnection(char *buffer, int size);
|
||||
wxTCPConnection();
|
||||
virtual ~wxTCPConnection();
|
||||
|
||||
// Calls that CLIENT can make
|
||||
bool Execute(char *data, int size = -1,
|
||||
wxDataFormat format = wxDF_TEXT);
|
||||
char *Request(const wxString& item, int *size = NULL,
|
||||
wxDataFormat format = wxDF_TEXT);
|
||||
bool Poke(const wxString& item, char *data, int size = -1,
|
||||
wxDataFormat format = wxDF_TEXT);
|
||||
bool StartAdvise(const wxString& item);
|
||||
bool StopAdvise(const wxString& item);
|
||||
|
||||
// Calls that SERVER can make
|
||||
bool Advise(const wxString& item, char *data, int size = -1,
|
||||
wxDataFormat format = wxDF_TEXT);
|
||||
|
||||
// Calls that both can make
|
||||
bool Disconnect();
|
||||
|
||||
// Called when we lost the peer.
|
||||
bool OnDisconnect() { return TRUE; }
|
||||
|
||||
// To enable the compressor
|
||||
void Compress(bool on);
|
||||
};
|
||||
|
||||
class wxTCPServer: public wxServerBase
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxTCPServer)
|
||||
|
||||
public:
|
||||
wxTCPConnection *topLevelConnection;
|
||||
|
||||
wxTCPServer();
|
||||
virtual ~wxTCPServer();
|
||||
|
||||
// Returns FALSE if can't create server (e.g. port number is already in use)
|
||||
virtual bool Create(const wxString& server_name);
|
||||
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
|
||||
};
|
||||
|
||||
class wxTCPClient: public wxClientBase
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxTCPClient)
|
||||
|
||||
public:
|
||||
wxTCPClient();
|
||||
virtual ~wxTCPClient();
|
||||
|
||||
virtual bool ValidHost(const wxString& host);
|
||||
// Call this to make a connection.
|
||||
// Returns NULL if cannot.
|
||||
virtual wxConnectionBase *MakeConnection(const wxString& host,
|
||||
const wxString& server,
|
||||
const wxString& topic);
|
||||
|
||||
// Tailor this to return own connection.
|
||||
virtual wxConnectionBase *OnMakeConnection();
|
||||
};
|
||||
|
||||
#endif // ipcsock.h
|
||||
62
include/wx/sckstrm.h
Normal file
62
include/wx/sckstrm.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sckstrm.h
|
||||
// Purpose: wxSocket*Stream
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 17/07/97
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __SCK_STREAM_H__
|
||||
#define __SCK_STREAM_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/stream.h"
|
||||
#include "wx/socket.h"
|
||||
|
||||
class WXDLLEXPORT wxSocketOutputStream : public wxOutputStream
|
||||
{
|
||||
public:
|
||||
wxSocketOutputStream(wxSocketBase& s);
|
||||
virtual ~wxSocketOutputStream();
|
||||
|
||||
wxOutputStream& Write(const void *buffer, size_t size);
|
||||
off_t SeekO(off_t pos, wxSeekMode mode) { return -1; }
|
||||
off_t TellO() { return -1; }
|
||||
|
||||
bool Bad() { return m_o_socket->IsDisconnected(); }
|
||||
size_t LastWrite() { return m_o_socket->LastCount(); }
|
||||
protected:
|
||||
wxSocketBase *m_o_socket;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxSocketInputStream : public wxInputStream
|
||||
{
|
||||
public:
|
||||
wxSocketInputStream(wxSocketBase& s);
|
||||
~wxSocketInputStream();
|
||||
|
||||
wxInputStream& Read(void *buffer, size_t size);
|
||||
off_t SeekI(off_t pos, wxSeekMode mode) { return -1; }
|
||||
off_t TellI() { return -1; }
|
||||
|
||||
bool Eof() { return m_i_socket->IsDisconnected(); }
|
||||
size_t LastRead() { return m_i_socket->LastCount(); }
|
||||
protected:
|
||||
wxSocketBase *m_i_socket;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxSocketStream : public wxSocketInputStream,
|
||||
public wxSocketOutputStream,
|
||||
public wxStream {
|
||||
|
||||
public:
|
||||
wxSocketStream(wxSocketBase& i_s, wxSocketBase& o_s);
|
||||
wxSocketStream(wxSocketBase& s);
|
||||
};
|
||||
|
||||
#endif
|
||||
336
include/wx/socket.h
Normal file
336
include/wx/socket.h
Normal file
@@ -0,0 +1,336 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: socket.h
|
||||
// Purpose: Socket handling classes
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: April 1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_NETWORK_SOCKET_H
|
||||
#define _WX_NETWORK_SOCKET_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Windows(tm) specific
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
|
||||
#include <winsock.h>
|
||||
#include <wx/msw/private.h>
|
||||
|
||||
struct wxSockInternal {
|
||||
UINT my_msg;
|
||||
};
|
||||
|
||||
struct wxSockHandlerInternal {
|
||||
HWND sockWin;
|
||||
UINT firstAvailableMsg;
|
||||
};
|
||||
#endif // defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Unix specific
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__UNIX__) && defined(WXSOCK_INTERNAL)
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Athena specific
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__WXXT__) || defined(__WXMOTIF__)
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
struct wxSockInternal {
|
||||
XtInputId sock_inputid, sock_outputid, sock_exceptid;
|
||||
};
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GTK specific
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__WXGTK__)
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
struct wxSockInternal {
|
||||
gint sock_inputid, sock_outputid, sock_exceptid;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // defined(__UNIX__) && defined(WXSOCK_INTERNAL)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxSocket headers (generic)
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifdef WXPREC
|
||||
#include <wx/wxprec.h>
|
||||
#else
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
#include "wx/sckaddr.h"
|
||||
|
||||
class WXDLLEXPORT wxSocketEvent;
|
||||
class WXDLLEXPORT wxSocketHandler;
|
||||
class WXDLLEXPORT wxSocketBase : public wxEvtHandler
|
||||
{
|
||||
DECLARE_CLASS(wxSocketBase)
|
||||
public:
|
||||
|
||||
enum wxSockFlags { NONE=0, NOWAIT=1, WAITALL=2, SPEED=4 };
|
||||
// Type of request
|
||||
enum { REQ_READ=0x1, REQ_PEEK=0x2, REQ_WRITE=0x4, REQ_LOST=0x8,
|
||||
REQ_ACCEPT=0x10, REQ_CONNECT=0x20};
|
||||
enum { EVT_READ=0, EVT_PEEK=1, EVT_WRITE=2, EVT_LOST=3, EVT_ACCEPT=4,
|
||||
EVT_CONNECT=5 };
|
||||
|
||||
typedef int wxRequestNotify;
|
||||
typedef int wxRequestEvent;
|
||||
typedef void (*wxSockCbk)(wxSocketBase& sock,wxRequestEvent evt,char *cdata);
|
||||
|
||||
protected:
|
||||
wxList req_list[EVT_WRITE+1];
|
||||
|
||||
// Internal use for SaveState() and RestoreState()
|
||||
class wxSockState : public wxObject {
|
||||
public:
|
||||
bool cbk_on;
|
||||
wxSockCbk cbk;
|
||||
char *cdata;
|
||||
bool notif;
|
||||
wxRequestNotify cbk_set;
|
||||
wxSockFlags flags;
|
||||
};
|
||||
typedef struct {
|
||||
char sig[4];
|
||||
char len[4];
|
||||
} SockMsg;
|
||||
enum wxSockType { SOCK_CLIENT, SOCK_SERVER, SOCK_INTERNAL, SOCK_UNINIT };
|
||||
|
||||
wxSockFlags m_flags;
|
||||
wxSockType m_type; // wxSocket type
|
||||
bool m_connected, m_connecting; // State of the socket
|
||||
int m_fd; // Socket file descriptors
|
||||
int m_waitflags; // Wait flags
|
||||
wxList m_states; // States list
|
||||
wxSockCbk m_cbk; // C callback
|
||||
char *m_cdata; // C callback data
|
||||
int m_id; // Socket id (for event handler)
|
||||
wxSocketHandler *m_handler; // the current socket handler
|
||||
wxRequestNotify m_neededreq; // Specify which requet signals we need
|
||||
bool m_cbkon;
|
||||
char *m_unread; // The unread buf
|
||||
size_t m_unrd_size; // The size of the unread buf
|
||||
bool m_processing; // To prevent some endless loop
|
||||
unsigned long m_timeout;
|
||||
int m_wantbuf;
|
||||
size_t m_lcount; // Last IO request size
|
||||
int m_error; // Last IO error
|
||||
bool m_notifyme;
|
||||
|
||||
struct wxSockInternal *m_internal; // System specific variables
|
||||
|
||||
public:
|
||||
wxSocketBase();
|
||||
virtual ~wxSocketBase();
|
||||
virtual bool Close();
|
||||
|
||||
// Base IO
|
||||
wxSocketBase& Peek(char* buffer, size_t nbytes);
|
||||
wxSocketBase& Read(char* buffer, size_t nbytes);
|
||||
wxSocketBase& Write(const char *buffer, size_t nbytes);
|
||||
wxSocketBase& WriteMsg(const char *buffer, size_t nbytes);
|
||||
wxSocketBase& ReadMsg(char* buffer, size_t nbytes);
|
||||
wxSocketBase& Unread(const char *buffer, size_t nbytes);
|
||||
void Discard();
|
||||
|
||||
// Try not to use this two methods (they sould be protected)
|
||||
void CreatePushbackAfter(const char *buffer, size_t size);
|
||||
void CreatePushbackBefore(const char *buffer, size_t size);
|
||||
|
||||
// Status
|
||||
inline bool Ok() const { return (m_fd < 0 ? 0 : 1); };
|
||||
inline bool Error() const { return (m_error != 0); };
|
||||
inline bool IsConnected() const { return m_connected; };
|
||||
inline bool IsDisconnected() const { return !IsConnected(); };
|
||||
inline bool IsNoWait() const { return m_flags & NOWAIT; };
|
||||
bool IsData() const;
|
||||
inline size_t LastCount() const { return m_lcount; }
|
||||
inline int LastError() const { return m_error; }
|
||||
|
||||
inline void SetFlags(wxSockFlags _flags);
|
||||
inline void SetTimeout(unsigned long sec) { m_timeout = sec; }
|
||||
|
||||
// seconds = -1 means infinite wait
|
||||
// seconds = 0 means no wait
|
||||
// seconds > 0 means specified wait
|
||||
bool Wait(long seconds = -1, long microseconds = 0);
|
||||
bool WaitForRead(long seconds = -1, long microseconds = 0);
|
||||
bool WaitForWrite(long seconds = -1, long microseconds = 0);
|
||||
bool WaitForLost(long seconds = -1, long microseconds = 0);
|
||||
|
||||
// Save the current state of Socket
|
||||
void SaveState();
|
||||
void RestoreState();
|
||||
|
||||
// Setup external callback
|
||||
wxSockCbk Callback(wxSockCbk cbk_);
|
||||
char *CallbackData(char *data);
|
||||
|
||||
// Setup event handler
|
||||
void SetEventHandler(wxEvtHandler& evt_hdlr, int id = -1);
|
||||
|
||||
// Method called when it happens something on the socket
|
||||
void SetNotify(wxRequestNotify flags);
|
||||
virtual void OnRequest(wxRequestEvent req_evt);
|
||||
|
||||
// Public internal callback
|
||||
virtual void OldOnNotify(wxRequestEvent WXUNUSED(evt));
|
||||
|
||||
// Some info on the socket...
|
||||
virtual bool GetPeer(wxSockAddress& addr_man) const;
|
||||
virtual bool GetLocal(wxSockAddress& addr_man) const;
|
||||
|
||||
// Install or uninstall callbacks
|
||||
void Notify(bool notify);
|
||||
|
||||
// So you can know what the socket driver is looking for ...
|
||||
inline wxRequestNotify NeededReq() const { return m_neededreq; }
|
||||
|
||||
static wxRequestNotify EventToNotify(wxRequestEvent evt);
|
||||
|
||||
protected:
|
||||
friend class wxSocketServer;
|
||||
friend class wxSocketHandler;
|
||||
|
||||
wxSocketBase(wxSockFlags flags, wxSockType type);
|
||||
|
||||
bool _Wait(long seconds, long microseconds, int type);
|
||||
|
||||
// Set "my" handler
|
||||
inline virtual void SetHandler(wxSocketHandler *handler)
|
||||
{ m_handler = handler; }
|
||||
|
||||
// Activate or disactivate callback
|
||||
void SetupCallbacks();
|
||||
void DestroyCallbacks();
|
||||
|
||||
// Pushback library
|
||||
size_t GetPushback(char *buffer, size_t size, bool peek);
|
||||
|
||||
// To prevent many read or write on the same socket at the same time
|
||||
// ==> cause strange things :-)
|
||||
void WantSpeedBuffer(char *buffer, size_t size, wxRequestEvent req);
|
||||
void WantBuffer(char *buffer, size_t size, wxRequestEvent req);
|
||||
|
||||
virtual bool DoRequests(wxRequestEvent req);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class WXDLLEXPORT wxSocketServer : public wxSocketBase
|
||||
{
|
||||
DECLARE_CLASS(wxSocketServer)
|
||||
public:
|
||||
|
||||
// 'service' can be a name or a port-number
|
||||
|
||||
wxSocketServer(wxSockAddress& addr_man, wxSockFlags flags = wxSocketBase::NONE);
|
||||
|
||||
wxSocketBase* Accept();
|
||||
bool AcceptWith(wxSocketBase& sock);
|
||||
virtual void OnRequest(wxRequestEvent flags);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class WXDLLEXPORT wxSocketClient : public wxSocketBase
|
||||
{
|
||||
DECLARE_CLASS(wxSocketClient)
|
||||
public:
|
||||
|
||||
wxSocketClient(wxSockFlags flags = wxSocketBase::NONE);
|
||||
virtual ~wxSocketClient();
|
||||
|
||||
virtual bool Connect(wxSockAddress& addr_man, bool wait = TRUE);
|
||||
|
||||
bool WaitOnConnect(long seconds = -1);
|
||||
|
||||
virtual void OnRequest(wxRequestEvent flags);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class WXDLLEXPORT wxSocketHandler : public wxObject
|
||||
{
|
||||
DECLARE_CLASS(wxSocketHandler)
|
||||
protected:
|
||||
static wxSocketHandler *master;
|
||||
#if defined(__WINDOWS__)
|
||||
wxList *smsg_list;
|
||||
struct wxSockHandlerInternal *internal;
|
||||
#endif
|
||||
wxList *socks;
|
||||
|
||||
public:
|
||||
enum SockStatus { SOCK_NONE, SOCK_DATA, SOCK_CONNECT, SOCK_DISCONNECT,
|
||||
SOCK_ERROR };
|
||||
|
||||
wxSocketHandler();
|
||||
virtual ~wxSocketHandler();
|
||||
|
||||
void Register(wxSocketBase* sock);
|
||||
void UnRegister(wxSocketBase* sock);
|
||||
|
||||
unsigned long Count() const;
|
||||
|
||||
// seconds = -1 means indefinite wait
|
||||
// seconds = 0 means no wait
|
||||
// seconds > 0 means specified wait
|
||||
|
||||
int Wait(long seconds = -1, long microseconds = 0);
|
||||
void YieldSock();
|
||||
|
||||
wxSocketServer *CreateServer
|
||||
(wxSockAddress& addr,
|
||||
wxSocketBase::wxSockFlags flags = wxSocketBase::NONE);
|
||||
wxSocketClient *CreateClient
|
||||
(wxSocketBase::wxSockFlags flags = wxSocketBase::NONE);
|
||||
|
||||
// Create or reuse a socket handler
|
||||
static wxSocketHandler& Master()
|
||||
{ return *((master) ? (master) : (master = new wxSocketHandler())); }
|
||||
|
||||
#if defined(WXSOCK_INTERNAL) && defined(__WINDOWS__)
|
||||
|
||||
friend LRESULT APIENTRY _EXPORT wxSocketHandlerWndProc(HWND hWnd,
|
||||
UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
UINT NewMessage(wxSocketBase *sock);
|
||||
void DestroyMessage(UINT msg);
|
||||
|
||||
HWND GetHWND() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxSocketEvent : public wxEvent {
|
||||
DECLARE_DYNAMIC_CLASS(wxSocketEvent)
|
||||
public:
|
||||
wxSocketEvent(int id = 0);
|
||||
|
||||
wxSocketBase::wxRequestEvent SocketEvent() const { return m_skevt; }
|
||||
public:
|
||||
wxSocketBase::wxRequestEvent m_skevt;
|
||||
};
|
||||
|
||||
typedef void (wxEvtHandler::*wxSocketEventFunction)(wxSocketEvent&);
|
||||
|
||||
#define wxEVT_SOCKET wxEVT_FIRST+301
|
||||
|
||||
#define EVT_SOCKET(id, func) { wxEVT_SOCKET, id, 0, (wxObjectEventFunction) (wxEventFunction) (wxSocketEventFunction) & func },
|
||||
|
||||
#endif
|
||||
@@ -29,6 +29,10 @@ typedef wxOutputStream& (*__wxOutputManip)(wxOutputStream&);
|
||||
|
||||
wxOutputStream& WXDLLEXPORT wxEndL(wxOutputStream& o_stream);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Stream buffer
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxStreamBuffer {
|
||||
public:
|
||||
wxStreamBuffer(wxInputStream& stream);
|
||||
@@ -63,16 +67,17 @@ class WXDLLEXPORT wxStreamBuffer {
|
||||
wxOutputStream *m_ostream;
|
||||
};
|
||||
|
||||
/*
|
||||
* wxStream: base classes
|
||||
*/
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxStream: base classes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxInputStream {
|
||||
public:
|
||||
wxInputStream();
|
||||
virtual ~wxInputStream();
|
||||
|
||||
// IO functions
|
||||
virtual char Peek() = 0;
|
||||
virtual char Peek() { return 0; }
|
||||
virtual char GetC();
|
||||
virtual wxInputStream& Read(void *buffer, size_t size);
|
||||
wxInputStream& Read(wxOutputStream& stream_out);
|
||||
@@ -108,9 +113,11 @@ class WXDLLEXPORT wxInputStream {
|
||||
|
||||
wxInputStream(wxStreamBuffer *buffer);
|
||||
|
||||
virtual size_t DoRead(void *buffer, size_t size) = 0;
|
||||
virtual off_t DoSeekInput(off_t pos, wxSeekMode mode) = 0;
|
||||
virtual off_t DoTellInput() const = 0;
|
||||
virtual size_t DoRead(void *buffer, size_t size) { return 0; }
|
||||
virtual off_t DoSeekInput(off_t pos, wxSeekMode mode)
|
||||
{ return wxInvalidOffset; }
|
||||
virtual off_t DoTellInput() const
|
||||
{ return wxInvalidOffset; }
|
||||
|
||||
protected:
|
||||
bool m_eof, m_i_destroybuf;
|
||||
@@ -158,9 +165,11 @@ class WXDLLEXPORT wxOutputStream {
|
||||
|
||||
wxOutputStream(wxStreamBuffer *buffer);
|
||||
|
||||
virtual size_t DoWrite(const void *buffer, size_t size) = 0;
|
||||
virtual off_t DoSeekOutput(off_t pos, wxSeekMode mode) = 0;
|
||||
virtual off_t DoTellOutput() const = 0;
|
||||
virtual size_t DoWrite(const void *buffer, size_t size) { return 0; }
|
||||
virtual off_t DoSeekOutput(off_t pos, wxSeekMode mode)
|
||||
{ return wxInvalidOffset; }
|
||||
virtual off_t DoTellOutput() const
|
||||
{ return wxInvalidOffset; }
|
||||
|
||||
protected:
|
||||
bool m_bad, m_o_destroybuf;
|
||||
@@ -168,48 +177,65 @@ class WXDLLEXPORT wxOutputStream {
|
||||
wxStreamBuffer *m_o_streambuf;
|
||||
};
|
||||
|
||||
/*
|
||||
* "Filter" streams
|
||||
*/
|
||||
|
||||
class WXDLLEXPORT wxFilterInputStream: public wxInputStream {
|
||||
class wxStream: virtual public wxInputStream,
|
||||
virtual public wxOutputStream
|
||||
{
|
||||
public:
|
||||
wxStream();
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// "Filter" streams
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxFilterInputStream: virtual public wxInputStream {
|
||||
public:
|
||||
wxFilterInputStream();
|
||||
wxFilterInputStream(wxInputStream& stream);
|
||||
virtual ~wxFilterInputStream();
|
||||
~wxFilterInputStream();
|
||||
|
||||
virtual char Peek() { return m_parent_i_stream->Peek(); }
|
||||
char Peek() { return m_parent_i_stream->Peek(); }
|
||||
|
||||
virtual bool Eof() const { return m_parent_i_stream->Eof(); }
|
||||
virtual size_t LastRead() const { return m_parent_i_stream->LastRead(); }
|
||||
virtual off_t TellI() const { return m_parent_i_stream->TellI(); }
|
||||
bool Eof() const { return m_parent_i_stream->Eof(); }
|
||||
size_t LastRead() const { return m_parent_i_stream->LastRead(); }
|
||||
off_t TellI() const { return m_parent_i_stream->TellI(); }
|
||||
|
||||
protected:
|
||||
virtual size_t DoRead(void *buffer, size_t size);
|
||||
virtual off_t DoSeekInput(off_t pos, wxSeekMode mode);
|
||||
virtual off_t DoTellInput() const;
|
||||
size_t DoRead(void *buffer, size_t size);
|
||||
off_t DoSeekInput(off_t pos, wxSeekMode mode);
|
||||
off_t DoTellInput() const;
|
||||
|
||||
protected:
|
||||
wxInputStream *m_parent_i_stream;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
|
||||
class WXDLLEXPORT wxFilterOutputStream: virtual public wxOutputStream {
|
||||
public:
|
||||
wxFilterOutputStream();
|
||||
wxFilterOutputStream(wxOutputStream& stream);
|
||||
virtual ~wxFilterOutputStream();
|
||||
|
||||
virtual bool Bad() const { return m_parent_o_stream->Bad(); }
|
||||
virtual size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
|
||||
virtual off_t TellO() const { return m_parent_o_stream->TellO(); }
|
||||
bool Bad() const { return m_parent_o_stream->Bad(); }
|
||||
size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
|
||||
off_t TellO() const { return m_parent_o_stream->TellO(); }
|
||||
|
||||
protected:
|
||||
// The forward is implicitely done by wxStreamBuffer.
|
||||
|
||||
virtual size_t DoWrite(const void *buffer, size_t size);
|
||||
virtual off_t DoSeekOutput(off_t pos, wxSeekMode mode);
|
||||
virtual off_t DoTellOutput() const;
|
||||
size_t DoWrite(const void *buffer, size_t size);
|
||||
off_t DoSeekOutput(off_t pos, wxSeekMode mode);
|
||||
off_t DoTellOutput() const;
|
||||
|
||||
protected:
|
||||
wxOutputStream *m_parent_o_stream;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxFilterStream: public wxStream,
|
||||
virtual public wxFilterInputStream,
|
||||
virtual public wxFilterOutputStream {
|
||||
public:
|
||||
wxFilterStream(wxStream& stream);
|
||||
wxFilterStream();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
40
include/wx/tokenzr.h
Normal file
40
include/wx/tokenzr.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tokenzr.h
|
||||
// Purpose: String tokenizer
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 04/22/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_TOKENZRH
|
||||
#define _WX_TOKENZRH
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/object.h"
|
||||
#include "wx/string.h"
|
||||
|
||||
class wxStringTokenizer : wxObject {
|
||||
public:
|
||||
wxStringTokenizer(const wxString& to_tokenize,
|
||||
const wxString& delims = " \t\r\n",
|
||||
bool ret_delim = FALSE);
|
||||
~wxStringTokenizer();
|
||||
|
||||
int CountTokens();
|
||||
bool HasMoreToken();
|
||||
wxString NextToken();
|
||||
wxString GetString() { return m_string; }
|
||||
protected:
|
||||
off_t FindDelims(const wxString& str, const wxString& delims);
|
||||
protected:
|
||||
wxString m_string, m_delims;
|
||||
bool m_retdelims;
|
||||
};
|
||||
|
||||
#endif
|
||||
70
include/wx/url.h
Normal file
70
include/wx/url.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: url.h
|
||||
// Purpose: URL parser
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 20/07/1997
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_URL_H
|
||||
#define _WX_URL_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// wxWindows header
|
||||
#include "wx/object.h"
|
||||
|
||||
// wxSocket headers
|
||||
#include "wx/protocol/protocol.h"
|
||||
#include "wx/protocol/http.h"
|
||||
|
||||
typedef enum {
|
||||
wxURL_NOERR = 0,
|
||||
wxURL_SNTXERR,
|
||||
wxURL_NOPROTO,
|
||||
wxURL_NOHOST,
|
||||
wxURL_NOPATH,
|
||||
wxURL_CONNERR,
|
||||
wxURL_PROTOERR
|
||||
} wxURLError;
|
||||
|
||||
class WXDLLEXPORT wxURL : public wxObject {
|
||||
DECLARE_DYNAMIC_CLASS(wxURL)
|
||||
protected:
|
||||
static wxProtoInfo *g_protocols;
|
||||
static wxHTTP g_proxy;
|
||||
wxProtoInfo *m_protoinfo;
|
||||
wxProtocol *m_protocol;
|
||||
wxHTTP m_proxy;
|
||||
wxURLError m_error;
|
||||
wxString m_protoname, m_hostname, m_servname, m_path, m_url;
|
||||
|
||||
bool PrepProto(wxString& url);
|
||||
bool PrepHost(wxString& url);
|
||||
bool PrepPath(wxString& url);
|
||||
bool ParseURL();
|
||||
void CleanData();
|
||||
bool FetchProtocol();
|
||||
|
||||
friend class wxProtoInfo;
|
||||
public:
|
||||
|
||||
wxURL(const wxString& url);
|
||||
virtual ~wxURL();
|
||||
|
||||
inline wxString GetProtocolName() const
|
||||
{ return m_protoinfo->m_protoname; }
|
||||
inline wxProtocol& GetProtocol() { return *m_protocol; }
|
||||
inline wxURLError GetError() const { return m_error; }
|
||||
|
||||
wxInputStream *GetInputStream();
|
||||
|
||||
static void SetDefaultProxy(const wxString& url_proxy);
|
||||
void SetProxy(const wxString& url_proxy);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user