C-style update: Unified comment, retvals in order, remove trailing spaces

Changed function name for `clicon_debug` functions
This commit is contained in:
Olof hagsand 2023-10-22 18:04:47 +02:00
parent 6e314dd96f
commit 62348fc9c7
204 changed files with 6047 additions and 4904 deletions

View file

@ -45,6 +45,14 @@
## 6.5.0
Expected: December 2023
### C/CLI-API changes on existing features
Developers may need to change their code
* Changed function name for `clicon_debug` functions. You need to rename as follows:
* clicon_debug() -> clixon_debug()
* clicon_debug_init() -> clixon_debug_init()
* clicon_debug_get() -> clixon_debug_get()
### Corrected Bugs
* Fixed: [Does clixon cli support autocompletion for leafrefs pointed to another module?](https://github.com/clicon/clixon/issues/455)

View file

@ -105,7 +105,7 @@ ce_event_cb(clicon_handle h,
{
struct client_entry *ce = (struct client_entry *)arg;
clicon_debug(1, "%s op:%d", __FUNCTION__, op);
clixon_debug(CLIXON_DBG_DEFAULT, "%s op:%d", __FUNCTION__, op);
switch (op){
case 1:
/* Risk of recursion here */
@ -273,7 +273,7 @@ backend_monitoring_state_get(clicon_handle h,
goto fail;
retval = 1;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
return retval;
@ -311,10 +311,10 @@ backend_client_rm(clicon_handle h,
if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
if (confirmed_commit_state_get(h) == EPHEMERAL) {
/* See if this client is the origin */
clicon_debug(1, "session_id: %u, confirmed_commit.session_id: %u", ce->ce_id, confirmed_commit_session_id_get(h));
clixon_debug(CLIXON_DBG_DEFAULT, "session_id: %u, confirmed_commit.session_id: %u", ce->ce_id, confirmed_commit_session_id_get(h));
if (myid == confirmed_commit_session_id_get(h)) {
clicon_debug(1, "ok, rolling back");
clixon_debug(CLIXON_DBG_DEFAULT, "ok, rolling back");
clicon_log(LOG_NOTICE, "a client with an active ephemeral confirmed-commit has disconnected; rolling back");
/* do_rollback errors are logged internally and there is no client to report errors to, so errors are
@ -326,7 +326,7 @@ backend_client_rm(clicon_handle h,
}
}
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* for all streams: XXX better to do it top-level? */
stream_ss_delete_all(h, ce_event_cb, (void*)ce);
c0 = backend_client_list(h);
@ -368,7 +368,7 @@ clixon_stats_datastore_get(clicon_handle h,
size_t sz = 0;
cxobj *xn = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, dbname);
clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, dbname);
/* This is the db cache */
if ((xt = xmldb_cache_get(h, dbname)) == NULL){
/* Trigger cache if no exist (trick to ensure cache is present) */
@ -645,9 +645,8 @@ from_client_edit_config(clicon_handle h,
xml_free(xret);
if (cbx)
cbuf_free(cbx);
clicon_debug(1, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret));
clixon_debug(CLIXON_DBG_DEFAULT, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret));
return retval;
} /* from_client_edit_config */
/*! Create or replace an entire config with another complete config db
@ -1292,9 +1291,9 @@ from_client_debug(clicon_handle h,
}
level = atoi(valstr);
clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
setlogmask(LOG_UPTO(level?LOG_DEBUG:LOG_INFO)); /* for syslog */
clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, clicon_debug_get());
clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, clixon_debug_get());
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;
@ -1582,7 +1581,7 @@ from_client_msg(clicon_handle h,
int nr = 0;
cbuf *cbce = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
yspec = clicon_dbspec_yang(h);
/* Return netconf message. Should be filled in by the dispatch(sub) functions
* as wither rpc-error or by positive response.
@ -1629,7 +1628,7 @@ from_client_msg(clicon_handle h,
* 3. Its a create-subscription message that uses a separate socket(=client)
*/
if (op_id != 0 && ce->ce_id != op_id && strcmp(rpcname, "create-subscription")){
clicon_debug(1, "%s Warning: incoming session-id:%u does not match ce_id:%u on socket: %d", __FUNCTION__, op_id, ce->ce_id, ce->ce_s);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Warning: incoming session-id:%u does not match ce_id:%u on socket: %d", __FUNCTION__, op_id, ce->ce_id, ce->ce_s);
}
/* Note that this validation is also made in xml_yang_validate_rpc, but not for hello
*/
@ -1707,7 +1706,7 @@ from_client_msg(clicon_handle h,
goto done;
}
module = yang_argument_get(ymod);
clicon_debug(CLIXON_DBG_DEFAULT, "%s module:%s rpc:%s ce_id:%u s:%d", __FUNCTION__, module,
clixon_debug(CLIXON_DBG_DEFAULT, "%s module:%s rpc:%s ce_id:%u s:%d", __FUNCTION__, module,
rpc, ce->ce_id, ce->ce_s);
/* Pre-NACM access step */
xnacm = NULL;
@ -1773,7 +1772,7 @@ from_client_msg(clicon_handle h,
if (cbuf_len(cbret) == 0)
if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0)
goto done;
// XXX clicon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret));
// XXX clixon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret));
/* XXX problem here is that cbret has not been parsed so may contain
parse errors */
if (ce_client_string(ce, &cbce) < 0)
@ -1798,7 +1797,7 @@ from_client_msg(clicon_handle h,
// ok:
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
if (xnacm){
xml_free(xnacm);
if (clicon_nacm_cache_set(h, NULL) < 0)
@ -1816,7 +1815,7 @@ from_client_msg(clicon_handle h,
if (retval < 0 && clicon_errno < 0)
clicon_log(LOG_NOTICE, "%s: Internal error: No clicon_err call on RPC error (message: %s)",
__FUNCTION__, rpc?rpc:"");
// clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
// clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;// -1 here terminates backend
}
@ -1839,7 +1838,7 @@ from_client(int s,
int eof = 0;
cbuf *cbce = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (s != ce->ce_s){
clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s");
goto done;
@ -1857,7 +1856,7 @@ from_client(int s,
goto done;
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval=%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval=%d", __FUNCTION__, retval);
if (cbce)
cbuf_free(cbce);
if (msg)

View file

@ -135,10 +135,11 @@ generic_validate(clicon_handle h,
}
/*! Common startup validation
*
* Get db, upgrade it w potential transformed XML, populate it w yang spec,
* sort it, validate it by triggering a transaction
* and call application callback validations.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The startup database. The wanted backend state
* @param[in] td Transaction data
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
@ -177,7 +178,7 @@ startup_common(clicon_handle h,
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
if ((msdiff = modstate_diff_new()) == NULL)
goto done;
clicon_debug(1, "Reading initial config from %s", db);
clixon_debug(CLIXON_DBG_DEFAULT, "Reading initial config from %s", db);
/* Get the startup datastore WITHOUT binding to YANG, sorting and default setting.
* It is done below, later in this function
*/
@ -202,7 +203,7 @@ startup_common(clicon_handle h,
if (xmldb_get0(h, db, YB_NONE, NULL, "/", 0, 0, &xt, msdiff, &xerr) < 0)
goto done;
}
clicon_debug_xml(CLIXON_DBG_DETAIL, xt, "startup");
clixon_debug_xml(CLIXON_DBG_DETAIL, xt, "startup");
if (msdiff && msdiff->md_status == 0){ // Possibly check for CLICON_XMLDB_MODSTATE
clicon_log(LOG_WARNING, "Modstate expected in startup datastore but not found\n"
"This may indicate that the datastore is not initialized corrrectly, such as copy/pasted.\n"
@ -212,7 +213,7 @@ startup_common(clicon_handle h,
clicon_err(OE_YANG, 0, "Yang spec not set");
goto done;
}
clicon_debug(1, "Reading startup config done");
clixon_debug(CLIXON_DBG_DEFAULT, "Reading startup config done");
/* Clear flags xpath for get */
xml_apply0(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
(void*)(XML_FLAG_MARK|XML_FLAG_CHANGE));
@ -301,7 +302,7 @@ startup_common(clicon_handle h,
/* 5. Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
clicon_debug(1, "Validating startup %s", db);
clixon_debug(CLIXON_DBG_DEFAULT, "Validating startup %s", db);
if ((ret = generic_validate(h, yspec, td, &xret)) < 0)
goto done;
if (ret == 0){
@ -335,7 +336,7 @@ startup_common(clicon_handle h,
/*! Read startup db, check upgrades and validate it, return upgraded XML
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The startup database. The wanted backend state
* @param[out] xtr (Potentially) transformed XML
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
@ -386,7 +387,7 @@ startup_validate(clicon_handle h,
/*! Read startup db, check upgrades and commit it
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The startup database. The wanted backend state
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
* @retval 1 Validation OK
@ -463,9 +464,10 @@ startup_commit(clicon_handle h,
}
/*! Validate a candidate db and comnpare to running
*
* Get both source and dest datastore, validate target, compute diffs
* and call application callback validations.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db The (candidate) database. The wanted backend state
* @param[in] td Transaction data
* @param[out] xret Error XML tree, if retval is 0. Free with xml_free after use
@ -520,7 +522,7 @@ validate_common(clicon_handle h,
&td->td_tcvec, /* changed: wanted values */
&td->td_clen) < 0)
goto done;
if (clicon_debug_get() & CLIXON_DBG_DETAIL)
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
transaction_dbg(h, CLIXON_DBG_DETAIL, td, __FUNCTION__);
/* Mark as changed in tree */
for (i=0; i<td->td_dlen; i++){ /* Also down */
@ -571,7 +573,7 @@ validate_common(clicon_handle h,
/*! Start a validate transaction
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db A candidate database, typically "candidate" but not necessarily so
* @param[out] cbret CLIgen buffer w error stmt if retval = 0
* @retval 1 Validation OK
@ -588,7 +590,7 @@ candidate_validate(clicon_handle h,
cxobj *xret = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (db == NULL || cbret == NULL){
clicon_err(OE_CFG, EINVAL, "db or cbret is NULL");
goto done;
@ -647,7 +649,7 @@ candidate_validate(clicon_handle h,
* The code reverts changes if the commit fails. But if the revert
* fails, we just ignore the errors and proceed. Maybe we should
* do something more drastic?
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc> (or NULL)
* @param[in] db A candidate database, not necessarily "candidate"
* @param[in] myid Client id of triggering incoming message (or 0)
@ -738,7 +740,6 @@ candidate_commit(clicon_handle h,
/* 9. Call plugin transaction end callbacks */
plugin_transaction_end_all(h, td);
retval = 1;
done:
/* In case of failure (or error), call plugin transaction termination callbacks */
@ -759,7 +760,7 @@ candidate_commit(clicon_handle h,
/*! Commit the candidate configuration as the device's new current configuration
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
@ -821,7 +822,7 @@ from_client_commit(clicon_handle h,
goto ok;
}
if ((ret = candidate_commit(h, xe, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */
clicon_debug(1, "Commit candidate failed");
clixon_debug(CLIXON_DBG_DEFAULT, "Commit candidate failed");
if (ret < 0)
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
goto done;
@ -839,13 +840,12 @@ from_client_commit(clicon_handle h,
/*! Revert the candidate configuration to the current running configuration.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
* @param[in] regarg User argument given at rpc_callback_register()
* @retval 0 OK. This may indicate both ok and err msg back to client
* @retval 0 OK
* @retval -1 Error
* NACM: No datastore permissions are needed.
*/
@ -890,7 +890,8 @@ from_client_discard_changes(clicon_handle h,
}
/*! Validates the contents of the specified configuration.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
@ -910,7 +911,7 @@ from_client_validate(clicon_handle h,
int ret;
char *db;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((db = netconf_db_find(xe, "source")) == NULL){
if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0)
goto done;
@ -927,6 +928,7 @@ from_client_validate(clicon_handle h,
} /* from_client_validate */
/*! Restart specific backend plugins without full backend restart
*
* Note, depending on plugin callbacks, there may be other dependencies which may make this
* difficult in the general case.
*/
@ -955,7 +957,7 @@ from_client_restart_one(clicon_handle h,
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done;
if ((retval = resetfn(h, db)) < 0) {
clicon_debug(1, "plugin_start() failed");
clixon_debug(CLIXON_DBG_DEFAULT, "plugin_start() failed");
goto done;
}
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)

View file

@ -105,6 +105,7 @@ confirmed_commit_init(clicon_handle h)
}
/*! If confirm commit persist-id exists, free it
*
* @param[in] h Clixon handle
* @retval 0 OK
*/
@ -222,6 +223,7 @@ confirmed_commit_fn_arg_set(clicon_handle h,
}
/*! Return if confirmed tag found
*
* @param[in] xe Commit rpc xml
* @retval 1 Confirmed tag exists
* @retval 0 Confirmed tag does not exist
@ -233,6 +235,7 @@ xe_confirmed(cxobj *xe)
}
/*! Return if persist exists and its string value field
*
* @param[in] xe Commit rpc xml
* @param[out] str Pointer to persist
* @retval 1 Persist field exists
@ -274,6 +277,7 @@ xe_persist_id(cxobj *xe,
}
/*! Return timeout
*
* @param[in] xe Commit rpc xml
* @retval sec Timeout in seconds, can be 0 if no timeout exists or is zero
*/
@ -373,6 +377,7 @@ schedule_rollback_event(clicon_handle h,
}
/*! Cancel a confirming commit by removing rollback, and free state
*
* @param[in] h
* @param[out] cbret
* @retval 0 OK
@ -401,7 +406,7 @@ cancel_confirmed_commit(clicon_handle h)
* without a <persist> value, OR
* 2) be presented with a <persist-id> value that matches the <persist> value accompanying the prior confirmed-commit
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] myid current client session-id
* @retval 1 The confirming-commit is valid
@ -452,7 +457,7 @@ check_valid_confirming_commit(clicon_handle h,
"not issued on the same session as the confirmed-commit");
goto invalid;
default:
clicon_debug(1, "commit-confirmed state !? %d", confirmed_commit_state_get(h));
clixon_debug(CLIXON_DBG_DEFAULT, "commit-confirmed state !? %d", confirmed_commit_state_get(h));
goto invalid;
}
retval = 1; // valid
@ -471,7 +476,7 @@ check_valid_confirming_commit(clicon_handle h,
* In the second phase, the action taken is to handle both confirming- and confirmed-commit by creating the
* rollback database as required, then deleting it once the sequence is complete.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Commit rpc xml or NULL
* @param[in] myid Current session-id, only valid > 0 if call is made as a result of an incoming message
* @retval 0 OK
@ -622,9 +627,9 @@ handle_confirmed_commit(clicon_handle h,
* 2. from_client_cancel_commit() (invoked either by netconf client, or CLI)
* 3. rollback_fn() (invoked by expiration of the rollback event timer)
*
* @param[in] h Clicon handle
* @retval -1 Error
* @param[in] h Clixon handle
* @retval 0 Success
* @retval -1 Error
* @see backend_client_rm()
* @see from_client_cancel_commit()
* @see rollback_fn()
@ -696,12 +701,13 @@ do_rollback(clicon_handle h,
}
/*! Cancel an ongoing confirmed commit.
*
* If the confirmed commit is persistent, the parameter 'persist-id' must be
* given, and it must match the value of the 'persist' parameter.
* If the confirmed-commit is ephemeral, the 'persist-id' must not be given and both the confirmed-commit and the
* cancel-commit must originate from the same session.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
@ -777,7 +783,8 @@ from_client_cancel_commit(clicon_handle h,
}
/*! Incoming commit handler for confirmed commit
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] myid Client-id
* @param[out] cbret Return xml tree

View file

@ -72,12 +72,15 @@
#include "backend_handle.h"
#include "backend_get.h"
/*!
/*! restrconf get capabilities
*
* Maybe should be in the restconf client instead of backend?
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xpath Xpath selection, not used but may be to filter early
* @param[out] xrs XML restconf-state node
* @retval 0 OK
* @retval -1 Error
* @see netconf_hello_server
* @see rfc8040 Sections 9.1
*/
@ -114,7 +117,8 @@ restconf_client_get_capabilities(clicon_handle h,
}
/*! Get streams state according to RFC 8040 or RFC5277 common function
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xpath Xpath selection, not used but may be to filter early
* @param[in] module Name of yang module
@ -176,7 +180,8 @@ client_get_streams(clicon_handle h,
}
/*! Get system state-data, including streams and plugins
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xpath XPath selection, may be used to filter early
* @param[in] nsc XML Namespace context for xpath
* @param[in] wdef With-defaults parameter, see RFC 6243
@ -213,7 +218,7 @@ get_statedata(clicon_handle h,
cbuf *cb = NULL;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec");
goto done;
@ -368,7 +373,7 @@ get_statedata(clicon_handle h,
} /* switch wdef */
retval = 1; /* OK */
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (xerr)
xml_free(xerr);
if (x1)
@ -390,7 +395,7 @@ get_statedata(clicon_handle h,
* and we need to re-add it.
* Note original xpath
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xret Result XML tree
* @param[in] xvec xpath lookup result on xret
@ -438,7 +443,7 @@ filter_xpath_again(clicon_handle h,
/*! Help function for NACM access and return message
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xret Result XML tree
* @param[in] xvec xpath lookup result on xret
* @param[in] xlen length of xvec
@ -520,7 +525,7 @@ element2value(clicon_handle h,
/*! Extract offset and limit from get/list-pagination
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] offset Number of entries in the working result-set that should be skipped
* @param[out] limit Limits the number of entries returned from the working result-set
@ -552,7 +557,7 @@ list_pagination_hdr(clicon_handle h,
*
* It is specialized enough to have its own function. Specifically, extra attributes as well
* as the list-paginaiton API
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] ce Client entry, for locking
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] content Get config/state/both
@ -764,7 +769,7 @@ get_list_pagination(clicon_handle h,
if ((ret = xml_bind_yang(h, xret, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_debug_xml(1, xret, "Yang bind pagination state");
clixon_debug_xml(1, xret, "Yang bind pagination state");
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML",
NULL) < 0)
@ -821,7 +826,7 @@ get_list_pagination(clicon_handle h,
/*! Common get/get-config code for retrieving configuration and state information.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] ce Client entry, for locking
* @param[in] xe Request: <rpc><xn></rpc>
* @param[in] content Get config/state/both
@ -867,7 +872,7 @@ get_common(clicon_handle h,
char *wdefstr;
wdef = WITHDEFAULTS_EXPLICIT;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec9");
@ -1013,7 +1018,7 @@ get_common(clicon_handle h,
(ret = xml_yang_validate_add(h, xret, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_debug_xml(1, xret, "VALIDATE_STATE");
clixon_debug_xml(1, xret, "VALIDATE_STATE");
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML",
NULL) < 0)
@ -1044,7 +1049,7 @@ get_common(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
free(xvec);
if (xret)
@ -1068,7 +1073,7 @@ get_common(clicon_handle h,
/*! Retrieve all or part of a specified configuration.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry
@ -1099,7 +1104,7 @@ from_client_get_config(clicon_handle h,
/*! Retrieve running configuration and device state information.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xe Request: <rpc><xn></rpc>
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
* @param[in] arg client-entry

View file

@ -84,6 +84,7 @@
#define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log"
/*! Clean and close all state of backend (but dont exit).
*
* Cannot use h after this
* @param[in] h Clixon handle
*/
@ -99,7 +100,7 @@ backend_terminate(clicon_handle h)
int ss;
cvec *nsctx;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ss = clicon_socket_get(h)) != -1)
close(ss);
/* Disconnect datastore */
@ -142,7 +143,7 @@ backend_terminate(clicon_handle h)
unlink(sockpath);
backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */
clixon_event_exit();
clicon_debug(1, "%s done", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
clixon_err_exit();
clicon_log_exit();
return 0;
@ -163,19 +164,21 @@ backend_sig_term(int arg)
clixon_exit_set(1); /* checked in clixon_event_loop() */
}
/*! wait for killed child
/*! Wait for killed child
*
* primary use in case restconf daemon forked using process-control API
* This may cause EINTR in eg select() in clixon_event_loop() which will be ignored
*/
static void
backend_sig_child(int arg)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
clicon_sig_child_set(1);
}
/*! Create backend server socket and register callback
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval s Server socket file descriptor (see socket(2))
* @retval -1 Error
*/
@ -278,7 +281,7 @@ xmldb_drop_priv(clicon_handle h,
* - uid is currently 0 (started as root)
* - CLICON_BACKEND_USER is set
* - CLICON_BACKEND_PRIVILEGES is not "none"
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] gid Group id (assume already known)
* @retval 0 OK
* @retval -1 Error
@ -425,7 +428,7 @@ backend_timer_setup(int fd,
struct timeval t;
struct timeval t1 = {10, 0};
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
gettimeofday(&now, NULL);
backend_client_print(h, stderr);
@ -588,7 +591,7 @@ main(int argc,
* double syslogs until fork below.
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Find and read configfile */
@ -1082,7 +1085,7 @@ main(int argc,
clicon_session_id_set(h, 1);
#if 0 /* debug */
/* Enable this to get prints of datastore and session status */
if (0 && clicon_debug_get() &&
if (clixon_debug_get() &&
backend_timer_setup(0, h) < 0)
goto done;
#endif

View file

@ -68,7 +68,7 @@
*
* The system 'state' should be the same as the contents of running_db
* @param[in] cp Plugin handle
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of datastore
* @retval 0 OK
* @retval -1 Error
@ -117,7 +117,7 @@ clixon_plugin_reset_all(clicon_handle h,
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_reset_one(cp, h, db) < 0)
@ -169,7 +169,7 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
* This point in time is after "start" and before
* before daemonization/fork,
* It is not called if backend is started in daemon mode.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
@ -179,7 +179,7 @@ clixon_plugin_pre_daemon_all(clicon_handle h)
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_pre_daemon_one(cp, h) < 0)
@ -231,7 +231,7 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp,
* after daemonization/fork, ie when
* daemon is in the background but before dropped privileges.
* In case of foreground mode (-F) it is still called but no fork has occured.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* @note Also called for non-background mode
@ -242,7 +242,7 @@ clixon_plugin_daemon_all(clicon_handle h)
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_daemon_one(cp, h) < 0)
@ -347,7 +347,7 @@ clixon_plugin_statedata_all(clicon_handle h,
cbuf *cberr = NULL;
cxobj *xerr = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, &x)) < 0)
goto done;
@ -373,7 +373,7 @@ clixon_plugin_statedata_all(clicon_handle h,
x = NULL;
continue;
}
clicon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp));
clixon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp));
/* XXX: ret == 0 invalid yang binding should be handled as internal error */
if ((ret = xml_bind_yang(h, x, YB_MODULE, yspec, &xerr)) < 0)
goto done;
@ -471,7 +471,7 @@ clixon_plugin_lockdb_all(clicon_handle h,
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_lockdb_one(cp, h, db, lock, id) < 0)
goto done;
@ -485,6 +485,8 @@ clixon_plugin_lockdb_all(clicon_handle h,
*
* @param[in] h Clixon handle
* @param[in] xpath Registered XPath using canonical prefixes
* @retval 1 OK
* @retval -1 Error
*/
int
clixon_pagination_cb_call(clicon_handle h,
@ -505,7 +507,7 @@ clixon_pagination_cb_call(clicon_handle h,
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable && dispatcher_call_handlers(htable, h, xpath, &pd) < 0)
goto done;
retval = 1;
retval = 1; // XXX 0?
done:
return retval;
}
@ -516,6 +518,8 @@ clixon_pagination_cb_call(clicon_handle h,
* @param[in] fn Callback
* @param[in] xpath Registered XPath using canonical prefixes
* @param[in] arg Domain-specific argument to send to callback
* @retval 0 OK
* @retval -1 Error
*/
int
clixon_pagination_cb_register(clicon_handle h,
@ -639,7 +643,7 @@ plugin_transaction_begin_one(clixon_plugin_t *cp,
/*! Call transaction_begin() in all plugins before a validate/commit.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
@ -651,7 +655,7 @@ plugin_transaction_begin_all(clicon_handle h,
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_begin_one(cp, h, td) < 0)
goto done;
@ -701,7 +705,7 @@ plugin_transaction_validate_one(clixon_plugin_t *cp,
/*! Call transaction_validate callbacks in all backend plugins
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK. Validation succeeded in all plugins
* @retval -1 Error: one of the plugin callbacks returned validation fail
@ -762,7 +766,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
/*! Call transaction_complete() in all plugins after validation (before commit)
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
@ -856,7 +860,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
/*! Call transaction_commit callbacks in all backend plugins
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
@ -924,7 +928,7 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp,
/*! Call transaction_commit_done callbacks in all backend plugins
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error: one of the plugin callbacks returned error
@ -985,7 +989,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp,
/*! Call transaction_end() in all plugins after a successful commit.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error
@ -997,7 +1001,7 @@ plugin_transaction_end_all(clicon_handle h,
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_end_one(cp, h, td) < 0)
goto done;
@ -1038,7 +1042,7 @@ plugin_transaction_abort_one(clixon_plugin_t *cp,
/*! Call transaction_abort() in all plugins after a failed validation/commit.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] td Transaction data
* @retval 0 OK
* @retval -1 Error
@ -1050,7 +1054,7 @@ plugin_transaction_abort_all(clicon_handle h,
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_abort_one(cp, h, td) < 0)
; /* dont abort on error */

View file

@ -70,6 +70,8 @@
* is started.
* @param[in] h Clixon backend
* @param[in] xt XML target
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_pseudo_set_log(clicon_handle h,
@ -138,6 +140,8 @@ restconf_pseudo_set_log(clicon_handle h,
* and insert it as a optimization to reading it from the backend.
* @param[in] h Clixon backend
* @param[in] xt XML target
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_pseudo_set_inline(clicon_handle h,
@ -150,7 +154,7 @@ restconf_pseudo_set_inline(clicon_handle h,
cxobj *xrestconf;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
goto done;
if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL)
@ -170,7 +174,7 @@ restconf_pseudo_set_inline(clicon_handle h,
clicon_err(OE_XML, errno, "stdup");
goto done;
}
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
clixon_debug(CLIXON_DBG_DEFAULT, "%s str:%s", __FUNCTION__, str);
if (argv[i+1])
free(argv[i+1]);
argv[i+1] = str;
@ -186,6 +190,7 @@ restconf_pseudo_set_inline(clicon_handle h,
}
/*! Process rpc callback function
*
* - if RPC op is start, if enable is true, start the service, if false, error or ignore it
* - if RPC op is stop, stop the service
* These rules give that if RPC op is start and enable is false -> change op to none
@ -198,7 +203,7 @@ restconf_rpc_wrapper(clicon_handle h,
int retval = -1;
cxobj *xt = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
switch (*operation){
case PROC_OP_STOP:
/* if RPC op is stop, stop the service */
@ -235,7 +240,8 @@ restconf_rpc_wrapper(clicon_handle h,
}
/*! Enable process-control of restconf daemon, ie start/stop restconf by registering restconf process
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @note Could also look in clixon-restconf and start process if enable is true, but that needs to
* be in start callback using a pseudo plugin.
* - Debug flag inheritance only works if backend is started with debug. If debug is set later
@ -277,24 +283,24 @@ restconf_pseudo_process_control(clicon_handle h)
cprintf(cb, "%s/clixon_restconf", dir0);
pgm = cbuf_get(cb);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm);
}
if (!found &&
(dir1 = CLIXON_CONFIG_SBINDIR) != NULL){
cbuf_reset(cb);
cprintf(cb, "%s/clixon_restconf", dir1);
pgm = cbuf_get(cb);
clicon_debug(1, "Looking for %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Looking for %s", pgm);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm);
}
if (!found){
clicon_err(OE_RESTCONF, 0, "clixon_restconf not found in neither CLICON_RESTCONF_INSTALLDIR(%s) nor CLIXON_CONFIG_SBINDIR(%s). Try overriding with CLICON_RESTCONF_INSTALLDIR",
@ -343,7 +349,7 @@ restconf_pseudo_process_validate(clicon_handle h,
int retval = -1;
cxobj *xtarget;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
xtarget = transaction_target(td);
/* If ssl-enable is true and (at least a) socket has ssl,
* then server-cert-path and server-key-path must exist */
@ -375,7 +381,7 @@ restconf_pseudo_process_commit(clicon_handle h,
cxobj *cx;
int enabled = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
xtarget = transaction_target(td);
xsource = transaction_src(td);
if (xpath_first(xtarget, NULL, "/restconf[enable='true']") != NULL)
@ -425,7 +431,10 @@ restconf_pseudo_process_commit(clicon_handle h,
}
/*! Register start/stop restconf RPC and create pseudo-plugin to monitor enable flag
*
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
int
backend_plugin_restconf_register(clicon_handle h,

View file

@ -78,7 +78,7 @@
/*! Open an INET stream socket and bind it to a file descriptor
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] dst IPv4 address (see inet_pton(3))
* @retval s Socket file descriptor (see socket(2))
* @retval -1 Error
@ -111,7 +111,7 @@ config_socket_init_ipv4(clicon_handle h,
clicon_err(OE_UNIX, errno, "bind");
goto err;
}
clicon_debug(1, "Listen on server socket at %s:%hu", dst, port);
clixon_debug(CLIXON_DBG_DEFAULT, "Listen on server socket at %s:%hu", dst, port);
if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto err;
@ -126,7 +126,7 @@ config_socket_init_ipv4(clicon_handle h,
*
* The socket is accessed via CLICON_SOCK option, has 770 permissions
* and group according to CLICON_SOCK_GROUP option.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] sock Unix file-system path
* @retval s Socket file descriptor (see socket(2))
* @retval -1 Error
@ -178,7 +178,7 @@ config_socket_init_unix(clicon_handle h,
clicon_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group);
goto err;
}
clicon_debug(1, "Listen on server socket at %s", addr.sun_path);
clixon_debug(CLIXON_DBG_DEFAULT, "Listen on server socket at %s", addr.sun_path);
if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto err;
@ -191,7 +191,7 @@ config_socket_init_unix(clicon_handle h,
/*! Open backend socket, the one clients send requests to, either ip or unix
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval s Socket file descriptor (see socket(2))
* @retval -1 Error
*/
@ -220,8 +220,11 @@ backend_socket_init(clicon_handle h)
}
/*! Accept new socket client
*
* @param[in] fd Socket (unix or ip)
* @param[in] arg typecast clicon_handle
* @retval 0 OK
* @retval -1 Error
*/
int
backend_accept_client(int fd,
@ -242,7 +245,7 @@ backend_accept_client(int fd,
uid_t guid;
#endif
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
len = sizeof(from);
if ((s = accept(fd, &from, &len)) < 0){
clicon_err(OE_UNIX, errno, "accept");

View file

@ -274,8 +274,6 @@ load_extraxml(clicon_handle h,
* @retval 0 Validation failed
* @retval -1 Error
running -----------------+----+------>
reset loadfile / merge
tmp |-------+-----+-----+

View file

@ -78,6 +78,7 @@
* entries in the struct below.
*/
/*! Backend specific handle added to header CLICON handle
*
* This file should only contain access functions for the _specific_
* entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c
@ -104,7 +105,8 @@ backend_handle_init(void)
}
/*! Deallocates a backend handle, including all client structs
* @Note: handle 'h' cannot be used in calls after this
*
* @note: handle 'h' cannot be used in calls after this
* @see backend_client_rm
*/
int
@ -125,7 +127,8 @@ backend_handle_exit(clicon_handle h)
}
/*! Add new client, typically frontend such as cli, netconf, restconf
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] addr Address of client
* @retval ce Client entry
* @retval NULL Error
@ -158,7 +161,8 @@ backend_client_add(clicon_handle h,
}
/*! Return client list
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval ce_list Client entry list (all sessions)
*/
struct client_entry *
@ -170,7 +174,8 @@ backend_client_list(clicon_handle h)
}
/*! Actually remove client from client list
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] ce Client handle
* @see backend_client_rm which is more high-level
*/
@ -201,7 +206,8 @@ backend_client_delete(clicon_handle h,
}
/*! Debug print backend clients
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] f UNIX output stream
*/
int

View file

@ -43,6 +43,7 @@
*/
/*! Transaction data describing a system transition from a src to target state
*
* Clixon internal, presented as void* to app's callback in the 'transaction_data'
* type in clicon_backend_api.h
* The struct contains source and target XML tree (e.g. candidate/running)
@ -68,6 +69,7 @@ typedef struct {
} transaction_data_t;
/*! Pagination userdata
*
* Pagination can use a lock/transaction mechanism
* If locking is not used, the plugin cannot expect more pagination calls, and no state or
* caching should be used

View file

@ -69,6 +69,7 @@
* would give running in source and 'a' and candidate in 'target'.
*/
/*! Get transaction id
*
* @param[in] td transaction_data
* @retval id transaction id
*/
@ -79,6 +80,7 @@ transaction_id(transaction_data td)
}
/*! Get plugin/application specific callback argument
*
* @param[in] td transaction_data
* @retval arg callback argument
*/
@ -89,6 +91,7 @@ transaction_arg(transaction_data td)
}
/*! Set plugin/application specific callback argument
*
* @param[in] td transaction_data
* @param[in] arg callback argument
*/
@ -101,6 +104,7 @@ transaction_arg_set(transaction_data td,
}
/*! Get source database xml tree
*
* @param[in] td transaction_data
* @retval src source xml tree containing original state
*/
@ -111,6 +115,7 @@ transaction_src(transaction_data td)
}
/*! Get target database xml tree
*
* @param[in] td transaction_data
* @retval xml target xml tree containing wanted state
*/
@ -121,6 +126,7 @@ transaction_target(transaction_data td)
}
/*! Get delete xml vector, ie vector of xml nodes that are deleted src->target
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
*/
@ -131,6 +137,7 @@ transaction_dvec(transaction_data td)
}
/*! Get length of delete xml vector
*
* @param[in] td transaction_data
* @retval len Length of vector of xml nodes
* @see transaction_dvec
@ -142,6 +149,7 @@ transaction_dlen(transaction_data td)
}
/*! Get add xml vector, ie vector of xml nodes that are added src->target
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
*/
@ -152,6 +160,7 @@ transaction_avec(transaction_data td)
}
/*! Get length of add xml vector
*
* @param[in] td transaction_data
* @retval len Length of vector of xml nodes
* @see transaction_avec
@ -163,6 +172,7 @@ transaction_alen(transaction_data td)
}
/*! Get source changed xml vector, ie vector of xml nodes that changed
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
* These are only nodes of type LEAF.
@ -177,6 +187,7 @@ transaction_scvec(transaction_data td)
}
/*! Get target changed xml vector, ie vector of xml nodes that changed
*
* @param[in] td transaction_data
* @retval vec Vector of xml nodes
* These are only nodes of type LEAF.
@ -191,6 +202,7 @@ transaction_tcvec(transaction_data td)
}
/*! Get length of changed xml vector
*
* @param[in] td transaction_data
* @retval len Length of vector of xml nodes
* This is the length of both the src change vector and the target change vector
@ -267,7 +279,7 @@ transaction_dbg(clicon_handle h,
goto done;
}
if (i)
clicon_debug(dbglevel, "%s %" PRIu64 " %s del: %s",
clixon_debug(dbglevel, "%s %" PRIu64 " %s del: %s",
__FUNCTION__, td->td_id, msg, cbuf_get(cb));
cbuf_reset(cb);
for (i=0; i<td->td_alen; i++){
@ -276,7 +288,7 @@ transaction_dbg(clicon_handle h,
goto done;
}
if (i)
clicon_debug(dbglevel, "%s %" PRIu64 " %s add: %s",
clixon_debug(dbglevel, "%s %" PRIu64 " %s add: %s",
__FUNCTION__, td->td_id, msg, cbuf_get(cb));
cbuf_reset(cb);
for (i=0; i<td->td_clen; i++){
@ -290,7 +302,7 @@ transaction_dbg(clicon_handle h,
goto done;
}
if (i)
clicon_debug(dbglevel, "%s %" PRIu64 " %s change: %s",
clixon_debug(dbglevel, "%s %" PRIu64 " %s change: %s",
__FUNCTION__, td->td_id, msg, cbuf_get(cb));
done:
if (cb)
@ -299,7 +311,6 @@ transaction_dbg(clicon_handle h,
}
/*! Log a transaction
*
*/
int
transaction_log(clicon_handle h,

View file

@ -137,7 +137,7 @@ cli_auto_edit(clicon_handle h,
str = cv_string_get(cvec_i(argv, argc++));
if (str && strncmp(str, "mtpoint:", strlen("mtpoint:")) == 0){
mtpoint = str + strlen("mtpoint:");
clicon_debug(1, "%s mtpoint:%s", __FUNCTION__, mtpoint);
clixon_debug(CLIXON_DBG_DEFAULT, "%s mtpoint:%s", __FUNCTION__, mtpoint);
treename = cv_string_get(cvec_i(argv, argc++));
}
else
@ -205,9 +205,12 @@ cli_auto_edit(clicon_handle h,
}
/*! CLI callback: Working point tree up to parent
*
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv Vector of user-supplied keywords
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <treename> Name of generated cligen parse-tree, eg "datamodel"
*/
@ -300,9 +303,12 @@ cli_auto_up(clicon_handle h,
}
/*! CLI callback: Working point tree reset to top level
*
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv Vector of user-supplied keywords
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <treename> Name of generated cligen parse-tree, eg "datamodel"
*/
@ -333,9 +339,12 @@ cli_auto_top(clicon_handle h,
}
/*! CLI callback: set auto db item
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <api-path-fmt> Generated
*/
@ -358,9 +367,12 @@ cli_auto_set(clicon_handle h,
}
/*! Merge datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_auto_merge(clicon_handle h,
@ -381,9 +393,12 @@ cli_auto_merge(clicon_handle h,
}
/*! Create datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_auto_create(clicon_handle h,
@ -404,9 +419,12 @@ cli_auto_create(clicon_handle h,
}
/*! Delete datastore xml
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_auto_del(clicon_handle h,
@ -438,7 +456,6 @@ struct findpt_arg{
* @param[in] arg Argument, cast to application-specific info
* @retval 1 OK and return (abort iteration)
* @retval 0 OK and continue
* @retval -1 Error: break and return
*/
static int
cli_auto_findpt(cg_obj *co,
@ -456,9 +473,12 @@ cli_auto_findpt(cg_obj *co,
}
/*! Enter edit mode
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector of args to function in command.
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <api_path_fmt> Generated API PATH FORMAT (print-like for variables)
* <vars>* List of static variables that can be used as values for api_path_fmt

View file

@ -106,8 +106,8 @@ autocli_listkw_int2str(int listkw)
* @param[in] h Clixon handle
* @param[in] modname Name of YANG module, or NULL for ANY module (eg default)
* @param[out] enablep Include this module in autocli
* @retval -1 Error
* @retval 0 OK, and enablep set
* @retval -1 Error
*/
int
autocli_module(clicon_handle h,
@ -228,9 +228,8 @@ autocli_compress_extension(yang_stmt *ys,
*
* @param[in] h Clixon handle
* @param[out] compress
* @retval -1 Error
* @retval 0 OK, and compress set
* @retval -1 Error
* Canonical examples:
The config and state containers are "compressed" out of the schema.
+ op=COMPRESS
@ -346,8 +345,8 @@ autocli_compress(clicon_handle h,
* Currently only returns list-keyword-default, could be extended to rules
* @param[in] h Clixon handle
* @param[out] completion Completion enabled
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_completion(clicon_handle h,
@ -389,8 +388,8 @@ autocli_completion(clicon_handle h,
* When false replaces uses with grouping, when true use tree reference
* @param[in] h Clixon handle
* @param[out] treeref grouping using treerefs enabled
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_grouping_treeref(clicon_handle h,
@ -432,8 +431,8 @@ autocli_grouping_treeref(clicon_handle h,
* Currently only returns list-keyword-default, could be extended to rules
* @param[in] h Clixon handle
* @param[out] listkw List keyword setting
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_list_keyword(clicon_handle h,
@ -465,8 +464,8 @@ autocli_list_keyword(clicon_handle h,
*
* @param[in] h Clixon handle
* @param[out] treeref_state If true, generate CLI from state
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_treeref_state(clicon_handle h,
@ -508,8 +507,8 @@ autocli_treeref_state(clicon_handle h,
* @param[in] h Clixon handle
* @param[in] keyw YANG keyword
* @param[out] flag If 0 keyw is not a part of default edit-mode, if 1 it is.
* @retval -1 Error
* @retval 0 OK, see result in keyw
* @retval -1 Error
* @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined
*/
int

View file

@ -72,13 +72,16 @@
#include "cli_common.h"
/*! Register log notification stream
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] stream Event stream. CLICON is predefined, others are application-defined
* @param[in] filter Filter. For xml notification ie xpath: .[name="kalle"]
* @param[in] status 0 for stop, 1 to start
* @param[in] fn Callback function called when notification occurs
* @param[in] arg Argument to function note
* Note this calls cligen_regfd which may callback on cli command interpretator
* @retval 0 OK
* @retval -1 Error
* @note this calls cligen_regfd which may callback on cli command interpretator
*/
int
cli_notification_register(clicon_handle h,
@ -183,6 +186,11 @@ cli_signal_flush(clicon_handle h)
}
/*! Create body and add last CLI variable vector as value
*
* @param[in] xbot
* @param[in] cvv
* @retval 0 OK
* @retval -1 Error
* Create and add an XML body as child of XML node xbot. Set its value to the last
* CLI variable vector element.
*/
@ -214,7 +222,12 @@ dbxml_body(cxobj *xbot,
}
/*! Special handling of identityref:s whose body may be: <namespace prefix>:<id>
*
* Ensure the namespace is declared if it exists in YANG
* @param[in] x
* @param[in] arg
* @retval 0 OK
* @retval -1 Error
*/
int
identityref_add_ns(cxobj *x,
@ -273,6 +286,8 @@ identityref_add_ns(cxobj *x,
* @param[in] mtpoint Mount-point, generic: if there are several with same yang, any will do
* @param[in] api_path_fmt1 Second part of api-path-fmt
* @param[out] api_path_fmt01 Combined api-path-fmt
* @retval 0 OK
* @retval -1 Error
*/
int
mtpoint_paths(yang_stmt *yspec0,
@ -346,7 +361,7 @@ mtpoint_paths(yang_stmt *yspec0,
/*! Modify xml datastore from a callback using xml key format strings
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Arguments given at the callback:
* <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv)
@ -354,6 +369,8 @@ mtpoint_paths(yang_stmt *yspec0,
* [<mt-point>] Optional YANG path-arg/xpath from mount-point
* @param[in] op Operation to perform on database
* @param[in] nsctx Namespace context for last value added
* @retval 0 OK
* @retval -1 Error
* cvv first contains the complete cli string, and then a set of optional
* instantiated variables.
* If the last node is a leaf, the last cvv element is added as a value. This value
@ -512,9 +529,12 @@ cli_dbxml(clicon_handle h,
}
/*! Set datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_set(clicon_handle h,
@ -531,9 +551,12 @@ cli_set(clicon_handle h,
}
/*! Merge datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_merge(clicon_handle h,
@ -550,9 +573,12 @@ cli_merge(clicon_handle h,
}
/*! Create datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_create(clicon_handle h,
@ -567,10 +593,14 @@ cli_create(clicon_handle h,
done:
return retval;
}
/*! Remove datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
* @see cli_del
*/
int
@ -588,9 +618,12 @@ cli_remove(clicon_handle h,
}
/*! Delete datastore xml
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_del(clicon_handle h,
@ -607,22 +640,25 @@ cli_del(clicon_handle h,
}
/*! Set debug level on CLI client (not backend daemon)
* @param[in] h Clicon handle
* @param[in] vars If variable "level" exists, its integer value is used
*
* @param[in] h Clixon handle
* @param[in] cvv If variable "level" exists, its integer value is used
* @param[in] arg Else use the integer value of argument
* @retval 0 OK
* @retval -1 Error
* @note The level is either what is specified in arg as int argument.
* _or_ if a 'level' variable is present in vars use that value instead.
* _or_ if a 'level' variable is present in cvv use that value instead.
*/
int
cli_debug_cli(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL){
if ((cv = cvec_find_var(cvv, "level")) == NULL){
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
goto done;
@ -631,29 +667,32 @@ cli_debug_cli(clicon_handle h,
}
level = cv_int32_get(cv);
/* cli */
clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
retval = 0;
done:
return retval;
}
/*! Set debug level on backend daemon (not CLI)
* @param[in] h Clicon handle
* @param[in] vars If variable "level" exists, its integer value is used
*
* @param[in] h Clixon handle
* @param[in] cvv If variable "level" exists, its integer value is used
* @param[in] arg Else use the integer value of argument
* @retval 0 OK
* @retval -1 Error
* @note The level is either what is specified in arg as int argument.
* _or_ if a 'level' variable is present in vars use that value instead.
* _or_ if a 'level' variable is present in cvv use that value instead.
*/
int
cli_debug_backend(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL){
if ((cv = cvec_find_var(cvv, "level")) == NULL){
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
goto done;
@ -668,11 +707,14 @@ cli_debug_backend(clicon_handle h,
}
/*! Set debug level on restconf daemon
* @param[in] h Clicon handle
* @param[in] vars If variable "level" exists, its integer value is used
*
* @param[in] h Clixon handle
* @param[in] cvv If variable "level" exists, its integer value is used
* @param[in] arg Else use the integer value of argument
* @retval 0 OK
* @retval -1 Error
* @note The level is either what is specified in arg as int argument.
* _or_ if a 'level' variable is present in vars use that value instead.
* _or_ if a 'level' variable is present in cvv use that value instead.
* @notes
* 1. clixon-restconf.yang is used (so that debug config can be set)
* 2. AND the <restconf> XML is in running db not in clixon-config (so that restconf read the new config from backend)
@ -680,14 +722,14 @@ cli_debug_backend(clicon_handle h,
*/
int
cli_debug_restconf(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cg_var *cv;
int level;
if ((cv = cvec_find_var(vars, "level")) == NULL){
if ((cv = cvec_find_var(cvv, "level")) == NULL){
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
goto done;
@ -703,10 +745,16 @@ cli_debug_restconf(clicon_handle h,
/*! Set syntax mode
*
* @param[in] h Clixon handle
* @param[in] cvv
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
*/
int
cli_set_mode(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -724,22 +772,25 @@ cli_set_mode(clicon_handle h,
}
/*! Start bash from cli callback
*
* Typical usage: shell("System Bash") <source:rest>, cli_start_shell();
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv [<shell>], defaults to "sh"
* @retval 0 OK
* @retval -1 Error
*/
int
cli_start_shell(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
char *cmd;
char *shcmd = "sh";
struct passwd *pw;
int retval = -1;
char bcmd[128];
cg_var *cv1 = cvec_i(vars, 1);
cg_var *cv1 = cvec_i(cvv, 1);
sigset_t oldsigset;
struct sigaction oldsigaction[32] = {{{0,},},};
@ -751,7 +802,7 @@ cli_start_shell(clicon_handle h,
if (cvec_len(argv) == 1){
shcmd = cv_string_get(cvec_i(argv, 0));
}
cmd = (cvec_len(vars)>1 ? cv_string_get(cv1) : NULL);
cmd = (cvec_len(cvv)>1 ? cv_string_get(cv1) : NULL);
if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid");
goto done;
@ -798,10 +849,16 @@ cli_start_shell(clicon_handle h,
}
/*! Generic quit callback
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv None expected
* @retval 0 OK
* @retval -1 Error
*/
int
cli_quit(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
cligen_exiting_set(cli_cligen(h), 1);
@ -809,11 +866,16 @@ cli_quit(clicon_handle h,
}
/*! Generic commit callback
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv No arguments expected
* @retval 0 OK
* @retval -1 Error
*/
int
cli_commit(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -824,14 +886,14 @@ cli_commit(clicon_handle h,
int confirmed;
int cancel;
confirmed = (cvec_find_str(vars, "confirmed") != NULL);
cancel = (cvec_find_str(vars, "cancel") != NULL);
if ((timeout_var = cvec_find(vars, "timeout")) != NULL) {
confirmed = (cvec_find_str(cvv, "confirmed") != NULL);
cancel = (cvec_find_str(cvv, "cancel") != NULL);
if ((timeout_var = cvec_find(cvv, "timeout")) != NULL) {
timeout = cv_uint32_get(timeout_var);
clicon_debug(1, "commit confirmed with timeout %ul", timeout);
clixon_debug(CLIXON_DBG_DEFAULT, "commit confirmed with timeout %ul", timeout);
}
persist = cvec_find_str(vars, "persist-val");
persist_id = cvec_find_str(vars, "persist-id-val");
persist = cvec_find_str(cvv, "persist-val");
persist_id = cvec_find_str(cvv, "persist-id-val");
if (clicon_rpc_commit(h, confirmed, cancel, timeout, persist, persist_id) < 1)
goto done;
retval = 0;
@ -840,10 +902,15 @@ cli_commit(clicon_handle h,
}
/*! Generic validate callback
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
*/
int
cli_validate(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -861,6 +928,8 @@ cli_validate(clicon_handle h,
* @param[in] format Output format
* @param[in] db1 Name of first datastrore
* @param[in] db2 Name of second datastrore
* @retval 0 OK
* @retval -1 Error
*/
int
compare_db_names(clicon_handle h,
@ -927,9 +996,12 @@ compare_db_names(clicon_handle h,
}
/*! Compare two dbs using XML. Write to file and run diff
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv
* @param[in] argv <db1> <db2> <format>
* @retval 0 OK
* @retval -1 Error
*/
int
compare_dbs(clicon_handle h,
@ -961,14 +1033,17 @@ compare_dbs(clicon_handle h,
}
/*! Load a configuration file to candidate database
*
* Utility function used by cligen spec file
* Note that the CLI function makes no Validation of the XML sent to the backend
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of variables (where <varname> is found)
* @param[in] argv A string: "<varname> <operation> [<format>]"
* <varname> is name of a variable occuring in "cvv" containing filename
* <operation> : merge or replace
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
* @retval 0 OK
* @retval -1 Error
*
* @note that "filename" is local on client filesystem not backend.
* @note file is assumed to have a dummy top-tag, eg <clicon></clicon>
@ -1136,12 +1211,14 @@ load_config_file(clicon_handle h,
/*! Copy database to local file as XMLn
*
* Utility function used by cligen spec file
* @param[in] h CLICON handle
* @param[in] cvv variable vector (containing <varname>)
* @param[in] argv a string: "<dbname> <varname> [<format>]"
* @param[in] h Clixon handle
* @param[in] cvv Variable vector (containing <varname>)
* @param[in] argv A string: "<dbname> <varname> [<format>]"
* <dbname> is running, candidate, or startup
* <varname> is name of cligen variable in the "cvv" vector containing file name
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
* @retval 0 OK
* @retval -1 Error
* Note that "filename" is local on client filesystem not backend.
* The function can run without a local database
* @note The file is saved with dummy top-tag: clicon: <clicon></clicon>
@ -1249,7 +1326,13 @@ save_config_file(clicon_handle h,
}
/*! Delete all elements in a database
*
* Utility function used by cligen spec file
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
*/
int
delete_all(clicon_handle h,
@ -1288,7 +1371,10 @@ discard_changes(clicon_handle h,
}
/*! Copy from one database to another, eg running->startup
*
* @param[in] argv a string: "<db1> <db2>" Copy from db1 to db2
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
db_copy(clicon_handle h,
@ -1304,8 +1390,11 @@ db_copy(clicon_handle h,
}
/*! This is the callback used by cli_setlog to print log message in CLI
*
* param[in] s UNIX socket from backend where message should be read
* param[in] arg format: txt, xml, xml2txt, xml2json
* @retval 0 OK
* @retval -1 Error
*/
static int
cli_notification_cb(int s,
@ -1361,11 +1450,13 @@ cli_notification_cb(int s,
/*! Make a notify subscription to backend and un/register callback for return messages.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg A string with <log stream name> <stream status> [<format>]
* where <status> is "0" or "1"
* and <format> is XXX
* @retval 0 OK
* @retval -1 Error
* Example code: Start logging of mystream and show logs as xml
* @code
* cmd("comment"), cli_notify("mystream","1","xml");
@ -1377,8 +1468,8 @@ cli_notify(clicon_handle h,
cvec *cvv,
cvec *argv)
{
char *stream = NULL;
int retval = -1;
char *stream = NULL;
int status;
char *formatstr = NULL;
enum format_enum format = FORMAT_TEXT;
@ -1409,9 +1500,11 @@ cli_notify(clicon_handle h,
/*! Lock database
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg A string with <database>
* @retval 0 OK
* @retval -1 Error
* @code
* lock("comment"), cli_lock("running");
* @endcode
@ -1422,8 +1515,8 @@ cli_lock(clicon_handle h,
cvec *cvv,
cvec *argv)
{
char *db;
int retval = -1;
char *db;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
@ -1439,9 +1532,11 @@ cli_lock(clicon_handle h,
/*! Unlock database
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg A string with <database>
* @retval 0 OK
* @retval -1 Error
* @code
* lock("comment"), cli_lock("running");
* @endcode
@ -1452,8 +1547,8 @@ cli_unlock(clicon_handle h,
cvec *cvv,
cvec *argv)
{
char *db;
int retval = -1;
char *db;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
@ -1474,13 +1569,15 @@ cli_unlock(clicon_handle h,
* key name;
* leaf name{...
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv Vector: <db>, <xpath>, <field>, <fromvar>, <tovar>
* @retval 0 OK
* @retval -1 Error
* Explanation of argv fields:
* db: Database name, eg candidate|tmp|startup
* xpath: XPATH expression with exactly two %s pointing to field and from name
* namespace: XPATH default namespace
* xpath: XPath expression with exactly two %s pointing to field and from name
* namespace: XPath default namespace
* field: Name of list key, eg name
* fromvar: Name of variable containing name of object to copy from (given by xpath)
* tovar: Name of variable containing name of object to copy to.
@ -1581,7 +1678,6 @@ cli_copy_config(clicon_handle h,
goto done;
xml_name_set(x2, NETCONF_INPUT_CONFIG);
cprintf(cb, "/%s", keyname);
if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){
clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
goto done;
@ -1608,8 +1704,18 @@ cli_copy_config(clicon_handle h,
return retval;
}
/*! CLI support function for printing comment/help string
*
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg A string with <database>
* @retval 0 OK
* @retval -1 Error
*/
int
cli_help(clicon_handle h, cvec *vars, cvec *argv)
cli_help(clicon_handle h,
cvec *cvv,
cvec *argv)
{
cligen_handle ch = cli_cligen(h);
parse_tree *pt;
@ -1620,9 +1726,11 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv)
/*! CLI support function for restarting a plugin
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg A string with <database>
* @retval 0 OK
* @retval -1 Error
* @code
* restart("comment") , cli_restart_plugin("myplugin", "restart");
* @endcode
@ -1682,6 +1790,8 @@ cvec_append(cvec *cvv0,
*
* @param[in] cvv Input vector
* @param[out] appstr Concatenated string as existing cbuf
* @retval 0 OK
* @retval -1 Error
*/
int
cvec_concat_cb(cvec *cvv,
@ -1717,9 +1827,11 @@ cvec_concat_cb(cvec *cvv,
/*! Process control as defined by clixon-lib API
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg Two strings: <process name> <process operation>
* @retval 0 OK
* @retval -1 Error
* @code
* actions-daemon("Actions daemon operations") start,
* cli_process_control("Action process", "start");

View file

@ -167,9 +167,12 @@ cli_expand_var_generate(clicon_handle h,
}
/*! Create callback with api_path format string as argument
*
* @param[in] h Clixon handle
* @param[in] ys yang_stmt of the node at hand
* @param[out] cb The string where the result format string is inserted.
* @retval 0 OK
* @retval -1 Error
* @see cli_dbxml This is where the xmlkeyfmt string is used
* @see pt_callback_reference in CLIgen where the actual callback overwrites the template
*/
@ -200,6 +203,7 @@ cli_callback_generate(clicon_handle h,
}
/*! Print cligen help string as ("<helpstring>")
*
* @param[in] cb CLIgen buf holding generated CLIspec
* @param[in] helptext Help text
*/
@ -243,10 +247,13 @@ yang2cli_print_alias(cbuf *cb,
}
/*! Generate identityref statements for CLI variables
*
* @param[in] ys Yang statement
* @param[in] ytype Resolved yang type.
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see yang2cli_var_sub Its sub-function
*/
static int
@ -316,10 +323,13 @@ yang2cli_var_identityref(yang_stmt *ys,
}
/*! Generate range check statements for CLI variables
*
* @param[in] ys Yang statement
* @param[in] options Flags field of optional values, eg YANG_OPTIONS_RANGE
* @param[in] cvv Cvec with array of range_min/range_max cv:s (if YANG_OPTIONS_RANGE is set in options)
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see yang2cli_var_sub which is the main function
* In yang ranges are given as range 1 or range 1 .. 16, encoded in a cvv
* 0 : range_min = x
@ -376,9 +386,12 @@ yang2cli_var_range(yang_stmt *ys,
}
/*! Generate CLI code for Yang variable pattern statement
*
* @param[in] h Clixon handle
* @param[in] patterns Cvec of regexp patterns
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see cv_validate_pattern for netconf validate code
* @note for cligen, need to escape " -> \"
*/
@ -439,6 +452,7 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
yang_stmt *ytype, char *helptext, cbuf *cb);
/*! Generate CLI code for Yang leaf state ment to CLIgen variable of specific type
*
* Check for completion (of already existent values), ranges (eg range[min:max]) and
* patterns, (eg regexp:"[0.9]*").
* @param[in] h Clixon handle
@ -451,6 +465,8 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
* @param[in] patterns Cvec of regexp patterns
* @param[in] fraction for decimal64, how many digits after period
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see yang_type_resolve for options and other arguments
*/
static int
@ -481,7 +497,6 @@ yang2cli_var_sub(clicon_handle h,
}
type = ytype?yang_argument_get(ytype):NULL;
cvtypestr = cv_type2str(cvtype);
if (type && strcmp(type, "identityref") == 0)
cprintf(cb, "(");
cprintf(cb, "<%s:%s", yang_argument_get(ys), cvtypestr);
@ -533,6 +548,7 @@ yang2cli_var_sub(clicon_handle h,
}
/*! Resolve a single Yang union and generate code
*
* Part of generating CLI code for Yang leaf statement to CLIgen variable
* @param[in] h Clixon handle
* @param[in] ys Yang statement (caller of type)
@ -540,6 +556,8 @@ yang2cli_var_sub(clicon_handle h,
* @param[in] ytsub Yang type invocation, a sub-type of a resolved union type
* @param[in] cb Buffer where cligen code is written
* @param[in] helptext CLI help text
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_var_union_one(clicon_handle h,
@ -593,6 +611,7 @@ yang2cli_var_union_one(clicon_handle h,
}
/*! Loop over all sub-types of a Yang union
*
* Part of generating CLI code for Yang leaf statement to CLIgen variable
* @param[in] h Clixon handle
* @param[in] ys Yang statement (caller)
@ -600,6 +619,8 @@ yang2cli_var_union_one(clicon_handle h,
* @param[in] ytype Yang resolved type (a union in this case)
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_var_union(clicon_handle h,
@ -688,11 +709,14 @@ yang2cli_var_leafref(clicon_handle h,
}
/*! Generate CLI code for Yang leaf statement to CLIgen variable
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement of original leaf
* @param[in] yreferred Yang statement of referred node for type (leafref)
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*
* Make a type lookup and complete a cligen variable expression such as <a:string>.
* One complication is yang union, that needs a recursion since it consists of
@ -803,12 +827,15 @@ yang2cli_var(clicon_handle h,
}
/*! Generate CLI code for Yang leaf statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[in] callback If set, include a "; cli_set()" callback, otherwise not
* @param[in] key_leaf 0: ordinary leaf, 1:prekey, 2: lastkey
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* Some complexity in callback, key_leaf and extralevel logic.
* If extralevel -> add extra { } level
* + if callbacks add: cb();{}
@ -821,8 +848,8 @@ yang2cli_leaf(clicon_handle h,
int key_leaf,
cbuf *cb)
{
yang_stmt *yd; /* description */
int retval = -1;
yang_stmt *yd; /* description */
char *helptext = NULL;
char *s;
autocli_listkw_t listkw;
@ -905,10 +932,13 @@ yang2cli_leaf(clicon_handle h,
}
/*! Generate CLI code for Yang container statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_container(clicon_handle h,
@ -916,9 +946,9 @@ yang2cli_container(clicon_handle h,
int level,
cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
yang_stmt *yd;
int retval = -1;
char *helptext = NULL;
char *s;
int compress = 0;
@ -977,10 +1007,13 @@ yang2cli_container(clicon_handle h,
}
/*! Generate CLI code for Yang list statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_list(clicon_handle h,
@ -988,13 +1021,13 @@ yang2cli_list(clicon_handle h,
int level,
cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
yang_stmt *yd;
yang_stmt *yleaf;
cg_var *cvi;
char *keyname;
cvec *cvk = NULL; /* vector of index keys */
int retval = -1;
char *helptext = NULL;
char *s;
int last_key = 0;
@ -1081,13 +1114,15 @@ yang2cli_list(clicon_handle h,
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[out] cb Buffer where cligen code is written
@example
* @retval 0 OK
* @retval -1 Error
* @code
choice interface-type {
container ethernet { ... }
container fddi { ... }
}
@example.end
@Note Removes 'meta-syntax' from cli syntax. They are not shown when xml is
* @code.end
@note Removes 'meta-syntax' from cli syntax. They are not shown when xml is
translated to cli. and therefore input-syntax != output syntax. Which is bad
*/
static int
@ -1206,6 +1241,7 @@ yang2cli_uses(clicon_handle h,
}
/*! Generate CLI code for Yang statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
@ -1230,11 +1266,11 @@ yang2cli_stmt(clicon_handle h,
goto done;
}
if (yang_find(ys, Y_STATUS, "obsolete") != NULL){
clicon_debug(4, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
goto ok;
}
if (yang_find(ys, Y_STATUS, "deprecated") != NULL){
clicon_debug(4, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
}
/* Check if autocli skip */
if (yang_extension_value(ys, "skip", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0)
@ -1301,6 +1337,7 @@ yang2cli_stmt(clicon_handle h,
}
/*! Add cv with name to cvec
*
* @param[in] cvv Either existing or NULL
* @param[in] name Name of cv to add
* @retval cvv Either same as in cvv parameter or new
@ -1506,11 +1543,11 @@ yang2cli_grouping(clicon_handle h,
}
/* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */
if (yang_find(ys, Y_STATUS, "obsolete") != NULL){
clicon_debug(4, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
goto empty;
}
if (yang_find(ys, Y_STATUS, "deprecated") != NULL){
clicon_debug(4, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
}
/* Only produce autocli for YANG non-config only if autocli-treeref-state is true */
if (autocli_treeref_state(h, &treeref_state) < 0)
@ -1539,12 +1576,12 @@ yang2cli_grouping(clicon_handle h,
fprintf(stderr, "%s\n", cbuf_get(cb));
goto done;
}
clicon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for grouping:%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for grouping:%s",
__FUNCTION__, yang_argument_get(ys));
/* Add prefix: assume new are appended */
for (i=0; i<pt_len_get(pt); i++){
if ((co = pt_vec_i_get(pt, i)) != NULL){
clicon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
__FUNCTION__, co->co_command);
co_prefix_set(co, prefix);
}
@ -1562,7 +1599,7 @@ yang2cli_grouping(clicon_handle h,
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
else
clicon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
clixon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
clicon_err(OE_YANG, errno, "cligen_parsetree_merge");
@ -1669,12 +1706,12 @@ yang2cli_yspec(clicon_handle h,
fprintf(stderr, "%s\n", cbuf_get(cb));
goto done;
}
clicon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for module:%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for module:%s",
__FUNCTION__, yang_argument_get(ymod));
/* Add prefix: assume new are appended */
for (i=0; i<pt_len_get(pt); i++){
if ((co = pt_vec_i_get(pt, i)) != NULL){
clicon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
__FUNCTION__, co->co_command);
co_prefix_set(co, prefix);
}
@ -1693,7 +1730,7 @@ yang2cli_yspec(clicon_handle h,
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
else
clicon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
clixon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
clicon_err(OE_YANG, errno, "cligen_parsetree_merge");

View file

@ -72,7 +72,8 @@
#define handle(h) (assert(clicon_handle_check(h)==0),(struct cli_handle *)(h))
#define cligen(h) (handle(h)->cl_cligen)
/*! CLI specific handle added to header CLICON handle
/*! CLI specific handle added to header Clixon handle
*
* This file should only contain access functions for the _specific_
* entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c
@ -115,6 +116,8 @@ cli_handle_init(void)
}
/*! Free clicon handle
*
* @param[in] h Clixon handle
*/
int
cli_handle_exit(clicon_handle h)
@ -130,7 +133,10 @@ cli_handle_exit(clicon_handle h)
* cli-specific handle access functions
*----------------------------------------------------------*/
/*! Return clicon handle */
/*! Return clicon handle
*
* @param[in] h Clixon handle
*/
cligen_handle
cli_cligen(clicon_handle h)
{
@ -158,6 +164,7 @@ cli_susp_hook(clicon_handle h,
/* This assume first arg of fn can be treated as void* */
return cligen_susp_hook(ch, fn);
}
int
cli_interrupt_hook(clicon_handle h,
cligen_interrupt_cb_t *fn)

View file

@ -76,8 +76,11 @@
#define CLI_OPTS "+hD:f:E:l:C:F:1a:u:d:m:qp:GLy:c:U:o:"
/*! Check if there is a CLI history file and if so dump the CLI histiry to it
*
* Just log if file does not exist or is not readable
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
static int
cli_history_load(clicon_handle h)
@ -121,8 +124,11 @@ cli_history_load(clicon_handle h)
}
/*! Start CLI history and load from file
*
* Just log if file does not exist or is not readable
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
static int
cli_history_save(clicon_handle h)
@ -157,6 +163,7 @@ cli_history_save(clicon_handle h)
}
/*! Clean and close all state of cli process (but dont exit).
*
* Cannot use h after this
* @param[in] h Clixon handle
*/
@ -226,7 +233,8 @@ cli_signal_init (clicon_handle h)
}
/*! Interactive CLI command loop
* @param[in] h CLICON handle
*
* @param[in] h Clixon handle
* @retval 0
* @retval -1
* @see cligen_loop
@ -269,6 +277,7 @@ cli_interactive(clicon_handle h)
}
/*! Create pre-5.5 tree-refs for backward compatibility
*
* should probably be moved to clispec default
*/
static int
@ -383,7 +392,7 @@ autocli_start(clicon_handle h)
yang_stmt *yspec;
int enable = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* There is no single "enable-autocli" flag,
* but set
* <module-default>false</module-default>
@ -394,7 +403,7 @@ autocli_start(clicon_handle h)
if (autocli_module(h, NULL, &enable) < 0)
goto done;
if (!enable){
clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
goto ok;
}
/* Init yang2cli */
@ -533,7 +542,7 @@ main(int argc,
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Initiate CLICON handle. CLIgen is also initialized */
/* Initiate Clixon handle. CLIgen is also initialized */
if ((h = cli_handle_init()) == NULL)
goto done;
@ -592,7 +601,7 @@ main(int argc,
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Find, read and parse configfile */
@ -802,7 +811,6 @@ main(int argc,
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
@ -868,7 +876,7 @@ main(int argc,
clicon_option_dump(h, 1);
cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING"));
/*! Start CLI history and load from file */
/* Start CLI history and load from file */
if (cli_history_load(h) < 0)
goto done;
/* Experimental utf8 mode */

View file

@ -123,7 +123,7 @@ pipe_arg_fn(clicon_handle h,
/* Grep pipe output function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of options. Format: <option> <value>
* @note Any vertical bar (|] in the patterns field is quoted for OR function
@ -182,9 +182,11 @@ pipe_grep_fn(clicon_handle h,
/*! wc pipe output function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of options. Format: <option> <value>
* @retval 0 OK
* @retval -1 Error
*/
int
pipe_wc_fn(clicon_handle h,
@ -211,9 +213,11 @@ pipe_wc_fn(clicon_handle h,
/*! wc pipe output function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of options. Format: <option> <value>
* @retval 0 OK
* @retval -1 Error
*/
int
pipe_tail_fn(clicon_handle h,
@ -252,12 +256,14 @@ pipe_tail_fn(clicon_handle h,
/*! Output pipe translate from xml to other format: json,text,
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of show options, format:
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum), default: xml
* <pretty> true|false: pretty-print or not
* <prepend> CLI prefix: prepend before cli syntax output
* @retval 0 OK
* @retval -1 Error
* @see cli_show_auto_devs
*/
int

View file

@ -81,8 +81,10 @@
/*! Generate CLIgen parse tree for syntax mode
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] m Syntax mode struct
* @retval 0 OK
* @retval -1 Error
*/
static int
gen_parse_tree(clicon_handle h,
@ -167,9 +169,7 @@ clixon_str2fn(char *name,
*
* @param[in] co CLIgen parse-tree object
* @param[in] arg Argument, cast to application-specific info
* @retval 1 OK and return (abort iteration)
* @retval 0 OK and continue
* @retval -1 Error: break and return
* @retval 0 OK
*/
static int
cli_mark_output_pipes(cg_obj *co,
@ -193,6 +193,8 @@ cli_mark_output_pipes(cg_obj *co,
* @param[in] dir Name of dir, or NULL
* @param[out] ptall Universal CLIgen parse tree: apply to all modes
* @param[out] modes Keep track of all modes
* @retval 0 OK
* @retval -1 Error
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
*/
static int
@ -202,10 +204,10 @@ clispec_load_file(clicon_handle h,
parse_tree *ptall,
cvec *modes)
{
int retval = -1;
void *handle = NULL; /* Handle to plugin .so module */
char *mode = NULL; /* Name of syntax mode to append new syntax */
parse_tree *pt = NULL;
int retval = -1;
FILE *f;
char filepath[MAXPATHLEN];
cvec *cvv = NULL;
@ -369,7 +371,9 @@ done:
*
* CLI .so plugins have been loaded: syntax table in place.
* Now load cligen syntax files and create cligen pt trees.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* XXX The parsetree loading needs a rewrite for multiple parse-trees
*/
int
@ -413,7 +417,7 @@ clispec_load(clicon_handle h)
goto done;
/* Load the syntax parse trees into cli_syntax stx structure */
for (i = 0; i < ndp; i++) {
clicon_debug(CLIXON_DBG_DEFAULT, "Loading clispec syntax: '%s/%s'",
clixon_debug(CLIXON_DBG_DEFAULT, "Loading clispec syntax: '%s/%s'",
clispec_dir, dp[i].d_name);
if (clispec_load_file(h, dp[i].d_name, clispec_dir, ptall, modes) < 0)
goto done;
@ -461,7 +465,8 @@ done:
}
/*! Free resources in plugin
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
int
cli_plugin_finish(clicon_handle h)
@ -470,6 +475,7 @@ cli_plugin_finish(clicon_handle h)
}
/*! Help function to print a meaningful error string.
*
* Sometimes the libraries specify an error string, if so print that.
* Otherwise just print 'command error'.
* But do not print it if error is already logged in eg clicon_err() using STDERR logging
@ -494,6 +500,7 @@ cli_handler_err(FILE *f)
}
/*! Given a command string, parse and if match single command, eval it.
*
* Parse and evaluate the string according to
* the syntax parse tree of the syntax mode specified by *mode.
* If there is no match in the tree for the command, the parse hook
@ -501,7 +508,7 @@ cli_handler_err(FILE *f)
* match is found in another mode, the mode variable is updated to point at
* the new mode string.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cmd Command string
* @param[in,out] modenamep Pointer to the mode string pointer
* @param[out] result CLIgen match result, < 0: errors, >=0 number of matches
@ -546,7 +553,7 @@ clicon_parse(clicon_handle h,
if (cliread_parse(ch, cmd, pt, &match_obj, &cvv, result, &reason) < 0)
goto done;
/* Debug command and result code */
clicon_debug(1, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
clixon_debug(CLIXON_DBG_DEFAULT, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
switch (*result) {
case CG_EOF: /* eof */
case CG_ERROR:
@ -596,6 +603,7 @@ done:
}
/*! Return a malloced expanded prompt string from printf-like format
*
* @param[in] h Clixon handle
* @param[in] fmt Format string, using %H, %
* @retval prompt Malloced string, free after use
@ -693,7 +701,7 @@ cli_prompt_get(clicon_handle h,
/*! Read command from CLIgen's cliread() using current syntax mode.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] ph Parse-tree head
* @param[out] stringp Pointer to command buffer or NULL on EOF
* @retval 1 OK
@ -756,7 +764,8 @@ clicon_cliread(clicon_handle h,
*/
/*! Set syntax mode mode for existing current plugin group.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval 1 OK
* @retval 0 Not found / error
*/
@ -774,7 +783,8 @@ cli_set_syntax_mode(clicon_handle h,
}
/*! Get syntax mode name
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
char *
cli_syntax_mode(clicon_handle h)

View file

@ -201,6 +201,8 @@ xpath_append(cbuf *cb0,
* [<mt-point>] Optional YANG path-arg/xpath from mount-point
* @param[out] commands vector of function pointers to callback functions
* @param[out] helptxt vector of pointers to helptexts
* @retval 0 OK
* @retval -1 Error
* @see cli_expand_var_generate where api_path_fmt + mt-point are generated
*/
int
@ -451,7 +453,14 @@ expand_dbvar(void *h,
return retval;
}
/*! CLI callback show yang spec. If arg given matches yang argument string */
/*! CLI callback show yang spec. If arg given matches yang argument string
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
*/
int
show_yang(clicon_handle h,
cvec *cvv,
@ -495,6 +504,8 @@ show_yang(clicon_handle h,
* @param[in] fromroot If 0, display config from node of XPATH, if 1 display from root
* @param[in] nsc Namespace mapping for xpath
* @param[in] skiptop If set, do not show object itself, only its children
* @retval 0 OK
* @retval -1 Error
*/
int
cli_show_common(clicon_handle h,
@ -722,7 +733,7 @@ cli_show_option_withdefault(cvec *argv,
/*! Generic show configuration callback
*
* Does not need to be used with the autocli as cli_show_auto does
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv String vector of show options, format:
* <dbname> Name of datastore, such as "running"
@ -735,6 +746,8 @@ cli_show_option_withdefault(cvec *argv,
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* @retval 0 OK
* @retval -1 Error
* @code
* clispec:
* show config, cli_show_config("running","xml");
@ -815,25 +828,14 @@ cli_show_config(clicon_handle h,
return retval;
}
/*! Show configuration and state CLIGEN callback function
/*! Show configuration xpath
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv String vector of show options, format:
* <dbname> "running"|"candidate"|"startup"
* @code
* show config id <n:string>, cli_show_config("running","xml","iface[name='foo']","urn:example:example");
* @endcode
* @see cli_show_config_state For config and state data (not only config)
*/
/*! Show configuration as text given an xpath using canonical namespace
*
* Utility function used by cligen spec file
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line must contain xpath and default namespace (if any)
* @param[in] argv A string: <dbname>
* @note Different from cli_show_conf: values taken cvv "xpath" and "ns" instead of argv
* @retval 0 OK
* @retval -1 Error
*/
int
show_conf_xpath(clicon_handle h,
@ -886,7 +888,7 @@ done:
*/
int
cli_show_version(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
cligen_output(stdout, "Clixon: %s\n", CLIXON_VERSION_STRING);
@ -914,6 +916,8 @@ cli_show_version(clicon_handle h,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* <fromroot> true|false: Show from root
* @retval 0 OK
* @retval -1 Error
* @code
* clispec:
* show config @datamodelshow, cli_show_auto("candidate", "xml");
@ -1046,6 +1050,8 @@ cli_show_auto(clicon_handle h,
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* @retval 0 OK
* @retval -1 Error
* @cli_show_auto_ctrl
code
* clispec:
@ -1170,6 +1176,11 @@ cli_show_auto_mode(clicon_handle h,
/*! Show clixon configuration options as loaded
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
'* @see clicon_option_dump clicon_option_dump1
*/
int
@ -1228,9 +1239,12 @@ cli_show_options(clicon_handle h,
}
/*! Show pagination
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. Format: <xpath> <prefix> <namespace> <format> <limit>
* @retval 0 OK
* @retval -1 Error
* Also, if there is a cligen variable called "xpath" it will override argv xpath arg
*/
int
@ -1363,7 +1377,7 @@ cli_pagination(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in,out] cb Cligen buffer to write to
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
@ -1491,11 +1505,13 @@ cli2cbuf(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
* @param[in] fn Callback to make print function
* @retval 0 OK
* @retval -1 Error
*/
static int
cli2file(clicon_handle h,
@ -1618,7 +1634,7 @@ cli2file(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
@ -1660,7 +1676,7 @@ clixon_cli2file(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.

View file

@ -50,6 +50,7 @@ extern "C" {
*/
/*! Called when plugin loaded. Only mandadory callback. All others optional
*
* @see plginit_t
*/
int plugin_init(clicon_handle h);

View file

@ -43,6 +43,7 @@
* Types
*/
/*! Autocli list keyword type, see clixon-autocli.yang list-keyword-type
*
* Assume a YANG LIST:
* list a {
* key x;

View file

@ -97,6 +97,7 @@ leafstring(cxobj *x)
}
/*! Internal recursive part where configuration xml tree is pruned from filter
*
* assume parent has been selected and filter match (same name) as parent
* parent is pruned according to selection.
* @param[in] xfilter Filter xml
@ -190,6 +191,7 @@ xml_filter_recursive(cxobj *xfilter,
}
/*! Remove parts of configuration xml tree that does not match filter xml tree
*
* @param[in] xfilter Filter xml
* @param[out] xconf Configuration xml
* @retval 0 OK

View file

@ -99,6 +99,8 @@ static int _netconf_hello_nr = 0;
* includes any "xmlns" attributes.
* @param[in] xrpc Incoming message on the form <rpc>...
* @param[in,out] xrep Reply message on the form <rpc-reply>...
* @retval 0 OK
* @retval -1 Error
*/
static int
netconf_add_request_attr(cxobj *xrpc,
@ -133,9 +135,14 @@ netconf_add_request_attr(cxobj *xrpc,
}
/*! Process netconf hello message
*
* A server receiving a <hello> message with a <session-id> element MUST
* terminate the NETCONF session.
* @param[in] h Clixon handle
* @param[in] xn
* @param[out] eof Request termination
* @retval 0 OK
* @retval -1 Error
*/
static int
netconf_hello_msg(clicon_handle h,
@ -152,7 +159,7 @@ netconf_hello_msg(clicon_handle h,
int foundbase_11 = 0;
char *body;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
_netconf_hello_nr++;
if (xml_find_type(xn, NULL, "session-id", CX_ELMNT) != NULL) {
clicon_err(OE_XML, errno, "Server received hello with session-id from client, terminating (see RFC 6241 Sec 8.1");
@ -172,12 +179,12 @@ netconf_hello_msg(clicon_handle h,
* event any parameters are encoded at the end of the URI string. */
if (strncmp(body, NETCONF_BASE_CAPABILITY_1_0, strlen(NETCONF_BASE_CAPABILITY_1_0)) == 0){ /* RFC 4741 */
foundbase_10++;
clicon_debug(1, "%s foundbase10", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s foundbase10", __FUNCTION__);
}
else if (strncmp(body, NETCONF_BASE_CAPABILITY_1_1, strlen(NETCONF_BASE_CAPABILITY_1_1)) == 0 &&
clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0){ /* RFC 6241 */
foundbase_11++;
clicon_debug(1, "%s foundbase11", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s foundbase11", __FUNCTION__);
clicon_data_int_set(h, NETCONF_FRAMING_TYPE, NETCONF_SSH_CHUNKED); /* enable chunked enc */
}
}
@ -195,6 +202,7 @@ netconf_hello_msg(clicon_handle h,
}
/*! Process incoming Netconf RPC netconf message
*
* @param[in] h Clixon handle
* @param[in] xreq XML tree containing netconf RPC message
* @param[in] yspec YANG spec
@ -303,6 +311,7 @@ netconf_rpc_message(clicon_handle h,
}
/*! Process incoming a single netconf message parsed as XML
*
* Identify what netconf message it is
* @param[in] h Clixon handle
* @param[in] xreq XML tree containing netconf
@ -325,8 +334,8 @@ netconf_input_packet(clicon_handle h,
cxobj *xret = NULL;
netconf_framing_type framing;
clicon_debug(1, "%s", __FUNCTION__);
clicon_debug_xml(1, xreq, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
clixon_debug_xml(1, xreq, "%s", __FUNCTION__);
rpcname = xml_name(xreq);
rpcprefix = xml_prefix(xreq);
framing = clicon_data_int_get(h, NETCONF_FRAMING_TYPE);
@ -381,8 +390,11 @@ netconf_input_packet(clicon_handle h,
}
/*! Get netconf message: detect end-of-msg
*
* @param[in] s Socket where input arrived. read from this.
* @param[in] arg Clixon handle.
* @retval 0 OK
* @retval -1 Error
* This routine continuously reads until no more data on s. There could
* be risk of starvation, but the netconf client does little else than
* read data so I do not see a danger of true starvation here.
@ -457,14 +469,14 @@ netconf_input_cb(int s,
&eom) < 0)
goto done;
if (eom == 0){ /* frame not complete */
clicon_debug(CLIXON_DBG_DETAIL, "%s: frame: %lu", __FUNCTION__, cbuf_len(cbmsg));
clixon_debug(CLIXON_DBG_DETAIL, "%s: frame: %lu", __FUNCTION__, cbuf_len(cbmsg));
/* Extra data to read, save data and continue on next round */
if (clicon_hash_add(cdat, NETCONF_FRAME_MSG, &cbmsg, sizeof(cbmsg)) == NULL)
goto done;
cbmsg = NULL;
break;
}
clicon_debug(CLIXON_DBG_MSG, "Recv ext: %s", cbuf_get(cbmsg));
clixon_debug(CLIXON_DBG_MSG, "Recv ext: %s", cbuf_get(cbmsg));
if ((ret = netconf_input_frame2(cbmsg, YB_RPC, yspec, &xtop, &xerr)) < 0)
goto done;
cbuf_reset(cbmsg);
@ -499,7 +511,7 @@ netconf_input_cb(int s,
}
}
if (eof){ /* socket closed / read returns 0 */
clicon_debug(1, "%s len==0, closing", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s len==0, closing", __FUNCTION__);
clixon_event_unreg_fd(s, netconf_input_cb);
close(s);
clixon_exit_set(1);
@ -522,8 +534,11 @@ netconf_input_cb(int s,
}
/*! Send netconf hello message
*
* @param[in] h Clixon handle
* @param[in] s File descriptor to write on (eg 1 - stdout)
* @retval 0 OK
* @retval -1 Error
*/
static int
send_hello(clicon_handle h,
@ -553,6 +568,7 @@ send_hello(clicon_handle h,
}
/*! Clean and close all state of netconf process (but dont exit).
*
* Cannot use h after this
* @param[in] h Clixon handle
*/
@ -610,6 +626,7 @@ timeout_fn(int s,
}
/*! Usage help routine
*
* @param[in] h Clixon handle
* @param[in] argv0 command line
*/
@ -713,7 +730,7 @@ main(int argc,
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Find, read and parse configfile */

View file

@ -107,9 +107,12 @@ ok:
}
/*! Get configuration
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
* @param[out] xret Return XML, error or OK
* @retval 0 OK
* @retval -1 Error
* @note filter type subtree and xpath is supported, but xpath is preferred, and
* better performance and tested. Please use xpath.
*
@ -206,13 +209,14 @@ netconf_get_config(clicon_handle h,
}
/*! Get options from netconf edit-config
*
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
* @param[out] op Operation type, eg merge,replace,...
* @param[out] testopt test option, eg set, test
* @param[out] erropt Error option, eg stop-on-error
* @retval -1 Fatal Error
* @retval 0 parameter error, xret returns error
* @retval 1 OK, op, testopt and erropt set
* @retval 0 parameter error, xret returns error
* @retval -1 Fatal Error
* @example
* <edit-config>
* <config>...</config>
@ -267,6 +271,7 @@ get_edit_opts(cxobj *xn,
}
/*! Netconf edit configuration
*
Write the change on a tmp file, then load that into candidate configuration.
<edit-config>
<target>
@ -353,9 +358,11 @@ netconf_edit_config(clicon_handle h,
/*! Get running configuration and device state information
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
* @param[out] xret Return XML, error or OK
* @retval 0 OK
* @retval -1 Error
* @note filter type subtree and xpath is supported, but xpath is preferred, and
* better performance and tested. Please use xpath.
*
@ -414,6 +421,7 @@ netconf_get(clicon_handle h,
}
/*! Called when a notification has happened on backend
*
* and this session has registered for that event.
* Filter it and forward it.
<notification>
@ -451,7 +459,7 @@ netconf_notification_cb(int s,
int ret;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* get msg (this is the reason this function is called) */
if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0)
goto done;
@ -496,7 +504,7 @@ netconf_notification_cb(int s,
ok:
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
if (nsc)
@ -571,10 +579,9 @@ netconf_create_subscription(clicon_handle h,
* @param[in] h clicon handle
* @param[in] xn Sub-tree (under xorig) at child of rpc: <rpc><xn></rpc>.
* @param[out] xret Return XML, error or OK
*
* @retval -1 Error
* @retval 0 OK, not found handler.
* @retval 1 OK, handler called
* @retval 0 OK, not found handler.
* @retval -1 Error
* @see netconf_input_packet Assume bind and validation made there
*/
static int
@ -679,6 +686,7 @@ netconf_application_rpc(clicon_handle h,
}
/*! The central netconf rpc dispatcher. Look at first tag and dispach to sub-functions.
*
* Call plugin handler if tag not found. If not handled by any handler, return
* error.
* @param[in] h clicon handle

View file

@ -172,4 +172,3 @@ http1_scan_exit(clixon_http1_yacc *hy)
clixon_http1_parselex_destroy(); /* modern */
return 0;
}

View file

@ -106,11 +106,11 @@
/* Best debugging is to enable PARSE_DEBUG below and add -d to the LEX compile statement in the Makefile
* And then run the testcase with -D 1
* Disable it to stop any calls to clicon_debug. Having it on by default would mean very large debug outputs.
* Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs.
*/
#if 0
#define _PARSE_DEBUG(s) clicon_debug(1,(s))
#define _PARSE_DEBUG1(s, s1) clicon_debug(1,(s), (s1))
#define _PARSE_DEBUG(s) clixon_debug(1,(s))
#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1))
#else
#define _PARSE_DEBUG(s)
#define _PARSE_DEBUG1(s, s1)
@ -151,7 +151,7 @@ http1_parse_query(clixon_http1_yacc *hy,
int retval = -1;
restconf_stream_data *sd = NULL;
clicon_debug(1, "%s: ?%s ", __FUNCTION__, query);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: ?%s ", __FUNCTION__, query);
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
clicon_err(OE_RESTCONF, 0, "stream 0 not found");
goto done;
@ -170,7 +170,7 @@ http1_body(clixon_http1_yacc *hy,
int retval = -1;
restconf_stream_data *sd = NULL;
clicon_debug(1, "%s: %s ", __FUNCTION__, body);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s ", __FUNCTION__, body);
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
clicon_err(OE_RESTCONF, 0, "stream 0 not found");
goto done;
@ -331,7 +331,7 @@ HTTP_version : HTTP SLASH DIGIT DOT DIGIT
/* make sanity check later */
_HY->hy_rc->rc_proto_d1 = $3;
_HY->hy_rc->rc_proto_d2 = $5;
clicon_debug(1, "clixon_http1_parse: http/%d.%d", $3, $5);
clixon_debug(CLIXON_DBG_DEFAULT, "clixon_http1_parse: http/%d.%d", $3, $5);
_PARSE_DEBUG("HTTP-version -> HTTP / DIGIT . DIGIT");
}
;

View file

@ -87,8 +87,8 @@ static const map_str2str mime_map[] = {
/*! Check if uri path denotes a data path
*
* @param[in] h Clixon handle
* @retval 0 No, not a data path, or not enabled
* @retval 1 Yes, a data path and "data" points to www-data if given
* @retval 0 No, not a data path, or not enabled
*/
int
api_path_is_data(clicon_handle h)
@ -117,6 +117,7 @@ api_path_is_data(clicon_handle h)
}
/*! Generic restconf error function on get/head request
*
* @param[in] h Clixon handle
* @param[in] req Generic http handle
* @param[in] code Error code
@ -130,7 +131,7 @@ api_http_data_err(clicon_handle h,
int retval = -1;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -152,23 +153,24 @@ api_http_data_err(clicon_handle h,
// ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
return retval;
}
/*! Check validity of path, may only be regular dir or file
*
* No .., soft link, ~, etc
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] prefix Prefix of path0, where to start file check
* @param[in,out] cbpath Filepath as cbuf, internal redirection may change it
* @param[out] fp Open file, if retval = 1
* @param[out] fsz Size of file, if retval = 1
* @retval -1 Error
* @retval 0 Invalid
* @retval 1 OK, fp,fsz set
* @retval 0 Invalid
* @retval -1 Error
*/
static int
http_data_check_file_path(clicon_handle h,
@ -190,7 +192,7 @@ http_data_check_file_path(clicon_handle h,
goto done;
}
p = cbuf_get(cbpath);
clicon_debug(1, "%s %s", __FUNCTION__, p);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, p);
if (strncmp(prefix, p, strlen(prefix)) != 0){
clicon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath");
goto done;
@ -200,31 +202,31 @@ http_data_check_file_path(clicon_handle h,
p[i] = '\0';
/* Ensure not soft link */
if (lstat(p, &fstat) < 0){
clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
code = 404;
goto invalid;
}
if (!S_ISDIR(fstat.st_mode)){
clicon_debug(1, "%s Error lstat(%s): Not dir", __FUNCTION__, p);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s): Not dir", __FUNCTION__, p);
code = 403;
goto invalid;
}
p[i] = '/';
}
else if (p[i] == '~'){
clicon_debug(1, "%s Error lstat(%s): ~ not allowed in file path", __FUNCTION__, p);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s): ~ not allowed in file path", __FUNCTION__, p);
code = 403;
goto invalid;
}
else if (p[i] == '.' && i>strlen(prefix) && p[i-1] == '.'){
clicon_debug(1, "%s Error lstat(%s): .. not allowed in file path", __FUNCTION__, p);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s): .. not allowed in file path", __FUNCTION__, p);
code = 403;
goto invalid;
}
}
/* Resulting file (ensure not soft link) */
if (lstat(p, &fstat) < 0){
clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
code = 404;
goto invalid;
}
@ -233,22 +235,22 @@ http_data_check_file_path(clicon_handle h,
if (S_ISDIR(fstat.st_mode)){
cprintf(cbpath, "/%s", HTTP_DATA_INTERNAL_REDIRECT);
p = cbuf_get(cbpath);
clicon_debug(1, "%s internal redirect: %s", __FUNCTION__, p);
clixon_debug(CLIXON_DBG_DEFAULT, "%s internal redirect: %s", __FUNCTION__, p);
if (lstat(p, &fstat) < 0){
clicon_debug(1, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s):%s", __FUNCTION__, p, strerror(errno));
code = 404;
goto invalid;
}
}
#endif
if (!S_ISREG(fstat.st_mode)){
clicon_debug(1, "%s Error lstat(%s): Not regular file", __FUNCTION__, p);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error lstat(%s): Not regular file", __FUNCTION__, p);
code = 403;
goto invalid;
}
*fsz = fstat.st_size;
if ((f = fopen(p, "rb")) == NULL){
clicon_debug(1, "%s Error fopen(%s) %s", __FUNCTION__, p, strerror(errno));
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error fopen(%s) %s", __FUNCTION__, p, strerror(errno));
code = 403;
goto invalid;
}
@ -264,10 +266,13 @@ http_data_check_file_path(clicon_handle h,
}
/*! Read file data request
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] pathname With stripped prefix (eg /data), ultimately a filename
* @param[in] head HEAD not GET
* @retval 0 OK
* @retval -1 Error
* @note: primitive file handling, just check if file exists and read it all
* XXX 1: Buffer copying once too many, see #if 0 below
*/
@ -291,7 +296,7 @@ api_http_data_file(clicon_handle h,
char *buf = NULL;
size_t sz;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cbfile = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -304,7 +309,7 @@ api_http_data_file(clicon_handle h,
cprintf(cbfile, "%s", www_data_root);
if (pathname){
if (strlen(pathname) && pathname[0] != '/'){
clicon_debug(1, "%s Error fopen(%s) pathname not prefixed with /",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error fopen(%s) pathname not prefixed with /",
__FUNCTION__, pathname);
if (api_http_data_err(h, req, 404) < 0)
goto done;
@ -333,7 +338,7 @@ api_http_data_file(clicon_handle h,
fsize = ftell(f);
/* Extra sanity check, had some problems with wrong file types */
if (fsz != fsize){
clicon_debug(1, "%s Error file %s size mismatch sz:%zu vs %li",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error file %s size mismatch sz:%zu vs %li",
__FUNCTION__, filename, (size_t)fsz, fsize);
if (api_http_data_err(h, req, 500) < 0) /* Internal error? */
goto done;
@ -357,7 +362,7 @@ api_http_data_file(clicon_handle h,
}
sz = (size_t)ret;
if (sz != 1){
clicon_debug(1, "%s Error fread(%s) sz:%zu", __FUNCTION__, filename, sz);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error fread(%s) sz:%zu", __FUNCTION__, filename, sz);
if (api_http_data_err(h, req, 500) < 0) /* Internal error? */
goto done;
goto ok;
@ -371,7 +376,7 @@ api_http_data_file(clicon_handle h,
if (restconf_reply_send(req, 200, cbdata, head) < 0)
goto done;
cbdata = NULL; /* consumed by reply-send */
clicon_debug(1, "%s Read %s OK", __FUNCTION__, filename);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Read %s OK", __FUNCTION__, filename);
ok:
retval = 0;
done:
@ -396,10 +401,12 @@ api_http_data_file(clicon_handle h,
* 5. indata should be NULL (no write operations)
* 6. Limited media: text/html, JavaScript, image, and css
* 7. Authentication as restconf
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] qvec Query parameters, ie the ?<id>=<val>&<id>=<val> stuff
* @param[in] pathname With stripped prefix (eg /data), ultimately a filename
* @retval 0 OK
* @retval -1 Error
* Need to enable clixon-restconf.yang www-data feature
*/
int
@ -416,7 +423,7 @@ api_http_data(clicon_handle h,
cbuf *indata = NULL;
char *path = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (req == NULL){
errno = EINVAL;
goto done;
@ -491,6 +498,6 @@ api_http_data(clicon_handle h,
done:
if (path)
free(path);
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}

View file

@ -45,6 +45,7 @@ extern "C" {
* Types
*/
/*! RESTCONF media types
*
* @see http_media_map
* @note DUPLICATED in restconf_lib.h
*/

View file

@ -69,6 +69,7 @@
/*! HTTP headers done, if there is a message body coming next
*
* @param[in] req Fastcgi request handle
* @retval body Handle for body handling (in fcgi same as req)
*
@ -86,9 +87,12 @@ restconf_reply_body_start(void *req0)
}
/*! Add HTTP header field name and value to reply, fcgi specific
*
* @param[in] req Fastcgi request handle
* @param[in] name HTTP header field name
* @param[in] vfmt HTTP header field value format string w variable parameter
* @retval 0 OK
* @retval -1 Error
* @see eg RFC 7230
*/
int
@ -132,9 +136,12 @@ restconf_reply_header(void *req0,
}
/*! Add HTTP message body to reply, fcgi specific
*
* @param[in] req Fastcgi request handle
* @param[in,out] content_len This is for Content-Length header
* @param[in] bfmt HTTP message body format string w variable parameter
* @retval 0 OK
* @retval -1 Error
* @see eg RFC 7230
*/
int
@ -184,12 +191,14 @@ restconf_reply_body_add(void *req0,
}
/*! Send HTTP reply with potential message body
*
* Prerequisites: status code set, headers given, body if wanted set
* @param[in] req Fastcgi request handle
* @param[in] code Status code
* @param[in] cb Body as a cbuf if non-NULL. Note is consumed
* @param[in] head Only send headers, dont send body.
*
* Prerequisites: status code set, headers given, body if wanted set
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_reply_send(void *req0,
@ -222,6 +231,7 @@ restconf_reply_send(void *req0,
}
/*! Get input data from http request, eg such as curl -X PUT http://... <indata>
*
* @param[in] req Fastcgi request handle
* @retval indata
* @retval NULL Error

View file

@ -65,9 +65,12 @@
#include "restconf_native.h"
/*! Add HTTP header field name and value to reply
*
* @param[in] req request handle
* @param[in] name HTTP header field name
* @param[in] vfmt HTTP header field value format string w variable parameter
* @retval 0 OK
* @retval -1 Error
* @see eg RFC 7230
*/
int
@ -83,7 +86,7 @@ restconf_reply_header(void *req0,
char *value = NULL;
va_list ap;
clicon_debug(1, "%s %s", __FUNCTION__, name);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name);
if (sd == NULL || name == NULL || vfmt == NULL){
clicon_err(OE_CFG, EINVAL, "sd, name or value is NULL");
goto done;
@ -121,11 +124,13 @@ restconf_reply_header(void *req0,
}
/*! Send HTTP reply with potential message body
*
* @param[in] req http request handle
* @param[in] code Status code
* @param[in] cb Body as a cbuf if non-NULL. Note: is consumed
* @param[in] head Only send headers, dont send body.
*
* @retval 0 OK
* @retval -1 Error
* Prerequisites: status code set, headers given, body if wanted set
*/
int
@ -137,7 +142,7 @@ restconf_reply_send(void *req0,
int retval = -1;
restconf_stream_data *sd = (restconf_stream_data *)req0;
clicon_debug(1, "%s code:%d", __FUNCTION__, code);
clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code);
if (sd == NULL){
clicon_err(OE_CFG, EINVAL, "sd is NULL");
goto done;
@ -167,6 +172,7 @@ restconf_reply_send(void *req0,
}
/*! Get input data from http request, eg such as curl -X PUT http://... <indata>
*
* @param[in] req Request handle
* @note: reuses cbuf from stream-data
*/

View file

@ -70,10 +70,13 @@
#include "restconf_err.h"
/*! HTTP error 405 Not Allowed
*
* @param[in] req Generic http handle
* @param[in] allow Which methods are allowed
* @param[in] pretty Pretty-print of reply
* @param[in] media_out Restconf output media
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_method_notallowed(clicon_handle h,
@ -100,7 +103,10 @@ restconf_method_notallowed(clicon_handle h,
}
/*! HTTP error 415 Unsupported media
*
* @param[in] req Generic http handle
* @retval 0 OK
* @retval -1 Error
* RFC8040, section 5.2:
* If the server does not support the requested input encoding for a request, then it MUST
* return an error response with a "415 Unsupported Media Type" status-line
@ -129,7 +135,9 @@ restconf_unsupported_media(clicon_handle h,
/*! HTTP error 406 Not acceptable
*
* @param[in] req Generic http handle
* RFC8040, section 5.2:
* @retval 0 OK
* @retval -1 Error
* @see RFC8040, section 5.2:
* If the server does not support any of the requested output encodings for a request, then it MUST
* return an error response with a "406 Not Acceptable" status-line.
*/
@ -179,6 +187,7 @@ restconf_notimplemented(clicon_handle h,
}
/*! Generic restconf error function on get/head request
*
* @param[in] h Clixon handle
* @param[in] req Generic http handle
* @param[in] xerr XML error message (eg from backend, or from a clixon_netconf_lib function)
@ -186,6 +195,8 @@ restconf_notimplemented(clicon_handle h,
* @param[in] media Output media
* @param[in] code If 0 use rfc8040 sec 7 netconf2restconf error-tag mapping
* otherwise use this code
* @retval 0 OK
* @retval -1 Error
* xerr should be on the form: <rpc-error>... otherwise an internal error is generated
* @note there are special cases see code
*/
@ -207,7 +218,7 @@ api_return_err(clicon_handle h,
cxobj *xmsg;
char *mb;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -238,7 +249,7 @@ api_return_err(clicon_handle h,
}
}
#if 1
clicon_debug_xml(1, xerr, "%s Send error:", __FUNCTION__);
clixon_debug_xml(CLIXON_DBG_DEFAULT, xerr, "%s Send error:", __FUNCTION__);
#endif
if (xml_name_set(xerr, "error") < 0)
goto done;
@ -275,7 +286,7 @@ api_return_err(clicon_handle h,
case YANG_DATA_XML:
case YANG_PATCH_XML:
case YANG_PAGINATION_XML:
clicon_debug(1, "%s code:%d", __FUNCTION__, code);
clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code);
if (pretty){
cprintf(cb, " <errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">\n");
if (clixon_xml2cbuf(cb, xerr, 2, pretty, NULL, -1, 0) < 0)
@ -291,7 +302,7 @@ api_return_err(clicon_handle h,
break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
clicon_debug(1, "%s code:%d", __FUNCTION__, code);
clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code);
if (pretty){
cprintf(cb, "{\n\"ietf-restconf:errors\" : ");
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
@ -318,7 +329,7 @@ api_return_err(clicon_handle h,
// ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
if (cberr)
@ -337,6 +348,8 @@ api_return_err(clicon_handle h,
* @param[in] media Output media
* @param[in] code If 0 use rfc8040 sec 7 netconf2restconf error-tag mapping
* otherwise use this code
* @retval 0 OK
* @retval -1 Error
* @see api_return_err where top level is expected to be <rpc-error>
*/
int

View file

@ -77,6 +77,7 @@
* entries in the struct below.
*/
/*! Backend specific handle added to header CLICON handle
*
* This file should only contain access functions for the _specific_
* entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c
@ -110,6 +111,7 @@ restconf_handle_init(void)
}
/*! Deallocates a backend handle, including all client structs
*
* @note: handle 'h' cannot be used in calls after this
* @see backend_client_rm
*/
@ -125,7 +127,8 @@ restconf_handle_exit(clicon_handle h)
}
/*! Get restconf http parameter
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @retval val Data value as string
* Currently using clixon runtime data but there is risk for colliding names
@ -142,7 +145,8 @@ restconf_param_get(clicon_handle h,
}
/*! Set restconf http parameter
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[in] val Data value as null-terminated string
* @retval 0 OK
@ -156,7 +160,7 @@ restconf_param_set(clicon_handle h,
{
struct restconf_handle *rh = handle(h);
clicon_debug(1, "%s: %s=%s", __FUNCTION__, param, val);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s=%s", __FUNCTION__, param, val);
if (rh->rh_params == NULL)
if ((rh->rh_params = clicon_hash_init()) == NULL)
return -1;
@ -164,7 +168,8 @@ restconf_param_set(clicon_handle h,
}
/*! Delete all restconf http parameter
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @retval 0 OK
* @retval -1 Error
@ -187,7 +192,8 @@ restconf_param_del_all(clicon_handle h)
}
/*! Get restconf http parameter
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval auth_type
*/
clixon_auth_type_t
@ -199,7 +205,8 @@ restconf_auth_type_get(clicon_handle h)
}
/*! Set restconf http parameter
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[in] val Data value as null-terminated string
* @retval 0 OK
@ -217,7 +224,8 @@ restconf_auth_type_set(clicon_handle h,
}
/*! Get restconf pretty-print (for replies)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval pretty
*/
int
@ -229,7 +237,8 @@ restconf_pretty_get(clicon_handle h)
}
/*! Set restconf pretty-print
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] pretty 0 or 1
* @retval 0 OK
* @retval -1 Error
@ -245,6 +254,7 @@ restconf_pretty_set(clicon_handle h,
}
/*! Get restconf http-data
*
* @param[in] h Clixon handle
* @retval 0 Yes, http-data enabled
* @retval 1 No, http-data disabled
@ -258,6 +268,7 @@ restconf_http_data_get(clicon_handle h)
}
/*! Set restconf http-data
*
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
@ -273,7 +284,8 @@ restconf_http_data_set(clicon_handle h,
}
/*! Get restconf fcgi socket path
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval socketpath
*/
char*
@ -285,7 +297,8 @@ restconf_fcgi_socket_get(clicon_handle h)
}
/*! Set restconf fcgi socketpath
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[in] val Data value as null-terminated string
* @retval 0 OK

View file

@ -90,7 +90,7 @@ _http1_parse(clicon_handle h,
clixon_http1_yacc hy = {0,};
int ret;
clicon_debug(1, "%s:\n%s", __FUNCTION__, str);
clixon_debug(CLIXON_DBG_DEFAULT, "%s:\n%s", __FUNCTION__, str);
if (strlen(str) == 0)
goto ok;
hy.hy_parse_string = str;
@ -119,7 +119,7 @@ _http1_parse(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}
@ -147,7 +147,7 @@ clixon_http1_parse_file(clicon_handle h,
int len = 0;
int oldbuflen;
clicon_debug(1, "%s %s", __FUNCTION__, filename);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename);
if (f == NULL){
clicon_err(OE_RESTCONF, EINVAL, "f is NULL");
goto done;
@ -239,6 +239,7 @@ clixon_http1_parse_buf(clicon_handle h,
#ifdef HAVE_LIBNGHTTP2
/*! Check http/1 UPGRADE to http/2
*
* If upgrade headers are encountered AND http/2 is configured, then
* - add upgrade headers or signal error
* - set http2 flag get settings to and signal to upper layer to do the actual transition.
@ -301,7 +302,7 @@ restconf_http1_reply(restconf_conn *rc,
int retval = -1;
cg_var *cv;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* If body, add a content-length header
* A server MUST NOT send a Content-Length header field in any response
* with a status code of 1xx (Informational) or 204 (No Content). A
@ -342,9 +343,12 @@ restconf_http1_reply(restconf_conn *rc,
return retval;
}
/*!
/*! restconf http1 path root
*
* @param[in] h Clixon handle
* @param[in] rc Clixon request connect pointer
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_http1_path_root(clicon_handle h,
@ -361,7 +365,7 @@ restconf_http1_path_root(clicon_handle h,
int ret;
#endif
clicon_debug(1, "------------");
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
pretty = restconf_pretty_get(h);
if ((sd = restconf_stream_find(rc, 0)) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "No stream_data");
@ -459,7 +463,7 @@ restconf_http1_path_root(clicon_handle h,
goto done;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (subject)
free(subject);
if (xerr)

View file

@ -322,6 +322,8 @@ restconf_convert_hdr(clicon_handle h,
* @param[in] cookiestr cookie string according to rfc6265 (modified)
* @param[in] attribute cookie attribute
* @param[out] val malloced cookie value, free with free()
* @retval 0 OK
* @retval -1 Error
*/
int
get_user_cookie(char *cookiestr,
@ -358,7 +360,7 @@ restconf_terminate(clicon_handle h)
cxobj *x;
int fs; /* fgcx socket */
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((fs = clicon_socket_get(h)) != -1)
close(fs);
/* Delete all plugins, and RPC callbacks */
@ -376,8 +378,8 @@ restconf_terminate(clicon_handle h)
xpath_optimize_exit();
restconf_handle_exit(h);
clixon_err_exit();
clicon_debug(1, "%s pid:%u done", __FUNCTION__, getpid());
clicon_log_exit(); /* Must be after last clicon_debug */
clixon_debug(CLIXON_DBG_DEFAULT, "%s pid:%u done", __FUNCTION__, getpid());
clicon_log_exit(); /* Must be after last clixon_debug */
return 0;
}
@ -522,7 +524,7 @@ restconf_main_extension_cb(clicon_handle h,
extname = yang_argument_get(yext);
if (strcmp(modname, "ietf-restconf") != 0 || strcmp(extname, "yang-data") != 0)
goto ok;
clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
if ((yc = yang_find(ys, 0, NULL)) == NULL)
goto ok;
if ((yn = ys_dup(yc)) == NULL)
@ -566,7 +568,9 @@ restconf_uripath(clicon_handle h)
/*! Drop privileges from root to user (or already at user)
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* Group set to CLICON_SOCK_GROUP to communicate with backend
*/
int
@ -580,7 +584,7 @@ restconf_drop_privileges(clicon_handle h)
char *user;
enum priv_mode_t priv_mode = PM_NONE;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Sanity check: backend group exists */
if ((group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set");
@ -635,7 +639,7 @@ restconf_drop_privileges(clicon_handle h)
case PM_NONE:
break; /* catched above */
}
clicon_debug(1, "%s dropped privileges from root to %s(%d)",
clixon_debug(CLIXON_DBG_DEFAULT, "%s dropped privileges from root to %s(%d)",
__FUNCTION__, user, newuid);
ok:
retval = 0;
@ -643,8 +647,9 @@ restconf_drop_privileges(clicon_handle h)
return retval;
}
/*!
* @param[in] h Clicon handle
/*! restconf auth cb
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] pretty Pretty-print
* @param[in] media_out Restconf output media
@ -668,7 +673,7 @@ restconf_authentication_cb(clicon_handle h,
char *anonymous = NULL;
auth_type = restconf_auth_type_get(h);
clicon_debug(1, "%s auth-type:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
clixon_debug(CLIXON_DBG_DEFAULT, "%s auth-type:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
ret = 0;
authenticated = 0;
/* ret: -1 Error, 0: Ignore/not handled, 1: OK see authenticated parameter */
@ -720,7 +725,7 @@ restconf_authentication_cb(clicon_handle h,
/* If set but no user, set a dummy user */
retval = 1;
done:
clicon_debug(1, "%s retval:%d authenticated:%d user:%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d authenticated:%d user:%s",
__FUNCTION__, retval, authenticated, clicon_username_get(h));
if (username)
free(username);
@ -763,7 +768,7 @@ restconf_config_init(clicon_handle h,
if ((x = xpath_first(xrestconf, nsc, "enable")) != NULL &&
(enable = xml_body(x)) != NULL){
if (strcmp(enable, "false") == 0){
clicon_debug(1, "%s restconf disabled", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf disabled", __FUNCTION__);
goto disable;
}
}
@ -825,6 +830,8 @@ restconf_config_init(clicon_handle h,
* @param[in] backlog Listen backlog, queie of pending connections
* @param[in] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[out] ss Server socket (bound for accept)
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_socket_init(const char *netns0,
@ -841,7 +848,7 @@ restconf_socket_init(const char *netns0,
size_t sa_len;
const char *netns;
clicon_debug(1, "%s %s %s %s %hu", __FUNCTION__, netns0, addrtype, addrstr, port);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %s %s %hu", __FUNCTION__, netns0, addrtype, addrstr, port);
/* netns default -> NULL */
if (netns0 != NULL && strcmp(netns0, RESTCONF_NETNS_DEFAULT)==0)
netns = NULL;
@ -851,10 +858,10 @@ restconf_socket_init(const char *netns0,
goto done;
if (clixon_netns_socket(netns, sa, sa_len, backlog, flags, addrstr, ss) < 0)
goto done;
clicon_debug(1, "%s ss=%d", __FUNCTION__, *ss);
clixon_debug(CLIXON_DBG_DEFAULT, "%s ss=%d", __FUNCTION__, *ss);
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}

View file

@ -45,6 +45,7 @@ extern "C" {
* Types
*/
/*! RESTCONF media types
*
* @see http_media_map
* @note DUPLICATED in clixon_restconf.h
*/

View file

@ -91,8 +91,11 @@
#define RESTCONF_OPTS "hD:f:E:l:C:p:d:y:a:u:rW:R:o:"
/*! Convert FCGI parameters to clixon runtime data
*
* @param[in] h Clixon handle
* @param[in] envp Fastcgi request handle parameter array on the format "<param>=<value>"
* @retval 0 OK
* @retval -1 Error
* @see https://nginx.org/en/docs/http/ngx_http_core_module.html#var_https
*/
static int
@ -104,7 +107,7 @@ fcgi_params_set(clicon_handle h,
char *param = NULL;
char *val = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
for (i = 0; envp[i] != NULL; i++){ /* on the form <param>=<value> */
if (clixon_strsplit(envp[i], '=', &param, &val) < 0)
goto done;
@ -121,7 +124,7 @@ fcgi_params_set(clicon_handle h,
}
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}
@ -144,7 +147,7 @@ restconf_main_config(clicon_handle h,
/* 1. try inline configure option */
if (inline_config != NULL && strlen(inline_config)){
clicon_debug(1, "restconf_main_fcgi using restconf inline config");
clixon_debug(CLIXON_DBG_DEFAULT, "restconf_main_fcgi using restconf inline config");
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
goto done;
if (ret == 0){
@ -217,19 +220,19 @@ static clicon_handle _CLICON_HANDLE = NULL;
*/
static int _MYSOCK;
/*! Signall terminates process
/*! Signal terminates process
*/
static void
restconf_sig_term(int arg)
{
static int i=0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (i++ == 0)
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
__PROGRAM__, __FUNCTION__, getpid(), arg);
else{
clicon_debug(1, "%s done", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
exit(-1);
}
@ -242,6 +245,7 @@ restconf_sig_term(int arg)
}
/*! Reap stream child
*
* XXX The -1 should be changed to proper pid, see eg clixon_process_waitpid
*/
static void
@ -255,8 +259,9 @@ restconf_sig_child(int arg)
}
/*! Usage help routine
*
* @param[in] h Clixon handle
* @param[in] argv0 command line
* @param[in] h Clicon handle
*/
static void
usage(clicon_handle h,
@ -360,7 +365,7 @@ main(int argc,
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
clicon_log(LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal");
@ -561,7 +566,7 @@ main(int argc,
clicon_err(OE_CFG, errno, "FCGX_Init");
goto done;
}
clicon_debug(1, "restconf_main: Opening FCGX socket: %s", sockpath);
clixon_debug(CLIXON_DBG_DEFAULT, "restconf_main: Opening FCGX socket: %s", sockpath);
if ((sock = FCGX_OpenSocket(sockpath, 10)) < 0){
clicon_err(OE_CFG, errno, "FCGX_OpenSocket");
goto done;
@ -608,7 +613,7 @@ main(int argc,
clicon_err(OE_CFG, errno, "FCGX_Accept_r");
goto done;
}
clicon_debug(1, "------------");
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
/* Translate from FCGI parameter form to Clixon runtime data
* XXX: potential name collision?
@ -616,7 +621,7 @@ main(int argc,
if (fcgi_params_set(h, req->envp) < 0)
goto done;
if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){
clicon_debug(1, "NULL URI");
clixon_debug(CLIXON_DBG_DEFAULT, "NULL URI");
}
else {
/* Matching algorithm:
@ -648,7 +653,7 @@ main(int argc,
(void)api_stream(h, req, qvec, &finish);
}
else{
clicon_debug(1, "top-level %s not found", path);
clixon_debug(CLIXON_DBG_DEFAULT, "top-level %s not found", path);
if (netconf_invalid_value_xml(&xerr, "protocol", "Top-level path not found") < 0)
goto done;
if (api_return_err0(h, req, xerr, 1, YANG_DATA_JSON, 0) < 0)

View file

@ -180,8 +180,10 @@ static int session_id_context = 1;
/*! Set restconf native handle
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] rh Restconf native handle (malloced pointer)
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_native_handle_set(clicon_handle h,
@ -215,7 +217,7 @@ clixon_openssl_log_cb(void *handle,
int suberr,
cbuf *cb)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
ERR_print_errors_cb(print_cb, cb);
return 0;
}
@ -241,7 +243,8 @@ init_openssl(void)
return retval;
}
/*!
/*! Verify cert
*
* The verify_callback function is used to control the behaviour when the SSL_VERIFY_PEER flag
* is set. It must be supplied by the application and receives two arguments: preverify_ok
* indicates, whether the verification of the certificate in question was passed
@ -258,23 +261,22 @@ restconf_verify_certs(int preverify_ok,
int depth;
// SSL *ssl;
// clicon_handle h;
err_cert = X509_STORE_CTX_get_current_cert(store);
err = X509_STORE_CTX_get_error(store);
depth = X509_STORE_CTX_get_error_depth(store);
// ssl = X509_STORE_CTX_get_ex_data(store, SSL_get_ex_data_X509_STORE_CTX_idx());
clicon_debug(1, "%s preverify_ok:%d err:%d depth:%d", __FUNCTION__, preverify_ok, err, depth);
clixon_debug(CLIXON_DBG_DEFAULT, "%s preverify_ok:%d err:%d depth:%d", __FUNCTION__, preverify_ok, err, depth);
X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
switch (err){
case X509_V_ERR_HOSTNAME_MISMATCH:
clicon_debug(1, "%s X509_V_ERR_HOSTNAME_MISMATCH", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s X509_V_ERR_HOSTNAME_MISMATCH", __FUNCTION__);
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
clicon_debug(1, "%s X509_V_ERR_CERT_HAS_EXPIRED", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s X509_V_ERR_CERT_HAS_EXPIRED", __FUNCTION__);
break;
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
clicon_debug(1, "%s X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT", __FUNCTION__);
break;
}
/* Catch a too long certificate chain. should be +1 in SSL_CTX_set_verify_depth() */
@ -303,7 +305,7 @@ alpn_proto_dump(const char *label,
const char *inp,
unsigned len)
{
clicon_debug(1, "%s %.*s", label, (int)len, inp);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %.*s", label, (int)len, inp);
return 0;
}
@ -325,13 +327,13 @@ alpn_select_proto_cb(SSL *ssl,
unsigned char len;
int pref = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* select http/1.1 */
inp = (unsigned char*)in;
while ((inp-in) < inlen) {
len = *inp;
inp++;
if (clicon_debug_get()) /* debug print the protoocol */
if (clixon_debug_get()) /* debug print the protoocol */
alpn_proto_dump(__FUNCTION__, (const char*)inp, len);
#ifdef HAVE_HTTP1
if (pref < 10 && len == 8 && strncmp((char*)inp, "http/1.1", len) == 0){
@ -454,18 +456,18 @@ restconf_listcerts(SSL *ssl)
X509 *cert;
char *line;
clicon_debug(1, "%s get peer certificates:", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s get peer certificates:", __FUNCTION__);
if ((cert = SSL_get_peer_certificate(ssl)) != NULL) { /* Get certificates (if available) */
if ((line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0)) != NULL){
clicon_debug(1, "Subject: %s", line);
clixon_debug(CLIXON_DBG_DEFAULT, "Subject: %s", line);
free(line);
}
if ((line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0)) != NULL){
clicon_debug(1, "Issuer: %s", line);
clixon_debug(CLIXON_DBG_DEFAULT, "Issuer: %s", line);
free(line);
}
if ((line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0)) != NULL){
clicon_debug(1, "Subject: %s", line);
clixon_debug(CLIXON_DBG_DEFAULT, "Subject: %s", line);
free(line);
}
X509_free(cert);
@ -515,6 +517,8 @@ restconf_checkcert_file(cxobj *xrestconf,
*
* @param[in] fd Socket (unix or ip)
* @param[in] arg typecast clicon_handle
* @retval 0 OK
* @retval -1 Error
* @see openssl_init_socket where this callback is registered
*/
static int
@ -530,7 +534,7 @@ restconf_accept_client(int fd,
char *name = NULL;
void *addr;
clicon_debug(1, "%s %d", __FUNCTION__, fd);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, fd);
if ((rsock = (restconf_socket *)arg) == NULL){
clicon_err(OE_YANG, EINVAL, "rsock is NULL");
goto done;
@ -566,7 +570,7 @@ restconf_accept_client(int fd,
}
if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) < 0)
goto done;
clicon_debug(1, "%s type:%s from:%s, dest:%s port:%hu", __FUNCTION__,
clixon_debug(CLIXON_DBG_DEFAULT, "%s type:%s from:%s, dest:%s port:%hu", __FUNCTION__,
rsock->rs_addrtype,
rsock->rs_from_addr,
rsock->rs_addrstr,
@ -577,7 +581,7 @@ restconf_accept_client(int fd,
goto done;
retval = 0;
done:
clicon_debug(1, "%s retval %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval %d", __FUNCTION__, retval);
if (name)
free(name);
return retval;
@ -592,7 +596,7 @@ restconf_native_terminate(clicon_handle h)
restconf_socket *rsock;
restconf_conn *rc;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((rn = restconf_native_handle_get(h)) != NULL){
while ((rsock = rn->rn_sockets) != NULL){
while ((rc = rsock->rs_conns) != NULL){
@ -702,7 +706,7 @@ restconf_clixon_backend(clicon_handle h,
/*! Per-socket openssl inits
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xs XML config of single restconf socket
* @param[in] nsc Namespace context
* @retval 0 OK
@ -723,7 +727,7 @@ openssl_init_socket(clicon_handle h,
restconf_socket *rsock = NULL; /* openssl per socket struct */
struct timeval now;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/*
* Create per-socket openssl handle
* See restconf_native_terminate for freeing
@ -793,7 +797,7 @@ openssl_init_socket(clicon_handle h,
/*! Init openssl, open and register server socket (ready for accept)
*
* Given a fully populated configuration tree.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] dbg0 Manually set debug flag, if set overrides configuration setting
* @param[in] xrestconf XML tree containing restconf config
* @retval 0 OK
@ -820,7 +824,7 @@ restconf_openssl_init(clicon_handle h,
size_t veclen;
int i;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* flag used for sanity of certs */
ssl_enable = xpath_first(xrestconf, nsc, "socket[ssl='true']") != NULL;
/* Auth type set in config */
@ -830,7 +834,7 @@ restconf_openssl_init(clicon_handle h,
(x = xpath_first(xrestconf, nsc, "debug")) != NULL &&
(bstr = xml_body(x)) != NULL){
dbg = atoi(bstr);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
/* If debug was enabled here from config and not initially,
* print clixn options and loaded yang files
*/
@ -897,7 +901,7 @@ restconf_openssl_init(clicon_handle h,
* - if local config found, open sockets accordingly and exit function
* - If no local config found, query backend for config and open sockets.
* That is, EITHER local config OR read config from backend once
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] inline_config If set, restconf conf is given by -R command-line
* @param[out] xrestconf XML restconf config, malloced (if retval = 1)
* @retval 1 OK (and xrestconf set)
@ -984,7 +988,6 @@ restconf_clixon_init(clicon_handle h,
/* Load yang restconf module */
if (yang_spec_parse_module(h, "ietf-restconf", NULL, yspec)< 0)
goto done;
#ifdef CLIXON_YANG_PATCH
/* Load yang restconf patch module */
if (yang_spec_parse_module(h, "ietf-yang-patch", NULL, yspec)< 0)
@ -1010,7 +1013,7 @@ restconf_clixon_init(clicon_handle h,
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
goto done;
if (inline_config != NULL && strlen(inline_config)){
clicon_debug(1, "%s reading from inline config", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s reading from inline config", __FUNCTION__);
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
goto done;
if (ret == 0){
@ -1032,10 +1035,10 @@ restconf_clixon_init(clicon_handle h,
goto done;
}
else if (clicon_option_bool(h, "CLICON_BACKEND_RESTCONF_PROCESS") == 0){
clicon_debug(1, "%s reading from clixon config", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s reading from clixon config", __FUNCTION__);
/* If not read from backend, try to get restconf config from local config-file */
if ((xrestconf = clicon_conf_restconf(h)) != NULL){
/*! Basic config init, set auth-type, pretty, etc ret 0 means disabled */
/* Basic config init, set auth-type, pretty, etc ret 0 means disabled */
if ((ret = restconf_config_init(h, xrestconf)) < 0)
goto done;
/* ret == 1 means this config is OK */
@ -1050,7 +1053,7 @@ restconf_clixon_init(clicon_handle h,
/* If no local config, or it is disabled, try to query backend of config.
*/
else {
clicon_debug(1, "%s reading from backend datastore config", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s reading from backend datastore config", __FUNCTION__);
if ((ret = restconf_clixon_backend(h, xrestconfp)) < 0)
goto done;
if (ret == 0)
@ -1089,7 +1092,7 @@ restconf_sig_term(int arg)
/*! Usage help routine
*
* @param[in] argv0 command line
* @param[in] h Clicon handle
* @param[in] h Clixon handle
*/
static void
usage(clicon_handle h,
@ -1195,7 +1198,7 @@ main(int argc,
) < 0)
goto done;
#endif
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
clicon_log(LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid());
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal");
@ -1214,7 +1217,6 @@ main(int argc,
if (clicon_options_main(h) < 0)
goto done;
// stream_path = clicon_option_str(h, "CLICON_STREAM_PATH");
/* Now rest of options, some overwrite option file */
optind = 1;
opterr = 0;
@ -1333,7 +1335,7 @@ main(int argc,
ok:
retval = 0;
done:
clicon_debug(1, "restconf_main_openssl done");
clixon_debug(CLIXON_DBG_DEFAULT, "restconf_main_openssl done");
if (xrestconf)
xml_free(xrestconf);
restconf_native_terminate(h);

View file

@ -78,10 +78,12 @@
#include "restconf_methods.h"
/*! REST OPTIONS method
*
* According to restconf
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
*
* @retval 0 OK
* @retval -1 Error
* @code
* curl -G http://localhost/restconf/data/interfaces/interface=eth0
* @endcode
@ -96,7 +98,7 @@ api_data_options(clicon_handle h,
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (restconf_reply_header(req, "Allow", "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE") < 0)
goto done;
if (restconf_reply_header(req, "Accept-Patch", "application/yang-data+xml,application/yang-data+json") < 0)
@ -140,7 +142,7 @@ match_list_keys(yang_stmt *y,
char *key1;
char *key2;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
switch (yang_keyword_get(y)){
case Y_LIST:
if ((cvk = yang_cvec_get(y)) == NULL) /* Use Y_LIST cache, see ys_populate_list() */
@ -174,11 +176,12 @@ match_list_keys(yang_stmt *y,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
/*! Common PUT plain PATCH method
*
* Code checks if object exists.
* PUT: If it does not, set op to create, otherwise replace
* PATCH: If it does not, fail, otherwise replace/merge
@ -187,6 +190,8 @@ match_list_keys(yang_stmt *y,
* @param[in] pretty Pretty-print
* @param[in] media_in Restconf input media
* @param[in] media_out Restconf output media
* @retval 0 OK
* @retval -1 Error
*/
int
api_data_write(clicon_handle h,
@ -231,8 +236,8 @@ api_data_write(clicon_handle h,
char *xpath = NULL;
char *attr;
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
clicon_debug(1, "%s data:\"%s\"", __FUNCTION__, data);
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -422,7 +427,7 @@ api_data_write(clicon_handle h,
/* There is an api-path that defines an element in the datastore tree.
* Not top-of-tree.
*/
clicon_debug(1, "%s Comparing bottom-of api-path (%s) with top-of-data (%s)",__FUNCTION__, xml_name(xbot), dname);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Comparing bottom-of api-path (%s) with top-of-data (%s)",__FUNCTION__, xml_name(xbot), dname);
/* Check same symbol in api-path as data */
if (strcmp(dname, xml_name(xbot))){
@ -487,11 +492,11 @@ api_data_write(clicon_handle h,
/* If we already have that default namespace, remove it in child */
if ((xa = xml_find_type(xdata, NULL, "xmlns", CX_ATTR)) != NULL){
if (xml2ns(xparent, NULL, &namespace) < 0){
clicon_debug(1, "%s G done", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s G done", __FUNCTION__);
goto done;
}
if (namespace == NULL){
clicon_debug_xml(1, xparent, "%s xparent:", __FUNCTION__);
clixon_debug_xml(1, xparent, "%s xparent:", __FUNCTION__);
/* XXX */
}
/* Set xmlns="" default namespace attribute (if diff from default) */
@ -535,7 +540,7 @@ api_data_write(clicon_handle h,
if (clixon_xml2cbuf(cbx, xtop, 0, 0, NULL, -1, 0) < 0)
goto done;
cprintf(cbx, "</edit-config></rpc>");
clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
clixon_debug(CLIXON_DBG_DEFAULT, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0)
goto done;
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
@ -555,7 +560,7 @@ api_data_write(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (xpath)
free(xpath);
if (nsc)
@ -578,6 +583,7 @@ api_data_write(clicon_handle h,
} /* api_data_write */
/*! Generic REST PUT method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
@ -587,6 +593,8 @@ api_data_write(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] ds 0 if "data" resource, 1 if rfc8527 "ds" resource
* @retval 0 OK
* @retval -1 Error
* @note restconf PUT is mapped to edit-config replace.
* @see RFC8040 Sec 4.5 PUT
* @see api_data_post
@ -630,6 +638,7 @@ api_data_put(clicon_handle h,
}
/*! Generic REST PATCH method for plain patch
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
@ -639,6 +648,8 @@ api_data_put(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] ds 0 if "data" resource, 1 if rfc8527 "ds" resource
* @retval 0 OK
* @retval -1 Error
* Netconf: <edit-config> (nc:operation="merge")
* See RFC8040 Sec 4.6.1
* Plain patch can be used to create or update, but not delete, a child
@ -685,6 +696,7 @@ api_data_patch(clicon_handle h,
}
/*! Generic REST DELETE method translated to edit-config
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
@ -692,6 +704,8 @@ api_data_patch(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] ds 0 if "data" resource, 1 if rfc8527 "ds" resource
* @retval 0 OK
* @retval -1 Error
* See RFC 8040 Sec 4.7
* Example:
* curl -X DELETE http://127.0.0.1/restconf/data/interfaces/interface=eth0
@ -723,7 +737,7 @@ api_data_delete(clicon_handle h,
int ret;
cxobj *xe; /* xml error, no free */
clicon_debug(1, "%s api_path:%s", __FUNCTION__, api_path);
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:%s", __FUNCTION__, api_path);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -807,7 +821,7 @@ api_data_delete(clicon_handle h,
xml_free(xretdis);
if (xtop)
xml_free(xtop);
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}

View file

@ -35,7 +35,6 @@
* Restconf method implementation
*/
#ifndef _RESTCONF_METHODS_H_
#define _RESTCONF_METHODS_H_

View file

@ -76,6 +76,8 @@ static int api_data_pagination(clicon_handle h, void *req, char *api_path, int p
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] head If 1 is HEAD, otherwise GET
* @retval 0 OK
* @retval -1 Error
* @code
* curl -X GET http://localhost/restconf/data/interfaces/interface=eth0
* @endcode
@ -126,7 +128,7 @@ api_data_get2(clicon_handle h,
char *defaults = NULL;
cvec *nscd = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -166,7 +168,7 @@ api_data_get2(clicon_handle h,
}
/* Check for content attribute */
if ((attr = cvec_find_str(qvec, "content")) != NULL){
clicon_debug(1, "%s content=%s", __FUNCTION__, attr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s content=%s", __FUNCTION__, attr);
if ((int)(content = netconf_content_str2int(attr)) == -1){
if (netconf_bad_attribute_xml(&xerr, "application",
"content", "Unrecognized value of content attribute") < 0)
@ -178,7 +180,7 @@ api_data_get2(clicon_handle h,
}
/* Check for depth attribute */
if ((attr = cvec_find_str(qvec, "depth")) != NULL){
clicon_debug(1, "%s depth=%s", __FUNCTION__, attr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s depth=%s", __FUNCTION__, attr);
if (strcmp(attr, "unbounded") != 0){
char *reason = NULL;
if ((ret = parse_int32(attr, &depth, &reason)) < 0){
@ -196,11 +198,11 @@ api_data_get2(clicon_handle h,
}
}
if ((attr = cvec_find_str(qvec, "with-defaults")) != NULL){
clicon_debug(1, "%s with_defaults=%s", __FUNCTION__, attr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s with_defaults=%s", __FUNCTION__, attr);
defaults = attr;
}
clicon_debug(1, "%s path:%s", __FUNCTION__, xpath);
clixon_debug(CLIXON_DBG_DEFAULT, "%s path:%s", __FUNCTION__, xpath);
ret = clicon_rpc_get(h, xpath, nsc, content, depth, defaults, &xret);
if (ret < 0){
@ -214,8 +216,8 @@ api_data_get2(clicon_handle h,
* We need to cut that tree to only the object.
*/
#if 0 /* DEBUG */
if (clicon_debug_get())
clicon_debug_xml(1, xret, "%s xret:", __FUNCTION__);
if (clixon_debug_get())
clixon_debug_xml(CLIXON_DBG_DEFAULT, xret, "%s xret:", __FUNCTION__);
#endif
/* Check if error return */
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
@ -290,7 +292,7 @@ api_data_get2(clicon_handle h,
break;
}
}
clicon_debug(1, "%s cbuf:%s", __FUNCTION__, cbuf_get(cbx));
clixon_debug(CLIXON_DBG_DEFAULT, "%s cbuf:%s", __FUNCTION__, cbuf_get(cbx));
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
@ -301,7 +303,7 @@ api_data_get2(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (xpath)
free(xpath);
if (nscd)
@ -322,6 +324,7 @@ api_data_get2(clicon_handle h,
}
/*! GET Collection
*
* According to restconf collection draft. Lists, work in progress
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
@ -331,6 +334,8 @@ api_data_get2(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] head If 1 is HEAD, otherwise GET
* @retval 0 OK
* @retval -1 Error
* @code
* curl -X GET http://localhost/restconf/data/interfaces
* @endcode
@ -376,7 +381,7 @@ api_data_pagination(clicon_handle h,
char *where;
char *ns;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -425,7 +430,7 @@ api_data_pagination(clicon_handle h,
/* Check for content attribute */
if ((attr = cvec_find_str(qvec, "content")) != NULL){
clicon_debug(1, "%s content=%s", __FUNCTION__, attr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s content=%s", __FUNCTION__, attr);
if ((int)(content = netconf_content_str2int(attr)) == -1){
if (netconf_bad_attribute_xml(&xerr, "application",
"content", "Unrecognized value of content attribute") < 0)
@ -439,7 +444,7 @@ api_data_pagination(clicon_handle h,
goto ok;
}
}
clicon_debug(1, "%s path:%s", __FUNCTION__, xpath);
clixon_debug(CLIXON_DBG_DEFAULT, "%s path:%s", __FUNCTION__, xpath);
if (content != CONTENT_CONFIG && content != CONTENT_NONCONFIG && content != CONTENT_ALL){
clicon_err(OE_XML, EINVAL, "Invalid content attribute %d", content);
goto done;
@ -447,7 +452,7 @@ api_data_pagination(clicon_handle h,
/* Clixon extensions and collection attributes */
/* Check for depth attribute */
if ((attr = cvec_find_str(qvec, "depth")) != NULL){
clicon_debug(1, "%s depth=%s", __FUNCTION__, attr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s depth=%s", __FUNCTION__, attr);
if (strcmp(attr, "unbounded") != 0){
char *reason = NULL;
if ((ret = parse_int32(attr, &depth, &reason)) < 0){
@ -502,7 +507,7 @@ api_data_pagination(clicon_handle h,
* We need to cut that tree to only the object.
*/
#if 0 /* DEBUG */
clicon_debug_xml(1, xret, "%s xret:", __FUNCTION__);
clixon_debug_xml(CLIXON_DBG_DEFAULT, xret, "%s xret:", __FUNCTION__);
#endif
/* Check if error return */
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
@ -551,7 +556,7 @@ api_data_pagination(clicon_handle h,
default:
break;
}
clicon_debug(1, "%s cbuf:%s", __FUNCTION__, cbuf_get(cbx));
clixon_debug(CLIXON_DBG_DEFAULT, "%s cbuf:%s", __FUNCTION__, cbuf_get(cbx));
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
@ -562,7 +567,7 @@ api_data_pagination(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cbrpc)
cbuf_free(cbrpc);
if (xpath)
@ -585,6 +590,11 @@ api_data_pagination(clicon_handle h,
}
/*! REST HEAD method
*
* The HEAD method is sent by the client to retrieve just the header fields
* that would be returned for the comparable GET method, without the
* response message-body.
* Relation to netconf: none
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
@ -593,11 +603,8 @@ api_data_pagination(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] ds 0 if "data" resource, 1 if rfc8527 "ds" resource
*
* The HEAD method is sent by the client to retrieve just the header fields
* that would be returned for the comparable GET method, without the
* response message-body.
* Relation to netconf: none
* @retval 0 OK
* @retval -1 Error
*/
int
api_data_head(clicon_handle h,
@ -613,6 +620,7 @@ api_data_head(clicon_handle h,
}
/*! REST GET method
*
* According to restconf
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
@ -623,6 +631,8 @@ api_data_head(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @param[in] ds RFC8527 datastore
* @retval 0 OK
* @retval -1 Error
* @code
* curl -G http://localhost/restconf/data/interfaces/interface=eth0
* @endcode
@ -667,6 +677,7 @@ api_data_get(clicon_handle h,
}
/*! GET restconf/operations resource
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] path According to restconf (Sec 3.5.1.1 in [draft])
@ -675,11 +686,12 @@ api_data_get(clicon_handle h,
* @param[in] data Stream input data
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
*
* @retval 0 OK
* @retval -1 Error
* @code
* curl -G http://localhost/restconf/operations
* @endcode
* RFC8040 Sec 3.3.2:
* @see RFC8040 Sec 3.3.2:
* This optional resource is a container that provides access to the
* data-model-specific RPC operations supported by the server. The
* server MAY omit this resource if no data-model-specific RPC
@ -709,7 +721,7 @@ api_operations_get(clicon_handle h,
cxobj *xt = NULL;
int i;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
yspec = clicon_dbspec_yang(h);
if ((cbx = cbuf_new()) == NULL)
goto done;
@ -777,7 +789,7 @@ api_operations_get(clicon_handle h,
// ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cbx)
cbuf_free(cbx);
if (xt)

View file

@ -100,11 +100,12 @@ yang_patch_op2int(char *op)
}
/*! Add square brackets after the surrounding curly brackets in JSON
*
* Needed, in order to modify the result of clixon_json2cbuf() to be valid input
* to api_data_post() and api_data_write()
* @param[in] x_simple_patch a cxobj to pass to clixon_json2cbuf()
* @retva cbuf With the modified json
* @retva NULL Error
* @retval cbuf With the modified json
* @retval NULL Error
*/
static cbuf*
yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
@ -187,6 +188,7 @@ yang_patch_strip_after_last_slash(char* val)
}
/*! YANG PATCH replace method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] pi Offset, where to start api-path
@ -199,6 +201,8 @@ yang_patch_strip_after_last_slash(char* val)
* @param[in] value_vec_len number of elements in the "value" array of an edit in YANG patch
* @param[in] value_vec pointer to the "value" array of an edit in YANG patch
* @param[in] x_simple_patch pointer to XML containing module name, e.g. <ietf-interfaces:interface/>
* @retval 0 OK
* @retval -1 Error
*/
static int
yang_patch_do_replace(clicon_handle h,
@ -287,6 +291,7 @@ yang_patch_do_replace(clicon_handle h,
}
/*! YANG PATCH create method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] pi Offset, where to start api-path
@ -298,6 +303,8 @@ yang_patch_do_replace(clicon_handle h,
* @param[in] value_vec_len number of elements in the "value" array of an edit in YANG patch
* @param[in] value_vec pointer to the "value" array of an edit in YANG patch
* @param[in] x_simple_patch pointer to XML containing module name, e.g. <ietf-interfaces:interface/>
* @retval 0 OK
* @retval -1 Error
*/
static int
yang_patch_do_create(clicon_handle h,
@ -343,6 +350,7 @@ yang_patch_do_create(clicon_handle h,
}
/*! YANG PATCH insert method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] pi Offset, where to start api-path
@ -356,6 +364,8 @@ yang_patch_do_create(clicon_handle h,
* @param[in] where_val value in "where" field of edit in YANG patch
* @param[in] api_path full API path, e.g. "/restconf/data/example-jukebox:jukebox/playlist=Foo-One"
* @param[in] point_val value in "point" field of edit in YANG patch
* @retval 0 OK
* @retval -1 Error
*/
static int
yang_patch_do_insert(clicon_handle h,
@ -431,6 +441,7 @@ yang_patch_do_insert(clicon_handle h,
}
/*! YANG PATCH merge method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] pi Offset, where to start api-path
@ -444,6 +455,8 @@ yang_patch_do_insert(clicon_handle h,
* @param[in] x_simple_patch pointer to XML containing module name, e.g. "<ietf-interfaces:interface/>"
* @param[in] where_val value in "where" field of edit in YANG patch
* @param[in] key_xn XML with key tag and value, e.g. "<name>Foo-One</name>"
* @retval 0 OK
* @retval -1 Error
*/
static int
yang_patch_do_merge(clicon_handle h,
@ -622,7 +635,7 @@ yang_patch_do_edit(clicon_handle h,
yang_stmt *ybot = NULL;
yang_stmt *ymod;
clicon_debug_xml(1, xn, "%s %d xn:", __FUNCTION__, __LINE__);
clixon_debug_xml(1, xn, "%s %d xn:", __FUNCTION__, __LINE__);
/* Create cbufs:s */
if ((simple_patch_request_uri = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
@ -723,6 +736,7 @@ yang_patch_do_edit(clicon_handle h,
}
/*! YANG PATCH method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path0 According to restconf (Sec 3.5.3.1 in rfc8040)
@ -764,7 +778,7 @@ api_data_yang_patch(clicon_handle h,
size_t veclen;
cxobj **vec = NULL;
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;

View file

@ -66,8 +66,11 @@
#include "restconf_methods_post.h"
/*! Print location header from
*
* @param[in] req Generic Www handle
* @param[in] xobj If set (eg POST) add to api-path
* @retval 0 OK
* @retval -1 Error
* $https on if connection operates in SSL mode, or an empty string otherwise
* @note ports are ignored
*/
@ -116,6 +119,7 @@ http_location_header(clicon_handle h,
}
/*! Generic REST POST method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
@ -185,8 +189,8 @@ api_data_post(clicon_handle h,
int nrchildren0 = 0;
yang_bind yb;
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path);
clicon_debug(1, "%s data:\"%s\"", __FUNCTION__, data);
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path);
clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -272,7 +276,7 @@ api_data_post(clicon_handle h,
/* RFC 8040 4.4.1: The message-body MUST contain exactly one instance of the
* expected data resource.
*/
clicon_debug(1, "%s nrchildren0: %d", __FUNCTION__, nrchildren0);
clixon_debug(CLIXON_DBG_DEFAULT, "%s nrchildren0: %d", __FUNCTION__, nrchildren0);
if (xml_child_nr_type(xbot, CX_ELMNT) - nrchildren0 != 1){
if (netconf_malformed_message_xml(&xerr, "The message-body MUST contain exactly one instance of the expected data resource") < 0)
goto done;
@ -326,7 +330,7 @@ api_data_post(clicon_handle h,
if (restconf_insert_attributes(xdata, qvec) < 0)
goto done;
#if 1
clicon_debug_xml(1, xdata, "%s xdata:", __FUNCTION__);
clixon_debug_xml(1, xdata, "%s xdata:", __FUNCTION__);
#endif
/* Create text buffer for transfer to backend */
@ -365,7 +369,7 @@ api_data_post(clicon_handle h,
if (clixon_xml2cbuf(cbx, xtop, 0, 0, NULL, -1, 0) < 0)
goto done;
cprintf(cbx, "</edit-config></rpc>");
clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
clixon_debug(CLIXON_DBG_DEFAULT, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0)
goto done;
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
@ -380,7 +384,7 @@ api_data_post(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (xret)
xml_free(xret);
if (xerr)
@ -397,6 +401,7 @@ api_data_post(clicon_handle h,
} /* api_data_post */
/*! Handle input data to api_operations_post
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] data Stream input data
@ -436,7 +441,7 @@ api_operations_post_input(clicon_handle h,
int ret;
restconf_media media_in;
clicon_debug(1, "%s %s", __FUNCTION__, data);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, data);
if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new");
goto done;
@ -486,7 +491,7 @@ api_operations_post_input(clicon_handle h,
* <data><input xmlns="urn:example:clixon">...</input></data>
*/
#if 1
clicon_debug_xml(1, xdata, "%s xdata:", __FUNCTION__);
clixon_debug_xml(1, xdata, "%s xdata:", __FUNCTION__);
#endif
/* Validate that exactly only <input> tag */
if ((xinput = xml_child_i_type(xdata, 0, CX_ELMNT)) == NULL ||
@ -504,7 +509,7 @@ api_operations_post_input(clicon_handle h,
goto done;
goto fail;
}
// clicon_debug(1, "%s input validation passed", __FUNCTION__);
// clixon_debug(CLIXON_DBG_DEFAULT, "%s input validation passed", __FUNCTION__);
/* Add all input under <rpc>path */
x = NULL;
while ((x = xml_child_i_type(xinput, 0, CX_ELMNT)) != NULL)
@ -515,7 +520,7 @@ api_operations_post_input(clicon_handle h,
// ok:
retval = 1;
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: %d", __FUNCTION__, retval);
if (cbret)
cbuf_free(cbret);
if (xerr)
@ -529,6 +534,7 @@ api_operations_post_input(clicon_handle h,
}
/*! Handle output data to api_operations_post
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] xret XML reply messages from backend/handler
@ -552,7 +558,6 @@ api_operations_post_output(clicon_handle h,
int pretty,
restconf_media media_out,
cxobj **xoutputp)
{
int retval = -1;
cxobj *xoutput = NULL;
@ -562,7 +567,7 @@ api_operations_post_output(clicon_handle h,
cxobj *xok;
int isempty;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Validate that exactly only <rpc-reply> tag with exactly one element child */
if ((xoutput = xml_child_i_type(xret, 0, CX_ELMNT)) == NULL ||
strcmp(xml_name(xoutput),"rpc-reply") != 0
@ -583,7 +588,7 @@ api_operations_post_output(clicon_handle h,
xml_name_set(xoutput, "output");
/* xoutput should now look: <output><x xmlns="uri">0</x></output> */
#if 1
clicon_debug_xml(1, xoutput, "%s xoutput:", __FUNCTION__);
clixon_debug_xml(1, xoutput, "%s xoutput:", __FUNCTION__);
#endif
/* Remove original netconf default namespace. Somewhat unsure what "output" belongs to? */
if ((xa = xml_find_type(xoutput, NULL, "xmlns", CX_ATTR)) != NULL)
@ -644,7 +649,7 @@ api_operations_post_output(clicon_handle h,
*xoutputp = xoutput;
retval = 1;
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: %d", __FUNCTION__, retval);
if (xerr)
xml_free(xerr);
return retval;
@ -654,6 +659,7 @@ api_operations_post_output(clicon_handle h,
}
/*! REST operation POST method
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
@ -661,6 +667,8 @@ api_operations_post_output(clicon_handle h,
* @param[in] data Stream input data
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Output media
* @retval 0 OK
* @retval -1 Error
* See RFC 8040 Sec 3.6 / 4.4.2
* @note We map post to edit-config create.
* POST {+restconf}/operations/<operation>
@ -714,7 +722,7 @@ api_operations_post(clicon_handle h,
char *namespace = NULL;
int nr = 0;
clicon_debug(1, "%s json:\"%s\" path:\"%s\"", __FUNCTION__, data, api_path);
clixon_debug(CLIXON_DBG_DEFAULT, "%s json:\"%s\" path:\"%s\"", __FUNCTION__, data, api_path);
/* 1. Initialize */
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
@ -784,7 +792,7 @@ api_operations_post(clicon_handle h,
* XML: <input xmlns="uri"><x>0</x></input>
*/
namespace = xml_find_type_value(xbot, NULL, "xmlns", CX_ATTR);
clicon_debug(1, "%s : 4. Parse input data: %s", __FUNCTION__, data);
clixon_debug(CLIXON_DBG_DEFAULT, "%s : 4. Parse input data: %s", __FUNCTION__, data);
if (data && strlen(data)){
if ((ret = api_operations_post_input(h, req, data, yspec, yrpc, xbot,
pretty, media_out)) < 0)
@ -795,7 +803,7 @@ api_operations_post(clicon_handle h,
/* Here xtop is:
<rpc username="foo"><myfn xmlns="uri"><x>42</x></myfn></rpc> */
#if 1
clicon_debug_xml(1, xtop, "%s 5. Translate input args:", __FUNCTION__);
clixon_debug_xml(1, xtop, "%s 5. Translate input args:", __FUNCTION__);
#endif
/* 6. Validate outgoing RPC and fill in defaults */
if ((ret = xml_bind_yang_rpc(h, xtop, yspec, &xerr)) < 0) /* */
@ -816,7 +824,7 @@ api_operations_post(clicon_handle h,
* <rpc username="foo"><myfn xmlns="uri"><x>42</x><y>99</y></myfn></rpc>
*/
#if 0
clicon_debug_xml(1, xtop, "%s 6. Validate and defaults:", __FUNCTION__);
clixon_debug_xml(1, xtop, "%s 6. Validate and defaults:", __FUNCTION__);
#endif
/* 7. Send to RPC handler, either local or backend
* Note (1) xtop is <rpc><method> xbot is <method>
@ -857,7 +865,7 @@ api_operations_post(clicon_handle h,
* <rpc-reply><x xmlns="uri">0</x></rpc-reply>
*/
#if 1
clicon_debug_xml(1, xret, "%s Receive reply:", __FUNCTION__);
clixon_debug_xml(1, xret, "%s Receive reply:", __FUNCTION__);
#endif
youtput = yang_find(yrpc, Y_OUTPUT, NULL);
if ((ret = api_operations_post_output(h, req, xret, yspec, youtput, namespace,
@ -889,7 +897,7 @@ api_operations_post(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (prefix)
free(prefix);
if (id)

View file

@ -80,7 +80,8 @@
/* Forward */
static int restconf_idle_cb(int fd, void *arg);
/*!
/*! Create restconf stream
*
* @param[in] rc Restconf connection handle
* @see restconf_stream_free
*/
@ -118,7 +119,8 @@ restconf_stream_data_new(restconf_conn *rc,
return sd;
}
/*!
/*! Find restconf stream data
*
* @param[in] rc Restconf connection handle
*/
restconf_stream_data *
@ -190,11 +192,12 @@ restconf_conn_new(clicon_handle h,
rc->rc_callhome = rsock->rs_callhome;
rc->rc_socket = rsock;
INSQ(rc, rsock->rs_conns);
clicon_debug(1, "%s %p", __FUNCTION__, rc);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %p", __FUNCTION__, rc);
return rc;
}
/*! Free clixon/cbuf resources related to a connection
*
* @param[in] rc restconf connection
*/
static int
@ -205,7 +208,7 @@ restconf_conn_free(restconf_conn *rc)
restconf_socket *rsock;
restconf_conn *rc1;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (rc == NULL){
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
goto done;
@ -238,8 +241,11 @@ restconf_conn_free(restconf_conn *rc)
}
/*! Given SSL connection, get peer certificate one-line name
*
* @param[in] ssl SSL session
* @param[out] oneline Cert name one-line
* @retval 0 OK
* @retval -1 Error
*/
int
ssl_x509_name_oneline(SSL *ssl,
@ -400,7 +406,7 @@ native_buf_write(clicon_handle h,
* 1. they are not "strings" in the sense they are not NULL-terminated
* 2. they are often very long
*/
if (clicon_debug_get()) {
if (clixon_debug_get()) {
char *dbgstr = NULL;
size_t sz;
sz = buflen>256?256:buflen; /* Truncate to 256 */
@ -410,7 +416,7 @@ native_buf_write(clicon_handle h,
}
memcpy(dbgstr, buf, sz);
dbgstr[sz] = '\0';
clicon_debug(1, "%s %s buflen:%zu buf:\n%s", __FUNCTION__, callfn, buflen, dbgstr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s buflen:%zu buf:\n%s", __FUNCTION__, callfn, buflen, dbgstr);
free(dbgstr);
}
while (totlen < buflen){
@ -424,7 +430,7 @@ native_buf_write(clicon_handle h,
goto closed; /* Close socket and ssl */
}
else if (er == EAGAIN){
clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write EAGAIN", __FUNCTION__);
usleep(10000);
continue;
}
@ -445,7 +451,7 @@ native_buf_write(clicon_handle h,
if ((len = write(rc->rc_s, buf+totlen, buflen-totlen)) < 0){
switch (errno){
case EAGAIN: /* Operation would block */
clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write EAGAIN", __FUNCTION__);
usleep(10000);
continue;
break;
@ -465,7 +471,7 @@ native_buf_write(clicon_handle h,
} /* while */
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
closed:
retval = 0;
@ -473,6 +479,7 @@ native_buf_write(clicon_handle h,
}
/*! Send early handcoded bad request reply before actual packet received, just after accept
*
* @param[in] h Clixon handle
* @param[in] media
* @param[in] body If given add message body using media
@ -491,7 +498,7 @@ native_send_badrequest(clicon_handle h,
int retval = -1;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -548,8 +555,8 @@ http1_native_clear_input(clicon_handle h,
* @param[in] sz Size of input buffer
* @param[out] np Bytes read
* @param[out] again If set, read data again, do not continue processing
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
static int
read_ssl(restconf_conn *rc,
@ -563,7 +570,7 @@ read_ssl(restconf_conn *rc,
if ((*np = SSL_read(rc->rc_ssl, buf, sz)) <= 0){
sslerr = SSL_get_error(rc->rc_ssl, *np);
clicon_debug(1, "%s SSL_read() n:%zd errno:%d sslerr:%d", __FUNCTION__, *np, errno, sslerr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_read() n:%zd errno:%d sslerr:%d", __FUNCTION__, *np, errno, sslerr);
switch (sslerr){
case SSL_ERROR_WANT_READ: /* 2 */
/* SSL_ERROR_WANT_READ is returned when the last operation was a read operation
@ -571,7 +578,7 @@ read_ssl(restconf_conn *rc,
* That is, it can happen if restconf_socket_init() below is called
* with SOCK_NONBLOCK
*/
clicon_debug(1, "%s SSL_read SSL_ERROR_WANT_READ", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_read SSL_ERROR_WANT_READ", __FUNCTION__);
usleep(1000);
*again = 1;
break;
@ -586,7 +593,7 @@ read_ssl(restconf_conn *rc,
}
retval = 0;
// done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}
@ -597,9 +604,9 @@ read_ssl(restconf_conn *rc,
* @param[in] sz Size of input buffer
* @param[out] np Bytes read
* @param[out] again If set, read data again, do not continue processing
* @retval -1 Error
* @retval 0 Socket closed, quit
* @retval 1 OK
* @retval 0 Socket closed, quit
* @retval -1 Error
* XXX:
* readmore/continue
* goto ok
@ -616,14 +623,14 @@ read_regular(restconf_conn *rc,
if ((*np = read(rc->rc_s, buf, sz)) < 0){ /* XXX atomicio ? */
switch(errno){
case ECONNRESET:/* Connection reset by peer */
clicon_debug(1, "%s %d Connection reset by peer", __FUNCTION__, rc->rc_s);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d Connection reset by peer", __FUNCTION__, rc->rc_s);
if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
goto done;
retval = 0; /* Close socket and ssl */
goto done;
break;
case EAGAIN:
clicon_debug(1, "%s read EAGAIN", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s read EAGAIN", __FUNCTION__);
usleep(1000);
*again = 1;
break;
@ -646,9 +653,9 @@ read_regular(restconf_conn *rc,
* @param[in] buf Input buffer
* @param[in] n Length of data in input buffer
* @param[out] readmore If set, read data again, do not continue processing
* @retval -1 Error
* @retval 0 Socket closed, quit
* @retval 1 OK
* @retval 0 Socket closed, quit
* @retval -1 Error
*/
static int
restconf_http1_process(restconf_conn *rc,
@ -859,14 +866,15 @@ restconf_http2_upgrade(restconf_conn *rc)
#endif /* HAVE_LIBHTTP1 */
/*! Restconf HTTP/2 processing after chunk of bytes read
*
* @param[in] rc Restconf connection
* @param[in] buf Input buffer
* @param[in] n Size of input buffer
* @param[in] n Length of data in input buffer
* @param[out] readmore If set, read data again, do not continue processing
* @retval -1 Error
* @retval 0 Socket closed, quit
* @retval 1 OK
* @retval 0 Socket closed, quit
* @retval -1 Error
*/
static int
restconf_http2_process(restconf_conn *rc,
@ -878,7 +886,7 @@ restconf_http2_process(restconf_conn *rc,
int ret;
nghttp2_error ngerr;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (rc->rc_exit){ /* Server-initiated exit for http/2 */
if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
@ -905,13 +913,14 @@ restconf_http2_process(restconf_conn *rc,
}
retval = 1;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}
#endif /* HAVE_LIBNGHTTP2 */
/*! Get restconf native handle
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval rn Restconf native handle
*/
restconf_native_handle *
@ -952,7 +961,7 @@ restconf_connection(int s,
int readmore = 1;
int ret;
clicon_debug(1, "%s %d", __FUNCTION__, s);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, s);
if ((rc = (restconf_conn*)arg) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
goto done;
@ -963,7 +972,7 @@ restconf_connection(int s,
}
gettimeofday(&rc->rc_t, NULL); /* activity timer */
while (readmore) {
clicon_debug(1, "%s readmore", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s readmore", __FUNCTION__);
readmore = 0;
/* Example: curl -Ssik -u wilma:bar -X GET https://localhost/restconf/data/example:x */
if (rc->rc_ssl){
@ -976,11 +985,11 @@ restconf_connection(int s,
if (ret == 0)
goto ok; /* abort here */
}
clicon_debug(1, "%s read:%zd", __FUNCTION__, n);
clixon_debug(CLIXON_DBG_DEFAULT, "%s read:%zd", __FUNCTION__, n);
if (readmore)
continue;
if (n == 0){
clicon_debug(1, "%s n=0 closing socket", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s n=0 closing socket", __FUNCTION__);
if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
goto done;
rc = NULL;
@ -1020,15 +1029,18 @@ restconf_connection(int s,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval %d", __FUNCTION__, retval);
return retval;
} /* restconf_connection */
/*----------------------------- Close socket ------------------------------*/
/*! Close Restconf native connection socket and unregister callback
*
* For callhome also start reconnect timer
* @param[in] rc rstconf connection
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_connection_close1(restconf_conn *rc)
@ -1041,7 +1053,7 @@ restconf_connection_close1(restconf_conn *rc)
goto done;
}
rsock = rc->rc_socket;
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (close(rc->rc_s) < 0){
clicon_err(OE_UNIX, errno, "close");
goto done;
@ -1056,16 +1068,19 @@ restconf_connection_close1(restconf_conn *rc)
}
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}
/*! Utility function to close restconf server ssl socket.
*
* There are many variants to closing, one could probably make this more generic
* and always use this function, but it is difficult.
* @param[in] rc restconf connection
* @param[in] callfn For debug
* @param[in] dontshutdown If != 0, do not shutdown
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_close_ssl_socket(restconf_conn *rc,
@ -1077,16 +1092,15 @@ restconf_close_ssl_socket(restconf_conn *rc,
int sslerr;
int er;
clicon_debug(1, "%s %s", __FUNCTION__, callfn);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, callfn);
if (rc->rc_ssl != NULL){
if (!dontshutdown &&
(ret = SSL_shutdown(rc->rc_ssl)) < 0){
er = errno;
sslerr = SSL_get_error(rc->rc_ssl, ret);
clicon_debug(1, "%s errno:%s(%d) sslerr:%d", __FUNCTION__, strerror(er), er, sslerr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s errno:%s(%d) sslerr:%d", __FUNCTION__, strerror(er), er, sslerr);
if (sslerr == SSL_ERROR_SSL || /* 1 */
sslerr == SSL_ERROR_ZERO_RETURN){ /* 6 */
}
else if (sslerr == SSL_ERROR_SYSCALL){ /* 5 */
/* Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue
@ -1112,14 +1126,16 @@ restconf_close_ssl_socket(restconf_conn *rc,
goto done;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
/*------------------------------ Accept--------------------------------*/
/*! Check ALPN result
* @proto[out] proto
*
* @param[in] h Clixon handle
* @param[out] proto
* @retval 1 OK with proto set
* @retval 0 Fail, ALPN null or not recognized
* @retval -1 Error
@ -1134,7 +1150,7 @@ ssl_alpn_check(clicon_handle h,
int retval = -1;
cbuf *cberr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Alternatively, call restconf_str2proto but alpn is not a proper string */
if (alpn && alpnlen == 8 && memcmp("http/1.1", alpn, 8) == 0){
*proto = HTTP_11;
@ -1186,7 +1202,7 @@ ssl_alpn_check(clicon_handle h,
}
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cberr)
cbuf_free(cberr);
return retval;
@ -1196,6 +1212,7 @@ ssl_alpn_check(clicon_handle h,
} /* ssl_alpn_check */
/*! Accept new socket client. Note SSL not ip, this applies also to callhome
*
* @param[in] h Clixon handle
* @param[in] s Socket (unix or ip)
* @param[in] rsock Socket struct
@ -1223,7 +1240,7 @@ restconf_ssl_accept_client(clicon_handle h,
unsigned int alpnlen = 0;
restconf_http_proto proto = HTTP_11; /* Non-SSL negotiation NYI */
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
#ifdef HAVE_LIBNGHTTP2
#ifndef HAVE_HTTP1
proto = HTTP_2; /* If nghttp2 only let default be 2.0 */
@ -1238,13 +1255,13 @@ restconf_ssl_accept_client(clicon_handle h,
*/
if ((rc = restconf_conn_new(h, s, rsock)) == NULL)
goto done;
clicon_debug(1, "%s s:%d", __FUNCTION__, rc->rc_s);
clixon_debug(CLIXON_DBG_DEFAULT, "%s s:%d", __FUNCTION__, rc->rc_s);
if (rsock->rs_ssl){
if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){
clicon_err(OE_SSL, 0, "SSL_new");
goto done;
}
clicon_debug(1, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl);
/* CCL_CTX_set_verify already set, need not call SSL_set_verify again for this server
*/
/* X509_CHECK_FLAG_NO_WILDCARDS disables wildcard expansion */
@ -1281,11 +1298,11 @@ restconf_ssl_accept_client(clicon_handle h,
* Both error cases: Call SSL_get_error() with the return value ret
*/
if ((ret = SSL_accept(rc->rc_ssl)) != 1) {
clicon_debug(1, "%s SSL_accept() ret:%d errno:%d", __FUNCTION__, ret, er=errno);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_accept() ret:%d errno:%d", __FUNCTION__, ret, er=errno);
e = SSL_get_error(rc->rc_ssl, ret);
switch (e){
case SSL_ERROR_SSL: /* 1 */
clicon_debug(1, "%s SSL_ERROR_SSL (non-ssl message on ssl socket)", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_ERROR_SSL (non-ssl message on ssl socket)", __FUNCTION__);
#ifdef HTTP_ON_HTTPS_REPLY
SSL_free(rc->rc_ssl);
rc->rc_ssl = NULL;
@ -1303,7 +1320,7 @@ restconf_ssl_accept_client(clicon_handle h,
consult errno for details. If this error occurs then no further I/O
operations should be performed on the connection and SSL_shutdown() must
not be called.*/
clicon_debug(1, "%s SSL_accept() SSL_ERROR_SYSCALL %d", __FUNCTION__, er);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_accept() SSL_ERROR_SYSCALL %d", __FUNCTION__, er);
if (restconf_close_ssl_socket(rc, __FUNCTION__, 1) < 0)
goto done;
rc = NULL;
@ -1316,7 +1333,7 @@ restconf_ssl_accept_client(clicon_handle h,
* That is, it can happen if restconf_socket_init() below is called
* with SOCK_NONBLOCK
*/
clicon_debug(1, "%s write SSL_ERROR_WANT_READ", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write SSL_ERROR_WANT_READ", __FUNCTION__);
usleep(10000);
readmore = 1;
break;
@ -1350,7 +1367,7 @@ restconf_ssl_accept_client(clicon_handle h,
if (ret == 0){
goto closed;
}
clicon_debug(1, "%s proto:%s", __FUNCTION__, restconf_proto2str(proto));
clixon_debug(CLIXON_DBG_DEFAULT, "%s proto:%s", __FUNCTION__, restconf_proto2str(proto));
#if 0 /* Seems too early to fail here, instead let authentication callback deal with this */
/* For client-cert authentication, check if any certs are present,
@ -1388,7 +1405,7 @@ restconf_ssl_accept_client(clicon_handle h,
const char *peername = SSL_get0_peername(rc->rc_ssl);
if (peername != NULL) {
/* Name checks were in scope and matched the peername */
clicon_debug(1, "%s peername:%s", __FUNCTION__, peername);
clixon_debug(CLIXON_DBG_DEFAULT, "%s peername:%s", __FUNCTION__, peername);
}
}
#if 0
@ -1402,7 +1419,7 @@ restconf_ssl_accept_client(clicon_handle h,
}
#endif
#if 0 /* debug */
if (clicon_debug_get())
if (clixon_debug_get())
restconf_listcerts(rc->rc_ssl);
#endif
} /* if ssl */
@ -1441,7 +1458,7 @@ restconf_ssl_accept_client(clicon_handle h,
*rcp = rc;
retval = 1; /* OK, up */
done:
clicon_debug(1, "%s retval %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval %d", __FUNCTION__, retval);
if (name)
free(name);
return retval;
@ -1475,8 +1492,11 @@ restconf_idle_timer_set(struct timeval t,
return retval;
}
/*! idle timeout timer callback
* @param[in] rc restconf connection, more specifically: callhome connection
/*! Idle timeout timer callback
*
* @param[in] rc Restconf connection, more specifically: callhome connection
* @retval 0 OK
* @retval -1 Error
*
* t0 tp t1 tn
* |---------|-----------|--------------------|
@ -1509,7 +1529,7 @@ restconf_idle_cb(int fd,
clicon_err(OE_YANG, EINVAL, "rsock is NULL");
goto done;
}
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (rc->rc_callhome && rsock->rs_periodic && rc->rc_s > 0 && rsock->rs_idle_timeout){
gettimeofday(&now, NULL);
timersub(&now, &rc->rc_t, &td); /* Last packet timestamp */
@ -1520,7 +1540,7 @@ restconf_idle_cb(int fd,
else{
to.tv_sec = rsock->rs_idle_timeout;
timeradd(&now, &to, &tn);
clicon_debug(1, "%s now:%lu timeout:%lu.%lu", __FUNCTION__,
clixon_debug(CLIXON_DBG_DEFAULT, "%s now:%lu timeout:%lu.%lu", __FUNCTION__,
now.tv_sec, tn.tv_sec, tn.tv_usec);
if (restconf_idle_timer_set(tn, rc, rsock->rs_description) < 0)
goto done;
@ -1538,6 +1558,7 @@ restconf_idle_timer_unreg(restconf_conn *rc)
}
/*! Set callhome periodic idle-timeout
*
* 1) If callhome and periodic, set timer for t0+idle-timeout(ti)
* 2) Timestamp any data passing on the socket(td)
* 3) At timeout (ti) check if ti = td+idle-timeout (for first timeout same as t0=td),
@ -1565,7 +1586,7 @@ restconf_idle_timer(restconf_conn *rc)
clicon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic");
goto done;
}
clicon_debug(1, "%s \"%s\" register", __FUNCTION__, rsock->rs_description);
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" register", __FUNCTION__, rsock->rs_description);
gettimeofday(&now, NULL);
to.tv_sec = rsock->rs_idle_timeout;
timeradd(&now, &to, &t);
@ -1603,7 +1624,7 @@ restconf_callhome_cb(int fd,
clicon_err(OE_YANG, EINVAL, "rsock is NULL");
goto done;
}
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
h = rsock->rs_h;
/* Already computed in restconf_socket_init, could be saved in rsock? */
if (clixon_inet2sin(rsock->rs_addrtype, rsock->rs_addrstr, rsock->rs_port, sa, &sa_len) < 0)
@ -1613,7 +1634,7 @@ restconf_callhome_cb(int fd,
goto done;
}
if (connect(s, sa, sa_len) < 0){
clicon_debug(1, "%s connect %hu fail:%d %s", __FUNCTION__, rsock->rs_port, errno, strerror(errno));
clixon_debug(CLIXON_DBG_DEFAULT, "%s connect %hu fail:%d %s", __FUNCTION__, rsock->rs_port, errno, strerror(errno));
close(s);
rsock->rs_attempts++;
/* Fail: Initiate new timer */
@ -1621,7 +1642,7 @@ restconf_callhome_cb(int fd,
goto done;
}
else {
clicon_debug(1, "%s connect %hu OK", __FUNCTION__, rsock->rs_port);
clixon_debug(CLIXON_DBG_DEFAULT, "%s connect %hu OK", __FUNCTION__, rsock->rs_port);
rsock->rs_attempts = 0;
if ((ret = restconf_ssl_accept_client(h, s, rsock, &rc)) < 0)
goto done;
@ -1648,6 +1669,8 @@ restconf_callhome_timer_unreg(restconf_socket *rsock)
* NYI: start-with, anchor-time
* @param[in] rsock restconf_socket
* @param[in] new if periodic: 1: Force a new period
* @retval 0 OK
* @retval -1 Error
* @see restconf_callhome_timer_unreg
*/
int
@ -1664,7 +1687,7 @@ restconf_callhome_timer(restconf_socket *rsock,
clicon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome");
goto done;
}
clicon_debug(1, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (!rsock->rs_callhome)
goto ok; /* shouldnt happen */
gettimeofday(&now, NULL);
@ -1692,9 +1715,9 @@ restconf_callhome_timer(restconf_socket *rsock,
}
cprintf(cb, "restconf callhome timer %s", rsock->rs_description);
if (rsock->rs_description)
clicon_debug(1, "%s registering \"%s\": +%lu", __FUNCTION__, rsock->rs_description, t.tv_sec-now.tv_sec);
clixon_debug(CLIXON_DBG_DEFAULT, "%s registering \"%s\": +%lu", __FUNCTION__, rsock->rs_description, t.tv_sec-now.tv_sec);
else
clicon_debug(1, "%s: %lu", __FUNCTION__, t.tv_sec);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: %lu", __FUNCTION__, t.tv_sec);
/* Should be only place restconf_callhome_cb is registered */
if (clixon_event_reg_timeout(t,
restconf_callhome_cb,
@ -1710,7 +1733,8 @@ restconf_callhome_timer(restconf_socket *rsock,
}
/*! Extract socket info from backend config
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xs socket config
* @param[in] nsc Namespace context
* @param[out] rsock restconf socket data, filled in with many fields
@ -1718,6 +1742,8 @@ restconf_callhome_timer(restconf_socket *rsock,
* @param[out] address Address as string, eg "0.0.0.0", "::"
* @param[out] addrtype One of inet:ipv4-address or inet:ipv6-address
* @param[out] port TCP Port
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_socket_extract(clicon_handle h,

View file

@ -92,7 +92,8 @@
#define ARRLEN(x) (sizeof(x) / sizeof(x[0]))
/*! Map http2 frame types in nghttp2
* I had expected it in in libnghttp2 but havent found it
*
* Had expected it in in libnghttp2 but havent found it
*/
static const map_str2int nghttp2_frame_type_map[] = {
{"DATA", NGHTTP2_DATA},
@ -119,7 +120,7 @@ clixon_nghttp2_log_cb(void *handle,
int suberr,
cbuf *cb)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
cprintf(cb, "Fatal error: %s", nghttp2_strerror(suberr));
return 0;
}
@ -131,12 +132,15 @@ nghttp2_print_header(const uint8_t *name,
const uint8_t *value,
size_t valuelen)
{
clicon_debug(1, "%s %s", name, value);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", name, value);
}
/* Print HTTP headers to |f|. Please note that this function does not
take into account that header name and value are sequence of
octets, therefore they may contain non-printable characters. */
/*! Print HTTP headers to |f|.
*
* Please note that this function does not
* take into account that header name and value are sequence of
* octets, therefore they may contain non-printable characters.
*/
static void
nghttp2_print_headers(nghttp2_nv *nva,
size_t nvlen)
@ -149,6 +153,7 @@ nghttp2_print_headers(nghttp2_nv *nva,
#endif /* NOTUSED */
/*! Send data to remote peer, Send at most the |length| bytes of |data|.
*
* This callback is required if the application uses
* `nghttp2_session_send()` to send data to the remote endpoint. If
* the application uses solely `nghttp2_session_mem_send()` instead,
@ -173,20 +178,20 @@ session_send_callback(nghttp2_session *session,
int s;
int sslerr;
clicon_debug(1, "%s buflen:%zu", __FUNCTION__, buflen);
clixon_debug(CLIXON_DBG_DEFAULT, "%s buflen:%zu", __FUNCTION__, buflen);
s = rc->rc_s;
while (totlen < buflen){
if (rc->rc_ssl){
if ((len = SSL_write(rc->rc_ssl, buf+totlen, buflen-totlen)) <= 0){
er = errno;
sslerr = SSL_get_error(rc->rc_ssl, len);
clicon_debug(1, "%s SSL_write: errno:%s(%d) sslerr:%d", __FUNCTION__,
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_write: errno:%s(%d) sslerr:%d", __FUNCTION__,
strerror(er),
er,
sslerr);
switch (sslerr){
case SSL_ERROR_WANT_WRITE: /* 3 */
clicon_debug(1, "%s write SSL_ERROR_WANT_WRITE", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write SSL_ERROR_WANT_WRITE", __FUNCTION__);
usleep(1000);
continue;
break;
@ -200,7 +205,7 @@ session_send_callback(nghttp2_session *session,
* platforms, linux here, freebsd want_write, or possibly differnt
* ssl lib versions?
*/
clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write EAGAIN", __FUNCTION__);
usleep(1000);
continue;
}
@ -220,7 +225,7 @@ session_send_callback(nghttp2_session *session,
else{
if ((len = write(s, buf+totlen, buflen-totlen)) < 0){
if (errno == EAGAIN){
clicon_debug(1, "%s write EAGAIN", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write EAGAIN", __FUNCTION__);
usleep(10000);
continue;
}
@ -247,10 +252,10 @@ session_send_callback(nghttp2_session *session,
retval = 0;
done:
if (retval < 0){
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
clicon_debug(1, "%s retval:%zd", __FUNCTION__, totlen);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%zd", __FUNCTION__, totlen);
return retval == 0 ? totlen : retval;
}
@ -264,7 +269,7 @@ recv_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -289,7 +294,7 @@ restconf_nghttp2_path(restconf_stream_data *sd)
cvec *cvv = NULL;
char *cn;
clicon_debug(1, "------------");
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
rc = sd->sd_conn;
if ((h = rc->rc_h) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
@ -341,7 +346,7 @@ restconf_nghttp2_path(restconf_stream_data *sd)
goto done;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (cvv)
cvec_free(cvv);
if (oneline)
@ -350,6 +355,7 @@ restconf_nghttp2_path(restconf_stream_data *sd)
}
/*! data callback, just pass pointer to cbuf
*
* XXX handle several chunks with cbuf
*/
static ssize_t
@ -384,7 +390,7 @@ restconf_sd_read(nghttp2_session *session,
#endif
assert(cbuf_len(cb) > sd->sd_body_offset);
remain = cbuf_len(cb) - sd->sd_body_offset;
clicon_debug(1, "%s length:%zu totlen:%zu, offset:%zu remain:%zu",
clixon_debug(CLIXON_DBG_DEFAULT, "%s length:%zu totlen:%zu, offset:%zu remain:%zu",
__FUNCTION__,
length,
cbuf_len(cb),
@ -400,7 +406,7 @@ restconf_sd_read(nghttp2_session *session,
}
memcpy(buf, cbuf_get(cb) + sd->sd_body_offset, len);
sd->sd_body_offset += len;
clicon_debug(1, "%s retval:%zu", __FUNCTION__, len);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%zu", __FUNCTION__, len);
return len;
}
@ -428,7 +434,7 @@ restconf_submit_response(nghttp2_session *session,
hdr = &hdrs[i++];
hdr->name = (uint8_t*)":status";
snprintf(valstr, 15, "%u", sd->sd_code);
clicon_debug(1, "%s status %d", __FUNCTION__, sd->sd_code);
clixon_debug(CLIXON_DBG_DEFAULT, "%s status %d", __FUNCTION__, sd->sd_code);
hdr->value = (uint8_t*)valstr;
hdr->namelen = strlen(":status");
hdr->valuelen = strlen(valstr);
@ -438,7 +444,7 @@ restconf_submit_response(nghttp2_session *session,
while ((cv = cvec_each(sd->sd_outp_hdrs, cv)) != NULL){
hdr = &hdrs[i++];
hdr->name = (uint8_t*)cv_name_get(cv);
clicon_debug(1, "%s hdr: %s", __FUNCTION__, hdr->name);
clixon_debug(CLIXON_DBG_DEFAULT, "%s hdr: %s", __FUNCTION__, hdr->name);
hdr->value = (uint8_t*)cv_string_get(cv);
hdr->namelen = strlen(cv_name_get(cv));
hdr->valuelen = strlen(cv_string_get(cv));
@ -453,7 +459,7 @@ restconf_submit_response(nghttp2_session *session,
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (hdrs)
free(hdrs);
return retval;
@ -469,7 +475,7 @@ http2_exec(restconf_conn *rc,
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (sd->sd_path){
free(sd->sd_path);
sd->sd_path = NULL;
@ -508,7 +514,7 @@ http2_exec(restconf_conn *rc,
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
@ -524,7 +530,7 @@ on_frame_recv_callback(nghttp2_session *session,
restconf_stream_data *sd = NULL;
char *query;
clicon_debug(1, "%s %s %d", __FUNCTION__,
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %d", __FUNCTION__,
clicon_int2str(nghttp2_frame_type_map, frame->hd.type),
frame->hd.stream_id);
switch (frame->hd.type) {
@ -566,7 +572,7 @@ on_invalid_frame_recv_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -588,7 +594,7 @@ on_data_chunk_recv_callback(nghttp2_session *session,
restconf_conn *rc = (restconf_conn *)user_data;
restconf_stream_data *sd;
clicon_debug(1, "%s %d", __FUNCTION__, stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, stream_id);
if ((sd = restconf_stream_find(rc, stream_id)) != NULL){
cbuf_append_buf(sd->sd_indata, (void*)data, len);
}
@ -603,7 +609,7 @@ before_frame_send_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -615,7 +621,7 @@ on_frame_send_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -628,7 +634,7 @@ on_frame_not_send_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -642,7 +648,7 @@ on_stream_close_callback(nghttp2_session *session,
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s %d %s", __FUNCTION__, error_code, nghttp2_strerror(error_code));
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d %s", __FUNCTION__, error_code, nghttp2_strerror(error_code));
#if 0 // NOTNEEDED /* XXX think this is not necessary? */
if (error_code){
if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
@ -662,7 +668,7 @@ on_begin_headers_callback(nghttp2_session *session,
restconf_conn *rc = (restconf_conn *)user_data;
restconf_stream_data *sd;
clicon_debug(1, "%s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type));
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type));
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
sd = restconf_stream_data_new(rc, frame->hd.stream_id);
@ -672,6 +678,7 @@ on_begin_headers_callback(nghttp2_session *session,
}
/*! Map from nghttp2 headers to "fcgi" type parameters used in clixon code
*
* Both |name| and |value| are guaranteed to be NULL-terminated.
*/
static int
@ -707,6 +714,7 @@ nghttp2_hdr2clixon(clicon_handle h,
}
/*! Header name/value pair is received
*
* Both |name| and |value| are guaranteed to be NULL-terminated.
* If the application uses `nghttp2_session_mem_recv()`, it can return
* :enum:`NGHTTP2_ERR_PAUSE` to make `nghttp2_session_mem_recv()`
@ -728,12 +736,12 @@ on_header_callback(nghttp2_session *session,
switch (frame->hd.type){
case NGHTTP2_HEADERS:
assert (frame->headers.cat == NGHTTP2_HCAT_REQUEST);
clicon_debug(1, "%s HEADERS %s %s", __FUNCTION__, name, value);
clixon_debug(CLIXON_DBG_DEFAULT, "%s HEADERS %s %s", __FUNCTION__, name, value);
if (nghttp2_hdr2clixon(rc->rc_h, (char*)name, (char*)value) < 0)
goto done;
break;
default:
clicon_debug(1, "%s %s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type), name);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, frame->hd.type), name);
break;
}
retval = 0;
@ -751,7 +759,7 @@ select_padding_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return frame->hd.length;
}
@ -767,12 +775,13 @@ data_source_read_length_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
#endif /* NOTUSED */
/*! Invoked when a frame header is received.
*
* Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will
* also be called when frame header of CONTINUATION frame is received.
*/
@ -782,13 +791,14 @@ on_begin_frame_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, hd->type));
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, clicon_int2str(nghttp2_frame_type_map, hd->type));
if (hd->type == NGHTTP2_CONTINUATION)
assert(0);
return 0;
}
/*! Send complete DATA frame for no-copy
*
* Callback function invoked when :enum:`NGHTTP2_DATA_FLAG_NO_COPY` is
* used in :type:`nghttp2_data_source_read_callback` to send complete
* DATA frame.
@ -801,7 +811,7 @@ send_data_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -815,7 +825,7 @@ pack_extension_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -828,7 +838,7 @@ unpack_extension_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
#endif /* NOTUSED */
@ -843,7 +853,7 @@ on_extension_chunk_recv_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -856,7 +866,7 @@ error_callback(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -871,7 +881,7 @@ error_callback2(nghttp2_session *session,
void *user_data)
{
// restconf_conn *rc = (restconf_conn *)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
clicon_err(OE_NGHTTP2, lib_error_code, "%s", msg);
return 0;
}
@ -894,7 +904,7 @@ http2_recv(restconf_conn *rc,
int retval = -1;
nghttp2_error ngerr;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (rc->rc_ngsession == NULL){
/* http2_session_init not called */
clicon_err(OE_RESTCONF, EINVAL, "No nghttp2 session");
@ -931,7 +941,7 @@ http2_recv(restconf_conn *rc,
}
retval = 1; /* OK */
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
fail:
retval = 0;
@ -948,7 +958,7 @@ http2_send_server_connection(restconf_conn *rc)
,{NGHTTP2_SETTINGS_ENABLE_PUSH, 0}};
nghttp2_error ngerr;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ngerr = nghttp2_submit_settings(rc->rc_ngsession,
NGHTTP2_FLAG_NONE,
iv,
@ -962,7 +972,7 @@ http2_send_server_connection(restconf_conn *rc)
}
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}

View file

@ -98,8 +98,11 @@ api_path_is_restconf(clicon_handle h)
}
/*! Determine the root of the RESTCONF API by accessing /.well-known
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @retval 0 OK
* @retval -1 Error
* @see RFC8040 3.1 and RFC7320
* In line with the best practices defined by [RFC7320], RESTCONF
* enables deployments to specify where the RESTCONF API is located.
@ -113,7 +116,7 @@ api_well_known(clicon_handle h,
cbuf *cb = NULL;
int head;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (req == NULL){
errno = EINVAL;
goto done;
@ -150,12 +153,14 @@ api_well_known(clicon_handle h,
}
/*! Retrieve the Top-Level API Resource /restconf/ (exact)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Generic request handle
* @param[in] method Http method
* @param[in] pretty Pretty print
* @param[in] media_out Restconf output media
* @retval 0 OK
* @retval -1 Error
* @note Only returns null for operations and data,...
* See RFC8040 3.3
* @see api_root_restconf for accessing /restconf/ *
@ -174,7 +179,7 @@ api_root_restconf_exact(clicon_handle h,
cbuf *cb = NULL;
int head;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
head = strcmp(request_method, "HEAD") == 0;
if (!head && strcmp(request_method, "GET") != 0){
if (restconf_method_notallowed(h, req, "GET", pretty, media_out) < 0)
@ -230,7 +235,7 @@ api_root_restconf_exact(clicon_handle h,
/** A stub implementation of the operational state datastore. The full
* implementation is required by https://tools.ietf.org/html/rfc8527#section-3.1
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] req Generic http handle
* @param[in] pretty Pretty-print
* @param[in] media_out Restconf output media
@ -243,31 +248,33 @@ api_operational_state(clicon_handle h,
restconf_media media_out)
{
clicon_debug(1, "%s request method:%s", __FUNCTION__, request_method);
clixon_debug(CLIXON_DBG_DEFAULT, "%s request method:%s", __FUNCTION__, request_method);
/* We are not implementing this method at this time, 20201105 despite it
* being mandatory https://tools.ietf.org/html/rfc8527#section-3.1 */
return restconf_notimplemented(h, req, pretty, media_out);
}
/*!
/*! get yang lib version
*
* See https://tools.ietf.org/html/rfc7895
* @param[in] pretty Pretty-print
* @param[in] media_out Restconf output media
* @retval 0 OK
* @retval -1 Error
*/
static int
api_yang_library_version(clicon_handle h,
void *req,
int pretty,
restconf_media media_out)
{
int retval = -1;
cxobj *xt = NULL;
cbuf *cb = NULL;
yang_stmt *yspec;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
goto done;
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
@ -312,6 +319,7 @@ api_yang_library_version(clicon_handle h,
}
/*! Generic REST method, GET, PUT, DELETE, etc
*
* @param[in] h CLIXON handle
* @param[in] r Fastcgi request handle
* @param[in] api_path According to restconf (Sec 3.5.1.1 in [draft])
@ -321,6 +329,8 @@ api_yang_library_version(clicon_handle h,
* @param[in] pretty Set to 1 for pretty-printed xml/json output
* @param[in] media_out Restconf output media
* @param[in] ds 0 if "data" resource, 1 if rfc8527 "ds" resource
* @retval 0 OK
* @retval -1 Error
*/
static int
api_data(clicon_handle h,
@ -339,9 +349,9 @@ api_data(clicon_handle h,
char *request_method;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
request_method = restconf_param_get(h, "REQUEST_METHOD");
clicon_debug(1, "%s method:%s", __FUNCTION__, request_method);
clixon_debug(CLIXON_DBG_DEFAULT, "%s method:%s", __FUNCTION__, request_method);
/* https://tools.ietf.org/html/rfc8527#section-3.2 */
/* We assume that dynamic datastores are read only at this time 20201105 */
@ -389,7 +399,7 @@ api_data(clicon_handle h,
goto done;
retval = api_return_err0(h, req, xerr, pretty, media_out, 0);
}
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
done:
if (xerr)
xml_free(xerr);
@ -397,6 +407,7 @@ api_data(clicon_handle h,
}
/*! Operations REST method, POST
*
* @param[in] h CLIXON handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] request_method eg GET,...
@ -406,6 +417,8 @@ api_data(clicon_handle h,
* @param[in] qvec Vector of query string (QUERY_STRING)
* @param[in] data Stream input data
* @param[in] media_out Output media
* @retval 0 OK
* @retval -1 Error
*/
static int
api_operations(clicon_handle h,
@ -422,7 +435,7 @@ api_operations(clicon_handle h,
int retval = -1;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (strcmp(request_method, "GET")==0)
retval = api_operations_get(h, req, path, pi, qvec, data, pretty, media_out);
else if (strcmp(request_method, "POST")==0)
@ -440,9 +453,12 @@ api_operations(clicon_handle h,
}
/*! Process a /restconf root input, this is the root of the restconf processing
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] qvec Query parameters, ie the ?<id>=<val>&<id>=<val> stuff
* @retval 0 OK
* @retval -1 Error
* @see api_root_restconf_exact for accessing /restconf/ exact
*/
int
@ -466,7 +482,7 @@ api_root_restconf(clicon_handle h,
int ret;
cxobj *xerr = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (req == NULL){
errno = EINVAL;
goto done;
@ -496,7 +512,7 @@ api_root_restconf(clicon_handle h,
goto ok;
}
}
clicon_debug(1, "%s ACCEPT: %s %s", __FUNCTION__, media_str, restconf_media_int2str(media_out));
clixon_debug(CLIXON_DBG_DEFAULT, "%s ACCEPT: %s %s", __FUNCTION__, media_str, restconf_media_int2str(media_out));
if ((pvec = clicon_strsep(path, "/", &pn)) == NULL)
goto done;
@ -527,14 +543,14 @@ api_root_restconf(clicon_handle h,
goto done;
goto ok;
}
clicon_debug(1, "%s: api_resource=%s", __FUNCTION__, api_resource);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: api_resource=%s", __FUNCTION__, api_resource);
if (uri_str2cvec(path, '/', '=', 1, &pcvec) < 0) /* rest url eg /album=ricky/foo */
goto done;
/* data */
if ((cb = restconf_get_indata(req)) == NULL) /* XXX NYI ACTUALLY not always needed, do this later? */
goto done;
indata = cbuf_get(cb);
clicon_debug(1, "%s DATA=%s", __FUNCTION__, indata);
clixon_debug(CLIXON_DBG_DEFAULT, "%s DATA=%s", __FUNCTION__, indata);
/* If present, check credentials. See "plugin_credentials" in plugin
* retvals:
@ -611,7 +627,7 @@ api_root_restconf(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
#ifdef WITH_RESTCONF_FCGI
if (cb)
cbuf_free(cb);

View file

@ -120,8 +120,8 @@ static struct stream_child *STREAM_CHILD = NULL;
/*! Check if uri path denotes a stream/notification path
*
* @retval 0 No, not a stream path
* @retval 1 Yes, a stream path
* @retval 0 No, not a stream path
*/
int
api_path_is_stream(clicon_handle h)
@ -151,7 +151,7 @@ api_path_is_stream(clicon_handle h)
/*! Find restconf child using PID and cleanup FCGI Request data
*
* For forked, called on SIGCHILD
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] pid Process id of child
* @note could hang STREAM_CHILD list on clicon handle instead.
*/
@ -177,6 +177,7 @@ stream_child_free(clicon_handle h,
}
/*! Free all streams
*
* Typically called on restconf exit
*/
int
@ -193,8 +194,11 @@ stream_child_freeall(clicon_handle h)
}
/*! Callback when stream notifications arrive from backend
*
* @param[in] s Socket
* @param[in] req Generic Www handle (can be part of clixon handle)
* @retval 0 OK
* @retval -1 Error
* @see netconf_notification_cb
*/
static int
@ -211,16 +215,16 @@ restconf_stream_cb(int s,
int pretty = 0; /* XXX should be via arg */
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* get msg (this is the reason this function is called) */
if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0){
clicon_debug(1, "%s msg_rcv error", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s msg_rcv error", __FUNCTION__);
goto done;
}
clicon_debug(1, "%s msg: %s", __FUNCTION__, reply?reply->op_body:"null");
clixon_debug(CLIXON_DBG_DEFAULT, "%s msg: %s", __FUNCTION__, reply?reply->op_body:"null");
/* handle close from remote end: this will exit the client */
if (eof){
clicon_debug(1, "%s eof", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s eof", __FUNCTION__);
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
errno = ESHUTDOWN;
FCGX_FPrintF(r->out, "SHUTDOWN\r\n");
@ -262,7 +266,7 @@ restconf_stream_cb(int s,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: %d", __FUNCTION__, retval);
if (xtop != NULL)
xml_free(xtop);
if (reply)
@ -273,13 +277,16 @@ restconf_stream_cb(int s,
}
/*! Send subscription to backend
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] name Stream name
* @param[in] qvec
* @param[in] pretty Pretty-print json/xml reply
* @param[in] media_out Restconf output media
* @param[out] sp Socket -1 if not set
* @retval 0 OK
* @retval -1 Error
*/
static int
restconf_stream(clicon_handle h,
@ -299,7 +306,7 @@ restconf_stream(clicon_handle h,
cg_var *cv;
char *vname;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
*sp = -1;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
@ -346,7 +353,7 @@ restconf_stream(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval: %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: %d", __FUNCTION__, retval);
if (xret)
xml_free(xret);
if (cb)
@ -359,6 +366,7 @@ restconf_stream(clicon_handle h,
#include "restconf_stream.h"
/*! Listen sock callback (from proxy?)
*
* @param[in] s Socket
* @param[in] req Generic Www handle (can be part of clixon handle)
*/
@ -368,9 +376,9 @@ stream_checkuplink(int s,
{
FCGX_Request *r = (FCGX_Request *)arg;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (FCGX_GetError(r->out) != 0){ /* break loop */
clicon_debug(1, "%s FCGX_GetError upstream", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s FCGX_GetError upstream", __FUNCTION__);
clixon_exit_set(1);
}
return 0;
@ -384,9 +392,9 @@ stream_timeout(int s,
struct timeval t1;
FCGX_Request *r = (FCGX_Request *)arg;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (FCGX_GetError(r->out) != 0){ /* break loop */
clicon_debug(1, "%s FCGX_GetError upstream", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s FCGX_GetError upstream", __FUNCTION__);
clixon_exit_set(1);
}
else{
@ -399,10 +407,13 @@ stream_timeout(int s,
}
/*! Process a stream request
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Generic Www handle (can be part of clixon handle)
* @param[in] qvec Query parameters, ie the ?<id>=<val>&<id>=<val> stuff
* @param[out] finish Set to zero, if request should not be finnished by upper layer
* @retval 0 OK
* @retval -1 Error
*/
int
api_stream(clicon_handle h,
@ -431,7 +442,7 @@ api_stream(clicon_handle h,
struct stream_child *sc;
#endif
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
streampath = clicon_option_str(h, "CLICON_STREAM_PATH");
if ((path = restconf_uripath(h)) == NULL)
goto done;
@ -467,7 +478,7 @@ api_stream(clicon_handle h,
goto done;
goto ok;
}
clicon_debug(1, "%s: method=%s", __FUNCTION__, method);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: method=%s", __FUNCTION__, method);
if (uri_str2cvec(path, '/', '=', 1, &pcvec) < 0) /* rest url eg /album=ricky/foo */
goto done;
@ -475,7 +486,7 @@ api_stream(clicon_handle h,
if ((cb = restconf_get_indata(req)) == NULL)
goto done;
indata = cbuf_get(cb);
clicon_debug(1, "%s DATA=%s", __FUNCTION__, indata);
clixon_debug(CLIXON_DBG_DEFAULT, "%s DATA=%s", __FUNCTION__, indata);
/* If present, check credentials. See "plugin_credentials" in plugin
* See RFC 8040 section 2.5
@ -511,12 +522,12 @@ api_stream(clicon_handle h,
req,
"stream socket") < 0)
goto done;
clicon_debug(1, "%s before loop", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s before loop", __FUNCTION__);
/* Poll upstream errors */
stream_timeout(0, req);
/* Start loop */
clixon_event_loop(h);
clicon_debug(1, "%s after loop", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s after loop", __FUNCTION__);
clicon_rpc_close_session(h);
clixon_event_unreg_fd(s, restconf_stream_cb);
close(s);
@ -551,7 +562,7 @@ api_stream(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (xerr)
xml_free(xerr);
if (pvec)

View file

@ -100,7 +100,7 @@ snmp_common_handler(netsnmp_mib_handler *handler,
oid_cbuf(cb, (*shp)->sh_oid, (*shp)->sh_oidlen);
if (oid_eq(requestvb->name, requestvb->name_length,
(*shp)->sh_oid, (*shp)->sh_oidlen) == 0){ /* equal */
clicon_debug(1, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
cbuf_get(cb),
snmp_msg_int2str(reqinfo->mode),
request->inclusive, tablehandler?"table":"scalar");
@ -110,7 +110,7 @@ snmp_common_handler(netsnmp_mib_handler *handler,
oid_cbuf(cb, requestvb->name, requestvb->name_length);
cprintf(cb, ")");
// nhreg->rootoid same as shp
clicon_debug(1, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" %s inclusive:%d %s", __FUNCTION__,
cbuf_get(cb),
snmp_msg_int2str(reqinfo->mode),
request->inclusive, tablehandler?"table":"scalar");
@ -122,7 +122,8 @@ snmp_common_handler(netsnmp_mib_handler *handler,
return retval;
}
/*!
/*! scalar return
*
* @param[in] reqinfo Agent transaction request structure
* @param[in] request The netsnmp request info structure.
* @retval 0 OK
@ -180,7 +181,7 @@ snmp_scalar_return(cxobj *xs,
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "%s %s", __FUNCTION__, reason);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, reason);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
@ -210,6 +211,7 @@ snmp_scalar_return(cxobj *xs,
}
/*! Scalar handler, set a value to clixon
*
* get xpath: see yang2api_path_fmt / api_path2xpath
* @param[in] h Clixon handle
* @param[in] ys Yang node
@ -244,7 +246,7 @@ snmp_scalar_get(clicon_handle h,
cxobj *xcache = NULL;
char *body = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Prepare backend call by constructing namespace context */
if (xml_nsctx_yang(ys, &nsc) < 0)
goto done;
@ -298,7 +300,7 @@ snmp_scalar_get(clicon_handle h,
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "%s %s", __FUNCTION__, reason);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, reason);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
@ -375,6 +377,7 @@ snmp_yang2xml(cxobj *xtop,
}
/*! Scalar handler, get a value from clixon
*
* @param[in] h Clixon handle
* @param[in] ys Yang node
* @param[in] cvk Vector of index/Key variables, if any
@ -404,7 +407,7 @@ snmp_scalar_set(clicon_handle h,
int asn1_type;
enum operation_type op = OP_MERGE;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((xtop = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
goto done;
if (snmp_yang2xml(xtop, ys, cvk, &xbot) < 0)
@ -553,7 +556,7 @@ snmp_cache_set(clicon_handle h,
int isrowstatus = 0;
cxobj *xcache = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -597,7 +600,7 @@ snmp_cache_set(clicon_handle h,
goto done;
}
else if (strcmp(valstr, "destroy") == 0){
clicon_debug(1, "%s %d", __FUNCTION__, rowstatus);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, rowstatus);
/* Dont send delete to backend if notInService(2) */
if (snmp_cache_row_op(h, yang_parent_get(ys), cvk, "delete", rowstatus!=2) < 0)
goto done;
@ -659,7 +662,7 @@ snmp_table_rowstatus_get(clicon_handle h,
char *intstr;
char *reason = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Prepare backend call by constructing namespace context */
if (xml_nsctx_yang(ys, &nsc) < 0)
goto done;
@ -672,14 +675,14 @@ snmp_table_rowstatus_get(clicon_handle h,
if ((ret = yang_enum2valstr(yrestype, body, &intstr)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "%s %s invalid or not found", __FUNCTION__, body);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s invalid or not found", __FUNCTION__, body);
*rowstatus = 0;
}
else {
if ((ret = parse_int32(intstr, rowstatus, &reason)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "%s parse_int32: %s", __FUNCTION__, reason);
clixon_debug(CLIXON_DBG_DEFAULT, "%s parse_int32: %s", __FUNCTION__, reason);
*rowstatus = 0;
}
}
@ -718,7 +721,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
netsnmp_variable_list *requestvb = request->requestvb;
int ret;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (snmp_common_handler(handler, nhreg, reqinfo, request, 0, &sh) < 0)
goto done;
/* see net-snmp/agent/snmp_agent.h / net-snmp/library/snmp.h */
@ -740,7 +743,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
if (type_yang2asn1(sh->sh_ys, &asn1_type, 0) < 0)
goto done;
if (requestvb->type != asn1_type){
clicon_debug(1, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok;
@ -787,7 +790,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
ok:
retval = SNMP_ERR_NOERROR;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
@ -797,6 +800,8 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
* @param[in] nhreg Root registration info.
* @param[in] reqinfo Agent transaction request structure
* @param[in] requests The netsnmp request info structure.
* @retval SNMP_ERR_NOERROR OK
* @retval -1 Error
* @see clixon_snmp_table_handler
*/
int
@ -809,7 +814,7 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
netsnmp_request_info *req;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
for (req = requests; req; req = req->next){
ret = clixon_snmp_scalar_handler1(handler, nhreg, reqinfo, req);
if (ret != SNMP_ERR_NOERROR){
@ -836,9 +841,9 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
* @param[in] oidslen OID length of scalar
* @param[in] reqinfo Agent transaction request structure
* @param[in] request The netsnmp request info structure.
* @retval -1 Error
* @retval 0 Object not found
* @retval 1 OK
* @retval 0 Object not found
* @retval -1 Error
*/
static int
snmp_table_get(clicon_handle h,
@ -938,6 +943,7 @@ snmp_table_get(clicon_handle h,
}
/*! Set value in table
*
* Get yang of leaf from first part of OID
* Create xpath with right keys from later part of OID
* Query clixon if object exists, if so return value
@ -948,9 +954,9 @@ snmp_table_get(clicon_handle h,
* @param[in] reqinfo Agent transaction request structure
* @param[in] request The netsnmp request info structure.
* @param[out] err Error code if failed (retval = 0)
* @retval -1 Error
* @retval 0 Failed, err set
* @retval 1 OK
* @retval 0 Failed, err set
* @retval -1 Error
*/
static int
snmp_table_set(clicon_handle h,
@ -1047,7 +1053,7 @@ snmp_table_set(clicon_handle h,
goto done;
requestvb = request->requestvb;
if (requestvb->type != asn1_type){
clicon_debug(1, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok;
@ -1152,6 +1158,7 @@ snmp_table_set(clicon_handle h,
}
/*! Find "next" object from oids minus key and return that.
*
* @param[in] h Clixon handle
* @param[in] ylist Yang of table (of list type)
* @param[in] oids OID of ultimate scalar value
@ -1194,7 +1201,7 @@ snmp_table_getnext(clicon_handle h,
yang_stmt *ynext = NULL;
cbuf *cb = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){
clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
@ -1256,7 +1263,7 @@ snmp_table_getnext(clicon_handle h,
goto done;
}
oid_cbuf(cb, oidnext, oidnextlen);
clicon_debug(1, "%s next: %s", __FUNCTION__, cbuf_get(cb));
clixon_debug(CLIXON_DBG_DEFAULT, "%s next: %s", __FUNCTION__, cbuf_get(cb));
}
retval = found;
done:
@ -1277,6 +1284,8 @@ snmp_table_getnext(clicon_handle h,
* @param[in] nhreg Root registration info.
* @param[in] reqinfo Agent transaction request structure
* @param[in] request The netsnmp request info structure.
* @retval 0 OK
* @retval -1 Error
*/
static int
clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
@ -1293,11 +1302,11 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
netsnmp_variable_list *requestvb;
int err = 0;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if ((ret = snmp_common_handler(handler, nhreg, reqinfo, request, 1, &sh)) < 0)
goto done;
if (sh->sh_ys == NULL){
clicon_debug(1, "%s Error table not registered", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error table not registered", __FUNCTION__);
goto ok;
}
requestvb = request->requestvb;
@ -1315,7 +1324,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
}
clicon_debug(1, "%s Nosuchinstance", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Nosuchinstance", __FUNCTION__);
}
break;
case MODE_GETNEXT: // 161
@ -1330,13 +1339,13 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
}
clicon_debug(1, "%s No such object", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s No such object", __FUNCTION__);
}
break;
case MODE_SET_RESERVE1: // 0
if (!yang_config_ancestor(sh->sh_ys)){
netsnmp_request_set_error(request, SNMP_ERR_NOTWRITABLE);
goto done;;
goto done;
}
// Check types: compare type in requestvb to yang type (or do later)
break;
@ -1352,7 +1361,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
}
clicon_debug(1, "%s Nosuchinstance", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Nosuchinstance", __FUNCTION__);
}
/*
* There does not seem to be a separate validation action and commit does not
@ -1401,6 +1410,8 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
* @param[in] nhreg Root registration info.
* @param[in] reqinfo Agent transaction request structure
* @param[in] requests The netsnmp request info structure.
* @retval 0 OK
* @retval -1 Error
* @see clixon_snmp_scalar_handler
*/
int
@ -1413,7 +1424,7 @@ clixon_snmp_table_handler(netsnmp_mib_handler *handler,
netsnmp_request_info *req;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
for (req = requests; req; req = req->next){
ret = clixon_snmp_table_handler1(handler, nhreg, reqinfo, req);
if (ret != SNMP_ERR_NOERROR){

View file

@ -217,6 +217,7 @@ yang_type_to_snmp(yang_stmt *ytype,
}
/*! Translate from snmp string to int representation
*
* @note Internal snmpd, maybe find something in netsnmpd?
*/
int
@ -268,6 +269,7 @@ oid_eq(const oid *objid0,
}
/*! Append a second OID to a first
*
* @param[in,out] objid0 First OID vector
* @param[in,out] objid0len Length of first OID vector
* @param[in] objid1 Second OID vector
@ -295,6 +297,7 @@ oid_append(const oid *objid0,
}
/*! Print objid to file
*
* @see fprint_objid but prints symbolic
*/
int
@ -443,6 +446,7 @@ yang_extension_value_opt(yang_stmt *ys,
}
/*! Given a YANG node, return SMIv2 oid extension as OID
*
* @param[in] yn Yang node
* @param[out] objid OID vector, assume allocated with MAX_OID_LEN > oidlen
* @param[out] objidlen Length of OID vector on return
@ -472,7 +476,7 @@ yangext_oid_get(yang_stmt *yn,
if (yang_extension_value_opt(yref, "smiv2:oid", &exist, &oidstr) < 0)
goto done;
if (exist == 0 || oidstr == NULL){
clicon_debug(1, "OID not found as SMIv2 yang extension of %s", yang_argument_get(yref));
clixon_debug(CLIXON_DBG_DEFAULT, "OID not found as SMIv2 yang extension of %s", yang_argument_get(yref));
goto fail;
}
if (snmp_parse_oid(oidstr, objid, objidlen) == NULL){
@ -490,13 +494,14 @@ yangext_oid_get(yang_stmt *yn,
}
/*! Given a YANG node, return 1 if leaf has oid directive in it, otherwise 0
*
* @param[in] yn Yang node
* @retval 1 found
* @retval 0 not found
*/
int
yangext_is_oid_exist(yang_stmt *yn) {
yangext_is_oid_exist(yang_stmt *yn)
{
int exist = 0;
char *oidstr = NULL;
@ -513,6 +518,7 @@ yangext_is_oid_exist(yang_stmt *yn) {
/*! Duplicate clixon snmp handler struct
*
* Use signature of libnetsnmp data_clone field of netsnmp_mib_handler in agent_handler.h
* @param[in] arg
*/
@ -538,6 +544,7 @@ snmp_handle_clone(void *arg)
}
/*! Free clixon snmp handler struct
*
* Use signature of libnetsnmp data_free field of netsnmp_mib_handler in agent_handler.h
* @param[in] arg
*/
@ -648,7 +655,7 @@ type_snmp2xml(yang_stmt *ys,
yang_stmt *yrestype = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (valstr == NULL){
clicon_err(OE_UNIX, EINVAL, "valstr is NULL");
goto done;
@ -732,7 +739,7 @@ type_snmp2xml(yang_stmt *ys,
}
default:
assert(0); // XXX
clicon_debug(1, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype));
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype));
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
@ -746,7 +753,7 @@ type_snmp2xml(yang_stmt *ys,
}
retval = 1;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval);
if (origtype)
free(origtype);
if (cv)
@ -793,7 +800,7 @@ type_xml2snmp_pre(char *xmlstr0,
if ((ret = yang_enum2valstr(yrestype, xmlstr0, &str)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "Invalid enum valstr %s", xmlstr0);
clixon_debug(CLIXON_DBG_DEFAULT, "Invalid enum valstr %s", xmlstr0);
goto fail;
}
}
@ -819,7 +826,7 @@ type_xml2snmp_pre(char *xmlstr0,
if ((ret = parse_dec64(xmlstr0, cv_dec64_n_get(cv), &num, NULL)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "Invalid decimal64 valstr %s", xmlstr0);
clixon_debug(CLIXON_DBG_DEFAULT, "Invalid decimal64 valstr %s", xmlstr0);
goto fail;
}
cv_dec64_i_set(cv, num);
@ -835,7 +842,7 @@ type_xml2snmp_pre(char *xmlstr0,
}
retval = 1;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
return retval;
@ -904,7 +911,7 @@ type_xml2snmp(char *snmpstr,
oid oid1[MAX_OID_LEN] = {0,};
size_t sz1 = MAX_OID_LEN;
if (snmp_parse_oid(snmpstr, oid1, &sz1) == NULL){
clicon_debug(1, "Failed to parse OID %s", snmpstr);
clixon_debug(CLIXON_DBG_DEFAULT, "Failed to parse OID %s", snmpstr);
goto fail;
}
*snmplen = sizeof(oid)*sz1;
@ -960,7 +967,7 @@ type_xml2snmp(char *snmpstr,
}
memset(*snmpval, 0, *snmplen + 1);
if ((eaddr = ether_aton(snmpstr)) == NULL){
clicon_debug(1, "ether_aton(%s)", snmpstr);
clixon_debug(CLIXON_DBG_DEFAULT, "ether_aton(%s)", snmpstr);
goto fail;
}
memcpy(*snmpval, eaddr, sizeof(*eaddr));
@ -980,7 +987,7 @@ type_xml2snmp(char *snmpstr,
}
retval = 1;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval);
return retval;
fail:
retval = 0;
@ -988,6 +995,7 @@ type_xml2snmp(char *snmpstr,
}
/*! Construct an xpath from yang statement, internal fn using cb
*
* Recursively construct it to the top.
* @param[in] ys Yang statement
* @param[in] keyvec Cvec of key values
@ -1053,6 +1061,7 @@ snmp_yang2xpath_cb(yang_stmt *ys,
}
/*! Construct an xpath from yang statement, limited to SNMP table translations
*
* Recursively construct it to the top.
* @param[in] ys Yang statement
* @param[in] keyvec Cvec of key values
@ -1089,12 +1098,15 @@ snmp_yang2xpath(yang_stmt *ys,
}
/*! Translate from xml body string to SMI OID representation
*
* For ints this is one to one, eg 42 -> 42
* But for eg strings this is more complex, eg foo -> 3.6.22.22 (or something,...)
* @param[in] str XML body string
* @param[in] yi Yang statement
* @param[out] objid OID vector
* @param[out] objidlen Length of OID vector
* @retval 0 OK
* @retval -1 Error
*/
int
snmp_str2oid(char *str,
@ -1135,12 +1147,15 @@ snmp_str2oid(char *str,
}
/*! Translate from SMI OID representation to name
*
* For ints this is one to one, eg 42 -> 42
* But for eg strings this is more complex, eg foo -> 3.6.22.22 (or something,...)
* @param[in,out] oidi ObjID vector
* @param[in,out] oidilen Length of ObjID vector
* @param[in] yk Yang statement of key
* @param[out] cv CLIgen variable string notation as "x.y.z"
* @retval 0 OK
* @retval -1 Error
* @see rfc2578 Section 7.7
*/
int
@ -1223,7 +1238,7 @@ clixon_snmp_err_cb(void *handle,
{
const char *errstr;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (suberr < 0){
if (suberr < -CLIXON_ERR_SNMP_MIB){
switch (suberr+CLIXON_ERR_SNMP_MIB){
@ -1262,9 +1277,9 @@ clixon_snmp_err_cb(void *handle,
* @param[in] cvk_name Vector of list keys
* @param[out] cvk_val Vector of XML key values
* @param[out] objidk OID key part, to be appended to node OID
* @retval -1 Error
* @retval 0 Invalid (not all indexes present)
* @retval 1 OK
* @retval 0 Invalid (not all indexes present)
* @retval -1 Error
* Both cvk_val and cvk_oid can be re-used in successive calls but need to be freed w cvec_free after use
*/
int
@ -1326,6 +1341,7 @@ snmp_xmlkey2val_oid(cxobj *xentry,
* Peeks into internal lib global variables, may be sensitive to library change
*/
/*! Check if netsnmp is connected
*
* @retval 1 yes, running
* @retval 0 No, not running
* XXX: this peeks into the "main_session" global variable in agent/snmp_agent.c
@ -1340,6 +1356,7 @@ clixon_snmp_api_agent_check(void)
}
/*! Cleanup remaining libnetsnmb memory
*
* XXX: this peeks into the "tclist" global variable in snmplib/parse.c
* Tried to find API function but failed
*/
@ -1354,12 +1371,13 @@ clixon_snmp_api_agent_cleanup(void)
}
/*! See if oid is registered
*
* This is good enough for add,
* But for delete a more advanced function is needed
* @see netsnmp_subtree_load
* @retval -1 Error
* @retval 0 Not found
* @retval 1 Found
* @retval 0 Not found
* @retval -1 Error
*/
int
clixon_snmp_api_oid_find(oid *oid0,

View file

@ -84,6 +84,7 @@ clicon_snmp_pidfile(clicon_handle h)
}
/*! Signal terminates process
*
* Just set exit flag for proper exit in event loop
*/
static void
@ -99,6 +100,7 @@ clixon_snmp_sig_term(int arg)
}
/*! Clean and close all state of netconf process (but dont exit).
*
* Cannot use h after this
* @param[in] h Clixon handle
*/
@ -139,7 +141,9 @@ snmp_terminate(clicon_handle h)
/*! Get which sockets are used from SNMP API, the register single sockets into clixon event system
*
* @param[in] h Clixon handle
* @param[in] register if 1 register snmp sockets with event handler. If 0 close and unregister
* @param[in] register If 1 register snmp sockets with event handler. If 0 close and unregister
* @retval 0 OK
* @retval -1 Error
* This is a workaround for netsnmps API usiing fdset:s, instead an fdset is created before calling
* the snmp api
* if you use select(), see snmp_select_info() in snmp_api(3)
@ -166,7 +170,7 @@ clixon_snmp_fdset_register(clicon_handle h,
/* eg 4, 6, 8 */
for (s=0; s<numfds; s++){
if (FD_ISSET(s, &readfds)){
clicon_debug(1, "%s %d", __FUNCTION__, s);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, s);
if (regfd){
if (clixon_event_reg_fd(s, clixon_snmp_input_cb, h, "snmp socket") < 0)
goto done;
@ -184,10 +188,13 @@ clixon_snmp_fdset_register(clicon_handle h,
}
/*! Callback for single socket
*
* This is a workaround for netsnmps API usiing fdset:s, instead an fdset is created before calling
* the snmp api
* @param[in] s Read socket
* @param[in] arg Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
static int
clixon_snmp_input_cb(int s,
@ -198,7 +205,7 @@ clixon_snmp_input_cb(int s,
clicon_handle h = (clicon_handle)arg;
int ret;
clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, s);
clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, s);
FD_ZERO(&readfds);
FD_SET(s, &readfds);
(void)snmp_read(&readfds);
@ -232,8 +239,11 @@ clixon_snmp_input_cb(int s,
}
/*! Init netsnmp agent connection
*
* @param[in] h Clixon handle
* @param[in] logdst Log destination, see clixon_log.h
* @retval 0 OK
* @retval -1 Error
* @see snmp_terminate
*/
static int
@ -243,7 +253,7 @@ clixon_snmp_init_subagent(clicon_handle h,
int retval = -1;
char *sockpath = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (logdst == CLICON_LOG_SYSLOG)
snmp_enable_calllog();
else
@ -257,7 +267,7 @@ clixon_snmp_init_subagent(clicon_handle h,
/* don't save persistent file */
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DISABLE_PERSISTENT_SAVE, 1);
if (clicon_debug_get())
if (clixon_debug_get())
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1);
if ((sockpath = clicon_option_str(h, "CLICON_SNMP_AGENT_SOCK")) == NULL){
@ -277,7 +287,6 @@ clixon_snmp_init_subagent(clicon_handle h,
clicon_err(OE_DAEMON, 0, "Connection to SNMP agent failed");
goto done;
}
if (set_signal(SIGTERM, clixon_snmp_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal");
goto done;
@ -299,6 +308,7 @@ clixon_snmp_init_subagent(clicon_handle h,
}
/*! Usage help routine
*
* @param[in] h Clixon handle
* @param[in] argv0 command line
*/
@ -386,7 +396,7 @@ main(int argc,
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
/* This is netsnmplib debugging which is quite extensive + only if compiled w debug */
if (dbg > 1)
snmp_set_do_debugging(1);
@ -398,13 +408,10 @@ main(int argc,
clixon_snmp_err_cb /* log fn */
) < 0)
goto done;
yang_init(h);
/* Find, read and parse configfile */
if (clicon_options_main(h) < 0)
goto done;
/* Now rest of options */
optind = 1;
opterr = 0;
@ -540,7 +547,6 @@ main(int argc,
if (clicon_hello_req(h, "cl:snmp", NULL, &id) < 0)
goto done;
clicon_session_id_set(h, id);
/* Init snmp as subagent */
if (clixon_snmp_init_subagent(h, logdst) < 0)
goto done;

View file

@ -80,6 +80,7 @@
#include "snmp_handler.h"
/*! Parse smiv2 extensions for YANG leaf
*
* Typical leaf:
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
* smiv2:max-access "read-write";
@ -189,7 +190,7 @@ mibyang_leaf_register(clicon_handle h,
goto done;
}
oid_cbuf(cboid, oid1, oid1len);
clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, cbuf_get(cboid));
clixon_debug(CLIXON_DBG_DEFAULT, "%s register: %s %s", __FUNCTION__, name, cbuf_get(cboid));
ok:
retval = 0;
done:
@ -319,7 +320,6 @@ mibyang_table_register(clicon_handle h,
while ((yleaf = yn_each(ylist, yleaf)) != NULL) {
if ((yang_keyword_get(yleaf) != Y_LEAF) || (ret = yangext_is_oid_exist(yleaf)) != 1)
continue;
table_info->max_column++;
}
if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){
@ -327,7 +327,7 @@ mibyang_table_register(clicon_handle h,
goto done;
}
sh->sh_table_info = table_info; /* Keep to free at exit */
clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, oidstr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s register: %s %s", __FUNCTION__, name, oidstr);
ok:
retval = 0;
done:
@ -446,6 +446,7 @@ mibyang_augment_register(clicon_handle h,
}
/*! Register table sub-oid:s of existing entries in clixon
*
* This assumes a table contains a set of keys and a list of leafs only
* The function makes a query to the datastore and registers all table entries that
* currently exists. This means it registers for a static table. If new rows or columns
@ -477,7 +478,7 @@ mibyang_table_poll(clicon_handle h,
oid oidk[MAX_OID_LEN] = {0,};
size_t oidklen = MAX_OID_LEN;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){
clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
@ -558,7 +559,7 @@ mibyang_traverse(clicon_handle h,
int ret;
static oid zero_oid = 0;
clicon_debug(1, "%s %s", __FUNCTION__, yang_argument_get(yn));
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, yang_argument_get(yn));
switch(yang_keyword_get(yn)){
case Y_AUGMENT:
if (mibyang_augment_register(h, yn) < 0)
@ -631,7 +632,7 @@ clixon_snmp_traverse_mibyangs(clicon_handle h)
continue;
if ((modname = xml_body(x)) == NULL)
continue;
clicon_debug(1, "%s %s: \"%s\"", __FUNCTION__, xml_name(x), modname);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s: \"%s\"", __FUNCTION__, xml_name(x), modname);
/* Note, here we assume the Yang is loaded by some other mechanism and
* error if it not found.
* Alternatively, that YANG could be loaded.

View file

@ -489,7 +489,7 @@ information on added, deleted and changed entries. You access this
information using access functions as defined in clixon_backend_transaction.h
## How do I check what has changed on commit?
You use XPATHs on the XML trees in the transaction commit callback.
You use XPaths on the XML trees in the transaction commit callback.
Suppose you want to print all added interfaces:
```
cxobj *target = transaction_target(td); # wanted XML tree
@ -500,7 +500,7 @@ Suppose you want to print all added interfaces:
You can look for added, deleted and changed entries in this way.
## How do I access the XML tree?
Using XPATH, find and iteration functions defined in the XML library. Example library functions:
Using XPath, find and iteration functions defined in the XML library. Example library functions:
```
xml_child_each(),
xml_find(),

View file

@ -251,7 +251,7 @@ main_commit(clicon_handle h,
/* Get all added i/fs */
if (xpath_vec_flag(target, nsc, "//interface", XML_FLAG_ADD, &vec, &len) < 0)
return -1;
if (clicon_debug_get())
if (clixon_debug_get())
for (i=0; i<len; i++) /* Loop over added i/fs */
xml_print(stdout, vec[i]); /* Print the added interface */
done:
@ -338,7 +338,7 @@ example_stream_timer_setup(clicon_handle h)
* in [RFC6241].
*/
static int
empty_rpc(clicon_handle h, /* Clicon handle */
empty_rpc(clicon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */
@ -353,7 +353,7 @@ empty_rpc(clicon_handle h, /* Clicon handle */
* The RPC returns the incoming parameters
*/
static int
example_rpc(clicon_handle h, /* Clicon handle */
example_rpc(clicon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */
@ -395,7 +395,7 @@ example_rpc(clicon_handle h, /* Clicon handle */
/*! This will be called as a hook right after the original system copy-config
*/
static int
example_copy_extra(clicon_handle h, /* Clicon handle */
example_copy_extra(clicon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */
@ -414,7 +414,7 @@ example_copy_extra(clicon_handle h, /* Clicon handle */
* @note callback is hardcoded C, while registration is controlled by -- -a option
*/
static int
example_action_reset(clicon_handle h, /* Clicon handle */
example_action_reset(clicon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */
@ -434,7 +434,7 @@ example_action_reset(clicon_handle h, /* Clicon handle */
/*! Called to get state data from plugin by programmatically adding state
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[out] xstate XML tree, <config/> on entry.
@ -539,7 +539,7 @@ example_statedata(clicon_handle h,
*
* The example shows how to read and parse a state XML file, (which is cached in the -i case).
* Return the requested xpath / pagination xstate by copying from the parsed state XML file
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[out] xstate XML tree, <config/> on entry. Copy to this
@ -752,7 +752,7 @@ example_lockdb(clicon_handle h,
{
int retval = -1;
clicon_debug(1, "%s Lock callback: db%s: locked:%d", __FUNCTION__, db, lock);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Lock callback: db%s: locked:%d", __FUNCTION__, db, lock);
/* Part of cached pagination example
*/
if (strcmp(db, "running") == 0 && lock == 0 &&
@ -793,7 +793,7 @@ example_extension(clicon_handle h,
extname = yang_argument_get(yext);
if (strcmp(modname, "example") != 0 || strcmp(extname, "e4") != 0)
goto ok;
clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
if ((yc = yang_find(ys, 0, NULL)) == NULL)
goto ok;
if ((yn = ys_dup(yc)) == NULL)
@ -833,7 +833,7 @@ static const map_str2str namespace_map[] = {
*
* Gets called on startup after initial XML parsing, but before module-specific upgrades
* and before validation.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of datastore, eg "running", "startup" or "tmp"
* @param[in] xt XML tree. Upgrade this "in place"
* @param[in] msd Info on datastore module-state, if any
@ -977,7 +977,7 @@ main_yang_mount(clicon_handle h,
/*! Testcase module-specific upgrade function moving interfaces-state to interfaces
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xn XML tree to be updated
* @param[in] ns Namespace of module (for info)
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
@ -1020,7 +1020,7 @@ upgrade_2014_to_2016(clicon_handle h,
int i;
char *name;
clicon_debug(1, "%s from:%d to:%d", __FUNCTION__, from, to);
clixon_debug(CLIXON_DBG_DEFAULT, "%s from:%d to:%d", __FUNCTION__, from, to);
if (op != XML_FLAG_CHANGE) /* Only treat fully present modules */
goto ok;
/* Get Yang module for this namespace. Note it may not exist (if obsolete) */
@ -1082,7 +1082,7 @@ upgrade_2014_to_2016(clicon_handle h,
/*! Testcase upgrade function removing interfaces-state
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xn XML tree to be updated
* @param[in] ns Namespace of module (for info)
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
@ -1123,14 +1123,14 @@ upgrade_2016_to_2018(clicon_handle h,
size_t vlen;
int i;
clicon_debug(1, "%s from:%d to:%d", __FUNCTION__, from, to);
clixon_debug(CLIXON_DBG_DEFAULT, "%s from:%d to:%d", __FUNCTION__, from, to);
if (op != XML_FLAG_CHANGE) /* Only treat fully present modules */
goto ok;
/* Get Yang module for this namespace. Note it may not exist (if obsolete) */
yspec = clicon_dbspec_yang(h);
if ((ym = yang_find_module_by_namespace(yspec, ns)) == NULL)
goto ok; /* shouldnt happen */
clicon_debug(1, "%s module %s", __FUNCTION__, ym?yang_argument_get(ym):"none");
clixon_debug(CLIXON_DBG_DEFAULT, "%s module %s", __FUNCTION__, ym?yang_argument_get(ym):"none");
/* Get all XML nodes with that namespace */
if (xml_namespace_vec(h, xt, ns, &vec, &vlen) < 0)
goto done;
@ -1182,7 +1182,7 @@ upgrade_2016_to_2018(clicon_handle h,
/*! Testcase module-specific upgrade function moving interfaces-state to interfaces
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xn XML tree to be updated
* @param[in] ns Namespace of module (for info)
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
@ -1247,8 +1247,10 @@ upgrade_interfaces(clicon_handle h,
* is well defined.
* This involves creating default configuration files for various daemons, set interface
* flags etc.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of database. Not3 may be other than "running"
* @retval 0 OK
* @retval -1 Error
* In this example, a loopback parameter is added
*/
int
@ -1264,7 +1266,6 @@ example_reset(clicon_handle h,
if (!_reset)
goto ok; /* Note not enabled by default */
yspec = clicon_dbspec_yang(h);
/* Parse extra XML */
if ((ret = clixon_xml_parse_string("<table xmlns=\"urn:example:clixon\">"
@ -1272,7 +1273,7 @@ example_reset(clicon_handle h,
"</table>", YB_MODULE, yspec, &xt, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_debug_xml(1, xerr, "Error when parsing XML");
clixon_debug_xml(CLIXON_DBG_DEFAULT, xerr, "Error when parsing XML");
goto ok;
}
/* xmldb_put requires modification tree to be: <config>... */
@ -1306,7 +1307,9 @@ example_reset(clicon_handle h,
* Called when application is "started", (almost) all initialization is complete
* Backend: daemon is in the background. If daemon privileges are dropped
* this callback is called *before* privileges are dropped.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
int
example_start(clicon_handle h)
@ -1338,7 +1341,9 @@ example_start(clicon_handle h)
/*! Plugin daemon.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* plugin_daemon is called once after daemonization has been made but before lowering of privileges
* the main event loop is entered.
*/
@ -1427,7 +1432,7 @@ clixon_plugin_init(clicon_handle h)
char **argv;
int c;
clicon_debug(1, "%s backend", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s backend", __FUNCTION__);
/* Get user command-line options (after --) */
if (clicon_argv_get(h, &argc, &argv) < 0)

View file

@ -62,12 +62,14 @@
#define BACKEND_NACM_OPTS "tv:"
/*! Variable to control transaction logging (for debug)
*
* If set, call syslog for every transaction callback
* Start backend with -- -t
*/
static int _transaction_log = 0;
/*! Variable to trigger validation/commit errors (synthetic errors) for tests
*
* XPath to trigger validation error, ie if the XPath matches, then validate fails
* This is to make tests where a transaction fails midway and aborts/reverts the transaction.
* Start backend with -- -v <xpath>
@ -76,6 +78,7 @@ static int _transaction_log = 0;
static char *_validate_fail_xpath = NULL;
/*! Sub state variable to fail on validate/commit (not configured)
*
* Obscure, but a way to first trigger a validation error, next time to trigger a commit error
*/
static int _validate_fail_toggle = 0; /* fail at validate and commit */
@ -172,9 +175,10 @@ nacm_abort(clicon_handle h,
}
/*! Called to get NACM state data
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] xpath String with XPath syntax. or NULL for all
* @param[in] xtop XML tree, <config/> on entry.
* @retval 0 OK
* @retval -1 Error
@ -224,6 +228,7 @@ static clixon_plugin_api api = {
};
/*! Backend plugin initialization
*
* @param[in] h Clixon handle
* @retval NULL Error with clicon_err set
* @retval api Pointer to API struct
@ -236,7 +241,7 @@ clixon_plugin_init(clicon_handle h)
char **argv;
int c;
clicon_debug(1, "%s backend nacm", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s backend nacm", __FUNCTION__);
/* Get user command-line options (after --) */
if (clicon_argv_get(h, &argc, &argv) < 0)
goto done;

View file

@ -64,7 +64,8 @@
static char *_mount_yang = NULL;
static char *_mount_namespace = NULL;
/*! Example cli function */
/*! Example cli function
*/
int
mycallback(clicon_handle h, cvec *cvv, cvec *argv)
{
@ -80,7 +81,7 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
if ((nsc = xml_nsctx_init(NULL, "urn:example:clixon")) == NULL)
goto done;
/* Show eth0 interfaces config using XPATH */
/* Show eth0 interfaces config using XPath */
if (clicon_rpc_get_config(h, NULL, "running",
"/interfaces/interface[name='eth0']",
nsc, NULL,
@ -97,7 +98,8 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
return retval;
}
/*! Example "downcall", ie initiate an RPC to the backend */
/*! Example "downcall", ie initiate an RPC to the backend
*/
int
example_client_rpc(clicon_handle h,
cvec *cvv,
@ -148,7 +150,11 @@ example_client_rpc(clicon_handle h,
}
/*! Translate function from an original value to a new.
*
* In this case, assume string and increment characters, eg HAL->IBM
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
int
cli_incstr(cligen_handle h,
@ -239,6 +245,7 @@ static clixon_plugin_api api = {
};
/*! CLI plugin initialization
*
* @param[in] h Clixon handle
* @retval NULL Error with clicon_err set
* @retval api Pointer to API struct

View file

@ -49,8 +49,10 @@
#include <clixon/clixon_netconf.h>
/*! Plugin start
*
* Called once everything has been initialized, right before
* the main event loop is entered.
* @param[in] h Clixon handle
*/
int
plugin_start(clicon_handle h)
@ -111,6 +113,7 @@ static struct clixon_plugin_api api = {
};
/*! Netconf plugin initialization
*
* @param[in] h Clixon handle
* @retval NULL Error with clicon_err set
* @retval api Pointer to API struct
@ -118,7 +121,7 @@ static struct clixon_plugin_api api = {
clixon_plugin_api *
clixon_plugin_init(clicon_handle h)
{
clicon_debug(1, "%s restconf", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__);
/* Register local netconf rpc client (note not backend rpc client) */
if (rpc_callback_register(h, netconf_client_rpc, NULL,
"urn:example:clixon", "client-rpc") < 0)

View file

@ -185,14 +185,15 @@ b64_decode(const char *src,
}
/*! HTTP basic authentication example (note hardwired)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Per-message request www handle to use with restconf_api.h
* @param[out] authp NULL: Credentials failed, no user set (401 returned).
* String: Credentials OK, the associated user, must be mallloc:ed
* Parameter signtificant only if retval is 1/OK
* @retval -1 Fatal error
* @retval 0 Ignore, undecided, not handled, same as no callback
* @retval 1 OK, see authp parameter for result.
* @retval 0 Ignore, undecided, not handled, same as no callback
* @retval -1 Fatal error
* @note authp should be malloced
* @note: Three hardwired users: andy, wilma, guest w password "bar".
*/
@ -211,7 +212,7 @@ example_basic_auth(clicon_handle h,
size_t authlen;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (authp == NULL){
clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
goto done;
@ -237,7 +238,7 @@ example_basic_auth(clicon_handle h,
goto fail;
*passwd = '\0';
passwd++;
clicon_debug(1, "%s http user:%s passwd:%s", __FUNCTION__, user, passwd);
clixon_debug(CLIXON_DBG_DEFAULT, "%s http user:%s passwd:%s", __FUNCTION__, user, passwd);
/* Here get auth sub-tree where all the users are */
if ((cb = cbuf_new()) == NULL)
goto done;
@ -252,7 +253,7 @@ example_basic_auth(clicon_handle h,
user=NULL; /* to avoid free below */
retval = 1;
done: /* error */
clicon_debug(1, "%s retval:%d authp:%s", __FUNCTION__, retval, authp?"":*authp);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d authp:%s", __FUNCTION__, retval, authp?"":*authp);
if (user)
free(user);
if (cb)
@ -267,15 +268,16 @@ example_basic_auth(clicon_handle h,
}
/*! Authentication callback
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] req Per-message request www handle to use with restconf_api.h
* @param[in] auth_type Authentication type: none, user-defined, or client-cert
* @param[out] authp NULL: Credentials failed, no user set (401 returned).
* String: Credentials OK, the associated user, must be mallloc:ed
* Parameter signtificant only if retval is 1/OK
* @retval -1 Fatal error
* @retval 0 Ignore, undecided, not handled, same as no callback
* @retval 1 OK, see authp parameter for result.
* @retval 0 Ignore, undecided, not handled, same as no callback
* @retval -1 Fatal error
* @note authp should be malloced
*/
int
@ -286,7 +288,7 @@ example_restconf_credentials(clicon_handle h,
{
int retval = -1;
clicon_debug(1, "%s auth:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
clixon_debug(CLIXON_DBG_DEFAULT, "%s auth:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
switch (auth_type){
case CLIXON_AUTH_NONE: /* FEATURE clixon-restconf:allow-auth-none must be enabled */
retval = 0;
@ -300,7 +302,7 @@ example_restconf_credentials(clicon_handle h,
break;
}
done:
clicon_debug(1, "%s retval:%d authp:%s", __FUNCTION__, retval, *authp);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d authp:%s", __FUNCTION__, retval, *authp);
return retval;
}
@ -344,7 +346,7 @@ restconf_client_rpc(clicon_handle h,
int
example_restconf_start(clicon_handle h)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -359,6 +361,7 @@ static clixon_plugin_api api = {
};
/*! Restconf plugin initialization
*
* @param[in] h Clixon handle
* @retval NULL Error with clicon_err set
* @retval api Pointer to API struct
@ -371,7 +374,7 @@ clixon_plugin_init(clicon_handle h)
char **argv = NULL;
int c;
clicon_debug(1, "%s restconf", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__);
/* Get user command-line options (after --) */
if (clicon_argv_get(h, &argc, &argv) < 0)
return NULL;

View file

@ -48,6 +48,7 @@
#undef RPC_USERNAME_ASSERT
/*! Tag for wrong handling of identityref prefixes (XML encoding)
*
* See https://github.com/clicon/clixon/issues/90
* Instead of using generic xmlns prefix bindings, the module's own prefix
* is used.
@ -60,7 +61,8 @@
*/
#undef IDENTITYREF_KLUDGE
/*! Optimize special list key searches in XPATH finds
/*! Optimize special list key searches in XPath finds
*
* Identify xpaths that search for exactly a list key, eg: "y[k='3']" and then call
* binary search. This only works if "y" has proper yang binding and is sorted by system
* Dont optimize on "hierarchical" lists such as: a/y[k='3'], where a is another list.
@ -68,6 +70,7 @@
#define XPATH_LIST_OPTIMIZE
/*! Add explicit search indexes, so that binary search can be made for non-key list indexes
*
* This also applies if there are multiple keys and you want to search on only the second for
* example.
* There may be some cases where the index vector is not updated, need to verify before
@ -76,6 +79,7 @@
#define XML_EXPLICIT_INDEX
/*! Let state data be ordered-by system
*
* RFC 7950 is cryptic about this
* It says in 7.7.7:
* This statement (red:The "ordered-by" Statement) is ignored if the list represents
@ -87,6 +91,7 @@
#define STATE_ORDERED_BY_SYSTEM
/*! Top-symbol in clixon datastores
*
* This is traditionally same as NETCONF_INPUT_CONFIG ("config") but can be different
* If you change this, you need to change test shell variable in lib.sh: DATASTORE_TOP
* Consider making this an option (but this has bootstrap problems) or configure option
@ -94,12 +99,14 @@
#define DATASTORE_TOP_SYMBOL "config"
/*! If set make an internal redirect if URI path indetifies a directory
*
* For example, path is /local, and redirect is 'index.html, the request
* will be redirected to /local/index.html
*/
#define HTTP_DATA_INTERNAL_REDIRECT "index.html"
/*! Set a temporary parent for use in special case "when" xpath calls
*
* Problem is when changing an existing (candidate) in-memory datastore that yang "when" conditionals
* should be changed in clixon_datastore_write.c:text_modify().
* Problem is that the tree is in an intermediate state so that a when condition may not see the
@ -115,16 +122,19 @@
#define XML_PARENT_CANDIDATE
/*! Enable "remaining" attribute (sub-feature of list pagination)
*
* As defined in draft-wwlh-netconf-list-pagination-00 using Yang metadata value [RFC7952]
*/
#undef LIST_PAGINATION_REMAINING
/*! Use Ancestor config cache
*
* The cache uses two yang stmt flag bits. One to say it is active, the second its value
*/
#define USE_CONFIG_FLAG_CACHE
/*! If backend is restarted, cli and netconf client will retry (once) and reconnect
*
* Note, if client has locked or had edits in progress, these will be lost
* A warning will be printed
* If not set, client will exit
@ -132,12 +142,14 @@
#define PROTO_RESTART_RECONNECT
/*! Disable top-level prefix for text syntax printing and parsing introduced in 5.8
*
* Note this is for showing/saving/printing, it is NOT for parsing/loading.
* This means that text output can not be parsed and loaded.
*/
#undef TEXT_SYNTAX_NOPREFIX
/*! Reply with HTTP error when HTTP request on HTTPS socket
*
* If not set, just close socket and return with TCP reset.
* If set: Incoming request on an SSL socket is known to be non-TLS.
* Problematic part is it is not known it is proper non-TLS HTTP, for that it
@ -153,6 +165,7 @@
#define HTTP_ON_HTTPS_REPLY
/*! Indentation number of spaces for XML, JSON and TEXT pretty-printed output.
*
* Consider moving to configure.ac(compile-time) or to clixon-config.yang(run-time)
*/
#define PRETTYPRINT_INDENT 3

View file

@ -125,19 +125,19 @@ int clicon_socket_set(clicon_handle h, int s);
int clicon_client_socket_get(clicon_handle h);
int clicon_client_socket_set(clicon_handle h, int s);
/*! Set and get module state full and brief cached tree */
/* Set and get module state full and brief cached tree */
cxobj *clicon_modst_cache_get(clicon_handle h, int brief);
int clicon_modst_cache_set(clicon_handle h, int brief, cxobj *xms);
/*! Set and get yang/xml module revision changelog */
/* Set and get yang/xml module revision changelog */
cxobj *clicon_xml_changelog_get(clicon_handle h);
int clicon_xml_changelog_set(clicon_handle h, cxobj *xchlog);
/*! Set and get user command-line options (after --) */
/* Set and get user command-line options (after --) */
int clicon_argv_get(clicon_handle h, int *argc, char ***argv);
int clicon_argv_set(clicon_handle h, char *argv0, int argc, char **argv);
/*! Set and get (client/backend) session id */
/* Set and get (client/backend) session id */
int clicon_session_id_set(clicon_handle h, uint32_t id);
int clicon_session_id_get(clicon_handle h, uint32_t *id);
int clicon_session_id_del(clicon_handle h);

View file

@ -38,6 +38,7 @@
#define _CLIXON_DISPATCH_DISPATCHER_H
/*! Prototype for a function to handle a path
*
* minimally needs the path it's working on, but probably
* we want to hand down cached data somehow
* @param[in] h Generic handler

View file

@ -83,7 +83,8 @@ enum clicon_err{
OE_NGHTTP2, /* nghttp2 errors, see HAVE_LIBNGHTTP2 */
};
/* Clixon error category log callback
/*! Clixon error category log callback
*
* @param[in] handle Application-specific handle
* @param[in] suberr Application-specific handle
* @param[out] cb Read log/error string into this buffer

View file

@ -67,10 +67,15 @@ size_t clicon_log_string_limit_get(void);
int clicon_get_logflags(void);
int clicon_log_str(int level, char *msg);
int clicon_log(int level, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int clicon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int clicon_debug_init(int dbglevel, FILE *f);
int clicon_debug_get(void);
int clixon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int clixon_debug_init(int dbglevel, FILE *f);
int clixon_debug_get(void);
char *mon2name(int md);
/* 6.4 backward compatability */
#if 1
#define clicon_debug clixon_debug
#define clicon_debug_init clixon_debug_init
#define clicon_debug_get clixon_debug_get
#endif
#endif /* _CLIXON_LOG_H_ */

View file

@ -98,6 +98,7 @@
* Types
*/
/*! Content query parameter RFC 8040 Sec 4.8.1
*
* Clixon extention: content so that RFC8040 content attribute can be conveyed
* internally used in <get>
*/
@ -147,6 +148,7 @@ typedef enum withdefaults_type withdefaults_type;
* Macros
*/
/*! Generate textual error log from Netconf error message
*
* @param[in] xerr Netconf error xml tree on the form: <rpc-error>
* @param[in] format Format string
* @param[in] arg String argument to format (optional)

View file

@ -46,6 +46,7 @@
* Constants
*/
/*! Clixon configuration namespace
*
* Probably should be defined somewhere else or extracted from yang
* @see clixon-config.yang
* @see clixon-lib.yang
@ -85,6 +86,7 @@ enum nacm_credentials_t{
};
/*! Datastore cache behaviour, see clixon_datastore.[ch]
*
* See config option type datastore_cache in clixon-config.yang
*/
enum datastore_cache{
@ -94,6 +96,7 @@ enum datastore_cache{
};
/*! yang clixon regexp engine
*
* @see regexp_mode in clixon-config.yang
*/
enum regexp_mode{

View file

@ -108,13 +108,15 @@ enum clixon_auth_type {
};
typedef enum clixon_auth_type clixon_auth_type_t;
/* Common plugin function names, function types and signatures.
/*! Common plugin function names, function types and signatures.
*
* This plugin code is exytended by backend, cli, netconf, restconf plugins
* Cli see cli_plugin.c
* Backend see config_plugin.c
*/
/* Called when application is "started", (almost) all initialization is complete
/*! Called when application is "started", (almost) all initialization is complete
*
* Backend: daemon is in the background. If daemon privileges are dropped
* this callback is called *before* privileges are dropped.
* @param[in] h Clixon handle
@ -215,7 +217,7 @@ typedef int (plgreset_t)(clicon_handle h, const char *db);
*
* @param[in] h Clicon handle
* @param[in] xpath Part of state requested
* @param[in] nsc XPATH namespace context.
* @param[in] nsc XPath namespace context.
* @param[out] xtop XML tree where statedata is added
* @retval 0 OK
* @retval -1 Fatal error
@ -226,7 +228,8 @@ typedef int (plgreset_t)(clicon_handle h, const char *db);
*/
typedef int (plgstatedata_t)(clicon_handle h, cvec *nsc, char *xpath, cxobj *xtop);
/* Pagination-data type
/*! Pagination-data type
*
* @see pagination_data_t in for full pagination data structure
* @see pagination_offset() and other accessor functions
*/
@ -243,7 +246,8 @@ typedef void *pagination_data;
*/
typedef int (plglockdb_t)(clicon_handle h, char *db, int lock, int id);
/* Transaction-data type
/*! Transaction-data type
*
* @see transaction_data_t and clixon_backend_transaction.h for full transaction API
*/
typedef void *transaction_data;
@ -252,6 +256,7 @@ typedef void *transaction_data;
typedef int (trans_cb_t)(clicon_handle h, transaction_data td);
/*! Hook to override default prompt with explicit function
*
* Format prompt before each getline
* @param[in] h Clicon handle
* @param[in] mode Cligen syntax mode
@ -311,6 +316,7 @@ typedef int (yang_mount_t)(clicon_handle h, cxobj *xt, int *config,
typedef int (yang_patch_t)(clicon_handle h, yang_stmt *ymod);
/*! Startup status for use in startup-callback
*
* Note that for STARTUP_ERR and STARTUP_INVALID, running runs in failsafe mode
* and startup contains the erroneous or invalid database.
* The user should repair the startup and
@ -400,6 +406,7 @@ typedef struct clixon_plugin_api clixon_plugin_api;
typedef struct clixon_plugin clixon_plugin_t;
/*! Structure for checking status before and after a plugin call
*
* The internal struct is defined in clixon_plugin.c */
typedef struct plugin_context plugin_context_t;

View file

@ -40,6 +40,7 @@
#define _CLIXON_QUEUE_H_
/*! Circular queue structure for use as first entry in a parent structure.
*
* Add qelem_t as first element in struct
* @code
* struct a{
@ -55,6 +56,7 @@ typedef struct _qelem_t {
} qelem_t;
/*! Append element 'elem' to queue.
*
* @param[in] elem Element to be added
* @param[in,out] pred Add element after this
* @code
@ -78,6 +80,7 @@ typedef struct _qelem_t {
}
/*! Insert element 'elem' in queue after 'pred'
*
* @param[in] elem Element to be added
* @param[in,out] pred Add element after this
* @code
@ -101,6 +104,7 @@ typedef struct _qelem_t {
}
/*! Remove element 'elem' from queue. 'head' is the pointer to the queue and
*
* is of 'type'.
* @param[in] elem
* @param[in] head
@ -121,6 +125,7 @@ typedef struct _qelem_t {
}
/*! Get next entry in list
*
* @param[in] type Type of element
* @param[in] el Return next element after elem.
* @code

View file

@ -45,7 +45,8 @@
/*
* Types
*/
/* Subscription callback
/*! Subscription callback
*
* @param[in] h Clicon handle
* @param[in] op Operation: 0 OK, 1 Close
* @param[in] event Event as XML

View file

@ -39,6 +39,7 @@
#define _CLIXON_STRING_H_
/*! Struct used to map between int and strings. Typically used to map between
*
* values and their names. Note NULL terminated
* Example:
* @code

View file

@ -304,7 +304,7 @@ char *xml_operation2str(enum operation_type op);
int xml_attr_insert2val(char *instr, enum insert_type *ins);
int xml_add_attr(cxobj *xn, char *name, char *value, char *prefix, char *ns);
int clicon_log_xml(int level, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int clicon_debug_xml(int dbglevel, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int clixon_debug_xml(int dbglevel, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
#ifdef XML_EXPLICIT_INDEX
int xml_search_index_p(cxobj *x);

View file

@ -32,7 +32,7 @@
***** END LICENSE BLOCK *****
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
*/
#ifndef _CLIXON_XPATH_H
#define _CLIXON_XPATH_H
@ -103,9 +103,10 @@ enum xp_type{
};
/*! XPATH Parsing generates a tree of nodes that is later traversed
* That is, a tree-structured XPATH.
* Note that the structure follows XPATH 1.0 closely. The drawback wit this is that the tree gets
* very deep very quickly, even for simple XPATHs.
*
* That is, a tree-structured XPath.
* Note that the structure follows XPath 1.0 closely. The drawback wit this is that the tree gets
* very deep very quickly, even for simple XPaths.
*/
struct xpath_tree{
enum xp_type xs_type;

View file

@ -33,8 +33,8 @@
***** END LICENSE BLOCK *****
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
* This file defines XPATH contexts using in traversing the XPATH parse tree.
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
* This file defines XPath contexts using in traversing the XPath parse tree.
*/
#ifndef _CLIXON_XPATH_CTX_H
#define _CLIXON_XPATH_CTX_H
@ -43,7 +43,8 @@
* Types
*/
/*! XPATH expression type
/*! XPath expression type
*
* An expression is evaluated to yield an object, which has one of the following four basic types:
* node-set (an unordered collection of nodes without duplicates)
* boolean (true or false)

View file

@ -32,7 +32,7 @@
***** END LICENSE BLOCK *****
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
* See XPATH_LIST_OPTIMIZE
*/
#ifndef _CLIXON_XPATH_OPTIMIZE_H

View file

@ -32,9 +32,9 @@
***** END LICENSE BLOCK *****
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
* Note: for YANG which is constrained to path-arg as defined in rfc7950
* See: clixon_xpath.[ch] for full XML XPATH implementation
* See: clixon_xpath.[ch] for full XML XPath implementation
*/
#ifndef _CLIXON_XPATH_YANG_H
#define _CLIXON_XPATH_YANG_H

View file

@ -88,6 +88,7 @@
* Types
*/
/*! YANG keywords from RFC6020.
*
* See also keywords generated by yacc/bison in clicon_yang_parse.tab.h, but they start with K_
* instead of Y_
* Wanted to unify these (K_ and Y_) but gave up for several reasons:
@ -186,11 +187,12 @@ struct xml;
typedef struct yang_stmt yang_stmt;
/*! Yang apply function worker
*
* @param[in] yn yang node
* @param[in] arg Argument
* @retval -1 Error, abort
* @retval 0 OK, continue with next
* @retval n OK, abort traversal and return to caller with "n"
* @retval 0 OK, continue with next
* @retval -1 Error, abort
*/
typedef int (yang_applyfn_t)(yang_stmt *ys, void *arg);

View file

@ -47,7 +47,8 @@
* Types
*/
/* Struct containing module state differences between two modules or two
/*! Struct containing module state differences between two modules or two
*
* revisions of same module.
* The most significant usecase is one module-state is a loaded datastore and the other
* is the one loaded by the server by its YANG files.

View file

@ -46,6 +46,7 @@
/* Limitations/deviations from RFC 8528 */
/*! Only support YANG presende containers as mount-points
*
* This is a limitation of othe current implementation
*/
#define YANG_SCHEMA_MOUNT_ONLY_PRESENCE_CONTAINERS

View file

@ -116,11 +116,11 @@
/* Best debugging is to enable PARSE_DEBUG below and add -d to the LEX compile statement in the Makefile
* And then run the testcase with -D 1
* Disable it to stop any calls to clicon_debug. Having it on by default would mean very large debug outputs.
* Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs.
*/
#if 0
#define _PARSE_DEBUG(s) clicon_debug(1,(s))
#define _PARSE_DEBUG1(s, s1) clicon_debug(1,(s), (s1))
#define _PARSE_DEBUG(s) clixon_debug(1,(s))
#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1))
#else
#define _PARSE_DEBUG(s)
#define _PARSE_DEBUG1(s, s1)
@ -159,7 +159,7 @@ static clixon_path *
path_append(clixon_path *list,
clixon_path *new)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
if (new == NULL)
return NULL;
ADDQ(new, list);
@ -172,7 +172,7 @@ static clixon_path *
path_add_keyvalue(clixon_path *cp,
cvec *cvk)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
if (cp)
cp->cp_cvk = cvk;
return cp;
@ -184,7 +184,7 @@ path_new(char *module_name,
{
clixon_path *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, module_name, id);
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, module_name, id);
if ((cp = malloc(sizeof(*cp))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -205,6 +205,7 @@ path_new(char *module_name,
}
/*! Append a key-value cv to a cvec, create the cvec if not exist
*
* @param[in] cvv Either created cvv or NULL, in whihc case it is created
* @param[in] cv Is consumed by thius function (if appended)
* @retval NULL Error
@ -214,7 +215,7 @@ static cvec *
keyval_add(cvec *cvv,
cg_var *cv)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
if (cv == NULL)
goto done;
if (cvv == NULL &&
@ -240,7 +241,7 @@ keyval_set(char *name,
{
cg_var *cv = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name?name:"NULL", val);
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name?name:"NULL", val);
if ((cv = cv_new(CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new");
goto done;
@ -261,7 +262,6 @@ keyval_set(char *name,
%}
%%
/*

View file

@ -118,7 +118,7 @@ clixon_client_init(const char *config_file)
{
clicon_handle h;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Initiate CLICON handle. CLIgen is also initialized */
if ((h = clicon_handle_init()) == NULL)
return NULL;
@ -139,7 +139,7 @@ clixon_client_init(const char *config_file)
int
clixon_client_terminate(clicon_handle h)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
clicon_handle_exit(h);
return 0;
}
@ -166,7 +166,7 @@ clixon_client_lock(int sock,
cbuf *msgret = NULL;
int eof = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (db == NULL){
clicon_err(OE_XML, EINVAL, "Expected db");
goto done;
@ -200,7 +200,7 @@ clixon_client_lock(int sock,
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (xret)
xml_free(xret);
if (msg)
@ -226,7 +226,7 @@ clixon_client_hello(int sock,
int retval = -1;
cbuf *msg = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((msg = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
@ -242,7 +242,7 @@ clixon_client_hello(int sock,
goto done;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (msg)
cbuf_free(msg);
return retval;
@ -263,7 +263,7 @@ clixon_client_connect_netconf(clicon_handle h,
char dbgstr[8];
nr = 7;
if (clicon_debug_get() != 0)
if (clixon_debug_get() != 0)
nr += 2;
if ((argv = calloc(nr, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
@ -283,9 +283,9 @@ clixon_client_connect_netconf(clicon_handle h,
argv[i++] = clicon_option_str(h, "CLICON_CONFIGFILE");
argv[i++] = "-l"; /* log to syslog */
argv[i++] = "s";
if (clicon_debug_get() != 0){
if (clixon_debug_get() != 0){
argv[i++] = "-D";
snprintf(dbgstr, sizeof(dbgstr)-1, "%d", clicon_debug_get());
snprintf(dbgstr, sizeof(dbgstr)-1, "%d", clixon_debug_get());
argv[i++] = dbgstr;
}
argv[i++] = NULL;
@ -312,7 +312,7 @@ clixon_client_connect_ssh(clicon_handle h,
char *ssh_bin = SSH_BIN;
struct stat st = {0,};
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
nr = 5;
if ((argv = calloc(nr, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
@ -330,7 +330,7 @@ clixon_client_connect_ssh(clicon_handle h,
argv[i++] = NULL;
assert(i==nr);
for (i=0;i<nr;i++)
clicon_debug(1, "%s: argv[%d]:%s", __FUNCTION__, i, argv[i]);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: argv[%d]:%s", __FUNCTION__, i, argv[i]);
if (clixon_proc_socket(argv, SOCK_STREAM, &cch->cch_pid, &cch->cch_socket) < 0){
goto done;
}
@ -356,7 +356,7 @@ clixon_client_connect(clicon_handle h,
struct clixon_client_handle *cch = NULL;
size_t sz = sizeof(struct clixon_client_handle);
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cch = malloc(sz)) == NULL){
clicon_err(OE_NETCONF, errno, "malloc");
goto done;
@ -384,7 +384,7 @@ clixon_client_connect(clicon_handle h,
break;
} /* switch */
done:
clicon_debug(1, "%s retval:%p", __FUNCTION__, cch);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%p", __FUNCTION__, cch);
return cch;
err:
if (cch)
@ -407,7 +407,7 @@ clixon_client_disconnect(clixon_client_handle ch)
int retval = -1;
struct clixon_client_handle *cch = chandle(ch);
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (cch == NULL){
clicon_err(OE_XML, EINVAL, "Expected cch handle");
goto done;
@ -494,7 +494,7 @@ clixon_client_get_xdata(int sock,
cvec *nsc = NULL;
int eof = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((msg = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
@ -549,7 +549,7 @@ clixon_client_get_xdata(int sock,
*xdata = xd;
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (xret)
xml_free(xret);
if (msg)
@ -580,7 +580,7 @@ clixon_client_get_body_val(int sock,
cxobj *xdata = NULL;
cxobj *xobj = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (val == NULL){
clicon_err(OE_XML, EINVAL, "Expected val");
goto done;
@ -605,7 +605,7 @@ clixon_client_get_body_val(int sock,
*val = xml_body(xobj);
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
@ -631,7 +631,7 @@ clixon_client_get_bool(clixon_client_handle ch,
int ret;
uint8_t val0=0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
@ -672,7 +672,7 @@ clixon_client_get_str(clixon_client_handle ch,
struct clixon_client_handle *cch = chandle(ch);
char *val = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
@ -704,7 +704,7 @@ clixon_client_get_uint8(clixon_client_handle ch,
char *reason = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
@ -744,7 +744,7 @@ clixon_client_get_uint16(clixon_client_handle ch,
char *reason = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
@ -784,7 +784,7 @@ clixon_client_get_uint32(clixon_client_handle ch,
char *reason = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;
@ -802,7 +802,7 @@ clixon_client_get_uint32(clixon_client_handle ch,
}
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (reason)
free(reason);
return retval;
@ -829,7 +829,7 @@ clixon_client_get_uint64(clixon_client_handle ch,
char *reason = NULL;
int ret;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (clixon_client_get_body_val(cch->cch_socket, cch->cch_descr,
namespace, xpath, &val) < 0)
goto done;

View file

@ -78,7 +78,8 @@
#include "clixon_data.h"
/*! Get generic clixon data on the form <name>=<val> where <val> is string
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[out] val Data value as string
* @retval 0 OK
@ -100,7 +101,8 @@ clicon_data_get(clicon_handle h,
}
/*! Set generic clixon data on the form <name>=<val> where <val> is string
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[in] val Data value as null-terminated string (copied)
* @retval 0 OK
@ -118,7 +120,8 @@ clicon_data_set(clicon_handle h,
}
/*! Delete generic clixon data
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @retval 0 OK
* @retval -1 Error
@ -134,7 +137,8 @@ clicon_data_del(clicon_handle h,
}
/*! Get generic clixon data on the form <name>=<ptr> where <ptr> is void*
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[out] ptr Pointer
* @retval 0 OK
@ -160,7 +164,8 @@ clicon_ptr_get(clicon_handle h,
}
/*! Set generic clixon data on the form <name>=<ptr> where <ptr> is void*
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @param[in] ptr Pointer
* @retval 0 OK
@ -178,7 +183,8 @@ clicon_ptr_set(clicon_handle h,
}
/*! Delete generic clixon data
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Data name
* @retval 0 OK
* @retval -1 Error
@ -195,7 +201,7 @@ clicon_ptr_del(clicon_handle h,
/*! Get generic cligen variable vector (cvv) on the form <name>=<val> where <val> is cvv
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] name Data name
* @retval cvv Data value as cvv
* @retval NULL Not found (or error)
@ -217,7 +223,8 @@ clicon_data_cvec_get(clicon_handle h,
}
/*! Set generic cligen variable vector (cvv) on the form <name>=<val> where <val> is cvv
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Name
* @param[in] cvv CLIgen variable vector (cvv) (malloced)
*/
@ -235,7 +242,8 @@ clicon_data_cvec_set(clicon_handle h,
}
/*! Delete generic cligen variable vector (cvv)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] name Name
*/
int
@ -310,7 +318,8 @@ clicon_data_int_del(clicon_handle h,
}
/*! Get data yangspec, yspec
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval yspec Yang spec
* @see clicon_config_yang for the configuration yang
*/
@ -325,7 +334,8 @@ clicon_dbspec_yang(clicon_handle h)
}
/*! Set yang specification for application specifications
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] yspec Yang spec (malloced pointer)
* @see clicon_config_yang_set for the configuration yang
*/
@ -337,7 +347,8 @@ clicon_dbspec_yang_set(clicon_handle h,
}
/*! Get YANG specification for clixon config (separate from application yangs)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval yspec Yang spec
* @see clicon_dbspec_yang for the application specs
*/
@ -352,7 +363,8 @@ clicon_config_yang(clicon_handle h)
}
/*! Set yang specification for configuration
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] yspec Yang spec (malloced pointer)
* @see clicon_dbspec_yang_set for the application specs
*/
@ -364,7 +376,8 @@ clicon_config_yang_set(clicon_handle h,
}
/*! Get YANG specification for external NACM (separate from application yangs)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval yspec Yang spec
* @see clicon_nacm_ext for external NACM XML
*/
@ -379,7 +392,8 @@ clicon_nacm_ext_yang(clicon_handle h)
}
/*! Set yang specification for external NACM
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] yspec Yang spec (malloced pointer)
* @see clicon_nacm_ext_set for external NACM XML
*/
@ -391,8 +405,9 @@ clicon_nacm_ext_yang_set(clicon_handle h,
}
/*! Get Global "canonical" namespace context
*
* Canonical: use prefix and namespace specified in the yang modules.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval nsctx Namespace context (malloced)
* @code
* cvec *nsctx;
@ -410,8 +425,9 @@ clicon_nsctx_global_get(clicon_handle h)
}
/*! Set global "canonical" namespace context
*
* Canonical: use prefix and namespace specified in the yang modules.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] nsctx Namespace context (malloced)
*/
int
@ -422,7 +438,8 @@ clicon_nsctx_global_set(clicon_handle h,
}
/*! Get NACM (rfc 8341) XML parse tree if external not in std xml config
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval xn XML NACM tree, or NULL
* @note only used if config option CLICON_NACM_MODE is external
* @see clicon_nacm_ext_set
@ -438,7 +455,8 @@ clicon_nacm_ext(clicon_handle h)
}
/*! Set NACM (rfc 8341) external XML parse tree, free old if any
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xn XML Nacm tree
* @note only used if config option CLICON_NACM_MODE is external
* @see clicon_nacm_ext
@ -455,7 +473,8 @@ clicon_nacm_ext_set(clicon_handle h,
}
/*! Get NACM (rfc 8341) XML parse tree cache
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval xn XML NACM tree, or NULL. Direct pointer, no copying
* @note Use with caution, only valid on a stack, direct pointer freed on function return
* @see from_client_msg
@ -471,7 +490,8 @@ clicon_nacm_cache(clicon_handle h)
}
/*! Set NACM (rfc 8341) external XML parse tree cache
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xn XML Nacm tree direct pointer, no copying
* @note Use with caution, only valid on a stack, direct pointer freed on function return
* @see from_client_msg
@ -484,6 +504,7 @@ clicon_nacm_cache_set(clicon_handle h,
}
/*! Get YANG specification for Clixon system options and features
*
* Must use hash functions directly since they are not strings.
* Example: features are typically accessed directly in the config tree.
* @code
@ -505,6 +526,7 @@ clicon_conf_xml(clicon_handle h)
}
/*! Set YANG specification for Clixon system options and features
*
* ys must be a malloced pointer
*/
int
@ -517,7 +539,7 @@ clicon_conf_xml_set(clicon_handle h,
/*! Get local YANG specification for Clixon-restconf.yang tree
*
* That is, get the XML of clixon-config/restconf container of clixon-config.yang
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval x XML tree containing restconf xml node from clixon-restconf.yang
* @code
* cxobj *xrestconf = clicon_conf_restconf(h);
@ -538,7 +560,7 @@ clicon_conf_restconf(clicon_handle h)
/*! Get clixon-autocli.yang part of the clixon config tree
*
* That is, get the XML of clixon-config/autocli container of clixon-config.yang
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval x XML tree containing clispec xml node from clixon-autoclu.yang
* @code
* cxobj *xautocli = clicon_conf_autocli(h);
@ -555,7 +577,8 @@ clicon_conf_autocli(clicon_handle h)
}
/*! Get authorized user name
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval username
*/
char *
@ -567,7 +590,8 @@ clicon_username_get(clicon_handle h)
}
/*! Set authorized user name
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] username
* @note Just keep note of it, dont allocate it or so.
*/
@ -583,7 +607,8 @@ clicon_username_set(clicon_handle h,
}
/*! Get backend daemon startup status
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval status Startup status
*/
enum startup_status
@ -598,7 +623,8 @@ clicon_startup_status_get(clicon_handle h)
}
/*! Set backend daemon startup status
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] status Startup status
* @retval 0 OK
* @retval -1 Error (when setting value)
@ -614,9 +640,10 @@ clicon_startup_status_set(clicon_handle h,
}
/*! Get server socket fd (ie backend server socket / restconf fcgi socket)
* @param[in] h Clicon handle
* @retval -1 No open socket
*
* @param[in] h Clixon handle
* @retval s Socket
* @retval -1 No open socket
*/
int
clicon_socket_get(clicon_handle h)
@ -630,7 +657,8 @@ clicon_socket_get(clicon_handle h)
}
/*! Set server socket fd (ie backend server socket / restconf fcgi socket)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] s Open socket (or -1 to close)
* @retval 0 OK
* @retval -1 Error
@ -647,9 +675,10 @@ clicon_socket_set(clicon_handle h,
}
/*! Get client socket fd (ie client cli / netconf / restconf / client-api socket
* @param[in] h Clicon handle
* @retval -1 No open socket
*
* @param[in] h Clixon handle
* @retval s Socket
* @retval -1 No open socket
*/
int
clicon_client_socket_get(clicon_handle h)
@ -663,7 +692,8 @@ clicon_client_socket_get(clicon_handle h)
}
/*! Set client socket fd (ie client cli / netconf / restconf / client-api socket
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] s Open socket (or -1 to close)
* @retval 0 OK
* @retval -1 Error
@ -680,7 +710,8 @@ clicon_client_socket_set(clicon_handle h,
}
/*! Get module state cache
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] brief 0: Full module state tree, 1: Brief tree (datastore)
* @retval xms Module state cache XML tree
* xms is on the form: <modules-state>...
@ -698,7 +729,8 @@ clicon_modst_cache_get(clicon_handle h,
}
/*! Set module state cache
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] brief 0: Full module state tree, 1: Brief tree (datastore)
* @param[in] xms Module state cache XML tree
* @retval 0 OK
@ -725,7 +757,8 @@ clicon_modst_cache_set(clicon_handle h,
}
/*! Get yang module changelog
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval xch Module revision changelog XML tree
* @see draft-wang-netmod-module-revision-management-01
*/
@ -741,7 +774,8 @@ clicon_xml_changelog_get(clicon_handle h)
}
/*! Set xml module changelog
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] s Module revision changelog XML tree
* @retval 0 OK
* @retval -1 Error
@ -759,7 +793,8 @@ clicon_xml_changelog_set(clicon_handle h,
}
/*! Get user clicon command-line options argv, argc (after --)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[out] argc
* @param[out] argv
* @retval 0 OK
@ -769,7 +804,6 @@ int
clicon_argv_get(clicon_handle h,
int *argc,
char ***argv)
{
clicon_hash_t *cdat = clicon_data(h);
void *p;
@ -788,7 +822,8 @@ clicon_argv_get(clicon_handle h,
}
/*! Set clicon user command-line options argv, argc (after --)
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] prog argv[0] - the program name
* @param[in] argc Length of argv
* @param[in] argv Array of command-line options or NULL
@ -829,7 +864,8 @@ clicon_argv_set(clicon_handle h,
}
/*! Get xml database element including id, xml cache, empty on startup and dirty bit
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] db Name of database
* @retval de Database element
* @retval NULL None found
@ -847,7 +883,8 @@ clicon_db_elmnt_get(clicon_handle h,
}
/*! Set xml database element including id, xml cache, empty on startup and dirty bit
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] db Name of database
* @param[in] de Database element
* @retval 0 OK
@ -868,7 +905,7 @@ clicon_db_elmnt_set(clicon_handle h,
/*! Get session id
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[out] sid Session identifier
* @retval 0 OK
* @retval -1 Session id not set
@ -902,7 +939,8 @@ clicon_session_id_del(clicon_handle h)
}
/*! Set session id
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] id Session id (in range 1..max uint32)
* @retval 0 OK
* @retval -1 Error
@ -919,7 +957,8 @@ clicon_session_id_set(clicon_handle h,
}
/*! Get quit-after-upgrade flag
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval 1 Flag set: quit startup directly after upgrade
* @retval 0 Flag not set
* If set, quit startup directly after upgrade
@ -936,7 +975,8 @@ clicon_quit_upgrade_get(clicon_handle h)
}
/*! Set quit-after-upgrade flag
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] val Set or reset flag
* @retval 0 OK
* @retval -1 Error

View file

@ -124,7 +124,7 @@ xmldb_db2file(clicon_handle h,
/*! Connect to a datastore plugin, allocate resources to be used in API calls
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
@ -167,7 +167,7 @@ xmldb_disconnect(clicon_handle h)
/*! Copy database from db1 to db2
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] from Source database
* @param[in] to Destination database
* @retval 0 OK
@ -187,7 +187,7 @@ xmldb_copy(clicon_handle h,
cxobj *x1 = NULL; /* from */
cxobj *x2 = NULL; /* to */
clicon_debug(1, "%s %s %s", __FUNCTION__, from, to);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %s", __FUNCTION__, from, to);
/* XXX lock */
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
/* Copy in-memory cache */
@ -245,7 +245,7 @@ xmldb_copy(clicon_handle h,
/*! Lock database
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @param[in] id Session id
* @retval 0 OK
@ -264,13 +264,13 @@ xmldb_lock(clicon_handle h,
de0.de_id = id;
gettimeofday(&de0.de_tv, NULL);
clicon_db_elmnt_set(h, db, &de0);
clicon_debug(1, "%s: locked by %u", db, id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: locked by %u", db, id);
return 0;
}
/*! Unlock database
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @retval 0 OK
* @retval -1 Error
@ -292,7 +292,7 @@ xmldb_unlock(clicon_handle h,
/*! Unlock all databases locked by session-id (eg process dies)
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] id Session id
* @retval 0 OK
* @retval -1 Error
@ -328,7 +328,7 @@ xmldb_unlock_all(clicon_handle h,
/*! Check if database is locked
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @retval >0 Session id of locker
* @retval 0 Not locked
@ -347,7 +347,7 @@ xmldb_islocked(clicon_handle h,
/*! Get timestamp of when database was locked
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @param[out] tv Timestamp
* @retval 0 OK
@ -368,7 +368,7 @@ xmldb_lock_timestamp(clicon_handle h,
/*! Check if db exists or is empty
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @retval 1 Yes it exists
* @retval 0 No it does not exist
@ -383,7 +383,7 @@ xmldb_exists(clicon_handle h,
char *filename = NULL;
struct stat sb;
clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, db);
clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, db);
if (xmldb_db2file(h, db, &filename) < 0)
goto done;
if (lstat(filename, &sb) < 0)
@ -403,7 +403,7 @@ xmldb_exists(clicon_handle h,
/*! Clear database cache if any for mem/size optimization only, not file itself
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @retval 0 OK
* @retval -1 Error
@ -426,7 +426,7 @@ xmldb_clear(clicon_handle h,
/*! Delete database, clear cache if any. Remove file
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @retval 0 OK
* @retval -1 Error
@ -441,7 +441,7 @@ xmldb_delete(clicon_handle h,
char *filename = NULL;
struct stat sb;
clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, db);
clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, db);
if (xmldb_clear(h, db) < 0)
goto done;
if (xmldb_db2file(h, db, &filename) < 0)
@ -460,7 +460,7 @@ xmldb_delete(clicon_handle h,
/*! Create a database. Open database for writing.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database
* @retval 0 OK
* @retval -1 Error
@ -475,7 +475,7 @@ xmldb_create(clicon_handle h,
db_elmnt *de = NULL;
cxobj *xt = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, db);
clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, db);
if ((de = clicon_db_elmnt_get(h, db)) != NULL){
if ((xt = de->de_xml) != NULL){
xml_free(xt);
@ -520,7 +520,7 @@ xmldb_db_reset(clicon_handle h,
/*! Get datastore XML cache
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database name
* @retval xml XML cached tree or NULL
*/
@ -537,7 +537,7 @@ xmldb_cache_get(clicon_handle h,
/*! Get modified flag from datastore
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database name
* @retval 1 Db is modified
* @retval 0 Db is not modified
@ -560,7 +560,7 @@ xmldb_modified_get(clicon_handle h,
/*! Get empty flag from datastore (the datastore was empty ON LOAD)
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database name
* @retval 1 Db was empty on load
* @retval 0 Db was not empty on load
@ -581,7 +581,7 @@ xmldb_empty_get(clicon_handle h,
/*! Set modified flag from datastore
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database name
* @param[in] value 0 or 1
* @retval 0 OK
@ -635,7 +635,7 @@ xmldb_print(clicon_handle h,
/*! Rename an XML database
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Database name
* @param[in] newdb New Database name; if NULL, then same as old
* @param[in] suffix Suffix to append to new database name

View file

@ -500,7 +500,7 @@ xmldb_readfile(clicon_handle h,
clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
goto done;
}
clicon_debug(CLIXON_DBG_DEFAULT, "Reading datastore %s using %s", dbfile, format);
clixon_debug(CLIXON_DBG_DEFAULT, "Reading datastore %s using %s", dbfile, format);
/* Parse file into internal XML tree from different formats */
if ((fp = fopen(dbfile, "r")) == NULL) {
clicon_err(OE_UNIX, errno, "open(%s)", dbfile);
@ -666,11 +666,11 @@ xmldb_readfile(clicon_handle h,
* The function returns a minimal tree that includes all sub-trees that match
* xpath.
* This is a clixon datastore plugin of the the xmldb api
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of database to search in (filename including dir path
* @param[in] yb How to bind yang to XML top-level when parsing
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] xpath String with XPath syntax. or NULL for all
* @param[in] wdef With-defaults parameter, see RFC 6243
* @param[out] xret Single return XML tree. Free with xml_free()
* @param[out] msdiff If set, return modules-state differences
@ -713,7 +713,6 @@ xmldb_get_nocache(clicon_handle h,
if (ret == 0)
goto fail;
clicon_db_elmnt_set(h, db, &de0); /* Content is copied */
/* Here xt looks like: <config>...</config> */
/* Given the xpath, return a vector of matches in xvec */
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
@ -802,7 +801,7 @@ xmldb_get_nocache(clicon_handle h,
if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
clicon_log(LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
#endif
if (clicon_debug_get()>1)
if (clixon_debug_get()>1)
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
*xtop = xt;
@ -826,11 +825,11 @@ xmldb_get_nocache(clicon_handle h,
* The function returns a minimal tree that includes all sub-trees that match
* xpath.
* This is a clixon datastore plugin of the the xmldb api
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of database to search in (filename including dir path
* @param[in] yb How to bind yang to XML top-level when parsing
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] xpath String with XPath syntax. or NULL for all
* @param[in] wdef With-defaults parameter, see RFC 6243
* @param[out] xtop Single return XML tree. Free with xml_free()
* @param[out] msdiff If set, return modules-state differences
@ -919,7 +918,6 @@ xmldb_get_cache(clicon_handle h,
goto done;
xml_flag_set(x1t, XML_FLAG_TOP);
xml_spec_set(x1t, xml_spec(x0t));
if (xlen < 1000){
/* This is optimized for the case when the tree is large and xlen is small
* If the tree is large and xlen too, then the other is better.
@ -1000,11 +998,11 @@ xmldb_get_cache(clicon_handle h,
if (disable_nacm_on_empty(x1t, yspec) < 0)
goto done;
}
clicon_debug_xml(CLIXON_DBG_DETAIL, x1t, "%s", __FUNCTION__);
clixon_debug_xml(CLIXON_DBG_DETAIL, x1t, "%s", __FUNCTION__);
*xtop = x1t;
retval = 1;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
free(xvec);
return retval;
@ -1017,11 +1015,11 @@ xmldb_get_cache(clicon_handle h,
*
* Useful for some higer level usecases for optimized access
* This is a clixon datastore plugin of the the xmldb api
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of database to search in (filename including dir path
* @param[in] yb How to bind yang to XML top-level when parsing
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] xpath String with XPath syntax. or NULL for all
* @param[in] wdef With-defaults parameter, see RFC 6243
* @param[out] xret Single return XML tree. Free with xml_free()
* @param[out] msdiff If set, return modules-state differences
@ -1107,8 +1105,7 @@ xmldb_get_zerocopy(clicon_handle h,
/* Mark and remove nodes having schema default values */
if (xml_apply(x0t, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
goto done;
if (xml_tree_prune_flags(x0t, XML_FLAG_MARK, XML_FLAG_MARK)
< 0)
if (xml_tree_prune_flags(x0t, XML_FLAG_MARK, XML_FLAG_MARK) < 0)
goto done;
if (xml_defaults_nopresence(x0t, 1) < 0)
goto done;
@ -1150,13 +1147,13 @@ xmldb_get_zerocopy(clicon_handle h,
if (disable_nacm_on_empty(x0t, yspec) < 0)
goto done;
}
if (clicon_debug_get() > 1)
if (clixon_debug_get() > 1)
if (clixon_xml2file(stderr, x0t, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
*xtop = x0t;
retval = 1;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
if (xvec)
free(xvec);
return retval;
@ -1167,10 +1164,10 @@ xmldb_get_zerocopy(clicon_handle h,
/*! Get content of datastore and return a copy of the XML tree
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of database to search in, eg "running"
* @param[in] nsc XML namespace context for XPATH
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] nsc XML namespace context for XPath
* @param[in] xpath String with XPath syntax. or NULL for all
* @param[out] xret Single return XML tree. Free with xml_free()
* @retval 1 OK
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
@ -1201,11 +1198,11 @@ xmldb_get(clicon_handle h,
* appropriately.
* The tree returned may be the actual cache, therefore calls for cleaning and
* freeing tree must be made after use.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of datastore, eg "running"
* @param[in] yb How to bind yang to XML top-level when parsing (if YB_NONE, no defaults)
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] xpath String with XPath syntax. or NULL for all
* @param[in] copy Force copy. Overrides cache_zerocopy -> cache
* @param[in] wdef With-defaults parameter, see RFC 6243
* @param[out] xret Single return XML tree. Free with xml_free()
@ -1294,7 +1291,7 @@ xmldb_get0(clicon_handle h,
/*! Clear cached xml tree obtained with xmldb_get0, if zerocopy
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] db Name of datastore
* @retval 0 OK
* @retval -1 General error, check specific clicon_errno, clicon_suberrno

View file

@ -430,7 +430,7 @@ choice_delete_other(cxobj *x0,
/*! Modify a base tree x0 with x1 with yang spec y according to operation op
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] x0 Base xml tree (can be NULL in add scenarios)
* @param[in] x0p Parent of x0
* @param[in] x0t Top level of existing tree, eg needed for NACM rules
@ -1010,7 +1010,7 @@ text_modify(clicon_handle h,
/*! Modify a top-level base tree x0 with modification tree x1
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] x0t Base xml tree (can be NULL in add scenarios)
* @param[in] x1t XML tree which modifies base
* @param[in] yspec Top-level yang spec (if y is NULL)

View file

@ -181,8 +181,8 @@ split_path_free(char **list,
}
/*! Find a peer of this node by name
* search through the list pointed at by peer
*
* search through the list pointed at by peer
* @param[in] node Pointer to a node in the peer list
* @param[in] node_name Name of node we're looking for
* @retval pointer Pointer to found node or NULL
@ -226,7 +226,6 @@ add_peer_node(dispatcher_entry_t *node,
if ((new_node = malloc(sizeof(dispatcher_entry_t))) == NULL)
return NULL;
memset(new_node, 0, sizeof(dispatcher_entry_t));
if (node == NULL) {
/* this is a new node */
@ -336,7 +335,6 @@ get_entry(dispatcher_entry_t *root,
/* clean up */
split_path_free(split_path_list, split_path_len);
return best;
}

View file

@ -199,6 +199,8 @@ find_category(int category)
* @param[in] category Clixon error category, See enum clicon_err
* @param[in] suberr Error number, typically errno
* @param[in] format Error string, format with argv
* @retval 0 OK
* @retval -1 Error
* @see clicon_err_reset Reset the global error variables.
*/
int
@ -208,10 +210,10 @@ clicon_err_fn(const char *fn,
int suberr,
const char *format, ...)
{
int retval = -1;
va_list args;
int len;
char *msg = NULL;
int retval = -1;
struct clixon_err_cats *cec;
/* Set the global variables */

View file

@ -102,6 +102,7 @@ static int _clicon_sig_child = 0;
static int _clicon_sig_ignore = 0;
/*! For signal handlers: instead of doing exit, set a global variable to exit
*
* - zero means dont exit,
* - one means exit,
* - more than one means decrement and make another event loop
@ -194,13 +195,16 @@ clixon_event_reg_fd(int fd,
e->e_type = EVENT_FD;
e->e_next = ee;
ee = e;
clicon_debug(CLIXON_DBG_DETAIL, "%s, registering %s", __FUNCTION__, e->e_string);
clixon_debug(CLIXON_DBG_DETAIL, "%s, registering %s", __FUNCTION__, e->e_string);
return 0;
}
/*! Deregister a file descriptor callback
*
* @param[in] s File descriptor
* @param[in] fn Function to call when input available on fd
* @retval 0 OK
* @retval -1 Error
* Note: deregister when exactly function and socket match, not argument
* @see clixon_event_reg_fd
* @see clixon_event_unreg_timeout
@ -209,7 +213,8 @@ int
clixon_event_unreg_fd(int s,
int (*fn)(int, void*))
{
struct event_data *e, **e_prev;
struct event_data *e;
struct event_data **e_prev;
int found = 0;
e_prev = &ee;
@ -232,6 +237,8 @@ clixon_event_unreg_fd(int s,
* @param[in] fn Function to call at time t
* @param[in] arg Argument to function fn
* @param[in] str Describing string for logging
* @retval 0 OK
* @retval -1 Error
* @code
* int fn(int d, void *arg){
* struct timeval t, t1;
@ -282,13 +289,14 @@ clixon_event_reg_timeout(struct timeval t,
}
e->e_next = e1;
*e_prev = e;
clicon_debug(CLIXON_DBG_DETAIL, "%s: %s", __FUNCTION__, str);
clixon_debug(CLIXON_DBG_DETAIL, "%s: %s", __FUNCTION__, str);
retval = 0;
done:
return retval;
}
/*! Deregister a timeout callback as previosly registered by clixon_event_reg_timeout()
*
* Note: deregister when exactly function and function arguments match, not time. So you
* cannot have same function and argument callback on different timeouts. This is a little
* different from clixon_event_unreg_fd.
@ -320,10 +328,11 @@ clixon_event_unreg_timeout(int (*fn)(int, void*),
}
/*! Poll to see if there is any data available on this file descriptor.
*
* @param[in] fd File descriptor
* @retval -1 Error
* @retval 0 Nothing to read/empty fd
* @retval 1 Something to read on fd
* @retval 0 Nothing to read/empty fd
* @retval -1 Error
*/
int
clixon_event_poll(int fd)
@ -396,7 +405,7 @@ clixon_event_loop(clicon_handle h)
* New select loop is called
* (3) Other signals result in an error and return -1.
*/
clicon_debug(1, "%s select: %s", __FUNCTION__, strerror(errno));
clixon_debug(CLIXON_DBG_DEFAULT, "%s select: %s", __FUNCTION__, strerror(errno));
if (clixon_exit_get() == 1){
clicon_err(OE_EVENTS, errno, "select");
retval = 0;
@ -422,7 +431,7 @@ clixon_event_loop(clicon_handle h)
if (n==0){ /* Timeout */
e = ee_timers;
ee_timers = ee_timers->e_next;
clicon_debug(CLIXON_DBG_DETAIL, "%s timeout: %s", __FUNCTION__, e->e_string);
clixon_debug(CLIXON_DBG_DETAIL, "%s timeout: %s", __FUNCTION__, e->e_string);
if ((*e->e_fn)(0, e->e_arg) < 0){
free(e);
goto err;
@ -436,9 +445,9 @@ clixon_event_loop(clicon_handle h)
}
e_next = e->e_next;
if(e->e_type == EVENT_FD && FD_ISSET(e->e_fd, &fdset)){
clicon_debug(CLIXON_DBG_DETAIL, "%s: FD_ISSET: %s", __FUNCTION__, e->e_string);
clixon_debug(CLIXON_DBG_DETAIL, "%s: FD_ISSET: %s", __FUNCTION__, e->e_string);
if ((*e->e_fn)(e->e_fd, e->e_arg) < 0){
clicon_debug(1, "%s Error in: %s", __FUNCTION__, e->e_string);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Error in: %s", __FUNCTION__, e->e_string);
goto err;
}
if (_ee_unreg){
@ -450,12 +459,12 @@ clixon_event_loop(clicon_handle h)
clixon_exit_decr(); /* If exit is set and > 1, decrement it (and exit when 1) */
continue;
err:
clicon_debug(1, "%s err", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s err", __FUNCTION__);
break;
}
if (clixon_exit_get() == 1)
retval = 0;
clicon_debug(1, "%s done:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s done:%d", __FUNCTION__, retval);
return retval;
}

View file

@ -74,7 +74,8 @@ clicon_file_dirent_sort(const void* arg1,
return strcoll(d1->d_name, d2->d_name);
}
/*!
/*! List files recursive
*
* @param[in,out] cvv On the format: (name, path)*
*/
static int
@ -144,7 +145,7 @@ clicon_files_recursive(const char *dir,
int res = 0;
char errbuf[128];
clicon_debug(CLIXON_DBG_DETAIL, "%s dir:%s", __FUNCTION__, dir);
clixon_debug(CLIXON_DBG_DETAIL, "%s dir:%s", __FUNCTION__, dir);
if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) {
regerror(res, &re, errbuf, sizeof(errbuf));
clicon_err(OE_DB, 0, "regcomp: %s", errbuf);
@ -165,7 +166,6 @@ clicon_files_recursive(const char *dir,
* @param[out] ent Entries pointer, will be filled in with dir entries. Free after use
* @param[in] regexp Regexp filename matching
* @param[in] type File type matching, see stat(2)
*
* @retval n Number of matching files in directory
* @retval -1 Error
*
@ -238,7 +238,7 @@ clicon_file_dirent(const char *dir,
clicon_err(OE_UNIX, errno, "realloc");
goto quit;
} /* realloc */
clicon_debug(CLIXON_DBG_DETAIL, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize);
clixon_debug(CLIXON_DBG_DETAIL, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize);
/* man (3) readdir:
* By implication, the use sizeof(struct dirent) to capture the size of the record including
* the size of d_name is also incorrect. */

View file

@ -66,6 +66,7 @@
#define handle(h) (assert(clicon_handle_check(h)==0),(struct clicon_handle *)(h))
/*! Internal structure of basic handle. Also header of all other handles.
*
* @note If you change here, you must also change the structs below:
* This is the internal definition of a "Clixon handle" which in its external
* form is "clicon_handle" and is used in most Clixon API calls.
@ -96,7 +97,7 @@ struct clicon_handle {
/*! Internal call to allocate a CLICON handle.
*
* @param[in] size Size of handle (internal) struct.
* @retval h Clicon handle
* @retval h Clixon handle
*
* There may be different variants of handles with some common options.
* So far the only common options is a MAGIC cookie for sanity checks and
@ -133,7 +134,7 @@ clicon_handle_init0(int size)
/*! Basic CLICON init functions returning a handle for API access.
*
* @retval h Clicon handle
* @retval h Clixon handle
* This is the first call to CLICON basic API which returns a handle to be
* used in the API functions. There are other clicon_init functions for more
* elaborate applications (cli/backend/netconf). This should be used by the most
@ -146,8 +147,11 @@ clicon_handle_init(void)
}
/*! Deallocate clicon handle, including freeing handle data.
* @param[in] h Clicon handle
* @Note: handle 'h' cannot be used in calls after this
*
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* @note: handle 'h' cannot be used in calls after this
*/
int
clicon_handle_exit(clicon_handle h)
@ -169,7 +173,8 @@ clicon_handle_exit(clicon_handle h)
}
/*! Check struct magic number for sanity checks
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval 0 Sanity check OK
* @retval -1 Sanity check failed
*/
@ -183,7 +188,8 @@ clicon_handle_check(clicon_handle h)
}
/*! Return clicon options (hash-array) given a handle.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
clicon_hash_t *
clicon_options(clicon_handle h)
@ -194,7 +200,8 @@ clicon_options(clicon_handle h)
}
/*! Return clicon data (hash-array) given a handle.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
clicon_hash_t *
clicon_data(clicon_handle h)
@ -205,7 +212,8 @@ clicon_data(clicon_handle h)
}
/*! Return clicon db_elmnt (hash-array) given a handle.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
clicon_hash_t *
clicon_db_elmnt(clicon_handle h)
@ -216,7 +224,8 @@ clicon_db_elmnt(clicon_handle h)
}
/*! Return stream hash-array given a clicon handle.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
event_stream_t *
clicon_stream(clicon_handle h)

View file

@ -247,16 +247,13 @@ clicon_hash_add(clicon_hash_t *hash,
goto catch;
}
memset(new, 0, sizeof(*new));
new->h_key = strdup(key);
if (new->h_key == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto catch;
}
h = new;
}
if (vlen){
/* Make copy of value. aligned */
newval = malloc(align4(vlen+3));
@ -266,7 +263,6 @@ clicon_hash_add(clicon_hash_t *hash,
}
memcpy(newval, val, vlen);
}
/* Free old value if existing variable */
if (h->h_val)
free(h->h_val);
@ -293,7 +289,6 @@ catch:
*
* @param[in] hash Hash table
* @param[in] key Variable name
*
* @retval 0 OK
* @retval -1 Key not found
*/
@ -310,9 +305,7 @@ clicon_hash_del(clicon_hash_t *hash,
h = clicon_hash_lookup(hash, key);
if (h == NULL)
return -1;
DELQ(h, hash[hash_bucket(key)], clicon_hash_t);
free(h->h_key);
free(h->h_val);
free(h);

View file

@ -124,7 +124,6 @@ uint [1-9][0-9]*
<STRSQ>[^\']+ { clixon_instance_id_parselval.string = strdup(yytext); return STRING; }
<STRSQ>\' { BEGIN(_IY->iy_lex_state); return SQUOTE; }
%%
/*! Initialize scanner.

View file

@ -128,7 +128,7 @@
/* Enable for debugging, steals some cycles otherwise */
#if 0
#define _PARSE_DEBUG(s) clicon_debug(1,(s))
#define _PARSE_DEBUG(s) clixon_debug(1,(s))
#else
#define _PARSE_DEBUG(s)
#endif
@ -166,7 +166,7 @@ static clixon_path *
path_append(clixon_path *list,
clixon_path *new)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
if (new == NULL)
return NULL;
ADDQ(new, list);
@ -174,6 +174,7 @@ path_append(clixon_path *list,
}
/*! Add keyvalue to existing clixon path
*
* If cvk has one integer argument, interpret as position, eg x/y[42]
* else as keyvalue strings, eg x/y[k1="foo"][k2="bar"]
*/
@ -181,7 +182,7 @@ static clixon_path *
path_add_keyvalue(clixon_path *cp,
cvec *cvk)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
if (cp == NULL)
goto done;
cp->cp_cvk = cvk;
@ -195,7 +196,7 @@ path_new(char *prefix,
{
clixon_path *cp = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, prefix, id);
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, prefix, id);
if ((cp = malloc(sizeof(*cp))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -225,7 +226,7 @@ keyval_pos(char *uint)
char *reason=NULL;
int ret;
clicon_debug(CLIXON_DBG_DETAIL, "%s(%s)", __FUNCTION__, uint);
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s)", __FUNCTION__, uint);
if ((cvv = cvec_new(1)) == NULL) {
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;
@ -249,16 +250,17 @@ keyval_pos(char *uint)
}
/*! Append a key-value cv to a cvec, create the cvec if not exist
*
* @param[in] cvv Either created cvv or NULL, in whihc case it is created
* @param[in] cv Is consumed by thius function (if appended)
* @retval NULL Error
* @retval cvv Cvec
* @retval NULL Error
*/
static cvec *
keyval_add(cvec *cvv,
cg_var *cv)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s()", __FUNCTION__);
if (cv == NULL)
goto done;
if (cvv == NULL &&
@ -284,7 +286,7 @@ keyval_set(char *name,
{
cg_var *cv = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name, val);
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name, val);
if ((cv = cv_new(CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new");
goto done;

View file

@ -245,14 +245,15 @@ array_eval(cxobj *xprev,
*
* @param[out] cb cbuf (encoded)
* @param[in] str string (unencoded)
* @retval 0 OK
*/
static int
json_str_escape_cdata(cbuf *cb,
char *str)
{
int retval = -1;
int i;
size_t len;
int i;
len = strlen(str);
for (i=0; i<len; i++)
@ -316,7 +317,7 @@ json2xml_decode_identityref(cxobj *x,
char *prefix2 = NULL;
cbuf *cbv = NULL;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
yspec = ys_spec(y);
if ((xb = xml_body_get(x)) == NULL)
goto ok;
@ -334,7 +335,7 @@ json2xml_decode_identityref(cxobj *x,
*/
if (xml_nsctx_node(x, &nsc) < 0)
goto done;
clicon_debug(1, "%s prefix:%s body:%s namespace:%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s prefix:%s body:%s namespace:%s",
__FUNCTION__, prefix, body, ns);
if (!xml_nsctx_get_prefix(nsc, ns, &prefix2)){
/* (no) insert a xmlns:<prefix> statement
@ -453,6 +454,8 @@ json2xml_decode(cxobj *x,
* @param[in] body body string
* @param[in] ys Yang spec of parent
* @param[out] cb Encoded string
* @retval 0 OK
* @retval -1 Error
*/
static int
xml2json_encode_identityref(cxobj *xb,
@ -468,7 +471,7 @@ xml2json_encode_identityref(cxobj *xb,
yang_stmt *yspec;
yang_stmt *my_ymod;
clicon_debug(1, "%s %s", __FUNCTION__, body);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, body);
my_ymod = ys_module(yp);
yspec = ys_spec(yp);
if (nodeid_split(body, &prefix, &id) < 0)
@ -477,7 +480,7 @@ xml2json_encode_identityref(cxobj *xb,
if (xml2ns(xb, prefix, &namespace) < 0)
goto done;
/* We got the namespace, now get the module */
// clicon_debug(1, "%s body:%s prefix:%s namespace:%s", __FUNCTION__, body, prefix, namespace);
// clixon_debug(CLIXON_DBG_DEFAULT, "%s body:%s prefix:%s namespace:%s", __FUNCTION__, body, prefix, namespace);
#ifdef IDENTITYREF_KLUDGE
if (namespace == NULL){
/* If we dont find namespace here, we assume it is because of a missing
@ -493,7 +496,6 @@ xml2json_encode_identityref(cxobj *xb,
#endif
{
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) != NULL){
if (ymod == my_ymod)
cprintf(cb, "%s", id);
else{
@ -518,6 +520,8 @@ xml2json_encode_identityref(cxobj *xb,
* @param[in] xp XML parent
* @param[in] yp Yang spec of parent
* @param[out] cb0 Encoded string
* @retval 0 OK
* @retval -1 Error
*/
static int
xml2json_encode_leafs(cxobj *xb,
@ -738,6 +742,8 @@ json_metadata_encoding(cbuf *cb,
* @param[in] pretty Pretty-print output (2 means debug)
* @param[in] modname Name of yang module
* @param[in,out] metacb Encode into cbuf
* @retval 0 OK
* @retval -1 Error
* @see RFC7952
*/
static int
@ -800,6 +806,8 @@ xml2json_encode_attr(cxobj *xa,
* @param[in] flat Dont print NO_ARRAY object name (for _vec call)
* @param[in] modname0
* @param[out] metacbp Meta encoding of attribute
* @retval 0 OK
* @retval -1 Error
*
* @note Does not work with XML attributes
* The following matrix explains how the mapping is done.
@ -1080,7 +1088,6 @@ xml2json_cbuf1(cbuf *cb,
cprintf(cb, "%*s{%s",
pretty?level*PRETTYPRINT_INDENT:0,"",
pretty?"\n":"");
if (y != NULL){
switch (yang_keyword_get(y)){
case Y_LEAF_LIST:
@ -1419,11 +1426,11 @@ json_xmlns_translate(yang_stmt *yspec,
* @param[in] yspec Yang specification (if rfc 7951)
* @param[out] xt XML top of tree typically w/o children on entry (but created)
* @param[out] xerr Reason for invalid returned as netconf err msg
*
* @see _xml_parse for XML variant
* @retval 1 OK and valid
* @retval 0 Invalid (only if yang spec)
* @retval -1 Error with clicon_err called
*
* @see _xml_parse for XML variant
* @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
* @see RFC 7951
*/
@ -1443,7 +1450,7 @@ _json_parse(char *str,
int i;
int failed = 0; /* yang assignment */
clicon_debug(1, "%s %d %s", __FUNCTION__, yb, str);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d %s", __FUNCTION__, yb, str);
jy.jy_parse_string = str;
jy.jy_linenum = 1;
jy.jy_current = xt;
@ -1529,7 +1536,7 @@ _json_parse(char *str,
goto done;
retval = 1;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cberr)
cbuf_free(cberr);
json_parse_exit(&jy);
@ -1572,7 +1579,7 @@ clixon_json_parse_string(char *str,
cxobj **xt,
cxobj **xerr)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (xt==NULL){
clicon_err(OE_JSON, EINVAL, "xt is NULL");
return -1;
@ -1602,6 +1609,9 @@ clixon_json_parse_string(char *str,
* @param[in] yspec Yang specification, or NULL
* @param[in,out] xt Pointer to (XML) parse tree. If empty, create.
* @param[out] xerr Reason for invalid returned as netconf err msg
* @retval 1 OK and valid
* @retval 0 Invalid (only if yang spec) w xerr set
* @retval -1 Error with clicon_err called
*
* @code
* cxobj *xt = NULL;
@ -1612,11 +1622,6 @@ clixon_json_parse_string(char *str,
* @note you need to free the xml parse tree after use, using xml_free()
* @note, If xt empty, a top-level symbol will be added so that <tree../> will be: <top><tree.../></tree></top>
* @note May block on file I/O
*
* @retval 1 OK and valid
* @retval 0 Invalid (only if yang spec) w xerr set
* @retval -1 Error with clicon_err called
*
* @see clixon_json_parse_string
* @see RFC7951
*/

View file

@ -137,7 +137,7 @@ object.
/* Enable for debugging, steals some cycles otherwise */
#if 0
#define _PARSE_DEBUG(s) clicon_debug(1,(s))
#define _PARSE_DEBUG(s) clixon_debug(1,(s))
#else
#define _PARSE_DEBUG(s)
#endif
@ -164,7 +164,7 @@ clixon_json_parseerror(void *_jy,
int
json_parse_init(clixon_json_yacc *jy)
{
// clicon_debug_init(2, NULL);
// clixon_debug_init(2, NULL);
return 0;
}
@ -175,6 +175,7 @@ json_parse_exit(clixon_json_yacc *jy)
}
/*! Create xml object from json object name (eg "string")
*
* Split name into prefix:name (extended JSON RFC7951)
*/
static int
@ -186,7 +187,7 @@ json_current_new(clixon_json_yacc *jy,
char *prefix = NULL;
char *id = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Find colon separator and if found split into prefix:name */
if (nodeid_split(name, &prefix, &id) < 0)
goto done;
@ -213,7 +214,7 @@ json_current_new(clixon_json_yacc *jy,
static int
json_current_pop(clixon_json_yacc *jy)
{
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (jy->jy_current)
jy->jy_current = xml_parent(jy->jy_current);
return 0;
@ -224,7 +225,7 @@ json_current_clone(clixon_json_yacc *jy)
{
cxobj *xn;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (jy->jy_current == NULL){
return -1;
}
@ -243,7 +244,6 @@ json_current_clone(clixon_json_yacc *jy)
maybe_prefixed_name = strdup(name);
}
json_current_new(jy, maybe_prefixed_name);
if (maybe_prefixed_name)
free(maybe_prefixed_name);
}
@ -257,7 +257,7 @@ json_current_body(clixon_json_yacc *jy,
int retval = -1;
cxobj *xn;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if ((xn = xml_new("body", jy->jy_current, CX_BODY)) == NULL)
goto done;
if (value && xml_value_append(xn, value) < 0)

View file

@ -80,7 +80,7 @@ static int _clixon_log_trunc = 0;
*
* Make syslog(3) calls with specified ident and gates calls of level upto specified level (upto).
* May also print to stderr, if err is set.
* Applies to clicon_err() and clicon_debug too
* Applies to clicon_err() and clixon_debug too
*
* @param[in] ident prefix that appears on syslog (eg 'cli')
* @param[in] upto log priority, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG (see syslog(3)).
@ -116,9 +116,10 @@ clicon_log_exit(void)
}
/*! Utility function to set log destination/flag using command-line option
*
* @param[in] c Log option,one of s,f,e,o
* @retval -1 No match
* @retval 0 One of CLICON_LOG_SYSLOG|STDERR|STDOUT|FILE
* @retval -1 No match
*/
int
clicon_log_opt(char c)
@ -148,10 +149,11 @@ clicon_log_opt(char c)
}
/*! If log flags include CLICON_LOG_FILE, set the file
*
* @param[in] filename File to log to
* @retval 0 OK
* @retval -1 Error
* @see clicon_debug_init where a strean
* @see clixon_debug_init where a strean
*/
int
clicon_log_file(char *filename)
@ -236,7 +238,7 @@ slogtime(void)
* @param[in] msg Message to print as argv.
* This is the _only_ place the actual syslog (or stderr) logging is made in clicon,..
* @note syslog makes its own filtering, but if log to stderr we do it here
* @see clicon_debug
* @see clixon_debug
*/
int
clicon_log_str(int level,
@ -274,6 +276,8 @@ clicon_log_str(int level,
* @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. This
* is OR:d with facility == LOG_USER
* @param[in] format Message to print as argv.
* @retval 0 OK
* @retval -1 Error
* @code
clicon_log(LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__);
* @endcode
@ -284,10 +288,10 @@ int
clicon_log(int level,
const char *format, ...)
{
int retval = -1;
va_list args;
size_t len;
char *msg = NULL;
int retval = -1;
size_t trunc;
/* first round: compute length of debug message */
@ -325,9 +329,9 @@ clicon_log(int level,
/*! Initialize debug messages. Set debug level.
*
* Initialize debug module. The level is used together with clicon_debug(dbglevel) calls as follows:
* Initialize debug module. The level is used together with clixon_debug(dbglevel) calls as follows:
* print message if level >= dbglevel.
* Example: clicon_debug_init(1) -> debug(1) is printed, but not debug(2).
* Example: clixon_debug_init(1) -> debug(1) is printed, but not debug(2).
* Normally, debug messages are sent to clicon_log() which in turn can be sent to syslog and/or stderr.
* But you can also override this with a specific debug file so that debug messages are written on the file
* independently of log or errors. This is to ensure that a syslog of normal logs is unpolluted by extensive
@ -341,7 +345,7 @@ clicon_log(int level,
* @see clicon_log_file where a filename can be given
*/
int
clicon_debug_init(int dbglevel,
clixon_debug_init(int dbglevel,
FILE *f)
{
_clixon_debug = dbglevel; /* Global variable */
@ -355,7 +359,7 @@ clicon_debug_init(int dbglevel,
}
int
clicon_debug_get(void)
clixon_debug_get(void)
{
return _clixon_debug;
}
@ -363,27 +367,29 @@ clicon_debug_get(void)
/*! Print a debug message with debug-level. Settings determine where msg appears.
*
* If the dbglevel passed in the function is equal to or lower than the one set by
* clicon_debug_init(level). That is, only print debug messages <= than what you want:
* clixon_debug_init(level). That is, only print debug messages <= than what you want:
* print message if level >= dbglevel.
* The message is sent to clicon_log. EIther to syslog, stderr or both, depending on
* clicon_log_init() setting
* @param[in] dbglevel Mask of CLIXON_DBG_DEFAULT and other masks
* @param[in] format Message to print as argv.
* @see clicon_debug_xml Specialization for XML tree
* @retval 0 OK
* @retval -1 Error
* @see clixon_debug_xml Specialization for XML tree
* @see CLIXON_DBG_DEFAULT and other flags
*/
int
clicon_debug(int dbglevel,
clixon_debug(int dbglevel,
const char *format, ...)
{
int retval = -1;
va_list args;
size_t len;
char *msg = NULL;
int retval = -1;
size_t trunc;
/* Mask debug level with global dbg variable */
if ((dbglevel & clicon_debug_get()) == 0)
if ((dbglevel & clixon_debug_get()) == 0)
return 0;
/* first round: compute length of debug message */
va_start(args, format);
@ -393,7 +399,6 @@ clicon_debug(int dbglevel,
/* Truncate long debug strings */
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
len = trunc;
/* allocate a message string exactly fitting the message length */
if ((msg = malloc(len+1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
@ -416,6 +421,7 @@ clicon_debug(int dbglevel,
}
/*! Translate month number (0..11) to a three letter month name
*
* @param[in] md month number, where 0 is january
*/
char *

View file

@ -79,13 +79,14 @@
#define NACM_NS "urn:ietf:params:xml:ns:yang:ietf-netconf-acm"
/*! Match nacm access operations according to RFC8341 3.4.4.
*
* Incoming RPC Message Validation Step 7 (c)
* The rule's "access-operations" leaf has the "exec" bit set or
* has the special value "*".
* @param[in] mode Primary mode, eg read, create, update, delete, exec
* @param[in] mode2 Secondary mode, eg "write"
* @retval 0 No match
* @retval 1 Match
* @retval 0 No match
* @note access_operations is bit-fields
*/
static int
@ -105,14 +106,15 @@ match_access(char *access_operations,
}
/*! Match nacm single rule. Either match with access or deny. Or not match.
*
* @param[in] rpc rpc name
* @param[in] module Yang module name
* @param[in] xrule NACM rule XML tree
* @param[out] cbret Cligen buffer result. Set to an error msg if retval=0.
* @retval -1 Error
* @retval 0 Matching rule AND Not access and cbret set
* @retval 1 Matching rule AND Access
* @retval 2 No matching rule Goto step 10
* @retval 1 Matching rule AND Access
* @retval 0 Matching rule AND Not access and cbret set
* @retval -1 Error
* @see RFC8341 3.4.4. Incoming RPC Message Validation
7.(cont) A rule matches if all of the following criteria are met:
* The rule's "module-name" leaf is "*" or equals the name of
@ -166,14 +168,15 @@ nacm_rule_rpc(char *rpc,
}
/*! Process nacm incoming RPC message validation steps
*
* @param[in] module Yang module name
* @param[in] rpc rpc name
* @param[in] username User name of requestor
* @param[in] xnacm NACM xml tree
* @param[out] cbret Cligen buffer result. Set to an error msg if retval=0.
* @retval -1 Error
* @retval 0 Not access and cbret set
* @retval 1 Access
* @retval 0 Not access and cbret set
* @retval -1 Error
* @see RFC8341 3.4.4. Incoming RPC Message Validation
* @see nacm_datanode_write
* @see nacm_datanode_read
@ -295,7 +298,7 @@ nacm_rpc(char *rpc,
permit:
retval = 1;
done:
clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
if (nsc)
xml_nsctx_free(nsc);
if (gvec)
@ -354,11 +357,15 @@ prepvec_add(prepvec **pv_listp,
}
/*! Prepare datastructures before running through XML tree
*
* Save rules in a "cache"
* These rules match:
* - user/group
* - have read access-op, etc
* Also make instance-id lookups on top object for each rule. Assume at most one result
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
static int
nacm_datanode_prepare(clicon_handle h,
@ -517,14 +524,15 @@ nacm_datanode_prepare(clicon_handle h,
*/
/*! Match specific rule to specific requested node
*
* @param[in] xn XML node (requested node)
* @param[in] xrule NACM rule
* @param[in] xp Xpath match
* @param[in] yspec YANG spec
* @retval -1 Error
* @retval 0 OK and rule does not match
* @retval 1 OK and rule matches deny
* @retval 2 OK and rule matches permit
* @retval 1 OK and rule matches deny
* @retval 0 OK and rule does not match
* @retval -1 Error
*/
static int
nacm_data_write_xrule_xml(cxobj *xn,
@ -583,7 +591,8 @@ nacm_data_write_xrule_xml(cxobj *xn,
}
/*! Recursive check for NACM write rules among all XML nodes
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xn XML node (requested node)
* @param[in] rulevec Precomputed rules that apply to this user group
* @param[in] xpathvec Precomputed xpath results that apply to this XML tree
@ -658,6 +667,7 @@ nacm_datanode_write_recurse(clicon_handle h,
}
/*! Make nacm datanode and module rule write access validation
*
* The operations of NACM are: create, read, update, delete, exec
* where write is short-hand for create+delete+update
* @param[in] h Clixon handle
@ -667,9 +677,9 @@ nacm_datanode_write_recurse(clicon_handle h,
* @param[in] username User making access
* @param[in] xnacm NACM xml tree
* @param[out] cbret Cligen buffer result. Set to an error msg if retval=0.
* @retval -1 Error
* @retval 0 Not access and cbret set
* @retval 1 Access
* @retval 0 Not access and cbret set
* @retval -1 Error
* @see RFC8341 3.4.5. Data Node Access Validation
* @see nacm_datanode_read
* @see nacm_rpc
@ -759,7 +769,7 @@ nacm_datanode_write(clicon_handle h,
permit:
retval = 1;
done:
clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
if (pv_list)
prepvec_free(pv_list);
if (nsc)
@ -782,10 +792,12 @@ nacm_datanode_write(clicon_handle h,
*/
/*! Perform NACM action: mark if permit, del if deny
*
* @param[in] xrule NACM rule
* @param[in] xn XML node (requested node)
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
static int
nacm_data_read_action(cxobj *xrule,
@ -806,12 +818,13 @@ nacm_data_read_action(cxobj *xrule,
}
/*! Match specific rule to specific requested node
*
* @param[in] xn XML node (requested node)
* @param[in] xrule NACM rule
* @param[in] yspec YANG spec
* @retval -1 Error
* @retval 0 OK and rule does not match
* @retval 1 OK and rule matches
* @retval 0 OK and rule does not match
* @retval -1 Error
* Two distinct cases:
* (1) read_default is permit
* mark all deny rules and remove them
@ -868,7 +881,8 @@ nacm_data_read_xrule_xml(cxobj *xn,
}
/*! Recursive check for NACM read rules among all XML nodes
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] xn XML node (requested node)
* @param[in] rulevec Precomputed rules that apply to this user group
* @param[in] xpathvec Precomputed xpath results that apply to this XML tree
@ -932,16 +946,17 @@ nacm_datanode_read_recurse(clicon_handle h,
}
/*! Make nacm datanode and module rule read access validation
*
* Just purge nodes that fail validation (dont send netconf error message)
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xt XML root tree with "config" label
* @param[in] xrvec Vector of requested nodes (sub-part of xt)
* @param[in] xrlen Length of requsted node vector
* @param[in] username
* @param[in] xnacm NACM xml tree
* @retval -1 Error
* @retval 0 Not access and cbret set
* @retval 1 Access
* @retval 0 Not access and cbret set
* @retval -1 Error
* 3.2.4: <get> and <get-config> Operations
* Data nodes to which the client does not have read access are silently
* omitted, along with any descendants, from the <rpc-reply> message.
@ -1059,7 +1074,7 @@ nacm_datanode_read(clicon_handle h,
ok:
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (pv_list)
prepvec_free(pv_list);
if (nsc)
@ -1077,15 +1092,16 @@ nacm_datanode_read(clicon_handle h,
*/
/*! NACM intial pre- access control enforcements
*
* Initial NACM steps and common to all NACM access validation.
* If retval=0 continue with next NACM step, eg rpc, module,
* etc. If retval = 1 access is OK and skip next NACM step.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] xnacm NACM XML tree, root should be "nacm"
* @param[in] username User name of requestor
* @retval -1 Error
* @retval 0 OK but not validated. Need to do NACM step using xnacm
* @retval 1 OK permitted. You do not need to do next NACM step
* @retval 0 OK but not validated. Need to do NACM step using xnacm
* @retval -1 Error
* @code
* if ((ret = nacm_access_check(h, mode, xnacm, peername, username)) < 0)
* err;
@ -1111,7 +1127,7 @@ nacm_access_check(clicon_handle h,
char *wwwuser;
#endif
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL)
goto done;
/* Do initial nacm processing common to all access validation in
@ -1164,7 +1180,7 @@ nacm_access_check(clicon_handle h,
done:
if (nsc)
xml_nsctx_free(nsc);
clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval);
return retval;
permit:
retval = 1;
@ -1172,15 +1188,16 @@ nacm_access_check(clicon_handle h,
}
/*! NACM intial pre- access control enforcements
*
* Initial NACM steps and common to all NACM access validation.
* If retval=0 continue with next NACM step, eg rpc, module,
* etc. If retval = 1 access is OK and skip next NACM step.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] username User name of requestor
* @param[out] xncam NACM XML tree, set if retval=0. Free after use
* @retval -1 Error
* @retval 0 OK but not validated. Need to do NACM step using xnacm
* @retval 1 OK permitted. You do not need to do next NACM step.
* @retval 0 OK but not validated. Need to do NACM step using xnacm
* @retval -1 Error
* @code
* cxobj *xnacm = NULL;
* if ((ret = nacm_access_pre(h, peername, username, &xnacm)) < 0)
@ -1224,7 +1241,6 @@ nacm_access_pre(clicon_handle h,
clicon_err(OE_XML, 0, "Invalid NACM mode: %s", mode);
goto done;
}
if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL)
goto done;
/* If config does not exist then the operation is permitted(?) */
@ -1263,9 +1279,9 @@ nacm_access_pre(clicon_handle h,
* @param[in] peername Peer username if any
* @param[in] username username received in XML (eg for NACM)
* @param[out] cbret Set with netconf error message if ret == 0
* @retval -1 Error
* @retval 0 Not verified (cbret set)
* @retval 1 Verified
* @retval 0 Not verified (cbret set)
* @retval -1 Error
* Credentials OK if
* - cred mode is NONE,
* Otherwise both NACM user AND peer user must exist, and

View file

@ -102,14 +102,14 @@ netconf_input_read2(int s,
goto done;
}
} /* read */
clicon_debug(CLIXON_DBG_DETAIL, "%s len:%ld", __FUNCTION__, len);
clixon_debug(CLIXON_DBG_DETAIL, "%s len:%ld", __FUNCTION__, len);
if (len == 0){ /* EOF */
clicon_debug(CLIXON_DBG_DETAIL, "%s len==0, closing", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s len==0, closing", __FUNCTION__);
*eof = 1;
}
retval = len;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
@ -146,7 +146,7 @@ netconf_input_msg2(unsigned char **bufp,
size_t len;
char ch;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
len = *lenp;
for (i=0; i<len; i++){
if ((ch = (*bufp)[i]) == 0)
@ -189,7 +189,7 @@ netconf_input_msg2(unsigned char **bufp,
*eom = found;
retval = 0;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
return retval;
}
@ -217,7 +217,7 @@ netconf_input_frame2(cbuf *cb,
cxobj *xtop = NULL; /* Request (in) */
int ret;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (xrecv == NULL){
clicon_err(OE_PLUGIN, EINVAL, "xrecv is NULL");
goto done;

View file

@ -87,6 +87,7 @@ static const map_str2int wdmap[] = {
};
/*! Map from with-defaults ints to strings
*
* @param[in] int Integer representation of withdefaults values
* @retval str String representation of withdefaults values
*/
@ -97,6 +98,7 @@ withdefaults_int2str(int keyword)
}
/*! Map from with-defaults strings to ints
*
* @param[in] str String representation of withdefaults values
* @retval int Integer representation of withdefaults values
*/
@ -112,6 +114,8 @@ withdefaults_str2int(char *str)
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_in_use(cbuf *cb,
@ -152,6 +156,8 @@ netconf_in_use(cbuf *cb,
* @param[out] xret Error XML tree. Free with xml_free after use
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_invalid_value_xml(cxobj **xret,
@ -201,6 +207,8 @@ netconf_invalid_value_xml(cxobj **xret,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_invalid_value(cbuf *cb,
@ -228,6 +236,8 @@ netconf_invalid_value(cbuf *cb,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "transport", "rpc", "application", "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_too_big(cbuf *cb,
@ -269,6 +279,8 @@ netconf_too_big(cbuf *cb,
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] attr bad-attribute and/or bad-element xml
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_missing_attribute_xml(cxobj **xret,
@ -320,6 +332,8 @@ netconf_missing_attribute_xml(cxobj **xret,
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] attr bad-attribute
* @param[in] message Error message (will be XML encoded) or NULL
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_missing_attribute(cbuf *cb,
@ -349,6 +363,8 @@ netconf_missing_attribute(cbuf *cb,
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] info Attribute name
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_bad_attribute(cbuf *cb,
@ -378,6 +394,9 @@ netconf_bad_attribute(cbuf *cb,
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] info Attribute name
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_bad_attribute_xml(cxobj **xret,
@ -429,6 +448,8 @@ netconf_bad_attribute_xml(cxobj **xret,
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] info bad-attribute or bad-element xml
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_unknown_attribute(cbuf *cb,
@ -471,6 +492,8 @@ netconf_unknown_attribute(cbuf *cb,
* @param[in] tag Error tag
* @param[in] element bad-element xml
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
*/
static int
netconf_common_xml(cxobj **xret,
@ -525,6 +548,8 @@ netconf_common_xml(cxobj **xret,
* @param[in] type Error type: "application" or "protocol"
* @param[in] info bad-element xml
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_missing_element(cbuf *cb,
@ -552,6 +577,8 @@ netconf_missing_element(cbuf *cb,
* @param[in] type Error type: "application" or "protocol"
* @param[in] element bad-element xml
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_missing_element_xml(cxobj **xret,
@ -571,6 +598,8 @@ netconf_missing_element_xml(cxobj **xret,
* @param[in] type Error type: "application" or "protocol"
* @param[in] elemnt Bad element name
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_bad_element(cbuf *cb,
@ -609,6 +638,8 @@ netconf_bad_element_xml(cxobj **xret,
* @param[in] type Error type: "application" or "protocol"
* @param[in] element Bad element name
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_unknown_element(cbuf *cb,
@ -638,6 +669,8 @@ netconf_unknown_element(cbuf *cb,
* @param[in] type Error type: "application" or "protocol"
* @param[in] element Bad element name
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_unknown_element_xml(cxobj **xret,
@ -656,6 +689,8 @@ netconf_unknown_element_xml(cxobj **xret,
* @param[in] type Error type: "application" or "protocol"
* @param[in] info bad-element or bad-namespace xml
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_unknown_namespace(cbuf *cb,
@ -695,6 +730,8 @@ netconf_unknown_namespace_xml(cxobj **xret,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
* @see netconf_access_denied_xml Same but returns XML tree
*/
int
@ -723,6 +760,8 @@ netconf_access_denied(cbuf *cb,
* @param[out] xret Error XML tree. Free with xml_free after use
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
* @code
* cxobj *xret = NULL;
* if (netconf_access_denied_xml(&xret, "protocol", "Unauthorized") < 0)
@ -779,6 +818,8 @@ netconf_access_denied_xml(cxobj **xret,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] info session-id xml
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_lock_denied(cbuf *cb,
@ -819,6 +860,8 @@ netconf_lock_denied(cbuf *cb,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "transport, "rpc", "application", "protocol"
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_resource_denied(cbuf *cb,
@ -859,6 +902,8 @@ netconf_resource_denied(cbuf *cb,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_rollback_failed(cbuf *cb,
@ -899,6 +944,8 @@ netconf_rollback_failed(cbuf *cb,
* a "create" operation was attempted on data that already exists.
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_data_exists(cbuf *cb,
@ -938,6 +985,8 @@ netconf_data_exists(cbuf *cb,
* data that does not exist.
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_data_missing(cbuf *cb,
@ -964,6 +1013,8 @@ netconf_data_missing(cbuf *cb,
* data that does not exist.
* @param[out] xret Error XML tree. Free with xml_free after use
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_data_missing_xml(cxobj **xret,
@ -1017,6 +1068,8 @@ netconf_data_missing_xml(cxobj **xret,
* @param[in] x Element with missing choice
* @param[in] name Name of missing mandatory choice
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_missing_choice_xml(cxobj **xret,
@ -1085,6 +1138,8 @@ netconf_missing_choice_xml(cxobj **xret,
* @param[out] xret Error XML tree
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
* @code
* cxobj *xret = NULL;
* if (netconf_operation_not_supported_xml(&xret, "protocol", "Unauthorized") < 0)
@ -1142,6 +1197,8 @@ netconf_operation_not_supported_xml(cxobj **xret,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "application" or "protocol"
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_operation_not_supported(cbuf *cb,
@ -1169,6 +1226,8 @@ netconf_operation_not_supported(cbuf *cb,
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
* @see netconf_operation_failed_xml Same but returns XML tree
*/
int
@ -1197,6 +1256,8 @@ netconf_operation_failed(cbuf *cb,
* @param[out] xret Error XML tree
* @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
* @code
* cxobj *xret = NULL;
* if (netconf_operation_failed_xml(&xret, "protocol", "Unauthorized") < 0)
@ -1254,6 +1315,8 @@ netconf_operation_failed_xml(cxobj **xret,
* invalid character set.
* @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] message Error message
* @retval 0 OK
* @retval -1 Error
* @note New in :base:1.1
* @see netconf_malformed_message_xml Same but returns XML tree
*/
@ -1282,6 +1345,8 @@ netconf_malformed_message(cbuf *cb,
* invalid character set.
* @param[out] xret Error XML tree
* @param[in] message Error message (will be XML encoded)
* @retval 0 OK
* @retval -1 Error
* @note New in :base:1.1
* @code
* cxobj *xret = NULL;
@ -1338,6 +1403,8 @@ netconf_malformed_message_xml(cxobj **xret,
* @param[out] xret Error XML tree. Free with xml_free after use
* @param[in] x List element containing duplicate
* @param[in] cvk List of components in x that are non-unique
* @retval 0 OK
* @retval -1 Error
* @see RFC7950 Sec 15.1
* @see netconf_data_not_unique_xml Same but returns XML tree
*/
@ -1367,6 +1434,8 @@ netconf_data_not_unique(cbuf *cb,
* @param[out] xret Error XML tree. Free with xml_free after use
* @param[in] x List element containing duplicate
* @param[in] cvk List of components in x that are non-unique
* @retval 0 OK
* @retval -1 Error
* @see RFC7950 Sec 15.1
*/
int
@ -1437,6 +1506,8 @@ netconf_data_not_unique_xml(cxobj **xret,
* @param[in] xp XML parent node (for error)
* @param[in] name Name of list (for error)
* @param[in] max If set, return too-many, otherwise too-few
* @retval 0 OK
* @retval -1 Error
* @see RFC7950 Sec 15.1
*/
int
@ -1489,6 +1560,7 @@ netconf_minmax_elements_xml(cxobj **xret,
}
/*! Help function: merge - check yang - if error make netconf errmsg
*
* @param[in] x XML tree
* @param[in] yspec Yang spec
* @param[in,out] xret Existing XML tree, merge x into this
@ -1574,6 +1646,7 @@ netconf_module_features(clicon_handle h)
}
/*! Load generic yang specs, ie ietf netconf yang module and set enabled features
*
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
@ -1642,6 +1715,7 @@ netconf_module_load(clicon_handle h)
}
/*! Find some sub-child in netconf/xm request.
*
* Actually, find a child with a certain name and return its body
* @param[in] xn
* @param[in] name
@ -1674,6 +1748,7 @@ netconf_db_find(cxobj *xn,
}
/*! Generate netconf error msg to cbuf to use in string printout or logs
*
* @param[in] xerr Netconf error message on the level: <rpc-error>
* @param[in,out] cberr Translation from netconf err to cbuf.
* @retval 0 OK, with cberr set
@ -1830,9 +1905,12 @@ netconf_capabilites(clicon_handle h,
}
/*! Create Netconf server hello. Single cap and defer individual to querying modules
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cb Msg buffer
* @param[in] session_id Id of client session
* @retval 0 OK
* @retval -1 Error
* Lots of dependencies here. regarding the hello protocol.
* RFC6241 NETCONF Protocol says: (8.1)
* MUST send a <hello> element containing a list of that peer's capabilities
@ -1880,6 +1958,8 @@ netconf_hello_server(clicon_handle h,
* @param[in] xerr Netconf error xml tree on the form: <rpc-error>
* @param[in] format Format string
* @param[in] arg String argument to format (optional)
* @retval 0 OK
* @retval -1 Error
* @see netconf_err2cb
*/
int
@ -2022,6 +2102,7 @@ netconf_parse_uint32(char *name,
}
/*! Parse string into uint32 and return netconf bad-element msg on error xml variant
*
* @see netconf_parse_uint32_xml
*/
int
@ -2090,6 +2171,8 @@ netconf_message_id_next(clicon_handle h)
*
* @param[in] framing Netconf framing
* @param[in,out] cb Netconf packet (cligen buffer)
* @retval 0 OK
* @retval -1 Error
* XXX: copies body
*/
int
@ -2140,6 +2223,7 @@ netconf_framing_postamble(netconf_framing_type framing,
}
/*! Send netconf message from cbuf on socket
*
* @param[in] s
* @param[in] cb Cligen buffer that contains the XML message
* @param[in] msg Only for debug
@ -2156,7 +2240,7 @@ netconf_output(int s,
char *buf = cbuf_get(cb);
int len = cbuf_len(cb);
clicon_debug(CLIXON_DBG_MSG, "Send ext: %s", cbuf_get(cb));
clixon_debug(CLIXON_DBG_MSG, "Send ext: %s", cbuf_get(cb));
#if 0 // Extra sanity check for debugging
{
cxobj *xt = NULL;
@ -2170,7 +2254,7 @@ netconf_output(int s,
#endif
if (write(s, buf, len) < 0){
if (errno == EPIPE)
clicon_debug(1, "%s write err SIGPIPE", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s write err SIGPIPE", __FUNCTION__);
else
clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno));
goto done;
@ -2252,7 +2336,7 @@ netconf_input_chunked_framing(char ch,
{
int retval = 0;
clicon_debug(CLIXON_DBG_DETAIL, "%s ch:%c(%d) state:%d size:%zu", __FUNCTION__, ch, ch, *state, *size);
clixon_debug(CLIXON_DBG_DETAIL, "%s ch:%c(%d) state:%d size:%zu", __FUNCTION__, ch, ch, *state, *size);
switch (*state){
case 0:
if (ch == '\n'){

View file

@ -99,7 +99,7 @@ per_datastore(clicon_handle h,
/*! Get netconf monitoring datastore state
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in,out] cb CLIgen buffer
* @retval 0 OK
@ -130,7 +130,7 @@ netconf_monitoring_datastores(clicon_handle h,
/*! Get netconf monitoring schema state
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in,out] cb CLIgen buffer
* @retval 0 OK
@ -181,7 +181,7 @@ netconf_monitoring_schemas(clicon_handle h,
/*! Get netconf monitoring statistics state
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in,out] cb CLIgen buffer
* @retval 0 OK
@ -230,7 +230,7 @@ netconf_monitoring_statistics(clicon_handle h,
*
* Netconf monitoring state is:
* capabilities, datastores, schemas, sessions, statistics
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] yspec Yang spec
* @param[in] xpath XML Xpath
* @param[in] nsc XML Namespace context for xpath
@ -276,7 +276,7 @@ netconf_monitoring_state_get(clicon_handle h,
}
retval = 1;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (cb)
cbuf_free(cb);
return retval;
@ -289,6 +289,8 @@ netconf_monitoring_state_get(clicon_handle h,
*
* @param[in] cvv Cligen vector
* @param[in] name Name of new counter
* @retval 0 OK
* @retval -1 Error
*/
static int
stat_counter_add(cvec *cvv,
@ -310,7 +312,9 @@ stat_counter_add(cvec *cvv,
/*! Init RFC6022 stats
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
int
netconf_monitoring_statistics_init(clicon_handle h)
@ -353,12 +357,12 @@ netconf_monitoring_statistics_init(clicon_handle h)
*
* @param[in] h Clixon handle
* @param[in] name Name of counter
* @retval 0 OK
*/
int
netconf_monitoring_counter_inc(clicon_handle h,
char *name)
{
int retval = -1;
cvec *cvv = NULL;
cg_var *cv;
uint32_t u32;
@ -370,6 +374,5 @@ netconf_monitoring_counter_inc(clicon_handle h,
cv_uint32_set(cv, u32);
}
}
retval = 0;
return retval;
return 0;
}

View file

@ -109,12 +109,15 @@ get_sock(int usock,
#endif /* HAVE_SETNS */
/*! Create and bind stream socket
*
* @param[in] sa Socketaddress
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
* @param[in] backlog Listen backlog, queie of pending connections
* @param[in] flags Socket flags Or:ed in with the socket(2) type parameter
* @param[in] addrstr Address string for debug
* @param[out] sock Server socket (bound for accept)
* @retval 0 OK
* @retval -1 Error
*/
static int
create_socket(struct sockaddr *sa,
@ -128,7 +131,7 @@ create_socket(struct sockaddr *sa,
int s = -1;
int on = 1;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (sock == NULL){
clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
goto done;
@ -182,7 +185,7 @@ create_socket(struct sockaddr *sa,
*sock = s;
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
if (retval != 0 && s != -1)
close(s);
return retval;
@ -198,6 +201,8 @@ create_socket(struct sockaddr *sa,
* @param[in] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[in] addrstr Address string for debug
* @param[out] sock Server socket (bound for accept)
* @retval 0 OK
* @retval -1 Error
*/
static int
fork_netns_socket(const char *netns,
@ -221,7 +226,7 @@ fork_netns_socket(const char *netns,
int sock_flags = SOCK_DGRAM | SOCK_CLOEXEC;
#endif
clicon_debug(1, "%s %s", __FUNCTION__, netns);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, netns);
if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){
clicon_err(OE_UNIX, errno, "socketpair");
goto done;
@ -288,19 +293,20 @@ fork_netns_socket(const char *netns,
if(waitpid(child, &wstatus, 0) == child)
; // retval = WEXITSTATUS(status); /* Dont know what to do with status */
if (WEXITSTATUS(wstatus)){
clicon_debug(1, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus));
clixon_debug(CLIXON_DBG_DEFAULT, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus));
*sock = -1;
clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
goto done;
}
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}
#endif /* HAVE_SETNS */
/*! Create and bind stream socket in network namespace
*
* @param[in] netns Network namespace
* @param[in] sa Socketaddress
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
@ -308,6 +314,8 @@ fork_netns_socket(const char *netns,
* @param[in] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[in] addrstr Address string for debug
* @param[out] sock Server socket (bound for accept)
* @retval 0 OK
* @retval -1 Error
*/
int
clixon_netns_socket(const char *netns,
@ -320,7 +328,7 @@ clixon_netns_socket(const char *netns,
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (netns == NULL){
if (create_socket(sa, sin_len, backlog, flags, addrstr, sock) < 0)
goto done;
@ -338,6 +346,6 @@ clixon_netns_socket(const char *netns,
ok:
retval = 0;
done:
clicon_debug(1, "%s %d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
return retval;
}

Some files were not shown because too many files have changed in this diff Show more