summaryrefslogtreecommitdiff
path: root/src/MySock.h
blob: 132978c9a311e219886197bcffc3b135d961451d (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
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h> 

using namespace std;
#define MAX_LINE 100
#define LINE_ARRAY_SIZE (MAX_LINE+1)

#define NO_ERROR                0
#define CANT_CREATE_SOCKET      20
#define CANT_RESOLVE_HOST       30
#define CANT_CONNECT            35
#define CANT_SEND_DATA          40
#define CANT_READ_DATA          45
#define NO_VALID_PROTOCOL       50
#define NO_VALID_HEADERS        52

#define CRLF "\r\n"
struct HTTP_Request
{
  string statusstr;
  int status;
  string date;
  string server;
  string last_modified;
  string content_type;
  string content_length;
  string data;
};

struct TKey_Value
{
  string key, value;
};

class MySock {
public:
  int error;
  bool connected;

  string GetTextData();
  int SendData(string data);
  HTTP_Request *GetHTTPData();
  void closeConnection();
  MySock();
  MySock(string server, int port);
  MySock(string uri);
  virtual ~MySock();
private:
  int sockd, puerto;
  struct hostent *server;

  void MakeConnection (string server, int port);
};

TKey_Value extract_key_value(string str);