diff libpurple/connection.c @ 15853:c5487dd19e61

merge of '31ed92ba1b530f050510b4958686e3013ba4176c' and '41f65a78d919384ad599d73c656a367d92292a41'
author Evan Schoenberg <evan.s@dreskin.net>
date Tue, 20 Mar 2007 14:37:22 +0000
parents 5198bd455160 2edbd4fede72
children
line wrap: on
line diff
--- a/libpurple/connection.c	Tue Mar 20 14:37:16 2007 +0000
+++ b/libpurple/connection.c	Tue Mar 20 14:37:22 2007 +0000
@@ -2,9 +2,9 @@
  * @file connection.c Connection API
  * @ingroup core
  *
- * gaim
+ * purple
  *
- * Gaim is the legal property of its developers, whose names are too numerous
+ * Purple is the legal property of its developers, whose names are too numerous
  * to list here.  Please refer to the COPYRIGHT file distributed with this
  * source distribution.
  *
@@ -39,18 +39,18 @@
 
 static GList *connections = NULL;
 static GList *connections_connecting = NULL;
-static GaimConnectionUiOps *connection_ui_ops = NULL;
+static PurpleConnectionUiOps *connection_ui_ops = NULL;
 
 static int connections_handle;
 
 static gboolean
 send_keepalive(gpointer data)
 {
-	GaimConnection *gc = data;
-	GaimPluginProtocolInfo *prpl_info = NULL;
+	PurpleConnection *gc = data;
+	PurplePluginProtocolInfo *prpl_info = NULL;
 
 	if (gc != NULL && gc->prpl != NULL)
-		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
 
 	if (prpl_info && prpl_info->keepalive)
 		prpl_info->keepalive(gc);
@@ -59,51 +59,51 @@
 }
 
 static void
-update_keepalive(GaimConnection *gc, gboolean on)
+update_keepalive(PurpleConnection *gc, gboolean on)
 {
-	GaimPluginProtocolInfo *prpl_info = NULL;
+	PurplePluginProtocolInfo *prpl_info = NULL;
 
 	if (gc != NULL && gc->prpl != NULL)
-		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
 
 	if (!prpl_info || !prpl_info->keepalive)
 		return;
 
 	if (on && !gc->keepalive)
 	{
-		gaim_debug_info("connection", "Activating keepalive.\n");
-		gc->keepalive = gaim_timeout_add(30000, send_keepalive, gc);
+		purple_debug_info("connection", "Activating keepalive.\n");
+		gc->keepalive = purple_timeout_add(30000, send_keepalive, gc);
 	}
 	else if (!on && gc->keepalive > 0)
 	{
-		gaim_debug_info("connection", "Deactivating keepalive.\n");
-		gaim_timeout_remove(gc->keepalive);
+		purple_debug_info("connection", "Deactivating keepalive.\n");
+		purple_timeout_remove(gc->keepalive);
 		gc->keepalive = 0;
 	}
 }
 
 void
-gaim_connection_new(GaimAccount *account, gboolean regist, const char *password)
+purple_connection_new(PurpleAccount *account, gboolean regist, const char *password)
 {
-	GaimConnection *gc;
-	GaimPlugin *prpl;
-	GaimPluginProtocolInfo *prpl_info;
+	PurpleConnection *gc;
+	PurplePlugin *prpl;
+	PurplePluginProtocolInfo *prpl_info;
 
 	g_return_if_fail(account != NULL);
 
-	if (!gaim_account_is_disconnected(account))
+	if (!purple_account_is_disconnected(account))
 		return;
 
-	prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
+	prpl = purple_find_prpl(purple_account_get_protocol_id(account));
 
 	if (prpl != NULL)
-		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 	else {
 		gchar *message;
 
 		message = g_strdup_printf(_("Missing protocol plugin for %s"),
-			gaim_account_get_username(account));
-		gaim_notify_error(NULL, regist ? _("Registration Error") :
+			purple_account_get_username(account));
+		purple_notify_error(NULL, regist ? _("Registration Error") :
 						  _("Connection Error"), message, NULL);
 		g_free(message);
 		return;
@@ -120,28 +120,28 @@
 			!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
 			!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
 		{
-			gaim_debug_error("connection", "Can not connect to account %s without "
-							 "a password.\n", gaim_account_get_username(account));
+			purple_debug_error("connection", "Can not connect to account %s without "
+							 "a password.\n", purple_account_get_username(account));
 			return;
 		}
 	}
 
-	gc = g_new0(GaimConnection, 1);
-	GAIM_DBUS_REGISTER_POINTER(gc, GaimConnection);
+	gc = g_new0(PurpleConnection, 1);
+	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);
 
 	gc->prpl = prpl;
 	if ((password != NULL) && (*password != '\0'))
 		gc->password = g_strdup(password);
