libxrdeveloper's documentation
xr-http.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2008 Ondrej Jirman <ondrej.jirman@zonio.net>
3  *
4  * This file is part of libxr.
5  *
6  * Libxr is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU Lesser General Public License as published by the Free
8  * Software Foundation, either version 2 of the License, or (at your option) any
9  * later version.
10  *
11  * Libxr is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13  * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with libxr. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __XR_HTTP_H__
21 #define __XR_HTTP_H__
22 
23 #include <glib.h>
24 #include <openssl/bio.h>
25 
46 typedef struct _xr_http xr_http;
47 
50 typedef enum {
51  XR_HTTP_NONE,
52  XR_HTTP_REQUEST,
53  XR_HTTP_RESPONSE
55 
56 #define XR_HTTP_ERROR xr_http_error_quark()
57 
58 typedef enum
59 {
60  XR_HTTP_ERROR_FAILED = 1
61 } XRHttpError;
62 
63 G_BEGIN_DECLS
64 
67 void xr_http_init();
68 
75 xr_http* xr_http_new(BIO* bio);
76 
81 void xr_http_free(xr_http* http);
82 
83 /* receive API */
84 
92 gboolean xr_http_read_header(xr_http* http, GError** err);
93 
101 const char* xr_http_get_header(xr_http* http, const char* name);
102 
109 void xr_http_set_basic_auth(xr_http* http, const char* username, const char* password);
110 
121 gboolean xr_http_get_basic_auth(xr_http* http, char** username, char** password);
122 
129 const char* xr_http_get_method(xr_http* http);
130 
137 int xr_http_get_code(xr_http* http);
138 
145 const char* xr_http_get_resource(xr_http* http);
146 
153 int xr_http_get_version(xr_http* http);
154 
163 
172 gssize xr_http_get_message_length(xr_http* http);
173 
183 gssize xr_http_read(xr_http* http, char* buffer, gsize length, GError** err);
184 
192 GString* xr_http_read_all(xr_http* http, GError** err);
193 
194 /* transmit API */
195 
202 void xr_http_set_header(xr_http* http, const char* name, const char* value);
203 
210 
216 void xr_http_set_message_length(xr_http* http, gsize length);
217 
225 void xr_http_setup_request(xr_http* http, const char* method, const char* resource, const char* host);
226 
232 void xr_http_setup_response(xr_http* http, int code);
233 
244 gboolean xr_http_write_header(xr_http* http, GError** err);
245 
260 gboolean xr_http_write(xr_http* http, const char* buffer, gsize length, GError** err);
261 
272 gboolean xr_http_write_complete(xr_http* http, GError** err);
273 
283 gboolean xr_http_write_all(xr_http* http, const char* buffer, gssize length, GError** err);
284 
291 gboolean xr_http_is_ready(xr_http* http);
292 
300 gboolean xr_http_has_pending_request(xr_http* http, time_t timeout);
301 
302 GQuark xr_http_error_quark();
303 
304 G_END_DECLS
305 
306 #endif
int xr_http_get_code(xr_http *http)
Get HTTP response code.
xr_http_message_type xr_http_get_message_type(xr_http *http)
Get message type.
G_BEGIN_DECLS void xr_http_init()
Initialize HTTP transport.
void xr_http_set_header(xr_http *http, const char *name, const char *value)
Set HTTP header for outgoing message.
gboolean xr_http_has_pending_request(xr_http *http, time_t timeout)
Check if object has pending request to be read within given time.
const char * xr_http_get_resource(xr_http *http)
Get resource (only if xr_http_get_message_type() == XR_HTTP_REQUEST).
int xr_http_get_version(xr_http *http)
Get HTTP request version.
gboolean xr_http_write(xr_http *http, const char *buffer, gsize length, GError **err)
Write response body.
xr_http_message_type
Message type (request/response).
Definition: xr-http.h:50
gssize xr_http_read(xr_http *http, char *buffer, gsize length, GError **err)
Read HTTP message body.
const char * xr_http_get_header(xr_http *http, const char *name)
Get specific HTTP header from incomming messages by its name.
gboolean xr_http_write_header(xr_http *http, GError **err)
Write outgoing message header.
struct _xr_http xr_http
Opaque HTTP object.
Definition: xr-http.h:46
void xr_http_set_message_type(xr_http *http, xr_http_message_type type)
Set outgoing message type.
void xr_http_setup_request(xr_http *http, const char *method, const char *resource, const char *host)
Setup outgoing request.
gboolean xr_http_write_all(xr_http *http, const char *buffer, gssize length, GError **err)
Write whole message body at once from the GString.
gboolean xr_http_write_complete(xr_http *http, GError **err)
Complete message.
void xr_http_set_basic_auth(xr_http *http, const char *username, const char *password)
Set Authorization: Basic header.
gboolean xr_http_get_basic_auth(xr_http *http, char **username, char **password)
Decode Authorization header.
void xr_http_setup_response(xr_http *http, int code)
Setup outgoing response.
gssize xr_http_get_message_length(xr_http *http)
Get length of the message body (Content-Length header value).
GString * xr_http_read_all(xr_http *http, GError **err)
Read whole message body into a GString object.
void xr_http_set_message_length(xr_http *http, gsize length)
Set Content-Length header for outgoing message.
void xr_http_free(xr_http *http)
Destroy HTTP transport object.
gboolean xr_http_is_ready(xr_http *http)
Check if object is ready to receive or send message.
xr_http * xr_http_new(BIO *bio)
Create new HTTP transport object.
const char * xr_http_get_method(xr_http *http)
Get HTTP method.
gboolean xr_http_read_header(xr_http *http, GError **err)
Read HTTP message header.
Documentation for libxr, Wed Apr 27 2016 22:07:49.