Skip to content

Commit

Permalink
Replace response_body reading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dar5hak committed Sep 28, 2024
1 parent 488e38a commit be1cff1
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 58 deletions.
12 changes: 6 additions & 6 deletions plugins/backend/bazqux/bazquxConnection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ 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_and_read(message);
string response = (string)message.response_body.flatten().data;
var response_body = m_session.send_and_read(message);
string response = (string)response_body.get_data();
try{

var regex = new Regex(".*\\w\\s.*\\w\\sAuth=");
Expand Down Expand Up @@ -100,11 +100,11 @@ public class FeedReader.bazquxConnection {
message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, message_string.data);
}

m_session.send_and_read(message);
var response_body = m_session.send_and_read(message);

return Response() {
status = message.status_code,
data = (string)message.response_body.flatten().data
data = (string)response_body.get_data()
};
}

Expand All @@ -114,9 +114,9 @@ public class FeedReader.bazquxConnection {

string oldauth = "GoogleLogin auth=" + m_utils.getAccessToken();
message.request_headers.append("Authorization", oldauth);
m_session.send_and_read(message);
var response_body = m_session.send_and_read(message);

if((string)message.response_body.data == "OK")
if((string)response_body.get_data() == "OK")
{
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/backend/feedhq/feedhqConnection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ 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_and_read(message);
string response = (string)message.response_body.flatten().data;
var response_body = m_session.send_and_read(message);
string response = (string)response_body.get_data();
try{

var regex = new Regex(".*\\w\\s.*\\w\\sAuth=");
Expand Down Expand Up @@ -85,15 +85,15 @@ public class FeedReader.FeedHQConnection {

string oldauth = "GoogleLogin auth=" + m_utils.getAccessToken();
message.request_headers.append("Authorization", oldauth);
m_session.send_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
Logger.debug("FeedHQ post token failed");
return false;
}

string response = (string)message.response_body.data;
string response = (string)response_body.get_data();
Logger.debug("FeedHQ post token : " + response);
m_utils.setPostToken(response);

Expand Down Expand Up @@ -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_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
Expand All @@ -140,7 +140,7 @@ public class FeedReader.FeedHQConnection {

return Response() {
status = message.status_code,
data = (string)message.response_body.flatten().data
data = (string)response_body.get_data()
};
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/backend/fresh/freshConnection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ 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_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
Logger.error("No response from freshRSS to message getSID()");
return LoginResponse.NO_CONNECTION;
}

string response = (string)message.response_body.flatten().data;
string response = (string)response_body.get_data();

if(!response.has_prefix("SID="))
{
Expand Down Expand Up @@ -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_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
Expand All @@ -101,7 +101,7 @@ public class FeedReader.freshConnection {

return Response() {
status = message.status_code,
data = (string)message.response_body.flatten().data
data = (string)response_body.get_data()
};
}

Expand All @@ -115,7 +115,7 @@ public class FeedReader.freshConnection {
message.request_headers.append("DNT", "1");
}

m_session.send_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
Expand All @@ -124,7 +124,7 @@ public class FeedReader.freshConnection {

return Response() {
status = message.status_code,
data = (string)message.response_body.flatten().data
data = (string)response_body.get_data()
};
}
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/backend/inoreader/InoReaderConnection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ 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_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
return LoginResponse.NO_CONNECTION;
}

string response = (string)message.response_body.flatten().data;
string response = (string)response_body.get_data();

try
{
Expand Down Expand Up @@ -90,14 +90,14 @@ 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_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
return LoginResponse.NO_CONNECTION;
}

string response = (string)message.response_body.flatten().data;
string response = (string)response_body.get_data();

try
{
Expand Down Expand Up @@ -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_and_read(message);
var response_body = m_session.send_and_read(message);

if(message.status_code != 200)
{
Expand All @@ -166,7 +166,7 @@ public class FeedReader.InoReaderConnection {

return Response() {
status = message.status_code,
data = (string)message.response_body.flatten().data
data = (string)response_body.get_data().data
};
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/backend/local/localInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ public class FeedReader.localInterface : FeedServerInterface {
var session = new Soup.Session();
session.user_agent = Constants.USER_AGENT;
session.timeout = 5;
session.send_and_read(msg);
string xml = (string)msg.response_body.flatten().data;
var response_body = session.send_and_read(msg);
string xml = (string)response_body.get_data();

// parse
Rss.Parser parser = new Rss.Parser();
Expand Down
4 changes: 2 additions & 2 deletions plugins/backend/local/localUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FeedReader.localUtils : GLib.Object {
return null;
}

session.send_and_read(msg);
var response_body = session.send_and_read(msg);
uint status = msg.status_code;

if(status < 100 || status >= 400)
Expand All @@ -53,7 +53,7 @@ public class FeedReader.localUtils : GLib.Object {
Logger.warning(errmsg);
return null;
}
string xml = (string)msg.response_body.flatten().data;
string xml = (string)response_body.get_data();
string? url = null;

// parse
Expand Down
7 changes: 4 additions & 3 deletions plugins/backend/owncloud/OwncloudNewsMessage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FeedReader.OwnCloudNewsMessage : GLib.Object {

private Soup.Session m_session;
private Soup.Message m_message_soup;
private Bytes response_body;
private GLib.StringBuilder m_message_string;
private string m_contenttype;
private Json.Parser m_parser;
Expand Down Expand Up @@ -136,7 +137,7 @@ public class FeedReader.OwnCloudNewsMessage : GLib.Object {
m_message_soup.request_headers.append("DNT", "1");
}

m_session.send_and_read(m_message_soup);
response_body = m_session.send_and_read(m_message_soup);
var status = m_message_soup.status_code;

if(status == 401) // unauthorized
Expand Down Expand Up @@ -165,7 +166,7 @@ public class FeedReader.OwnCloudNewsMessage : GLib.Object {

try
{
m_parser.load_from_data((string)m_message_soup.response_body.flatten().data);
m_parser.load_from_data((string)response_body.get_data());
}
catch(Error e)
{
Expand Down Expand Up @@ -201,6 +202,6 @@ public class FeedReader.OwnCloudNewsMessage : GLib.Object {

public void printResponse()
{
Logger.debug((string)m_message_soup.response_body.flatten().data);
Logger.debug((string)response_body.get_data());
}
}
7 changes: 4 additions & 3 deletions plugins/backend/ttrss/ttrssMessage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FeedReader.ttrssMessage : GLib.Object {

private Soup.Session m_session;
private Soup.Message m_message_soup;
private Bytes response_body;
private Json.Object m_request_object = new Json.Object();
private const string m_contenttype = "application/x-www-form-urlencoded";
private Json.Object m_response_object;
Expand Down Expand Up @@ -97,7 +98,7 @@ public class FeedReader.ttrssMessage : GLib.Object {
m_message_soup.request_headers.append("DNT", "1");
}

m_session.send_and_read(m_message_soup);
response_body = m_session.send_and_read(m_message_soup);
var status_code = m_message_soup.status_code;

if(status_code == 401) // unauthorized
Expand Down Expand Up @@ -127,7 +128,7 @@ public class FeedReader.ttrssMessage : GLib.Object {
var parser = new Json.Parser();
try
{
parser.load_from_data((string)m_message_soup.response_body.flatten().data);
parser.load_from_data((string)response_body.get_data());
}
catch(Error e)
{
Expand Down Expand Up @@ -220,7 +221,7 @@ public class FeedReader.ttrssMessage : GLib.Object {
});
}
var request = object_to_string(obj);
var response = (string)m_message_soup.response_body.flatten().data;
var response = (string)response_body.get_data();
Logger.error(@"$prefix\nURL: $url\nRequest object: $request\nResponse: $response");
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/share/Instapaper/InstapaperAPI.vala
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ public class FeedReader.InstaAPI : ShareAccountInterface, Peas.ExtensionBase {
message_soup.request_headers.append("DNT", "1");
}

session.send_and_read(message_soup);
string response = (string)message_soup.response_body.flatten().data;
var response_body = session.send_and_read(message_soup);
string response = (string)response_body.get_data();

if(response == null || response == "")
{
Expand Down
18 changes: 9 additions & 9 deletions plugins/share/Pocket/PocketAPI.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase {
message_soup.request_headers.append("DNT", "1");
}

session.send_and_read(message_soup);
var response_body = session.send_and_read(message_soup);

string response = (string)message_soup.response_body.flatten().data;
string response = (string)response_body.get_data();
return response.substring(response.index_of_char('=')+1);
}

Expand All @@ -98,15 +98,15 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase {
message_soup.request_headers.append("DNT", "1");
}

session.send_and_read(message_soup);
var response_body = session.send_and_read(message_soup);

if((string)message_soup.response_body.flatten().data == null
|| (string)message_soup.response_body.flatten().data == "")
if((string)response_body.get_data() == null
|| (string)response_body.get_data() == "")
{
return false;
}

string response = (string)message_soup.response_body.flatten().data;
string response = (string)response_body.get_data();
Logger.debug(response);
int tokenStart = response.index_of_char('=')+1;
int tokenEnd = response.index_of_char('&', tokenStart);
Expand Down Expand Up @@ -183,10 +183,10 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase {
message_soup.request_headers.append("DNT", "1");
}

session.send_and_read(message_soup);
var response_body = session.send_and_read(message_soup);

if((string)message_soup.response_body.flatten().data == null
|| (string)message_soup.response_body.flatten().data == "")
if((string)response_body.get_data() == null
|| (string)response_body.get_data() == "")
{
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/share/Wallabag/WallabagAPI.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ 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_and_read(message_soup);
var response_body = session.send_and_read(message_soup);

if((string)message_soup.response_body.flatten().data == null
|| (string)message_soup.response_body.flatten().data == "")
if((string)response_body.get_data() == null
|| (string)response_body.get_data() == "")
{
Logger.error("WallabagAPI - getAccessToken: no response");
Logger.error(url);
Logger.error(message);
return false;
}

string response = (string)message_soup.response_body.flatten().data;
string response = (string)response_body.get_data();
Logger.debug(response);

var parser = new Json.Parser();
Expand Down Expand Up @@ -156,8 +156,8 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase
message_soup.request_headers.append("Authorization", "Bearer " + settings.get_string("oauth-access-token"));
session.send_and_read(message_soup);

if((string)message_soup.response_body.flatten().data == null
|| (string)message_soup.response_body.flatten().data == "")
if((string)response_body.get_data() == null
|| (string)response_body.get_data() == "")
{
Logger.error("WallabagAPI - addBookmark: no response");
Logger.error(url);
Expand Down
Loading

0 comments on commit be1cff1

Please sign in to comment.