コード例 #1
0
void
gaim_connection_disconnect(GaimConnection *gc)
{
	GaimAccount *account;
	GList *wins;

	g_return_if_fail(gc != NULL);

	account = gaim_connection_get_account(gc);

	if (gaim_account_get_connection(account) != NULL) {
		gaim_account_disconnect(account);
		return;
	}

	gaim_debug(GAIM_DEBUG_INFO, "connection",
			   "Disconnecting connection %p\n", gc);

	if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) {
		if (gaim_connection_get_state(gc) != GAIM_CONNECTING)
			gaim_blist_remove_account(gaim_connection_get_account(gc));

		gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc);

		serv_close(gc);

		connections = g_list_remove(connections, gc);

		gaim_connection_set_state(gc, GAIM_DISCONNECTED);

		gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc);

		system_log(log_signoff, gc, NULL,
				   OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);

		/*
		 * 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) {
			GaimWindow *win = (GaimWindow *)wins->data;
			gaim_conversation_update(gaim_window_get_conversation_at(win, 0),
									 GAIM_CONV_ACCOUNT_OFFLINE);
		}

		gaim_request_close_with_handle(gc);
		gaim_notify_close_with_handle(gc);
	}

	gaim_connection_destroy(gc);
}
コード例 #2
0
ファイル: status.c プロジェクト: VoxOx/VoxOx
static void
update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence,
		time_t current_time, gboolean old_idle, gboolean idle)
{
	GaimBlistUiOps *ops = gaim_blist_get_ui_ops();

	if (!old_idle && idle)
	{
		if (gaim_prefs_get_bool("/core/logging/log_system"))
		{
			GaimLog *log = gaim_account_get_log(buddy->account, FALSE);

			if (log != NULL)
			{
				char *tmp = g_strdup_printf(_("%s became idle"),
				gaim_buddy_get_alias(buddy));

				gaim_log_write(log, GAIM_MESSAGE_SYSTEM,
				gaim_buddy_get_alias(buddy), current_time, tmp);
				g_free(tmp);
			}
		}
	}
	else if (old_idle && !idle)
	{
		if (gaim_prefs_get_bool("/core/logging/log_system"))
		{
			GaimLog *log = gaim_account_get_log(buddy->account, FALSE);

			if (log != NULL)
			{
				char *tmp = g_strdup_printf(_("%s became unidle"),
				gaim_buddy_get_alias(buddy));

				gaim_log_write(log, GAIM_MESSAGE_SYSTEM,
				gaim_buddy_get_alias(buddy), current_time, tmp);
				g_free(tmp);
			}
		}
	}

	if (old_idle != idle)
		gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle-changed", buddy,
		                 old_idle, idle);

	gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy));

	/* Should this be done here? It'd perhaps make more sense to
	 * connect to buddy-[un]idle signals and update from there
	 */

	if (ops != NULL && ops->update != NULL)
		ops->update(gaim_get_blist(), (GaimBlistNode *)buddy);
}
コード例 #3
0
ファイル: gayminfo.c プロジェクト: BackupTheBerlios/qrc-svn
void gaym_fetch_thumbnail_cb(void *user_data, const char *pic_data,
                             size_t len)
{
    if (!user_data)
        return;
    struct gaym_fetch_thumbnail_data *d = user_data;
    if (!pic_data) {
        return;
    }

    if (len && !g_strrstr_len(pic_data, len, "Server Error")) {
        char *dir =
            g_build_filename(gaim_user_dir(), "icons", "gaym", d->who,
                             NULL);
        char *filename = g_strdup(d->filename);
        char *path = g_build_filename(dir, filename, NULL);
        gaim_debug_misc("gayminfo", "dir: %s\n", dir);
        gaim_debug_misc("gayminfo", "filename: %s\n", filename);
        gaim_debug_misc("gayminfo", "path: %s\n", path);
        if (!g_file_test(dir, G_FILE_TEST_EXISTS))
            gaim_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR);

        if (path && !g_file_test(path, G_FILE_TEST_EXISTS)) {
            FILE *file;
            if ((file = g_fopen(path, "wb"))) {
                fwrite(pic_data, 1, len, file);
                fclose(file);
            } else {
                gaim_debug_misc("fetch_thumbnail_cb",
                                "Couldn't write file\n");
            }
            g_free(filename);
            g_free(path);
            g_free(dir);
        }
    }
    if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
        gaim_signal_emit(gaim_accounts_get_handle(), "info-updated",
                         d->gc, NULL, d->who);
        if (gaim_find_conversation_with_account(d->who, d->gc->account)) {
            //gaim_buddy_icons_set_for_user(gaim_connection_get_account
            //                              (d->gc), d->who,
            //                              (void *) pic_data, len);
        }

    } else {
        gaim_debug_error("gaym", "Fetching buddy icon failed.\n");
    }

    g_free(d->who);
    g_free(d);
}
コード例 #4
0
ファイル: gayminfo.c プロジェクト: BackupTheBerlios/qrc-svn
void gaym_fetch_thumbnail_cb(GaimUtilFetchUrlData *url_data, void *user_data, const gchar *pic_data,
                             gsize len, const gchar* error_message)
{
    if (!user_data)
        return;
    struct gaym_fetch_thumbnail_data *d = user_data;
    if (!pic_data) {
        return;
    }
     
    if (!d->gc)
	return;
    if (len && !g_strrstr_len(pic_data, len, "Server Error")) {
	gaim_debug_misc("gaym","Setting buddy icon for %s\n",d->who);
	if(len<1024) {
	    void* new_pic_data=NULL;
	    gaim_debug_misc("gaym","Short icon file, padding to 1024\n");
	    new_pic_data=g_malloc0(1024);
	    memcpy(new_pic_data, pic_data, len);
	    len=1024;
	    gaim_buddy_icon_new(d->gc->account, d->who, (void*)new_pic_data, len);
	    g_free(new_pic_data);
	}
	else {
	    gaim_buddy_icon_new(d->gc->account, d->who, (void*)pic_data, len);
	}
	//GaimBuddyIcon *icon=gaim_buddy_icons_find(d->gc->account,d->who);
	//guint len;
	//const guchar* data=gaim_buddy_icon_get_data(icon, &len);
    }
    if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
        gaim_signal_emit(gaim_accounts_get_handle(), "info-updated",
                         d->gc->account, d->who);
      /*  if (gaim_find_conversation_with_account(d->who, d->gc->account)) {
	    
	    gaim_debug_misc("fetch_thumbnail_cb","setting buddy icon\n");
            gaim_buddy_icons_set_for_user(gaim_connection_get_account
             (d->gc), d->who,
             (void *) pic_data, len);
        }*/

    } else {
        gaim_debug_error("gaym", "Fetching buddy icon failed.\n");
    }

    g_free(d->who);
    g_free(d);
}
コード例 #5
0
void
gaim_core_quit(void)
{
	GaimCoreUiOps *ops;
	GaimCore *core = gaim_get_core();
#ifndef GAIM_SMALL_SCREEN
	g_return_if_fail(core != NULL);
#else
    if(core != NULL){
#endif

	/* The self destruct sequence has been initiated */
	gaim_signal_emit(gaim_get_core(), "quitting");

	/* Transmission ends */
	gaim_connections_disconnect_all();

	/* Save .xml files, remove signals, etc. */
	gaim_ssl_uninit();
	gaim_pounces_uninit();
	gaim_blist_uninit();
	gaim_conversations_uninit();
	gaim_connections_uninit();
	gaim_buddy_icons_uninit();
	gaim_accounts_uninit();
	gaim_prefs_uninit();

	gaim_debug(GAIM_DEBUG_INFO, "main", "Unloading all plugins\n");
	gaim_plugins_destroy_all();

#ifdef GAIM_SMALL_SCREEN
    }
#endif
	ops = gaim_core_get_ui_ops();
	if (ops != NULL && ops->quit != NULL)
		ops->quit();

	if(core != NULL) gaim_signals_uninit();

	if (core != NULL && core->ui != NULL) {
		g_free(core->ui);
		core->ui = NULL;
	}

	if(core != NULL) g_free(core);

	_core = NULL;
}
コード例 #6
0
void
gaim_connection_register(GaimConnection *gc)
{
	GaimAccount *account;
	GaimConnectionUiOps *ops;
	GaimPluginProtocolInfo *prpl_info = NULL;

	g_return_if_fail(gc != NULL);

	gaim_debug(GAIM_DEBUG_INFO, "connection",
			"Registering.  gc = %p\n", gc);

	ops = gaim_get_connection_ui_ops();

	if (gc->prpl != NULL)
	        prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
	else {
	        gchar *message = g_strdup_printf(_("Missing protocol plugin for %s"),
						 gaim_account_get_username(gaim_connection_get_account(gc)));

		gaim_debug(GAIM_DEBUG_ERROR, "connection",
			   "Could not get prpl info for %p\n", gc);
		gaim_notify_error(NULL, _("Registration Error"),
				  message, NULL);
		g_free(message);
		return;
	}

	account = gaim_connection_get_account(gc);

	if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED)
		return;

	gaim_connection_set_state(gc, GAIM_CONNECTING);

	connections = g_list_append(connections, gc);

	gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc);

	/* set this so we don't auto-reconnect after registering */
	gc->wants_to_die = TRUE;

	gaim_debug(GAIM_DEBUG_INFO, "connection", "Calling register_user\n");

	prpl_info->register_user(account);
}
コード例 #7
0
ファイル: notify.c プロジェクト: VoxOx/VoxOx
void *
gaim_notify_userinfo(GaimConnection *gc, const char *who,
						   GaimNotifyUserInfo *user_info, GaimNotifyCloseCallback cb, gpointer user_data)
{
	GaimNotifyUiOps *ops;

	g_return_val_if_fail(who != NULL, NULL);

	ops = gaim_notify_get_ui_ops();

	if (ops != NULL && ops->notify_userinfo != NULL) {
		GaimNotifyInfo *info;

		info            = g_new0(GaimNotifyInfo, 1);
		info->type      = GAIM_NOTIFY_USERINFO;
		info->handle    = gc;

		gaim_signal_emit(gaim_notify_get_handle(), "displaying-userinfo",
						 gaim_connection_get_account(gc), who, user_info);

		info->ui_handle = ops->notify_userinfo(gc, who, user_info);
		info->cb = cb;
		info->cb_user_data = user_data;

		if (info->ui_handle != NULL) {
			handles = g_list_append(handles, info);

			return info->ui_handle;

		} else {
			if (info->cb != NULL)
				info->cb(info->cb_user_data);

			g_free(info);

			return NULL;
		}

	} else {
		if (cb != NULL)
			cb(user_data);
	}

	return NULL;
}
コード例 #8
0
ファイル: privacy.c プロジェクト: VoxOx/VoxOx
gboolean
gaim_privacy_permit_remove(GaimAccount *account, const char *who,
                           gboolean local_only)
{
    GSList *l;
    const char *name;
    GaimBuddy *buddy;
    char *del;

    g_return_val_if_fail(account != NULL, FALSE);
    g_return_val_if_fail(who     != NULL, FALSE);

    name = gaim_normalize(account, who);

    for (l = account->permit; l != NULL; l = l->next) {
        if (!gaim_utf8_strcasecmp(name, (char *)l->data))
            break;
    }

    if (l == NULL)
        return FALSE;

    /* We should not free l->data just yet. There can be occasions where
     * l->data == who. In such cases, freeing l->data here can cause crashes
     * later when who is used. */
    del = l->data;
    account->permit = g_slist_delete_link(account->permit, l);

    if (!local_only && gaim_account_is_connected(account))
        serv_rem_permit(gaim_account_get_connection(account), who);

    if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
        privacy_ops->permit_removed(account, who);

    gaim_blist_schedule_save();

    buddy = gaim_find_buddy(account, name);
    if (buddy != NULL) {
        gaim_signal_emit(gaim_blist_get_handle(),
                         "buddy-privacy-changed", buddy);
    }
    g_free(del);
    return TRUE;
}
コード例 #9
0
ファイル: privacy.c プロジェクト: VoxOx/VoxOx
gboolean
gaim_privacy_deny_remove(GaimAccount *account, const char *who,
                         gboolean local_only)
{
    GSList *l;
    const char *normalized;
    char *name;
    GaimBuddy *buddy;

    g_return_val_if_fail(account != NULL, FALSE);
    g_return_val_if_fail(who     != NULL, FALSE);

    normalized = gaim_normalize(account, who);

    for (l = account->deny; l != NULL; l = l->next) {
        if (!gaim_utf8_strcasecmp(normalized, (char *)l->data))
            break;
    }

    buddy = gaim_find_buddy(account, normalized);

    if (l == NULL)
        return FALSE;

    name = l->data;
    account->deny = g_slist_delete_link(account->deny, l);

    if (!local_only && gaim_account_is_connected(account))
        serv_rem_deny(gaim_account_get_connection(account), name);

    if (privacy_ops != NULL && privacy_ops->deny_removed != NULL)
        privacy_ops->deny_removed(account, who);

    if (buddy != NULL) {
        gaim_signal_emit(gaim_blist_get_handle(),
                         "buddy-privacy-changed", buddy);
    }

    g_free(name);
    gaim_blist_schedule_save();

    return TRUE;
}
コード例 #10
0
ファイル: privacy.c プロジェクト: VoxOx/VoxOx
gboolean
gaim_privacy_permit_add(GaimAccount *account, const char *who,
                        gboolean local_only)
{
    GSList *l;
    char *name;
    GaimBuddy *buddy;

    g_return_val_if_fail(account != NULL, FALSE);
    g_return_val_if_fail(who     != NULL, FALSE);

    name = g_strdup(gaim_normalize(account, who));

    for (l = account->permit; l != NULL; l = l->next) {
        if (!gaim_utf8_strcasecmp(name, (char *)l->data))
            break;
    }

    if (l != NULL)
    {
        g_free(name);
        return FALSE;
    }

    account->permit = g_slist_append(account->permit, name);

    if (!local_only && gaim_account_is_connected(account))
        serv_add_permit(gaim_account_get_connection(account), who);

    if (privacy_ops != NULL && privacy_ops->permit_added != NULL)
        privacy_ops->permit_added(account, who);

    gaim_blist_schedule_save();

    /* This lets the UI know a buddy has had its privacy setting changed */
    buddy = gaim_find_buddy(account, name);
    if (buddy != NULL) {
        gaim_signal_emit(gaim_blist_get_handle(),
                         "buddy-privacy-changed", buddy);
    }
    return TRUE;
}
コード例 #11
0
ファイル: irc.c プロジェクト: VoxOx/VoxOx
int irc_send(struct irc_conn *irc, const char *buf)
{
	int ret, buflen;
 	char *tosend= g_strdup(buf);

	gaim_signal_emit(_irc_plugin, "irc-sending-text", gaim_account_get_connection(irc->account), &tosend);
	if (tosend == NULL)
		return 0;
	
	buflen = strlen(tosend);
	
	
	/* If we're not buffering writes, try to send immediately */
	if (!irc->writeh)
		ret = do_send(irc, tosend, buflen);
	else {
		ret = -1;
		errno = EAGAIN;
	}

	/* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent%s: %s",
		irc->gsc ? " (ssl)" : "", tosend); */
	if (ret <= 0 && errno != EAGAIN) {
		gaim_connection_error(gaim_account_get_connection(irc->account),
				      _("Server has disconnected"));
	} else if (ret < buflen) {
		if (ret < 0)
			ret = 0;
		if (!irc->writeh)
			irc->writeh = gaim_input_add(
				irc->gsc ? irc->gsc->fd : irc->fd,
				GAIM_INPUT_WRITE, irc_send_cb, irc);
		gaim_circ_buffer_append(irc->outbuf, tosend + ret,
			buflen - ret);
	}
	g_free(tosend);
	return ret;
}
コード例 #12
0
void
gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state)
{
	GaimConnectionUiOps *ops;

	g_return_if_fail(gc != NULL);

	if (gc->state == state)
		return;

	gc->state = state;

	ops = gaim_get_connection_ui_ops();

	if (gc->state == GAIM_CONNECTING) {
		connections_connecting = g_list_append(connections_connecting, gc);
	}
	else {
		connections_connecting = g_list_remove(connections_connecting, gc);
	}

	if (gc->state == GAIM_CONNECTED) {
		GaimBlistNode *gnode,*cnode,*bnode;
		GList *wins;
		GList *add_buds=NULL;

		/* Set the time the account came online */
		time(&gc->login_time);

		if (ops != NULL && ops->connected != NULL)
			ops->connected(gc);

		gaim_blist_show();
		gaim_blist_add_account(gc->account);

		/*
		 * 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) {
			GaimWindow *win = (GaimWindow *)wins->data;
			gaim_conversation_update(gaim_window_get_conversation_at(win, 0),
									 GAIM_CONV_ACCOUNT_ONLINE);
		}

		gaim_signal_emit(gaim_connections_get_handle(), "signed-on", gc);

		system_log(log_signon, gc, NULL,
				   OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);

#if 0
		/* away option given? */
		if (opt_away) {
			away_on_login(opt_away_arg);
			/* don't do it again */
			opt_away = 0;
		} else if (awaymessage) {
			serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message);
		}
		if (opt_away_arg != NULL) {
			g_free(opt_away_arg);
			opt_away_arg = NULL;
		}
#endif

		/* let the prpl know what buddies we pulled out of the local list */
		for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) {
			if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
				continue;
			for(cnode = gnode->child; cnode; cnode = cnode->next) {
				if(!GAIM_BLIST_NODE_IS_CONTACT(cnode))
					continue;
				for(bnode = cnode->child; bnode; bnode = bnode->next) {
					GaimBuddy *b;
					if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
						continue;

					b = (GaimBuddy *)bnode;
					if(b->account == gc->account) {
						add_buds = g_list_append(add_buds, b->name);
					}
				}
			}
		}

		if(add_buds) {
			serv_add_buddies(gc, add_buds);
			g_list_free(add_buds);
		}

		serv_set_permit_deny(gc);
	}
	else if (gc->state == GAIM_DISCONNECTED) {
		if (ops != NULL && ops->disconnected != NULL)
			ops->disconnected(gc);
	}
}
コード例 #13
0
void
gaim_connection_connect(GaimConnection *gc)
{
	GaimAccount *account;
	GaimConnectionUiOps *ops;
	GaimPluginProtocolInfo *prpl_info = NULL;

	g_return_if_fail(gc != NULL);

	gaim_debug(GAIM_DEBUG_INFO, "connection",
			   "Connecting. gc = %p\n", gc);

	ops = gaim_get_connection_ui_ops();

	if (gc->prpl != NULL)
	        prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
	else {
	        gchar *message = g_strdup_printf(_("Missing protocol plugin for %s"),
						 gaim_account_get_username(gaim_connection_get_account(gc)));

		gaim_debug(GAIM_DEBUG_ERROR, "connection",
			   "Could not get prpl info for %p\n", gc);
		gaim_notify_error(NULL, _("Connection Error"),
				  message, NULL);
		g_free(message);
		return;
	}

	account = gaim_connection_get_account(gc);

	if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED)
		return;

	if (!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
			!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL) &&
			gaim_account_get_password(account) == NULL) {
		gchar *primary;
		gchar *escaped;
		const gchar *username = gaim_account_get_username(account);

		gaim_debug(GAIM_DEBUG_INFO, "connection", "Requesting password\n");
		gaim_connection_destroy(gc);
		escaped = g_markup_escape_text(username, strlen(username));
		primary = g_strdup_printf(_("Enter password for %s"), escaped);
		gaim_request_input(gc, NULL, primary, NULL, NULL, FALSE, TRUE,
						   _("OK"), G_CALLBACK(request_pass_ok_cb),
						   _("Cancel"), NULL, account);
		g_free(primary);
		g_free(escaped);

		return;
	}

	gaim_connection_set_state(gc, GAIM_CONNECTING);

	connections = g_list_append(connections, gc);

	gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc);

	gaim_debug(GAIM_DEBUG_INFO, "connection", "Calling serv_login\n");

	serv_login(account);
}
コード例 #14
0
ファイル: connection.c プロジェクト: VoxOx/VoxOx
void
gaim_connection_new(GaimAccount *account, gboolean regist, const char *password)
{
	GaimConnection *gc;
	GaimPlugin *prpl;
	GaimPluginProtocolInfo *prpl_info;

	g_return_if_fail(account != NULL);

	if (!gaim_account_is_disconnected(account))
		return;

	prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));

	if (prpl != NULL)
		prpl_info = GAIM_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") :
						  _("Connection Error"), message, NULL);
		g_free(message);
		return;
	}

	if (regist)
	{
		if (prpl_info->register_user == NULL)
			return;
	}
	else
	{
		if (((password == NULL) || (*password == '\0')) &&
			!(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));
			return;
		}
	}

	gc = g_new0(GaimConnection, 1);
	GAIM_DBUS_REGISTER_POINTER(gc, GaimConnection);

	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);
	connections = g_list_append(connections, gc);
	gaim_account_set_connection(account, gc);

	gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc);

	if (regist)
	{
		gaim_debug_info("connection", "Registering.  gc = %p\n", gc);

		/* set this so we don't auto-reconnect after registering */
		gc->wants_to_die = TRUE;

		prpl_info->register_user(account);
	}
	else
	{
		gaim_debug_info("connection", "Connecting. gc = %p\n", gc);

		gaim_signal_emit(gaim_accounts_get_handle(), "account-connecting", account);
		prpl_info->login(account);
	}
}
コード例 #15
0
ファイル: connection.c プロジェクト: VoxOx/VoxOx
void
gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state)
{
	GaimConnectionUiOps *ops;

	g_return_if_fail(gc != NULL);

	if (gc->state == state)
		return;

	gc->state = state;

	ops = gaim_connections_get_ui_ops();

	if (gc->state == GAIM_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;

		account = gaim_connection_get_account(gc);
		presence = gaim_account_get_presence(account);

		/* Set the time the account came online */
		gaim_presence_set_login_time(presence, time(NULL));

		if (gaim_prefs_get_bool("/core/logging/log_system"))
		{
			GaimLog *log = gaim_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),
							   msg);
				g_free(msg);
			}
		}

		if (ops != NULL && ops->connected != NULL)
			ops->connected(gc);

		gaim_blist_add_account(account);

		gaim_signal_emit(gaim_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);

		if (gaim_prefs_get_bool("/core/logging/log_system"))
		{
			GaimLog *log = gaim_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),
							   msg);
				g_free(msg);
			}
		}

		gaim_account_destroy_log(account);

		if (ops != NULL && ops->disconnected != NULL)
			ops->disconnected(gc);
	}
}
コード例 #16
0
ファイル: connection.c プロジェクト: VoxOx/VoxOx
void
gaim_connection_destroy(GaimConnection *gc)
{
	GaimAccount *account;
	GSList *buddies, *tmp;
#if 0
	GList *wins;
#endif
	GaimPluginProtocolInfo *prpl_info = NULL;
	gboolean remove = FALSE;

	g_return_if_fail(gc != NULL);

	account = gaim_connection_get_account(gc);

	gaim_debug_info("connection", "Disconnecting connection %p\n", gc);

	if (gaim_connection_get_state(gc) != GAIM_CONNECTING)
		remove = TRUE;

	gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc);

	while (gc->buddy_chats)
	{
		GaimConversation *b = gc->buddy_chats->data;

		gc->buddy_chats = g_slist_remove(gc->buddy_chats, b);
		gaim_conv_chat_left(GAIM_CONV_CHAT(b));
	}

	update_keepalive(gc, FALSE);

	gaim_proxy_connect_cancel_with_handle(gc);

	prpl_info = GAIM_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);
	for (tmp = buddies; tmp; tmp = tmp->next) {
		GaimBuddy *buddy = tmp->data;
		buddy->proto_data = NULL;
	}
	g_slist_free(buddies);

	connections = g_list_remove(connections, gc);

	gaim_connection_set_state(gc, GAIM_DISCONNECTED);

	if (remove)
		gaim_blist_remove_account(account);

	gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc);

#if 0
	/* see comment later in file on if 0'd same code */
	/*
	 * 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);
	}
#endif

	gaim_request_close_with_handle(gc);
	gaim_notify_close_with_handle(gc);

	gaim_debug_info("connection", "Destroying connection %p\n", gc);

	gaim_account_set_connection(account, NULL);

	g_free(gc->password);
	g_free(gc->display_name);

	if (gc->disconnect_timeout)
		gaim_timeout_remove(gc->disconnect_timeout);

	GAIM_DBUS_UNREGISTER_POINTER(gc);
	g_free(gc);
}