Yo.
gtk1-stable
v0_59_9
2003-03-01, Sean Egan
* 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 static guchar *UI_build(guint32 *len, guchar type, guchar subtype, va_list args) *len = sizeof(guchar) * 2 + 4; memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type); memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype); /* we come back and do size last */ size = va_arg(args, int); buffer = g_realloc(buffer, *len); data = va_arg(args, void *); memcpy(buffer + pos, data, size); size = va_arg(args, int); pos -= sizeof(guchar) * 2 + 4; memcpy(buffer + sizeof(guchar) * 2, &pos, 4); gint UI_write(struct UI *ui, guchar *data, gint len) /* we'll let the write silently fail because the read will pick it up as dead */ g_io_channel_write(ui->channel, data, len, &sent); void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...) data = UI_build(&len, type, subtype, ap); void UI_broadcast(guchar *data, gint len) void UI_build_broadcast(guchar type, guchar subtype, ...) data = UI_build(&len, type, subtype, ap); static void meta_handler(struct UI *ui, guchar subtype, guchar *data) uis = g_slist_remove(uis, ui); g_io_channel_close(ui->channel); g_source_remove(ui->inpa); uis = g_slist_remove(uis, ui); g_io_channel_close(ui->channel); g_source_remove(ui->inpa); debug_printf("unhandled meta subtype %d\n", subtype); static void plugin_handler(struct UI *ui, guchar subtype, guchar *data) /* XXX need to broadcast to UIs that plugin has been loaded */ memcpy(&id, data, sizeof(id)); p = g_list_nth_data(plugins, id); /* XXX need to broadcast to UIs that plugin has been unloaded */ memcpy(&id, data, sizeof(id)); p = g_list_nth_data(plugins, id); /* XXX need to broadcast to UIs that plugin has been reloaded */ debug_printf("unhandled plugin subtype %d\n", subtype); static void user_handler(struct UI *ui, guchar subtype, guchar *data) memcpy(&id, data, sizeof(id)); u = g_slist_nth_data(aim_users, id); /* don't need to do anything here because the UI will get updates from other handlers */ debug_printf("unhandled user subtype %d\n", subtype); static void message_handler(struct UI *ui, guchar subtype, guchar *data) struct gaim_connection *gc; memcpy(&id, data + pos, sizeof(id)); gc = g_slist_nth_data(connections, id); memcpy(&len, data + pos, sizeof(len)); who = g_strndup(data + pos, len + 1); memcpy(&len, data + pos, sizeof(len)); msg = g_strndup(data + pos, len + 1); memcpy(&flags, data + pos, sizeof(flags)); serv_send_im(gc, who, msg, -1, flags); debug_printf("unhandled message subtype %d\n", subtype); static gint gaim_recv(GIOChannel *source, guchar *buf, gint len) if (g_io_channel_read(source, buf + total, len - total, &cur) != G_IO_ERROR_NONE) static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) /* no byte order worries! this'll change if we go to TCP */ if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { debug_printf("UI has abandoned us!\n"); uis = g_slist_remove(uis, ui); g_io_channel_close(ui->channel); g_source_remove(ui->inpa); if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) { debug_printf("UI has abandoned us!\n"); uis = g_slist_remove(uis, ui); g_io_channel_close(ui->channel); g_source_remove(ui->inpa); 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); in = g_new0(guchar, len); if (gaim_recv(source, in, len) != 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); meta_handler(ui, subtype, in); plugin_handler(ui, subtype, in); user_handler(ui, subtype, in); conn_handler(ui, subtype, in); buddy_handler(ui, subtype, in); message_handler(ui, subtype, in); chat_handler(ui, subtype, in); debug_printf("unhandled type %d\n", type); static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data) struct sockaddr_un saddr; gint len = sizeof(saddr); if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1) 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"); static gint open_socket() struct sockaddr_un saddr; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { 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) g_log(NULL, G_LOG_LEVEL_CRITICAL, "Failed to assign %s to a socket (Error: %s)", saddr.sun_path, strerror(errno)); g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); channel = g_io_channel_unix_new(UI_fd); g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); g_io_channel_unref(channel); sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), getpid()); debug_printf("Removed core\n");