From 488e38ad29f1b65bff5fa23003aa9f1844170ee2 Mon Sep 17 00:00:00 2001 From: Darshak Parikh Date: Sat, 28 Sep 2024 19:59:40 +0530 Subject: [PATCH] Replace send_message calls with send_and_read from libsoup3 --- plugins/backend/bazqux/bazquxConnection.vala | 6 +++--- plugins/backend/feedbin/feedbinAPI.vala | 2 +- plugins/backend/feedhq/feedhqConnection.vala | 6 +++--- plugins/backend/fresh/freshConnection.vala | 6 +++--- plugins/backend/inoreader/InoReaderConnection.vala | 6 +++--- plugins/backend/local/localInterface.vala | 2 +- plugins/backend/local/localUtils.vala | 4 +++- plugins/backend/owncloud/OwncloudNewsMessage.vala | 3 ++- plugins/backend/ttrss/ttrssMessage.vala | 3 ++- plugins/share/Instapaper/InstapaperAPI.vala | 2 +- plugins/share/Pocket/PocketAPI.vala | 6 +++--- plugins/share/Wallabag/WallabagAPI.vala | 4 ++-- src/ContentGrabber/grabber.vala | 4 ++-- src/ContentGrabber/grabberUtils.vala | 8 +++++--- src/Utils.vala | 3 ++- 15 files changed, 36 insertions(+), 29 deletions(-) diff --git a/plugins/backend/bazqux/bazquxConnection.vala b/plugins/backend/bazqux/bazquxConnection.vala index f7b61aa94..aafc0a3a2 100644 --- a/plugins/backend/bazqux/bazquxConnection.vala +++ b/plugins/backend/bazqux/bazquxConnection.vala @@ -50,7 +50,7 @@ public class FeedReader.bazquxConnection { var message = new Soup.Message("POST", "https://bazqux.com/accounts/ClientLogin/"); string message_string = "Email=" + m_username + "&Passwd=" + m_passwd; message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data); - m_session.send_message(message); + m_session.send_and_read(message); string response = (string)message.response_body.flatten().data; try{ @@ -100,7 +100,7 @@ public class FeedReader.bazquxConnection { message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data); } - m_session.send_message(message); + m_session.send_and_read(message); return Response() { status = message.status_code, @@ -114,7 +114,7 @@ public class FeedReader.bazquxConnection { string oldauth = "GoogleLogin auth=" + m_utils.getAccessToken(); message.request_headers.append("Authorization", oldauth); - m_session.send_message(message); + m_session.send_and_read(message); if((string)message.response_body.data == "OK") { diff --git a/plugins/backend/feedbin/feedbinAPI.vala b/plugins/backend/feedbin/feedbinAPI.vala index b4ec9218e..2502db0d3 100644 --- a/plugins/backend/feedbin/feedbinAPI.vala +++ b/plugins/backend/feedbin/feedbinAPI.vala @@ -78,7 +78,7 @@ public class FeedbinAPI : Object { message.request_body.append_take(input.data); } - m_session.send_message(message); + m_session.send_and_read(message); var status = message.status_code; if(status < 200 || status >= 400) { diff --git a/plugins/backend/feedhq/feedhqConnection.vala b/plugins/backend/feedhq/feedhqConnection.vala index f05ce2681..6ac5c84e4 100644 --- a/plugins/backend/feedhq/feedhqConnection.vala +++ b/plugins/backend/feedhq/feedhqConnection.vala @@ -50,7 +50,7 @@ public class FeedReader.FeedHQConnection { var message = new Soup.Message("POST", "https://feedhq.org/accounts/ClientLogin"); string message_string = "Email=" + m_username + "&Passwd=" + m_passwd; message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data); - m_session.send_message(message); + m_session.send_and_read(message); string response = (string)message.response_body.flatten().data; try{ @@ -85,7 +85,7 @@ public class FeedReader.FeedHQConnection { string oldauth = "GoogleLogin auth=" + m_utils.getAccessToken(); message.request_headers.append("Authorization", oldauth); - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { @@ -124,7 +124,7 @@ public class FeedReader.FeedHQConnection { message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string_post.data); } - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { diff --git a/plugins/backend/fresh/freshConnection.vala b/plugins/backend/fresh/freshConnection.vala index 522bfe13e..7262e5223 100644 --- a/plugins/backend/fresh/freshConnection.vala +++ b/plugins/backend/fresh/freshConnection.vala @@ -46,7 +46,7 @@ public class FeedReader.freshConnection { msg.add("Passwd", m_utils.getPasswd()); message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, msg.get().data); - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { @@ -92,7 +92,7 @@ public class FeedReader.freshConnection { message.request_headers.append("Content-Type", type); message.request_body.append_take(input.data); - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { @@ -115,7 +115,7 @@ public class FeedReader.freshConnection { message.request_headers.append("DNT", "1"); } - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { diff --git a/plugins/backend/inoreader/InoReaderConnection.vala b/plugins/backend/inoreader/InoReaderConnection.vala index 1a8e6306f..2ac6cd4f6 100644 --- a/plugins/backend/inoreader/InoReaderConnection.vala +++ b/plugins/backend/inoreader/InoReaderConnection.vala @@ -40,7 +40,7 @@ public class FeedReader.InoReaderConnection { + "&scope=" + "&grant_type=authorization_code"; message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data); - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { @@ -90,7 +90,7 @@ public class FeedReader.InoReaderConnection { + "&refresh_token=" + m_utils.getRefreshToken(); message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data); - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { @@ -156,7 +156,7 @@ public class FeedReader.InoReaderConnection { message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data); } - m_session.send_message(message); + m_session.send_and_read(message); if(message.status_code != 200) { diff --git a/plugins/backend/local/localInterface.vala b/plugins/backend/local/localInterface.vala index 5419b6aee..ea9ec8d88 100644 --- a/plugins/backend/local/localInterface.vala +++ b/plugins/backend/local/localInterface.vala @@ -529,7 +529,7 @@ public class FeedReader.localInterface : FeedServerInterface { var session = new Soup.Session(); session.user_agent = Constants.USER_AGENT; session.timeout = 5; - session.send_message(msg); + session.send_and_read(msg); string xml = (string)msg.response_body.flatten().data; // parse diff --git a/plugins/backend/local/localUtils.vala b/plugins/backend/local/localUtils.vala index ecb0d046a..7901a2d44 100644 --- a/plugins/backend/local/localUtils.vala +++ b/plugins/backend/local/localUtils.vala @@ -34,7 +34,9 @@ public class FeedReader.localUtils : GLib.Object { return null; } - uint status = session.send_message(msg); + session.send_and_read(msg); + uint status = msg.status_code; + if(status < 100 || status >= 400) { if(status < 100) diff --git a/plugins/backend/owncloud/OwncloudNewsMessage.vala b/plugins/backend/owncloud/OwncloudNewsMessage.vala index 952df63ee..dcf0d4ad8 100644 --- a/plugins/backend/owncloud/OwncloudNewsMessage.vala +++ b/plugins/backend/owncloud/OwncloudNewsMessage.vala @@ -136,7 +136,8 @@ public class FeedReader.OwnCloudNewsMessage : GLib.Object { m_message_soup.request_headers.append("DNT", "1"); } - var status = m_session.send_message(m_message_soup); + m_session.send_and_read(m_message_soup); + var status = m_message_soup.status_code; if(status == 401) // unauthorized diff --git a/plugins/backend/ttrss/ttrssMessage.vala b/plugins/backend/ttrss/ttrssMessage.vala index 367a478ab..5e3d71ef8 100644 --- a/plugins/backend/ttrss/ttrssMessage.vala +++ b/plugins/backend/ttrss/ttrssMessage.vala @@ -97,7 +97,8 @@ public class FeedReader.ttrssMessage : GLib.Object { m_message_soup.request_headers.append("DNT", "1"); } - var status_code = m_session.send_message(m_message_soup); + m_session.send_and_read(m_message_soup); + var status_code = m_message_soup.status_code; if(status_code == 401) // unauthorized diff --git a/plugins/share/Instapaper/InstapaperAPI.vala b/plugins/share/Instapaper/InstapaperAPI.vala index 40caa71c4..a5974e7f9 100644 --- a/plugins/share/Instapaper/InstapaperAPI.vala +++ b/plugins/share/Instapaper/InstapaperAPI.vala @@ -184,7 +184,7 @@ public class FeedReader.InstaAPI : ShareAccountInterface, Peas.ExtensionBase { message_soup.request_headers.append("DNT", "1"); } - session.send_message(message_soup); + session.send_and_read(message_soup); string response = (string)message_soup.response_body.flatten().data; if(response == null || response == "") diff --git a/plugins/share/Pocket/PocketAPI.vala b/plugins/share/Pocket/PocketAPI.vala index 37d195cc8..50ec75dd8 100644 --- a/plugins/share/Pocket/PocketAPI.vala +++ b/plugins/share/Pocket/PocketAPI.vala @@ -78,7 +78,7 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase { message_soup.request_headers.append("DNT", "1"); } - session.send_message(message_soup); + session.send_and_read(message_soup); string response = (string)message_soup.response_body.flatten().data; return response.substring(response.index_of_char('=')+1); @@ -98,7 +98,7 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase { message_soup.request_headers.append("DNT", "1"); } - session.send_message(message_soup); + session.send_and_read(message_soup); if((string)message_soup.response_body.flatten().data == null || (string)message_soup.response_body.flatten().data == "") @@ -183,7 +183,7 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase { message_soup.request_headers.append("DNT", "1"); } - session.send_message(message_soup); + session.send_and_read(message_soup); if((string)message_soup.response_body.flatten().data == null || (string)message_soup.response_body.flatten().data == "") diff --git a/plugins/share/Wallabag/WallabagAPI.vala b/plugins/share/Wallabag/WallabagAPI.vala index 97b56e969..56d06956e 100644 --- a/plugins/share/Wallabag/WallabagAPI.vala +++ b/plugins/share/Wallabag/WallabagAPI.vala @@ -40,7 +40,7 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase string url = baseURL + "oauth/v2/token"; var message_soup = new Soup.Message("POST", url); message_soup.set_request("application/x-www-form-urlencoded; charset=UTF8", Soup.MemoryUse.COPY, message.data); - session.send_message(message_soup); + session.send_and_read(message_soup); if((string)message_soup.response_body.flatten().data == null || (string)message_soup.response_body.flatten().data == "") @@ -154,7 +154,7 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase var message_soup = new Soup.Message("POST", baseURL + "api/entries.json"); message_soup.set_request("application/x-www-form-urlencoded; charset=UTF8", Soup.MemoryUse.COPY, message.data); message_soup.request_headers.append("Authorization", "Bearer " + settings.get_string("oauth-access-token")); - session.send_message(message_soup); + session.send_and_read(message_soup); if((string)message_soup.response_body.flatten().data == null || (string)message_soup.response_body.flatten().data == "") diff --git a/src/ContentGrabber/grabber.vala b/src/ContentGrabber/grabber.vala index f4ed6b910..57dc974d6 100644 --- a/src/ContentGrabber/grabber.vala +++ b/src/ContentGrabber/grabber.vala @@ -204,7 +204,7 @@ public class FeedReader.Grabber : GLib.Object { return false; } - m_session.send_message(message); + m_session.send_and_read(message); var params = new GLib.HashTable(null, null); string? contentType = message.response_headers.get_content_type(out params); if(contentType != null) @@ -245,7 +245,7 @@ public class FeedReader.Grabber : GLib.Object { msg.request_headers.append("DNT", "1"); } - m_session.send_message(msg); + m_session.send_and_read(msg); msg.disconnect(handlerID); if(msg.response_body == null) diff --git a/src/ContentGrabber/grabberUtils.vala b/src/ContentGrabber/grabberUtils.vala index ecec2cf6f..dc57cc6c7 100644 --- a/src/ContentGrabber/grabberUtils.vala +++ b/src/ContentGrabber/grabberUtils.vala @@ -630,7 +630,9 @@ public class FeedReader.grabberUtils : GLib.Object { message_dlImg.request_headers.append("DNT", "1"); } - var status = session.send_message(message_dlImg); + session.send_and_read(message_dlImg); + var status = message_dlImg.status_code; + if(status == 200) { var params = new GLib.HashTable(null, null); @@ -772,7 +774,7 @@ public class FeedReader.grabberUtils : GLib.Object { { return null; } - session.send_message(message); + session.send_and_read(message); var params = new GLib.HashTable(null, null); string? contentType = message.response_headers.get_content_type(out params); size = message.response_headers.get_content_length(); @@ -781,7 +783,7 @@ public class FeedReader.grabberUtils : GLib.Object { { return null; } - session.send_message(message2); + session.send_and_read(message2); origSize = message2.response_headers.get_content_length(); if(contentType != null) { diff --git a/src/Utils.vala b/src/Utils.vala index 0aad66927..271e2e086 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -278,7 +278,8 @@ public class FeedReader.Utils : GLib.Object { return false; } - var status = getSession().send_message(message); + getSession().send_and_read(message); + var status = message.status_code; Logger.debug(@"Ping: status $status");