Exemplo n.º 1
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);
}
Exemplo n.º 2
0
static void
hangouts_auth_get_session_cookies_uberauth_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data)
{
	HangoutsAccount *ha = user_data;
	PurpleHttpRequest *request;
	const gchar *uberauth;

	uberauth = purple_http_response_get_data(response, NULL);

	if (purple_http_response_get_error(response) != NULL) {
		purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, 
			_("Auth error"));
		return;
	}
	
	purple_debug_misc("hangouts-prpl", "uberauth: %s", uberauth);

	request = purple_http_request_new(NULL);
	purple_http_request_set_url_printf(request, "https://accounts.google.com/MergeSession" "?service=mail&continue=http://www.google.com&uberauth=%s", purple_url_encode(uberauth));
	purple_http_request_set_cookie_jar(request, ha->cookie_jar);
	purple_http_request_header_set_printf(request, "Authorization", "Bearer %s", ha->access_token);
	purple_http_request_set_max_redirects(request, 0);
	
	purple_http_request(ha->pc, request, hangouts_auth_get_session_cookies_got_cb, ha);
	purple_http_request_unref(request);
}
Exemplo n.º 3
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");
}
Exemplo 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 */
}
Exemplo 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);
}
Exemplo 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));
}
Exemplo n.º 7
0
static void
jabber_bosh_connection_recv(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _bosh_conn)
{
	PurpleJabberBOSHConnection *bosh_conn = _bosh_conn;
	PurpleXmlNode *node, *child;

	if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
		purple_debug_misc("jabber-bosh", "received: %s\n",
			purple_http_response_get_data(response, NULL));
	}

	node = jabber_bosh_connection_parse(bosh_conn, response);
	if (node == NULL)
		return;

	child = node->child;
	while (child != NULL) {
		/* jabber_process_packet might free child */
		PurpleXmlNode *next = child->next;
		const gchar *xmlns;

		if (child->type != PURPLE_XMLNODE_TYPE_TAG) {
			child = next;
			continue;
		}

		/* Workaround for non-compliant servers that don't stamp
		 * the right xmlns on these packets. See #11315.
		 */
		xmlns = purple_xmlnode_get_namespace(child);
		if ((xmlns == NULL || g_strcmp0(xmlns, NS_BOSH) == 0) &&
			(g_strcmp0(child->name, "iq") == 0 ||
			g_strcmp0(child->name, "message") == 0 ||
			g_strcmp0(child->name, "presence") == 0))
		{
			purple_xmlnode_set_namespace(child, NS_XMPP_CLIENT);
		}

		jabber_process_packet(bosh_conn->js, &child);

		child = next;
	}

	jabber_bosh_connection_send(bosh_conn, NULL);
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
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));
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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"));
}
Exemplo n.º 14
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);
}
Exemplo n.º 15
0
static void
fb_data_image_cb(PurpleHttpConnection *con, PurpleHttpResponse *res,
                 gpointer data)
{
	FbDataImage *img = data;
	FbDataImagePrivate *priv = img->priv;
	GError *err = NULL;

	if (G_UNLIKELY(purple_http_conn_is_cancelling(con))) {
		/* Ignore canceling HTTP requests */
		return;
	}

	fb_http_error_chk(res, &err);
	priv->image = (guint8*) purple_http_response_get_data(res, &priv->size);
	priv->func(img, err);

	if (G_UNLIKELY(err != NULL)) {
		g_error_free(err);
	}

	fb_data_image_queue(priv->fata);
	g_object_unref(img);
}
Exemplo 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);
}
Exemplo n.º 17
0
static void ggp_pubdir_got_data(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _request)
{
	ggp_pubdir_request *request = _request;
	PurpleConnection *gc = request->gc;
	gboolean succ = TRUE;
	PurpleXmlNode *xml;
	const gchar *xml_raw;
	unsigned int status, next_offset;
	int record_count, i;
	ggp_pubdir_record *records;

	xml_raw = purple_http_response_get_data(response, NULL);

	if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
		purple_debug_misc("gg", "ggp_pubdir_got_data: xml=[%s]\n",
			xml_raw);
	}

	xml = purple_xmlnode_from_str(xml_raw, -1);
	if (xml == NULL) {
		purple_debug_error("gg", "ggp_pubdir_got_data: "
			"invalid xml\n");
		request->cb(gc, -1, NULL, 0, request->user_data);
		ggp_pubdir_request_free(request);
		return;
	}

	succ &= ggp_xml_get_uint(xml, "status", &status);
	if (!ggp_xml_get_uint(xml, "nextOffset", &next_offset))
		next_offset = 0;
	xml = purple_xmlnode_get_child(xml, "users");
	if (!succ || status != 0 || !xml) {
		purple_debug_error("gg", "ggp_pubdir_got_data: "
			"invalid reply\n");
		request->cb(gc, -1, NULL, 0, request->user_data);
		ggp_pubdir_request_free(request);
		return;
	}

	record_count = ggp_xml_child_count(xml, "user");
	records = g_new0(ggp_pubdir_record, record_count);

	xml = purple_xmlnode_get_child(xml, "user");
	i = 0;
	while (xml) {
		ggp_pubdir_record *record = &records[i++];
		gchar *city = NULL, *birth_s = NULL;
		unsigned int gender = 0;
		const gchar *uin_s;

		g_assert(i <= record_count);

		record->uin = ggp_str_to_uin(purple_xmlnode_get_attrib(xml, "uin"));
		if (record->uin == 0)
			ggp_xml_get_uint(xml, "uin", &record->uin);
		if (record->uin == 0)
			purple_debug_error("gg", "ggp_pubdir_got_data:"
				" invalid uin\n");
		uin_s = ggp_uin_to_str(record->uin);

		ggp_xml_get_string(xml, "label", &record->label);
		ggp_xml_get_string(xml, "nick", &record->nickname);
		ggp_xml_get_string(xml, "name", &record->first_name);
		ggp_xml_get_string(xml, "surname", &record->last_name);
		ggp_xml_get_string(xml, "city", &city);
		ggp_xml_get_string(xml, "birth", &birth_s);
		ggp_xml_get_uint(xml, "gender", &gender);
		ggp_xml_get_uint(xml, "age", &record->age);
		ggp_xml_get_uint(xml, "province", &record->province);

		record->label = ggp_free_if_equal(record->label, uin_s);
		record->label = ggp_free_if_equal(record->label, "");
		record->nickname = ggp_free_if_equal(record->nickname, uin_s);
		record->nickname = ggp_free_if_equal(record->nickname, "");
		record->first_name = ggp_free_if_equal(record->first_name, "");
		record->last_name = ggp_free_if_equal(record->last_name, "");

		if (record->label) {}
		else if (record->nickname)
			record->label = g_strdup(record->nickname);
		else if (record->first_name && record->last_name)
			record->label = g_strdup_printf("%s %s",
				record->first_name, record->last_name);
		else if (record->first_name)
			record->label = g_strdup(record->first_name);
		else if (record->last_name)
			record->label = g_strdup(record->last_name);
		if (record->label)
			g_strstrip(record->label);
		if (record->nickname)
			g_strstrip(record->nickname);

		if (gender == 1)
			record->gender = GGP_PUBDIR_GENDER_FEMALE;
		else if (gender == 2)
			record->gender = GGP_PUBDIR_GENDER_MALE;
		else
			record->gender = GGP_PUBDIR_GENDER_UNSPECIFIED;

		if (city && city[0] != '\0')
			record->city = g_strdup(city);
		if (record->city)
			g_strstrip(record->city);
		if (!record->city) {
			g_free(record->city);
			record->city = NULL;
		}

		record->birth = ggp_date_from_iso8601(birth_s);
		/*TODO: calculate age from birth */

		if (purple_debug_is_verbose()) {
			purple_debug_misc("gg", "ggp_pubdir_got_data: [uin:%d] "
				"[label:%s] [nick:%s] [first name:%s] "
				"[last name:%s] [city:%s] [gender:%d] [age:%d] "
				"[birth:%lu]\n", record->uin, record->label,
				record->nickname, record->first_name,
				record->last_name, record->city, record->gender,
				record->age, record->birth);
		}

		g_free(city);

		xml = purple_xmlnode_get_next_twin(xml);
	}

	request->cb(gc, record_count, records, next_offset, request->user_data);

	ggp_pubdir_request_free(request);
	ggp_pubdir_record_free(records, record_count);
}
Exemplo n.º 18
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);
}
Exemplo n.º 19
0
static void
jabber_bosh_connection_session_created(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _bosh_conn)
{
	PurpleJabberBOSHConnection *bosh_conn = _bosh_conn;
	PurpleXmlNode *node, *features;
	const gchar *sid, *ver, *inactivity_str;
	int inactivity = 0;

	bosh_conn->sc_req = NULL;

	if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
		purple_debug_misc("jabber-bosh",
			"received (session creation): %s\n",
			purple_http_response_get_data(response, NULL));
	}

	node = jabber_bosh_connection_parse(bosh_conn, response);
	if (node == NULL)
		return;

	sid = purple_xmlnode_get_attrib(node, "sid");
	ver = purple_xmlnode_get_attrib(node, "ver");
	inactivity_str = purple_xmlnode_get_attrib(node, "inactivity");
	/* requests = purple_xmlnode_get_attrib(node, "requests"); */

	if (!sid) {
		purple_connection_error(bosh_conn->js->gc,
			PURPLE_CONNECTION_ERROR_OTHER_ERROR,
			_("No BOSH session ID given"));
		purple_xmlnode_free(node);
		return;
	}

	if (ver == NULL) {
		purple_debug_info("jabber-bosh", "Missing version in BOSH initiation\n");
	} else if (!jabber_bosh_version_check(ver, 1, 6)) {
		purple_debug_error("jabber-bosh",
			"Unsupported BOSH version: %s\n", ver);
		purple_connection_error(bosh_conn->js->gc,
			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
			_("Unsupported version of BOSH protocol"));
		purple_xmlnode_free(node);
		return;
	}

	purple_debug_misc("jabber-bosh", "Session created for %p\n", bosh_conn);

	bosh_conn->sid = g_strdup(sid);

	if (inactivity_str)
		inactivity = atoi(inactivity_str);
	if (inactivity < 0 || inactivity > 3600) {
		purple_debug_warning("jabber-bosh", "Ignoring invalid "
			"inactivity value: %s\n", inactivity_str);
		inactivity = 0;
	}
	if (inactivity > 0) {
		inactivity -= 5; /* rounding */
		if (inactivity <= 0)
			inactivity = 1;
		bosh_conn->js->max_inactivity = inactivity;
		if (bosh_conn->js->inactivity_timer == 0) {
			purple_debug_misc("jabber-bosh", "Starting inactivity "
				"timer for %d secs (compensating for "
				"rounding)\n", inactivity);
			jabber_stream_restart_inactivity_timer(bosh_conn->js);
		}
	}

	jabber_stream_set_state(bosh_conn->js, JABBER_STREAM_AUTHENTICATING);

	/* FIXME: Depending on receiving features might break with some hosts */
	features = purple_xmlnode_get_child(node, "features");
	jabber_stream_features_parse(bosh_conn->js, features);

	purple_xmlnode_free(node);

	jabber_bosh_connection_send(bosh_conn, NULL);
}