Exemplo n.º 1
0
PurpleDnsQueryData *
purple_dnsquery_a(const char *hostname, int port,
				PurpleDnsQueryConnectFunction callback, gpointer data)
{
	PurpleDnsQueryData *query_data;

	g_return_val_if_fail(hostname != NULL, NULL);
	g_return_val_if_fail(port	  != 0, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	query_data = g_new(PurpleDnsQueryData, 1);
	query_data->hostname = g_strdup(hostname);
	g_strstrip(query_data->hostname);
	query_data->port = port;
	query_data->callback = callback;
	query_data->data = data;

	if (strlen(query_data->hostname) == 0)
	{
		purple_dnsquery_destroy(query_data);
		g_return_val_if_reached(NULL);
	}

	/* Don't call the callback before returning */
	query_data->timeout = purple_timeout_add(0, resolve_host, query_data);

	return query_data;
}
Exemplo n.º 2
0
static void om_close(PurpleConnection *pc)
{
	OmegleAccount *oma;
	GList *ims;
	
	g_return_if_fail(pc != NULL);
	g_return_if_fail(pc->proto_data != NULL);
	
	ims = purple_get_ims();
	//TODO: Loop through all im's and disconnect them all
	
	oma = pc->proto_data;
	
	while (oma->conns != NULL)
		om_connection_destroy(oma->conns->data);
	while (oma->dns_queries != NULL) {
		PurpleDnsQueryData *dns_query = oma->dns_queries->data;
		oma->dns_queries = g_slist_remove(oma->dns_queries, dns_query);
		purple_dnsquery_destroy(dns_query);
	}

	g_hash_table_destroy(oma->cookie_table);
	g_hash_table_destroy(oma->hostname_ip_cache);
	
	g_free(oma);
}
Exemplo n.º 3
0
PurpleDnsQueryData *
purple_dnsquery_a(const char *hostname, int port,
				PurpleDnsQueryConnectFunction callback, gpointer data)
{
	PurpleDnsQueryData *query_data;

	g_return_val_if_fail(hostname != NULL, NULL);
	g_return_val_if_fail(port	  != 0, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	query_data = g_new(PurpleDnsQueryData, 1);
	query_data->hostname = g_strdup(hostname);
	g_strstrip(query_data->hostname);
	query_data->port = port;
	query_data->callback = callback;
	query_data->data = data;
	query_data->resolver = NULL;

	if (strlen(query_data->hostname) == 0)
	{
		purple_dnsquery_destroy(query_data);
		g_return_val_if_reached(NULL);
	}

	queued_requests = g_slist_append(queued_requests, query_data);

	purple_debug_info("dns", "DNS query for '%s' queued\n", query_data->hostname);

	query_data->timeout = purple_timeout_add(0, resolve_host, query_data);

	return query_data;
}
Exemplo n.º 4
0
static void
purple_dnsquery_resolved(PurpleDnsQueryData *query_data, GSList *hosts)
{
	purple_debug_info("dnsquery", "IP resolved for %s\n", query_data->hostname);
	if (query_data->callback != NULL)
		query_data->callback(hosts, query_data->data, NULL);
	else
	{
		/*
		 * Callback is a required parameter, but it can get set to
		 * NULL if we cancel a thread-based DNS lookup.  So we need
		 * to free hosts.
		 */
		while (hosts != NULL)
		{
			hosts = g_slist_remove(hosts, hosts->data);
			g_free(hosts->data);
			hosts = g_slist_remove(hosts, hosts->data);
		}
	}

#ifdef PURPLE_DNSQUERY_USE_FORK
	/*
	 * Add the resolver to the list of available resolvers, and set it
	 * to NULL so that it doesn't get destroyed along with the query_data
	 */
	if (query_data->resolver)
	{
		free_dns_children = g_slist_prepend(free_dns_children, query_data->resolver);
		query_data->resolver = NULL;
	}
#endif /* PURPLE_DNSQUERY_USE_FORK */

	purple_dnsquery_destroy(query_data);
}
Exemplo n.º 5
0
PurpleDnsQueryData *
purple_dnsquery_a_account(PurpleAccount *account, const char *hostname, int port,
				PurpleDnsQueryConnectFunction callback, gpointer data)
{
	PurpleDnsQueryData *query_data;

	g_return_val_if_fail(hostname != NULL, NULL);
	g_return_val_if_fail(port != 0, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	purple_debug_info("dnsquery", "Performing DNS lookup for %s\n", hostname);

	query_data = g_new0(PurpleDnsQueryData, 1);
	query_data->hostname = g_strdup(hostname);
	g_strstrip(query_data->hostname);
	query_data->port = port;
	query_data->callback = callback;
	query_data->data = data;
	query_data->account = account;

	if (*query_data->hostname == '\0')
	{
		purple_dnsquery_destroy(query_data);
		g_return_val_if_reached(NULL);
	}

	query_data->timeout = purple_timeout_add(0, initiate_resolving, query_data);

	return query_data;
}
Exemplo n.º 6
0
static void
purple_dnsquery_failed(PurpleDnsQueryData *query_data, const gchar *error_message)
{
	purple_debug_info("dnsquery", "%s\n", error_message);
	if (query_data->callback != NULL)
		query_data->callback(NULL, query_data->data, error_message);
	purple_dnsquery_destroy(query_data);
}
Exemplo n.º 7
0
/* clean up qq_data structure and all its components
 * always used before a redirectly connection */
void qq_disconnect(PurpleConnection *gc)
{
	qq_data *qd;

	g_return_if_fail(gc != NULL && gc->proto_data != NULL);
	qd = (qq_data *) gc->proto_data;

	purple_debug_info("QQ", "Disconnecting...\n");

	if (qd->network_watcher > 0) {
		purple_debug_info("QQ", "Remove network watcher\n");
		purple_timeout_remove(qd->network_watcher);
		qd->network_watcher = 0;
	}

	/* finish  all I/O */
	if (qd->fd >= 0 && qd->is_login) {
		qq_request_logout(gc);
	}

	/* not connected */
	if (qd->conn_data != NULL) {
		purple_debug_info("QQ", "Connect cancel\n");
		purple_proxy_connect_cancel(qd->conn_data);
		qd->conn_data = NULL;
	}
#ifndef purple_proxy_connect_udp
	if (qd->udp_can_write_handler) {
		purple_input_remove(qd->udp_can_write_handler);
		qd->udp_can_write_handler = 0;
	}
	if (qd->udp_query_data != NULL) {
		purple_debug_info("QQ", "destroy udp_query_data\n");
		purple_dnsquery_destroy(qd->udp_query_data);
		qd->udp_query_data = NULL;
	}
#endif
	connection_free_all(qd);
	qd->fd = -1;

	qq_trans_remove_all(gc);

	memset(qd->ld.random_key, 0, sizeof(qd->ld.random_key));
	memset(qd->ld.pwd_md5, 0, sizeof(qd->ld.pwd_md5));
	memset(qd->ld.pwd_twice_md5, 0, sizeof(qd->ld.pwd_twice_md5));
	memset(qd->ld.login_key, 0, sizeof(qd->ld.login_key));
	memset(qd->session_key, 0, sizeof(qd->session_key));
	memset(qd->session_md5, 0, sizeof(qd->session_md5));

	qd->my_local_ip.s_addr = 0;
	qd->my_local_port = 0;
	qd->my_ip.s_addr = 0;
	qd->my_port = 0;

	qq_room_data_free_all(gc);
	qq_buddy_data_free_all(gc);
}
Exemplo n.º 8
0
static void
skypeweb_close(PurpleConnection *pc)
{
	SkypeWebAccount *sa;
	
	g_return_if_fail(pc != NULL);
	
	sa = purple_connection_get_protocol_data(pc);
	g_return_if_fail(sa != NULL);
	
	purple_timeout_remove(sa->authcheck_timeout);
	purple_timeout_remove(sa->poll_timeout);
	purple_timeout_remove(sa->watchdog_timeout);

	skypeweb_logout(sa);
	purple_signal_disconnect(purple_conversations_get_handle(), "conversation-updated", pc, PURPLE_CALLBACK(skypeweb_mark_conv_seen));
	purple_debug_info("skypeweb", "destroying %d waiting connections\n",
					  g_queue_get_length(sa->waiting_conns));
	
	while (!g_queue_is_empty(sa->waiting_conns))
		skypeweb_connection_destroy(g_queue_pop_tail(sa->waiting_conns));
	g_queue_free(sa->waiting_conns);
	
	purple_debug_info("skypeweb", "destroying %d incomplete connections\n",
			g_slist_length(sa->conns));

	while (sa->conns != NULL)
		skypeweb_connection_destroy(sa->conns->data);
		
	while (sa->dns_queries != NULL) {
		PurpleDnsQueryData *dns_query = sa->dns_queries->data;
		purple_debug_info("skypeweb", "canceling dns query for %s\n",
					purple_dnsquery_get_host(dns_query));
		sa->dns_queries = g_slist_remove(sa->dns_queries, dns_query);
		purple_dnsquery_destroy(dns_query);
	}
	
	g_hash_table_destroy(sa->sent_messages_hash);
	g_hash_table_destroy(sa->cookie_table);
	g_hash_table_destroy(sa->hostname_ip_cache);
	
	g_free(sa->messages_host);
	g_free(sa->skype_token);
	g_free(sa->registration_token);
	g_free(sa->endpoint);
	g_free(sa->username);
	g_free(sa);
}
Exemplo n.º 9
0
void gfire_p2p_natcheck_destroy(gfire_p2p_natcheck *p_nat)
{
	if(!p_nat)
		return;

	if(p_nat->timeout)
		g_source_remove(p_nat->timeout);

	if(p_nat->dnsdata)
		purple_dnsquery_destroy(p_nat->dnsdata);

	if(p_nat->prpl_inpa)
		purple_input_remove(p_nat->prpl_inpa);

	g_free(p_nat);
}
Exemplo n.º 10
0
static void
purple_dnsquery_resolved(PurpleDnsQueryData *query_data, GSList *hosts)
{
	purple_debug_info("dnsquery", "IP resolved for %s\n", query_data->hostname);
	if (query_data->callback != NULL)
		query_data->callback(hosts, query_data->data, NULL);
	else
	{
		/*
		 * Callback is a required parameter, but it can get set to
		 * NULL if we cancel a thread-based DNS lookup.  So we need
		 * to free hosts.
		 */
		while (hosts != NULL)
		{
			hosts = g_slist_remove(hosts, hosts->data);
			g_free(hosts->data);
			hosts = g_slist_remove(hosts, hosts->data);
		}
	}

	purple_dnsquery_destroy(query_data);
}
Exemplo n.º 11
0
static void
jabber_google_jingle_info_common(JabberStream *js, const char *from,
                                 JabberIqType type, xmlnode *query)
{
	const xmlnode *stun = xmlnode_get_child(query, "stun");
	const xmlnode *relay = xmlnode_get_child(query, "relay");
	gchar *my_bare_jid;

	/*
	 * Make sure that random people aren't sending us STUN servers. Per
	 * http://code.google.com/apis/talk/jep_extensions/jingleinfo.html, these
	 * stanzas are stamped from our bare JID.
	 */
	if (from) {
		my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
		if (!purple_strequal(from, my_bare_jid)) {
			purple_debug_warning("jabber", "got google:jingleinfo with invalid from (%s)\n",
			                  from);
			g_free(my_bare_jid);
			return;
		}

		g_free(my_bare_jid);
	}

	if (type == JABBER_IQ_ERROR || type == JABBER_IQ_GET)
		return;

	purple_debug_info("jabber", "got google:jingleinfo\n");

	if (stun) {
		xmlnode *server = xmlnode_get_child(stun, "server");

		if (server) {
			const gchar *host = xmlnode_get_attrib(server, "host");
			const gchar *udp = xmlnode_get_attrib(server, "udp");

			if (host && udp) {
				PurpleAccount *account;
				int port = atoi(udp);
				/* if there, would already be an ongoing query,
				 cancel it */
				if (js->stun_query)
					purple_dnsquery_destroy(js->stun_query);

				account = purple_connection_get_account(js->gc);
				js->stun_query = purple_dnsquery_a_account(account, host, port,
					jabber_google_stun_lookup_cb, js);
			}
		}
	}

	if (relay) {
		xmlnode *token = xmlnode_get_child(relay, "token");
		xmlnode *server = xmlnode_get_child(relay, "server");

		if (token) {
			gchar *relay_token = xmlnode_get_data(token);

			/* we let js own the string returned from xmlnode_get_data */
			js->google_relay_token = relay_token;
		}

		if (server) {
			js->google_relay_host =
				g_strdup(xmlnode_get_attrib(server, "host"));
		}
	}
}
Exemplo n.º 12
0
static void fb_close(PurpleConnection *pc)
{
	FacebookAccount *fba;
	gchar *postdata;
	GSList *buddies;

	purple_debug_info("facebook", "disconnecting account\n");

	g_return_if_fail(pc != NULL);
	g_return_if_fail(pc->proto_data != NULL);
	
	fba = pc->proto_data;

	if ( fba == NULL )		//VOXOX - JRT - 2009.10.12 - Prevent crash when network is lost or resuming from hibernation.
		return;

	purple_debug_info("facebook", "unloading plugin\n");

	/* destroy blist subsystem */
	fb_blist_destroy(fba);

	/* destroy conversation subsystem */
	fb_conversation_destroy(fba);
	buddies = purple_find_buddies(fba->account, NULL);
	while(buddies) {
		PurpleBuddy *b = buddies->data;
		fb_buddy_free(b);
		buddies = g_slist_delete_link(buddies, buddies);
	}

	/* Tell Facebook that we've logged out. */
	/*
	 * TODO
	 * This doesn't actually work because the request is non-blocking
	 * and we're in the process of logging out.  So we start making a
	 * connection but then libpurple immediately cancels the attempt
	 * and frees everything.
	 *
	 * There are two ways to fix this:
	 * 1. We could make this request, but not pass in fba or reference
	 *    any other data.  The request could complete normally even
	 *    after this account has logged out, since it really doesn't
	 *    need access to the PurpleConnection or the FacebookAccount.
	 *
	 * 2. The close prpl callback could be changed in libpurple so that
	 *    protocol plugins can have a chance to make network requests
	 *    and do other long cleanup operations.  So the call to
	 *    prpl->close() would become asynchronous.  It tells the
	 *    protocol plugin to begin the shutdown sequence, and the
	 *    protocol plugin tells the core when it's finished.
	 */
	if (fba->post_form_id)
		postdata = g_strdup_printf(
				"visibility=false&post_form_id=%s&"
				"fb_dtsg=%s&post_form_id_source=AsyncRequest&"
				"__a=1",
				fba->post_form_id, fba->dtsg);
	else
		postdata = g_strdup("visibility=false");
	fb_post_or_get(fba, FB_METHOD_POST, NULL, "/ajax/chat/settings.php",
			postdata, NULL, NULL, FALSE);
	g_free(postdata);

	if (fba->friend_request_timer) {
		purple_timeout_remove(fba->friend_request_timer);
	}
	if (fba->notifications_timer) {
		purple_timeout_remove(fba->notifications_timer);
	}
	if (fba->new_messages_check_timer) {
		purple_timeout_remove(fba->new_messages_check_timer);
	}
	if (fba->perpetual_messages_timer) {
		purple_timeout_remove(fba->perpetual_messages_timer);
	}

	purple_debug_info("facebook", "destroying %d incomplete connections\n",
			g_slist_length(fba->conns));

	while (fba->conns != NULL)
		fb_connection_destroy(fba->conns->data);

	while (fba->dns_queries != NULL) {
		PurpleDnsQueryData *dns_query = fba->dns_queries->data;
		purple_debug_info("facebook", "canceling dns query for %s\n",
					purple_dnsquery_get_host(dns_query));
		fba->dns_queries = g_slist_remove(fba->dns_queries, dns_query);
		purple_dnsquery_destroy(dns_query);
	}
	
	if (fba->resending_messages != NULL) {
		fb_cancel_resending_messages(fba);
	}

	//VOXOX - JRT - 2009.10.13 - I know we are deleting fba anyway, but since other threads may also be accessing this,
	//							 it helps reduce crashes due to freed memory ptrs.  (There is no thread syncing to control this better).
	g_hash_table_destroy(fba->cookie_table);

	g_hash_table_destroy(fba->hostname_ip_cache);

	g_hash_table_destroy(fba->auth_buddies);

	g_free(fba->post_form_id);
	g_free(fba->dtsg);
	g_free(fba->channel_number);
	g_free(fba->last_status_message);
	g_free(fba->extra_challenge);
	g_free(fba->captcha_session);
	g_free(fba->persist_data);
	g_free(fba);

}