Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

console_session.c

Go to the documentation of this file.
00001 #include "intl.h"
00002 #include "console_session.h"
00003 #include <sys/un.h>
00004 #include <stdlib.h>
00005 #include "chat_window.h"
00006 #include "util.h"
00007 #include "status.h"
00008 
00009 static void console_session_close(int * session)
00010 {
00011     gdk_input_remove(*((int*)session));
00012     g_free(session);
00013 }
00014 
00015 void console_session_get_command(gpointer data, 
00016                                 gint source, 
00017                                 GdkInputCondition condition )
00018 {
00019     char * contact_name;
00020     char * message;
00021     struct contact * remote_contact;
00022     short len;
00023     int pos = 0;
00024     int ret;
00025 
00026     if(read(source, &len, sizeof(short))<=0)
00027     {
00028         console_session_close((int*)data);
00029         return;
00030     }
00031     contact_name = alloca(len);
00032     if(read(source, contact_name, len)<=0)
00033     {
00034         console_session_close((int*)data);
00035         return;
00036     }
00037     if(strcmp(contact_name, "focus-yattm")) {
00038         if(read(source, &len, sizeof(short))<=0)
00039         {
00040             console_session_close((int*)data);
00041             return;
00042         }
00043         message = alloca(len);
00044         if(read(source, message, len)<=0)
00045         {
00046             console_session_close((int*)data);
00047             return;
00048         }
00049 
00050         remote_contact = find_contact_by_nick(contact_name);
00051         if(!remote_contact)
00052         {
00053             ret = -1;
00054             write(source, &ret, sizeof(int));
00055             return;
00056         }
00057         eb_chat_window_display_contact(remote_contact);
00058         remote_contact->chatwindow->perfered= 
00059                 find_suitable_remote_account(remote_contact->chatwindow->perfered, 
00060                                             remote_contact->chatwindow->contact);
00061         if(!remote_contact->chatwindow->perfered)
00062         {
00063             ret = -2;
00064             write(source, &ret, sizeof(int));
00065             return;
00066         }
00067 
00068         gtk_editable_insert_text(GTK_EDITABLE(remote_contact->chatwindow->entry),
00069                                  message, strlen(message), &pos);
00070         send_message(NULL, remote_contact->chatwindow);
00071     } else {
00072         focus_statuswindow();
00073     }
00074     
00075     ret = 0;
00076     write(source, &ret, sizeof(int));
00077 
00078 }
00079 
00080 void console_session_init(gpointer data, gint source, GdkInputCondition condition )
00081 {
00082     struct sockaddr_un remote;
00083     int len;
00084     int sock;
00085     int * listener = g_new0(int, 1);
00086     
00087     sock = accept(source, (struct sockaddr *)&remote, &len);
00088     *listener = gdk_input_add(sock, GDK_INPUT_READ,
00089                     console_session_get_command, 
00090                     (gpointer)listener);
00091 }

Contact: Andy Maloney     [Documentation generated by doxygen]