diff options
| author | Jelmer Vernooij <jelmer@samba.org> | 2005-12-14 02:17:25 +0100 | 
|---|---|---|
| committer | Jelmer Vernooij <jelmer@samba.org> | 2005-12-14 02:17:25 +0100 | 
| commit | 703f0f7f4622194bce8023712a3a9966be6f8827 (patch) | |
| tree | 311125ae518c2b277845dc78ec62fc9553081bdf /protocols | |
| parent | 22bf64eab8a79352317ee190cddfeef3011aa8dc (diff) | |
| parent | 568aaf7ce17a4db2dddd13f8baed02a6d2757eb6 (diff) | |
Merge my pluginable branch
Diffstat (limited to 'protocols')
| -rw-r--r-- | protocols/jabber/jabber.c | 15 | ||||
| -rw-r--r-- | protocols/msn/msn.c | 9 | ||||
| -rw-r--r-- | protocols/nogaim.c | 113 | ||||
| -rw-r--r-- | protocols/nogaim.h | 45 | ||||
| -rw-r--r-- | protocols/oscar/oscar.c | 13 | ||||
| -rw-r--r-- | protocols/yahoo/yahoo.c | 18 | 
6 files changed, 116 insertions, 97 deletions
| diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 535607e6..fc419124 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -155,11 +155,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); @@ -2367,13 +2362,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; @@ -2397,5 +2392,5 @@ void jabber_init(struct prpl *ret)  	ret->group_buddy = jabber_group_change;  	ret->cmp_buddynames = g_strcasecmp; -	my_protocol = ret; +	register_protocol (ret);  } diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index bc2f1235..b828d31c 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; @@ -399,5 +398,5 @@ void msn_init(struct prpl *ret)  	ret->send_typing = msn_send_typing;  	ret->cmp_buddynames = g_strcasecmp; -	my_protocol = ret; +	register_protocol(ret);  } diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 34dfb2c3..4966a76f 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,29 +54,104 @@ static int remove_chat_buddy_silent( struct conversation *b, char *handle );  GSList *connections; +#ifdef WITH_PLUGINS +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; +} + +void load_plugins(void) +{ +	GDir *dir; +	GError *error = NULL; + +	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); +	} +} +#endif  /* 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 ); +	extern void msn_init(); +	extern void oscar_init(); +	extern void byahoo_init(); +	extern void jabber_init(); +  #ifdef WITH_MSN -	msn_init( proto_prpl[PROTO_MSN] ); +	msn_init();  #endif -	proto_prpl[PROTO_OSCAR] = g_new0( struct prpl, 1 );  #ifdef WITH_OSCAR -	oscar_init( proto_prpl[PROTO_OSCAR] ); +	oscar_init();  #endif -	proto_prpl[PROTO_YAHOO] = g_new0( struct prpl, 1 );  #ifdef WITH_YAHOO -	byahoo_init( proto_prpl[PROTO_YAHOO] ); +	byahoo_init();  #endif -	proto_prpl[PROTO_JABBER] = g_new0( struct prpl, 1 );  #ifdef WITH_JABBER -	jabber_init( proto_prpl[PROTO_JABBER] ); +	jabber_init(); +#endif + +#ifdef WITH_PLUGINS +	load_plugins();  #endif  } @@ -171,8 +243,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,14 +324,14 @@ void serv_got_crap( struct gaim_connection *gc, char *format, ... )  	/* Try to find a different connection on the same protocol. */  	for( a = gc->irc->accounts; a; a = a->next ) -		if( proto_prpl[a->protocol] == gc->prpl && a->gc != gc ) +		if( a->prpl == gc->prpl && a->gc != gc )  			break;  	/* If we found one, add the screenname to the acc_id. */  	if( a ) -		g_snprintf( acc_id, 32, "%s(%s)", proto_name[gc->protocol], gc->username ); +		g_snprintf( acc_id, 32, "%s(%s)", gc->prpl->name, gc->username );  	else -		g_snprintf( acc_id, 32, "%s", proto_name[gc->protocol] ); +		g_snprintf( acc_id, 32, "%s", gc->prpl->name );  	irc_usermsg( gc->irc, "%s - %s", acc_id, msg );  } @@ -294,7 +365,7 @@ void account_online( struct gaim_connection *gc )  	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 ) @@ -429,7 +500,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 ); @@ -453,7 +524,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 );  	} @@ -582,11 +653,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" ); diff --git a/protocols/nogaim.h b/protocols/nogaim.h index 829a96c0..607a67de 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]; @@ -161,9 +160,8 @@ struct aim_user {  };  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 */ @@ -223,22 +221,6 @@ struct prpl {  	int (* cmp_buddynames) (const char *who1, const char *who2);  }; -#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 */ @@ -248,7 +230,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); @@ -318,26 +301,6 @@ 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 -  /* prefs.c */  G_MODULE_EXPORT void build_block_list();  G_MODULE_EXPORT void build_allow_list(); diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 240bab14..b350456e 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -356,10 +356,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;  	} @@ -2633,10 +2631,10 @@ void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv)  	g_free(inv);  } -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; @@ -2658,8 +2656,7 @@ void oscar_init(struct prpl *ret) {  	ret->keepalive = oscar_keepalive;  	ret->cmp_buddynames = aim_sncmp;  	ret->get_status_string = oscar_get_status_string; -  	ret->send_typing = oscar_send_typing; -	my_protocol = ret; +	register_protocol(ret);  } diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c index 74d468eb..832d1ab4 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,6 +404,7 @@ 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; @@ -418,7 +412,7 @@ void byahoo_init( struct prpl *ret )  	ret->chat_open = byahoo_chat_open;  	ret->cmp_buddynames = g_strcasecmp; -	my_protocol = ret; +	register_protocol(ret);  }  static struct gaim_connection *byahoo_get_gc_by_id( int id ) @@ -432,7 +426,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 );  	} | 
