xml config default; api_path_fmt2api_path cleanup

This commit is contained in:
Olof hagsand 2017-10-03 22:41:12 +02:00
parent e1b7ea8449
commit 5cea5fa768
10 changed files with 165 additions and 70 deletions

View file

@ -250,6 +250,7 @@ main(int argc, char **argv)
/* Initiate CLICON handle */
if ((h = cli_handle_init()) == NULL)
goto done;
if (cli_plugin_init(h) != 0)
goto done;
once = 0;
@ -486,7 +487,8 @@ main(int argc, char **argv)
// Gets in your face if we log on stderr
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clicon_log(LOG_NOTICE, "%s: %u Terminated\n", __PROGRAM__, getpid());
cli_terminate(h);
if (h)
cli_terminate(h);
return 0;
}

View file

@ -99,7 +99,8 @@ expand_dbvar(void *h,
cvec *helptexts)
{
int retval = -1;
char *api_path;
char *api_path_fmt;
char *api_path = NULL;
char *dbstr;
cxobj *xt = NULL;
char *xpath = NULL;
@ -145,13 +146,16 @@ expand_dbvar(void *h,
clicon_err(OE_PLUGIN, 0, "%s: Error when accessing argument <api_path>");
goto done;
}
api_path = cv_string_get(cv);
/* api_path = /interface/%s/address/%s
api_path_fmt = cv_string_get(cv);
/* api_path_fmt = /interface/%s/address/%s
--> ^/interface/eth0/address/.*$
--> /interface/[name=eth0]/address
*/
if (api_path_fmt2xpath(api_path, cvv, &xpath) < 0)
goto done;
if (api_path_fmt2xpath(api_path_fmt, cvv, &xpath) < 0)
goto done;
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0)
goto done;
/* XXX read whole configuration, why not send xpath? */
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
goto done;
@ -165,7 +169,7 @@ expand_dbvar(void *h,
if ((xtop = xml_new("config", NULL)) == NULL)
goto done;
xbot = xtop;
/* This is primarily to get "y", XXX xbot can be broken (contains =%s)
/* This is primarily to get "y",
* xpath2xml would have worked!!
*/
if (api_path && api_path2xml(api_path, yspec, xtop, 0, &xbot, &y) < 0)
@ -236,6 +240,8 @@ expand_dbvar(void *h,
}
retval = 0;
done:
if (api_path)
free(api_path);
if (xvec)
free(xvec);
if (xtop)

View file

@ -31,7 +31,7 @@ sudo /etc/init.d nginx start
Start clixon restconf daemon
```
olof@vandal> sudo su -c "/www-data/clixon_restconf -f /usr/local/etc/routing.conf " -s /bin/sh www-data
olof@vandal> sudo su -c "/www-data/clixon_restconf -f /usr/local/etc/routing.xml " -s /bin/sh www-data
```
Make restconf calls with curl
@ -67,7 +67,7 @@ curl -sX POST -d '{"interfaces":{"interface":{"name":"eth1","type":"eth","enable
Start the restconf fastcgi program with debug flag:
```
sudo su -c "/www-data/clixon_restconf -Df /usr/local/etc/routing.conf" -s /bin/sh www-data
sudo su -c "/www-data/clixon_restconf -Df /usr/local/etc/routing.xml" -s /bin/sh www-data
```
Look at syslog:
```

View file

@ -39,7 +39,7 @@
* sudo apt-get install libfcgi-dev
* gcc -o fastcgi fastcgi.c -lfcgi
* sudo su -c "/www-data/clixon_restconf -Df /usr/local/etc/routing.conf " -s /bin/sh www-data
* sudo su -c "/www-data/clixon_restconf -Df /usr/local/etc/routing.xml " -s /bin/sh www-data
* This is the interface:
* api/data/profile=<name>/metric=<name> PUT data:enable=<flag>

View file

@ -39,7 +39,7 @@
* sudo apt-get install libfcgi-dev
* gcc -o fastcgi fastcgi.c -lfcgi
* sudo su -c "/www-data/clixon_restconf -Df /usr/local/etc/routing.conf " -s /bin/sh www-data
* sudo su -c "/www-data/clixon_restconf -Df /usr/local/etc/routing.xml " -s /bin/sh www-data
* This is the interface:
* api/data/profile=<name>/metric=<name> PUT data:enable=<flag>