aboutsummaryrefslogtreecommitdiff
path: root/weechat
diff options
context:
space:
mode:
Diffstat (limited to 'weechat')
-rw-r--r--weechat/tomsg.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/weechat/tomsg.c b/weechat/tomsg.c
index 439322b..2103406 100644
--- a/weechat/tomsg.c
+++ b/weechat/tomsg.c
@@ -400,6 +400,51 @@ static int conn_input_cb(const void *conn_vp,void *_d,struct t_gui_buffer *buffe
return WEECHAT_RC_OK;
}
+static bool password_hide_modifier__found;
+
+static void password_hide_modifier_hmapper(void *data,struct t_hashtable *ht,const void *key,const void *value){
+ (void)ht; (void)key;
+ const struct conndata *conn=(const struct conndata*)value;
+ if(conn->buffer==(struct t_gui_buffer*)data){
+ password_hide_modifier__found=true;
+ }
+}
+
+static char* password_hide_modifier(const void *_p,void *_d,const char *modifier,const char *bufstr,const char *str){
+ (void)_p; (void)_d; (void)modifier;
+ struct t_gui_buffer *buffer=(struct t_gui_buffer*)strtoll(bufstr,NULL,16);
+ if(buffer==NULL){
+ fprintf(debugf,"password_hide_modifier: bufstr is NULL: '%s'\n",bufstr);
+ return NULL;
+ }
+ password_hide_modifier__found=false;
+ weechat_hashtable_map(conntable,password_hide_modifier_hmapper,buffer);
+ if(!password_hide_modifier__found)return NULL;
+
+ bool cursor_in_login=false;
+ for(int i=0,j=0;i<6;i++,j++){
+ if(str[j]==0x19){
+ j+=3;
+ cursor_in_login=true;
+ }
+ if(str[j]!="login "[i]){
+ return NULL;
+ }
+ }
+
+ const char *p=strchr(str+6+3*cursor_in_login,' ');
+ if(p==NULL)return NULL;
+ char *newstr=malloc(p-str+8);
+ assert(newstr);
+ memcpy(newstr,str,p-str);
+ if(memchr(newstr,0x19,p-str)!=NULL){
+ memcpy(newstr+(p-str)," ***",5); // count includes '\0'
+ } else {
+ memcpy(newstr+(p-str)," ***\x19" "b#",8); // count includes '\0'
+ }
+ return newstr;
+}
+
static int conn_close_cb(const void *conn_vp,void *_d,struct t_gui_buffer *buffer){
(void)_d; (void)buffer;
struct conndata *conn=(struct conndata*)conn_vp;
@@ -509,6 +554,8 @@ int weechat_plugin_init(struct t_weechat_plugin *plugin,int argc,char **argv){
NULL,
cmd_tomsg_cb,NULL,NULL);
+ weechat_hook_modifier("input_text_display_with_cursor",password_hide_modifier,NULL,NULL);
+
net_set_push_callback(push_net_callback);
net_set_history_callback(history_push_net_callback);