Răsfoiți Sursa

vcc: add command -hist

intirain 4 ani în urmă
părinte
comite
0895417ee8
4 a modificat fișierele cu 66 adăugiri și 6 ștergeri
  1. 2 2
      Makefile
  2. 8 0
      include/vcc/interfaces.h
  3. 2 2
      include/vcc/version.h
  4. 54 2
      plugins/hist/hist.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 26
-VCC_PATCH 		= 1
+VCC_MINOR 		= 27
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 8 - 0
include/vcc/interfaces.h

@@ -33,6 +33,14 @@ struct banlist {
 
 #define banlist_of(n) 		container_of(n, struct banlist, node)
 
+struct history {
+	char 			*usrname;
+	char 			*msg;
+	struct klist_node 	node;
+};
+
+#define hist_of(n) 		container_of(n, struct history, node)
+
 int vcc_login(char *, char *);
 int do_intiauth(void);
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.26.1 Wed Jun  8 01:11:02 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.26.1-rc "
+#define VCC_VERSION "VCC 1.27.0 Wed Jun  8 01:25:43 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.27.0-rc "

+ 54 - 2
plugins/hist/hist.c

@@ -33,14 +33,18 @@
 #include <vcc/pretty.h>
 #include <vcc/plugin.h>
 #include <vcc/version.h>
+#include <vcc/interfaces.h>
+#include <klist.h>
 
 #include <readconf/readconf.h>
 
 
 int hist_init(void);
+int do_cmd_hist(int argc, char **argv);
 int hist_fd;
 
 struct cmdtable hist_cmdtab[] = {
+	{ "-hist", do_cmd_hist, "Dump history (from login to now). \n" }, 
 	{ NULL, NULL, NULL }
 };
 
@@ -52,14 +56,34 @@ struct plugin plg_hist = {
 	.cmdtab = hist_cmdtab
 };
 
+struct klist_node history = KLIST_NODE_INIT(&history);
+
 #define this_plg (&plg_hist)
 #define DEFAULT_HISTFILE ".vcc_history"
 
-char *hist_recvhook(char *s, char *usr) {
+char *hist_hook(char *s, char *usr) {
+	struct history *n;
+
+	if (unlikely(!(n = malloc(sizeof(struct history))))) {
+		fprintf(stderr, "*** malloc() failed\n");
+
+		return strdup(s);
+	}
+
+	n->usrname = strdup(usr);
+	n->msg = strdup(s);
+
+	klist_init(&n->node);
+	klist_add(&history, &n->node);
+
 	dprintf(hist_fd, "[%ld] %s: %s", times(NULL), usr, s);
+
 	return strdup(s);
 }
 
+char *hist_msghook(char *s) {
+	return hist_hook(s, usrname);
+}
 
 int open_hist_file(void) {
 	struct readconf_strconf *conf;
@@ -92,6 +116,34 @@ int hist_init(void) {
 		return 1;
 	}
 
-	return register_recvhook(hist_recvhook, this_plg);
+	register_recvhook(hist_hook, this_plg);
+	register_msghook(hist_msghook, this_plg);
+
+	return 0;
+}
+
+
+int do_cmd_hist(int argc, char **argv) {
+	struct klist_node *n;
+	struct history *hist;
+
+	(void) argv;
+
+	plg_check_enabled();
+
+	if (argc != 1) {
+		fprintf(stderr, _("usage: -hist\n"));
+
+		return 1;
+	}
+
+	for (n = history.next; n != &history; n = n->next) {
+		hist = hist_of(n);
+
+		pretty_new_msg(hist->usrname, hist->msg, 0, 0);
+	}
+
+	return 0;
 }
 
+