aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-04-09 15:24:50 +0200
committertomsmeding <tom.smeding@gmail.com>2017-04-09 15:24:50 +0200
commit0d7100767e21a3a77b2f588e8bc5118d9858f626 (patch)
tree8ad9911861fe4f02959e9c3fb429e05d41a3ed60
parentca35234630332e5ebb70626ca4052339454ff0fa (diff)
weechat: Add support for _push join/invite
-rw-r--r--weechat/net.c39
-rw-r--r--weechat/net.h2
-rw-r--r--weechat/tomsg.c33
3 files changed, 63 insertions, 11 deletions
diff --git a/weechat/net.c b/weechat/net.c
index 12e3625..8c6cee5 100644
--- a/weechat/net.c
+++ b/weechat/net.c
@@ -285,6 +285,45 @@ void net_handle_recv(int fd,const char *msg){
free(res.room);
free(res.username);
free(res.message);
+ } else if(cmdlen==4&&memcmp(cmd,"join",4)==0){
+ const char *q;
+ if(*p=='\0'||(q=strchr(p+1,' '))==NULL){
+ fprintf(debugf,"net_handle_recv: not enough arguments to 'join' <%s>\n",msg);
+ return;
+ }
+ const char *roomp=p+1;
+ i64 roomlen=q-roomp;
+ const char *userp=q+1;
+ i64 userlen=msglen-(userp-msg);
+
+ struct net_response res;
+ res.type=NET_JOIN;
+ res.room=malloc(roomlen+1);
+ res.username=malloc(userlen+1);
+ assert(res.room&&res.username);
+ memcpy(res.room,roomp,roomlen);
+ res.room[roomlen]='\0';
+ memcpy(res.username,userp,userlen);
+ res.username[userlen]='\0';
+ cb(fd,res,payload);
+ free(res.room);
+ free(res.username);
+ } else if(cmdlen==6&&memcmp(cmd,"invite",6)==0){
+ if(*p=='\0'){
+ fprintf(debugf,"net_handle_recv: no arguments to 'invite' <%s>\n",msg);
+ return;
+ }
+ const char *roomp=p+1;
+ i64 roomlen=msglen-(roomp-msg);
+
+ struct net_response res;
+ res.type=NET_INVITE;
+ res.room=malloc(roomlen+1);
+ assert(res.room);
+ memcpy(res.room,roomp,roomlen);
+ res.room[roomlen]='\0';
+ cb(fd,res,payload);
+ free(res.room);
} else {
fprintf(debugf,"net_handle_recv: unknown command <%s>\n",msg);
}
diff --git a/weechat/net.h b/weechat/net.h
index 59f5f45..c8b0f03 100644
--- a/weechat/net.h
+++ b/weechat/net.h
@@ -11,6 +11,8 @@ enum net_response_type{
NET_LIST,
NET_HISTORY,
NET_MESSAGE,
+ NET_JOIN,
+ NET_INVITE,
};
struct net_history_item{
diff --git a/weechat/tomsg.c b/weechat/tomsg.c
index 6b5703c..7778645 100644
--- a/weechat/tomsg.c
+++ b/weechat/tomsg.c
@@ -17,7 +17,7 @@ WEECHAT_PLUGIN_LICENSE("MIT")
WEECHAT_PLUGIN_PRIORITY(1000)
-static const char *errpfx;
+static const char *errpfx,*netpfx;
struct roomdata{
@@ -98,12 +98,18 @@ static int room_close_cb(const void *room_vp,void *_d,struct t_gui_buffer *buffe
return WEECHAT_RC_OK;
}
+static void history_net_callback(int fd,struct net_response res,void *payload){
+ struct roomdata *room=(struct roomdata*)payload;
+ assert(room);
+ fprintf(debugf,"history_net_callback(fd=%d,res={.type=%d})\n",fd,res.type);
+}
+
static void push_net_callback(int fd,struct net_response res,void *payload){
(void)payload;
fprintf(debugf,"push_net_callback(fd=%d,res={.type=%d})\n",fd,res.type);
struct conndata *conn=weechat_hashtable_get(conntable,&fd);
assert(conn);
- if(res.type==NET_MESSAGE){
+ if(res.type==NET_MESSAGE||res.type==NET_JOIN||res.type==NET_INVITE){
i64 roomi;
for(roomi=0;roomi<conn->nrooms;roomi++){
if(strcmp(conn->rooms[roomi]->name,res.room)==0){
@@ -121,9 +127,19 @@ static void push_net_callback(int fd,struct net_response res,void *payload){
room_input_cb,room,NULL,
room_close_cb,room,NULL);
}
- weechat_printf_date_tags(
- room->buffer,res.timestamp/1000000LL,NULL,
- "%s\t%s",res.username,res.message);
+
+ if(res.type==NET_MESSAGE){
+ weechat_printf_date_tags(
+ room->buffer,res.timestamp/1000000LL,NULL,
+ "%s\t%s",res.username,res.message);
+ } else if(res.type==NET_JOIN){
+ weechat_printf(room->buffer,"%sUser %s joined this room",netpfx,res.username);
+ } else if(res.type==NET_INVITE){
+ weechat_printf(room->buffer,"%sYou were invited into this room",netpfx);
+ net_sendf(fd,history_net_callback,room,"history %s 10",room->name);
+ } else {
+ assert(false);
+ }
} else {
fprintf(debugf,"push_net_callback: unknown response type %d\n",res.type);
}
@@ -133,12 +149,6 @@ static void history_push_net_callback(int fd,struct net_response res,void *paylo
push_net_callback(fd,res,payload);
}
-static void history_net_callback(int fd,struct net_response res,void *payload){
- struct roomdata *room=(struct roomdata*)payload;
- assert(room);
- fprintf(debugf,"history_net_callback(fd=%d,res={.type=%d})\n",fd,res.type);
-}
-
static void roomlist_net_callback(int fd,struct net_response res,void *payload){
(void)payload;
fprintf(debugf,"roomlist_net_callback(fd=%d,res={.type=%d})\n",fd,res.type);
@@ -368,6 +378,7 @@ int weechat_plugin_init(struct t_weechat_plugin *plugin,int argc,char **argv){
fprintf(debugf,"------\n");
errpfx=weechat_prefix("error");
+ netpfx=weechat_prefix("network");
weechat_hook_command(
"tomsg",