From b2abab71f0cb83c1afdedd709e6a04f74323198d Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Sun, 15 Apr 2018 10:52:52 +0100 Subject: [PATCH] local restconf rpc callback sent error and then main restconf handler sent ok. Callback should just return xml buffer, not do actual restconf callback --- apps/restconf/restconf_lib.c | 2 +- apps/restconf/restconf_methods.c | 18 +++++++++++++++--- lib/src/clixon_plugin.c | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/restconf/restconf_lib.c b/apps/restconf/restconf_lib.c index d42a63ac..9f07985c 100644 --- a/apps/restconf/restconf_lib.c +++ b/apps/restconf/restconf_lib.c @@ -385,7 +385,7 @@ get_user_cookie(char *cookiestr, return retval; } -/*! Return error on get/head request +/*! Return restconf error on get/head request * @param[in] h Clixon handle * @param[in] r Fastcgi request handle * @param[in] xerr XML error message from backend diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index 49ea3efa..22b3c322 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -984,6 +984,7 @@ api_operations_post(clicon_handle h, yang_stmt *youtput; cxobj *xdata = NULL; cxobj *xret = NULL; + cxobj *xerr; cbuf *cbx = NULL; cxobj *xtop = NULL; /* xpath root */ cxobj *xe; @@ -1080,6 +1081,7 @@ api_operations_post(clicon_handle h, goto done; } xe = NULL; + while ((xe = xml_child_each(xtop, xe, CX_ELMNT)) != NULL) { /* Look for local (client-side) restconf plugins. */ if ((ret = rpc_callback_call(h, xe, cbret, r)) < 0) @@ -1087,6 +1089,12 @@ api_operations_post(clicon_handle h, if (ret == 1){ /* Handled locally */ if (xml_parse_string(cbuf_get(cbret), NULL, &xret) < 0) goto done; + /* Local error: return it and quit */ + if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){ + if (api_return_err(h, r, xerr, pretty, use_xml) < 0) + goto done; + goto ok; + } } break; /* Just one if local */ } @@ -1095,11 +1103,13 @@ api_operations_post(clicon_handle h, goto done; if ((cbx = cbuf_new()) == NULL) goto done; - xoutput=xpath_first(xret, "/"); - xml_name_set(xoutput, "output"); + if ((xoutput=xpath_first(xret, "/")) != NULL) + xml_name_set(xoutput, "output"); if ((youtput = yang_find((yang_node*)yrpc, Y_OUTPUT, NULL)) != NULL && xoutput){ - // clicon_debug(1, "%s xoutput:%s", __FUNCTION__, cbuf_get(cbx)); +#if 0 + clicon_debug(1, "%s xoutput:%s", __FUNCTION__, cbuf_get(cbx)); +#endif cbuf_reset(cbx); xml_spec_set(xoutput, youtput); /* needed for xml_spec_populate */ if (xml_apply(xoutput, CX_ELMNT, xml_spec_populate, youtput) < 0) @@ -1122,7 +1132,9 @@ api_operations_post(clicon_handle h, else if (xml2json_cbuf(cbx, xoutput, pretty) < 0) goto done; +#if 1 clicon_debug(1, "%s xoutput:%s", __FUNCTION__, cbuf_get(cbx)); +#endif FCGX_FPrintF(r->out, "%s", cbx?cbuf_get(cbx):""); FCGX_FPrintF(r->out, "\r\n\r\n"); } diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index 1e231b45..3675b37b 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -465,8 +465,8 @@ rpc_callback_call(clicon_handle h, cbuf *cbret, void *arg) { - rpc_callback_t *rc; int retval = -1; + rpc_callback_t *rc; if (rpc_cb_list == NULL) return 0; @@ -486,5 +486,6 @@ rpc_callback_call(clicon_handle h, } while (rc != rpc_cb_list); retval = 0; done: + clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); return retval; }