2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19 * @file SoupMessageSendBase.cpp
20 * @brief Simple wrapper for soup.
22 #include "SoupMessageSendBase.h"
24 #include <dpl/assert.h>
25 #include <dpl/foreach.h>
26 #include <dpl/log/log.h>
28 namespace SoupWrapper {
30 SoupMessageSendBase::SoupMessageSendBase()
31 : m_status(STATUS_IDLE)
36 SoupMessageSendBase::~SoupMessageSendBase(){
37 Assert(m_status == STATUS_IDLE);
40 void SoupMessageSendBase::setHeader(const std::string &property, const std::string &value){
41 Assert(m_status == STATUS_IDLE);
42 m_headerMap[property] = value;
45 void SoupMessageSendBase::setHost(const std::string &host){
46 Assert(m_status == STATUS_IDLE);
50 void SoupMessageSendBase::setRequest(const std::string &contentType, const MessageBuffer &message){
51 Assert(m_status == STATUS_IDLE);
52 m_requestType = contentType;
53 m_requestBuffer = message;
56 SoupMessageSendBase::MessageBuffer SoupMessageSendBase::getResponse() const {
57 Assert(m_status == STATUS_IDLE);
58 return m_responseBuffer;
61 void SoupMessageSendBase::setTimeout(int seconds) {
62 Assert(m_status == STATUS_IDLE);
67 void SoupMessageSendBase::setRetry(int retry) {
68 Assert(m_status == STATUS_IDLE);
70 m_tryCount = retry + 1;
74 SoupMessage* SoupMessageSendBase::createRequest(){
77 LogInfo("Soup message will be send to: " << m_host.c_str());
79 if (!m_requestBuffer.empty()) {
80 message = soup_message_new("POST", m_host.c_str());
82 message = soup_message_new("GET", m_host.c_str());
86 LogError("Error creating request!");
90 FOREACH(it, m_headerMap){
91 soup_message_headers_append(message->request_headers,
96 if (!m_requestBuffer.empty()) {
97 soup_message_set_http_version(message, SOUP_HTTP_1_0);
98 soup_message_set_request(message,
99 m_requestType.c_str(),
102 m_requestBuffer.size());
104 soup_message_set_flags(message, SOUP_MESSAGE_NO_REDIRECT);
108 } // namespace ValidationCore