version 1.6, 2016/10/13 22:48:51 |
version 1.7, 2016/10/16 17:55:14 |
|
|
|
|
static struct hook *hooks_find1(struct hooks *, const char *); |
static struct hook *hooks_find1(struct hooks *, const char *); |
static void hooks_free1(struct hooks *, struct hook *); |
static void hooks_free1(struct hooks *, struct hook *); |
static void hooks_emptyfn(struct cmd_q *); |
|
|
|
static int |
static int |
hooks_cmp(struct hook *hook1, struct hook *hook2) |
hooks_cmp(struct hook *hook1, struct hook *hook2) |
|
|
return (hook); |
return (hook); |
} |
} |
|
|
static void |
void |
hooks_emptyfn(struct cmd_q *hooks_cmdq) |
|
{ |
|
struct cmd_q *cmdq = hooks_cmdq->data; |
|
|
|
if (cmdq != NULL) { |
|
if (hooks_cmdq->client_exit >= 0) |
|
cmdq->client_exit = hooks_cmdq->client_exit; |
|
if (!cmdq_free(cmdq)) |
|
cmdq_continue(cmdq); |
|
} |
|
cmdq_free(hooks_cmdq); |
|
} |
|
|
|
int |
|
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, |
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, |
const char *fmt, ...) |
const char *fmt, ...) |
{ |
{ |
struct hook *hook; |
struct hook *hook; |
struct cmd_q *hooks_cmdq; |
|
va_list ap; |
va_list ap; |
char *name; |
char *name; |
|
struct cmd_q *new_cmdq, *loop; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
xvasprintf(&name, fmt, ap); |
xvasprintf(&name, fmt, ap); |
|
|
hook = hooks_find(hooks, name); |
hook = hooks_find(hooks, name); |
if (hook == NULL) { |
if (hook == NULL) { |
free(name); |
free(name); |
return (-1); |
return; |
} |
} |
log_debug("running hook %s", name); |
log_debug("running hook %s", name); |
free(name); |
|
|
|
hooks_cmdq = cmdq_new(c); |
new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); |
hooks_cmdq->flags |= CMD_Q_NOHOOKS; |
|
|
|
if (fs != NULL) |
for (loop = new_cmdq; loop != NULL; loop = loop->next) |
cmd_find_copy_state(&hooks_cmdq->current, fs); |
loop->hook = xstrdup(name); |
hooks_cmdq->parent = NULL; |
free(name); |
|
|
cmdq_run(hooks_cmdq, hook->cmdlist, NULL); |
cmdq_append(c, new_cmdq); |
cmdq_free(hooks_cmdq); |
|
return (0); |
|
} |
} |
|
|
int |
void |
hooks_wait(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, |
hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, |
const char *fmt, ...) |
const char *fmt, ...) |
{ |
{ |
struct hook *hook; |
struct hook *hook; |
struct cmd_q *hooks_cmdq; |
|
va_list ap; |
va_list ap; |
char *name; |
char *name; |
|
struct cmd_q *new_cmdq, *loop; |
|
|
if (cmdq->flags & CMD_Q_NOHOOKS) |
if (cmdq->flags & CMD_Q_NOHOOKS) |
return (-1); |
return; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
xvasprintf(&name, fmt, ap); |
xvasprintf(&name, fmt, ap); |
|
|
hook = hooks_find(hooks, name); |
hook = hooks_find(hooks, name); |
if (hook == NULL) { |
if (hook == NULL) { |
free(name); |
free(name); |
return (-1); |
return; |
} |
} |
log_debug("running hook %s (parent %p)", name, cmdq); |
log_debug("running hook %s (parent %p)", name, cmdq); |
free(name); |
|
|
|
hooks_cmdq = cmdq_new(cmdq->client); |
new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); |
hooks_cmdq->flags |= CMD_Q_NOHOOKS; |
|
|
|
if (fs != NULL) |
for (loop = new_cmdq; loop != NULL; loop = loop->next) |
cmd_find_copy_state(&hooks_cmdq->current, fs); |
loop->hook = xstrdup(name); |
hooks_cmdq->parent = cmdq; |
free(name); |
|
|
hooks_cmdq->emptyfn = hooks_emptyfn; |
|
hooks_cmdq->data = cmdq; |
|
|
|
if (cmdq != NULL) |
if (cmdq != NULL) |
cmdq->references++; |
cmdq_insert_after(cmdq, new_cmdq); |
cmdq_run(hooks_cmdq, hook->cmdlist, NULL); |
else |
return (0); |
cmdq_append(NULL, new_cmdq); |
} |
} |