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

util.h File Reference

#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include "contact.h"
#include "service.h"

Include dependency graph for util.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Defines

#define NAME_MAX   4096

Enumerations

enum  {
  TOKEN_NORMAL, TOKEN_HTTP, TOKEN_FTP, TOKEN_EMAIL,
  TOKEN_CUSTOM
}

Functions

gint clean_pid (void *dummy)
char * get_local_addresses ()
gchar * convert_eol (gchar *input)
gchar * linkify (gchar *input)
char * escape_string (char *input)
char * unescape_string (char *input)
eb_local_accountfind_suitable_local_account (eb_local_account *first, gint second)
eb_local_accountfind_local_account_for_remote (eb_account *remote, gboolean online)
eb_accountcan_offline_message (struct contact *con)
eb_accountfind_suitable_remote_account (eb_account *first, struct contact *rest)
eb_accountfind_suitable_file_transfer_account (eb_account *first, struct contact *rest)
eb_chat_room * find_chat_room_by_id (gchar *id)
eb_chat_room * find_chat_room_by_name (gchar *name, gint service_id)
grouplistfind_grouplist_by_nick (gchar *nick)
grouplistfind_grouplist_by_name (gchar *name)
contactfind_contact_by_handle (gchar *handle)
contactfind_contact_by_nick (gchar *nick)
contactfind_contact_in_group_by_nick (gchar *nick, grouplist *gl)
void refresh_service_contacts (gint type)
eb_accountfind_account_by_handle (gchar *handle, gint type)
eb_accountfind_account_by_handle_normalized (gchar *handle, gint type)
eb_local_accountfind_local_account_by_handle (gchar *handle, gint type)
void strip_html (gchar *text)
void remove_account (eb_account *a)
void remove_contact (struct contact *c)
void remove_group (grouplist *g)
void add_group (gchar *name)
contactadd_new_contact (gchar *group, gchar *con, gint type)
void add_unknown (eb_account *ea)
void add_unknown_with_name (eb_account *ea, gchar *name)
void add_account (gchar *contact, eb_account *account)
void add_account_silent (gchar *contact, eb_account *account)
void move_account (struct contact *c, eb_account *account)
void move_contact (gchar *group, struct contact *c)
void invite_dialog (eb_local_account *ela, char *user, char *chat_room, void *id)
void make_safe_filename (gchar *buff, gchar *name)
gint gtk_notebook_get_number_pages (GtkNotebook *notebook)
pid_t create_lock_file (gchar *fname)
void delete_lock_file (gchar *fname)
void eb_generic_menu_function (GtkWidget *add_button, gpointer userdata)

Variables

GtkWidget * statuswindow


Define Documentation

#define NAME_MAX   4096
 

Definition at line 126 of file util.h.

Referenced by eb_chat_window_display_account(), eb_chat_window_display_contact(), eb_chat_window_display_remote_message(), eb_chat_window_new(), load_log_information(), and make_safe_filename().


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
TOKEN_NORMAL 
TOKEN_HTTP 
TOKEN_FTP 
TOKEN_EMAIL 
TOKEN_CUSTOM 

Definition at line 59 of file util.h.

00060 {
00061   TOKEN_NORMAL,
00062   TOKEN_HTTP,
00063   TOKEN_FTP,
00064   TOKEN_EMAIL,
00065   TOKEN_CUSTOM
00066 
00067 };


Function Documentation

void add_account gchar *    contact,
eb_account   account
 

Definition at line 1226 of file util.c.

References add_account_verbose().

Referenced by add_button_callback(), and ok_callback().

01227 {
01228     add_account_verbose(contact, account, TRUE);
01229 }

void add_account_silent gchar *    contact,
eb_account   account
 

Definition at line 1222 of file util.c.

References add_account_verbose().

01223 {
01224     add_account_verbose(contact, account, FALSE);
01225 }

void add_group gchar *    name
 

Definition at line 1143 of file util.c.

References add_group_line(), _grouplist::list_item, _grouplist::members, and _grouplist::name.

Referenced by add_button_callback(), add_contact(), move_contact(), and ok_callback().

01144 {
01145     grouplist g, *eg;
01146     strncpy(g.name, name,255);
01147     g.members = NULL;
01148     g.list_item = NULL;
01149    
01150     groups = g_list_append( groups, eg = g_memdup(&g, sizeof(grouplist)));
01151     add_group_line(eg);
01152 }

struct contact* add_new_contact gchar *    group,
gchar *    con,
gint    type
 

Definition at line 1162 of file util.c.

References contact_cmp(), contact::default_chatb, contact::default_filetransb, find_grouplist_by_name(), contact::group, contact::nick, and contact::online.

Referenced by add_button_callback(), and ok_callback().

01163 {
01164     grouplist * g = find_grouplist_by_name( group);
01165     struct contact * c = g_new0( struct contact, 1);
01166     c->online = 0;
01167     if (con != NULL) {      // don't copy from null pointers !!
01168         strncpy(c->nick, con, 255);
01169     }
01170     c->default_chatb = c->default_filetransb = type;
01171    
01172     if(g)
01173     {
01174         g->members = g_list_insert_sorted(g->members, c, contact_cmp);
01175         c->group = g;
01176     }
01177     return c;
01178 }

