Exemple #1
0
static PurpleUtilFetchUrlData *
np_util_post_url2(const gchar *url, const gchar *postdata,gchar *cookies,gboolean include_headers, PurpleUtilFetchUrlCallback callback, gpointer data)
{
	PurpleUtilFetchUrlData *urldata;
	gchar *host, *path, *request;
	int port;
    
    gchar *formatted_cookie;
    if (cookies && strlen(cookies)) {
        formatted_cookie = g_strdup_printf("Cookie: %s",cookies);
    } else {
        formatted_cookie = g_strdup_printf("");
    }
    
	purple_url_parse(url, &host, &port, &path, NULL, NULL);
	request = g_strdup_printf("POST /%s HTTP/1.1\r\n"
                              "Connection: close\r\n"
                              "Host: %s\r\n"
                              "Accept: */*\r\n"
                              "%s"
                              "Content-Type: application/x-www-form-urlencoded\r\n"
                              "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
                              path, host,formatted_cookie ,strlen(postdata), postdata);
	
	urldata = purple_util_fetch_url_request(url, TRUE, NULL, TRUE, request, include_headers, callback, data);
	
	g_free(formatted_cookie);
    g_free(host);
	g_free(path);
	g_free(request);
	
	return urldata;
}
void
google_translate(const gchar *plain_phrase, const gchar *from_lang, const gchar *to_lang, TranslateCallback callback, gpointer userdata)
{
	gchar *encoded_phrase;
	gchar *url;
	struct _TranslateStore *store;
	
	encoded_phrase = g_strdup(purple_url_encode(plain_phrase));
	
	if (!from_lang || g_str_equal(from_lang, "auto"))
		from_lang = "";
	
	url = g_strdup_printf(GOOGLE_TRANSLATE_URL, from_lang, to_lang, encoded_phrase);
	
	store = g_new0(struct _TranslateStore, 1);
	store->original_phrase = g_strdup(plain_phrase);
	store->callback = callback;
	store->userdata = userdata;
	
	purple_debug_info("translate", "Fetching %s\n", url);
	
	purple_util_fetch_url_request(url, TRUE, "libpurple", FALSE, NULL, FALSE, google_translate_cb, store);
	
	g_free(encoded_phrase);
	g_free(url);
}
void
get_lastfm_ws_info(struct TrackInfo* ti)
{
  const char *user = purple_prefs_get_string(PREF_LASTFM);
  if (!strcmp(user,""))
    {
      trace("No last.fm user name");
      return;
    }
  trace("Got user name: %s",user);

  // Check if it's time to check again
  static int count = 0;
  if (count < 0)
    {
      trace("last.fm ratelimit %d",count);
    }
  else
    {
      count = count - purple_prefs_get_int(PREF_LASTFM_INTERVAL);

      char *url = g_strdup_printf(LASTFM_WS_URL, user, LASTFM_WS_API_KEY);
      trace("URL is %s", url);

      purple_util_fetch_url_request(url, TRUE, USER_AGENT, FALSE, NULL, FALSE, lastfm_ws_fetch, NULL);

      g_free(url);
    }
  count = count + INTERVAL_SECONDS;

  *ti = lastfm_ws_ti;
}
Exemple #4
0
void
jabber_google_do_relay_request(JabberStream *js, GoogleSession *session,
	JabberGoogleRelayCallback cb)
{
	PurpleUtilFetchUrlData *url_data = NULL;
	gchar *url = g_strdup_printf("http://%s", 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... */
	gchar *request =
		g_strdup_printf("GET /create_session HTTP/1.0\r\n"
			            "Host: %s\r\n"
						"X-Talk-Google-Relay-Auth: %s\r\n"
						"X-Google-Relay-Auth: %s\r\n\r\n",
			js->google_relay_host, js->google_relay_token, js->google_relay_token);
	JabberGoogleRelayCallbackData *data = g_new0(JabberGoogleRelayCallbackData, 1);

	data->session = session;
	data->cb = cb;
	purple_debug_info("jabber",
		"sending Google relay request %s to %s\n", request, url);
	url_data =
		purple_util_fetch_url_request(url, FALSE, NULL, FALSE, request, FALSE,
			jabber_google_relay_fetch_cb, data);
	if (url_data) {
		js->google_relay_requests =
			g_list_prepend(js->google_relay_requests, url_data);
	} else {
		purple_debug_error("jabber", "unable to create Google relay request\n");
		jabber_google_relay_fetch_cb(NULL, data, NULL, 0, NULL);
	}
	g_free(url);
	g_free(request);
}
void
bing_translate(const gchar *plain_phrase, const gchar *from_lang, const gchar *to_lang, TranslateCallback callback, gpointer userdata)
{
	gchar *encoded_phrase;
	gchar *url;
	struct _TranslateStore *store;
	PurpleUtilFetchUrlCallback urlcallback;
	
	encoded_phrase = g_strescape(purple_url_encode(plain_phrase), NULL);
	
	store = g_new0(struct _TranslateStore, 1);
	store->original_phrase = g_strdup(plain_phrase);
	store->callback = callback;
	store->userdata = userdata;
	
	if (!from_lang || !(*from_lang) || g_str_equal(from_lang, "auto"))
	{
		url = g_strdup_printf("http://api.microsofttranslator.com/V2/Ajax.svc/Detect?appId=" BING_APPID "&text=%%22%s%%22",
						encoded_phrase);
		store->detected_language = g_strdup(to_lang);
		urlcallback = bing_translate_autodetect_cb;
	} else {
		url = g_strdup_printf("http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=" BING_APPID "&text=%%22%s%%22&from=%s&to=%s",
						encoded_phrase, from_lang, to_lang);
		urlcallback = bing_translate_cb;
	}
	
	purple_debug_info("translate", "Fetching %s\n", url);
	
	purple_util_fetch_url_request(url, TRUE, "libpurple", FALSE, NULL, FALSE, urlcallback, store);
	
	g_free(encoded_phrase);
	g_free(url);
}
Exemple #6
0
PurpleFbApiCall *purple_fbapi_request_vargs(PurpleAccount *account, PurpleFbApiCallback callback, gpointer user_data, GDestroyNotify user_data_destroy_func, const char *method, va_list args)
{
	GString *body;
	PurpleFbApiCall *apicall;

	body = purple_fbapi_construct_request_vargs(account, method, args);

	/* Construct an HTTP POST request */
	apicall = g_new(PurpleFbApiCall, 1);
	apicall->callback = callback;
	apicall->user_data = user_data;
	apicall->user_data_destroy_func = user_data_destroy_func;
	apicall->attempt_number = 1;

	apicall->request = g_strdup_printf("POST /restserver.php HTTP/1.0\r\n"
			"Connection: close\r\n"
			"Accept: */*\r\n"
			"Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"
			"Content-Length: %zu\r\n\r\n%s", (size_t)body->len, body->str);
	g_string_free(body, TRUE);

	apicall->url_data = purple_util_fetch_url_request(API_URL,
			TRUE, NULL, FALSE, apicall->request, FALSE,
			purple_fbapi_request_fetch_cb, apicall);

	apicalls = g_slist_prepend(apicalls, apicall);

	return apicall;
}
void
google_translate(const gchar *plain_phrase, const gchar *from_lang, const gchar *to_lang, TranslateCallback callback, gpointer userdata)
{
	gchar *encoded_phrase;
	gchar *url;
	struct _TranslateStore *store;
	
	encoded_phrase = g_strdup(purple_url_encode(plain_phrase));
	
	if (!from_lang || g_str_equal(from_lang, "auto"))
		from_lang = "";
	
	url = g_strdup_printf("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=%s%%7C%s&q=%s",
							from_lang, to_lang, encoded_phrase);
	
	store = g_new0(struct _TranslateStore, 1);
	store->original_phrase = g_strdup(plain_phrase);
	store->callback = callback;
	store->userdata = userdata;
	
	purple_debug_info("translate", "Fetching %s\n", url);
	
	purple_util_fetch_url_request(url, TRUE, "libpurple", FALSE, NULL, FALSE, google_translate_cb, store);
	
	g_free(encoded_phrase);
	g_free(url);
}
void
bing_translate(const gchar *plain_phrase, const gchar *from_lang, const gchar *to_lang, TranslateCallback callback, gpointer userdata)
{
	gchar *encoded_phrase;
	gchar *url;
	struct _TranslateStore *store;
	PurpleUtilFetchUrlCallback urlcallback;
	
	encoded_phrase = g_strescape(purple_url_encode(plain_phrase), NULL);
	
	store = g_new0(struct _TranslateStore, 1);
	store->original_phrase = g_strdup(plain_phrase);
	store->callback = callback;
	store->userdata = userdata;
	
	if (!from_lang || !(*from_lang) || g_str_equal(from_lang, "auto"))
	{
		url = g_strdup_printf(BING_DETECT_URL, encoded_phrase);
		store->detected_language = g_strdup(to_lang);
		urlcallback = bing_translate_autodetect_cb;
	} else {
		url = g_strdup_printf(BING_TRANSLATE_URL, encoded_phrase, from_lang, to_lang);
		urlcallback = bing_translate_cb;
	}
	
	purple_debug_info("translate", "Fetching %s\n", url);
	
	purple_util_fetch_url_request(url, TRUE, "libpurple", FALSE, NULL, FALSE, urlcallback, store);
	
	g_free(encoded_phrase);
	g_free(url);
}
Exemple #9
0
void qq_process_auth_token( PurpleConnection *gc, guint8 *data, gint data_len, guint32 dataptr, qq_buddy_opt_req *opt_req )
{
	gint bytes;
	guint8 cmd, reply;
	guint16 sub_cmd;
	guint8 *code = NULL;
	guint16 code_len = 0;

	g_return_if_fail(data != NULL && data_len != 0);
	g_return_if_fail(opt_req && opt_req->uid != 0);

	//qq_show_packet("qq_process_auth_token", data, data_len);
	bytes = 0;
	bytes += qq_get8(&cmd, data + bytes);
	bytes += qq_get16(&sub_cmd, data + bytes);
	bytes += qq_get8(&reply, data + bytes);

	/* if reply == 0x01, we need request captcha */
	if (reply)
	{
		/* if this is end, means you have submitted the wrong captcha  */
		if (bytes>=data_len)
		{
			qq_request_auth_token(gc, QQ_AUTH_INFO_BUDDY, QQ_AUTH_INFO_ADD_BUDDY, 0, opt_req);
			return;
		}

		bytes += qq_get_vstr(&code, NULL, sizeof(guint16), data + bytes);
		purple_util_fetch_url_request(
			(gchar *)code, TRUE, NULL, TRUE,  NULL, TRUE, auth_token_captcha_input_cb, opt_req);
		return;
	}
	
	bytes += qq_get16(&opt_req->auth_len, data + bytes);
	g_return_if_fail(opt_req->auth_len > 0);
	g_return_if_fail(bytes + opt_req->auth_len <= data_len);
	opt_req->auth = g_new0(guint8, opt_req->auth_len);
	bytes += qq_getdata(opt_req->auth, opt_req->auth_len, data + bytes);

	if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_REMOVE_BUDDY) {
		qq_request_remove_buddy(gc, opt_req);
		return;
	}
	if (sub_cmd == QQ_AUTH_INFO_ADD_BUDDY) {
		if (opt_req->auth_type == 0x01)
			add_buddy_authorize_input(gc, opt_req);
		else if (opt_req->auth_type == 0x00)
			qq_request_search_uid(gc, opt_req);
		return;
	}
	if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_UPDATE_BUDDY_INFO) {
		request_change_info(gc, (guint8 *)dataptr, code, code_len);
		return;
	}
	purple_debug_info("QQ", "Got auth info cmd 0x%x, sub 0x%x, reply 0x%x\n",
			cmd, sub_cmd, reply);
}
void
skypeweb_begin_oauth_login(SkypeWebAccount *sa)
{
    const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST "/login/oauth/microsoft?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com";

    purple_util_fetch_url_request(sa->account, login_url, TRUE, NULL, FALSE, NULL, TRUE, 524288, skypeweb_login_got_ppft, sa);

    purple_connection_set_state(sa->pc, PURPLE_CONNECTION_CONNECTING);
    purple_connection_update_progress(sa->pc, _("Connecting"), 1, 4);
}
Exemple #11
0
FListWebRequestData* flist_web_request(const gchar* url, GHashTable* args, gboolean post, FListWebCallback cb, gpointer data) {
    gchar *http = http_request(url, FALSE, post, USER_AGENT, args, NULL);
    FListWebRequestData *ret = g_new0(FListWebRequestData, 1);
    PurpleUtilFetchUrlData *url_data = purple_util_fetch_url_request(url, FALSE, USER_AGENT, FALSE, http, FALSE, flist_web_request_cb, ret);
    ret->url_data = url_data;
    ret->cb = cb;
    ret->user_data = data;
    ret->timer = purple_timeout_add_seconds(FLIST_WEB_REQUEST_TIMEOUT, (GSourceFunc) flist_web_request_timeout, ret);
    g_hash_table_insert(requests, ret, ret);
    return ret;
}
Exemple #12
0
/**
 * This function sends a request to
 * https://api.screenname.aol.com/auth/clientLogin with the user's
 * username and password and receives the user's session key, which is
 * used to request a connection to the BOSS server.
 */
