예제 #1
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);
}
예제 #2
0
파일: bosh.c 프로젝트: Lilitana/Pidgin
static void http_connection_connect(PurpleHTTPConnection *conn)
{
	PurpleBOSHConnection *bosh = conn->bosh;
	PurpleConnection *gc = bosh->js->gc;
	PurpleAccount *account = purple_connection_get_account(gc);

	conn->state = HTTP_CONN_CONNECTING;

	if (bosh->ssl) {
		if (purple_ssl_is_supported()) {
			conn->psc = purple_ssl_connect(account, bosh->host, bosh->port,
			                               ssl_connection_established_cb,
			                               ssl_connection_error_cb,
			                               conn);
			if (!conn->psc) {
				purple_connection_error_reason(gc,
					PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
					_("Unable to establish SSL connection"));
			}
		} else {
			purple_connection_error_reason(gc,
			    PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
			    _("SSL support unavailable"));
		}
	} else if (purple_proxy_connect(conn, account, bosh->host, bosh->port,
	                                 connection_established_cb, conn) == NULL) {
		purple_connection_error_reason(gc,
		    PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
		    _("Unable to connect"));
	}
}
예제 #3
0
TwitterRequestParams *twitter_request_params_add_oauth_params(PurpleAccount * account, gboolean post, const gchar * url, const TwitterRequestParams * params, const gchar * token, const gchar * signing_key)
{
    gboolean        use_https = twitter_option_use_https(account) && purple_ssl_is_supported();
    TwitterRequestParams *oauth_params = twitter_request_params_clone(params);
    gchar          *signme;
    gchar          *signature;
    if (oauth_params == NULL)
        oauth_params = twitter_request_params_new();

    twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_consumer_key", prpltwtr_auth_get_oauth_key(account)));
    twitter_request_params_add(oauth_params, twitter_request_param_new_ll("oauth_nonce", twitter_oauth_generate_nonce()));
    twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_signature_method", "HMAC-SHA1"));
    /* Added for status.net. Twitter doesn't seem to care */
    twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_callback", "oob"));
    twitter_request_params_add(oauth_params, twitter_request_param_new_ll("oauth_timestamp", time(NULL)));
    if (token)
        twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_token", token));

    g_array_sort(oauth_params, (GCompareFunc) twitter_request_params_sort_do);
    signme = twitter_oauth_get_text_to_sign(post, use_https, url, oauth_params);
    signature = twitter_oauth_sign(signme, signing_key);

    g_free(signme);

    if (!signature) {
        twitter_request_params_free(oauth_params);
        return NULL;
    } else {
        twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_signature", signature));
        g_free(signature);
        return oauth_params;
    }
}
예제 #4
0
파일: irc.c 프로젝트: arminius2/apolloim
static void irc_login(PurpleAccount *account)
{
	PurpleConnection *gc;
	struct irc_conn *irc;
	char **userparts;
	const char *username = purple_account_get_username(account);

	gc = purple_account_get_connection(account);
	gc->flags |= PURPLE_CONNECTION_NO_NEWLINES;

	if (strpbrk(username, " \t\v\r\n") != NULL) {
		purple_connection_error(gc, _("IRC nicks may not contain whitespace"));
		return;
	}

	gc->proto_data = irc = g_new0(struct irc_conn, 1);
	irc->fd = -1;
	irc->account = account;
	irc->outbuf = purple_circ_buffer_new(512);

	userparts = g_strsplit(username, "@", 2);
	purple_connection_set_display_name(gc, userparts[0]);
	irc->server = g_strdup(userparts[1]);
	g_strfreev(userparts);

	irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal,
					     NULL, (GDestroyNotify)irc_buddy_free);
	irc->cmds = g_hash_table_new(g_str_hash, g_str_equal);
	irc_cmd_table_build(irc);
	irc->msgs = g_hash_table_new(g_str_hash, g_str_equal);
	irc_msg_table_build(irc);

	purple_connection_update_progress(gc, _("Connecting"), 1, 2);

	if (purple_account_get_bool(account, "ssl", FALSE)) {
		if (purple_ssl_is_supported()) {
			irc->gsc = purple_ssl_connect(account, irc->server,
					purple_account_get_int(account, "port", IRC_DEFAULT_SSL_PORT),
					irc_login_cb_ssl, irc_ssl_connect_failure, gc);
		} else {
			purple_connection_error(gc, _("SSL support unavailable"));
			return;
		}
	}

	if (!irc->gsc) {

		if (purple_proxy_connect(gc, account, irc->server,
				 purple_account_get_int(account, "port", IRC_DEFAULT_PORT),
				 irc_login_cb, gc) == NULL)
		{
			purple_connection_error(gc, _("Couldn't create socket"));
			return;
		}
	}
}
예제 #5
0
void
ggp_tcpsocket_setup(PurpleConnection *gc, struct gg_login_params *glp)
{
	glp->socket_manager_type = purple_ssl_is_supported() ?
		GG_SOCKET_MANAGER_TYPE_TLS : GG_SOCKET_MANAGER_TYPE_TCP;
	glp->socket_manager.cb_data = gc;
	glp->socket_manager.connect_cb = ggp_tcpsocket_connect;
	glp->socket_manager.close_cb = ggp_tcpsocket_close;
	glp->socket_manager.read_cb = ggp_tcpsocket_read;
	glp->socket_manager.write_cb = ggp_tcpsocket_write;
}
예제 #6
0
파일: sslconn.c 프로젝트: Draghtnod/pidgin
void
purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func,
				   void *data)
{
	g_return_if_fail(func != NULL);
	g_return_if_fail(purple_ssl_is_supported());

	gsc->recv_cb_data = data;
	gsc->recv_cb      = func;

	gsc->inpa = purple_input_add(gsc->fd, PURPLE_INPUT_READ, recv_cb, gsc);
}
예제 #7
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);
}
예제 #8
0
파일: sslconn.c 프로젝트: Draghtnod/pidgin
PurpleSslConnection *
purple_ssl_connect_with_ssl_cn(PurpleAccount *account, const char *host, int port,
				 PurpleSslInputFunction func, PurpleSslErrorFunction error_func,
				 const char *ssl_cn, void *data)
{
	PurpleSslConnection *gsc;

	g_return_val_if_fail(host != NULL,            NULL);
	g_return_val_if_fail(port != 0 && port != -1, NULL);
	g_return_val_if_fail(func != NULL,            NULL);
	g_return_val_if_fail(purple_ssl_is_supported(), NULL);

	if (!_ssl_initialized)
	{
		if (!ssl_init())
			return NULL;
	}

	gsc = g_new0(PurpleSslConnection, 1);

	gsc->fd              = -1;
	gsc->host            = ssl_cn ? g_strdup(ssl_cn) : g_strdup(host);
	gsc->port            = port;
	gsc->connect_cb_data = data;
	gsc->connect_cb      = func;
	gsc->error_cb        = error_func;

	/* TODO: Move this elsewhere */
	gsc->verifier = purple_certificate_find_verifier("x509","tls_cached");

	gsc->connect_data = purple_proxy_connect(NULL, account, host, port, purple_ssl_connect_cb, gsc);

	if (gsc->connect_data == NULL)
	{
		g_free(gsc->host);
		g_free(gsc);

		return NULL;
	}

	return (PurpleSslConnection *)gsc;
}
예제 #9
0
static void
skypeweb_login(PurpleAccount *account)
{
	PurpleConnection *pc = purple_account_get_connection(account);
	SkypeWebAccount *sa = g_new0(SkypeWebAccount, 1);
	PurpleConnectionFlags flags;
	
	purple_connection_set_protocol_data(pc, sa);
	
	if (!purple_ssl_is_supported()) {
		purple_connection_error (pc,
								PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
								_("Server requires TLS/SSL for login.  No TLS/SSL support found."));
		return;
	}

	flags = purple_connection_get_flags(pc);
	flags |= PURPLE_CONNECTION_FLAG_HTML | PURPLE_CONNECTION_FLAG_NO_BGCOLOR | PURPLE_CONNECTION_FLAG_NO_FONTSIZE;
	purple_connection_set_flags(pc, flags);
	
	if (!SKYPEWEB_BUDDY_IS_MSN(purple_account_get_username(account))) {
		sa->username = g_ascii_strdown(purple_account_get_username(account), -1);
	}
	sa->account = account;
	sa->pc = pc;
	sa->cookie_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	sa->hostname_ip_cache = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	sa->sent_messages_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
	sa->waiting_conns = g_queue_new();
	sa->messages_host = g_strdup(SKYPEWEB_DEFAULT_MESSAGES_HOST);
	
	if(strchr(purple_account_get_username(account), '@')) {
		//Has an email address for a username, probably a microsoft account?
		skypeweb_begin_oauth_login(sa);
	} else {
		skypeweb_begin_web_login(sa);
	}
	
	purple_signal_connect(purple_conversations_get_handle(), "conversation-updated", pc, PURPLE_CALLBACK(skypeweb_mark_conv_seen), NULL);
}
예제 #10
0
파일: sslconn.c 프로젝트: Draghtnod/pidgin
PurpleSslConnection *
purple_ssl_connect_with_host_fd(PurpleAccount *account, int fd,
                      PurpleSslInputFunction func,
                      PurpleSslErrorFunction error_func,
                      const char *host,
                      void *data)
{
	PurpleSslConnection *gsc;
	PurpleSslOps *ops;

	g_return_val_if_fail(fd != -1,                NULL);
	g_return_val_if_fail(func != NULL,            NULL);
	g_return_val_if_fail(purple_ssl_is_supported(), NULL);

	if (!_ssl_initialized)
	{
		if (!ssl_init())
			return NULL;
	}

	gsc = g_new0(PurpleSslConnection, 1);

	gsc->connect_cb_data = data;
	gsc->connect_cb      = func;
	gsc->error_cb        = error_func;
	gsc->fd              = fd;
    if(host)
        gsc->host            = g_strdup(host);

	/* TODO: Move this elsewhere */
	gsc->verifier = purple_certificate_find_verifier("x509","tls_cached");


	ops = purple_ssl_get_ops();
	ops->connectfunc(gsc);

	return (PurpleSslConnection *)gsc;
}
예제 #11
0
static gpointer twitter_send_request_querystring(TwitterRequestor * r, gboolean post, const char *url, const char *query_string, char **header_fields, TwitterSendRequestSuccessFunc success_callback, TwitterSendRequestErrorFunc error_callback, gpointer data)
{
    PurpleAccount  *account = r->account;
    gchar          *request;
    gboolean        use_https = twitter_option_use_https(account) && purple_ssl_is_supported();
    char           *slash = strchr(url, '/');
    TwitterSendRequestData *request_data = g_new0(TwitterSendRequestData, 1);
    char           *host = slash ? g_strndup(url, slash - url) : g_strdup(url);
    char           *full_url = g_strdup_printf("%s://%s",
                                               use_https ? "https" : "http",
                                               url);
    char           *header_fields_text = (header_fields ? g_strjoinv("\r\n", header_fields) : NULL);

    purple_debug_info(purple_account_get_protocol_id(account), "Sending %s request to: %s ? %s\n", post ? "POST" : "GET", full_url, query_string ? query_string : "");

    request_data->requestor = r;
    request_data->user_data = data;
    request_data->success_func = success_callback;
    request_data->error_func = error_callback;

    request = g_strdup_printf("%s %s%s%s HTTP/1.0\r\n" "User-Agent: " USER_AGENT "\r\n" "Host: %s\r\n" "%s" //Content-Type if post
                              "%s%s"             //extra header fields, if any
                              "Content-Length: %lu\r\n\r\n" "%s", post ? "POST" : "GET", full_url, (!post && query_string ? "?" : ""), (!post && query_string ? query_string : ""), host, header_fields_text ? header_fields_text : "", header_fields_text ? "\r\n" : "", post ? "Content-Type: application/x-www-form-urlencoded\r\n" : "", query_string && post ? (unsigned long) strlen(query_string) : 0, query_string && post ? query_string : "");

#ifdef _DEBUG_
    purple_debug_info(purple_account_get_protocol_id(account), "Sending request: %s\n", request);
#endif

    request_data->request_id = purple_util_fetch_url_request_len_with_account(account, full_url, TRUE, USER_AGENT, TRUE, request, TRUE, -1, twitter_send_request_cb, request_data);
    g_free(full_url);
    g_free(request);
    g_free(host);
    g_free(header_fields_text);

    return request_data;
}