source: SMSSender/gateways/Sunrise/network/httphelper.cpp @ 378:7553d82ad234

separation-frontend-backend
Last change on this file since 378:7553d82ad234 was 378:7553d82ad234, checked in by Sämy Zehnder <saemy.zehnder@…>, 7 years ago
  • Reverts the removal of the CA certificates to avoid the disavailability of a service due to the system CA store not containing it's CA.
File size: 2.1 KB
Line 
1/*
2 Sunrise gateway plugin - The smssender plugin for the Sunrise platform.
3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "httphelper.h"
19
20#include <QFile>
21
22#include "common/exceptions/eparseexception.h"
23#include "common/network/snetworkreply.h"
24
25namespace Sunrise {
26
27HttpHelper::HttpHelper()
28    : SNetworkHelper()
29{
30    addTrustedCA(":/certs/ThawtePremiumServerCA.crt");
31}
32
33SNetworkReply HttpHelper::sendForm(const QString &lastHtml,
34                                   const QString &formIdOrName,
35                                   QList<IParam *> &posts,
36                                   SNetworkHelper::PostType postType) {
37    /* Get post action */
38    QRegExp rx("<form.*(?:id|name)=\"" + formIdOrName + "\".*action=\"([^\"]*)\".*>");
39    rx.setMinimal(true);
40
41    if (rx.indexIn(lastHtml) == -1) {
42        EParseException(tr("Could not find the given form."))
43                .addDebugInfo("formIdOrName", formIdOrName)
44                .addDebugInfo("html", lastHtml)
45                .raise();
46    }
47
48    /* Correct url */
49    QString url = urldecodeString(rx.cap(1));
50    url.replace(":443", "", Qt::CaseInsensitive);
51
52    /* Post it */
53    return syncPost(url, posts, postType);
54}
55
56QString HttpHelper::replaceEncodedUTF8Chars(const QString &str) {
57    QString s = str;
58
59    QRegExp rx("&#(\\d+);");
60    int idx = -1;
61    while ((idx = rx.indexIn(s, idx+1)) >= 0) {
62        s.replace(idx, rx.cap(0).length(), QChar(rx.cap(1).toInt()));
63    }
64    return s;
65}
66
67}
Note: See TracBrowser for help on using the repository browser.