json print revert

This commit is contained in:
Olof Hagsand 2016-09-21 21:24:39 +02:00
parent 601d79b972
commit fe91ba707d
3 changed files with 46 additions and 35 deletions

View file

@ -63,8 +63,9 @@
#define RESTCONF_API_ROOT "/restconf/" #define RESTCONF_API_ROOT "/restconf/"
/*! Generic REST GET method /*! Generic REST GET method
* According to restconf (Sec 3.5.1.1 in [draft])
* @param[in] h Clixon handle
* @param[in] r Fastcgi request handle * @param[in] r Fastcgi request handle
* @param[in] api_path According to restconf (Sec 3.5.1.1 in [draft])
* @param[in] pcvec Vector of path ie DOCUMENT_URI element * @param[in] pcvec Vector of path ie DOCUMENT_URI element
* @param[in] pi Offset, where path starts * @param[in] pi Offset, where path starts
* @param[in] qvec Vector of query string (QUERY_STRING) * @param[in] qvec Vector of query string (QUERY_STRING)

View file

@ -137,6 +137,7 @@ enum list_element_type{
LIST_MIDDLE, LIST_MIDDLE,
LIST_LAST LIST_LAST
}; };
static enum list_element_type static enum list_element_type
list_eval(cxobj *x) list_eval(cxobj *x)
{ {
@ -179,11 +180,8 @@ list_eval(cxobj *x)
return list; return list;
} }
/*! /*!
* @param[in] pretty set if the output should be pretty-printed * @param[in] pretty set if the output should be pretty-printed
* List only if adjacent, * List only if adjacent,
* ie <a>1</a><a>2</a><b>3</b> -> {"a":[1,2],"b":3} * ie <a>1</a><a>2</a><b>3</b> -> {"a":[1,2],"b":3}
* ie <a>1</a><b>3</b><a>2</a> -> {"a":1,"b":3,"a":2} * ie <a>1</a><b>3</b><a>2</a> -> {"a":1,"b":3,"a":2}
@ -252,22 +250,29 @@ xml2json1_cbuf(cbuf *cb,
} }
switch (list){ switch (list){
case LIST_NO: case LIST_NO:
if (!tleaf(x)) if (!tleaf(x)){
if (pretty) if (pretty)
cprintf(cb, "%*s}\n", cprintf(cb, "%*s}\n",
(level*JSON_INDENT), ""); (level*JSON_INDENT), "");
else
cprintf(cb, "}");
}
break; break;
case LIST_MIDDLE: case LIST_MIDDLE:
case LIST_FIRST: case LIST_FIRST:
if (pretty) if (pretty)
cprintf(cb, "\n%*s}", cprintf(cb, "\n%*s}",
(level*JSON_INDENT), ""); (level*JSON_INDENT), "");
else
cprintf(cb, "}");
break; break;
case LIST_LAST: case LIST_LAST:
if (!tleaf(x)){ if (!tleaf(x)){
if (pretty) if (pretty)
cprintf(cb, "\n%*s}\n", cprintf(cb, "\n%*s}\n",
(level*JSON_INDENT), ""); (level*JSON_INDENT), "");
else
cprintf(cb, "}");
level--; level--;
} }
cprintf(cb, "%*s]%s", cprintf(cb, "%*s]%s",
@ -309,15 +314,16 @@ xml2json_cbuf(cbuf *cb,
int pretty) int pretty)
{ {
int retval = 1; int retval = 1;
int level = 0; int level = 1;
int i;
cxobj *xc;
for (i=0; i<xml_child_nr(x); i++){ cprintf(cb, "%*s{%s",
xc = xml_child_i(x, i); pretty?(level*JSON_INDENT):0,"",
if (xml2json1_cbuf(cb, xc, level, pretty) < 0) pretty?"\n":"");
if (xml2json1_cbuf(cb, x, level+1, pretty) < 0)
goto done; goto done;
} cprintf(cb, "%*s}%s",
pretty?(level*JSON_INDENT):0,"",
pretty?"\n":"");
retval = 0; retval = 0;
done: done:
return retval; return retval;

View file

@ -38,11 +38,15 @@
#include "clixon_log.h" #include "clixon_log.h"
#include "clixon_sig.h" #include "clixon_sig.h"
/* /*! Set a signal handler.
* Set a signal handler. * @param[in] signo Signal number
* @param[in] handler Function to call when signal occurs
* @param[out] oldhandler Pointer to old handler
*/ */
int int
set_signal(int signo, void (*handler)(int), void (**oldhandler)(int)) set_signal(int signo,
void (*handler)(int),
void (**oldhandler)(int))
{ {
#if defined(HAVE_SIGACTION) #if defined(HAVE_SIGACTION)
struct sigaction sold, snew; struct sigaction sold, snew;
@ -64,8 +68,8 @@ set_signal(int signo, void (*handler)(int), void (**oldhandler)(int))
} }
/* /*! Block signal.
* Block signal. If 'sig' is 0, block all signals * @param[in] sig Signal number to block, If 0, block all signals
*/ */
void void
clicon_signal_block (int sig) clicon_signal_block (int sig)
@ -82,8 +86,8 @@ clicon_signal_block (int sig)
sigprocmask (SIG_BLOCK, &set, NULL); sigprocmask (SIG_BLOCK, &set, NULL);
} }
/* /*! Unblock signal.
* Unblock signal. If 'sig' is 0, unblock all signals * @param[in] sig Signal number to unblock. If 0, unblock all signals
*/ */
void void
clicon_signal_unblock (int sig) clicon_signal_unblock (int sig)
@ -108,7 +112,8 @@ clicon_signal_unblock (int sig)
* @retval -1 Error, and clicon_err() called * @retval -1 Error, and clicon_err() called
*/ */
int int
pidfile_get(char *pidfile, pid_t *pid0) pidfile_get(char *pidfile,
pid_t *pid0)
{ {
FILE *f; FILE *f;
char *ptr; char *ptr;
@ -156,7 +161,6 @@ pidfile_zapold(pid_t pid)
/*! Write a pid-file /*! Write a pid-file
* *
* @param[in] pidfile Name of pidfile * @param[in] pidfile Name of pidfile
* @param[in] kill_it If set, kill existing process otherwise return pid
*/ */
int int
pidfile_write(char *pidfile) pidfile_write(char *pidfile)