xml_print

This commit is contained in:
Olof Hagsand 2016-04-17 17:52:48 +02:00
parent 55201c9b4a
commit dfa30aa39c
12 changed files with 101 additions and 27 deletions

View file

@ -133,7 +133,9 @@ client_subscription_find(struct client_entry *ce, char *stream)
/*! Remove client entry state
* Close down everything wrt clients (eg sockets, subscriptions)
* Finally actually remove client struct in handle
* @see backend_client_delete
* @param[in] h Clicon handle
* @param[in] ce Client hadnle
* @see backend_client_delete for actual deallocation of client entry struct
*/
int
backend_client_rm(clicon_handle h,
@ -338,7 +340,7 @@ config_snapshot(clicon_handle h,
}
if (xmldb_get(h, db, "/", 0, &xn, NULL, NULL) < 0)
goto done;
if (clicon_xml2file(f, xn, 0, 1) < 0)
if (xml_print(f, xn) < 0)
goto done;
retval = 0;
done:
@ -404,7 +406,7 @@ from_client_save(clicon_handle h,
}
if (xmldb_get(h, db, "/", 0, &xn, NULL, NULL) < 0)
goto done;
if (clicon_xml2file(f, xn, 0, 1) < 0)
if (xml_print(f, xn) < 0)
goto done;
}
if (send_msg_ok(s) < 0)

View file

@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <regex.h>
#include <syslog.h>
#include <netinet/in.h>
/* cligen */
@ -114,18 +115,35 @@ backend_notify(clicon_handle h,
char *event)
{
struct client_entry *ce;
struct client_entry *ce_next;
struct client_subscription *su;
struct handle_subscription *hs;
int retval = -1;
/* First thru all clients(sessions), and all subscriptions and find matches */
for (ce = backend_client_list(h); ce; ce = ce->ce_next)
for (ce = backend_client_list(h); ce; ce = ce_next){
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 (send_msg_notify(ce->ce_s, level, event) < 0)
if (send_msg_notify(ce->ce_s, level, event) < 0){
if (errno == ECONNRESET){
clicon_log(LOG_WARNING, "client %s reset", ce->ce_nr);
#if 0
/* We should remove here but removal is not possible
from a client since backend_client is not linked.
Maybe we should add it to the plugin, but it feels
"safe" that you cant remove a client.
Instead, the client is (hopefully) removed elsewhere?
*/
backend_client_rm(h, ce);
#endif
break;
}
goto done;
}
}
}
/* Then go thru all global (handle) subscriptions and find matches */
hs = NULL;
while ((hs = subscription_each(h, hs)) != NULL){
@ -162,6 +180,7 @@ backend_notify_xml(clicon_handle h,
cxobj *x)
{
struct client_entry *ce;
struct client_entry *ce_next;
struct client_subscription *su;
int retval = -1;
cbuf *cb = NULL;
@ -169,7 +188,8 @@ backend_notify_xml(clicon_handle h,
clicon_debug(1, "%s %s", __FUNCTION__, stream);
/* Now go thru all clients(sessions), and all subscriptions and find matches */
for (ce = backend_client_list(h); ce; ce = ce->ce_next)
for (ce = backend_client_list(h); ce; ce = ce_next){
ce_next = ce->ce_next;
for (su = ce->ce_subscription; su; su = su->su_next)
if (strcmp(su->su_stream, stream) == 0){
if (strlen(su->su_filter)==0 || xpath_first(x, su->su_filter) != NULL){
@ -181,10 +201,25 @@ backend_notify_xml(clicon_handle h,
if (clicon_xml2cbuf(cb, x, 0, 0) < 0)
goto done;
}
if (send_msg_notify(ce->ce_s, level, cbuf_get(cb)) < 0)
if (send_msg_notify(ce->ce_s, level, cbuf_get(cb)) < 0){
if (errno == ECONNRESET){
clicon_log(LOG_WARNING, "client %s reset", ce->ce_nr);
#if 0
/* We should remove here but removal is not possible
from a client since backend_client is not linked.
Maybe we should add it to the plugin, but it feels
"safe" that you cant remove a client.
Instead, the client is (hopefully) removed elsewhere?
*/
backend_client_rm(h, ce);
#endif
break;
}
goto done;
}
}
}
}
/* Then go thru all global (handle) subscriptions and find matches */
hs = NULL;
while ((hs = subscription_each(h, hs)) != NULL){
@ -230,11 +265,14 @@ backend_client_list(clicon_handle h)
return cb->cb_ce_list;
}
/*! Actually remove client from list
* See also backend_client_rm()
/*! Actually remove client from client list
* @param[in] h Clicon handle
* @param[in] ce Client hadnle
* @see backend_client_rm which is more high-level
*/
int
backend_client_delete(clicon_handle h, struct client_entry *ce)
backend_client_delete(clicon_handle h,
struct client_entry *ce)
{
struct client_entry *c;
struct client_entry **ce_prev;

View file

@ -188,19 +188,19 @@ transaction_print(FILE *f,
fprintf(f, "Removed\n=========\n");
for (i=0; i<td->td_dlen; i++){
xn = td->td_dvec[i];
clicon_xml2file(f, xn, 0, 1);
xml_print(f, xn);
}
fprintf(f, "Added\n=========\n");
for (i=0; i<td->td_alen; i++){
xn = td->td_avec[i];
clicon_xml2file(f, xn, 0, 1);
xml_print(f, xn);
}
fprintf(stderr, "Changed\n=========\n");
for (i=0; i<td->td_clen; i++){
xn = td->td_scvec[i];
clicon_xml2file(f, xn, 0, 1);
xml_print(f, xn);
xn = td->td_tcvec[i];
clicon_xml2file(f, xn, 0, 1);
xml_print(f, xn);
}
return 0;
}