void add_unknown eb_account   ea
 

Definition at line 1248 of file util.c.

References _, account::account_contact, contact::accounts, add_contact(), contact::default_chatb, contact::default_filetransb, account::handle, account::icon_handler, contact::nick, RUN_SERVICE, account::service_id, account::status_handler, and write_contact_list().

Referenced by add_account_verbose().

01249 {
01250     struct contact * con = g_new0(struct contact, 1);
01251     strncpy(con->nick, ea->handle, 255);
01252     con->accounts = g_list_append( con->accounts, ea );
01253     con->default_chatb = ea->service_id;
01254     con->default_filetransb = ea->service_id;
01255     ea->account_contact = con;
01256     add_contact(_("Unknown"), con);
01257     ea->icon_handler = -1;
01258     ea->status_handler = -1;
01259     RUN_SERVICE(ea)->add_user(ea);
01260     write_contact_list();
01261 }

void add_unknown_with_name eb_account   ea,
gchar *    name
 

Definition at line 1263 of file util.c.

References _, account::account_contact, contact::accounts, add_contact(), contact::default_chatb, contact::default_filetransb, account::handle, account::icon_handler, contact::nick, RUN_SERVICE, account::service_id, account::status_handler, and write_contact_list().

01264 {
01265     struct contact * con = g_new0(struct contact, 1);
01266 
01267     /* Check that name is defined */
01268     if (name && strlen(name))
01269         strncpy(con->nick, name, 255);
01270     else
01271         strncpy(con->nick, ea->handle, 255);
01272 
01273     con->accounts = g_list_append( con->accounts, ea );
01274     con->default_chatb = ea->service_id;
01275     con->default_filetransb = ea->service_id;
01276     ea->account_contact = con;
01277     add_contact(_("Unknown"), con);
01278     ea->icon_handler = -1;
01279     ea->status_handler = -1;
01280     RUN_SERVICE(ea)->add_user(ea);
01281     write_contact_list();
01282 }

eb_account* can_offline_message struct contact   con
 

Definition at line 659 of file util.c.

References contact::accounts, and account::service_id.

Referenced by eb_chat_window_new(), handle_click(), and send_message().

00660 {
00661     GList * node;
00662     for(node = con->accounts; node; node=node->next)
00663     {
00664         eb_account * ea = (eb_account*)node->data;
00665         
00666         if( eb_services[ea->service_id].offline_messaging )
00667             return ea;
00668     }
00669     return 0;
00670 }   

gint clean_pid void *    dummy
 

Definition at line 59 of file util.c.

00060 {
00061     int status;
00062     pid_t pid;
00063 
00064 #ifndef __MINGW32__
00065     pid = waitpid(-1, &status, WNOHANG);
00066 #endif
00067 
00068     if (pid == 0)
00069         return TRUE;
00070 
00071     return FALSE;
00072 }

gchar* convert_eol gchar *    input
 

Definition at line 543 of file util.c.

Referenced by send_message().

00544 {
00545     gchar * temp;
00546     gchar **data=NULL;
00547     int i;
00548     
00549     if (strstr (text, "\r\n") != NULL)
00550         return text;
00551     
00552     data = g_strsplit(text,"\n",64);
00553     temp = g_strdup(data[0]);
00554     for(i=1; data[i] != NULL; i++) {
00555         temp = g_strdup_printf("%s\r\n%s",temp,data[i]);
00556     }
00557     g_strfreev(data);
00558     return temp;
00559 }

pid_t create_lock_file gchar *    fname
 

Definition at line 1454 of file util.c.

References _.

Referenced by main().

01455 {
01456   pid_t ourpid = -1;
01457   struct stat sbuff;
01458   FILE* f;
01459 
01460 #ifndef __MINGW32__
01461   if (stat(fname, &sbuff) != 0) { 
01462     /* file doesn't exist, so we're gonna open it to write out pid to it */
01463     ourpid = getpid();
01464     if ((f = fopen(fname, "a")) != NULL) {
01465       fprintf(f, "%d\n", ourpid);
01466       fclose(f);
01467       ourpid = -1;
01468     } else {
01469       ourpid = 0;       /* I guess could be considered an error condition */
01470                 /* in that we couldn't create the lock file */
01471     }           
01472   } else {
01473     /* this means that the file exists */
01474     if ((f = fopen(fname, "r")) != NULL) {
01475       char data[20];
01476       fscanf(f, "%d", &ourpid);
01477       fclose(f);
01478       sprintf(data, "/proc/%d", ourpid);
01479       if(stat(data, &sbuff) != 0) // we got a lock file but the process is gone
01480       {
01481           fprintf(stderr, _("deleting stale lock file\n"));
01482           unlink(fname); /*delete lock file and try again :) */
01483           return create_lock_file(fname);
01484       } else {
01485            FILE * fd = NULL;
01486            sprintf(data, "%s/cmdline", data);
01487        fd = fopen(data, "r");
01488        if(fd==NULL)
01489         perror("fopen");
01490        else {
01491             char cmd[1024];
01492         fgets(cmd, sizeof(cmd), fd);
01493         printf("registered PID is from %s\n",cmd);
01494         fclose(fd);
01495         if(cmd == NULL || strstr(cmd, "yattm") == NULL) {
01496           fprintf(stderr, _("deleting stale lock file\n"));
01497           unlink(fname); /*delete lock file and try again :) */
01498           return create_lock_file(fname);
01499         }
01500        }
01501       }
01502           
01503     } else {
01504       /* couldn't open it... bizarre... allow the program to run anyway... heh */
01505       ourpid = -1;
01506     }
01507   }
01508 #endif
01509 
01510   return ourpid;
01511 }

