* Restconf stream notification support - two variants.

* Both a "native" stream support and one using nginx/nchan pub/sub.
  * See (apps/restconf/README.md) for details.
* clixon-config YAML file has new revision: 2018-10-21.
This commit is contained in:
Olof hagsand 2018-10-21 22:19:38 +02:00
parent a4e29bcdb7
commit 71eddeaa74
21 changed files with 811 additions and 144 deletions

View file

@ -75,6 +75,7 @@ struct event_data{
/*
* Internal variables
* XXX consider use handle variables instead of global
*/
static struct event_data *ee = NULL;
static struct event_data *ee_timers = NULL;
@ -86,7 +87,7 @@ static int _clicon_exit = 0;
/*! For signal handlers: instead of doing exit, set a global variable to exit
* Status is then checked in event_loop.
* Note it maybe would be better to do use on a handle basis, bit a signal
* Note it maybe would be better to do use on a handle basis, but a signal
* handler is global
*/
int
@ -96,6 +97,15 @@ clicon_exit_set(void)
return 0;
}
/*! Set exit to 0
*/
int
clicon_exit_reset(void)
{
_clicon_exit = 0;
return 0;
}
/*! Get the status of global exit variable, usually set by signal handlers
*/
int
@ -274,6 +284,8 @@ event_poll(int fd)
/*! Dispatch file descriptor events (and timeouts) by invoking callbacks.
* There is an issue with fairness that timeouts may take over all events
* One could try to poll the file descriptors after a timeout?
* @retval 0 OK
* @retval -1 Error: eg select, callback, timer,
*/
int
event_loop(void)

View file

@ -151,8 +151,14 @@ clicon_rpc_msg(clicon_handle h,
* Want to go over to use netconf directly between client and server,...
* @param[in] h clicon handle
* @param[in] xmlstr XML netconf tree as string
* @param[out] xret Return XML netconf tree, error or OK
* @param[out] xret Return XML netconf tree, error or OK (need to be freed)
* @param[out] sp Socket pointer for notification, otherwise NULL
* @code
* cxobj *xret = NULL;
* if (clicon_rpc_netconf(h, "<rpc></rpc>", &xret, NULL) < 0)
* err;
* xml_free(xret);
* @endcode
* @see clicon_rpc_netconf_xml xml as tree instead of string
*/
int
@ -181,6 +187,14 @@ clicon_rpc_netconf(clicon_handle h,
* @param[in] xml XML netconf tree
* @param[out] xret Return XML netconf tree, error or OK
* @param[out] sp Socket pointer for notification, otherwise NULL
* @code
* cxobj *xret = NULL;
* int s;
* if (clicon_rpc_netconf_xml(h, x, &xret, &s) < 0)
* err;
* xml_free(xret);
* @endcode
* @see clicon_rpc_netconf xml as string instead of tree
*/
int

View file

@ -149,6 +149,7 @@ stream_get_xml(clicon_handle h,
{
event_stream_t *es = NULL;
char *url_prefix;
char *stream_path;
cprintf(cb, "<streams>");
for (es=clicon_stream(h); es; es=es->es_next){
@ -160,9 +161,10 @@ stream_get_xml(clicon_handle h,
if (access){
cprintf(cb, "<access>");
cprintf(cb, "<encoding>xml</encoding>");
url_prefix = clicon_option_str(h, "CLICON_STREAM_URL_PREFIX");
cprintf(cb, "<location>%s/%s</location>",
url_prefix, es->es_name);
url_prefix = clicon_option_str(h, "CLICON_STREAM_URL");
stream_path = clicon_option_str(h, "CLICON_STREAM_PATH");
cprintf(cb, "<location>%s/%s/%s</location>",
url_prefix, stream_path, es->es_name);
cprintf(cb, "</access>");
}
cprintf(cb, "</stream>");
@ -190,8 +192,7 @@ stream_del()
* @param[in] fn Callback when event occurs
* @param[in] arg Argument to use with callback. Also handle when deleting
* @retval 0 OK
* @retval -1 Error
* XXX: from subscription_add and client_subscription_add
* @retval -1 Error, ie no such stream
*/
int
stream_cb_add(clicon_handle h,
@ -502,8 +503,8 @@ stream_publish_cb(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if ((pub_prefix = clicon_option_str(h, "CLICON_STREAM_PUB_PREFIX")) == NULL){
clicon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB_PREFIX not defined");
if ((pub_prefix = clicon_option_str(h, "CLICON_STREAM_PUB")) == NULL){
clicon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined");
goto done;
}