Code

fix some includes
[inkscape.git] / src / dom / io / httpclient.cpp
1 /**\r
2  * Phoebe DOM Implementation.\r
3  *\r
4  * This is a C++ approximation of the W3C DOM model, which follows\r
5  * fairly closely the specifications in the various .idl files, copies of\r
6  * which are provided for reference.  Most important is this one:\r
7  *\r
8  * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html\r
9  *\r
10  * Authors:\r
11  *   Bob Jamison\r
12  *\r
13  * Copyright (C) 2006 Bob Jamison\r
14  *\r
15  *  This library is free software; you can redistribute it and/or\r
16  *  modify it under the terms of the GNU Lesser General Public\r
17  *  License as published by the Free Software Foundation; either\r
18  *  version 2.1 of the License, or (at your option) any later version.\r
19  *\r
20  *  This library is distributed in the hope that it will be useful,\r
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
23  *  Lesser General Public License for more details.\r
24  *\r
25  *  You should have received a copy of the GNU Lesser General Public\r
26  *  License along with this library; if not, write to the Free Software\r
27  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
28  */\r
29 \r
30 \r
31 \r
32 #include "httpclient.h"\r
33 \r
34 namespace org\r
35 {\r
36 namespace w3c\r
37 {\r
38 namespace dom\r
39 {\r
40 namespace io\r
41 {\r
42 \r
43 \r
44 \r
45 \r
46 /**\r
47  *\r
48  */\r
49 HttpClient::HttpClient()\r
50 {\r
51 }\r
52 \r
53 \r
54 /**\r
55  *\r
56  */\r
57 HttpClient::~HttpClient()\r
58 {\r
59 }\r
60 \r
61 \r
62 /**\r
63  *\r
64  */\r
65 bool HttpClient::openGet(const URI &uri)\r
66 {\r
67 \r
68     socket.disconnect();\r
69 \r
70     if (uri.getScheme() == URI::SCHEME_HTTP)\r
71         socket.enableSSL(false);\r
72     else if (uri.getScheme() == URI::SCHEME_HTTPS)\r
73         socket.enableSSL(true);\r
74     else\r
75         {\r
76         printf("Bad proto scheme:%d\n", uri.getScheme());\r
77         return false;\r
78         }\r
79 \r
80     DOMString host = uri.getHost();\r
81     int port       = uri.getPort();\r
82     DOMString path = uri.getPath();\r
83     if (path.size() == 0)\r
84         path = "/";\r
85 \r
86     //printf("host:%s port:%d, path:%s\n", host.c_str(), port, path.c_str());\r
87 \r
88     if (!socket.connect(host, port))\r
89         {\r
90         return false;\r
91         }\r
92 \r
93     DOMString msg = "GET ";\r
94     msg.append(path);\r
95     msg.append(" HTTP/1.0\r\n\r\n");\r
96     //printf("msg:'%s'\n", msg.c_str());\r
97 \r
98     //# Make the request\r
99     if (!socket.write(msg))\r
100         {\r
101         return false;\r
102         }\r
103 \r
104     //# Read the HTTP headers\r
105     while (true)\r
106         {\r
107         if (!socket.readLine(msg))\r
108             return false;\r
109         printf("header:'%s'\n", msg.c_str());\r
110         if (msg.size() < 1)\r
111             break;\r
112         }\r
113 \r
114     return true;\r
115 }\r
116 \r
117 \r
118 /**\r
119  *\r
120  */\r
121 int HttpClient::read()\r
122 {\r
123     int ret = socket.read();\r
124     return ret;\r
125 }\r
126 \r
127 /**\r
128  *\r
129  */\r
130 bool HttpClient::write(int ch)\r
131 {\r
132     if (!socket.write(ch))\r
133         return false;\r
134     return true;\r
135 }\r
136 \r
137 /**\r
138  *\r
139  */\r
140 bool HttpClient::write(const DOMString &msg)\r
141 {\r
142     if (!socket.write(msg))\r
143         return false;\r
144     return true;\r
145 }\r
146 \r
147 /**\r
148  *\r
149  */\r
150 bool HttpClient::close()\r
151 {\r
152     socket.disconnect();\r
153     return true;\r
154 }\r
155 \r
156 \r
157 \r
158 }  //namespace io\r
159 }  //namespace dom\r
160 }  //namespace w3c\r
161 }  //namespace org\r
162 \r
163 \r
164 //#########################################################################\r
165 //# E N D    O F    F I L E\r
166 //#########################################################################\r
167 \r