|
@@ -33,14 +33,18 @@
|
|
|
#include <vcc/pretty.h>
|
|
#include <vcc/pretty.h>
|
|
|
#include <vcc/plugin.h>
|
|
#include <vcc/plugin.h>
|
|
|
#include <vcc/version.h>
|
|
#include <vcc/version.h>
|
|
|
|
|
+#include <vcc/interfaces.h>
|
|
|
|
|
+#include <klist.h>
|
|
|
|
|
|
|
|
#include <readconf/readconf.h>
|
|
#include <readconf/readconf.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
int hist_init(void);
|
|
int hist_init(void);
|
|
|
|
|
+int do_cmd_hist(int argc, char **argv);
|
|
|
int hist_fd;
|
|
int hist_fd;
|
|
|
|
|
|
|
|
struct cmdtable hist_cmdtab[] = {
|
|
struct cmdtable hist_cmdtab[] = {
|
|
|
|
|
+ { "-hist", do_cmd_hist, "Dump history (from login to now). \n" },
|
|
|
{ NULL, NULL, NULL }
|
|
{ NULL, NULL, NULL }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -52,14 +56,34 @@ struct plugin plg_hist = {
|
|
|
.cmdtab = hist_cmdtab
|
|
.cmdtab = hist_cmdtab
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+struct klist_node history = KLIST_NODE_INIT(&history);
|
|
|
|
|
+
|
|
|
#define this_plg (&plg_hist)
|
|
#define this_plg (&plg_hist)
|
|
|
#define DEFAULT_HISTFILE ".vcc_history"
|
|
#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);
|
|
dprintf(hist_fd, "[%ld] %s: %s", times(NULL), usr, s);
|
|
|
|
|
+
|
|
|
return strdup(s);
|
|
return strdup(s);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+char *hist_msghook(char *s) {
|
|
|
|
|
+ return hist_hook(s, usrname);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
int open_hist_file(void) {
|
|
int open_hist_file(void) {
|
|
|
struct readconf_strconf *conf;
|
|
struct readconf_strconf *conf;
|
|
@@ -92,6 +116,34 @@ int hist_init(void) {
|
|
|
return 1;
|
|
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;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|