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 SoupMessageSendSync.cpp
20 * @brief Implementation of soup synchronous interface.
22 #include "SoupMessageSendSync.h"
29 #include <dpl/log/log.h>
31 namespace SoupWrapper {
33 SoupMessageSendBase::RequestStatus SoupMessageSendSync::sendSync()
35 Assert(m_status == STATUS_IDLE);
36 m_status = STATUS_SEND_SYNC;
38 ScopedGMainContext context(g_main_context_new());
40 std::unique_ptr<char,std::function<void(void*)> >
41 proxy(vconf_get_str(VCONFKEY_NETWORK_PROXY), free);
43 std::unique_ptr <SoupURI, std::function<void(SoupURI*)> >
44 proxyURI(soup_uri_new (proxy.get()), soup_uri_free);
46 LogDebug("Proxy ptr:" << (void*)proxy.get() <<
47 " Proxy addr: " << proxy.get());
49 for(int tryCount = 0; tryCount < m_tryCount; ++ tryCount){
50 LogDebug("Try(" << tryCount << ") to download " << m_host);
52 ScopedSoupSession session(soup_session_async_new_with_options(
53 SOUP_SESSION_ASYNC_CONTEXT,
57 SOUP_SESSION_PROXY_URI,
61 ScopedSoupMessage msg;
63 msg.Reset(createRequest());
66 LogError("Unable to send HTTP request.");
67 m_status = STATUS_IDLE;
68 return REQUEST_STATUS_CONNECTION_ERROR;
70 soup_session_send_message(&*session, &*msg);
72 // if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code))
74 if (msg->status_code == SOUP_STATUS_OK) {
75 m_responseBuffer.resize(msg->response_body->length);
76 memcpy(&m_responseBuffer[0],
77 msg->response_body->data,
78 msg->response_body->length);
80 m_status = STATUS_IDLE;
81 return REQUEST_STATUS_OK;
83 LogWarning("Soup failed with code " << msg->status_code
84 << " message \n------------\n"
85 << msg->response_body->data
86 << "\n--------------\n");
90 m_status = STATUS_IDLE;
91 return REQUEST_STATUS_CONNECTION_ERROR;
94 } // namespave ValidationCore