| 1 /* purple |
|
| 2 * |
|
| 3 * Purple is the legal property of its developers, whose names are too numerous |
|
| 4 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
| 5 * source distribution. |
|
| 6 * |
|
| 7 * This program is free software; you can redistribute it and/or modify |
|
| 8 * it under the terms of the GNU General Public License as published by |
|
| 9 * the Free Software Foundation; either version 2 of the License, or |
|
| 10 * (at your option) any later version. |
|
| 11 * |
|
| 12 * This program is distributed in the hope that it will be useful, |
|
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 * GNU General Public License for more details. |
|
| 16 * |
|
| 17 * You should have received a copy of the GNU General Public License |
|
| 18 * along with this program; if not, write to the Free Software |
|
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
| 20 */ |
|
| 21 |
|
| 22 #ifndef PURPLE_FACEBOOK_HTTP_H |
|
| 23 #define PURPLE_FACEBOOK_HTTP_H |
|
| 24 |
|
| 25 #include <glib.h> |
|
| 26 #include <libsoup/soup.h> |
|
| 27 |
|
| 28 /** |
|
| 29 * FB_HTTP_ERROR: |
|
| 30 * |
|
| 31 * The #GQuark of the domain of HTTP errors. |
|
| 32 */ |
|
| 33 #define FB_HTTP_ERROR fb_http_error_quark() |
|
| 34 |
|
| 35 /** |
|
| 36 * FbHttpParams: |
|
| 37 * |
|
| 38 * Represents a set of key/value HTTP parameters. |
|
| 39 */ |
|
| 40 typedef GHashTable FbHttpParams; |
|
| 41 |
|
| 42 /** |
|
| 43 * FbHttpError: |
|
| 44 * @FB_HTTP_ERROR_SUCCESS: There is no error. |
|
| 45 * @FB_HTTP_ERROR_NOMATCH: The name does not match anything. |
|
| 46 * |
|
| 47 * The error codes for the #FB_HTTP_ERROR domain. |
|
| 48 */ |
|
| 49 typedef enum |
|
| 50 { |
|
| 51 FB_HTTP_ERROR_SUCCESS = 0, |
|
| 52 FB_HTTP_ERROR_NOMATCH |
|
| 53 } FbHttpError; |
|
| 54 |
|
| 55 /** |
|
| 56 * fb_http_error_quark: |
|
| 57 * |
|
| 58 * Gets the #GQuark of the domain of HTTP errors. |
|
| 59 * |
|
| 60 * Returns: The #GQuark of the domain. |
|
| 61 */ |
|
| 62 GQuark |
|
| 63 fb_http_error_quark(void); |
|
| 64 |
|
| 65 /** |
|
| 66 * fb_http_error_chk: |
|
| 67 * @res: The #SoupMessage. |
|
| 68 * @error: The return location for the #GError or #NULL. |
|
| 69 * |
|
| 70 * Checks a #SoupMessage for success. This optionally assigns an |
|
| 71 * appropriate #GError upon failure. |
|
| 72 * |
|
| 73 * Returns: #TRUE if the request was successful, otherwise #FALSE. |
|
| 74 */ |
|
| 75 gboolean fb_http_error_chk(SoupMessage *res, GError **error); |
|
| 76 |
|
| 77 /** |
|
| 78 * fb_http_params_new: |
|
| 79 * |
|
| 80 * Creates a new #FbHttpParams. The returned #FbHttpParams should be |
|
| 81 * freed with #fb_http_params_free() when no longer needed. Optionally, |
|
| 82 * instead of freeing, the returned #FbHttpParams can be closed with |
|
| 83 * #fb_http_params_close(). |
|
| 84 * |
|
| 85 * Returns: (transfer full): The new #FbHttpParams. |
|
| 86 */ |
|
| 87 FbHttpParams * |
|
| 88 fb_http_params_new(void); |
|
| 89 |
|
| 90 /** |
|
| 91 * fb_http_params_new_parse: |
|
| 92 * @data: The string containing HTTP parameters. |
|
| 93 * @isurl: #TRUE if @data is a URL, otherwise #FALSE. |
|
| 94 * |
|
| 95 * Creates a new #FbHttpParams. This parses the #FbHttpParams from a |
|
| 96 * string, which can be a URL. The returned #FbHttpParams should be |
|
| 97 * freed with #fb_http_params_free() when no longer needed. Optionally, |
|
| 98 * instead of freeing, the returned #FbHttpParams can be closed with |
|
| 99 * #fb_http_params_close(). |
|
| 100 * |
|
| 101 * Returns: (transfer full): The new #FbHttpParams. |
|
| 102 */ |
|
| 103 FbHttpParams * |
|
| 104 fb_http_params_new_parse(const gchar *data, gboolean isurl); |
|
| 105 |
|
| 106 /** |
|
| 107 * fb_http_params_free: |
|
| 108 * @params: The #FbHttpParams. |
|
| 109 * |
|
| 110 * Frees all memory used by the #FbHttpParams. |
|
| 111 */ |
|
| 112 void |
|
| 113 fb_http_params_free(FbHttpParams *params); |
|
| 114 |
|
| 115 /** |
|
| 116 * fb_http_params_get_bool: |
|
| 117 * @params: The #FbHttpParams. |
|
| 118 * @name: The parameter name. |
|
| 119 * @error: The return location for the #GError or #NULL. |
|
| 120 * |
|
| 121 * Gets a boolean value from the #FbHttpParams. This optionally assigns |
|
| 122 * an appropriate #GError upon failure. |
|
| 123 * |
|
| 124 * Return: The boolean value. |
|
| 125 */ |
|
| 126 gboolean |
|
| 127 fb_http_params_get_bool(FbHttpParams *params, const gchar *name, |
|
| 128 GError **error); |
|
| 129 |
|
| 130 /** |
|
| 131 * fb_http_params_get_dbl: |
|
| 132 * @params: The #FbHttpParams. |
|
| 133 * @name: The parameter name. |
|
| 134 * @error: The return location for the #GError or #NULL. |
|
| 135 * |
|
| 136 * Gets a floating point value from the #FbHttpParams. This optionally |
|
| 137 * assigns an appropriate #GError upon failure. |
|
| 138 * |
|
| 139 * Return: The floating point value. |
|
| 140 */ |
|
| 141 gdouble |
|
| 142 fb_http_params_get_dbl(FbHttpParams *params, const gchar *name, |
|
| 143 GError **error); |
|
| 144 |
|
| 145 /** |
|
| 146 * fb_http_params_get_int: |
|
| 147 * @params: The #FbHttpParams. |
|
| 148 * @name: The parameter name. |
|
| 149 * @error: The return location for the #GError or #NULL. |
|
| 150 * |
|
| 151 * Gets an integer value from the #FbHttpParams. This optionally |
|
| 152 * assigns an appropriate #GError upon failure. |
|
| 153 * |
|
| 154 * Return: The integer value. |
|
| 155 */ |
|
| 156 gint64 |
|
| 157 fb_http_params_get_int(FbHttpParams *params, const gchar *name, |
|
| 158 GError **error); |
|
| 159 |
|
| 160 /** |
|
| 161 * fb_http_params_get_str: |
|
| 162 * @params: The #FbHttpParams. |
|
| 163 * @name: The parameter name. |
|
| 164 * @error: The return location for the #GError or #NULL. |
|
| 165 * |
|
| 166 * Gets a string value from the #FbHttpParams. This optionally assigns |
|
| 167 * an appropriate #GError upon failure. |
|
| 168 * |
|
| 169 * Return: The string value. |
|
| 170 */ |
|
| 171 const gchar * |
|
| 172 fb_http_params_get_str(FbHttpParams *params, const gchar *name, |
|
| 173 GError **error); |
|
| 174 |
|
| 175 /** |
|
| 176 * fb_http_params_dup_str: |
|
| 177 * @params: The #FbHttpParams. |
|
| 178 * @name: The parameter name. |
|
| 179 * @error: The return location for the #GError or #NULL. |
|
| 180 * |
|
| 181 * Gets a duplicated string value from the #FbHttpParams. This |
|
| 182 * optionally assigns an appropriate #GError upon failure. The returned |
|
| 183 * string should be freed with #g_free() when no longer needed. |
|
| 184 * |
|
| 185 * Return: The duplicated string value. |
|
| 186 */ |
|
| 187 gchar * |
|
| 188 fb_http_params_dup_str(FbHttpParams *params, const gchar *name, |
|
| 189 GError **error); |
|
| 190 |
|
| 191 /** |
|
| 192 * fb_http_params_set_bool: |
|
| 193 * @params: The #FbHttpParams. |
|
| 194 * @name: The parameter name. |
|
| 195 * @value: The value. |
|
| 196 * |
|
| 197 * Sets a boolean value to the #FbHttpParams. |
|
| 198 */ |
|
| 199 void |
|
| 200 fb_http_params_set_bool(FbHttpParams *params, const gchar *name, |
|
| 201 gboolean value); |
|
| 202 |
|
| 203 /** |
|
| 204 * fb_http_params_set_dbl: |
|
| 205 * @params: The #FbHttpParams. |
|
| 206 * @name: The parameter name. |
|
| 207 * @value: The value. |
|
| 208 * |
|
| 209 * Sets a floating point value to the #FbHttpParams. |
|
| 210 */ |
|
| 211 void |
|
| 212 fb_http_params_set_dbl(FbHttpParams *params, const gchar *name, gdouble value); |
|
| 213 |
|
| 214 /** |
|
| 215 * fb_http_params_set_int: |
|
| 216 * @params: The #FbHttpParams. |
|
| 217 * @name: The parameter name. |
|
| 218 * @value: The value. |
|
| 219 * |
|
| 220 * Sets an integer value to the #FbHttpParams. |
|
| 221 */ |
|
| 222 void |
|
| 223 fb_http_params_set_int(FbHttpParams *params, const gchar *name, gint64 value); |
|
| 224 |
|
| 225 /** |
|
| 226 * fb_http_params_set_str: |
|
| 227 * @params: The #FbHttpParams. |
|
| 228 * @name: The parameter name. |
|
| 229 * @value: The value. |
|
| 230 * |
|
| 231 * Sets a string value to the #FbHttpParams. |
|
| 232 */ |
|
| 233 void |
|
| 234 fb_http_params_set_str(FbHttpParams *params, const gchar *name, |
|
| 235 const gchar *value); |
|
| 236 |
|
| 237 /** |
|
| 238 * fb_http_params_set_strf: |
|
| 239 * @params: The #FbHttpParams. |
|
| 240 * @name: The parameter name. |
|
| 241 * @format: The format string literal. |
|
| 242 * @...: The arguments for @format. |
|
| 243 * |
|
| 244 * Sets a formatted string value to the #FbHttpParams. |
|
| 245 */ |
|
| 246 void |
|
| 247 fb_http_params_set_strf(FbHttpParams *params, const gchar *name, |
|
| 248 const gchar *format, ...) |
|
| 249 G_GNUC_PRINTF(3, 4); |
|
| 250 |
|
| 251 /** |
|
| 252 * fb_http_urlcmp: |
|
| 253 * @url1: The first URL. |
|
| 254 * @url2: The second URL. |
|
| 255 * @protocol: #TRUE to match the protocols, otherwise #FALSE. |
|
| 256 * |
|
| 257 * Compares two URLs. This is more reliable than just comparing two URL |
|
| 258 * strings, as it avoids casing in some areas, while not in others. It |
|
| 259 * can also, optionally, ignore the matching of the URL protocol. |
|
| 260 * |
|
| 261 * Returns: #TRUE if the URLs match, otherwise #FALSE. |
|
| 262 */ |
|
| 263 gboolean |
|
| 264 fb_http_urlcmp(const gchar *url1, const gchar *url2, gboolean protocol); |
|
| 265 |
|
| 266 #endif /* PURPLE_FACEBOOK_HTTP_H */ |
|