formalizing xmldb api
This commit is contained in:
parent
540cd96e74
commit
ee9b74d735
13 changed files with 252 additions and 166 deletions
|
|
@ -438,7 +438,7 @@ from_client_unlock(clicon_handle h,
|
|||
goto ok;
|
||||
}
|
||||
else{
|
||||
xmldb_unlock(h, db, pid);
|
||||
xmldb_unlock(h, db);
|
||||
if (cprintf(cbret, "<rpc-reply><ok/></rpc-reply>") < 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -496,7 +496,7 @@ from_client_kill_session(clicon_handle h,
|
|||
if (1 || (kill (pid, 0) != 0 && errno == ESRCH)){ /* Nothing there */
|
||||
/* clear from locks */
|
||||
if (xmldb_islocked(h, db) == pid)
|
||||
xmldb_unlock(h, db, pid);
|
||||
xmldb_unlock(h, db);
|
||||
}
|
||||
else{ /* failed to kill client */
|
||||
cprintf(cbret, "<rpc-reply><rpc-error>"
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@
|
|||
#include "backend_handle.h"
|
||||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#define BACKEND_OPTS "hD:f:d:Fzu:P:1IRCc:rg:pty:x:"
|
||||
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1IRCc:rg:py:x:"
|
||||
|
||||
/*! Terminate. Cannot use h after this */
|
||||
static int
|
||||
|
|
@ -129,6 +129,7 @@ usage(char *argv0, clicon_handle h)
|
|||
" -D <level>\tdebug\n"
|
||||
" -f <file>\tCLICON config file (mandatory)\n"
|
||||
" -d <dir>\tSpecify backend plugin directory (default: %s)\n"
|
||||
" -b <dir>\tSpecify XMLDB database directory\n"
|
||||
" -z\t\tKill other config daemon and exit\n"
|
||||
" -F\t\tforeground\n"
|
||||
" -1\t\tonce (dont wait for events)\n"
|
||||
|
|
@ -140,7 +141,6 @@ usage(char *argv0, clicon_handle h)
|
|||
" -c <file>\tLoad specified application config.\n"
|
||||
" -r\t\tReload running database\n"
|
||||
" -p \t\tPrint database yang specification\n"
|
||||
" -t \t\tPrint alternate spec translation (eg if YANG print KEY, if KEY print YANG)\n"
|
||||
" -g <group>\tClient membership required to this group (default: %s)\n"
|
||||
" -y <file>\tOverride yang spec file (dont include .yang suffix)\n"
|
||||
" -x <plugin>\tXMLDB plugin\n",
|
||||
|
|
@ -308,7 +308,6 @@ main(int argc, char **argv)
|
|||
clicon_handle h;
|
||||
int help = 0;
|
||||
int printspec = 0;
|
||||
int printalt = 0;
|
||||
int pid;
|
||||
char *pidfile;
|
||||
char *sock;
|
||||
|
|
@ -387,6 +386,11 @@ main(int argc, char **argv)
|
|||
usage(argv[0], h);
|
||||
clicon_option_str_set(h, "CLICON_BACKEND_DIR", optarg);
|
||||
break;
|
||||
case 'b': /* XMLDB database directory */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
clicon_option_str_set(h, "CLICON_XMLDB_DIR", optarg);
|
||||
break;
|
||||
case 'F' : /* foreground */
|
||||
foreground = 1;
|
||||
break;
|
||||
|
|
@ -425,9 +429,6 @@ main(int argc, char **argv)
|
|||
case 'p' : /* Print spec */
|
||||
printspec++;
|
||||
break;
|
||||
case 't' : /* Print alternative dbspec format (eg if YANG, print KEY) */
|
||||
printalt++;
|
||||
break;
|
||||
case 'y' :{ /* yang module */
|
||||
/* Set revision to NULL, extract dir and module */
|
||||
char *str = strdup(optarg);
|
||||
|
|
|
|||
|
|
@ -152,86 +152,19 @@ api_data_get_gen(clicon_handle h,
|
|||
int head)
|
||||
{
|
||||
int retval = -1;
|
||||
cg_var *cv;
|
||||
char *val;
|
||||
char *v;
|
||||
int i;
|
||||
cbuf *path = NULL;
|
||||
cbuf *path1 = NULL;
|
||||
cbuf *cbx = NULL;
|
||||
cxobj **vec = NULL;
|
||||
yang_spec *yspec;
|
||||
yang_stmt *y = NULL;
|
||||
yang_stmt *ykey;
|
||||
char *name;
|
||||
cvec *cvk = NULL; /* vector of index keys */
|
||||
cg_var *cvi;
|
||||
cxobj *xret = NULL;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((path = cbuf_new()) == NULL)
|
||||
goto done;
|
||||
if ((path1 = cbuf_new()) == NULL) /* without [] qualifiers */
|
||||
goto done;
|
||||
cv = NULL;
|
||||
cprintf(path1, "/");
|
||||
/* translate eg a/b=c -> a/[b=c] */
|
||||
for (i=pi; i<cvec_len(pcvec); i++){
|
||||
cv = cvec_i(pcvec, i);
|
||||
name = cv_name_get(cv);
|
||||
clicon_debug(1, "[%d] cvname:%s", i, name);
|
||||
clicon_debug(1, "cv2str%d", cv2str(cv, NULL, 0));
|
||||
if (i == pi){
|
||||
if ((y = yang_find_topnode(yspec, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", name);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else{
|
||||
assert(y!=NULL);
|
||||
if ((y = yang_find_syntax((yang_node*)y, name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "No yang node found: %s", name);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* Check if has value, means '=' */
|
||||
if (cv2str(cv, NULL, 0) > 0){
|
||||
if ((val = cv2str_dup(cv)) == NULL)
|
||||
goto done;
|
||||
v = val;
|
||||
/* XXX sync with yang */
|
||||
while((v=index(v, ',')) != NULL){
|
||||
*v = '\0';
|
||||
v++;
|
||||
}
|
||||
/* Find keys */
|
||||
if ((ykey = yang_find((yang_node*)y, Y_KEY, NULL)) == NULL){
|
||||
clicon_err(OE_XML, errno, "%s: List statement \"%s\" has no key",
|
||||
__FUNCTION__, y->ys_argument);
|
||||
notfound(r);
|
||||
goto done;
|
||||
}
|
||||
clicon_debug(1, "ykey:%s", ykey->ys_argument);
|
||||
|
||||
/* The value is a list of keys: <key>[ <key>]* */
|
||||
if ((cvk = yang_arg2cvec(ykey, " ")) == NULL)
|
||||
goto done;
|
||||
cvi = NULL;
|
||||
/* Iterate over individual yang keys */
|
||||
cprintf(path, "/%s", name);
|
||||
v = val;
|
||||
while ((cvi = cvec_each(cvk, cvi)) != NULL){
|
||||
cprintf(path, "[%s=%s]", cv_string_get(cvi), v);
|
||||
v += strlen(v)+1;
|
||||
}
|
||||
if (val)
|
||||
free(val);
|
||||
}
|
||||
else{
|
||||
cprintf(path, "%s%s", (i==pi?"":"/"), name);
|
||||
cprintf(path1, "/%s", name);
|
||||
}
|
||||
if (xml_apipath2xpath(yspec, pcvec, pi, path) < 0){
|
||||
notfound(r);
|
||||
goto done;
|
||||
}
|
||||
clicon_debug(1, "%s path:%s", __FUNCTION__, cbuf_get(path));
|
||||
if (clicon_rpc_get_config(h, "running", cbuf_get(path), &xret) < 0){
|
||||
|
|
@ -267,8 +200,6 @@ api_data_get_gen(clicon_handle h,
|
|||
cbuf_free(cbx);
|
||||
if (path)
|
||||
cbuf_free(path);
|
||||
if (path1)
|
||||
cbuf_free(path1);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
return retval;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue