Changeset bf02a67 for protocols


Ignore:
Timestamp:
2005-12-15T11:55:27Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
15832cc, bd69a21
Parents:
11e090b (diff), 547f937 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged Jelmer's pluginable tree (mainly useful for the Win32 port).

Location:
protocols
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r11e090b rbf02a67  
    155155#define JCS_CLOSED  3   /* closed */
    156156
    157 
    158 static char *jabber_name()
    159 {
    160         return "Jabber";
    161 }
    162157
    163158#define STATE_EVT(arg) if(gjc->on_state) { (gjc->on_state)(gjc, (arg) ); }
     
    23682363}
    23692364
    2370 static struct prpl *my_protocol = NULL;
    2371 
    2372 void jabber_init(struct prpl *ret)
    2373 {
     2365
     2366void jabber_init()
     2367{
     2368        struct prpl *ret = g_new0(struct prpl, 1);
     2369
    23742370        /* the NULL's aren't required but they're nice to have */
    2375         ret->protocol = PROTO_JABBER;
    2376         ret->name = jabber_name;
     2371        ret->name = "jabber";
    23772372        ret->away_states = jabber_away_states;
    23782373        ret->actions = jabber_actions;
     
    23982393        ret->cmp_buddynames = g_strcasecmp;
    23992394
    2400         my_protocol = ret;
    2401 }
     2395        register_protocol (ret);
     2396}
  • protocols/msn/msn.c

    r11e090b rbf02a67  
    2626#include "nogaim.h"
    2727#include "msn.h"
    28 
    29 static struct prpl *my_protocol = NULL;
    3028
    3129static void msn_login( struct aim_user *acct )
     
    375373}
    376374
    377 void msn_init(struct prpl *ret)
    378 {
    379         ret->protocol = PROTO_MSN;
     375void msn_init()
     376{
     377        struct prpl *ret = g_new0(struct prpl, 1);
     378        ret->name = "msn";
    380379        ret->login = msn_login;
    381380        ret->close = msn_close;
     
    400399        ret->cmp_buddynames = g_strcasecmp;
    401400
    402         my_protocol = ret;
    403 }
     401        register_protocol(ret);
     402}
  • protocols/nogaim.c

    r11e090b rbf02a67  
    3939#include <iconv.h>
    4040
    41 struct prpl *proto_prpl[PROTO_MAX];
    42 char proto_name[PROTO_MAX][8] = { "TOC", "OSCAR", "YAHOO", "ICQ", "MSN", "", "", "", "JABBER", "", "", "", "", "", "", "" };
    43 
    4441static char *proto_away_alias[7][5] =
    4542{
     
    5855GSList *connections;
    5956
     57#ifdef WITH_PLUGINS
     58gboolean load_plugin(char *path)
     59{
     60        void (*init_function) (void);
     61       
     62        GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY);
     63
     64        if(!mod) {
     65                log_message(LOGLVL_ERROR, "Can't find `%s', not loading", path);
     66                return FALSE;
     67        }
     68
     69        if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) {
     70                log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path);
     71                return FALSE;
     72        }
     73
     74        init_function();
     75
     76        return TRUE;
     77}
     78
     79void load_plugins(void)
     80{
     81        GDir *dir;
     82        GError *error = NULL;
     83
     84        dir = g_dir_open(PLUGINDIR, 0, &error);
     85
     86        if (dir) {
     87                const gchar *entry;
     88                char *path;
     89
     90                while ((entry = g_dir_read_name(dir))) {
     91                        path = g_build_filename(PLUGINDIR, entry, NULL);
     92                        if(!path) {
     93                                log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry);
     94                                continue;
     95                        }
     96
     97                        load_plugin(path);
     98
     99                        g_free(path);
     100                }
     101
     102                g_dir_close(dir);
     103        }
     104}
     105#endif
    60106
    61107/* nogaim.c */
    62108
     109GList *protocols = NULL;
     110 
     111void register_protocol (struct prpl *p)
     112{
     113        protocols = g_list_append(protocols, p);
     114}
     115
     116 
     117struct prpl *find_protocol(const char *name)
     118{
     119        GList *gl;
     120        for (gl = protocols; gl; gl = gl->next)
     121        {
     122                struct prpl *proto = gl->data;
     123                if(!g_strcasecmp(proto->name, name))
     124                        return proto;
     125        }
     126        return NULL;
     127}
     128
     129/* nogaim.c */
    63130void nogaim_init()
    64131{
    65         proto_prpl[PROTO_MSN] = g_new0 ( struct prpl, 1 );
     132        extern void msn_init();
     133        extern void oscar_init();
     134        extern void byahoo_init();
     135        extern void jabber_init();
     136
    66137#ifdef WITH_MSN
    67         msn_init( proto_prpl[PROTO_MSN] );
     138        msn_init();
    68139#endif
    69140
    70         proto_prpl[PROTO_OSCAR] = g_new0( struct prpl, 1 );
    71141#ifdef WITH_OSCAR
    72         oscar_init( proto_prpl[PROTO_OSCAR] );
     142        oscar_init();
    73143#endif
    74144       
    75         proto_prpl[PROTO_YAHOO] = g_new0( struct prpl, 1 );
    76145#ifdef WITH_YAHOO
    77         byahoo_init( proto_prpl[PROTO_YAHOO] );
     146        byahoo_init();
    78147#endif
    79148       
    80         proto_prpl[PROTO_JABBER] = g_new0( struct prpl, 1 );
    81149#ifdef WITH_JABBER
    82         jabber_init( proto_prpl[PROTO_JABBER] );
     150        jabber_init();
     151#endif
     152
     153#ifdef WITH_PLUGINS
     154        load_plugins();
    83155#endif
    84156}
     
    172244        gc = g_new0( struct gaim_connection, 1 );
    173245       
    174         gc->protocol = user->protocol;
    175         gc->prpl = proto_prpl[gc->protocol];
     246        gc->prpl = user->prpl;
    176247        g_snprintf( gc->username, sizeof( gc->username ), "%s", user->username );
    177248        g_snprintf( gc->password, sizeof( gc->password ), "%s", user->password );
     
    254325        /* Try to find a different connection on the same protocol. */
    255326        for( a = gc->irc->accounts; a; a = a->next )
    256                 if( proto_prpl[a->protocol] == gc->prpl && a->gc != gc )
     327                if( a->prpl == gc->prpl && a->gc != gc )
    257328                        break;
    258329       
    259330        /* If we found one, add the screenname to the acc_id. */
    260331        if( a )
    261                 g_snprintf( acc_id, 32, "%s(%s)", proto_name[gc->protocol], gc->username );
     332                g_snprintf( acc_id, 32, "%s(%s)", gc->prpl->name, gc->username );
    262333        else
    263                 g_snprintf( acc_id, 32, "%s", proto_name[gc->protocol] );
     334                g_snprintf( acc_id, 32, "%s", gc->prpl->name );
    264335       
    265336        irc_usermsg( gc->irc, "%s - %s", acc_id, msg );
     
    295366        if( u && u->away ) proto_away( gc, u->away );
    296367       
    297         if( gc->protocol == PROTO_ICQ )
     368        if( !strcmp(gc->prpl->name, "icq") )
    298369        {
    299370                for( u = gc->irc->users; u; u = u->next )
     
    430501       
    431502        memset( nick, 0, MAX_NICK_LENGTH + 1 );
    432         strcpy( nick, nick_get( gc->irc, handle, gc->protocol, realname ) );
     503        strcpy( nick, nick_get( gc->irc, handle, gc->prpl, realname ) );
    433504       
    434505        u = user_add( gc->irc, nick );
     
    454525        else
    455526        {
    456                 u->host = g_strdup( proto_name[gc->user->protocol] );
     527                u->host = g_strdup( gc->user->prpl->name );
    457528                u->user = g_strdup( handle );
    458529        }
     
    583654        }
    584655       
    585         if( ( type & UC_UNAVAILABLE ) && ( gc->protocol == PROTO_OSCAR || gc->protocol == PROTO_TOC ) )
     656        if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "oscar") || !strcmp(gc->prpl->name, "icq")) )
    586657        {
    587658                u->away = g_strdup( "Away" );
    588659        }
    589         else if( ( type & UC_UNAVAILABLE ) && ( gc->protocol == PROTO_JABBER ) )
     660        else if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "jabber") ) )
    590661        {
    591662                if( type & UC_DND )
  • protocols/nogaim.h

    r11e090b rbf02a67  
    7272        /* we need to do either oscar or TOC */
    7373        /* we make this as an int in case if we want to add more protocols later */
    74         int protocol;
    7574        struct prpl *prpl;
    7675        guint32 flags;
     
    152151        char user_info[2048];
    153152        int options;
    154         int protocol;
     153        struct prpl *prpl;
    155154        /* prpls can use this to save information about the user,
    156155         * like which server to connect to, etc */
     
    162161
    163162struct prpl {
    164         int protocol;
    165163        int options;
    166         char *(* name)();
     164        const char *name;
    167165
    168166        /* for ICQ and Yahoo, who have off/on per-conversation options */
     
    224222};
    225223
    226 #define PROTO_TOC       0
    227 #define PROTO_OSCAR     1
    228 #define PROTO_YAHOO     2
    229 #define PROTO_ICQ       3
    230 #define PROTO_MSN       4
    231 #define PROTO_IRC       5
    232 #define PROTO_FTP       6
    233 #define PROTO_VGATE     7
    234 #define PROTO_JABBER    8
    235 #define PROTO_NAPSTER   9
    236 #define PROTO_ZEPHYR    10
    237 #define PROTO_GADUGADU  11
    238 #define PROTO_MAX       16
    239 
    240 extern char proto_name[PROTO_MAX][8];
    241 
    242224#define UC_UNAVAILABLE  1
    243225
     
    249231
    250232G_MODULE_EXPORT GSList *get_connections();
    251 extern struct prpl *proto_prpl[16];
     233G_MODULE_EXPORT struct prpl *find_protocol(const char *name);
     234G_MODULE_EXPORT void register_protocol(struct prpl *);
    252235
    253236/* nogaim.c */
     
    319302G_MODULE_EXPORT void info_string_append(GString *str, char *newline, char *name, char *value);
    320303
    321 #ifdef WITH_MSN
    322 /* msn.c */
    323 G_MODULE_EXPORT void msn_init( struct prpl *ret );
    324 #endif
    325 
    326 #ifdef WITH_OSCAR
    327 /* oscar.c */
    328 G_MODULE_EXPORT void oscar_init( struct prpl *ret );
    329 #endif
    330 
    331 #ifdef WITH_JABBER
    332 /* jabber.c */
    333 G_MODULE_EXPORT void jabber_init( struct prpl *ret );
    334 #endif
    335 
    336 #ifdef WITH_YAHOO
    337 /* yahoo.c */
    338 G_MODULE_EXPORT void byahoo_init( struct prpl *ret );
    339 #endif
    340 
    341304/* prefs.c */
    342305G_MODULE_EXPORT void build_block_list();
  • protocols/oscar/oscar.c

    r11e090b rbf02a67  
    357357                odata->icq = TRUE;
    358358                /* this is odd but it's necessary for a proper do_import and do_export */
    359                 gc->protocol = PROTO_ICQ;
    360359                gc->password[8] = 0;
    361360        } else {
    362                 gc->protocol = PROTO_TOC;
    363361                gc->flags |= OPT_CONN_HTML;
    364362        }
     
    26332631}
    26342632
    2635 static struct prpl *my_protocol = NULL;
    2636 
    2637 void oscar_init(struct prpl *ret) {
    2638         ret->protocol = PROTO_OSCAR;
     2633void oscar_init()
     2634{
     2635        struct prpl *ret = g_new0(struct prpl, 1);
     2636        ret->name = "oscar";
    26392637        ret->away_states = oscar_away_states;
    26402638        ret->login = oscar_login;
     
    26582656        ret->cmp_buddynames = aim_sncmp;
    26592657        ret->get_status_string = oscar_get_status_string;
    2660 
    26612658        ret->send_typing = oscar_send_typing;
    26622659
    2663         my_protocol = ret;
    2664 }
     2660        register_protocol(ret);
     2661}
  • protocols/yahoo/yahoo.c

    r11e090b rbf02a67  
    6464};
    6565
    66 static char *yahoo_name()
    67 {
    68         return "Yahoo";
    69 }
    70 
    71 static struct prpl *my_protocol = NULL;
    7266static GSList *byahoo_inputs = NULL;
    7367static int byahoo_chat_id = 0;
     
    396390}
    397391
    398 void byahoo_init( struct prpl *ret )
    399 {
    400         ret->protocol = PROTO_YAHOO;
    401         ret->name = yahoo_name;
     392void byahoo_init( )
     393{
     394        struct prpl *ret = g_new0(struct prpl, 1);
     395        ret->name = "yahoo";
    402396       
    403397        ret->login = byahoo_login;
    404398        ret->close = byahoo_close;
    405399        ret->send_im = byahoo_send_im;
    406         ret->send_typing = byahoo_send_typing;
    407400        ret->get_info = byahoo_get_info;
    408401        ret->away_states = byahoo_away_states;
     
    412405        ret->remove_buddy = byahoo_remove_buddy;
    413406        ret->get_status_string = byahoo_get_status_string;
     407        ret->send_typing = byahoo_send_typing;
    414408       
    415409        ret->chat_send = byahoo_chat_send;
     
    419413        ret->cmp_buddynames = g_strcasecmp;
    420414       
    421         my_protocol = ret;
     415        register_protocol(ret);
    422416}
    423417
     
    433427                yd = gc->proto_data;
    434428               
    435                 if( gc->protocol == PROTO_YAHOO && yd->y2_id == id )
     429                if( !strcmp(gc->prpl->name, "yahoo") && yd->y2_id == id )
    436430                        return( gc );
    437431        }
Note: See TracChangeset for help on using the changeset viewer.