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

@ -62,22 +62,23 @@
resource ([RFC6415]) */
#define RESTCONF_API_ROOT "/restconf/"
/*! Generic REST GET method
* @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
/*! 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] pcvec Vector of path ie DOCUMENT_URI element
* @param[in] pi Offset, where path starts
* @param[in] qvec Vector of query string (QUERY_STRING)
* @code
* @param[in] qvec Vector of query string (QUERY_STRING)
* @code
* curl -G http://localhost/restconf/data/interfaces/interface=eth0
* @endcode
* XXX: cant find a way to use Accept request field to choose Content-Type
* I would like to support both xml and json.
* Request may contain
* Accept: application/yang.data+json,application/yang.data+xml
* Response contains one of:
* Content-Type: application/yang.data+xml
* Content-Type: application/yang.data+json
* @endcode
* XXX: cant find a way to use Accept request field to choose Content-Type
* I would like to support both xml and json.
* Request may contain
* Accept: application/yang.data+json,application/yang.data+xml
* Response contains one of:
* Content-Type: application/yang.data+xml
* Content-Type: application/yang.data+json
* NOTE: If a retrieval request for a data resource representing a YANG leaf-
* list or list object identifies more than one instance, and XML
* encoding is used in the response, then an error response containing a

View file

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

View file

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