void delete_lock_file gchar *    fname
 

Definition at line 1513 of file util.c.

Referenced by main().

01514 {
01515 #ifndef __MINGW32__
01516   gchar cmd[1024];
01517   /* non-portable?  Yeah... I'll fix it at a later date... */
01518   g_snprintf(cmd, sizeof(cmd), "rm %s", fname);
01519   system(cmd);
01520 #endif
01521 }

void eb_generic_menu_function GtkWidget *    add_button,
gpointer    userdata
 

Definition at line 1523 of file util.c.

References _, menu_item_data::callback, menu_item_data::data, DBG_CORE, eb_debug, and IS_ebmCallbackData.

01524 {
01525     menu_item_data *mid=(menu_item_data *)userdata;
01526     ebmCallbackData *ecd=NULL;
01527 
01528     assert(userdata);
01529     ecd=mid->data;
01530     /* Check for valid data type */
01531     if(!ecd || !IS_ebmCallbackData(ecd)) {
01532         g_warning(_("Unexpected datatype passed to eb_generic_menu_function, ignoring call!"));
01533         return;
01534     }
01535     if(!mid->callback) {
01536         g_warning(_("No callback defined in call to eb_generic_menu_function, ignoring call!"));
01537         return;
01538     }
01539     eb_debug(DBG_CORE, "Calling callback\n");
01540     mid->callback(ecd);
01541 }

char* escape_string char *    input
 

Definition at line 199 of file util.c.

Referenced by value_pair_add(), write_contact_list(), and yyparse().

00200 {
00201     GString * temp_result = g_string_sized_new(2048);
00202     gchar * result;
00203     int ipos = 0;
00204     for(ipos=0;input[ipos];ipos++)
00205     {
00206         if(input[ipos] == '\n')
00207         {
00208             g_string_append(temp_result, "\\n");
00209         }
00210         else if(input[ipos] == '\r')
00211         {
00212             g_string_append(temp_result, "\\r");
00213         }
00214         else if(input[ipos] == '\\')
00215         {
00216             g_string_append(temp_result, "\\\\");
00217         }
00218         else if(input[ipos] == '"')
00219         {
00220             g_string_append(temp_result, "\\\"");
00221         }
00222         else
00223         {
00224             g_string_append_c(temp_result, input[ipos]);
00225         }
00226     }
00227 
00228     result = temp_result->str;
00229     g_string_free(temp_result, FALSE);
00230     return result;
00231 }

eb_account* find_account_by_handle gchar *    handle,
gint    type
 

Definition at line 932 of file util.c.

References aim_normalize(), account::handle, and account::service_id.

Referenced by add_account_verbose().

00933 {
00934     GList * l1;
00935     GList * l2;
00936     GList * l3;
00937 
00938     if (handle == NULL) {
00939     return NULL;
00940     }
00941     for(l1 = groups; l1; l1=l1->next )
00942     {
00943         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next )
00944         {
00945             for(l3 = ((struct contact*)l2->data)->accounts; l3; l3=l3->next)
00946             {
00947                 eb_account * account = (eb_account*)l3->data;
00948         char string1[255];
00949         char string2[255];
00950         strcpy(string1, aim_normalize(account->handle));
00951         strcpy(string2, aim_normalize(handle));
00952                 if(!g_strncasecmp(string1, string2,strlen(string1)+1)
00953                         && account->service_id == type )
00954                     return account;
00955             }
00956         }
00957     }
00958     return NULL;
00959 }

eb_account* find_account_by_handle_normalized gchar *    handle,
gint    type
 

Definition at line 961 of file util.c.

References aim_normalize(), account::handle, and account::service_id.

00962 {
00963     GList * l1;
00964     GList * l2;
00965     GList * l3;
00966  
00967     if (handle == NULL) {
00968         return NULL;
00969     }
00970     for(l1 = groups; l1; l1=l1->next )
00971     {
00972         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next )
00973         {
00974             for(l3 = ((struct contact*)l2->data)->accounts; l3; l3=l3->next)
00975             {
00976                 eb_account * account = (eb_account*)l3->data;
00977                 if(!g_strncasecmp(aim_normalize(account->handle), handle,strlen(handle)+1)
00978                                                 && account->service_id == type )
00979                     return account;
00980             }
00981         }
00982     }
00983     return NULL;
00984 }

eb_chat_room* find_chat_room_by_id gchar *    id
 

Definition at line 737 of file util.c.

References DBG_CORE, and eb_debug.

00738 {
00739     GList * node = chat_rooms;
00740     for( node= chat_rooms; node; node=node->next)
00741     {
00742         eb_chat_room * ecr = node->data;
00743         eb_debug(DBG_CORE, "Comparing %s to %s\n", id, ecr->id );
00744         if(!strcmp(id, ecr->id))
00745             return ecr;
00746     }
00747     return NULL;
00748 
00749 }

