summaryrefslogtreecommitdiff
path: root/libs/net/grl-net-wc.h
blob: 082f5cbebd1b9d4614e6b3a32ddf4893423ecc4f (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * Copyright (C) 2010, 2011 Igalia S.L.
 * Copyright (C) 2012 Canonical Ltd.
 *
 * Contact: Iago Toral Quiroga <itoral@igalia.com>
 *
 * Authors: Víctor M. Jáquez L. <vjaquez@igalia.com>
 *          Jens Georg <jensg@openismus.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef _GRL_NET_WC_H_
#define _GRL_NET_WC_H_

#include <gio/gio.h>

G_BEGIN_DECLS

/**
 * GrlNetWcError:
 * @GRL_NET_WC_ERROR_UNAVAILABLE: Deprecated. For generic errors, you
 * should check for G_IO_ERROR_FAILED from G_IO_ERROR domain.
 * @GRL_NET_WC_ERROR_PROTOCOL_ERROR: Invalid URI or header
 * @GRL_NET_WC_ERROR_AUTHENTICATION_REQUIRED: Required authentication
 * @GRL_NET_WC_ERROR_NOT_FOUND: Request resource not found
 * @GRL_NET_WC_ERROR_CONFLICT: The entry has been modified since is was
 * downloaded
 * @GRL_NET_WC_ERROR_FORBIDDEN: TBD
 * @GRL_NET_WC_ERROR_NETWORK_ERROR: Cannot connect to the server
 * @GRL_NET_WC_ERROR_PROXY_ERROR: Deprecated. You should check for
 * G_IO_ERROR_PROXY_FAILED from G_IO_ERROR domain.
 * @GRL_NET_WC_ERROR_CANCELLED: Deprecated. You should check for
 * G_IO_ERROR_CANCELLED from G_IO_ERROR domain.
 *
 * These constants identify all the available errors managed by
 * the web client.
 */
typedef enum {
	GRL_NET_WC_ERROR_UNAVAILABLE = 1,
	GRL_NET_WC_ERROR_PROTOCOL_ERROR,
	GRL_NET_WC_ERROR_AUTHENTICATION_REQUIRED,
	GRL_NET_WC_ERROR_NOT_FOUND,
	GRL_NET_WC_ERROR_CONFLICT,
	GRL_NET_WC_ERROR_FORBIDDEN,
	GRL_NET_WC_ERROR_NETWORK_ERROR,
	GRL_NET_WC_ERROR_PROXY_ERROR,
	GRL_NET_WC_ERROR_CANCELLED
} GrlNetWcError;

#define GRL_TYPE_NET_WC				\
  (grl_net_wc_get_type ())

#define GRL_NET_WC(obj)						\
  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRL_TYPE_NET_WC, GrlNetWc))

#define GRL_IS_NET_WC(obj)					\
  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRL_TYPE_NET_WC))

#define GRL_NET_WC_CLASS(klass)					\
  (G_TYPE_CHECK_CLASS_CAST((klass), GRL_TYPE_NET_WC, GrlNetWcClass))

#define GRL_IS_NET_WC_CLASS(klass)				\
  (G_TYPE_CHECK_CLASS_TYPE((klass), GRL_TYPE_NET_WC))

#define GRL_NET_WC_GET_CLASS(obj)					\
  (G_TYPE_INSTANCE_GET_CLASS ((obj), GRL_TYPE_NET_WC, GrlNetWcClass))

#define GRL_NET_WC_ERROR grl_net_wc_error_quark ()

typedef struct _GrlNetWc        GrlNetWc;
typedef struct _GrlNetWcClass   GrlNetWcClass;
typedef struct _GrlNetWcPrivate GrlNetWcPrivate;

G_DEFINE_AUTOPTR_CLEANUP_FUNC (GrlNetWc, g_object_unref)

/**
 * GrlNetWcClass:
 * @parent_class: the parent class structure
 *
 * Grilo web client helper class.
 *
 * It's a simple and thin web client to be used by the sources to download
 * content from Internet.
 */
struct _GrlNetWcClass
{
  GObjectClass parent_class;
};

GType grl_net_wc_get_type (void) G_GNUC_CONST;

GQuark grl_net_wc_error_quark (void) G_GNUC_CONST;

GrlNetWc *grl_net_wc_new (void);

void grl_net_wc_request_async (GrlNetWc *self,
			       const char *uri,
			       GCancellable *cancellable,
			       GAsyncReadyCallback callback,
			       gpointer user_data);

void grl_net_wc_request_with_headers_hash_async (GrlNetWc *self,
                                                 const char *uri,
                                                 GHashTable *headers,
                                                 GCancellable *cancellable,
                                                 GAsyncReadyCallback callback,
                                                 gpointer user_data);

void grl_net_wc_request_with_headers_async (GrlNetWc *self,
                                            const char *uri,
                                            GCancellable *cancellable,
                                            GAsyncReadyCallback callback,
                                            gpointer user_data,
                                            ...) G_GNUC_NULL_TERMINATED;

gboolean grl_net_wc_request_finish (GrlNetWc *self,
				    GAsyncResult *result,
				    gchar **content,
				    gsize *length,
				    GError **error);

void grl_net_wc_set_log_level (GrlNetWc *self,
			       guint log_level);

void grl_net_wc_set_throttling (GrlNetWc *self,
				guint throttling);

void grl_net_wc_set_cache (GrlNetWc *self,
                           gboolean use_cache);

void grl_net_wc_set_cache_size (GrlNetWc *self,
                                guint cache_size);

void grl_net_wc_flush_delayed_requests (GrlNetWc *self);

G_END_DECLS

#endif /* _GRL_NET_WC_H_ */