summaryrefslogtreecommitdiffstats
path: root/libktorrent/util/httprequest.h
blob: f472c07a7bb2a96e65c6efa3f19e9113d062c014 (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
/***************************************************************************
 *   Copyright (C) 2005 by Joris Guisson                                   *
 *   joris.guisson@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef BTHTTPREQUEST_H
#define BTHTTPREQUEST_H

#include <tqobject.h>
#include <kurl.h>
#include <kstreamsocket.h>
#include <interfaces/exitoperation.h>
#include "constants.h"

using KNetwork::KResolverEntry;

namespace bt 
{
	
	/**
	 * @author Joris Guisson
	 * 
	 * Just create one, fill in the fields,
	 * connect to the right signals and forget about it. After the reply has been received or
	 * an error occurred, the appropriate signal will be emitted.
	*/
	class HTTPRequest : public kt::ExitOperation
	{
		Q_OBJECT
  
	public:
		/**
		 * Constructor, set the url and the request header.
		 * @param hdr The http request header
		 * @param payload The payload
		 * @param host The host
		 * @param port THe port
		 * @param verbose Print traffic to the log
		 */
		HTTPRequest(const TQString & hdr,const TQString & payload,const TQString & host,
					Uint16 port,bool verbose);
		virtual ~HTTPRequest();
		
		/**
		 * Open a connetion and send the request.
		 */
		void start();
		
	signals:
		/**
		 * An OK reply was sent.
	     * @param r The sender of the request
		 * @param data The data of the reply
		 */
		void replyOK(bt::HTTPRequest* r,const TQString & data);
		
		/**
		 * Anything else but an 200 OK was sent.
		 * @param r The sender of the request
		 * @param data The data of the reply
		 */
		void replyError(bt::HTTPRequest* r,const TQString & data);
		
		/**
		 * No reply was sent and an error or timeout occurred.
		 * @param r The sender of the request
		 * @param timeout Wether or not a timeout occurred
		 */
		void error(bt::HTTPRequest* r,bool timeout);
		
	private slots:
		void onReadyRead();
		void onError(int);
		void onTimeout();
		void onConnect(const KResolverEntry&);
		
	private:
		KNetwork::KStreamSocket* sock;
		TQString hdr,payload;
		bool verbose;
	};

}

#endif