eb_chat_room* find_chat_room_by_name gchar *    name,
gint    service_id
 

Definition at line 751 of file util.c.

00752 {
00753     GList * node = chat_rooms;
00754     for( node= chat_rooms; node; node=node->next)
00755     {
00756         eb_chat_room * ecr = node->data;
00757         if(!strcmp(name, ecr->room_name)  && (ecr->chat_room_account->service_id == service_id) )
00758             return ecr;
00759     }
00760     return NULL;
00761 
00762 }

struct contact* find_contact_by_handle gchar *    handle
 

Definition at line 802 of file util.c.

References account::handle.

Referenced by eb_chat_window_display_status().

00803 {
00804     GList * l1;
00805     GList * l2;
00806     GList * l3;
00807 
00808     if (handle == NULL) {
00809     return NULL;
00810     }
00811     for(l1 = groups; l1; l1=l1->next )
00812     {
00813         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next )
00814         {
00815             for(l3 = ((struct contact*)l2->data)->accounts; l3; l3=l3->next)
00816             {
00817                 eb_account * account = (eb_account*)l3->data;
00818                 if(!strcmp(account->handle, handle))
00819                     return (struct contact*)l2->data;
00820             }
00821         }
00822     }
00823     return NULL;
00824 }

struct contact* find_contact_by_nick gchar *    nick
 

Definition at line 826 of file util.c.

Referenced by add_account_verbose(), add_button_callback(), console_session_get_command(), get_accounts(), get_eb_accounts(), and move_contact().

00827 {
00828     GList * l1;
00829     GList * l2;
00830 
00831     if (nick == NULL){
00832     return NULL;
00833     }
00834     for(l1 = groups; l1; l1=l1->next )
00835     {
00836         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next )
00837         {
00838             if(!g_strncasecmp(((struct contact*)l2->data)->nick, nick, strlen(nick)+1))
00839             {
00840                 return (struct contact*)l2->data;
00841             }
00842         }
00843     }
00844     return NULL;
00845 }

struct contact* find_contact_in_group_by_nick gchar *    nick,
grouplist   gl
 

Definition at line 847 of file util.c.

Referenced by ok_callback().

00848 {
00849     GList * l;
00850 
00851     if (nick == NULL || gl == NULL){
00852     return NULL;
00853     }
00854 
00855     for(l = gl->members; l; l=l->next )
00856     {
00857         if(!g_strncasecmp(((struct contact*)l->data)->nick, nick, strlen(nick)+1))
00858         {
00859             return (struct contact*)l->data;
00860         }
00861     }
00862 
00863     return NULL;
00864 }

grouplist* find_grouplist_by_name gchar *    name
 

Definition at line 764 of file util.c.

Referenced by add_button_callback(), add_contact(), add_new_contact(), get_contacts(), get_group_contacts(), move_contact(), and ok_callback().

00765 {
00766     GList * l1;
00767 
00768     if (name == NULL) {
00769     return NULL;
00770     }
00771     for(l1 = groups; l1; l1=l1->next )
00772     {
00773         if(!g_strncasecmp(((grouplist *)l1->data)->name, name, strlen(name)+1))
00774         {
00775              return (grouplist*)l1->data;
00776         }
00777     }
00778     return NULL;
00779 }

grouplist* find_grouplist_by_nick gchar *    nick
 

Definition at line 781 of file util.c.

00782 {
00783     GList * l1;
00784     GList * l2;
00785 
00786     if (nick == NULL) {
00787     return NULL;
00788     }
00789     for(l1 = groups; l1; l1=l1->next )
00790     {
00791         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next )
00792         {
00793             if(!strcmp(((struct contact*)l2->data)->nick, nick))
00794             {
00795                     return (grouplist*)l1->data;
00796             }
00797         }
00798     }
00799     return NULL;
00800 }

eb_local_account* find_local_account_by_handle gchar *    handle,
gint    type
 

Definition at line 986 of file util.c.

References local_account::handle, and local_account::service_id.

Referenced by ok_callback().

00987 {
00988     GList * l1;
00989 
00990     for(l1 = accounts; l1; l1=l1->next )
00991     {
00992          eb_local_account * account = (eb_local_account*)l1->data;
00993          if(account->service_id == type && !g_strncasecmp(account->handle, handle, strlen(handle)+1))
00994               return account;
00995     }
00996     return NULL;
00997 }

eb_local_account* find_local_account_for_remote eb_account   remote,
gboolean    online
 

Definition at line 565 of file util.c.

References local_account::connected, local_account::service_id, and account::service_id.

Referenced by get_local_accounts().

