Esempio n. 1
0
static void fx_login(PurpleAccount *account)
{
	PurplePresence *presence;
	PurpleConnection *pc = purple_account_get_connection(account);
	const gchar *mobileno = purple_account_get_username(account);
	const gchar *password = purple_connection_get_password(pc);
	const gchar *status_id;
	fetion_account  *ac = session_new(account);

	/* construct a user object */
 	ac->user = fetion_user_new(mobileno, password);
	ac->account = account;
	ac->gc = pc;
	ac->chan_ready = 1;

	purple_connection_set_protocol_data(pc, ac);

	presence = purple_account_get_presence(account);

	status_id = get_status_id(ac->user->state);
	if(ac->user->state == 0) status_id = "Hidden";
	purple_presence_set_status_active(presence, status_id, TRUE);
	purple_connection_update_progress(pc, "Connecting", 1, 2);
	purple_ssl_connect(ac->account, SSI_SERVER,
			PURPLE_SSL_DEFAULT_PORT, 
			(PurpleSslInputFunction)ssi_auth_action,
			(PurpleSslErrorFunction)0, ac);
}
Esempio n. 2
0
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"));
	}
}
Esempio n. 3
0
void
msn_nexus_connect(MsnNexus *nexus)
{
	nexus->gsc = purple_ssl_connect(nexus->session->account,
			"nexus.passport.com", PURPLE_SSL_DEFAULT_PORT,
			nexus_connect_cb, login_error_cb, nexus);
}
Esempio n. 4
0
static void om_attempt_connection(OmegleConnection *omconn)
{
	OmegleAccount *oma = omconn->oma;

#if 0
	/* Connection to attempt retries.  This code doesn't work perfectly, but
	 * remains here for future reference if needed */
	if (time(NULL) - omconn->request_time > 5) {
		/* We've continuously tried to remake this connection for a 
		 * bit now.  It isn't happening, sadly.  Time to die. */
		purple_debug_error("omegle", "could not connect after retries\n");
		om_fatal_connection_cb(omconn);
		return;
	}

	purple_debug_info("omegle", "making connection attempt\n");

	/* TODO: If we're retrying the connection, consider clearing the cached
	 * DNS value.  This will require some juggling with the hostname param */
	/* TODO/FIXME: This retries almost instantenously, which in some cases
	 * runs at blinding speed.  Slow it down. */
	/* TODO/FIXME: this doesn't retry properly on non-ssl connections */
#endif

	if (omconn->method & OM_METHOD_SSL) {
		omconn->ssl_conn = purple_ssl_connect(oma->account, omconn->hostname,
				443, om_post_or_get_ssl_connect_cb,
				om_ssl_connection_error, omconn);
	} else {
		omconn->connect_data = purple_proxy_connect(NULL, oma->account,
				omconn->hostname, 80, om_post_or_get_connect_cb, omconn);
	}

	return;
}
Esempio n. 5
0
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;
		}
	}
}
Esempio n. 6
0
static void
skypeweb_got_object_for_file(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
	SkypeWebFileTransfer *swft = user_data;
	SkypeWebAccount *sa = swft->sa;
	PurpleXfer *xfer = swft->xfer;
	JsonParser *parser;
	JsonNode *node;
	JsonObject *obj;
	gchar *id;
	
	sa->url_datas = g_slist_remove(sa->url_datas, url_data);
	
	//Get back {"id": "0-cus-d3-deadbeefdeadbeef012345678"}
	parser = json_parser_new();
	if (!json_parser_load_from_data(parser, url_text, len, NULL)) {
		g_free(swft->from);
		g_free(swft);
		g_object_unref(parser);
		return;
	}
	node = json_parser_get_root(parser);
	if (node == NULL || json_node_get_node_type(node) != JSON_NODE_OBJECT) {
		g_free(swft->from);
		g_free(swft);
		g_object_unref(parser);
		purple_xfer_cancel_local(xfer);
		return;
	}
	obj = json_node_get_object(node);
	
	if (!json_object_has_member(obj, "id")) {
		g_free(swft->from);
		g_free(swft);
		g_object_unref(parser);
		purple_xfer_cancel_local(xfer);
		return;
	}
	
	swft->id = g_strdup(json_object_get_string_member(obj, "id"));
	swft->url = g_strconcat("https://" SKYPEWEB_XFER_HOST "/v1/objects/", purple_url_encode(swft->id), "/views/original/status", NULL);
	
	g_object_unref(parser);
	
	//Send the data
	
	//can't use fetch_url_request because it doesn't handle binary data
	//TODO make an error handler callback func
	purple_ssl_connect(sa->account, SKYPEWEB_XFER_HOST, 443, skypeweb_xfer_send_connect_cb, NULL, swft);
	
	//poll swft->url for progress
	purple_timeout_add_seconds(1, poll_file_send_progress, swft);
}
Esempio n. 7
0
gboolean
purple_socket_connect(PurpleSocket *ps, PurpleSocketConnectCb cb,
	gpointer user_data)
{
	PurpleAccount *account = NULL;

	g_return_val_if_fail(ps != NULL, FALSE);

	if (ps->gc && purple_connection_is_disconnecting(ps->gc)) {
		purple_debug_error("socket", "connection is being destroyed");
		ps->state = PURPLE_SOCKET_STATE_ERROR;
		return FALSE;
	}

	if (!purple_socket_check_state(ps, PURPLE_SOCKET_STATE_DISCONNECTED))
		return FALSE;
	ps->state = PURPLE_SOCKET_STATE_CONNECTING;

	if (ps->host == NULL || ps->port < 0) {
		purple_debug_error("socket", "Host or port is not specified");
		ps->state = PURPLE_SOCKET_STATE_ERROR;
		return FALSE;
	}

	if (ps->gc != NULL)
		account = purple_connection_get_account(ps->gc);

	ps->cb = cb;
	ps->cb_data = user_data;

	if (ps->is_tls) {
		ps->tls_connection = purple_ssl_connect(account, ps->host,
			ps->port, _purple_socket_connected_tls,
			_purple_socket_connected_tls_error, ps);
	} else {
		ps->raw_connection = purple_proxy_connect(ps->gc, account,
			ps->host, ps->port, _purple_socket_connected_raw, ps);
	}

	if (ps->tls_connection == NULL &&
		ps->raw_connection == NULL)
	{
		ps->state = PURPLE_SOCKET_STATE_ERROR;
		return FALSE;
	}

	return TRUE;
}
Esempio n. 8
0
void LoginToSsiPortal(gpointer sodata)
{
    PurpleSslConnection *gsc;
    struct fetion_account_data *sip;
    sip = sodata;
    sip->registerstatus = 0;	//avoid reconnected error
    purple_debug_info("Fetion:", "LoginToSsiPortal\n");

    gsc = purple_ssl_connect(sip->account, sip->SsicServer,
                             PURPLE_SSL_DEFAULT_PORT,
                             (PurpleSslInputFunction) Ssi_cb, NULL, sip);
    g_return_if_fail(gsc != NULL);

    purple_debug_info("Fetion:", "SSL connected\n");

}
Esempio n. 9
0
static void okc_attempt_connection(OkCupidConnection *okconn)
{
	OkCupidAccount *oca = okconn->oca;

	oca->conns = g_slist_prepend(oca->conns, okconn);

	if (okconn->method & OKC_METHOD_SSL) {
		okconn->ssl_conn = purple_ssl_connect(oca->account, okconn->hostname,
				443, okc_post_or_get_ssl_connect_cb,
				okc_ssl_connection_error, okconn);
	} else {
		okconn->connect_data = purple_proxy_connect(NULL, oca->account,
				okconn->hostname, 80, okc_post_or_get_connect_cb, okconn);
	}

	return;
}
Esempio n. 10
0
void check_ssl_requests(PurpleAccount * acct)
{
	PurpleConnection *gc = purple_account_get_connection(acct);
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);

	char *host;
	int port;
	if (wconn->gsc == 0 && waAPI_hassslconnection(wconn->waAPI, &host, &port) > 0) {
		purple_debug_info("waprpl", "Establishing SSL connection to %s:%d\n", host, port);

		PurpleSslConnection *sslc = purple_ssl_connect(acct, host, port, waprpl_ssl_connected_cb, waprpl_ssl_cerr_cb, gc);
		if (sslc == 0) {
			waprpl_ssl_cerr_cb(0, 0, gc);
		} else {
			/* The Fd are not available yet, wait for connected callback */
			wconn->gsc = sslc;
		}
	}
}
Esempio n. 11
0
void
fb_mqtt_open(FbMqtt *mqtt, const gchar *host, gint port)
{
	FbMqttPrivate *priv;
	PurpleAccount *acc;

	g_return_if_fail(FB_IS_MQTT(mqtt));
	priv = mqtt->priv;

	acc = purple_connection_get_account(priv->gc);
	fb_mqtt_close(mqtt);
	priv->gsc = purple_ssl_connect(acc, host, port, fb_mqtt_cb_open,
	                               fb_mqtt_cb_open_error, mqtt);

	if (priv->gsc == NULL) {
		fb_mqtt_cb_open_error(NULL, 0, mqtt);
		return;
	}

	fb_mqtt_timeout(mqtt);
}
Esempio n. 12
0
static void
campfire_ssl_connect(CampfireConn * campfire,
		     G_GNUC_UNUSED PurpleInputCondition cond,
		     gboolean from_connection_callback)
{
	GList *first = NULL;
	CampfireSslTransaction *xaction = NULL;

	purple_debug_info("campfire", "%s\n", __FUNCTION__);
	if (!campfire) {
		return;
	} else {
		first = g_list_first(campfire->queue);
	}

	if (!first) {
		return;
	} else {
		xaction = first->data;
	}

	if (!xaction) {
		return;
	}

	if (!campfire->gsc) {
		purple_debug_info("campfire", "new ssl connection\n");
		campfire->gsc = purple_ssl_connect(campfire->account,
						   campfire->hostname,
						   443, (PurpleSslInputFunction)
						   (campfire_ssl_connect_cb),
						   campfire_ssl_failure,
						   campfire);
		purple_debug_info("campfire",
				  "new ssl connection kicked off.\n");
	} else {
		purple_debug_info("campfire", "previous ssl connection\n");
		/* we want to write our http request to the ssl connection
		 * WHENEVER this is called from the callback (meaning we've
		 * JUST NOW established the connection). OR when the first
		 * transaction is added to the queue on an OPEN ssl connection
		 */
		if (from_connection_callback
		    || g_list_length(campfire->queue) == 1) {
			/* campfire_ssl_handler is the ONLY input handler we
			 * EVER use So... if there is already an input handler
			 * present (inpa > 0), then we DON"T want to add another
			 * input handler.  Quite a few hours spent chasing bugs
			 * when multiple input handlers were added!
			 */
			if (campfire->gsc->inpa == 0) {
				purple_debug_info("campfire", "adding input\n");
				purple_ssl_input_add(campfire->gsc,
						     (PurpleSslInputFunction)
						     (campfire_ssl_handler),
						     campfire);
			}
			purple_debug_info("campfire",
					  "writing first request on ssl connection\n");
			purple_ssl_write(campfire->gsc,
					 xaction->http_request->str,
					 xaction->http_request->len);
		}
	}
	return;
}
Esempio n. 13
0
static void
nexus_login_written_cb(gpointer data, gint source, PurpleInputCondition cond)
{
	MsnNexus *nexus = data;
	MsnSession *session;
	int len;

	session = nexus->session;
	g_return_if_fail(session != NULL);

	if (nexus->input_handler == 0)
		/* TODO: Use purple_ssl_input_add()? */
		nexus->input_handler = purple_input_add(nexus->gsc->fd,
			PURPLE_INPUT_READ, nexus_login_written_cb, nexus);


	len = msn_ssl_read(nexus);

	if (len < 0 && errno == EAGAIN)
		return;
	else if (len < 0) {
		purple_input_remove(nexus->input_handler);
		nexus->input_handler = 0;
		g_free(nexus->read_buf);
		nexus->read_buf = NULL;
		nexus->read_len = 0;
		/* TODO: error handling */
		return;
	}

	if (g_strstr_len(nexus->read_buf, nexus->read_len,
			"\r\n\r\n") == NULL)
		return;

	purple_input_remove(nexus->input_handler);
	nexus->input_handler = 0;

	purple_ssl_close(nexus->gsc);
	nexus->gsc = NULL;

	pecan_log ("ssl buffer: [%s]", nexus->read_buf);

	if (strstr(nexus->read_buf, "HTTP/1.1 302") != NULL)
	{
		/* Redirect. */
		char *location, *c;

		location = strstr(nexus->read_buf, "Location: ");
		if (location == NULL)
		{
			g_free(nexus->read_buf);
			nexus->read_buf = NULL;
			nexus->read_len = 0;

			return;
		}
		location = strchr(location, ' ') + 1;

		if ((c = strchr(location, '\r')) != NULL)
			*c = '\0';

		/* Skip the http:// */
		if ((c = strchr(location, '/')) != NULL)
			location = c + 2;

		if ((c = strchr(location, '/')) != NULL)
		{
			g_free(nexus->login_path);
			nexus->login_path = g_strdup(c);

			*c = '\0';
		}

		g_free(nexus->login_host);
		nexus->login_host = g_strdup(location);

		nexus->gsc = purple_ssl_connect(session->account,
				nexus->login_host, PURPLE_SSL_DEFAULT_PORT,
				login_connect_cb, login_error_cb, nexus);
	}
	else if (strstr(nexus->read_buf, "HTTP/1.1 401 Unauthorized") != NULL)
	{
		const char *error;

		if ((error = strstr(nexus->read_buf, "WWW-Authenticate")) != NULL)
		{
			if ((error = strstr(error, "cbtxt=")) != NULL)
			{
				const char *c;
				char *temp;

				error += strlen("cbtxt=");

				if ((c = strchr(error, '\n')) == NULL)
					c = error + strlen(error);

				temp = g_strndup(error, c - error);
				error = purple_url_decode(temp);
				g_free(temp);
				if ((temp = strstr(error, " Do one of the following or try again:")) != NULL)
					*temp = '\0';
			}
		}

		msn_session_set_error(session, MSN_ERROR_AUTH, error);
	}
	else if (strstr(nexus->read_buf, "HTTP/1.1 503 Service Unavailable"))
	{
		msn_session_set_error(session, MSN_ERROR_SERV_UNAVAILABLE, NULL);
	}
	else if (strstr(nexus->read_buf, "HTTP/1.1 200 OK"))
	{
		char *base, *c;
		char *login_params;

#if 0
		/* All your base are belong to us. */
		base = buffer;

		/* For great cookie! */
		while ((base = strstr(base, "Set-Cookie: ")) != NULL)
		{
			base += strlen("Set-Cookie: ");

			c = strchr(base, ';');

			session->login_cookies =
				g_list_append(session->login_cookies,
							  g_strndup(base, c - base));
		}
#endif

		base  = strstr(nexus->read_buf, "Authentication-Info: ");

		g_return_if_fail(base != NULL);

		base  = strstr(base, "from-PP='");
		base += strlen("from-PP='");
		c     = strchr(base, '\'');

		login_params = g_strndup(base, c - base);

		msn_got_login_params(session, login_params);

		g_free(login_params);

		msn_nexus_destroy(nexus);
		session->nexus = NULL;
		return;
	}

	g_free(nexus->read_buf);
	nexus->read_buf = NULL;
	nexus->read_len = 0;

}
Esempio n. 14
0
static void
nexus_connect_written_cb(gpointer data, gint source, PurpleInputCondition cond)
{
	MsnNexus *nexus = data;
	int len;
	char *da_login;
	char *base, *c;

	if (nexus->input_handler == 0)
		/* TODO: Use purple_ssl_input_add()? */
		nexus->input_handler = purple_input_add(nexus->gsc->fd,
			PURPLE_INPUT_READ, nexus_connect_written_cb, nexus);

	/* Get the PassportURLs line. */
	len = msn_ssl_read(nexus);

	if (len < 0 && errno == EAGAIN)
		return;
	else if (len < 0) {
		purple_input_remove(nexus->input_handler);
		nexus->input_handler = 0;
		g_free(nexus->read_buf);
		nexus->read_buf = NULL;
		nexus->read_len = 0;
		/* TODO: error handling */
		return;
	}

	if (g_strstr_len(nexus->read_buf, nexus->read_len,
			"\r\n\r\n") == NULL)
		return;

	purple_input_remove(nexus->input_handler);
	nexus->input_handler = 0;

	base = strstr(nexus->read_buf, "PassportURLs");

	if (base == NULL)
	{
		g_free(nexus->read_buf);
		nexus->read_buf = NULL;
		nexus->read_len = 0;
		return;
	}

	if ((da_login = strstr(base, "DALogin="******"DALogin=" */
		da_login += 8;

		if ((c = strchr(da_login, ',')) != NULL)
			*c = '\0';

		if ((c = strchr(da_login, '/')) != NULL)
		{
			nexus->login_path = g_strdup(c);
			*c = '\0';
		}

		nexus->login_host = g_strdup(da_login);
	}

	g_free(nexus->read_buf);
	nexus->read_buf = NULL;
	nexus->read_len = 0;

	purple_ssl_close(nexus->gsc);

	/* Now begin the connection to the login server. */
	nexus->gsc = purple_ssl_connect(nexus->session->account,
			nexus->login_host, PURPLE_SSL_DEFAULT_PORT,
			login_connect_cb, login_error_cb, nexus);
}
Esempio n. 15
0
static gboolean
msn_soap_connection_run(gpointer data)
{
	MsnSoapConnection *conn = data;
	MsnSoapRequest *req = g_queue_peek_head(conn->queue);

	conn->run_timer = 0;

	if (req) {
		if (conn->ssl == NULL) {
			conn->ssl = purple_ssl_connect(conn->session->account, conn->host,
				443, msn_soap_connected_cb, msn_soap_error_cb, conn);
		} else if (conn->connected) {
			int len = -1;
			char *body = xmlnode_to_str(req->message->xml, &len);
			GSList *iter;

			g_queue_pop_head(conn->queue);

			conn->buf = g_string_new("");

			g_string_append_printf(conn->buf,
				"POST /%s HTTP/1.1\r\n"
				"SOAPAction: %s\r\n"
				"Content-Type:text/xml; charset=utf-8\r\n"
				"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
				"Accept: */*\r\n"
				"Host: %s\r\n"
				"Content-Length: %d\r\n"
				"Connection: Keep-Alive\r\n"
				"Cache-Control: no-cache\r\n",
				req->path, req->message->action ? req->message->action : "",
				conn->host, len);

			for (iter = req->message->headers; iter; iter = iter->next) {
				g_string_append(conn->buf, (char *)iter->data);
				g_string_append(conn->buf, "\r\n");
			}

			g_string_append(conn->buf, "\r\n");
			g_string_append(conn->buf, body);

			if (req->secure && !purple_debug_is_unsafe())
				purple_debug_misc("soap", "Sending secure request.\n");
			else
				purple_debug_misc("soap", "%s\n", conn->buf->str);

			conn->handled_len = 0;
			conn->current_request = req;

			if (conn->event_handle)
				purple_input_remove(conn->event_handle);
			conn->event_handle = purple_input_add(conn->ssl->fd,
				PURPLE_INPUT_WRITE, msn_soap_write_cb, conn);
			if (!msn_soap_write_cb_internal(conn, conn->ssl->fd, PURPLE_INPUT_WRITE, TRUE)) {
				/* Not connected => reconnect and retry */
				purple_debug_info("soap", "not connected, reconnecting\n");

				conn->connected = FALSE;
				conn->current_request = NULL;
				msn_soap_connection_sanitize(conn, FALSE);

				g_queue_push_head(conn->queue, req);
				conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
			}

			g_free(body);
		}
	}

	return FALSE;
}
Esempio n. 16
0
static void sevencup_attempt_connection(SevenCupConnection *scon)
{
	gboolean is_proxy = FALSE;
	SevenCupAccount *sa = scon->sa;
	PurpleProxyInfo *proxy_info = NULL;

	if (sa && sa->account && !(scon->method & STEAM_METHOD_SSL))
	{
		proxy_info = purple_proxy_get_setup(sa->account);
		if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_USE_GLOBAL)
			proxy_info = purple_global_proxy_get_info();
		if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_HTTP)
		{
			is_proxy = TRUE;
		}	
	}

#if 0
	/* Connection to attempt retries.  This code doesn't work perfectly, but
	 * remains here for future reference if needed */
	if (time(NULL) - scon->request_time > 5) {
		/* We've continuously tried to remake this connection for a 
		 * bit now.  It isn't happening, sadly.  Time to die. */
		purple_debug_error("7cups", "could not connect after retries\n");
		sevencup_fatal_connection_cb(scon);
		return;
	}

	purple_debug_info("7cups", "making connection attempt\n");

	/* TODO: If we're retrying the connection, consider clearing the cached
	 * DNS value.  This will require some juggling with the hostname param */
	/* TODO/FIXME: This retries almost instantenously, which in some cases
	 * runs at blinding speed.  Slow it down. */
	/* TODO/FIXME: this doesn't retry properly on non-ssl connections */
#endif
	
	sa->conns = g_slist_prepend(sa->conns, scon);

	/*
	 * Do a separate DNS lookup for the given host name and cache it
	 * for next time.
	 *
	 * TODO: It would be better if we did this before we call
	 *       purple_proxy_connect(), so we could re-use the result.
	 *       Or even better: Use persistent HTTP connections for servers
	 *       that we access continually.
	 *
	 * TODO: This cache of the hostname<-->IP address does not respect
	 *       the TTL returned by the DNS server.  We should expire things
	 *       from the cache after some amount of time.
	 */
	if (!is_proxy && !(scon->method & STEAM_METHOD_SSL) && !g_hostname_is_ip_address(scon->hostname))
	{
		/* Don't do this for proxy connections, since proxies do the DNS lookup */
		gchar *host_ip;

		host_ip = g_hash_table_lookup(sa->hostname_ip_cache, scon->hostname);
		if (host_ip != NULL) {
			g_free(scon->hostname);
			scon->hostname = g_strdup(host_ip);
		} else if (sa->account && !sa->account->disconnecting) {
			GSList *host_lookup_list = NULL;
			PurpleDnsQueryData *query;

			host_lookup_list = g_slist_prepend(
					host_lookup_list, g_strdup(scon->hostname));
			host_lookup_list = g_slist_prepend(
					host_lookup_list, sa);

			query = purple_dnsquery_a(
#if PURPLE_VERSION_CHECK(3, 0, 0)
					scon->sa->account,
#endif
					scon->hostname, 80,
					sevencup_host_lookup_cb, host_lookup_list);
			sa->dns_queries = g_slist_prepend(sa->dns_queries, query);
			host_lookup_list = g_slist_append(host_lookup_list, query);
		}
	}

	if (scon->method & STEAM_METHOD_SSL) {
		scon->ssl_conn = purple_ssl_connect(sa->account, scon->hostname,
				443, sevencup_post_or_get_ssl_connect_cb,
				sevencup_ssl_connection_error, scon);
	} else {
		scon->connect_data = purple_proxy_connect(NULL, sa->account,
				scon->hostname, 80, sevencup_post_or_get_connect_cb, scon);
	}
	
	scon->timeout_watcher = purple_timeout_add_seconds(120, sevencup_connection_timedout, scon);

	return;
}
Esempio n. 17
0
static void
pb_start_socket(PushBulletAccount *pba)
{
	pba->websocket = purple_ssl_connect(pba->account, "stream.pushbullet.com", 443, pb_socket_connected, pb_socket_failed, pba);
}