source: SMSSender/common/network/snetworkhelper_params.cpp @ 438:81606f5c0c65

Last change on this file since 438:81606f5c0c65 was 438:81606f5c0c65, checked in by Sämy Zehnder <saemy.zehnder@…>, 8 years ago
  • Makes smssender exception-free.
  • Replaces Q_ASSERT with S_ASSERT which segfaults even in release mode.
File size: 2.4 KB
Line 
1/*
2  smssender - A frontend for fast and easy SMS sending over different gateways.
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
19#include "snetworkhelper.h"
20
21SKeyValueParam::SKeyValueParam(const QByteArray &key, const QByteArray &value)
22    : m_key(key)
23    , m_value(value)
24{
25}
26
27
28QByteArray SKeyValueParam::encode(SNetworkHelper::PostType postType) const {
29    switch (postType) {
30        case SNetworkHelper::ptUrlEncoded: {
31            QUrl params;
32            params.addEncodedQueryItem(key(), value().toPercentEncoding());
33            return params.encodedQuery();
34        }
35
36        case SNetworkHelper::ptMultipart:
37        default:{
38            return "Content-Disposition: form-data; name=\"" + key() + "\"" + "\r\n" +
39                   "\r\n" +
40                   value();
41        }
42    }
43}
44
45QByteArray SKeyValueParam::key() const {
46    return m_key;
47}
48QByteArray SKeyValueParam::value() const {
49    return m_value;
50}
51
52/**************************************************/
53
54SFileParam::SFileParam(const QByteArray &key, const QByteArray &fileName, const QByteArray &fileType, const QByteArray &value)
55    : SKeyValueParam(key, value)
56    , m_fileName(fileName)
57    , m_fileType(fileType)
58{
59}
60
61
62QByteArray SFileParam::encode(SNetworkHelper::PostType postType) const {
63    S_ASSERT(postType == SNetworkHelper::ptMultipart); // Only multipart is allowed
64
65    return "Content-Disposition: form-data; name=\"" + key() + "\"; filename=\"" + fileName() + "\"" + "\r\n" +
66           "Content-Type: " + fileType() + "\r\n" +
67           "Content-Transfer-Encoding: binary" + "\r\n" +
68           "\r\n" +
69           value();
70}
71
72QByteArray SFileParam::fileName() const {
73    return m_fileName;
74}
75QByteArray SFileParam::fileType() const {
76    return m_fileType;
77}
Note: See TracBrowser for help on using the repository browser.