blob: 07b0c87b909baae154aceea77cc6a4c09c714a80 (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
//
// HtNNTP.h
//
// HtNNTP: Class for NNTP messaging (derived from Transport)
//
// Gabriele Bartolini - Prato - Italia
// started: 01.08.2000
//
//
// Part of the ht://Dig package <http://www.htdig.org/>
// Copyright (c) 1995-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the General GNU Library General Public License (LGPL) version 2 or later
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: HtNNTP.h,v 1.5 2004/05/28 13:15:23 lha Exp $
//
#ifndef _HTNNTP_H
#define _HTNNTP_H
#ifdef HAVE_CONFIG_H
#include "htconfig.h"
#endif
#include "Transport.h"
#include "URL.h"
#include "htString.h"
// for HtNNTP::ShowStatistics
#ifdef HAVE_STD
#include <iostream>
#ifdef HAVE_NAMESPACES
using namespace std;
#endif
#else
#include <iostream.h>
#endif /* HAVE_STD */
// In advance declarations
class HtNNTP;
class HtNNTP_Response : public Transport_Response
{
friend class HtNNTP; // declaring friendship
public:
///////
// Construction / Destruction
///////
HtNNTP_Response();
~HtNNTP_Response();
///////
// Interface
///////
// Reset
void Reset();
protected:
// Other header information
};
class HtNNTP : public Transport
{
public:
///////
// Construction/Destruction
///////
HtNNTP();
~HtNNTP();
///////
// Sends an NNTP request message
///////
// manages a Transport request (method inherited from Transport class)
virtual DocStatus Request ();
///////
// Control of member the variables
///////
///////
// Interface for resource retrieving
///////
// Set and get the document to be retrieved
void SetRequestURL(URL &u) { _url = u;}
URL GetRequestURL () { return _url;}
Transport_Response *GetResponse()
{
if (_response._status_code != -1)
return &_response;
else return NULL;
}
// Get the document status
virtual DocStatus GetDocumentStatus()
{ return GetDocumentStatus (_response); }
// It's a static method
static DocStatus GetDocumentStatus(HtNNTP_Response &);
// Manage statistics
static int GetTotSeconds () { return _tot_seconds; }
static int GetTotRequests () { return _tot_requests; }
static int GetTotBytes () { return _tot_bytes; }
static double GetAverageRequestTime ()
{ return _tot_seconds?( ((double) _tot_seconds) / _tot_requests) : 0; }
static float GetAverageSpeed ()
{ return _tot_bytes?( ((double) _tot_bytes) / _tot_seconds) : 0; }
static void ResetStatistics ()
{ _tot_seconds=0; _tot_requests=0; _tot_bytes=0;}
// Show stats
static ostream &ShowStatistics (ostream &out);
// Proxy settings
void SetProxy(int aUse) { _useproxy=aUse; }
protected:
///////
// Member attributes
///////
///////
// NNTP single Request information (Member attributes)
///////
int _bytes_read; // Bytes read
URL _url; // URL to retrieve
int _useproxy; // Shall we use a proxy?
///////
// NNTP Response information
///////
HtNNTP_Response _response; // Object where response
// information will be stored into
///////
// Set the string of the command containing the request
///////
void SetRequestCommand(String &);
///////
// Parse the header returned by the server
///////
int ParseHeader();
///////
// Read the body returned by the server
///////
int ReadBody();
///////
// Static attributes and methods
///////
static int _tot_seconds; // Requests last (in seconds)
static int _tot_requests; // Number of requests
static int _tot_bytes; // Number of bytes read
};
#endif
|