intirain пре 4 година
родитељ
комит
3fa0e593d7
7 измењених фајлова са 44 додато и 19 уклоњено
  1. 1 1
      Makefile
  2. 7 4
      include/vcc/plugin.h
  3. 1 3
      include/vcc/robot.h
  4. 1 1
      include/vcc/version.h
  5. 7 1
      main.c
  6. 26 6
      plugins.c
  7. 1 3
      plugins/m4/m4.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
 VCC_MINOR 		= 16
-VCC_PATCH 		= 0
+VCC_PATCH 		= 1
 VCC_STR 		= -rc 
 
 VCC_COMPILE_TIME 	= $(shell date)

+ 7 - 4
include/vcc/plugin.h

@@ -30,7 +30,7 @@
 
 
 typedef char *(* hookfn_t) (char *);
-extern hookfn_t msg_hook;
+extern hookfn_t msg_hook, recv_hook;
 
 struct cmdtable {
 	char 			*cmd;
@@ -48,7 +48,8 @@ struct plugin {
 	int 			(* init) (void);
 	int 			(* exit) (void);
 	
-	hookfn_t 		hook;
+	hookfn_t 		msg_hook, 
+				recv_hook;
 	struct cmdtable 	*cmdtab;
 };
 
@@ -65,8 +66,10 @@ extern struct plugin *plugins[];
 
 int plg_insert(struct plugin *);
 struct plugin *find_plg(char *name);
-int register_hook(hookfn_t, struct plugin *);
-int unregister_hook(hookfn_t, struct plugin *);
+int register_msghook(hookfn_t, struct plugin *);
+int unregister_msghook(hookfn_t, struct plugin *);
+int register_recvhook(hookfn_t, struct plugin *);
+int unregister_recvhook(hookfn_t, struct plugin *);
 
 #endif
 

+ 1 - 3
include/vcc/robot.h

@@ -25,9 +25,7 @@
 #include <sys/types.h>
 #include <vcc/vcc.h>
 
-extern int 	mode;
-struct plugin 	*plgctl;
-
+extern int mode;
 int robot(void);
 
 #endif

+ 1 - 1
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.16.0 Tue May  3 22:01:49 CST 2022 root"
+#define VCC_VERSION "VCC 1.16.0 Wed May  4 15:54:43 CST 2022 root"
 #define VCC_SEMVER "vcc 1.16.0-rc "

+ 7 - 1
main.c

@@ -72,7 +72,6 @@ int 		fd;
 /* robot mode. we run in the background pgroup, and give all the messages to the plugin specified. */
 #define MODE_ROBOT 	2
 int 		mode = MODE_NORMAL;
-struct plugin 	*plgctl;
 
 char usrname[USRNAME_SIZE];
 struct klist_node banned_people = KLIST_NODE_INIT(&banned_people);
@@ -381,8 +380,15 @@ int main(int argc, char **argv) {
 			if (ntohl(req->flags) & FLAG_ENCRYPTED) 
 				decrypt(msg);
 
+			if (recv_hook) 
+				if (unlikely(!(msg = recv_hook(msg)))) 
+					continue;
+
 			pretty_new_msg(req->usrname, msg, ntohl(req->session));
 			pretty_prompt(usrname);
+
+			if (recv_hook) 
+				free(msg);
 		}
 	}
 

+ 26 - 6
plugins.c

@@ -43,7 +43,7 @@
 
 
 extern struct plugin plg_hello, plg_robot, plg_m4;
-hookfn_t msg_hook;
+hookfn_t msg_hook, recv_hook;
 
 struct plugin *plugins[] = {
 	&plg_hello, &plg_robot, &plg_m4, 
@@ -124,7 +124,8 @@ int do_cmd_prem(int argc, char **argv) {
 	if (p->exit) 
 		p->exit();
 
-	unregister_hook(p->hook, p);
+	unregister_msghook(p->msg_hook, p);
+	unregister_recvhook(p->recv_hook, p);
 	
 	return plg_remove(p);
 }
@@ -168,22 +169,41 @@ int do_cmd_pins(int argc, char **argv) {
 }
 
 
-int register_hook(hookfn_t hook, struct plugin *plg) {
+int register_msghook(hookfn_t hook, struct plugin *plg) {
 	/* unlike other things, we can have only one hook at the same moment. */
 
 	if (msg_hook) 
 		fprintf(stderr, "warning: the old hook removed. \n");
 		
-	plg->hook = msg_hook = hook;
+	plg->msg_hook = msg_hook = hook;
 	return 0;
 }
 
 
-int unregister_hook(hookfn_t hook, struct plugin *plg) {
+int register_recvhook(hookfn_t hook, struct plugin *plg) {	
+	if (recv_hook) 
+		fprintf(stderr, "warning: the old hook removed. \n");
+		
+	plg->recv_hook = recv_hook = hook;
+	return 0;
+	
+}
+
+
+int unregister_msghook(hookfn_t hook, struct plugin *plg) {
 	if (msg_hook != hook) 
 		return 0;
 
-	plg->hook = msg_hook = NULL;
+	plg->msg_hook = msg_hook = NULL;
+
+	return 0;
+}
+
+int unregister_recvhook(hookfn_t hook, struct plugin *plg) {
+	if (recv_hook != hook) 
+		return 0;
+
+	plg->recv_hook = recv_hook = NULL;
 
 	return 0;
 }

+ 1 - 3
plugins/m4/m4.c

@@ -92,8 +92,6 @@ int do_cmd_m4def(int argc, char **argv) {
 		m4cache_size += size;
 	}
 
-	printf("%s\n", m4cachep);
-
 	return 0;
 }
 
@@ -137,7 +135,7 @@ int m4_init(void) {
 	m4cachep = NULL;
 	m4cache_size = 0;
 
-	return register_hook(m4_msghook, this_plg);
+	return register_msghook(m4_msghook, this_plg);
 }