File: iwebstream.H

package info (click to toggle)
bk2site 1%3A1.1.9-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 788 kB
  • ctags: 436
  • sloc: cpp: 4,052; perl: 1,248; sh: 605; makefile: 104
file content (79 lines) | stat: -rw-r--r-- 2,634 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Author: Jose M. Vidal
// $Id: iwebstream.H,v 1.6 2002/04/02 19:02:22 jmvidal Exp $
// This code is copyright of Jose M. Vidal and released under
// the GNU General Public License
//
// A class thats is meant to look like an istream, regardless of
//  whether it opens a local file or an http object.
//  Sometime later I might also add ftp.
//
#ifndef IWEBSTREAM_H
#define IWEBSTREAM_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <cctype>
//#include <ctime>
#include <sys/time.h>
#include <sys/socket.h>
#include <string>
#include <iostream>

// Objects of the http class can connect to WWW servers and get pages from
// those servers

using namespace std;

class iwebstream {
private:
  int socketDesc; // socket descriptor used in system calls
  fd_set read_map; // selects socket descriptors that are ready for reading
  struct timeval tval; // timeout for reading
  int defaultTimeout; // default value of tval
  string data; //the contents of the file
  unsigned int position; //the current position on data
  string http_proxy; // hostname of the HTTP proxy to be used
  int http_proxy_port; // port number of the HTTP proxy to be used
  string http_proxy_user; // user name for the HTTP proxy
  string http_proxy_password; // password for the HTTP proxy

  void readFile(string & filename);
  int connect(string hostName, unsigned short int port, int timeOut);
  int get(const string hostname, const string port, const string path, string& pageContents);
  unsigned int findNC(const string & s, unsigned int p);
	void init(const string& url);
	void string2base64Helper(unsigned char *, unsigned char *);
	string string2base64(const string&);

public:
  iwebstream(string url, int timeout = 30);
	iwebstream(const string& url, const string& proxy, int proxy_port, const string& proxy_user, const string& proxy_passwd, int timeout = 30);
  iwebstream & operator>>(long int & t);
  iwebstream & operator>>(int & t);
  iwebstream & operator>>(string & s);
  string getData() {
    return data;
  }
  char get();
  void putback(char & c);
  void getline(string & s);
  bool eof();
  void close(){};
  bool operator==(int x);
  bool operator!=(int x) {
    return !operator==(x);};

  //find the next occurance of s, set position to point to it
  bool find(const string & s);
  //find the next occurance of s, set position to point past it
  bool findAndPass(const string & s);

  //return whatever is between the next begin & end. If begin is not found,
  // return ""
  string findTag(const string & begin, const string & end, const string & after = "",
		 const string & before = "");
};

#endif // IWEBSTREAM_H