00566 {
00567     static GList * node = NULL;
00568     static eb_account *last_remote=NULL;
00569 
00570     /* If this is a normal call, start at the top and give the first, otherwise continue where we left off */
00571     if(remote) {
00572         node = accounts;
00573         last_remote=remote;
00574     }
00575     else {
00576         remote = last_remote;
00577         if(node)
00578             node=node->next;
00579     }
00580     for( ; node; node = node->next )
00581     {
00582         eb_local_account * ela = (eb_local_account *)(node->data);
00583         
00584         if (remote->service_id == ela->service_id)
00585         {
00586             if (eb_services[ela->service_id].sc->is_suitable != NULL)
00587             {
00588                 if (eb_services[ela->service_id].sc->is_suitable(ela, remote) == TRUE)
00589                 {
00590                     if (online && (! ela->connected)) {}
00591                     else
00592                     {
00593                         return (ela);
00594                     }
00595                 }
00596             }
00597             else
00598             {
00599                 if (online && (! ela->connected)) {}
00600                 else
00601                 {
00602                     return (ela);
00603                 }
00604             }
00605         }
00606     }
00607     
00608     /*We can't find anything, let's bail*/
00609     return NULL;
00610 }

eb_account* find_suitable_file_transfer_account eb_account   first,
struct contact   rest
 

Definition at line 702 of file util.c.

References contact::accounts, contact::default_chatb, and account::service_id.

Referenced by send_file_callback().

00704 {
00705     GList * node;
00706     eb_account * possibility = NULL;
00707 
00708     if ( first == NULL )
00709         return NULL;
00710 
00711     if( first && eb_services[first->service_id].sc->query_connected(first)
00712             && eb_services[first->service_id].file_transfer )
00713     {
00714         return first;
00715     }
00716     
00717     for(node = rest->accounts; node; node=node->next)
00718     {
00719         eb_account * ea = (eb_account*)node->data;
00720         
00721         if( eb_services[ea->service_id].sc->query_connected(ea)
00722                 && eb_services[first->service_id].file_transfer )
00723         {
00724             if(ea->service_id == rest->default_chatb )
00725             {
00726                 return ea;
00727             }
00728             else
00729             {
00730                 possibility = ea;
00731             }
00732         }
00733     }
00734     return possibility;
00735 }

eb_local_account* find_suitable_local_account eb_local_account   first,
gint    second
 

Definition at line 612 of file util.c.

References local_account::connected, DBG_CORE, eb_debug, local_account::handle, and local_account::service_id.

Referenced by eb_chat_window_display_account(), eb_chat_window_display_contact(), eb_start_chat_room(), get_info(), send_file_callback(), send_message(), and send_typing_status().

00614 {
00615     GList * node;
00616     GList * states;
00617     
00618     /*The last state in the list of states will be the OFFLINE state*
00619      *The first state in the list will be the ONLINE states         *
00620      *The rest of the states are the various AWAY states            */
00621     
00622     states = eb_services[second].sc->get_states();
00623     
00624     g_list_free(states);
00625     
00626     if( first && first->connected )
00627     {
00628         /* hurrah, we got our first choice */
00629         return first;
00630     }
00631             
00632     /*dang, we are out of luck with our first choice, do we have something
00633       else that uses the same service? */
00634 
00635     for( node = accounts; node; node = node->next )
00636     {
00637         eb_local_account * ela = (eb_local_account *)(node->data);
00638             eb_debug(DBG_CORE, "%s %s\n", eb_services[ela->service_id].name, ela->handle);
00639         
00640         if( ela->service_id == second && ela->connected )
00641         {
00642             return ela;
00643         }
00644         else if( !ela->connected )
00645         {
00646             eb_debug(DBG_CORE, "%s is offline!\n", ela->handle );
00647         }
00648             
00649     }
00650     
00651     /*We can't find anything, let's bail*/
00652     return NULL;
00653 }

eb_account* find_suitable_remote_account eb_account   first,
struct contact   rest
 

Definition at line 672 of file util.c.

References contact::accounts, contact::default_chatb, and account::service_id.

Referenced by add_unknown_callback(), console_session_get_command(), eb_chat_window_display_contact(), get_local_accounts(), send_file(), send_file_with_contact_callback(), send_message(), and send_typing_status().

00674 {
00675     GList * node;
00676     eb_account * possibility = NULL;
00677 
00678     if( first && eb_services[first->service_id].sc->query_connected(first) )
00679     {
00680         return first;
00681     }
00682     
00683     for(node = rest->accounts; node; node=node->next)
00684     {
00685         eb_account * ea = (eb_account*)node->data;
00686         
00687         if( eb_services[ea->service_id].sc->query_connected(ea) )
00688         {
00689             if(ea->service_id == rest->default_chatb )
00690             {
00691                 return ea;
00692             }
00693             else
00694             {
00695                 possibility = ea;
00696             }
00697         }
00698     }
00699     return possibility;
00700 }

char* get_local_addresses  
 

Definition at line 74 of file util.c.

Referenced by eb_parse_incomming_message().

