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);
}
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);
}
Example #3
0
static void fb_login(PurpleAccount *account)
{
	FacebookAccount *fba;
	gchar *postdata, *encoded_username, *encoded_password, *encoded_charset_test;
	const gchar* const *languages;
	const gchar *locale;
	
	/* Create account and initialize state */
	fba = g_new0(FacebookAccount, 1);
	fba->account = account;
	fba->pc = purple_account_get_connection(account);
	fba->uid = -1;
	fba->last_messages_download_time = time(NULL) - 60; /* 60 secs is a safe buffer */
	fba->cookie_table = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, g_free);
	fba->hostname_ip_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, g_free);
	fba->sent_messages_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, NULL);
	fba->auth_buddies = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, NULL);

	g_hash_table_replace(fba->cookie_table, g_strdup("test_cookie"),
			g_strdup("1"));

	account->gc->proto_data = fba;

	/* Error localized in libpurple jabber.c */
	if (!purple_ssl_is_supported()) {
		purple_connection_error_reason (purple_account_get_connection(account),
				PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
				_("Server requires TLS/SSL for login.  No TLS/SSL support found."));
		return;
	}

	purple_connection_set_state(fba->pc, PURPLE_CONNECTING);
	purple_connection_update_progress(fba->pc, _("Connecting"), 1, 3);

	encoded_username = g_strdup(purple_url_encode(
			purple_account_get_username(fba->account)));
	encoded_password = g_strdup(purple_url_encode(
			purple_account_get_password(fba->account)));
	encoded_charset_test = g_strdup(purple_url_encode("€,´,€,´,水,Д,Є"));
	languages = g_get_language_names();
	locale = languages[0];
	if (locale == NULL || g_str_equal(locale, "C"))
		locale = "en_US";

	g_hash_table_replace(fba->cookie_table, g_strdup("lsd"), g_strdup("abcde"));
	postdata = g_strdup_printf(
			"charset_test=%s&locale=%s&email=%s&pass=%s&pass_placeHolder=Password&persistent=1&login=Login&charset_test=%s&lsd=abcde",
			encoded_charset_test, locale, encoded_username, encoded_password, encoded_charset_test);
	g_free(encoded_username);
	g_free(encoded_password);
	g_free(encoded_charset_test);

	fb_post_or_get(fba, FB_METHOD_POST | FB_METHOD_SSL, "login.facebook.com",
			"/login.php?login_attempt=1&_fb_noscript=1", postdata, fb_login_cb, NULL, FALSE);
	g_free(postdata);
}
Example #4
0
static void
login_open_cb(PnNode *conn,
              gpointer data)
{
    MsnNexus *nexus = data;
    MsnSession *session;
    const char *username, *password;
    char *req, *head, *tail;
    guint32 ctint;
    GIOStatus status = G_IO_STATUS_NORMAL;

    g_return_if_fail(conn);

    g_signal_handler_disconnect(conn, nexus->open_handler);
    nexus->open_handler = 0;

    session = nexus->session;

    username = msn_session_get_username(session);
    password = msn_session_get_password(session);

    ctint = strtoul((char *) g_hash_table_lookup(nexus->challenge_data, "ct"), NULL, 10) + 200;

    head = g_strdup_printf("GET %s HTTP/1.1\r\n"
                           "Authorization: Passport1.4 OrgVerb=GET,OrgURL=%s,sign-in=%s",
                           nexus->login_path,
                           (char *) g_hash_table_lookup(nexus->challenge_data, "ru"),
                           purple_url_encode(username));

    tail = g_strdup_printf("lc=%s,id=%s,tw=%s,fs=%s,ru=%s,ct=%" G_GUINT32_FORMAT ",kpp=%s,kv=%s,ver=%s,tpf=%s\r\n"
                           "User-Agent: MSMSGS\r\n"
                           "Host: %s\r\n"
                           "Connection: Keep-Alive\r\n"
                           "Cache-Control: no-cache\r\n",
                           get_key(nexus->challenge_data, "lc"),
                           get_key(nexus->challenge_data, "id"),
                           get_key(nexus->challenge_data, "tw"),
                           get_key(nexus->challenge_data, "fs"),
                           get_key(nexus->challenge_data, "ru"),
                           ctint,
                           get_key(nexus->challenge_data, "kpp"),
                           get_key(nexus->challenge_data, "kv"),
                           get_key(nexus->challenge_data, "ver"),
                           get_key(nexus->challenge_data, "tpf"),
                           nexus->login_host);

    req = g_strdup_printf("%s,pwd=%s,%s\r\n", head, purple_url_encode(password), tail);

    g_free(head);
    g_free(tail);

    status = pn_node_write(conn, req, strlen(req), NULL, NULL);

    if (status != G_IO_STATUS_NORMAL) {
        msn_session_set_error(nexus->session, MSN_ERROR_AUTH,
                              _("nexus stream error"));
    }

    g_free(req);
}
Example #5
0
static void g_string_append_cookies(GString *str, GHashTable *table) {
    GHashTableIter iter;
    gpointer key, value;
    gboolean first = TRUE;
    g_hash_table_iter_init(&iter, table);
    while(g_hash_table_iter_next(&iter, &key, &value)) {
        if(!first) g_string_append(str, " ");
        g_string_append_printf(str, "%s", purple_url_encode(key));
        g_string_append(str, "=");
        g_string_append_printf(str, "%s;", purple_url_encode(value));
        first = FALSE;
    }
}
Example #6
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_len_with_account(
                       purple_connection_get_account(gc), URL_CLIENT_LOGIN,
                       TRUE, NULL, FALSE, request->str, FALSE, -1,
                       client_login_cb, od);
    g_string_free(request, TRUE);
}
Example #7
0
static gchar *format_icon(ParserVars *vars, const gchar *ts, const gchar *inner) {
    gchar *lower = g_utf8_strdown(inner, -1);
    gchar *ret;
    if(vars->fla && vars->convo) {
        gchar *smiley = g_strdup_printf("[icon]%s[/icon]", purple_url_encode(lower));
        ret = g_strdup_printf("%s<a href=\"http://www.f-list.net/c/%s\">(%s)</a>", smiley, purple_url_encode(lower), inner);
        flist_fetch_emoticon(vars->fla, smiley, lower, vars->convo);
        g_free(smiley);
    } else {
        ret = g_strdup_printf("<a href=\"http://www.f-list.net/c/%s\">%s</a>", purple_url_encode(lower), inner);
    }
    g_free(lower);
    return ret;
}
Example #8
0
/* Frees 'urls' */
static void
process_urls(PurpleConversation *conv, GList *urls)
{
	GList *iter;
	int c;
	FinchConv *fconv = FINCH_CONV(conv);
	GntTextView *tv = GNT_TEXT_VIEW(fconv->tv);

	for (iter = urls, c = 1; iter; iter = iter->next, c++) {
		int i;
		CbInfo *cbdata;
		gchar *url, *str;
		gchar *original_url;
		const gchar *tiny_url;

		i = gnt_text_view_get_lines_below(tv);

		original_url = purple_unescape_html((char *)iter->data);
		tiny_url = g_hash_table_lookup(tinyurl_cache, original_url);
		if (tiny_url) {
			gchar *str = g_strdup_printf("\n[%d] %s", c, tiny_url);

			g_free(original_url);
			gnt_text_view_append_text_with_flags(tv, str, GNT_TEXT_FLAG_DIM);
			if (i == 0)
				gnt_text_view_scroll(tv, 0);
			g_free(str);
			continue;
		}
		cbdata = g_new(CbInfo, 1);
		cbdata->num = c;
		cbdata->original_url = original_url;
		cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++);
		cbdata->conv = conv;
		if (g_ascii_strncasecmp(original_url, "http://", 7) && g_ascii_strncasecmp(original_url, "https://", 8)) {
			url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url));
		} else {
			url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url));
		}
		purple_http_get(NULL, url_fetched, cbdata, url);
		str = g_strdup_printf(_("\nFetching TinyURL..."));
		gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag);
		g_free(str);
		if (i == 0)
			gnt_text_view_scroll(tv, 0);
		g_free(iter->data);
		g_free(url);
	}
	g_list_free(urls);
}
Example #9
0
void
skypeweb_download_video_message(SkypeWebAccount *sa, const gchar *sid, PurpleConversation *conv)
{
	gchar *url, *username_encoded;
	
	username_encoded = g_strdup(purple_url_encode(sa->username));
	url = g_strdup_printf("/users/%s/video_mails/%s", username_encoded, purple_url_encode(sid));
	
	skypeweb_post_or_get(sa, SKYPEWEB_METHOD_GET | SKYPEWEB_METHOD_SSL, SKYPEWEB_VIDEOMAIL_HOST, url, NULL, skypeweb_got_vm_info, conv, TRUE);
	
	g_free(url);
	g_free(username_encoded);
	
}
Example #10
0
//TODO: you're supposed to change spaces to "+" values??
static void g_string_append_cgi(GString *str, GHashTable *table) {
    GHashTableIter iter;
    gpointer key, value;
    gboolean first = TRUE;
    g_hash_table_iter_init(&iter, table);
    while(g_hash_table_iter_next(&iter, &key, &value)) {
        purple_debug_info("flist", "cgi writing key, value: %s, %s\n", (gchar *)key, (gchar *)value);
        if(!first) g_string_append(str, "&");
        g_string_append_printf(str, "%s", purple_url_encode(key));
        g_string_append(str, "=");
        g_string_append_printf(str, "%s", purple_url_encode(value));
        first = FALSE;
    }
}
Example #11
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;
}
Example #12
0
static gboolean append_params_to_body(gpointer key, gpointer value, gpointer data)
{
	GString *body;

	body = data;

	if (body->len > 0)
		g_string_append_c(body, '&');

	g_string_append(body, purple_url_encode(key));
	g_string_append_c(body, '=');
	g_string_append(body, purple_url_encode(value));

	return FALSE;
}
Example #13
0
static gchar *format_user(ParserVars *vars, const gchar *ts, const gchar *inner) {
    const gchar *url_pattern = "<a href=\"http://www.f-list.net/c/%s\">%s</a>";
    gchar *lower = g_utf8_strdown(inner, -1);
    gchar *ret = g_strdup_printf(url_pattern, purple_url_encode(lower), inner);
    g_free(lower);
    return ret;
}
void fb_buddy_delete(PurpleConnection *pc, PurpleBuddy *buddy,
		PurpleGroup *group)
{
	FacebookAccount *fba = pc->proto_data;
	gchar *buddy_tmp, *postdata;

	//This function removes a buddy from our friends list on facebook
	//and shouldn't really be used
	if (!purple_account_get_bool(fba->account, "facebook_manage_friends", FALSE)) {
		purple_debug_warning("facebook", "attempted to add %s but was blocked\n", buddy->name);
		return;
	}

	buddy_tmp = g_strdup(purple_url_encode(buddy->name));
	postdata = g_strdup_printf(
			"uid=%s&post_form_id=%s&fb_dtsg=%s&"
			"post_form_id_source=AsyncRequest&__a=1",
			buddy_tmp, fba->post_form_id, fba->dtsg);
	g_free(buddy_tmp);

	fb_post_or_get(fba, FB_METHOD_POST, NULL, "/ajax/profile/removefriend.php",
			postdata, NULL, NULL, FALSE);

	g_free(postdata);
}
Example #15
0
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);
}
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);
}
Example #17
0
static unsigned int om_send_typing(PurpleConnection *pc, const gchar *name,
		PurpleTypingState state)
{
	gchar *postdata;
	OmegleAccount *oma = pc->proto_data;
	gchar *url;

	g_return_val_if_fail(oma != NULL, 0);

	if (state == PURPLE_TYPING)
	{
		url = "/typing";	
	} else if (state == PURPLE_TYPED)
	{
		url = "/stoppedtyping";
	} else {
		return 0;
	}
	
	postdata = g_strdup_printf("id=%s", purple_url_encode(name));
	
	om_post_or_get(oma, OM_METHOD_POST, NULL, url, postdata, NULL, NULL, FALSE);
	
	g_free(postdata);
	
	return 10;
}
Example #18
0
static void
skypeweb_xfer_send_connect_cb(gpointer user_data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
{
	SkypeWebFileTransfer *swft = user_data;
	SkypeWebAccount *sa = swft->sa;
	PurpleXfer *xfer = swft->xfer;
	gchar *headers;
	
	headers = g_strdup_printf("PUT /v1/objects/%s/content/original HTTP/1.0\r\n"
			"Connection: close\r\n"
			"Authorization: skype_token %s\r\n" //slightly different to normal!
			"Host: " SKYPEWEB_XFER_HOST "\r\n"
			"Content-Length: %d\r\n"
			"Content-Type: application/json\r\n"
			"\r\n\r\n",
			purple_url_encode(swft->id),
			sa->skype_token, 
			purple_xfer_get_size(xfer));
	
	purple_ssl_write(ssl_connection, headers, strlen(headers));
	
	swft->conn = ssl_connection;
	purple_xfer_ref(xfer);
	purple_xfer_start(xfer, ssl_connection->fd, NULL, 0);
	
	//TODO add input watcher that calls this repeatedly
	purple_xfer_prpl_ready(xfer);
	//purple_ssl_input_add(
			
	g_free(headers);
}
Example #19
0
static gchar   *twitter_oauth_get_text_to_sign(gboolean post, gboolean https, const gchar * url, const TwitterRequestParams * params)
{
    gchar          *query_string = twitter_request_params_to_string(params);
    gchar          *pieces[4];
    int             i;
    gchar          *sig_base;
    pieces[0] = g_strdup(post ? "POST" : "GET");
    pieces[1] = g_strdup_printf("http%s%%3A%%2F%%2F%s", https ? "s" : "", purple_url_encode(url));
    pieces[2] = g_strdup(purple_url_encode(query_string));
    pieces[3] = NULL;
    sig_base = g_strjoinv("&", pieces);
    for (i = 0; i < 3; i++)
        g_free(pieces[i]);
    g_free(query_string);
    return sig_base;
}
Example #20
0
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
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);
}
Example #22
0
void msn_set_friendly_name(PurpleConnection *gc, const char *entry)
{
	MsnCmdProc *cmdproc;
	MsnSession *session;
	PurpleAccount *account;
	const char *alias;
	
	session = gc->proto_data;
	cmdproc = session->notification->cmdproc;
	account = purple_connection_get_account(gc);
	
	if(entry && strlen(entry))
		alias = purple_url_encode(entry);
	else
		alias = "";
	
	if (strlen(alias) > BUDDY_ALIAS_MAXLEN)
	{
		purple_notify_error(gc, NULL,
						  _("Your new MSN friendly name is too long."), NULL);
		return;
	}
	
	msn_cmdproc_send(cmdproc, "REA", "%s %s",
					 purple_account_get_username(account),
					 alias);
}
Example #23
0
/**
 * @return A base-64 encoded HMAC-SHA256 signature created using the
 *         technique documented at
 *         http://dev.aol.com/authentication_for_clients#signing
 */
