00001
00009 #ifndef __INET_H
00010 #define __INET_H
00011
00012 #include "GMem.h"
00013 #include "GContainers.h"
00014 #include "LgiNetInc.h"
00015 #include "GStream.h"
00016 #include "LgiInterfaces.h"
00017
00018 #if defined WIN32
00019
00020 #elif defined BEOS
00021
00022 #include <socket.h>
00023 #include <netdb.h>
00024
00025 #elif defined ATHEOS
00026
00027 #include <atheos/socket.h>
00028
00029 #else
00030
00031 typedef int SOCKET;
00032
00033 #endif
00034
00035 #define DEFAULT_TIMEOUT 30
00036
00037
00038 #define SMTP_PORT 25
00039 #define SMTP_SSL_PORT 465
00040 #define POP3_PORT 110
00041 #define POP3_SSL_PORT 995
00042 #define IMAP_PORT 143
00043 #define IMAP_SSL_PORT 993
00044
00045
00046
00048 #define GSocket_Log 1
00049
00050 #define GSocket_Progress 2
00051
00052 #define GSocket_TransferSize 3
00053
00054 #define GSocket_Protocol 4
00055
00056 #if defined BEOS
00057
00058 #include "NetworkKit.h"
00059 #define ValidSocket(s) ((s)>=0)
00060 #define INVALID_SOCKET -1
00061 typedef int OsSocket;
00062
00063 #elif defined ATHEOS
00064
00065 #define ValidSocket(s) ((s)>=0)
00066 #define INVALID_SOCKET -1
00067 typedef int OsSocket;
00068
00069 #elif defined WIN32
00070
00071
00072 #elif defined POSIX
00073
00074
00075 #endif
00076
00077
00078
00079 LgiNetFunc bool HaveNetConnection();
00080 LgiNetFunc bool WhatsMyIp(char *IpAddr);
00081
00083 LgiNetFunc void MDStringToDigest
00084 (
00086 unsigned char digest[16],
00088 char *Str,
00090 int Len = -1
00091 );
00092
00093
00094
00095
00096 class GNetwork;
00097
00099 class LgiNetClass GNetwork
00100 {
00101 bool SocketsOpen;
00102
00103 public:
00104 GNetwork();
00105 virtual ~GNetwork();
00106
00108 bool IsValid() { return SocketsOpen; }
00109
00111 bool EnumInterfaces(List<char> &Lst);
00112 };
00113
00115 class LgiNetClass GSocket : public GSocketI, public GStream
00116 {
00117 friend class GNetwork;
00118
00119 protected:
00120 class GSocketImplPrivate *d;
00121
00122
00123 void Log(char *Msg, int Ret, char *Buf, int Len);
00124
00125 public:
00126 int BytesWritten;
00127 int BytesRead;
00128
00130 GSocket();
00131
00133 ~GSocket();
00134
00136 OsSocket Handle(OsSocket Set = INVALID_SOCKET);
00137
00139 bool IsOK();
00140
00142 void SetLogFile
00143 (
00145 char *FileName = 0,
00147 int Type = NET_LOG_HEX_DUMP
00148 );
00149
00151 bool WhatsMyIp(char *IpAddr);
00152
00154 int WhatsMyPort();
00155
00157 bool GetRemoteIp(char *IpAddr);
00158
00160 bool IsReadable();
00161
00163 int Is(GSocketProp p);
00164
00166 void Is(GSocketProp p, int i);
00167
00169 bool Cancel();
00170
00172 void Cancel(bool i);
00173
00175 int Open
00176 (
00178 char *HostAddr,
00180 int Port
00181 );
00182
00184 bool IsOpen();
00185
00187 int Close();
00188
00190 bool Listen(int Port = 0);
00191
00193 bool Accept
00194 (
00196 GSocketI *c
00197 );
00198
00201 int Write
00202 (
00204 void *Data,
00206 int Len,
00208 int Flags
00209 );
00210
00217 int Read
00218 (
00220 void *Data,
00222 int Len,
00224 int Flags
00225 );
00226
00228 int Error();
00229
00231 int64 GetSize() { return -1; }
00233 int64 SetSize(int64 Size) { return -1; }
00235 int64 GetPos() { return -1; }
00237 int64 SetPos(int64 Pos) { return -1; }
00238
00240 void OnDisconnect();
00241
00243 void OnRead(char *Data, int Len) {}
00244
00246 void OnWrite(char *Data, int Len) {}
00247
00249 void OnError(int ErrorCode, char *ErrorDescription) {}
00250
00252 void OnInformation(char *Str) {}
00253
00255 int SetParameter
00256 (
00258 int Param,
00259 int Value
00260 ) { return false; }
00261 };
00262
00263 class LgiNetClass GSocks5Socket : public GSocket
00264 {
00265 char *Proxy;
00266 int Port;
00267 char *UserName;
00268 char *Password;
00269
00270 protected:
00271 bool Socks5Connected;
00272
00273 public:
00274 GSocks5Socket(char *proxy, int port, char *username, char *password);
00275 ~GSocks5Socket();
00276
00277
00278 int Open(char *HostAddr, int port);
00279
00280
00281 bool Listen(int Port) { return false; }
00282 };
00283
00285 class LgiNetClass GHost
00286 {
00287 int DefaultPort;
00288
00289 public:
00291 char *Server;
00293 int Port;
00294
00296 GHost
00297 (
00299 int DefaultPort,
00301 char *Str = 0
00302 );
00303
00304 ~GHost();
00305
00306 void Empty();
00307 GHost &operator =(char *s);
00308 operator int()
00309 {
00310 return Server != 0;
00311 }
00312 };
00313
00314 #endif
00315