summaryrefslogtreecommitdiff
path: root/protocols/YAMN/src/proto/netlib.h
blob: 415ab80a174dd98984deb98a357f5897223baaac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef __NETLIB_H
#define __NETLIB_H

class CNLClient : public MZeroedObject
{
	HNETLIBCONN hConnection;
	BOOL isTLSed;

	int LocalNetlib_Send(HNETLIBCONN hConn, const char *buf, int len, int flags);
	int LocalNetlib_Recv(HNETLIBCONN hConn, char *buf, int len, int flags);

public:
	void Connect(const char *servername, const int port);
	void Send(const char *query);
	char *Recv(char *buf = nullptr, int buflen = 65536);
	void Disconnect();
	void SSLify();

	bool Connected() const { return hConnection != nullptr; }

	BOOL Stopped;
	int Rcv;
	uint32_t NetworkError;
	uint32_t SystemError;
	BOOL ifTLSed;
};

enum
{
	ENL_WINSOCKINIT=1,	//error initializing socket	//only wsock
	ENL_GETHOSTBYNAME,	//DNS error			//only wsock
	ENL_CREATESOCKET,	//error creating socket		//only wsock
	ENL_CONNECT,		//cannot connect to server
	ENL_SEND,			//cannot send data
	ENL_RECV,			//cannot receive data
	ENL_RECVALLOC,		//cannot allocate memory for received data
	ENL_TIMEOUT,		//timed out during recv
};

enum
{
	ESSL_NOTLOADED=1,	//OpenSSL is not loaded
	ESSL_WINSOCKINIT,	//WinSock 2.0 init failed
	ESSL_GETHOSTBYNAME,	//DNS error
	ESSL_CREATESOCKET,	//error creating socket
	ESSL_SOCKETCONNECT,	//error connecting with socket
	ESSL_CREATESSL,		//error creating SSL session structure
	ESSL_SETSOCKET,		//error connect socket with SSL session for bidirect I/O space
	ESSL_CONNECT,		//cannot connect to server
	ESSL_SEND,		//cannot send data
	ESSL_RECV,		//cannot receive data
	ESSL_RECVALLOC,		//cannot allocate memory for received data
};
#endif