Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 16 Jun 2024 09:31:53 UTC Commit: bc2bf399cf0f8dccbe678479e9a7520254edbce7 https://github.com/geany/geany-plugins/commit/bc2bf399cf0f8dccbe678479e9a752...
Log Message: ----------- Merge pull request #1342 from b4n/geniuspaste-libsoup3
Various GeniusPaste fixes:
* Port to libsoup3 * Avoid GTK3 deprecations * Fix GLib >= 2.79 support * Pastebins updates
Modified Paths: -------------- .github/workflows/build.yml build/ci_mingw64_geany_plugins.sh build/geniuspaste.m4 build/gtk-bundle-from-msys2.sh geniuspaste/README geniuspaste/TODO geniuspaste/data/Makefile.am geniuspaste/data/dpaste.com.conf geniuspaste/data/dpaste.org.conf geniuspaste/data/fpaste.org.conf geniuspaste/data/paste.debian.net.conf geniuspaste/data/pastebin.geany.org.conf geniuspaste/data/sprunge.us.conf geniuspaste/src/geniuspaste.c
Modified: .github/workflows/build.yml 8 lines changed, 5 insertions(+), 3 deletions(-) =================================================================== @@ -32,7 +32,7 @@ env: jobs: linux: name: Linux Build - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04
env: CC: ccache gcc @@ -111,7 +111,7 @@ jobs: # geany autopoint gettext - python-docutils + python3-docutils # geany-plugins intltool check @@ -128,16 +128,18 @@ jobs: libgtkspell3-3-dev # geaniuspaste/updatechecker libsoup2.4-dev + libsoup-3.0-dev # git-changebar libgit2-dev # markdown libmarkdown2-dev # markdown/webhelper libwebkit2gtk-4.0-dev + libwebkit2gtk-4.1-dev # pretty-printer libxml2-dev # spellcheck - libenchant-dev + libenchant-2-dev # cppcheck cmake libpcre3-dev
Modified: build/ci_mingw64_geany_plugins.sh 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -181,7 +181,7 @@ install_dependencies() { mingw-w64-${ARCH}-gpgme \ mingw-w64-${ARCH}-gtkspell3 \ mingw-w64-${ARCH}-libgit2 \ - mingw-w64-${ARCH}-libsoup \ + mingw-w64-${ARCH}-libsoup3 \ mingw-w64-${ARCH}-lua51 }
Modified: build/geniuspaste.m4 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -3,7 +3,8 @@ AC_DEFUN([GP_CHECK_GENIUSPASTE], GP_ARG_DISABLE([GeniusPaste], [auto])
GP_CHECK_PLUGIN_DEPS([GeniusPaste], GENIUSPASTE, - [libsoup-2.4 >= 2.4.0]) + [gtk+-3.0 >= 3.16 + libsoup-3.0])
GP_COMMIT_PLUGIN_STATUS([GeniusPaste])
Modified: build/gtk-bundle-from-msys2.sh 9 lines changed, 7 insertions(+), 2 deletions(-) =================================================================== @@ -21,26 +21,30 @@ EXE_WRAPPER_64="mingw-w64-x86_64-wine" # enchant, hunspell - for SpellCheck plugin # lua51 - for GeanyLua plugin # gnupg, gpgme - for GeanyPG plugin -# libsoup - for UpdateChecker plugin +# libsoup3 - for UpdateChecker & GeniusPaste plugins # libgit2 - for GitChangeBar plugin # gtkspell3 - for GeanyVC plugin # the rest is dependency-dependency packages=" ca-certificates ctags ctpl-git +curl enchant +glib-networking gnupg gpgme +gsettings-desktop-schemas http-parser hunspell libassuan libgcrypt libgit2 libgpg-error libidn2 +libproxy libpsl -libsoup +libsoup3 libssh2 libsystre libunistring @@ -51,6 +55,7 @@ p11-kit readline sqlite3 termcap +zstd "
gtk3_dependency_pkgs="
Modified: geniuspaste/README 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -35,8 +35,8 @@ configuration shipped with the plugin, please report the issue to:
Requirements ------------ - * GTK+ >= 2.12 - * libsoup 2.4 >= 2.4.0 + * GTK+ >= 3.16 + * libsoup 3.0
Installation ------------
Modified: geniuspaste/TODO 6 lines changed, 4 insertions(+), 2 deletions(-) =================================================================== @@ -2,5 +2,7 @@ TODO ----
- recent pastes history - - URL shortening - + - URL shortening (?) + - authentication (per-pastebin) + - confirmation dialog/infobar? pasted data is potentially sensitive + - support for Gist, which is likely the most used service
Modified: geniuspaste/data/Makefile.am 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -4,7 +4,8 @@ plugin = geniuspaste pastebinsdir = $(plugindatadir)/pastebins dist_pastebins_DATA = \ codepad.org.conf \ - dpaste.de.conf \ + dpaste.com.conf \ + dpaste.org.conf \ fpaste.org.conf \ pastebin.geany.org.conf \ paste.debian.net.conf \
Modified: geniuspaste/data/dpaste.com.conf 89 lines changed, 89 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,89 @@ +[pastebin] +name=dpaste.com +url=https://dpaste.com/api/v2/ + +[format] +content=%contents% +title=%title% +syntax=%language% +#expiry_days=%expire_days% +poster=%user% + +[parse] + +[defaults] +language=plain +expire_days=7 + +# map GeanyFileType=PastebinFileType +[languages] +ActionScript=actionscript +Ada=ada +Arduino=arduino +AutoIt=autoit +Batch=batch +BibTeX=bibtex +CAML=ocaml +C=c +C++=cpp +C#=csharp +Clojure=clojure +CMake=cmake +COBOL=cobol +CoffeeScript=coffeescript +Conf=ini +CSS=css +CUDA=cuda +Cython=cython +D=d +Diff=diff +Docbook=xml +Erlang=erlang +F77=fortran +Forth=forth +Fortran=fortran +GDScript=gdscript +GLSL=glsl +Go=go +Graphviz=graphviz +Groovy=groovy +Haskell=haskell +Haxe=haxe +HTML=html +Java=java +Javascript=js +JSON=json +Julia=julia +Kotlin=kotlin +Lisp=common-lisp +Lua=lua +Make=make +Markdown=md +Matlab/Octave=octave +Meson=meson +Nim=nimrod +NSIS=nsis +Objective-C=objective-c +Perl=perl +PHP=php +Po=pot +PowerShell=powershell +Python=python +reStructuredText=rst +Raku=perl6 +Ruby=rb +Rust=rust +Scala=scala +Sh=bash +Smalltalk=smalltalk +SQL=sql +Swift=swift +Tcl=tcl +TypeScript=ts +Vala=vala +Verilog=verilog +VHDL=vhdl +XML=xml +YAML=yaml +Zephir=zephir +None=text
Modified: geniuspaste/data/dpaste.org.conf 34 lines changed, 21 insertions(+), 13 deletions(-) =================================================================== @@ -1,6 +1,6 @@ [pastebin] -name=dpaste.de -url=https://dpaste.de/api/ +name=dpaste.org +url=https://dpaste.org/api/
[format] filename=%title% @@ -10,44 +10,51 @@ lexer=%language%
[parse] search=^"(.+)"$ -replace=\1 +replace=\1
[defaults] -# default language to plain which means "Code" -language=plain -expire=604800 +language=_code +expire=2592000
# map GeanyFileType=PastebinFileType [languages] -# list as of 2016-01-14 -None=text +None=_text ActionScript=as +Arduino=arduino +Batch=bat C=c -# better than nothing +# better than nothing, because the configuration has "cpp" disabled C++=c -#CAML=ocaml +C#=csharp +CAML=ocaml Clojure=clojure +CMake=cmake COBOL=cobol +CoffeeScript=coffee-script Conf=ini CSS=css CUDA=cuda +D=d Diff=diff Docbook=xml Erlang=erlang F77=fortran +Forth=forth Fortran=fortran -GLSL=C +GLSL=glsl Go=go Haskell=haskell HTML=html Java=java Javascript=js JSON=json LaTeX=tex +Kotlin=kotlin +Lisp=common-lisp Lua=lua Make=make Matlab/Octave=matlab -Objective-C=objc +Objective-C=objective-c Perl=perl PHP=php PowerShell=powershell @@ -59,6 +66,7 @@ Scala=scala Sh=bash SQL=sql Tcl=tcl +Swift=swift XML=xml YAML=yaml -Zephir=php +Zephir=zephir
Modified: geniuspaste/data/fpaste.org.conf 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -17,7 +17,7 @@ title=%title%
[parse] search="url" *: *"([^"]+)" -replace=\1 +replace=\1
# map GeanyFileType=PastebinFileType [languages]
Modified: geniuspaste/data/paste.debian.net.conf 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -1,6 +1,6 @@ [pastebin] name=paste.debian.net -url=http://paste.debian.net/ +url=https://paste.debian.net/
[format] code=%contents%
Modified: geniuspaste/data/pastebin.geany.org.conf 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -11,7 +11,7 @@ lexer=%language%
[parse] search=^.+$ -replace=\0 +replace=\0
[defaults] language=text
Modified: geniuspaste/data/sprunge.us.conf 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -7,7 +7,7 @@ sprunge=%contents%
[parse] search=^[[:space:]]*(.+?)[[:space:]]*$ -replace=\1?%language% +replace=\1?%language%
# map GeanyFileType=PastebinFileType [languages]
Modified: geniuspaste/src/geniuspaste.c 97 lines changed, 58 insertions(+), 39 deletions(-) =================================================================== @@ -605,13 +605,15 @@ static SoupMessage *json_request_new(const gchar *method, { SoupMessage *msg = soup_message_new(method, url); GString *str = g_string_new(NULL); + GBytes *bytes;
g_string_append_c(str, '{'); g_datalist_foreach(fields, append_json_data_item, str); g_string_append_c(str, '}'); - soup_message_set_request(msg, "application/json", SOUP_MEMORY_TAKE, - str->str, str->len); - g_string_free(str, FALSE); + bytes = g_bytes_new_take(str->str, str->len); + (void) g_string_free(str, FALSE); /* buffer already taken above */ + soup_message_set_request_body_from_bytes(msg, "application/json", bytes); + g_bytes_unref(bytes);
return msg; } @@ -657,19 +659,30 @@ static SoupMessage *pastebin_soup_message_new(const Pastebin *pastebin,
default: case FORMAT_HTML_FORM_URLENCODED: - msg = soup_form_request_new_from_datalist(method, url, &data); + msg = soup_message_new_from_encoded_form(method, url, + soup_form_encode_datalist(&data)); break; } g_datalist_clear(&data);
return msg; }
+static gchar *bytes_to_string(GBytes *bytes) +{ + gsize bytes_size = g_bytes_get_size(bytes); + gchar *str = g_malloc(bytes_size + 1); + memcpy(str, g_bytes_get_data(bytes, NULL), bytes_size); + str[bytes_size] = 0; + return str; +} + /* parses @response and returns the URL of the paste, or %NULL on parse error * or if the URL couldn't be found. * @warning: it may return NULL even if @error is not set */ static gchar *pastebin_parse_response(const Pastebin *pastebin, SoupMessage *msg, + GBytes *response_body, GeanyDocument *doc, const gchar *contents, GError **error) @@ -684,7 +697,8 @@ static gchar *pastebin_parse_response(const Pastebin *pastebin, if (! g_key_file_has_group(pastebin->config, PASTEBIN_GROUP_PARSE)) { /* by default, use the response URI (redirect) */ - url = soup_uri_to_string(soup_message_get_uri(msg), FALSE); + url = g_uri_to_string_partial(soup_message_get_uri(msg), + G_URI_HIDE_PASSWORD); } else { @@ -695,7 +709,9 @@ static gchar *pastebin_parse_response(const Pastebin *pastebin, PASTEBIN_GROUP_PARSE_KEY_REPLACE, "\1"); SETPTR(replace, expand_placeholders(replace, pastebin, doc, contents));
- url = regex_replace(search, msg->response_body->data, replace, error); + gchar *response_str = bytes_to_string(response_body); + url = regex_replace(search, response_str, replace, error); + g_free(response_str);
g_free(search); g_free(replace); @@ -757,27 +773,21 @@ static void show_msgbox(GtkMessageType type, GtkButtonsType buttons, /* cppcheck-suppress memleak symbolName=dlg */ }
-static void debug_log_message_body(SoupMessage *msg, - SoupMessageBody *body, - const gchar *label) +static void debug_logger(SoupLogger *logger, + SoupLoggerLogLevel level, + char direction, + const char *data, + gpointer user_data) { - if (geany->app->debug_mode) + const char *prefix; + switch (direction) { - gchar *real_uri = soup_uri_to_string(soup_message_get_uri(msg), FALSE); - - soup_message_body_flatten(body); - msgwin_msg_add(COLOR_BLUE, -1, NULL, - "[geniuspaste] %s:\n" - "URI: %s\n" - "Body: %s\n" - "Code: %d (%s)", - label, - real_uri, - body->data, - msg->status_code, - msg->reason_phrase); - g_free(real_uri); + case '>': prefix = "Request: "; break; + case '<': prefix = "Response: "; break; + default: prefix = ""; break; } + + msgwin_msg_add(COLOR_BLUE, -1, NULL, "[geniuspaste] %s%s", prefix, data); }
static void paste(GeanyDocument * doc, const gchar * website) @@ -788,6 +798,8 @@ static void paste(GeanyDocument * doc, const gchar * website) SoupMessage *msg; gchar *user_agent = NULL; guint status; + GError *err = NULL; + GBytes *response;
g_return_if_fail(doc && doc->is_valid);
@@ -816,35 +828,40 @@ static void paste(GeanyDocument * doc, const gchar * website) msg = pastebin_soup_message_new(pastebin, doc, f_content);
user_agent = g_strconcat(PLUGIN_NAME, " ", PLUGIN_VERSION, " / Geany ", GEANY_VERSION, NULL); - session = soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, user_agent, NULL); + session = soup_session_new_with_options("user-agent", user_agent, NULL); + if (geany->app->debug_mode) + { + SoupLogger *logger = soup_logger_new(SOUP_LOGGER_LOG_BODY); + soup_logger_set_printer(logger, debug_logger, NULL, NULL); + soup_session_add_feature(session, SOUP_SESSION_FEATURE(logger)); + g_object_unref(logger); + } g_free(user_agent);
- debug_log_message_body(msg, msg->request_body, "Request"); - - status = soup_session_send_message(session, msg); + response = soup_session_send_and_read(session, msg, NULL, &err); g_object_unref(session);
- debug_log_message_body(msg, msg->response_body, "Response"); - - if (! SOUP_STATUS_IS_SUCCESSFUL(status)) + status = soup_message_get_status(msg); + if (err || ! SOUP_STATUS_IS_SUCCESSFUL(status)) { show_msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to paste the code"), _("Error pasting the code to the pastebin service %s.\n" "Error code: %u (%s).\n\n%s"), - pastebin->name, status, msg->reason_phrase, - (SOUP_STATUS_IS_TRANSPORT_ERROR(status) + pastebin->name, status, + err ? err->message : soup_message_get_reason_phrase(msg), + (err ? _("Check your connection or the pastebin configuration and retry.") : SOUP_STATUS_IS_SERVER_ERROR(status) ? _("Wait for the service to come back and retry, or retry " "with another pastebin service.") : _("Check the pastebin configuration and retry."))); + g_clear_error(&err); } else { - GError *err = NULL; - gchar *p_url = pastebin_parse_response(pastebin, msg, doc, f_content, - &err); + gchar *p_url = pastebin_parse_response(pastebin, msg, response, doc, + f_content, &err);
if (err || ! p_url) { @@ -876,6 +893,8 @@ static void paste(GeanyDocument * doc, const gchar * website) g_free(p_url); }
+ if (response) + g_bytes_unref(response); g_object_unref(msg); g_free(f_content); } @@ -917,13 +936,13 @@ GtkWidget *plugin_configure(GtkDialog * dialog) gint i; GtkWidget *label, *vbox, *author_label;
- vbox = gtk_vbox_new(FALSE, 6); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
label = gtk_label_new(_("Select a pastebin:")); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_label_set_xalign(GTK_LABEL(label), 0);
author_label = gtk_label_new(_("Enter the author name:")); - gtk_misc_set_alignment(GTK_MISC(author_label), 0, 0.5); + gtk_label_set_xalign(GTK_LABEL(author_label), 0);
widgets.author_entry = gtk_entry_new();
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).