Mercurial > pidgin.yaz
changeset 2416:61b816a7b467
[gaim-migrate @ 2429]
core.c. There's nothing here yet and nothing in it is used by default (though most of it is compiled). i need to split gaim.h into core.h and ui.h next. oh, and split struct conversation and move it completely out of the prpls.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 03 Oct 2001 07:49:38 +0000 |
parents | 88e35feb75f8 |
children | 5473c8c5378d |
files | acconfig.h configure.ac src/Makefile.am src/aim.c src/core.c src/gaim.h |
diffstat | 6 files changed, 226 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/acconfig.h Wed Oct 03 06:04:44 2001 +0000 +++ b/acconfig.h Wed Oct 03 07:49:38 2001 +0000 @@ -19,6 +19,7 @@ #undef NEED_GNOMESUPPORT_H #undef ZEPHYR_INT32 #undef ZEPHYR_USES_KERBEROS +#undef DEVEL #ifndef STATIC_PROTO_INIT #undef STATIC_PROTO_INIT #endif
--- a/configure.ac Wed Oct 03 06:04:44 2001 +0000 +++ b/configure.ac Wed Oct 03 07:49:38 2001 +0000 @@ -41,6 +41,11 @@ CFLAGS="$CFLAGS -I/usr/local/include -I/opt/include -I\$(top_srcdir)" AC_ARG_ENABLE(distrib,,,enable_distrib=no) +AC_ARG_ENABLE(devel,,,enable_devel=no) +if test "$enable_devel" = "yes" ; then + CFLAGS="$CFLAGS -Wall" + AC_DEFINE(DEVEL) +fi AM_CONDITIONAL(DISTRIB, test "x$enable_distrib" = "xyes") AC_ARG_ENABLE(multi, [ --disable-multi disable multiple connections],,enable_multi=yes) AC_ARG_ENABLE(prpls, [ --disable-prpls don't build dynamic protocol plugins],,enable_prpls=yes) @@ -95,7 +100,7 @@ AC_ARG_ENABLE(plugins, [ --disable-plugins compile without plugin support],,enable_plugins=yes) AC_ARG_ENABLE(perl, [ --disable-perl compile without perl scripting],,enable_perl=yes) -AC_ARG_ENABLE(debug, [ --enable-debug compile with debugging support],,enable_debug=no) +AC_ARG_ENABLE(debug, [ --enable-debug compile with debugging support],,enable_debug=$enable_devel) AC_ARG_ENABLE(screensaver, [ --disable-screensaver compile without X screensaver extension],,enable_xss=yes) AC_ARG_WITH(krb4, [ --with-krb4=PREFIX Compile Zephyr plugin with Kerberos 4 support],kerberos="$withval",kerberos="no")
--- a/src/Makefile.am Wed Oct 03 06:04:44 2001 +0000 +++ b/src/Makefile.am Wed Oct 03 07:49:38 2001 +0000 @@ -10,6 +10,7 @@ buddy.c \ buddy_chat.c \ conversation.c \ + core.c \ dialogs.c \ gaimrc.c \ gtkimhtml.c \ @@ -42,6 +43,7 @@ buddy.c \ buddy_chat.c \ conversation.c \ + core.c \ dialogs.c \ gaimrc.c \ gtkimhtml.c \
--- a/src/aim.c Wed Oct 03 06:04:44 2001 +0000 +++ b/src/aim.c Wed Oct 03 07:49:38 2001 +0000 @@ -382,6 +382,7 @@ signoff_all(NULL, NULL); break; case SIGSEGV: + core_quit(); fprintf(stderr, "Gaim has segfaulted and attempted to dump a core file.\n" "This is a bug in the software and has happened through\n" "no fault of your own.\n\n" @@ -408,6 +409,7 @@ #endif if (gtk_main_level()) gtk_main_quit(); + core_quit(); exit(0); } } @@ -620,6 +622,8 @@ load_prefs(); + core_main(); + /* set the default username */ if (opt_user_arg != NULL) { set_first_user(opt_user_arg); @@ -678,6 +682,7 @@ #endif /* USE_APPLET */ gtkspell_stop(); + core_quit(); return 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core.c Wed Oct 03 07:49:38 2001 +0000 @@ -0,0 +1,208 @@ +/* + * gaim + * + * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/un.h> +#include <unistd.h> +#include <errno.h> +#include <signal.h> +#include <getopt.h> + +#include "gaim.h" + +static gint UI_fd = -1; +struct UI { + GIOChannel *channel; + guint inpa; +}; +GSList *uis = NULL; + +static gint gaim_recv(GIOChannel *source, guchar *buf, gint len) +{ + gint total = 0; + gint cur; + + while (total < len) { + if (g_io_channel_read(source, buf + total, len - total, &cur) != G_IO_ERROR_NONE) + return -1; + if (cur == 0) + return total; + total += cur; + } + + return total; +} + +static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) +{ + struct UI *ui = data; + + guchar buf[2] = {0, 0}; + guint32 len; + + guchar *in; + + gushort type; + + /* buf[0] is to specify gaim, buf[1] is for protocol version */ + if ((gaim_recv(source, buf, 2) != 2) || (buf[0] != 102) || (buf[1] != 1)) { + debug_printf("UI has abandoned us! (%d %d)\n", buf[0], buf[1]); + uis = g_slist_remove(uis, ui); + g_io_channel_close(ui->channel); + g_source_remove(ui->inpa); + g_free(ui); + return FALSE; + } + + /* no byte order worries! this'll change if we go to TCP */ + if (gaim_recv(source, (guchar *)&len, sizeof(len)) != sizeof(len)) { + debug_printf("UI has abandoned us!\n"); + uis = g_slist_remove(uis, ui); + g_io_channel_close(ui->channel); + g_source_remove(ui->inpa); + g_free(ui); + return FALSE; + } + + in = g_new0(guchar, len + 1); + gaim_recv(source, in, len); + + memcpy(&type, in, sizeof(type)); + switch (type) { + /* + case CUI_TYPE_META: + meta_handler(ui, in); + break; + case CUI_TYPE_PLUGIN: + plugin_handler(ui, in); + break; + case CUI_TYPE_USER: + user_handler(ui, in); + break; + case CUI_TYPE_CONN: + conn_handler(ui, in); + break; + case CUI_TYPE_BUDDY: + buddy_handler(ui, in); + break; + case CUI_TYPE_MESSAGE: + message_handler(ui, in); + break; + case CUI_TYPE_CHAT: + chat_handler(ui, in); + break; + */ + default: + debug_printf("unhandled type %d\n", type); + break; + } + + g_free(in); + return TRUE; +} + +static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data) +{ + struct sockaddr_un saddr; + gint len; + gint fd; + + struct UI *ui; + + if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1) + return FALSE; + + ui = g_new0(struct UI, 1); + uis = g_slist_append(uis, ui); + + ui->channel = g_io_channel_unix_new(fd); + ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui); + g_io_channel_unref(ui->channel); + + debug_printf("got one\n"); + return TRUE; +} + +static gint open_socket() +{ + struct sockaddr_un saddr; + gint fd; + + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { + umask(0177); + saddr.sun_family = AF_UNIX; + g_snprintf(saddr.sun_path, 108, "%s/gaim_%s.%d", + g_get_tmp_dir(), g_get_user_name(), getpid()); + if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) + listen(fd, 100); + else + g_log(NULL, G_LOG_LEVEL_CRITICAL, + "Failed to assign %s to a socket (Error: %s)", + saddr.sun_path, strerror(errno)); + } else + g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); + return fd; +} + +int core_main() +{ + /* + GMainLoop *loop; + */ + +#if DEVEL + GIOChannel *channel; + + UI_fd = open_socket(); + if (UI_fd < 0) + return 1; + + channel = g_io_channel_unix_new(UI_fd); + g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); + g_io_channel_unref(channel); +#endif + + /* + loop = g_main_new(TRUE); + g_main_run(loop); + */ + + return 0; +} + +void core_quit() +{ +#ifdef DEVEL + char buf[1024]; + close(UI_fd); + sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), getpid()); + unlink(buf); +#endif +}
--- a/src/gaim.h Wed Oct 03 06:04:44 2001 +0000 +++ b/src/gaim.h Wed Oct 03 07:49:38 2001 +0000 @@ -906,6 +906,10 @@ /* Functions in multi.c */ extern void account_editor(GtkWidget *, GtkWidget *); +/* Functions in core.c */ /* Don't ever use these */ +extern int core_main(); +extern void core_quit(); + /* fucntions in ticker.c */ void SetTickerPrefs(); void BuddyTickerSignOff();