1 /* 2 * This file is part of GNOME Twitch - 'Enjoy Twitch on your GNU/Linux desktop' 3 * Copyright © 2017 Vincent Szolnoky <vinszent@vinszent.com> 4 * 5 * GNOME Twitch is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * GNOME Twitch is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with GNOME Twitch. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef GT_HTTP_H 20 #define GT_HTTP_H 21 22 #include "config.h" 23 #include <glib-object.h> 24 #include <gio/gio.h> 25 26 G_BEGIN_DECLS 27 28 #define GT_TYPE_HTTP gt_http_get_type() 29 30 G_DECLARE_INTERFACE(GtHTTP, gt_http, GT, HTTP, GObject); 31 32 typedef void (*GtHTTPStreamCallback) (GtHTTP* http, GInputStream* res, GError* error, gpointer user_data); 33 typedef void (*GtHTTPDataCallback) (GtHTTP* http, gconstpointer res, gsize length, GError* error, gpointer user_data); 34 35 typedef enum 36 { 37 GT_HTTP_FLAG_RETURN_STREAM = 1, 38 GT_HTTP_FLAG_RETURN_DATA = 1 << 2, 39 GT_HTTP_FLAG_CACHE_RESPONSE = 1 << 3, 40 } GtHTTPFlag; 41 42 #define GT_HTTP_ERROR g_quark_from_static_string("gt-http-error-quark") 43 44 typedef enum 45 { 46 GT_HTTP_ERROR_UNKNOWN, 47 GT_HTTP_ERROR_UNSUCCESSFUL_RESPONSE, 48 GT_HTTP_ERROR_NOT_FOUND = 404, 49 } GtHTTPError; 50 51 static gchar* GT_HTTP_NO_HEADERS[] = {NULL}; 52 53 static gchar* GT_HTTP_TWITCH_HLS_HEADERS[] = 54 { 55 "Client-ID", CLIENT_ID, 56 "Accept", "application/vnd.apple.mpegurl, text/html", /* NOTE: text/html is for when the stream isn't live and HTML is returned instead */ 57 NULL, 58 }; 59 60 static gchar* DEFAULT_TWITCH_HEADERS[] = 61 { 62 "Client-ID", CLIENT_ID, 63 "Accept", "application/vnd.twitchtv.v5+json", 64 "Accept", "image/*", 65 NULL, 66 }; 67 68 struct _GtHTTPInterface 69 { 70 GTypeInterface parent_interface; 71 72 void (*get) (GtHTTP* http, const gchar* uri, gchar** headers, 73 GCancellable* cancel, GCallback cb, gpointer udata, gint flags); 74 void (*get_with_category) (GtHTTP* http, const gchar* uri, const gchar* category, gchar** headers, 75 GCancellable* cancel, GCallback cb, gpointer udata, gint flags); 76 }; 77 78 /* TODO: Add docs */ 79 void gt_http_get(GtHTTP* http, const gchar* uri, gchar** headers, 80 GCancellable* cancel, GCallback cb, gpointer udata, gint flags); 81 void gt_http_get_with_category(GtHTTP* http, const gchar* uri, const gchar* category, gchar** headers, 82 GCancellable* cancel, GCallback cb, gpointer udata, gint flags); 83 84 G_END_DECLS 85 86 #endif 87