aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--account.c14
-rw-r--r--account.h4
-rw-r--r--bitlbee.c39
-rw-r--r--commands.c33
-rwxr-xr-xconfigure9
-rw-r--r--doc/example_plugin.c13
-rw-r--r--irc.c2
-rw-r--r--nick.c4
-rw-r--r--nick.h6
-rw-r--r--protocols/jabber/jabber.c15
-rw-r--r--protocols/msn/msn.c9
-rw-r--r--protocols/nogaim.c127
-rw-r--r--protocols/nogaim.h75
-rw-r--r--protocols/oscar/oscar.c12
-rw-r--r--protocols/proxy.c10
-rw-r--r--protocols/yahoo/yahoo.c18
-rw-r--r--query.c2
-rw-r--r--unix.c5
-rw-r--r--url.h3
-rw-r--r--user.c2
20 files changed, 234 insertions, 168 deletions
diff --git a/account.c b/account.c
index d5bd24c4..c1e25a06 100644
--- a/account.c
+++ b/account.c
@@ -27,7 +27,7 @@
#include "bitlbee.h"
#include "account.h"
-account_t *account_add( irc_t *irc, int protocol, char *user, char *pass )
+account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass )
{
account_t *a;
@@ -41,7 +41,7 @@ account_t *account_add( irc_t *irc, int protocol, char *user, char *pass )
irc->accounts = a = g_new0 ( account_t, 1 );
}
- a->protocol = protocol;
+ a->prpl = prpl;
a->user = g_strdup( user );
a->pass = g_strdup( pass );
a->irc = irc;
@@ -65,7 +65,7 @@ account_t *account_get( irc_t *irc, char *id )
for( a = irc->accounts; a; a = a->next )
{
- if( g_strcasecmp( id, proto_name[a->protocol] ) == 0 )
+ if( g_strcasecmp( id, a->prpl->name ) == 0 )
{
if( !ret )
ret = a;
@@ -123,9 +123,9 @@ void account_on( irc_t *irc, account_t *a )
return;
}
- if( proto_prpl[a->protocol]->login == NULL )
+ if (a->prpl == NULL )
{
- irc_usermsg( irc, "Support for protocol %s is not included in this BitlBee", proto_name[a->protocol] );
+ irc_usermsg( irc, "Support for protocol %s is not included in this BitlBee", a->prpl->name );
return;
}
@@ -133,7 +133,7 @@ void account_on( irc_t *irc, account_t *a )
u = g_new0 ( struct aim_user, 1 );
u->irc = irc;
- u->protocol = a->protocol;
+ u->prpl = a->prpl;
strncpy( u->username, a->user, sizeof( u->username ) - 1 );
strncpy( u->password, a->pass, sizeof( u->password ) - 1 );
if( a->server) strncpy( u->proto_opt[0], a->server, sizeof( u->proto_opt[0] ) - 1 );
@@ -141,7 +141,7 @@ void account_on( irc_t *irc, account_t *a )
a->gc = (struct gaim_connection *) u; /* Bit hackish :-/ */
a->reconnect = 0;
- proto_prpl[a->protocol]->login( u );
+ a->prpl->login( u );
}
void account_off( irc_t *irc, account_t *a )
diff --git a/account.h b/account.h
index a8653411..37cd8814 100644
--- a/account.h
+++ b/account.h
@@ -28,7 +28,7 @@
typedef struct account
{
- int protocol;
+ struct prpl *prpl;
char *user;
char *pass;
char *server;
@@ -40,7 +40,7 @@ typedef struct account
struct account *next;
} account_t;
-account_t *account_add( irc_t *irc, int protocol, char *user, char *pass );
+account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass );
account_t *account_get( irc_t *irc, char *id );
void account_del( irc_t *irc, account_t *acc );
void account_on( irc_t *irc, account_t *a );
diff --git a/bitlbee.c b/bitlbee.c
index e32b0e90..9591fab5 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -235,11 +235,26 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi
}
}
+/* DO NOT USE THIS FUNCTION IN NEW CODE. This
+ * function is here merely because the save/load code still uses
+ * ids rather then names */
+struct prpl *find_protocol_by_id(int id)
+{
+ switch (id) {
+ case 1: return find_protocol("oscar");
+ case 4: return find_protocol("msn");
+ case 2: return find_protocol("yahoo");
+ case 8: return find_protocol("jabber");
+ default: break;
+ }
+ return NULL;
+}
+
int bitlbee_load( irc_t *irc, char* password )
{
char s[512];
char *line;
- int proto;
+ char proto[20];
char nick[MAX_NICK_LENGTH+1];
FILE *fp;
user_t *ru = user_find( irc, ROOT_NICK );
@@ -274,10 +289,22 @@ int bitlbee_load( irc_t *irc, char* password )
g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
fp = fopen( s, "r" );
if( !fp ) return( 0 );
- while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 )
+ while( fscanf( fp, "%s %s %s", s, proto, nick ) > 0 )
{
+ struct prpl *prpl;
+
+ prpl = find_protocol(proto);
+
+ /* Older files saved the protocol number rather then the protocol name */
+ if (!prpl && atoi(proto)) {
+ prpl = find_protocol_by_id(atoi(proto));
+ }
+
+ if (!prpl)
+ continue;
+
http_decode( s );
- nick_set( irc, s, proto, nick );
+ nick_set( irc, s, prpl, nick );
}
fclose( fp );
@@ -332,7 +359,7 @@ int bitlbee_save( irc_t *irc )
strcpy( s, n->handle );
s[169] = 0; /* Prevent any overflow (169 ~ 512 / 3) */
http_encode( s );
- g_snprintf( s + strlen( s ), 510 - strlen( s ), " %d %s", n->proto, n->nick );
+ g_snprintf( s + strlen( s ), 510 - strlen( s ), " %s %s", n->proto->name, n->nick );
if( fprintf( fp, "%s\n", s ) != strlen( s ) + 1 )
{
irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );
@@ -374,11 +401,11 @@ int bitlbee_save( irc_t *irc )
for( a = irc->accounts; a; a = a->next )
{
- if( a->protocol == PROTO_OSCAR || a->protocol == PROTO_ICQ || a->protocol == PROTO_TOC )
+ if( !strcmp( a->prpl->name, "oscar" ) )
g_snprintf( s, sizeof( s ), "account add oscar \"%s\" \"%s\" %s", a->user, a->pass, a->server );
else
g_snprintf( s, sizeof( s ), "account add %s \"%s\" \"%s\" \"%s\"",
- proto_name[a->protocol], a->user, a->pass, a->server ? a->server : "" );
+ a->prpl->name, a->user, a->pass, a->server ? a->server : "" );
line = obfucrypt( irc, s );
if( *line )
diff --git a/commands.c b/commands.c
index 9c1a9aec..09fd6a91 100644
--- a/commands.c
+++ b/commands.c
@@ -183,7 +183,7 @@ int cmd_account( irc_t *irc, char **cmd )
if( g_strcasecmp( cmd[1], "add" ) == 0 )
{
- int prot;
+ struct prpl *prpl;
if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL )
{
@@ -191,23 +191,15 @@ int cmd_account( irc_t *irc, char **cmd )
return( 0 );
}
- for( prot = 0; prot < PROTO_MAX; prot ++ )
- if( proto_name[prot] && *proto_name[prot] && g_strcasecmp( proto_name[prot], cmd[2] ) == 0 )
- break;
+ prpl = find_protocol(cmd[2]);
- if( ( prot == PROTO_MAX ) || ( proto_prpl[prot] == NULL ) )
+ if( prpl == NULL )
{
irc_usermsg( irc, "Unknown protocol" );
return( 0 );
}
- if( prot == PROTO_OSCAR && cmd[5] == NULL )
- {
- irc_usermsg( irc, "Not enough parameters" );
- return( 0 );
- }
-
- a = account_add( irc, prot, cmd[3], cmd[4] );
+ a = account_add( irc, prpl, cmd[3], cmd[4] );
if( cmd[5] )
a->server = g_strdup( cmd[5] );
@@ -251,10 +243,7 @@ int cmd_account( irc_t *irc, char **cmd )
else
con = "";
- if( a->protocol == PROTO_OSCAR || a->protocol == PROTO_ICQ || a->protocol == PROTO_TOC )
- irc_usermsg( irc, "%2d. OSCAR, %s on %s%s", i, a->user, a->server, con );
- else
- irc_usermsg( irc, "%2d. %s, %s%s", i, proto_name[a->protocol], a->user, con );
+ irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con );
i ++;
}
@@ -371,7 +360,7 @@ int cmd_add( irc_t *irc, char **cmd )
}
else
{
- nick_set( irc, cmd[2], a->gc->protocol, cmd[3] );
+ nick_set( irc, cmd[2], a->gc->prpl, cmd[3] );
}
}
a->gc->prpl->add_buddy( a->gc, cmd[2] );
@@ -452,7 +441,7 @@ int cmd_rename( irc_t *irc, char **cmd )
}
else if( u->send_handler == buddy_send_handler )
{
- nick_set( irc, u->handle, u->gc->protocol, cmd[2] );
+ nick_set( irc, u->handle, u->gc->prpl, cmd[2] );
}
irc_usermsg( irc, "Nick successfully changed" );
@@ -663,21 +652,21 @@ int cmd_blist( irc_t *irc, char **cmd )
if( online == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away )
{
- g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
+ g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, "Online" );
n_online ++;
}
if( away == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away )
{
- g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
+ g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, u->away );
n_away ++;
}
if( offline == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && !u->online )
{
- g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
+ g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, "Offline" );
n_offline ++;
}
@@ -783,7 +772,7 @@ int cmd_import_buddies( irc_t *irc, char **cmd )
for( n = gc->irc->nicks; n; n = n->next )
{
- if( n->proto == gc->protocol && !user_findhandle( gc, n->handle ) )
+ if( n->proto == gc->prpl && !user_findhandle( gc, n->handle ) )
{
gc->prpl->add_buddy( gc, n->handle );
add_buddy( gc, NULL, n->handle, NULL );
diff --git a/configure b/configure
index 985e8209..365159f7 100755
--- a/configure
+++ b/configure
@@ -13,6 +13,7 @@ etcdir='$prefix/etc/bitlbee/'
mandir='$prefix/share/man/'
datadir='$prefix/share/bitlbee/'
config='/var/lib/bitlbee/'
+plugindir='$prefix/lib/bitlbee'
msn=1
jabber=1
@@ -44,6 +45,7 @@ Option Description Default
--etcdir=... $etcdir
--mandir=... $mandir
--datadir=... $datadir
+--plugindir=... $plugindir
--config=... $config
--msn=0/1 Disable/enable MSN part $msn
@@ -72,6 +74,7 @@ etcdir=`eval echo "$etcdir/" | sed 's/\/\{1,\}/\//g'`
mandir=`eval echo "$mandir/" | sed 's/\/\{1,\}/\//g'`
datadir=`eval echo "$datadir/" | sed 's/\/\{1,\}/\//g'`
config=`eval echo "$config/" | sed 's/\/\{1,\}/\//g'`
+plugindir=`eval echo "$plugindir/" | sed 's/\/\{1,\}/\//g'`
cat<<EOF>Makefile.settings
## BitlBee settings, generated by configure
@@ -80,6 +83,7 @@ BINDIR=$bindir
ETCDIR=$etcdir
MANDIR=$mandir
DATADIR=$datadir
+PLUGINDIR=$plugindir
CONFIG=$config
ARCH=$arch
@@ -100,6 +104,7 @@ cat<<EOF>config.h
#define CONFIG "$config"
#define ETCDIR "$etcdir"
#define VARDIR "$datadir"
+#define PLUGINDIR "$plugindir"
#define ARCH "$arch"
#define CPU "$cpu"
EOF
@@ -140,8 +145,8 @@ fi
if type pkg-config > /dev/null 2>/dev/null && pkg-config glib-2.0; then
cat<<EOF>>Makefile.settings
-EFLAGS+=`pkg-config --libs glib-2.0`
-CFLAGS+=`pkg-config --cflags glib-2.0`
+EFLAGS+=`pkg-config --libs glib-2.0 gmodule-2.0`
+CFLAGS+=`pkg-config --cflags glib-2.0 gmodule-2.0`
EOF
echo '#define GLIB2' >> config.h
elif type glib-config > /dev/null 2> /dev/null; then
diff --git a/doc/example_plugin.c b/doc/example_plugin.c
new file mode 100644
index 00000000..38d02260
--- /dev/null
+++ b/doc/example_plugin.c
@@ -0,0 +1,13 @@
+/*
+ * This is the most simple possible BitlBee plugin. To use, compile it as
+ * a shared library and place it in the plugin directory:
+ *
+ * gcc -o example.so -shared example.c
+ * cp example.so /usr/local/lib/bitlbee
+ */
+#include <stdio.h>
+
+void init_plugin(void)
+{
+ printf("I am a BitlBee plugin!\n");
+}
diff --git a/irc.c b/irc.c
index c1d91ad2..a3031199 100644
--- a/irc.c
+++ b/irc.c
@@ -1152,7 +1152,7 @@ void irc_whois( irc_t *irc, char *nick )
if( u->gc )
irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->gc->user->username,
- *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", proto_name[u->gc->user->protocol] );
+ *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", u->gc->prpl->name );
else
irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
diff --git a/nick.c b/nick.c
index ebf156c3..1376f365 100644
--- a/nick.c
+++ b/nick.c
@@ -26,7 +26,7 @@
#define BITLBEE_CORE
#include "bitlbee.h"
-void nick_set( irc_t *irc, char *handle, int proto, char *nick )
+void nick_set( irc_t *irc, char *handle, struct prpl *proto, char *nick )
{
nick_t *m = NULL, *n = irc->nicks;
@@ -55,7 +55,7 @@ void nick_set( irc_t *irc, char *handle, int proto, char *nick )
nick_strip( n->nick );
}
-char *nick_get( irc_t *irc, char *handle, int proto, const char *realname )
+char *nick_get( irc_t *irc, char *handle, struct prpl *proto, const char *realname )
{
static char nick[MAX_NICK_LENGTH+1];
nick_t *n = irc->nicks;
diff --git a/nick.h b/nick.h
index 5e53694c..d48369c6 100644
--- a/nick.h
+++ b/nick.h
@@ -26,13 +26,13 @@
typedef struct __NICK
{
char *handle;
- int proto;
+ struct prpl *proto;
char *nick;
struct __NICK *next;
} nick_t;
-void nick_set( irc_t *irc, char *handle, int proto, char *nick );
-char *nick_get( irc_t *irc, char *handle, int proto, const char *realname );
+void nick_set( irc_t *irc, char *handle, struct prpl *proto, char *nick );
+char *nick_get( irc_t *irc, char *handle, struct prpl *proto, const char *realname );
void nick_del( irc_t *irc, char *nick );
void nick_strip( char *nick );
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index 931a2182..5d499950 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -157,11 +157,6 @@ struct jabber_chat {
#define JCS_CLOSED 3 /* closed */
-static char *jabber_name()
-{
- return "Jabber";
-}
-
#define STATE_EVT(arg) if(gjc->on_state) { (gjc->on_state)(gjc, (arg) ); }
static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group);
@@ -2412,13 +2407,13 @@ static GList *jabber_actions()
return m;
}
-static struct prpl *my_protocol = NULL;
-void jabber_init(struct prpl *ret)
+void jabber_init()
{
+ struct prpl *ret = g_new0(struct prpl, 1);
+
/* the NULL's aren't required but they're nice to have */
- ret->protocol = PROTO_JABBER;
- ret->name = jabber_name;
+ ret->name = "jabber";
ret->away_states = jabber_away_states;
ret->actions = jabber_actions;
ret->login = jabber_login;
@@ -2441,5 +2436,5 @@ void jabber_init(struct prpl *ret)
ret->alias_buddy = jabber_roster_update;
ret->group_buddy = jabber_group_change;
- my_protocol = ret;
+ register_protocol (ret);
}
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c
index 33e12af5..42d763e8 100644
--- a/protocols/msn/msn.c
+++ b/protocols/msn/msn.c
@@ -26,8 +26,6 @@
#include "nogaim.h"
#include "msn.h"
-static struct prpl *my_protocol = NULL;
-
static void msn_login( struct aim_user *acct )
{
struct gaim_connection *gc = new_gaim_conn( acct );
@@ -374,9 +372,10 @@ static int msn_send_typing( struct gaim_connection *gc, char *who, int typing )
return( 1 );
}
-void msn_init(struct prpl *ret)
+void msn_init()
{
- ret->protocol = PROTO_MSN;
+ struct prpl *ret = g_new0(struct prpl, 1);
+ ret->name = "msn";
ret->login = msn_login;
ret->close = msn_close;
ret->send_im = msn_send_im;
@@ -398,5 +397,5 @@ void msn_init(struct prpl *ret)
ret->rem_deny = msn_rem_deny;
ret->send_typing = msn_send_typing;
- my_protocol = ret;
+ register_protocol(ret);
}
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index dee89a5e..a5f034c7 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -38,9 +38,6 @@
#include <ctype.h>
#include <iconv.h>
-struct prpl *proto_prpl[PROTO_MAX];
-char proto_name[PROTO_MAX][8] = { "TOC", "OSCAR", "YAHOO", "ICQ", "MSN", "", "", "", "JABBER", "", "", "", "", "", "", "" };
-
static char *proto_away_alias[7][5] =
{
{ "Away from computer", "Away", "Extended away", NULL },
@@ -57,30 +54,95 @@ static int remove_chat_buddy_silent( struct conversation *b, char *handle );
GSList *connections;
+gboolean load_plugin(char *path)
+{
+ void (*init_function) (void);
+
+ GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY);
+
+ if(!mod) {
+ log_message(LOGLVL_ERROR, "Can't find `%s', not loading", path);
+ return FALSE;
+ }
+
+ if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) {
+ log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path);
+ return FALSE;
+ }
+
+ init_function();
+
+ return TRUE;
+}
/* nogaim.c */
+GList *protocols = NULL;
+
+void register_protocol (struct prpl *p)
+{
+ protocols = g_list_append(protocols, p);
+}
+
+
+struct prpl *find_protocol(const char *name)
+{
+ GList *gl;
+ for (gl = protocols; gl; gl = gl->next)
+ {
+ struct prpl *proto = gl->data;
+ if(!g_strcasecmp(proto->name, name))
+ return proto;
+ }
+ return NULL;
+}
+
+/* nogaim.c */
void nogaim_init()
{
- proto_prpl[PROTO_MSN] = g_new0 ( struct prpl, 1 );
+ GDir *dir;
+ GError *error = NULL;
+
#ifdef WITH_MSN
- msn_init( proto_prpl[PROTO_MSN] );
+ extern void msn_init();
+ msn_init();
#endif
- proto_prpl[PROTO_OSCAR] = g_new0( struct prpl, 1 );
#ifdef WITH_OSCAR
- oscar_init( proto_prpl[PROTO_OSCAR] );
+ extern void oscar_init();
+ oscar_init();
#endif
- proto_prpl[PROTO_YAHOO] = g_new0( struct prpl, 1 );
#ifdef WITH_YAHOO
- byahoo_init( proto_prpl[PROTO_YAHOO] );
+ extern void byahoo_init();
+ byahoo_init();
#endif
- proto_prpl[PROTO_JABBER] = g_new0( struct prpl, 1 );
#ifdef WITH_JABBER
- jabber_init( proto_prpl[PROTO_JABBER] );
+ extern void jabber_init();
+ jabber_init();
#endif
+
+ dir = g_dir_open(PLUGINDIR, 0, &error);
+
+ if (dir) {
+ const gchar *entry;
+ char *path;
+
+ while ((entry = g_dir_read_name(dir))) {
+ path = g_build_filename(PLUGINDIR, entry, NULL);
+ if(!path) {
+ log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry);
+ continue;
+ }
+
+ load_plugin(path);
+
+ g_free(path);
+ }
+
+ g_dir_close(dir);
+ }
}
GSList *get_connections() { return connections; }
@@ -121,7 +183,7 @@ int proto_away( struct gaim_connection *gc, char *away )
{
gc->prpl->set_away( gc, s, away );
if( set_getint( gc->irc, "debug" ) )
- irc_usermsg( gc->irc, "Setting away state for %s to %s", proto_name[gc->protocol], s );
+ irc_usermsg( gc->irc, "Setting away state for %s to %s", gc->prpl->name, s );
}
else
gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away );
@@ -167,9 +229,9 @@ static char *proto_away_alias_find( GList *gcm, char *away )
should be a compare function inside the PRPL module, but I do it this
way for now because I don't want to touch the Gaim code too much since
it's not going to be here for too long anymore. */
-int handle_cmp( char *a, char *b, int protocol )
+int handle_cmp( char *a, char *b, struct prpl *protocol )
{
- if( protocol == PROTO_TOC || protocol == PROTO_ICQ )
+ if( !strcmp(protocol->name, "oscar") )
{
/* AIM, being teh evil, thinks it's cool that users can put
random spaces in screennames. But "A B" and "AB" are
@@ -209,8 +271,7 @@ struct gaim_connection *new_gaim_conn( struct aim_user *user )
gc = g_new0( struct gaim_connection, 1 );
- gc->protocol = user->protocol;
- gc->prpl = proto_prpl[gc->protocol];
+ gc->prpl = user->prpl;
g_snprintf( gc->username, sizeof( gc->username ), "%s", user->username );
g_snprintf( gc->password, sizeof( gc->password ), "%s", user->password );
/* [MD] BUGFIX: don't set gc->irc to the global IRC, but use the one from the struct aim_user.
@@ -253,19 +314,19 @@ void destroy_gaim_conn( struct gaim_connection *gc )
void set_login_progress( struct gaim_connection *gc, int step, char *msg )
{
- irc_usermsg( gc->irc, "%s(%s) - Logging in: %s", proto_name[gc->protocol], gc->username, msg );
+ irc_usermsg( gc->irc, "%s(%s) - Logging in: %s", gc->prpl->name, gc->username, msg );
}
/* Errors *while* logging in */
void hide_login_progress( struct gaim_connection *gc, char *msg )
{
- irc_usermsg( gc->irc, "%s(%s) - Login error: %s", proto_name[gc->protocol], gc->username, msg );
+ irc_usermsg( gc->irc, "%s(%s) - Login error: %s", gc->prpl->name, gc->username, msg );
}
/* Errors *after* logging in */
void hide_login_progress_error( struct gaim_connection *gc, char *msg )
{
- irc_usermsg( gc->irc, "%s(%s) - Logged out: %s", proto_name[gc->protocol], gc->username, msg );
+ irc_usermsg( gc->irc, "%s(%s) - Logged out: %s", gc->prpl->name, gc->username, msg );
}
void serv_got_crap( struct gaim_connection *gc, char *format, ... )
@@ -288,7 +349,7 @@ void serv_got_crap( struct gaim_connection *gc, char *format, ... )
if( gc->flags & OPT_CONN_HTML )
strip_html( msg );
- irc_usermsg( gc->irc, "%s(%s) - %s", proto_name[gc->protocol], gc->username, msg );
+ irc_usermsg( gc->irc, "%s(%s) - %s", gc->prpl->name, gc->username, msg );
}
static gboolean send_keepalive( gpointer d )
@@ -313,14 +374,14 @@ void account_online( struct gaim_connection *gc )
u = user_find( gc->irc, gc->irc->nick );
- irc_usermsg( gc->irc, "%s(%s) - Logged in", proto_name[gc->protocol], gc->username );
+ irc_usermsg( gc->irc, "%s(%s) - Logged in", gc->prpl->name, gc->username );
gc->keepalive = g_timeout_add( 60000, send_keepalive, gc );
gc->flags |= OPT_LOGGED_IN;
if( u && u->away ) proto_away( gc, u->away );
- if( gc->protocol == PROTO_ICQ )
+ if( !strcmp(gc->prpl->name, "icq") )
{
for( u = gc->irc->users; u; u = u->next )
if( u->gc == gc )
@@ -360,7 +421,7 @@ void signoff( struct gaim_connection *gc )
user_t *t, *u = irc->users;
account_t *a;
- irc_usermsg( gc->irc, "%s(%s) - Signing off..", proto_name[gc->protocol], gc->username );
+ irc_usermsg( gc->irc, "%s(%s) - Signing off..", gc->prpl->name, gc->username );
gaim_input_remove( gc->keepalive );
gc->keepalive = 0;
@@ -392,7 +453,7 @@ void signoff( struct gaim_connection *gc )
else if( !gc->wants_to_die && set_getint( irc, "auto_reconnect" ) )
{
int delay = set_getint( irc, "auto_reconnect_delay" );
- irc_usermsg( gc->irc, "%s(%s) - Reconnecting in %d seconds..", proto_name[gc->protocol], gc->username, delay);
+ irc_usermsg( gc->irc, "%s(%s) - Reconnecting in %d seconds..", gc->prpl->name, gc->username, delay);
a->reconnect = 1;
g_timeout_add( delay * 1000, auto_reconnect, a );
@@ -406,7 +467,7 @@ void signoff( struct gaim_connection *gc )
void do_error_dialog( struct gaim_connection *gc, char *msg, char *title )
{
- irc_usermsg( gc->irc, "%s(%s) - Error: %s", proto_name[gc->protocol], gc->username, msg );
+ irc_usermsg( gc->irc, "%s(%s) - Error: %s", gc->prpl->name, gc->username, msg );
}
void do_ask_dialog( struct gaim_connection *gc, char *msg, void *data, void *doit, void *dont )
@@ -448,7 +509,7 @@ void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *rea
}
memset( nick, 0, MAX_NICK_LENGTH + 1 );
- strcpy( nick, nick_get( gc->irc, handle, gc->protocol, realname ) );
+ strcpy( nick, nick_get( gc->irc, handle, gc->prpl, realname ) );
u = user_add( gc->irc, nick );
@@ -472,7 +533,7 @@ void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *rea
}
else
{
- u->host = g_strdup( proto_name[gc->user->protocol] );
+ u->host = g_strdup( gc->user->prpl->name );
u->user = g_strdup( handle );
}
@@ -566,7 +627,7 @@ void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, in
{
if( set_getint( gc->irc, "debug" ) || g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "ignore" ) != 0 )
{
- irc_usermsg( gc->irc, "serv_got_update() for handle %s on connection %s(%s):", handle, proto_name[gc->protocol], gc->username );
+ irc_usermsg( gc->irc, "serv_got_update() for handle %s on connection %s(%s):", handle, gc->prpl->name, gc->username );
irc_usermsg( gc->irc, "loggedin = %d, type = %d", loggedin, type );
}
@@ -601,11 +662,11 @@ void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, in
remove_chat_buddy_silent( c, handle );
}
- if( ( type & UC_UNAVAILABLE ) && ( gc->protocol == PROTO_OSCAR || gc->protocol == PROTO_TOC ) )
+ if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "oscar") || !strcmp(gc->prpl->name, "icq")) )
{
u->away = g_strdup( "Away" );
}
- else if( ( type & UC_UNAVAILABLE ) && ( gc->protocol == PROTO_JABBER ) )
+ else if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "jabber") ) )
{
if( type & UC_DND )
u->away = g_strdup( "Do Not Disturb" );
@@ -647,7 +708,7 @@ void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 f
if( g_strcasecmp( h, "ignore" ) == 0 )
{
if( set_getint( irc, "debug" ) )
- irc_usermsg( irc, "Ignoring message from unknown handle %s on connection %s(%s)", handle, proto_name[gc->protocol], gc->username );
+ irc_usermsg( irc, "Ignoring message from unknown handle %s on connection %s(%s)", handle, gc->prpl->name, gc->username );
return;
}
@@ -669,7 +730,7 @@ void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 f
}
else
{
- irc_usermsg( irc, "Message from unknown handle %s on connection %s(%s):", handle, proto_name[gc->protocol], gc->username );
+ irc_usermsg( irc, "Message from unknown handle %s on connection %s(%s):", handle, gc->prpl->name, gc->username );
u = user_find( irc, irc->mynick );
}
}
@@ -835,7 +896,7 @@ void add_chat_buddy( struct conversation *b, char *handle )
irc_usermsg( b->gc->irc, "User %s added to conversation %d", handle, b->id );
/* It might be yourself! */
- if( handle_cmp ( handle, b->gc->user->username, b->gc->protocol ) == 0 )
+ if( handle_cmp ( handle, b->gc->user->username, b->gc->prpl ) == 0 )
{
u = user_find( b->gc->irc, b->gc->irc->nick );
if( !b->joined )
diff --git a/protocols/nogaim.h b/protocols/nogaim.h
index 4e10330a..477f1df9 100644
--- a/protocols/nogaim.h
+++ b/protocols/nogaim.h
@@ -71,7 +71,6 @@
struct gaim_connection {
/* we need to do either oscar or TOC */
/* we make this as an int in case if we want to add more protocols later */
- int protocol;
struct prpl *prpl;
guint32 flags;
@@ -151,7 +150,7 @@ struct aim_user {
char password[32];
char user_info[2048];
int options;
- int protocol;
+ struct prpl *prpl;
/* prpls can use this to save information about the user,
* like which server to connect to, etc */
char proto_opt[7][256];
@@ -160,10 +159,28 @@ struct aim_user {
irc_t *irc;
};
+struct ft
+{
+ const char *filename;
+
+ /* Total number of bytes in file */
+ size_t total_bytes;
+
+ /* Current number of bytes received */
+ size_t cur_bytes;
+};
+
+struct ft_request
+{
+ const char *filename;
+ struct gaim_connection *gc;
+};
+
+typedef void (*ft_recv_handler) (struct ft *, void *data, size_t len);
+
struct prpl {
- int protocol;
int options;
- char *(* name)();
+ const char *name;
/* for ICQ and Yahoo, who have off/on per-conversation options */
/* char *checkbox; this should be per-connection */
@@ -216,27 +233,16 @@ struct prpl {
/* change a buddy's group on a server list/roster */
void (* group_buddy) (struct gaim_connection *, char *who, char *old_group, char *new_group);
+ /* file transfers */
+ struct ft_send_req *(* req_send_file) (struct gaim_connection *, const char *file);
+ void (* send_file_part) (struct gaim_connection *, struct ft*, void *data, size_t length);
+ void (* accept_recv_file) (struct gaim_connection *, struct ft*, ft_recv_handler);
+
void (* buddy_free) (struct buddy *);
char *(* get_status_string) (struct gaim_connection *gc, int stat);
};
-#define PROTO_TOC 0
-#define PROTO_OSCAR 1
-#define PROTO_YAHOO 2
-#define PROTO_ICQ 3
-#define PROTO_MSN 4
-#define PROTO_IRC 5
-#define PROTO_FTP 6
-#define PROTO_VGATE 7
-#define PROTO_JABBER 8
-#define PROTO_NAPSTER 9
-#define PROTO_ZEPHYR 10
-#define PROTO_GADUGADU 11
-#define PROTO_MAX 16
-
-extern char proto_name[PROTO_MAX][8];
-
#define UC_UNAVAILABLE 1
/* JABBER */
@@ -246,7 +252,8 @@ extern char proto_name[PROTO_MAX][8];
#define UC_DND (0x10 | UC_UNAVAILABLE)
G_MODULE_EXPORT GSList *get_connections();
-extern struct prpl *proto_prpl[16];
+G_MODULE_EXPORT struct prpl *find_protocol(const char *name);
+G_MODULE_EXPORT void register_protocol(struct prpl *);
/* nogaim.c */
int serv_send_im(irc_t *irc, user_t *u, char *msg, int flags);
@@ -258,7 +265,7 @@ char *set_eval_charset( irc_t *irc, set_t *set, char *value );
void nogaim_init();
int proto_away( struct gaim_connection *gc, char *away );
char *set_eval_away_devoice( irc_t *irc, set_t *set, char *value );
-int handle_cmp( char *a, char *b, int protocol );
+int handle_cmp( char *a, char *b, struct prpl *protocol );
gboolean auto_reconnect( gpointer data );
void cancel_auto_reconnect( struct account *a );
@@ -317,25 +324,11 @@ G_MODULE_EXPORT void strip_html( char *msg );
G_MODULE_EXPORT char * escape_html(const char *html);
G_MODULE_EXPORT void info_string_append(GString *str, char *newline, char *name, char *value);
-#ifdef WITH_MSN
-/* msn.c */
-G_MODULE_EXPORT void msn_init( struct prpl *ret );
-#endif
-
-#ifdef WITH_OSCAR
-/* oscar.c */
-G_MODULE_EXPORT void oscar_init( struct prpl *ret );
-#endif
-
-#ifdef WITH_JABBER
-/* jabber.c */
-G_MODULE_EXPORT void jabber_init( struct prpl *ret );
-#endif
-
-#ifdef WITH_YAHOO
-/* yahoo.c */
-G_MODULE_EXPORT void byahoo_init( struct prpl *ret );
-#endif
+/* file transfers */
+G_MODULE_EXPORT void ft_progress( struct ft *, int);
+G_MODULE_EXPORT void ft_incoming( struct ft_request * );
+G_MODULE_EXPORT void ft_accepted( struct ft_request *, struct ft *);
+G_MODULE_EXPORT void ft_denied( struct ft_request *, const char *reason);
/* prefs.c */
G_MODULE_EXPORT void build_block_list();
diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c
index 5a1ddc45..6ff0a742 100644
--- a/protocols/oscar/oscar.c
+++ b/protocols/oscar/oscar.c
@@ -363,10 +363,8 @@ static void oscar_login(struct aim_user *user) {
if (isdigit(*user->username)) {
odata->icq = TRUE;
/* this is odd but it's necessary for a proper do_import and do_export */
- gc->protocol = PROTO_ICQ;
gc->password[8] = 0;
} else {
- gc->protocol = PROTO_TOC;
gc->flags |= OPT_CONN_HTML;
}
@@ -2466,10 +2464,10 @@ static char *oscar_get_status_string( struct gaim_connection *gc, int number )
}
}
-static struct prpl *my_protocol = NULL;
-
-void oscar_init(struct prpl *ret) {
- ret->protocol = PROTO_OSCAR;
+void oscar_init()
+{
+ struct prpl *ret = g_new0(struct prpl, 1);
+ ret->name = "oscar";
ret->away_states = oscar_away_states;
ret->login = oscar_login;
ret->close = oscar_close;
@@ -2487,5 +2485,5 @@ void oscar_init(struct prpl *ret) {
ret->keepalive = oscar_keepalive;
ret->get_status_string = oscar_get_status_string;
- my_protocol = ret;
+ register_protocol(ret);
}
diff --git a/protocols/proxy.c b/protocols/proxy.c
index 59b480f4..6d450c92 100644
--- a/protocols/proxy.c
+++ b/protocols/proxy.c
@@ -49,16 +49,6 @@
#define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
#define GAIM_ERR_COND (G_IO_HUP | G_IO_ERR | G_IO_NVAL)
-/*FIXME*
- #ifndef _WIN32
- if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
- closesocket(fd);
- g_free(phb);
- return -1;
- }
- fcntl(fd, F_SETFL, 0);
-#endif*/
-
char proxyhost[128] = "";
int proxyport = 0;
int proxytype = PROXY_NONE;
diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c
index 77fd86cc..cc3ffdf7 100644
--- a/protocols/yahoo/yahoo.c
+++ b/protocols/yahoo/yahoo.c
@@ -63,12 +63,6 @@ struct byahoo_conf_invitation
struct gaim_connection *gc;
};
-static char *yahoo_name()
-{
- return "Yahoo";
-}
-
-static struct prpl *my_protocol = NULL;
static GSList *byahoo_inputs = NULL;
static int byahoo_chat_id = 0;
@@ -395,15 +389,14 @@ static int byahoo_chat_open( struct gaim_connection *gc, char *who )
return( 1 );
}
-void byahoo_init( struct prpl *ret )
+void byahoo_init( )
{
- ret->protocol = PROTO_YAHOO;
- ret->name = yahoo_name;
+ struct prpl *ret = g_new0(struct prpl, 1);
+ ret->name = "yahoo";
ret->login = byahoo_login;
ret->close = byahoo_close;
ret->send_im = byahoo_send_im;
- ret->send_typing = byahoo_send_typing;
ret->get_info = byahoo_get_info;
ret->away_states = byahoo_away_states;
ret->set_away = byahoo_set_away;
@@ -411,13 +404,14 @@ void byahoo_init( struct prpl *ret )
ret->add_buddy = byahoo_add_buddy;
ret->remove_buddy = byahoo_remove_buddy;
ret->get_status_string = byahoo_get_status_string;
+ ret->send_typing = byahoo_send_typing;
ret->chat_send = byahoo_chat_send;
ret->chat_invite = byahoo_chat_invite;
ret->chat_leave = byahoo_chat_leave;
ret->chat_open = byahoo_chat_open;
- my_protocol = ret;
+ register_protocol(ret);
}
static struct gaim_connection *byahoo_get_gc_by_id( int id )
@@ -431,7 +425,7 @@ static struct gaim_connection *byahoo_get_gc_by_id( int id )
gc = l->data;
yd = gc->proto_data;
- if( gc->protocol == PROTO_YAHOO && yd->y2_id == id )
+ if( !strcmp(gc->prpl->name, "yahoo") && yd->y2_id == id )
return( gc );
}
diff --git a/query.c b/query.c
index 0eda3584..90d0e923 100644
--- a/query.c
+++ b/query.c
@@ -148,7 +148,7 @@ void query_answer( irc_t *irc, query_t *q, int ans )
static void query_display( irc_t *irc, query_t *q )
{
if( q->gc )
- irc_usermsg( irc, "Question on %s connection (handle %s):", proto_name[q->gc->protocol], q->gc->username );
+ irc_usermsg( irc, "Question on %s connection (handle %s):", q->gc->prpl->name, q->gc->username );
else
irc_usermsg( irc, "Question:" );
diff --git a/unix.c b/unix.c
index c4b3975e..406bf3c8 100644
--- a/unix.c
+++ b/unix.c
@@ -46,8 +46,9 @@ int main( int argc, char *argv[] )
global.loop = g_main_new( FALSE );
log_init( );
- nogaim_init( );
-
+
+ nogaim_init();
+
CONF_FILE = g_strdup( CONF_FILE_DEF );
global.helpfile = g_strdup( HELP_FILE );
diff --git a/url.h b/url.h
index 6555d15d..c8426876 100644
--- a/url.h
+++ b/url.h
@@ -25,7 +25,8 @@
#include "bitlbee.h"
-#define PROTO_HTTP 2
+#define PROTO_FTP 1
+#define PROTO_HTTP 2
#define PROTO_SOCKS4 3
#define PROTO_SOCKS5 4
#define PROTO_DEFAULT PROTO_HTTP
diff --git a/user.c b/user.c
index dc288c84..bd68d20b 100644
--- a/user.c
+++ b/user.c
@@ -145,7 +145,7 @@ user_t *user_findhandle( struct gaim_connection *gc, char *handle )
while( u )
{
- if( u->gc == gc && u->handle && handle_cmp( u->handle, handle, gc->protocol ) == 0 )
+ if( u->gc == gc && u->handle && handle_cmp( u->handle, handle, gc->prpl) == 0 )
break;
u = u->next;
}