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