void send_client_login(OscarData *od, const char *username)
{
	PurpleConnection *gc;
	GString *request, *body;
	const char *tmp;
	char *password;
	int password_len;

	gc = od->gc;

	/*
	 * We truncate ICQ passwords to 8 characters.  There is probably a
	 * limit for AIM passwords, too, but we really only need to do
	 * this for ICQ because older ICQ clients let you enter a password
	 * as long as you wanted and then they truncated it silently.
	 *
	 * And we can truncate based on the number of bytes and not the
	 * number of characters because passwords for AIM and ICQ are
	 * supposed to be plain ASCII (I don't know if this has always been
	 * the case, though).
	 */
	tmp = purple_connection_get_password(gc);
	password_len = strlen(tmp);
	password = g_strndup(tmp, od->icq ? MIN(password_len, MAXICQPASSLEN) : password_len);

	/* Construct the body of the HTTP POST request */
	body = g_string_new("");
	g_string_append_printf(body, "devId=%s", get_client_key(od));
	g_string_append_printf(body, "&f=xml");
	g_string_append_printf(body, "&pwd=%s", purple_url_encode(password));
	g_string_append_printf(body, "&s=%s", purple_url_encode(username));
	g_free(password);

	/* Construct an HTTP POST request */
	request = g_string_new("POST /auth/clientLogin HTTP/1.0\r\n"
			"Connection: close\r\n"
			"Accept: */*\r\n");

	/* Tack on the body */
	g_string_append_printf(request, "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n");
	g_string_append_printf(request, "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n", body->len);
	g_string_append_len(request, body->str, body->len);
	g_string_free(body, TRUE);

	/* Send the POST request  */
	od->url_data = purple_util_fetch_url_request(URL_CLIENT_LOGIN,
			TRUE, NULL, FALSE, request->str, FALSE,
			client_login_cb, od);
	g_string_free(request, TRUE);
}
PurpleUtilFetchUrlData *
skypeweb_fetch_url_request(SkypeWebAccount *sa,
		const char *url, gboolean full, const char *user_agent, gboolean http11,
		const char *request, gboolean include_headers, gssize max_len,
		PurpleUtilFetchUrlCallback callback, void *user_data)
{
	PurpleUtilFetchUrlData *url_data;

	url_data = purple_util_fetch_url_request(sa->account, url, full, user_agent, http11, request, include_headers, max_len, callback, user_data);

	if (url_data != NULL)
		sa->url_datas = g_slist_prepend(sa->url_datas, url_data);

	return url_data;
}
Exemple #14
0
static void flist_fetch_icon_real(FListAccount *fla, FListFetchIcon *fli) {
    gchar *character_lower;
    gchar *url;
    
    purple_debug_info(FLIST_DEBUG, "Fetching character icon... (Character: %s) (Convo: %s) (Secure: %s)\n", 
        fli->character, fli->convo ? fli->convo : "none", fla->secure ? "yes" : "no");

    character_lower = g_utf8_strdown(fli->character, -1);
    url = g_strdup_printf("%sstatic.f-list.net/images/avatar/%s.png", fla->secure ? "https://" : "http://", purple_url_encode(character_lower));
    fli->url_data = purple_util_fetch_url_request(url, TRUE, USER_AGENT, TRUE, NULL, FALSE, flist_fetch_icon_cb, fli);
    fla->icon_requests = g_slist_prepend(fla->icon_requests, fli);
    
    g_free(url);
    g_free(character_lower);
}
static void
skypeweb_init_vm_download(PurpleXfer *xfer)
{
	JsonObject *file = xfer->data;
	gint64 fileSize;
	const gchar *url;

	fileSize = json_object_get_int_member(file, "fileSize");
	url = json_object_get_string_member(file, "url");
	
	purple_xfer_set_completed(xfer, FALSE);
	purple_util_fetch_url_request(xfer->account, url, TRUE, NULL, FALSE, NULL, FALSE, fileSize, skypeweb_got_vm_file, xfer);
	
	json_object_unref(file);
}
Exemple #16
0
PurpleUtilFetchUrlData *flist_login_ticket_request(PurpleConnection *pc, const gchar *user_agent, const gchar *username, const gchar *password, PurpleUtilFetchUrlCallback callback) {
    const gchar *url_pattern = "http://www.f-list.net/json/getApiTicket.php";
    PurpleUtilFetchUrlData *ret;
    GString *url_str = g_string_new(NULL);
    gchar *url;
    
    g_string_append(url_str, url_pattern);
    g_string_append_printf(url_str, "?account=%s", purple_url_encode(username));
    g_string_append_printf(url_str, "&password=%s", purple_url_encode(password));
    g_string_append_printf(url_str, "&secure=%s", "no");
    url = g_string_free(url_str, FALSE);
    ret = purple_util_fetch_url_request(url, FALSE, user_agent, TRUE, NULL, FALSE, callback, pc);
    g_free(url);
    return ret;
}
Exemple #17
0
void twitter_send_request(PurpleAccount *account, gboolean post,
		const char *url, const char *query_string, 
		TwitterSendRequestSuccessFunc success_callback, TwitterSendRequestErrorFunc error_callback,
		gpointer data)
{
	gchar *request;
	const char *pass = purple_connection_get_password(purple_account_get_connection(account));
	const char *sn = purple_account_get_username(account);
	char *auth_text = g_strdup_printf("%s:%s", sn, pass);
	char *auth_text_b64 = purple_base64_encode((guchar *) auth_text, strlen(auth_text));
	gboolean use_https = purple_account_get_bool(account, "use_https", FALSE) && purple_ssl_is_supported();
	char *host = "twitter.com";
	TwitterSendRequestData *request_data = g_new0(TwitterSendRequestData, 1);
	char *full_url = g_strdup_printf("%s://%s%s",
			use_https ? "https" : "http",
			host,
			url);
	request_data->account = account;
	request_data->user_data = data;
	request_data->success_func = success_callback;
	request_data->error_func = error_callback;

	g_free(auth_text);

	request = g_strdup_printf(
			"%s %s%s%s HTTP/1.0\r\n"
			"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n"
			"Host: %s\r\n"
			"Authorization: Basic %s\r\n"
			"Content-Length: %d\r\n\r\n"
			"%s",
			post ? "POST" : "GET",
			full_url,
			(!post && query_string ? "?" : ""), (!post && query_string ? query_string : ""),
			host,
			auth_text_b64,
			query_string  && post ? strlen(query_string) : 0,
			query_string && post ? query_string : "");

	g_free(auth_text_b64);
	purple_util_fetch_url_request(full_url, TRUE,
			"Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE,
			twitter_send_request_cb, request_data);
	g_free(full_url);
	g_free(request);
}
Exemple #18
0
PurpleUtilFetchUrlData *flist_login_fls_request(PurpleConnection *pc, const gchar *user_agent, 
        const gchar *username, const gchar *password, PurpleUtilFetchUrlCallback callback) {
    gchar *url = "http://www.f-list.net/action/script_login.php";
    PurpleUtilFetchUrlData *ret;
    GHashTable *post = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
    gchar *request;
    
    g_hash_table_insert(post, (gpointer) "username", (gpointer) username);
    g_hash_table_insert(post, (gpointer) "password", (gpointer) password);
    request = http_request(url, FALSE, TRUE, user_agent, post, NULL);
    ret = purple_util_fetch_url_request(url, FALSE, user_agent, FALSE, request, TRUE, callback, pc);
    
    g_free(request);
    g_hash_table_destroy(post);
    
    return ret;
}
Exemple #19
0
void mb_conn_process_request(MbConnData * data)
{
	gchar * url;

	purple_debug_info(MB_NET, "NEW mb_conn_process_request, conn_data = %p\n", data);

	purple_debug_info(MB_NET, "connecting to %s on port %hd\n", data->host, data->port);

	if(data->prepare_handler) {
		data->prepare_handler(data, data->prepare_handler_data, NULL);
	}
	url = mb_conn_url_unparse(data);

	// we manage user_agent by ourself so ignore this completely
	mb_http_data_prepare_write(data->request);
	data->fetch_url_data = purple_util_fetch_url_request(url, TRUE, "", TRUE, data->request->packet, TRUE, mb_conn_fetch_url_cb, (gpointer)data);
	g_free(url);
}
Exemple #20
0
/*------------------------------------------------------------------------
 * Send a request to the MXit WAP site to download the specified emoticon.
 *
 *  @param mx				The Markup message object
 *  @param id				The ID for the emoticon
 */
