Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WebFetch.h « mumble « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0bca4bb5e9dca9eb978069f92430a002a2ed91a4 (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
// Copyright 2005-2016 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#ifndef MUMBLE_MUMBLE_WEBFETCH_H_
#define MUMBLE_MUMBLE_WEBFETCH_H_

#include <QtCore/QByteArray>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QUrl>

class QNetworkReply;

/// WebFetch is a utility class to download data from Mumble services.
class WebFetch : public QObject {
	private:
		Q_OBJECT
		Q_DISABLE_COPY(WebFetch)
	protected:
		QObject *qoObject;
		const char *cpSlot;
		QNetworkReply *qnr;
		QString m_service;

		QString prefixedServiceHost() const;
		QString serviceHost() const;

		WebFetch(QString service, QUrl url, QObject *obj, const char *slot);
	signals:
		void fetched(QByteArray data, QUrl url, QMap<QString, QString> headers);
	protected slots:
		void finished();
	public:
		/// The fetch function downloads the resource specified by the url parameter from the
		/// Mumble service given in the service parameter. Once the download completes, the
		/// function invokes the slot specified via the slot parameter.
		///
		/// Only the path part of the url parameter
		/// is used to construct the final, fully-qualified URL from which the resource is
		/// downloaded.
		///
		/// By default, the service parameter and the url parameter are combined to create
		/// a service as follows:
		///
		///     fullyQualifiedURL = https://${service}.mumble.info/${url.path}
		///
		/// When a resource is downloaded from a Mumble service, the service may optionally
		/// specify a service prefix to use for future requests to all Mumble services. This
		/// is communicated via the Use-Service-Prefix HTTP header in HTTP responses from
		/// Mumble services. When this function encounters such a response header, it stores
		/// the service prefix in the "net/serviceprefix" Mumble setting. If this setting
		/// is non-empty, the fully-qualified URL is instead constructed as such:
		///
		///     fullyQualifiedURL = https://${serivcePrefixSetting}-${service}.mumble.info/${url.path}
		///
		/// The service prefix must only contain ASCII characters 'A' through 'Z' (upper case)
		/// or 'a' through 'z (lower case).
		///
		/// @param  service  The Mumble service name to use for this request.
		///
		///                  The service name specified is used to create base URL
		///                  used by the final, fully-qualified URL as follows:
		///
		///                      baseURL = https://${service}.mumble.info
		///
		///                  If the Mumble setting "net/serviceprefix" is non-empty,
		///                  it will be used as a prefix to the base URL. In this case,
		///                  the base URL will be constructed as follows:
		///
		///                      baseURL = https://${servicePrefixSetting}-${service}.mumble.info
		///
		/// @param  url      The path to the endpoint that the request is targetted at.
		///                  Only the path of the URL will be used. The specified path is
		///                  used in combination with the base URL constructed by the service
		///                  parameter to construct the fully-qualified URL for the HTTP request
		///                  that will be sent by this function.
		///                  The path is used in combination with the base URL from the service
		///                  parameter as follows:
		///
		///                      fullyQualifiedURL = ${baseURL}/${url.path}
		///
		/// @param  slot     A Qt slot of the form fetched(QByteArray data, QUrl url,
		///                                                QMap<QString,QString> httpHeaders)
		///                  If the download initiated by the function was succesful, the data
		///                  parameter will be a non-null QByteArray.
		///                  If the download failed, the data parameter will be a null QByteArray.
				static void fetch(const QString &service, const QUrl &url, QObject *obj, const char *slot);
};

#endif