static gchar *generate_signature(const char *method, const char *url, const char *parameters, const char *session_key)
{
    char *encoded_url, *signature_base_string, *signature;
    const char *encoded_parameters;

    encoded_url = g_strdup(purple_url_encode(url));
    encoded_parameters = purple_url_encode(parameters);
    signature_base_string = g_strdup_printf("%s&%s&%s",
                                            method, encoded_url, encoded_parameters);
    g_free(encoded_url);

    signature = hmac_sha256(session_key, signature_base_string);
    g_free(signature_base_string);

    return signature;
}
Example #24
0
static const char*
get_friendly_name(MsnUser *user)
{
	const char *friendly_name;

	g_return_val_if_fail(user != NULL, NULL);

	friendly_name = msn_user_get_friendly_name(user);

	if (friendly_name != NULL)
		friendly_name = purple_url_encode(friendly_name);
	else
		friendly_name = msn_user_get_passport(user);

	/* this might be a bit of a hack, but it should prevent notification server
	 * disconnections for people who have buddies with insane friendly names
	 * who added you to their buddy list from being disconnected. Stu. */
	/* Shx: What? Isn't the store_name obtained from the server, and hence it's
	 * below the BUDDY_ALIAS_MAXLEN ? */
	/* Stu: yeah, that's why it's a bit of a hack, as you pointed out, we're
	 * probably decoding the incoming store_name wrong, or something. bleh. */

	if (strlen(friendly_name) > BUDDY_ALIAS_MAXLEN)
		friendly_name = msn_user_get_passport(user);

	return friendly_name;
}
Example #25
0
void flist_get_profile(PurpleConnection *pc, const char *who) {
    FListAccount *fla;
    FListProfiles *flp;
    GString *link_str;
    gchar *link;
    FListCharacter *character;

    g_return_if_fail((fla = pc->proto_data));
    flp = _flist_profiles(fla);

    if(flp->character) g_free(flp->character);
    flp->character = NULL;
    if(flp->profile_info) purple_notify_user_info_destroy(flp->profile_info);
    flp->profile_info = NULL;
    if(flp->table) g_hash_table_destroy(flp->table);
    flp->table = NULL;
    if(flp->profile_request) {
        flist_web_request_cancel(flp->profile_request);
        flp->profile_request = NULL;
    }

    flp->character = g_strdup(who);
    flp->profile_info = purple_notify_user_info_new();

    link_str = g_string_new(NULL);
    g_string_append_printf(link_str, "http://www.f-list.net/c/%s", purple_url_encode(who));
    link = g_string_free(link_str, FALSE);

    character = flist_get_character(fla, who);
    if(!character) {
        purple_notify_user_info_add_pair(flp->profile_info, "Status", "Offline");
    } else {
        gchar *clean_message = flist_html_unescape_utf8(character->status_message);
        gchar *parsed_message = flist_bbcode_to_html(fla, NULL, clean_message);
        purple_notify_user_info_add_pair(flp->profile_info, "Status", flist_format_status(character->status));
        purple_notify_user_info_add_pair(flp->profile_info, "Gender", flist_format_gender(character->gender));
        purple_notify_user_info_add_pair(flp->profile_info, "Message", parsed_message);
        g_free(parsed_message);
        g_free(clean_message);
    }
    purple_notify_user_info_add_pair(flp->profile_info, "Link", link);
    purple_notify_userinfo(pc, flp->character, flp->profile_info, NULL, NULL);

    if(!character) {
        //The character is offline. There's nothing more we should do.
        g_free(flp->character); flp->character = NULL;
        purple_notify_user_info_destroy(flp->profile_info); flp->profile_info = NULL;
    } else if(flp->category_table) { /* Try to get the profile through the website API first. */
        GHashTable *args = flist_web_request_args(fla);
        g_hash_table_insert(args, "name", g_strdup(flp->character));
        flp->profile_request = flist_web_request(JSON_CHARACTER_INFO, args, NULL, TRUE, fla->secure, flist_get_profile_cb, fla);
        g_hash_table_destroy(args);
    } else { /* Try to get the profile through F-Chat. */
        JsonObject *json = json_object_new();
        json_object_set_string_member(json, "character", flp->character);
        flist_request(pc, "PRO", json);
        json_object_unref(json);
    }
    g_free(link);
}
Example #26
0
static unsigned int fb_send_typing(PurpleConnection *pc, const gchar *name,
		PurpleTypingState state)
{
	int typing_state;
	gchar *postdata;
	FacebookAccount *fba = pc->proto_data;
	gchar *encoded_name;

	g_return_val_if_fail(fba != NULL, 0);
	g_return_val_if_fail(fba->post_form_id != NULL, 0);

	typing_state = (state == PURPLE_TYPING) ? 1 : 0;

	/* Don't send typing notifications to self */
	if (atoll(name) != fba->uid)
	{
		encoded_name = g_strdup(purple_url_encode(name));
		postdata = g_strdup_printf("typ=%d&to=%s&post_form_id=%s",
				typing_state, encoded_name, fba->post_form_id);
		g_free(encoded_name);
		fb_post_or_get(fba, FB_METHOD_POST, NULL, "/ajax/chat/typ.php",
				postdata, NULL, NULL, FALSE);
		g_free(postdata);
	} else {
		serv_got_typing(pc, name, 10, state);
	}

	/* 7 is the number of seconds before sending the new typing state.  It
	 * corresponds with the default value that Facebook waits. */
	return 7;
}
Example #27
0
void
pn_update_status (MsnSession *session)
{
    MsnCmdProc *cmdproc;
    struct pn_contact *user;
    const gchar *state_text;
    int client_id;
    int caps;

    g_return_if_fail (session);

    if (!session->logged_in)
        return;

    user = msn_session_get_contact (session);
    cmdproc = session->notification->cmdproc;
    state_text = util_type_to_str (util_status_from_session (session));

    caps = PN_CLIENT_CAP_BASE;
#if defined(PECAN_CVR)
    caps |= PN_CLIENT_CAP_INK_GIF;
#if defined(PECAN_LIBSIREN)
    caps |= PN_CLIENT_CAP_VOICE_CLIP;
#endif
#if defined(PECAN_LIBMSPACK)
    caps |= PN_CLIENT_CAP_WINKS;
#endif
#endif

    client_id = caps | (PN_CLIENT_VER_7_5 << 24);

#if defined(PECAN_CVR)
    {
        struct pn_msnobj *obj;

        obj = pn_contact_get_object (user);

        if (obj)
        {
            gchar *msnobj_str;

            msnobj_str = pn_msnobj_to_string (obj);

            msn_cmdproc_send (cmdproc, "CHG", "%s %d %s", state_text,
                              client_id, purple_url_encode (msnobj_str));

            g_free (msnobj_str);
        }
        else
        {
            msn_cmdproc_send (cmdproc, "CHG", "%s %d", state_text,
                              client_id);
        }
    }
#else
    msn_cmdproc_send (cmdproc, "CHG", "%s %d", state_text,
                      client_id);
#endif /* defined(PECAN_CVR) */
}
Example #28
0
static void *
tinyurl_notify_uri(const char *uri)
{
	char *fullurl = NULL;
	GntWidget *win;
	PurpleHttpConnection *hc;
	const gchar *tiny_url;

	/* XXX: The following expects that finch_notify_message gets called. This
	 * may not always happen, e.g. when another plugin sets its own
	 * notify_message. So tread carefully. */
	win = purple_notify_message(NULL, PURPLE_NOTIFY_MSG_INFO, _("URI"), uri,
			_("Please wait while TinyURL fetches a shorter URL ..."), NULL, NULL, NULL);
	if (!GNT_IS_WINDOW(win) || !g_object_get_data(G_OBJECT(win), "info-widget"))
		return win;

	tiny_url = g_hash_table_lookup(tinyurl_cache, uri);
	if (tiny_url) {
		tinyurl_notify_tinyuri(win, tiny_url);
		return win;
	}

	if (g_ascii_strncasecmp(uri, "http://", 7) && g_ascii_strncasecmp(uri, "https://", 8)) {
		fullurl = g_strdup_printf("%shttp%%3A%%2F%%2F%s",
				purple_prefs_get_string(PREF_URL), purple_url_encode(uri));
	} else {
		fullurl = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL),
				purple_url_encode(uri));
	}

	g_object_set_data_full(G_OBJECT(win), "gnttinyurl-original", g_strdup(uri), g_free);

	/* Store the return value of purple_http_get and destroy that when win
	 * is destroyed, so that the callback for purple_http_get does not try
	 * to molest a non-existent window
	 */
	hc = purple_http_get(NULL, tinyurl_notify_fetch_cb, win, fullurl);
	g_free(fullurl);
	g_signal_connect_swapped(G_OBJECT(win), "destroy",
			G_CALLBACK(purple_http_conn_cancel), hc);

	return win;
}
Example #29
0
void fb_login_captcha_ok_cb(PurpleConnection *pc, PurpleRequestFields *fields)
{
	const gchar *captcha_response;
	gchar *postdata, *encoded_username, *encoded_password, *encoded_charset_test,
			*encoded_persist_data, *encoded_response, *encoded_extra_challenge,
			*encoded_session;
	FacebookAccount *fba = pc->proto_data;

	captcha_response = purple_request_fields_get_string(fields, "captcha_response");
	
	encoded_response = g_strdup(purple_url_encode(captcha_response));
	encoded_username = g_strdup(purple_url_encode(
			purple_account_get_username(fba->account)));
	encoded_password = g_strdup(purple_url_encode(
			purple_account_get_password(fba->account)));
	encoded_extra_challenge = g_strdup(purple_url_encode(
			fba->extra_challenge));
	encoded_persist_data = g_strdup(purple_url_encode(
			fba->persist_data));
	encoded_session = g_strdup(purple_url_encode(
			fba->captcha_session));
	encoded_charset_test = g_strdup(purple_url_encode("€,´,€,´,水,Д,Є"));

	postdata = g_strdup_printf("charset_test=%s&"
								"version=1.0&"
								"return_session=0&"
								"charset_test=%s&"
								"answered_captcha=1&"
								"captcha_persist_data=%s&"
								"captcha_session=%s&"
								"extra_challenge_params=%s&"
								"captcha_response=%s&"
								"email=%s&pass=%s&"
								"persistent=1",
								encoded_charset_test, encoded_charset_test,
								encoded_persist_data, encoded_session,
								encoded_extra_challenge, encoded_response,
								encoded_username, encoded_password);
	g_free(encoded_username);
	g_free(encoded_password);
	g_free(encoded_charset_test);
	g_free(encoded_extra_challenge);
	g_free(encoded_persist_data);
	g_free(encoded_response);
	g_free(encoded_session);

	fb_post_or_get(fba, FB_METHOD_POST | FB_METHOD_SSL, "login.facebook.com",
			"/login.php?login_attempt=1&_fb_noscript=1", postdata, fb_login_cb, NULL, FALSE);
	g_free(postdata);
	
	g_free(fba->extra_challenge);
	g_free(fba->persist_data);
	g_free(fba->captcha_session);
	fba->extra_challenge = NULL;
	fba->persist_data = NULL;
	fba->captcha_session = NULL;
}
Example #30
0
static void om_fetch_events(OmegleAccount *oma, gchar *who)
{
	gchar *postdata;
	
	postdata = g_strdup_printf("id=%s", purple_url_encode(who));
	
	om_post_or_get(oma, OM_METHOD_POST, NULL, "/events",
				postdata, om_got_events, who, FALSE);
				
	g_free(postdata);
}