source: SMSSender/gateways/Sunrise/network/httphelper.cpp @ 375:c57f1c92bcb8

separation-frontend-backend
Last change on this file since 375:c57f1c92bcb8 was 375:c57f1c92bcb8, checked in by Sämy Zehnder <saemy.zehnder@…>, 7 years ago
  • Removes explicit listing of CAs wherever possible (uses the systems trusted CAs).
  • Cleans up the locales in the resource files.
File size: 2.0 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}
31
32SNetworkReply HttpHelper::sendForm(const QString &lastHtml,
33                                   const QString &formIdOrName,
34                                   QList<IParam *> &posts,
35                                   SNetworkHelper::PostType postType) {
36    /* Get post action */
37    QRegExp rx("<form.*(?:id|name)=\"" + formIdOrName + "\".*action=\"([^\"]*)\".*>");
38    rx.setMinimal(true);
39
40    if (rx.indexIn(lastHtml) == -1) {
41        EParseException(tr("Could not find the given form."))
42                .addDebugInfo("formIdOrName", formIdOrName)
43                .addDebugInfo("html", lastHtml)
44                .raise();
45    }
46
47    /* Correct url */
48    QString url = urldecodeString(rx.cap(1));
49    url.replace(":443", "", Qt::CaseInsensitive);
50
51    /* Post it */
52    return syncPost(url, posts, postType);
53}
54
55QString HttpHelper::replaceEncodedUTF8Chars(const QString &str) {
56    QString s = str;
57
58    QRegExp rx("&#(\\d+);");
59    int idx = -1;
60    while ((idx = rx.indexIn(s, idx+1)) >= 0) {
61        s.replace(idx, rx.cap(0).length(), QChar(rx.cap(1).toInt()));
62    }
63    return s;
64}
65
66}
Note: See TracBrowser for help on using the repository browser.