00075 {
00076     static char addresses[1024];
00077     char buff[1024];
00078     char gateway[16];
00079     char  * c;
00080     struct hostent * hn;
00081     int i;
00082         FILE * f;
00083         //system("getip.pl > myip");
00084         f = popen("netstat -nr", "r");
00085         if((int)f < 1)
00086                 goto IP_TEST_2;
00087         while( fgets(buff, sizeof(buff), f)  != NULL )
00088         {
00089                 c = strtok( buff, " " );
00090                 if( (strstr(c, "default") || strstr(c,"0.0.0.0") ) &&
00091                                 !strstr(c, "127.0.0" ) )
00092                         break;
00093         }
00094         c = strtok( NULL, " " );
00095         pclose(f);
00096 
00097         strncpy(gateway,c, 16);
00098 
00099         
00100         
00101         for(i = strlen(gateway); gateway[i] != '.'; i-- )
00102         {
00103             gateway[i] = 0;
00104         }
00105 
00106         gateway[i] = 0;
00107 
00108         for(i = strlen(gateway); gateway[i] != '.'; i-- )
00109         {
00110             gateway[i] = 0;
00111         }
00112 
00113         //g_snprintf(buff, 1024, "/sbin/ifconfig -a|grep inet|grep %s", gateway );
00114         f = popen("/sbin/ifconfig -a", "r");
00115         if((int)f < 1)
00116                 goto IP_TEST_2;
00117         
00118         while( fgets(buff, sizeof(buff), f) != NULL )
00119         {
00120                 if( strstr(buff, "inet") && strstr(buff,gateway) )
00121                         break;
00122         }
00123         pclose(f);
00124         
00125         c = strtok( buff, " " );
00126         c = strtok( NULL, " " );
00127 
00128         strncpy ( addresses, c, sizeof(addresses) );
00129         c = strtok(addresses, ":" );
00130         strncpy ( buff, c, sizeof(buff) );
00131         if((c=strtok(NULL, ":")))
00132         {
00133             strncpy( buff, c, sizeof(buff) );
00134         }
00135 
00136         
00137         strncpy(addresses, buff, sizeof(addresses));
00138 
00139         return addresses;
00140         
00141         
00142 IP_TEST_2:
00143 
00144         gethostname(buff,sizeof(buff));
00145         
00146         hn = gethostbyname(buff);
00147         if(hn)
00148                 strncpy(addresses, inet_ntoa( *((struct in_addr*)hn->h_addr)), sizeof(addresses) );
00149         else
00150                 addresses[0] = 0;
00151         return addresses;
00152 }

gint gtk_notebook_get_number_pages GtkNotebook *    notebook
 

Definition at line 1442 of file util.c.

Referenced by close_tab_callback().

01443 {
01444   gint i = 0;  
01445 
01446   for (i = 0; gtk_notebook_get_nth_page(notebook, i) != NULL; i++) {
01447   }
01448 
01449   return i;
01450 }

void invite_dialog eb_local_account   ela,
char *    user,
char *    chat_room,
void *    id
 

Definition at line 1406 of file util.c.

References _, do_dialog(), _invite_request::ela, _invite_request::id, and process_invite().

01408 {
01409     char * message = g_strdup_printf(
01410             _("User %s wants to invite you to\n%s\nWould you like to accept?"),
01411             user, chat_room);
01412     invite_request * invite = g_new0( invite_request, 1 );
01413 
01414     invite->ela = ela;
01415     invite->id = id;
01416     do_dialog( message, _("Chat Invite"), process_invite, invite );
01417     g_free(message);
01418 }

gchar* linkify gchar *    input
 

Definition at line 510 of file util.c.

References DBG_HTML, eb_debug, get_next_token(), and linkify_token().

Referenced by eb_chat_room_show_message(), eb_parse_incomming_message(), and send_message().

00511 {
00512     int i = 0;
00513     int len = strlen(input);
00514     gchar * result;
00515     GString * temp_result;
00516     GString * temp = NULL;
00517 
00518     temp_result = g_string_sized_new(2048);
00519 
00520     while( i < len )
00521     {
00522         if( isspace(input[i]) )
00523         {
00524             g_string_append_c(temp_result, input[i]);
00525             i++;
00526         }
00527         else
00528         {
00529             temp = get_next_token(input+i);
00530             eb_debug(DBG_HTML, "%s\t%s\t%d\t%d\n", input, input+i, i, temp->len);
00531             i += temp->len;
00532             linkify_token(temp);
00533             g_string_append(temp_result, temp->str);
00534             g_string_free(temp, TRUE);
00535         }
00536     }
00537 
00538     result = temp_result->str;
00539     g_string_free(temp_result, FALSE);
00540     return result;
00541 }

void make_safe_filename gchar *    buff,
gchar *    name
 

Definition at line 1423 of file util.c.

References NAME_MAX.

Referenced by eb_chat_window_display_account(), eb_chat_window_display_contact(), eb_chat_window_display_remote_message(), eb_chat_window_new(), and load_log_information().

01423                                                    {
01424     
01425     /* i'm pretty sure the only illegal character is '/', but maybe 
01426      * there are others i'm forgetting */
01427     char *bad_chars="/";
01428     char *p;
01429     char holder[NAME_MAX];
01430 
01431     strncpy(holder, name, NAME_MAX);
01432 
01433     for (p=holder; *p; p++) {
01434         if ( strchr(bad_chars, *p) )
01435             *p='_';
01436     }
01437     g_snprintf(buff, NAME_MAX, "%slogs/%s", 
01438                 config_dir, holder);
01439 }

void move_account struct contact   c,
eb_account   account
 

Definition at line 1304 of file util.c.

References account::account_contact, contact::accounts, add_contact_and_accounts(), contact::group, handle_group_change(), _grouplist::name, account::online, contact::online, remove_account_line(), remove_contact(), and remove_contact_line().

Referenced by ok_callback().

