|
@@ -61,28 +61,24 @@ 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_hook(char *s, char *usr) {
|
|
|
|
|
|
|
+char *hist_hook(struct hook_info *hi) {
|
|
|
struct history *n;
|
|
struct history *n;
|
|
|
|
|
|
|
|
if (unlikely(!(n = malloc(sizeof(struct history))))) {
|
|
if (unlikely(!(n = malloc(sizeof(struct history))))) {
|
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
fprintf(stderr, "*** malloc() failed\n");
|
|
|
|
|
|
|
|
- return strdup(s);
|
|
|
|
|
|
|
+ return strdup(hi->msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- n->usrname = strdup(usr);
|
|
|
|
|
- n->msg = strdup(s);
|
|
|
|
|
|
|
+ n->usrname = strdup(hi->usr);
|
|
|
|
|
+ n->msg = strdup(hi->msg);
|
|
|
|
|
|
|
|
klist_init(&n->node);
|
|
klist_init(&n->node);
|
|
|
klist_add(&history, &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), hi->usr, hi->msg);
|
|
|
|
|
|
|
|
- return strdup(s);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-char *hist_msghook(char *s) {
|
|
|
|
|
- return hist_hook(s, usrname);
|
|
|
|
|
|
|
+ return strdup(hi->msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int open_hist_file(void) {
|
|
int open_hist_file(void) {
|
|
@@ -116,8 +112,8 @@ int hist_init(void) {
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- register_recvhook(hist_hook, this_plg);
|
|
|
|
|
- register_msghook(hist_msghook, this_plg);
|
|
|
|
|
|
|
+ register_hook(HOOK_RECV, hist_hook);
|
|
|
|
|
+ register_hook(HOOK_SEND, hist_hook);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -147,3 +143,16 @@ int do_cmd_hist(int argc, char **argv) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+struct history *hist_getmsg(int last) {
|
|
|
|
|
+ struct klist_node *n;
|
|
|
|
|
+
|
|
|
|
|
+ for (n = history.next; n != &history && last--; n = n->next)
|
|
|
|
|
+ ;
|
|
|
|
|
+
|
|
|
|
|
+ if (n == &history)
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+
|
|
|
|
|
+ return hist_of(n);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|