diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index a59e3e46..5dd4ca43 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -624,11 +624,14 @@ from_client_debug(clicon_handle h, goto done; } clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ + setlogmask(LOG_UPTO(level?LOG_DEBUG:LOG_INFO)); /* for syslog */ if (send_msg_ok(s) < 0) goto done; + clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, debug); retval = 0; done: + return retval; } diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c index ffd0b43a..2efcb7c6 100644 --- a/apps/backend/clixon_backend_handle.c +++ b/apps/backend/clixon_backend_handle.c @@ -125,7 +125,7 @@ backend_notify(clicon_handle h, ce_next = ce->ce_next; for (su = ce->ce_subscription; su; su = su->su_next) if (strcmp(su->su_stream, stream) == 0){ - if (fnmatch(su->su_filter, event, 0) == 0) + if (strlen(su->su_filter)==0 || fnmatch(su->su_filter, event, 0) == 0){ if (send_msg_notify(ce->ce_s, level, event) < 0){ if (errno == ECONNRESET){ clicon_log(LOG_WARNING, "client %s reset", ce->ce_nr); @@ -142,6 +142,7 @@ backend_notify(clicon_handle h, } goto done; } + } } } /* Then go thru all global (handle) subscriptions and find matches */ @@ -151,7 +152,9 @@ backend_notify(clicon_handle h, continue; if (strcmp(hs->hs_stream, stream)) continue; - if (fnmatch(hs->hs_filter, event, 0) == 0) + if (hs->hs_filter==NULL || + strlen(hs->hs_filter)==0 || + fnmatch(hs->hs_filter, event, 0) == 0) if ((*hs->hs_fn)(h, event, hs->hs_arg) < 0) goto done; } @@ -227,9 +230,10 @@ backend_notify_xml(clicon_handle h, continue; if (strcmp(hs->hs_stream, stream)) continue; - if (strlen(hs->hs_filter)==0 || xpath_first(x, hs->hs_filter) != NULL) + if (strlen(hs->hs_filter)==0 || xpath_first(x, hs->hs_filter) != NULL){ if ((*hs->hs_fn)(h, x, hs->hs_arg) < 0) goto done; + } } retval = 0; done: @@ -319,7 +323,7 @@ subscription_add(clicon_handle h, memset(hs, 0, sizeof(*hs)); hs->hs_stream = strdup(stream); hs->hs_format = format; - hs->hs_filter = strdup(filter); + hs->hs_filter = filter?strdup(filter):NULL; hs->hs_next = cb->cb_subscription; hs->hs_fn = fn; hs->hs_arg = arg; diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 8b071752..e9929413 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -95,6 +95,7 @@ int xml_addsub(cxobj *xp, cxobj *xc); cxobj *xml_insert(cxobj *xt, char *tag); int xml_purge(cxobj *xc); int xml_child_rm(cxobj *xp, int i); +int xml_rm(cxobj *xc); int xml_rootchild(cxobj *xp, int i, cxobj **xcp); char *xml_body(cxobj *xn); diff --git a/lib/clixon/clixon_xml_map.h b/lib/clixon/clixon_xml_map.h index 249cde0f..cd59c1e4 100644 --- a/lib/clixon/clixon_xml_map.h +++ b/lib/clixon/clixon_xml_map.h @@ -41,6 +41,7 @@ enum { */ int xml2txt(FILE *f, cxobj *x, int level); int xml2cli(FILE *f, cxobj *x, char *prepend, enum genmodel_type gt, const char *label); +int xml2json_cbuf(cbuf *cb, cxobj *x, int level); int xml2json(FILE *f, cxobj *x, int level); int xml_yang_validate(cxobj *xt, yang_stmt *ys) ; int xml2cvec(cxobj *xt, yang_stmt *ys, cvec **cvv0); diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c index 03bfcf85..8c530fba 100644 --- a/lib/src/clixon_log.c +++ b/lib/src/clixon_log.c @@ -96,8 +96,7 @@ clicon_log_register_callback(clicon_log_notify_t *cb, return old; } -/* - * Mimic syslog and print a time on file f +/*! Mimic syslog and print a time on file f */ static int flogtime(FILE *f) diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index 3435f8ee..3a59d2fa 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -609,7 +609,7 @@ xml_purge(cxobj *xc) return retval; } -/*! Remove xml node from parent xml node. No freeing and child is new own root +/*! Remove child xml node from parent xml node. No free and child is root * @param[in] xp xml parent node * @param[in] i Number of xml child node (to remove) * @retval 0 OK @@ -617,6 +617,7 @@ xml_purge(cxobj *xc) * @note you should not remove xchild in loop (unless yoy keep track of xprev) * * @see xml_rootchild + * @see xml_rm Remove the node itself from parent */ int xml_child_rm(cxobj *xp, @@ -640,6 +641,38 @@ xml_child_rm(cxobj *xp, return retval; } +/*! Remove this xml node from parent xml node. No freeing and node is new root + * @param[in] xc xml child node to be removed + * @retval 0 OK + * @retval -1 + * @note you should not remove xchild in loop (unless yoy keep track of xprev) + * + * @see xml_child_rm Remove a child of a node + */ +int +xml_rm(cxobj *xc) +{ + int retval = 0; + cxobj *xp; + cxobj *x; + int i; + + if ((xp = xml_parent(xc)) == NULL) + goto done; + retval = -1; + /* Find child in parent */ + x = NULL; i = 0; + while ((x = xml_child_each(xp, x, -1)) != NULL) { + if (x == xc) + break; + i++; + } + if (x != NULL) + retval = xml_child_rm(xp, i); + done: + return retval; +} + /*! Return a child sub-tree, while removing parent and all other children * Given a root xml node, and the i:th child, remove the child from its parent * and return it, remove the parent and all other children. @@ -678,13 +711,12 @@ xml_rootchild(cxobj *xp, return retval; } - /*! Get the first sub-node which is an XML body. * @param[in] xn xml tree node * @retval The returned body as a pointer to the name string * @retval NULL if no such node or no body in found node * Note, make a copy of the return value to use it properly - * See also xml_find_body + * @see xml_find_body */ char * xml_body(cxobj *xn) @@ -817,9 +849,9 @@ xml_print(FILE *f, #define XML_INDENT 3 /* maybve we should set this programmatically? */ -/*! Print an XML tree structure to a clicon buffer +/*! Print an XML tree structure to a cligen buffer * - * @param[in,out] cb Clicon buffer to write to + * @param[in,out] cb Cligen buffer to write to * @param[in] xn clicon xml tree * @param[in] level how many spaces to insert before each line * @param[in] prettyprint insert \n and spaces tomake the xml more readable. @@ -1027,7 +1059,7 @@ clicon_xml_parse_file(int fd, * xml_free(cx); * @endcode * @see clicon_xml_parse_file - * Note, you need to free the xml parse tree after use, using xml_free() + * @note you need to free the xml parse tree after use, using xml_free() * Update: with yacc parser I dont think it changes,.... */ int diff --git a/lib/src/clixon_xml_db.c b/lib/src/clixon_xml_db.c index ac9a11b9..404efabe 100644 --- a/lib/src/clixon_xml_db.c +++ b/lib/src/clixon_xml_db.c @@ -1001,7 +1001,6 @@ xmldb_get_local(clicon_handle h, * free(xvec); * @endcode * @see xpath_vec - * @endcode */ int xmldb_get(clicon_handle h, diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index b17705ad..dd7e3c0f 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -262,11 +262,22 @@ xml2cli(FILE *f, return retval; } -/*! Translate from xml tree to JSON +/*! Internal function to translate from xml tree to JSON + * @param[in,out] cb Cligen buffer to write to + * @param[in] x XML tree to translate from + * @param[in] level Indentation level + * @param[in] eq + * @param[in] comma + * @retval 0 OK + * @retval -1 Error * XXX ugly code could be cleaned up */ -int -xml2json1(FILE *f, cxobj *x, int level, int eq, int comma) +static int +xml2json1_cbuf(cbuf *cb, + cxobj *x, + int level, + int eq, + int comma) { cxobj *xe = NULL; cxobj *x1; @@ -279,23 +290,23 @@ xml2json1(FILE *f, cxobj *x, int level, int eq, int comma) switch(xml_type(x)){ case CX_BODY: - fprintf(f, "\"%s\"", xml_value(x)); + cprintf(cb, "\"%s\"", xml_value(x)); break; case CX_ELMNT: if (eq == 2) - fprintf(f, "%*s", 2*level2, ""); + cprintf(cb, "%*s", 2*level2, ""); else{ - fprintf(f, "%*s", 2*level1, ""); - fprintf(f, "\"%s\": ", xml_name(x)); + cprintf(cb, "%*s", 2*level1, ""); + cprintf(cb, "\"%s\": ", xml_name(x)); } if (xml_body(x)!=NULL){ if (eq==1){ - fprintf(f, "[\n"); - fprintf(f, "%*s", 2*level2, ""); + cprintf(cb, "[\n"); + cprintf(cb, "%*s", 2*level2, ""); } } else { - fprintf(f, "{\n"); + cprintf(cb, "{\n"); } xe = NULL; n = xml_child_nr(x); @@ -313,17 +324,17 @@ xml2json1(FILE *f, cxobj *x, int level, int eq, int comma) eq1 = 2; /* last */ } } - if (xml2json1(f, xe, level1, eq1, (i+1= * -