From 8feadcbb2fa7414ca8a464e3293138762fec5fad Mon Sep 17 00:00:00 2001 From: c0dev0id Date: Fri, 2 Feb 2024 22:02:17 +0100 Subject: [PATCH] Downgrade from libsoup3 to libsoup2 --- CHANGELOG.md | 2 +- clib/request.c | 2 +- clib/unique.c | 7 +--- common/clib/soup.h | 79 +++++++++++++----------------------------- common/property.c | 31 +++++------------ config.mk | 4 +-- widgets/webview/auth.c | 3 ++ 7 files changed, 40 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 400aab7a..77376458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [develop] +## Develop ### Added diff --git a/clib/request.c b/clib/request.c index b6614639..6d9f847b 100644 --- a/clib/request.c +++ b/clib/request.c @@ -85,7 +85,7 @@ luaH_request_finish(lua_State *L) size_t length; const gchar *data = lua_tolstring(L, 2, &length); const gchar *mime = lua_tostring(L, 3) ?: "text/html"; - GInputStream *stream = g_memory_input_stream_new_from_data(g_memdup2(data, length), length, g_free); + GInputStream *stream = g_memory_input_stream_new_from_data(g_memdup(data, length), length, g_free); webkit_uri_scheme_request_finish(request->request, stream, length, mime); g_object_unref(stream); diff --git a/clib/unique.c b/clib/unique.c index 8d389f1b..2b947ecd 100644 --- a/clib/unique.c +++ b/clib/unique.c @@ -77,13 +77,8 @@ luaH_unique_new(lua_State *L) } GError *error = NULL; - if (!globalconf.application) { -#if GLIB_CHECK_VERSION(2,74,0) - globalconf.application = gtk_application_new(name, G_APPLICATION_DEFAULT_FLAGS); -#else + if (!globalconf.application) globalconf.application = gtk_application_new(name, G_APPLICATION_FLAGS_NONE); -#endif - } g_application_register(G_APPLICATION(globalconf.application), NULL, &error); if (error != NULL) { diff --git a/common/clib/soup.h b/common/clib/soup.h index ae3669cc..f495092f 100644 --- a/common/clib/soup.h +++ b/common/clib/soup.h @@ -21,19 +21,6 @@ #ifndef LUAKIT_COMMON_CLIB_SOUP_H #define LUAKIT_COMMON_CLIB_SOUP_H -#include -#if SOUP_CHECK_VERSION(3,0,0) -#include -#else -#include -#define SOUP_HTTP_URI_FLAGS (G_URI_FLAGS_HAS_PASSWORD |\ - G_URI_FLAGS_ENCODED_PATH |\ - G_URI_FLAGS_ENCODED_QUERY |\ - G_URI_FLAGS_ENCODED_FRAGMENT |\ - G_URI_FLAGS_SCHEME_NORMALIZE) -#endif - - static GRegex *scheme_reg; static gint @@ -43,19 +30,15 @@ luaH_soup_uri_tostring(lua_State *L) gint port; /* check for uri table */ luaH_checktable(L, 1); - const gchar * scheme = "http"; - const gchar * user = NULL; - const gchar * host = NULL; - const gchar * path = NULL; - const gchar * query = NULL; - const gchar * fragment = NULL; - gchar * uri; + /* create empty soup uri object */ + SoupURI *uri = soup_uri_new(NULL); + soup_uri_set_scheme(uri, "http"); #define GET_PROP(prop) \ lua_pushliteral(L, #prop); \ lua_rawget(L, 1); \ if (!lua_isnil(L, -1) && (p = lua_tostring(L, -1)) && p[0]) \ - prop = p; \ + soup_uri_set_##prop(uri, p); \ lua_pop(L, 1); GET_PROP(scheme) @@ -64,13 +47,12 @@ luaH_soup_uri_tostring(lua_State *L) * Without host set, a path of "/home/..." will become "file:/home/..." * instead of "file:///home/..." */ - if (!g_strcmp0(scheme, "file")) { - /* I assume that this is strdup()ed by g_uri_join(), so use - * some space on the stack rather than calloc'ing */ - host = ""; + if (soup_uri_get_scheme(uri) == SOUP_URI_SCHEME_FILE) { + soup_uri_set_host(uri, ""); } GET_PROP(user) + GET_PROP(password) GET_PROP(host) GET_PROP(path) GET_PROP(query) @@ -78,40 +60,29 @@ luaH_soup_uri_tostring(lua_State *L) lua_pushliteral(L, "port"); lua_rawget(L, 1); - if (lua_isnil(L, -1) || !(port = lua_tonumber(L, -1))) - port = -1; + if (!lua_isnil(L, -1) && (port = lua_tonumber(L, -1))) + soup_uri_set_port(uri, port); lua_pop(L, 1); - uri = g_uri_join_with_user (SOUP_HTTP_URI_FLAGS, - scheme, - user, - NULL, // omit password to retain soup_uri_to_string()'s behaviour - NULL, // auth_params - host, - port, - path, - query, - fragment); - - lua_pushstring(L, uri); - g_free(uri); - + gchar *str = soup_uri_to_string(uri, FALSE); + lua_pushstring(L, str); + g_free(str); + soup_uri_free(uri); return 1; } static gint -luaH_soup_push_uri(lua_State *L, GUri *uri) +luaH_soup_push_uri(lua_State *L, SoupURI *uri) { const gchar *p; - gint port; /* create table for uri properties */ lua_newtable(L); -#define PUSH_PROP(prop) \ - if ((p = g_uri_get_##prop(uri)) && p[0]) { \ - lua_pushliteral(L, #prop); \ - lua_pushstring(L, p); \ - lua_rawset(L, -3); \ +#define PUSH_PROP(prop) \ + if ((p = uri->prop) && p[0]) { \ + lua_pushliteral(L, #prop); \ + lua_pushstring(L, p); \ + lua_rawset(L, -3); \ } PUSH_PROP(scheme) @@ -122,10 +93,9 @@ luaH_soup_push_uri(lua_State *L, GUri *uri) PUSH_PROP(query) PUSH_PROP(fragment) - port = g_uri_get_port(uri); - if (port > 0) { + if (uri->port) { lua_pushliteral(L, "port"); - lua_pushnumber(L, port); + lua_pushnumber(L, uri->port); lua_rawset(L, -3); } @@ -148,14 +118,13 @@ luaH_soup_parse_uri(lua_State *L) str = g_strdup(str); /* parse & push uri */ - GUri *uri = g_uri_parse (str, SOUP_HTTP_URI_FLAGS, NULL); + SoupURI *uri = soup_uri_new(str); g_free(str); if (uri) { luaH_soup_push_uri(L, uri); - g_uri_unref(uri); - return 1; + soup_uri_free(uri); } - return 0; + return uri ? 1 : 0; } static void diff --git a/common/property.c b/common/property.c index 0c152e41..83f1b7bf 100644 --- a/common/property.c +++ b/common/property.c @@ -22,24 +22,13 @@ #include #include "common/property.h" -#include -#include -#if SOUP_CHECK_VERSION(3,0,0) -#include -#else #include -#define SOUP_HTTP_URI_FLAGS (G_URI_FLAGS_HAS_PASSWORD |\ - G_URI_FLAGS_ENCODED_PATH |\ - G_URI_FLAGS_ENCODED_QUERY |\ - G_URI_FLAGS_ENCODED_FRAGMENT |\ - G_URI_FLAGS_SCHEME_NORMALIZE) -#endif - +#include static gint luaH_gobject_get(lua_State *L, property_t *p, GObject *object) { - GUri *u; + SoupURI *u; property_tmp_t tmp; #define TG_CASE(type, dest, pfunc) \ @@ -62,9 +51,9 @@ luaH_gobject_get(lua_State *L, property_t *p, GObject *object) case URI: g_object_get(object, p->name, &u, NULL); - tmp.c = u ? g_uri_to_string_partial (u, G_URI_HIDE_PASSWORD) : NULL; + tmp.c = u ? soup_uri_to_string(u, 0) : NULL; lua_pushstring(L, tmp.c); - if (u) g_uri_unref(u); + if (u) soup_uri_free(u); g_free(tmp.c); return 1; @@ -78,7 +67,7 @@ luaH_gobject_get(lua_State *L, property_t *p, GObject *object) static gboolean luaH_gobject_set(lua_State *L, property_t *p, gint vidx, GObject *object) { - GUri *u; + SoupURI *u; property_tmp_t tmp; size_t len; @@ -114,17 +103,13 @@ luaH_gobject_set(lua_State *L, property_t *p, gint vidx, GObject *object) tmp.c = g_strdup(tmp.c); else tmp.c = g_strdup_printf("http://%s", tmp.c); - u = g_uri_parse(tmp.c, SOUP_HTTP_URI_FLAGS, NULL); - - gboolean valid = !u || ( (!g_strcmp0(g_uri_get_scheme(u), "http") - || !g_strcmp0(g_uri_get_scheme(u), "https") ) - && g_uri_get_host(u) - && g_uri_get_path(u) ); + u = soup_uri_new(tmp.c); + gboolean valid = !u || SOUP_URI_VALID_FOR_HTTP(u); if (valid) { g_object_set(object, p->name, u, NULL); g_free(tmp.c); } - if (u) g_uri_unref(u); + soup_uri_free(u); if (!valid) { lua_pushfstring(L, "invalid uri: %s", tmp.c); g_free(tmp.c); diff --git a/config.mk b/config.mk index b1abcca7..4fbf77b5 100644 --- a/config.mk +++ b/config.mk @@ -98,10 +98,10 @@ endif # Packages required to build luakit. PKGS += gtk+-3.0 PKGS += gthread-2.0 -PKGS += webkit2gtk-4.1 +PKGS += webkit2gtk-4.0 PKGS += sqlite3 PKGS += $(LUA_PKG_NAME) -PKGS += javascriptcoregtk-4.1 +PKGS += javascriptcoregtk-4.0 # Check user has correct packages installed (and found by pkg-config). PKGS_OK := $(shell $(PKG_CONFIG) --print-errors --exists $(PKGS) && echo 1) diff --git a/widgets/webview/auth.c b/widgets/webview/auth.c index f0e9105c..9fe7235f 100644 --- a/widgets/webview/auth.c +++ b/widgets/webview/auth.c @@ -22,6 +22,9 @@ #include "luah.h" #include +#include +#include +#include typedef struct { WebKitAuthenticationRequest *request; -- 2.46.0