tizen beta release
[framework/web/wrt-commons.git] / modules / vcore / src / vcore / SoupMessageSendBase.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*!
17  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
18  * @version     0.1
19  * @file        SoupMessageSendBase.h
20  * @brief       Simple wrapper for soup.
21  */
22 #ifndef _SRC_VALIDATION_CORE_SOUP_MESSAGE_SEND_BASE_H_
23 #define _SRC_VALIDATION_CORE_SOUP_MESSAGE_SEND_BASE_H_
24
25 #include <map>
26 #include <vector>
27 #include <string>
28
29 #include <libsoup/soup.h>
30
31 namespace SoupWrapper {
32
33 class SoupMessageSendBase {
34   public:
35
36     typedef std::vector<char> MessageBuffer;
37     typedef std::map<std::string,std::string> HeaderMap;
38
39     enum RequestStatus {
40         REQUEST_STATUS_OK,
41         REQUEST_STATUS_CONNECTION_ERROR
42     };
43
44     SoupMessageSendBase();
45
46     virtual ~SoupMessageSendBase();
47
48     /**
49      * Add specific information to request header.
50      *
51      * @param[in] property property name (for example "Host")
52      * @param[in] value property value (for example "onet.pl:80")
53      */
54     void setHeader(const std::string &property,
55                 const std::string &value);
56
57     /**
58      * Set request destination.
59      *
60      * @param[in] host - full path to source (http://onet.pl/index.html)
61      */
62     void setHost(const std::string &host);
63
64     /**
65      * Set body of request.
66      *
67      * @param[in] contentType (for example: "application/ocsp-request")
68      * @param[in] message body of reqeust
69      */
70     void setRequest(const std::string &contentType,
71                 const MessageBuffer &message);
72
73     /**
74      * Set network timeout. Default is 30 seconds.
75      *
76      * @param[in] seconds timeout in seconds
77      */
78     void setTimeout(int seconds);
79
80     /**
81      * How many erros soup will accept before he will terminate connection.
82      * Default is 5.
83      *
84      * @param[in] retry number
85      */
86     void setRetry(int retry);
87
88     /**
89      * Get response from serwer.
90      */
91     MessageBuffer getResponse() const;
92
93   protected:
94
95     SoupMessage* createRequest();
96
97     enum Status {
98         STATUS_IDLE,
99         STATUS_SEND_SYNC,
100         STATUS_SEND_ASYNC
101     };
102
103     Status m_status;
104
105     int m_timeout;
106     int m_tryCount;
107
108     std::string m_host;
109     std::string m_requestType;
110     MessageBuffer m_requestBuffer;
111     MessageBuffer m_responseBuffer;
112     HeaderMap m_headerMap;
113 };
114
115 } // namespace ValidationCore
116
117 #endif