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.14 2003/07/11 07:54:46 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 |
|
class HttpHandler |
74 |
|
#endif // _WIN32 |
75 |
|
SOCKET http; |
76 |
|
char* buffer; |
92 |
– |
unsigned begin; |
77 |
|
string page; |
78 |
|
string type; |
79 |
|
unsigned length; |
80 |
|
string location; |
81 |
|
bool chunked; |
82 |
+ |
string email; |
83 |
+ |
void populate(); |
84 |
|
void putline(const string line = ""); |
85 |
|
string getline(); |
86 |
|
void error(const string& prefix, bool host = false); |
87 |
|
public: |
88 |
|
HttpHandler(); |
89 |
|
~HttpHandler(); |
90 |
< |
bool handle(URL& url, bool head = false); |
90 |
> |
bool handle(URL& url, const string referer = "", bool head = false); |
91 |
|
HttpHandler& getline(string& line, char endline = '\n'); |
92 |
< |
bool good(); |
92 |
> |
bool good() { return (page.length() > 0); } |
93 |
|
void clear(); |
94 |
|
string contentType() { return type; } |
95 |
|
unsigned contentLength() { return length; } |