aboutsummaryrefslogtreecommitdiffstats
path: root/matrix-connection.c
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2015-10-29 12:29:07 +0000
committerRichard van der Hoff <richard@matrix.org>2015-10-29 12:29:07 +0000
commit32e9c376d3a25e527327974dd97e2313d430a5fd (patch)
tree4876a9d24c819bb83fca2b21761db3806b066d37 /matrix-connection.c
parent2498e41374edc940d6de474c11e0530fcc83752f (diff)
downloadpurple-matrix-32e9c376d3a25e527327974dd97e2313d430a5fd.tar.gz
Improve error-handling in API requests
Try to deal better with errors which occur during API requests, in terms of reporting them to the user/logs, and in terms of not writing to freed structures. Also do some sanity-checking of the supplied homeserver URL: make sure it is https:// or http://, and make sure we get the right number of '/'s.
Diffstat (limited to 'matrix-connection.c')
-rw-r--r--matrix-connection.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/matrix-connection.c b/matrix-connection.c
index 6c499d8..925fef6 100644
--- a/matrix-connection.c
+++ b/matrix-connection.c
@@ -200,9 +200,14 @@ void matrix_connection_start_login(PurpleConnection *pc)
{
PurpleAccount *acct = pc->account;
MatrixConnectionData *conn = purple_connection_get_protocol_data(pc);
+ const gchar *homeserver = purple_account_get_string(pc->account,
+ PRPL_ACCOUNT_OPT_HOME_SERVER, DEFAULT_HOME_SERVER);
- conn->homeserver = g_strdup(purple_account_get_string(pc->account,
- PRPL_ACCOUNT_OPT_HOME_SERVER, DEFAULT_HOME_SERVER));
+ if(!g_str_has_suffix(homeserver, "/")) {
+ conn->homeserver = g_strconcat(homeserver, "/", NULL);
+ } else {
+ conn->homeserver = g_strdup(homeserver);
+ }
purple_connection_set_state(pc, PURPLE_CONNECTING);
purple_connection_update_progress(pc, _("Logging in"), 0, 3);