From 18093441a804cacf5115c5097c2e915d6d6d51a5 Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Mon, 3 Apr 2017 15:21:13 +0200 Subject: [PATCH] revert xsl for . and .. --- apps/backend/backend_client.c | 1 + apps/backend/backend_commit.c | 2 +- apps/backend/backend_socket.c | 8 +++---- apps/backend/clixon_backend_handle.c | 2 +- apps/cli/cli_common.c | 33 +++++++++++++++++++--------- lib/src/clixon_proto.c | 1 + lib/src/clixon_proto_client.c | 2 +- lib/src/clixon_xml_db.c | 6 ++--- lib/src/clixon_xsl.c | 13 ++++++++++- 9 files changed, 47 insertions(+), 21 deletions(-) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 41d36a86..f30467dd 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -870,6 +870,7 @@ from_client_msg(clicon_handle h, } reply: assert(cbuf_len(cbret)); + clicon_debug(1, "%s %s", __FUNCTION__, cbuf_get(cbret)); if (send_msg_reply(ce->ce_s, cbuf_get(cbret), cbuf_len(cbret)+1) < 0){ if (errno == ECONNRESET) clicon_log(LOG_WARNING, "client rpc reset"); diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index 1f9ba7d7..95b15869 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -163,7 +163,7 @@ validate_common(clicon_handle h, &td->td_tcvec, /* changed: wanted values */ &td->td_clen) < 0) goto done; - if (debug) + if (debug>1) transaction_print(stderr, td); /* Mark as changed in tree */ for (i=0; itd_dlen; i++){ /* Also down */ diff --git a/apps/backend/backend_socket.c b/apps/backend/backend_socket.c index 6065cbf7..b83f7ce3 100644 --- a/apps/backend/backend_socket.c +++ b/apps/backend/backend_socket.c @@ -193,12 +193,12 @@ config_socket_init(clicon_handle h) return 0; } -/* - * config_accept_client +/*! Accept new socket client * XXX: credentials not properly implemented */ int -config_accept_client(int fd, void *arg) +config_accept_client(int fd, + void *arg) { int retval = -1; clicon_handle h = (clicon_handle)arg; @@ -218,7 +218,7 @@ config_accept_client(int fd, void *arg) char *mem; int i; - clicon_debug(1, "%s", __FUNCTION__); + clicon_debug(2, "%s", __FUNCTION__); len = sizeof(from); if ((s = accept(fd, (struct sockaddr*)&from, &len)) < 0){ clicon_err(OE_UNIX, errno, "%s: accept", __FUNCTION__); diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c index a795d7b0..84ecebbe 100644 --- a/apps/backend/clixon_backend_handle.c +++ b/apps/backend/clixon_backend_handle.c @@ -133,7 +133,7 @@ backend_notify(clicon_handle h, struct handle_subscription *hs; int retval = -1; - clicon_debug(1, "%s %s", __FUNCTION__, stream); + clicon_debug(2, "%s %s", __FUNCTION__, stream); /* First thru all clients(sessions), and all subscriptions and find matches */ for (ce = backend_client_list(h); ce; ce = ce_next){ ce_next = ce->ce_next; diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index e4402680..c41bf3e1 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -646,16 +646,18 @@ load_config_filev(clicon_handle h, goto done; if (xt == NULL) goto done; - /* Ensure top-level is "config", maybe this is too rough? */ - xml_name_set(xt, "config"); + // if ((xn = xml_child_i(xt, 0)) != NULL){ if ((cbxml = cbuf_new()) == NULL) goto done; x = NULL; - while ((x = xml_child_each(xt, x, -1)) != NULL) + while ((x = xml_child_each(xt, x, -1)) != NULL) { + /* Ensure top-level is "config", maybe this is too rough? */ + xml_name_set(x, "config"); if (clicon_xml2cbuf(cbxml, x, 0, 0) < 0) goto done; + } if (clicon_rpc_edit_config(h, "candidate", replace?OP_REPLACE:OP_MERGE, "", @@ -802,10 +804,12 @@ db_copy(clicon_handle h, } /* These are strings that can be used as 3rd argument to cli_setlog */ +#ifdef notused // broke in new version static const char *SHOWAS_TXT = "txt"; static const char *SHOWAS_XML = "xml"; static const char *SHOWAS_XML2TXT = "xml2txt"; static const char *SHOWAS_XML2JSON = "xml2json"; +#endif /*! This is the callback used by cli_setlog to print log message in CLI * param[in] s UNIX socket from backend where message should be read @@ -818,12 +822,14 @@ cli_notification_cb(int s, struct clicon_msg *reply = NULL; int eof; int retval = -1; - char *eventstr = NULL; cxobj *xt = NULL; - cxobj *xn; cxobj *xe; char *format = (char*)arg; - +#if 0 + char *eventstr = NULL; + cxobj *xn; +#endif + /* get msg (this is the reason this function is called) */ if (clicon_msg_rcv(s, &reply, &eof) < 0) goto done; @@ -838,8 +844,11 @@ cli_notification_cb(int s, goto done; if (clicon_msg_decode(reply, &xt) < 0) goto done; - if ((xe = xpath_first(xt, "//event")) != NULL) - eventstr = xml_body(xe); + if ((xe = xpath_first(xt, "//event")) != NULL){ + if (xml_print(stdout, xe) < 0) + goto done; + } +#ifdef notyet /* Broke in new version */ if (strcmp(format, SHOWAS_TXT) == 0){ fprintf(stdout, "%s\n", eventstr); } @@ -864,7 +873,7 @@ cli_notification_cb(int s, goto done; } } - +#endif retval = 0; done: if (xt) @@ -908,6 +917,10 @@ cli_notifyv(clicon_handle h, formatstr = cv_string_get(cvec_i(argv, 2)); if (strcmp(formatstr, "SHOWAS_TXT") != 0) format = MSG_NOTIFY_XML; + if ((formatstr = strdup(formatstr)) == NULL){ /* XXX */ + clicon_err(OE_PLUGIN, 0, "%s Requires arguments: []", __FUNCTION__); + goto done; + } } if (cli_notification_register(h, stream, @@ -915,7 +928,7 @@ cli_notifyv(clicon_handle h, "", status, cli_notification_cb, - (void*)strdup(formatstr)) < 0) + formatstr) < 0) goto done; retval = 0; diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 43816194..e74e28b1 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -119,6 +119,7 @@ clicon_msg_decode(struct clicon_msg *msg, /* body */ xmlstr = msg->op_body; + clicon_debug(1, "%s %s", __FUNCTION__, xmlstr); if (clicon_xml_parse_str(xmlstr, xml) < 0) goto done; retval = 0; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index cc60ffb1..1ed8d5b9 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -606,7 +606,7 @@ clicon_rpc_discard_changes(clicon_handle h) cxobj *xret = NULL; cxobj *xerr; - if ((msg = clicon_msg_encode("")) == NULL) + if ((msg = clicon_msg_encode("")) == NULL) goto done; if (clicon_rpc_msg(h, msg, &xret, NULL) < 0) goto done; diff --git a/lib/src/clixon_xml_db.c b/lib/src/clixon_xml_db.c index 8066c5fb..1dbd4a6a 100644 --- a/lib/src/clixon_xml_db.c +++ b/lib/src/clixon_xml_db.c @@ -1011,7 +1011,7 @@ xmldb_get(clicon_handle h, struct db_pair *pairs; cxobj *xt = NULL; - clicon_debug(1, "%s", __FUNCTION__); + clicon_debug(2, "%s", __FUNCTION__); if (db2file(h, db, &dbname) < 0) goto done; if (dbname==NULL){ @@ -1065,8 +1065,8 @@ xmldb_get(clicon_handle h, goto done; if (xml_apply(xt, CX_ELMNT, xml_sanity, NULL) < 0) goto done; - if (debug) - clicon_xml2file(stdout, xt, 0, 1); + if (debug>1) + clicon_xml2file(stderr, xt, 0, 1); *xtop = xt; retval = 0; done: diff --git a/lib/src/clixon_xsl.c b/lib/src/clixon_xsl.c index c90bb290..441d15a4 100644 --- a/lib/src/clixon_xsl.c +++ b/lib/src/clixon_xsl.c @@ -199,7 +199,7 @@ xpath_parse_predicate(struct xpath_element *xe, int len; len = strlen(pred); - for (i=len-1; i>=0; i--){ /* -2 since we search for ][ */ + for (i=len-1; i>=0; i--){ /* -1 since we search for ][ */ s = &pred[i]; if (i==0 || (*(s)==']' && *(s+1)=='[')){ @@ -358,12 +358,23 @@ xpath_parse(char *xpath, else if (strncmp(s,"descendant-or-self::", strlen("descendant-or-self::"))==0){ xpath_element_new(A_DESCENDANT_OR_SELF, s+strlen("descendant-or-self::"), &xpnext); } +#if 1 /* Problems with .[userid=1321] */ + else if (strncmp(s,".", strlen("."))==0) + xpath_element_new(A_SELF, s+strlen("."), &xpnext); +#else else if (strncmp(s,".", strlen(s))==0) /* abbreviatedstep */ xpath_element_new(A_SELF, NULL, &xpnext); +#endif + else if (strncmp(s,"self::", strlen("self::"))==0) xpath_element_new(A_SELF, s+strlen("self::"), &xpnext); +#if 1 + else if (strncmp(s,"..", strlen(".."))==0) /* abbreviatedstep */ + xpath_element_new(A_PARENT, s+strlen(".."), &xpnext); +#else else if (strncmp(s,"..", strlen(s))==0) /* abbreviatedstep */ xpath_element_new(A_PARENT, NULL, &xpnext); +#endif else if (strncmp(s,"parent::", strlen("parent::"))==0) xpath_element_new(A_PARENT, s+strlen("parent::"), &xpnext); else if (strncmp(s,"ancestor::", strlen("ancestor::"))==0)