1 /* 2 * librest - RESTful web services access 3 * Copyright (c) 2008, 2009, Intel Corporation. 4 * 5 * Authors: Rob Bradford <rob@linux.intel.com> 6 * Ross Burton <ross@linux.intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms and conditions of the GNU Lesser General Public License, 10 * version 2.1, as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope it will be useful, but WITHOUT ANY 13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this program; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 */ 22 23 #ifndef _REST_PROXY 24 #define _REST_PROXY 25 26 #include <glib-object.h> 27 #include <libsoup/soup-session-feature.h> 28 #include <rest/rest-proxy-auth.h> 29 #include <rest/rest-proxy-call.h> 30 31 G_BEGIN_DECLS 32 33 #define REST_TYPE_PROXY rest_proxy_get_type() 34 35 #define REST_PROXY(obj) \ 36 (G_TYPE_CHECK_INSTANCE_CAST ((obj), REST_TYPE_PROXY, RestProxy)) 37 38 #define REST_PROXY_CLASS(klass) \ 39 (G_TYPE_CHECK_CLASS_CAST ((klass), REST_TYPE_PROXY, RestProxyClass)) 40 41 #define REST_IS_PROXY(obj) \ 42 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), REST_TYPE_PROXY)) 43 44 #define REST_IS_PROXY_CLASS(klass) \ 45 (G_TYPE_CHECK_CLASS_TYPE ((klass), REST_TYPE_PROXY)) 46 47 #define REST_PROXY_GET_CLASS(obj) \ 48 (G_TYPE_INSTANCE_GET_CLASS ((obj), REST_TYPE_PROXY, RestProxyClass)) 49 50 typedef struct _RestProxy RestProxy; 51 typedef struct _RestProxyClass RestProxyClass; 52 53 /** 54 * RestProxy: 55 * 56 * #RestProxy has no publicly available members. 57 */ 58 struct _RestProxy { 59 GObject parent; 60 }; 61 62 /** 63 * RestProxyClass: 64 * @bind_valist: Virtual function called to bind parameters. 65 * @new_call: Virtual function called to construct a new #RestProxyCall. 66 * @simple_run_valist: Virtual function called when making a "simple" call. 67 * @authenticate: class handler for the #RestProxy::authenticate signal 68 * 69 * Class structure for #RestProxy for subclasses to implement specialised 70 * behaviour. 71 * 72 * Typically subclasses will override @new_call to construct a subclass of 73 * #RestProxyCall. 74 */ 75 struct _RestProxyClass { 76 /*< private >*/ 77 GObjectClass parent_class; 78 /*< public >*/ 79 gboolean (*bind_valist)(RestProxy *proxy, va_list params); 80 RestProxyCall *(*new_call)(RestProxy *proxy); 81 gboolean (*simple_run_valist)(RestProxy *proxy, gchar **payload, 82 goffset *len, GError **error, va_list params); 83 gboolean (*authenticate)(RestProxy *proxy, RestProxyAuth *auth, gboolean retrying); 84 85 /*< private >*/ 86 /* padding for future expansion */ 87 gpointer _padding_dummy[7]; 88 }; 89 90 #define REST_PROXY_ERROR rest_proxy_error_quark () 91 92 /** 93 * RestProxyError: 94 * @REST_PROXY_ERROR_CANCELLED: Cancelled 95 * @REST_PROXY_ERROR_RESOLUTION: Resolution 96 * @REST_PROXY_ERROR_CONNECTION: Connection 97 * @REST_PROXY_ERROR_SSL: SSL 98 * @REST_PROXY_ERROR_IO: Input/Output 99 * @REST_PROXY_ERROR_FAILED: Failure 100 * @REST_PROXY_ERROR_HTTP_MULTIPLE_CHOICES: HTTP/Multiple choices 101 * @REST_PROXY_ERROR_HTTP_MOVED_PERMANENTLY: HTTP/Moved permanently 102 * @REST_PROXY_ERROR_HTTP_FOUND: HTTP/Found 103 * @REST_PROXY_ERROR_HTTP_SEE_OTHER: HTTP/See other 104 * @REST_PROXY_ERROR_HTTP_NOT_MODIFIED: HTTP/Not modified 105 * @REST_PROXY_ERROR_HTTP_USE_PROXY: HTTP/Use proxy 106 * @REST_PROXY_ERROR_HTTP_THREEOHSIX: HTTP/306 107 * @REST_PROXY_ERROR_HTTP_TEMPORARY_REDIRECT: HTTP/Temporary redirect 108 * @REST_PROXY_ERROR_HTTP_BAD_REQUEST: HTTP/Bad request 109 * @REST_PROXY_ERROR_HTTP_UNAUTHORIZED: HTTP/Unauthorized 110 * @REST_PROXY_ERROR_HTTP_FOUROHTWO: HTTP/402 111 * @REST_PROXY_ERROR_HTTP_FORBIDDEN: HTTP/Forbidden 112 * @REST_PROXY_ERROR_HTTP_NOT_FOUND: HTTP/Not found 113 * @REST_PROXY_ERROR_HTTP_METHOD_NOT_ALLOWED: HTTP/Method not allowed 114 * @REST_PROXY_ERROR_HTTP_NOT_ACCEPTABLE: HTTP/Not acceptable 115 * @REST_PROXY_ERROR_HTTP_PROXY_AUTHENTICATION_REQUIRED: HTTP/Proxy authentication required 116 * @REST_PROXY_ERROR_HTTP_REQUEST_TIMEOUT: HTTP/Request timeout 117 * @REST_PROXY_ERROR_HTTP_CONFLICT: HTTP/Conflict 118 * @REST_PROXY_ERROR_HTTP_GONE: HTTP/Gone 119 * @REST_PROXY_ERROR_HTTP_LENGTH_REQUIRED: HTTP/Length required 120 * @REST_PROXY_ERROR_HTTP_PRECONDITION_FAILED: HTTP/Precondition failed 121 * @REST_PROXY_ERROR_HTTP_REQUEST_ENTITY_TOO_LARGE: HTTP/Request entity too large 122 * @REST_PROXY_ERROR_HTTP_REQUEST_URI_TOO_LONG: HTTP/Request URI too long 123 * @REST_PROXY_ERROR_HTTP_UNSUPPORTED_MEDIA_TYPE: HTTP/Unsupported media type 124 * @REST_PROXY_ERROR_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE: HTTP/Requested range not satisfiable 125 * @REST_PROXY_ERROR_HTTP_EXPECTATION_FAILED: HTTP/Expectation failed 126 * @REST_PROXY_ERROR_HTTP_INTERNAL_SERVER_ERROR: HTTP/Internal server error 127 * @REST_PROXY_ERROR_HTTP_NOT_IMPLEMENTED: HTTP/Not implemented 128 * @REST_PROXY_ERROR_HTTP_BAD_GATEWAY: HTTP/Bad gateway 129 * @REST_PROXY_ERROR_HTTP_SERVICE_UNAVAILABLE: HTTP/Service unavailable 130 * @REST_PROXY_ERROR_HTTP_GATEWAY_TIMEOUT: HTTP/Gateway timeout 131 * @REST_PROXY_ERROR_HTTP_HTTP_VERSION_NOT_SUPPORTED: HTTP/Version not supported 132 * 133 * Error domain used when returning errors from a #RestProxy. 134 */ 135 typedef enum { 136 REST_PROXY_ERROR_CANCELLED = 1, 137 REST_PROXY_ERROR_RESOLUTION, 138 REST_PROXY_ERROR_CONNECTION, 139 REST_PROXY_ERROR_SSL, 140 REST_PROXY_ERROR_IO, 141 REST_PROXY_ERROR_FAILED, 142 143 REST_PROXY_ERROR_HTTP_MULTIPLE_CHOICES = 300, 144 REST_PROXY_ERROR_HTTP_MOVED_PERMANENTLY = 301, 145 REST_PROXY_ERROR_HTTP_FOUND = 302, 146 REST_PROXY_ERROR_HTTP_SEE_OTHER = 303, 147 REST_PROXY_ERROR_HTTP_NOT_MODIFIED = 304, 148 REST_PROXY_ERROR_HTTP_USE_PROXY = 305, 149 REST_PROXY_ERROR_HTTP_THREEOHSIX = 306, 150 REST_PROXY_ERROR_HTTP_TEMPORARY_REDIRECT = 307, 151 REST_PROXY_ERROR_HTTP_BAD_REQUEST = 400, 152 REST_PROXY_ERROR_HTTP_UNAUTHORIZED = 401, 153 REST_PROXY_ERROR_HTTP_FOUROHTWO = 402, 154 REST_PROXY_ERROR_HTTP_FORBIDDEN = 403, 155 REST_PROXY_ERROR_HTTP_NOT_FOUND = 404, 156 REST_PROXY_ERROR_HTTP_METHOD_NOT_ALLOWED = 405, 157 REST_PROXY_ERROR_HTTP_NOT_ACCEPTABLE = 406, 158 REST_PROXY_ERROR_HTTP_PROXY_AUTHENTICATION_REQUIRED = 407, 159 REST_PROXY_ERROR_HTTP_REQUEST_TIMEOUT = 408, 160 REST_PROXY_ERROR_HTTP_CONFLICT = 409, 161 REST_PROXY_ERROR_HTTP_GONE = 410, 162 REST_PROXY_ERROR_HTTP_LENGTH_REQUIRED = 411, 163 REST_PROXY_ERROR_HTTP_PRECONDITION_FAILED = 412, 164 REST_PROXY_ERROR_HTTP_REQUEST_ENTITY_TOO_LARGE = 413, 165 REST_PROXY_ERROR_HTTP_REQUEST_URI_TOO_LONG = 414, 166 REST_PROXY_ERROR_HTTP_UNSUPPORTED_MEDIA_TYPE = 415, 167 REST_PROXY_ERROR_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416, 168 REST_PROXY_ERROR_HTTP_EXPECTATION_FAILED = 417, 169 REST_PROXY_ERROR_HTTP_INTERNAL_SERVER_ERROR = 500, 170 REST_PROXY_ERROR_HTTP_NOT_IMPLEMENTED = 501, 171 REST_PROXY_ERROR_HTTP_BAD_GATEWAY = 502, 172 REST_PROXY_ERROR_HTTP_SERVICE_UNAVAILABLE = 503, 173 REST_PROXY_ERROR_HTTP_GATEWAY_TIMEOUT = 504, 174 REST_PROXY_ERROR_HTTP_HTTP_VERSION_NOT_SUPPORTED = 505, 175 } RestProxyError; 176 177 GQuark rest_proxy_error_quark (void); 178 179 GType rest_proxy_get_type (void); 180 181 RestProxy *rest_proxy_new (const gchar *url_format, 182 gboolean binding_required); 183 184 RestProxy * 185 rest_proxy_new_with_authentication (const gchar *url_format, 186 gboolean binding_required, 187 const gchar *username, 188 const gchar *password); 189 190 gboolean rest_proxy_bind (RestProxy *proxy, 191 ...); 192 193 gboolean rest_proxy_bind_valist (RestProxy *proxy, 194 va_list params); 195 196 void rest_proxy_set_user_agent (RestProxy *proxy, const char *user_agent); 197 198 const gchar *rest_proxy_get_user_agent (RestProxy *proxy); 199 200 void rest_proxy_add_soup_feature (RestProxy *proxy, 201 SoupSessionFeature *feature); 202 203 RestProxyCall *rest_proxy_new_call (RestProxy *proxy); 204 205 G_GNUC_NULL_TERMINATED 206 gboolean rest_proxy_simple_run (RestProxy *proxy, 207 gchar **payload, 208 goffset *len, 209 GError **error, 210 ...); 211 gboolean rest_proxy_simple_run_valist (RestProxy *proxy, 212 gchar **payload, 213 goffset *len, 214 GError **error, 215 va_list params); 216 G_END_DECLS 217 218 #endif /* _REST_PROXY */ 219 220