Esempio n. 1
0
static void url_fetched(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _data)
{
	CbInfo *data = (CbInfo *)_data;
	PurpleConversation *conv = data->conv;
	GList *convs = purple_conversations_get_all();
	const gchar *url;

	if (purple_http_response_is_successful(response)) {
		url = purple_http_response_get_data(response, NULL);
		g_hash_table_insert(tinyurl_cache, data->original_url, g_strdup(url));
	} else {
		url = _("Error while querying TinyURL");
		g_free(data->original_url);
	}

	/* ensure the conversation still exists */
	for (; convs; convs = convs->next) {
		if ((PurpleConversation *)(convs->data) == conv) {
			FinchConv *fconv = FINCH_CONV(conv);
			gchar *str = g_strdup_printf("[%d] %s", data->num, url);
			GntTextView *tv = GNT_TEXT_VIEW(fconv->tv);
			gnt_text_view_tag_change(tv, data->tag, str, FALSE);
			g_free(str);
			g_free(data->tag);
			g_free(data);
			return;
		}
	}
	g_free(data->tag);
	g_free(data);
	purple_debug_info("TinyURL", "Conversation no longer exists... :(\n");
}
Esempio n. 2
0
static void ggp_edisc_xfer_recv_done(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);

	if (purple_xfer_is_cancelled(xfer))
		return;

	g_return_if_fail(edisc_xfer != NULL);

	edisc_xfer->hc = NULL;

	if (!purple_http_response_is_successful(response)) {
		ggp_edisc_xfer_error(xfer, _("Error while receiving a file"));
		return;
	}

	if (purple_xfer_get_bytes_remaining(xfer) == 0) {
		purple_xfer_set_completed(xfer, TRUE);
		purple_xfer_end(xfer);
		ggp_edisc_xfer_free(xfer);
	} else {
		purple_debug_warning("gg", "ggp_edisc_xfer_recv_done: didn't "
			"received everything\n");
		ggp_edisc_xfer_error(xfer, _("Error while receiving a file"));
	}
}
Esempio n. 3
0
static void ggp_ggdrive_auth_done(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer user_data)
{
	PurpleConnection *gc = purple_http_conn_get_purple_connection(hc);
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
	JsonParser *parser;
	JsonObject *result;
	int status = -1;

	g_return_if_fail(sdata != NULL);

	sdata->auth_request = NULL;

	if (!purple_http_response_is_successful(response)) {
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: authentication "
			"failed due to unsuccessful request (code = %d)\n",
			purple_http_response_get_code(response));
		ggp_ggdrive_auth_results(gc, FALSE);
		return;
	}

	parser = ggp_json_parse(purple_http_response_get_data(response, NULL));
	result = json_node_get_object(json_parser_get_root(parser));
	result = json_object_get_object_member(result, "result");
	if (json_object_has_member(result, "status"))
		status = json_object_get_int_member(result, "status");
	g_object_unref(parser);

	if (status != 0 ) {
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: authentication "
			"failed due to bad result (status=%d)\n", status);
		if (purple_debug_is_verbose())
			purple_debug_misc("gg", "ggp_ggdrive_auth_done: "
				"result = %s\n",
				purple_http_response_get_data(response, NULL));
		ggp_ggdrive_auth_results(gc, FALSE);
		return;
	}

	sdata->security_token = g_strdup(purple_http_response_get_header(
		response, "X-gged-security-token"));
	if (!sdata->security_token) {
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: authentication "
			"failed due to missing security token header\n");
		ggp_ggdrive_auth_results(gc, FALSE);
		return;
	}

	if (purple_debug_is_unsafe())
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: "
			"security_token=%s\n", sdata->security_token);
	ggp_ggdrive_auth_results(gc, TRUE);
}
Esempio n. 4
0
static void ggp_pubdir_set_info_got_response(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer user_data)
{
	if (!purple_http_response_is_successful(response)) {
		purple_debug_error("gg", "ggp_pubdir_set_info_got_response: "
			"failed\n");
		return;
	}

	purple_debug_info("gg", "ggp_pubdir_set_info_got_response: [%s]\n",
		purple_http_response_get_data(response, NULL));
	/* <result><status>0</status></result> */

	/* TODO: notify about failure */
}
Esempio n. 5
0
static void ggp_avatar_buddy_update_received(PurpleHttpConnection *http_conn,
        PurpleHttpResponse *response, gpointer _pending_update)
{
    ggp_avatar_buddy_update_req *pending_update = _pending_update;
    PurpleBuddy *buddy;
    PurpleAccount *account;
    PurpleConnection *gc = pending_update->gc;
    ggp_avatar_session_data *avdata;
    gchar timestamp_str[20];
    const gchar *got_data;
    size_t got_len;

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    avdata = ggp_avatar_get_avdata(gc);
    g_assert(pending_update == avdata->current_update);
    avdata->current_update = NULL;

    if (!purple_http_response_is_successful(response)) {
        purple_debug_error("gg", "ggp_avatar_buddy_update_received: bad"
                           " response while getting avatar for %u: %s\n",
                           pending_update->uin,
                           purple_http_response_get_error(response));
        g_free(pending_update);
        return;
    }

    account = purple_connection_get_account(gc);
    buddy = purple_blist_find_buddy(account, ggp_uin_to_str(pending_update->uin));

    if (!buddy) {
        purple_debug_warning("gg", "ggp_avatar_buddy_update_received: "
                             "buddy %u disappeared\n", pending_update->uin);
        g_free(pending_update);
        return;
    }

    g_snprintf(timestamp_str, sizeof(timestamp_str), "%lu",
               pending_update->timestamp);
    got_data = purple_http_response_get_data(response, &got_len);
    purple_buddy_icons_set_for_user(account, purple_buddy_get_name(buddy),
                                    g_memdup(got_data, got_len), got_len, timestamp_str);

    purple_debug_info("gg", "ggp_avatar_buddy_update_received: "
                      "got avatar for buddy %u [ts=%lu]\n", pending_update->uin,
                      pending_update->timestamp);
    g_free(pending_update);
}
Esempio n. 6
0
static void ggp_avatar_own_sent(PurpleHttpConnection *http_conn,
                                PurpleHttpResponse *response, gpointer user_data)
{
    PurpleConnection *gc =
        purple_http_conn_get_purple_connection(http_conn);

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    if (!purple_http_response_is_successful(response)) {
        purple_debug_error("gg", "ggp_avatar_own_sent: "
                           "avatar not sent. %s\n",
                           purple_http_response_get_error(response));
        return;
    }
    purple_debug_info("gg", "ggp_avatar_own_sent: %s\n",
                      purple_http_response_get_data(response, NULL));
}
Esempio n. 7
0
static void
hangouts_oauth_with_code_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data)
{
	HangoutsAccount *ha = user_data;
	JsonObject *obj;
	const gchar *raw_response;
	gsize response_len;
	PurpleAccount *account = ha->account;

	raw_response = purple_http_response_get_data(response, &response_len);
	obj = json_decode_object(raw_response, response_len);

	if (purple_http_response_is_successful(response) && obj)
	{
		ha->access_token = g_strdup(json_object_get_string_member(obj, "access_token"));
		ha->refresh_token = g_strdup(json_object_get_string_member(obj, "refresh_token"));
		
		purple_account_set_remember_password(account, TRUE);
		hangouts_save_refresh_token_password(account, ha->refresh_token);
		
		hangouts_auth_get_session_cookies(ha);
	} else {
		if (obj != NULL) {
			if (json_object_has_member(obj, "error")) {
				if (g_strcmp0(json_object_get_string_member(obj, "error"), "invalid_grant") == 0) {
					hangouts_save_refresh_token_password(ha->account, NULL);
					purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
						json_object_get_string_member(obj, "error_description"));
				} else {
					purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
						json_object_get_string_member(obj, "error_description"));
				}
			} else {
				purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, 
					_("Invalid response"));
			}
		}
		purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
			_("Invalid response"));
	}

	json_object_unref(obj);
}
Esempio n. 8
0
static void ggp_edisc_xfer_recv_ack_done(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer;

	if (purple_xfer_is_cancelled(xfer))
		g_return_if_reached();

	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	edisc_xfer->hc = NULL;

	if (!purple_http_response_is_successful(response)) {
		ggp_edisc_xfer_error(xfer, _("Cannot confirm file transfer."));
		return;
	}

	purple_debug_info("gg", "ggp_edisc_xfer_recv_ack_done: [%s]\n",
		purple_http_response_get_data(response, NULL));
}
Esempio n. 9
0
static void
fetched_user_display(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _data)
{
	MsnFetchUserDisplayData *data = _data;
	MsnSession *session = data->session;

	if (purple_http_response_is_successful(response)) {
		size_t len;
		const gchar *icon_data;

		icon_data = purple_http_response_get_data(response, &len);
		purple_buddy_icons_set_for_user(session->account,
			data->remote_user, g_memdup(icon_data, len), len,
			data->sha1);
	}

	end_user_display(NULL, session);

	g_free(data);
}
Esempio n. 10
0
static void
tinyurl_notify_fetch_cb(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _win)
{
	GntWidget *win = _win;
	const gchar *url;
	const gchar *original_url;

	if (!purple_http_response_is_successful(response))
		return;

	original_url = g_object_get_data(G_OBJECT(win), "gnttinyurl-original");
	url = purple_http_response_get_data(response, NULL);
	g_hash_table_insert(tinyurl_cache,
		g_strdup(original_url), g_strdup(url));

	tinyurl_notify_tinyuri(win, url);

	g_signal_handlers_disconnect_matched(G_OBJECT(win), G_SIGNAL_MATCH_FUNC,
			0, 0, NULL,
			G_CALLBACK(purple_http_conn_cancel), NULL);
}
Esempio n. 11
0
static PurpleXmlNode *
jabber_bosh_connection_parse(PurpleJabberBOSHConnection *conn,
	PurpleHttpResponse *response)
{
	PurpleXmlNode *root;
	const gchar *data;
	size_t data_len;
	const gchar *type;

	g_return_val_if_fail(conn != NULL, NULL);
	g_return_val_if_fail(response != NULL, NULL);

	if (conn->is_terminating || purple_account_is_disconnecting(
		purple_connection_get_account(conn->js->gc)))
	{
		return NULL;
	}

	if (!purple_http_response_is_successful(response)) {
		purple_connection_error(conn->js->gc,
			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
			_("Unable to connect"));
		return NULL;
	}

	data = purple_http_response_get_data(response, &data_len);
	root = purple_xmlnode_from_str(data, data_len);

	type = purple_xmlnode_get_attrib(root, "type");
	if (g_strcmp0(type, "terminate") == 0) {
		purple_connection_error(conn->js->gc,
			PURPLE_CONNECTION_ERROR_OTHER_ERROR, _("The BOSH "
			"connection manager terminated your session."));
		purple_xmlnode_free(root);
		return NULL;
	}

	return root;
}
static void
yahoo_process_filetrans_info_15_got(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	struct yahoo_xfer_data *xd;
	YahooData *yd;

	xd = purple_xfer_get_protocol_data(xfer);
	yd = purple_connection_get_protocol_data(xd->gc);

	xd->hc = NULL;

	if (!purple_http_response_is_successful(response)) {
		purple_notify_error(yd->gc, NULL, _("File Transfer Failed"),
			_("Unable to get file header."),
			purple_request_cpar_from_connection(yd->gc));
		purple_xfer_cancel_remote(xfer);
		return;
	}

	purple_xfer_start(xfer, -1, NULL, 0);
}
Esempio n. 13
0
static void
jabber_google_relay_fetch_cb(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer user_data)
{
	JabberGoogleRelayCallbackData *data =
		(JabberGoogleRelayCallbackData *) user_data;
	GoogleSession *session = data->session;
	JabberGoogleRelayCallback *cb = data->cb;
	gchar *relay_ip = NULL;
	guint relay_udp = 0;
	guint relay_tcp = 0;
	guint relay_ssltcp = 0;
	gchar *relay_username = NULL;
	gchar *relay_password = NULL;

	g_free(data);

	purple_debug_info("jabber", "got response on HTTP request to relay server\n");

	if (purple_http_response_is_successful(response)) {
		const gchar *got_data =
			purple_http_response_get_data(response, NULL);
		purple_debug_info("jabber", "got Google relay request response:\n%s\n",
			got_data);
		jabber_google_relay_parse_response(got_data, &relay_ip, &relay_udp,
			&relay_tcp, &relay_ssltcp, &relay_username, &relay_password);
	}

	if (cb)
		cb(session, relay_ip, relay_udp, relay_tcp, relay_ssltcp,
		   relay_username, relay_password);

	g_free(relay_ip);
	g_free(relay_username);
	g_free(relay_password);
}
static void
yahoo_process_filetrans_15_downloaded(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	struct yahoo_xfer_data *xd;

	xd = purple_xfer_get_protocol_data(xfer);

	xd->hc = NULL;

	if (purple_xfer_is_cancelled(xfer))
		return;

	if (!purple_http_response_is_successful(response) ||
		purple_xfer_get_bytes_remaining(xfer) > 0)
	{
		purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE);
		purple_xfer_end(xfer);
	} else {
		purple_xfer_set_completed(xfer, TRUE);
		purple_xfer_end(xfer);
	}
}
Esempio n. 15
0
static void ggp_edisc_xfer_send_done(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
	const gchar *data = purple_http_response_get_data(response, NULL);
	JsonParser *parser;
	JsonObject *result;
	int result_status = -1;

	if (purple_xfer_is_cancelled(xfer))
		return;

	g_return_if_fail(edisc_xfer != NULL);

	edisc_xfer->hc = NULL;

	if (!purple_http_response_is_successful(response)) {
		ggp_edisc_xfer_error(xfer, _("Error while sending a file"));
		return;
	}

	parser = ggp_json_parse(data);
	result = json_node_get_object(json_parser_get_root(parser));
	result = json_object_get_object_member(result, "result");
	if (json_object_has_member(result, "status"))
		result_status = json_object_get_int_member(result, "status");
	g_object_unref(parser);

	if (result_status == 0) {
		purple_xfer_set_completed(xfer, TRUE);
		purple_xfer_end(xfer);
		ggp_edisc_xfer_free(xfer);
	} else
		ggp_edisc_xfer_error(xfer, _("Error while sending a file"));
}
Esempio n. 16
0
static void ggp_edisc_xfer_send_init_ticket_created(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer _xfer)
{
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(
		purple_http_conn_get_purple_connection(hc));
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
	const gchar *data = purple_http_response_get_data(response, NULL);
	ggp_edisc_xfer_ack_status ack_status;
	JsonParser *parser;
	JsonObject *ticket;

	if (purple_xfer_is_cancelled(xfer))
		return;

	g_return_if_fail(sdata != NULL);

	edisc_xfer->hc = NULL;

	if (!purple_http_response_is_successful(response)) {
		int error_id = ggp_edisc_parse_error(data);
		if (error_id == 206) /* recipient not logged in */
			ggp_edisc_xfer_error(xfer,
				_("Recipient not logged in"));
		else if (error_id == 207) /* bad sender recipient relation */
			ggp_edisc_xfer_error(xfer, _("You aren't on the "
                                "recipient's buddy list"));
		else
			ggp_edisc_xfer_error(xfer,
				_("Unable to send file"));
		return;
	}

	parser = ggp_json_parse(data);
	ticket = json_node_get_object(json_parser_get_root(parser));
	ticket = json_object_get_object_member(ticket, "result");
	ticket = json_object_get_object_member(ticket, "send_ticket");
	edisc_xfer->ticket_id = g_strdup(json_object_get_string_member(
		ticket, "id"));
	ack_status = ggp_edisc_xfer_parse_ack_status(
		json_object_get_string_member(ticket, "ack_status"));
	/* send_mode: "normal", "publink" (for legacy clients) */

	g_object_unref(parser);

	if (edisc_xfer->ticket_id == NULL) {
		purple_debug_error("gg",
			"ggp_edisc_xfer_send_init_ticket_created: "
			"couldn't get ticket id\n");
		return;
	}

	purple_debug_info("gg", "ggp_edisc_xfer_send_init_ticket_created: "
		"ticket \"%s\" created\n", edisc_xfer->ticket_id);

	g_hash_table_insert(sdata->xfers_initialized,
		edisc_xfer->ticket_id, xfer);
	g_hash_table_insert(sdata->xfers_history,
		g_strdup(edisc_xfer->ticket_id), GINT_TO_POINTER(1));

	if (ack_status != GGP_EDISC_XFER_ACK_STATUS_UNKNOWN)
		ggp_edisc_xfer_send_ticket_changed(edisc_xfer->gc, xfer,
			ack_status == GGP_EDISC_XFER_ACK_STATUS_ALLOWED);
}
Esempio n. 17
0
static void ggp_edisc_xfer_recv_ticket_update_got(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer user_data)
{
	PurpleConnection *gc = purple_http_conn_get_purple_connection(hc);
	PurpleXfer *xfer;
	ggp_edisc_xfer *edisc_xfer;
	JsonParser *parser;
	JsonObject *result;
	int status = -1;
	ggp_edisc_session_data *sdata;

	const gchar *ticket_id, *file_name, *send_mode_str;
	uin_t sender, recipient;
	int file_size;

	if (!purple_http_response_is_successful(response)) {
		purple_debug_error("gg",
			"ggp_edisc_xfer_recv_ticket_update_got: "
			"cannot fetch update for ticket (code=%d)\n",
			purple_http_response_get_code(response));
		return;
	}

	sdata = ggp_edisc_get_sdata(gc);
	g_return_if_fail(sdata != NULL);

	parser = ggp_json_parse(purple_http_response_get_data(response, NULL));
	result = json_node_get_object(json_parser_get_root(parser));
	result = json_object_get_object_member(result, "result");
	if (json_object_has_member(result, "status"))
		status = json_object_get_int_member(result, "status");
	result = json_object_get_object_member(result, "send_ticket");

	if (status != 0) {
		purple_debug_warning("gg",
			"ggp_edisc_xfer_recv_ticket_update_got: failed to get "
			"update (status=%d)\n", status);
		g_object_unref(parser);
		return;
	}

	ticket_id = json_object_get_string_member(result, "id");
	sender = ggp_str_to_uin(json_object_get_string_member(result,
		"sender"));
	recipient = ggp_str_to_uin(json_object_get_string_member(result,
		"recipient"));
	file_size = g_ascii_strtoll(json_object_get_string_member(result,
		"file_size"), NULL, 10);
	file_name = json_object_get_string_member(result, "file_name");

	/* GG11: normal
	 * AQQ 2.4.2.10: direct_inbox
	 */
	send_mode_str = json_object_get_string_member(result, "send_mode");

	/* more fields:
	 * send_progress (float), ack_status, send_status
	 */

	if (purple_debug_is_verbose() && purple_debug_is_unsafe())
		purple_debug_info("gg", "Got ticket update: id=%s, sender=%u, "
			"recipient=%u, file name=\"%s\", file size=%d, "
			"send mode=%s)\n",
			ticket_id,
			sender, recipient,
			file_name, file_size,
			send_mode_str);

	xfer = g_hash_table_lookup(sdata->xfers_initialized, ticket_id);
	if (xfer != NULL) {
		purple_debug_misc("gg", "ggp_edisc_xfer_recv_ticket_update_got:"
			" ticket %s already updated\n",
			purple_debug_is_unsafe() ? ticket_id : "");
		g_object_unref(parser);
		return;
	}

	if (recipient != ggp_get_my_uin(gc)) {
		purple_debug_misc("gg", "ggp_edisc_xfer_recv_ticket_update_got:"
			" ticket %s is not for incoming transfer "
			"(its from %u to %u)\n",
			purple_debug_is_unsafe() ? ticket_id : "",
			sender, recipient);
		g_object_unref(parser);
		return;
	}

	xfer = ggp_edisc_xfer_recv_new(gc, ggp_uin_to_str(sender));
	purple_xfer_set_filename(xfer, file_name);
	purple_xfer_set_size(xfer, file_size);
	purple_xfer_request(xfer);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	edisc_xfer->ticket_id = g_strdup(ticket_id);
	g_hash_table_insert(sdata->xfers_initialized,
		edisc_xfer->ticket_id, xfer);
	g_hash_table_insert(sdata->xfers_history,
		g_strdup(ticket_id), GINT_TO_POINTER(1));

	g_object_unref(parser);
}