diff options
| author | dequis <dx@dxzone.com.ar> | 2016-11-13 21:37:14 -0300 | 
|---|---|---|
| committer | dequis <dx@dxzone.com.ar> | 2016-11-13 21:37:14 -0300 | 
| commit | 9f03c472fef309878ff2f3bc720d51e6d03077f1 (patch) | |
| tree | b49d1be8c2e870e39432a3a9fc5cc41086ade894 | |
| parent | ea902752503fc5b356d6513911081ec932d804f2 (diff) | |
Improve support for protocols which don't require a password
This adds a prpl_options_t enum with flags, which mostly just brings
OPT_PROTO_{NO_PASSWORD,PASSWORD_OPTIONAL} from libpurple as
PRPL_OPT_{NO_PASSWORD,PASSWORD_OPTIONAL}
| -rw-r--r-- | otr.c | 4 | ||||
| -rw-r--r-- | protocols/nogaim.h | 21 | ||||
| -rw-r--r-- | protocols/purple/purple.c | 10 | ||||
| -rw-r--r-- | protocols/twitter/twitter.c | 3 | ||||
| -rw-r--r-- | root_commands.c | 9 | 
5 files changed, 44 insertions, 3 deletions
| @@ -428,7 +428,7 @@ int otr_check_for_key(account_t *a)  	OtrlPrivKey *k;  	/* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ -	if (a->prpl->options & OPT_NOOTR) { +	if (a->prpl->options & PRPL_OPT_NOOTR) {  		return 0;  	} @@ -456,7 +456,7 @@ char *otr_filter_msg_in(irc_user_t *iu, char *msg, int flags)  	struct im_connection *ic = iu->bu->ic;  	/* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ -	if (ic->acc->prpl->options & OPT_NOOTR || +	if (ic->acc->prpl->options & PRPL_OPT_NOOTR ||  	    iu->bu->flags & BEE_USER_NOOTR) {  		return msg;  	} diff --git a/protocols/nogaim.h b/protocols/nogaim.h index 4cba2174..b5a46524 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -139,6 +139,27 @@ struct buddy_action {  	char *description;  }; +/* This enum takes a few things from libpurple and a few things from old OPT_ flags. + * The only flag that was used before this struct was PRPL_OPT_NOOTR. + * + * The libpurple ones only use the same values as the PurpleProtocolOptions + * enum for convenience, but there's no promise of direct compatibility with + * those values. As of libpurple 2.8.0 they use up to 0x800 (1 << 11), which is + * a nice coincidence. + */ +typedef enum { +	/* The protocol doesn't use passwords +	 * Mirrors libpurple's OPT_PROTO_NO_PASSWORD */ +	PRPL_OPT_NO_PASSWORD = 1 << 4, + +	/* The protocol doesn't require passwords, but may use them +	 * Mirrors libpurple's OPT_PROTO_PASSWORD_OPTIONAL */ +	PRPL_OPT_PASSWORD_OPTIONAL = 1 << 7, + +	/* The protocol is not suitable for OTR, see OPT_NOOTR */ +	PRPL_OPT_NOOTR = 1 << 12, +} prpl_options_t; +  struct prpl {  	int options;  	/* You should set this to the name of your protocol. diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index 4ee41d62..c7123798 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -1724,6 +1724,7 @@ void purple_initmodule()  	   supported by this libpurple instance. */  	for (prots = purple_plugins_get_protocols(); prots; prots = prots->next) {  		PurplePlugin *prot = prots->data; +		PurplePluginProtocolInfo *pi = prot->info->extra_info;  		struct prpl *ret;  		/* If we already have this one (as a native module), don't @@ -1737,6 +1738,15 @@ void purple_initmodule()  		if (strncmp(ret->name, "prpl-", 5) == 0) {  			ret->name += 5;  		} + +		if (pi->options & OPT_PROTO_NO_PASSWORD) { +			ret->options |= PRPL_OPT_NO_PASSWORD; +		} + +		if (pi->options & OPT_PROTO_PASSWORD_OPTIONAL) { +			ret->options |= PRPL_OPT_PASSWORD_OPTIONAL; +		} +  		register_protocol(ret);  		g_string_append_printf(help, "\n* %s (%s)", ret->name, prot->info->name); diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index b2039171..8bc6140a 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -1091,7 +1091,7 @@ void twitter_initmodule()  {  	struct prpl *ret = g_new0(struct prpl, 1); -	ret->options = OPT_NOOTR; +	ret->options = PRPL_OPT_NOOTR | PRPL_OPT_NO_PASSWORD;  	ret->name = "twitter";  	ret->login = twitter_login;  	ret->init = twitter_init; @@ -1118,5 +1118,6 @@ void twitter_initmodule()  	/* And an identi.ca variant: */  	ret = g_memdup(ret, sizeof(struct prpl));  	ret->name = "identica"; +	ret->options =  PRPL_OPT_NOOTR;  	register_protocol(ret);  } diff --git a/root_commands.c b/root_commands.c index d4b278c4..732949d8 100644 --- a/root_commands.c +++ b/root_commands.c @@ -469,6 +469,13 @@ static void cmd_account(irc_t *irc, char **cmd)  				*a->pass = '\0';  				irc_rootmsg(irc, "No need to enter a password for this "  				            "account since it's using OAuth"); +			} else if (prpl->options & PRPL_OPT_NO_PASSWORD) { +				*a->pass = '\0'; +			} else if (prpl->options & PRPL_OPT_PASSWORD_OPTIONAL) { +				*a->pass = '\0'; +				irc_rootmsg(irc, "Passwords are optional for this account. " +				            "If you wish to enter the password with /OPER, do " +				            "account %s set -del password", a->tag);  			} else {  				irc_rootmsg(irc, "You can now use the /OPER command to "  				            "enter the password"); @@ -478,6 +485,8 @@ static void cmd_account(irc_t *irc, char **cmd)  					            "set oauth on", a->tag);  				}  			} +		} else if (prpl->options & PRPL_OPT_NO_PASSWORD) { +			irc_rootmsg(irc, "Note: this account doesn't use password for login");  		}  		return; | 
