1 //
2 // ExternalTransport.h
3 //
4 // ExternalTransport: Allows external programs to retrieve given URLs with
5 //                    unknown protocols.
6 //
7 // Part of the ht://Dig package   <http://www.htdig.org/>
8 // Copyright (c) 1995-2004 The ht://Dig Group
9 // For copyright details, see the file COPYING in your distribution
10 // or the GNU Library General Public License (LGPL) version 2 or later
11 // <http://www.gnu.org/copyleft/lgpl.html>
12 //
13 // $Id: ExternalTransport.h,v 1.5 2004/05/28 13:15:14 lha Exp $
14 //
15 
16 #ifndef _ExternalTransport_h_
17 #define _ExternalTransport_h_
18 
19 #include "Transport.h"
20 #include "htString.h"
21 
22 #include <stdio.h>
23 
24 // First we must declare a derived Transport_Response class
25 // This requires declaring the main class in advance
26 class ExternalTransport;
27 class ExternalTransport_Response : public Transport_Response
28 {
29   friend class ExternalTransport;
30 
31   // Nothing else... We just want it so we can access the protected fields
32 };
33 
34 // Right, now we get on with the show...
35 class ExternalTransport : public Transport
36 {
37 public:
38     //
39     // Construction/Destruction
40     //
41                         ExternalTransport(const String &protocol);
42     virtual		~ExternalTransport();
43 
44 
45     //
46     // Check if the given protocol has a handler
47     //
48     static int		canHandle(const String &protocol);
49 
50     // Setting connections is obviously a bit different than the base class
51     // from a URL pointer
52     void SetConnection (URL *u);
53 
54     // from a URL object
SetConnection(URL & u)55     void SetConnection (URL &u)
56         { SetConnection (&u); }
57 
58     // Make the request
59     DocStatus Request();
60 
61     // Get the response or the status
GetResponse()62     Transport_Response	*GetResponse()	 { return _Response; }
GetDocumentStatus()63     DocStatus GetDocumentStatus() { return GetDocumentStatus(_Response); }
64 
65 
66 private:
67     // The command to handle the current protocol
68     String			_Handler;
69     // And the current protocol
70     String			_Protocol;
71 
72     // The URL to Request()
73     URL				_URL;
74 
75     // The result of the Request()
76     ExternalTransport_Response	*_Response;
77 
78 
79 
80     // Private helper to read in the result from the handler
81     int			readLine(FILE *, String &);
82     // Work out the DocStatus from the HTTP-style status codes
83     DocStatus		GetDocumentStatus(ExternalTransport_Response *r);
84 };
85 
86 #endif
87 
88 
89