Low-level message functions added descr argument for better logging C-API change

This commit is contained in:
Olof hagsand 2023-09-11 18:48:20 +02:00
parent 17b64f0bab
commit 9091582087
16 changed files with 397 additions and 236 deletions

View file

@ -86,11 +86,13 @@ struct clixon_client_handle{
uint32_t cch_magic; /* magic number */
clixon_client_type cch_type; /* Clixon socket type */
int cch_socket; /* Input/output socket */
char *cch_descr; /* Description of socket / peer for logging XXX NYI */
int cch_pid; /* Sub-process-id Only applies for NETCONF/SSH */
int cch_locked; /* State variable: 1 means locked */
};
/*! Check struct magic number for sanity checks
*
* @param[in] h Clicon client handle
* @retval 0 Sanity check OK
* @retval -1 Sanity check failed
@ -105,9 +107,10 @@ clixon_client_handle_check(clixon_client_handle ch)
}
/*! Initialize Clixon client API
*
* @param[in] config_file Clixon configuration file, or NULL for default
* @retval h Clixon handler
* @retval NULL Error
* @retval h Clixon handler
* @retval NULL Error
* @see clixon_client_close
*/
clixon_handle
@ -129,6 +132,7 @@ clixon_client_init(const char *config_file)
}
/*! Deallocate everything from client_init
*
* @param[in] h Clixon handle
* @see clixon_client_init
*/
@ -141,14 +145,17 @@ clixon_client_terminate(clicon_handle h)
}
/*! Send a lock request (internal)
*
* @param[in] sock Open socket
* @param[in] descr Description of peer for logging
* @param[in] lock 0: unlock, 1: lock
* @param[in] db Datastore name
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_lock(int sock,
const char *descr,
const int lock,
const char *db)
{
@ -177,7 +184,7 @@ clixon_client_lock(int sock,
NETCONF_BASE_NAMESPACE,
NETCONF_MESSAGE_ID_ATTR,
lock?"":"un", db, lock?"":"un");
if (clicon_rpc1(sock, msg, msgret, &eof) < 0)
if (clicon_rpc1(sock, descr, msg, msgret, &eof) < 0)
goto done;
if (eof){
close(sock);
@ -205,14 +212,16 @@ clixon_client_lock(int sock,
/*! Internal function to construct the encoding and hello message
*
* @param[in] sock Socket to netconf server
* @param[in] version Netconf version for capability announcement
* @retval 0 OK
* @retval -1 Error
* @param[in] sock Socket to netconf server
* @param[in] descr Description of peer for logging
* @param[in] version Netconf version for capability announcement
* @retval 0 OK
* @retval -1 Error
*/
int
clixon_client_hello(int sock,
int version)
clixon_client_hello(int sock,
const char *descr,
int version)
{
int retval = -1;
cbuf *msg = NULL;
@ -229,7 +238,7 @@ clixon_client_hello(int sock,
cprintf(msg, "</capabilities>");
cprintf(msg, "</hello>");
cprintf(msg, "]]>]]>");
if (clicon_msg_send1(sock, msg) < 0)
if (clicon_msg_send1(sock, descr, msg) < 0)
goto done;
retval = 0;
done:
@ -331,6 +340,7 @@ clixon_client_connect_ssh(clicon_handle h,
}
/*! Connect client to clixon backend according to config and return a socket
*
* @param[in] h Clixon handle
* @param[in] socktype Type of socket, internal/external/netconf/ssh
* @param[in] dest Destination for some types
@ -384,14 +394,17 @@ clixon_client_connect(clicon_handle h,
}
/*! Connect client to clixon backend according to config and return a socket
* @param[in] ch Clixon client session handle
*
* @param[in] ch Clixon client session handle
* @retval 0 OK
* @retval -1 Error
* @see clixon_client_connect where the handle is created
* The handle is deallocated
*/
int
clixon_client_disconnect(clixon_client_handle ch)
{
int retval = -1;
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
clicon_debug(1, "%s", __FUNCTION__);
@ -421,9 +434,10 @@ clixon_client_disconnect(clixon_client_handle ch)
}
/*! Get the bottom-most leaf in an xml tree being a result of xpath
* @param[in] xtop Pointer to XML top-of-tree
* @param[out] xbotp Pointer to XML bottom node
* @retval 0 OK
*
* @param[in] xtop Pointer to XML top-of-tree
* @param[out] xbotp Pointer to XML bottom node
* @retval 0 OK
*/
static int
clixon_xml_bottom(cxobj *xtop,
@ -456,15 +470,17 @@ clixon_xml_bottom(cxobj *xtop,
/*! Internal function to construct a get-config and query a value from the backend
*
* @param[in] sock Socket
* @param[in] descr Description of peer for logging
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[out] xdata XML data tree (may or may not include the intended data)
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
* @note configurable netconf framing type, now hardwired to 0
*/
static int
clixon_client_get_xdata(int sock,
const char *descr,
const char *namespace,
const char *xpath,
cxobj **xdata)
@ -506,9 +522,9 @@ clixon_client_get_xdata(int sock,
cprintf(msg, "</get-config></rpc>");
if (netconf_output_encap(0, msg) < 0) // XXX configurable session
goto done;
if (clicon_msg_send1(sock, msg) < 0)
if (clicon_msg_send1(sock, descr, msg) < 0)
goto done;
if (clicon_msg_rcv1(sock, msgret, &eof) < 0)
if (clicon_msg_rcv1(sock, descr, msgret, &eof) < 0)
goto done;
if (eof){
close(sock);
@ -544,15 +560,18 @@ clixon_client_get_xdata(int sock,
}
/*! Generic get value of body
*
* @param[in] sock Open socket
* @param[in] descr Description of peer for logging
* @param[in] namespace Default namespace used for non-prefixed entries in xpath.
* @param[in] xpath XPath
* @param[out] val Output value
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
static int
clixon_client_get_body_val(int sock,
const char *descr,
const char *namespace,
const char *xpath,
char **val)
@ -566,7 +585,7 @@ clixon_client_get_body_val(int sock,
clicon_err(OE_XML, EINVAL, "Expected val");
goto done;
}
if (clixon_client_get_xdata(sock, namespace, xpath, &xdata) < 0)
if (clixon_client_get_xdata(sock, descr, namespace, xpath, &xdata) < 0)
goto done;
if (xdata == NULL){
clicon_err(OE_XML, EINVAL, "No xml obj found");
@ -591,12 +610,13 @@ clixon_client_get_body_val(int sock,
}
/*! Client-api get boolean
* @param[in] ch Clixon client handle
* @param[out] rval Return value
*
* @param[in] ch Clixon client handle
* @param[out] rval Return value
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[in] xpath XPath
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_get_bool(clixon_client_handle ch,
@ -612,7 +632,7 @@ clixon_client_get_bool(clixon_client_handle ch,
uint8_t val0=0;
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
if ((ret = parse_bool(val, &val0, &reason)) < 0){
@ -632,13 +652,14 @@ clixon_client_get_bool(clixon_client_handle ch,
}
/*! Client-api get string
* @param[in] ch Clixon client handle
* @param[out] rval Return value string
* @param[in] n Length of string
*
* @param[in] ch Clixon client handle
* @param[out] rval Return value string
* @param[in] n Length of string
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[in] xpath XPath
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_get_str(clixon_client_handle ch,
@ -652,7 +673,7 @@ clixon_client_get_str(clixon_client_handle ch,
char *val = NULL;
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
strncpy(rval, val, n-1);
@ -663,12 +684,13 @@ clixon_client_get_str(clixon_client_handle ch,
}
/*! Client-api get uint8
* @param[in] ch Clixon client handle
* @param[out] rval Return value
*
* @param[in] ch Clixon client handle
* @param[out] rval Return value
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[in] xpath XPath
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_get_uint8(clixon_client_handle ch,
@ -683,7 +705,7 @@ clixon_client_get_uint8(clixon_client_handle ch,
int ret;
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
if ((ret = parse_uint8(val, rval, &reason)) < 0){
@ -702,12 +724,13 @@ clixon_client_get_uint8(clixon_client_handle ch,
}
/*! Client-api get uint16
* @param[in] ch Clixon client handle
* @param[out] rval Return value
*
* @param[in] ch Clixon client handle
* @param[out] rval Return value
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[in] xpath XPath
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_get_uint16(clixon_client_handle ch,
@ -722,7 +745,7 @@ clixon_client_get_uint16(clixon_client_handle ch,
int ret;
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
if ((ret = parse_uint16(val, rval, &reason)) < 0){
@ -741,12 +764,13 @@ clixon_client_get_uint16(clixon_client_handle ch,
}
/*! Client-api get uint32
* @param[in] ch Clixon client handle
* @param[out] rval Return value
*
* @param[in] ch Clixon client handle
* @param[out] rval Return value
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[in] xpath XPath
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_get_uint32(clixon_client_handle ch,
@ -761,7 +785,7 @@ clixon_client_get_uint32(clixon_client_handle ch,
int ret;
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
if (val == NULL){
@ -785,12 +809,13 @@ clixon_client_get_uint32(clixon_client_handle ch,
}
/*! Client-api get uint64
* @param[in] ch Clixon client handle
* @param[out] rval Return value
*
* @param[in] ch Clixon client handle
* @param[out] rval Return value
* @param[in] namespace Default namespace used for non-prefixed entries in xpath. (Alt use nsc)
* @param[in] xpath XPath
* @param[in] xpath XPath
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
clixon_client_get_uint64(clixon_client_handle ch,
@ -805,7 +830,7 @@ clixon_client_get_uint64(clixon_client_handle ch,
int ret;
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket,
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
if ((ret = parse_uint64(val, rval, &reason)) < 0){
@ -825,6 +850,7 @@ clixon_client_get_uint64(clixon_client_handle ch,
/* Access functions */
/*! Client-api get uint64
*
* @param[in] ch Clixon client handle
* @retval s Open socket
* @retval -1 No/closed socket

View file

@ -100,6 +100,7 @@ static struct formatvec _FORMATS[] = {
};
/*! Translate from numeric format to string representation
*
* @param[in] showas Format value (see enum format_enum)
* @retval str String value
*/
@ -115,6 +116,7 @@ format_int2str(enum format_enum showas)
}
/*! Translate from string to numeric format representation
*
* @param[in] str String value
* @retval enum Format value (see enum format_enum)
*/
@ -130,10 +132,11 @@ format_str2int(char *str)
}
/*! Encode a clicon netconf message using variable argument lists
*
* @param[in] id Session id of client
* @param[in] format Variable agrument list format an XML netconf string
* @retval NULL Error
* @retval msg Clicon message to send to eg clicon_msg_send()
* @retval NULL Error
* @note if format includes %, they will be expanded according to printf rules.
* if this is a problem, use ("%s", xml) instaead of (xml)
* Notaly this may an issue of RFC 3896 encoded strings
@ -171,7 +174,8 @@ clicon_msg_encode(uint32_t id,
}
/*! Decode a clicon netconf message
* @param[in] msg CLICON msg
*
* @param[in] msg Clixon msg
* @param[in] yspec Yang specification, (can be NULL)
* @param[out] id Session id
* @param[out] xml XML parse tree
@ -211,10 +215,11 @@ clicon_msg_decode(struct clicon_msg *msg,
}
/*! Open local connection using unix domain sockets
*
* @param[in] h Clicon handle
* @param[in] sockpath Unix domain file path
* @retval s socket
* @retval -1 error
* @retval s Socket
* @retval -1 Error
*/
int
clicon_connect_unix(clicon_handle h,
@ -255,6 +260,7 @@ atomicio_sig_handler(int arg)
}
/*! Ensure all of data on socket comes through. fn is either read or write
*
* @param[in] fn I/O function, ie read/write
* @param[in] fd File descriptor, eg socket
* @param[in] s0 Buffer to read to or write from
@ -339,21 +345,29 @@ msg_hex(int dbglevel,
return retval;
}
/*! Send a CLICON netconf message using internal IPC message
/*! Send a Clixon netconf message using internal IPC message
*
* @param[in] s socket (unix or inet) to communicate with backend
* @param[out] msg CLICON msg data reply structure. Free with free()
* @param[in] s Socket (unix or inet) to communicate with backend
* @param[in] descr Description of peer for logging
* @param[in] msg Clixon msg data reply structure
* @retval 0 OK
* @retval -1 Error
* @see clicon_msg_send1 using plain NETCONF
*/
int
clicon_msg_send(int s,
const char *descr,
struct clicon_msg *msg)
{
int retval = -1;
int e;
clicon_debug(CLIXON_DBG_DETAIL, "%s: send msg len=%d", __FUNCTION__, ntohl(msg->op_len));
clicon_debug(CLIXON_DBG_MSG, "Send: %s", msg->op_body);
if (descr)
clicon_debug(CLIXON_DBG_MSG, "Send [%s]: %s", descr, msg->op_body);
else{
clicon_debug(CLIXON_DBG_MSG, "Send: %s", msg->op_body);
}
msg_hex(CLIXON_DBG_EXTRA, (char*)msg, ntohl(msg->op_len), __FUNCTION__);
if (atomicio((ssize_t (*)(int, void *, size_t))write,
s, msg, ntohl(msg->op_len)) < 0){
@ -368,7 +382,7 @@ clicon_msg_send(int s,
return retval;
}
/*! Receive a CLICON message using IPC message struct
/*! Receive a Clixon message using IPC message struct
*
* XXX: timeout? and signals?
* There is rudimentary code for turning on signals and handling them
@ -378,27 +392,29 @@ clicon_msg_send(int s,
* behaviour.
* Now, ^C will interrupt the whole process, and this may not be what you want.
*
* @param[in] s socket (unix or inet) to communicate with backend
* @param[in] intr If set, make a ^C cause an error
* @param[out] msg CLICON msg data reply structure. Free with free()
* @param[out] eof Set if eof encountered
* @retval 0 OK
* @retval -1 Error
* @param[in] s Socket (unix or inet) to communicate with backend
* @param[in] descr Description of peer for logging
* @param[in] intr If set, make a ^C cause an error
* @param[out] msg Clixon msg data reply structure. Free with free()
* @param[out] eof Set if eof encountered
* @retval 0 OK
* @retval -1 Error
* Note: caller must ensure that s is closed if eof is set after call.
* @see clicon_msg_rcv1 using plain NETCONF
*/
int
clicon_msg_rcv(int s,
int intr,
clicon_msg_rcv(int s,
const char *descr,
int intr,
struct clicon_msg **msg,
int *eof)
{
int retval = -1;
int retval = -1;
struct clicon_msg hdr;
int hlen;
ssize_t len2;
sigfn_t oldhandler;
uint32_t mlen;
int hlen;
ssize_t len2;
sigfn_t oldhandler;
uint32_t mlen;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
*eof = 0;
@ -453,7 +469,10 @@ clicon_msg_rcv(int s,
*eof = 1;
goto ok;
}
clicon_debug(CLIXON_DBG_MSG, "Recv: %s", (*msg)->op_body);
if (descr)
clicon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, (*msg)->op_body);
else
clicon_debug(CLIXON_DBG_MSG, "Recv: %s", (*msg)->op_body);
ok:
retval = 0;
done:
@ -468,16 +487,20 @@ clicon_msg_rcv(int s,
/*! Receive a message using plain NETCONF
*
* @param[in] s socket (unix or inet) to communicate with backend
* @param[in] descr Description of peer for logging
* @param[out] cb cligen buf struct containing the incoming message
* @param[out] eof Set if eof encountered
* @retval 0 OK
* @retval -1 Error
* @see netconf_input_cb()
* @see clicon_msg_rcv using IPC message struct
* @note only NETCONF version 1.0 EOM framing
*/
int
clicon_msg_rcv1(int s,
cbuf *cb,
int *eof)
clicon_msg_rcv1(int s,
const char *descr,
cbuf *cb,
int *eof)
{
int retval = -1;
unsigned char buf[BUFSIZ];
@ -523,27 +546,37 @@ clicon_msg_rcv1(int s,
break; /* No data to read */
} /* while */
ok:
clicon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cb));
if (descr)
clicon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, cbuf_get(cb));
else
clicon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cb));
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s done", __FUNCTION__);
return retval;
}
/*! Send a CLICON netconf message plain NETCONF
/*! Send a Clixon netconf message plain NETCONF
*
* @param[in] s socket (unix or inet) to communicate with backend
* @param[out] msg CLICON msg data reply structure. Free with free()
* @param[in] s socket (unix or inet) to communicate with backend
* @param[in] cb data buffer including NETCONF
* @param[in] descr Description of peer for logging
* @retval 0 OK
* @retval -1 Error
* @see clicon_msg_send using internal IPC header
*/
int
clicon_msg_send1(int s,
cbuf *cb)
clicon_msg_send1(int s,
const char *descr,
cbuf *cb)
{
int retval = -1;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clicon_debug(CLIXON_DBG_MSG, "Send: %s", cbuf_get(cb));
if (descr)
clicon_debug(CLIXON_DBG_MSG, "Send [%s]: %s", descr, cbuf_get(cb));
else
clicon_debug(CLIXON_DBG_MSG, "Send: %s", cbuf_get(cb));
if (atomicio((ssize_t (*)(int, void *, size_t))write,
s, cbuf_get(cb), cbuf_len(cb)) < 0){
clicon_err(OE_CFG, errno, "atomicio");
@ -557,19 +590,19 @@ clicon_msg_send1(int s,
/*! Connect to server, send a clicon_msg message and wait for result using unix socket
*
* @param[in] h Clicon handle
* @param[in] msg CLICON msg data structure. It has fixed header and variable body.
* @param[in] h Clicon handle
* @param[in] msg Internal msg data structure. It has fixed header and variable body.
* @param[in] sockpath Unix domain file path
* @param[out] retdata Returned data as string netconf xml tree.
* @param[out] sock0 Return socket in case of asynchronous notify
* @retval 0 OK
* @retval -1 Error
* @param[out] sock0 Return socket in case of asynchronous notify
* @retval 0 OK
* @retval -1 Error
* @see clicon_rpc But this is one-shot rpc: open, send, get reply and close.
*/
int
clicon_rpc_connect_unix(clicon_handle h,
char *sockpath,
int *sock0)
clicon_rpc_connect_unix(clicon_handle h,
char *sockpath,
int *sock0)
{
int retval = -1;
int s = -1;
@ -602,10 +635,10 @@ clicon_rpc_connect_unix(clicon_handle h,
* @param[in] h Clicon handle (not used)
* @param[in] dst IPv4 address
* @param[in] port TCP port
* @param[out] retdata Returned data as string netconf xml tree.
* @param[out] retdata Returned data as string netconf xml tree.
* @param[out] sock0 Return socket in case of asynchronous notify
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
* @see clicon_rpc But this is one-shot rpc: open, send, get reply and close.
*/
int
@ -652,16 +685,18 @@ clicon_rpc_connect_inet(clicon_handle h,
* errno set to ENOTCONN/ESHUTDOWN which means that socket is now closed probably
* due to remote peer disconnecting. The caller may have to do something,...
*
* @param[in] sock Socket / file descriptor
* @param[in] msg CLICON msg data structure. It has fixed header and variable body.
* @param[out] xret Returned data as netconf xml tree.
* @param[out] eof Set if eof encountered
* @retval 0 OK (check eof)
* @retval -1 Error
* @param[in] sock Socket / file descriptor
* @param[in] descr Description of peer for logging
* @param[in] msg Clixon msg data structure. It has fixed header and variable body.
* @param[out] xret Returned data as netconf xml tree.
* @param[out] eof Set if eof encountered
* @retval 0 OK (check eof)
* @retval -1 Error
* @see clicon_rpc1 using plain NETCONF XML
*/
int
clicon_rpc(int sock,
const char *descr,
struct clicon_msg *msg,
char **ret,
int *eof)
@ -671,9 +706,9 @@ clicon_rpc(int sock,
char *data = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (clicon_msg_send(sock, msg) < 0)
if (clicon_msg_send(sock, descr, msg) < 0)
goto done;
if (clicon_msg_rcv(sock, 0, &reply, eof) < 0)
if (clicon_msg_rcv(sock, descr, 0, &reply, eof) < 0)
goto done;
if (*eof)
goto ok;
@ -695,20 +730,21 @@ clicon_rpc(int sock,
/*! Send a netconf message and recieve result using plain NETCONF
*
* This is mainly used by the client API.
*
* @param[in] sock Socket / file descriptor
* @param[in] msgin CLICON msg data structure. It has fixed header and variable body.
* @param[in] descr Description of peer for logging
* @param[in] msgin Clixon msg data structure. It has fixed header and variable body.
* @param[out] msgret Returned data as netconf xml tree.
* @param[out] eof Set if eof encountered
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
* @see clicon_rpc using clicon_msg protocol header
*/
int
clicon_rpc1(int sock,
cbuf *msg,
cbuf *msgret,
int *eof)
clicon_rpc1(int sock,
const char *descr,
cbuf *msg,
cbuf *msgret,
int *eof)
{
int retval = -1;
@ -717,9 +753,9 @@ clicon_rpc1(int sock,
goto done;
if (netconf_framing_postamble(NETCONF_SSH_CHUNKED, msg) < 0)
goto done;
if (clicon_msg_send1(sock, msg) < 0)
if (clicon_msg_send1(sock, descr, msg) < 0)
goto done;
if (clicon_msg_rcv1(sock, msgret, eof) < 0)
if (clicon_msg_rcv1(sock, descr, msgret, eof) < 0)
goto done;
retval = 0;
done:
@ -730,15 +766,17 @@ clicon_rpc1(int sock,
/*! Send a clicon_msg message as reply to a clicon rpc request
*
* @param[in] s Socket to communicate with client
* @param[in] descr Description of peer for logging
* @param[in] data Returned data as byte-string.
* @param[in] datalen Length of returned data XXX may be unecessary if always string?
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
send_msg_reply(int s,
char *data,
uint32_t datalen)
send_msg_reply(int s,
const char *descr,
char *data,
uint32_t datalen)
{
int retval = -1;
struct clicon_msg *reply = NULL;
@ -751,7 +789,7 @@ send_msg_reply(int s,
reply->op_len = htonl(len);
if (datalen > 0)
memcpy(reply->op_body, data, datalen);
if (clicon_msg_send(s, reply) < 0)
if (clicon_msg_send(s, descr, reply) < 0)
goto done;
retval = 0;
done:
@ -763,22 +801,24 @@ send_msg_reply(int s,
/*! Send a clicon_msg NOTIFY message asynchronously to client
*
* @param[in] s Socket to communicate with client
* @param[in] descr Description of peer for logging
* @param[in] level
* @param[in] event
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
* @see send_msg_notify_xml
*/
static int
send_msg_notify(int s,
char *event)
send_msg_notify(int s,
const char *descr,
char *event)
{
int retval = -1;
struct clicon_msg *msg = NULL;
if ((msg=clicon_msg_encode(0, "%s", event)) == NULL)
goto done;
if (clicon_msg_send(s, msg) < 0)
if (clicon_msg_send(s, descr, msg) < 0)
goto done;
retval = 0;
done:
@ -789,16 +829,18 @@ send_msg_notify(int s,
/*! Send a clicon_msg NOTIFY message asynchronously to client
*
* @param[in] h Clicon handle
* @param[in] s Socket to communicate with client
* @param[in] xev Event as XML
* @retval 0 OK
* @retval -1 Error
* @param[in] h Clicon handle
* @param[in] s Socket to communicate with client
* @param[in] descr Description of peer for logging
* @param[in] xev Event as XML
* @retval 0 OK
* @retval -1 Error
* @see send_msg_notify
*/
int
send_msg_notify_xml(clicon_handle h,
int s,
const char *descr,
cxobj *xev)
{
int retval = -1;
@ -810,7 +852,7 @@ send_msg_notify_xml(clicon_handle h,
}
if (clixon_xml2cbuf(cb, xev, 0, 0, NULL, -1, 0) < 0)
goto done;
if (send_msg_notify(s, cbuf_get(cb)) < 0)
if (send_msg_notify(s, descr, cbuf_get(cb)) < 0)
goto done;
retval = 0;
done:
@ -821,11 +863,12 @@ send_msg_notify_xml(clicon_handle h,
}
/*! Look for a text pattern in an input string, one char at a time
*
* @param[in] tag What to look for
* @param[in] ch New input character
* @param[in,out] state A state integer holding how far we have parsed.
* @retval 0 No, we havent detected end tag
* @retval 1 Yes, we have detected end tag!
* @retval 0 No, we havent detected end tag
* @code
* int state = 0;
* char ch;

View file

@ -168,7 +168,7 @@ clicon_rpc_msg_once(clicon_handle h,
}
else if (clicon_rpc_connect(h, &s) < 0)
goto done;
if (clicon_rpc(s, msg, retdata, eof) < 0){
if (clicon_rpc(s, clicon_sock_str(h), msg, retdata, eof) < 0){
/* 2. check socket shutdown AFTER rpc */
close(s);
s = -1;
@ -184,7 +184,7 @@ clicon_rpc_msg_once(clicon_handle h,
/*! Send internal netconf rpc from client to backend
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] msg Encoded message. Deallocate with free
* @param[out] xret0 Return value from backend as xml tree. Free w xml_free
* @retval 0 OK
@ -263,13 +263,13 @@ clicon_rpc_msg(clicon_handle h,
/*! Send internal netconf rpc from client to backend and return a persistent socket
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] msg Encoded message. Deallocate with free
* @param[out] xret0 Return value from backend as xml tree. Free w xml_free
* @param[out] sock0 If pointer exists, do not close socket to backend on success
* and return it here. For keeping a notify socket open
* @retval 0 OK
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
* @note xret is populated with yangspec according to standard handle yangspec
*/
int
@ -364,6 +364,7 @@ session_id_check(clicon_handle h,
}
/*! Generic xml netconf clicon rpc for persistent
*
* 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
@ -484,7 +485,7 @@ clicon_rpc_netconf_xml(clicon_handle h,
/*! Get database configuration
*
* Same as clicon_proto_change just with a cvec instead of lvec
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] username If NULL, use default
* @param[in] db Name of database
* @param[in] xpath XPath (or "")
@ -492,8 +493,8 @@ clicon_rpc_netconf_xml(clicon_handle h,
* @param[in] defaults Value of the with-defaults mode, rfc6243, or NULL
* @param[out] xt XML tree. Free with xml_free.
* Either <config> or <rpc-error>.
* @retval 0 OK
* @retval -1 Error, fatal or xml
* @retval 0 OK
* @retval -1 Error, fatal or xml
* @code
* cxobj *xt = NULL;
* cvec *nsc = NULL;
@ -619,7 +620,7 @@ clicon_rpc_get_config(clicon_handle h,
/*! Send database entries as XML to backend daemon
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] db Name of database
* @param[in] op Operation on database item: OP_MERGE, OP_REPLACE
* @param[in] xml XML string. Ex: <config><a>..</a><b>...</b></config>
@ -688,11 +689,11 @@ clicon_rpc_edit_config(clicon_handle h,
*
* Note this assumes the backend can access these files and (usually) assumes
* clients and servers have the access to the same filesystem.
* @param[in] h CLICON handle
* @param[in] db1 src database, eg "running"
* @param[in] db2 dst database, eg "startup"
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @param[in] h Clixon handle
* @param[in] db1 src database, eg "running"
* @param[in] db2 dst database, eg "startup"
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @code
* if (clicon_rpc_copy_config(h, "running", "startup") < 0)
* err;
@ -748,10 +749,10 @@ clicon_rpc_copy_config(clicon_handle h,
/*! Send a request to backend to delete a config database
*
* @param[in] h CLICON handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @param[in] h Clixon handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @code
* if (clicon_rpc_delete_config(h, "startup") < 0)
* err;
@ -805,10 +806,11 @@ clicon_rpc_delete_config(clicon_handle h,
}
/*! Lock a database
* @param[in] h CLICON handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
*
* @param[in] h Clixon handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_lock(clicon_handle h,
@ -858,10 +860,11 @@ clicon_rpc_lock(clicon_handle h,
}
/*! Unlock a database
* @param[in] h CLICON handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
*
* @param[in] h Clixon handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_unlock(clicon_handle h,
@ -911,6 +914,7 @@ clicon_rpc_unlock(clicon_handle h,
}
/*! Get database configuration and state data
*
* @param[in] h Clicon handle
* @param[in] xpath XPath in a filter stmt (or NULL/"" for no filter)
* @param[in] namespace Namespace associated w xpath
@ -1073,15 +1077,15 @@ clicon_rpc_get(clicon_handle h,
* @param[in] content Clixon extension: all, config, noconfig. -1 means all
* @param[in] depth Nr of XML levels to get, -1 is all, 0 is none
* @param[in] defaults Value of the with-defaults mode, rfc6243, or NULL
* @param[in] offset uint32, 0 means none
* @param[in] limit uint32, 0 means unbounded
* @param[in] offset 0 means none
* @param[in] limit 0 means unbounded
* @param[in] direction Collection/clixon extension
* @param[in] sort Collection/clixon extension
* @param[in] where Collection/clixon extension
* @param[out] xt XML tree. Free with xml_free.
* Either <config> or <rpc-error>.
* @retval 0 OK
* @retval -1 Error, fatal or xml
* @retval 0 OK
* @retval -1 Error, fatal or xml
* @see clicon_rpc_get
* @see draft-ietf-netconf-restconf-collection-00
* @note the netconf return message is yang populated, as well as the return data
@ -1232,7 +1236,7 @@ clicon_rpc_get_pageable_list(clicon_handle h,
/*! Send a close a netconf user session. Socket is also closed if still open
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error and logged to syslog
* Session is implicitly created in eg clicon_rpc_netconf
@ -1291,7 +1295,7 @@ clicon_rpc_close_session(clicon_handle h)
/*! Kill other user sessions
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] session_id Session id of other user session
* @retval 0 OK
* @retval -1 Error and logged to syslog
@ -1345,7 +1349,7 @@ clicon_rpc_kill_session(clicon_handle h,
/*! Send validate request to backend daemon
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] db Name of database
* @retval 1 OK
* @retval 0 Invalid, netconf error return, and logged to syslog
@ -1402,7 +1406,7 @@ clicon_rpc_validate(clicon_handle h,
/*! Commit changes send a commit request to backend daemon
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] confirmed If set, send commit/confirmed
* @param[in] cancel If set, send cancel-commit
* @param[in] timeout For confirmed, a timeout in seconds (default 600s)
@ -1515,7 +1519,7 @@ clicon_rpc_commit(clicon_handle h,
/*! Discard all changes in candidate / revert to running
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
@ -1632,7 +1636,7 @@ clicon_rpc_create_subscription(clicon_handle h,
/*! Send a debug request to backend server
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] level Debug level
* @retval 0 OK
* @retval -1 Error and logged to syslog
@ -1690,7 +1694,8 @@ clicon_rpc_debug(clicon_handle h,
}
/*! Send a debug request to backend server to set restconf debug
* @param[in] h CLICON handle
*
* @param[in] h Clixon handle
* @param[in] level Debug level
* @retval 0 OK
* @retval -1 Error and logged to syslog
@ -1846,7 +1851,7 @@ clicon_hello_req(clicon_handle h,
/*! Send a restart plugin request to backend server
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] level Debug level
* @retval 0 OK
* @retval -1 Error and logged to syslog

View file

@ -91,6 +91,7 @@
#define STREAM_TIMER_TIMEOUT_S 5
/*! Find an event notification stream given name
*
* @param[in] h Clicon handle
* @param[in] name Name of stream
* @retval es Event notification stream structure
@ -114,6 +115,7 @@ stream_find(clicon_handle h,
}
/*! Add notification event stream
*
* @param[in] h Clicon handle
* @param[in] name Name of stream
* @param[in] description Description of stream
@ -156,6 +158,7 @@ stream_add(clicon_handle h,
}
/*! Delete complete notification event stream list (not just single stream)
*
* @param[in] h Clicon handle
* @param[in] force Force deletion of
*/
@ -189,11 +192,12 @@ stream_delete_all(clicon_handle h,
}
/*! Return stream definition state in XML supporting RFC 8040 and RFC5277
*
* @param[in] h Clicon handle
* @param[in] access If set, include access/location
* @param[out] cb Output buffer containing XML on exit
* @retval 0 OK
* @retval -1 Error
* @retval -1 Error
*/
int
stream_get_xml(clicon_handle h,
@ -231,6 +235,7 @@ stream_get_xml(clicon_handle h,
}
/*! Check all stream subscription stop timers, set up new timer
*
* @param[in] fd No-op
* @param[in] arg Clicon handle
* @note format is given by clixon_event_reg_timeout callback function (fd not needed)
@ -320,6 +325,7 @@ stream_del()
#endif
/*! Add an event notification callback to a stream given a callback function
*
* @param[in] h Clicon handle
* @param[in] stream Name of stream
* @param[in] xpath Filter selector - xpath
@ -328,7 +334,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, ie no such stream
* @retval -1 Error, ie no such stream
*/
struct stream_subscription *
stream_ss_add(clicon_handle h,
@ -375,12 +381,13 @@ stream_ss_add(clicon_handle h,
}
/*! Delete event stream subscription to a stream given a callback and arg
*
* @param[in] h Clicon handle
* @param[in] stream Name of stream or NULL for all streams
* @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
* @retval -1 Error
*/
int
stream_ss_rm(clicon_handle h,
@ -404,6 +411,7 @@ stream_ss_rm(clicon_handle h,
}
/*! Find stream callback given callback function and its (unique) argument
*
* @param[in] es Pointer to event stream
* @param[in] fn Stream callback
* @param[in] arg Argument - typically unique client handle
@ -427,6 +435,7 @@ stream_ss_find(event_stream_t *es,
}
/*! Remove stream subscription identified with fn and arg in all streams
*
* @param[in] h Clicon handle
* @param[in] fn Stream callback
* @param[in] arg Argument - typically unique client handle
@ -456,6 +465,7 @@ stream_ss_delete_all(clicon_handle h,
}
/*! Delete a single stream
*
* @see stream_ss_delete_all (merge with this?)
*/
int
@ -484,12 +494,13 @@ stream_ss_delete(clicon_handle h,
}
/*! Stream notify event and distribute to all registered callbacks
*
* @param[in] h Clicon handle
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
* @param[in] tv Timestamp. Dont notify if subscription has stoptime<tv
* @param[in] event Notification as xml tree
* @retval 0 OK
* @retval -1 Error with clicon_err called
* @retval 0 OK
* @retval -1 Error with clicon_err called
* @see stream_notify
* @see stream_ss_timeout where subscriptions are removed if stoptime<now
*/
@ -530,11 +541,12 @@ stream_notify1(clicon_handle h,
}
/*! Stream notify event and distribute to all registered callbacks
*
* @param[in] h Clicon handle
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
* @param[in] event Notification as format string according to printf(3)
* @retval 0 OK
* @retval -1 Error with clicon_err called
* @retval 0 OK
* @retval -1 Error with clicon_err called
* @code
* if (stream_notify(h, "NETCONF", "<event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>") < 0)
* err;
@ -611,11 +623,12 @@ stream_notify(clicon_handle h,
}
/*! Backward compatible function
*
* @param[in] h Clicon handle
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
* @param[in] xml Notification as XML stream. Is copied.
* @retval 0 OK
* @retval -1 Error with clicon_err called
* @retval 0 OK
* @retval -1 Error with clicon_err called
* @see stream_notify Should be merged with this
*/
int
@ -681,6 +694,7 @@ stream_notify_xml(clicon_handle h,
/*! Replay a stream by sending notification messages
*
* @see RFC5277 Sec 2.1.1:
* Start Time:
A parameter, <startTime>, used to trigger the replay feature
@ -745,6 +759,7 @@ stream_replay_notify(clicon_handle h,
}
/*! Add replay sample to stream with timestamp
*
* @param[in] es Stream
* @param[in] tv Timestamp
* @param[in] xv XML
@ -781,6 +796,7 @@ struct replay_arg{
};
/*! Timeout callback for replaying stream
*
* @param[in] fd Ignore
* @param[in] arg tmp struct including clicon handle, stream and subscription
*/
@ -816,10 +832,10 @@ stream_replay_cb(int fd,
/*! Schedule stream replay to occur asap, eg "now"
*
* @param[in] h clicon handle
* @param[in] stream Name of stream
* @param[in] fn Stream callback
* @param[in] arg Argument - typically unique client handle
* @param[in] h clicon handle
* @param[in] stream Name of stream
* @param[in] fn Stream callback
* @param[in] arg Argument - typically unique client handle
*/
int
stream_replay_trigger(clicon_handle h,
@ -892,9 +908,10 @@ curl_get_cb(void *ptr,
}
/*! Send a curl POST request
* @retval -1 fatal error
* @retval 0 expect set but did not expected return or other non-fatal error
*
* @retval 1 ok
* @retval 0 expect set but did not expected return or other non-fatal error
* @retval -1 fatal error
* Note: curl_easy_perform blocks
* Note: New handle is created every time, the handle can be re-used for better TCP performance
* @see same function (url_post) in grideye_curl.c
@ -953,6 +970,7 @@ url_post(char *url,
}
/*! Stream callback for example stream notification
*
* Push via curl_post to publish stream event
* @param[in] h Clicon handle
* @param[in] op Operation: 0 OK, 1 Close