-	gaim_connection_set_account(gc, account);
-	gaim_connection_set_state(gc, GAIM_CONNECTING);
+	purple_connection_set_account(gc, account);
+	purple_connection_set_state(gc, PURPLE_CONNECTING);
 	connections = g_list_append(connections, gc);
-	gaim_account_set_connection(account, gc);
+	purple_account_set_connection(account, gc);
 
-	gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc);
+	purple_signal_emit(purple_connections_get_handle(), "signing-on", gc);
 
 	if (regist)
 	{
-		gaim_debug_info("connection", "Registering.  gc = %p\n", gc);
+		purple_debug_info("connection", "Registering.  gc = %p\n", gc);
 
 		/* set this so we don't auto-reconnect after registering */
 		gc->wants_to_die = TRUE;
@@ -150,67 +150,67 @@
 	}
 	else
 	{
-		gaim_debug_info("connection", "Connecting. gc = %p\n", gc);
+		purple_debug_info("connection", "Connecting. gc = %p\n", gc);
 
-		gaim_signal_emit(gaim_accounts_get_handle(), "account-connecting", account);
+		purple_signal_emit(purple_accounts_get_handle(), "account-connecting", account);
 		prpl_info->login(account);
 	}
 }
 
 void
-gaim_connection_destroy(GaimConnection *gc)
+purple_connection_destroy(PurpleConnection *gc)
 {
-	GaimAccount *account;
+	PurpleAccount *account;
 	GSList *buddies, *tmp;
 #if 0
 	GList *wins;
 #endif
-	GaimPluginProtocolInfo *prpl_info = NULL;
+	PurplePluginProtocolInfo *prpl_info = NULL;
 	gboolean remove = FALSE;
 
 	g_return_if_fail(gc != NULL);
 
-	account = gaim_connection_get_account(gc);
+	account = purple_connection_get_account(gc);
 
-	gaim_debug_info("connection", "Disconnecting connection %p\n", gc);
+	purple_debug_info("connection", "Disconnecting connection %p\n", gc);
 
-	if (gaim_connection_get_state(gc) != GAIM_CONNECTING)
+	if (purple_connection_get_state(gc) != PURPLE_CONNECTING)
 		remove = TRUE;
 
-	gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc);
+	purple_signal_emit(purple_connections_get_handle(), "signing-off", gc);
 
 	while (gc->buddy_chats)
 	{
-		GaimConversation *b = gc->buddy_chats->data;
+		PurpleConversation *b = gc->buddy_chats->data;
 
 		gc->buddy_chats = g_slist_remove(gc->buddy_chats, b);
-		gaim_conv_chat_left(GAIM_CONV_CHAT(b));
+		purple_conv_chat_left(PURPLE_CONV_CHAT(b));
 	}
 
 	update_keepalive(gc, FALSE);
 
-	gaim_proxy_connect_cancel_with_handle(gc);
+	purple_proxy_connect_cancel_with_handle(gc);
 
-	prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
 	if (prpl_info->close)
 		(prpl_info->close)(gc);
 
 	/* Clear out the proto data that was freed in the prpl close method*/
-	buddies = gaim_find_buddies(account, NULL);
+	buddies = purple_find_buddies(account, NULL);
 	for (tmp = buddies; tmp; tmp = tmp->next) {
-		GaimBuddy *buddy = tmp->data;
+		PurpleBuddy *buddy = tmp->data;
 		buddy->proto_data = NULL;
 	}
 	g_slist_free(buddies);
 
 	connections = g_list_remove(connections, gc);
 
-	gaim_connection_set_state(gc, GAIM_DISCONNECTED);
+	purple_connection_set_state(gc, PURPLE_DISCONNECTED);
 
 	if (remove)
-		gaim_blist_remove_account(account);
+		purple_blist_remove_account(account);
 
-	gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc);
+	purple_signal_emit(purple_connections_get_handle(), "signed-off", gc);
 
 #if 0
 	/* see comment later in file on if 0'd same code */
@@ -218,28 +218,28 @@
 	 * XXX This is a hack! Remove this and replace it with a better event
 	 *     notification system.
 	 */
