Skip to content

Commit c2dba14

Browse files
committed
Fix libsoup errors in Feedbin API
1 parent 18117d3 commit c2dba14

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

plugins/backend/feedbin/feedbinAPI.vala

+35-43
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,15 @@ public class FeedbinAPI : Object {
4242
{
4343
m_session.user_agent = user_agent;
4444
}
45-
46-
m_session.authenticate.connect(authenticate);
47-
}
48-
49-
~FeedbinAPI()
50-
{
51-
m_session.authenticate.disconnect(authenticate);
5245
}
5346

54-
private void authenticate(Soup.Message msg, Soup.Auth auth, bool retrying)
55-
{
56-
if(!retrying)
57-
{
58-
auth.authenticate(this.username, this.password);
47+
private bool authenticate (Soup.Auth auth, bool retrying) {
48+
if (!retrying) {
49+
auth.authenticate (this.username, this.password);
50+
return true;
5951
}
52+
53+
return false;
6054
}
6155

6256
private Soup.Message request(string method, string last_part, string? input = null) throws FeedbinError
@@ -68,35 +62,34 @@ public class FeedbinAPI : Object {
6862
var path = m_base_uri + last_part;
6963
var message = new Soup.Message(method, path);
7064

71-
if(method == "POST")
72-
{
65+
message.authenticate.connect (authenticate);
66+
67+
if (method == "POST") {
7368
message.request_headers.append("Content-Type", "application/json; charset=utf-8");
7469
}
7570

76-
if(input != null)
77-
{
78-
message.request_body.append_take(input.data);
71+
if (input != null) {
72+
message.set_request_body_from_bytes ("application/x-www-form-urlencoded", new Bytes(input.data));
7973
}
8074

81-
m_session.send_and_read(message);
82-
var status = message.status_code;
83-
if(status < 200 || status >= 400)
84-
{
85-
switch(status)
86-
{
87-
case Soup.Status.CANT_RESOLVE:
88-
case Soup.Status.CANT_RESOLVE_PROXY:
89-
case Soup.Status.CANT_CONNECT:
90-
case Soup.Status.CANT_CONNECT_PROXY:
91-
throw new FeedbinError.NO_CONNECTION(@"Connection to $m_base_uri failed");
92-
case Soup.Status.UNAUTHORIZED:
93-
throw new FeedbinError.NOT_AUTHORIZED(@"Not authorized to $method $path");
94-
case Soup.Status.NOT_FOUND:
95-
throw new FeedbinError.NOT_FOUND(@"$method $path not found");
96-
}
97-
string phrase = Soup.Status.get_phrase(status);
98-
throw new FeedbinError.UNKNOWN_ERROR(@"Unexpected status $status ($phrase) for $method $path");
75+
try {
76+
m_session.send_and_read(message);
77+
var status = message.status_code;
78+
79+
if (status < 200 || status >= 400) {
80+
switch (status) {
81+
case Soup.Status.UNAUTHORIZED:
82+
throw new FeedbinError.NOT_AUTHORIZED(@"Not authorized to $method $path");
83+
case Soup.Status.NOT_FOUND:
84+
throw new FeedbinError.NOT_FOUND(@"$method $path not found");
85+
}
86+
string phrase = Soup.Status.get_phrase(status);
87+
throw new FeedbinError.UNKNOWN_ERROR(@"Unexpected status $status ($phrase) for $method $path");
88+
}
89+
} catch (Error e) {
90+
throw new FeedbinError.NO_CONNECTION(@"Connection to $m_base_uri failed");
9991
}
92+
10093
return message;
10194
}
10295

@@ -138,22 +131,21 @@ public class FeedbinAPI : Object {
138131
private static Json.Node parse_json(Soup.Message response) throws FeedbinError
139132
{
140133
var method = response.method;
141-
var uri = response.uri.to_string(false);
134+
var uri = response.uri.to_string();
142135
string content = (string)response.response_body.flatten().data;
143-
if(content == null)
144-
{
136+
137+
if (content == null) {
145138
throw new FeedbinError.INVALID_FORMAT(@"$method $uri returned no content but expected JSON");
146139
}
147140

148141
var parser = new Json.Parser();
149-
try
150-
{
142+
143+
try {
151144
parser.load_from_data(content, -1);
152-
}
153-
catch (Error e)
154-
{
145+
} catch (Error e) {
155146
throw new FeedbinError.INVALID_FORMAT(@"$method $uri returned invalid JSON: " + e.message + "\nContent is: $content");
156147
}
148+
157149
return parser.get_root();
158150
}
159151

plugins/backend/meson.build

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ supported_backend_plugins = [
55
'fresh',
66
'inoreader',
77
'local',
8-
'owncloud',
9-
'ttrss'
8+
# 'owncloud',
9+
# 'ttrss'
1010
]
1111
backend_plugins = get_option('backend-plugins')
1212

0 commit comments

Comments
 (0)