Hi,
Turns out you can override all the error messages using
/clispec/$MODE/modifications/errorMessageRewrite
See clispec man pages and examples.confd/message_rewrite example.
Quick demo for the “Incomplete path” message adding the errorMessageRewrite to the examples.confd/cli/climods example:
$ diff -u /Users/tailf/confd-6.2/examples.confd/cli/climods/confd.c.cli ./confd.c.cli
--- /Users//tailf/confd-6.2/examples.confd/cli/climods/confd.c.cli 2016-05-28 19:50:18.000000000 +0200
+++ ./confd.c.cli 2016-09-09 09:57:20.000000000 +0200
@@ -2,6 +2,11 @@
<operationalMode>
<modifications>
+ <errorMessageRewrite>
+ <callback>
+ <capi>error_message_rewrite</capi>
+ </callback>
+ </errorMessageRewrite>
</modifications>
</operationalMode>
$ diff -u /Users/tailf/confd-6.2/examples.confd/cli/climods/actions.c ./actions.c
--- /Users/tailf/confd-6.2/examples.confd/cli/climods/actions.c 2016-05-28 19:50:18.000000000 +0200
+++ ./actions.c 2016-09-09 10:28:59.000000000 +0200
@@ -44,6 +44,8 @@
confd_hkeypath_t *kp,
confd_tag_value_t *params,
int n);
+static int do_error_message_rewrite(struct confd_user_info *uinfo,
+ char *path, int argc, char **argv);
static int do_modename(struct confd_user_info *uinfo,
char *path, int argc, char **argv);
static int abort_action(struct confd_user_info *uinfo);
@@ -58,7 +60,7 @@
{
struct sockaddr_in addr;
int debuglevel = CONFD_TRACE;
- struct confd_action_cbs acb;
+ struct confd_action_cbs acb, acb2;
/* Init library */
confd_init("actions_daemon",stderr, debuglevel);
@@ -107,8 +109,17 @@
acb.abort = abort_action;
if (confd_register_action_cbs(dctx, &acb) != CONFD_OK)
- fail("Couldn't register action callbacks");
+ fail("Couldn't register reset-point action callback");
+ /* register the show path rewrite action handler callback */
+ memset(&acb, 0, sizeof(acb2));
+ strcpy(acb2.actionpoint, "error_message_rewrite");
+ acb2.init = init_action;
+ acb2.command = do_error_message_rewrite;
+
+ if (confd_register_action_cbs(dctx, &acb2) != CONFD_OK)
+ fail("Couldn't register error message rewrite action callback");
+
if (confd_register_done(dctx) != CONFD_OK)
fail("Couldn't complete callback registration");
@@ -271,6 +282,39 @@
return CONFD_OK;
}
+static int do_error_message_rewrite(struct confd_user_info *uinfo,
+ char *type, int argc, char **argv)
+{
+ /* possible types are "error", "warning", "aborted", "info", and
+ * "syntax"
+ */
+
+ /* for syntax message argv[0] contains the message,
+ * argv[1] the part of the line before the error, and
+ * argv[2] the orignal command line
+ */
+
+ char *rep1[] = { "% My error message\n" };
+
+ int i;
+
+ printf("do_error_message_rewrite called\n");
+
+ printf("type of message: %s\n", type);
+
+ for (i = 0; i < argc; i++) {
+ printf("argv %d: %s\n", i, argv[i]);
+ }
+
+ if (strcmp(type, "info") == 0 &&
+ i == 1 && strcmp(argv[0], "% Incomplete path\n") == 0) {
+ if (confd_action_reply_command(uinfo, rep1, 1) < 0)
+ confd_fatal("Failed to reply to confd\n");
+ }
+
+ return CONFD_OK;
+}
+
void fail(char *fmt, ...)
{
va_list ap;
$ make all start
...
$ confd_cli -C -u admin
admin connected from 127.0.0.1 using console
# show arp1 arpe
% My error message