File: comhttpsocket.h

package info (click to toggle)
musicbrainz 1.0.1.final-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,168 kB
  • ctags: 2,610
  • sloc: ansic: 16,052; sh: 8,658; cpp: 6,283; perl: 327; makefile: 112
file content (63 lines) | stat: -rw-r--r-- 2,201 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
60
61
62
63
/***************************************************************************
                          MBCOMHTTPSocket.h  -  description
                             -------------------
    begin                : Sat Jun 3 2000
    copyright            : (C) 2000 by Relatable
    written by           : Sean Ward
    email                : sward@relatable.com
 ***************************************************************************/

#ifndef MBCOMHTTPSocket_H
#define MBCOMHTTPSocket_H
#include <stdio.h>
#include <string>

using namespace std;

class MBCOMSocket;
/**Wraps the OS specifics of an http based proxiable client socket.
  *@author Sean Ward
  */
class MBCOMHTTPSocket {
public: 

	MBCOMHTTPSocket();
	~MBCOMHTTPSocket();
	/** Connects a socket to pIP, on nPort, of type nType. */
	int Connect(const char* pURL);
	/** Checks if there is a current open connection */
	bool IsConnected();
	/** Disconnects the current socket */
	int Disconnect();
	/** Reads in a non blocking fashion (ie, selects and polls) for nTimeout seconds */
	int NBRead(char* pBuffer, int nLen, int* nBytesWritten, int nTimeout);
        /** Reads from a socket, into pbuffer, up to a max of nLen byte, and writes how many were actually written to nBytesWritten. */
        int Read(char* pBuffer, int nLen, int* nBytesWritten);
	/** Writes to a socket, from buffer pBuffer, up to nLen bytes, and returns the number of written bytes in pnBytesWritten. */
	int Write(const char* pBuffer, int nLen, int* pnBytesWritten);
	/** Sets the proxy address. Use NULL to disable. */
	int SetProxy(const char* pURL);

protected:
	/** Internal validation function */
	bool IsHTTPHeaderComplete(char* buffer, unsigned int length);

private: // Private attributes
	/** socket used for transport */
	MBCOMSocket* m_pSock;
	/** URL of proxy */
	string m_strProxyAddr;
	/** URL of current connection */
	string m_strURL;
        /** hostname field for current request */
	char m_hostname[65];
        /** proxy URL for current request */
	char m_proxyname[1025];
        /** file to request or post to */
	const char* m_pFile;
	/** temp buffer for excess data when parsing header */
	char* m_pTempBuf;
	int m_nBufLen;
};

#endif