-	for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) {
-		GaimConvWindow *win = (GaimConvWindow *)wins->data;
-		gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0),
-								 GAIM_CONV_ACCOUNT_OFFLINE);
+	for (wins = purple_get_windows(); wins != NULL; wins = wins->next) {
+		PurpleConvWindow *win = (PurpleConvWindow *)wins->data;
+		purple_conversation_update(purple_conv_window_get_conversation_at(win, 0),
+								 PURPLE_CONV_ACCOUNT_OFFLINE);
 	}
 #endif
 
-	gaim_account_request_close_with_account(account);
-	gaim_request_close_with_handle(gc);
-	gaim_notify_close_with_handle(gc);
+	purple_account_request_close_with_account(account);
+	purple_request_close_with_handle(gc);
+	purple_notify_close_with_handle(gc);
 
-	gaim_debug_info("connection", "Destroying connection %p\n", gc);
+	purple_debug_info("connection", "Destroying connection %p\n", gc);
 
-	gaim_account_set_connection(account, NULL);
+	purple_account_set_connection(account, NULL);
 
 	g_free(gc->password);
 	g_free(gc->display_name);
 
 	if (gc->disconnect_timeout)
-		gaim_timeout_remove(gc->disconnect_timeout);
+		purple_timeout_remove(gc->disconnect_timeout);
 
-	GAIM_DBUS_UNREGISTER_POINTER(gc);
+	PURPLE_DBUS_UNREGISTER_POINTER(gc);
 	g_free(gc);
 }
 
@@ -254,9 +254,9 @@
  */
 
 void
-gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state)
+purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state)
 {
-	GaimConnectionUiOps *ops;
+	PurpleConnectionUiOps *ops;
 
 	g_return_if_fail(gc != NULL);
 
@@ -265,36 +265,36 @@
 
 	gc->state = state;
 
-	ops = gaim_connections_get_ui_ops();
+	ops = purple_connections_get_ui_ops();
 
-	if (gc->state == GAIM_CONNECTING) {
+	if (gc->state == PURPLE_CONNECTING) {
 		connections_connecting = g_list_append(connections_connecting, gc);
 	}
 	else {
 		connections_connecting = g_list_remove(connections_connecting, gc);
 	}
 
-	if (gc->state == GAIM_CONNECTED) {
-		GaimAccount *account;
-		GaimPresence *presence;
+	if (gc->state == PURPLE_CONNECTED) {
+		PurpleAccount *account;
+		PurplePresence *presence;
 
-		account = gaim_connection_get_account(gc);
-		presence = gaim_account_get_presence(account);
+		account = purple_connection_get_account(gc);
+		presence = purple_account_get_presence(account);
 
 		/* Set the time the account came online */
-		gaim_presence_set_login_time(presence, time(NULL));
+		purple_presence_set_login_time(presence, time(NULL));
 
-		if (gaim_prefs_get_bool("/core/logging/log_system"))
+		if (purple_prefs_get_bool("/core/logging/log_system"))
 		{
-			GaimLog *log = gaim_account_get_log(account, TRUE);
+			PurpleLog *log = purple_account_get_log(account, TRUE);
 
 			if (log != NULL)
 			{
 				char *msg = g_strdup_printf(_("+++ %s signed on"),
-											gaim_account_get_username(account));
-				gaim_log_write(log, GAIM_MESSAGE_SYSTEM,
-							   gaim_account_get_username(account),
-							   gaim_presence_get_login_time(presence),
+											purple_account_get_username(account));
+				purple_log_write(log, PURPLE_MESSAGE_SYSTEM,
+							   purple_account_get_username(account),
+							   purple_presence_get_login_time(presence),
 							   msg);
 				g_free(msg);
 			}
@@ -303,33 +303,33 @@
 		if (ops != NULL && ops->connected != NULL)
 			ops->connected(gc);
 
-		gaim_blist_add_account(account);
+		purple_blist_add_account(account);
 
-		gaim_signal_emit(gaim_connections_get_handle(), "signed-on", gc);
+		purple_signal_emit(purple_connections_get_handle(), "signed-on", gc);
 
 		serv_set_permit_deny(gc);
 
 		update_keepalive(gc, TRUE);
 	}
-	else if (gc->state == GAIM_DISCONNECTED) {
-		GaimAccount *account = gaim_connection_get_account(gc);
+	else if (gc->state == PURPLE_DISCONNECTED) {
+		PurpleAccount *account = purple_connection_get_account(gc);
 
-		if (gaim_prefs_get_bool("/core/logging/log_system"))
+		if (purple_prefs_get_bool("/core/logging/log_system"))
 		{
-			GaimLog *log = gaim_account_get_log(account, FALSE);
+			PurpleLog *log = purple_account_get_log(account, FALSE);
 
 			if (log != NULL)
 			{
 				char *msg = g_strdup_printf(_("+++ %s signed off"),
-											gaim_account_get_username(account));
-				gaim_log_write(log, GAIM_MESSAGE_SYSTEM,
-							   gaim_account_get_username(account), time(NULL),
+											purple_account_get_username(account));
+				purple_log_write(log, PURPLE_MESSAGE_SYSTEM,
+							   purple_account_get_username(account), time(NULL),
 							   msg);
 				g_free(msg);
 			}
 		}
 
-		gaim_account_destroy_log(account);
+		purple_account_destroy_log(account);
 
 		if (ops != NULL && ops->disconnected != NULL)
 			ops->disconnected(gc);
@@ -337,7 +337,7 @@
 }
 
 void
-gaim_connection_set_account(GaimConnection *gc, GaimAccount *account)
+purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account)
 {
 	g_return_if_fail(gc != NULL);
 	g_return_if_fail(account != NULL);
@@ -346,7 +346,7 @@
 }
 
 void
-gaim_connection_set_display_name(GaimConnection *gc, const char *name)
+purple_connection_set_display_name(PurpleConnection *gc, const char *name)
 {
 	g_return_if_fail(gc != NULL);
 
@@ -354,16 +354,16 @@
 	gc->display_name = g_strdup(name);
 }
 
-GaimConnectionState
-gaim_connection_get_state(const GaimConnection *gc)
+PurpleConnectionState
+purple_connection_get_state(const PurpleConnection *gc)
 {
-	g_return_val_if_fail(gc != NULL, GAIM_DISCONNECTED);
+	g_return_val_if_fail(gc != NULL, PURPLE_DISCONNECTED);
 
 	return gc->state;
 }
 
-GaimAccount *
-gaim_connection_get_account(const GaimConnection *gc)
+PurpleAccount *
+purple_connection_get_account(const PurpleConnection *gc)
 {
 	g_return_val_if_fail(gc != NULL, NULL);
 
@@ -371,7 +371,7 @@
 }
 
 const char *
-gaim_connection_get_password(const GaimConnection *gc)
+purple_connection_get_password(const PurpleConnection *gc)
 {
 	g_return_val_if_fail(gc != NULL, NULL);
 
@@ -379,7 +379,7 @@
 }
 
 const char *
-gaim_connection_get_display_name(const GaimConnection *gc)
+purple_connection_get_display_name(const PurpleConnection *gc)
 {
 	g_return_val_if_fail(gc != NULL, NULL);
 
@@ -387,56 +387,56 @@
 }
 
 void
-gaim_connection_update_progress(GaimConnection *gc, const char *text,
+purple_connection_update_progress(PurpleConnection *gc, const char *text,
 								size_t step, size_t count)
 {
-	GaimConnectionUiOps *ops;
+	PurpleConnectionUiOps *ops;
 
 	g_return_if_fail(gc   != NULL);
 	g_return_if_fail(text != NULL);
 	g_return_if_fail(step < count);
 	g_return_if_fail(count > 1);
 
-	ops = gaim_connections_get_ui_ops();
+	ops = purple_connections_get_ui_ops();
 
 	if (ops != NULL && ops->connect_progress != NULL)
 		ops->connect_progress(gc, text, step, count);
 }
 
 void
-gaim_connection_notice(GaimConnection *gc, const char *text)
+purple_connection_notice(PurpleConnection *gc, const char *text)
 {
-	GaimConnectionUiOps *ops;
+	PurpleConnectionUiOps *ops;
 
 	g_return_if_fail(gc   != NULL);
 	g_return_if_fail(text != NULL);
 
-	ops = gaim_connections_get_ui_ops();
+	ops = purple_connections_get_ui_ops();
 
 	if (ops != NULL && ops->notice != NULL)
 		ops->notice(gc, text);
 }
 
 static gboolean
-gaim_connection_disconnect_cb(gpointer data)
+purple_connection_disconnect_cb(gpointer data)
 {
-	GaimAccount *account = data;
-	char *password = g_strdup(gaim_account_get_password(account));
-	gaim_account_disconnect(account);
-	gaim_account_set_password(account, password);
+	PurpleAccount *account = data;
+	char *password = g_strdup(purple_account_get_password(account));
+	purple_account_disconnect(account);
+	purple_account_set_password(account, password);
 	g_free(password);
 	return FALSE;
 }
 
 void
-gaim_connection_error(GaimConnection *gc, const char *text)
+purple_connection_error(PurpleConnection *gc, const char *text)
 {
-	GaimConnectionUiOps *ops;
+	PurpleConnectionUiOps *ops;
 
 	g_return_if_fail(gc   != NULL);
 
 	if (text == NULL) {
-		g_critical("gaim_connection_error: check `text != NULL' failed");
+		g_critical("purple_connection_error: check `text != NULL' failed");
 		text = _("Unknown error");
 	}
 
@@ -444,86 +444,86 @@
 	if (gc->disconnect_timeout)
 		return;
 
-	ops = gaim_connections_get_ui_ops();
+	ops = purple_connections_get_ui_ops();
 
 	if (ops != NULL && ops->report_disconnect != NULL)
 		ops->report_disconnect(gc, text);
 
-	gc->disconnect_timeout = gaim_timeout_add(0, gaim_connection_disconnect_cb,
-			gaim_connection_get_account(gc));
+	gc->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb,
+			purple_connection_get_account(gc));
 }
 
 void
-gaim_connections_disconnect_all(void)
+purple_connections_disconnect_all(void)
 {
 	GList *l;
-	GaimConnection *gc;
+	PurpleConnection *gc;
 
-	while ((l = gaim_connections_get_all()) != NULL) {
+	while ((l = purple_connections_get_all()) != NULL) {
 		gc = l->data;
 		gc->wants_to_die = TRUE;
-		gaim_account_disconnect(gc->account);
+		purple_account_disconnect(gc->account);
 	}
 }
 
 GList *
-gaim_connections_get_all(void)
+purple_connections_get_all(void)
 {
 	return connections;
 }
 
 GList *
-gaim_connections_get_connecting(void)
+purple_connections_get_connecting(void)
 {
 	return connections_connecting;
 }
 
 void
-gaim_connections_set_ui_ops(GaimConnectionUiOps *ops)
+purple_connections_set_ui_ops(PurpleConnectionUiOps *ops)
 {
 	connection_ui_ops = ops;
 }
 
-GaimConnectionUiOps *
-gaim_connections_get_ui_ops(void)
+PurpleConnectionUiOps *
+purple_connections_get_ui_ops(void)
 {
 	return connection_ui_ops;
 }
 
 void
-gaim_connections_init(void)
+purple_connections_init(void)
 {
-	void *handle = gaim_connections_get_handle();
+	void *handle = purple_connections_get_handle();
 
-	gaim_signal_register(handle, "signing-on",
-						 gaim_marshal_VOID__POINTER, NULL, 1,
-						 gaim_value_new(GAIM_TYPE_SUBTYPE,
-										GAIM_SUBTYPE_CONNECTION));
+	purple_signal_register(handle, "signing-on",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE,
+										PURPLE_SUBTYPE_CONNECTION));
 
-	gaim_signal_register(handle, "signed-on",
-						 gaim_marshal_VOID__POINTER, NULL, 1,
-						 gaim_value_new(GAIM_TYPE_SUBTYPE,
-										GAIM_SUBTYPE_CONNECTION));
+	purple_signal_register(handle, "signed-on",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE,
+										PURPLE_SUBTYPE_CONNECTION));
 
-	gaim_signal_register(handle, "signing-off",
-						 gaim_marshal_VOID__POINTER, NULL, 1,
-						 gaim_value_new(GAIM_TYPE_SUBTYPE,
-										GAIM_SUBTYPE_CONNECTION));
+	purple_signal_register(handle, "signing-off",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE,
+										PURPLE_SUBTYPE_CONNECTION));
 
-	gaim_signal_register(handle, "signed-off",
-						 gaim_marshal_VOID__POINTER, NULL, 1,
-						 gaim_value_new(GAIM_TYPE_SUBTYPE,
-										GAIM_SUBTYPE_CONNECTION));
+	purple_signal_register(handle, "signed-off",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE,
+										PURPLE_SUBTYPE_CONNECTION));
 }
 
 void
-gaim_connections_uninit(void)
+purple_connections_uninit(void)
 {
-	gaim_signals_unregister_by_instance(gaim_connections_get_handle());
+	purple_signals_unregister_by_instance(purple_connections_get_handle());
 }
 
 void *
-gaim_connections_get_handle(void)
+purple_connections_get_handle(void)
 {
 	return &connections_handle;
 }