void
hangouts_oauth_with_code(HangoutsAccount *ha, const gchar *auth_code)
{
	PurpleHttpRequest *request;
	PurpleConnection *pc;
	GString *postdata;

	pc = ha->pc;

	postdata = g_string_new(NULL);
	g_string_append_printf(postdata, "client_id=%s&", purple_url_encode(GOOGLE_CLIENT_ID));
	g_string_append_printf(postdata, "client_secret=%s&", purple_url_encode(GOOGLE_CLIENT_SECRET));
	g_string_append_printf(postdata, "code=%s&", purple_url_encode(auth_code));
	g_string_append_printf(postdata, "redirect_uri=%s&", purple_url_encode(HANGOUTS_API_OAUTH2_REDIRECT_URI));
	g_string_append(postdata, "grant_type=authorization_code&");

	request = purple_http_request_new(HANGOUTS_API_OAUTH2_TOKEN_URL);
	purple_http_request_set_cookie_jar(request, ha->cookie_jar);
	purple_http_request_set_method(request, "POST");
	purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded");
	purple_http_request_set_contents(request, postdata->str, postdata->len);

	purple_http_request(pc, request, hangouts_oauth_with_code_cb, ha);
	purple_http_request_unref(request);
	
	g_string_free(postdata, TRUE);
}
Exemple #2
0
static void ggp_pubdir_search_got_token(PurpleConnection *gc,
	const gchar *token, gpointer _request)
{
	PurpleHttpRequest *req;
	ggp_pubdir_request *request = _request;
	gchar *query;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (!token) {
		request->cb(gc, -1, NULL, 0, request->user_data);
		ggp_pubdir_request_free(request);
		return;
	}

	purple_debug_misc("gg", "ggp_pubdir_search_got_token\n");

	query = ggp_pubdir_search_make_query(request->params.search_form);

	req = purple_http_request_new(NULL);
	purple_http_request_set_url_printf(req, "http://api.gadu-gadu.pl%s", query);
	purple_http_request_header_set(req, "Authorization", token);
	purple_http_request(gc, req, ggp_pubdir_got_data, request);
	purple_http_request_unref(req);

	g_free(query);
}
void
hangouts_oauth_refresh_token(HangoutsAccount *ha)
{
	PurpleHttpRequest *request;
	PurpleConnection *pc;
	GString *postdata;

	pc = ha->pc;

	postdata = g_string_new(NULL);
	g_string_append_printf(postdata, "client_id=%s&", purple_url_encode(GOOGLE_CLIENT_ID));
	g_string_append_printf(postdata, "client_secret=%s&", purple_url_encode(GOOGLE_CLIENT_SECRET));
	g_string_append_printf(postdata, "refresh_token=%s&", purple_url_encode(ha->refresh_token));
	g_string_append(postdata, "grant_type=refresh_token&");
	
	request = purple_http_request_new(HANGOUTS_API_OAUTH2_TOKEN_URL);
	purple_http_request_set_cookie_jar(request, ha->cookie_jar);
	purple_http_request_set_method(request, "POST");
	purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded");
	purple_http_request_set_contents(request, postdata->str, postdata->len);

	purple_http_request(pc, request, hangouts_oauth_refresh_token_cb, ha);
	purple_http_request_unref(request);
	
	purple_debug_info("hangouts", "Postdata: %s\n", postdata->str);
	
	g_string_free(postdata, TRUE);
}
Exemple #4
0
static void ggp_edisc_xfer_recv_ack(PurpleXfer *xfer, gboolean accept)
{
	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(edisc_xfer->gc);
	PurpleHttpRequest *req;

	g_return_if_fail(sdata != NULL);

	edisc_xfer->allowed = accept;

	req = purple_http_request_new(ggp_edisc_xfer_ticket_url(
		edisc_xfer->ticket_id));
	purple_http_request_set_method(req, "PUT");

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);
	purple_http_request_header_set(req, "X-gged-security-token",
		sdata->security_token);

	purple_http_request_header_set(req, "X-gged-ack-status",
		accept ? "allow" : "reject");

	edisc_xfer->hc = purple_http_request(edisc_xfer->gc, req,
		accept ? ggp_edisc_xfer_recv_ack_done : NULL, xfer);
	purple_http_request_unref(req);

	if (!accept) {
		edisc_xfer->hc = NULL;
		ggp_edisc_xfer_free(xfer);
	}
}
Exemple #5
0
static void ggp_edisc_xfer_recv_ticket_update_authenticated(
	PurpleConnection *gc, gboolean success, gpointer _ticket)
{
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
	PurpleHttpRequest *req;
	gchar *ticket = _ticket;

	g_return_if_fail(sdata != NULL);

	if (!success) {
		purple_debug_warning("gg",
			"ggp_edisc_xfer_recv_ticket_update_authenticated: "
			"update of ticket %s aborted due to authentication "
			"failure\n", ticket);
		g_free(ticket);
		return;
	}

	req = purple_http_request_new(ggp_edisc_xfer_ticket_url(ticket));
	g_free(ticket);

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	purple_http_request_header_set(req, "X-gged-security-token",
		sdata->security_token);

	purple_http_request(gc, req, ggp_edisc_xfer_recv_ticket_update_got,
		NULL);
	purple_http_request_unref(req);
}
static void yahoo_xfer_start(PurpleXfer *xfer)
{
	PurpleHttpRequest *req;
	struct yahoo_xfer_data *xd;

	xd = purple_xfer_get_protocol_data(xfer);

	req = yahoo_ft_new_req(xd);
	purple_http_request_set_timeout(req, -1);
	if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_RECEIVE) {
		purple_http_request_set_max_len(req, -1);
		purple_http_request_set_response_writer(req,
			yahoo_process_filetrans_15_writer, xfer);
		xd->hc = purple_http_request(xd->gc, req,
			yahoo_process_filetrans_15_downloaded, xfer);
	} else {
		purple_http_request_set_method(req, "POST");
		/* YHttpServer quirk: it sets content-length, but doesn't sends
		 * any data. */
		purple_http_request_set_max_len(req, 0);
		purple_http_request_set_contents_reader(req,
			yahoo_process_filetrans_15_reader,
			purple_xfer_get_size(xfer), xfer);
		xd->hc = purple_http_request(xd->gc, req,
			yahoo_process_filetrans_15_sent, xfer);
	}

	purple_http_conn_set_progress_watcher(xd->hc,
		yahoo_process_filetrans_15_watcher, xfer, -1);
	purple_http_request_unref(req);
}
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);
}
Exemple #8
0
static void ggp_ggdrive_auth(PurpleConnection *gc, ggp_ggdrive_auth_cb cb,
	gpointer user_data)
{
	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
	ggp_edisc_auth_data *auth;
	const gchar *imtoken;
	gchar *metadata;
	PurpleHttpRequest *req;

	g_return_if_fail(sdata != NULL);

	imtoken = ggp_get_imtoken(gc);
	if (!imtoken) {
		cb(gc, FALSE, user_data);
		return;
	}

	if (sdata->auth_done) {
		cb(gc, sdata->security_token != NULL, user_data);
		return;
	}

	auth = g_new0(ggp_edisc_auth_data, 1);
	auth->cb = cb;
	auth->user_data = user_data;
	sdata->auth_pending = g_list_prepend(sdata->auth_pending, auth);

	if (sdata->auth_request)
		return;

	purple_debug_info("gg", "ggp_ggdrive_auth(gc=%p)\n", gc);

	req = purple_http_request_new("https://drive.mpa.gg.pl/signin");
	purple_http_request_set_method(req, "PUT");

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	metadata = g_strdup_printf("{"
		"\"id\": \"%032x\", "
		"\"name\": \"%s\", "
		"\"os_version\": \"" GGP_EDISC_OS "\", "
		"\"client_version\": \"%s\", "
		"\"type\": \"" GGP_EDISC_TYPE "\"}",
		g_random_int_range(1, 1 << 16),
		purple_get_host_name(),
		ggp_libgaduw_version(gc));

	purple_http_request_header_set_printf(req, "Authorization",
		"IMToken %s", imtoken);
	purple_http_request_header_set_printf(req, "X-gged-user",
		"gg/pl:%u", accdata->session->uin);
	purple_http_request_header_set(req, "X-gged-client-metadata", metadata);
	g_free(metadata);

	sdata->auth_request = purple_http_request(gc, req,
		ggp_ggdrive_auth_done, NULL);
	purple_http_request_unref(req);
}
Exemple #9
0
static void
jabber_bosh_connection_send_now(PurpleJabberBOSHConnection *conn)
{
	PurpleHttpRequest *req;
	GString *data;

	g_return_if_fail(conn != NULL);

	if (conn->send_timer != 0) {
		purple_timeout_remove(conn->send_timer);
		conn->send_timer = 0;
	}

	if (conn->sid == NULL)
		return;

	data = g_string_new(NULL);

	/* missing parameters: route, from, ack */
	g_string_printf(data, "<body "
		"rid='%" G_GUINT64_FORMAT "' "
		"sid='%s' "
		"xmlns='" NS_BOSH "' "
		"xmlns:xmpp='" NS_XMPP_BOSH "' ",
		++conn->rid, conn->sid);

	if (conn->js->reinit && !conn->is_terminating) {
		g_string_append(data, "xmpp:restart='true'/>");
		conn->js->reinit = FALSE;
	} else {
		if (conn->is_terminating)
			g_string_append(data, "type='terminate' ");
		g_string_append_c(data, '>');
		g_string_append_len(data, conn->send_buff->str,
			conn->send_buff->len);
		g_string_append(data, "</body>");
		g_string_set_size(conn->send_buff, 0);
	}

	if (purple_debug_is_verbose() && purple_debug_is_unsafe())
		purple_debug_misc("jabber-bosh", "sending: %s\n", data->str);

	req = jabber_bosh_connection_http_request_new(conn, data);
	g_string_free(data, TRUE);

	if (conn->is_terminating) {
		purple_http_request(NULL, req, NULL, NULL);
		g_free(conn->sid);
		conn->sid = NULL;
	} else {
		purple_http_connection_set_add(conn->payload_reqs,
			purple_http_request(conn->js->gc, req,
				jabber_bosh_connection_recv, conn));
	}

	purple_http_request_unref(req);
}
Exemple #10
0
static void ggp_pubdir_set_info_got_token(PurpleConnection *gc,
	const gchar *token, gpointer _record)
{
	PurpleHttpRequest *req;
	ggp_pubdir_record *record = _record;
	gchar *request_data;
	gchar *name, *surname, *city;
	uin_t uin = record->uin;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (!token) {
		/* TODO: notify about failure */
		ggp_pubdir_record_free(record, 1);
		return;
	}

	name = g_uri_escape_string(record->first_name, NULL, FALSE);
	surname = g_uri_escape_string(record->last_name, NULL, FALSE);
	city = g_uri_escape_string(record->city, NULL, FALSE);

	request_data = g_strdup_printf(
		"name=%s&"
		"surname=%s&"
		"birth=%sT10:00:00%%2B00:00&"
		"birth_priv=2&"
		"gender=%d&"
		"gender_priv=2&"
		"city=%s&"
		"province=%d",
		name, surname,
		ggp_date_strftime("%Y-%m-%d", record->birth),
		record->gender,
		city,
		record->province);

	if (purple_debug_is_verbose() && purple_debug_is_unsafe()) {
		purple_debug_misc("gg", "ggp_pubdir_set_info_got_token: "
			"query [%s]\n", request_data);
	}

	req = purple_http_request_new(NULL);
	purple_http_request_set_method(req, "PUT");
	purple_http_request_set_url_printf(req,
		"http://api.gadu-gadu.pl/users/%u.xml", uin);
	purple_http_request_header_set(req, "Authorization", token);
	purple_http_request_header_set(req, "Content-Type",
		"application/x-www-form-urlencoded");
	purple_http_request_set_contents(req, request_data, -1);
	purple_http_request(gc, req, ggp_pubdir_set_info_got_response, NULL);
	purple_http_request_unref(req);

	g_free(request_data);
	ggp_pubdir_record_free(record, 1);
}
void
hangouts_auth_get_session_cookies(HangoutsAccount *ha)
{
	PurpleHttpRequest *request;

	request = purple_http_request_new("https://accounts.google.com/accounts/OAuthLogin"
	                                  "?source=pidgin&issueuberauth=1");
	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(ha->pc, request, hangouts_auth_get_session_cookies_uberauth_cb, ha);
	purple_http_request_unref(request);
}
Exemple #12
0
void
msn_request_user_display(MsnUser *user)
{
	PurpleAccount *account;
	MsnSession *session;
	MsnSlpLink *slplink;
	MsnObject *obj;
	const char *info;

	session = user->userlist->session;
	account = session->account;

	slplink = msn_session_get_slplink(session, user->passport);

	obj = msn_user_get_object(user);

	info = msn_object_get_sha1(obj);

	if (g_ascii_strcasecmp(user->passport,
						   purple_account_get_username(account)))
	{
		const char *url = msn_object_get_url1(obj);
		if (url) {
			PurpleHttpRequest *req;
			MsnFetchUserDisplayData *data = g_new0(MsnFetchUserDisplayData, 1);
			data->session = session;
			data->remote_user = user->passport;
			data->sha1 = info;

			req = purple_http_request_new(url);
			purple_http_request_set_max_len(req, 200*1024);
			purple_http_connection_set_add(session->http_reqs,
				purple_http_request(NULL, req,
					fetched_user_display, data));
			purple_http_request_unref(req);
		} else {
			msn_slplink_request_object(slplink, info, got_user_display,
			                           end_user_display, obj);
		}
	}
	else
		request_own_user_display(user);
}
Exemple #13
0
static void ggp_edisc_xfer_send_init_authenticated(PurpleConnection *gc,
	gboolean success, gpointer _xfer)
{
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
	PurpleHttpRequest *req;
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
	gchar *data;

	if (purple_xfer_is_cancelled(xfer))
		return;

	if (!success) {
		ggp_edisc_xfer_error(xfer, _("Authentication failed"));
		return;
	}

	g_return_if_fail(sdata != NULL);

	req = purple_http_request_new("https://drive.mpa.gg.pl/send_ticket");
	purple_http_request_set_method(req, "PUT");

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	purple_http_request_header_set(req, "X-gged-security-token",
		sdata->security_token);

	data = g_strdup_printf("{\"send_ticket\":{"
		"\"recipient\":\"%s\","
		"\"file_name\":\"%s\","
		"\"file_size\":\"%u\""
		"}}",
		purple_xfer_get_remote_user(xfer),
		edisc_xfer->filename,
		(int)purple_xfer_get_size(xfer));
	purple_http_request_set_contents(req, data, -1);
	g_free(data);

	edisc_xfer->hc = purple_http_request(gc, req,
		ggp_edisc_xfer_send_init_ticket_created, xfer);
	purple_http_request_unref(req);
}
Exemple #14
0
static void ggp_edisc_xfer_send_start(PurpleXfer *xfer)
{
	ggp_edisc_session_data *sdata;
	ggp_edisc_xfer *edisc_xfer;
	gchar *upload_url, *filename_e;
	PurpleHttpRequest *req;

	g_return_if_fail(xfer != NULL);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	g_return_if_fail(edisc_xfer != NULL);
	sdata = ggp_edisc_get_sdata(edisc_xfer->gc);
	g_return_if_fail(sdata != NULL);

	filename_e = purple_strreplace(edisc_xfer->filename, " ", "%20");
	upload_url = g_strdup_printf("https://drive.mpa.gg.pl/me/file/outbox/"
		"%s%%2C%s", edisc_xfer->ticket_id, filename_e);
	g_free(filename_e);
	req = purple_http_request_new(upload_url);
	g_free(upload_url);

	purple_http_request_set_method(req, "PUT");
	purple_http_request_set_timeout(req, -1);

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	purple_http_request_header_set(req, "X-gged-local-revision", "0");
	purple_http_request_header_set(req, "X-gged-security-token",
		sdata->security_token);
	purple_http_request_header_set(req, "X-gged-metadata",
		"{\"node_type\": \"file\"}");

	purple_http_request_set_contents_reader(req, ggp_edisc_xfer_send_reader,
		purple_xfer_get_size(xfer), xfer);

	edisc_xfer->hc = purple_http_request(edisc_xfer->gc, req,
		ggp_edisc_xfer_send_done, xfer);
	purple_http_request_unref(req);

	purple_http_conn_set_progress_watcher(edisc_xfer->hc,
		ggp_edisc_xfer_progress_watcher, xfer, 250000);
}
Exemple #15
0
static void
ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
                         gpointer _img)
{
    PurpleHttpRequest *req;
    PurpleImage *img = _img;
    ggp_avatar_own_data *own_data = ggp_avatar_get_avdata(gc)->own_data;
    gchar *img_data, *img_data_e, *request_data;
    PurpleAccount *account = purple_connection_get_account(gc);
    uin_t uin = ggp_str_to_uin(purple_account_get_username(account));

    if (img != own_data->img) {
        purple_debug_warning("gg", "ggp_avatar_own_got_token: "
                             "avatar was changed in meantime\n");
        return;
    }
    own_data->img = NULL;

    img_data = purple_base64_encode(purple_image_get_data(img),
                                    purple_image_get_size(img));
    img_data_e = g_uri_escape_string(img_data, NULL, FALSE);
    g_free(img_data);
    request_data = g_strdup_printf("uin=%d&photo=%s", uin, img_data_e);
    g_free(img_data_e);

    purple_debug_misc("gg", "ggp_avatar_own_got_token: "
                      "uploading new avatar...\n");

    req = purple_http_request_new("http://avatars.nowe.gg/upload");
    purple_http_request_set_max_len(req, GGP_AVATAR_RESPONSE_MAX);
    purple_http_request_set_method(req, "POST");
    purple_http_request_header_set(req, "Authorization", token);
    purple_http_request_header_set(req, "From", "avatars to avatars");
    purple_http_request_header_set(req, "Content-Type",
                                   "application/x-www-form-urlencoded");
    purple_http_request_set_contents(req, request_data, -1);
    purple_http_request(gc, req, ggp_avatar_own_sent, NULL);
    purple_http_request_unref(req);

    g_free(request_data);
}
Exemple #16
0
void
jabber_google_do_relay_request(JabberStream *js, GoogleSession *session,
	JabberGoogleRelayCallback cb)
{
	PurpleHttpRequest *req;
	JabberGoogleRelayCallbackData *data = g_new0(JabberGoogleRelayCallbackData, 1);

	data->session = session;
	data->cb = cb;
	purple_debug_info("jabber", "sending Google relay request\n");

	req = purple_http_request_new(NULL);
	purple_http_request_set_url_printf(req, "http://%s/create_session",
		js->google_relay_host);
	/* yes, the relay token is included twice as different request headers,
	   this is apparently needed to make Google's relay servers work... */
	purple_http_request_header_set(req, "X-Talk-Google-Relay-Auth", js->google_relay_token);
	purple_http_request_header_set(req, "X-Google-Relay-Auth", js->google_relay_token);
	purple_http_request(js->gc, req, jabber_google_relay_fetch_cb, data);
	purple_http_request_unref(req);
}
Exemple #17
0
static void ggp_pubdir_get_info_got_token(PurpleConnection *gc,
	const gchar *token, gpointer _request)
{
	PurpleHttpRequest *req;
	ggp_pubdir_request *request = _request;

	PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

	if (!token) {
		request->cb(gc, -1, NULL, 0, request->user_data);
		ggp_pubdir_request_free(request);
		return;
	}

	req = purple_http_request_new(NULL);
	purple_http_request_set_url_printf(req,
		"http://api.gadu-gadu.pl/users/%u",
		request->params.user_info.uin);
	purple_http_request_header_set(req, "Authorization", token);
	purple_http_request(gc, req, ggp_pubdir_got_data, request);
	purple_http_request_unref(req);
}
Exemple #18
0
static void
jabber_bosh_connection_session_create(PurpleJabberBOSHConnection *conn)
{
	PurpleHttpRequest *req;
	GString *data;

	g_return_if_fail(conn != NULL);

	if (conn->sid || conn->sc_req)
		return;

	purple_debug_misc("jabber-bosh", "Requesting Session Create for %p\n",
		conn);

	data = g_string_new(NULL);

	/* missing optional parameters: route, from, ack */
	g_string_printf(data, "<body content='text/xml; charset=utf-8' "
		"rid='%" G_GUINT64_FORMAT "' "
		"to='%s' "
		"xml:lang='en' "
		"ver='1.10' "
		"wait='%d' "
		"hold='1' "
		"xmlns='" NS_BOSH "' "
		"xmpp:version='1.0' "
		"xmlns:xmpp='urn:xmpp:xbosh' "
		"/>",
		++conn->rid, conn->js->user->domain, JABBER_BOSH_TIMEOUT);

	req = jabber_bosh_connection_http_request_new(conn, data);
	g_string_free(data, TRUE);

	conn->sc_req = purple_http_request(conn->js->gc, req,
		jabber_bosh_connection_session_created, conn);

	purple_http_request_unref(req);
}
Exemple #19
0
static void ggp_edisc_xfer_recv_start(PurpleXfer *xfer)
{
	ggp_edisc_session_data *sdata;
	ggp_edisc_xfer *edisc_xfer;
	gchar *upload_url;
	PurpleHttpRequest *req;

	g_return_if_fail(xfer != NULL);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	g_return_if_fail(edisc_xfer != NULL);
	sdata = ggp_edisc_get_sdata(edisc_xfer->gc);
	g_return_if_fail(sdata != NULL);

	upload_url = g_strdup_printf("https://drive.mpa.gg.pl/me/file/inbox/"
		"%s,%s?api_version=%s&security_token=%s",
		edisc_xfer->ticket_id, purple_url_encode(purple_xfer_get_filename(xfer)),
		GGP_EDISC_API, sdata->security_token);
	req = purple_http_request_new(upload_url);
	g_free(upload_url);

	purple_http_request_set_timeout(req, -1);

	ggp_edisc_set_defaults(req);
	purple_http_request_set_max_len(req, purple_xfer_get_size(xfer) + 1);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	purple_http_request_set_response_writer(req, ggp_edisc_xfer_recv_writer,
		xfer);

	edisc_xfer->hc = purple_http_request(edisc_xfer->gc, req,
		ggp_edisc_xfer_recv_done, xfer);
	purple_http_request_unref(req);

	purple_http_conn_set_progress_watcher(edisc_xfer->hc,
		ggp_edisc_xfer_progress_watcher, xfer, 250000);
}
void yahoo_process_filetrans_info_15(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	char *url = NULL;
	long val_249 = 0;
	long val_66 = 0;
	PurpleXfer *xfer;
	YahooData *yd;
	struct yahoo_xfer_data *xfer_data;
	char *xfer_peer_idstring = NULL;
	char *xfer_idstring_for_relay = NULL;
	GSList *l;
	struct yahoo_packet *pkt_to_send;

	yd = purple_connection_get_protocol_data(gc);

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;

		switch (pair->key) {
		case 4: /* from */
			break;
		case 5: /* to */
			break;
		case 265:
			if (g_utf8_validate(pair->value, -1, NULL)) {
				xfer_peer_idstring = pair->value;
			} else {
				purple_debug_warning("yahoo", "yahoo_process_filetrans_info_15 "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			break;
		case 27: /* filename */
			break;
		case 66:
			val_66 = strtol(pair->value, NULL, 10);
			break;
		case 249:
			val_249 = strtol(pair->value, NULL, 10);
			/* 249 has value 1 or 2 when doing p2p transfer and value 3 when relaying through yahoo server */
			break;
		case 250:
			if (g_utf8_validate(pair->value, -1, NULL)) {
				url = pair->value; /* TODO: rename to host? what about non-relay? */
			} else {
				purple_debug_warning("yahoo", "yahoo_process_filetrans_info_15 "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			break;
		case 251:
			if (g_utf8_validate(pair->value, -1, NULL)) {
				xfer_idstring_for_relay = pair->value;
			} else {
				purple_debug_warning("yahoo", "yahoo_process_filetrans_info_15 "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			break;
		}
	}

	if(!xfer_peer_idstring)
		return;

	xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring);

	if(!xfer) return;

	if(val_66==-1)
	{
		purple_xfer_cancel_remote(xfer);
		return;
	}

	xfer_data = purple_xfer_get_protocol_data(xfer);

	xfer_data->info_val_249 = val_249;
	xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay);
	if(val_249 == 1 || val_249 == 3) {
		PurpleHttpRequest *req;
		PurpleAccount *account;

		xfer_data->is_relay = (val_249 == 3);

		if (!xfer_data->is_relay) {
			purple_debug_error("yahoo", "Non-relay FT aren't tested yet.\n");
			purple_notify_error(gc, NULL, _("File Transfer Failed"),
				_("Unsupported method"),
				purple_request_cpar_from_connection(gc));
			purple_xfer_cancel_remote(xfer);
		}

		account = purple_connection_get_account(xfer_data->gc);

		xfer_data->url = yahoo_ft_url_gen(xfer, url);

		pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15,
			YAHOO_STATUS_AVAILABLE, yd->session_id);
		yahoo_packet_hash(pkt_to_send, "ssssis",
			1, purple_normalize(account, purple_account_get_username(account)),
			5, purple_xfer_get_remote_user(xfer),
			265, xfer_data->xfer_peer_idstring,
			27, purple_xfer_get_filename(xfer),
			249, xfer_data->info_val_249,
			251, xfer_data->xfer_idstring_for_relay);

		yahoo_packet_send_and_free(pkt_to_send, yd);

		req = yahoo_ft_new_req(xfer_data);
		purple_http_request_set_method(req, "HEAD");
		xfer_data->hc = purple_http_request(gc, req, yahoo_process_filetrans_info_15_got, xfer);
		purple_http_request_unref(req);
	}
	else if (val_249 == 2)
		purple_debug_error("yahoo", "p2p file transfers are not supported yet\n");
}
Exemple #21
0
/* return TRUE if avatar update was performed or there is no new requests,
   FALSE if we can request another one immediately */
static gboolean ggp_avatar_buddy_update_next(PurpleConnection *gc)
{
    PurpleHttpRequest *req;
    ggp_avatar_session_data *avdata = ggp_avatar_get_avdata(gc);
    GList *pending_update_it;
    ggp_avatar_buddy_update_req *pending_update;
    PurpleBuddy *buddy;
    PurpleAccount *account = purple_connection_get_account(gc);
    time_t old_timestamp;
    const char *old_timestamp_str;

    pending_update_it = g_list_first(avdata->pending_updates);
    if (pending_update_it == NULL)
        return TRUE;

    pending_update = pending_update_it->data;
    avdata->pending_updates = g_list_remove(avdata->pending_updates,
                                            pending_update);
    buddy = purple_blist_find_buddy(account, ggp_uin_to_str(pending_update->uin));

    if (!buddy) {
        if (ggp_str_to_uin(purple_account_get_username(account)) ==
                pending_update->uin)
        {
            purple_debug_misc("gg",
                              "ggp_avatar_buddy_update_next(%p): own "
                              "avatar update requested, but we don't have "
                              "ourselves on buddy list\n", gc);
        } else {
            purple_debug_warning("gg",
                                 "ggp_avatar_buddy_update_next(%p): "
                                 "%u update requested, but he's not on buddy "
                                 "list\n", gc, pending_update->uin);
        }
        return FALSE;
    }

    old_timestamp_str = purple_buddy_icons_get_checksum_for_user(buddy);
    old_timestamp = old_timestamp_str ? g_ascii_strtoull(
                        old_timestamp_str, NULL, 10) : 0;
    if (old_timestamp == pending_update->timestamp) {
        if (purple_debug_is_verbose()) {
            purple_debug_misc("gg",
                              "ggp_avatar_buddy_update_next(%p): "
                              "%u have up to date avatar with ts=%lu\n", gc,
                              pending_update->uin, pending_update->timestamp);
        }
        return FALSE;
    }
    if (old_timestamp > pending_update->timestamp) {
        purple_debug_warning("gg",
                             "ggp_avatar_buddy_update_next(%p): "
                             "saved timestamp for %u is newer than received "
                             "(%lu > %lu)\n", gc, pending_update->uin, old_timestamp,
                             pending_update->timestamp);
    }

    purple_debug_info("gg",
                      "ggp_avatar_buddy_update_next(%p): "
                      "updating %u with ts=%lu...\n", gc, pending_update->uin,
                      pending_update->timestamp);

    pending_update->gc = gc;
    avdata->current_update = pending_update;

    req = purple_http_request_new(NULL);
    purple_http_request_set_url_printf(req, GGP_AVATAR_BUDDY_URL,
                                       pending_update->uin);
    purple_http_request_header_set(req, "User-Agent", GGP_AVATAR_USERAGENT);
    purple_http_request_set_max_len(req, GGP_AVATAR_SIZE_MAX);
    pending_update->request = purple_http_request(gc, req,
                              ggp_avatar_buddy_update_received, pending_update);
    purple_http_request_unref(req);

    return TRUE;
}