1 |
|
/* ============================================================================ |
2 |
|
* Douglas Thrift's Search Engine License |
3 |
|
* |
4 |
< |
* Copyright (C) 2002, Douglas Thrift. All Rights Reserved. |
4 |
> |
* Copyright (C) 2002-2003, Douglas Thrift. All Rights Reserved. |
5 |
|
* Redistribution and use in source and binary forms, with or without |
6 |
|
* modification, are permitted provided that the following conditions are met: |
7 |
|
* |
46 |
|
// |
47 |
|
// Douglas Thrift |
48 |
|
// |
49 |
< |
// HttpHandler.h |
49 |
> |
// $Id: HttpHandler.h,v 1.17 2003/07/18 07:17:10 douglas Exp $ |
50 |
|
|
51 |
|
#ifndef _HttpHandler_h_ |
52 |
|
#define _HttpHandler_h_ |
56 |
|
|
57 |
|
// Lovely C Sockets! |
58 |
|
#ifdef _WIN32 |
59 |
– |
|
59 |
|
// Windows Sockets |
60 |
|
#include <winsock2.h> |
61 |
|
#include <windows.h> |
63 |
– |
|
62 |
|
#else |
65 |
– |
|
63 |
|
// BSD Sockets |
67 |
– |
#include <unistd.h> |
68 |
– |
#include <sys/types.h> |
69 |
– |
#include <sys/socket.h> |
70 |
– |
#include <netinet/in.h> |
71 |
– |
#include <netdb.h> |
72 |
– |
|
73 |
– |
#define INVALID_SOCKET -1 |
74 |
– |
#define SOCKET_ERROR -1 |
75 |
– |
|
64 |
|
typedef int SOCKET; |
77 |
– |
|
78 |
– |
inline int closesocket(SOCKET s) { return close(s); } |
79 |
– |
|
65 |
|
#endif // _WIN32 |
66 |
|
|
67 |
+ |
#ifdef _OpenSSL_ |
68 |
+ |
#include <openssl/ssl.h> |
69 |
+ |
#include <openssl/err.h> |
70 |
+ |
#include <openssl/rand.h> |
71 |
+ |
#endif |
72 |
+ |
|
73 |
|
class HttpHandler |
74 |
|
{ |
75 |
|
private: |
79 |
|
WSADATA data; |
80 |
|
#endif // _WIN32 |
81 |
|
SOCKET http; |
82 |
+ |
#ifdef _OpenSSL_ |
83 |
+ |
SSL_CTX* ctx; |
84 |
+ |
SSL* ssl; |
85 |
+ |
bool tls; |
86 |
+ |
#endif |
87 |
|
char* buffer; |
88 |
< |
unsigned begin; |
89 |
< |
string page; |
88 |
> |
bool binary; |
89 |
> |
stringstream page; |
90 |
|
string type; |
91 |
|
unsigned length; |
92 |
|
string location; |
93 |
|
bool chunked; |
94 |
+ |
void populate(); |
95 |
|
void putline(const string line = ""); |
96 |
|
string getline(); |
97 |
|
void error(const string& prefix, bool host = false); |
98 |
+ |
#ifdef _OpenSSL_ |
99 |
+ |
void error(const string& prefix, int number); |
100 |
+ |
bool starttls(); |
101 |
+ |
#endif |
102 |
|
public: |
103 |
|
HttpHandler(); |
104 |
|
~HttpHandler(); |
105 |
< |
bool handle(URL& url, bool head = false); |
106 |
< |
HttpHandler& getline(string& line, char endline = '\n'); |
107 |
< |
bool good(); |
105 |
> |
bool handle(URL& url, const string referer = "", bool head = false); |
106 |
> |
istream& pageStream() { return page; } |
107 |
> |
istream& getline(string& line) { return std::getline(page, line); } |
108 |
> |
istream& getline(string& line, char end) { return std::getline(page, line, |
109 |
> |
end); } |
110 |
> |
bool good() { return page.good(); } |
111 |
|
void clear(); |
112 |
|
string contentType() { return type; } |
113 |
|
unsigned contentLength() { return length; } |