01305 {
01306     struct contact *c = ea->account_contact;
01307     gchar * new_group = con->group->name;
01308     gchar *old_group = c->group->name;
01309     
01310     handle_group_change(ea, old_group, new_group);
01311 
01312     c->accounts = g_list_remove(c->accounts, ea);
01313 
01314     remove_account_line(ea);
01315     if(g_list_length(c->accounts) == 0)
01316         remove_contact(c);
01317     else {
01318         GList *l;
01319         c->online = 0;
01320         for(l=c->accounts; l; l=l->next)
01321             if(((eb_account *)l->data)->online)
01322                 c->online++;
01323         if(!c->online)
01324             remove_contact_line(c);
01325         else
01326             add_contact_and_accounts(c);
01327     }
01328 
01329     con->accounts = g_list_append(con->accounts, ea);
01330 
01331     ea->account_contact = con;
01332     if(ea->online)
01333         con->online++;
01334 
01335     add_contact_and_accounts(con);
01336 }

void move_contact gchar *    group,
struct contact   c
 

Definition at line 1338 of file util.c.

References account::account_contact, contact::accounts, add_contact_and_accounts(), add_group(), add_group_line(), contact_cmp(), find_contact_by_nick(), find_grouplist_by_name(), contact::group, handle_group_change(), _grouplist::members, _grouplist::name, contact::nick, and remove_contact_line().

Referenced by drag_data_get(), ignore_dialog_callback(), and ok_callback().

01339 {
01340     grouplist * g = c->group;
01341     struct contact *con;
01342     GList *l = c->accounts;
01343     
01344     g->members = g_list_remove(g->members, c);
01345     remove_contact_line(c);
01346     g = find_grouplist_by_name(group);
01347     
01348     if(!g)
01349     {
01350         add_group(group);
01351         g = find_grouplist_by_name(group);
01352     }
01353     add_group_line(g);
01354 
01355     for(; l; l=l->next)
01356     {
01357         eb_account *ea = l->data;
01358         handle_group_change(ea, c->group->name, group);
01359     }
01360 
01361     con = find_contact_by_nick(c->nick);
01362     if(con) 
01363     {
01364         l = c->accounts;
01365         while(l)
01366         {
01367             eb_account *ea = l->data;
01368 
01369                 ea->account_contact = con;
01370             con->accounts = g_list_append(con->accounts, ea);
01371             l = l->next;
01372         }
01373         g_list_free(c->accounts);
01374         add_contact_and_accounts(con);
01375     } else {
01376         g->members = g_list_insert_sorted(g->members, c, contact_cmp);
01377         c->group = g;
01378         add_contact_and_accounts(c);
01379     }
01380 }

void refresh_service_contacts gint    type
 

Definition at line 890 of file util.c.

References contact::accounts, contact::chatwindow, DBG_CORE, DBG_MOD, eb_debug, account::handle, contact::nick, _chat_window::perfered, account::protocol_account_data, account::service_id, value_pair_add(), and value_pair_free().

Referenced by add_service().

00891 {
00892     GList * l1;
00893     GList * l2;
00894     GList * l3;
00895     GList * config=NULL;
00896     struct contact *con=NULL;
00897 
00898     eb_debug(DBG_CORE, ">Refreshing contacts for %i\n", type);
00899     for(l1 = groups; l1; l1=l1->next )
00900     {
00901         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next )
00902         {
00903         con=(struct contact *)l2->data;
00904         if(con->chatwindow && con->chatwindow->perfered && (con->chatwindow->perfered->service_id==type))
00905         {
00906         eb_debug(DBG_MOD, "Setting the perfered service to NULL for %s\n", con->nick);
00907         con->chatwindow->perfered=NULL;
00908         }
00909             for(l3 = con->accounts; l3; l3=l3->next)
00910             {
00911                 eb_account * account = (eb_account*)l3->data;
00912                 if(account->service_id == type) {
00913                eb_debug(DBG_CORE, "Refreshing %s - %i\n", account->handle, type);
00914                config = value_pair_add(NULL, "NAME", account->handle);
00915                g_free(account->protocol_account_data);
00916                g_free(account);
00917                account = eb_services[type].sc->read_account_config(config, (struct contact*)l2->data);
00918                /* Is this a nomodule account?  Make it the right service number */
00919                if(account->service_id==-1)
00920                    account->service_id=type;
00921                value_pair_free(config);
00922                config=NULL;
00923                l3->data=account;
00924         }
00925             }
00926         }
00927     }
00928     eb_debug(DBG_CORE, "<Leaving\n");
00929     return;
00930 }

void remove_account eb_account   a
 

Definition at line 1109 of file util.c.

References account::account_contact, contact::accounts, buddy_logoff(), remove_account_line(), and RUN_SERVICE.

Referenced by add_account_verbose(), remove_account_callback(), and remove_contact().

01110 {
01111     struct contact * c = a->account_contact;
01112     buddy_logoff(a);
01113     remove_account_line(a);
01114     c->accounts = g_list_remove(c->accounts, a);
01115     RUN_SERVICE(a)->del_user(a);
01116     g_free(a);
01117 }

void remove_contact struct contact   c
 

Definition at line 1118 of file util.c.

References contact::accounts, contact::chatwindow, contact::group, _grouplist::members, remove_account(), remove_contact_line(), and _chat_window::window.

