summaryrefslogtreecommitdiff
path: root/gweb/gweb.h
blob: 104345e81c39d8ae37b4ee1b02be5ffd2e44799a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 *
 *  Web service library with GLib integration
 *
 *  Copyright (C) 2009-2012  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef __G_WEB_H
#define __G_WEB_H

#include <stdint.h>

#include <glib.h>

#ifdef __cplusplus
extern "C" {
#endif

struct _GWeb;
struct _GWebResult;
struct _GWebParser;

typedef struct _GWeb GWeb;
typedef struct _GWebResult GWebResult;
typedef struct _GWebParser GWebParser;

typedef gboolean (*GWebResultFunc)(GWebResult *result, gpointer user_data);

typedef gboolean (*GWebRouteFunc)(const char *addr, int ai_family,
		int if_index, gpointer user_data);

typedef gboolean (*GWebInputFunc)(const guint8 **data, gsize *length,
							gpointer user_data);

typedef void (*GWebDebugFunc)(const char *str, gpointer user_data);

GWeb *g_web_new(int index);

GWeb *g_web_ref(GWeb *web);
void g_web_unref(GWeb *web);

void g_web_set_debug(GWeb *web, GWebDebugFunc func, gpointer user_data);

gboolean g_web_supports_tls(void);

gboolean g_web_set_proxy(GWeb *web, const char *proxy);

gboolean g_web_set_address_family(GWeb *web, int family);

gboolean g_web_add_nameserver(GWeb *web, const char *address);

gboolean g_web_set_accept(GWeb *web, const char *format, ...)
				__attribute__((format(printf, 2, 3)));
gboolean g_web_set_user_agent(GWeb *web, const char *format, ...)
				__attribute__((format(printf, 2, 3)));
gboolean g_web_set_ua_profile(GWeb *web, const char *profile);

gboolean g_web_set_http_version(GWeb *web, const char *version);

void g_web_set_close_connection(GWeb *web, gboolean enabled);
gboolean g_web_get_close_connection(GWeb *web);

guint g_web_request_get(GWeb *web, const char *url,
				GWebResultFunc func, GWebRouteFunc route,
				gpointer user_data);
guint g_web_request_post(GWeb *web, const char *url,
				const char *type, GWebInputFunc input,
				GWebResultFunc func, gpointer user_data);
guint g_web_request_post_file(GWeb *web, const char *url,
				const char *type, const char *file,
				GWebResultFunc func, gpointer user_data);

gboolean g_web_cancel_request(GWeb *web, guint id);

guint16 g_web_result_get_status(GWebResult *result);

gboolean g_web_result_get_header(GWebResult *result,
				const char *header, const char **value);
gboolean g_web_result_get_chunk(GWebResult *result,
				const guint8 **chunk, gsize *length);

typedef void (*GWebParserFunc)(const char *str, gpointer user_data);

GWebParser *g_web_parser_new(const char *begin, const char *end,
				GWebParserFunc func, gpointer user_data);

GWebParser *g_web_parser_ref(GWebParser *parser);
void g_web_parser_unref(GWebParser *parser);

void g_web_parser_feed_data(GWebParser *parser,
				const guint8 *data, gsize length);
void g_web_parser_end_data(GWebParser *parser);

#ifdef __cplusplus
}
#endif

#endif /* __G_WEB_H */