static void emoticon_request( struct RXMsgData* mx, const char* id )
{
	PurpleUtilFetchUrlData*	url_data;
	const char*				wapserver;
	char*					url;

	purple_debug_info( MXIT_PLUGIN_ID, "sending request for emoticon '%s'\n", id );

	wapserver = purple_account_get_string( mx->session->acc, MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE );

	/* reference: "libpurple/util.h" */
	url = g_strdup_printf( "%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver, MXIT_EMOTICON_SIZE, id, time( NULL ) );
	url_data = purple_util_fetch_url_request( url, TRUE, NULL, TRUE, NULL, FALSE, emoticon_returned, mx );
	if ( url_data )
		mx->session->async_calls = g_slist_prepend( mx->session->async_calls, url_data );

	g_free( url );
}
static void
skypeweb_login_got_t(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
    SkypeWebAccount *sa = user_data;
    const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com";
    gchar *request;
    GString *postdata;
    gchar *magic_t_value; // T is for tasty

    // <input type="hidden" name="t" id="t" value="...">
    magic_t_value = skypeweb_string_get_chunk(url_text, len, "=\"t\" value=\"", "\"");
    if (!magic_t_value) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting Magic T value"));
        return;
    }

    // postdata: t=...&oauthPartner=999&client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com
    postdata = g_string_new("");
    g_string_append_printf(postdata, "t=%s&", purple_url_encode(magic_t_value));
    g_string_append(postdata, "oauthPartner=999&");
    g_string_append(postdata, "client_id=578134&");
    g_string_append(postdata, "redirect_uri=https%3A%2F%2Fweb.skype.com");

    // post the t to https://login.skype.com/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com
    request = g_strdup_printf("POST /login/oauth?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n"
                              "Connection: close\r\n"
                              "Accept: */*\r\n"
                              "BehaviorOverride: redirectAs404\r\n"
                              "Host: " SKYPEWEB_LOGIN_HOST "\r\n"
                              "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"
                              "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
                              strlen(postdata->str), postdata->str);

    purple_util_fetch_url_request(sa->account, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa);

    g_string_free(postdata, TRUE);
    g_free(request);
    g_free(magic_t_value);

    purple_connection_update_progress(sa->pc, _("Verifying"), 3, 4);
}
void
skypeweb_download_uri_to_conv(SkypeWebAccount *sa, const gchar *uri, PurpleConversation *conv)
{
	gchar *headers;
	gchar *path, *host;
	
	purple_url_parse(uri, &host, NULL, &path, NULL, NULL);
	headers = g_strdup_printf("GET /%s HTTP/1.0\r\n"
			"Connection: close\r\n"
			"Accept: image/*\r\n"
			"Cookie: skypetoken_asm=%s\r\n"
			"Host: %s\r\n"
			"\r\n\r\n",
			path, sa->skype_token, host);
	
	purple_util_fetch_url_request(sa->account, uri, TRUE, NULL, FALSE, headers, FALSE, -1, skypeweb_got_imagemessage, conv);
	
	g_free(headers);
	g_free(host);
	g_free(path);
}
static void
skypeweb_get_icon_now(PurpleBuddy *buddy)
{
	SkypeWebBuddy *sbuddy;
	gchar *url;
	
	purple_debug_info("skypeweb", "getting new buddy icon for %s\n", purple_buddy_get_name(buddy));
	
	sbuddy = purple_buddy_get_protocol_data(buddy);
	if (sbuddy != NULL && sbuddy->avatar_url && sbuddy->avatar_url[0]) {
		url = g_strdup(sbuddy->avatar_url);
	} else {
		url = g_strdup_printf("https://api.skype.com/users/%s/profile/avatar", purple_url_encode(purple_buddy_get_name(buddy)));
	}
	
	purple_util_fetch_url_request(purple_buddy_get_account(buddy), url, TRUE, NULL, FALSE, NULL, FALSE, 524288, skypeweb_get_icon_cb, buddy);

	g_free(url);

	active_icon_downloads++;
}
void
bing_translate_autodetect_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
	struct _TranslateStore *store = user_data;
	gchar *from_lang = NULL;
	gchar *to_lang;
	gchar *encoded_phrase;
	gchar *url;
	
	purple_debug_info("translate", "Got response: %s\n", url_text);
	
	if (!url_text || !len || g_strstr_len(url_text, len, "\"\""))
	{
		// Unknown language
		store->callback(store->original_phrase, store->original_phrase, NULL, store->userdata);
		g_free(store->detected_language);
		g_free(store->original_phrase);
		g_free(store);
		
	} else {
	
		from_lang = strchr(url_text, '"') + 1; 
		from_lang = g_strndup(from_lang, len - (from_lang - url_text) - 1);
		
		to_lang = store->detected_language;
		store->detected_language = from_lang;
		
		// Same as bing_translate() but we've already made the _TranslateStore
		encoded_phrase = g_strescape(purple_url_encode(store->original_phrase), NULL);
		url = g_strdup_printf("http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=" BING_APPID "&text=%%22%s%%22&from=%s&to=%s",
						encoded_phrase, from_lang, to_lang);
		purple_debug_info("translate", "Fetching %s\n", url);
		
		purple_util_fetch_url_request(url, TRUE, "libpurple", FALSE, NULL, FALSE, bing_translate_cb, store);
		
		g_free(to_lang);
		g_free(encoded_phrase);
		g_free(url);
	}
}
static void
skypeweb_login_got_pie(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
    SkypeWebAccount *sa = user_data;
    PurpleAccount *account = sa->account;
    gchar *pie;
    gchar *etm;
    const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com";
    GString *postdata;
    gchar *request;
    struct timeval tv;
    struct timezone tz;
    guint tzhours, tzminutes;

    if (error_message && *error_message) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message);
        return;
    }

    gettimeofday(&tv, &tz);
    (void) tv;
    tzminutes = tz.tz_minuteswest;
    if (tzminutes < 0) tzminutes = -tzminutes;
    tzhours = tzminutes / 60;
    tzminutes -= tzhours * 60;

    pie = skypeweb_string_get_chunk(url_text, len, "=\"pie\" value=\"", "\"");
    if (!pie) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PIE value"));
        return;
    }

    etm = skypeweb_string_get_chunk(url_text, len, "=\"etm\" value=\"", "\"");
    if (!etm) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting ETM value"));
        return;
    }


    postdata = g_string_new("");
    g_string_append_printf(postdata, "username=%s&", purple_url_encode(purple_account_get_username(account)));
    g_string_append_printf(postdata, "password=%s&", purple_url_encode(purple_account_get_password(account)));
    g_string_append_printf(postdata, "timezone_field=%c|%d|%d&", (tz.tz_minuteswest < 0 ? '+' : '-'), tzhours, tzminutes);
    g_string_append_printf(postdata, "pie=%s&", purple_url_encode(pie));
    g_string_append_printf(postdata, "etm=%s&", purple_url_encode(etm));
    g_string_append_printf(postdata, "js_time=%" G_GINT64_FORMAT "&", skypeweb_get_js_time());
    g_string_append(postdata, "client_id=578134&");
    g_string_append(postdata, "redirect_uri=https://web.skype.com/");

    request = g_strdup_printf("POST /login?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n"
                              "Connection: close\r\n"
                              "Accept: */*\r\n"
                              "BehaviorOverride: redirectAs404\r\n"
                              "Host: " SKYPEWEB_LOGIN_HOST "\r\n"
                              "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"
                              "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
                              strlen(postdata->str), postdata->str);

    purple_util_fetch_url_request(sa->account, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa);

    g_string_free(postdata, TRUE);
    g_free(request);

    g_free(pie);
    g_free(etm);

    purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4);
}
static void
skypeweb_login_got_ppft(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
    SkypeWebAccount *sa = user_data;
    const gchar *live_login_url = "https://login.live.com";// "/ppsecure/post.srf?wa=wsignin1.0&wreply=https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com";
    gchar *msprequ_cookie;
    gchar *mspok_cookie;
    gchar *cktst_cookie;
    gchar *ppft;
    GString *postdata;
    gchar *request;

    // grab PPFT and cookies (MSPRequ, MSPOK)
    msprequ_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPRequ=", ";");
    if (!msprequ_cookie) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting MSPRequ cookie"));
        return;
    }
    mspok_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPOK=", ";");
    if (!mspok_cookie) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting MSPOK cookie"));
        return;
    }
    // <input type="hidden" name="PPFT" id="i0327" value="..."/>
    ppft = skypeweb_string_get_chunk(url_text, len, "name=\"PPFT\" id=\"i0327\" value=\"", "\"");
    if (!ppft) {
        purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PPFT value"));
        return;
    }
    // CkTst=G + timestamp   e.g. G1422309314913
    cktst_cookie = g_strdup_printf("G%" G_GINT64_FORMAT, skypeweb_get_js_time());

    // postdata: login={username}&passwd={password}&PPFT={ppft value}
    postdata = g_string_new("");
    g_string_append_printf(postdata, "login=%s&", purple_url_encode(purple_account_get_username(sa->account)));
    g_string_append_printf(postdata, "passwd=%s&", purple_url_encode(purple_account_get_password(sa->account)));
    g_string_append_printf(postdata, "PPFT=%s&", purple_url_encode(ppft));

    // POST to https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&wreply=https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com

    request = g_strdup_printf("POST /ppsecure/post.srf?wa=wsignin1.0&wp=MBI_SSL&wreply=https%%3A%%2F%%2Fsecure.skype.com%%2Flogin%%2Foauth%%2Fproxy%%3Fclient_id%%3D578134%%26redirect_uri%%3Dhttps%%253A%%252F%%252Fweb.skype.com HTTP/1.0\r\n"
                              "Connection: close\r\n"
                              "Accept: */*\r\n"
                              "Host: login.live.com\r\n"
                              "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"
                              "Cookie: MSPRequ=%s;MSPOK=%s;CkTst=%s;\r\n"
                              "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
                              msprequ_cookie, mspok_cookie, cktst_cookie, strlen(postdata->str), postdata->str);

    purple_util_fetch_url_request(sa->account, live_login_url, TRUE, NULL, FALSE, request, FALSE, 524288, skypeweb_login_got_t, sa);

    g_string_free(postdata, TRUE);
    g_free(request);

    g_free(msprequ_cookie);
    g_free(mspok_cookie);
    g_free(cktst_cookie);
    g_free(ppft);

    purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4);
}
Exemple #27
0
static void purple_fbapi_request_fetch_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
	PurpleFbApiCall *apicall;
	xmlnode *response;
	PurpleConnectionError error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
	char *error_message2 = NULL;

	apicall = user_data;

	if (error_message != NULL) {
		/* Request failed */

		if (apicall->attempt_number < MAX_CONNECTION_ATTEMPTS) {
			/* Retry! */
			apicall->url_data = purple_util_fetch_url_request(API_URL,
					TRUE, NULL, FALSE, apicall->request, FALSE,
					purple_fbapi_request_fetch_cb, apicall);
			apicall->attempt_number++;
			return;
		}

		response = NULL;
		error_message2 = g_strdup(error_message);
		error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
	} else if (url_text != NULL && len > 0) {
		/* Parse the response as XML */
		response = xmlnode_from_str(url_text, len);

		if (response == NULL)
		{
			gchar *salvaged;

			if (g_utf8_validate(url_text, len, NULL)) {
				salvaged = g_strdup(url_text);
			} else {
				/* Facebook responded with invalid UTF-8.  Bastards. */
				purple_debug_error("fbapi", "Response is not valid UTF-8\n");
				salvaged = purple_utf8_salvage(url_text);
			}

			purple_fbapi_xml_salvage(salvaged);
			response = xmlnode_from_str(salvaged, -1);
			g_free(salvaged);
		}

		if (response == NULL) {
			purple_debug_error("fbapi", "Could not parse response as XML: %*s\n",
			(int)len, url_text);
			error_message2 = g_strdup(_("Invalid response from server"));
		} else if (g_str_equal(response->name, "error_response")) {
			/*
			 * The response is an error message, in the standard format
			 * for errors from API calls.
			 */
			xmlnode *tmp;
			char *tmpstr;

			tmp = xmlnode_get_child(response, "error_code");
			if (tmp != NULL) {
				tmpstr = xmlnode_get_data_unescaped(tmp);
				if (tmpstr != NULL && strcmp(tmpstr, "293") == 0) {
					error_message2 = g_strdup(_("Need chat permission"));
					error = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
				}
				g_free(tmpstr);
			}
			if (error_message2 == NULL) {
				error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
				tmp = xmlnode_get_child(response, "error_msg");
				if (tmp != NULL)
					error_message2 = xmlnode_get_data_unescaped(tmp);
			}
			if (error_message2 == NULL)
				error_message2 = g_strdup(_("Unknown"));
		} else {
			error_message2 = NULL;
		}
	} else {
		/* Response body was empty */
		response = NULL;
		error_message2 = NULL;
	}

	if (apicall->attempt_number > 1 || error_message2 != NULL)
		purple_debug_error("fbapi", "Request '%s' %s after %u attempts: %s\n",
				apicall->request,
				error_message == NULL ? "succeeded" : "failed",
				apicall->attempt_number, error_message2);

	/*
	 * The request either succeeded or failed the maximum number of
	 * times.  In either case, pass control off to the callback
	 * function and let them decide what to do.
	 */
	apicall->callback(apicall, apicall->user_data, response, error, error_message2);
	apicall->url_data = NULL;
	purple_fbapi_request_destroy(apicall);

	xmlnode_free(response);
	g_free(error_message2);
}