Referenced by add_account_verbose(), move_account(), remove_contact_callback(), and remove_group().

01119 {
01120     grouplist * g = c->group;
01121     if(c->chatwindow)
01122         gtk_widget_destroy(c->chatwindow->window);
01123     while(c->accounts)
01124     {
01125         remove_account(c->accounts->data);
01126     }
01127     remove_contact_line(c);
01128     g->members = g_list_remove(g->members, c);
01129     g_free(c);
01130 
01131 }

void remove_group grouplist   g
 

Definition at line 1132 of file util.c.

References _grouplist::members, remove_contact(), and remove_group_line().

Referenced by remove_group_callback().

01133 {
01134     while(g->members)
01135     {
01136         remove_contact(g->members->data);
01137     }
01138     remove_group_line(g);
01139     groups = g_list_remove(groups,g);
01140     g_free(g);
01141 }

void strip_html gchar *    text
 

Definition at line 999 of file util.c.

Referenced by eb_log_message(), eb_restore_last_conv(), search_callback(), and speak_message().

01000 {
01001     int i, j;
01002     int visible = 1;
01003     
01004     for( i=0, j=0; text[i]; i++ )
01005     {
01006         if(text[i]=='<')
01007         {
01008             switch(text[i+1])
01009             {
01010                 case 'a':
01011                 case 'A':
01012                     if(isspace(text[i+2]) || text[i+2] == '>')
01013                     {
01014                         visible = 0;
01015                     }
01016                     break;
01017 
01018                 case 'i':
01019                 case 'I':
01020                 case 'u':
01021                 case 'U':
01022                 case 'p':
01023                 case 'P':
01024                     if(text[i+2] == '>')
01025                     {
01026                         visible = 0;
01027                     }
01028                     break;
01029                 case 'b':
01030                 case 'B':
01031                     if(text[i+2] == '>')
01032                     {
01033                         visible = 0;
01034                     }
01035                     else if(text[i+2] == 'O' || text[i+2] == 'o')
01036                     {
01037                         if(text[i+3] == 'D' || text[i+3] == 'd' )
01038                         {
01039                             if(text[i+4] == 'Y' || text[i+4] == 'y' )
01040                             {
01041                                 if(isspace(text[i+5]) || text[i+5] == '>')
01042                                 {
01043                                     visible = 0;
01044                                 }
01045                             }
01046                         }
01047                     }
01048                     break;
01049                 case 'h':
01050                 case 'H':
01051                     if(text[i+2] == 'T' || text[i+2] == 't')
01052                     {
01053                         if(text[i+3] == 'M' || text[i+3] == 'm')
01054                         {
01055                             if(text[i+4] == 'L' || text[i+4] == 'l')
01056                             {
01057                                 if(isspace(text[i+5]) || text[i+5] == '>')
01058                                 {
01059                                     visible = 0;
01060                                 }
01061                             }
01062                         }
01063                     }
01064                     break;
01065                                 
01066                 case 'F':
01067                 case 'f':
01068                     if(text[i+2] == 'o' || text[i+2] == 'O')
01069                     {
01070                         if(text[i+3] == 'n' || text[i+3] == 'N')
01071                         {
01072                             if(text[i+4] == 't' || text[i+4] == 'T')
01073                             {
01074                                 if(isspace(text[i+5]) || text[i+5] == '>')
01075                                 {
01076                                     visible = 0;
01077                                 }
01078                             }
01079                         }
01080                     }
01081                     break;
01082                 case 's':
01083                     if (!strncmp(text+i+2,"miley", 5)) {
01084                         visible = 0;
01085                         text[j++]=' '; /*hack*/
01086                     }
01087                 case '/':
01088                     visible = 0;
01089                     break;
01090             }
01091         }
01092         else if(text[i] == '>')
01093         {
01094             if(!visible)
01095             {
01096                 visible = 1;
01097                 continue;
01098             }
01099         }
01100         if(visible)
01101         {
01102             text[j++] = text[i];
01103         }
01104     }
01105     text[j] = '\0';
01106 }

char* unescape_string char *    input
 

Definition at line 232 of file util.c.

Referenced by value_pair_get_value(), and yyparse().

00233 {
00234     gchar * result = g_malloc0(strlen(input)+1);
00235     int ipos=0, opos=0; 
00236     while(input[ipos])
00237     {
00238         char c = input[ipos++];
00239         if(c == '\\')
00240         {
00241             c = input[ipos++];
00242             switch(c)
00243             {
00244                 case 'n':
00245                     result[opos++] = '\n';
00246                     break;
00247                 case 'r':   
00248                     result[opos++] = '\r';
00249                     break;
00250                 case '\\':  
00251                     result[opos++] = '\\';
00252                     break;
00253                 case '\"':  
00254                     result[opos++] = '\"';
00255                     break;
00256             }
00257         }
00258         else
00259         {
00260             result[opos++] = c;
00261         }
00262     }
00263     result[opos] = '\0';
00264 
00265     return result;
00266 
00267 }


Variable Documentation

GtkWidget* statuswindow
 

Definition at line 49 of file util.h.

Referenced by eb_status_window(), and focus_statuswindow().


Contact: Andy Maloney     [Documentation generated by doxygen]