view console/gntdebug.c @ 14357:4e14503b9bac

[gaim-migrate @ 17063] Fix an assertion that fails for me about half the time when I try to sign onto MSN. Here's a backtrace, in case someone wants to look at this more in depth: #4 0x00002aaab203d857 in msn_object_new_from_string (str=0x2aaaac4f0860 "0") at object.c:79 obj = (MsnObject *) 0x7fff2bc6efe0 tag = 0x2aaaac4f0861 "" c = 0x100000001 <Address 0x100000001 out of bounds> __PRETTY_FUNCTION__ = "msn_object_new_from_string" #5 0x00002aaab203bf37 in nln_cmd (cmdproc=0xd84f30, cmd=0xcb1e10) at notification.c:687 session = (MsnSession *) 0xd72e70 account = (GaimAccount *) 0x63c020 gc = (GaimConnection *) 0xd5d9b0 user = (MsnUser *) 0xcb1d90 msnobj = (MsnObject *) 0x2aaaacc127d9 clientid = 32767 state = 0xc97820 "NLN" passport = 0xd65310 "lbdash@yahoo.com" friendly = 0x2aaaac4f0860 "0" #6 0x00002aaab202ff18 in msn_cmdproc_process_cmd (cmdproc=0xd84f30, cmd=0xcb1e10) at cmdproc.c:313 cb = 0x2aaab203be63 <nln_cmd> trans = (MsnTransaction *) 0x0 #7 0x00002aaab202ffbe in msn_cmdproc_process_cmd_text (cmdproc=0xd84f30, command=0xe082b0 "NLN NLN lbdash@yahoo.com lbdash@yahoo.com 1073741856 0") at cmdproc.c:335 No locals. #8 0x00002aaab2032c06 in read_cb (data=0xd4e600, source=7, cond=GAIM_INPUT_READ) at httpconn.c:380 httpconn = (MsnHttpConn *) 0xd4e600 servconn = (MsnServConn *) 0xd65360 session = (MsnSession *) 0xd72e70 buf = "HTTP/1.1 200 OK\r\nDate: Sun, 27 Aug 2006 21:29:58 GMT\r\nServer: Microsoft-IIS/6.0\r\nX-Powered-By: ASP.N ET\r\nX-MSN-Messenger: SessionID=26246177.8760; GW-IP=207.46.7.4\r\nContent-Length: 56\r\nContent-type: ap"... cur = 0xe082b0 "NLN NLN lbdash@yahoo.com lbdash@yahoo.com 1073741856 0" end = 0xe082e8 "" old_rx_buf = 0xe082b0 "NLN NLN lbdash@yahoo.com lbdash@yahoo.com 1073741856 0" len = 285 cur_len = 56 result_msg = 0xe082b0 "NLN NLN lbdash@yahoo.com lbdash@yahoo.com 1073741856 0" result_len = 56 error = 0 committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Aug 2006 21:36:52 +0000
parents 43d9afee9c3c
children 81650a27f253
line wrap: on
line source

#include <gnt.h>
#include <gntbox.h>
#include <gnttextview.h>

#include "gntdebug.h"
#include "gntgaim.h"

#include <stdio.h>
#include <string.h>

static struct
{
	GntWidget *window;
	GntWidget *tview;
} debug;

static gboolean
debug_window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view)
{
	if (key[0] == 27)
	{
		if (strcmp(key+1, GNT_KEY_DOWN) == 0)
			gnt_text_view_scroll(view, 1);
		else if (strcmp(key+1, GNT_KEY_UP) == 0)
			gnt_text_view_scroll(view, -1);
		else if (strcmp(key+1, GNT_KEY_PGDOWN) == 0)
			gnt_text_view_scroll(view, wid->priv.height - 2);
		else if (strcmp(key+1, GNT_KEY_PGUP) == 0)
			gnt_text_view_scroll(view, -(wid->priv.height - 2));
		else
			return FALSE;
		return TRUE;
	}
	return FALSE;
}

static void
gg_debug_print(GaimDebugLevel level, const char *category,
		const char *args)
{
	if (debug.window)
	{
		GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;

		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				category, GNT_TEXT_FLAG_BOLD);
		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				": ", GNT_TEXT_FLAG_BOLD);
		
		switch (level)
		{
			case GAIM_DEBUG_WARNING:
				flag |= GNT_TEXT_FLAG_UNDERLINE;
			case GAIM_DEBUG_ERROR:
			case GAIM_DEBUG_FATAL:
				flag |= GNT_TEXT_FLAG_BOLD;
				break;
			default:
				break;
		}
		
		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag);
		gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0);
	}
}

static GaimDebugUiOps uiops = 
{
	gg_debug_print,
};

GaimDebugUiOps *gg_debug_get_ui_ops()
{
	return &uiops;
}

static void
reset_debug_win(GntWidget *w, gpointer null)
{
	debug.window = debug.tview = NULL;
}

static void
print_stderr(const char *string)
{
	g_printerr("%s", string);
}

void gg_debug_window_show()
{
	if (debug.window == NULL)
	{
		debug.window = gnt_vbox_new(FALSE);
		gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE);
		gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window"));

		debug.tview = gnt_text_view_new();
		gnt_box_add_widget(GNT_BOX(debug.window), debug.tview);

		/* XXX: Add checkboxes/buttons for Clear, Pause, Timestamps */

		g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL);
		g_signal_connect(G_OBJECT(debug.window), "key_pressed", G_CALLBACK(debug_window_kpress_cb), debug.tview);
	}

	gnt_widget_show(debug.window);
}

static gboolean
start_with_debugwin(gpointer null)
{
	gg_debug_window_show();
	return FALSE;
}

void gg_debug_init()
{
	g_set_print_handler(print_stderr);   /* Redirect the debug messages to stderr */
	if (gaim_debug_is_enabled())
		g_timeout_add(0, start_with_debugwin, NULL);
}

void gg_debug_uninit()
{
}