From e4a48d4046a03f0b9b3bab3a77db0f056ed4c07e Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Mon, 4 Jan 2016 01:07:56 +1300 Subject: [PATCH 1/2] Allow building for winpidgin --- matrix-api.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/matrix-api.c b/matrix-api.c index 9817949..99b5865 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -324,20 +324,14 @@ static void _add_proxy_auth_headers(GString *request_str, PurpleProxyInfo *gpi) { const char *username, *password; char *t1, *t2, *ntlm_type1; - char hostname[256]; - int ret; + const gchar *hostname; username = purple_proxy_info_get_username(gpi); password = purple_proxy_info_get_password(gpi); if (username == NULL) return; - ret = gethostname(hostname, sizeof(hostname)); - hostname[sizeof(hostname) - 1] = '\0'; - if (ret < 0 || hostname[0] == '\0') { - purple_debug_warning("util", "proxy - gethostname() failed -- is your hostname set?"); - strcpy(hostname, "localhost"); - } + hostname = g_get_host_name(); t1 = g_strdup_printf("%s:%s", username, password ? password : ""); t2 = purple_base64_encode((const guchar *)t1, strlen(t1)); @@ -427,7 +421,7 @@ static gchar *_build_request(PurpleAccount *acct, const gchar *url, (int)(url_path-url_host), url_host); g_string_append(request_str, "Connection: close\r\n"); - g_string_append_printf(request_str, "Content-Length: %zi\r\n", + g_string_append_printf(request_str, "Content-Length: %" G_GSIZE_FORMAT "\r\n", body == NULL ? 0 : strlen(body)); if(using_http_proxy) @@ -532,15 +526,16 @@ gchar *_build_login_body(const gchar *username, const gchar *password) json_object_set_string_member(body, "type", "m.login.password"); json_object_set_string_member(body, "user", username); json_object_set_string_member(body, "password", password); - node = json_node_alloc(); - json_node_init_object(node, body); - json_object_unref(body); + + node = json_node_new(JSON_NODE_OBJECT); + json_node_set_object(node, body); generator = json_generator_new(); json_generator_set_root(generator, node); result = json_generator_to_data(generator, NULL); g_object_unref(G_OBJECT(generator)); json_node_free(node); + json_object_unref(body); return result; } @@ -632,8 +627,8 @@ MatrixApiRequestData *matrix_api_send(MatrixConnectionData *conn, g_string_append(url, "?access_token="); g_string_append(url, purple_url_encode(conn->access_token)); - body_node = json_node_alloc(); - json_node_init_object(body_node, content); + body_node = json_node_new(JSON_NODE_OBJECT); + json_node_set_object(body_node, content); generator = json_generator_new(); json_generator_set_root(generator, body_node); From e161f3d693362f973a1f8ff8e2981fee66b8527f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Sun, 3 Jan 2016 12:23:25 +0000 Subject: [PATCH 2/2] Fix some indentation; move json_object_unref back to where it was --- matrix-api.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/matrix-api.c b/matrix-api.c index 99b5865..b5e99bb 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -331,7 +331,7 @@ static void _add_proxy_auth_headers(GString *request_str, PurpleProxyInfo *gpi) if (username == NULL) return; - hostname = g_get_host_name(); + hostname = g_get_host_name(); t1 = g_strdup_printf("%s:%s", username, password ? password : ""); t2 = purple_base64_encode((const guchar *)t1, strlen(t1)); @@ -527,15 +527,15 @@ gchar *_build_login_body(const gchar *username, const gchar *password) json_object_set_string_member(body, "user", username); json_object_set_string_member(body, "password", password); - node = json_node_new(JSON_NODE_OBJECT); - json_node_set_object(node, body); + node = json_node_new(JSON_NODE_OBJECT); + json_node_set_object(node, body); + json_object_unref(body); generator = json_generator_new(); json_generator_set_root(generator, node); result = json_generator_to_data(generator, NULL); g_object_unref(G_OBJECT(generator)); json_node_free(node); - json_object_unref(body); return result; } @@ -627,8 +627,8 @@ MatrixApiRequestData *matrix_api_send(MatrixConnectionData *conn, g_string_append(url, "?access_token="); g_string_append(url, purple_url_encode(conn->access_token)); - body_node = json_node_new(JSON_NODE_OBJECT); - json_node_set_object(body_node, content); + body_node = json_node_new(JSON_NODE_OBJECT); + json_node_set_object(body_node, content); generator = json_generator_new(); json_generator_set_root(generator, body_node);