Restructured error,debug anf log API

Renamed functions clicon->clixon, replaced global variables w access functions
Unified clicon_netconf_error with clixon_err()
This commit is contained in:
Olof hagsand 2023-11-13 10:12:52 +01:00
parent 261469be16
commit 24a4991ec8
199 changed files with 4668 additions and 4158 deletions

View file

@ -23,6 +23,39 @@ Expected: February 2024
* Added reference count for shared yang-specs (schema mounts) * Added reference count for shared yang-specs (schema mounts)
* Allowed for sharing yspec+modules between several mountpoints * Allowed for sharing yspec+modules between several mountpoints
### C/CLI-API changes on existing features
Developers may need to change their code
* Refactoring basic clixon modules and some API changes
* Changes marked in code with `COMPAT_6_5`
* Most common functions have backward compatible macros through the 6.6 release
* Handle API
* Renamed `clicon_handle` -> `clixon_handle`
* `clicon_handle_init()` -> `clixon_handle_init()
* `clicon_handle_exit()` -> `clixon_handle_exit()
* Log/Debug API
* Changed function names. You need to rename as follows:
* `clicon_log_init()` -> `clixon_log_init(h,)` NOTE added "clixon_handle h"
* `clicon_log()` -> `clixon_log(h,)` NOTE added "clixon_handle h"
* `clixon_debug_init(d, f)` -> `clixon_debug_init(h, )` NOTE h added, f removed
* `clicon_log_xml()` -> `clixon_debug_xml(h,)` NOTE added "clixon_handle h"
* `clixon_debug_xml()` -> `clixon_debug_xml(h,)` NOTE added "clixon_handle h"
* Error API:
* Added `clixon_err_init(h)` function
* Renaming, make the following changes:
* `clicon_err()` -> `clixon_err()`
* `clicon_err_reset()` -> `clixon_err_reset()`
* `clicon_strerror(int)` -> `clixon_err_str()`
* `clicon_netconf_error(h, x, fmt)` -> clixon_err_netconf(h, OE_XML, 0, x, fmt)`
* `netconf_err2cb(...)` --> `netconf_err2cb(h, ...)`
* Likewise for some other minor functions: `clicon_err_*` -> `clixon_err_*`
* Replaced global variables with access functions. Replace variables with functions as follows:
* `clicon_errno` -> `clixon_err_category()`
* `clicon_suberrno` -> `clixon_err_subnr()`
* `clicon_err_reason` -> `clixon_err_reason()`
* Changed process API:
* `clixon_proc_socket(...)` --> `clixon_proc_socket(h, ...)`
### Corrected Bugs ### Corrected Bugs
* Fixed: [Using the characters '<' and '>' might cause an invalid diff](https://github.com/clicon/clixon-controller/issues/73) * Fixed: [Using the characters '<' and '>' might cause an invalid diff](https://github.com/clicon/clixon-controller/issues/73)

View file

@ -51,7 +51,7 @@ is identified, exit as soon as possible and with an explicit error log.
Errors are typically declared as follows: Errors are typically declared as follows:
``` ```
if (myfn(0) < 0){ if (myfn(0) < 0){
clicon_err(OE_UNIX, EINVAL, "myfn"); clixon_err(OE_UNIX, EINVAL, "myfn");
goto done; goto done;
} }
``` ```

View file

@ -62,7 +62,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_client.h" #include "clixon_backend_client.h"
@ -105,11 +105,11 @@ ce_client_descr(struct client_entry *ce,
char *id = NULL; char *id = NULL;
if (ce == NULL || cbp == NULL){ if (ce == NULL || cbp == NULL){
clicon_err(OE_UNIX, EINVAL, "ce or cbp is NULL"); clixon_err(OE_UNIX, EINVAL, "ce or cbp is NULL");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (ce->ce_transport){ if (ce->ce_transport){
@ -137,7 +137,7 @@ ce_client_descr(struct client_entry *ce,
* @see stream_ss_add * @see stream_ss_add
*/ */
int int
ce_event_cb(clicon_handle h, ce_event_cb(clixon_handle h,
int op, int op,
cxobj *event, cxobj *event,
void *arg) void *arg)
@ -158,7 +158,7 @@ ce_event_cb(clicon_handle h,
goto done; goto done;
if (send_msg_notify_xml(h, ce->ce_s, cbuf_get(cbce), event) < 0){ if (send_msg_notify_xml(h, ce->ce_s, cbuf_get(cbce), event) < 0){
if (errno == ECONNRESET || errno == EPIPE){ if (errno == ECONNRESET || errno == EPIPE){
clicon_log(LOG_WARNING, "client %d reset", ce->ce_nr); clixon_log(h, LOG_WARNING, "client %d reset", ce->ce_nr);
} }
break; break;
} }
@ -179,7 +179,7 @@ ce_event_cb(clicon_handle h,
* @see xmldb_unlock_all unlocks, but does not call user callbacks which is a backend thing * @see xmldb_unlock_all unlocks, but does not call user callbacks which is a backend thing
*/ */
static int static int
release_all_dbs(clicon_handle h, release_all_dbs(clixon_handle h,
uint32_t id) uint32_t id)
{ {
int retval = -1; int retval = -1;
@ -224,7 +224,7 @@ release_all_dbs(clicon_handle h,
* @see RFC 6022 * @see RFC 6022
*/ */
int int
backend_monitoring_state_get(clicon_handle h, backend_monitoring_state_get(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
char *xpath, char *xpath,
cvec *nsc, cvec *nsc,
@ -238,7 +238,7 @@ backend_monitoring_state_get(clicon_handle h,
int ret; int ret;
if ((cb = cbuf_new()) ==NULL){ if ((cb = cbuf_new()) ==NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<netconf-state xmlns=\"%s\">", NETCONF_MONITORING_NAMESPACE); cprintf(cb, "<netconf-state xmlns=\"%s\">", NETCONF_MONITORING_NAMESPACE);
@ -248,7 +248,7 @@ backend_monitoring_state_get(clicon_handle h,
cprintf(cb, "<session-id>%u</session-id>", ce->ce_id); cprintf(cb, "<session-id>%u</session-id>", ce->ce_id);
if (ce->ce_transport == NULL){ if (ce->ce_transport == NULL){
#ifdef NOTYET // XXX: too strict, race conditions in clixon_snmp #ifdef NOTYET // XXX: too strict, race conditions in clixon_snmp
clicon_err(OE_XML, 0, "Mandatory element transport missing"); clixon_err(OE_XML, 0, "Mandatory element transport missing");
goto done; goto done;
#else #else
cprintf(cb, "<transport xmlns:%s=\"%s\">cl:netconf</transport>", cprintf(cb, "<transport xmlns:%s=\"%s\">cl:netconf</transport>",
@ -264,7 +264,7 @@ backend_monitoring_state_get(clicon_handle h,
cprintf(cb, "<source-host>%s</source-host>", ce->ce_source_host); cprintf(cb, "<source-host>%s</source-host>", ce->ce_source_host);
if (ce->ce_time.tv_sec != 0){ if (ce->ce_time.tv_sec != 0){
if (time2str(&ce->ce_time, timestr, sizeof(timestr)) < 0){ if (time2str(&ce->ce_time, timestr, sizeof(timestr)) < 0){
clicon_err(OE_UNIX, errno, "time2str"); clixon_err(OE_UNIX, errno, "time2str");
goto done; goto done;
} }
cprintf(cb, "<login-time>%s</login-time>", timestr); cprintf(cb, "<login-time>%s</login-time>", timestr);
@ -304,7 +304,7 @@ backend_monitoring_state_get(clicon_handle h,
* @see backend_client_delete for actual deallocation of client entry struct * @see backend_client_delete for actual deallocation of client entry struct
*/ */
int int
backend_client_rm(clicon_handle h, backend_client_rm(clixon_handle h,
struct client_entry *ce) struct client_entry *ce)
{ {
struct client_entry *c; struct client_entry *c;
@ -316,7 +316,7 @@ backend_client_rm(clicon_handle h,
/* If the confirmed-commit feature is enabled, rollback any ephemeral commit originated by this client */ /* If the confirmed-commit feature is enabled, rollback any ephemeral commit originated by this client */
if ((yspec = clicon_dbspec_yang(h)) == NULL) { if ((yspec = clicon_dbspec_yang(h)) == NULL) {
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
@ -326,7 +326,7 @@ backend_client_rm(clicon_handle h,
if (myid == confirmed_commit_session_id_get(h)) { if (myid == confirmed_commit_session_id_get(h)) {
clixon_debug(CLIXON_DBG_DEFAULT, "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"); clixon_log(h, 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 /* do_rollback errors are logged internally and there is no client to report errors to, so errors are
* ignored here. * ignored here.
@ -369,7 +369,7 @@ backend_client_rm(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
clixon_stats_datastore_get(clicon_handle h, clixon_stats_datastore_get(clixon_handle h,
char *dbname, char *dbname,
cbuf *cb) cbuf *cb)
{ {
@ -412,7 +412,7 @@ clixon_stats_datastore_get(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
clixon_stats_module_get(clicon_handle h, clixon_stats_module_get(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
cbuf *cb) cbuf *cb)
{ {
@ -452,7 +452,7 @@ clixon_stats_module_get(clicon_handle h,
* But this could discard other previous changes to candidate. * But this could discard other previous changes to candidate.
*/ */
static int static int
from_client_edit_config(clicon_handle h, from_client_edit_config(clixon_handle h,
cxobj *xn, cxobj *xn,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -480,7 +480,7 @@ from_client_edit_config(clicon_handle h,
username = clicon_username_get(h); username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec9"); clixon_err(OE_YANG, ENOENT, "No yang spec9");
goto done; goto done;
} }
if ((target = netconf_db_find(xn, "target")) == NULL){ if ((target = netconf_db_find(xn, "target")) == NULL){
@ -489,7 +489,7 @@ from_client_edit_config(clicon_handle h,
goto ok; goto ok;
} }
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* Check if target locked by other client */ /* Check if target locked by other client */
@ -572,7 +572,7 @@ from_client_edit_config(clicon_handle h,
if (xml_sort_recurse(xc) < 0) if (xml_sort_recurse(xc) < 0)
goto done; goto done;
if ((ret = xmldb_put(h, target, operation, xc, username, cbret)) < 0){ if ((ret = xmldb_put(h, target, operation, xc, username, cbret)) < 0){
if (netconf_operation_failed(cbret, "protocol", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "protocol", clixon_err_reason())< 0)
goto done; goto done;
goto ok; goto ok;
} }
@ -614,14 +614,14 @@ from_client_edit_config(clicon_handle h,
} }
} }
if ((ret = candidate_commit(h, NULL, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */ if ((ret = candidate_commit(h, NULL, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
xmldb_copy(h, "running", "candidate"); xmldb_copy(h, "running", "candidate");
goto ok; goto ok;
} }
if (ret == 0){ /* discard */ if (ret == 0){ /* discard */
if (xmldb_copy(h, "running", "candidate") < 0){ if (xmldb_copy(h, "running", "candidate") < 0){
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
goto ok; goto ok;
} }
@ -632,13 +632,13 @@ from_client_edit_config(clicon_handle h,
if ((attr = xml_find_value(xn, "copystartup")) != NULL && if ((attr = xml_find_value(xn, "copystartup")) != NULL &&
strcmp(attr,"true") == 0){ strcmp(attr,"true") == 0){
if (xmldb_copy(h, "running", "startup") < 0){ if (xmldb_copy(h, "running", "startup") < 0){
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
goto ok; goto ok;
} }
} }
if (cbuf_len(cbret) != 0){ if (cbuf_len(cbret) != 0){
clicon_err(OE_NETCONF, EINVAL, "Internal error: cbret is not empty"); clixon_err(OE_NETCONF, EINVAL, "Internal error: cbret is not empty");
goto done; goto done;
} }
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok", NETCONF_BASE_NAMESPACE); cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok", NETCONF_BASE_NAMESPACE);
@ -675,7 +675,7 @@ from_client_edit_config(clicon_handle h,
* - access denied if user lacks create/delete/update * - access denied if user lacks create/delete/update
*/ */
static int static int
from_client_copy_config(clicon_handle h, from_client_copy_config(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -696,7 +696,7 @@ from_client_copy_config(clicon_handle h,
goto ok; goto ok;
} }
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if ((target = netconf_db_find(xe, "target")) == NULL){ if ((target = netconf_db_find(xe, "target")) == NULL){
@ -714,10 +714,10 @@ from_client_copy_config(clicon_handle h,
} }
if (xmldb_copy(h, source, target) < 0){ if (xmldb_copy(h, source, target) < 0){
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Copy %s datastore to %s: %s", source, target, clicon_err_reason); cprintf(cbmsg, "Copy %s datastore to %s: %s", source, target, clixon_err_reason());
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg))< 0) if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg))< 0)
goto done; goto done;
goto ok; goto ok;
@ -745,7 +745,7 @@ from_client_copy_config(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_delete_config(clicon_handle h, from_client_delete_config(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -767,7 +767,7 @@ from_client_delete_config(clicon_handle h,
goto ok; goto ok;
} }
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* Check if target locked by other client */ /* Check if target locked by other client */
@ -780,20 +780,20 @@ from_client_delete_config(clicon_handle h,
} }
if (xmldb_delete(h, target) < 0){ if (xmldb_delete(h, target) < 0){
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Delete %s datastore: %s", target, clicon_err_reason); cprintf(cbmsg, "Delete %s datastore: %s", target, clixon_err_reason());
if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0) if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0)
goto done; goto done;
goto ok; goto ok;
} }
if (xmldb_create(h, target) < 0){ if (xmldb_create(h, target) < 0){
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Create %s datastore: %s", target, clicon_err_reason); cprintf(cbmsg, "Create %s datastore: %s", target, clixon_err_reason());
if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0) if (netconf_operation_failed(cbret, "protocol", cbuf_get(cbmsg))< 0)
goto done; goto done;
goto ok; goto ok;
@ -821,7 +821,7 @@ from_client_delete_config(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_lock(clicon_handle h, from_client_lock(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -837,7 +837,7 @@ from_client_lock(clicon_handle h,
yang_stmt *yspec; yang_stmt *yspec;
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
if ((db = netconf_db_find(xe, "target")) == NULL){ if ((db = netconf_db_find(xe, "target")) == NULL){
@ -846,7 +846,7 @@ from_client_lock(clicon_handle h,
goto ok; goto ok;
} }
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* /*
@ -908,7 +908,7 @@ from_client_lock(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_unlock(clicon_handle h, from_client_unlock(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -927,7 +927,7 @@ from_client_unlock(clicon_handle h,
goto ok; goto ok;
} }
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
iddb = xmldb_islocked(h, db); iddb = xmldb_islocked(h, db);
@ -978,7 +978,7 @@ from_client_unlock(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_close_session(clicon_handle h, from_client_close_session(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1005,7 +1005,7 @@ from_client_close_session(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_kill_session(clicon_handle h, from_client_kill_session(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1070,7 +1070,7 @@ from_client_kill_session(clicon_handle h,
* </create-subscription> * </create-subscription>
*/ */
static int static int
from_client_create_subscription(clicon_handle h, from_client_create_subscription(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1163,7 +1163,7 @@ from_client_create_subscription(clicon_handle h,
* @see RFC6022, ietf-netconf-monitoring.yang * @see RFC6022, ietf-netconf-monitoring.yang
*/ */
static int static int
from_client_get_schema(clicon_handle h, from_client_get_schema(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1184,7 +1184,7 @@ from_client_get_schema(clicon_handle h,
const char *filename; const char *filename;
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
if ((nsc = xml_nsctx_init(NULL, NETCONF_MONITORING_NAMESPACE)) == NULL) if ((nsc = xml_nsctx_init(NULL, NETCONF_MONITORING_NAMESPACE)) == NULL)
@ -1229,7 +1229,7 @@ from_client_get_schema(clicon_handle h,
} }
if (ymatch == NULL){ if (ymatch == NULL){
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (version) if (version)
@ -1242,7 +1242,7 @@ from_client_get_schema(clicon_handle h,
} }
if (format && strcmp(format, "yang") != 0){ if (format && strcmp(format, "yang") != 0){
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Format not supported: %s", format); cprintf(cbmsg, "Format not supported: %s", format);
@ -1253,7 +1253,7 @@ from_client_get_schema(clicon_handle h,
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><data xmlns=\"%s\">", cprintf(cbret, "<rpc-reply xmlns=\"%s\"><data xmlns=\"%s\">",
NETCONF_BASE_NAMESPACE, NETCONF_MONITORING_NAMESPACE); NETCONF_BASE_NAMESPACE, NETCONF_MONITORING_NAMESPACE);
if ((cbyang = cbuf_new()) == NULL){ if ((cbyang = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((filename = yang_filename_get(ymatch)) != NULL){ if ((filename = yang_filename_get(ymatch)) != NULL){
@ -1285,7 +1285,7 @@ from_client_get_schema(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_debug(clicon_handle h, from_client_debug(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1302,9 +1302,9 @@ from_client_debug(clicon_handle h,
} }
level = atoi(valstr); level = atoi(valstr);
clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ clixon_debug_init(h, level); /* 0: dont debug, 1:debug */
setlogmask(LOG_UPTO(level?LOG_DEBUG:LOG_INFO)); /* for syslog */ setlogmask(LOG_UPTO(level?LOG_DEBUG:LOG_INFO)); /* for syslog */
clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, clixon_debug_get()); clixon_log(h, LOG_NOTICE, "%s debug:%d", __FUNCTION__, clixon_debug_get());
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE); cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
ok: ok:
retval = 0; retval = 0;
@ -1323,7 +1323,7 @@ from_client_debug(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_ping(clicon_handle h, from_client_ping(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1344,7 +1344,7 @@ from_client_ping(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_stats(clicon_handle h, from_client_stats(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1437,7 +1437,7 @@ from_client_stats(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_restart_plugin(clicon_handle h, from_client_restart_plugin(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1485,7 +1485,7 @@ from_client_restart_plugin(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_process_control(clicon_handle h, from_client_process_control(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1529,7 +1529,7 @@ from_client_process_control(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
from_client_hello(clicon_handle h, from_client_hello(clixon_handle h,
cxobj *x, cxobj *x,
struct client_entry *ce, struct client_entry *ce,
cbuf *cbret) cbuf *cbret)
@ -1539,13 +1539,13 @@ from_client_hello(clicon_handle h,
if ((val = xml_find_type_value(x, "cl", "transport", CX_ATTR)) != NULL){ if ((val = xml_find_type_value(x, "cl", "transport", CX_ATTR)) != NULL){
if ((ce->ce_transport = strdup(val)) == NULL){ if ((ce->ce_transport = strdup(val)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
if ((val = xml_find_type_value(x, "cl", "source-host", CX_ATTR)) != NULL){ if ((val = xml_find_type_value(x, "cl", "source-host", CX_ATTR)) != NULL){
if ((ce->ce_source_host = strdup(val)) == NULL){ if ((ce->ce_source_host = strdup(val)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -1566,7 +1566,7 @@ from_client_hello(clicon_handle h,
* propagated back to client. * propagated back to client.
*/ */
static int static int
from_client_msg(clicon_handle h, from_client_msg(clixon_handle h,
struct client_entry *ce, struct client_entry *ce,
struct clicon_msg *msg) struct clicon_msg *msg)
{ {
@ -1598,7 +1598,7 @@ from_client_msg(clicon_handle h,
* as wither rpc-error or by positive response. * as wither rpc-error or by positive response.
*/ */
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* Decode msg from client -> xml top (ct) and session id /* Decode msg from client -> xml top (ct) and session id
@ -1627,7 +1627,7 @@ from_client_msg(clicon_handle h,
goto reply; goto reply;
} }
if ((x = xml_child_i_type(xt, 0, CX_ELMNT)) == NULL){ /* Shouldnt happen */ if ((x = xml_child_i_type(xt, 0, CX_ELMNT)) == NULL){ /* Shouldnt happen */
clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)"); clixon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)");
goto done; goto done;
} }
rpcname = xml_name(x); rpcname = xml_name(x);
@ -1647,7 +1647,7 @@ from_client_msg(clicon_handle h,
(ce0 = ce_find_byid(backend_client_list(h), op_id)) != NULL && (ce0 = ce_find_byid(backend_client_list(h), op_id)) != NULL &&
ce0->ce_transport){ ce0->ce_transport){
if ((ce->ce_transport = strdup(ce0->ce_transport)) == NULL){ if ((ce->ce_transport = strdup(ce0->ce_transport)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -1665,7 +1665,7 @@ from_client_msg(clicon_handle h,
else if (strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){ else if (strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
cbuf *cbmsg = NULL; cbuf *cbmsg = NULL;
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "No appropriate namespace found for: %s %s", rpcprefix, rpcname); cprintf(cbmsg, "No appropriate namespace found for: %s %s", rpcprefix, rpcname);
@ -1724,7 +1724,7 @@ from_client_msg(clicon_handle h,
goto reply; goto reply;
} }
if ((ymod = ys_module(ye)) == NULL){ if ((ymod = ys_module(ye)) == NULL){
clicon_err(OE_XML, ENOENT, "rpc yang does not have module"); clixon_err(OE_XML, ENOENT, "rpc yang does not have module");
goto done; goto done;
} }
module = yang_argument_get(ymod); module = yang_argument_get(ymod);
@ -1762,11 +1762,11 @@ from_client_msg(clicon_handle h,
goto reply; goto reply;
} }
} }
clicon_err_reset(); clixon_err_reset();
if ((ret = rpc_callback_call(h, xe, ce, &nr, cbret)) < 0){ if ((ret = rpc_callback_call(h, xe, ce, &nr, cbret)) < 0){
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
clicon_log(LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe)); clixon_log(h, LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe));
ce->ce_out_rpc_errors++; ce->ce_out_rpc_errors++;
netconf_monitoring_counter_inc(h, "out-rpc-errors"); netconf_monitoring_counter_inc(h, "out-rpc-errors");
goto reply; /* Dont quit here on user callbacks */ goto reply; /* Dont quit here on user callbacks */
@ -1792,7 +1792,8 @@ from_client_msg(clicon_handle h,
} /* while */ } /* while */
reply: reply:
if (cbuf_len(cbret) == 0) if (cbuf_len(cbret) == 0)
if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0) if (netconf_operation_failed(cbret, "application",
clixon_err_category()?clixon_err_reason():"unknown")< 0)
goto done; goto done;
// XXX clixon_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 /* XXX problem here is that cbret has not been parsed so may contain
@ -1810,7 +1811,7 @@ from_client_msg(clicon_handle h,
* the (UNIX domain) socket. * the (UNIX domain) socket.
*/ */
case ECONNRESET: case ECONNRESET:
clicon_log(LOG_WARNING, "client rpc reset"); clixon_log(h, LOG_WARNING, "client rpc reset");
break; break;
default: default:
goto done; goto done;
@ -1833,9 +1834,9 @@ from_client_msg(clicon_handle h,
cbuf_free(cbce); cbuf_free(cbce);
if (cbret) if (cbret)
cbuf_free(cbret); cbuf_free(cbret);
/* Sanity: log if clicon_err() is not called ! */ /* Sanity: log if clixon_err() is not called ! */
if (retval < 0 && clicon_errno < 0) if (retval < 0 && clixon_err_category() < 0)
clicon_log(LOG_NOTICE, "%s: Internal error: No clicon_err call on RPC error (message: %s)", clixon_log(h, LOG_NOTICE, "%s: Internal error: No clixon_err call on RPC error (message: %s)",
__FUNCTION__, rpc?rpc:""); __FUNCTION__, rpc?rpc:"");
// clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); // clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
return retval;// -1 here terminates backend return retval;// -1 here terminates backend
@ -1856,13 +1857,13 @@ from_client(int s,
int retval = -1; int retval = -1;
struct clicon_msg *msg = NULL; struct clicon_msg *msg = NULL;
struct client_entry *ce = (struct client_entry *)arg; struct client_entry *ce = (struct client_entry *)arg;
clicon_handle h = ce->ce_handle; clixon_handle h = ce->ce_handle;
int eof = 0; int eof = 0;
cbuf *cbce = NULL; cbuf *cbce = NULL;
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (s != ce->ce_s){ if (s != ce->ce_s){
clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s"); clixon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s");
goto done; goto done;
} }
if (ce_client_descr(ce, &cbce) < 0) if (ce_client_descr(ce, &cbce) < 0)
@ -1894,7 +1895,7 @@ from_client(int s,
* @see ietf-netconf@2011-06-01.yang * @see ietf-netconf@2011-06-01.yang
*/ */
int int
backend_rpc_init(clicon_handle h) backend_rpc_init(clixon_handle h)
{ {
int retval = -1; int retval = -1;

View file

@ -40,9 +40,9 @@
/* /*
* Prototypes * Prototypes
*/ */
int backend_monitoring_state_get(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); int backend_monitoring_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
int backend_client_rm(clicon_handle h, struct client_entry *ce); int backend_client_rm(clixon_handle h, struct client_entry *ce);
int from_client(int fd, void *arg); int from_client(int fd, void *arg);
int backend_rpc_init(clicon_handle h); int backend_rpc_init(clixon_handle h);
#endif /* _BACKEND_CLIENT_H_ */ #endif /* _BACKEND_CLIENT_H_ */

View file

@ -62,7 +62,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -90,7 +90,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
generic_validate(clicon_handle h, generic_validate(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
transaction_data_t *td, transaction_data_t *td,
cxobj **xret) cxobj **xret)
@ -158,7 +158,7 @@ generic_validate(clicon_handle h,
* @see validate_common for incoming validate/commit * @see validate_common for incoming validate/commit
*/ */
static int static int
startup_common(clicon_handle h, startup_common(clixon_handle h,
char *db, char *db,
transaction_data_t *td, transaction_data_t *td,
cbuf *cbret) cbuf *cbret)
@ -189,7 +189,7 @@ startup_common(clicon_handle h,
/* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */ /* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */
if (clicon_quit_upgrade_get(h) == 1){ if (clicon_quit_upgrade_get(h) == 1){
xml_print(stderr, xerr); xml_print(stderr, xerr);
clicon_err(OE_XML, 0, "invalid configuration before upgrade"); clixon_err(OE_XML, 0, "invalid configuration before upgrade");
exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
* See similar clause below * See similar clause below
*/ */
@ -205,12 +205,12 @@ startup_common(clicon_handle h,
} }
clixon_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 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" clixon_log(h, 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" "This may indicate that the datastore is not initialized corrrectly, such as copy/pasted.\n"
"It may also be normal bootstrapping since module state will be written on next datastore save"); "It may also be normal bootstrapping since module state will be written on next datastore save");
} }
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, 0, "Yang spec not set"); clixon_err(OE_YANG, 0, "Yang spec not set");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "Reading startup config done"); clixon_debug(CLIXON_DBG_DEFAULT, "Reading startup config done");
@ -237,16 +237,16 @@ startup_common(clicon_handle h,
if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xret)) < 1){ if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xret)) < 1){
if (ret == 0){ if (ret == 0){
/* invalid */ /* invalid */
clicon_err(OE_XML, EFAULT, "invalid configuration"); clixon_err(OE_XML, EFAULT, "invalid configuration");
} }
else { else {
/* error */ /* error */
xml_print(stderr, xret); xml_print(stderr, xret);
clicon_err(OE_XML, 0, "%s: YANG binding error", __func__); clixon_err(OE_XML, 0, "%s: YANG binding error", __func__);
} }
} /* sort yang */ } /* sort yang */
else if (xml_sort_recurse(xt) < 0) { else if (xml_sort_recurse(xt) < 0) {
clicon_err(OE_XML, EFAULT, "Yang sort error"); clixon_err(OE_XML, EFAULT, "Yang sort error");
} }
if (xmldb_dump(h, stdout, xt) < 0) if (xmldb_dump(h, stdout, xt) < 0)
goto done; goto done;
@ -345,7 +345,7 @@ startup_common(clicon_handle h,
* @retval -1 Error - or validation failed (but cbret not set) * @retval -1 Error - or validation failed (but cbret not set)
*/ */
int int
startup_validate(clicon_handle h, startup_validate(clixon_handle h,
char *db, char *db,
cxobj **xtr, cxobj **xtr,
cbuf *cbret) cbuf *cbret)
@ -396,7 +396,7 @@ startup_validate(clicon_handle h,
* Only called from startup_mode_startup * Only called from startup_mode_startup
*/ */
int int
startup_commit(clicon_handle h, startup_commit(clixon_handle h,
char *db, char *db,
cbuf *cbret) cbuf *cbret)
{ {
@ -405,7 +405,7 @@ startup_commit(clicon_handle h,
transaction_data_t *td = NULL; transaction_data_t *td = NULL;
if (strcmp(db,"running")==0){ if (strcmp(db,"running")==0){
clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db); clixon_err(OE_FATAL, 0, "Invalid startup db: %s", db);
goto done; goto done;
} }
/* Handcraft a transition with only target and add trees */ /* Handcraft a transition with only target and add trees */
@ -479,7 +479,7 @@ startup_commit(clicon_handle h,
* @see startup_common for startup scenario * @see startup_common for startup scenario
*/ */
static int static int
validate_common(clicon_handle h, validate_common(clixon_handle h,
char *db, char *db,
transaction_data_t *td, transaction_data_t *td,
cxobj **xret) cxobj **xret)
@ -491,7 +491,7 @@ validate_common(clicon_handle h,
int ret; int ret;
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
/* This is the state we are going to */ /* This is the state we are going to */
@ -581,7 +581,7 @@ validate_common(clicon_handle h,
* @retval -1 Error - or validation failed * @retval -1 Error - or validation failed
*/ */
int int
candidate_validate(clicon_handle h, candidate_validate(clixon_handle h,
char *db, char *db,
cbuf *cbret) cbuf *cbret)
{ {
@ -592,7 +592,7 @@ candidate_validate(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (db == NULL || cbret == NULL){ if (db == NULL || cbret == NULL){
clicon_err(OE_CFG, EINVAL, "db or cbret is NULL"); clixon_err(OE_CFG, EINVAL, "db or cbret is NULL");
goto done; goto done;
} }
/* 1. Start transaction */ /* 1. Start transaction */
@ -602,23 +602,23 @@ candidate_validate(clicon_handle h,
if ((ret = validate_common(h, db, td, &xret)) < 0){ if ((ret = validate_common(h, db, td, &xret)) < 0){
/* A little complex due to several sources of validation fails or errors. /* A little complex due to several sources of validation fails or errors.
* (1) xerr is set -> translate to cbret; (2) cbret set use that; otherwise * (1) xerr is set -> translate to cbret; (2) cbret set use that; otherwise
* use clicon_err. * use clixon_err.
* TODO: -1 return should be fatal error, not failed validation * TODO: -1 return should be fatal error, not failed validation
*/ */
if (!cbuf_len(cbret) && if (!cbuf_len(cbret) &&
netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
goto fail; goto fail;
} }
if (ret == 0){ if (ret == 0){
if (xret == NULL){ if (xret == NULL){
clicon_err(OE_CFG, EINVAL, "xret is NULL"); clixon_err(OE_CFG, EINVAL, "xret is NULL");
goto done; goto done;
} }
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
goto done; goto done;
if (!cbuf_len(cbret) && if (!cbuf_len(cbret) &&
netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
goto fail; goto fail;
} }
@ -660,7 +660,7 @@ candidate_validate(clicon_handle h,
* @retval -1 Error - or validation failed * @retval -1 Error - or validation failed
*/ */
int int
candidate_commit(clicon_handle h, candidate_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
char *db, char *db,
uint32_t myid, uint32_t myid,
@ -694,7 +694,7 @@ candidate_commit(clicon_handle h,
* to activate it. * to activate it.
*/ */
if ((yspec = clicon_dbspec_yang(h)) == NULL) { if ((yspec = clicon_dbspec_yang(h)) == NULL) {
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
@ -786,7 +786,7 @@ candidate_commit(clicon_handle h,
* candidate_commit() method. * candidate_commit() method.
*/ */
int int
from_client_commit(clicon_handle h, from_client_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -801,7 +801,7 @@ from_client_commit(clicon_handle h,
yang_stmt *yspec; yang_stmt *yspec;
if ((yspec = clicon_dbspec_yang(h)) == NULL) { if ((yspec = clicon_dbspec_yang(h)) == NULL) {
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
@ -814,7 +814,7 @@ from_client_commit(clicon_handle h,
iddb = xmldb_islocked(h, "running"); iddb = xmldb_islocked(h, "running");
if (iddb && myid != iddb){ if (iddb && myid != iddb){
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (netconf_in_use(cbret, "protocol", "Operation failed, lock is already held") < 0) if (netconf_in_use(cbret, "protocol", "Operation failed, lock is already held") < 0)
@ -824,7 +824,7 @@ from_client_commit(clicon_handle h,
if ((ret = candidate_commit(h, xe, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */ if ((ret = candidate_commit(h, xe, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */
clixon_debug(CLIXON_DBG_DEFAULT, "Commit candidate failed"); clixon_debug(CLIXON_DBG_DEFAULT, "Commit candidate failed");
if (ret < 0) if (ret < 0)
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
goto ok; goto ok;
} }
@ -852,7 +852,7 @@ from_client_commit(clicon_handle h,
* NACM: No datastore permissions are needed. * NACM: No datastore permissions are needed.
*/ */
int int
from_client_discard_changes(clicon_handle h, from_client_discard_changes(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -868,7 +868,7 @@ from_client_discard_changes(clicon_handle h,
iddb = xmldb_islocked(h, "candidate"); iddb = xmldb_islocked(h, "candidate");
if (iddb && myid != iddb){ if (iddb && myid != iddb){
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbx, "<session-id>%u</session-id>", iddb); cprintf(cbx, "<session-id>%u</session-id>", iddb);
@ -877,7 +877,7 @@ from_client_discard_changes(clicon_handle h,
goto ok; goto ok;
} }
if (xmldb_copy(h, "running", "candidate") < 0){ if (xmldb_copy(h, "running", "candidate") < 0){
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0)
goto done; goto done;
goto ok; goto ok;
} }
@ -903,7 +903,7 @@ from_client_discard_changes(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
from_client_validate(clicon_handle h, from_client_validate(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -935,7 +935,7 @@ from_client_validate(clicon_handle h,
* difficult in the general case. * difficult in the general case.
*/ */
int int
from_client_restart_one(clicon_handle h, from_client_restart_one(clixon_handle h,
clixon_plugin_t *cp, clixon_plugin_t *cp,
cbuf *cbret) cbuf *cbret)
{ {
@ -1065,7 +1065,7 @@ running ----|-------+---------------> RUNNING FAILSAFE
tmp |----------------------> tmp |---------------------->
*/ */
int int
load_failsafe(clicon_handle h, load_failsafe(clixon_handle h,
char *phase) char *phase)
{ {
int retval = -1; int retval = -1;
@ -1076,13 +1076,13 @@ load_failsafe(clicon_handle h,
phase = phase == NULL ? "(unknown)" : phase; phase = phase == NULL ? "(unknown)" : phase;
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if ((ret = xmldb_exists(h, db)) < 0) if ((ret = xmldb_exists(h, db)) < 0)
goto done; goto done;
if (ret == 0){ /* No it does not exist, fail */ if (ret == 0){ /* No it does not exist, fail */
clicon_err(OE_DB, 0, "%s failed and no Failsafe database found, exiting", phase); clixon_err(OE_DB, 0, "%s failed and no Failsafe database found, exiting", phase);
goto done; goto done;
} }
/* Copy original running to tmp as backup (restore if error) */ /* Copy original running to tmp as backup (restore if error) */
@ -1097,10 +1097,10 @@ load_failsafe(clicon_handle h,
if (ret < 0) if (ret < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clicon_err(OE_DB, 0, "%s failed, Failsafe database validation failed %s", phase, cbuf_get(cbret)); clixon_err(OE_DB, 0, "%s failed, Failsafe database validation failed %s", phase, cbuf_get(cbret));
goto done; goto done;
} }
clicon_log(LOG_NOTICE, "%s failed, Failsafe database loaded ", phase); clixon_log(h, LOG_NOTICE, "%s failed, Failsafe database loaded ", phase);
retval = 0; retval = 0;
done: done:
if (cbret) if (cbret)

View file

@ -62,7 +62,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -83,17 +83,17 @@ struct confirmed_commit {
char *cc_persist_id; /* a value given by a client in the confirmed-commit */ char *cc_persist_id; /* a value given by a client in the confirmed-commit */
uint32_t cc_session_id; /* the session_id of the client that gave no <persist> value */ uint32_t cc_session_id; /* the session_id of the client that gave no <persist> value */
int (*cc_fn)(int, void*); /* function pointer for rollback event (rollback_fn()) */ int (*cc_fn)(int, void*); /* function pointer for rollback event (rollback_fn()) */
void *cc_arg; /* clicon_handle that will be passed to rollback_fn() */ void *cc_arg; /* clixon_handle that will be passed to rollback_fn() */
}; };
int int
confirmed_commit_init(clicon_handle h) confirmed_commit_init(clixon_handle h)
{ {
int retval = -1; int retval = -1;
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
if ((cc = calloc(1, sizeof(*cc))) == NULL){ if ((cc = calloc(1, sizeof(*cc))) == NULL){
clicon_err(OE_UNIX, errno, "calloc"); clixon_err(OE_UNIX, errno, "calloc");
goto done; goto done;
} }
cc->cc_state = INACTIVE; cc->cc_state = INACTIVE;
@ -110,7 +110,7 @@ confirmed_commit_init(clicon_handle h)
* @retval 0 OK * @retval 0 OK
*/ */
int int
confirmed_commit_free(clicon_handle h) confirmed_commit_free(clixon_handle h)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -128,7 +128,7 @@ confirmed_commit_free(clicon_handle h)
* Accessor functions * Accessor functions
*/ */
enum confirmed_commit_state enum confirmed_commit_state
confirmed_commit_state_get(clicon_handle h) confirmed_commit_state_get(clixon_handle h)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -137,7 +137,7 @@ confirmed_commit_state_get(clicon_handle h)
} }
static int static int
confirmed_commit_state_set(clicon_handle h, confirmed_commit_state_set(clixon_handle h,
enum confirmed_commit_state state) enum confirmed_commit_state state)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -148,7 +148,7 @@ confirmed_commit_state_set(clicon_handle h,
} }
char * char *
confirmed_commit_persist_id_get(clicon_handle h) confirmed_commit_persist_id_get(clixon_handle h)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -157,7 +157,7 @@ confirmed_commit_persist_id_get(clicon_handle h)
} }
static int static int
confirmed_commit_persist_id_set(clicon_handle h, confirmed_commit_persist_id_set(clixon_handle h,
char *persist_id) char *persist_id)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -167,7 +167,7 @@ confirmed_commit_persist_id_set(clicon_handle h,
free(cc->cc_persist_id); free(cc->cc_persist_id);
if (persist_id){ if (persist_id){
if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){ if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){
clicon_err(OE_UNIX, errno, "strdup4"); clixon_err(OE_UNIX, errno, "strdup4");
return -1; return -1;
} }
} }
@ -177,7 +177,7 @@ confirmed_commit_persist_id_set(clicon_handle h,
} }
uint32_t uint32_t
confirmed_commit_session_id_get(clicon_handle h) confirmed_commit_session_id_get(clixon_handle h)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -186,7 +186,7 @@ confirmed_commit_session_id_get(clicon_handle h)
} }
static int static int
confirmed_commit_session_id_set(clicon_handle h, confirmed_commit_session_id_set(clixon_handle h,
uint32_t session_id) uint32_t session_id)
{ {
struct confirmed_commit *cc = NULL; struct confirmed_commit *cc = NULL;
@ -197,7 +197,7 @@ confirmed_commit_session_id_set(clicon_handle h,
} }
static int static int
confirmed_commit_fn_arg_get(clicon_handle h, confirmed_commit_fn_arg_get(clixon_handle h,
int (**fn)(int, void*), int (**fn)(int, void*),
void **arg) void **arg)
{ {
@ -210,7 +210,7 @@ confirmed_commit_fn_arg_get(clicon_handle h,
} }
static int static int
confirmed_commit_fn_arg_set(clicon_handle h, confirmed_commit_fn_arg_set(clixon_handle h,
int (*fn)(int, void*), int (*fn)(int, void*),
void *arg) void *arg)
{ {
@ -300,7 +300,7 @@ xe_timeout(cxobj *xe)
* @retval -1 No Rollback event was found * @retval -1 No Rollback event was found
*/ */
int int
cancel_rollback_event(clicon_handle h) cancel_rollback_event(clixon_handle h)
{ {
int retval; int retval;
int (*fn)(int, void*) = NULL; int (*fn)(int, void*) = NULL;
@ -308,9 +308,9 @@ cancel_rollback_event(clicon_handle h)
confirmed_commit_fn_arg_get(h, &fn, &arg); confirmed_commit_fn_arg_get(h, &fn, &arg);
if ((retval = clixon_event_unreg_timeout(fn, arg)) == 0) { if ((retval = clixon_event_unreg_timeout(fn, arg)) == 0) {
clicon_log(LOG_INFO, "a scheduled rollback event has been cancelled"); clixon_log(h, LOG_INFO, "a scheduled rollback event has been cancelled");
} else { } else {
clicon_log(LOG_WARNING, "the specified scheduled rollback event was not found"); clixon_log(h, LOG_WARNING, "the specified scheduled rollback event was not found");
} }
return retval; return retval;
@ -319,7 +319,7 @@ cancel_rollback_event(clicon_handle h)
/*! Apply the rollback configuration upon expiration of the confirm-timeout /*! Apply the rollback configuration upon expiration of the confirm-timeout
* *
* @param[in] fd a dummy argument per the event callback semantics * @param[in] fd a dummy argument per the event callback semantics
* @param[in] arg a void pointer to a clicon_handle * @param[in] arg a void pointer to a clixon_handle
* @retval 0 the rollback was successful * @retval 0 the rollback was successful
* @retval -1 the rollback failed * @retval -1 the rollback failed
* @see do_rollback() * @see do_rollback()
@ -328,9 +328,9 @@ static int
rollback_fn(int fd, rollback_fn(int fd,
void *arg) void *arg)
{ {
clicon_handle h = arg; clixon_handle h = arg;
clicon_log(LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back"); clixon_log(NULL, LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back");
return do_rollback(h, NULL); return do_rollback(h, NULL);
} }
@ -344,7 +344,7 @@ rollback_fn(int fd,
* @retval -1 Rollback event was not scheduled * @retval -1 Rollback event was not scheduled
*/ */
static int static int
schedule_rollback_event(clicon_handle h, schedule_rollback_event(clixon_handle h,
uint32_t timeout) uint32_t timeout)
{ {
int retval = -1; int retval = -1;
@ -352,7 +352,7 @@ schedule_rollback_event(clicon_handle h,
// register a new scheduled event // register a new scheduled event
struct timeval t, t1; struct timeval t, t1;
if (gettimeofday(&t, NULL) < 0) { if (gettimeofday(&t, NULL) < 0) {
clicon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno)); clixon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno));
goto done; goto done;
}; };
t1.tv_sec = timeout; t1.tv_usec = 0; t1.tv_sec = timeout; t1.tv_usec = 0;
@ -383,7 +383,7 @@ schedule_rollback_event(clicon_handle h,
* @retval 0 OK * @retval 0 OK
*/ */
int int
cancel_confirmed_commit(clicon_handle h) cancel_confirmed_commit(clixon_handle h)
{ {
cancel_rollback_event(h); cancel_rollback_event(h);
@ -395,7 +395,7 @@ cancel_confirmed_commit(clicon_handle h)
confirmed_commit_state_set(h, INACTIVE); confirmed_commit_state_set(h, INACTIVE);
if (xmldb_delete(h, "rollback") < 0) if (xmldb_delete(h, "rollback") < 0)
clicon_err(OE_DB, 0, "Error deleting the rollback configuration"); clixon_err(OE_DB, 0, "Error deleting the rollback configuration");
return 0; return 0;
} }
@ -414,7 +414,7 @@ cancel_confirmed_commit(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
check_valid_confirming_commit(clicon_handle h, check_valid_confirming_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
uint32_t myid) uint32_t myid)
{ {
@ -422,7 +422,7 @@ check_valid_confirming_commit(clicon_handle h,
char *persist_id = NULL; char *persist_id = NULL;
if (xe == NULL){ if (xe == NULL){
clicon_err(OE_CFG, EINVAL, "xe is NULL"); clixon_err(OE_CFG, EINVAL, "xe is NULL");
goto done; goto done;
} }
if (myid == 0) if (myid == 0)
@ -435,13 +435,13 @@ check_valid_confirming_commit(clicon_handle h,
break; // valid break; // valid
} }
else { else {
clicon_log(LOG_INFO, clixon_log(h, LOG_INFO,
"a persistent confirmed-commit is in progress but the client issued a " "a persistent confirmed-commit is in progress but the client issued a "
"confirming-commit with an incorrect persist-id"); "confirming-commit with an incorrect persist-id");
goto invalid; goto invalid;
} }
} else { } else {
clicon_log(LOG_INFO, clixon_log(h, LOG_INFO,
"a persistent confirmed-commit is in progress but the client issued a confirming-commit" "a persistent confirmed-commit is in progress but the client issued a confirming-commit"
"without a persist-id"); "without a persist-id");
goto invalid; goto invalid;
@ -453,7 +453,7 @@ check_valid_confirming_commit(clicon_handle h,
*/ */
break; // valid break; // valid
} }
clicon_log(LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was" clixon_log(h, LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was"
"not issued on the same session as the confirmed-commit"); "not issued on the same session as the confirmed-commit");
goto invalid; goto invalid;
default: default:
@ -485,7 +485,7 @@ check_valid_confirming_commit(clicon_handle h,
* actually occur, and if so, if they are correctly handled. The calls are from do_rollback() and load_failsafe() * actually occur, and if so, if they are correctly handled. The calls are from do_rollback() and load_failsafe()
*/ */
int int
handle_confirmed_commit(clicon_handle h, handle_confirmed_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
uint32_t myid) uint32_t myid)
{ {
@ -496,7 +496,7 @@ handle_confirmed_commit(clicon_handle h,
int db_exists; int db_exists;
if (xe == NULL){ if (xe == NULL){
clicon_err(OE_CFG, EINVAL, "xe is NULL"); clixon_err(OE_CFG, EINVAL, "xe is NULL");
goto done; goto done;
} }
if (myid == 0) if (myid == 0)
@ -509,7 +509,7 @@ handle_confirmed_commit(clicon_handle h,
cc_valid = check_valid_confirming_commit(h, xe, myid); cc_valid = check_valid_confirming_commit(h, xe, myid);
if (cc_valid) { if (cc_valid) {
if (cancel_rollback_event(h) < 0) { if (cancel_rollback_event(h) < 0) {
clicon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found"); clixon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found");
} }
if (confirmed_commit_state_get(h) == PERSISTENT && if (confirmed_commit_state_get(h) == PERSISTENT &&
@ -537,7 +537,7 @@ handle_confirmed_commit(clicon_handle h,
* <persist-id> * <persist-id>
*/ */
confirmed_commit_state_set(h, PERSISTENT); confirmed_commit_state_set(h, PERSISTENT);
clicon_log(LOG_INFO, clixon_log(h, LOG_INFO,
"a persistent confirmed-commit has been requested with persist id of '%s' and a timeout of %lu seconds", "a persistent confirmed-commit has been requested with persist id of '%s' and a timeout of %lu seconds",
confirmed_commit_persist_id_get(h), confirm_timeout); confirmed_commit_persist_id_get(h), confirm_timeout);
} }
@ -549,7 +549,7 @@ handle_confirmed_commit(clicon_handle h,
confirmed_commit_session_id_set(h, myid); confirmed_commit_session_id_set(h, myid);
confirmed_commit_state_set(h, EPHEMERAL); confirmed_commit_state_set(h, EPHEMERAL);
clicon_log(LOG_INFO, clixon_log(h, LOG_INFO,
"an ephemeral confirmed-commit has been requested by session-id %u and a timeout of %lu seconds", "an ephemeral confirmed-commit has been requested by session-id %u and a timeout of %lu seconds",
confirmed_commit_session_id_get(h), confirmed_commit_session_id_get(h),
confirm_timeout); confirm_timeout);
@ -586,18 +586,18 @@ handle_confirmed_commit(clicon_handle h,
db_exists = xmldb_exists(h, "rollback"); db_exists = xmldb_exists(h, "rollback");
if (db_exists == -1) { if (db_exists == -1) {
clicon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database"); clixon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database");
goto done; goto done;
} else if (db_exists == 0) { } else if (db_exists == 0) {
// db does not yet exists // db does not yet exists
if (xmldb_copy(h, "running", "rollback") < 0) { if (xmldb_copy(h, "running", "rollback") < 0) {
clicon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database."); clixon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database.");
goto done; goto done;
}; };
} }
if (schedule_rollback_event(h, confirm_timeout) < 0) { if (schedule_rollback_event(h, confirm_timeout) < 0) {
clicon_err(OE_DAEMON, 0, "the rollback event could not be scheduled"); clixon_err(OE_DAEMON, 0, "the rollback event could not be scheduled");
goto done; goto done;
}; };
@ -607,7 +607,7 @@ handle_confirmed_commit(clicon_handle h,
* The new configuration is already committed to running and the rollback database can now be deleted * The new configuration is already committed to running and the rollback database can now be deleted
*/ */
if (xmldb_delete(h, "rollback") < 0) { if (xmldb_delete(h, "rollback") < 0) {
clicon_err(OE_DB, 0, "Error deleting the rollback configuration"); clixon_err(OE_DB, 0, "Error deleting the rollback configuration");
goto done; goto done;
} }
} }
@ -635,7 +635,7 @@ handle_confirmed_commit(clicon_handle h,
* @see rollback_fn() * @see rollback_fn()
*/ */
int int
do_rollback(clicon_handle h, do_rollback(clixon_handle h,
uint8_t *errs) uint8_t *errs)
{ {
int retval = -1; int retval = -1;
@ -643,13 +643,13 @@ do_rollback(clicon_handle h,
cbuf *cbret; cbuf *cbret;
if ((cbret = cbuf_new()) == NULL) { if ((cbret = cbuf_new()) == NULL) {
clicon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno)); clixon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno));
/* the rollback_db won't be deleted, so one can try recovery by: /* the rollback_db won't be deleted, so one can try recovery by:
* load rollback running * load rollback running
* restart the backend, which will try to load the rollback_db, and delete it if successful * restart the backend, which will try to load the rollback_db, and delete it if successful
* (otherwise it will load the failsafe) * (otherwise it will load the failsafe)
*/ */
clicon_log(LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted."); clixon_log(h, LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted.");
errstate |= ROLLBACK_NOT_APPLIED | ROLLBACK_DB_NOT_DELETED; errstate |= ROLLBACK_NOT_APPLIED | ROLLBACK_DB_NOT_DELETED;
goto done; goto done;
} }
@ -663,19 +663,19 @@ do_rollback(clicon_handle h,
/* theoretically, this should never error, since the rollback database was previously active and therefore /* theoretically, this should never error, since the rollback database was previously active and therefore
* had itself been previously and successfully committed. * had itself been previously and successfully committed.
*/ */
clicon_log(LOG_CRIT, "An error occurred committing the rollback database."); clixon_log(h, LOG_CRIT, "An error occurred committing the rollback database.");
errstate |= ROLLBACK_NOT_APPLIED; errstate |= ROLLBACK_NOT_APPLIED;
/* Rename the errored rollback database */ /* Rename the errored rollback database */
if (xmldb_rename(h, "rollback", NULL, ".error") < 0) { if (xmldb_rename(h, "rollback", NULL, ".error") < 0) {
clicon_log(LOG_CRIT, "An error occurred renaming the rollback database."); clixon_log(h, LOG_CRIT, "An error occurred renaming the rollback database.");
errstate |= ROLLBACK_DB_NOT_DELETED; errstate |= ROLLBACK_DB_NOT_DELETED;
} }
/* Attempt to load the failsafe config */ /* Attempt to load the failsafe config */
if (load_failsafe(h, "Rollback") < 0) { if (load_failsafe(h, "Rollback") < 0) {
clicon_log(LOG_CRIT, "An error occurred committing the failsafe database. Exiting."); clixon_log(h, LOG_CRIT, "An error occurred committing the failsafe database. Exiting.");
/* Invoke our own signal handler to exit */ /* Invoke our own signal handler to exit */
raise(SIGINT); raise(SIGINT);
@ -688,7 +688,7 @@ do_rollback(clicon_handle h,
cbuf_free(cbret); cbuf_free(cbret);
if (xmldb_delete(h, "rollback") < 0) { if (xmldb_delete(h, "rollback") < 0) {
clicon_log(LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted."); clixon_log(h, LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted.");
errstate |= ROLLBACK_DB_NOT_DELETED; errstate |= ROLLBACK_DB_NOT_DELETED;
goto done; goto done;
}; };
@ -717,7 +717,7 @@ do_rollback(clicon_handle h,
* @see RFC 6241 Sec 8.4 * @see RFC 6241 Sec 8.4
*/ */
int int
from_client_cancel_commit(clicon_handle h, from_client_cancel_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -775,7 +775,7 @@ from_client_cancel_commit(clicon_handle h,
if (do_rollback(h, NULL) < 0) if (do_rollback(h, NULL) < 0)
goto done; goto done;
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE); cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
clicon_log(LOG_INFO, "a confirmed-commit has been cancelled by client request"); clixon_log(h, LOG_INFO, "a confirmed-commit has been cancelled by client request");
} }
retval = 0; retval = 0;
done: done:
@ -793,7 +793,7 @@ from_client_cancel_commit(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
from_client_confirmed_commit(clicon_handle h, from_client_confirmed_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
uint32_t myid, uint32_t myid,
cbuf *cbret) cbuf *cbret)

View file

@ -62,7 +62,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_client.h" #include "clixon_backend_client.h"
@ -85,7 +85,7 @@
* @see rfc8040 Sections 9.1 * @see rfc8040 Sections 9.1
*/ */
static int static int
restconf_client_get_capabilities(clicon_handle h, restconf_client_get_capabilities(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
char *xpath, char *xpath,
cxobj **xret) cxobj **xret)
@ -95,11 +95,11 @@ restconf_client_get_capabilities(clicon_handle h,
cbuf *cb = NULL; cbuf *cb = NULL;
if ((xrstate = xpath_first(*xret, NULL, "restconf-state")) == NULL){ if ((xrstate = xpath_first(*xret, NULL, "restconf-state")) == NULL){
clicon_err(OE_YANG, ENOENT, "restconf-state not found in config node"); clixon_err(OE_YANG, ENOENT, "restconf-state not found in config node");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<capabilities>"); cprintf(cb, "<capabilities>");
@ -129,7 +129,7 @@ restconf_client_get_capabilities(clicon_handle h,
* @retval -1 Error (fatal) * @retval -1 Error (fatal)
*/ */
static int static int
client_get_streams(clicon_handle h, client_get_streams(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
char *xpath, char *xpath,
yang_stmt *ymod, yang_stmt *ymod,
@ -143,11 +143,11 @@ client_get_streams(clicon_handle h,
int ret; int ret;
if ((yns = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){ if ((yns = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){
clicon_err(OE_YANG, 0, "%s yang namespace not found", yang_argument_get(ymod)); clixon_err(OE_YANG, 0, "%s yang namespace not found", yang_argument_get(ymod));
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<%s xmlns=\"%s\">", top, yang_argument_get(yns)); cprintf(cb, "<%s xmlns=\"%s\">", top, yang_argument_get(yns));
@ -159,7 +159,7 @@ client_get_streams(clicon_handle h,
cprintf(cb,"</%s>", top); cprintf(cb,"</%s>", top);
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){ if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){
if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0) if (xret && netconf_operation_failed_xml(xret, "protocol", clixon_err_reason())< 0)
goto done; goto done;
goto fail; goto fail;
} }
@ -203,7 +203,7 @@ client_get_streams(clicon_handle h,
* *
*/ */
static int static int
get_statedata(clicon_handle h, get_statedata(clixon_handle h,
char *xpath, char *xpath,
cvec *nsc, cvec *nsc,
withdefaults_type wdef, withdefaults_type wdef,
@ -220,20 +220,20 @@ get_statedata(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277")){ if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277")){
if ((ymod = yang_find_module_by_name(yspec, "clixon-rfc5277")) == NULL){ if ((ymod = yang_find_module_by_name(yspec, "clixon-rfc5277")) == NULL){
clicon_err(OE_YANG, ENOENT, "yang module clixon-rfc5277 not found"); clixon_err(OE_YANG, ENOENT, "yang module clixon-rfc5277 not found");
goto done; goto done;
} }
if ((namespace = yang_find_mynamespace(ymod)) == NULL){ if ((namespace = yang_find_mynamespace(ymod)) == NULL){
clicon_err(OE_YANG, ENOENT, "clixon-rfc5277 namespace not found"); clixon_err(OE_YANG, ENOENT, "clixon-rfc5277 namespace not found");
goto done; goto done;
} }
cprintf(cb, "<netconf xmlns=\"%s\"/>", namespace); cprintf(cb, "<netconf xmlns=\"%s\"/>", namespace);
@ -246,11 +246,11 @@ get_statedata(clicon_handle h,
} }
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040")){ if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040")){
if ((ymod = yang_find_module_by_name(yspec, "ietf-restconf-monitoring")) == NULL){ if ((ymod = yang_find_module_by_name(yspec, "ietf-restconf-monitoring")) == NULL){
clicon_err(OE_YANG, ENOENT, "yang module ietf-restconf-monitoring not found"); clixon_err(OE_YANG, ENOENT, "yang module ietf-restconf-monitoring not found");
goto done; goto done;
} }
if ((namespace = yang_find_mynamespace(ymod)) == NULL){ if ((namespace = yang_find_mynamespace(ymod)) == NULL){
clicon_err(OE_YANG, ENOENT, "ietf-restconf-monitoring namespace not found"); clixon_err(OE_YANG, ENOENT, "ietf-restconf-monitoring namespace not found");
goto done; goto done;
} }
cbuf_reset(cb); cbuf_reset(cb);
@ -406,7 +406,7 @@ get_statedata(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
filter_xpath_again(clicon_handle h, filter_xpath_again(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
cxobj *xret, cxobj *xret,
cxobj **xvec, cxobj **xvec,
@ -418,7 +418,7 @@ filter_xpath_again(clicon_handle h,
int i; int i;
if (xret == NULL){ if (xret == NULL){
clicon_err(OE_PLUGIN, EINVAL, "xret is NULL"); clixon_err(OE_PLUGIN, EINVAL, "xret is NULL");
goto done; goto done;
} }
/* If vectors are specified then mark the nodes found and /* If vectors are specified then mark the nodes found and
@ -456,7 +456,7 @@ filter_xpath_again(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
get_nacm_and_reply(clicon_handle h, get_nacm_and_reply(clixon_handle h,
cxobj *xret, cxobj *xret,
cxobj **xvec, cxobj **xvec,
size_t xlen, size_t xlen,
@ -505,7 +505,7 @@ get_nacm_and_reply(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
element2value(clicon_handle h, element2value(clixon_handle h,
cxobj *xe, cxobj *xe,
char *name, char *name,
char *defaultstr, char *defaultstr,
@ -535,7 +535,7 @@ element2value(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
list_pagination_hdr(clicon_handle h, list_pagination_hdr(clixon_handle h,
cxobj *xe, cxobj *xe,
uint32_t *offset, uint32_t *offset,
uint32_t *limit, uint32_t *limit,
@ -576,7 +576,7 @@ list_pagination_hdr(clicon_handle h,
* XXX Lots of this code (in particular at the end) is copy of get_common * XXX Lots of this code (in particular at the end) is copy of get_common
*/ */
static int static int
get_list_pagination(clicon_handle h, get_list_pagination(clixon_handle h,
struct client_entry *ce, struct client_entry *ce,
cxobj *xe, cxobj *xe,
netconf_content content, netconf_content content,
@ -614,7 +614,7 @@ get_list_pagination(clicon_handle h,
#endif #endif
if (cbret == NULL){ if (cbret == NULL){
clicon_err(OE_PLUGIN, EINVAL, "cbret is NULL"); clixon_err(OE_PLUGIN, EINVAL, "cbret is NULL");
goto done; goto done;
} }
/* Check if list/leaf-list */ /* Check if list/leaf-list */
@ -622,10 +622,10 @@ get_list_pagination(clicon_handle h,
goto done; goto done;
if (ylist == NULL){ if (ylist == NULL){
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* error reason should be in clicon_err_reason */ /* error reason should be in clixon_err_reason() */
cprintf(cbmsg, "Netconf get list-pagination: \"%s\" not found", xpath); cprintf(cbmsg, "Netconf get list-pagination: \"%s\" not found", xpath);
if (netconf_invalid_value(cbret, "application", cbuf_get(cbmsg)) < 0) if (netconf_invalid_value(cbret, "application", cbuf_get(cbmsg)) < 0)
goto done; goto done;
@ -686,7 +686,7 @@ get_list_pagination(clicon_handle h,
* relational operators <>. * relational operators <>.
*/ */
if ((cbpath = cbuf_new()) == NULL){ if ((cbpath = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* This uses xpath. Maybe limit should use parameters */ /* This uses xpath. Maybe limit should use parameters */
@ -712,10 +712,10 @@ get_list_pagination(clicon_handle h,
/* specific xpath */ /* specific xpath */
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, wdef, &xret, NULL, NULL) < 0) { if (xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, wdef, &xret, NULL, NULL) < 0) {
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason());
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
goto done; goto done;
goto ok; goto ok;
@ -752,12 +752,12 @@ get_list_pagination(clicon_handle h,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* error reason should be in clicon_err_reason */ /* error reason should be in clixon_err_reason */
cprintf(cberr, "Internal error, pagination state callback invalid return : %s", cprintf(cberr, "Internal error, pagination state callback invalid return : %s",
clicon_err_reason); clixon_err_reason());
if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
goto done; goto done;
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
@ -794,7 +794,7 @@ get_list_pagination(clicon_handle h,
/* Add remaining attribute */ /* Add remaining attribute */
if ((cba = cbuf_new()) == NULL){ if ((cba = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cba, "%u", remaining); cprintf(cba, "%u", remaining);
@ -838,7 +838,7 @@ get_list_pagination(clicon_handle h,
* @see from_client_get_config * @see from_client_get_config
*/ */
static int static int
get_common(clicon_handle h, get_common(clixon_handle h,
struct client_entry *ce, struct client_entry *ce,
cxobj *xe, cxobj *xe,
netconf_content content, netconf_content content,
@ -875,7 +875,7 @@ get_common(clicon_handle h,
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
username = clicon_username_get(h); username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec9"); clixon_err(OE_YANG, ENOENT, "No yang spec9");
goto done; goto done;
} }
if ((xfilter = xml_find(xe, "filter")) != NULL){ if ((xfilter = xml_find(xe, "filter")) != NULL){
@ -900,7 +900,7 @@ get_common(clicon_handle h,
/* Clixon extensions: depth */ /* Clixon extensions: depth */
if ((attr = xml_find_value(xe, "depth")) != NULL){ if ((attr = xml_find_value(xe, "depth")) != NULL){
if ((ret = parse_int32(attr, &depth, &reason)) < 0){ if ((ret = parse_int32(attr, &depth, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_int32"); clixon_err(OE_XML, errno, "parse_int32");
goto done; goto done;
} }
if (ret == 0){ if (ret == 0){
@ -946,10 +946,10 @@ get_common(clicon_handle h,
/* specific xpath */ /* specific xpath */
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, wdef, &xret, NULL, NULL) < 0) { if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, wdef, &xret, NULL, NULL) < 0) {
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason());
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
goto done; goto done;
goto ok; goto ok;
@ -961,10 +961,10 @@ get_common(clicon_handle h,
/* Whole config tree, for validate debug */ /* Whole config tree, for validate debug */
if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, wdef, &xret, NULL, NULL) < 0) { if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, wdef, &xret, NULL, NULL) < 0) {
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason());
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
goto done; goto done;
goto ok; goto ok;
@ -974,10 +974,10 @@ get_common(clicon_handle h,
/* specific xpath */ /* specific xpath */
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, wdef, &xret, NULL, NULL) < 0) { if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, wdef, &xret, NULL, NULL) < 0) {
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason());
if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0)
goto done; goto done;
goto ok; goto ok;
@ -1083,7 +1083,7 @@ get_common(clicon_handle h,
* @see from_client_get * @see from_client_get
*/ */
int int
from_client_get_config(clicon_handle h, from_client_get_config(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -1094,7 +1094,7 @@ from_client_get_config(clicon_handle h,
struct client_entry *ce = (struct client_entry *)arg; struct client_entry *ce = (struct client_entry *)arg;
if ((db = netconf_db_find(xe, "source")) == NULL){ if ((db = netconf_db_find(xe, "source")) == NULL){
clicon_err(OE_XML, 0, "db not found"); clixon_err(OE_XML, 0, "db not found");
goto done; goto done;
} }
retval = get_common(h, ce, xe, CONTENT_CONFIG, db, cbret); retval = get_common(h, ce, xe, CONTENT_CONFIG, db, cbret);
@ -1115,7 +1115,7 @@ from_client_get_config(clicon_handle h,
* @see from_client_get_config * @see from_client_get_config
*/ */
int int
from_client_get(clicon_handle h, from_client_get(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,

View file

@ -40,8 +40,8 @@
/* /*
* Prototypes * Prototypes
*/ */
int from_client_get_config(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); int from_client_get_config(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_get(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); int from_client_get(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_get_pageable_list(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); /* XXX */ int from_client_get_pageable_list(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); /* XXX */
#endif /* _BACKEND_GET_H_ */ #endif /* _BACKEND_GET_H_ */

View file

@ -43,16 +43,16 @@
* Prototypes * Prototypes
* not exported. * not exported.
*/ */
clicon_handle backend_handle_init(void); clixon_handle backend_handle_init(void);
int backend_handle_exit(clicon_handle h); int backend_handle_exit(clixon_handle h);
struct client_entry *backend_client_add(clicon_handle h, struct sockaddr *addr); struct client_entry *backend_client_add(clixon_handle h, struct sockaddr *addr);
struct client_entry *backend_client_list(clicon_handle h); struct client_entry *backend_client_list(clixon_handle h);
int backend_client_delete(clicon_handle h, struct client_entry *ce); int backend_client_delete(clixon_handle h, struct client_entry *ce);
int backend_client_print(clicon_handle h, FILE *f); int backend_client_print(clixon_handle h, FILE *f);
#endif /* _BACKEND_HANDLE_H_ */ #endif /* _BACKEND_HANDLE_H_ */

View file

@ -65,7 +65,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -89,7 +89,7 @@
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
static int static int
backend_terminate(clicon_handle h) backend_terminate(clixon_handle h)
{ {
yang_stmt *yspec; yang_stmt *yspec;
char *pidfile = clicon_backend_pidfile(h); char *pidfile = clicon_backend_pidfile(h);
@ -145,7 +145,7 @@ backend_terminate(clicon_handle h)
clixon_event_exit(); clixon_event_exit();
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
clixon_err_exit(); clixon_err_exit();
clicon_log_exit(); clixon_log_exit();
return 0; return 0;
} }
@ -157,7 +157,7 @@ backend_sig_term(int arg)
static int i=0; static int i=0;
if (i++ == 0) if (i++ == 0)
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
__PROGRAM__, __FUNCTION__, getpid(), arg); __PROGRAM__, __FUNCTION__, getpid(), arg);
else else
exit(1); exit(1);
@ -183,7 +183,7 @@ backend_sig_child(int arg)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
backend_server_socket(clicon_handle h) backend_server_socket(clixon_handle h)
{ {
int ss; int ss;
@ -202,7 +202,7 @@ backend_server_socket(clicon_handle h)
/*! Load external NACM file /*! Load external NACM file
*/ */
static int static int
nacm_load_external(clicon_handle h) nacm_load_external(clixon_handle h)
{ {
int retval = -1; int retval = -1;
char *filename; /* NACM config file */ char *filename; /* NACM config file */
@ -213,19 +213,19 @@ nacm_load_external(clicon_handle h)
filename = clicon_option_str(h, "CLICON_NACM_FILE"); filename = clicon_option_str(h, "CLICON_NACM_FILE");
if (filename == NULL || strlen(filename)==0){ if (filename == NULL || strlen(filename)==0){
clicon_err(OE_UNIX, errno, "CLICON_NACM_FILE not set in NACM external mode"); clixon_err(OE_UNIX, errno, "CLICON_NACM_FILE not set in NACM external mode");
goto done; goto done;
} }
if (stat(filename, &st) < 0){ if (stat(filename, &st) < 0){
clicon_err(OE_UNIX, errno, "%s", filename); clixon_err(OE_UNIX, errno, "%s", filename);
goto done; goto done;
} }
if (!S_ISREG(st.st_mode)){ if (!S_ISREG(st.st_mode)){
clicon_err(OE_UNIX, 0, "%s is not a regular file", filename); clixon_err(OE_UNIX, 0, "%s is not a regular file", filename);
goto done; goto done;
} }
if ((f = fopen(filename, "r")) == NULL) { if ((f = fopen(filename, "r")) == NULL) {
clicon_err(OE_UNIX, errno, "configure file: %s", filename); clixon_err(OE_UNIX, errno, "configure file: %s", filename);
return -1; return -1;
} }
if ((yspec = yspec_new()) == NULL) if ((yspec = yspec_new()) == NULL)
@ -236,7 +236,7 @@ nacm_load_external(clicon_handle h)
if (clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, NULL) < 0) if (clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, NULL) < 0)
goto done; goto done;
if (xt == NULL){ if (xt == NULL){
clicon_err(OE_XML, 0, "No xml tree in %s", filename); clixon_err(OE_XML, 0, "No xml tree in %s", filename);
goto done; goto done;
} }
if (clicon_nacm_ext_yang_set(h, yspec) < 0) if (clicon_nacm_ext_yang_set(h, yspec) < 0)
@ -252,7 +252,7 @@ nacm_load_external(clicon_handle h)
} }
static int static int
xmldb_drop_priv(clicon_handle h, xmldb_drop_priv(clixon_handle h,
const char *db, const char *db,
uid_t uid, uid_t uid,
gid_t gid) gid_t gid)
@ -263,7 +263,7 @@ xmldb_drop_priv(clicon_handle h,
if (xmldb_db2file(h, db, &filename) < 0) if (xmldb_db2file(h, db, &filename) < 0)
goto done; goto done;
if (chown(filename, uid, gid) < 0){ if (chown(filename, uid, gid) < 0){
clicon_err(OE_UNIX, errno, "chown"); clixon_err(OE_UNIX, errno, "chown");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -287,7 +287,7 @@ xmldb_drop_priv(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
check_drop_priv(clicon_handle h, check_drop_priv(clixon_handle h,
gid_t gid, gid_t gid,
yang_stmt *yspec) yang_stmt *yspec)
{ {
@ -304,19 +304,19 @@ check_drop_priv(clicon_handle h,
/* From here, drop privileges */ /* From here, drop privileges */
/* Check backend user exists */ /* Check backend user exists */
if ((backend_user = clicon_backend_user(h)) == NULL){ if ((backend_user = clicon_backend_user(h)) == NULL){
clicon_err(OE_DAEMON, EPERM, "Privileges cannot be dropped without specifying CLICON_BACKEND_USER\n"); clixon_err(OE_DAEMON, EPERM, "Privileges cannot be dropped without specifying CLICON_BACKEND_USER\n");
goto done; goto done;
} }
/* Get (wanted) new backend user id */ /* Get (wanted) new backend user id */
if (name2uid(backend_user, &newuid) < 0){ if (name2uid(backend_user, &newuid) < 0){
clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", backend_user); clixon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", backend_user);
goto done; goto done;
} }
/* get current backend userid, if already at this level OK */ /* get current backend userid, if already at this level OK */
if ((uid = getuid()) == newuid) if ((uid = getuid()) == newuid)
goto ok; goto ok;
if (uid != 0){ if (uid != 0){
clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid); clixon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
goto done; goto done;
} }
/* When dropping privileges, datastores are created if they do not exist. /* When dropping privileges, datastores are created if they do not exist.
@ -348,7 +348,7 @@ check_drop_priv(clicon_handle h,
goto done; goto done;
} }
if (setgid(gid) == -1) { if (setgid(gid) == -1) {
clicon_err(OE_DAEMON, errno, "setgid %d", gid); clixon_err(OE_DAEMON, errno, "setgid %d", gid);
goto done; goto done;
} }
switch (priv_mode){ switch (priv_mode){
@ -357,7 +357,7 @@ check_drop_priv(clicon_handle h,
goto done; goto done;
/* Verify you cannot regain root privileges */ /* Verify you cannot regain root privileges */
if (setuid(0) != -1){ if (setuid(0) != -1){
clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges"); clixon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
goto done; goto done;
} }
break; break;
@ -381,8 +381,8 @@ check_drop_priv(clicon_handle h,
* @retval 0 OK, status set * @retval 0 OK, status set
* @retval -1 Fatal error outside scope of startup_status * @retval -1 Fatal error outside scope of startup_status
* Transformation rules: * Transformation rules:
* 1) retval -1 assume clicon_errno/suberrno set. Special case from xml parser * 1) retval -1 assume clixon_err_category/subnr set. Special case from xml parser
* is clicon_suberrno = XMLPARSE_ERRNO which assumes an XML (non-fatal) parse * is clixon_err_subnr = XMLPARSE_ERRNO which assumes an XML (non-fatal) parse
* error which translates to -> STARTUP_ERR * error which translates to -> STARTUP_ERR
* All other error cases translates to fatal error * All other error cases translates to fatal error
* 2) retval 0 is xml validation fails -> STARTUP_INVALID * 2) retval 0 is xml validation fails -> STARTUP_INVALID
@ -397,9 +397,9 @@ ret2status(int ret,
switch (ret){ switch (ret){
case -1: case -1:
if (clicon_suberrno != XMLPARSE_ERRNO) if (clixon_err_subnr() != XMLPARSE_ERRNO)
goto done; goto done;
clicon_err_reset(); clixon_err_reset();
*status = STARTUP_ERR; *status = STARTUP_ERR;
break; break;
case 0: case 0:
@ -409,7 +409,7 @@ ret2status(int ret,
*status = STARTUP_OK; *status = STARTUP_OK;
break; break;
default: default:
clicon_err(OE_CFG, EINVAL, "No such retval %d", retval); clixon_err(OE_CFG, EINVAL, "No such retval %d", retval);
} /* switch */ } /* switch */
retval = 0; retval = 0;
done: done:
@ -423,7 +423,7 @@ backend_timer_setup(int fd,
void *arg) void *arg)
{ {
int retval = -1; int retval = -1;
clicon_handle h = (clicon_handle)arg; clixon_handle h = (clixon_handle)arg;
struct timeval now; struct timeval now;
struct timeval t; struct timeval t;
struct timeval t1 = {10, 0}; struct timeval t1 = {10, 0};
@ -451,7 +451,7 @@ backend_timer_setup(int fd,
/*! usage /*! usage
*/ */
static void static void
usage(clicon_handle h, usage(clixon_handle h,
char *argv0) char *argv0)
{ {
char *plgdir = clicon_backend_dir(h); char *plgdir = clicon_backend_dir(h);
@ -510,14 +510,14 @@ main(int argc,
char *backend_group = NULL; char *backend_group = NULL;
char *argv0 = argv[0]; char *argv0 = argv[0];
struct stat st; struct stat st;
clicon_handle h; clixon_handle h;
int help = 0; int help = 0;
int pid; int pid;
char *pidfile; char *pidfile;
char *sock; char *sock;
int sockfamily; int sockfamily;
char *nacm_mode; char *nacm_mode;
int logdst = CLICON_LOG_SYSLOG|CLICON_LOG_STDERR; int logdst = CLIXON_LOG_SYSLOG|CLIXON_LOG_STDERR;
yang_stmt *yspec = NULL; yang_stmt *yspec = NULL;
char *str; char *str;
int ss = -1; /* server socket */ int ss = -1; /* server socket */
@ -535,11 +535,14 @@ main(int argc,
enum format_enum config_dump_format = FORMAT_XML; enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0; int print_version = 0;
/* In the startup, logs to stderr & syslog and debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Initiate CLICON handle */ /* Initiate CLICON handle */
if ((h = backend_handle_init()) == NULL) if ((h = backend_handle_init()) == NULL)
return -1; return -1;
/* In the startup, logs to stderr & syslog and debug flag set later */
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
goto done;
if (clixon_err_init(h) < 0)
goto done;
foreground = 0; foreground = 0;
once = 0; once = 0;
zap = 0; zap = 0;
@ -581,11 +584,11 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break; break;
case 'l': /* Log destination: s|e|o */ case 'l': /* Log destination: s|e|o */
if ((logdst = clicon_log_opt(optarg[0])) < 0) if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]); usage(h, argv[0]);
if (logdst == CLICON_LOG_FILE && if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 && strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0) clixon_log_file(optarg+1) < 0)
goto done; goto done;
break; break;
} }
@ -596,8 +599,8 @@ main(int argc,
* XXX: if started in a start-daemon script, there will be irritating * XXX: if started in a start-daemon script, there will be irritating
* double syslogs until fork below. * double syslogs until fork below.
*/ */
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
yang_init(h); yang_init(h);
/* Find and read configfile */ /* Find and read configfile */
@ -718,8 +721,8 @@ main(int argc,
/* Access the remaining argv/argc options (after --) w clicon-argv_get() */ /* Access the remaining argv/argc options (after --) w clicon-argv_get() */
clicon_argv_set(h, argv0, argc, argv); clicon_argv_set(h, argv0, argc, argv);
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
/* Defer: Wait to the last minute to print help message */ /* Defer: Wait to the last minute to print help message */
if (help) if (help)
usage(h, argv[0]); usage(h, argv[0]);
@ -730,22 +733,22 @@ main(int argc,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(sz); clixon_log_string_limit_set(sz);
#ifndef HAVE_LIBXML2 #ifndef HAVE_LIBXML2
if (clicon_yang_regexp(h) == REGEXP_LIBXML2){ if (clicon_yang_regexp(h) == REGEXP_LIBXML2){
clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); clixon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
goto done; goto done;
} }
#endif #endif
/* Check pid-file, if zap kil the old daemon, else return here */ /* Check pid-file, if zap kil the old daemon, else return here */
if ((pidfile = clicon_backend_pidfile(h)) == NULL){ if ((pidfile = clicon_backend_pidfile(h)) == NULL){
clicon_err(OE_FATAL, 0, "pidfile not set"); clixon_err(OE_FATAL, 0, "pidfile not set");
goto done; goto done;
} }
sockfamily = clicon_sock_family(h); sockfamily = clicon_sock_family(h);
if ((sock = clicon_sock_str(h)) == NULL){ if ((sock = clicon_sock_str(h)) == NULL){
clicon_err(OE_FATAL, 0, "sock not set"); clixon_err(OE_FATAL, 0, "sock not set");
goto done; goto done;
} }
if (pidfile_get(pidfile, &pid) < 0) if (pidfile_get(pidfile, &pid) < 0)
@ -762,7 +765,7 @@ main(int argc,
} }
else else
if (pid){ if (pid){
clicon_err(OE_DAEMON, 0, "Daemon already running with pid %d\n(Try killing it with %s -z)", clixon_err(OE_DAEMON, 0, "Daemon already running with pid %d\n(Try killing it with %s -z)",
pid, argv0); pid, argv0);
return -1; /* goto done deletes pidfile */ return -1; /* goto done deletes pidfile */
} }
@ -777,11 +780,11 @@ main(int argc,
/* Sanity check: backend group exists */ /* Sanity check: backend group exists */
if ((backend_group = clicon_sock_group(h)) == NULL){ if ((backend_group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); clixon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1; return -1;
} }
if (group_name2gid(backend_group, &gid) < 0){ if (group_name2gid(backend_group, &gid) < 0){
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */ clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */
"The config daemon requires a valid group to create a server UNIX socket\n" "The config daemon requires a valid group to create a server UNIX socket\n"
"Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n" "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
"or create the group and add the user to it. Check documentation for how to do this on your platform", "or create the group and add the user to it. Check documentation for how to do this on your platform",
@ -899,13 +902,13 @@ main(int argc,
/* Startup mode needs to be defined, */ /* Startup mode needs to be defined, */
startup_mode = clicon_startup_mode(h); startup_mode = clicon_startup_mode(h);
if ((int)startup_mode == -1){ if ((int)startup_mode == -1){
clicon_log(LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend."); clixon_log(h, LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend.");
goto done; goto done;
} }
/* Check that netconf :startup is enabled */ /* Check that netconf :startup is enabled */
if ((startup_mode == SM_STARTUP || startup_mode == SM_RUNNING_STARTUP) && if ((startup_mode == SM_STARTUP || startup_mode == SM_RUNNING_STARTUP) &&
!if_feature(yspec, "ietf-netconf", "startup")){ !if_feature(yspec, "ietf-netconf", "startup")){
clicon_log(LOG_ERR, "Startup mode selected but Netconf :startup feature is not enabled. Enable with option: <CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>"); clixon_log(h, LOG_ERR, "Startup mode selected but Netconf :startup feature is not enabled. Enable with option: <CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>");
goto done; goto done;
} }
@ -924,7 +927,7 @@ main(int argc,
xmldb_delete(h, "candidate"); xmldb_delete(h, "candidate");
/* If startup fails, lib functions report invalidation info in a cbuf */ /* If startup fails, lib functions report invalidation info in a cbuf */
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
switch (startup_mode){ switch (startup_mode){
@ -1003,7 +1006,7 @@ main(int argc,
} }
if (status != STARTUP_OK){ if (status != STARTUP_OK){
if (cbuf_len(cbret)) if (cbuf_len(cbret))
clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret)); clixon_log(h, LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
if (load_failsafe(h, "Startup") < 0){ if (load_failsafe(h, "Startup") < 0){
goto done; goto done;
} }
@ -1022,7 +1025,7 @@ main(int argc,
goto done; goto done;
if (status == STARTUP_INVALID && cbuf_len(cbret)) if (status == STARTUP_INVALID && cbuf_len(cbret))
clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret)); clixon_log(h, LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
/* Call backend plugin_start with user -- options */ /* Call backend plugin_start with user -- options */
if (clixon_plugin_start_all(h) < 0) if (clixon_plugin_start_all(h) < 0)
@ -1044,13 +1047,13 @@ main(int argc,
daemonized errors OK. Before this stage, errors are logged on stderr daemonized errors OK. Before this stage, errors are logged on stderr
also */ also */
if (foreground==0){ if (foreground==0){
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO,
logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG); logdst==CLIXON_LOG_FILE?CLIXON_LOG_FILE:CLIXON_LOG_SYSLOG);
/* Call plugin callbacks just before fork/daemonization */ /* Call plugin callbacks just before fork/daemonization */
if (clixon_plugin_pre_daemon_all(h) < 0) if (clixon_plugin_pre_daemon_all(h) < 0)
goto done; goto done;
if (daemon(0, 0) < 0){ if (daemon(0, 0) < 0){
clicon_err(OE_UNIX, errno, "daemon"); clixon_err(OE_UNIX, errno, "daemon");
exit(-1); exit(-1);
} }
} }
@ -1065,21 +1068,21 @@ main(int argc,
goto done; goto done;
if (set_signal(SIGTERM, backend_sig_term, NULL) < 0){ if (set_signal(SIGTERM, backend_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGINT, backend_sig_term, NULL) < 0){ if (set_signal(SIGINT, backend_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
/* This is in case restconf daemon forked using process-control API */ /* This is in case restconf daemon forked using process-control API */
if (set_signal(SIGCHLD, backend_sig_child, NULL) < 0){ if (set_signal(SIGCHLD, backend_sig_child, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
/* Client exit in the middle of a transaction, handled in clicon_msg_send */ /* Client exit in the middle of a transaction, handled in clicon_msg_send */
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
/* Initialize server socket and save it to handle */ /* Initialize server socket and save it to handle */
@ -1106,7 +1109,7 @@ main(int argc,
/* Just before event-loop, after socket bind/listen */ /* Just before event-loop, after socket bind/listen */
if (netconf_monitoring_statistics_init(h) < 0) if (netconf_monitoring_statistics_init(h) < 0)
goto done; goto done;
clicon_log(LOG_NOTICE, "%s: %u Started", __PROGRAM__, getpid()); clixon_log(h, LOG_NOTICE, "%s: %u Started", __PROGRAM__, getpid());
if (clixon_event_loop(h) < 0) if (clixon_event_loop(h) < 0)
goto done; goto done;
ok: ok:
@ -1114,7 +1117,7 @@ main(int argc,
done: done:
if (cbret) if (cbret)
cbuf_free(cbret); cbuf_free(cbret);
clicon_log(LOG_NOTICE, "%s: %u Terminated retval:%d", __PROGRAM__, getpid(), retval); clixon_log(h, LOG_NOTICE, "%s: %u Terminated retval:%d", __PROGRAM__, getpid(), retval);
backend_terminate(h); /* Cannot use h after this */ backend_terminate(h); /* Cannot use h after this */
return retval; return retval;

View file

@ -57,7 +57,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -75,7 +75,7 @@
*/ */
int int
clixon_plugin_reset_one(clixon_plugin_t *cp, clixon_plugin_reset_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
char *db) char *db)
{ {
int retval = -1; int retval = -1;
@ -89,8 +89,8 @@ clixon_plugin_reset_one(clixon_plugin_t *cp,
if (fn(h, db) < 0) { if (fn(h, db) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (clicon_errno < 0) if (clixon_err_category() < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Reset callback in plugin: %s returned -1 but did not make a clicon_err call", clixon_log(h, LOG_WARNING, "%s: Internal error: Reset callback in plugin: %s returned -1 but did not make a clixon_err call",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -111,7 +111,7 @@ clixon_plugin_reset_one(clixon_plugin_t *cp,
* @retval -1 Error * @retval -1 Error
*/ */
int int
clixon_plugin_reset_all(clicon_handle h, clixon_plugin_reset_all(clixon_handle h,
char *db) char *db)
{ {
int retval = -1; int retval = -1;
@ -137,7 +137,7 @@ clixon_plugin_reset_all(clicon_handle h,
*/ */
static int static int
clixon_plugin_pre_daemon_one(clixon_plugin_t *cp, clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
clicon_handle h) clixon_handle h)
{ {
int retval = -1; int retval = -1;
plgdaemon_t *fn; /* Daemonize plugin callback function */ plgdaemon_t *fn; /* Daemonize plugin callback function */
@ -150,9 +150,9 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
if (fn(h) < 0) { if (fn(h) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (clicon_errno < 0) if (clixon_err_category() < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\ clixon_log(h, LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\
%s returned -1 but did not make a clicon_err call", %s returned -1 but did not make a clixon_err call",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -174,7 +174,7 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
* @retval -1 Error * @retval -1 Error
*/ */
int int
clixon_plugin_pre_daemon_all(clicon_handle h) clixon_plugin_pre_daemon_all(clixon_handle h)
{ {
int retval = -1; int retval = -1;
clixon_plugin_t *cp = NULL; clixon_plugin_t *cp = NULL;
@ -199,7 +199,7 @@ clixon_plugin_pre_daemon_all(clicon_handle h)
*/ */
static int static int
clixon_plugin_daemon_one(clixon_plugin_t *cp, clixon_plugin_daemon_one(clixon_plugin_t *cp,
clicon_handle h) clixon_handle h)
{ {
int retval = -1; int retval = -1;
plgdaemon_t *fn; /* Daemonize plugin callback function */ plgdaemon_t *fn; /* Daemonize plugin callback function */
@ -212,8 +212,8 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp,
if (fn(h) < 0) { if (fn(h) < 0) {
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (clicon_errno < 0) if (clixon_err_category() < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clicon_err call", clixon_log(h, LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clixon_err call",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -237,7 +237,7 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp,
* @note Also called for non-background mode * @note Also called for non-background mode
*/ */
int int
clixon_plugin_daemon_all(clicon_handle h) clixon_plugin_daemon_all(clixon_handle h)
{ {
int retval = -1; int retval = -1;
clixon_plugin_t *cp = NULL; clixon_plugin_t *cp = NULL;
@ -280,7 +280,7 @@ clixon_plugin_daemon_all(clicon_handle h)
*/ */
static int static int
clixon_plugin_statedata_one(clixon_plugin_t *cp, clixon_plugin_statedata_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
cvec *nsc, cvec *nsc,
char *xpath, char *xpath,
cxobj **xp) cxobj **xp)
@ -299,8 +299,8 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
if (fn(h, nsc, xpath, x) < 0){ if (fn(h, nsc, xpath, x) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (clicon_errno < 0) if (clixon_err_category() < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call", clixon_log(h, LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clixon_err call",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto fail; /* Dont quit here on user callbacks */ goto fail; /* Dont quit here on user callbacks */
} }
@ -333,7 +333,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
* @note xret can be replaced in this function * @note xret can be replaced in this function
*/ */
int int
clixon_plugin_statedata_all(clicon_handle h, clixon_plugin_statedata_all(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
cvec *nsc, cvec *nsc,
char *xpath, char *xpath,
@ -353,12 +353,12 @@ clixon_plugin_statedata_all(clicon_handle h,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* error reason should be in clicon_err_reason */ /* error reason should be in clixon_err_reason */
cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s", cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s",
clixon_plugin_name_get(cp), clicon_err_reason); clixon_plugin_name_get(cp), clixon_err_reason());
if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
goto done; goto done;
xml_free(*xret); xml_free(*xret);
@ -430,7 +430,7 @@ clixon_plugin_statedata_all(clicon_handle h,
*/ */
static int static int
clixon_plugin_lockdb_one(clixon_plugin_t *cp, clixon_plugin_lockdb_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
char *db, char *db,
int lock, int lock,
int id) int id)
@ -463,7 +463,7 @@ clixon_plugin_lockdb_one(clixon_plugin_t *cp,
* @retval -1 Fatal error * @retval -1 Fatal error
*/ */
int int
clixon_plugin_lockdb_all(clicon_handle h, clixon_plugin_lockdb_all(clixon_handle h,
char *db, char *db,
int lock, int lock,
int id int id
@ -491,7 +491,7 @@ clixon_plugin_lockdb_all(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
clixon_pagination_cb_call(clicon_handle h, clixon_pagination_cb_call(clixon_handle h,
char *xpath, char *xpath,
int locked, int locked,
uint32_t offset, uint32_t offset,
@ -524,7 +524,7 @@ clixon_pagination_cb_call(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
clixon_pagination_cb_register(clicon_handle h, clixon_pagination_cb_register(clixon_handle h,
handler_function fn, handler_function fn,
char *xpath, char *xpath,
void *arg) void *arg)
@ -535,7 +535,7 @@ clixon_pagination_cb_register(clicon_handle h,
clicon_ptr_get(h, "pagination-entries", (void**)&htable); clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (dispatcher_register_handler(&htable, &x) < 0){ if (dispatcher_register_handler(&htable, &x) < 0){
clicon_err(OE_PLUGIN, errno, "dispatcher"); clixon_err(OE_PLUGIN, errno, "dispatcher");
goto done; goto done;
} }
if (clicon_ptr_set(h, "pagination-entries", htable) < 0) if (clicon_ptr_set(h, "pagination-entries", htable) < 0)
@ -550,7 +550,7 @@ clixon_pagination_cb_register(clicon_handle h,
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
int int
clixon_pagination_free(clicon_handle h) clixon_pagination_free(clixon_handle h)
{ {
dispatcher_entry_t *htable = NULL; dispatcher_entry_t *htable = NULL;
@ -573,7 +573,7 @@ transaction_new(void)
static uint64_t id = 0; /* Global transaction id */ static uint64_t id = 0; /* Global transaction id */
if ((td = malloc(sizeof(*td))) == NULL){ if ((td = malloc(sizeof(*td))) == NULL){
clicon_err(OE_CFG, errno, "malloc"); clixon_err(OE_CFG, errno, "malloc");
return NULL; return NULL;
} }
memset(td, 0, sizeof(*td)); memset(td, 0, sizeof(*td));
@ -614,7 +614,7 @@ transaction_free(transaction_data_t *td)
*/ */
int int
plugin_transaction_begin_one(clixon_plugin_t *cp, plugin_transaction_begin_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -628,8 +628,8 @@ plugin_transaction_begin_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -651,7 +651,7 @@ plugin_transaction_begin_one(clixon_plugin_t *cp,
* @retval -1 Error: one of the plugin callbacks returned error * @retval -1 Error: one of the plugin callbacks returned error
*/ */
int int
plugin_transaction_begin_all(clicon_handle h, plugin_transaction_begin_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -677,7 +677,7 @@ plugin_transaction_begin_all(clicon_handle h,
*/ */
int int
plugin_transaction_validate_one(clixon_plugin_t *cp, plugin_transaction_validate_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -691,8 +691,8 @@ plugin_transaction_validate_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
@ -713,7 +713,7 @@ plugin_transaction_validate_one(clixon_plugin_t *cp,
* @retval -1 Error: one of the plugin callbacks returned validation fail * @retval -1 Error: one of the plugin callbacks returned validation fail
*/ */
int int
plugin_transaction_validate_all(clicon_handle h, plugin_transaction_validate_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -739,7 +739,7 @@ plugin_transaction_validate_all(clicon_handle h,
*/ */
int int
plugin_transaction_complete_one(clixon_plugin_t *cp, plugin_transaction_complete_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -753,8 +753,8 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -776,7 +776,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp,
* @note Rename to transaction_complete? * @note Rename to transaction_complete?
*/ */
int int
plugin_transaction_complete_all(clicon_handle h, plugin_transaction_complete_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -802,7 +802,7 @@ plugin_transaction_complete_all(clicon_handle h,
* plugin 2, then the revert will be made in plugins 1 and 0. * plugin 2, then the revert will be made in plugins 1 and 0.
*/ */
static int static int
plugin_transaction_revert_all(clicon_handle h, plugin_transaction_revert_all(clixon_handle h,
transaction_data_t *td, transaction_data_t *td,
int nr) int nr)
{ {
@ -814,7 +814,7 @@ plugin_transaction_revert_all(clicon_handle h,
if ((fn = clixon_plugin_api_get(cp)->ca_trans_revert) == NULL) if ((fn = clixon_plugin_api_get(cp)->ca_trans_revert) == NULL)
continue; continue;
if ((retval = fn(h, (transaction_data)td)) < 0){ if ((retval = fn(h, (transaction_data)td)) < 0){
clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
break; break;
} }
@ -833,7 +833,7 @@ plugin_transaction_revert_all(clicon_handle h,
*/ */
int int
plugin_transaction_commit_one(clixon_plugin_t *cp, plugin_transaction_commit_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -847,8 +847,8 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -871,7 +871,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp,
* and in reverse order. * and in reverse order.
*/ */
int int
plugin_transaction_commit_all(clicon_handle h, plugin_transaction_commit_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -901,7 +901,7 @@ plugin_transaction_commit_all(clicon_handle h,
*/ */
int int
plugin_transaction_commit_done_one(clixon_plugin_t *cp, plugin_transaction_commit_done_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -915,8 +915,8 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -937,7 +937,7 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp,
* @note no revert is done * @note no revert is done
*/ */
int int
plugin_transaction_commit_done_all(clicon_handle h, plugin_transaction_commit_done_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -962,7 +962,7 @@ plugin_transaction_commit_done_all(clicon_handle h,
*/ */
int int
plugin_transaction_end_one(clixon_plugin_t *cp, plugin_transaction_end_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -976,8 +976,8 @@ plugin_transaction_end_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -997,7 +997,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp,
* @retval -1 Error * @retval -1 Error
*/ */
int int
plugin_transaction_end_all(clicon_handle h, plugin_transaction_end_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -1015,7 +1015,7 @@ plugin_transaction_end_all(clicon_handle h,
int int
plugin_transaction_abort_one(clixon_plugin_t *cp, plugin_transaction_abort_one(clixon_plugin_t *cp,
clicon_handle h, clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;
@ -1029,8 +1029,8 @@ plugin_transaction_abort_one(clixon_plugin_t *cp,
if (fn(h, (transaction_data)td) < 0){ if (fn(h, (transaction_data)td) < 0){
if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0)
goto done; goto done;
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error",
__FUNCTION__, clixon_plugin_name_get(cp)); __FUNCTION__, clixon_plugin_name_get(cp));
goto done; goto done;
} }
@ -1050,7 +1050,7 @@ plugin_transaction_abort_one(clixon_plugin_t *cp,
* @retval -1 Error * @retval -1 Error
*/ */
int int
plugin_transaction_abort_all(clicon_handle h, plugin_transaction_abort_all(clixon_handle h,
transaction_data_t *td) transaction_data_t *td)
{ {
int retval = -1; int retval = -1;

View file

@ -51,7 +51,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -74,7 +74,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
restconf_pseudo_set_log(clicon_handle h, restconf_pseudo_set_log(clixon_handle h,
cxobj *xt) cxobj *xt)
{ {
int retval = -1; int retval = -1;
@ -102,7 +102,7 @@ restconf_pseudo_set_log(clicon_handle h,
if (argv[i+1]) if (argv[i+1])
free(argv[i+1]); free(argv[i+1]);
if ((argv[i+1] = strdup("s")) == NULL){ if ((argv[i+1] = strdup("s")) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -110,7 +110,7 @@ restconf_pseudo_set_log(clicon_handle h,
if (argv[i+1]) if (argv[i+1])
free(argv[i+1]); free(argv[i+1]);
if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){ if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -121,7 +121,7 @@ restconf_pseudo_set_log(clicon_handle h,
if (dbg){ if (dbg){
free(argv[i+1]); free(argv[i+1]);
if ((argv[i+1] = strdup(dbg)) == NULL){ if ((argv[i+1] = strdup(dbg)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -144,7 +144,7 @@ restconf_pseudo_set_log(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
restconf_pseudo_set_inline(clicon_handle h, restconf_pseudo_set_inline(clixon_handle h,
cxobj *xt) cxobj *xt)
{ {
int retval = -1; int retval = -1;
@ -165,13 +165,13 @@ restconf_pseudo_set_inline(clicon_handle h,
char *str; char *str;
if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){ if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cb, xrestconf, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cb, xrestconf, 0, 0, NULL, -1, 0) < 0)
goto done; goto done;
if ((str = strdup(cbuf_get(cb))) == NULL){ if ((str = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_XML, errno, "stdup"); clixon_err(OE_XML, errno, "stdup");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s str:%s", __FUNCTION__, str); clixon_debug(CLIXON_DBG_DEFAULT, "%s str:%s", __FUNCTION__, str);
@ -196,7 +196,7 @@ restconf_pseudo_set_inline(clicon_handle h,
* These rules give that if RPC op is start and enable is false -> change op to none * These rules give that if RPC op is start and enable is false -> change op to none
*/ */
int int
restconf_rpc_wrapper(clicon_handle h, restconf_rpc_wrapper(clixon_handle h,
process_entry_t *pe, process_entry_t *pe,
proc_operation *operation) proc_operation *operation)
{ {
@ -248,7 +248,7 @@ restconf_rpc_wrapper(clicon_handle h,
* this is ignored. * this is ignored.
*/ */
static int static int
restconf_pseudo_process_control(clicon_handle h) restconf_pseudo_process_control(clixon_handle h)
{ {
int retval = -1; int retval = -1;
char **argv = NULL; char **argv = NULL;
@ -266,12 +266,12 @@ restconf_pseudo_process_control(clicon_handle h)
nr += 2; nr += 2;
#endif #endif
if ((argv = calloc(nr, sizeof(char *))) == NULL){ if ((argv = calloc(nr, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc"); clixon_err(OE_UNIX, errno, "calloc");
goto done; goto done;
} }
i = 0; i = 0;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* Try to figure out where clixon_restconf is installed /* Try to figure out where clixon_restconf is installed
@ -303,7 +303,7 @@ restconf_pseudo_process_control(clicon_handle h)
clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm); clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm);
} }
if (!found){ 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", clixon_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",
dir0, dir1); dir0, dir1);
goto done; goto done;
} }
@ -343,7 +343,7 @@ restconf_pseudo_process_control(clicon_handle h)
/*! Restconf pseudo-plugin process validate /*! Restconf pseudo-plugin process validate
*/ */
static int static int
restconf_pseudo_process_validate(clicon_handle h, restconf_pseudo_process_validate(clixon_handle h,
transaction_data td) transaction_data td)
{ {
int retval = -1; int retval = -1;
@ -357,11 +357,11 @@ restconf_pseudo_process_validate(clicon_handle h,
xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){ xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){
/* Should filepath be checked? One could claim this is a runtime system,... */ /* Should filepath be checked? One could claim this is a runtime system,... */
if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){ if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set"); clixon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set");
return -1; /* induce fail */ return -1; /* induce fail */
} }
if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){ if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-key-path not set"); clixon_err(OE_CFG, 0, "SSL enabled but server-key-path not set");
return -1; /* induce fail */ return -1; /* induce fail */
} }
} }
@ -372,7 +372,7 @@ restconf_pseudo_process_validate(clicon_handle h,
/*! Restconf pseduo-plugin process commit /*! Restconf pseduo-plugin process commit
*/ */
static int static int
restconf_pseudo_process_commit(clicon_handle h, restconf_pseudo_process_commit(clixon_handle h,
transaction_data td) transaction_data td)
{ {
int retval = -1; int retval = -1;
@ -437,7 +437,7 @@ restconf_pseudo_process_commit(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
backend_plugin_restconf_register(clicon_handle h, backend_plugin_restconf_register(clixon_handle h,
yang_stmt *yspec) yang_stmt *yspec)
{ {
int retval = -1; int retval = -1;

View file

@ -38,6 +38,6 @@
#ifndef _BACKEND_PLUGIN_RESTCONF_H_ #ifndef _BACKEND_PLUGIN_RESTCONF_H_
#define _BACKEND_PLUGIN_RESTCONF_H_ #define _BACKEND_PLUGIN_RESTCONF_H_
int backend_plugin_restconf_register(clicon_handle h, yang_stmt *yspec); int backend_plugin_restconf_register(clixon_handle h, yang_stmt *yspec);
#endif /* _BACKEND_PLUGIN_RESTCONF_H_ */ #endif /* _BACKEND_PLUGIN_RESTCONF_H_ */

View file

@ -68,7 +68,7 @@
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "backend_socket.h" #include "backend_socket.h"
@ -84,7 +84,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
config_socket_init_ipv4(clicon_handle h, config_socket_init_ipv4(clixon_handle h,
char *dst) char *dst)
{ {
int s; int s;
@ -96,7 +96,7 @@ config_socket_init_ipv4(clicon_handle h,
/* create inet socket */ /* create inet socket */
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
clicon_err(OE_UNIX, errno, "socket"); clixon_err(OE_UNIX, errno, "socket");
return -1; return -1;
} }
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one)); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one));
@ -104,16 +104,16 @@ config_socket_init_ipv4(clicon_handle h,
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);
if (inet_pton(addr.sin_family, dst, &addr.sin_addr) != 1){ if (inet_pton(addr.sin_family, dst, &addr.sin_addr) != 1){
clicon_err(OE_UNIX, errno, "inet_pton: %s (Expected IPv4 address. Check settings of CLICON_SOCK_FAMILY and CLICON_SOCK)", dst); clixon_err(OE_UNIX, errno, "inet_pton: %s (Expected IPv4 address. Check settings of CLICON_SOCK_FAMILY and CLICON_SOCK)", dst);
goto err; /* Could check getaddrinfo */ goto err; /* Could check getaddrinfo */
} }
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0){ if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0){
clicon_err(OE_UNIX, errno, "bind"); clixon_err(OE_UNIX, errno, "bind");
goto err; goto err;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "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){ if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen"); clixon_err(OE_UNIX, errno, "listen");
goto err; goto err;
} }
return s; return s;
@ -132,7 +132,7 @@ config_socket_init_ipv4(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
config_socket_init_unix(clicon_handle h, config_socket_init_unix(clixon_handle h,
char *sock) char *sock)
{ {
int s; int s;
@ -143,23 +143,23 @@ config_socket_init_unix(clicon_handle h,
struct stat st; struct stat st;
if (lstat(sock, &st) == 0 && unlink(sock) < 0){ if (lstat(sock, &st) == 0 && unlink(sock) < 0){
clicon_err(OE_UNIX, errno, "unlink(%s)", sock); clixon_err(OE_UNIX, errno, "unlink(%s)", sock);
return -1; return -1;
} }
/* then find configuration group (for clients) and find its groupid */ /* then find configuration group (for clients) and find its groupid */
if ((config_group = clicon_sock_group(h)) == NULL){ if ((config_group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); clixon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1; return -1;
} }
if (group_name2gid(config_group, &gid) < 0) if (group_name2gid(config_group, &gid) < 0)
return -1; return -1;
#if 0 #if 0
if (gid == 0) if (gid == 0)
clicon_log(LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group); clixon_log(h, LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group);
#endif #endif
/* create unix socket */ /* create unix socket */
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
clicon_err(OE_UNIX, errno, "socket"); clixon_err(OE_UNIX, errno, "socket");
return -1; return -1;
} }
// setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one)); // setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one));
@ -168,19 +168,19 @@ config_socket_init_unix(clicon_handle h,
strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1); strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1);
old_mask = umask(S_IRWXO | S_IXGRP | S_IXUSR); old_mask = umask(S_IRWXO | S_IXGRP | S_IXUSR);
if (bind(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){ if (bind(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){
clicon_err(OE_UNIX, errno, "bind"); clixon_err(OE_UNIX, errno, "bind");
umask(old_mask); umask(old_mask);
goto err; goto err;
} }
umask(old_mask); umask(old_mask);
/* change socket path file group */ /* change socket path file group */
if (lchown(sock, -1, gid) < 0){ if (lchown(sock, -1, gid) < 0){
clicon_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group); clixon_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group);
goto err; goto err;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "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){ if (listen(s, 5) < 0){
clicon_err(OE_UNIX, errno, "listen"); clixon_err(OE_UNIX, errno, "listen");
goto err; goto err;
} }
return s; return s;
@ -196,12 +196,12 @@ config_socket_init_unix(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
backend_socket_init(clicon_handle h) backend_socket_init(clixon_handle h)
{ {
char *sock; /* unix path or ip address string */ char *sock; /* unix path or ip address string */
if ((sock = clicon_sock_str(h)) == NULL){ if ((sock = clicon_sock_str(h)) == NULL){
clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); clixon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
return -1; return -1;
} }
switch (clicon_sock_family(h)){ switch (clicon_sock_family(h)){
@ -212,7 +212,7 @@ backend_socket_init(clicon_handle h)
return config_socket_init_ipv4(h, sock); return config_socket_init_ipv4(h, sock);
break; break;
default: default:
clicon_err(OE_UNIX, EINVAL, "No such address family: %d", clixon_err(OE_UNIX, EINVAL, "No such address family: %d",
clicon_sock_family(h)); clicon_sock_family(h));
break; break;
} }
@ -222,7 +222,7 @@ backend_socket_init(clicon_handle h)
/*! Accept new socket client /*! Accept new socket client
* *
* @param[in] fd Socket (unix or ip) * @param[in] fd Socket (unix or ip)
* @param[in] arg typecast clicon_handle * @param[in] arg typecast clixon_handle
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
@ -231,7 +231,7 @@ backend_accept_client(int fd,
void *arg) void *arg)
{ {
int retval = -1; int retval = -1;
clicon_handle h = (clicon_handle)arg; clixon_handle h = (clixon_handle)arg;
int s; int s;
struct sockaddr from = {0,}; struct sockaddr from = {0,};
socklen_t len; socklen_t len;
@ -248,7 +248,7 @@ backend_accept_client(int fd,
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
len = sizeof(from); len = sizeof(from);
if ((s = accept(fd, &from, &len)) < 0){ if ((s = accept(fd, &from, &len)) < 0){
clicon_err(OE_UNIX, errno, "accept"); clixon_err(OE_UNIX, errno, "accept");
goto done; goto done;
} }
if ((ce = backend_client_add(h, &from)) == NULL) if ((ce = backend_client_add(h, &from)) == NULL)
@ -262,7 +262,7 @@ backend_accept_client(int fd,
#if defined(HAVE_SO_PEERCRED) #if defined(HAVE_SO_PEERCRED)
clen = sizeof(cr); clen = sizeof(cr);
if(getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &clen) < 0){ if(getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &clen) < 0){
clicon_err(OE_UNIX, errno, "getsockopt"); clixon_err(OE_UNIX, errno, "getsockopt");
goto done; goto done;
} }
if (uid2name(cr.uid, &name) < 0) if (uid2name(cr.uid, &name) < 0)
@ -277,7 +277,7 @@ backend_accept_client(int fd,
#endif #endif
if (name != NULL){ if (name != NULL){
if ((ce->ce_username = name) == NULL){ if ((ce->ce_username = name) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
name = NULL; name = NULL;
goto done; goto done;
} }

View file

@ -42,7 +42,7 @@
/* /*
* Prototypes * Prototypes
*/ */
int backend_socket_init(clicon_handle h); int backend_socket_init(clixon_handle h);
int backend_accept_client(int fd, void *arg); int backend_accept_client(int fd, void *arg);
#endif /* _BACKEND_SOCKET_H_ */ #endif /* _BACKEND_SOCKET_H_ */

View file

@ -62,7 +62,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -78,7 +78,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
db_merge(clicon_handle h, db_merge(clixon_handle h,
const char *db1, const char *db1,
const char *db2, const char *db2,
cbuf *cbret) cbuf *cbret)
@ -130,7 +130,7 @@ startup --+-------------------------------------> BROKEN XML
* @note: if commit fails, copy factory to running * @note: if commit fails, copy factory to running
*/ */
int int
startup_mode_startup(clicon_handle h, startup_mode_startup(clixon_handle h,
char *db, char *db,
cbuf *cbret) cbuf *cbret)
{ {
@ -140,7 +140,7 @@ startup_mode_startup(clicon_handle h,
yang_stmt *yspec = clicon_dbspec_yang(h); yang_stmt *yspec = clicon_dbspec_yang(h);
if (strcmp(db, "running")==0){ if (strcmp(db, "running")==0){
clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db); clixon_err(OE_FATAL, 0, "Invalid startup db: %s", db);
goto done; goto done;
} }
/* If startup does not exist, create it empty */ /* If startup does not exist, create it empty */
@ -158,7 +158,7 @@ startup_mode_startup(clicon_handle h,
*/ */
if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) {
if ((rollback_exists = xmldb_exists(h, "rollback")) < 0) { if ((rollback_exists = xmldb_exists(h, "rollback")) < 0) {
clicon_err(OE_DAEMON, 0, "Error checking for the existence of the rollback database"); clixon_err(OE_DAEMON, 0, "Error checking for the existence of the rollback database");
goto done; goto done;
} }
if (rollback_exists == 1) { if (rollback_exists == 1) {
@ -211,7 +211,7 @@ startup_mode_startup(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
load_extraxml(clicon_handle h, load_extraxml(clixon_handle h,
char *filename, char *filename,
const char *db, const char *db,
cbuf *cbret) cbuf *cbret)
@ -226,7 +226,7 @@ load_extraxml(clicon_handle h,
if (filename == NULL) if (filename == NULL)
return 1; return 1;
if ((fp = fopen(filename, "r")) == NULL){ if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", filename); clixon_err(OE_UNIX, errno, "open(%s)", filename);
goto done; goto done;
} }
yspec = clicon_dbspec_yang(h); yspec = clicon_dbspec_yang(h);
@ -248,7 +248,6 @@ load_extraxml(clicon_handle h,
retval = 0; retval = 0;
goto done; goto done;
} }
/* Merge user reset state */ /* Merge user reset state */
retval = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret); retval = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret);
done: done:
@ -280,7 +279,7 @@ tmp |-------+-----+-----+
reset extrafile reset extrafile
*/ */
int int
startup_extraxml(clicon_handle h, startup_extraxml(clixon_handle h,
char *file, char *file,
cbuf *cbret) cbuf *cbret)
{ {
@ -352,7 +351,7 @@ startup_extraxml(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
startup_module_state(clicon_handle h, startup_module_state(clixon_handle h,
yang_stmt *yspec) yang_stmt *yspec)
{ {
int retval = -1; int retval = -1;

View file

@ -42,8 +42,8 @@
/* /*
* Prototypes * Prototypes
*/ */
int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret); int startup_mode_startup(clixon_handle h, char *db, cbuf *cbret);
int startup_extraxml(clicon_handle h, char *file, cbuf *cbret); int startup_extraxml(clixon_handle h, char *file, cbuf *cbret);
int startup_module_state(clicon_handle h, yang_stmt *yspec); int startup_module_state(clixon_handle h, yang_stmt *yspec);
#endif /* _BACKEND_STARTUP_H_ */ #endif /* _BACKEND_STARTUP_H_ */

View file

@ -62,7 +62,7 @@ struct client_entry{
int ce_nr; /* Client number (for dbg/tracing) */ int ce_nr; /* Client number (for dbg/tracing) */
uint32_t ce_id; /* Session id, accessor functions: clicon_session_id_get/set */ uint32_t ce_id; /* Session id, accessor functions: clicon_session_id_get/set */
char *ce_username;/* Translated from peer user cred */ char *ce_username;/* Translated from peer user cred */
clicon_handle ce_handle; /* clicon config handle (all clients have same?) */ clixon_handle ce_handle; /* clicon config handle (all clients have same?) */
char *ce_transport; /* Identifies the transport for each session. char *ce_transport; /* Identifies the transport for each session.
Clixon-lib.yang extends these values by prefixing with Clixon-lib.yang extends these values by prefixing with
"cl:", where cl is ensured to be declared ie by "cl:", where cl is ensured to be declared ie by

View file

@ -56,28 +56,28 @@ enum confirmed_commit_state {
* Prototypes * Prototypes
*/ */
/* backend_confirm.c */ /* backend_confirm.c */
int confirmed_commit_init(clicon_handle h); int confirmed_commit_init(clixon_handle h);
int confirmed_commit_free(clicon_handle h); int confirmed_commit_free(clixon_handle h);
enum confirmed_commit_state confirmed_commit_state_get(clicon_handle h); enum confirmed_commit_state confirmed_commit_state_get(clixon_handle h);
uint32_t confirmed_commit_session_id_get(clicon_handle h); uint32_t confirmed_commit_session_id_get(clixon_handle h);
int cancel_rollback_event(clicon_handle h); int cancel_rollback_event(clixon_handle h);
int cancel_confirmed_commit(clicon_handle h); int cancel_confirmed_commit(clixon_handle h);
int handle_confirmed_commit(clicon_handle h, cxobj *xe, uint32_t myid); int handle_confirmed_commit(clixon_handle h, cxobj *xe, uint32_t myid);
int do_rollback(clicon_handle h, uint8_t *errs); int do_rollback(clixon_handle h, uint8_t *errs);
int from_client_cancel_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); int from_client_cancel_commit(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_confirmed_commit(clicon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret); int from_client_confirmed_commit(clixon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret);
/* backend_commit.c */ /* backend_commit.c */
int startup_validate(clicon_handle h, char *db, cxobj **xtr, cbuf *cbret); int startup_validate(clixon_handle h, char *db, cxobj **xtr, cbuf *cbret);
int startup_commit(clicon_handle h, char *db, cbuf *cbret); int startup_commit(clixon_handle h, char *db, cbuf *cbret);
int candidate_validate(clicon_handle h, char *db, cbuf *cbret); int candidate_validate(clixon_handle h, char *db, cbuf *cbret);
int candidate_commit(clicon_handle h, cxobj *xe, char *db, uint32_t myid, int candidate_commit(clixon_handle h, cxobj *xe, char *db, uint32_t myid,
validate_level vlev, cbuf *cbret); validate_level vlev, cbuf *cbret);
int from_client_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); int from_client_commit(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_discard_changes(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); int from_client_discard_changes(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_validate(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); int from_client_validate(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_restart_one(clicon_handle h, clixon_plugin_t *cp, cbuf *cbret); int from_client_restart_one(clixon_handle h, clixon_plugin_t *cp, cbuf *cbret);
int load_failsafe(clicon_handle h, char *phase); int load_failsafe(clixon_handle h, char *phase);
#endif /* _CLIXON_BACKEND_COMMIT_H_ */ #endif /* _CLIXON_BACKEND_COMMIT_H_ */

View file

@ -58,21 +58,21 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_client.h" #include "clixon_backend_client.h"
#include "backend_client.h" #include "backend_client.h"
#include "backend_handle.h" #include "backend_handle.h"
/* header part is copied from struct clicon_handle in lib/src/clicon_handle.c */ /* header part is copied from struct clixon_handle in lib/src/clixon_handle.c */
#define CLICON_MAGIC 0x99aafabe #define CLICON_MAGIC 0x99aafabe
#define handle(h) (assert(clicon_handle_check(h)==0),(struct backend_handle *)(h)) #define handle(h) (assert(clixon_handle_check(h)==0),(struct backend_handle *)(h))
/* Clicon_handle for backends. /* Clixon_handle for backends.
* First part of this is header, same for clicon_handle and cli_handle. * First part of this is header, same for clixon_handle and cli_handle.
* Access functions for common fields are found in clicon lib: clicon_options.[ch] * Access functions for common fields are found in clicon lib: clicon_options.[ch]
* This file should only contain access functions for the _specific_ * This file should only contain access functions for the _specific_
* entries in the struct below. * entries in the struct below.
@ -81,8 +81,8 @@
* *
* This file should only contain access functions for the _specific_ * This file should only contain access functions for the _specific_
* entries in the struct below. * entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c * @note The top part must be equivalent to struct clixon_handle in clixon_handle.c
* @see struct clicon_handle, struct cli_handle * @see struct clixon_handle, struct cli_handle
*/ */
struct backend_handle { struct backend_handle {
int bh_magic; /* magic (HDR)*/ int bh_magic; /* magic (HDR)*/
@ -98,14 +98,14 @@ struct backend_handle {
/*! Creates and returns a clicon config handle for other CLICON API calls /*! Creates and returns a clicon config handle for other CLICON API calls
*/ */
clicon_handle clixon_handle
backend_handle_init(void) backend_handle_init(void)
{ {
struct backend_handle *bh; struct backend_handle *bh;
bh = (struct backend_handle *)clicon_handle_init0(sizeof(struct backend_handle)); bh = (struct backend_handle *)clixon_handle_init0(sizeof(struct backend_handle));
bh->bh_ce_nr = 1; /* To align with session-id */ bh->bh_ce_nr = 1; /* To align with session-id */
return (clicon_handle)bh; return (clixon_handle)bh;
} }
/*! Deallocates a backend handle, including all client structs /*! Deallocates a backend handle, including all client structs
@ -114,7 +114,7 @@ backend_handle_init(void)
* @see backend_client_rm * @see backend_client_rm
*/ */
int int
backend_handle_exit(clicon_handle h) backend_handle_exit(clixon_handle h)
{ {
struct client_entry *ce; struct client_entry *ce;
@ -126,7 +126,7 @@ backend_handle_exit(clicon_handle h)
} }
backend_client_delete(h, ce); backend_client_delete(h, ce);
} }
clicon_handle_exit(h); /* frees h and options (and streams) */ clixon_handle_exit(h); /* frees h and options (and streams) */
return 0; return 0;
} }
@ -138,14 +138,14 @@ backend_handle_exit(clicon_handle h)
* @retval NULL Error * @retval NULL Error
*/ */
struct client_entry * struct client_entry *
backend_client_add(clicon_handle h, backend_client_add(clixon_handle h,
struct sockaddr *addr) struct sockaddr *addr)
{ {
struct backend_handle *bh = handle(h); struct backend_handle *bh = handle(h);
struct client_entry *ce; struct client_entry *ce;
if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){ if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){
clicon_err(OE_PLUGIN, errno, "malloc"); clixon_err(OE_PLUGIN, errno, "malloc");
return NULL; return NULL;
} }
memset(ce, 0, sizeof(*ce)); memset(ce, 0, sizeof(*ce));
@ -154,7 +154,7 @@ backend_client_add(clicon_handle h,
ce->ce_next = bh->bh_ce_list; ce->ce_next = bh->bh_ce_list;
ce->ce_handle = h; ce->ce_handle = h;
if (clicon_session_id_get(h, &ce->ce_id) < 0){ if (clicon_session_id_get(h, &ce->ce_id) < 0){
clicon_err(OE_NETCONF, ENOENT, "session_id not set"); clixon_err(OE_NETCONF, ENOENT, "session_id not set");
return NULL; return NULL;
} }
clicon_session_id_set(h, ce->ce_id + 1); clicon_session_id_set(h, ce->ce_id + 1);
@ -170,7 +170,7 @@ backend_client_add(clicon_handle h,
* @retval ce_list Client entry list (all sessions) * @retval ce_list Client entry list (all sessions)
*/ */
struct client_entry * struct client_entry *
backend_client_list(clicon_handle h) backend_client_list(clixon_handle h)
{ {
struct backend_handle *bh = handle(h); struct backend_handle *bh = handle(h);
@ -184,7 +184,7 @@ backend_client_list(clicon_handle h)
* @see backend_client_rm which is more high-level * @see backend_client_rm which is more high-level
*/ */
int int
backend_client_delete(clicon_handle h, backend_client_delete(clixon_handle h,
struct client_entry *ce) struct client_entry *ce)
{ {
struct client_entry *c; struct client_entry *c;
@ -215,7 +215,7 @@ backend_client_delete(clicon_handle h,
* @param[in] f UNIX output stream * @param[in] f UNIX output stream
*/ */
int int
backend_client_print(clicon_handle h, backend_client_print(clixon_handle h,
FILE *f) FILE *f)
{ {
struct backend_handle *bh = handle(h); struct backend_handle *bh = handle(h);

View file

@ -94,44 +94,44 @@ typedef struct {
/* /*
* Prototypes * Prototypes
*/ */
int clixon_plugin_reset_one(clixon_plugin_t *cp, clicon_handle h, char *db); int clixon_plugin_reset_one(clixon_plugin_t *cp, clixon_handle h, char *db);
int clixon_plugin_reset_all(clicon_handle h, char *db); int clixon_plugin_reset_all(clixon_handle h, char *db);
int clixon_plugin_pre_daemon_all(clicon_handle h); int clixon_plugin_pre_daemon_all(clixon_handle h);
int clixon_plugin_daemon_all(clicon_handle h); int clixon_plugin_daemon_all(clixon_handle h);
int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath, int clixon_plugin_statedata_all(clixon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath,
withdefaults_type wdef, cxobj **xtop); withdefaults_type wdef, cxobj **xtop);
int clixon_plugin_lockdb_all(clicon_handle h, char *db, int lock, int id); int clixon_plugin_lockdb_all(clixon_handle h, char *db, int lock, int id);
int clixon_pagination_cb_register(clicon_handle h, handler_function fn, char *path, void *arg); int clixon_pagination_cb_register(clixon_handle h, handler_function fn, char *path, void *arg);
int clixon_pagination_cb_call(clicon_handle h, char *xpath, int locked, int clixon_pagination_cb_call(clixon_handle h, char *xpath, int locked,
uint32_t offset, uint32_t limit, uint32_t offset, uint32_t limit,
cxobj *xstate); cxobj *xstate);
int clixon_pagination_free(clicon_handle h); int clixon_pagination_free(clixon_handle h);
transaction_data_t * transaction_new(void); transaction_data_t * transaction_new(void);
int transaction_free(transaction_data_t *); int transaction_free(transaction_data_t *);
int plugin_transaction_begin_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_begin_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_begin_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_begin_all(clixon_handle h, transaction_data_t *td);
int plugin_transaction_validate_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_validate_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_validate_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_validate_all(clixon_handle h, transaction_data_t *td);
int plugin_transaction_complete_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_complete_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_complete_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_complete_all(clixon_handle h, transaction_data_t *td);
int plugin_transaction_commit_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_commit_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_commit_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_commit_all(clixon_handle h, transaction_data_t *td);
int plugin_transaction_commit_done_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_commit_done_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_commit_done_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_commit_done_all(clixon_handle h, transaction_data_t *td);
int plugin_transaction_end_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_end_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_end_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_end_all(clixon_handle h, transaction_data_t *td);
int plugin_transaction_abort_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); int plugin_transaction_abort_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td);
int plugin_transaction_abort_all(clicon_handle h, transaction_data_t *td); int plugin_transaction_abort_all(clixon_handle h, transaction_data_t *td);
#endif /* _CLIXON_BACKEND_PLUGIN_H_ */ #endif /* _CLIXON_BACKEND_PLUGIN_H_ */

View file

@ -57,7 +57,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_backend_transaction.h" #include "clixon_backend_transaction.h"
@ -258,7 +258,7 @@ transaction_print(FILE *f,
* @param[in] msg Debug msg tag * @param[in] msg Debug msg tag
*/ */
int int
transaction_dbg(clicon_handle h, transaction_dbg(clixon_handle h,
int dbglevel, int dbglevel,
transaction_data th, transaction_data th,
const char *msg) const char *msg)
@ -270,7 +270,7 @@ transaction_dbg(clicon_handle h,
td = (transaction_data_t *)th; td = (transaction_data_t *)th;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_CFG, errno, "cbuf_new"); clixon_err(OE_CFG, errno, "cbuf_new");
goto done; goto done;
} }
for (i=0; i<td->td_dlen; i++){ for (i=0; i<td->td_dlen; i++){
@ -313,7 +313,7 @@ transaction_dbg(clicon_handle h,
/*! Log a transaction /*! Log a transaction
*/ */
int int
transaction_log(clicon_handle h, transaction_log(clixon_handle h,
transaction_data th, transaction_data th,
int level, int level,
const char *op) const char *op)
@ -325,7 +325,7 @@ transaction_log(clicon_handle h,
td = (transaction_data_t *)th; td = (transaction_data_t *)th;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_CFG, errno, "cbuf_new"); clixon_err(OE_CFG, errno, "cbuf_new");
goto done; goto done;
} }
for (i=0; i<td->td_dlen; i++){ for (i=0; i<td->td_dlen; i++){
@ -334,7 +334,7 @@ transaction_log(clicon_handle h,
goto done; goto done;
} }
if (i) if (i)
clicon_log(level, "%s %" PRIu64 " %s del: %s", clixon_log(h, level, "%s %" PRIu64 " %s del: %s",
__FUNCTION__, td->td_id, op, cbuf_get(cb)); __FUNCTION__, td->td_id, op, cbuf_get(cb));
cbuf_reset(cb); cbuf_reset(cb);
for (i=0; i<td->td_alen; i++){ for (i=0; i<td->td_alen; i++){
@ -343,7 +343,7 @@ transaction_log(clicon_handle h,
goto done; goto done;
} }
if (i) if (i)
clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); clixon_log(h, level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
cbuf_reset(cb); cbuf_reset(cb);
for (i=0; i<td->td_clen; i++){ for (i=0; i<td->td_clen; i++){
if (td->td_scvec){ if (td->td_scvec){
@ -356,7 +356,7 @@ transaction_log(clicon_handle h,
goto done; goto done;
} }
if (i) if (i)
clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); clixon_log(h, level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
done: done:
if (cb) if (cb)
cbuf_free(cb); cbuf_free(cb);

View file

@ -62,8 +62,8 @@ cxobj **transaction_tcvec(transaction_data td);
size_t transaction_clen(transaction_data td); size_t transaction_clen(transaction_data td);
int transaction_print(FILE *f, transaction_data th); int transaction_print(FILE *f, transaction_data th);
int transaction_dbg(clicon_handle h, int dbglevel, transaction_data th, const char *msg); int transaction_dbg(clixon_handle h, int dbglevel, transaction_data th, const char *msg);
int transaction_log(clicon_handle h, transaction_data th, int level, const char *op); int transaction_log(clixon_handle h, transaction_data th, int level, const char *op);
/* Pagination callbacks /* Pagination callbacks

View file

@ -70,7 +70,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_cli_api.h" #include "clixon_cli_api.h"
@ -113,7 +113,7 @@ co2apipath(cg_obj *co)
* code * code
*/ */
int int
cli_auto_edit(clicon_handle h, cli_auto_edit(clixon_handle h,
cvec *cvv1, cvec *cvv1,
cvec *argv) cvec *argv)
{ {
@ -130,7 +130,7 @@ cli_auto_edit(clicon_handle h,
char *mtpoint = NULL; char *mtpoint = NULL;
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){ if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, <treename>)", __FUNCTION__); clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, <treename>)", __FUNCTION__);
goto done; goto done;
} }
api_path_fmt = cv_string_get(cvec_i(argv, argc++)); api_path_fmt = cv_string_get(cvec_i(argv, argc++));
@ -144,7 +144,7 @@ cli_auto_edit(clicon_handle h,
treename = str; treename = str;
/* Find current cligen tree */ /* Find current cligen tree */
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
goto done; goto done;
} }
/* Find the matching cligen object /* Find the matching cligen object
@ -156,19 +156,19 @@ cli_auto_edit(clicon_handle h,
(coorig = co->co_ref) != NULL) (coorig = co->co_ref) != NULL)
cligen_ph_workpoint_set(ph, coorig); cligen_ph_workpoint_set(ph, coorig);
else { else {
clicon_err(OE_YANG, EINVAL, "No workpoint found"); clixon_err(OE_YANG, EINVAL, "No workpoint found");
goto done; goto done;
} }
} }
else{ else{
clicon_err(OE_YANG, EINVAL, "No workpoint found"); clixon_err(OE_YANG, EINVAL, "No workpoint found");
goto done; goto done;
} }
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL) if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
goto done; goto done;
/* API_path format */ /* API_path format */
if ((api_path_fmt = co2apipath(coorig)) == NULL){ if ((api_path_fmt = co2apipath(coorig)) == NULL){
clicon_err(OE_YANG, EINVAL, "No apipath found"); clixon_err(OE_YANG, EINVAL, "No apipath found");
goto done; goto done;
} }
/* get api-path and xpath */ /* get api-path and xpath */
@ -180,7 +180,7 @@ cli_auto_edit(clicon_handle h,
if (mtpoint){ if (mtpoint){
char *mtpoint2; char *mtpoint2;
if ((mtpoint2 = strdup(mtpoint)) == NULL){ if ((mtpoint2 = strdup(mtpoint)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
if (clicon_data_set(h, "cli-edit-mtpoint", mtpoint2) < 0) if (clicon_data_set(h, "cli-edit-mtpoint", mtpoint2) < 0)
@ -191,7 +191,7 @@ cli_auto_edit(clicon_handle h,
if (co->co_filter){ if (co->co_filter){
cvec *cvv3; cvec *cvv3;
if ((cvv3 = cvec_dup(co->co_filter)) == NULL){ if ((cvv3 = cvec_dup(co->co_filter)) == NULL){
clicon_err(OE_YANG, errno, "cvec_dup"); clixon_err(OE_YANG, errno, "cvec_dup");
goto done; goto done;
} }
if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0) if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0)
@ -215,7 +215,7 @@ cli_auto_edit(clicon_handle h,
* <treename> Name of generated cligen parse-tree, eg "datamodel" * <treename> Name of generated cligen parse-tree, eg "datamodel"
*/ */
int int
cli_auto_up(clicon_handle h, cli_auto_up(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -236,13 +236,13 @@ cli_auto_up(clicon_handle h,
cvec *cvv_filter = NULL; cvec *cvv_filter = NULL;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__); clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
goto done; goto done;
} }
cv = cvec_i(argv, 0); cv = cvec_i(argv, 0);
treename = cv_string_get(cv); treename = cv_string_get(cv);
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
goto done; goto done;
} }
if ((co0 = cligen_ph_workpoint_get(ph)) == NULL) if ((co0 = cligen_ph_workpoint_get(ph)) == NULL)
@ -313,7 +313,7 @@ cli_auto_up(clicon_handle h,
* <treename> Name of generated cligen parse-tree, eg "datamodel" * <treename> Name of generated cligen parse-tree, eg "datamodel"
*/ */
int int
cli_auto_top(clicon_handle h, cli_auto_top(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -325,7 +325,7 @@ cli_auto_top(clicon_handle h,
cv = cvec_i(argv, 0); cv = cvec_i(argv, 0);
treename = cv_string_get(cv); treename = cv_string_get(cv);
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
goto done; goto done;
} }
cligen_ph_workpoint_set(ph, NULL); cligen_ph_workpoint_set(ph, NULL);
@ -349,7 +349,7 @@ cli_auto_top(clicon_handle h,
* <api-path-fmt> Generated * <api-path-fmt> Generated
*/ */
int int
cli_auto_set(clicon_handle h, cli_auto_set(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -375,7 +375,7 @@ cli_auto_set(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_auto_merge(clicon_handle h, cli_auto_merge(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -401,7 +401,7 @@ cli_auto_merge(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_auto_create(clicon_handle h, cli_auto_create(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -427,7 +427,7 @@ cli_auto_create(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_auto_del(clicon_handle h, cli_auto_del(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -492,7 +492,7 @@ cli_auto_findpt(cg_obj *co,
* @see cli_auto_edit * @see cli_auto_edit
*/ */
int int
cli_auto_sub_enter(clicon_handle h, cli_auto_sub_enter(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -508,7 +508,7 @@ cli_auto_sub_enter(clicon_handle h,
struct findpt_arg fa = {0,}; struct findpt_arg fa = {0,};
if (cvec_len(argv) < 2){ if (cvec_len(argv) < 2){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__); clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__);
goto done; goto done;
} }
/* First argv argument: treename */ /* First argv argument: treename */
@ -527,7 +527,7 @@ cli_auto_sub_enter(clicon_handle h,
*/ */
/* Create a cvv with variables to add to api-path */ /* Create a cvv with variables to add to api-path */
if ((cvv1 = cvec_new(0)) == NULL){ if ((cvv1 = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
/* Append static variables (skip first treename) */ /* Append static variables (skip first treename) */
@ -552,7 +552,7 @@ cli_auto_sub_enter(clicon_handle h,
goto done; goto done;
/* Find current cligen tree */ /* Find current cligen tree */
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename); clixon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename);
goto done; goto done;
} }
/* Find the point in the generated clispec tree where workpoint should be set */ /* Find the point in the generated clispec tree where workpoint should be set */
@ -560,7 +560,7 @@ cli_auto_sub_enter(clicon_handle h,
if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, INT32_MAX, &fa) < 0) if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, INT32_MAX, &fa) < 0)
goto done; goto done;
if (fa.fa_co == NULL){ if (fa.fa_co == NULL){
clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path); clixon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path);
goto done; goto done;
} }
cligen_ph_workpoint_set(ph, fa.fa_co); cligen_ph_workpoint_set(ph, fa.fa_co);

View file

@ -110,7 +110,7 @@ autocli_listkw_int2str(int listkw)
* @retval -1 Error * @retval -1 Error
*/ */
int int
autocli_module(clicon_handle h, autocli_module(clixon_handle h,
char *modname, char *modname,
int *enablep) int *enablep)
{ {
@ -124,7 +124,7 @@ autocli_module(clicon_handle h,
char *body; char *body;
if (enablep == NULL){ if (enablep == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
enable = 0; enable = 0;
@ -132,7 +132,7 @@ autocli_module(clicon_handle h,
goto ok; goto ok;
/* Default rule */ /* Default rule */
if ((str = xml_find_body(xautocli, "module-default")) == NULL){ if ((str = xml_find_body(xautocli, "module-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No module-default rule"); clixon_err(OE_XML, EINVAL, "No module-default rule");
goto done; goto done;
} }
enable = strcmp(str, "true") == 0; enable = strcmp(str, "true") == 0;
@ -243,7 +243,7 @@ The surrounding container entities are removed from list nodes.
- Only one child + Child keyword is LIST - Only one child + Child keyword is LIST
*/ */
int int
autocli_compress(clicon_handle h, autocli_compress(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int *compress) int *compress)
{ {
@ -262,11 +262,11 @@ autocli_compress(clicon_handle h,
char *body; char *body;
if (compress == NULL){ if (compress == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
if ((xautocli = clicon_conf_autocli(h)) == NULL){ if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli"); clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done; goto done;
} }
ymod = ys_module(ys); ymod = ys_module(ys);
@ -349,7 +349,7 @@ autocli_compress(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
autocli_completion(clicon_handle h, autocli_completion(clixon_handle h,
int *completion) int *completion)
{ {
int retval = -1; int retval = -1;
@ -360,19 +360,19 @@ autocli_completion(clicon_handle h,
cxobj *xautocli; cxobj *xautocli;
if (completion == NULL){ if (completion == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
if ((xautocli = clicon_conf_autocli(h)) == NULL){ if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli"); clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done; goto done;
} }
if ((str = xml_find_body(xautocli, "completion-default")) == NULL){ if ((str = xml_find_body(xautocli, "completion-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No completion-default rule"); clixon_err(OE_XML, EINVAL, "No completion-default rule");
goto done; goto done;
} }
if ((ret = parse_bool(str, &val, &reason)) < 0){ if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool"); clixon_err(OE_CFG, errno, "parse_bool");
goto done; goto done;
} }
*completion = val; *completion = val;
@ -392,7 +392,7 @@ autocli_completion(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
autocli_grouping_treeref(clicon_handle h, autocli_grouping_treeref(clixon_handle h,
int *treeref) int *treeref)
{ {
int retval = -1; int retval = -1;
@ -403,19 +403,19 @@ autocli_grouping_treeref(clicon_handle h,
cxobj *xautocli; cxobj *xautocli;
if (treeref == NULL){ if (treeref == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
if ((xautocli = clicon_conf_autocli(h)) == NULL){ if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli"); clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done; goto done;
} }
if ((str = xml_find_body(xautocli, "grouping-treeref")) == NULL){ if ((str = xml_find_body(xautocli, "grouping-treeref")) == NULL){
clicon_err(OE_XML, EINVAL, "No grouping-treeref rule"); clixon_err(OE_XML, EINVAL, "No grouping-treeref rule");
goto done; goto done;
} }
if ((ret = parse_bool(str, &val, &reason)) < 0){ if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool"); clixon_err(OE_CFG, errno, "parse_bool");
goto done; goto done;
} }
*treeref = val; *treeref = val;
@ -435,7 +435,7 @@ autocli_grouping_treeref(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
autocli_list_keyword(clicon_handle h, autocli_list_keyword(clixon_handle h,
autocli_listkw_t *listkw) autocli_listkw_t *listkw)
{ {
int retval = -1; int retval = -1;
@ -443,15 +443,15 @@ autocli_list_keyword(clicon_handle h,
cxobj *xautocli = NULL; cxobj *xautocli = NULL;
if (listkw == NULL){ if (listkw == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
if ((xautocli = clicon_conf_autocli(h)) == NULL){ if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli"); clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done; goto done;
} }
if ((str = xml_find_body(xautocli, "list-keyword-default")) == NULL){ if ((str = xml_find_body(xautocli, "list-keyword-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No list-keyword-default rule"); clixon_err(OE_XML, EINVAL, "No list-keyword-default rule");
goto done; goto done;
} }
*listkw = autocli_listkw_str2int(str); *listkw = autocli_listkw_str2int(str);
@ -468,7 +468,7 @@ autocli_list_keyword(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
autocli_treeref_state(clicon_handle h, autocli_treeref_state(clixon_handle h,
int *treeref_state) int *treeref_state)
{ {
int retval = -1; int retval = -1;
@ -479,19 +479,19 @@ autocli_treeref_state(clicon_handle h,
cxobj *xautocli; cxobj *xautocli;
if (treeref_state == NULL){ if (treeref_state == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
if ((xautocli = clicon_conf_autocli(h)) == NULL){ if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli"); clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done; goto done;
} }
if ((str = xml_find_body(xautocli, "treeref-state-default")) == NULL){ if ((str = xml_find_body(xautocli, "treeref-state-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No treeref-state-default rule"); clixon_err(OE_XML, EINVAL, "No treeref-state-default rule");
goto done; goto done;
} }
if ((ret = parse_bool(str, &val, &reason)) < 0){ if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool"); clixon_err(OE_CFG, errno, "parse_bool");
goto done; goto done;
} }
*treeref_state = val; *treeref_state = val;
@ -512,7 +512,7 @@ autocli_treeref_state(clicon_handle h,
* @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined * @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined
*/ */
int int
autocli_edit_mode(clicon_handle h, autocli_edit_mode(clixon_handle h,
char *keyw, char *keyw,
int *flag) int *flag)
{ {
@ -525,16 +525,16 @@ autocli_edit_mode(clicon_handle h,
int i; int i;
if (flag == NULL){ if (flag == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL"); clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done; goto done;
} }
*flag = 0; *flag = 0;
if ((xautocli = clicon_conf_autocli(h)) == NULL){ if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli"); clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done; goto done;
} }
if ((str = xml_find_body(xautocli, "edit-mode-default")) == NULL){ if ((str = xml_find_body(xautocli, "edit-mode-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No edit-mode-default rule"); clixon_err(OE_XML, EINVAL, "No edit-mode-default rule");
goto done; goto done;
} }
if ((vec = clicon_strsep(str, " ", &nvec)) == NULL) if ((vec = clicon_strsep(str, " ", &nvec)) == NULL)

View file

@ -50,12 +50,12 @@ enum autocli_op{
/* /*
* Prototypes * Prototypes
*/ */
int autocli_module(clicon_handle h, char *modname, int *enable); int autocli_module(clixon_handle h, char *modname, int *enable);
int autocli_completion(clicon_handle h, int *completion); int autocli_completion(clixon_handle h, int *completion);
int autocli_grouping_treeref(clicon_handle h, int *grouping_treeref); int autocli_grouping_treeref(clixon_handle h, int *grouping_treeref);
int autocli_list_keyword(clicon_handle h, autocli_listkw_t *listkw); int autocli_list_keyword(clixon_handle h, autocli_listkw_t *listkw);
int autocli_compress(clicon_handle h, yang_stmt *ys, int *compress); int autocli_compress(clixon_handle h, yang_stmt *ys, int *compress);
int autocli_treeref_state(clicon_handle h, int *treeref_state); int autocli_treeref_state(clixon_handle h, int *treeref_state);
int autocli_edit_mode(clicon_handle h, char *keyw, int *flag); int autocli_edit_mode(clixon_handle h, char *keyw, int *flag);
#endif /* _CLI_AUTOCLI_H_ */ #endif /* _CLI_AUTOCLI_H_ */

View file

@ -64,7 +64,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_cli_api.h" #include "clixon_cli_api.h"
@ -84,7 +84,7 @@
* @note this calls cligen_regfd which may callback on cli command interpretator * @note this calls cligen_regfd which may callback on cli command interpretator
*/ */
int int
cli_notification_register(clicon_handle h, cli_notification_register(clixon_handle h,
char *stream, char *stream,
enum format_enum format, enum format_enum format,
char *filter, char *filter,
@ -102,7 +102,7 @@ cli_notification_register(clicon_handle h,
len = strlen("log_socket_") + strlen(stream) + 1; len = strlen("log_socket_") + strlen(stream) + 1;
if ((logname = malloc(len)) == NULL){ if ((logname = malloc(len)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
snprintf(logname, len, "log_socket_%s", stream); snprintf(logname, len, "log_socket_%s", stream);
@ -111,7 +111,7 @@ cli_notification_register(clicon_handle h,
if (status){ /* start */ if (status){ /* start */
if (s_exist!=-1){ if (s_exist!=-1){
clicon_err(OE_PLUGIN, 0, "Result log socket already exists"); clixon_err(OE_PLUGIN, 0, "Result log socket already exists");
goto done; goto done;
} }
if (clicon_rpc_create_subscription(h, stream, filter, &s) < 0) if (clicon_rpc_create_subscription(h, stream, filter, &s) < 0)
@ -142,7 +142,7 @@ cli_notification_register(clicon_handle h,
* This is for CLIgen to handle these signals, eg ^Ĉ means abort command, not program * This is for CLIgen to handle these signals, eg ^Ĉ means abort command, not program
*/ */
void void
cli_signal_block(clicon_handle h) cli_signal_block(clixon_handle h)
{ {
clicon_signal_block (SIGTSTP); clicon_signal_block (SIGTSTP);
clicon_signal_block (SIGQUIT); clicon_signal_block (SIGQUIT);
@ -152,7 +152,7 @@ cli_signal_block(clicon_handle h)
} }
void void
cli_signal_unblock(clicon_handle h) cli_signal_unblock(clixon_handle h)
{ {
clicon_signal_unblock (SIGTSTP); clicon_signal_unblock (SIGTSTP);
clicon_signal_unblock (SIGQUIT); clicon_signal_unblock (SIGQUIT);
@ -164,7 +164,7 @@ cli_signal_unblock(clicon_handle h)
* Flush pending signals for a given signal type * Flush pending signals for a given signal type
*/ */
void void
cli_signal_flush(clicon_handle h) cli_signal_flush(clixon_handle h)
{ {
/* XXX A bit rough. Use sigpending() and more clever logic ?? */ /* XXX A bit rough. Use sigpending() and more clever logic ?? */
@ -207,7 +207,7 @@ dbxml_body(cxobj *xbot,
len = cvec_len(cvv); len = cvec_len(cvv);
cval = cvec_i(cvv, len-1); cval = cvec_i(cvv, len-1);
if ((str = cv2str_dup(cval)) == NULL){ if ((str = cv2str_dup(cval)) == NULL){
clicon_err(OE_UNIX, errno, "cv2str_dup"); clixon_err(OE_UNIX, errno, "cv2str_dup");
goto done; goto done;
} }
if ((xb = xml_new("body", xbot, CX_BODY)) == NULL) if ((xb = xml_new("body", xbot, CX_BODY)) == NULL)
@ -307,25 +307,25 @@ mtpoint_paths(yang_stmt *yspec0,
yang_stmt *yspec1; yang_stmt *yspec1;
if (api_path_fmt01 == NULL){ if (api_path_fmt01 == NULL){
clicon_err(OE_FATAL, EINVAL, "arg is NULL"); clixon_err(OE_FATAL, EINVAL, "arg is NULL");
goto done; goto done;
} }
if ((xtop0 = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL) if ((xtop0 = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (yang_path_arg(yspec0, mtpoint, &yu) < 0) if (yang_path_arg(yspec0, mtpoint, &yu) < 0)
goto done; goto done;
if (yu == NULL){ if (yu == NULL){
clicon_err(OE_FATAL, 0, "yu not found"); clixon_err(OE_FATAL, 0, "yu not found");
goto done; goto done;
} }
if (yang_mount_get(yu, mtpoint, &yspec1) < 0) if (yang_mount_get(yu, mtpoint, &yspec1) < 0)
goto done; goto done;
if (yspec1 == NULL){ if (yspec1 == NULL){
clicon_err(OE_FATAL, 0, "yspec1 not found"); clixon_err(OE_FATAL, 0, "yspec1 not found");
goto done; goto done;
} }
xbot0 = xtop0; xbot0 = xtop0;
@ -334,18 +334,18 @@ mtpoint_paths(yang_stmt *yspec0,
if ((ret = xpath2xml(mtpoint, nsc0, xtop0, yspec0, &xbot0, &ybot0, NULL)) < 0) if ((ret = xpath2xml(mtpoint, nsc0, xtop0, yspec0, &xbot0, &ybot0, NULL)) < 0)
goto done; goto done;
if (xbot0 == NULL){ if (xbot0 == NULL){
clicon_err(OE_YANG, 0, "No xbot"); clixon_err(OE_YANG, 0, "No xbot");
goto done; goto done;
} }
if (yang2api_path_fmt(ybot0, 0, &api_path_fmt0) < 0) if (yang2api_path_fmt(ybot0, 0, &api_path_fmt0) < 0)
goto done; goto done;
if (api_path_fmt0 == NULL){ if (api_path_fmt0 == NULL){
clicon_err(OE_YANG, 0, "No api_path_fmt0"); clixon_err(OE_YANG, 0, "No api_path_fmt0");
goto done; goto done;
} }
cprintf(cb, "%s%s", api_path_fmt0, api_path_fmt1); cprintf(cb, "%s%s", api_path_fmt0, api_path_fmt1);
if ((*api_path_fmt01 = strdup(cbuf_get(cb))) == NULL){ if ((*api_path_fmt01 = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_YANG, errno, "strdup"); clixon_err(OE_YANG, errno, "strdup");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -386,7 +386,7 @@ mtpoint_paths(yang_stmt *yspec0,
* generated by a function such as clixon_instance_id_bind() or other programmatically. * generated by a function such as clixon_instance_id_bind() or other programmatically.
*/ */
int int
cli_dbxml(clicon_handle h, cli_dbxml(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv, cvec *argv,
enum operation_type op, enum operation_type op,
@ -412,11 +412,11 @@ cli_dbxml(clicon_handle h,
/* Top-level yspec */ /* Top-level yspec */
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if ((api_path_fmt_cb = cbuf_new()) == NULL){ if ((api_path_fmt_cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* Concatenate all argv strings to a single string */ /* Concatenate all argv strings to a single string */
@ -428,7 +428,7 @@ cli_dbxml(clicon_handle h,
cv = cvec_i(argv, argc++); cv = cvec_i(argv, argc++);
str = cv_string_get(cv); str = cv_string_get(cv);
if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){ if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){
clicon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'"); clixon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'");
goto done; goto done;
} }
mtpoint = str + strlen("mtpoint:"); mtpoint = str + strlen("mtpoint:");
@ -463,13 +463,12 @@ cli_dbxml(clicon_handle h,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "api-path syntax error \"%s\": ", api_path_fmt);
if (netconf_err2cb(h, xerr, cb) < 0) if (netconf_err2cb(h, xerr, cb) < 0)
goto done; goto done;
clicon_err(OE_CFG, EINVAL, "%s", cbuf_get(cb)); clixon_err(OE_CFG, EINVAL, "api-path syntax error \"%s\": %s", api_path_fmt, cbuf_get(cb));
goto done; goto done;
} }
} }
@ -504,7 +503,7 @@ cli_dbxml(clicon_handle h,
if ((ret = xml_apply0(xbot, CX_ELMNT, identityref_add_ns, yspec0)) < 0) if ((ret = xml_apply0(xbot, CX_ELMNT, identityref_add_ns, yspec0)) < 0)
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0)
@ -537,7 +536,7 @@ cli_dbxml(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_set(clicon_handle h, cli_set(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -559,7 +558,7 @@ cli_set(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_merge(clicon_handle h, cli_merge(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -581,7 +580,7 @@ cli_merge(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_create(clicon_handle h, cli_create(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -604,7 +603,7 @@ cli_create(clicon_handle h,
* @see cli_del * @see cli_del
*/ */
int int
cli_remove(clicon_handle h, cli_remove(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -626,7 +625,7 @@ cli_remove(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_del(clicon_handle h, cli_del(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -650,7 +649,7 @@ cli_del(clicon_handle h,
* _or_ if a 'level' variable is present in cvv use that value instead. * _or_ if a 'level' variable is present in cvv use that value instead.
*/ */
int int
cli_debug_cli(clicon_handle h, cli_debug_cli(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -660,14 +659,14 @@ cli_debug_cli(clicon_handle h,
if ((cv = cvec_find_var(cvv, "level")) == NULL){ if ((cv = cvec_find_var(cvv, "level")) == NULL){
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
goto done; goto done;
} }
cv = cvec_i(argv, 0); cv = cvec_i(argv, 0);
} }
level = cv_int32_get(cv); level = cv_int32_get(cv);
/* cli */ /* cli */
clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ clixon_debug_init(h, level); /* 0: dont debug, 1:debug */
retval = 0; retval = 0;
done: done:
return retval; return retval;
@ -684,7 +683,7 @@ cli_debug_cli(clicon_handle h,
* _or_ if a 'level' variable is present in cvv use that value instead. * _or_ if a 'level' variable is present in cvv use that value instead.
*/ */
int int
cli_debug_backend(clicon_handle h, cli_debug_backend(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -694,7 +693,7 @@ cli_debug_backend(clicon_handle h,
if ((cv = cvec_find_var(cvv, "level")) == NULL){ if ((cv = cvec_find_var(cvv, "level")) == NULL){
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
goto done; goto done;
} }
cv = cvec_i(argv, 0); cv = cvec_i(argv, 0);
@ -721,7 +720,7 @@ cli_debug_backend(clicon_handle h,
* 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf) * 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf)
*/ */
int int
cli_debug_restconf(clicon_handle h, cli_debug_restconf(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -731,7 +730,7 @@ cli_debug_restconf(clicon_handle h,
if ((cv = cvec_find_var(cvv, "level")) == NULL){ if ((cv = cvec_find_var(cvv, "level")) == NULL){
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
goto done; goto done;
} }
cv = cvec_i(argv, 0); cv = cvec_i(argv, 0);
@ -753,7 +752,7 @@ cli_debug_restconf(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_set_mode(clicon_handle h, cli_set_mode(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -761,7 +760,7 @@ cli_set_mode(clicon_handle h,
char *str = NULL; char *str = NULL;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode"); clixon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode");
goto done; goto done;
} }
str = cv_string_get(cvec_i(argv, 0)); str = cv_string_get(cvec_i(argv, 0));
@ -781,7 +780,7 @@ cli_set_mode(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_start_shell(clicon_handle h, cli_start_shell(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -795,7 +794,7 @@ cli_start_shell(clicon_handle h,
struct sigaction oldsigaction[32] = {{{0,},},}; struct sigaction oldsigaction[32] = {{{0,},},};
if (cvec_len(argv) > 1){ if (cvec_len(argv) > 1){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [<shell>]", clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [<shell>]",
cvec_len(argv)); cvec_len(argv));
goto done; goto done;
} }
@ -804,11 +803,11 @@ cli_start_shell(clicon_handle h,
} }
cmd = (cvec_len(cvv)>1 ? cv_string_get(cv1) : NULL); cmd = (cvec_len(cvv)>1 ? cv_string_get(cv1) : NULL);
if ((pw = getpwuid(getuid())) == NULL){ if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid"); clixon_err(OE_UNIX, errno, "getpwuid");
goto done; goto done;
} }
if (chdir(pw->pw_dir) < 0){ if (chdir(pw->pw_dir) < 0){
clicon_err(OE_UNIX, errno, "chdir"); clixon_err(OE_UNIX, errno, "chdir");
endpwent(); endpwent();
goto done; goto done;
} }
@ -822,7 +821,7 @@ cli_start_shell(clicon_handle h,
snprintf(bcmd, 128, "%s -c \"%s\"", shcmd, cmd); snprintf(bcmd, 128, "%s -c \"%s\"", shcmd, cmd);
if (system(bcmd) < 0){ if (system(bcmd) < 0){
cli_signal_block(h); cli_signal_block(h);
clicon_err(OE_UNIX, errno, "system(bash -c)"); clixon_err(OE_UNIX, errno, "system(bash -c)");
goto done; goto done;
} }
} }
@ -830,14 +829,14 @@ cli_start_shell(clicon_handle h,
snprintf(bcmd, 128, "%s ", shcmd); /* -l (login shell) but is applicable to bash only */ snprintf(bcmd, 128, "%s ", shcmd); /* -l (login shell) but is applicable to bash only */
if (system(bcmd) < 0){ if (system(bcmd) < 0){
cli_signal_block(h); cli_signal_block(h);
clicon_err(OE_UNIX, errno, "system(bash)"); clixon_err(OE_UNIX, errno, "system(bash)");
goto done; goto done;
} }
} }
cli_signal_block(h); cli_signal_block(h);
#if 0 /* Allow errcodes from bash */ #if 0 /* Allow errcodes from bash */
if (retval != 0){ if (retval != 0){
clicon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval); clixon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval);
goto done; goto done;
} }
#endif #endif
@ -857,7 +856,7 @@ cli_start_shell(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_quit(clicon_handle h, cli_quit(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -874,7 +873,7 @@ cli_quit(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_commit(clicon_handle h, cli_commit(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -909,7 +908,7 @@ cli_commit(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_validate(clicon_handle h, cli_validate(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -932,7 +931,7 @@ cli_validate(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
compare_db_names(clicon_handle h, compare_db_names(clixon_handle h,
enum format_enum format, enum format_enum format,
char *db1, char *db1,
char *db2) char *db2)
@ -946,13 +945,23 @@ compare_db_names(clicon_handle h,
if (clicon_rpc_get_config(h, NULL, db1, "/", NULL, NULL, &xc1) < 0) if (clicon_rpc_get_config(h, NULL, db1, "/", NULL, NULL, &xc1) < 0)
goto done; goto done;
if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_netconf_error(h, xerr, "Get configuration", NULL);
#endif
goto done; goto done;
} }
if (clicon_rpc_get_config(h, NULL, db2, "/", NULL, NULL, &xc2) < 0) if (clicon_rpc_get_config(h, NULL, db2, "/", NULL, NULL, &xc2) < 0)
goto done; goto done;
if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_netconf_error(h, xerr, "Get configuration", NULL);
#endif
goto done; goto done;
} }
/* Note that XML and TEXT uses a (new) structured in-mem algorithm while /* Note that XML and TEXT uses a (new) structured in-mem algorithm while
@ -961,7 +970,7 @@ compare_db_names(clicon_handle h,
switch (format){ switch (format){
case FORMAT_XML: case FORMAT_XML:
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml_diff2cbuf(cb, xc1, xc2) < 0) if (clixon_xml_diff2cbuf(cb, xc1, xc2) < 0)
@ -970,7 +979,7 @@ compare_db_names(clicon_handle h,
break; break;
case FORMAT_TEXT: case FORMAT_TEXT:
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_text_diff2cbuf(cb, xc1, xc2) < 0) if (clixon_text_diff2cbuf(cb, xc1, xc2) < 0)
@ -1004,7 +1013,7 @@ compare_db_names(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
compare_dbs(clicon_handle h, compare_dbs(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1015,14 +1024,14 @@ compare_dbs(clicon_handle h,
char *formatstr; char *formatstr;
if (cvec_len(argv) != 3){ if (cvec_len(argv) != 3){
clicon_err(OE_PLUGIN, EINVAL, "Expected arguments: <db1> <db2> <format>"); clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: <db1> <db2> <format>");
goto done; goto done;
} }
db1 = cv_string_get(cvec_i(argv, 0)); db1 = cv_string_get(cvec_i(argv, 0));
db2 = cv_string_get(cvec_i(argv, 1)); db2 = cv_string_get(cvec_i(argv, 1));
formatstr = cv_string_get(cvec_i(argv, 2)); formatstr = cv_string_get(cvec_i(argv, 2));
if ((format = format_str2int(formatstr)) < 0){ if ((format = format_str2int(formatstr)) < 0){
clicon_err(OE_XML, 0, "format not found %s", formatstr); clixon_err(OE_XML, 0, "format not found %s", formatstr);
goto done; goto done;
} }
if (compare_db_names(h, format, db1, db2) < 0) if (compare_db_names(h, format, db1, db2) < 0)
@ -1054,7 +1063,7 @@ compare_dbs(clicon_handle h,
* @see save_config_file * @see save_config_file
*/ */
int int
load_config_file(clicon_handle h, load_config_file(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1076,18 +1085,18 @@ load_config_file(clicon_handle h,
char *lineptr = NULL; char *lineptr = NULL;
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){ if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]", clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
cvec_len(argv)); cvec_len(argv));
goto done; goto done;
} }
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if (cvec_len(argv) > 2){ if (cvec_len(argv) > 2){
formatstr = cv_string_get(cvec_i(argv, 2)); formatstr = cv_string_get(cvec_i(argv, 2));
if ((int)(format = format_str2int(formatstr)) < 0){ if ((int)(format = format_str2int(formatstr)) < 0){
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
goto done; goto done;
} }
} }
@ -1098,21 +1107,21 @@ load_config_file(clicon_handle h,
else if (strcmp(opstr, "replace") == 0) else if (strcmp(opstr, "replace") == 0)
replace = 1; replace = 1;
else{ else{
clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr); clixon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr);
goto done; goto done;
} }
if ((cv = cvec_find(cvv, varstr)) == NULL){ if ((cv = cvec_find(cvv, varstr)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); clixon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
goto done; goto done;
} }
filename = cv_string_get(cv); filename = cv_string_get(cv);
if (stat(filename, &st) < 0){ if (stat(filename, &st) < 0){
clicon_err(OE_UNIX, errno, "load_config: stat(%s)", filename); clixon_err(OE_UNIX, errno, "load_config: stat(%s)", filename);
goto done; goto done;
} }
/* Open and parse local file into xml */ /* Open and parse local file into xml */
if ((fp = fopen(filename, "r")) == NULL){ if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "fopen(%s)", filename); clixon_err(OE_UNIX, errno, "fopen(%s)", filename);
goto done; goto done;
} }
switch (format){ switch (format){
@ -1120,7 +1129,12 @@ load_config_file(clicon_handle h,
if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0) if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Loading", filename); clixon_netconf_error(h, xerr, "Loading", filename);
#endif
goto done; goto done;
} }
break; break;
@ -1128,7 +1142,12 @@ load_config_file(clicon_handle h,
if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0) if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Loading", filename); clixon_netconf_error(h, xerr, "Loading", filename);
#endif
goto done; goto done;
} }
break; break;
@ -1139,7 +1158,12 @@ load_config_file(clicon_handle h,
if ((ret = clixon_text_syntax_parse_file(fp, YB_MODULE_NEXT, yspec, &xt, &xerr)) < 0) if ((ret = clixon_text_syntax_parse_file(fp, YB_MODULE_NEXT, yspec, &xt, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Loading", filename); clixon_netconf_error(h, xerr, "Loading", filename);
#endif
goto done; goto done;
} }
break; break;
@ -1154,7 +1178,7 @@ load_config_file(clicon_handle h,
lineptr = NULL; n = 0; lineptr = NULL; n = 0;
if (getline(&lineptr, &n, fp) < 0){ if (getline(&lineptr, &n, fp) < 0){
if (errno){ if (errno){
clicon_err(OE_UNIX, errno, "getline"); clixon_err(OE_UNIX, errno, "getline");
goto done; goto done;
} }
goto ok; /* eof, skip backend rpc since this is done by cli code */ goto ok; /* eof, skip backend rpc since this is done by cli code */
@ -1173,16 +1197,18 @@ load_config_file(clicon_handle h,
break; break;
} }
default: default:
clicon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr); clixon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr);
goto done; goto done;
break; break;
} }
if (xt == NULL) if (xt == NULL)
goto done; goto done;
if ((cbxml = cbuf_new()) == NULL) if ((cbxml = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
}
x = NULL; x = NULL;
while ((x = xml_child_each(xt, x, -1)) != NULL) { while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
/* Read as datastore-top but transformed into an edit-config "config" */ /* Read as datastore-top but transformed into an edit-config "config" */
xml_name_set(x, NETCONF_INPUT_CONFIG); xml_name_set(x, NETCONF_INPUT_CONFIG);
} }
@ -1228,7 +1254,7 @@ load_config_file(clicon_handle h,
* @see load_config_file * @see load_config_file
*/ */
int int
save_config_file(clicon_handle h, save_config_file(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1246,14 +1272,14 @@ save_config_file(clicon_handle h,
int pretty = 1; /* XXX hardcoded */ int pretty = 1; /* XXX hardcoded */
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){ if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]", clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
cvec_len(argv)); cvec_len(argv));
goto done; goto done;
} }
if (cvec_len(argv) > 2){ if (cvec_len(argv) > 2){
formatstr = cv_string_get(cvec_i(argv, 2)); formatstr = cv_string_get(cvec_i(argv, 2));
if ((int)(format = format_str2int(formatstr)) < 0){ if ((int)(format = format_str2int(formatstr)) < 0){
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
goto done; goto done;
} }
} }
@ -1261,23 +1287,28 @@ save_config_file(clicon_handle h,
if (strcmp(dbstr, "running") != 0 && if (strcmp(dbstr, "running") != 0 &&
strcmp(dbstr, "candidate") != 0 && strcmp(dbstr, "candidate") != 0 &&
strcmp(dbstr, "startup") != 0) { strcmp(dbstr, "startup") != 0) {
clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); clixon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
goto done; goto done;
} }
varstr = cv_string_get(cvec_i(argv, 1)); varstr = cv_string_get(cvec_i(argv, 1));
if ((cv = cvec_find(cvv, varstr)) == NULL){ if ((cv = cvec_find(cvv, varstr)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); clixon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
goto done; goto done;
} }
filename = cv_string_get(cv); filename = cv_string_get(cv);
if (clicon_rpc_get_config(h, NULL, dbstr,"/", NULL, NULL, &xt) < 0) if (clicon_rpc_get_config(h, NULL, dbstr,"/", NULL, NULL, &xt) < 0)
goto done; goto done;
if (xt == NULL){ if (xt == NULL){
clicon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */ clixon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */
goto done; goto done;
} }
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_netconf_error(h, xerr, "Get configuration", NULL);
#endif
goto done; goto done;
} }
/* get-config returns a <data> tree. Save as <config> tree so it can be used /* get-config returns a <data> tree. Save as <config> tree so it can be used
@ -1286,7 +1317,7 @@ save_config_file(clicon_handle h,
if (xml_name_set(xt, DATASTORE_TOP_SYMBOL) < 0) if (xml_name_set(xt, DATASTORE_TOP_SYMBOL) < 0)
goto done; goto done;
if ((f = fopen(filename, "w")) == NULL){ if ((f = fopen(filename, "w")) == NULL){
clicon_err(OE_CFG, errno, "Creating file %s", filename); clixon_err(OE_CFG, errno, "Creating file %s", filename);
goto done; goto done;
} }
switch (format){ switch (format){
@ -1335,7 +1366,7 @@ save_config_file(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
delete_all(clicon_handle h, delete_all(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1343,14 +1374,14 @@ delete_all(clicon_handle h,
int retval = -1; int retval = -1;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname"); clixon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname");
goto done; goto done;
} }
dbstr = cv_string_get(cvec_i(argv, 0)); dbstr = cv_string_get(cvec_i(argv, 0));
if (strcmp(dbstr, "running") != 0 && if (strcmp(dbstr, "running") != 0 &&
strcmp(dbstr, "candidate") != 0 && strcmp(dbstr, "candidate") != 0 &&
strcmp(dbstr, "startup") != 0){ strcmp(dbstr, "startup") != 0){
clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); clixon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
goto done; goto done;
} }
if (clicon_rpc_delete_config(h, dbstr) < 0) if (clicon_rpc_delete_config(h, dbstr) < 0)
@ -1363,7 +1394,7 @@ delete_all(clicon_handle h,
/*! Discard all changes in candidate and replace with running /*! Discard all changes in candidate and replace with running
*/ */
int int
discard_changes(clicon_handle h, discard_changes(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1377,7 +1408,7 @@ discard_changes(clicon_handle h,
* @retval -1 Error and logged to syslog * @retval -1 Error and logged to syslog
*/ */
int int
db_copy(clicon_handle h, db_copy(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1411,7 +1442,7 @@ cli_notification_cb(int s,
if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0) if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0)
goto done; goto done;
if (eof){ if (eof){
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
close(s); close(s);
errno = ESHUTDOWN; errno = ESHUTDOWN;
clixon_event_unreg_fd(s, cli_notification_cb); clixon_event_unreg_fd(s, cli_notification_cb);
@ -1421,7 +1452,7 @@ cli_notification_cb(int s,
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0) if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0)
goto done; goto done;
if (ret == 0){ /* will not happen since no yspec ^*/ if (ret == 0){ /* will not happen since no yspec ^*/
clicon_err(OE_NETCONF, EFAULT, "Notification malformed"); clixon_err(OE_NETCONF, EFAULT, "Notification malformed");
goto done; goto done;
} }
switch (format){ switch (format){
@ -1464,7 +1495,7 @@ cli_notification_cb(int s,
* XXX: format is a memory leak * XXX: format is a memory leak
*/ */
int int
cli_notify(clicon_handle h, cli_notify(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1475,7 +1506,7 @@ cli_notify(clicon_handle h,
enum format_enum format = FORMAT_TEXT; enum format_enum format = FORMAT_TEXT;
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){ if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <logstream> <status> [<format>]"); clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <logstream> <status> [<format>]");
goto done; goto done;
} }
stream = cv_string_get(cvec_i(argv, 0)); stream = cv_string_get(cvec_i(argv, 0));
@ -1511,7 +1542,7 @@ cli_notify(clicon_handle h,
* XXX: format is a memory leak * XXX: format is a memory leak
*/ */
int int
cli_lock(clicon_handle h, cli_lock(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1519,7 +1550,7 @@ cli_lock(clicon_handle h,
char *db; char *db;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>"); clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
goto done; goto done;
} }
db = cv_string_get(cvec_i(argv, 0)); db = cv_string_get(cvec_i(argv, 0));
@ -1543,7 +1574,7 @@ cli_lock(clicon_handle h,
* XXX: format is a memory leak * XXX: format is a memory leak
*/ */
int int
cli_unlock(clicon_handle h, cli_unlock(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1551,7 +1582,7 @@ cli_unlock(clicon_handle h,
char *db; char *db;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>"); clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
goto done; goto done;
} }
db = cv_string_get(cvec_i(argv, 0)); db = cv_string_get(cvec_i(argv, 0));
@ -1589,7 +1620,7 @@ cli_unlock(clicon_handle h,
* @endcode * @endcode
*/ */
int int
cli_copy_config(clicon_handle h, cli_copy_config(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1615,7 +1646,7 @@ cli_copy_config(clicon_handle h,
size_t len; size_t len;
if (cvec_len(argv) != 6){ if (cvec_len(argv) != 6){
clicon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: <db> <xpath> <namespace> <keyname> <from> <to>"); clixon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: <db> <xpath> <namespace> <keyname> <from> <to>");
goto done; goto done;
} }
/* First argv argument: Database */ /* First argv argument: Database */
@ -1633,14 +1664,14 @@ cli_copy_config(clicon_handle h,
/* Get from variable -> cv -> from name */ /* Get from variable -> cv -> from name */
if ((fromcv = cvec_find(cvv, fromvar)) == NULL){ if ((fromcv = cvec_find(cvv, fromvar)) == NULL){
clicon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar); clixon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar);
goto done; goto done;
} }
/* Get from name from cv */ /* Get from name from cv */
fromname = cv_string_get(fromcv); fromname = cv_string_get(fromcv);
/* Create xpath */ /* Create xpath */
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
/* Sanity check that xpath contains exactly two %s, ie [%s='%s'] */ /* Sanity check that xpath contains exactly two %s, ie [%s='%s'] */
@ -1651,7 +1682,7 @@ cli_copy_config(clicon_handle h,
j++; j++;
} }
if (j != 2){ if (j != 2){
clicon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath); clixon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath);
goto done; goto done;
} }
cprintf(cb, xpath, keyname, fromname); cprintf(cb, xpath, keyname, fromname);
@ -1661,13 +1692,18 @@ cli_copy_config(clicon_handle h,
if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cb), nsc, NULL, &x1) < 0) if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cb), nsc, NULL, &x1) < 0)
goto done; goto done;
if ((xerr = xpath_first(x1, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(x1, NULL, "/rpc-error")) != NULL){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_netconf_error(h, xerr, "Get configuration", NULL);
#endif
goto done; goto done;
} }
/* Get to variable -> cv -> to name */ /* Get to variable -> cv -> to name */
if ((tocv = cvec_find(cvv, tovar)) == NULL){ if ((tocv = cvec_find(cvv, tovar)) == NULL){
clicon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar); clixon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar);
goto done; goto done;
} }
toname = cv_string_get(tocv); toname = cv_string_get(tocv);
@ -1679,7 +1715,7 @@ cli_copy_config(clicon_handle h,
xml_name_set(x2, NETCONF_INPUT_CONFIG); xml_name_set(x2, NETCONF_INPUT_CONFIG);
cprintf(cb, "/%s", keyname); cprintf(cb, "/%s", keyname);
if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){ if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){
clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname); clixon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
goto done; goto done;
} }
x = xml_find(x, "body"); x = xml_find(x, "body");
@ -1713,7 +1749,7 @@ cli_copy_config(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_help(clicon_handle h, cli_help(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1736,7 +1772,7 @@ cli_help(clicon_handle h,
* @endcode * @endcode
*/ */
int int
cli_restart_plugin(clicon_handle h, cli_restart_plugin(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1746,7 +1782,7 @@ cli_restart_plugin(clicon_handle h,
if ((cv = cvec_find_var(cvv, "plugin")) == NULL){ if ((cv = cvec_find_var(cvv, "plugin")) == NULL){
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires plugin variable"); clixon_err(OE_PLUGIN, EINVAL, "Requires plugin variable");
goto done; goto done;
} }
cv = cvec_i(argv, 0); cv = cvec_i(argv, 0);
@ -1770,13 +1806,13 @@ cvec_append(cvec *cvv0,
if (cvv0 == NULL){ if (cvv0 == NULL){
if ((cvv2 = cvec_dup(cvv1)) == NULL){ if ((cvv2 = cvec_dup(cvv1)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
return NULL; return NULL;
} }
} }
else{ else{
if ((cvv2 = cvec_dup(cvv0)) == NULL){ if ((cvv2 = cvec_dup(cvv0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
return NULL; return NULL;
} }
cv = NULL; /* Append cvv1 to cvv2 */ cv = NULL; /* Append cvv1 to cvv2 */
@ -1804,7 +1840,7 @@ cvec_concat_cb(cvec *cvv,
int i; int i;
if (cb == NULL){ if (cb == NULL){
clicon_err(OE_PLUGIN, EINVAL, "cb is NULL"); clixon_err(OE_PLUGIN, EINVAL, "cb is NULL");
goto done; goto done;
} }
/* Iterate through all api_path_fmt:s, assume they start with / */ /* Iterate through all api_path_fmt:s, assume they start with / */
@ -1838,7 +1874,7 @@ cvec_concat_cb(cvec *cvv,
* @endcode * @endcode
*/ */
int int
cli_process_control(clicon_handle h, cli_process_control(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1850,17 +1886,17 @@ cli_process_control(clicon_handle h,
cxobj *xerr; cxobj *xerr;
if (cvec_len(argv) != 2){ if (cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation"); clixon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation");
goto done; goto done;
} }
name = cv_string_get(cvec_i(argv, 0)); name = cv_string_get(cvec_i(argv, 0));
opstr = cv_string_get(cvec_i(argv, 1)); opstr = cv_string_get(cvec_i(argv, 1));
if (clixon_process_op_str2int(opstr) == -1){ if (clixon_process_op_str2int(opstr) == -1){
clicon_err(OE_UNIX, 0, "No such process op: %s", opstr); clixon_err(OE_UNIX, 0, "No such process op: %s", opstr);
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE); cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
@ -1874,7 +1910,7 @@ cli_process_control(clicon_handle h,
if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, NULL) < 0) if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, NULL) < 0)
goto done; goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){ if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 1, NULL, cligen_output, 0, 1) < 0) if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 1, NULL, cligen_output, 0, 1) < 0)

View file

@ -39,8 +39,8 @@
#ifndef _CLI_COMMON_H_ #ifndef _CLI_COMMON_H_
#define _CLI_COMMON_H_ #define _CLI_COMMON_H_
void cli_signal_block(clicon_handle h); void cli_signal_block(clixon_handle h);
void cli_signal_unblock(clicon_handle h); void cli_signal_unblock(clixon_handle h);
int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **api_path_fmt01); int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **api_path_fmt01);
cvec *cvec_append(cvec *cvv0, cvec *cvv1); cvec *cvec_append(cvec *cvv0, cvec *cvv1);

View file

@ -122,7 +122,7 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
* @note XXX only fraction_digits handled,should also have mincv, maxcv, pattern * @note XXX only fraction_digits handled,should also have mincv, maxcv, pattern
*/ */
static int static int
cli_expand_var_generate(clicon_handle h, cli_expand_var_generate(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
const char *cvtypestr, const char *cvtypestr,
int options, int options,
@ -177,7 +177,7 @@ cli_expand_var_generate(clicon_handle h,
* @see pt_callback_reference in CLIgen where the actual callback overwrites the template * @see pt_callback_reference in CLIgen where the actual callback overwrites the template
*/ */
static int static int
cli_callback_generate(clicon_handle h, cli_callback_generate(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
cbuf *cb) cbuf *cb)
{ {
@ -396,7 +396,7 @@ yang2cli_var_range(yang_stmt *ys,
* @note for cligen, need to escape " -> \" * @note for cligen, need to escape " -> \"
*/ */
static int static int
yang2cli_var_pattern(clicon_handle h, yang2cli_var_pattern(clixon_handle h,
cvec *patterns, cvec *patterns,
cbuf *cb) cbuf *cb)
{ {
@ -446,9 +446,9 @@ yang2cli_var_pattern(clicon_handle h,
} }
/* Forward */ /* Forward */
static int yang2cli_stmt(clicon_handle h, yang_stmt *ys, int level, cbuf *cb); static int yang2cli_stmt(clixon_handle h, yang_stmt *ys, int level, cbuf *cb);
static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype, static int yang2cli_var_union(clixon_handle h, yang_stmt *ys, char *origtype,
yang_stmt *ytype, char *helptext, cbuf *cb); yang_stmt *ytype, char *helptext, cbuf *cb);
/*! Generate CLI code for Yang leaf state ment to CLIgen variable of specific type /*! Generate CLI code for Yang leaf state ment to CLIgen variable of specific type
@ -470,7 +470,7 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
* @see yang_type_resolve for options and other arguments * @see yang_type_resolve for options and other arguments
*/ */
static int static int
yang2cli_var_sub(clicon_handle h, yang2cli_var_sub(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
yang_stmt *ytype, /* resolved type */ yang_stmt *ytype, /* resolved type */
char *helptext, char *helptext,
@ -560,7 +560,7 @@ yang2cli_var_sub(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang2cli_var_union_one(clicon_handle h, yang2cli_var_union_one(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
char *origtype, char *origtype,
yang_stmt *ytsub, yang_stmt *ytsub,
@ -577,7 +577,7 @@ yang2cli_var_union_one(clicon_handle h,
char *restype; char *restype;
if ((patterns = cvec_new(0)) == NULL){ if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
/* Resolve the sub-union type to a resolved type */ /* Resolve the sub-union type to a resolved type */
@ -586,7 +586,7 @@ yang2cli_var_union_one(clicon_handle h,
&cvv, patterns, NULL, &fraction_digits) < 0) &cvv, patterns, NULL, &fraction_digits) < 0)
goto done; goto done;
if (ytype == NULL){ if (ytype == NULL){
clicon_err(OE_YANG, 0, "result-type should not be NULL"); clixon_err(OE_YANG, 0, "result-type should not be NULL");
goto done; goto done;
} }
restype = ytype?yang_argument_get(ytype):NULL; restype = ytype?yang_argument_get(ytype):NULL;
@ -623,7 +623,7 @@ yang2cli_var_union_one(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang2cli_var_union(clicon_handle h, yang2cli_var_union(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
char *origtype, char *origtype,
yang_stmt *ytype, yang_stmt *ytype,
@ -653,7 +653,7 @@ yang2cli_var_union(clicon_handle h,
} }
static int static int
yang2cli_var_leafref(clicon_handle h, yang2cli_var_leafref(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
yang_stmt *yrestype, yang_stmt *yrestype,
char *helptext, char *helptext,
@ -729,7 +729,7 @@ yang2cli_var_leafref(clicon_handle h,
* and thus its type. * and thus its type.
*/ */
static int static int
yang2cli_var(clicon_handle h, yang2cli_var(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
yang_stmt *yreferred, yang_stmt *yreferred,
char *helptext, char *helptext,
@ -749,7 +749,7 @@ yang2cli_var(clicon_handle h,
int ret; int ret;
if ((patterns = cvec_new(0)) == NULL){ if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
if (yang_type_get(yreferred, &origtype, &yrestype, if (yang_type_get(yreferred, &origtype, &yrestype,
@ -785,11 +785,11 @@ yang2cli_var(clicon_handle h,
yang_stmt *yref = NULL; yang_stmt *yref = NULL;
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){ if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
clicon_err(OE_YANG, 0, "No Y_PATH for leafref"); clixon_err(OE_YANG, 0, "No Y_PATH for leafref");
goto done; goto done;
} }
if ((path_arg = yang_argument_get(ypath)) == NULL){ if ((path_arg = yang_argument_get(ypath)) == NULL){
clicon_err(OE_YANG, 0, "No argument for Y_PATH"); clixon_err(OE_YANG, 0, "No argument for Y_PATH");
goto done; goto done;
} }
if (yang_path_arg(yreferred, path_arg, &yref) < 0) if (yang_path_arg(yreferred, path_arg, &yref) < 0)
@ -803,7 +803,7 @@ yang2cli_var(clicon_handle h,
} }
else { else {
if (yreferred == yref){ if (yreferred == yref){
clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg); clixon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg);
goto done; goto done;
} }
/* recurse call with new referred node */ /* recurse call with new referred node */
@ -841,7 +841,7 @@ yang2cli_var(clicon_handle h,
* + if callbacks add: cb();{} * + if callbacks add: cb();{}
*/ */
static int static int
yang2cli_leaf(clicon_handle h, yang2cli_leaf(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int level, int level,
int callback, int callback,
@ -860,7 +860,7 @@ yang2cli_leaf(clicon_handle h,
/* description */ /* description */
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
if ((s = strstr(helptext, "\n\n")) != NULL) if ((s = strstr(helptext, "\n\n")) != NULL)
@ -941,7 +941,7 @@ yang2cli_leaf(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang2cli_container(clicon_handle h, yang2cli_container(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int level, int level,
cbuf *cb) cbuf *cb)
@ -968,7 +968,7 @@ yang2cli_container(clicon_handle h,
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys)); cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
if ((s = strstr(helptext, "\n\n")) != NULL) if ((s = strstr(helptext, "\n\n")) != NULL)
@ -1016,7 +1016,7 @@ yang2cli_container(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang2cli_list(clicon_handle h, yang2cli_list(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int level, int level,
cbuf *cb) cbuf *cb)
@ -1037,7 +1037,7 @@ yang2cli_list(clicon_handle h,
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys)); cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
if ((s = strstr(helptext, "\n\n")) != NULL) if ((s = strstr(helptext, "\n\n")) != NULL)
@ -1056,7 +1056,7 @@ yang2cli_list(clicon_handle h,
while ((cvi = cvec_each(cvk, cvi)) != NULL) { while ((cvi = cvec_each(cvk, cvi)) != NULL) {
keyname = cv_string_get(cvi); keyname = cv_string_get(cvi);
if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){ if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){
clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", clixon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
yang_argument_get(ys), keyname); yang_argument_get(ys), keyname);
goto done; goto done;
} }
@ -1126,7 +1126,7 @@ yang2cli_list(clicon_handle h,
translated to cli. and therefore input-syntax != output syntax. Which is bad translated to cli. and therefore input-syntax != output syntax. Which is bad
*/ */
static int static int
yang2cli_choice(clicon_handle h, yang2cli_choice(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int level, int level,
cbuf *cb) cbuf *cb)
@ -1168,7 +1168,7 @@ yang2cli_choice(clicon_handle h,
* @note Tie-break of same top-level symbol: prefix is NYI * @note Tie-break of same top-level symbol: prefix is NYI
* @see yang2cli_yspec for original * @see yang2cli_yspec for original
*/ */
static int yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename); static int yang2cli_grouping(clixon_handle h, yang_stmt *ys, char *treename);
/*! Generate CLI code for Yang uses statement /*! Generate CLI code for Yang uses statement
* *
@ -1180,7 +1180,7 @@ static int yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename);
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang2cli_uses(clicon_handle h, yang2cli_uses(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int level, int level,
cbuf *cb) cbuf *cb)
@ -1200,11 +1200,11 @@ yang2cli_uses(clicon_handle h,
if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0) if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0)
goto done; goto done;
if (ygrouping == NULL){ if (ygrouping == NULL){
clicon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys)); clixon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys));
goto done; goto done;
} }
if ((cbtree = cbuf_new()) == NULL){ if ((cbtree = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* prefix is not globally unique, need namespace */ /* prefix is not globally unique, need namespace */
@ -1250,7 +1250,7 @@ yang2cli_uses(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang2cli_stmt(clicon_handle h, yang2cli_stmt(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
int level, int level,
cbuf *cb) cbuf *cb)
@ -1262,7 +1262,7 @@ yang2cli_stmt(clicon_handle h,
int extvalue = 0; int extvalue = 0;
if (ys == NULL){ if (ys == NULL){
clicon_err(OE_YANG, EINVAL, "No yang spec"); clixon_err(OE_YANG, EINVAL, "No yang spec");
goto done; goto done;
} }
if (yang_find(ys, Y_STATUS, "obsolete") != NULL){ if (yang_find(ys, Y_STATUS, "obsolete") != NULL){
@ -1350,11 +1350,11 @@ cvec_add_name(cvec *cvv,
if (cvv == NULL && if (cvv == NULL &&
(cvv = cvec_new(0)) == NULL){ (cvv = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
return NULL; return NULL;
} }
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){ if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add"); clixon_err(OE_UNIX, errno, "cvec_add");
return NULL; return NULL;
} }
/* Filter out state data, use "nonconfig" as defined in RFC8040 4.8.1 /* Filter out state data, use "nonconfig" as defined in RFC8040 4.8.1
@ -1392,7 +1392,7 @@ cvec_add_name(cvec *cvv,
* (2) rewrite yang2cli code to create pt directly instead of via a cbuf. * (2) rewrite yang2cli code to create pt directly instead of via a cbuf.
*/ */
static int static int
yang2cli_post(clicon_handle h, yang2cli_post(clixon_handle h,
cg_obj *cop, cg_obj *cop,
parse_tree *pt, parse_tree *pt,
int i0, int i0,
@ -1412,7 +1412,7 @@ yang2cli_post(clicon_handle h,
ypkeyword = yang_keyword_get(yp); ypkeyword = yang_keyword_get(yp);
for (i = i0; i<pt_len_get(pt); i++){ for (i = i0; i<pt_len_get(pt); i++){
if ((co = pt_vec_i_get(pt, i)) == NULL){ if ((co = pt_vec_i_get(pt, i)) == NULL){
clicon_err(OE_YANG, 0, "Empty object in parsetreelist"); /* shouldnt happen */ clixon_err(OE_YANG, 0, "Empty object in parsetreelist"); /* shouldnt happen */
goto done; goto done;
} }
if (co->co_type == CO_EMPTY){ if (co->co_type == CO_EMPTY){
@ -1517,7 +1517,7 @@ yang2cli_post(clicon_handle h,
* XXX merge with yang2cli_yspec * XXX merge with yang2cli_yspec
*/ */
static int static int
yang2cli_grouping(clicon_handle h, yang2cli_grouping(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
char *treename) char *treename)
{ {
@ -1534,11 +1534,11 @@ yang2cli_grouping(clicon_handle h,
int i; int i;
if ((pt0 = pt_new()) == NULL){ if ((pt0 = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */ /* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */
@ -1564,11 +1564,11 @@ yang2cli_grouping(clicon_handle h,
* Needs to move cligen_parse_str() call here instead of later * Needs to move cligen_parse_str() call here instead of later
*/ */
if ((prefix = yang_find_myprefix(ys)) == NULL){ if ((prefix = yang_find_myprefix(ys)) == NULL){
clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ys)); /* shouldnt happen */ clixon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ys)); /* shouldnt happen */
goto done; goto done;
} }
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
/* Parse the buffer using cligen parser. load cli syntax */ /* Parse the buffer using cligen parser. load cli syntax */
@ -1596,13 +1596,13 @@ yang2cli_grouping(clicon_handle h,
goto done; goto done;
} }
if (clicon_data_int_get(h, "autocli-print-debug") == 1) if (clicon_data_int_get(h, "autocli-print-debug") == 1)
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb)); __FUNCTION__, treename, cbuf_get(cb));
else else
clixon_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)); __FUNCTION__, treename, cbuf_get(cb));
if (cligen_parsetree_merge(pt0, NULL, pt) < 0){ if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
clicon_err(OE_YANG, errno, "cligen_parsetree_merge"); clixon_err(OE_YANG, errno, "cligen_parsetree_merge");
goto done; goto done;
} }
pt_free(pt, 1); pt_free(pt, 1);
@ -1617,11 +1617,11 @@ yang2cli_grouping(clicon_handle h,
goto done; goto done;
/* Append cligen tree and name it */ /* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){ if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){
clicon_err(OE_UNIX, 0, "cligen_ph_add"); clixon_err(OE_UNIX, 0, "cligen_ph_add");
goto done; goto done;
} }
if (cligen_ph_parsetree_set(ph, pt0) < 0){ if (cligen_ph_parsetree_set(ph, pt0) < 0){
clicon_err(OE_UNIX, 0, "cligen_ph_parsetree_set"); clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
goto done; goto done;
} }
pt0 = NULL; pt0 = NULL;
@ -1651,7 +1651,7 @@ yang2cli_grouping(clicon_handle h,
* @note Tie-break of same top-level symbol: prefix is NYI * @note Tie-break of same top-level symbol: prefix is NYI
*/ */
int int
yang2cli_yspec(clicon_handle h, yang2cli_yspec(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
char *treename) char *treename)
{ {
@ -1668,11 +1668,11 @@ yang2cli_yspec(clicon_handle h,
int config; int config;
if ((pt0 = pt_new()) == NULL){ if ((pt0 = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* Traverse YANG, loop through all modules and generate CLI */ /* Traverse YANG, loop through all modules and generate CLI */
@ -1694,11 +1694,11 @@ yang2cli_yspec(clicon_handle h,
* Needs to move cligen_parse_str() call here instead of later * Needs to move cligen_parse_str() call here instead of later
*/ */
if ((prefix = yang_find_myprefix(ymod)) == NULL){ if ((prefix = yang_find_myprefix(ymod)) == NULL){
clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */ clixon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */
goto done; goto done;
} }
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
/* Parse the buffer using cligen parser. load cli syntax */ /* Parse the buffer using cligen parser. load cli syntax */
@ -1727,13 +1727,13 @@ yang2cli_yspec(clicon_handle h,
} }
// pt_print(stderr,pt); // pt_print(stderr,pt);
if (clicon_data_int_get(h, "autocli-print-debug") == 1) if (clicon_data_int_get(h, "autocli-print-debug") == 1)
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb)); __FUNCTION__, treename, cbuf_get(cb));
else else
clixon_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)); __FUNCTION__, treename, cbuf_get(cb));
if (cligen_parsetree_merge(pt0, NULL, pt) < 0){ if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
clicon_err(OE_YANG, errno, "cligen_parsetree_merge"); clixon_err(OE_YANG, errno, "cligen_parsetree_merge");
goto done; goto done;
} }
pt_free(pt, 1); pt_free(pt, 1);
@ -1748,17 +1748,17 @@ yang2cli_yspec(clicon_handle h,
goto done; goto done;
/* Append cligen tree and name it */ /* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){ if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){
clicon_err(OE_UNIX, 0, "cligen_ph_add"); clixon_err(OE_UNIX, 0, "cligen_ph_add");
goto done; goto done;
} }
if (cligen_ph_parsetree_set(ph, pt0) < 0){ if (cligen_ph_parsetree_set(ph, pt0) < 0){
clicon_err(OE_UNIX, 0, "cligen_ph_parsetree_set"); clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
goto done; goto done;
} }
pt0 = NULL; pt0 = NULL;
#if 0 #if 0
if (clicon_data_int_get(h, "autocli-print-debug") == 1){ if (clicon_data_int_get(h, "autocli-print-debug") == 1){
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename); clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename);
pt_print1(stderr, pt0, 0); pt_print1(stderr, pt0, 0);
} }
#endif #endif
@ -1781,7 +1781,7 @@ yang2cli_yspec(clicon_handle h,
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
int int
yang2cli_init(clicon_handle h) yang2cli_init(clixon_handle h)
{ {
return 0; return 0;
} }

View file

@ -61,7 +61,7 @@
/* /*
* Prototypes * Prototypes
*/ */
int yang2cli_yspec(clicon_handle h, yang_stmt *yspec, char *treename); int yang2cli_yspec(clixon_handle h, yang_stmt *yspec, char *treename);
int yang2cli_init(clicon_handle h); int yang2cli_init(clixon_handle h);
#endif /* _CLI_GENERATE_H_ */ #endif /* _CLI_GENERATE_H_ */

View file

@ -60,7 +60,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_cli_api.h" #include "clixon_cli_api.h"
@ -69,15 +69,15 @@
#define CLICON_MAGIC 0x99aafabe #define CLICON_MAGIC 0x99aafabe
#define handle(h) (assert(clicon_handle_check(h)==0),(struct cli_handle *)(h)) #define handle(h) (assert(clixon_handle_check(h)==0),(struct cli_handle *)(h))
#define cligen(h) (handle(h)->cl_cligen) #define cligen(h) (handle(h)->cl_cligen)
/*! CLI specific handle added to header Clixon handle /*! CLI specific handle added to header Clixon handle
* *
* This file should only contain access functions for the _specific_ * This file should only contain access functions for the _specific_
* entries in the struct below. * entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c * @note The top part must be equivalent to struct clixon_handle in clixon_handle.c
* @see struct clicon_handle, struct backend_handle * @see struct clixon_handle, struct backend_handle
*/ */
struct cli_handle { struct cli_handle {
int cl_magic; /* magic (HDR)*/ int cl_magic; /* magic (HDR)*/
@ -92,25 +92,25 @@ struct cli_handle {
/*! Return a clicon handle for other CLICON API calls /*! Return a clicon handle for other CLICON API calls
*/ */
clicon_handle clixon_handle
cli_handle_init(void) cli_handle_init(void)
{ {
struct cli_handle *cl; struct cli_handle *cl;
cligen_handle clih = NULL; cligen_handle clih = NULL;
clicon_handle h = NULL; clixon_handle h = NULL;
if ((cl = (struct cli_handle *)clicon_handle_init0(sizeof(struct cli_handle))) == NULL) if ((cl = (struct cli_handle *)clixon_handle_init0(sizeof(struct cli_handle))) == NULL)
return NULL; return NULL;
if ((clih = cligen_init()) == NULL){ if ((clih = cligen_init()) == NULL){
clicon_handle_exit((clicon_handle)cl); clixon_handle_exit((clixon_handle)cl);
goto done; goto done;
} }
cligen_userhandle_set(clih, cl); cligen_userhandle_set(clih, cl);
cligen_eval_wrap_fn_set(clih, plugin_context_check, cl); cligen_eval_wrap_fn_set(clih, plugin_context_check, cl);
cl->cl_cligen = clih; cl->cl_cligen = clih;
h = (clicon_handle)cl; h = (clixon_handle)cl;
done: done:
return h; return h;
} }
@ -120,11 +120,11 @@ cli_handle_init(void)
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
int int
cli_handle_exit(clicon_handle h) cli_handle_exit(clixon_handle h)
{ {
cligen_handle ch = cligen(h); cligen_handle ch = cligen(h);
clicon_handle_exit(h); /* frees h and options */ clixon_handle_exit(h); /* frees h and options */
cligen_exit(ch); cligen_exit(ch);
return 0; return 0;
} }
@ -138,13 +138,13 @@ cli_handle_exit(clicon_handle h)
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
cligen_handle cligen_handle
cli_cligen(clicon_handle h) cli_cligen(clixon_handle h)
{ {
return cligen(h); return cligen(h);
} }
int int
cli_parse_file(clicon_handle h, cli_parse_file(clixon_handle h,
FILE *f, FILE *f,
char *name, /* just for errs */ char *name, /* just for errs */
parse_tree *pt, parse_tree *pt,
@ -156,7 +156,7 @@ cli_parse_file(clicon_handle h,
} }
int int
cli_susp_hook(clicon_handle h, cli_susp_hook(clixon_handle h,
cligen_susp_cb_t *fn) cligen_susp_cb_t *fn)
{ {
cligen_handle ch = cligen(h); cligen_handle ch = cligen(h);
@ -166,7 +166,7 @@ cli_susp_hook(clicon_handle h,
} }
int int
cli_interrupt_hook(clicon_handle h, cli_interrupt_hook(clixon_handle h,
cligen_interrupt_cb_t *fn) cligen_interrupt_cb_t *fn)
{ {
cligen_handle ch = cligen(h); cligen_handle ch = cligen(h);
@ -176,7 +176,7 @@ cli_interrupt_hook(clicon_handle h,
} }
int int
cli_prompt_set(clicon_handle h, cli_prompt_set(clixon_handle h,
char *prompt) char *prompt)
{ {
cligen_handle ch = cligen(h); cligen_handle ch = cligen(h);
@ -184,7 +184,7 @@ cli_prompt_set(clicon_handle h,
} }
int int
cli_logsyntax_set(clicon_handle h, cli_logsyntax_set(clixon_handle h,
int status) int status)
{ {
cligen_handle ch = cligen(h); cligen_handle ch = cligen(h);

View file

@ -43,18 +43,18 @@
* Prototypes * Prototypes
* Internal prototypes. For exported functions see clixon_cli_api.h * Internal prototypes. For exported functions see clixon_cli_api.h
*/ */
int cli_parse_file(clicon_handle h, int cli_parse_file(clixon_handle h,
FILE *f, FILE *f,
char *name, /* just for errs */ char *name, /* just for errs */
parse_tree *pt, parse_tree *pt,
cvec *globals); cvec *globals);
int cli_susp_hook(clicon_handle h, cligen_susp_cb_t *fn); int cli_susp_hook(clixon_handle h, cligen_susp_cb_t *fn);
int cli_interrupt_hook(clicon_handle h, cligen_interrupt_cb_t *fn); int cli_interrupt_hook(clixon_handle h, cligen_interrupt_cb_t *fn);
int cli_prompt_set(clicon_handle h, char *prompt); int cli_prompt_set(clixon_handle h, char *prompt);
int cli_logsyntax_set(clicon_handle h, int status); int cli_logsyntax_set(clixon_handle h, int status);
#endif /* _CLI_HANDLE_H_ */ #endif /* _CLI_HANDLE_H_ */

View file

@ -61,7 +61,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_cli_api.h" #include "clixon_cli_api.h"
@ -82,7 +82,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
cli_history_load(clicon_handle h) cli_history_load(clixon_handle h)
{ {
int retval = -1; int retval = -1;
int lines; int lines;
@ -101,16 +101,16 @@ cli_history_load(clicon_handle h)
if ((filename = clicon_option_str(h,"CLICON_CLI_HIST_FILE")) == NULL) if ((filename = clicon_option_str(h,"CLICON_CLI_HIST_FILE")) == NULL)
goto ok; /* ignore */ goto ok; /* ignore */
if (wordexp(filename, &result, 0) < 0){ if (wordexp(filename, &result, 0) < 0){
clicon_err(OE_UNIX, errno, "wordexp"); clixon_err(OE_UNIX, errno, "wordexp");
goto done; goto done;
} }
if ((f = fopen(result.we_wordv[0], "r")) == NULL){ if ((f = fopen(result.we_wordv[0], "r")) == NULL){
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s", clixon_log(h, LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
result.we_wordv[0], strerror(errno)); result.we_wordv[0], strerror(errno));
goto ok; goto ok;
} }
if (cligen_hist_file_load(cli_cligen(h), f) < 0){ if (cligen_hist_file_load(cli_cligen(h), f) < 0){
clicon_err(OE_UNIX, errno, "cligen_hist_file_load"); clixon_err(OE_UNIX, errno, "cligen_hist_file_load");
goto done; goto done;
} }
ok: ok:
@ -130,7 +130,7 @@ cli_history_load(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
cli_history_save(clicon_handle h) cli_history_save(clixon_handle h)
{ {
int retval = -1; int retval = -1;
char *filename; char *filename;
@ -140,16 +140,16 @@ cli_history_save(clicon_handle h)
if ((filename = clicon_option_str(h, "CLICON_CLI_HIST_FILE")) == NULL) if ((filename = clicon_option_str(h, "CLICON_CLI_HIST_FILE")) == NULL)
goto ok; /* ignore */ goto ok; /* ignore */
if (wordexp(filename, &result, 0) < 0){ if (wordexp(filename, &result, 0) < 0){
clicon_err(OE_UNIX, errno, "wordexp"); clixon_err(OE_UNIX, errno, "wordexp");
goto done; goto done;
} }
if ((f = fopen(result.we_wordv[0], "w+")) == NULL){ if ((f = fopen(result.we_wordv[0], "w+")) == NULL){
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s", clixon_log(h, LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
result.we_wordv[0], strerror(errno)); result.we_wordv[0], strerror(errno));
goto ok; goto ok;
} }
if (cligen_hist_file_save(cli_cligen(h), f) < 0){ if (cligen_hist_file_save(cli_cligen(h), f) < 0){
clicon_err(OE_UNIX, errno, "cligen_hist_file_save"); clixon_err(OE_UNIX, errno, "cligen_hist_file_save");
goto done; goto done;
} }
ok: ok:
@ -167,7 +167,7 @@ cli_history_save(clicon_handle h)
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
static int static int
cli_terminate(clicon_handle h) cli_terminate(clixon_handle h)
{ {
yang_stmt *yspec; yang_stmt *yspec;
cvec *nsctx; cvec *nsctx;
@ -196,7 +196,7 @@ cli_terminate(clicon_handle h)
cli_history_save(h); cli_history_save(h);
cli_handle_exit(h); cli_handle_exit(h);
clixon_err_exit(); clixon_err_exit();
clicon_log_exit(); clixon_log_exit();
return 0; return 0;
} }
@ -205,7 +205,7 @@ cli_terminate(clicon_handle h)
static void static void
cli_sig_term(int arg) cli_sig_term(int arg)
{ {
clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)", clixon_log(NULL, LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
__PROGRAM__, getpid(), arg); __PROGRAM__, getpid(), arg);
exit(1); exit(1);
} }
@ -213,17 +213,17 @@ cli_sig_term(int arg)
/*! Setup signal handlers /*! Setup signal handlers
*/ */
static int static int
cli_signal_init (clicon_handle h) cli_signal_init (clixon_handle h)
{ {
int retval = -1; int retval = -1;
cli_signal_block(h); cli_signal_block(h);
if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){ if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting SIGTERM signal"); clixon_err(OE_UNIX, errno, "Setting SIGTERM signal");
goto done; goto done;
} }
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal"); clixon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -239,7 +239,7 @@ cli_signal_init (clicon_handle h)
* @see cligen_loop * @see cligen_loop
*/ */
static int static int
cli_interactive(clicon_handle h) cli_interactive(clixon_handle h)
{ {
int retval = -1; int retval = -1;
char *cmd; char *cmd;
@ -251,7 +251,7 @@ cli_interactive(clicon_handle h)
/* Loop through all commands */ /* Loop through all commands */
while(!cligen_exiting(cli_cligen(h))) { while(!cligen_exiting(cli_cligen(h))) {
if ((ph = cligen_pt_head_active_get(cli_cligen(h))) == NULL){ if ((ph = cligen_pt_head_active_get(cli_cligen(h))) == NULL){
clicon_err(OE_UNIX, 0, "active tree not found"); clixon_err(OE_UNIX, 0, "active tree not found");
goto done; goto done;
} }
new_mode = cligen_ph_name_get(ph); new_mode = cligen_ph_name_get(ph);
@ -280,7 +280,7 @@ cli_interactive(clicon_handle h)
* should probably be moved to clispec default * should probably be moved to clispec default
*/ */
static int static int
autocli_trees_default(clicon_handle h) autocli_trees_default(clixon_handle h)
{ {
int retval = -1; int retval = -1;
cbuf *cb = NULL; cbuf *cb = NULL;
@ -292,7 +292,7 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodel")) == NULL) if ((ph = cligen_ph_add(cli_cligen(h), "datamodel")) == NULL)
goto done; goto done;
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if (clispec_parse_str(cli_cligen(h), if (clispec_parse_str(cli_cligen(h),
@ -306,7 +306,7 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelshow")) == NULL) if ((ph = cligen_ph_add(cli_cligen(h), "datamodelshow")) == NULL)
goto done; goto done;
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if (clispec_parse_str(cli_cligen(h), if (clispec_parse_str(cli_cligen(h),
@ -319,7 +319,7 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelstate")) == NULL) if ((ph = cligen_ph_add(cli_cligen(h), "datamodelstate")) == NULL)
goto done; goto done;
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if (clispec_parse_str(cli_cligen(h), if (clispec_parse_str(cli_cligen(h),
@ -333,11 +333,11 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelmode")) == NULL) if ((ph = cligen_ph_add(cli_cligen(h), "datamodelmode")) == NULL)
goto done; goto done;
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "@basemodel, @remove:act-prekey, @remove:act-leafconst, @remove:ac-state"); cprintf(cb, "@basemodel, @remove:act-prekey, @remove:act-leafconst, @remove:ac-state");
@ -385,7 +385,7 @@ autocli_trees_default(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
autocli_start(clicon_handle h) autocli_start(clixon_handle h)
{ {
int retval = -1; int retval = -1;
yang_stmt *yspec; yang_stmt *yspec;
@ -435,7 +435,7 @@ autocli_start(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
options_split(clicon_handle h, options_split(clixon_handle h,
char *argv0, char *argv0,
int argc, int argc,
char **argv, char **argv,
@ -470,7 +470,7 @@ options_split(clicon_handle h,
} }
static void static void
usage(clicon_handle h, usage(clixon_handle h,
char *argv0) char *argv0)
{ {
char *plgdir = clicon_cli_dir(h); char *plgdir = clicon_cli_dir(h);
@ -518,10 +518,10 @@ main(int argc,
int once; int once;
char *tmp; char *tmp;
char *argv0 = argv[0]; char *argv0 = argv[0];
clicon_handle h; clixon_handle h;
int logclisyntax = 0; int logclisyntax = 0;
int help = 0; int help = 0;
int logdst = CLICON_LOG_STDERR; int logdst = CLIXON_LOG_STDERR;
char *restarg = NULL; /* what remains after options */ char *restarg = NULL; /* what remains after options */
yang_stmt *yspec; yang_stmt *yspec;
struct passwd *pw; struct passwd *pw;
@ -540,18 +540,20 @@ main(int argc,
once = 0; once = 0;
config_dump = 0; config_dump = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Initiate Clixon handle. CLIgen is also initialized */ /* Initiate Clixon handle. CLIgen is also initialized */
if ((h = cli_handle_init()) == NULL) if ((h = cli_handle_init()) == NULL)
goto done; goto done;
/* In the startup, logs to stderr & debug flag set later */
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
goto done;
if (clixon_err_init(h) < 0)
goto done;
/* Set username to clicon handle. Use in all communication to backend /* Set username to clicon handle. Use in all communication to backend
* Note, can be overridden by -U * Note, can be overridden by -U
*/ */
if ((pw = getpwuid(getuid())) == NULL){ if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid"); clixon_err(OE_UNIX, errno, "getpwuid");
goto done; goto done;
} }
if (clicon_username_set(h, pw->pw_name) < 0) if (clicon_username_set(h, pw->pw_name) < 0)
@ -594,19 +596,19 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break; break;
case 'l': /* Log destination: s|e|o|f */ case 'l': /* Log destination: s|e|o|f */
if ((logdst = clicon_log_opt(optarg[0])) < 0) if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]); usage(h, argv[0]);
if (logdst == CLICON_LOG_FILE && if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 && strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0) clixon_log_file(optarg+1) < 0)
goto done; goto done;
break; break;
} }
/* /*
* Logs, error and debug to stderr or syslog, set debug level * Logs, error and debug to stderr or syslog, set debug level
*/ */
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
yang_init(h); yang_init(h);
/* Find, read and parse configfile */ /* Find, read and parse configfile */
@ -734,7 +736,7 @@ main(int argc,
/* Enable XSD libxml2 regex engine */ /* Enable XSD libxml2 regex engine */
cligen_regex_xsd_set(cli_cligen(h), 1); cligen_regex_xsd_set(cli_cligen(h), 1);
#else #else
clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); clixon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
goto done; goto done;
#endif #endif
} }
@ -746,7 +748,7 @@ main(int argc,
cligen_helpstring_lines_set(cli_cligen(h), nr); cligen_helpstring_lines_set(cli_cligen(h), nr);
if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(nr); clixon_log_string_limit_set(nr);
/* Setup signal handlers */ /* Setup signal handlers */
if (cli_signal_init(h) < 0) if (cli_signal_init(h) < 0)
@ -852,7 +854,7 @@ main(int argc,
goto done; goto done;
} }
if (cligen_ph_find(cli_cligen(h), cli_syntax_mode(h)) == NULL) if (cligen_ph_find(cli_cligen(h), cli_syntax_mode(h)) == NULL)
clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m <mode> on command line", cli_syntax_mode(h)); clixon_log(h, LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m <mode> on command line", cli_syntax_mode(h));
/* CLIgen tab mode, ie how <tab>s behave */ /* CLIgen tab mode, ie how <tab>s behave */
if ((tabmode = clicon_cli_tab_mode(h)) < 0){ if ((tabmode = clicon_cli_tab_mode(h)) < 0){
fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n"); fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n");
@ -922,9 +924,9 @@ main(int argc,
done: done:
if (restarg) if (restarg)
free(restarg); free(restarg);
// Gets in your face if we log on stderr // Gets in your face if we log on stderr
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
if (h) if (h)
cli_terminate(h); cli_terminate(h);
return retval; return retval;

View file

@ -67,7 +67,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "clixon_cli_api.h" #include "clixon_cli_api.h"
@ -83,7 +83,7 @@
* @endcode * @endcode
*/ */
int int
pipe_arg_fn(clicon_handle h, pipe_arg_fn(clixon_handle h,
char *cmd, char *cmd,
char *option, char *option,
char *value) char *value)
@ -94,19 +94,19 @@ pipe_arg_fn(clicon_handle h,
int i; int i;
if (cmd == NULL || strlen(cmd) == 0){ if (cmd == NULL || strlen(cmd) == 0){
clicon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd); clixon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd);
goto done; goto done;
} }
if (stat(cmd, &fstat) < 0) { if (stat(cmd, &fstat) < 0) {
clicon_err(OE_UNIX, errno, "stat(%s)", cmd); clixon_err(OE_UNIX, errno, "stat(%s)", cmd);
goto done; goto done;
} }
if (!S_ISREG(fstat.st_mode)){ if (!S_ISREG(fstat.st_mode)){
clicon_err(OE_UNIX, errno, "%s is not a regular file", cmd); clixon_err(OE_UNIX, errno, "%s is not a regular file", cmd);
goto done; goto done;
} }
if ((argv = calloc(4, sizeof(char *))) == NULL){ if ((argv = calloc(4, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc"); clixon_err(OE_UNIX, errno, "calloc");
goto done; goto done;
} }
i = 0; i = 0;
@ -129,7 +129,7 @@ pipe_arg_fn(clicon_handle h,
* @note Any vertical bar (|] in the patterns field is quoted for OR function * @note Any vertical bar (|] in the patterns field is quoted for OR function
*/ */
int int
pipe_grep_fn(clicon_handle h, pipe_grep_fn(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -144,7 +144,7 @@ pipe_grep_fn(clicon_handle h,
char c; char c;
if (cvec_len(argv) != 2){ if (cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
goto done; goto done;
} }
if ((cv = cvec_i(argv, 0)) != NULL && if ((cv = cvec_i(argv, 0)) != NULL &&
@ -156,7 +156,7 @@ pipe_grep_fn(clicon_handle h,
strlen(str)) strlen(str))
argname = str; argname = str;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (argname && strlen(argname)){ if (argname && strlen(argname)){
@ -189,7 +189,7 @@ pipe_grep_fn(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
pipe_wc_fn(clicon_handle h, pipe_wc_fn(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -199,7 +199,7 @@ pipe_wc_fn(clicon_handle h,
char *option = NULL; char *option = NULL;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <NUM>", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <NUM>", cvec_len(argv));
goto done; goto done;
} }
if ((cv = cvec_i(argv, 0)) != NULL && if ((cv = cvec_i(argv, 0)) != NULL &&
@ -220,7 +220,7 @@ pipe_wc_fn(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
pipe_tail_fn(clicon_handle h, pipe_tail_fn(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -232,7 +232,7 @@ pipe_tail_fn(clicon_handle h,
char *argname = NULL; char *argname = NULL;
if (cvec_len(argv) != 2){ if (cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
goto done; goto done;
} }
if ((cv = cvec_i(argv, 0)) != NULL && if ((cv = cvec_i(argv, 0)) != NULL &&
@ -267,7 +267,7 @@ pipe_tail_fn(clicon_handle h,
* @see cli_show_auto_devs * @see cli_show_auto_devs
*/ */
int int
pipe_showas_fn(clicon_handle h, pipe_showas_fn(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -282,7 +282,7 @@ pipe_showas_fn(clicon_handle h,
cxobj *xerr = NULL; cxobj *xerr = NULL;
if (cvec_len(argv) < 1 || cvec_len(argv) > 3){ if (cvec_len(argv) < 1 || cvec_len(argv) > 3){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <format> [<pretty> [<prepend>]]", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <format> [<pretty> [<prepend>]]", cvec_len(argv));
goto done; goto done;
} }
if (cvec_len(argv) > argc){ if (cvec_len(argv) > argc){
@ -308,7 +308,7 @@ pipe_showas_fn(clicon_handle h,
if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xerr)) < 0) if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clixon_netconf_error(h, xerr, "Parse top file", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Parse top file");
goto done; goto done;
} }
break; break;

View file

@ -59,7 +59,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
/* clicon_cli */ /* clicon_cli */
@ -87,7 +87,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
gen_parse_tree(clicon_handle h, gen_parse_tree(clixon_handle h,
char *name, char *name,
parse_tree *pt, parse_tree *pt,
pt_head **php) pt_head **php)
@ -100,7 +100,7 @@ gen_parse_tree(clicon_handle h,
if (cligen_ph_parsetree_set(ph, pt) < 0) if (cligen_ph_parsetree_set(ph, pt) < 0)
goto done; goto done;
if (cligen_ph_prompt_set(ph, CLI_DEFAULT_PROMPT) < 0){ if (cligen_ph_prompt_set(ph, CLI_DEFAULT_PROMPT) < 0){
clicon_err(OE_UNIX, errno, "cligen_ph_prompt_set"); clixon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
goto done; goto done;
} }
*php = ph; *php = ph;
@ -198,7 +198,7 @@ cli_mark_output_pipes(cg_obj *co,
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this * @see clixon_plugins_load Where .so plugin code has been loaded prior to this
*/ */
static int static int
clispec_load_file(clicon_handle h, clispec_load_file(clixon_handle h,
const char *filename, const char *filename,
const char *dir, const char *dir,
parse_tree *ptall, parse_tree *ptall,
@ -223,7 +223,7 @@ clispec_load_file(clicon_handle h,
#endif #endif
if ((pt = pt_new()) == NULL){ if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if (dir) if (dir)
@ -231,18 +231,18 @@ clispec_load_file(clicon_handle h,
else else
snprintf(filepath, MAXPATHLEN-1, "%s", filename); snprintf(filepath, MAXPATHLEN-1, "%s", filename);
if ((cvv = cvec_new(0)) == NULL){ if ((cvv = cvec_new(0)) == NULL){
clicon_err(OE_PLUGIN, errno, "cvec_new"); clixon_err(OE_PLUGIN, errno, "cvec_new");
goto done; goto done;
} }
/* Build parse tree from syntax spec. */ /* Build parse tree from syntax spec. */
if ((f = fopen(filepath, "r")) == NULL){ if ((f = fopen(filepath, "r")) == NULL){
clicon_err(OE_PLUGIN, errno, "fopen %s", filepath); clixon_err(OE_PLUGIN, errno, "fopen %s", filepath);
goto done; goto done;
} }
/* Assuming this plugin is first in queue */ /* Assuming this plugin is first in queue */
if (clispec_parse_file(h, f, filepath, NULL, pt, cvv) < 0){ if (clispec_parse_file(h, f, filepath, NULL, pt, cvv) < 0){
clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath); clixon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
fclose(f); fclose(f);
goto done; goto done;
} }
@ -267,7 +267,7 @@ clispec_load_file(clicon_handle h,
if ((cp = clixon_plugin_find(h, plgnam)) != NULL) if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
handle = clixon_plugin_handle_get(cp); handle = clixon_plugin_handle_get(cp);
if (handle == NULL){ if (handle == NULL){
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s", clixon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
plgnam, filename, plgnam, plgnam, filename, plgnam,
clicon_cli_dir(h)); clicon_cli_dir(h));
goto done; goto done;
@ -284,7 +284,7 @@ clispec_load_file(clicon_handle h,
/* Resolve callback names to function pointers. */ /* Resolve callback names to function pointers. */
if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){ if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){
clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)", clixon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
filename, plgnam, plgnam); filename, plgnam, plgnam);
goto done; goto done;
} }
@ -298,7 +298,7 @@ clispec_load_file(clicon_handle h,
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */ if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
mode = clicon_cli_mode(h); mode = clicon_cli_mode(h);
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */ if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath); clixon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
goto done; goto done;
} }
} }
@ -312,7 +312,7 @@ clispec_load_file(clicon_handle h,
* all modes may not be known (not yet loaded) * all modes may not be known (not yet loaded)
*/ */
if (cligen_parsetree_merge(ptall, NULL, pt) < 0){ if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge"); clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
goto done; goto done;
} }
} }
@ -323,7 +323,7 @@ clispec_load_file(clicon_handle h,
cg_var *cv; cg_var *cv;
if ((ph = cligen_ph_find(cli_cligen(h), name)) == NULL){ if ((ph = cligen_ph_find(cli_cligen(h), name)) == NULL){
if ((ptnew = pt_new()) == NULL){ if ((ptnew = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if (gen_parse_tree(h, name, ptnew, &ph) < 0) if (gen_parse_tree(h, name, ptnew, &ph) < 0)
@ -331,12 +331,12 @@ clispec_load_file(clicon_handle h,
if (ph == NULL) if (ph == NULL)
goto done; goto done;
if ((cv = cv_new(CGV_STRING)) == NULL){ if ((cv = cv_new(CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new"); clixon_err(OE_UNIX, errno, "cv_new");
goto done; goto done;
} }
cv_string_set(cv, name); cv_string_set(cv, name);
if (cvec_append_var(modes, cv) < 0){ if (cvec_append_var(modes, cv) < 0){
clicon_err(OE_UNIX, errno, "cvec_append_var"); clixon_err(OE_UNIX, errno, "cvec_append_var");
goto done; goto done;
} }
if (cv) if (cv)
@ -346,12 +346,12 @@ clispec_load_file(clicon_handle h,
if (cligen_ph_pipe_set(ph, pipetree) < 0) if (cligen_ph_pipe_set(ph, pipetree) < 0)
goto done; goto done;
if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph), NULL, pt) < 0){ if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph), NULL, pt) < 0){
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge"); clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
goto done; goto done;
} }
if (prompt){ if (prompt){
if (cligen_ph_prompt_set(ph, prompt) < 0){ if (cligen_ph_prompt_set(ph, prompt) < 0){
clicon_err(OE_UNIX, errno, "cligen_ph_prompt_set"); clixon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
return -1; return -1;
} }
} }
@ -377,7 +377,7 @@ done:
* XXX The parsetree loading needs a rewrite for multiple parse-trees * XXX The parsetree loading needs a rewrite for multiple parse-trees
*/ */
int int
clispec_load(clicon_handle h) clispec_load(clixon_handle h)
{ {
int retval = -1; int retval = -1;
char *clispec_dir = NULL; char *clispec_dir = NULL;
@ -394,11 +394,11 @@ clispec_load(clicon_handle h)
cg_var *cv = NULL; cg_var *cv = NULL;
if ((ptall = pt_new()) == NULL){ if ((ptall = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new"); clixon_err(OE_UNIX, errno, "pt_new");
goto done; goto done;
} }
if ((modes = cvec_new(0)) == NULL){ if ((modes = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
/* Format plugin directory path */ /* Format plugin directory path */
@ -438,7 +438,7 @@ clispec_load(clicon_handle h)
if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph), if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph),
NULL, NULL,
ptall) < 0){ ptall) < 0){
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge"); clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
goto done; goto done;
} }
} }
@ -469,7 +469,7 @@ done:
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
int int
cli_plugin_finish(clicon_handle h) cli_plugin_finish(clixon_handle h)
{ {
return 0; return 0;
} }
@ -478,19 +478,19 @@ cli_plugin_finish(clicon_handle h)
* *
* Sometimes the libraries specify an error string, if so print that. * Sometimes the libraries specify an error string, if so print that.
* Otherwise just print 'command error'. * Otherwise just print 'command error'.
* But do not print it if error is already logged in eg clicon_err() using STDERR logging * But do not print it if error is already logged in eg clixon_err() using STDERR logging
* See eg https://github.com/clicon/clixon/issues/325 * See eg https://github.com/clicon/clixon/issues/325
* @param[in] f File handler to write error to. * @param[in] f File handler to write error to.
*/ */
int int
cli_handler_err(FILE *f) cli_handler_err(FILE *f)
{ {
if (clicon_errno){ if (clixon_err_category()){
/* Check if error is already logged on stderr */ /* Check if error is already logged on stderr */
if ((clicon_get_logflags() & CLICON_LOG_STDERR) == 0){ if ((clixon_get_logflags() & CLIXON_LOG_STDERR) == 0){
fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason); fprintf(f, "%s: %s", clixon_err_str(), clixon_err_reason());
if (clicon_suberrno) if (clixon_err_subnr())
fprintf(f, ": %s", strerror(clicon_suberrno)); fprintf(f, ": %s", strerror(clixon_err_subnr()));
fprintf(f, "\n"); fprintf(f, "\n");
} }
else else
@ -517,7 +517,7 @@ cli_handler_err(FILE *f)
* @retval -1 Error * @retval -1 Error
*/ */
int int
clicon_parse(clicon_handle h, clicon_parse(clixon_handle h,
char *cmd, char *cmd,
char **modenamep, char **modenamep,
cligen_result *result, cligen_result *result,
@ -535,7 +535,7 @@ clicon_parse(clicon_handle h,
pt_head *ph; pt_head *ph;
ch = cli_cligen(h); ch = cli_cligen(h);
if (clicon_get_logflags()&CLICON_LOG_STDOUT) if (clixon_get_logflags()&CLIXON_LOG_STDOUT)
f = stdout; f = stdout;
else else
f = stderr; f = stderr;
@ -569,10 +569,10 @@ clicon_parse(clicon_handle h,
} }
cli_output_reset(); cli_output_reset();
if (!cligen_exiting(ch)) { if (!cligen_exiting(ch)) {
clicon_err_reset(); clixon_err_reset();
if ((ret = cligen_eval(ch, match_obj, cvv)) < 0) { if ((ret = cligen_eval(ch, match_obj, cvv)) < 0) {
cli_handler_err(stdout); cli_handler_err(stdout);
if (clicon_suberrno == ESHUTDOWN) if (clixon_err_subnr() == ESHUTDOWN)
goto done; goto done;
} }
} }
@ -610,7 +610,7 @@ done:
* @retval NULL Error * @retval NULL Error
*/ */
static char * static char *
cli_prompt_get(clicon_handle h, cli_prompt_get(clixon_handle h,
char *fmt) char *fmt)
{ {
char *s = fmt; char *s = fmt;
@ -623,7 +623,7 @@ cli_prompt_get(clicon_handle h,
char *str0; char *str0;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
/* Start with empty string */ /* Start with empty string */
@ -690,7 +690,7 @@ cli_prompt_get(clicon_handle h,
} }
str0 = cbuf_len(cb) ? cbuf_get(cb) : CLI_DEFAULT_PROMPT; str0 = cbuf_len(cb) ? cbuf_get(cb) : CLI_DEFAULT_PROMPT;
if ((promptstr = strdup(str0)) == NULL){ if ((promptstr = strdup(str0)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
done: done:
@ -709,7 +709,7 @@ cli_prompt_get(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
clicon_cliread(clicon_handle h, clicon_cliread(clixon_handle h,
pt_head *ph, pt_head *ph,
char **stringp) char **stringp)
{ {
@ -739,10 +739,10 @@ clicon_cliread(clicon_handle h,
cli_prompt_set(h, promptstr); cli_prompt_set(h, promptstr);
free(promptstr); free(promptstr);
} }
clicon_err_reset(); clixon_err_reset();
if (cliread(cli_cligen(h), stringp) < 0){ if (cliread(cli_cligen(h), stringp) < 0){
cli_handler_err(stdout); cli_handler_err(stdout);
if (clicon_suberrno == ESHUTDOWN) if (clixon_err_subnr() == ESHUTDOWN)
goto done; goto done;
goto fail; goto fail;
} }
@ -770,7 +770,7 @@ clicon_cliread(clicon_handle h,
* @retval 0 Not found / error * @retval 0 Not found / error
*/ */
int int
cli_set_syntax_mode(clicon_handle h, cli_set_syntax_mode(clixon_handle h,
char *name) char *name)
{ {
@ -787,7 +787,7 @@ cli_set_syntax_mode(clicon_handle h,
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
char * char *
cli_syntax_mode(clicon_handle h) cli_syntax_mode(clixon_handle h)
{ {
pt_head *ph; pt_head *ph;

View file

@ -43,15 +43,15 @@
#include <netinet/in.h> #include <netinet/in.h>
/* clicon generic callback pointer */ /* clicon generic callback pointer */
typedef void (clicon_callback_t)(clicon_handle h); typedef void (clicon_callback_t)(clixon_handle h);
void *clixon_str2fn(char *name, void *handle, char **error); void *clixon_str2fn(char *name, void *handle, char **error);
int clicon_parse(clicon_handle h, char *cmd, char **mode, cligen_result *result, int *evalres); int clicon_parse(clixon_handle h, char *cmd, char **mode, cligen_result *result, int *evalres);
int clicon_cliread(clicon_handle h, pt_head *ph, char **stringp); int clicon_cliread(clixon_handle h, pt_head *ph, char **stringp);
int cli_plugin_finish(clicon_handle h); int cli_plugin_finish(clixon_handle h);
#endif /* _CLI_PLUGIN_H_ */ #endif /* _CLI_PLUGIN_H_ */

View file

@ -66,7 +66,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
/* Exported functions in this file are in clixon_cli_api.h */ /* Exported functions in this file are in clixon_cli_api.h */
@ -115,7 +115,7 @@ xpath_append(cbuf *cb0,
int j; int j;
if (cb0 == NULL){ if (cb0 == NULL){
clicon_err(OE_XML, EINVAL, "cb0 is NULL"); clixon_err(OE_XML, EINVAL, "cb0 is NULL");
goto done; goto done;
} }
if (xpath1 == NULL || strlen(xpath1)==0) if (xpath1 == NULL || strlen(xpath1)==0)
@ -158,7 +158,7 @@ xpath_append(cbuf *cb0,
if ((ret = yang_find_namespace_by_prefix(y, prefix, &ns)) < 0) if ((ret = yang_find_namespace_by_prefix(y, prefix, &ns)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clicon_err(OE_DB, 0, "Prefix %s does not have an associated namespace", prefix); clixon_err(OE_DB, 0, "Prefix %s does not have an associated namespace", prefix);
goto done; goto done;
} }
if (xml_nsctx_add(nsc, prefix, ns) < 0) if (xml_nsctx_add(nsc, prefix, ns) < 0)
@ -250,32 +250,32 @@ expand_dbvar(void *h,
cvec *callback_cvv; cvec *callback_cvv;
if (argv == NULL || (cvec_len(argv) != 2 && cvec_len(argv) != 3)){ if (argv == NULL || (cvec_len(argv) != 2 && cvec_len(argv) != 3)){
clicon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <apipathfmt> [<mountpt>]"); clixon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <apipathfmt> [<mountpt>]");
goto done; goto done;
} }
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if ((cv = cvec_i(argv, 0)) == NULL){ if ((cv = cvec_i(argv, 0)) == NULL){
clicon_err(OE_PLUGIN, 0, "Error when accessing argument <db>"); clixon_err(OE_PLUGIN, 0, "Error when accessing argument <db>");
goto done; goto done;
} }
dbstr = cv_string_get(cv); dbstr = cv_string_get(cv);
if (strcmp(dbstr, "running") != 0 && if (strcmp(dbstr, "running") != 0 &&
strcmp(dbstr, "candidate") != 0 && strcmp(dbstr, "candidate") != 0 &&
strcmp(dbstr, "startup") != 0){ strcmp(dbstr, "startup") != 0){
clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); clixon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
goto done; goto done;
} }
if ((cv = cvec_i(argv, 1)) == NULL){ if ((cv = cvec_i(argv, 1)) == NULL){
clicon_err(OE_PLUGIN, 0, "Error when accessing argument <api_path>"); clixon_err(OE_PLUGIN, 0, "Error when accessing argument <api_path>");
goto done; goto done;
} }
if (autocli_grouping_treeref(h, &grouping_treeref) < 0) if (autocli_grouping_treeref(h, &grouping_treeref) < 0)
goto done; goto done;
if ((api_path_fmt_cb = cbuf_new()) == NULL){ if ((api_path_fmt_cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
if (grouping_treeref && if (grouping_treeref &&
@ -290,7 +290,7 @@ expand_dbvar(void *h,
cv = cvec_i(argv, 2); cv = cvec_i(argv, 2);
str = cv_string_get(cv); str = cv_string_get(cv);
if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){ if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){
clicon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'"); clixon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'");
goto done; goto done;
} }
mtpoint = str + strlen("mtpoint:"); mtpoint = str + strlen("mtpoint:");
@ -320,8 +320,7 @@ expand_dbvar(void *h,
if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0) if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
// XXX cf cli_dbxml clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Expand datastore symbol");
clixon_netconf_error(h, xerr, "Expand datastore symbol", NULL);
goto done; goto done;
} }
} }
@ -331,7 +330,7 @@ expand_dbvar(void *h,
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0) if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
goto done; goto done;
if ((cbxpath = cbuf_new()) == NULL){ if ((cbxpath = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (mtpoint){ if (mtpoint){
@ -372,7 +371,7 @@ expand_dbvar(void *h,
* the "path" statement is defined. * the "path" statement is defined.
*/ */
if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){ if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){
clicon_err(OE_DB, 0, "Leafref %s requires path statement", yang_argument_get(ytype)); clixon_err(OE_DB, 0, "Leafref %s requires path statement", yang_argument_get(ytype));
goto done; goto done;
} }
/* Extend xpath with leafref path: Append yang_argument_get(ypath) to xpath /* Extend xpath with leafref path: Append yang_argument_get(ypath) to xpath
@ -384,7 +383,7 @@ expand_dbvar(void *h,
if (clicon_rpc_get_config(h, NULL, dbstr, cbuf_get(cbxpath), nsc, NULL, &xt) < 0) if (clicon_rpc_get_config(h, NULL, dbstr, cbuf_get(cbxpath), nsc, NULL, &xt) < 0)
goto done; goto done;
if ((xe = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xe = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xe, "Get configuration", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto ok; goto ok;
} }
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, cbuf_get(cbxpath)) < 0) if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, cbuf_get(cbxpath)) < 0)
@ -462,7 +461,7 @@ expand_dbvar(void *h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
show_yang(clicon_handle h, show_yang(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -508,7 +507,7 @@ show_yang(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
cli_show_common(clicon_handle h, cli_show_common(clixon_handle h,
char *db, char *db,
enum format_enum format, enum format_enum format,
int pretty, int pretty,
@ -531,7 +530,7 @@ cli_show_common(clicon_handle h,
int i; int i;
if (state && strcmp(db, "running") != 0){ if (state && strcmp(db, "running") != 0){
clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db); clixon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
goto done; goto done;
} }
if (state == 0){ /* Get configuration-only from a database */ if (state == 0){ /* Get configuration-only from a database */
@ -543,7 +542,7 @@ cli_show_common(clicon_handle h,
goto done; goto done;
} }
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
/* Special tagged modes: strip wd:default=true attribute and (optionally) nodes associated with it */ /* Special tagged modes: strip wd:default=true attribute and (optionally) nodes associated with it */
@ -640,7 +639,7 @@ cli_show_option_format(cvec *argv,
formatstr = cv_string_get(cvec_i(argv, argc)); formatstr = cv_string_get(cvec_i(argv, argc));
if ((int)(*format = format_str2int(formatstr)) < 0){ if ((int)(*format = format_str2int(formatstr)) < 0){
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
goto done; goto done;
} }
retval = 0; retval = 0;
@ -668,11 +667,11 @@ cli_show_option_bool(cvec *argv,
boolstr = cv_string_get(cvec_i(argv, argc)); boolstr = cv_string_get(cvec_i(argv, argc));
if ((boolcv = cv_new(CGV_BOOL)) == NULL){ if ((boolcv = cv_new(CGV_BOOL)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new"); clixon_err(OE_UNIX, errno, "cv_new");
goto done; goto done;
} }
if (cv_parse(boolstr, boolcv) < 0){ if (cv_parse(boolstr, boolcv) < 0){
clicon_err(OE_UNIX, errno, "Parse boolean %s", boolstr); clixon_err(OE_UNIX, errno, "Parse boolean %s", boolstr);
goto done; goto done;
} }
*result = cv_bool_get(boolcv); *result = cv_bool_get(boolcv);
@ -719,7 +718,7 @@ cli_show_option_withdefault(cvec *argv,
strcmp(e, "trim") != 0 && strcmp(e, "trim") != 0 &&
strcmp(e, "explicit") != 0 && strcmp(e, "explicit") != 0 &&
strcmp(e, "report-all-tagged") != 0){ strcmp(e, "report-all-tagged") != 0){
clicon_err(OE_YANG, EINVAL, "Unexpected with-default option: %s", e); clixon_err(OE_YANG, EINVAL, "Unexpected with-default option: %s", e);
goto done; goto done;
} }
else else
@ -765,7 +764,7 @@ cli_show_option_withdefault(cvec *argv,
* @see cli_show_auto_mode autocli with edit menu support * @see cli_show_auto_mode autocli with edit menu support
*/ */
int int
cli_show_config(clicon_handle h, cli_show_config(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -784,7 +783,7 @@ cli_show_config(clicon_handle h,
int fromroot = 0; int fromroot = 0;
if (cvec_len(argv) < 2 || cvec_len(argv) > 8){ if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv));
goto done; goto done;
} }
dbname = cv_string_get(cvec_i(argv, argc++)); dbname = cv_string_get(cvec_i(argv, argc++));
@ -838,7 +837,7 @@ cli_show_config(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
show_conf_xpath(clicon_handle h, show_conf_xpath(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -851,17 +850,17 @@ show_conf_xpath(clicon_handle h,
int fromroot = 0; int fromroot = 0;
if (cvec_len(argv) != 1){ if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>"); clixon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
goto done; goto done;
} }
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
dbname = cv_string_get(cvec_i(argv, 0)); dbname = cv_string_get(cvec_i(argv, 0));
/* Look for xpath in command (kludge: cv must be called "xpath") */ /* Look for xpath in command (kludge: cv must be called "xpath") */
if ((cv = cvec_find(cvv, "xpath")) == NULL){ if ((cv = cvec_find(cvv, "xpath")) == NULL){
clicon_err(OE_PLUGIN, EINVAL, "Requires one variable to be <xpath>"); clixon_err(OE_PLUGIN, EINVAL, "Requires one variable to be <xpath>");
goto done; goto done;
} }
xpath = cv_string_get(cv); xpath = cv_string_get(cv);
@ -887,7 +886,7 @@ done:
/*! Show clixon and CLIgen versions /*! Show clixon and CLIgen versions
*/ */
int int
cli_show_version(clicon_handle h, cli_show_version(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -936,7 +935,7 @@ cli_show_version(clicon_handle h,
* @see cli_callback_generate where api_path_fmt + mt-point are generated * @see cli_callback_generate where api_path_fmt + mt-point are generated
*/ */
int int
cli_show_auto(clicon_handle h, cli_show_auto(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -961,7 +960,7 @@ cli_show_auto(clicon_handle h,
int fromroot = 0; int fromroot = 0;
if (cvec_len(argv) < 2 || cvec_len(argv) > 9){ if (cvec_len(argv) < 2 || cvec_len(argv) > 9){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend> <fromroot>]", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend> <fromroot>]", cvec_len(argv));
goto done; goto done;
} }
api_path_fmt = cv_string_get(cvec_i(argv, argc++)); api_path_fmt = cv_string_get(cvec_i(argv, argc++));
@ -997,7 +996,7 @@ cli_show_auto(clicon_handle h,
goto done; goto done;
} }
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if (mtpoint){ if (mtpoint){
@ -1014,7 +1013,7 @@ cli_show_auto(clicon_handle h,
if (api_path2xpath(api_path, yspec0, &xpath, &nsc, NULL) < 0) if (api_path2xpath(api_path, yspec0, &xpath, &nsc, NULL) < 0)
goto done; goto done;
if (xpath == NULL){ if (xpath == NULL){
clicon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path); clixon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
goto done; goto done;
} }
if (cli_show_common(h, dbname, format, pretty, state, if (cli_show_common(h, dbname, format, pretty, state,
@ -1069,7 +1068,7 @@ code
* @see cli_show_config with no autocli coupling * @see cli_show_config with no autocli coupling
*/ */
int int
cli_show_auto_mode(clicon_handle h, cli_show_auto_mode(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1096,11 +1095,11 @@ cli_show_auto_mode(clicon_handle h,
int fromroot = 0; int fromroot = 0;
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){ if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <database> [ <format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv)); clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <database> [ <format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv));
goto done; goto done;
} }
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
dbname = cv_string_get(cvec_i(argv, argc++)); dbname = cv_string_get(cvec_i(argv, argc++));
@ -1140,11 +1139,11 @@ cli_show_auto_mode(clicon_handle h,
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0) if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
goto done; goto done;
if (xpath == NULL){ if (xpath == NULL){
clicon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path); clixon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
goto done; goto done;
} }
if ((cbxpath = cbuf_new()) == NULL){ if ((cbxpath = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (mtpoint){ if (mtpoint){
@ -1184,7 +1183,7 @@ cli_show_auto_mode(clicon_handle h,
'* @see clicon_option_dump clicon_option_dump1 '* @see clicon_option_dump clicon_option_dump1
*/ */
int int
cli_show_options(clicon_handle h, cli_show_options(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1248,7 +1247,7 @@ cli_show_options(clicon_handle h,
* Also, if there is a cligen variable called "xpath" it will override argv xpath arg * Also, if there is a cligen variable called "xpath" it will override argv xpath arg
*/ */
int int
cli_pagination(clicon_handle h, cli_pagination(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1272,7 +1271,7 @@ cli_pagination(clicon_handle h,
int locked = 0; int locked = 0;
if (cvec_len(argv) != 5){ if (cvec_len(argv) != 5){
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>"); clixon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
goto done; goto done;
} }
/* prefix:variable overrides argv */ /* prefix:variable overrides argv */
@ -1284,17 +1283,17 @@ cli_pagination(clicon_handle h,
namespace = cvec_i_str(argv, 2); namespace = cvec_i_str(argv, 2);
str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */ str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
if ((int)(format = format_str2int(str)) < 0){ if ((int)(format = format_str2int(str)) < 0){
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", str); clixon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
goto done; goto done;
} }
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){ if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
if (parse_uint32(str, &limit, NULL) < 1){ if (parse_uint32(str, &limit, NULL) < 1){
clicon_err(OE_UNIX, errno, "error parsing limit:%s", str); clixon_err(OE_UNIX, errno, "error parsing limit:%s", str);
goto done; goto done;
} }
} }
if (limit == 0){ if (limit == 0){
clicon_err(OE_UNIX, EINVAL, "limit is 0"); clixon_err(OE_UNIX, EINVAL, "limit is 0");
goto done; goto done;
} }
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL) if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
@ -1314,7 +1313,7 @@ cli_pagination(clicon_handle h,
goto done; goto done;
} }
if ((xerr = xpath_first(xret, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xret, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0) if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0)
@ -1386,7 +1385,7 @@ cli_pagination(clicon_handle h,
* @see clixon_cli2file * @see clixon_cli2file
*/ */
static int static int
cli2cbuf(clicon_handle h, cli2cbuf(clixon_handle h,
cbuf *cb, cbuf *cb,
cxobj *xn, cxobj *xn,
char *prepend) char *prepend)
@ -1435,7 +1434,7 @@ cli2cbuf(clicon_handle h,
} }
/* Create prepend variable string */ /* Create prepend variable string */
if ((cbpre = cbuf_new()) == NULL){ if ((cbpre = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
if (prepend) if (prepend)
@ -1514,7 +1513,7 @@ cli2cbuf(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
cli2file(clicon_handle h, cli2file(clixon_handle h,
FILE *f, FILE *f,
cxobj *xn, cxobj *xn,
char *prepend, char *prepend,
@ -1564,7 +1563,7 @@ cli2file(clicon_handle h,
} }
/* Create prepend variable string */ /* Create prepend variable string */
if ((cbpre = cbuf_new()) == NULL){ if ((cbpre = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
if (prepend) if (prepend)
@ -1645,7 +1644,7 @@ cli2file(clicon_handle h,
* @see clixon_cli2cbuf * @see clixon_cli2cbuf
*/ */
int int
clixon_cli2file(clicon_handle h, clixon_cli2file(clixon_handle h,
FILE *f, FILE *f,
cxobj *xn, cxobj *xn,
char *prepend, char *prepend,
@ -1687,7 +1686,7 @@ clixon_cli2file(clicon_handle h,
* @see clixon_cli2file * @see clixon_cli2file
*/ */
int int
clixon_cli2cbuf(clicon_handle h, clixon_cli2cbuf(clixon_handle h,
cbuf *cb, cbuf *cb,
cxobj *xn, cxobj *xn,
char *prepend, char *prepend,
@ -1714,7 +1713,7 @@ clixon_cli2cbuf(clicon_handle h,
/*! CLI callback show statistics /*! CLI callback show statistics
*/ */
int int
cli_show_statistics(clicon_handle h, cli_show_statistics(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -1730,7 +1729,7 @@ cli_show_statistics(clicon_handle h,
size_t sz = 0; size_t sz = 0;
if (argv != NULL && cvec_len(argv) != 1){ if (argv != NULL && cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Expected arguments: [modules]"); clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [modules]");
goto done; goto done;
} }
if (argv){ if (argv){
@ -1738,7 +1737,7 @@ cli_show_statistics(clicon_handle h,
modules = (strcmp(cv_string_get(cv), "modules") == 0); modules = (strcmp(cv_string_get(cv), "modules") == 0);
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
/* CLI */ /* CLI */
@ -1764,7 +1763,7 @@ cli_show_statistics(clicon_handle h,
if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, NULL) < 0) if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, NULL) < 0)
goto done; goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){ if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
fprintf(stdout, "Backend:\n"); fprintf(stdout, "Backend:\n");

View file

@ -53,17 +53,17 @@ extern "C" {
* *
* @see plginit_t * @see plginit_t
*/ */
int plugin_init(clicon_handle h); int plugin_init(clixon_handle h);
/* Called when backend started with cmd-line arguments from daemon call. /* Called when backend started with cmd-line arguments from daemon call.
* @see plgstart_t * @see plgstart_t
*/ */
int plugin_start(clicon_handle h, int argc, char **argv); int plugin_start(clixon_handle h, int argc, char **argv);
/* Called just before plugin unloaded. /* Called just before plugin unloaded.
* @see plgexit_t * @see plgexit_t
*/ */
int plugin_exit(clicon_handle h); int plugin_exit(clixon_handle h);
#endif /* _CLIXON_CLI_H_ */ #endif /* _CLIXON_CLI_H_ */

View file

@ -63,21 +63,21 @@ typedef enum autocli_listkw autocli_listkw_t;
* Function Declarations * Function Declarations
*/ */
/* cli_plugin.c */ /* cli_plugin.c */
int cli_set_syntax_mode(clicon_handle h, char *mode); int cli_set_syntax_mode(clixon_handle h, char *mode);
char *cli_syntax_mode(clicon_handle h); char *cli_syntax_mode(clixon_handle h);
int clispec_load(clicon_handle h); int clispec_load(clixon_handle h);
int cli_handler_err(FILE *fd); int cli_handler_err(FILE *fd);
int cli_set_prompt(clicon_handle h, char *mode, char *prompt); int cli_set_prompt(clixon_handle h, char *mode, char *prompt);
int cli_ptpush(clicon_handle h, char *mode, char *string, char *op); int cli_ptpush(clixon_handle h, char *mode, char *string, char *op);
int cli_ptpop(clicon_handle h, char *mode, char *op); int cli_ptpop(clixon_handle h, char *mode, char *op);
/* cli_handle.c */ /* cli_handle.c */
clicon_handle cli_handle_init(void); clixon_handle cli_handle_init(void);
int cli_handle_exit(clicon_handle h); int cli_handle_exit(clixon_handle h);
cligen_handle cli_cligen(clicon_handle h); cligen_handle cli_cligen(clixon_handle h);
/* cli_common.c */ /* cli_common.c */
int cli_notification_register(clicon_handle h, char *stream, enum format_enum format, int cli_notification_register(clixon_handle h, char *stream, enum format_enum format,
char *filter, int status, char *filter, int status,
int (*fn)(int, void*), void *arg); int (*fn)(int, void*), void *arg);
@ -85,70 +85,70 @@ int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **
int dbxml_body(cxobj *xbot, cvec *cvv); int dbxml_body(cxobj *xbot, cvec *cvv);
int identityref_add_ns(cxobj *x, void *arg); int identityref_add_ns(cxobj *x, void *arg);
int cli_dbxml(clicon_handle h, cvec *vars, cvec *argv, enum operation_type op, cvec *nsctx); int cli_dbxml(clixon_handle h, cvec *vars, cvec *argv, enum operation_type op, cvec *nsctx);
int cli_set(clicon_handle h, cvec *vars, cvec *argv); int cli_set(clixon_handle h, cvec *vars, cvec *argv);
int cli_merge(clicon_handle h, cvec *vars, cvec *argv); int cli_merge(clixon_handle h, cvec *vars, cvec *argv);
int cli_create(clicon_handle h, cvec *vars, cvec *argv); int cli_create(clixon_handle h, cvec *vars, cvec *argv);
int cli_remove(clicon_handle h, cvec *vars, cvec *argv); int cli_remove(clixon_handle h, cvec *vars, cvec *argv);
int cli_del(clicon_handle h, cvec *vars, cvec *argv); int cli_del(clixon_handle h, cvec *vars, cvec *argv);
int cli_debug_cli(clicon_handle h, cvec *vars, cvec *argv); int cli_debug_cli(clixon_handle h, cvec *vars, cvec *argv);
int cli_debug_backend(clicon_handle h, cvec *vars, cvec *argv); int cli_debug_backend(clixon_handle h, cvec *vars, cvec *argv);
int cli_debug_restconf(clicon_handle h, cvec *vars, cvec *argv); int cli_debug_restconf(clixon_handle h, cvec *vars, cvec *argv);
int cli_set_mode(clicon_handle h, cvec *vars, cvec *argv); int cli_set_mode(clixon_handle h, cvec *vars, cvec *argv);
int cli_start_shell(clicon_handle h, cvec *vars, cvec *argv); int cli_start_shell(clixon_handle h, cvec *vars, cvec *argv);
int cli_quit(clicon_handle h, cvec *vars, cvec *argv); int cli_quit(clixon_handle h, cvec *vars, cvec *argv);
int cli_commit(clicon_handle h, cvec *vars, cvec *argv); int cli_commit(clixon_handle h, cvec *vars, cvec *argv);
int cli_validate(clicon_handle h, cvec *vars, cvec *argv); int cli_validate(clixon_handle h, cvec *vars, cvec *argv);
int compare_db_names(clicon_handle h, enum format_enum format, char *db1, char *db2); int compare_db_names(clixon_handle h, enum format_enum format, char *db1, char *db2);
int compare_dbs(clicon_handle h, cvec *vars, cvec *argv); int compare_dbs(clixon_handle h, cvec *vars, cvec *argv);
int load_config_file(clicon_handle h, cvec *vars, cvec *argv); int load_config_file(clixon_handle h, cvec *vars, cvec *argv);
int save_config_file(clicon_handle h, cvec *vars, cvec *argv); int save_config_file(clixon_handle h, cvec *vars, cvec *argv);
int delete_all(clicon_handle h, cvec *vars, cvec *argv); int delete_all(clixon_handle h, cvec *vars, cvec *argv);
int discard_changes(clicon_handle h, cvec *vars, cvec *argv); int discard_changes(clixon_handle h, cvec *vars, cvec *argv);
int cli_notify(clicon_handle h, cvec *cvv, cvec *argv); int cli_notify(clixon_handle h, cvec *cvv, cvec *argv);
int db_copy(clicon_handle h, cvec *cvv, cvec *argv); int db_copy(clixon_handle h, cvec *cvv, cvec *argv);
int cli_lock(clicon_handle h, cvec *cvv, cvec *argv); int cli_lock(clixon_handle h, cvec *cvv, cvec *argv);
int cli_unlock(clicon_handle h, cvec *cvv, cvec *argv); int cli_unlock(clixon_handle h, cvec *cvv, cvec *argv);
int cli_copy_config(clicon_handle h, cvec *cvv, cvec *argv); int cli_copy_config(clixon_handle h, cvec *cvv, cvec *argv);
int cli_help(clicon_handle h, cvec *vars, cvec *argv); int cli_help(clixon_handle h, cvec *vars, cvec *argv);
cvec *cvec_append(cvec *cvv0, cvec *cvv1); cvec *cvec_append(cvec *cvv0, cvec *cvv1);
int cvec_concat_cb(cvec *cvv, cbuf *cb); int cvec_concat_cb(cvec *cvv, cbuf *cb);
int cli_process_control(clicon_handle h, cvec *vars, cvec *argv); int cli_process_control(clixon_handle h, cvec *vars, cvec *argv);
/* In cli_show.c */ /* In cli_show.c */
int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv, int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
cvec *commands, cvec *helptexts); cvec *commands, cvec *helptexts);
int clixon_cli2file(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop); int clixon_cli2file(clixon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
int clixon_cli2cbuf(clicon_handle h, cbuf *cb, cxobj *xn, char *prepend, int skiptop); int clixon_cli2cbuf(clixon_handle h, cbuf *cb, cxobj *xn, char *prepend, int skiptop);
/* cli_show.c: CLIgen new vector arg callbacks */ /* cli_show.c: CLIgen new vector arg callbacks */
int cli_show_common(clicon_handle h, char *db, enum format_enum format, int pretty, int state, char *withdefault, char *extdefault, char *prepend, char *xpath, int fromroot, cvec *nsc, int skiptop); int cli_show_common(clixon_handle h, char *db, enum format_enum format, int pretty, int state, char *withdefault, char *extdefault, char *prepend, char *xpath, int fromroot, cvec *nsc, int skiptop);
int show_yang(clicon_handle h, cvec *vars, cvec *argv); int show_yang(clixon_handle h, cvec *vars, cvec *argv);
int show_conf_xpath(clicon_handle h, cvec *cvv, cvec *argv); int show_conf_xpath(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_option_format(cvec *argv, int argc, enum format_enum *format); int cli_show_option_format(cvec *argv, int argc, enum format_enum *format);
int cli_show_option_bool(cvec *argv, int argc, int *result); int cli_show_option_bool(cvec *argv, int argc, int *result);
int cli_show_option_withdefault(cvec *argv, int argc, char **withdefault, char **extdefault); int cli_show_option_withdefault(cvec *argv, int argc, char **withdefault, char **extdefault);
int cli_show_config(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_config(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_config_state(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_config_state(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_auto(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_auto(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_options(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_options(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_version(clicon_handle h, cvec *vars, cvec *argv); int cli_show_version(clixon_handle h, cvec *vars, cvec *argv);
/* cli_auto.c: Autocli mode support */ /* cli_auto.c: Autocli mode support */
int cli_auto_edit(clicon_handle h, cvec *cvv1, cvec *argv); int cli_auto_edit(clixon_handle h, cvec *cvv1, cvec *argv);
int cli_auto_up(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_up(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_top(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_top(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_auto_mode(clicon_handle h, cvec *cvv, cvec *argv); int cli_show_auto_mode(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_set(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_set(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_merge(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_merge(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_create(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_create(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_del(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_del(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_sub_enter(clicon_handle h, cvec *cvv, cvec *argv); int cli_auto_sub_enter(clixon_handle h, cvec *cvv, cvec *argv);
int cli_pagination(clicon_handle h, cvec *cvv, cvec *argv); int cli_pagination(clixon_handle h, cvec *cvv, cvec *argv);
#endif /* _CLIXON_CLI_API_H_ */ #endif /* _CLIXON_CLI_API_H_ */

View file

@ -59,7 +59,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "netconf_rpc.h" #include "netconf_rpc.h"

View file

@ -63,7 +63,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
//#include "clixon_netconf.h" //#include "clixon_netconf.h"
@ -145,7 +145,7 @@ netconf_add_request_attr(cxobj *xrpc,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
netconf_hello_msg(clicon_handle h, netconf_hello_msg(clixon_handle h,
cxobj *xn, cxobj *xn,
int *eof) int *eof)
{ {
@ -162,7 +162,7 @@ netconf_hello_msg(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
_netconf_hello_nr++; _netconf_hello_nr++;
if (xml_find_type(xn, NULL, "session-id", CX_ELMNT) != NULL) { 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"); clixon_err(OE_XML, errno, "Server received hello with session-id from client, terminating (see RFC 6241 Sec 8.1");
goto done; goto done;
} }
if (xpath_vec(xn, nsc, "capabilities/capability", &vec, &veclen) < 0) if (xpath_vec(xn, nsc, "capabilities/capability", &vec, &veclen) < 0)
@ -190,7 +190,7 @@ netconf_hello_msg(clicon_handle h,
} }
} }
if (foundbase_10 == 0 && foundbase_11 == 0){ if (foundbase_10 == 0 && foundbase_11 == 0){
clicon_err(OE_XML, errno, "Server received hello without matching netconf base capability, terminating (see RFC 6241 Sec 8.1"); clixon_err(OE_XML, errno, "Server received hello without matching netconf base capability, terminating (see RFC 6241 Sec 8.1");
*eof = 1; *eof = 1;
goto done; goto done;
} }
@ -211,7 +211,7 @@ netconf_hello_msg(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
netconf_rpc_message(clicon_handle h, netconf_rpc_message(clixon_handle h,
cxobj *xrpc, cxobj *xrpc,
yang_stmt *yspec, yang_stmt *yspec,
int *eof) int *eof)
@ -232,7 +232,7 @@ netconf_rpc_message(clicon_handle h,
if (netconf_add_request_attr(xrpc, xret) < 0) if (netconf_add_request_attr(xrpc, xret) < 0)
goto done; goto done;
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
@ -253,7 +253,7 @@ netconf_rpc_message(clicon_handle h,
if (netconf_add_request_attr(xrpc, xret) < 0) if (netconf_add_request_attr(xrpc, xret) < 0)
goto done; goto done;
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
@ -274,7 +274,7 @@ netconf_rpc_message(clicon_handle h,
if (netconf_add_request_attr(xrpc, xret) < 0) if (netconf_add_request_attr(xrpc, xret) < 0)
goto done; goto done;
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
@ -290,7 +290,7 @@ netconf_rpc_message(clicon_handle h,
if (netconf_add_request_attr(xrpc, xc) < 0) if (netconf_add_request_attr(xrpc, xc) < 0)
goto done; goto done;
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, NULL, -1, 0) < 0)
@ -321,7 +321,7 @@ netconf_rpc_message(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
netconf_input_packet(clicon_handle h, netconf_input_packet(clixon_handle h,
cxobj *xreq, cxobj *xreq,
yang_stmt *yspec, yang_stmt *yspec,
int *eof) int *eof)
@ -349,7 +349,7 @@ netconf_input_packet(clicon_handle h,
if (netconf_add_request_attr(xreq, xret) < 0) if (netconf_add_request_attr(xreq, xret) < 0)
goto done; goto done;
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
@ -367,7 +367,7 @@ netconf_input_packet(clicon_handle h,
/* Only accept resolved NETCONF base namespace -> terminate*/ /* Only accept resolved NETCONF base namespace -> terminate*/
if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){ if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
*eof = 1; *eof = 1;
clicon_err(OE_XML, EFAULT, "No appropriate namespace associated with namespace:%s", clixon_err(OE_XML, EFAULT, "No appropriate namespace associated with namespace:%s",
namespace); namespace);
goto done; goto done;
} }
@ -376,7 +376,7 @@ netconf_input_packet(clicon_handle h,
} }
else{ /* Shouldnt happen should be caught by yang bind check in netconf_input_frame */ else{ /* Shouldnt happen should be caught by yang bind check in netconf_input_frame */
*eof = 1; *eof = 1;
clicon_err(OE_NETCONF, 0, "Unrecognized netconf operation %s", rpcname); clixon_err(OE_NETCONF, 0, "Unrecognized netconf operation %s", rpcname);
goto done; goto done;
} }
ok: ok:
@ -408,7 +408,7 @@ netconf_input_cb(int s,
void *arg) void *arg)
{ {
int retval = -1; int retval = -1;
clicon_handle h = arg; clixon_handle h = arg;
cbuf *cbmsg=NULL; cbuf *cbmsg=NULL;
cbuf *cberr = NULL; cbuf *cberr = NULL;
void *ptr; void *ptr;
@ -435,7 +435,7 @@ netconf_input_cb(int s,
/* Get unfinished frame */ /* Get unfinished frame */
if ((ptr = clicon_hash_value(cdat, NETCONF_FRAME_MSG, &cdatlen)) != NULL){ if ((ptr = clicon_hash_value(cdat, NETCONF_FRAME_MSG, &cdatlen)) != NULL){
if (cdatlen != sizeof(cbmsg)){ if (cdatlen != sizeof(cbmsg)){
clicon_err(OE_XML, errno, "size mismatch %lu %lu", clixon_err(OE_XML, errno, "size mismatch %lu %lu",
(unsigned long)cdatlen, (unsigned long)sizeof(cbmsg)); (unsigned long)cdatlen, (unsigned long)sizeof(cbmsg));
goto done; goto done;
} }
@ -444,7 +444,7 @@ netconf_input_cb(int s,
} }
else{ else{
if ((cbmsg = cbuf_new()) == NULL){ if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
} }
@ -482,7 +482,7 @@ netconf_input_cb(int s,
cbuf_reset(cbmsg); cbuf_reset(cbmsg);
if (ret == 0){ /* Invalid frame, parse error, etc */ if (ret == 0){ /* Invalid frame, parse error, etc */
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cberr, xerr, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cberr, xerr, 0, 0, NULL, -1, 0) < 0)
@ -498,7 +498,7 @@ netconf_input_cb(int s,
} }
else { else {
if ((xreq = xml_child_i_type(xtop, 0, CX_ELMNT)) == NULL){ if ((xreq = xml_child_i_type(xtop, 0, CX_ELMNT)) == NULL){
clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)"); clixon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)");
goto done; goto done;
} }
if (netconf_input_packet(h, xreq, yspec, &eof) < 0){ if (netconf_input_packet(h, xreq, yspec, &eof) < 0){
@ -541,7 +541,7 @@ netconf_input_cb(int s,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
send_hello(clicon_handle h, send_hello(clixon_handle h,
int s, int s,
uint32_t id) uint32_t id)
{ {
@ -550,7 +550,7 @@ send_hello(clicon_handle h,
netconf_framing_type framing; netconf_framing_type framing;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_log(LOG_ERR, "%s: cbuf_new", __FUNCTION__); clixon_log(h, LOG_ERR, "%s: cbuf_new", __FUNCTION__);
goto done; goto done;
} }
if (netconf_hello_server(h, cb, id) < 0) if (netconf_hello_server(h, cb, id) < 0)
@ -573,7 +573,7 @@ send_hello(clicon_handle h,
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
static int static int
netconf_terminate(clicon_handle h) netconf_terminate(clixon_handle h)
{ {
yang_stmt *yspec; yang_stmt *yspec;
cvec *nsctx; cvec *nsctx;
@ -594,22 +594,21 @@ netconf_terminate(clicon_handle h)
xml_free(x); xml_free(x);
xpath_optimize_exit(); xpath_optimize_exit();
clixon_event_exit(); clixon_event_exit();
clicon_handle_exit(h); clixon_handle_exit(h);
clixon_err_exit(); clixon_err_exit();
clicon_log_exit(); clixon_log_exit();
return 0; return 0;
} }
/*! Setup signal handlers /*! Setup signal handlers
*/ */
static int static int
netconf_signal_init (clicon_handle h) netconf_signal_init (clixon_handle h)
{ {
int retval = -1; int retval = -1;
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal"); clixon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -621,7 +620,7 @@ static int
timeout_fn(int s, timeout_fn(int s,
void *arg) void *arg)
{ {
clicon_err(OE_EVENTS, ETIMEDOUT, "User request timeout"); clixon_err(OE_EVENTS, ETIMEDOUT, "User request timeout");
return -1; return -1;
} }
@ -631,7 +630,7 @@ timeout_fn(int s,
* @param[in] argv0 command line * @param[in] argv0 command line
*/ */
static void static void
usage(clicon_handle h, usage(clixon_handle h,
char *argv0) char *argv0)
{ {
fprintf(stderr, "usage:%s\n" fprintf(stderr, "usage:%s\n"
@ -669,9 +668,9 @@ main(int argc,
int c; int c;
char *argv0 = argv[0]; char *argv0 = argv[0];
int quiet = 0; int quiet = 0;
clicon_handle h; clixon_handle h;
char *dir; char *dir;
int logdst = CLICON_LOG_SYSLOG; int logdst = CLIXON_LOG_SYSLOG;
struct passwd *pw; struct passwd *pw;
struct timeval tv = {0,}; /* timeout */ struct timeval tv = {0,}; /* timeout */
yang_stmt *yspec = NULL; yang_stmt *yspec = NULL;
@ -687,14 +686,16 @@ main(int argc,
int print_version = 0; int print_version = 0;
/* Create handle */ /* Create handle */
if ((h = clicon_handle_init()) == NULL) if ((h = clixon_handle_init()) == NULL)
return -1; return -1;
/* In the startup, logs to stderr & debug flag set later */ /* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst); if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
return -1;
if (clixon_err_init(h) < 0)
return -1;
/* Set username to clixon handle. Use in all communication to backend */ /* Set username to clixon handle. Use in all communication to backend */
if ((pw = getpwuid(getuid())) == NULL){ if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid"); clixon_err(OE_UNIX, errno, "getpwuid");
goto done; goto done;
} }
if (clicon_username_set(h, pw->pw_name) < 0) if (clicon_username_set(h, pw->pw_name) < 0)
@ -723,11 +724,11 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break; break;
case 'l': /* Log destination: s|e|o */ case 'l': /* Log destination: s|e|o */
if ((logdst = clicon_log_opt(optarg[0])) < 0) if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]); usage(h, argv[0]);
if (logdst == CLICON_LOG_FILE && if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 && strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0) clixon_log_file(optarg+1) < 0)
goto done; goto done;
break; break;
} }
@ -735,8 +736,8 @@ main(int argc,
/* /*
* Logs, error and debug to stderr or syslog, set debug level * Logs, error and debug to stderr or syslog, set debug level
*/ */
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
yang_init(h); yang_init(h);
/* Find, read and parse configfile */ /* Find, read and parse configfile */
@ -832,7 +833,7 @@ main(int argc,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(sz); clixon_log_string_limit_set(sz);
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h); xml_nsctx_namespace_netconf_default(h);
@ -954,7 +955,7 @@ main(int argc,
retval = 0; retval = 0;
clixon_exit_set(1); /* This is to disable resend mechanism in close-session */ clixon_exit_set(1); /* This is to disable resend mechanism in close-session */
netconf_terminate(h); netconf_terminate(h);
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
return retval; return retval;
} }

View file

@ -67,7 +67,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "netconf_filter.h" #include "netconf_filter.h"
@ -80,7 +80,7 @@
*/ */
static int static int
netconf_get_config_subtree(clicon_handle h, netconf_get_config_subtree(clixon_handle h,
cxobj *xfilter, cxobj *xfilter,
cxobj **xret) cxobj **xret)
{ {
@ -158,7 +158,7 @@ ok:
<rpc><get-config><source><candidate/></source><filter type="xpath" select="/interfaces/interface/ipv4"/></get-config></rpc>]]>]]> <rpc><get-config><source><candidate/></source><filter type="xpath" select="/interfaces/interface/ipv4"/></get-config></rpc>]]>]]>
*/ */
static int static int
netconf_get_config(clicon_handle h, netconf_get_config(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret) cxobj **xret)
{ {
@ -321,7 +321,7 @@ CLIXON addition:
* @note erropt, testopt only supports default * @note erropt, testopt only supports default
*/ */
static int static int
netconf_edit_config(clicon_handle h, netconf_edit_config(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret) cxobj **xret)
{ {
@ -371,7 +371,7 @@ netconf_edit_config(clicon_handle h,
* </get></rpc>]]>]]> * </get></rpc>]]>]]>
*/ */
static int static int
netconf_get(clicon_handle h, netconf_get(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret) cxobj **xret)
{ {
@ -453,7 +453,7 @@ netconf_notification_cb(int s,
cbuf *cb = NULL; cbuf *cb = NULL;
cxobj *xn = NULL; /* event xml */ cxobj *xn = NULL; /* event xml */
cxobj *xt = NULL; /* top xml */ cxobj *xt = NULL; /* top xml */
clicon_handle h = (clicon_handle)arg; clixon_handle h = (clixon_handle)arg;
yang_stmt *yspec = NULL; yang_stmt *yspec = NULL;
cvec *nsc = NULL; cvec *nsc = NULL;
int ret; int ret;
@ -465,7 +465,7 @@ netconf_notification_cb(int s,
goto done; goto done;
/* handle close from remote end: this will exit the client */ /* handle close from remote end: this will exit the client */
if (eof){ if (eof){
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
close(s); close(s);
errno = ESHUTDOWN; errno = ESHUTDOWN;
clixon_event_unreg_fd(s, netconf_notification_cb); clixon_event_unreg_fd(s, netconf_notification_cb);
@ -475,7 +475,7 @@ netconf_notification_cb(int s,
if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0) if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ /* XXX use xerr */ if (ret == 0){ /* XXX use xerr */
clicon_err(OE_NETCONF, EFAULT, "Notification malformed"); clixon_err(OE_NETCONF, EFAULT, "Notification malformed");
goto done; goto done;
} }
if ((nsc = xml_nsctx_init(NULL, NETCONF_NOTIFICATION_NAMESPACE)) == NULL) if ((nsc = xml_nsctx_init(NULL, NETCONF_NOTIFICATION_NAMESPACE)) == NULL)
@ -484,7 +484,7 @@ netconf_notification_cb(int s,
goto ok; goto ok;
/* create netconf message */ /* create netconf message */
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0)
@ -494,7 +494,7 @@ netconf_notification_cb(int s,
goto done; goto done;
} }
if (netconf_output(1, cb, "notification") < 0){ if (netconf_output(1, cb, "notification") < 0){
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
close(s); close(s);
errno = ESHUTDOWN; errno = ESHUTDOWN;
clixon_event_unreg_fd(s, netconf_notification_cb); clixon_event_unreg_fd(s, netconf_notification_cb);
@ -532,7 +532,7 @@ netconf_notification_cb(int s,
* @see netconf_notification_cb for asynchronous stream notifications * @see netconf_notification_cb for asynchronous stream notifications
*/ */
static int static int
netconf_create_subscription(clicon_handle h, netconf_create_subscription(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret) cxobj **xret)
{ {
@ -585,7 +585,7 @@ netconf_create_subscription(clicon_handle h,
* @see netconf_input_packet Assume bind and validation made there * @see netconf_input_packet Assume bind and validation made there
*/ */
static int static int
netconf_application_rpc(clicon_handle h, netconf_application_rpc(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret) cxobj **xret)
{ {
@ -603,17 +603,17 @@ netconf_application_rpc(clicon_handle h,
/* First check system / netconf RPC:s */ /* First check system / netconf RPC:s */
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new"); clixon_err(OE_UNIX, 0, "cbuf_new");
goto done; goto done;
} }
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new"); clixon_err(OE_UNIX, 0, "cbuf_new");
goto done; goto done;
} }
/* Find yang rpc statement, return yang rpc statement if found /* Find yang rpc statement, return yang rpc statement if found
Check application RPC */ Check application RPC */
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
cbuf_reset(cb); cbuf_reset(cb);
@ -666,7 +666,7 @@ netconf_application_rpc(clicon_handle h,
if (ret == 0){ if (ret == 0){
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
goto done; goto done;
clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret)); clixon_log(h, LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
goto ok; goto ok;
} }
} }
@ -697,7 +697,7 @@ netconf_application_rpc(clicon_handle h,
* @retval -1 Error, fatal * @retval -1 Error, fatal
*/ */
int int
netconf_rpc_dispatch(clicon_handle h, netconf_rpc_dispatch(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret, cxobj **xret,
int *eof) int *eof)

View file

@ -43,7 +43,7 @@
* Prototypes * Prototypes
*/ */
int int
netconf_rpc_dispatch(clicon_handle h, netconf_rpc_dispatch(clixon_handle h,
cxobj *xn, cxobj *xn,
cxobj **xret, cxobj **xret,
int *eof); int *eof);

View file

@ -41,7 +41,7 @@
*/ */
struct clixon_http1_yacc { struct clixon_http1_yacc {
const char *hy_name; /* Name of syntax (for error string) */ const char *hy_name; /* Name of syntax (for error string) */
clicon_handle hy_h; /* Clixon handle */ clixon_handle hy_h; /* Clixon handle */
restconf_conn *hy_rc; /* Connection handle */ restconf_conn *hy_rc; /* Connection handle */
int hy_linenum; /* Number of \n in parsed buffer */ int hy_linenum; /* Number of \n in parsed buffer */
char *hy_parse_string; /* original (copy of) parse string */ char *hy_parse_string; /* original (copy of) parse string */

View file

@ -78,7 +78,7 @@
/* typecast macro */ /* typecast macro */
#define _HY ((clixon_http1_yacc *)_hy) #define _HY ((clixon_http1_yacc *)_hy)
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_http1_parsetext, _HY->hy_linenum); YYERROR;} #define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_http1_parsetext, _HY->hy_linenum); YYERROR;}
/* add _yy to error parameters */ /* add _yy to error parameters */
#define YY_(msgid) msgid #define YY_(msgid) msgid
@ -124,7 +124,7 @@ void
clixon_http1_parseerror(void *_hy, clixon_http1_parseerror(void *_hy,
char *s) char *s)
{ {
clicon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'", clixon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'",
_HY->hy_name, _HY->hy_name,
_HY->hy_linenum, _HY->hy_linenum,
s, s,
@ -153,7 +153,7 @@ http1_parse_query(clixon_http1_yacc *hy,
clixon_debug(CLIXON_DBG_DEFAULT, "%s: ?%s ", __FUNCTION__, query); clixon_debug(CLIXON_DBG_DEFAULT, "%s: ?%s ", __FUNCTION__, query);
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){ if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
clicon_err(OE_RESTCONF, 0, "stream 0 not found"); clixon_err(OE_RESTCONF, 0, "stream 0 not found");
goto done; goto done;
} }
if (uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0) if (uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0)
@ -172,11 +172,11 @@ http1_body(clixon_http1_yacc *hy,
clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s ", __FUNCTION__, body); clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s ", __FUNCTION__, body);
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){ if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
clicon_err(OE_RESTCONF, 0, "stream 0 not found"); clixon_err(OE_RESTCONF, 0, "stream 0 not found");
goto done; goto done;
} }
if (cbuf_append_buf(sd->sd_indata, body, strlen(body)) < 0){ if (cbuf_append_buf(sd->sd_indata, body, strlen(body)) < 0){
clicon_err(OE_RESTCONF, errno, "cbuf_append_buf"); clixon_err(OE_RESTCONF, errno, "cbuf_append_buf");
goto done; goto done;
} }
retval = 0; retval = 0;

View file

@ -58,7 +58,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
/* restconf */ /* restconf */
@ -91,7 +91,7 @@ static const map_str2str mime_map[] = {
* @retval 0 No, not a data path, or not enabled * @retval 0 No, not a data path, or not enabled
*/ */
int int
api_path_is_data(clicon_handle h) api_path_is_data(clixon_handle h)
{ {
int retval = 0; int retval = 0;
char *path = NULL; char *path = NULL;
@ -124,7 +124,7 @@ api_path_is_data(clicon_handle h)
* @see api_return_err * @see api_return_err
*/ */
static int static int
api_http_data_err(clicon_handle h, api_http_data_err(clixon_handle h,
void *req, void *req,
int code) int code)
{ {
@ -133,7 +133,7 @@ api_http_data_err(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (restconf_reply_header(req, "Content-Type", "text/html") < 0) if (restconf_reply_header(req, "Content-Type", "text/html") < 0)
@ -173,7 +173,7 @@ api_http_data_err(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
http_data_check_file_path(clicon_handle h, http_data_check_file_path(clixon_handle h,
void *req, void *req,
char *prefix, char *prefix,
cbuf *cbpath, cbuf *cbpath,
@ -188,13 +188,13 @@ http_data_check_file_path(clicon_handle h,
FILE *f; FILE *f;
if (prefix == NULL || cbpath == NULL || fp == NULL){ if (prefix == NULL || cbpath == NULL || fp == NULL){
clicon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL"); clixon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL");
goto done; goto done;
} }
p = cbuf_get(cbpath); p = cbuf_get(cbpath);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, p); clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, p);
if (strncmp(prefix, p, strlen(prefix)) != 0){ if (strncmp(prefix, p, strlen(prefix)) != 0){
clicon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath"); clixon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath");
goto done; goto done;
} }
for (i=strlen(prefix); i<strlen(p); i++){ for (i=strlen(prefix); i<strlen(p); i++){
@ -277,7 +277,7 @@ http_data_check_file_path(clicon_handle h,
* XXX 1: Buffer copying once too many, see #if 0 below * XXX 1: Buffer copying once too many, see #if 0 below
*/ */
static int static int
api_http_data_file(clicon_handle h, api_http_data_file(clixon_handle h,
void *req, void *req,
char *pathname, char *pathname,
int head) int head)
@ -298,11 +298,11 @@ api_http_data_file(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cbfile = cbuf_new()) == NULL){ if ((cbfile = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((www_data_root = clicon_option_str(h, "CLICON_HTTP_DATA_ROOT")) == NULL){ if ((www_data_root = clicon_option_str(h, "CLICON_HTTP_DATA_ROOT")) == NULL){
clicon_err(OE_RESTCONF, ENOENT, "CLICON_HTTP_DATA_ROOT missing"); clixon_err(OE_RESTCONF, ENOENT, "CLICON_HTTP_DATA_ROOT missing");
goto done; goto done;
} }
@ -346,18 +346,18 @@ api_http_data_file(clicon_handle h,
} }
fseek(f, 0, SEEK_SET); /* same as rewind(f); */ fseek(f, 0, SEEK_SET); /* same as rewind(f); */
if ((cbdata = cbuf_new_alloc(fsize+1)) == NULL){ if ((cbdata = cbuf_new_alloc(fsize+1)) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new_alloc"); clixon_err(OE_UNIX, errno, "cbuf_new_alloc");
goto done; goto done;
} }
/* Unoptimized, no direct read but requires an extra copy, /* Unoptimized, no direct read but requires an extra copy,
* the cligen buf API should have some mechanism for this case without the extra copy. * the cligen buf API should have some mechanism for this case without the extra copy.
*/ */
if ((buf = malloc(fsize)) == NULL){ if ((buf = malloc(fsize)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
if ((ret = fread(buf, fsize, 1, f)) < 0){ if ((ret = fread(buf, fsize, 1, f)) < 0){
clicon_err(OE_UNIX, errno, "fread"); clixon_err(OE_UNIX, errno, "fread");
goto done; goto done;
} }
sz = (size_t)ret; sz = (size_t)ret;
@ -368,7 +368,7 @@ api_http_data_file(clicon_handle h,
goto ok; goto ok;
} }
if (cbuf_append_buf(cbdata, buf, fsize) < 0){ if (cbuf_append_buf(cbdata, buf, fsize) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str"); clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done; goto done;
} }
if (restconf_reply_header(req, "Content-Type", "%s", media) < 0) if (restconf_reply_header(req, "Content-Type", "%s", media) < 0)
@ -410,7 +410,7 @@ api_http_data_file(clicon_handle h,
* Need to enable clixon-restconf.yang www-data feature * Need to enable clixon-restconf.yang www-data feature
*/ */
int int
api_http_data(clicon_handle h, api_http_data(clixon_handle h,
void *req, void *req,
cvec *qvec) cvec *qvec)
{ {
@ -459,7 +459,7 @@ api_http_data(clicon_handle h,
} }
/* 4. indata should be NULL (no write operations) */ /* 4. indata should be NULL (no write operations) */
if ((indata = restconf_get_indata(req)) == NULL) { if ((indata = restconf_get_indata(req)) == NULL) {
clicon_err(OE_RESTCONF, ENOENT, "Unexpected no input cbuf"); clixon_err(OE_RESTCONF, ENOENT, "Unexpected no input cbuf");
goto done; goto done;
} }
if (cbuf_len(indata)){ if (cbuf_len(indata)){
@ -474,7 +474,7 @@ api_http_data(clicon_handle h,
else if (strcmp(media_str, "*/*") != 0 && else if (strcmp(media_str, "*/*") != 0 &&
strcmp(media_str, "text/html") != 0){ strcmp(media_str, "text/html") != 0){
#ifdef NOTYET #ifdef NOTYET
clicon_log(LOG_NOTICE, "%s: media error %s", __FUNCTION__, media_str); clixon_log(h, LOG_NOTICE, "%s: media error %s", __FUNCTION__, media_str);
goto done; goto done;
#endif #endif
} }

View file

@ -41,7 +41,7 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_path_is_data(clicon_handle h); int api_path_is_data(clixon_handle h);
int api_http_data(clicon_handle h, void *req, cvec *qvec); int api_http_data(clixon_handle h, void *req, cvec *qvec);
#endif /* _CLIXON_HTTP_DATA_H_ */ #endif /* _CLIXON_HTTP_DATA_H_ */

View file

@ -69,12 +69,12 @@ const char *restconf_code2reason(int code);
const restconf_media restconf_media_str2int(char *media); const restconf_media restconf_media_str2int(char *media);
const char *restconf_media_int2str(restconf_media media); const char *restconf_media_int2str(restconf_media media);
int get_user_cookie(char *cookiestr, char *attribute, char **val); int get_user_cookie(char *cookiestr, char *attribute, char **val);
int restconf_terminate(clicon_handle h); int restconf_terminate(clixon_handle h);
int restconf_insert_attributes(cxobj *xdata, cvec *qvec); int restconf_insert_attributes(cxobj *xdata, cvec *qvec);
int restconf_main_extension_cb(clicon_handle h, yang_stmt *yext, yang_stmt *ys); int restconf_main_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys);
/* also in restconf_handle.h */ /* also in restconf_handle.h */
char *restconf_param_get(clicon_handle h, const char *param); char *restconf_param_get(clixon_handle h, const char *param);
int restconf_param_set(clicon_handle h, const char *param, char *val); int restconf_param_set(clixon_handle h, const char *param, char *val);
#endif /* _CLIXON_RESTCONF_H_ */ #endif /* _CLIXON_RESTCONF_H_ */

View file

@ -57,7 +57,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
/* restconf */ /* restconf */

View file

@ -59,7 +59,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include <fcgiapp.h> /* Need to be after clixon_xml-h due to attribute format */ #include <fcgiapp.h> /* Need to be after clixon_xml-h due to attribute format */
@ -108,7 +108,7 @@ restconf_reply_header(void *req0,
va_list ap; va_list ap;
if (req == NULL || name == NULL || vfmt == NULL){ if (req == NULL || name == NULL || vfmt == NULL){
clicon_err(OE_CFG, EINVAL, "req, name or value is NULL"); clixon_err(OE_CFG, EINVAL, "req, name or value is NULL");
return -1; return -1;
} }
va_start(ap, vfmt); va_start(ap, vfmt);
@ -116,13 +116,13 @@ restconf_reply_header(void *req0,
va_end(ap); va_end(ap);
/* allocate value string exactly fitting */ /* allocate value string exactly fitting */
if ((value = malloc(vlen+1)) == NULL){ if ((value = malloc(vlen+1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
/* second round: compute actual value */ /* second round: compute actual value */
va_start(ap, vfmt); va_start(ap, vfmt);
if (vsnprintf(value, vlen+1, vfmt, ap) < 0){ if (vsnprintf(value, vlen+1, vfmt, ap) < 0){
clicon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
goto done; goto done;
} }
@ -158,7 +158,7 @@ restconf_reply_body_add(void *req0,
va_list ap; va_list ap;
if (req == NULL || bfmt == NULL){ if (req == NULL || bfmt == NULL){
clicon_err(OE_CFG, EINVAL, "req or body is NULL"); clixon_err(OE_CFG, EINVAL, "req or body is NULL");
return -1; return -1;
} }
va_start(ap, bfmt); va_start(ap, bfmt);
@ -166,13 +166,13 @@ restconf_reply_body_add(void *req0,
va_end(ap); va_end(ap);
/* allocate body string exactly fitting */ /* allocate body string exactly fitting */
if ((body = malloc(blen+1)) == NULL){ if ((body = malloc(blen+1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
/* second round: compute actual body */ /* second round: compute actual body */
va_start(ap, bfmt); va_start(ap, bfmt);
if (vsnprintf(body, blen+1, bfmt, ap) < 0){ if (vsnprintf(body, blen+1, bfmt, ap) < 0){
clicon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
goto done; goto done;
} }

View file

@ -57,7 +57,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
@ -88,11 +88,11 @@ restconf_reply_header(void *req0,
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name); clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name);
if (sd == NULL || name == NULL || vfmt == NULL){ if (sd == NULL || name == NULL || vfmt == NULL){
clicon_err(OE_CFG, EINVAL, "sd, name or value is NULL"); clixon_err(OE_CFG, EINVAL, "sd, name or value is NULL");
goto done; goto done;
} }
if ((rc = sd->sd_conn) == NULL){ if ((rc = sd->sd_conn) == NULL){
clicon_err(OE_CFG, EINVAL, "rc is NULL"); clixon_err(OE_CFG, EINVAL, "rc is NULL");
goto done; goto done;
} }
/* First round: compute vlen and allocate value */ /* First round: compute vlen and allocate value */
@ -101,19 +101,19 @@ restconf_reply_header(void *req0,
va_end(ap); va_end(ap);
/* allocate value string exactly fitting */ /* allocate value string exactly fitting */
if ((value = malloc(vlen+1)) == NULL){ if ((value = malloc(vlen+1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
/* Second round: compute actual value */ /* Second round: compute actual value */
va_start(ap, vfmt); va_start(ap, vfmt);
if (vsnprintf(value, vlen+1, vfmt, ap) < 0){ if (vsnprintf(value, vlen+1, vfmt, ap) < 0){
clicon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
goto done; goto done;
} }
va_end(ap); va_end(ap);
if (cvec_add_string(sd->sd_outp_hdrs, (char*)name, value) < 0){ if (cvec_add_string(sd->sd_outp_hdrs, (char*)name, value) < 0){
clicon_err(OE_RESTCONF, errno, "cvec_add_string"); clixon_err(OE_RESTCONF, errno, "cvec_add_string");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -144,7 +144,7 @@ restconf_reply_send(void *req0,
clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code); clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code);
if (sd == NULL){ if (sd == NULL){
clicon_err(OE_CFG, EINVAL, "sd is NULL"); clixon_err(OE_CFG, EINVAL, "sd is NULL");
goto done; goto done;
} }
sd->sd_code = code; sd->sd_code = code;
@ -183,7 +183,7 @@ restconf_get_indata(void *req0)
cbuf *cb = NULL; cbuf *cb = NULL;
if (sd == NULL){ if (sd == NULL){
clicon_err(OE_CFG, EINVAL, "sd is NULL"); clixon_err(OE_CFG, EINVAL, "sd is NULL");
goto done; goto done;
} }
cb = sd->sd_indata; cb = sd->sd_indata;

View file

@ -62,7 +62,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
@ -79,7 +79,7 @@
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_method_notallowed(clicon_handle h, restconf_method_notallowed(clixon_handle h,
void *req, void *req,
char *allow, char *allow,
int pretty, int pretty,
@ -112,7 +112,7 @@ restconf_method_notallowed(clicon_handle h,
* return an error response with a "415 Unsupported Media Type" status-line * return an error response with a "415 Unsupported Media Type" status-line
*/ */
int int
restconf_unsupported_media(clicon_handle h, restconf_unsupported_media(clixon_handle h,
void *req, void *req,
int pretty, int pretty,
restconf_media media) restconf_media media)
@ -142,7 +142,7 @@ restconf_unsupported_media(clicon_handle h,
* return an error response with a "406 Not Acceptable" status-line. * return an error response with a "406 Not Acceptable" status-line.
*/ */
int int
restconf_not_acceptable(clicon_handle h, restconf_not_acceptable(clixon_handle h,
void *req, void *req,
int pretty, int pretty,
restconf_media media) restconf_media media)
@ -166,7 +166,7 @@ restconf_not_acceptable(clicon_handle h,
* @param[in] req Generic http handle * @param[in] req Generic http handle
*/ */
int int
restconf_notimplemented(clicon_handle h, restconf_notimplemented(clixon_handle h,
void *req, void *req,
int pretty, int pretty,
restconf_media media) restconf_media media)
@ -201,7 +201,7 @@ restconf_notimplemented(clicon_handle h,
* @note there are special cases see code * @note there are special cases see code
*/ */
int int
api_return_err(clicon_handle h, api_return_err(clixon_handle h,
void *req, void *req,
cxobj *xerr, cxobj *xerr,
int pretty, int pretty,
@ -220,7 +220,7 @@ api_return_err(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* A well-formed error message when entering here should look like: /* A well-formed error message when entering here should look like:
@ -230,7 +230,7 @@ api_return_err(clicon_handle h,
if (strcmp(xml_name(xerr), "rpc-error") != 0 || if (strcmp(xml_name(xerr), "rpc-error") != 0 ||
(xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){ (xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cberr, "Internal error, system returned invalid error message: "); cprintf(cberr, "Internal error, system returned invalid error message: ");
@ -240,11 +240,11 @@ api_return_err(clicon_handle h,
cbuf_get(cberr)) < 0) cbuf_get(cberr)) < 0)
goto done; goto done;
if ((xerr = xpath_first(xerr2, NULL, "rpc-error")) == NULL){ if ((xerr = xpath_first(xerr2, NULL, "rpc-error")) == NULL){
clicon_err(OE_XML, 0, "Internal error, shouldnt happen"); clixon_err(OE_XML, 0, "Internal error, shouldnt happen");
goto done; goto done;
} }
if ((xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){ if ((xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
clicon_err(OE_XML, 0, "Internal error, shouldnt happen"); clixon_err(OE_XML, 0, "Internal error, shouldnt happen");
goto done; goto done;
} }
} }
@ -318,7 +318,7 @@ api_return_err(clicon_handle h,
} }
break; break;
default: /* Just ignore the body so that there is a reply */ default: /* Just ignore the body so that there is a reply */
clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media); clixon_err(OE_YANG, EINVAL, "Invalid media type %d", media);
goto done; goto done;
break; break;
} /* switch media */ } /* switch media */
@ -353,7 +353,7 @@ api_return_err(clicon_handle h,
* @see api_return_err where top level is expected to be <rpc-error> * @see api_return_err where top level is expected to be <rpc-error>
*/ */
int int
api_return_err0(clicon_handle h, api_return_err0(clixon_handle h,
void *req, void *req,
cxobj *xerr, cxobj *xerr,
int pretty, int pretty,
@ -364,7 +364,7 @@ api_return_err0(clicon_handle h,
cxobj *xe; cxobj *xe;
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
clicon_err(OE_XML, EINVAL, "Expected xml on the form <rpc-error>.."); clixon_err(OE_XML, EINVAL, "Expected xml on the form <rpc-error>..");
goto done; goto done;
} }
if (api_return_err(h, req, xe, pretty, media, code) < 0) if (api_return_err(h, req, xe, pretty, media, code) < 0)

View file

@ -43,13 +43,13 @@
* Prototypes * Prototypes
*/ */
int restconf_method_notallowed(clicon_handle h, void *req, char *allow, int pretty, restconf_media media); int restconf_method_notallowed(clixon_handle h, void *req, char *allow, int pretty, restconf_media media);
int restconf_unsupported_media(clicon_handle h, void *req, int pretty, restconf_media media); int restconf_unsupported_media(clixon_handle h, void *req, int pretty, restconf_media media);
int restconf_not_acceptable(clicon_handle h, void *req, int pretty, restconf_media media); int restconf_not_acceptable(clixon_handle h, void *req, int pretty, restconf_media media);
int restconf_notimplemented(clicon_handle h, void *req, int pretty, restconf_media media); int restconf_notimplemented(clixon_handle h, void *req, int pretty, restconf_media media);
int api_return_err(clicon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0); int api_return_err(clixon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0);
int api_return_err0(clicon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0); int api_return_err0(clixon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0);
#endif /* _RESTCONF_ERR_H_ */ #endif /* _RESTCONF_ERR_H_ */

View file

@ -58,20 +58,20 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
#include "restconf_handle.h" #include "restconf_handle.h"
/* header part is copied from struct clicon_handle in lib/src/clixon_handle.c */ /* header part is copied from struct clixon_handle in lib/src/clixon_handle.c */
#define CLICON_MAGIC 0x99aafabe #define CLICON_MAGIC 0x99aafabe
#define handle(h) (assert(clicon_handle_check(h)==0),(struct restconf_handle *)(h)) #define handle(h) (assert(clixon_handle_check(h)==0),(struct restconf_handle *)(h))
/* Clicon_handle for backends. /* Clixon_handle for backends.
* First part of this is header, same for clicon_handle and cli_handle. * First part of this is header, same for clixon_handle and cli_handle.
* Access functions for common fields are found in clicon lib: clicon_options.[ch] * Access functions for common fields are found in clicon lib: clicon_options.[ch]
* This file should only contain access functions for the _specific_ * This file should only contain access functions for the _specific_
* entries in the struct below. * entries in the struct below.
@ -80,8 +80,8 @@
* *
* This file should only contain access functions for the _specific_ * This file should only contain access functions for the _specific_
* entries in the struct below. * entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c * @note The top part must be equivalent to struct clixon_handle in clixon_handle.c
* @see struct clicon_handle, struct cli_handle * @see struct clixon_handle, struct cli_handle
*/ */
struct restconf_handle { struct restconf_handle {
int rh_magic; /* magic (HDR)*/ int rh_magic; /* magic (HDR)*/
@ -100,12 +100,12 @@ struct restconf_handle {
/*! Creates and returns a clicon config handle for other CLICON API calls /*! Creates and returns a clicon config handle for other CLICON API calls
*/ */
clicon_handle clixon_handle
restconf_handle_init(void) restconf_handle_init(void)
{ {
struct restconf_handle *rh; struct restconf_handle *rh;
rh = clicon_handle_init0(sizeof(struct restconf_handle)); rh = clixon_handle_init0(sizeof(struct restconf_handle));
rh->rh_pretty = 1; /* clixon-restconf.yang : pretty is default true*/ rh->rh_pretty = 1; /* clixon-restconf.yang : pretty is default true*/
return rh; return rh;
} }
@ -116,13 +116,13 @@ restconf_handle_init(void)
* @see backend_client_rm * @see backend_client_rm
*/ */
int int
restconf_handle_exit(clicon_handle h) restconf_handle_exit(clixon_handle h)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
if (rh->rh_fcgi_socket) if (rh->rh_fcgi_socket)
free(rh->rh_fcgi_socket); free(rh->rh_fcgi_socket);
clicon_handle_exit(h); /* frees h and options (and streams) */ clixon_handle_exit(h); /* frees h and options (and streams) */
return 0; return 0;
} }
@ -134,7 +134,7 @@ restconf_handle_exit(clicon_handle h)
* Currently using clixon runtime data but there is risk for colliding names * Currently using clixon runtime data but there is risk for colliding names
*/ */
char * char *
restconf_param_get(clicon_handle h, restconf_param_get(clixon_handle h,
const char *param) const char *param)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -154,7 +154,7 @@ restconf_param_get(clicon_handle h,
* Currently using clixon runtime data but there is risk for colliding names * Currently using clixon runtime data but there is risk for colliding names
*/ */
int int
restconf_param_set(clicon_handle h, restconf_param_set(clixon_handle h,
const char *param, const char *param,
char *val) char *val)
{ {
@ -176,7 +176,7 @@ restconf_param_set(clicon_handle h,
* Currently using clixon runtime data but there is risk for colliding names * Currently using clixon runtime data but there is risk for colliding names
*/ */
int int
restconf_param_del_all(clicon_handle h) restconf_param_del_all(clixon_handle h)
{ {
int retval = -1; int retval = -1;
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -197,7 +197,7 @@ restconf_param_del_all(clicon_handle h)
* @retval auth_type * @retval auth_type
*/ */
clixon_auth_type_t clixon_auth_type_t
restconf_auth_type_get(clicon_handle h) restconf_auth_type_get(clixon_handle h)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -214,7 +214,7 @@ restconf_auth_type_get(clicon_handle h)
* Currently using clixon runtime data but there is risk for colliding names * Currently using clixon runtime data but there is risk for colliding names
*/ */
int int
restconf_auth_type_set(clicon_handle h, restconf_auth_type_set(clixon_handle h,
clixon_auth_type_t type) clixon_auth_type_t type)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -229,7 +229,7 @@ restconf_auth_type_set(clicon_handle h,
* @retval pretty * @retval pretty
*/ */
int int
restconf_pretty_get(clicon_handle h) restconf_pretty_get(clixon_handle h)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -244,7 +244,7 @@ restconf_pretty_get(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_pretty_set(clicon_handle h, restconf_pretty_set(clixon_handle h,
int pretty) int pretty)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -260,7 +260,7 @@ restconf_pretty_set(clicon_handle h,
* @retval 1 No, http-data disabled * @retval 1 No, http-data disabled
*/ */
int int
restconf_http_data_get(clicon_handle h) restconf_http_data_get(clixon_handle h)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -274,7 +274,7 @@ restconf_http_data_get(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_http_data_set(clicon_handle h, restconf_http_data_set(clixon_handle h,
int http_data) int http_data)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -289,7 +289,7 @@ restconf_http_data_set(clicon_handle h,
* @retval socketpath * @retval socketpath
*/ */
char* char*
restconf_fcgi_socket_get(clicon_handle h) restconf_fcgi_socket_get(clixon_handle h)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
@ -306,13 +306,13 @@ restconf_fcgi_socket_get(clicon_handle h)
* Currently using clixon runtime data but there is risk for colliding names * Currently using clixon runtime data but there is risk for colliding names
*/ */
int int
restconf_fcgi_socket_set(clicon_handle h, restconf_fcgi_socket_set(clixon_handle h,
char *socketpath) char *socketpath)
{ {
struct restconf_handle *rh = handle(h); struct restconf_handle *rh = handle(h);
if ((rh->rh_fcgi_socket = strdup(socketpath)) == NULL){ if ((rh->rh_fcgi_socket = strdup(socketpath)) == NULL){
clicon_err(OE_RESTCONF, errno, "strdup"); clixon_err(OE_RESTCONF, errno, "strdup");
return -1; return -1;
} }
return 0; return 0;

View file

@ -42,18 +42,18 @@
/* /*
* Prototypes * Prototypes
*/ */
clicon_handle restconf_handle_init(void); clixon_handle restconf_handle_init(void);
int restconf_handle_exit(clicon_handle h); int restconf_handle_exit(clixon_handle h);
char *restconf_param_get(clicon_handle h, const char *param); char *restconf_param_get(clixon_handle h, const char *param);
int restconf_param_set(clicon_handle h, const char *param, char *val); int restconf_param_set(clixon_handle h, const char *param, char *val);
int restconf_param_del_all(clicon_handle h); int restconf_param_del_all(clixon_handle h);
clixon_auth_type_t restconf_auth_type_get(clicon_handle h); clixon_auth_type_t restconf_auth_type_get(clixon_handle h);
int restconf_auth_type_set(clicon_handle h, clixon_auth_type_t type); int restconf_auth_type_set(clixon_handle h, clixon_auth_type_t type);
int restconf_pretty_get(clicon_handle h); int restconf_pretty_get(clixon_handle h);
int restconf_pretty_set(clicon_handle h, int pretty); int restconf_pretty_set(clixon_handle h, int pretty);
int restconf_http_data_get(clicon_handle h); int restconf_http_data_get(clixon_handle h);
int restconf_http_data_set(clicon_handle h, int http_data); int restconf_http_data_set(clixon_handle h, int http_data);
char *restconf_fcgi_socket_get(clicon_handle h); char *restconf_fcgi_socket_get(clixon_handle h);
int restconf_fcgi_socket_set(clicon_handle h, char *socketpath); int restconf_fcgi_socket_set(clixon_handle h, char *socketpath);
#endif /* _RESTCONF_HANDLE_H_ */ #endif /* _RESTCONF_HANDLE_H_ */

View file

@ -78,10 +78,10 @@
* @param[in] str Pointer to string containing HTTP/1 * @param[in] str Pointer to string containing HTTP/1
* @param[in] filename Debug string identifying file or connection * @param[in] filename Debug string identifying file or connection
* @retval 0 Parse OK * @retval 0 Parse OK
* @retval -1 Error with clicon_err called. * @retval -1 Error
*/ */
static int static int
_http1_parse(clicon_handle h, _http1_parse(clixon_handle h,
restconf_conn *rc, restconf_conn *rc,
char *str, char *str,
const char *filename) const char *filename)
@ -109,11 +109,11 @@ _http1_parse(clicon_handle h,
http1_scan_exit(&hy); http1_scan_exit(&hy);
if (ret != 0){ if (ret != 0){
if (filename) if (filename)
clicon_log(LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename); clixon_log(h, LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename);
else else
clicon_log(LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum); clixon_log(h, LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum);
if (clicon_errno == 0) if (clixon_err_category() == 0)
clicon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)"); clixon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)");
goto done; goto done;
} }
ok: ok:
@ -130,10 +130,10 @@ _http1_parse(clicon_handle h,
* @param[in] f A file descriptor containing HTTP/1 (as ASCII characters) * @param[in] f A file descriptor containing HTTP/1 (as ASCII characters)
* @param[in] filename Debug string identifying file or connection * @param[in] filename Debug string identifying file or connection
* @retval 0 Parse OK * @retval 0 Parse OK
* @retval -1 Error with clicon_err called. * @retval -1 Error
*/ */
int int
clixon_http1_parse_file(clicon_handle h, clixon_http1_parse_file(clixon_handle h,
restconf_conn *rc, restconf_conn *rc,
FILE *f, FILE *f,
const char *filename) const char *filename)
@ -149,18 +149,18 @@ clixon_http1_parse_file(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename); clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename);
if (f == NULL){ if (f == NULL){
clicon_err(OE_RESTCONF, EINVAL, "f is NULL"); clixon_err(OE_RESTCONF, EINVAL, "f is NULL");
goto done; goto done;
} }
if ((buf = malloc(buflen)) == NULL){ if ((buf = malloc(buflen)) == NULL){
clicon_err(OE_XML, errno, "malloc"); clixon_err(OE_XML, errno, "malloc");
goto done; goto done;
} }
memset(buf, 0, buflen); memset(buf, 0, buflen);
ptr = buf; ptr = buf;
while (1){ while (1){
if ((ret = fread(&ch, 1, 1, f)) < 0){ if ((ret = fread(&ch, 1, 1, f)) < 0){
clicon_err(OE_XML, errno, "read"); clixon_err(OE_XML, errno, "read");
break; break;
} }
if (ret != 0){ if (ret != 0){
@ -175,7 +175,7 @@ clixon_http1_parse_file(clicon_handle h,
oldbuflen = buflen; oldbuflen = buflen;
buflen *= 2; buflen *= 2;
if ((buf = realloc(buf, buflen)) == NULL){ if ((buf = realloc(buf, buflen)) == NULL){
clicon_err(OE_XML, errno, "realloc"); clixon_err(OE_XML, errno, "realloc");
goto done; goto done;
} }
memset(buf+oldbuflen, 0, buflen-oldbuflen); memset(buf+oldbuflen, 0, buflen-oldbuflen);
@ -195,10 +195,10 @@ clixon_http1_parse_file(clicon_handle h,
* @param[in] rc Restconf connection * @param[in] rc Restconf connection
* @param[in] str HTTP/1 string * @param[in] str HTTP/1 string
* @retval 0 Parse OK * @retval 0 Parse OK
* @retval -1 Error with clicon_err called. * @retval -1 Error
*/ */
int int
clixon_http1_parse_string(clicon_handle h, clixon_http1_parse_string(clixon_handle h,
restconf_conn *rc, restconf_conn *rc,
char *str) char *str)
{ {
@ -213,12 +213,12 @@ clixon_http1_parse_string(clicon_handle h,
* @param[in] buf HTTP/1 buffer * @param[in] buf HTTP/1 buffer
* @param[in] n Length of buffer * @param[in] n Length of buffer
* @retval 0 Parse OK * @retval 0 Parse OK
* @retval -1 Error with clicon_err called. * @retval -1 Error
* @note Had preferred to do this without copying, OR * @note Had preferred to do this without copying, OR
* input flex with a non-null terminated string * input flex with a non-null terminated string
*/ */
int int
clixon_http1_parse_buf(clicon_handle h, clixon_http1_parse_buf(clixon_handle h,
restconf_conn *rc, restconf_conn *rc,
char *buf, char *buf,
size_t n) size_t n)
@ -227,7 +227,7 @@ clixon_http1_parse_buf(clicon_handle h,
int ret; int ret;
if ((str = malloc(n+1)) == NULL){ if ((str = malloc(n+1)) == NULL){
clicon_err(OE_RESTCONF, errno, "malloc"); clixon_err(OE_RESTCONF, errno, "malloc");
return -1; return -1;
} }
memcpy(str, buf, n); memcpy(str, buf, n);
@ -250,7 +250,7 @@ clixon_http1_parse_buf(clicon_handle h,
* runtime config option * runtime config option
*/ */
static int static int
http1_upgrade_http2(clicon_handle h, http1_upgrade_http2(clixon_handle h,
restconf_stream_data *sd) restconf_stream_data *sd)
{ {
int retval = -1; int retval = -1;
@ -280,7 +280,7 @@ http1_upgrade_http2(clicon_handle h,
sd->sd_upgrade2 = 1; sd->sd_upgrade2 = 1;
if ((settings = restconf_param_get(h, "HTTP_HTTP2_Settings")) != NULL && if ((settings = restconf_param_get(h, "HTTP_HTTP2_Settings")) != NULL &&
(sd->sd_settings2 = (uint8_t*)strdup(settings)) == NULL){ (sd->sd_settings2 = (uint8_t*)strdup(settings)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -332,7 +332,7 @@ restconf_http1_reply(restconf_conn *rc,
/* Write a body */ /* Write a body */
if (sd->sd_body){ if (sd->sd_body){
if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){ if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){
clicon_err(OE_RESTCONF, errno, "cbuf_append_buf"); clixon_err(OE_RESTCONF, errno, "cbuf_append_buf");
goto done; goto done;
} }
cbuf_free(sd->sd_body); cbuf_free(sd->sd_body);
@ -351,7 +351,7 @@ restconf_http1_reply(restconf_conn *rc,
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_http1_path_root(clicon_handle h, restconf_http1_path_root(clixon_handle h,
restconf_conn *rc) restconf_conn *rc)
{ {
int retval = -1; int retval = -1;
@ -368,7 +368,7 @@ restconf_http1_path_root(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "------------"); clixon_debug(CLIXON_DBG_DEFAULT, "------------");
pretty = restconf_pretty_get(h); pretty = restconf_pretty_get(h);
if ((sd = restconf_stream_find(rc, 0)) == NULL){ if ((sd = restconf_stream_find(rc, 0)) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "No stream_data"); clixon_err(OE_RESTCONF, EINVAL, "No stream_data");
goto done; goto done;
} }
/* Sanity check */ /* Sanity check */
@ -484,7 +484,7 @@ restconf_http1_path_root(clicon_handle h,
* @see rfc7231 Sec 5.1.1 * @see rfc7231 Sec 5.1.1
*/ */
int int
http1_check_expect(clicon_handle h, http1_check_expect(clixon_handle h,
restconf_conn *rc, restconf_conn *rc,
restconf_stream_data *sd) restconf_stream_data *sd)
{ {
@ -518,7 +518,7 @@ http1_check_expect(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
http1_check_content_length(clicon_handle h, http1_check_content_length(clixon_handle h,
restconf_stream_data *sd, restconf_stream_data *sd,
int *status) int *status)
{ {

View file

@ -39,11 +39,11 @@
/* /*
* Prototypes * Prototypes
*/ */
int clixon_http1_parse_file(clicon_handle h, restconf_conn *rc, FILE *f, const char *filename); int clixon_http1_parse_file(clixon_handle h, restconf_conn *rc, FILE *f, const char *filename);
int clixon_http1_parse_string(clicon_handle h, restconf_conn *rc, char *str); int clixon_http1_parse_string(clixon_handle h, restconf_conn *rc, char *str);
int clixon_http1_parse_buf(clicon_handle h, restconf_conn *rc, char *buf, size_t n); int clixon_http1_parse_buf(clixon_handle h, restconf_conn *rc, char *buf, size_t n);
int restconf_http1_path_root(clicon_handle h, restconf_conn *rc); int restconf_http1_path_root(clixon_handle h, restconf_conn *rc);
int http1_check_expect(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd); int http1_check_expect(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd);
int http1_check_content_length(clicon_handle h, restconf_stream_data *sd, int *status); int http1_check_content_length(clixon_handle h, restconf_stream_data *sd, int *status);
#endif /* _RESTCONF_HTTP1_H_ */ #endif /* _RESTCONF_HTTP1_H_ */

View file

@ -61,7 +61,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_api.h" #include "restconf_api.h"
@ -265,7 +265,7 @@ restconf_proto2str(int proto)
* *
*/ */
restconf_media restconf_media
restconf_content_type(clicon_handle h) restconf_content_type(clixon_handle h)
{ {
char *str = NULL; char *str = NULL;
restconf_media m; restconf_media m;
@ -282,7 +282,7 @@ restconf_content_type(clicon_handle h)
* Example: Host -> HTTP_HOST * Example: Host -> HTTP_HOST
*/ */
int int
restconf_convert_hdr(clicon_handle h, restconf_convert_hdr(clixon_handle h,
char *name, char *name,
char *val) char *val)
{ {
@ -293,7 +293,7 @@ restconf_convert_hdr(clicon_handle h,
size_t len; size_t len;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* convert key name */ /* convert key name */
@ -353,7 +353,7 @@ get_user_cookie(char *cookiestr,
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
int int
restconf_terminate(clicon_handle h) restconf_terminate(clixon_handle h)
{ {
yang_stmt *yspec; yang_stmt *yspec;
cvec *nsctx; cvec *nsctx;
@ -379,7 +379,7 @@ restconf_terminate(clicon_handle h)
restconf_handle_exit(h); restconf_handle_exit(h);
clixon_err_exit(); clixon_err_exit();
clixon_debug(CLIXON_DBG_DEFAULT, "%s pid:%u done", __FUNCTION__, getpid()); clixon_debug(CLIXON_DBG_DEFAULT, "%s pid:%u done", __FUNCTION__, getpid());
clicon_log_exit(); /* Must be after last clixon_debug */ clixon_log_exit(); /* Must be after last clixon_debug */
return 0; return 0;
} }
@ -432,7 +432,7 @@ restconf_insert_attributes(cxobj *xdata,
} }
if ((pstr = cvec_find_str(qvec, "point")) != NULL){ if ((pstr = cvec_find_str(qvec, "point")) != NULL){
if (y == NULL){ if (y == NULL){
clicon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata)); clixon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata));
goto done; goto done;
} }
if (yang_keyword_get(y) == Y_LIST) if (yang_keyword_get(y) == Y_LIST)
@ -443,7 +443,7 @@ restconf_insert_attributes(cxobj *xdata,
if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0) if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0)
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (yang_keyword_get(y) == Y_LIST){ if (yang_keyword_get(y) == Y_LIST){
@ -456,12 +456,12 @@ restconf_insert_attributes(cxobj *xdata,
else{ /* LEAF_LIST */ else{ /* LEAF_LIST */
/* translate /../x[.='x'] --> x */ /* translate /../x[.='x'] --> x */
if ((p = rindex(xpath,'\'')) == NULL){ if ((p = rindex(xpath,'\'')) == NULL){
clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath); clixon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
goto done; goto done;
} }
*p = '\0'; *p = '\0';
if ((p = rindex(xpath,'\'')) == NULL){ if ((p = rindex(xpath,'\'')) == NULL){
clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath); clixon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
goto done; goto done;
} }
p++; p++;
@ -508,7 +508,7 @@ restconf_insert_attributes(cxobj *xdata,
* @see ietf-restconf.yang * @see ietf-restconf.yang
*/ */
int int
restconf_main_extension_cb(clicon_handle h, restconf_main_extension_cb(clixon_handle h,
yang_stmt *yext, yang_stmt *yext,
yang_stmt *ys) yang_stmt *ys)
{ {
@ -547,18 +547,18 @@ restconf_main_extension_cb(clicon_handle h,
* @retval path malloced, need free * @retval path malloced, need free
*/ */
char * char *
restconf_uripath(clicon_handle h) restconf_uripath(clixon_handle h)
{ {
char *path = NULL; char *path = NULL;
char *path2 = NULL; char *path2 = NULL;
char *q; char *q;
if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){ if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){
clicon_err(OE_RESTCONF, 0, "No REQUEST_URI"); clixon_err(OE_RESTCONF, 0, "No REQUEST_URI");
return NULL; return NULL;
} }
if ((path2 = strdup(path)) == NULL){ if ((path2 = strdup(path)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
return NULL; return NULL;
} }
if ((q = index(path2, '?')) != NULL) if ((q = index(path2, '?')) != NULL)
@ -574,7 +574,7 @@ restconf_uripath(clicon_handle h)
* Group set to CLICON_SOCK_GROUP to communicate with backend * Group set to CLICON_SOCK_GROUP to communicate with backend
*/ */
int int
restconf_drop_privileges(clicon_handle h) restconf_drop_privileges(clixon_handle h)
{ {
int retval = -1; int retval = -1;
uid_t newuid = -1; uid_t newuid = -1;
@ -587,11 +587,11 @@ restconf_drop_privileges(clicon_handle h)
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Sanity check: backend group exists */ /* Sanity check: backend group exists */
if ((group = clicon_sock_group(h)) == NULL){ if ((group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); clixon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1; return -1;
} }
if (group_name2gid(group, &gid) < 0){ if (group_name2gid(group, &gid) < 0){
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */ clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */
"The config daemon requires a valid group to create a server UNIX socket\n" "The config daemon requires a valid group to create a server UNIX socket\n"
"Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n" "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
"or create the group and add the user to it. Check documentation for how to do this on your platform", "or create the group and add the user to it. Check documentation for how to do this on your platform",
@ -608,18 +608,18 @@ restconf_drop_privileges(clicon_handle h)
/* Get (wanted) new www user id */ /* Get (wanted) new www user id */
if (name2uid(user, &newuid) < 0){ if (name2uid(user, &newuid) < 0){
clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user); clixon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user);
goto done; goto done;
} }
/* get current userid, if already at this level OK */ /* get current userid, if already at this level OK */
if ((uid = getuid()) == newuid) if ((uid = getuid()) == newuid)
goto ok; goto ok;
if (uid != 0){ if (uid != 0){
clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid); clixon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
goto done; goto done;
} }
if (setgid(gid) == -1) { if (setgid(gid) == -1) {
clicon_err(OE_DAEMON, errno, "setgid %d", gid); clixon_err(OE_DAEMON, errno, "setgid %d", gid);
goto done; goto done;
} }
switch (priv_mode){ switch (priv_mode){
@ -628,7 +628,7 @@ restconf_drop_privileges(clicon_handle h)
goto done; goto done;
/* Verify you cannot regain root privileges */ /* Verify you cannot regain root privileges */
if (setuid(0) != -1){ if (setuid(0) != -1){
clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges"); clixon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
goto done; goto done;
} }
break; break;
@ -658,7 +658,7 @@ restconf_drop_privileges(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_authentication_cb(clicon_handle h, restconf_authentication_cb(clixon_handle h,
void *req, void *req,
int pretty, int pretty,
restconf_media media_out) restconf_media media_out)
@ -746,7 +746,7 @@ restconf_authentication_cb(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_config_init(clicon_handle h, restconf_config_init(clixon_handle h,
cxobj *xrestconf) cxobj *xrestconf)
{ {
int retval = -1; int retval = -1;
@ -759,7 +759,7 @@ restconf_config_init(clicon_handle h,
yang_stmt *y; yang_stmt *y;
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
/* Apply default values (removed in clear function) */ /* Apply default values (removed in clear function) */
@ -776,7 +776,7 @@ restconf_config_init(clicon_handle h,
if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL && if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL &&
(bstr = xml_body(x)) != NULL){ (bstr = xml_body(x)) != NULL){
if ((auth_type = clixon_auth_type_str2int(bstr)) < 0){ if ((auth_type = clixon_auth_type_str2int(bstr)) < 0){
clicon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr); clixon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr);
goto done; goto done;
} }
restconf_auth_type_set(h, auth_type); restconf_auth_type_set(h, auth_type);

View file

@ -87,16 +87,16 @@ const restconf_media restconf_media_str2int(char *media);
const char *restconf_media_int2str(restconf_media media); const char *restconf_media_int2str(restconf_media media);
int restconf_str2proto(char *str); int restconf_str2proto(char *str);
const char *restconf_proto2str(int proto); const char *restconf_proto2str(int proto);
restconf_media restconf_content_type(clicon_handle h); restconf_media restconf_content_type(clixon_handle h);
int restconf_convert_hdr(clicon_handle h, char *name, char *val); int restconf_convert_hdr(clixon_handle h, char *name, char *val);
int get_user_cookie(char *cookiestr, char *attribute, char **val); int get_user_cookie(char *cookiestr, char *attribute, char **val);
int restconf_terminate(clicon_handle h); int restconf_terminate(clixon_handle h);
int restconf_insert_attributes(cxobj *xdata, cvec *qvec); int restconf_insert_attributes(cxobj *xdata, cvec *qvec);
int restconf_main_extension_cb(clicon_handle h, yang_stmt *yext, yang_stmt *ys); int restconf_main_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys);
char *restconf_uripath(clicon_handle h); char *restconf_uripath(clixon_handle h);
int restconf_drop_privileges(clicon_handle h); int restconf_drop_privileges(clixon_handle h);
int restconf_authentication_cb(clicon_handle h, void *req, int pretty, restconf_media media_out); int restconf_authentication_cb(clixon_handle h, void *req, int pretty, restconf_media media_out);
int restconf_config_init(clicon_handle h, cxobj *xrestconf); int restconf_config_init(clixon_handle h, cxobj *xrestconf);
int restconf_socket_init(const char *netns0, const char *addrstr, const char *addrtype, uint16_t port, int backlog, int flags, int *ss); int restconf_socket_init(const char *netns0, const char *addrstr, const char *addrtype, uint16_t port, int backlog, int flags, int *ss);
#endif /* _RESTCONF_LIB_H_ */ #endif /* _RESTCONF_LIB_H_ */

View file

@ -71,7 +71,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */ #include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */
@ -99,7 +99,7 @@
* @see https://nginx.org/en/docs/http/ngx_http_core_module.html#var_https * @see https://nginx.org/en/docs/http/ngx_http_core_module.html#var_https
*/ */
static int static int
fcgi_params_set(clicon_handle h, fcgi_params_set(clixon_handle h,
char **envp) char **envp)
{ {
int retval = -1; int retval = -1;
@ -131,7 +131,7 @@ fcgi_params_set(clicon_handle h,
/*! Try to get config: inline, config-file or query backend /*! Try to get config: inline, config-file or query backend
*/ */
static int static int
restconf_main_config(clicon_handle h, restconf_main_config(clixon_handle h,
yang_stmt *yspec, yang_stmt *yspec,
const char *inline_config) const char *inline_config)
{ {
@ -151,7 +151,12 @@ restconf_main_config(clicon_handle h,
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0) if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Inline restconf config") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Inline restconf config", NULL); clixon_netconf_error(h, xerr, "Inline restconf config", NULL);
#endif
goto done; goto done;
} }
/* Replace parent w first child */ /* Replace parent w first child */
@ -172,7 +177,7 @@ restconf_main_config(clicon_handle h,
sleep(1); sleep(1);
continue; continue;
} }
clicon_err(OE_UNIX, errno, "clicon_session_id_get"); clixon_err(OE_UNIX, errno, "clicon_session_id_get");
goto done; goto done;
} }
clicon_session_id_set(h, id); clicon_session_id_set(h, id);
@ -181,13 +186,13 @@ restconf_main_config(clicon_handle h,
if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL) if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
goto done; goto done;
if ((pw = getpwuid(getuid())) == NULL){ if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid"); clixon_err(OE_UNIX, errno, "getpwuid");
goto done; goto done;
} }
if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0) if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
goto done; goto done;
if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get backend restconf config", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config");
goto done; goto done;
} }
/* Extract restconf configuration */ /* Extract restconf configuration */
@ -198,7 +203,7 @@ restconf_main_config(clicon_handle h,
(configure_done = restconf_config_init(h, xrestconf)) < 0) (configure_done = restconf_config_init(h, xrestconf)) < 0)
goto done; goto done;
if (!configure_done){ /* Query backend of config. */ if (!configure_done){ /* Query backend of config. */
clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled"); clixon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -214,7 +219,7 @@ restconf_main_config(clicon_handle h,
/* XXX Need global variable to for SIGCHLD signal handler /* XXX Need global variable to for SIGCHLD signal handler
*/ */
static clicon_handle _CLICON_HANDLE = NULL; static clixon_handle _CLIXON_HANDLE = NULL;
/* XXX Need global variable to break FCGI accept loop from signal handler see FCGX_Accept_r(req) /* XXX Need global variable to break FCGI accept loop from signal handler see FCGX_Accept_r(req)
*/ */
@ -229,7 +234,7 @@ restconf_sig_term(int arg)
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (i++ == 0) if (i++ == 0)
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
__PROGRAM__, __FUNCTION__, getpid(), arg); __PROGRAM__, __FUNCTION__, getpid(), arg);
else{ else{
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
@ -255,7 +260,7 @@ restconf_sig_child(int arg)
int pid; int pid;
if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status)) if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status))
stream_child_free(_CLICON_HANDLE, pid); stream_child_free(_CLIXON_HANDLE, pid);
} }
/*! Usage help routine /*! Usage help routine
@ -264,7 +269,7 @@ restconf_sig_child(int arg)
* @param[in] argv0 command line * @param[in] argv0 command line
*/ */
static void static void
usage(clicon_handle h, usage(clixon_handle h,
char *argv0) char *argv0)
{ {
fprintf(stderr, "usage:%s [options]\n" fprintf(stderr, "usage:%s [options]\n"
@ -303,9 +308,9 @@ main(int argc,
int c; int c;
char *sockpath = NULL; char *sockpath = NULL;
char *path; char *path;
clicon_handle h; clixon_handle h;
char *dir; char *dir;
int logdst = CLICON_LOG_SYSLOG; int logdst = CLIXON_LOG_SYSLOG;
yang_stmt *yspec = NULL; yang_stmt *yspec = NULL;
char *query; char *query;
cvec *qvec; cvec *qvec;
@ -324,14 +329,16 @@ main(int argc,
enum format_enum config_dump_format = FORMAT_XML; enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0; int print_version = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Create handle */ /* Create handle */
if ((h = restconf_handle_init()) == NULL) if ((h = restconf_handle_init()) == NULL)
goto done; goto done;
/* In the startup, logs to stderr & debug flag set later */
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
goto done;
if (clixon_err_init(h) < 0)
goto done;
_CLICON_HANDLE = h; /* for termination handling */ _CLIXON_HANDLE = h; /* for termination handling */
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1) while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
switch (c) { switch (c) {
@ -357,11 +364,11 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break; break;
case 'l': /* Log destination: s|e|o */ case 'l': /* Log destination: s|e|o */
if ((logdst = clicon_log_opt(optarg[0])) < 0) if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]); usage(h, argv[0]);
if (logdst == CLICON_LOG_FILE && if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 && strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0) clixon_log_file(optarg+1) < 0)
goto done; goto done;
break; break;
} /* switch getopt */ } /* switch getopt */
@ -369,20 +376,20 @@ main(int argc,
/* /*
* Logs, error and debug to stderr or syslog, set debug level * Logs, error and debug to stderr or syslog, set debug level
*/ */
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
clicon_log(LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid()); clixon_log(h, LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){ if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){ if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGCHLD, restconf_sig_child, NULL) < 0){ if (set_signal(SIGCHLD, restconf_sig_child, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
@ -460,8 +467,8 @@ main(int argc,
cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD"); cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD");
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) if ((sz = clicon_option_int(h, "CLIXON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(sz); clixon_log_string_limit_set(sz);
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h); xml_nsctx_namespace_netconf_default(h);
@ -572,16 +579,16 @@ main(int argc,
if (restconf_main_config(h, yspec, inline_config) < 0) if (restconf_main_config(h, yspec, inline_config) < 0)
goto done; goto done;
if ((sockpath = restconf_fcgi_socket_get(h)) == NULL){ if ((sockpath = restconf_fcgi_socket_get(h)) == NULL){
clicon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)"); clixon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
goto done; goto done;
} }
if (FCGX_Init() != 0){ /* How to cleanup memory after this? */ if (FCGX_Init() != 0){ /* How to cleanup memory after this? */
clicon_err(OE_CFG, errno, "FCGX_Init"); clixon_err(OE_CFG, errno, "FCGX_Init");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "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){ if ((sock = FCGX_OpenSocket(sockpath, 10)) < 0){
clicon_err(OE_CFG, errno, "FCGX_OpenSocket"); clixon_err(OE_CFG, errno, "FCGX_OpenSocket");
goto done; goto done;
} }
_MYSOCK = sock; _MYSOCK = sock;
@ -590,18 +597,18 @@ main(int argc,
gid_t wgid = -1; gid_t wgid = -1;
wwwuser = clicon_option_str(h, "CLICON_RESTCONF_USER"); wwwuser = clicon_option_str(h, "CLICON_RESTCONF_USER");
if (group_name2gid(wwwuser, &wgid) < 0){ if (group_name2gid(wwwuser, &wgid) < 0){
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser); clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
goto done; goto done;
} }
if (chown(sockpath, -1, wgid) < 0){ if (chown(sockpath, -1, wgid) < 0){
clicon_err(OE_CFG, errno, "chown"); clixon_err(OE_CFG, errno, "chown");
goto done; goto done;
} }
if (clicon_socket_set(h, sock) < 0) if (clicon_socket_set(h, sock) < 0)
goto done; goto done;
/* umask settings may interfer: we want group to write: this is 774 */ /* umask settings may interfer: we want group to write: this is 774 */
if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){ if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){
clicon_err(OE_UNIX, errno, "chmod"); clixon_err(OE_UNIX, errno, "chmod");
goto done; goto done;
} }
@ -616,14 +623,14 @@ main(int argc,
clicon_data_set(h, "session-transport", "cl:restconf"); clicon_data_set(h, "session-transport", "cl:restconf");
if (FCGX_InitRequest(req, sock, 0) != 0){ if (FCGX_InitRequest(req, sock, 0) != 0){
clicon_err(OE_CFG, errno, "FCGX_InitRequest"); clixon_err(OE_CFG, errno, "FCGX_InitRequest");
goto done; goto done;
} }
while (1) { while (1) {
finish = 1; /* If zero, dont finish request, initiate new */ finish = 1; /* If zero, dont finish request, initiate new */
if (FCGX_Accept_r(req) < 0) { if (FCGX_Accept_r(req) < 0) {
clicon_err(OE_CFG, errno, "FCGX_Accept_r"); clixon_err(OE_CFG, errno, "FCGX_Accept_r");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "------------"); clixon_debug(CLIXON_DBG_DEFAULT, "------------");
@ -692,7 +699,7 @@ main(int argc,
else{ /* A handler is forked so we initiate a new request after instead else{ /* A handler is forked so we initiate a new request after instead
of finishing the old */ of finishing the old */
if (FCGX_InitRequest(req, sock, 0) != 0){ if (FCGX_InitRequest(req, sock, 0) != 0){
clicon_err(OE_CFG, errno, "FCGX_InitRequest"); clixon_err(OE_CFG, errno, "FCGX_InitRequest");
goto done; goto done;
} }
} }

View file

@ -36,7 +36,7 @@
* Data structures: * Data structures:
* 1 1 * 1 1
* +--------------------+ restconf_handle_get +--------------------+ * +--------------------+ restconf_handle_get +--------------------+
* | rn restconf_native | <--------------------- | h clicon_handle | * | rn restconf_native | <--------------------- | h clixon_handle |
* | _handle | +--------------------+ * | _handle | +--------------------+
* +--------------------+ ^ * +--------------------+ ^
* common SSL config \ | * common SSL config \ |
@ -186,7 +186,7 @@ static int session_id_context = 1;
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
restconf_native_handle_set(clicon_handle h, restconf_native_handle_set(clixon_handle h,
restconf_native_handle *rh) restconf_native_handle *rh)
{ {
clicon_hash_t *cdat = clicon_data(h); clicon_hash_t *cdat = clicon_data(h);
@ -235,7 +235,7 @@ init_openssl(void)
/* This isn't strictly necessary... OpenSSL performs RAND_poll /* This isn't strictly necessary... OpenSSL performs RAND_poll
* automatically on first use of random number generator. */ * automatically on first use of random number generator. */
if (RAND_poll() != 1) { if (RAND_poll() != 1) {
clicon_err(OE_SSL, errno, "Random generator has not been seeded with enough data"); clixon_err(OE_SSL, errno, "Random generator has not been seeded with enough data");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -260,7 +260,7 @@ restconf_verify_certs(int preverify_ok,
int err; int err;
int depth; int depth;
// SSL *ssl; // SSL *ssl;
// clicon_handle h; // clixon_handle h;
err_cert = X509_STORE_CTX_get_current_cert(store); err_cert = X509_STORE_CTX_get_current_cert(store);
err = X509_STORE_CTX_get_error(store); err = X509_STORE_CTX_get_error(store);
depth = X509_STORE_CTX_get_error_depth(store); depth = X509_STORE_CTX_get_error_depth(store);
@ -361,7 +361,7 @@ alpn_select_proto_cb(SSL *ssl,
/* /*
*/ */
static SSL_CTX * static SSL_CTX *
restconf_ssl_context_create(clicon_handle h) restconf_ssl_context_create(clixon_handle h)
{ {
const SSL_METHOD *method; const SSL_METHOD *method;
SSL_CTX *ctx = NULL; SSL_CTX *ctx = NULL;
@ -369,7 +369,7 @@ restconf_ssl_context_create(clicon_handle h)
method = TLS_server_method(); method = TLS_server_method();
if ((ctx = SSL_CTX_new(method)) == NULL) { if ((ctx = SSL_CTX_new(method)) == NULL) {
clicon_err(OE_SSL, 0, "SSL_CTX_new"); clixon_err(OE_SSL, 0, "SSL_CTX_new");
goto done; goto done;
} }
/* Options /* Options
@ -414,7 +414,7 @@ restconf_ssl_context_configure(clixon_handle h,
*/ */
if (server_ca_cert_path){ if (server_ca_cert_path){
if (SSL_CTX_load_verify_locations(ctx, server_ca_cert_path, NULL) != 1){ if (SSL_CTX_load_verify_locations(ctx, server_ca_cert_path, NULL) != 1){
clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path); clixon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path);
goto done; goto done;
} }
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER /*| SSL_VERIFY_FAIL_IF_NO_PEER_CERT */, SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER /*| SSL_VERIFY_FAIL_IF_NO_PEER_CERT */,
@ -496,15 +496,15 @@ restconf_checkcert_file(cxobj *xrestconf,
char *filename; char *filename;
if ((x = xpath_first(xrestconf, nsc, "%s", name)) == NULL){ if ((x = xpath_first(xrestconf, nsc, "%s", name)) == NULL){
clicon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name); clixon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name);
goto done; goto done;
} }
if ((filename = xml_body(x)) == NULL){ if ((filename = xml_body(x)) == NULL){
clicon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name); clixon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name);
goto done; goto done;
} }
if (stat(filename, &fstat) < 0) { if (stat(filename, &fstat) < 0) {
clicon_err(OE_FATAL, errno, "cert '%s'", filename); clixon_err(OE_FATAL, errno, "cert '%s'", filename);
goto done; goto done;
} }
*var = filename; *var = filename;
@ -516,7 +516,7 @@ restconf_checkcert_file(cxobj *xrestconf,
/*! Accept new socket client /*! Accept new socket client
* *
* @param[in] fd Socket (unix or ip) * @param[in] fd Socket (unix or ip)
* @param[in] arg typecast clicon_handle * @param[in] arg typecast clixon_handle
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @see openssl_init_socket where this callback is registered * @see openssl_init_socket where this callback is registered
@ -527,7 +527,7 @@ restconf_accept_client(int fd,
{ {
int retval = -1; int retval = -1;
restconf_socket *rsock; restconf_socket *rsock;
clicon_handle h; clixon_handle h;
int s; int s;
struct sockaddr from = {0,}; struct sockaddr from = {0,};
socklen_t len; socklen_t len;
@ -536,13 +536,13 @@ restconf_accept_client(int fd,
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, fd); clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, fd);
if ((rsock = (restconf_socket *)arg) == NULL){ if ((rsock = (restconf_socket *)arg) == NULL){
clicon_err(OE_YANG, EINVAL, "rsock is NULL"); clixon_err(OE_YANG, EINVAL, "rsock is NULL");
goto done; goto done;
} }
h = rsock->rs_h; h = rsock->rs_h;
len = sizeof(from); len = sizeof(from);
if ((s = accept(rsock->rs_ss, &from, &len)) < 0){ if ((s = accept(rsock->rs_ss, &from, &len)) < 0){
clicon_err(OE_UNIX, errno, "accept"); clixon_err(OE_UNIX, errno, "accept");
goto done; goto done;
} }
switch (from.sa_family){ switch (from.sa_family){
@ -565,7 +565,7 @@ restconf_accept_client(int fd,
rsock->rs_from_addr = NULL; rsock->rs_from_addr = NULL;
} }
if ((rsock->rs_from_addr = calloc(INET6_ADDRSTRLEN, 1)) == NULL){ if ((rsock->rs_from_addr = calloc(INET6_ADDRSTRLEN, 1)) == NULL){
clicon_err(OE_UNIX, errno, "calloc"); clixon_err(OE_UNIX, errno, "calloc");
goto done; goto done;
} }
if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) < 0) if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) < 0)
@ -590,7 +590,7 @@ restconf_accept_client(int fd,
/*! /*!
*/ */
static int static int
restconf_native_terminate(clicon_handle h) restconf_native_terminate(clixon_handle h)
{ {
restconf_native_handle *rn; restconf_native_handle *rn;
restconf_socket *rsock; restconf_socket *rsock;
@ -643,7 +643,7 @@ restconf_native_terminate(clicon_handle h)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
restconf_clixon_backend(clicon_handle h, restconf_clixon_backend(clixon_handle h,
cxobj **xrestconfp) cxobj **xrestconfp)
{ {
int retval = -1; int retval = -1;
@ -659,11 +659,11 @@ restconf_clixon_backend(clicon_handle h,
while (1){ while (1){
if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){ if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){
if (errno == ENOENT){ if (errno == ENOENT){
clicon_err(OE_UNIX, errno, "waiting"); clixon_err(OE_UNIX, errno, "waiting");
sleep(1); sleep(1);
continue; continue;
} }
clicon_err(OE_UNIX, errno, "clicon_session_id_get"); clixon_err(OE_UNIX, errno, "clicon_session_id_get");
goto done; goto done;
} }
clicon_session_id_set(h, id); clicon_session_id_set(h, id);
@ -672,14 +672,19 @@ restconf_clixon_backend(clicon_handle h,
if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL) if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
goto done; goto done;
if ((pw = getpwuid(getuid())) == NULL){ if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid"); clixon_err(OE_UNIX, errno, "getpwuid");
goto done; goto done;
} }
/* XXX xconfig leaked */ /* XXX xconfig leaked */
if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0) if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
goto done; goto done;
if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "Get backend restconf config", NULL); clixon_netconf_error(h, xerr, "Get backend restconf config", NULL);
#endif
goto done; goto done;
} }
/* Extract restconf configuration */ /* Extract restconf configuration */
@ -713,7 +718,7 @@ restconf_clixon_backend(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
openssl_init_socket(clicon_handle h, openssl_init_socket(clixon_handle h,
cxobj *xs, cxobj *xs,
cvec *nsc) cvec *nsc)
{ {
@ -733,7 +738,7 @@ openssl_init_socket(clicon_handle h,
* See restconf_native_terminate for freeing * See restconf_native_terminate for freeing
*/ */
if ((rsock = malloc(sizeof *rsock)) == NULL){ if ((rsock = malloc(sizeof *rsock)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(rsock, 0, sizeof *rsock); memset(rsock, 0, sizeof *rsock);
@ -745,7 +750,7 @@ openssl_init_socket(clicon_handle h,
goto done; goto done;
if (rsock->rs_callhome){ if (rsock->rs_callhome){
if (!rsock->rs_ssl){ if (!rsock->rs_ssl){
clicon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL"); clixon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL");
goto done; goto done;
} }
} }
@ -763,15 +768,15 @@ openssl_init_socket(clicon_handle h,
goto done; goto done;
} }
if ((rn = restconf_native_handle_get(h)) == NULL){ if ((rn = restconf_native_handle_get(h)) == NULL){
clicon_err(OE_XML, EFAULT, "No openssl handle"); clixon_err(OE_XML, EFAULT, "No openssl handle");
goto done; goto done;
} }
if ((rsock->rs_addrstr = strdup(address)) == NULL){ if ((rsock->rs_addrstr = strdup(address)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
if ((rsock->rs_addrtype = strdup(addrtype)) == NULL){ if ((rsock->rs_addrtype = strdup(addrtype)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
rsock->rs_port = port; rsock->rs_port = port;
@ -804,7 +809,7 @@ openssl_init_socket(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_openssl_init(clicon_handle h, restconf_openssl_init(clixon_handle h,
int dbg0, int dbg0,
cxobj *xrestconf) cxobj *xrestconf)
{ {
@ -834,7 +839,7 @@ restconf_openssl_init(clicon_handle h,
(x = xpath_first(xrestconf, nsc, "debug")) != NULL && (x = xpath_first(xrestconf, nsc, "debug")) != NULL &&
(bstr = xml_body(x)) != NULL){ (bstr = xml_body(x)) != NULL){
dbg = atoi(bstr); dbg = atoi(bstr);
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
/* If debug was enabled here from config and not initially, /* If debug was enabled here from config and not initially,
* print clixn options and loaded yang files * print clixn options and loaded yang files
*/ */
@ -852,7 +857,7 @@ restconf_openssl_init(clicon_handle h,
} }
int status = setrlimit(RLIMIT_CORE, &rlp); int status = setrlimit(RLIMIT_CORE, &rlp);
if (status != 0) { if (status != 0) {
clicon_log(LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno)); clixon_log(h, LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno));
} }
} }
@ -880,8 +885,8 @@ restconf_openssl_init(clicon_handle h,
for (i=0; i<veclen; i++){ for (i=0; i<veclen; i++){
if (openssl_init_socket(h, vec[i], nsc) < 0){ if (openssl_init_socket(h, vec[i], nsc) < 0){
/* Bind errors are ignored, proceed with next after log */ /* Bind errors are ignored, proceed with next after log */
if (clicon_errno == OE_UNIX && clicon_suberrno == EADDRNOTAVAIL) if (clixon_err_category() == OE_UNIX && clixon_err_subnr() == EADDRNOTAVAIL)
clicon_err_reset(); clixon_err_reset();
else else
goto done; goto done;
} }
@ -910,7 +915,7 @@ restconf_openssl_init(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_clixon_init(clicon_handle h, restconf_clixon_init(clixon_handle h,
char *inline_config, char *inline_config,
int print_version, int print_version,
cxobj **xrestconfp) cxobj **xrestconfp)
@ -937,7 +942,7 @@ restconf_clixon_init(clicon_handle h,
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(sz); clixon_log_string_limit_set(sz);
/* Add (hardcoded) netconf features in case ietf-netconf loaded here /* Add (hardcoded) netconf features in case ietf-netconf loaded here
* Otherwise it is loaded in netconf_module_load below * Otherwise it is loaded in netconf_module_load below
@ -1025,7 +1030,7 @@ restconf_clixon_init(clicon_handle h,
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0) if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clixon_netconf_error(h, xerr, "Inline restconf config", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Inline restconf config");
goto done; goto done;
} }
/* Replace parent w first child */ /* Replace parent w first child */
@ -1086,7 +1091,7 @@ restconf_sig_term(int arg)
{ {
static int i=0; static int i=0;
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
__PROGRAM__, __FUNCTION__, getpid(), arg); __PROGRAM__, __FUNCTION__, getpid(), arg);
if (i++ > 0) /* Allow one sigterm before proper exit */ if (i++ > 0) /* Allow one sigterm before proper exit */
exit(-1); exit(-1);
@ -1103,7 +1108,7 @@ restconf_sig_term(int arg)
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
static void static void
usage(clicon_handle h, usage(clixon_handle h,
char *argv0) char *argv0)
{ {
fprintf(stderr, "usage:%s [options]\n" fprintf(stderr, "usage:%s [options]\n"
@ -1138,9 +1143,9 @@ main(int argc,
int retval = -1; int retval = -1;
char *argv0 = argv[0]; char *argv0 = argv[0];
int c; int c;
clicon_handle h; clixon_handle h;
int dbg = 0; int dbg = 0;
int logdst = CLICON_LOG_SYSLOG; int logdst = CLIXON_LOG_SYSLOG;
restconf_native_handle *rn = NULL; restconf_native_handle *rn = NULL;
int ret; int ret;
cxobj *xrestconf = NULL; cxobj *xrestconf = NULL;
@ -1149,12 +1154,14 @@ main(int argc,
enum format_enum config_dump_format = FORMAT_XML; enum format_enum config_dump_format = FORMAT_XML;
int print_version = 0; int print_version = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Create handle */ /* Create handle */
if ((h = restconf_handle_init()) == NULL) if ((h = restconf_handle_init()) == NULL)
goto done; goto done;
/* In the startup, logs to stderr & debug flag set later */
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
goto done;
if (clixon_err_init(h) < 0)
goto done;
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1) while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
switch (c) { switch (c) {
@ -1180,11 +1187,11 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break; break;
case 'l': /* Log destination: s|e|o */ case 'l': /* Log destination: s|e|o */
if ((logdst = clicon_log_opt(optarg[0])) < 0) if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv0); usage(h, argv0);
if (logdst == CLICON_LOG_FILE && if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 && strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0) clixon_log_file(optarg+1) < 0)
goto done; goto done;
break; break;
} /* switch getopt */ } /* switch getopt */
@ -1192,7 +1199,7 @@ main(int argc,
/* /*
* Logs, error and debug to stderr or syslog, set debug level * Logs, error and debug to stderr or syslog, set debug level
*/ */
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
/* /*
* Register error category and error/log callbacks for openssl special error handling * Register error category and error/log callbacks for openssl special error handling
@ -1212,18 +1219,18 @@ main(int argc,
) < 0) ) < 0)
goto done; goto done;
#endif #endif
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
clicon_log(LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid()); clixon_log(h, LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid());
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){ if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){ if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
yang_init(h); yang_init(h);
@ -1317,13 +1324,13 @@ main(int argc,
if ((ret = restconf_clixon_init(h, inline_config, print_version, &xrestconf)) < 0) if ((ret = restconf_clixon_init(h, inline_config, print_version, &xrestconf)) < 0)
goto done; goto done;
if (ret == 0){ /* restconf disabled */ if (ret == 0){ /* restconf disabled */
clicon_log(LOG_INFO, "restconf configuration not found or disabled"); clixon_log(h, LOG_INFO, "restconf configuration not found or disabled");
retval = 0; retval = 0;
goto done; goto done;
} }
/* Create and stroe global openssl handle */ /* Create and stroe global openssl handle */
if ((rn = malloc(sizeof *rn)) == NULL){ if ((rn = malloc(sizeof *rn)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(rn, 0, sizeof *rn); memset(rn, 0, sizeof *rn);

View file

@ -66,7 +66,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
@ -93,7 +93,7 @@
* @see RFC5789 PATCH Method for HTTP Section 3.2 * @see RFC5789 PATCH Method for HTTP Section 3.2
*/ */
int int
api_data_options(clicon_handle h, api_data_options(clixon_handle h,
void *req) void *req)
{ {
int retval = -1; int retval = -1;
@ -194,7 +194,7 @@ match_list_keys(yang_stmt *y,
* @retval -1 Error * @retval -1 Error
*/ */
int int
api_data_write(clicon_handle h, api_data_write(clixon_handle h,
void *req, void *req,
char *api_path0, char *api_path0,
int pi, int pi,
@ -239,7 +239,7 @@ api_data_write(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0); clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data); clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
api_path=api_path0; api_path=api_path0;
@ -328,7 +328,7 @@ api_data_write(clicon_handle h,
switch (media_in){ switch (media_in){
case YANG_DATA_XML: case YANG_DATA_XML:
if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){ if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -342,7 +342,7 @@ api_data_write(clicon_handle h,
break; break;
case YANG_DATA_JSON: case YANG_DATA_JSON:
if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xdata0, &xerr)) < 0){ if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xdata0, &xerr)) < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -620,7 +620,7 @@ api_data_write(clicon_handle h,
* --> Best solution and applied here * --> Best solution and applied here
*/ */
int int
api_data_put(clicon_handle h, api_data_put(clixon_handle h,
void *req, void *req,
char *api_path0, char *api_path0,
int pi, int pi,
@ -658,7 +658,7 @@ api_data_put(clicon_handle h,
* create it. (CANT BE DONE WITH NETCONF) * create it. (CANT BE DONE WITH NETCONF)
*/ */
int int
api_data_patch(clicon_handle h, api_data_patch(clixon_handle h,
void *req, void *req,
char *api_path0, char *api_path0,
int pi, int pi,
@ -712,7 +712,7 @@ api_data_patch(clicon_handle h,
* Netconf: <edit-config> (nc:operation="delete") * Netconf: <edit-config> (nc:operation="delete")
*/ */
int int
api_data_delete(clicon_handle h, api_data_delete(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -739,7 +739,7 @@ api_data_delete(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
for (i=0; i<pi; i++) for (i=0; i<pi; i++)

View file

@ -41,24 +41,24 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_data_options(clicon_handle h, void *req); int api_data_options(clixon_handle h, void *req);
int api_data_write(clicon_handle h, void *req, char *api_path0, int api_data_write(clixon_handle h, void *req, char *api_path0,
int pi, int pi,
cvec *qvec, char *data, cvec *qvec, char *data,
int pretty, restconf_media media_in, restconf_media media_out, int pretty, restconf_media media_in, restconf_media media_out,
int plain_patch, ietf_ds_t ds); int plain_patch, ietf_ds_t ds);
int api_data_put(clicon_handle h, void *req, char *api_path, int api_data_put(clixon_handle h, void *req, char *api_path,
int pi, int pi,
cvec *qvec, char *data, cvec *qvec, char *data,
int pretty, restconf_media media_out, ietf_ds_t ds); int pretty, restconf_media media_out, ietf_ds_t ds);
int api_data_patch(clicon_handle h, void *req, char *api_path, int api_data_patch(clixon_handle h, void *req, char *api_path,
int pi, int pi,
cvec *qvec, char *data, int pretty, cvec *qvec, char *data, int pretty,
restconf_media media_out, ietf_ds_t ds); restconf_media media_out, ietf_ds_t ds);
int api_data_delete(clicon_handle h, void *req, char *api_path, int pi, int api_data_delete(clixon_handle h, void *req, char *api_path, int pi,
int pretty, restconf_media media_out, ietf_ds_t ds); int pretty, restconf_media media_out, ietf_ds_t ds);
#endif /* _RESTCONF_METHODS_H_ */ #endif /* _RESTCONF_METHODS_H_ */

View file

@ -54,7 +54,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
@ -64,7 +64,7 @@
#include "restconf_methods_get.h" #include "restconf_methods_get.h"
/* Forward */ /* Forward */
static int api_data_pagination(clicon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out); static int api_data_pagination(clixon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out);
/*! Generic GET (both HEAD and GET) /*! Generic GET (both HEAD and GET)
* According to restconf * According to restconf
@ -97,7 +97,7 @@ static int api_data_pagination(clicon_handle h, void *req, char *api_path, int p
* @note there is an ad-hoc method to determine json pagination request instead of regular GET * @note there is an ad-hoc method to determine json pagination request instead of regular GET
*/ */
static int static int
api_data_get2(clicon_handle h, api_data_get2(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -130,7 +130,7 @@ api_data_get2(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
/* strip /... from start */ /* strip /... from start */
@ -184,7 +184,7 @@ api_data_get2(clicon_handle h,
if (strcmp(attr, "unbounded") != 0){ if (strcmp(attr, "unbounded") != 0){
char *reason = NULL; char *reason = NULL;
if ((ret = parse_int32(attr, &depth, &reason)) < 0){ if ((ret = parse_int32(attr, &depth, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_int32"); clixon_err(OE_XML, errno, "parse_int32");
goto done; goto done;
} }
if (ret==0){ if (ret==0){
@ -206,7 +206,7 @@ api_data_get2(clicon_handle h,
ret = clicon_rpc_get(h, xpath, nsc, content, depth, defaults, &xret); ret = clicon_rpc_get(h, xpath, nsc, content, depth, defaults, &xret);
if (ret < 0){ if (ret < 0){
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0) if (netconf_operation_failed_xml(&xerr, "protocol", clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -227,7 +227,7 @@ api_data_get2(clicon_handle h,
} }
/* Normal return, no error */ /* Normal return, no error */
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */ if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */
@ -246,7 +246,7 @@ api_data_get2(clicon_handle h,
} }
else{ else{
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0){ if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0){
if (netconf_operation_failed_xml(&xerr, "application", clicon_err_reason) < 0) if (netconf_operation_failed_xml(&xerr, "application", clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -345,7 +345,7 @@ api_data_get2(clicon_handle h,
* @see draft-ietf-netconf-restconf-collection-00.txt * @see draft-ietf-netconf-restconf-collection-00.txt
*/ */
static int static int
api_data_pagination(clicon_handle h, api_data_pagination(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -383,7 +383,7 @@ api_data_pagination(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
/* strip /... from start */ /* strip /... from start */
@ -406,7 +406,7 @@ api_data_pagination(clicon_handle h,
goto done; goto done;
if (ret == 0){ /* validation failed */ if (ret == 0){ /* validation failed */
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
goto done; goto done;
} }
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
@ -419,7 +419,7 @@ api_data_pagination(clicon_handle h,
"Element is not list or leaf-list which is required for GET paginate") < 0) "Element is not list or leaf-list which is required for GET paginate") < 0)
goto done; goto done;
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
goto done; goto done;
} }
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
@ -436,7 +436,7 @@ api_data_pagination(clicon_handle h,
"content", "Unrecognized value of content attribute") < 0) "content", "Unrecognized value of content attribute") < 0)
goto done; goto done;
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
goto done; goto done;
} }
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
@ -446,7 +446,7 @@ api_data_pagination(clicon_handle h,
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if (content != CONTENT_CONFIG && content != CONTENT_NONCONFIG && content != CONTENT_ALL){
clicon_err(OE_XML, EINVAL, "Invalid content attribute %d", content); clixon_err(OE_XML, EINVAL, "Invalid content attribute %d", content);
goto done; goto done;
} }
/* Clixon extensions and collection attributes */ /* Clixon extensions and collection attributes */
@ -456,7 +456,7 @@ api_data_pagination(clicon_handle h,
if (strcmp(attr, "unbounded") != 0){ if (strcmp(attr, "unbounded") != 0){
char *reason = NULL; char *reason = NULL;
if ((ret = parse_int32(attr, &depth, &reason)) < 0){ if ((ret = parse_int32(attr, &depth, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_int32"); clixon_err(OE_XML, errno, "parse_int32");
goto done; goto done;
} }
if (ret==0){ if (ret==0){
@ -493,10 +493,10 @@ api_data_pagination(clicon_handle h,
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc, content, if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc, content,
depth, NULL, offset, limit, direction, sort, where, depth, NULL, offset, limit, direction, sort, where,
&xret) < 0){ &xret) < 0){
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0) if (netconf_operation_failed_xml(&xerr, "protocol", clixon_err_reason()) < 0)
goto done; goto done;
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
goto done; goto done;
} }
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
@ -607,7 +607,7 @@ api_data_pagination(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
api_data_head(clicon_handle h, api_data_head(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -648,7 +648,7 @@ api_data_head(clicon_handle h,
* Netconf: <get-config>, <get> * Netconf: <get-config>, <get>
*/ */
int int
api_data_get(clicon_handle h, api_data_get(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -703,7 +703,7 @@ api_data_get(clicon_handle h,
* { 'ietf-system:system-restart' : [null] } * { 'ietf-system:system-restart' : [null] }
*/ */
int int
api_operations_get(clicon_handle h, api_operations_get(clixon_handle h,
void *req, void *req,
char *path, char *path,
int pi, int pi,

View file

@ -41,11 +41,11 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_data_head(clicon_handle h, void *req, char *api_path, int pi, int api_data_head(clixon_handle h, void *req, char *api_path, int pi,
cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds); cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
int api_data_get(clicon_handle h, void *req, char *api_path, int pi, int api_data_get(clixon_handle h, void *req, char *api_path, int pi,
cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds); cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
int api_operations_get(clicon_handle h, void *req, int api_operations_get(clixon_handle h, void *req,
char *api_path, int pi, cvec *qvec, char *data, char *api_path, int pi, cvec *qvec, char *data,
int pretty, restconf_media media_out); int pretty, restconf_media media_out);

View file

@ -56,7 +56,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
@ -205,7 +205,7 @@ yang_patch_strip_after_last_slash(char* val)
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang_patch_do_replace(clicon_handle h, yang_patch_do_replace(clixon_handle h,
void *req, void *req,
int pi, int pi,
cvec *qvec, cvec *qvec,
@ -226,23 +226,23 @@ yang_patch_do_replace(clicon_handle h,
cbuf *json_simple_patch = NULL; cbuf *json_simple_patch = NULL;
if ((delete_req_uri = cbuf_new()) == NULL){ if ((delete_req_uri = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((json_simple_patch = cbuf_new()) == NULL){ if ((json_simple_patch = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
// Make delete_req_uri something like "/restconf/data/ietf-interfaces:interfaces" // Make delete_req_uri something like "/restconf/data/ietf-interfaces:interfaces"
if (cbuf_append_str(delete_req_uri, cbuf_get(simple_patch_request_uri)) < 0){ if (cbuf_append_str(delete_req_uri, cbuf_get(simple_patch_request_uri)) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str"); clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done; goto done;
} }
// Add the target to delete_req_uri, // Add the target to delete_req_uri,
// so it's something like "/restconf/data/ietf-interfaces:interfaces/interface=eth2" // so it's something like "/restconf/data/ietf-interfaces:interfaces/interface=eth2"
if (cbuf_append_str(delete_req_uri, target_val) < 0){ if (cbuf_append_str(delete_req_uri, target_val) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str"); clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done; goto done;
} }
@ -259,7 +259,7 @@ yang_patch_do_replace(clicon_handle h,
// Make post_req_uri something like "/restconf/data/ietf-interfaces:interfaces" // Make post_req_uri something like "/restconf/data/ietf-interfaces:interfaces"
if (cbuf_append_str(simple_patch_request_uri, cbuf_get(post_req_uri)) < 0){ if (cbuf_append_str(simple_patch_request_uri, cbuf_get(post_req_uri)) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str"); clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done; goto done;
} }
// Now insert the new values into the data // Now insert the new values into the data
@ -307,7 +307,7 @@ yang_patch_do_replace(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang_patch_do_create(clicon_handle h, yang_patch_do_create(clixon_handle h,
void *req, void *req,
int pi, int pi,
cvec *qvec, cvec *qvec,
@ -326,7 +326,7 @@ yang_patch_do_create(clicon_handle h,
// Send the POST request // Send the POST request
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
for (int k = 0; k < value_vec_len; k++) { for (int k = 0; k < value_vec_len; k++) {
@ -368,7 +368,7 @@ yang_patch_do_create(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang_patch_do_insert(clicon_handle h, yang_patch_do_insert(clixon_handle h,
void *req, void *req,
int pi, int pi,
int pretty, int pretty,
@ -391,11 +391,11 @@ yang_patch_do_insert(clicon_handle h,
cvec *qvec_tmp = NULL; cvec *qvec_tmp = NULL;
if ((point_str = cbuf_new()) == NULL){ if ((point_str = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((qvec_tmp = cvec_new(0)) == NULL){ if ((qvec_tmp = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
// Loop through the XML, and get each value // Loop through the XML, and get each value
@ -410,7 +410,7 @@ yang_patch_do_insert(clicon_handle h,
// Set the insert attributes // Set the insert attributes
if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){ if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add"); clixon_err(OE_UNIX, errno, "cvec_add");
goto done; goto done;
} }
cv_name_set(cv, "insert"); cv_name_set(cv, "insert");
@ -420,7 +420,7 @@ yang_patch_do_insert(clicon_handle h,
if (point_val) if (point_val)
cbuf_append_str(point_str, point_val); cbuf_append_str(point_str, point_val);
if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){ if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add"); clixon_err(OE_UNIX, errno, "cvec_add");
goto done; goto done;
} }
cv_name_set(cv, "point"); cv_name_set(cv, "point");
@ -459,7 +459,7 @@ yang_patch_do_insert(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang_patch_do_merge(clicon_handle h, yang_patch_do_merge(clixon_handle h,
void *req, void *req,
int pi, int pi,
cvec *qvec, cvec *qvec,
@ -479,7 +479,7 @@ yang_patch_do_merge(clicon_handle h,
cbuf *json_simple_patch = NULL; cbuf *json_simple_patch = NULL;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (key_xn != NULL) if (key_xn != NULL)
@ -521,7 +521,7 @@ yang_patch_do_merge(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang_patch_do_value(clicon_handle h, yang_patch_do_value(clixon_handle h,
void *req, void *req,
int pi, int pi,
cvec *qvec, cvec *qvec,
@ -551,7 +551,7 @@ yang_patch_do_value(clicon_handle h,
key_node_id = xml_name(*values_child_vec); key_node_id = xml_name(*values_child_vec);
/* Create cbufs:s */ /* Create cbufs:s */
if ((patch_header = cbuf_new()) == NULL){ if ((patch_header = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(patch_header, "%s:%s", modname, key_node_id); cprintf(patch_header, "%s:%s", modname, key_node_id);
@ -601,7 +601,7 @@ yang_patch_do_value(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
yang_patch_do_edit(clicon_handle h, yang_patch_do_edit(clixon_handle h,
void *req, void *req,
int pi, int pi,
cvec *qvec, cvec *qvec,
@ -638,26 +638,26 @@ yang_patch_do_edit(clicon_handle h,
clixon_debug_xml(1, xn, "%s %d xn:", __FUNCTION__, __LINE__); clixon_debug_xml(1, xn, "%s %d xn:", __FUNCTION__, __LINE__);
/* Create cbufs:s */ /* Create cbufs:s */
if ((simple_patch_request_uri = cbuf_new()) == NULL){ if ((simple_patch_request_uri = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((api_path_target = cbuf_new()) == NULL){ if ((api_path_target = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((x = xpath_first(xn, NULL, "target")) == NULL){ if ((x = xpath_first(xn, NULL, "target")) == NULL){
clicon_err(OE_YANG, 0, "target mandatory element not found"); clixon_err(OE_YANG, 0, "target mandatory element not found");
goto done; goto done;
} }
target_val = xml_body(x); target_val = xml_body(x);
if ((x = xpath_first(xn, NULL, "operation")) == NULL){ if ((x = xpath_first(xn, NULL, "operation")) == NULL){
clicon_err(OE_YANG, 0, "operation mandatory element not found"); clixon_err(OE_YANG, 0, "operation mandatory element not found");
goto done; goto done;
} }
operation = yang_patch_op2int(xml_body(x)); operation = yang_patch_op2int(xml_body(x));
/* target and operation are mandatory */ /* target and operation are mandatory */
if (target_val == NULL){ if (target_val == NULL){
clicon_err(OE_YANG, 0, "operation/target: mandatory element not found"); clixon_err(OE_YANG, 0, "operation/target: mandatory element not found");
goto done; goto done;
} }
if (operation == YANG_PATCH_OP_INSERT){ if (operation == YANG_PATCH_OP_INSERT){
@ -666,7 +666,7 @@ yang_patch_do_edit(clicon_handle h,
if ((x = xpath_first(xn, NULL, "where")) != NULL) if ((x = xpath_first(xn, NULL, "where")) != NULL)
where_val = xml_body(x); where_val = xml_body(x);
if (point_val == NULL || where_val == NULL){ if (point_val == NULL || where_val == NULL){
clicon_err(OE_YANG, 0, "point/where: expected element not found"); clixon_err(OE_YANG, 0, "point/where: expected element not found");
goto done; goto done;
} }
} }
@ -756,7 +756,7 @@ yang_patch_do_edit(clicon_handle h,
* Currently "move" not supported * Currently "move" not supported
*/ */
int int
api_data_yang_patch(clicon_handle h, api_data_yang_patch(clixon_handle h,
void *req, void *req,
char *api_path0, char *api_path0,
int pi, int pi,
@ -780,7 +780,7 @@ api_data_yang_patch(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
api_path=api_path0; api_path=api_path0;
@ -808,7 +808,7 @@ api_data_yang_patch(clicon_handle h,
} }
/* Common error handling for json/xml parsing above */ /* Common error handling for json/xml parsing above */
if (ret < 0){ if (ret < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -860,7 +860,7 @@ api_data_yang_patch(clicon_handle h,
#else // CLIXON_YANG_PATCH #else // CLIXON_YANG_PATCH
int int
api_data_yang_patch(clicon_handle h, api_data_yang_patch(clixon_handle h,
void *req, void *req,
char *api_path0, char *api_path0,
int pi, int pi,
@ -871,7 +871,7 @@ api_data_yang_patch(clicon_handle h,
restconf_media media_out, restconf_media media_out,
ietf_ds_t ds) ietf_ds_t ds)
{ {
clicon_err(OE_RESTCONF, 0, "Not implemented"); clixon_err(OE_RESTCONF, 0, "Not implemented");
return -1; return -1;
} }
#endif // CLIXON_YANG_PATCH #endif // CLIXON_YANG_PATCH

View file

@ -43,7 +43,7 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_data_yang_patch(clicon_handle h, void *req, char *api_path0, int api_data_yang_patch(clixon_handle h, void *req, char *api_path0,
int pi, int pi,
cvec *qvec, char *data, cvec *qvec, char *data,
int pretty, restconf_media media_in, restconf_media media_out, int pretty, restconf_media media_in, restconf_media media_out,

View file

@ -56,7 +56,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "restconf_lib.h" #include "restconf_lib.h"
@ -75,7 +75,7 @@
* @note ports are ignored * @note ports are ignored
*/ */
static int static int
http_location_header(clicon_handle h, http_location_header(clixon_handle h,
void *req, void *req,
cxobj *xobj) cxobj *xobj)
{ {
@ -91,7 +91,7 @@ http_location_header(clicon_handle h,
goto done; goto done;
if (xobj != NULL){ if (xobj != NULL){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new"); clixon_err(OE_UNIX, 0, "cbuf_new");
goto done; goto done;
} }
if (xml2api_path_1(xobj, cb) < 0) if (xml2api_path_1(xobj, cb) < 0)
@ -155,7 +155,7 @@ http_location_header(clicon_handle h,
* @see api_data_put * @see api_data_put
*/ */
int int
api_data_post(clicon_handle h, api_data_post(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -192,7 +192,7 @@ api_data_post(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path); clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path);
clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data); clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
for (i=0; i<pi; i++) for (i=0; i<pi; i++)
@ -241,7 +241,7 @@ api_data_post(clicon_handle h,
switch (media_in){ switch (media_in){
case YANG_DATA_XML: case YANG_DATA_XML:
if ((ret = clixon_xml_parse_string(data, yb, yspec, &xbot, &xerr)) < 0){ if ((ret = clixon_xml_parse_string(data, yb, yspec, &xbot, &xerr)) < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -255,7 +255,7 @@ api_data_post(clicon_handle h,
break; break;
case YANG_DATA_JSON: case YANG_DATA_JSON:
if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xbot, &xerr)) < 0){ if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xbot, &xerr)) < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -335,7 +335,7 @@ api_data_post(clicon_handle h,
/* Create text buffer for transfer to backend */ /* Create text buffer for transfer to backend */
if ((cbx = cbuf_new()) == NULL){ if ((cbx = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new"); clixon_err(OE_UNIX, 0, "cbuf_new");
goto done; goto done;
} }
/* For internal XML protocol: add username attribute for access control /* For internal XML protocol: add username attribute for access control
@ -412,7 +412,7 @@ api_data_post(clicon_handle h,
* @param[in] media_out Output media * @param[in] media_out Output media
* @retval 1 OK * @retval 1 OK
* @retval 0 Fail, Error message sent * @retval 0 Fail, Error message sent
* @retval -1 Fatal error, clicon_err called * @retval -1 Fatal error
* *
* RFC8040 3.6.1 * RFC8040 3.6.1
* If the "rpc" or "action" statement has an "input" section, then * If the "rpc" or "action" statement has an "input" section, then
@ -423,7 +423,7 @@ api_data_post(clicon_handle h,
* (Any other input is assumed as error.) * (Any other input is assumed as error.)
*/ */
static int static int
api_operations_post_input(clicon_handle h, api_operations_post_input(clixon_handle h,
void *req, void *req,
char *data, char *data,
yang_stmt *yspec, yang_stmt *yspec,
@ -443,7 +443,7 @@ api_operations_post_input(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, data); clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, data);
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new"); clixon_err(OE_UNIX, 0, "cbuf_new");
goto done; goto done;
} }
/* Parse input data as json or xml into xml */ /* Parse input data as json or xml into xml */
@ -453,7 +453,7 @@ api_operations_post_input(clicon_handle h,
/* XXX: Here data is on the form: <input xmlns="urn:example:clixon"/> and has no proper yang binding /* XXX: Here data is on the form: <input xmlns="urn:example:clixon"/> and has no proper yang binding
* support */ * support */
if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){ if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -469,7 +469,7 @@ api_operations_post_input(clicon_handle h,
/* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding /* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding
* support */ * support */
if ((ret = clixon_json_parse_string(data, 1, YB_NONE, yspec, &xdata, &xerr)) < 0){ if ((ret = clixon_json_parse_string(data, 1, YB_NONE, yspec, &xdata, &xerr)) < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done; goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done; goto done;
@ -545,11 +545,11 @@ api_operations_post_input(clicon_handle h,
* @param[out] xoutputp Restconf JSON/XML output * @param[out] xoutputp Restconf JSON/XML output
* @retval 1 OK * @retval 1 OK
* @retval 0 Fail, Error message sent * @retval 0 Fail, Error message sent
* @retval -1 Fatal error, clicon_err called * @retval -1 Fatal error
* xret should like: <top><rpc-reply><x xmlns="uri">0</x></rpc-reply></top> * xret should like: <top><rpc-reply><x xmlns="uri">0</x></rpc-reply></top>
*/ */
static int static int
api_operations_post_output(clicon_handle h, api_operations_post_output(clixon_handle h,
void *req, void *req,
cxobj *xret, cxobj *xret,
yang_stmt *yspec, yang_stmt *yspec,
@ -691,7 +691,7 @@ api_operations_post_output(clicon_handle h,
* 10. Validate and send reply to originator * 10. Validate and send reply to originator
*/ */
int int
api_operations_post(clicon_handle h, api_operations_post(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
int pi, int pi,
@ -725,11 +725,11 @@ api_operations_post(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%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 */ /* 1. Initialize */
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_UNIX, 0, "cbuf_new"); clixon_err(OE_UNIX, 0, "cbuf_new");
goto done; goto done;
} }
for (i=0; i<pi; i++) for (i=0; i<pi; i++)

View file

@ -41,13 +41,13 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_data_post(clicon_handle h, void *req, char *api_path, int api_data_post(clixon_handle h, void *req, char *api_path,
int pi, cvec *qvec, char *data, int pi, cvec *qvec, char *data,
int pretty, int pretty,
restconf_media media_in, restconf_media media_in,
restconf_media media_out, ietf_ds_t ds); restconf_media media_out, ietf_ds_t ds);
int api_operations_post(clicon_handle h, void *req, char *api_path, int api_operations_post(clixon_handle h, void *req, char *api_path,
int pi, cvec *qvec, char *data, int pi, cvec *qvec, char *data,
int pretty, restconf_media media_out); int pretty, restconf_media media_out);

View file

@ -92,26 +92,26 @@ restconf_stream_data_new(restconf_conn *rc,
restconf_stream_data *sd; restconf_stream_data *sd;
if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){ if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
return NULL; return NULL;
} }
memset(sd, 0, sizeof(restconf_stream_data)); memset(sd, 0, sizeof(restconf_stream_data));
sd->sd_stream_id = stream_id; sd->sd_stream_id = stream_id;
sd->sd_fd = -1; sd->sd_fd = -1;
if ((sd->sd_inbuf = cbuf_new()) == NULL){ if ((sd->sd_inbuf = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
return NULL; return NULL;
} }
if ((sd->sd_indata = cbuf_new()) == NULL){ if ((sd->sd_indata = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
return NULL; return NULL;
} }
if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){ if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
return NULL; return NULL;
} }
if ((sd->sd_outp_buf = cbuf_new()) == NULL){ if ((sd->sd_outp_buf = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
return NULL; return NULL;
} }
sd->sd_conn = rc; sd->sd_conn = rc;
@ -176,14 +176,14 @@ restconf_stream_free(restconf_stream_data *sd)
* @see restconf_conn_free * @see restconf_conn_free
*/ */
restconf_conn * restconf_conn *
restconf_conn_new(clicon_handle h, restconf_conn_new(clixon_handle h,
int s, int s,
restconf_socket *rsock) restconf_socket *rsock)
{ {
restconf_conn *rc; restconf_conn *rc;
if ((rc = (restconf_conn*)malloc(sizeof(restconf_conn))) == NULL){ if ((rc = (restconf_conn*)malloc(sizeof(restconf_conn))) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
return NULL; return NULL;
} }
memset(rc, 0, sizeof(restconf_conn)); memset(rc, 0, sizeof(restconf_conn));
@ -210,7 +210,7 @@ restconf_conn_free(restconf_conn *rc)
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (rc == NULL){ if (rc == NULL){
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL"); clixon_err(OE_RESTCONF, EINVAL, "rc is NULL");
goto done; goto done;
} }
#ifdef HAVE_LIBNGHTTP2 #ifdef HAVE_LIBNGHTTP2
@ -257,7 +257,7 @@ ssl_x509_name_oneline(SSL *ssl,
X509_NAME *name; X509_NAME *name;
if (ssl == NULL || oneline == NULL) { if (ssl == NULL || oneline == NULL) {
clicon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL"); clixon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL");
goto done; goto done;
} }
#if OPENSSL_VERSION_NUMBER < 0x30000000L #if OPENSSL_VERSION_NUMBER < 0x30000000L
@ -272,7 +272,7 @@ ssl_x509_name_oneline(SSL *ssl,
if ((p = X509_NAME_oneline(name, NULL, 0)) == NULL) if ((p = X509_NAME_oneline(name, NULL, 0)) == NULL)
goto ok; goto ok;
if ((*oneline = strdup(p)) == NULL){ if ((*oneline = strdup(p)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
ok: ok:
@ -303,7 +303,7 @@ ssl_x509_name_oneline(SSL *ssl,
* @see restconf_accept_client where connection can be exited at an earlier stage * @see restconf_accept_client where connection can be exited at an earlier stage
*/ */
int int
restconf_connection_sanity(clicon_handle h, restconf_connection_sanity(clixon_handle h,
restconf_conn *rc, restconf_conn *rc,
restconf_stream_data *sd) restconf_stream_data *sd)
{ {
@ -339,12 +339,12 @@ restconf_connection_sanity(clicon_handle h,
if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0) if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0)
goto done; goto done;
if (oneline) if (oneline)
clicon_log(LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code)); clixon_log(h, LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code));
else else
clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code)); clixon_log(h, LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code));
/* Send return error message */ /* Send return error message */
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cberr, "HTTP cert verification failed: %s[%ld]", cprintf(cberr, "HTTP cert verification failed: %s[%ld]",
@ -385,7 +385,7 @@ restconf_connection_sanity(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
native_buf_write(clicon_handle h, native_buf_write(clixon_handle h,
char *buf, char *buf,
size_t buflen, size_t buflen,
restconf_conn *rc, restconf_conn *rc,
@ -398,7 +398,7 @@ native_buf_write(clicon_handle h,
SSL *ssl; SSL *ssl;
if (rc == NULL){ if (rc == NULL){
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL"); clixon_err(OE_RESTCONF, EINVAL, "rc is NULL");
goto done; goto done;
} }
ssl = rc->rc_ssl; ssl = rc->rc_ssl;
@ -411,7 +411,7 @@ native_buf_write(clicon_handle h,
size_t sz; size_t sz;
sz = buflen>256?256:buflen; /* Truncate to 256 */ sz = buflen>256?256:buflen; /* Truncate to 256 */
if ((dbgstr = malloc(sz+1)) == NULL){ if ((dbgstr = malloc(sz+1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memcpy(dbgstr, buf, sz); memcpy(dbgstr, buf, sz);
@ -435,12 +435,12 @@ native_buf_write(clicon_handle h,
continue; continue;
} }
else{ else{
clicon_err(OE_RESTCONF, er, "SSL_write %d", er); clixon_err(OE_RESTCONF, er, "SSL_write %d", er);
goto done; goto done;
} }
break; break;
default: default:
clicon_err(OE_SSL, 0, "SSL_write"); clixon_err(OE_SSL, 0, "SSL_write");
goto done; goto done;
break; break;
} }
@ -461,7 +461,7 @@ native_buf_write(clicon_handle h,
goto closed; /* Close socket and ssl */ goto closed; /* Close socket and ssl */
break; break;
default: default:
clicon_err(OE_UNIX, errno, "write %d", errno); clixon_err(OE_UNIX, errno, "write %d", errno);
goto done; goto done;
break; break;
} }
@ -490,7 +490,7 @@ native_buf_write(clicon_handle h,
* @see restconf_badrequest which can only be called in a request context * @see restconf_badrequest which can only be called in a request context
*/ */
static int static int
native_send_badrequest(clicon_handle h, native_send_badrequest(clixon_handle h,
char *media, char *media,
char *body, char *body,
restconf_conn *rc) restconf_conn *rc)
@ -500,7 +500,7 @@ native_send_badrequest(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n"); cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n");
@ -530,7 +530,7 @@ native_send_badrequest(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
http1_native_clear_input(clicon_handle h, http1_native_clear_input(clixon_handle h,
restconf_stream_data *sd) restconf_stream_data *sd)
{ {
int retval = -1; int retval = -1;
@ -586,7 +586,7 @@ read_ssl(restconf_conn *rc,
*np = 0; /* should already be zero */ *np = 0; /* should already be zero */
break; break;
default: default:
clicon_log(LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr); clixon_log(rc->rc_h, LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr);
*np = 0; *np = 0;
break; break;
} /* switch */ } /* switch */
@ -635,7 +635,7 @@ read_regular(restconf_conn *rc,
*again = 1; *again = 1;
break; break;
default:; default:;
clicon_err(OE_XML, errno, "read"); clixon_err(OE_XML, errno, "read");
goto done; goto done;
break; break;
} }
@ -665,14 +665,14 @@ restconf_http1_process(restconf_conn *rc,
{ {
int retval = -1; int retval = -1;
restconf_stream_data *sd; restconf_stream_data *sd;
clicon_handle h; clixon_handle h;
int ret; int ret;
int status; int status;
cbuf *cberr = NULL; cbuf *cberr = NULL;
h = rc->rc_h; h = rc->rc_h;
if ((sd = restconf_stream_find(rc, 0)) == NULL){ if ((sd = restconf_stream_find(rc, 0)) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found"); clixon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
goto done; goto done;
} }
/* Two states for reading: /* Two states for reading:
@ -691,7 +691,7 @@ restconf_http1_process(restconf_conn *rc,
goto done; goto done;
if (status == 1){ /* Next read: keep header state and only append inbody */ if (status == 1){ /* Next read: keep header state and only append inbody */
if (cbuf_append_buf(sd->sd_indata, buf, n) < 0){ if (cbuf_append_buf(sd->sd_indata, buf, n) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append"); clixon_err(OE_UNIX, errno, "cbuf_append");
goto done; goto done;
} }
} }
@ -700,7 +700,7 @@ restconf_http1_process(restconf_conn *rc,
* This is different from sd_indata that it is before and includes headers * This is different from sd_indata that it is before and includes headers
*/ */
if (cbuf_append_buf(sd->sd_inbuf, buf, n) < 0){ if (cbuf_append_buf(sd->sd_inbuf, buf, n) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append"); clixon_err(OE_UNIX, errno, "cbuf_append");
goto done; goto done;
} }
if (clixon_http1_parse_string(h, rc, cbuf_get(sd->sd_inbuf)) < 0){ if (clixon_http1_parse_string(h, rc, cbuf_get(sd->sd_inbuf)) < 0){
@ -720,10 +720,10 @@ restconf_http1_process(restconf_conn *rc,
* timeout here. * timeout here.
*/ */
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>%s</error-message></error></errors>", clicon_err_reason); cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>%s</error-message></error></errors>", clixon_err_reason());
if ((ret = native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc)) < 0) if ((ret = native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc)) < 0)
goto done; goto done;
if (http1_native_clear_input(h, sd) < 0) if (http1_native_clear_input(h, sd) < 0)
@ -812,7 +812,7 @@ restconf_http2_upgrade(restconf_conn *rc)
restconf_stream_data *sd; restconf_stream_data *sd;
if ((sd = restconf_stream_find(rc, 0)) == NULL){ if ((sd = restconf_stream_find(rc, 0)) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found"); clixon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
goto done; goto done;
} }
if (sd->sd_upgrade2){ if (sd->sd_upgrade2){
@ -836,7 +836,7 @@ restconf_http2_upgrade(restconf_conn *rc)
sd->sd_settings2?strlen((const char*)sd->sd_settings2):0, sd->sd_settings2?strlen((const char*)sd->sd_settings2):0,
0, /* XXX: 1 if HEAD */ 0, /* XXX: 1 if HEAD */
NULL)) < 0){ NULL)) < 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2"); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2");
goto done; goto done;
} }
if (http2_send_server_connection(rc) < 0){ if (http2_send_server_connection(rc) < 0){
@ -889,7 +889,7 @@ restconf_http2_process(restconf_conn *rc,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (rc->rc_exit){ /* Server-initiated exit for http/2 */ if (rc->rc_exit){ /* Server-initiated exit for http/2 */
if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){ if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
goto done; // XXX not here in original? goto done; // XXX not here in original?
} }
} }
@ -924,7 +924,7 @@ restconf_http2_process(restconf_conn *rc,
* @retval rn Restconf native handle * @retval rn Restconf native handle
*/ */
restconf_native_handle * restconf_native_handle *
restconf_native_handle_get(clicon_handle h) restconf_native_handle_get(clixon_handle h)
{ {
clicon_hash_t *cdat = clicon_data(h); clicon_hash_t *cdat = clicon_data(h);
size_t len; size_t len;
@ -963,11 +963,11 @@ restconf_connection(int s,
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, s); clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, s);
if ((rc = (restconf_conn*)arg) == NULL){ if ((rc = (restconf_conn*)arg) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "arg is NULL"); clixon_err(OE_RESTCONF, EINVAL, "arg is NULL");
goto done; goto done;
} }
if (s != rc->rc_s){ if (s != rc->rc_s){
clicon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s"); clixon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s");
goto done; goto done;
} }
gettimeofday(&rc->rc_t, NULL); /* activity timer */ gettimeofday(&rc->rc_t, NULL); /* activity timer */
@ -1049,13 +1049,13 @@ restconf_connection_close1(restconf_conn *rc)
restconf_socket *rsock; restconf_socket *rsock;
if (rc == NULL){ if (rc == NULL){
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL"); clixon_err(OE_RESTCONF, EINVAL, "rc is NULL");
goto done; goto done;
} }
rsock = rc->rc_socket; rsock = rc->rc_socket;
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
if (close(rc->rc_s) < 0){ if (close(rc->rc_s) < 0){
clicon_err(OE_UNIX, errno, "close"); clixon_err(OE_UNIX, errno, "close");
goto done; goto done;
} }
clixon_event_unreg_fd(rc->rc_s, restconf_connection); clixon_event_unreg_fd(rc->rc_s, restconf_connection);
@ -1113,7 +1113,7 @@ restconf_close_ssl_socket(restconf_conn *rc,
else{ else{
/* To avoid close again in restconf_native_terminate */ /* To avoid close again in restconf_native_terminate */
rc->rc_s = -1; rc->rc_s = -1;
clicon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er); clixon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er);
goto done; goto done;
} }
} }
@ -1141,7 +1141,7 @@ restconf_close_ssl_socket(restconf_conn *rc,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
ssl_alpn_check(clicon_handle h, ssl_alpn_check(clixon_handle h,
const unsigned char *alpn, const unsigned char *alpn,
unsigned int alpnlen, unsigned int alpnlen,
restconf_conn *rc, restconf_conn *rc,
@ -1162,12 +1162,12 @@ ssl_alpn_check(clicon_handle h,
#endif #endif
else { else {
if ((cberr = cbuf_new()) == NULL){ if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (alpn != NULL){ if (alpn != NULL){
cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>ALPN: protocol not recognized: %s</error-message></error></errors>", alpn); cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>ALPN: protocol not recognized: %s</error-message></error></errors>", alpn);
clicon_log(LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr)); clixon_log(h, LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr));
if (native_send_badrequest(h, if (native_send_badrequest(h,
"application/yang-data+xml", "application/yang-data+xml",
cbuf_get(cberr), rc) < 0) cbuf_get(cberr), rc) < 0)
@ -1186,7 +1186,7 @@ ssl_alpn_check(clicon_handle h,
if (pstr) if (pstr)
p = restconf_str2proto(pstr); p = restconf_str2proto(pstr);
if (pstr == NULL || p == -1){ if (pstr == NULL || p == -1){
clicon_log(LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__); clixon_log(h, LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__);
if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0) if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
goto done; goto done;
goto fail; goto fail;
@ -1223,7 +1223,7 @@ ssl_alpn_check(clicon_handle h,
* @see openssl_init_socket where this callback is registered * @see openssl_init_socket where this callback is registered
*/ */
int int
restconf_ssl_accept_client(clicon_handle h, restconf_ssl_accept_client(clixon_handle h,
int s, int s,
restconf_socket *rsock, restconf_socket *rsock,
restconf_conn **rcp) restconf_conn **rcp)
@ -1247,7 +1247,7 @@ restconf_ssl_accept_client(clicon_handle h,
#endif #endif
#endif #endif
if ((rn = restconf_native_handle_get(h)) == NULL){ if ((rn = restconf_native_handle_get(h)) == NULL){
clicon_err(OE_XML, EFAULT, "No openssl handle"); clixon_err(OE_XML, EFAULT, "No openssl handle");
goto done; goto done;
} }
/* /*
@ -1258,7 +1258,7 @@ restconf_ssl_accept_client(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s s:%d", __FUNCTION__, rc->rc_s); clixon_debug(CLIXON_DBG_DEFAULT, "%s s:%d", __FUNCTION__, rc->rc_s);
if (rsock->rs_ssl){ if (rsock->rs_ssl){
if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){ if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){
clicon_err(OE_SSL, 0, "SSL_new"); clixon_err(OE_SSL, 0, "SSL_new");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl); clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl);
@ -1279,16 +1279,16 @@ restconf_ssl_accept_client(clicon_handle h,
emailAddress = olof@hagsand.se emailAddress = olof@hagsand.se
*/ */
if (SSL_set1_host(rc->rc_ssl, "andy") != 1) { /* for peer cert */ if (SSL_set1_host(rc->rc_ssl, "andy") != 1) { /* for peer cert */
clicon_err(OE_SSL, 0, "SSL_set1_host"); clixon_err(OE_SSL, 0, "SSL_set1_host");
goto done; goto done;
} }
if (SSL_add1_host(rc->rc_ssl, "olof") != 1) { /* for peer cert */ if (SSL_add1_host(rc->rc_ssl, "olof") != 1) { /* for peer cert */
clicon_err(OE_SSL, 0, "SSL_set1_host"); clixon_err(OE_SSL, 0, "SSL_set1_host");
goto done; goto done;
} }
#endif #endif
if (SSL_set_fd(rc->rc_ssl, rc->rc_s) != 1){ if (SSL_set_fd(rc->rc_ssl, rc->rc_s) != 1){
clicon_err(OE_SSL, 0, "SSL_set_fd"); clixon_err(OE_SSL, 0, "SSL_set_fd");
goto done; goto done;
} }
readmore = 1; readmore = 1;
@ -1348,7 +1348,7 @@ restconf_ssl_accept_client(clicon_handle h,
case SSL_ERROR_WANT_CLIENT_HELLO_CB: /* 11 */ case SSL_ERROR_WANT_CLIENT_HELLO_CB: /* 11 */
#endif #endif
default: default:
clicon_err(OE_SSL, 0, "SSL_accept:%d", e); clixon_err(OE_SSL, 0, "SSL_accept:%d", e);
goto done; goto done;
break; break;
} }
@ -1409,7 +1409,7 @@ restconf_ssl_accept_client(clicon_handle h,
} }
#if 0 #if 0
else{ else{
clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret)); clixon_log(h, LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret));
/* Maybe should return already here, but to get proper return message need to /* Maybe should return already here, but to get proper return message need to
* continue to http/1 or http/2 handling * continue to http/1 or http/2 handling
* @see restconf_connection_sanity * @see restconf_connection_sanity
@ -1436,12 +1436,12 @@ restconf_ssl_accept_client(clicon_handle h,
case HTTP_2:{ case HTTP_2:{
if (http2_session_init(rc) < 0){ if (http2_session_init(rc) < 0){
restconf_close_ssl_socket(rc, __FUNCTION__, 0); restconf_close_ssl_socket(rc, __FUNCTION__, 0);
clicon_err_reset(); clixon_err_reset();
goto closed; goto closed;
} }
if (http2_send_server_connection(rc) < 0){ if (http2_send_server_connection(rc) < 0){
restconf_close_ssl_socket(rc, __FUNCTION__, 0); restconf_close_ssl_socket(rc, __FUNCTION__, 0);
clicon_err_reset(); clixon_err_reset();
goto closed; goto closed;
} }
break; break;
@ -1475,7 +1475,7 @@ restconf_idle_timer_set(struct timeval t,
cbuf *cb = NULL; cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "restconf idle timer %s", descr); cprintf(cb, "restconf idle timer %s", descr);
@ -1521,11 +1521,11 @@ restconf_idle_cb(int fd,
struct timeval to = {0,}; struct timeval to = {0,};
if ((rc = (restconf_conn *)arg) == NULL){ if ((rc = (restconf_conn *)arg) == NULL){
clicon_err(OE_YANG, EINVAL, "rc is NULL"); clixon_err(OE_YANG, EINVAL, "rc is NULL");
goto done; goto done;
} }
if ((rsock = rc->rc_socket) == NULL){ if ((rsock = rc->rc_socket) == NULL){
clicon_err(OE_YANG, EINVAL, "rsock is NULL"); clixon_err(OE_YANG, EINVAL, "rsock is NULL");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
@ -1577,12 +1577,12 @@ restconf_idle_timer(restconf_conn *rc)
restconf_socket *rsock; restconf_socket *rsock;
if (rc == NULL || !rc->rc_callhome){ if (rc == NULL || !rc->rc_callhome){
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome"); clixon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome");
goto done; goto done;
} }
rsock = rc->rc_socket; rsock = rc->rc_socket;
if (rsock == NULL || !rsock->rs_periodic || rsock->rs_idle_timeout==0){ if (rsock == NULL || !rsock->rs_periodic || rsock->rs_idle_timeout==0){
clicon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic"); clixon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" register", __FUNCTION__, rsock->rs_description); clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" register", __FUNCTION__, rsock->rs_description);
@ -1609,7 +1609,7 @@ restconf_callhome_cb(int fd,
void *arg) void *arg)
{ {
int retval = -1; int retval = -1;
clicon_handle h; clixon_handle h;
restconf_socket *rsock = NULL; restconf_socket *rsock = NULL;
struct sockaddr_in6 sin6 = {0,}; // because its larger than sin and sa struct sockaddr_in6 sin6 = {0,}; // because its larger than sin and sa
struct sockaddr *sa = (struct sockaddr *)&sin6; struct sockaddr *sa = (struct sockaddr *)&sin6;
@ -1620,7 +1620,7 @@ restconf_callhome_cb(int fd,
rsock = (restconf_socket *)arg; rsock = (restconf_socket *)arg;
if (rsock == NULL || !rsock->rs_callhome){ if (rsock == NULL || !rsock->rs_callhome){
clicon_err(OE_YANG, EINVAL, "rsock is NULL"); clixon_err(OE_YANG, EINVAL, "rsock is NULL");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
@ -1629,7 +1629,7 @@ restconf_callhome_cb(int fd,
if (clixon_inet2sin(rsock->rs_addrtype, rsock->rs_addrstr, rsock->rs_port, sa, &sa_len) < 0) if (clixon_inet2sin(rsock->rs_addrtype, rsock->rs_addrstr, rsock->rs_port, sa, &sa_len) < 0)
goto done; goto done;
if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) { if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
clicon_err(OE_UNIX, errno, "socket"); clixon_err(OE_UNIX, errno, "socket");
goto done; goto done;
} }
if (connect(s, sa, sa_len) < 0){ if (connect(s, sa, sa_len) < 0){
@ -1683,7 +1683,7 @@ restconf_callhome_timer(restconf_socket *rsock,
cbuf *cb = NULL; cbuf *cb = NULL;
if (rsock == NULL || !rsock->rs_callhome){ if (rsock == NULL || !rsock->rs_callhome){
clicon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome"); clixon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
@ -1709,7 +1709,7 @@ restconf_callhome_timer(restconf_socket *rsock,
timeradd(&now, &t1, &t); timeradd(&now, &t1, &t);
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "restconf callhome timer %s", rsock->rs_description); cprintf(cb, "restconf callhome timer %s", rsock->rs_description);
@ -1745,7 +1745,7 @@ restconf_callhome_timer(restconf_socket *rsock,
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_socket_extract(clicon_handle h, restconf_socket_extract(clixon_handle h,
cxobj *xs, cxobj *xs,
cvec *nsc, cvec *nsc,
restconf_socket *rsock, restconf_socket *rsock,
@ -1765,18 +1765,18 @@ restconf_socket_extract(clicon_handle h,
yang_stmt *ysub = NULL; yang_stmt *ysub = NULL;
if ((x = xpath_first(xs, nsc, "namespace")) == NULL){ if ((x = xpath_first(xs, nsc, "namespace")) == NULL){
clicon_err(OE_XML, EINVAL, "Mandatory namespace not given"); clixon_err(OE_XML, EINVAL, "Mandatory namespace not given");
goto done; goto done;
} }
*namespace = xml_body(x); *namespace = xml_body(x);
if ((x = xpath_first(xs, nsc, "description")) != NULL){ if ((x = xpath_first(xs, nsc, "description")) != NULL){
if ((rsock->rs_description = strdup(xml_body(x))) == NULL){ if ((rsock->rs_description = strdup(xml_body(x))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
if ((x = xpath_first(xs, nsc, "address")) == NULL){ if ((x = xpath_first(xs, nsc, "address")) == NULL){
clicon_err(OE_XML, EINVAL, "Mandatory address not given"); clixon_err(OE_XML, EINVAL, "Mandatory address not given");
goto done; goto done;
} }
/* address is a union type and needs a special investigation to see which type (ipv4 or ipv6) /* address is a union type and needs a special investigation to see which type (ipv4 or ipv6)
@ -1785,25 +1785,25 @@ restconf_socket_extract(clicon_handle h,
body = xml_body(x); body = xml_body(x);
y = xml_spec(x); y = xml_spec(x);
if ((cv = cv_dup(yang_cv_get(y))) == NULL){ if ((cv = cv_dup(yang_cv_get(y))) == NULL){
clicon_err(OE_UNIX, errno, "cv_dup"); clixon_err(OE_UNIX, errno, "cv_dup");
goto done; goto done;
} }
if ((ret = cv_parse1(body, cv, &reason)) < 0){ if ((ret = cv_parse1(body, cv, &reason)) < 0){
clicon_err(OE_XML, errno, "cv_parse1"); clixon_err(OE_XML, errno, "cv_parse1");
goto done; goto done;
} }
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EFAULT, "%s", reason); clixon_err(OE_XML, EFAULT, "%s", reason);
goto done; goto done;
} }
if ((ret = ys_cv_validate(h, cv, y, &ysub, &reason)) < 0) if ((ret = ys_cv_validate(h, cv, y, &ysub, &reason)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EFAULT, "Validation os address: %s", reason); clixon_err(OE_XML, EFAULT, "Validation os address: %s", reason);
goto done; goto done;
} }
if (ysub == NULL){ if (ysub == NULL){
clicon_err(OE_XML, EFAULT, "No address union type"); clixon_err(OE_XML, EFAULT, "No address union type");
goto done; goto done;
} }
*address = body; *address = body;
@ -1818,11 +1818,11 @@ restconf_socket_extract(clicon_handle h,
if ((x = xpath_first(xs, nsc, "port")) != NULL && if ((x = xpath_first(xs, nsc, "port")) != NULL &&
(str = xml_body(x)) != NULL){ (str = xml_body(x)) != NULL){
if ((ret = parse_uint16(str, port, &reason)) < 0){ if ((ret = parse_uint16(str, port, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_uint16"); clixon_err(OE_XML, errno, "parse_uint16");
goto done; goto done;
} }
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str); clixon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str);
goto done; goto done;
} }
} }
@ -1834,7 +1834,7 @@ restconf_socket_extract(clicon_handle h,
else if (strcmp(str, "true") == 0) else if (strcmp(str, "true") == 0)
rsock->rs_ssl = 1; rsock->rs_ssl = 1;
else { else {
clicon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str); clixon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str);
goto done; goto done;
} }
} }
@ -1848,22 +1848,22 @@ restconf_socket_extract(clicon_handle h,
if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/period")) != NULL && if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/period")) != NULL &&
(str = xml_body(x)) != NULL){ (str = xml_body(x)) != NULL){
if ((ret = parse_uint32(str, &rsock->rs_period, &reason)) < 0){ if ((ret = parse_uint32(str, &rsock->rs_period, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_uint16"); clixon_err(OE_XML, errno, "parse_uint16");
goto done; goto done;
} }
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str); clixon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str);
goto done; goto done;
} }
} }
if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/idle-timeout")) != NULL && if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/idle-timeout")) != NULL &&
(str = xml_body(x)) != NULL){ (str = xml_body(x)) != NULL){
if ((ret = parse_uint16(str, &rsock->rs_idle_timeout, &reason)) < 0){ if ((ret = parse_uint16(str, &rsock->rs_idle_timeout, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_uint16"); clixon_err(OE_XML, errno, "parse_uint16");
goto done; goto done;
} }
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str); clixon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str);
goto done; goto done;
} }
} }
@ -1871,11 +1871,11 @@ restconf_socket_extract(clicon_handle h,
if ((x = xpath_first(xs, nsc, "call-home/reconnect-strategy/max-attempts")) != NULL && if ((x = xpath_first(xs, nsc, "call-home/reconnect-strategy/max-attempts")) != NULL &&
(str = xml_body(x)) != NULL){ (str = xml_body(x)) != NULL){
if ((ret = parse_uint8(str, &rsock->rs_max_attempts, &reason)) < 0){ if ((ret = parse_uint8(str, &rsock->rs_max_attempts, &reason)) < 0){
clicon_err(OE_XML, errno, "parse_uint8"); clixon_err(OE_XML, errno, "parse_uint8");
goto done; goto done;
} }
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str); clixon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str);
goto done; goto done;
} }
} }

View file

@ -35,7 +35,7 @@
* Data structures: * Data structures:
* 1 1 * 1 1
* +--------------------+ restconf_handle_get +--------------------+ * +--------------------+ restconf_handle_get +--------------------+
* | rn restconf_native | <--------------------- | h clicon_handle | * | rn restconf_native | <--------------------- | h clixon_handle |
* | _handle | +--------------------+ * | _handle | +--------------------+
* +--------------------+ ^ * +--------------------+ ^
* common SSL config \ | * common SSL config \ |
@ -109,7 +109,7 @@ typedef struct restconf_conn {
int rc_proto_d1; /* parsed version digit 1 */ int rc_proto_d1; /* parsed version digit 1 */
int rc_proto_d2; /* parsed version digit 2 */ int rc_proto_d2; /* parsed version digit 2 */
int rc_s; /* Connection socket */ int rc_s; /* Connection socket */
clicon_handle rc_h; /* Clixon handle */ clixon_handle rc_h; /* Clixon handle */
SSL *rc_ssl; /* Structure for SSL connection */ SSL *rc_ssl; /* Structure for SSL connection */
restconf_stream_data *rc_streams; /* List of http/2 session streams */ restconf_stream_data *rc_streams; /* List of http/2 session streams */
int rc_exit; /* Set to close socket server-side */ int rc_exit; /* Set to close socket server-side */
@ -132,7 +132,7 @@ typedef struct restconf_conn {
*/ */
typedef struct restconf_socket{ typedef struct restconf_socket{
qelem_t rs_qelem; /* List header */ qelem_t rs_qelem; /* List header */
clicon_handle rs_h; /* Clixon handle */ clixon_handle rs_h; /* Clixon handle */
char *rs_description; /* Description */ char *rs_description; /* Description */
int rs_callhome; /* 0: listen, 1: callhome */ int rs_callhome; /* 0: listen, 1: callhome */
int rs_ss; /* Listen: Server socket, ready for accept int rs_ss; /* Listen: Server socket, ready for accept
@ -174,19 +174,19 @@ typedef struct {
restconf_stream_data *restconf_stream_data_new(restconf_conn *rc, int32_t stream_id); restconf_stream_data *restconf_stream_data_new(restconf_conn *rc, int32_t stream_id);
restconf_stream_data *restconf_stream_find(restconf_conn *rc, int32_t id); restconf_stream_data *restconf_stream_find(restconf_conn *rc, int32_t id);
int restconf_stream_free(restconf_stream_data *sd); int restconf_stream_free(restconf_stream_data *sd);
restconf_conn *restconf_conn_new(clicon_handle h, int s, restconf_socket *socket); restconf_conn *restconf_conn_new(clixon_handle h, int s, restconf_socket *socket);
int ssl_x509_name_oneline(SSL *ssl, char **oneline); int ssl_x509_name_oneline(SSL *ssl, char **oneline);
int restconf_close_ssl_socket(restconf_conn *rc, const char *callfn, int sslerr0); int restconf_close_ssl_socket(restconf_conn *rc, const char *callfn, int sslerr0);
int restconf_connection_sanity(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd); int restconf_connection_sanity(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd);
restconf_native_handle *restconf_native_handle_get(clicon_handle h); restconf_native_handle *restconf_native_handle_get(clixon_handle h);
int restconf_connection(int s, void *arg); int restconf_connection(int s, void *arg);
int restconf_ssl_accept_client(clicon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp); int restconf_ssl_accept_client(clixon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp);
int restconf_idle_timer_unreg(restconf_conn *rc); int restconf_idle_timer_unreg(restconf_conn *rc);
int restconf_idle_timer(restconf_conn *rc); int restconf_idle_timer(restconf_conn *rc);
int restconf_callhome_timer_unreg(restconf_socket *rsock); int restconf_callhome_timer_unreg(restconf_socket *rsock);
int restconf_callhome_timer(restconf_socket *rsock, int status); int restconf_callhome_timer(restconf_socket *rsock, int status);
int restconf_socket_extract(clicon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock, int restconf_socket_extract(clixon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock,
char **namespace, char **address, char **addrtype, uint16_t *port); char **namespace, char **address, char **addrtype, uint16_t *port);
#endif /* _RESTCONF_NATIVE_H_ */ #endif /* _RESTCONF_NATIVE_H_ */

View file

@ -71,7 +71,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#ifdef HAVE_LIBNGHTTP2 #ifdef HAVE_LIBNGHTTP2
@ -210,12 +210,12 @@ session_send_callback(nghttp2_session *session,
continue; continue;
} }
else{ else{
clicon_err(OE_RESTCONF, er, "SSL_write %d", sslerr); clixon_err(OE_RESTCONF, er, "SSL_write %d", sslerr);
goto done; goto done;
} }
break; break;
default: default:
clicon_err(OE_SSL, 0, "SSL_write"); clixon_err(OE_SSL, 0, "SSL_write");
goto done; goto done;
break; break;
} }
@ -240,7 +240,7 @@ session_send_callback(nghttp2_session *session,
} }
#endif #endif
else{ else{
clicon_err(OE_UNIX, errno, "write"); clixon_err(OE_UNIX, errno, "write");
goto done; goto done;
} }
} }
@ -288,7 +288,7 @@ static int
restconf_nghttp2_path(restconf_stream_data *sd) restconf_nghttp2_path(restconf_stream_data *sd)
{ {
int retval = -1; int retval = -1;
clicon_handle h; clixon_handle h;
restconf_conn *rc; restconf_conn *rc;
char *oneline = NULL; char *oneline = NULL;
cvec *cvv = NULL; cvec *cvv = NULL;
@ -297,7 +297,7 @@ restconf_nghttp2_path(restconf_stream_data *sd)
clixon_debug(CLIXON_DBG_DEFAULT, "------------"); clixon_debug(CLIXON_DBG_DEFAULT, "------------");
rc = sd->sd_conn; rc = sd->sd_conn;
if ((h = rc->rc_h) == NULL){ if ((h = rc->rc_h) == NULL){
clicon_err(OE_RESTCONF, EINVAL, "arg is NULL"); clixon_err(OE_RESTCONF, EINVAL, "arg is NULL");
goto done; goto done;
} }
if (rc->rc_ssl != NULL){ if (rc->rc_ssl != NULL){
@ -428,7 +428,7 @@ restconf_submit_response(nghttp2_session *session,
data_prd.source.ptr = sd; data_prd.source.ptr = sd;
data_prd.read_callback = restconf_sd_read; data_prd.read_callback = restconf_sd_read;
if ((hdrs = (nghttp2_nv*)calloc(1+cvec_len(sd->sd_outp_hdrs), sizeof(nghttp2_nv))) == NULL){ if ((hdrs = (nghttp2_nv*)calloc(1+cvec_len(sd->sd_outp_hdrs), sizeof(nghttp2_nv))) == NULL){
clicon_err(OE_UNIX, errno, "calloc"); clixon_err(OE_UNIX, errno, "calloc");
goto done; goto done;
} }
hdr = &hdrs[i++]; hdr = &hdrs[i++];
@ -454,7 +454,7 @@ restconf_submit_response(nghttp2_session *session,
stream_id, stream_id,
hdrs, i, hdrs, i,
(data_prd.source.ptr != NULL)?&data_prd:NULL)) < 0){ (data_prd.source.ptr != NULL)?&data_prd:NULL)) < 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response"); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -682,7 +682,7 @@ on_begin_headers_callback(nghttp2_session *session,
* Both |name| and |value| are guaranteed to be NULL-terminated. * Both |name| and |value| are guaranteed to be NULL-terminated.
*/ */
static int static int
nghttp2_hdr2clixon(clicon_handle h, nghttp2_hdr2clixon(clixon_handle h,
char *name, char *name,
char *value) char *value)
{ {
@ -882,7 +882,7 @@ error_callback2(nghttp2_session *session,
{ {
// restconf_conn *rc = (restconf_conn *)user_data; // restconf_conn *rc = (restconf_conn *)user_data;
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
clicon_err(OE_NGHTTP2, lib_error_code, "%s", msg); clixon_err(OE_NGHTTP2, lib_error_code, "%s", msg);
return 0; return 0;
} }
#endif #endif
@ -907,7 +907,7 @@ http2_recv(restconf_conn *rc,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (rc->rc_ngsession == NULL){ if (rc->rc_ngsession == NULL){
/* http2_session_init not called */ /* http2_session_init not called */
clicon_err(OE_RESTCONF, EINVAL, "No nghttp2 session"); clixon_err(OE_RESTCONF, EINVAL, "No nghttp2 session");
goto done; goto done;
} }
/* may make additional pending frames */ /* may make additional pending frames */
@ -918,13 +918,13 @@ http2_recv(restconf_conn *rc,
* when |session| was configured as server and * when |session| was configured as server and
* `nghttp2_option_set_no_recv_client_magic()` is not used with * `nghttp2_option_set_no_recv_client_magic()` is not used with
* nonzero value. */ * nonzero value. */
clicon_log(LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__); clixon_log(NULL, LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__);
/* unsure if this does anything, byt does not seem to hurt */ /* unsure if this does anything, byt does not seem to hurt */
if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, ngerr)) < 0) if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, ngerr)) < 0)
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
goto fail; goto fail;
} }
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv"); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv");
goto done; goto done;
} }
/* sends highest prio frame from outbound queue to remote peer. It does this as /* sends highest prio frame from outbound queue to remote peer. It does this as
@ -932,9 +932,9 @@ http2_recv(restconf_conn *rc,
* :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty. * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty.
* @see session_send_callback() * @see session_send_callback()
*/ */
clicon_err_reset(); clixon_err_reset();
if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){ if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){
if (clicon_errno) if (clixon_err_category())
goto done; goto done;
else else
goto fail; /* Not fatal error */ goto fail; /* Not fatal error */
@ -963,11 +963,11 @@ http2_send_server_connection(restconf_conn *rc)
NGHTTP2_FLAG_NONE, NGHTTP2_FLAG_NONE,
iv, iv,
ARRLEN(iv))) != 0){ ARRLEN(iv))) != 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings"); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings");
goto done; goto done;
} }
if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){ if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send"); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -1017,7 +1017,7 @@ http2_session_init(restconf_conn *rc)
/* Create session for server use, register callbacks */ /* Create session for server use, register callbacks */
if ((ngerr = nghttp2_session_server_new3(&session, callbacks, rc, NULL, NULL)) < 0){ if ((ngerr = nghttp2_session_server_new3(&session, callbacks, rc, NULL, NULL)) < 0){
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new"); clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new");
goto done; goto done;
} }
nghttp2_session_callbacks_del(callbacks); nghttp2_session_callbacks_del(callbacks);

View file

@ -57,7 +57,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
/* restconf */ /* restconf */
@ -76,7 +76,7 @@
* @retval 1 Yes, a restconf path * @retval 1 Yes, a restconf path
*/ */
int int
api_path_is_restconf(clicon_handle h) api_path_is_restconf(clixon_handle h)
{ {
int retval = 0; int retval = 0;
char *path = NULL; char *path = NULL;
@ -108,7 +108,7 @@ api_path_is_restconf(clicon_handle h)
* enables deployments to specify where the RESTCONF API is located. * enables deployments to specify where the RESTCONF API is located.
*/ */
int int
api_well_known(clicon_handle h, api_well_known(clixon_handle h,
void *req) void *req)
{ {
int retval = -1; int retval = -1;
@ -134,7 +134,7 @@ api_well_known(clicon_handle h,
goto done; goto done;
/* Create body */ /* Create body */
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"); cprintf(cb, "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n");
@ -166,7 +166,7 @@ api_well_known(clicon_handle h,
* @see api_root_restconf for accessing /restconf/ * * @see api_root_restconf for accessing /restconf/ *
*/ */
static int static int
api_root_restconf_exact(clicon_handle h, api_root_restconf_exact(clixon_handle h,
void *req, void *req,
char *request_method, char *request_method,
int pretty, int pretty,
@ -187,7 +187,7 @@ api_root_restconf_exact(clicon_handle h,
goto ok; goto ok;
} }
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0) if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
@ -201,7 +201,7 @@ api_root_restconf_exact(clicon_handle h,
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
if (xml_rootchild(xt, 0, &xt) < 0) if (xml_rootchild(xt, 0, &xt) < 0)
@ -241,7 +241,7 @@ api_root_restconf_exact(clicon_handle h,
* @param[in] media_out Restconf output media * @param[in] media_out Restconf output media
*/ */
static int static int
api_operational_state(clicon_handle h, api_operational_state(clixon_handle h,
void *req, void *req,
char *request_method, char *request_method,
int pretty, int pretty,
@ -264,7 +264,7 @@ api_operational_state(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
api_yang_library_version(clicon_handle h, api_yang_library_version(clixon_handle h,
void *req, void *req,
int pretty, int pretty,
restconf_media media_out) restconf_media media_out)
@ -289,7 +289,7 @@ api_yang_library_version(clicon_handle h,
if (xml_bind_special(xt, yspec, "/rc:restconf/yang-library-version") < 0) if (xml_bind_special(xt, yspec, "/rc:restconf/yang-library-version") < 0)
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
switch (media_out){ switch (media_out){
@ -333,7 +333,7 @@ api_yang_library_version(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
api_data(clicon_handle h, api_data(clixon_handle h,
void *req, void *req,
char *api_path, char *api_path,
cvec *pcvec, cvec *pcvec,
@ -421,7 +421,7 @@ api_data(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
api_operations(clicon_handle h, api_operations(clixon_handle h,
void *req, void *req,
char *request_method, char *request_method,
char *path, char *path,
@ -462,7 +462,7 @@ api_operations(clicon_handle h,
* @see api_root_restconf_exact for accessing /restconf/ exact * @see api_root_restconf_exact for accessing /restconf/ exact
*/ */
int int
api_root_restconf(clicon_handle h, api_root_restconf(clixon_handle h,
void *req, void *req,
cvec *qvec) cvec *qvec)
{ {

View file

@ -52,8 +52,8 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_path_is_restconf(clicon_handle h); int api_path_is_restconf(clixon_handle h);
int api_well_known(clicon_handle h, void *req); int api_well_known(clixon_handle h, void *req);
int api_root_restconf(clicon_handle h, void *req, cvec *qvec); int api_root_restconf(clixon_handle h, void *req, cvec *qvec);
#endif /* _RESTCONF_ROOT_H_ */ #endif /* _RESTCONF_ROOT_H_ */

View file

@ -40,9 +40,9 @@
/* /*
* Prototypes * Prototypes
*/ */
int api_path_is_stream(clicon_handle h); int api_path_is_stream(clixon_handle h);
int stream_child_free(clicon_handle h, int pid); int stream_child_free(clixon_handle h, int pid);
int stream_child_freeall(clicon_handle h); int stream_child_freeall(clixon_handle h);
int api_stream(clicon_handle h, void *req, cvec *qvec, int *finish); int api_stream(clixon_handle h, void *req, cvec *qvec, int *finish);
#endif /* _RESTCONF_STREAM_H_ */ #endif /* _RESTCONF_STREAM_H_ */

View file

@ -86,7 +86,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */ #include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */
@ -124,7 +124,7 @@ static struct stream_child *STREAM_CHILD = NULL;
* @retval 0 No, not a stream path * @retval 0 No, not a stream path
*/ */
int int
api_path_is_stream(clicon_handle h) api_path_is_stream(clixon_handle h)
{ {
int retval = 0; int retval = 0;
char *path = NULL; char *path = NULL;
@ -156,7 +156,7 @@ api_path_is_stream(clicon_handle h)
* @note could hang STREAM_CHILD list on clicon handle instead. * @note could hang STREAM_CHILD list on clicon handle instead.
*/ */
int int
stream_child_free(clicon_handle h, stream_child_free(clixon_handle h,
int pid) int pid)
{ {
struct stream_child *sc; struct stream_child *sc;
@ -181,7 +181,7 @@ stream_child_free(clicon_handle h,
* Typically called on restconf exit * Typically called on restconf exit
*/ */
int int
stream_child_freeall(clicon_handle h) stream_child_freeall(clixon_handle h)
{ {
struct stream_child *sc; struct stream_child *sc;
@ -225,7 +225,7 @@ restconf_stream_cb(int s,
/* handle close from remote end: this will exit the client */ /* handle close from remote end: this will exit the client */
if (eof){ if (eof){
clixon_debug(CLIXON_DBG_DEFAULT, "%s eof", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s eof", __FUNCTION__);
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
errno = ESHUTDOWN; errno = ESHUTDOWN;
FCGX_FPrintF(r->out, "SHUTDOWN\r\n"); FCGX_FPrintF(r->out, "SHUTDOWN\r\n");
FCGX_FPrintF(r->out, "\r\n"); FCGX_FPrintF(r->out, "\r\n");
@ -236,12 +236,12 @@ restconf_stream_cb(int s,
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xtop, NULL)) < 0) /* XXX pass yang_spec */ if ((ret = clicon_msg_decode(reply, NULL, NULL, &xtop, NULL)) < 0) /* XXX pass yang_spec */
goto done; goto done;
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, EFAULT, "Invalid notification"); clixon_err(OE_XML, EFAULT, "Invalid notification");
goto done; goto done;
} }
/* create event */ /* create event */
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new"); clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done; goto done;
} }
if ((xn = xpath_first(xtop, NULL, "notification")) == NULL) if ((xn = xpath_first(xtop, NULL, "notification")) == NULL)
@ -289,7 +289,7 @@ restconf_stream_cb(int s,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
restconf_stream(clicon_handle h, restconf_stream(clixon_handle h,
void *req, void *req,
char *name, char *name,
cvec *qvec, cvec *qvec,
@ -309,7 +309,7 @@ restconf_stream(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
*sp = -1; *sp = -1;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<rpc xmlns=\"%s\" %s><create-subscription xmlns=\"%s\"><stream>%s</stream>", cprintf(cb, "<rpc xmlns=\"%s\" %s><create-subscription xmlns=\"%s\"><stream>%s</stream>",
@ -416,7 +416,7 @@ stream_timeout(int s,
* @retval -1 Error * @retval -1 Error
*/ */
int int
api_stream(clicon_handle h, api_stream(clixon_handle h,
void *req, void *req,
cvec *qvec, cvec *qvec,
int *finish) int *finish)
@ -548,7 +548,7 @@ api_stream(clicon_handle h,
* killed, call FCGX_Free * killed, call FCGX_Free
*/ */
if ((sc = malloc(sizeof(struct stream_child))) == NULL){ if ((sc = malloc(sizeof(struct stream_child))) == NULL){
clicon_err(OE_XML, errno, "malloc"); clixon_err(OE_XML, errno, "malloc");
goto done; goto done;
} }
memset(sc, 0, sizeof(struct stream_child)); memset(sc, 0, sizeof(struct stream_child));

View file

@ -53,7 +53,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "snmp_lib.h" #include "snmp_lib.h"
@ -85,16 +85,16 @@ snmp_common_handler(netsnmp_mib_handler *handler,
cbuf *cb = NULL; cbuf *cb = NULL;
if (request == NULL || shp == NULL){ if (request == NULL || shp == NULL){
clicon_err(OE_XML, EINVAL, "request or shp is null"); clixon_err(OE_XML, EINVAL, "request or shp is null");
goto done; goto done;
} }
requestvb = request->requestvb; requestvb = request->requestvb;
if ((*shp = (clixon_snmp_handle*)handler->myvoid) == NULL){ if ((*shp = (clixon_snmp_handle*)handler->myvoid) == NULL){
clicon_err(OE_XML, 0, "No myvoid handler"); clixon_err(OE_XML, 0, "No myvoid handler");
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
oid_cbuf(cb, (*shp)->sh_oid, (*shp)->sh_oidlen); oid_cbuf(cb, (*shp)->sh_oid, (*shp)->sh_oidlen);
@ -157,7 +157,7 @@ snmp_scalar_return(cxobj *xs,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto ok; goto ok;
@ -165,13 +165,13 @@ snmp_scalar_return(cxobj *xs,
} }
else if (defaultval != NULL){ else if (defaultval != NULL){
if ((xmlstr = strdup(defaultval)) == NULL){ if ((xmlstr = strdup(defaultval)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
else{ else{
if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto ok; goto ok;
@ -183,7 +183,7 @@ snmp_scalar_return(cxobj *xs,
if (ret == 0){ if (ret == 0){
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto ok; goto ok;
@ -191,11 +191,11 @@ snmp_scalar_return(cxobj *xs,
/* see snmplib/snmp_client. somewhat indirect /* see snmplib/snmp_client. somewhat indirect
*/ */
if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){ if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value"); clixon_err(OE_SNMP, ret, "snmp_set_var_typed_value");
goto done; goto done;
} }
if ((ret = snmp_set_var_objid(requestvb, oidc, oidclen)) != SNMPERR_SUCCESS){ if ((ret = snmp_set_var_objid(requestvb, oidc, oidclen)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "snmp_set_var_objid"); clixon_err(OE_SNMP, ret, "snmp_set_var_objid");
goto done; goto done;
} }
ok: ok:
@ -223,7 +223,7 @@ snmp_scalar_return(cxobj *xs,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_scalar_get(clicon_handle h, snmp_scalar_get(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
cvec *cvk, cvec *cvk,
char *defaultval, char *defaultval,
@ -263,7 +263,12 @@ snmp_scalar_get(clicon_handle h,
goto done; goto done;
/* Detect error XXX Error handling could improve */ /* Detect error XXX Error handling could improve */
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
#if 1
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
goto done;
#else
clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL); clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL);
#endif
goto done; goto done;
} }
x = xpath_first(xt, nsc, "%s", xpath); x = xpath_first(xt, nsc, "%s", xpath);
@ -278,7 +283,7 @@ snmp_scalar_get(clicon_handle h,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto ok; goto ok;
@ -286,13 +291,13 @@ snmp_scalar_get(clicon_handle h,
} }
else if (defaultval != NULL){ else if (defaultval != NULL){
if ((xmlstr = strdup(defaultval)) == NULL){ if ((xmlstr = strdup(defaultval)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
else{ else{
if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto ok; goto ok;
@ -302,7 +307,7 @@ snmp_scalar_get(clicon_handle h,
if (ret == 0){ if (ret == 0){
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto ok; goto ok;
@ -310,7 +315,7 @@ snmp_scalar_get(clicon_handle h,
/* see snmplib/snmp_client. somewhat indirect /* see snmplib/snmp_client. somewhat indirect
*/ */
if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){ if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value"); clixon_err(OE_SNMP, ret, "snmp_set_var_typed_value");
goto done; goto done;
} }
ok: ok:
@ -352,7 +357,7 @@ snmp_yang2xml(cxobj *xtop,
goto done; goto done;
/* Need to prepend an element to fit api_path_fmt2api_path cvv parameter */ /* Need to prepend an element to fit api_path_fmt2api_path cvv parameter */
if ((cvk1 = cvec_new(1)) == NULL){ if ((cvk1 = cvec_new(1)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clixon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
for (i=0; i<cvec_len(cvk); i++) for (i=0; i<cvec_len(cvk); i++)
@ -362,7 +367,7 @@ snmp_yang2xml(cxobj *xtop,
if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 1, xbot, NULL, NULL)) < 0) if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 1, xbot, NULL, NULL)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, 0, "api_path2xml %s invalid", api_path); clixon_err(OE_XML, 0, "api_path2xml %s invalid", api_path);
goto done; goto done;
} }
retval = 0; retval = 0;
@ -389,7 +394,7 @@ snmp_yang2xml(cxobj *xtop,
* @note contains special logic for rowstatus handling * @note contains special logic for rowstatus handling
*/ */
static int static int
snmp_scalar_set(clicon_handle h, snmp_scalar_set(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
cvec *cvk, cvec *cvk,
char *valstr0, char *valstr0,
@ -430,7 +435,7 @@ snmp_scalar_set(clicon_handle h,
goto done; goto done;
} }
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0)
@ -461,7 +466,7 @@ snmp_scalar_set(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_cache_row_op(clicon_handle h, snmp_cache_row_op(clixon_handle h,
yang_stmt *yp, yang_stmt *yp,
cvec *cvk, cvec *cvk,
char *opstr, char *opstr,
@ -500,7 +505,7 @@ snmp_cache_row_op(clicon_handle h,
if (xml_addsub(xbot, xrow) < 0) if (xml_addsub(xbot, xrow) < 0)
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0)
@ -537,7 +542,7 @@ snmp_cache_row_op(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_cache_set(clicon_handle h, snmp_cache_set(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
cvec *cvk, cvec *cvk,
int rowstatus, int rowstatus,
@ -558,7 +563,7 @@ snmp_cache_set(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if ((xtop = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL) if ((xtop = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
@ -583,14 +588,14 @@ snmp_cache_set(clicon_handle h,
if (strcmp(valstr, "createAndGo") == 0){ if (strcmp(valstr, "createAndGo") == 0){
free(valstr); free(valstr);
if ((valstr = strdup("active")) == NULL){ if ((valstr = strdup("active")) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
else if (strcmp(valstr, "createAndWait") == 0){ else if (strcmp(valstr, "createAndWait") == 0){
free(valstr); free(valstr);
if ((valstr = strdup("notInService")) == NULL){ if ((valstr = strdup("notInService")) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
} }
@ -646,7 +651,7 @@ snmp_cache_set(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_table_rowstatus_get(clicon_handle h, snmp_table_rowstatus_get(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
yang_stmt *yrestype, yang_stmt *yrestype,
cvec *cvk, cvec *cvk,
@ -745,7 +750,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
if (requestvb->type != asn1_type){ if (requestvb->type != asn1_type){
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok; goto ok;
} }
} }
@ -846,7 +851,7 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_table_get(clicon_handle h, snmp_table_get(clixon_handle h,
yang_stmt *yt, yang_stmt *yt,
oid *oidt, oid *oidt,
size_t oidtlen, size_t oidtlen,
@ -899,11 +904,11 @@ snmp_table_get(clicon_handle h,
* Inverse of snmp_str2oid * Inverse of snmp_str2oid
*/ */
if ((cvk_orig = yang_cvec_get(yt)) == NULL){ if ((cvk_orig = yang_cvec_get(yt)) == NULL){
clicon_err(OE_YANG, 0, "No keys"); clixon_err(OE_YANG, 0, "No keys");
goto done; goto done;
} }
if ((cvk_val = cvec_dup(cvk_orig)) == NULL){ if ((cvk_val = cvec_dup(cvk_orig)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
goto done; goto done;
} }
/* read through keys and create cvk */ /* read through keys and create cvk */
@ -913,14 +918,14 @@ snmp_table_get(clicon_handle h,
for (i=0; i<cvec_len(cvk_val); i++){ for (i=0; i<cvec_len(cvk_val); i++){
cv = cvec_i(cvk_val, i); cv = cvec_i(cvk_val, i);
if ((yk = yang_find(yt, Y_LEAF, cv_string_get(cv))) == NULL){ if ((yk = yang_find(yt, Y_LEAF, cv_string_get(cv))) == NULL){
clicon_err(OE_YANG, 0, "List key %s not found", cv_string_get(cv)); clixon_err(OE_YANG, 0, "List key %s not found", cv_string_get(cv));
goto done; goto done;
} }
if (snmp_oid2str(&oidi, &oidilen, yk, cv) < 0) if (snmp_oid2str(&oidi, &oidilen, yk, cv) < 0)
goto done; goto done;
} }
if (oidilen != 0){ if (oidilen != 0){
clicon_err(OE_YANG, 0, "Expected oidlen 0 but is %zu", oidilen); clixon_err(OE_YANG, 0, "Expected oidlen 0 but is %zu", oidilen);
goto fail; goto fail;
} }
/* Get scalar value */ /* Get scalar value */
@ -959,7 +964,7 @@ snmp_table_get(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_table_set(clicon_handle h, snmp_table_set(clixon_handle h,
yang_stmt *yt, yang_stmt *yt,
oid *oids, oid *oids,
size_t oidslen, size_t oidslen,
@ -1055,7 +1060,7 @@ snmp_table_set(clicon_handle h,
if (requestvb->type != asn1_type){ if (requestvb->type != asn1_type){
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok; goto ok;
} }
} }
@ -1063,11 +1068,11 @@ snmp_table_set(clicon_handle h,
* Inverse of snmp_str2oid * Inverse of snmp_str2oid
*/ */
if ((cvk_orig = yang_cvec_get(yt)) == NULL){ if ((cvk_orig = yang_cvec_get(yt)) == NULL){
clicon_err(OE_YANG, 0, "No keys"); clixon_err(OE_YANG, 0, "No keys");
goto done; goto done;
} }
if ((cvk_val = cvec_dup(cvk_orig)) == NULL){ if ((cvk_val = cvec_dup(cvk_orig)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
goto done; goto done;
} }
/* read through keys and create cvk */ /* read through keys and create cvk */
@ -1077,14 +1082,14 @@ snmp_table_set(clicon_handle h,
for (i=0; i<cvec_len(cvk_val); i++){ for (i=0; i<cvec_len(cvk_val); i++){
cv = cvec_i(cvk_val, i); cv = cvec_i(cvk_val, i);
if ((yk = yang_find(yt, Y_LEAF, cv_string_get(cv))) == NULL){ if ((yk = yang_find(yt, Y_LEAF, cv_string_get(cv))) == NULL){
clicon_err(OE_YANG, 0, "List key %s not found", cv_string_get(cv)); clixon_err(OE_YANG, 0, "List key %s not found", cv_string_get(cv));
goto done; goto done;
} }
if (snmp_oid2str(&oidi, &oidilen, yk, cv) < 0) if (snmp_oid2str(&oidi, &oidilen, yk, cv) < 0)
goto done; goto done;
} }
if (oidilen != 0){ if (oidilen != 0){
clicon_err(OE_YANG, 0, "Expected oidlen 0 but is %zu", oidilen); clixon_err(OE_YANG, 0, "Expected oidlen 0 but is %zu", oidilen);
*err = SNMP_NOSUCHOBJECT; *err = SNMP_NOSUCHOBJECT;
goto fail; goto fail;
} }
@ -1116,7 +1121,7 @@ snmp_table_set(clicon_handle h,
case 3: /* notReady */ case 3: /* notReady */
case 6: /* destroy */ case 6: /* destroy */
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_INCONSISTENTVALUE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_INCONSISTENTVALUE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok; goto ok;
} }
break; break;
@ -1171,7 +1176,7 @@ snmp_table_set(clicon_handle h,
* XXX: merge with cache * XXX: merge with cache
*/ */
static int static int
snmp_table_getnext(clicon_handle h, snmp_table_getnext(clixon_handle h,
yang_stmt *ylist, yang_stmt *ylist,
oid *oids, oid *oids,
size_t oidslen, size_t oidslen,
@ -1204,7 +1209,7 @@ snmp_table_getnext(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ys = yang_parent_get(ylist)) == NULL || if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){ yang_keyword_get(ys) != Y_CONTAINER){
clicon_err(OE_YANG, EINVAL, "ylist parent is not list"); clixon_err(OE_YANG, EINVAL, "ylist parent is not list");
goto done; goto done;
} }
if (xml_nsctx_yang(ys, &nsc) < 0) if (xml_nsctx_yang(ys, &nsc) < 0)
@ -1214,13 +1219,13 @@ snmp_table_getnext(clicon_handle h,
if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0)
goto done; goto done;
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) { if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) {
/* Make a clone of key-list, but replace names with values */ /* Make a clone of key-list, but replace names with values */
if ((cvk_name = yang_cvec_get(ylist)) == NULL){ if ((cvk_name = yang_cvec_get(ylist)) == NULL){
clicon_err(OE_YANG, 0, "No keys"); clixon_err(OE_YANG, 0, "No keys");
goto done; goto done;
} }
xrow = NULL; xrow = NULL;
@ -1259,7 +1264,7 @@ snmp_table_getnext(clicon_handle h,
if (snmp_scalar_return(xnext, ynext, oidnext, oidnextlen, reqinfo, request) < 0) if (snmp_scalar_return(xnext, ynext, oidnext, oidnextlen, reqinfo, request) < 0)
goto done; goto done;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
oid_cbuf(cb, oidnext, oidnextlen); oid_cbuf(cb, oidnext, oidnextlen);
@ -1321,7 +1326,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s Nosuchinstance", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s Nosuchinstance", __FUNCTION__);
@ -1336,7 +1341,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s No such object", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s No such object", __FUNCTION__);
@ -1358,7 +1363,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, err)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, err)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
clixon_debug(CLIXON_DBG_DEFAULT, "%s Nosuchinstance", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s Nosuchinstance", __FUNCTION__);

View file

@ -71,7 +71,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "snmp_lib.h" #include "snmp_lib.h"
@ -277,7 +277,7 @@ oid_append(const oid *objid0,
dst = (void*)objid0; dst = (void*)objid0;
dst += (*objid0len)*sizeof(*objid0); dst += (*objid0len)*sizeof(*objid0);
if (memcpy(dst, objid1, objid1len*sizeof(*objid0)) < 0){ if (memcpy(dst, objid1, objid1len*sizeof(*objid0)) < 0){
clicon_err(OE_UNIX, errno, "memcpy"); clixon_err(OE_UNIX, errno, "memcpy");
return -1; return -1;
} }
*objid0len += objid1len; *objid0len += objid1len;
@ -309,7 +309,7 @@ oid_print(FILE *f,
cbuf *cb; cbuf *cb;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
oid_cbuf(cb, objid, objidlen); oid_cbuf(cb, objid, objidlen);
@ -351,13 +351,13 @@ snmp_yang_type_get(yang_stmt *ys,
restype2 = restype; restype2 = restype;
if (strcmp(restype2, "leafref")==0){ if (strcmp(restype2, "leafref")==0){
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){ if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
clicon_err(OE_YANG, 0, "No path in leafref"); clixon_err(OE_YANG, 0, "No path in leafref");
goto done; goto done;
} }
if (yang_path_arg(ys, yang_argument_get(ypath), &yref) < 0) if (yang_path_arg(ys, yang_argument_get(ypath), &yref) < 0)
goto done; goto done;
if (yref == NULL){ if (yref == NULL){
clicon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", yang_argument_get(ypath)); clixon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", yang_argument_get(ypath));
goto done; goto done;
} }
if (origtype){ if (origtype){
@ -414,7 +414,7 @@ yang_extension_value_opt(yang_stmt *ys,
cg_var *cv; cg_var *cv;
if (ys == NULL){ if (ys == NULL){
clicon_err(OE_YANG, EINVAL, "ys is NULL"); clixon_err(OE_YANG, EINVAL, "ys is NULL");
goto done; goto done;
} }
if (exist) if (exist)
@ -474,7 +474,7 @@ yangext_oid_get(yang_stmt *yn,
goto fail; goto fail;
} }
if (snmp_parse_oid(oidstr, objid, objidlen) == NULL){ if (snmp_parse_oid(oidstr, objid, objidlen) == NULL){
clicon_err(OE_XML, errno, "snmp_parse_oid"); clixon_err(OE_XML, errno, "snmp_parse_oid");
goto done; goto done;
} }
if (objidstrp) if (objidstrp)
@ -525,13 +525,13 @@ snmp_handle_clone(void *arg)
if (sh0 == NULL) if (sh0 == NULL)
return NULL; return NULL;
if ((sh1 = malloc(sizeof(*sh1))) == NULL){ if ((sh1 = malloc(sizeof(*sh1))) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
return NULL; return NULL;
} }
memset(sh1, 0, sizeof(*sh1)); memset(sh1, 0, sizeof(*sh1));
if (sh0->sh_cvk_orig && if (sh0->sh_cvk_orig &&
(sh1->sh_cvk_orig = cvec_dup(sh0->sh_cvk_orig)) == NULL){ (sh1->sh_cvk_orig = cvec_dup(sh0->sh_cvk_orig)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
return NULL; return NULL;
} }
return (void*)sh1; return (void*)sh1;
@ -594,7 +594,7 @@ type_yang2asn1(yang_stmt *ys,
} }
/* Then try fully resolved type */ /* Then try fully resolved type */
else if ((at = clicon_str2int(snmp_type_map, restype)) < 0){ else if ((at = clicon_str2int(snmp_type_map, restype)) < 0){
clicon_err(OE_YANG, 0, "No snmp translation for YANG %s type:%s", clixon_err(OE_YANG, 0, "No snmp translation for YANG %s type:%s",
yang_argument_get(ys), restype); yang_argument_get(ys), restype);
goto done; goto done;
} }
@ -651,11 +651,11 @@ type_snmp2xml(yang_stmt *ys,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (valstr == NULL){ if (valstr == NULL){
clicon_err(OE_UNIX, EINVAL, "valstr is NULL"); clixon_err(OE_UNIX, EINVAL, "valstr is NULL");
goto done; goto done;
} }
if ((cvstr = (char*)clicon_int2str(snmp_type_map, requestvb->type)) == NULL){ if ((cvstr = (char*)clicon_int2str(snmp_type_map, requestvb->type)) == NULL){
clicon_err(OE_XML, 0, "No mapping for snmp type %d", requestvb->type); clixon_err(OE_XML, 0, "No mapping for snmp type %d", requestvb->type);
goto done; goto done;
} }
/* Get yang type of leaf and trasnslate to ASN.1 */ /* Get yang type of leaf and trasnslate to ASN.1 */
@ -668,7 +668,7 @@ type_snmp2xml(yang_stmt *ys,
cvstr = "string"; cvstr = "string";
cvtype = cv_str2type(cvstr); cvtype = cv_str2type(cvstr);
if ((cv = cv_new(cvtype)) == NULL){ if ((cv = cv_new(cvtype)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new"); clixon_err(OE_UNIX, errno, "cv_new");
goto done; goto done;
} }
switch (*asn1type){ switch (*asn1type){
@ -683,7 +683,7 @@ type_snmp2xml(yang_stmt *ys,
if (strcmp(restype, "enumeration") == 0){ if (strcmp(restype, "enumeration") == 0){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "%ld", *requestvb->val.integer); cprintf(cb, "%ld", *requestvb->val.integer);
@ -735,14 +735,14 @@ type_snmp2xml(yang_stmt *ys,
assert(0); // XXX assert(0); // XXX
clixon_debug(CLIXON_DBG_DEFAULT, "%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){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done; goto done;
} }
goto fail; goto fail;
break; break;
} }
if ((*valstr = cv2str_dup(cv)) == NULL){ if ((*valstr = cv2str_dup(cv)) == NULL){
clicon_err(OE_UNIX, errno, "cv2str_dup"); clixon_err(OE_UNIX, errno, "cv2str_dup");
goto done; goto done;
} }
retval = 1; retval = 1;
@ -784,7 +784,7 @@ type_xml2snmp_pre(char *xmlstr0,
cbuf *cb = NULL; cbuf *cb = NULL;
if (xmlstr0 == NULL || xmlstr1 == NULL){ if (xmlstr0 == NULL || xmlstr1 == NULL){
clicon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL"); clixon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL");
goto done; goto done;
} }
/* Get yang type of leaf and trasnslate to ASN.1 */ /* Get yang type of leaf and trasnslate to ASN.1 */
@ -814,7 +814,7 @@ type_xml2snmp_pre(char *xmlstr0,
int64_t num; int64_t num;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((ret = parse_dec64(xmlstr0, cv_dec64_n_get(cv), &num, NULL)) < 0) if ((ret = parse_dec64(xmlstr0, cv_dec64_n_get(cv), &num, NULL)) < 0)
@ -831,7 +831,7 @@ type_xml2snmp_pre(char *xmlstr0,
str = xmlstr0; str = xmlstr0;
} }
if ((*xmlstr1 = strdup(str)) == NULL){ if ((*xmlstr1 = strdup(str)) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
retval = 1; retval = 1;
@ -869,7 +869,7 @@ type_xml2snmp(char *snmpstr,
int ret; int ret;
if (snmpval == NULL || snmplen == NULL){ if (snmpval == NULL || snmplen == NULL){
clicon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL"); clixon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL");
goto done; goto done;
} }
switch (*asn1type){ switch (*asn1type){
@ -879,7 +879,7 @@ type_xml2snmp(char *snmpstr,
case ASN_INTEGER: // 2 case ASN_INTEGER: // 2
*snmplen = 4; *snmplen = 4;
if ((*snmpval = malloc(*snmplen)) == NULL){ if ((*snmpval = malloc(*snmplen)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
if ((ret = parse_int32(snmpstr, (int32_t*)*snmpval, reason)) < 0) if ((ret = parse_int32(snmpstr, (int32_t*)*snmpval, reason)) < 0)
@ -892,7 +892,7 @@ type_xml2snmp(char *snmpstr,
case ASN_GAUGE: // 0x42 case ASN_GAUGE: // 0x42
*snmplen = 4; *snmplen = 4;
if ((*snmpval = malloc(*snmplen)) == NULL){ if ((*snmpval = malloc(*snmplen)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
if ((ret = parse_uint32(snmpstr, (uint32_t*)*snmpval, reason)) < 0) if ((ret = parse_uint32(snmpstr, (uint32_t*)*snmpval, reason)) < 0)
@ -910,7 +910,7 @@ type_xml2snmp(char *snmpstr,
} }
*snmplen = sizeof(oid)*sz1; *snmplen = sizeof(oid)*sz1;
if ((*snmpval = malloc(*snmplen)) == NULL){ if ((*snmpval = malloc(*snmplen)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memcpy(*snmpval, oid1, *snmplen); memcpy(*snmpval, oid1, *snmplen);
@ -919,7 +919,7 @@ type_xml2snmp(char *snmpstr,
case ASN_OCTET_STR: // 4 case ASN_OCTET_STR: // 4
*snmplen = strlen(snmpstr)+1; *snmplen = strlen(snmpstr)+1;
if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){ if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
break; break;
@ -928,7 +928,7 @@ type_xml2snmp(char *snmpstr,
struct counter64 *c64; struct counter64 *c64;
*snmplen = sizeof(struct counter64); // 16! *snmplen = sizeof(struct counter64); // 16!
if ((*snmpval = malloc(*snmplen)) == NULL){ if ((*snmpval = malloc(*snmplen)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(*snmpval, 0, *snmplen); memset(*snmpval, 0, *snmplen);
@ -945,7 +945,7 @@ type_xml2snmp(char *snmpstr,
in_addr_t saddr; in_addr_t saddr;
*snmplen = 4; *snmplen = 4;
if ((*snmpval = malloc(*snmplen)) == NULL){ if ((*snmpval = malloc(*snmplen)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
saddr = (int32_t)inet_addr(snmpstr); saddr = (int32_t)inet_addr(snmpstr);
@ -956,7 +956,7 @@ type_xml2snmp(char *snmpstr,
struct ether_addr *eaddr; struct ether_addr *eaddr;
*snmplen = sizeof(*eaddr); *snmplen = sizeof(*eaddr);
if ((*snmpval = malloc(*snmplen + 1)) == NULL){ if ((*snmpval = malloc(*snmplen + 1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(*snmpval, 0, *snmplen + 1); memset(*snmpval, 0, *snmplen + 1);
@ -971,7 +971,7 @@ type_xml2snmp(char *snmpstr,
case CLIXON_ASN_FIXED_STRING: /* OCTET-STRING with decrement length */ case CLIXON_ASN_FIXED_STRING: /* OCTET-STRING with decrement length */
*snmplen = strlen(snmpstr); *snmplen = strlen(snmpstr);
if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){ if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
*asn1type = ASN_OCTET_STR; *asn1type = ASN_OCTET_STR;
@ -1010,7 +1010,7 @@ snmp_yang2xpath_cb(yang_stmt *ys,
char *prefix = NULL; char *prefix = NULL;
if ((yp = yang_parent_get(ys)) == NULL){ if ((yp = yang_parent_get(ys)) == NULL){
clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys)); clixon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
goto done; goto done;
} }
if (yp != NULL && /* XXX rm */ if (yp != NULL && /* XXX rm */
@ -1075,13 +1075,13 @@ snmp_yang2xpath(yang_stmt *ys,
cbuf *cb = NULL; cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if (snmp_yang2xpath_cb(ys, keyvec, cb) < 0) if (snmp_yang2xpath_cb(ys, keyvec, cb) < 0)
goto done; goto done;
if (xpath && (*xpath = strdup(cbuf_get(cb))) == NULL){ if (xpath && (*xpath = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_UNIX, errno, "strdup"); clixon_err(OE_UNIX, errno, "strdup");
goto done; goto done;
} }
retval = 0; retval = 0;
@ -1167,7 +1167,7 @@ snmp_oid2str(oid **oidi,
if (type_yang2asn1(yk, &asn1_type, 1) < 0) if (type_yang2asn1(yk, &asn1_type, 1) < 0)
goto done; goto done;
if ((enc = cbuf_new()) == NULL){ if ((enc = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
switch (asn1_type){ switch (asn1_type){
@ -1196,7 +1196,7 @@ snmp_oid2str(oid **oidi,
} }
if (cbuf_len(enc)){ if (cbuf_len(enc)){
if (cv_string_set(cv, cbuf_get(enc)) < 0){ if (cv_string_set(cv, cbuf_get(enc)) < 0){
clicon_err(OE_UNIX, errno, "cv_string_set"); clixon_err(OE_UNIX, errno, "cv_string_set");
goto done; goto done;
} }
} }
@ -1296,12 +1296,12 @@ snmp_xmlkey2val_oid(cxobj *xentry,
if (*cvk_val){ if (*cvk_val){
cvec_free(*cvk_val); cvec_free(*cvk_val);
if ((*cvk_val = cvec_dup(cvk_name)) == NULL){ if ((*cvk_val = cvec_dup(cvk_name)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
goto done; goto done;
} }
} }
else if ((*cvk_val = cvec_dup(cvk_name)) == NULL){ else if ((*cvk_val = cvec_dup(cvk_name)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
goto done; goto done;
} }
} }
@ -1312,7 +1312,7 @@ snmp_xmlkey2val_oid(cxobj *xentry,
if (cvk_val){ if (cvk_val){
cv = cvec_i(*cvk_val, i); cv = cvec_i(*cvk_val, i);
if (cv_string_set(cv, xml_body(xi)) < 0){ if (cv_string_set(cv, xml_body(xi)) < 0){
clicon_err(OE_UNIX, errno, "cv_string_set"); clixon_err(OE_UNIX, errno, "cv_string_set");
goto done; goto done;
} }
} }

View file

@ -65,7 +65,7 @@ extern "C" {
/* Userdata to pass around in netsmp callbacks /* Userdata to pass around in netsmp callbacks
*/ */
struct clixon_snmp_handle { struct clixon_snmp_handle {
clicon_handle sh_h; clixon_handle sh_h;
yang_stmt *sh_ys; /* Leaf for scalar, list for table */ yang_stmt *sh_ys; /* Leaf for scalar, list for table */
oid sh_oid[MAX_OID_LEN]; /* OID of registered table (list) */ oid sh_oid[MAX_OID_LEN]; /* OID of registered table (list) */
size_t sh_oidlen; size_t sh_oidlen;

View file

@ -63,7 +63,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "snmp_lib.h" #include "snmp_lib.h"
@ -78,7 +78,7 @@ static int clixon_snmp_input_cb(int s, void *arg);
/*! Return (hardcoded) pid file /*! Return (hardcoded) pid file
*/ */
static char* static char*
clicon_snmp_pidfile(clicon_handle h) clicon_snmp_pidfile(clixon_handle h)
{ {
return "/var/tmp/clixon_snmp.pid"; return "/var/tmp/clixon_snmp.pid";
} }
@ -90,7 +90,7 @@ clicon_snmp_pidfile(clicon_handle h)
static void static void
clixon_snmp_sig_term(int arg) clixon_snmp_sig_term(int arg)
{ {
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
__PROGRAM__, __FUNCTION__, getpid(), arg); __PROGRAM__, __FUNCTION__, getpid(), arg);
/* This should ensure no more accepts or incoming packets are processed because next time eventloop /* This should ensure no more accepts or incoming packets are processed because next time eventloop
* is entered, it will terminate. * is entered, it will terminate.
@ -105,7 +105,7 @@ clixon_snmp_sig_term(int arg)
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
static int static int
snmp_terminate(clicon_handle h) snmp_terminate(clixon_handle h)
{ {
yang_stmt *yspec; yang_stmt *yspec;
cvec *nsctx; cvec *nsctx;
@ -130,9 +130,9 @@ snmp_terminate(clicon_handle h)
xml_free(x); xml_free(x);
xpath_optimize_exit(); xpath_optimize_exit();
clixon_event_exit(); clixon_event_exit();
clicon_handle_exit(h); clixon_handle_exit(h);
clixon_err_exit(); clixon_err_exit();
clicon_log_exit(); clixon_log_exit();
if (pidfile) if (pidfile)
unlink(pidfile); unlink(pidfile);
return 0; return 0;
@ -151,7 +151,7 @@ snmp_terminate(clicon_handle h)
* @see clixon_snmp_input_cb * @see clixon_snmp_input_cb
*/ */
static int static int
clixon_snmp_fdset_register(clicon_handle h, clixon_snmp_fdset_register(clixon_handle h,
int regfd) int regfd)
{ {
int retval = -1; int retval = -1;
@ -164,7 +164,7 @@ clixon_snmp_fdset_register(clicon_handle h,
FD_ZERO(&readfds); FD_ZERO(&readfds);
if ((nr = snmp_sess_select_info(NULL, &numfds, &readfds, &timeout, &block)) < 0){ if ((nr = snmp_sess_select_info(NULL, &numfds, &readfds, &timeout, &block)) < 0){
clicon_err(OE_XML, errno, "snmp_select_error"); clixon_err(OE_XML, errno, "snmp_select_error");
goto done; goto done;
} }
/* eg 4, 6, 8 */ /* eg 4, 6, 8 */
@ -202,7 +202,7 @@ clixon_snmp_input_cb(int s,
{ {
int retval = -1; int retval = -1;
fd_set readfds; fd_set readfds;
clicon_handle h = (clicon_handle)arg; clixon_handle h = (clixon_handle)arg;
int ret; int ret;
clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, s); clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, s);
@ -211,7 +211,7 @@ clixon_snmp_input_cb(int s,
(void)snmp_read(&readfds); (void)snmp_read(&readfds);
if (clixon_event_poll(s) < 0){ if (clixon_event_poll(s) < 0){
if (errno == EBADF){ if (errno == EBADF){
clicon_err_reset(); clixon_err_reset();
/* Close the active socket */ /* Close the active socket */
if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0) if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0)
goto done; goto done;
@ -220,7 +220,7 @@ clixon_snmp_input_cb(int s,
if (clixon_snmp_fdset_register(h, 0) < 0) if (clixon_snmp_fdset_register(h, 0) < 0)
goto done; goto done;
if ((ret = snmp_close_sessions()) != 1){ if ((ret = snmp_close_sessions()) != 1){
clicon_err(OE_SNMP, ret, "snmp_close_sessions"); clixon_err(OE_SNMP, ret, "snmp_close_sessions");
goto done; goto done;
} }
/* Signal normal exit to upper layers (=event handling) /* Signal normal exit to upper layers (=event handling)
@ -229,7 +229,7 @@ clixon_snmp_input_cb(int s,
clixon_exit_set(1); clixon_exit_set(1);
} }
else { else {
clicon_err(OE_UNIX, errno, "poll"); clixon_err(OE_UNIX, errno, "poll");
goto done; goto done;
} }
} }
@ -247,14 +247,14 @@ clixon_snmp_input_cb(int s,
* @see snmp_terminate * @see snmp_terminate
*/ */
static int static int
clixon_snmp_init_subagent(clicon_handle h, clixon_snmp_init_subagent(clixon_handle h,
int logdst) int logdst)
{ {
int retval = -1; int retval = -1;
char *sockpath = NULL; char *sockpath = NULL;
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (logdst == CLICON_LOG_SYSLOG) if (logdst == CLIXON_LOG_SYSLOG)
snmp_enable_calllog(); snmp_enable_calllog();
else else
snmp_enable_stderrlog(); snmp_enable_stderrlog();
@ -271,7 +271,7 @@ clixon_snmp_init_subagent(clicon_handle h,
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1); netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1);
if ((sockpath = clicon_option_str(h, "CLICON_SNMP_AGENT_SOCK")) == NULL){ if ((sockpath = clicon_option_str(h, "CLICON_SNMP_AGENT_SOCK")) == NULL){
clicon_err(OE_XML, 0, "CLICON_SNMP_AGENT_SOCK not set"); clixon_err(OE_XML, 0, "CLICON_SNMP_AGENT_SOCK not set");
goto done; goto done;
} }
/* XXX: This should be configurable. */ /* XXX: This should be configurable. */
@ -284,19 +284,19 @@ clixon_snmp_init_subagent(clicon_handle h,
init_snmp(__PROGRAM__); init_snmp(__PROGRAM__);
if (!clixon_snmp_api_agent_check()){ if (!clixon_snmp_api_agent_check()){
clicon_err(OE_DAEMON, 0, "Connection to SNMP agent failed"); clixon_err(OE_DAEMON, 0, "Connection to SNMP agent failed");
goto done; goto done;
} }
if (set_signal(SIGTERM, clixon_snmp_sig_term, NULL) < 0){ if (set_signal(SIGTERM, clixon_snmp_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGINT, clixon_snmp_sig_term, NULL) < 0){ if (set_signal(SIGINT, clixon_snmp_sig_term, NULL) < 0){
clicon_err(OE_DAEMON, errno, "Setting signal"); clixon_err(OE_DAEMON, errno, "Setting signal");
goto done; goto done;
} }
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting SIGPIPE signal"); clixon_err(OE_UNIX, errno, "Setting SIGPIPE signal");
goto done; goto done;
} }
/* Workaround for netsnmps API use of fdset:s instead of sockets */ /* Workaround for netsnmps API use of fdset:s instead of sockets */
@ -313,7 +313,7 @@ clixon_snmp_init_subagent(clicon_handle h,
* @param[in] argv0 command line * @param[in] argv0 command line
*/ */
static void static void
usage(clicon_handle h, usage(clixon_handle h,
char *argv0) char *argv0)
{ {
fprintf(stderr, "usage:%s\n" fprintf(stderr, "usage:%s\n"
@ -338,8 +338,8 @@ main(int argc,
int retval = -1; int retval = -1;
int c; int c;
char *argv0 = argv[0]; char *argv0 = argv[0];
clicon_handle h; clixon_handle h;
int logdst = CLICON_LOG_STDERR; int logdst = CLIXON_LOG_STDERR;
struct passwd *pw; struct passwd *pw;
yang_stmt *yspec = NULL; yang_stmt *yspec = NULL;
char *str; char *str;
@ -357,14 +357,17 @@ main(int argc,
enum format_enum config_dump_format = FORMAT_XML; enum format_enum config_dump_format = FORMAT_XML;
/* Create handle */ /* Create handle */
if ((h = clicon_handle_init()) == NULL) if ((h = clixon_handle_init()) == NULL)
return -1; return -1;
/* In the startup, logs to stderr & debug flag set later */ /* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst); if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
goto done;
if (clixon_err_init(h) < 0)
goto done;
/* Set username to clixon handle. Use in all communication to backend */ /* Set username to clixon handle. Use in all communication to backend */
if ((pw = getpwuid(getuid())) == NULL){ if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid"); clixon_err(OE_UNIX, errno, "getpwuid");
goto done; goto done;
} }
if (clicon_username_set(h, pw->pw_name) < 0) if (clicon_username_set(h, pw->pw_name) < 0)
@ -387,12 +390,12 @@ main(int argc,
usage(h, argv[0]); usage(h, argv[0]);
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg); clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
break; break;
case 'l': /* Log destination: s|e|o */ case 'l': /* Log destination: s|e|o */
if ((logdst = clicon_log_opt(optarg[0])) < 0) if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]); usage(h, argv[0]);
if (logdst == CLICON_LOG_FILE && if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 && strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0) clixon_log_file(optarg+1) < 0)
goto done; goto done;
break; break;
} }
@ -400,8 +403,8 @@ main(int argc,
/* /*
* Logs, error and debug to stderr or syslog, set debug level * Logs, error and debug to stderr or syslog, set debug level
*/ */
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(dbg, NULL); clixon_debug_init(h, dbg);
/* This is netsnmplib debugging which is quite extensive + only if compiled w debug */ /* This is netsnmplib debugging which is quite extensive + only if compiled w debug */
if (dbg > 1) if (dbg > 1)
snmp_set_do_debugging(1); snmp_set_do_debugging(1);
@ -458,7 +461,7 @@ main(int argc,
/* Check pid-file, if zap kill the old daemon, else return here */ /* Check pid-file, if zap kill the old daemon, else return here */
if ((pidfile = clicon_snmp_pidfile(h)) == NULL){ if ((pidfile = clicon_snmp_pidfile(h)) == NULL){
clicon_err(OE_FATAL, 0, "pidfile not set"); clixon_err(OE_FATAL, 0, "pidfile not set");
goto done; goto done;
} }
if (pidfile_get(pidfile, &pid) < 0) if (pidfile_get(pidfile, &pid) < 0)
@ -472,7 +475,7 @@ main(int argc,
exit(0); /* OK */ exit(0); /* OK */
} }
else if (pid){ else if (pid){
clicon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)", clixon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)",
pid, argv0); pid, argv0);
return -1; /* goto done deletes pidfile */ return -1; /* goto done deletes pidfile */
} }
@ -485,8 +488,8 @@ main(int argc,
cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD"); cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD");
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) if ((sz = clicon_option_int(h, "CLIXON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(sz); clixon_log_string_limit_set(sz);
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h); xml_nsctx_namespace_netconf_default(h);
@ -570,7 +573,7 @@ main(int argc,
retval = 0; retval = 0;
done: done:
snmp_terminate(h); snmp_terminate(h);
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
return retval; return retval;
} }

View file

@ -72,7 +72,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include "snmp_lib.h" #include "snmp_lib.h"
@ -95,7 +95,7 @@
* netsnmp_subtree_find(oid1,sz1, 0, 0) * netsnmp_subtree_find(oid1,sz1, 0, 0)
*/ */
static int static int
mibyang_leaf_register(clicon_handle h, mibyang_leaf_register(clixon_handle h,
yang_stmt *ys, yang_stmt *ys,
cvec *cvk_val, cvec *cvk_val,
oid *oidk, oid *oidk,
@ -115,7 +115,7 @@ mibyang_leaf_register(clicon_handle h,
cbuf *cboid = NULL; cbuf *cboid = NULL;
if ((cboid = cbuf_new()) == NULL){ if ((cboid = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
if ((ret = yangext_oid_get(ys, oid1, &oid1len, NULL)) < 0) if ((ret = yangext_oid_get(ys, oid1, &oid1len, NULL)) < 0)
@ -146,7 +146,7 @@ mibyang_leaf_register(clicon_handle h,
name = yang_argument_get(ys); name = yang_argument_get(ys);
/* Stateless function, just returns ptr */ /* Stateless function, just returns ptr */
if ((handler = netsnmp_create_handler(name, clixon_snmp_scalar_handler)) == NULL){ if ((handler = netsnmp_create_handler(name, clixon_snmp_scalar_handler)) == NULL){
clicon_err(OE_XML, errno, "netsnmp_create_handler"); clixon_err(OE_XML, errno, "netsnmp_create_handler");
goto done; goto done;
} }
@ -154,7 +154,7 @@ mibyang_leaf_register(clicon_handle h,
* XXX: not deallocated * XXX: not deallocated
*/ */
if ((sh = malloc(sizeof(*sh))) == NULL){ if ((sh = malloc(sizeof(*sh))) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(sh, 0, sizeof(*sh)); memset(sh, 0, sizeof(*sh));
@ -165,14 +165,14 @@ mibyang_leaf_register(clicon_handle h,
sh->sh_default = default_str; sh->sh_default = default_str;
if (cvk_val && if (cvk_val &&
(sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){ (sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_dup"); clixon_err(OE_UNIX, errno, "cvec_dup");
goto done; goto done;
} }
/* Stateless function, just returns ptr */ /* Stateless function, just returns ptr */
if ((nhreg = netsnmp_handler_registration_create(name, handler, if ((nhreg = netsnmp_handler_registration_create(name, handler,
oid1, oid1len, oid1, oid1len,
modes)) == NULL){ modes)) == NULL){
clicon_err(OE_XML, errno, "netsnmp_handler_registration_create"); clixon_err(OE_XML, errno, "netsnmp_handler_registration_create");
netsnmp_handler_free(handler); netsnmp_handler_free(handler);
goto done; goto done;
} }
@ -186,7 +186,7 @@ mibyang_leaf_register(clicon_handle h,
*/ */
if ((ret = netsnmp_register_instance(nhreg)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_register_instance(nhreg)) != SNMPERR_SUCCESS){
/* Note MIB_ errors, not regular SNMPERR_ */ /* Note MIB_ errors, not regular SNMPERR_ */
clicon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance"); clixon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance");
goto done; goto done;
} }
oid_cbuf(cboid, oid1, oid1len); oid_cbuf(cboid, oid1, oid1len);
@ -216,7 +216,7 @@ mibyang_leaf_register(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
mibyang_table_register(clicon_handle h, mibyang_table_register(clixon_handle h,
yang_stmt *ylist, yang_stmt *ylist,
oid *oid1, oid *oid1,
size_t oid1len, size_t oid1len,
@ -240,7 +240,7 @@ mibyang_table_register(clicon_handle h,
if ((ys = yang_parent_get(ylist)) == NULL || if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){ yang_keyword_get(ys) != Y_CONTAINER){
clicon_err(OE_YANG, EINVAL, "ylist parent is not list"); clixon_err(OE_YANG, EINVAL, "ylist parent is not list");
goto done; goto done;
} }
/* Note: This is wrong for augmented nodes where name is the original list, not the /* Note: This is wrong for augmented nodes where name is the original list, not the
@ -253,7 +253,7 @@ mibyang_table_register(clicon_handle h,
* XXX: not deallocated * XXX: not deallocated
*/ */
if ((sh = malloc(sizeof(*sh))) == NULL){ if ((sh = malloc(sizeof(*sh))) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(sh, 0, sizeof(*sh)); memset(sh, 0, sizeof(*sh));
@ -265,13 +265,13 @@ mibyang_table_register(clicon_handle h,
sh->sh_oid2len = oid2len; sh->sh_oid2len = oid2len;
if ((handler = netsnmp_create_handler(name, clixon_snmp_table_handler)) == NULL){ if ((handler = netsnmp_create_handler(name, clixon_snmp_table_handler)) == NULL){
clicon_err(OE_XML, errno, "netsnmp_create_handler"); clixon_err(OE_XML, errno, "netsnmp_create_handler");
goto done; goto done;
} }
if ((nhreg = netsnmp_handler_registration_create(name, handler, if ((nhreg = netsnmp_handler_registration_create(name, handler,
oid1, oid1len, oid1, oid1len,
HANDLER_CAN_RWRITE)) == NULL){ HANDLER_CAN_RWRITE)) == NULL){
clicon_err(OE_XML, errno, "netsnmp_handler_registration_create"); clixon_err(OE_XML, errno, "netsnmp_handler_registration_create");
netsnmp_handler_free(handler); netsnmp_handler_free(handler);
goto done; goto done;
} }
@ -282,12 +282,12 @@ mibyang_table_register(clicon_handle h,
/* See netsnmp_register_table_data_set */ /* See netsnmp_register_table_data_set */
if ((table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL){ if ((table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL){
clicon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF"); clixon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF");
goto done; goto done;
} }
/* Keys, go through keys */ /* Keys, go through keys */
if ((cvk = yang_cvec_get(ylist)) == NULL){ if ((cvk = yang_cvec_get(ylist)) == NULL){
clicon_err(OE_YANG, 0, "No keys"); clixon_err(OE_YANG, 0, "No keys");
goto done; goto done;
} }
cvi = NULL; cvi = NULL;
@ -295,7 +295,7 @@ mibyang_table_register(clicon_handle h,
while ((cvi = cvec_each(cvk, cvi)) != NULL) { while ((cvi = cvec_each(cvk, cvi)) != NULL) {
keyname = cv_string_get(cvi); keyname = cv_string_get(cvi);
if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){ if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){
clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", clixon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
yang_argument_get(ylist), keyname); yang_argument_get(ylist), keyname);
goto done; goto done;
} }
@ -308,7 +308,7 @@ mibyang_table_register(clicon_handle h,
asn1type, asn1type,
NULL, // value NULL, // value
0) == NULL){ 0) == NULL){
clicon_err(OE_XML, errno, "snmp_varlist_add_variable"); clixon_err(OE_XML, errno, "snmp_varlist_add_variable");
goto done; goto done;
} }
} }
@ -323,7 +323,7 @@ mibyang_table_register(clicon_handle h,
table_info->max_column++; table_info->max_column++;
} }
if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){
clicon_err(OE_SNMP, ret, "netsnmp_register_table"); clixon_err(OE_SNMP, ret, "netsnmp_register_table");
goto done; goto done;
} }
sh->sh_table_info = table_info; /* Keep to free at exit */ sh->sh_table_info = table_info; /* Keep to free at exit */
@ -350,7 +350,7 @@ mibyang_table_register(clicon_handle h,
* @see mibyang_augment_register * @see mibyang_augment_register
*/ */
static int static int
mibyang_list_register(clicon_handle h, mibyang_list_register(clixon_handle h,
yang_stmt *ylist) yang_stmt *ylist)
{ {
int retval = -1; int retval = -1;
@ -364,7 +364,7 @@ mibyang_list_register(clicon_handle h,
if ((yc = yang_parent_get(ylist)) == NULL || if ((yc = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(yc) != Y_CONTAINER){ yang_keyword_get(yc) != Y_CONTAINER){
clicon_err(OE_YANG, EINVAL, "ylist parent is not container"); clixon_err(OE_YANG, EINVAL, "ylist parent is not container");
goto done; goto done;
} }
if ((ret = yangext_oid_get(ylist, oid2, &oid2len, NULL)) < 0) if ((ret = yangext_oid_get(ylist, oid2, &oid2len, NULL)) < 0)
@ -405,7 +405,7 @@ mibyang_list_register(clicon_handle h,
* @see mibyang_list_register * @see mibyang_list_register
*/ */
static int static int
mibyang_augment_register(clicon_handle h, mibyang_augment_register(clixon_handle h,
yang_stmt *yaug) yang_stmt *yaug)
{ {
int retval = -1; int retval = -1;
@ -459,7 +459,7 @@ mibyang_augment_register(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
mibyang_table_poll(clicon_handle h, mibyang_table_poll(clixon_handle h,
yang_stmt *ylist) yang_stmt *ylist)
{ {
int retval = -1; int retval = -1;
@ -481,7 +481,7 @@ mibyang_table_poll(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if ((ys = yang_parent_get(ylist)) == NULL || if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){ yang_keyword_get(ys) != Y_CONTAINER){
clicon_err(OE_YANG, EINVAL, "ylist parent is not list"); clixon_err(OE_YANG, EINVAL, "ylist parent is not list");
goto done; goto done;
} }
if (xml_nsctx_yang(ys, &nsc) < 0) if (xml_nsctx_yang(ys, &nsc) < 0)
@ -491,13 +491,13 @@ mibyang_table_poll(clicon_handle h,
if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0)
goto done; goto done;
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) { if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) {
/* Make a clone of key-list, but replace names with values */ /* Make a clone of key-list, but replace names with values */
if ((cvk_name = yang_cvec_get(ylist)) == NULL){ if ((cvk_name = yang_cvec_get(ylist)) == NULL){
clicon_err(OE_YANG, 0, "No keys"); clixon_err(OE_YANG, 0, "No keys");
goto done; goto done;
} }
xrow = NULL; xrow = NULL;
@ -550,7 +550,7 @@ mibyang_table_poll(clicon_handle h,
* @retval -1 Error, aborted at first error encounter * @retval -1 Error, aborted at first error encounter
*/ */
static int static int
mibyang_traverse(clicon_handle h, mibyang_traverse(clixon_handle h,
yang_stmt *yn) yang_stmt *yn)
{ {
int retval = -1; int retval = -1;
@ -611,7 +611,7 @@ mibyang_traverse(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
clixon_snmp_traverse_mibyangs(clicon_handle h) clixon_snmp_traverse_mibyangs(clixon_handle h)
{ {
int retval = -1; int retval = -1;
char *modname; char *modname;
@ -620,7 +620,7 @@ clixon_snmp_traverse_mibyangs(clicon_handle h)
yang_stmt *ymod; yang_stmt *ymod;
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
/* Loop over clixon configuration file to find all CLICON_SNMP_MIB, and /* Loop over clixon configuration file to find all CLICON_SNMP_MIB, and
@ -640,7 +640,7 @@ clixon_snmp_traverse_mibyangs(clicon_handle h)
* What happens if backend has not loaded it? * What happens if backend has not loaded it?
*/ */
if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){ if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){
clicon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname); clixon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname);
goto done; goto done;
} }
/* Recursively traverse the mib-yang to find extensions */ /* Recursively traverse the mib-yang to find extensions */

View file

@ -44,8 +44,8 @@ extern "C" {
/* /*
* Prototypes * Prototypes
*/ */
int mibyang_table_poll(clicon_handle h, yang_stmt *ylist); int mibyang_table_poll(clixon_handle h, yang_stmt *ylist);
int clixon_snmp_traverse_mibyangs(clicon_handle h); int clixon_snmp_traverse_mibyangs(clixon_handle h);
#endif /* _SNMP_REGISTER_H_ */ #endif /* _SNMP_REGISTER_H_ */

View file

@ -473,7 +473,7 @@ Each plugin is initiated with an API struct followed by a plugin init function a
... /* more functions here */ ... /* more functions here */
} }
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
... ...
return &api; /* Return NULL on error */ return &api; /* Return NULL on error */
@ -515,7 +515,7 @@ More are found in the doxygen reference.
1. You add an entry in example_cli.cli 1. You add an entry in example_cli.cli
> example("This is a comment") <var:int32>("This is a variable"), mycallback("myarg"); > example("This is a comment") <var:int32>("This is a variable"), mycallback("myarg");
2. Then define a function in example_cli.c 2. Then define a function in example_cli.c
> mycallback(clicon_handle h, cvec *cvv, cvec *arv) > mycallback(clixon_handle h, cvec *cvv, cvec *arv)
where 'cvv' contains the value of the variable 'var' and 'argv' contains the string "myarg". where 'cvv' contains the value of the variable 'var' and 'argv' contains the string "myarg".
The 'cvv' datatype is a 'CLIgen variable vector'. The 'cvv' datatype is a 'CLIgen variable vector'.
@ -523,9 +523,9 @@ They are documented in [CLIgen tutorial](https://github.com/clicon/cligen/blob/m
## How do I write a validation function? ## How do I write a validation function?
Similar to a commit function, but instead write the transaction_validate() function. Similar to a commit function, but instead write the transaction_validate() function.
Check for inconsistencies in the XML trees and if they fail, make an clicon_err() call. Check for inconsistencies in the XML trees and if they fail, make an clixon_err() call.
``` ```
clicon_err(OE_PLUGIN, 0, "Route %s lacks ipv4 addr", name); clixon_err(OE_PLUGIN, 0, "Route %s lacks ipv4 addr", name);
return -1; return -1;
``` ```
The validation or commit will then be aborted. The validation or commit will then be aborted.
@ -560,7 +560,7 @@ implement the RFC, you need to register an RPC callback in the backend plugin:
Example: Example:
``` ```
int int
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
... ...
rpc_callback_register(h, example_rpc, NULL, "urn:example:my", "example-rpc"); rpc_callback_register(h, example_rpc, NULL, "urn:example:my", "example-rpc");
@ -570,7 +570,7 @@ clixon_plugin_init(clicon_handle h)
And then define the callback itself: And then define the callback itself:
``` ```
static int static int
example_rpc(clicon_handle h, /* Clicon handle */ example_rpc(clixon_handle h, /* Clicon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* Client session */ void *arg, /* Client session */
@ -592,7 +592,7 @@ The following example shows how `my_copy` can be called right after the system (
the original operation: the original operation:
``` ```
static int static int
my_copy(clicon_handle h, /* Clicon handle */ my_copy(clixon_handle h, /* Clicon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* Client session */ void *arg, /* Client session */
@ -602,7 +602,7 @@ my_copy(clicon_handle h, /* Clicon handle */
return 0; return 0;
} }
int int
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
... ...
rpc_callback_register(h, my_copy, NULL, "urn:ietf:params:xml:ns:netconf:base:1.0", "copy-config"); rpc_callback_register(h, my_copy, NULL, "urn:ietf:params:xml:ns:netconf:base:1.0", "copy-config");
@ -616,7 +616,7 @@ A restconf call may need to be authenticated.
You can specify an authentication callback for restconf as follows: You can specify an authentication callback for restconf as follows:
``` ```
int int
plugin_credentials(clicon_handle h, plugin_credentials(clixon_handle h,
void *arg) void *arg)
{ {
FCGX_Request *r = (FCGX_Request *)arg; FCGX_Request *r = (FCGX_Request *)arg;

View file

@ -326,7 +326,7 @@ In the CLI a netconf rpc call is constructed and sent to the backend: See `examp
The clixon backend plugin [example_backend.c] reveives the netconf call and replies. This is made byregistering a callback handling handling the RPC: The clixon backend plugin [example_backend.c] reveives the netconf call and replies. This is made byregistering a callback handling handling the RPC:
``` ```
static int static int
example_rpc(clicon_handle h, example_rpc(clixon_handle h,
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* Client session */ void *arg, /* Client session */
@ -336,7 +336,7 @@ example_rpc(clicon_handle h,
return 0; return 0;
} }
int int
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
... ...
rpc_callback_register(h, example_rpc, NULL, "example"); rpc_callback_register(h, example_rpc, NULL, "example");
@ -426,7 +426,7 @@ static clixon_plugin_api api = {
}; };
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
/* Optional callback registration for RPC calls */ /* Optional callback registration for RPC calls */
rpc_callback_register(h, example_rpc, NULL, "example"); rpc_callback_register(h, example_rpc, NULL, "example");

View file

@ -60,10 +60,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/time.h> #include <sys/time.h>
/* clicon */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* Clicon library functions. */ /* Clixon library functions. */
#include <clixon/clixon.h> #include <clixon/clixon.h>
/* These include signatures for plugin and transaction callbacks. */ /* These include signatures for plugin and transaction callbacks. */
@ -182,10 +182,10 @@ static char *_validate_fail_xpath = NULL;
static int _validate_fail_toggle = 0; /* fail at validate and commit */ static int _validate_fail_toggle = 0; /* fail at validate and commit */
/* forward */ /* forward */
static int example_stream_timer_setup(clicon_handle h); static int example_stream_timer_setup(clixon_handle h);
int int
main_begin(clicon_handle h, main_begin(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -196,7 +196,7 @@ main_begin(clicon_handle h,
/*! This is called on validate (and commit). Check validity of candidate /*! This is called on validate (and commit). Check validity of candidate
*/ */
int int
main_validate(clicon_handle h, main_validate(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -205,7 +205,7 @@ main_validate(clicon_handle h,
if (_validate_fail_toggle==0 && if (_validate_fail_toggle==0 &&
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
_validate_fail_toggle = 1; /* toggle if triggered */ _validate_fail_toggle = 1; /* toggle if triggered */
clicon_err(OE_XML, 0, "User error"); clixon_err(OE_XML, 0, "User error");
return -1; /* induce fail */ return -1; /* induce fail */
} }
} }
@ -213,7 +213,7 @@ main_validate(clicon_handle h,
} }
int int
main_complete(clicon_handle h, main_complete(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -224,7 +224,7 @@ main_complete(clicon_handle h,
/*! This is called on commit. Identify modifications and adjust machine state /*! This is called on commit. Identify modifications and adjust machine state
*/ */
int int
main_commit(clicon_handle h, main_commit(clixon_handle h,
transaction_data td) transaction_data td)
{ {
cxobj *target = transaction_target(td); /* wanted XML tree */ cxobj *target = transaction_target(td); /* wanted XML tree */
@ -239,7 +239,7 @@ main_commit(clicon_handle h,
if (_validate_fail_toggle==1 && if (_validate_fail_toggle==1 &&
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
_validate_fail_toggle = 0; /* toggle if triggered */ _validate_fail_toggle = 0; /* toggle if triggered */
clicon_err(OE_XML, 0, "User error"); clixon_err(OE_XML, 0, "User error");
return -1; /* induce fail */ return -1; /* induce fail */
} }
} }
@ -263,7 +263,7 @@ main_commit(clicon_handle h,
} }
int int
main_commit_done(clicon_handle h, main_commit_done(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -272,7 +272,7 @@ main_commit_done(clicon_handle h,
} }
int int
main_revert(clicon_handle h, main_revert(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -281,7 +281,7 @@ main_revert(clicon_handle h,
} }
int int
main_end(clicon_handle h, main_end(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -290,7 +290,7 @@ main_end(clicon_handle h,
} }
int int
main_abort(clicon_handle h, main_abort(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -305,7 +305,7 @@ example_stream_timer(int fd,
void *arg) void *arg)
{ {
int retval = -1; int retval = -1;
clicon_handle h = (clicon_handle)arg; clixon_handle h = (clixon_handle)arg;
/* XXX Change to actual netconf notifications and namespace */ /* XXX Change to actual netconf notifications and namespace */
if (stream_notify(h, "EXAMPLE", "<event xmlns=\"urn:example:clixon\"><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>") < 0) if (stream_notify(h, "EXAMPLE", "<event xmlns=\"urn:example:clixon\"><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>") < 0)
@ -320,7 +320,7 @@ example_stream_timer(int fd,
/*! Set up example stream notification timer /*! Set up example stream notification timer
*/ */
static int static int
example_stream_timer_setup(clicon_handle h) example_stream_timer_setup(clixon_handle h)
{ {
struct timeval t, t1; struct timeval t, t1;
@ -338,7 +338,7 @@ example_stream_timer_setup(clicon_handle h)
* in [RFC6241]. * in [RFC6241].
*/ */
static int static int
empty_rpc(clicon_handle h, /* Clixon handle */ empty_rpc(clixon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */ void *arg, /* client_entry */
@ -353,7 +353,7 @@ empty_rpc(clicon_handle h, /* Clixon handle */
* The RPC returns the incoming parameters * The RPC returns the incoming parameters
*/ */
static int static int
example_rpc(clicon_handle h, /* Clixon handle */ example_rpc(clixon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */ void *arg, /* client_entry */
@ -367,7 +367,7 @@ example_rpc(clicon_handle h, /* Clixon handle */
/* get namespace from rpc name, return back in each output parameter */ /* get namespace from rpc name, return back in each output parameter */
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
goto done; goto done;
} }
cprintf(cbret, "<rpc-reply xmlns=\"%s\"", NETCONF_BASE_NAMESPACE); cprintf(cbret, "<rpc-reply xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
@ -395,7 +395,7 @@ example_rpc(clicon_handle h, /* Clixon handle */
/*! This will be called as a hook right after the original system copy-config /*! This will be called as a hook right after the original system copy-config
*/ */
static int static int
example_copy_extra(clicon_handle h, /* Clixon handle */ example_copy_extra(clixon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */ void *arg, /* client_entry */
@ -414,7 +414,7 @@ example_copy_extra(clicon_handle h, /* Clixon handle */
* @note callback is hardcoded C, while registration is controlled by -- -a option * @note callback is hardcoded C, while registration is controlled by -- -a option
*/ */
static int static int
example_action_reset(clicon_handle h, /* Clixon handle */ example_action_reset(clixon_handle h, /* Clixon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */ cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */ cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */ void *arg, /* client_entry */
@ -453,7 +453,7 @@ example_action_reset(clicon_handle h, /* Clixon handle */
* @see example_statefile where state is read from file and also pagination * @see example_statefile where state is read from file and also pagination
*/ */
int int
example_statedata(clicon_handle h, example_statedata(clixon_handle h,
cvec *nsc, cvec *nsc,
char *xpath, char *xpath,
cxobj *xstate) cxobj *xstate)
@ -471,7 +471,7 @@ example_statedata(clicon_handle h,
if (!_state) if (!_state)
goto ok; goto ok;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
yspec = clicon_dbspec_yang(h); yspec = clicon_dbspec_yang(h);
@ -549,7 +549,7 @@ example_statedata(clicon_handle h,
* @see example_statefile where state is programmatically added * @see example_statefile where state is programmatically added
*/ */
int int
example_statefile(clicon_handle h, example_statefile(clixon_handle h,
cvec *nsc, cvec *nsc,
char *xpath, char *xpath,
cxobj *xstate) cxobj *xstate)
@ -574,7 +574,7 @@ example_statefile(clicon_handle h,
if (_state_file_cached == 0 || if (_state_file_cached == 0 ||
_state_xml_cache == NULL){ _state_xml_cache == NULL){
if ((fp = fopen(_state_file, "r")) == NULL){ if ((fp = fopen(_state_file, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", _state_file); clixon_err(OE_UNIX, errno, "open(%s)", _state_file);
goto done; goto done;
} }
if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
@ -641,7 +641,7 @@ example_pagination(void *h0,
void *arg) void *arg)
{ {
int retval = -1; int retval = -1;
clicon_handle h = (clicon_handle)h0; clixon_handle h = (clixon_handle)h0;
int locked; int locked;
uint32_t offset; uint32_t offset;
uint32_t limit; uint32_t limit;
@ -675,7 +675,7 @@ example_pagination(void *h0,
if (_state_file_cached == 0 || if (_state_file_cached == 0 ||
_state_xml_cache == NULL){ _state_xml_cache == NULL){
if ((fp = fopen(_state_file, "r")) == NULL){ if ((fp = fopen(_state_file, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", _state_file); clixon_err(OE_UNIX, errno, "open(%s)", _state_file);
goto done; goto done;
} }
if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
@ -745,7 +745,7 @@ example_pagination(void *h0,
* @retval -1 Fatal error * @retval -1 Fatal error
*/ */
int int
example_lockdb(clicon_handle h, example_lockdb(clixon_handle h,
char *db, char *db,
int lock, int lock,
int id) int id)
@ -777,7 +777,7 @@ example_lockdb(clicon_handle h,
* @retval -1 Error in one callback * @retval -1 Error in one callback
*/ */
int int
example_extension(clicon_handle h, example_extension(clixon_handle h,
yang_stmt *yext, yang_stmt *yext,
yang_stmt *ys) yang_stmt *ys)
{ {
@ -841,7 +841,7 @@ static const map_str2str namespace_map[] = {
* @retval -1 Error * @retval -1 Error
*/ */
int int
example_upgrade(clicon_handle h, example_upgrade(clixon_handle h,
const char *db, const char *db,
cxobj *xt, cxobj *xt,
modstate_diff_t *msd) modstate_diff_t *msd)
@ -891,7 +891,7 @@ example_upgrade(clicon_handle h,
mypath = ms->ms_s0; mypath = ms->ms_s0;
mynamespace = ms->ms_s1; mynamespace = ms->ms_s1;
if (xml_nsctx_get_prefix(nsc, mynamespace, &myprefix) == 0){ if (xml_nsctx_get_prefix(nsc, mynamespace, &myprefix) == 0){
clicon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map", clixon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map",
mynamespace); mynamespace);
goto done; goto done;
} }
@ -933,7 +933,7 @@ example_upgrade(clicon_handle h,
* @see RFC 8528 * @see RFC 8528
*/ */
int int
main_yang_mount(clicon_handle h, main_yang_mount(clixon_handle h,
cxobj *xt, cxobj *xt,
int *config, int *config,
validate_level *vl, validate_level *vl,
@ -948,7 +948,7 @@ main_yang_mount(clicon_handle h,
*vl = VL_FULL; *vl = VL_FULL;
if (yanglib && _mount_yang){ if (yanglib && _mount_yang){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"); cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">");
@ -999,7 +999,7 @@ main_yang_mount(clicon_handle h,
* - Rename /interfaces/interface/description to descr * - Rename /interfaces/interface/description to descr
*/ */
static int static int
upgrade_2014_to_2016(clicon_handle h, upgrade_2014_to_2016(clixon_handle h,
cxobj *xt, cxobj *xt,
char *ns, char *ns,
uint16_t op, uint16_t op,
@ -1103,7 +1103,7 @@ upgrade_2014_to_2016(clicon_handle h,
* fraction-digits 3 and divide all values with 1000 * fraction-digits 3 and divide all values with 1000
*/ */
static int static int
upgrade_2016_to_2018(clicon_handle h, upgrade_2016_to_2018(clixon_handle h,
cxobj *xt, cxobj *xt,
char *ns, char *ns,
uint16_t op, uint16_t op,
@ -1159,7 +1159,7 @@ upgrade_2016_to_2018(clicon_handle h,
cbuf *cb; cbuf *cb;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
@ -1204,7 +1204,7 @@ upgrade_2016_to_2018(clicon_handle h,
* - Rename /interfaces/interface/description to descr * - Rename /interfaces/interface/description to descr
*/ */
static int static int
upgrade_interfaces(clicon_handle h, upgrade_interfaces(clixon_handle h,
cxobj *xt, cxobj *xt,
char *ns, char *ns,
uint16_t op, uint16_t op,
@ -1216,7 +1216,7 @@ upgrade_interfaces(clicon_handle h,
int retval = -1; int retval = -1;
if (_module_upgrade) /* For testing */ if (_module_upgrade) /* For testing */
clicon_log(LOG_NOTICE, "%s %s op:%s from:%d to:%d", clixon_log(h, LOG_NOTICE, "%s %s op:%s from:%d to:%d",
__FUNCTION__, ns, __FUNCTION__, ns,
(op&XML_FLAG_ADD)?"ADD":(op&XML_FLAG_DEL)?"DEL":"CHANGE", (op&XML_FLAG_ADD)?"ADD":(op&XML_FLAG_DEL)?"DEL":"CHANGE",
from, to); from, to);
@ -1254,7 +1254,7 @@ upgrade_interfaces(clicon_handle h,
* In this example, a loopback parameter is added * In this example, a loopback parameter is added
*/ */
int int
example_reset(clicon_handle h, example_reset(clixon_handle h,
const char *db) const char *db)
{ {
int retval = -1; int retval = -1;
@ -1279,14 +1279,14 @@ example_reset(clicon_handle h,
/* xmldb_put requires modification tree to be: <config>... */ /* xmldb_put requires modification tree to be: <config>... */
xml_name_set(xt, "config"); xml_name_set(xt, "config");
if ((cbret = cbuf_new()) == NULL){ if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
/* Merge user reset state */ /* Merge user reset state */
if ((ret = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret)) < 0) if ((ret = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
clicon_err(OE_XML, 0, "Error when writing to XML database: %s", clixon_err(OE_XML, 0, "Error when writing to XML database: %s",
cbuf_get(cbret)); cbuf_get(cbret));
goto done; goto done;
} }
@ -1312,7 +1312,7 @@ example_reset(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
example_start(clicon_handle h) example_start(clixon_handle h)
{ {
int retval = -1; int retval = -1;
yang_stmt *yspec; yang_stmt *yspec;
@ -1326,7 +1326,7 @@ example_start(clicon_handle h)
*/ */
if (_action_instanceid){ if (_action_instanceid){
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
} }
if (yang_abs_schema_nodeid(yspec, _action_instanceid, &ya) == 0){ if (yang_abs_schema_nodeid(yspec, _action_instanceid, &ya) == 0){
@ -1348,7 +1348,7 @@ example_start(clicon_handle h)
* the main event loop is entered. * the main event loop is entered.
*/ */
int int
example_daemon(clicon_handle h) example_daemon(clixon_handle h)
{ {
int retval = -1; int retval = -1;
int ret; int ret;
@ -1360,7 +1360,7 @@ example_daemon(clicon_handle h)
if (_state && _state_file && _state_file_cached){ if (_state && _state_file && _state_file_cached){
yspec = clicon_dbspec_yang(h); yspec = clicon_dbspec_yang(h);
if ((fp = fopen(_state_file, "r")) == NULL){ if ((fp = fopen(_state_file, "r")) == NULL){
clicon_err(OE_UNIX, errno, "open(%s)", _state_file); clixon_err(OE_UNIX, errno, "open(%s)", _state_file);
goto done; goto done;
} }
/* Need to be yang bound for eg xml_copy_marked() in example_pagination /* Need to be yang bound for eg xml_copy_marked() in example_pagination
@ -1382,7 +1382,7 @@ example_daemon(clicon_handle h)
} }
int int
example_exit(clicon_handle h) example_exit(clixon_handle h)
{ {
if (_state_xml_cache){ if (_state_xml_cache){
xml_free(_state_xml_cache); xml_free(_state_xml_cache);
@ -1392,7 +1392,7 @@ example_exit(clicon_handle h)
} }
/* Forward declaration */ /* Forward declaration */
clixon_plugin_api *clixon_plugin_init(clicon_handle h); clixon_plugin_api *clixon_plugin_init(clixon_handle h);
static clixon_plugin_api api = { static clixon_plugin_api api = {
"example", /* name */ "example", /* name */
@ -1419,13 +1419,13 @@ static clixon_plugin_api api = {
/*! Backend plugin initialization /*! Backend plugin initialization
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @retval NULL Error with clicon_err set * @retval NULL Error
* @retval api Pointer to API struct * @retval api Pointer to API struct
* In this example, you can pass -r, -s, -u to control the behaviour, mainly * In this example, you can pass -r, -s, -u to control the behaviour, mainly
* for use in the test suites. * for use in the test suites.
*/ */
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
struct timeval retention = {0,0}; struct timeval retention = {0,0};
int argc; /* command-line options (after --) */ int argc; /* command-line options (after --) */
@ -1482,7 +1482,7 @@ clixon_plugin_init(clicon_handle h)
break; break;
} }
if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){ if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){
clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
goto done; goto done;
} }
if (_state_file){ if (_state_file){

View file

@ -49,7 +49,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/syslog.h> #include <sys/syslog.h>
/* clicon */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* Clicon library functions. */ /* Clicon library functions. */
@ -84,7 +84,7 @@ static char *_validate_fail_xpath = NULL;
static int _validate_fail_toggle = 0; /* fail at validate and commit */ static int _validate_fail_toggle = 0; /* fail at validate and commit */
int int
nacm_begin(clicon_handle h, nacm_begin(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -94,7 +94,7 @@ nacm_begin(clicon_handle h,
/*! This is called on validate (and commit). Check validity of candidate /*! This is called on validate (and commit). Check validity of candidate
*/ */
int int
nacm_validate(clicon_handle h, nacm_validate(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -103,7 +103,7 @@ nacm_validate(clicon_handle h,
if (_validate_fail_toggle==0 && if (_validate_fail_toggle==0 &&
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
_validate_fail_toggle = 1; /* toggle if triggered */ _validate_fail_toggle = 1; /* toggle if triggered */
clicon_err(OE_XML, 0, "User error"); clixon_err(OE_XML, 0, "User error");
return -1; /* induce fail */ return -1; /* induce fail */
} }
} }
@ -111,7 +111,7 @@ nacm_validate(clicon_handle h,
} }
int int
nacm_complete(clicon_handle h, nacm_complete(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -122,7 +122,7 @@ nacm_complete(clicon_handle h,
/*! This is called on commit. Identify modifications and adjust machine state /*! This is called on commit. Identify modifications and adjust machine state
*/ */
int int
nacm_commit(clicon_handle h, nacm_commit(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -131,7 +131,7 @@ nacm_commit(clicon_handle h,
if (_validate_fail_toggle==1 && if (_validate_fail_toggle==1 &&
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
_validate_fail_toggle = 0; /* toggle if triggered */ _validate_fail_toggle = 0; /* toggle if triggered */
clicon_err(OE_XML, 0, "User error"); clixon_err(OE_XML, 0, "User error");
return -1; /* induce fail */ return -1; /* induce fail */
} }
} }
@ -139,7 +139,7 @@ nacm_commit(clicon_handle h,
} }
int int
nacm_commit_done(clicon_handle h, nacm_commit_done(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -148,7 +148,7 @@ nacm_commit_done(clicon_handle h,
} }
int int
nacm_revert(clicon_handle h, nacm_revert(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -157,7 +157,7 @@ nacm_revert(clicon_handle h,
} }
int int
nacm_end(clicon_handle h, nacm_end(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -166,7 +166,7 @@ nacm_end(clicon_handle h,
} }
int int
nacm_abort(clicon_handle h, nacm_abort(clixon_handle h,
transaction_data td) transaction_data td)
{ {
if (_transaction_log) if (_transaction_log)
@ -187,7 +187,7 @@ nacm_abort(clicon_handle h,
* Real code would poll state * Real code would poll state
*/ */
int int
nacm_statedata(clicon_handle h, nacm_statedata(clixon_handle h,
cvec *nsc, cvec *nsc,
char *xpath, char *xpath,
cxobj *xstate) cxobj *xstate)
@ -209,7 +209,7 @@ nacm_statedata(clicon_handle h,
return retval; return retval;
} }
clixon_plugin_api *clixon_plugin_init(clicon_handle h); clixon_plugin_api *clixon_plugin_init(clixon_handle h);
static clixon_plugin_api api = { static clixon_plugin_api api = {
"nacm", /* name */ /*--- Common fields. ---*/ "nacm", /* name */ /*--- Common fields. ---*/
@ -230,11 +230,11 @@ static clixon_plugin_api api = {
/*! Backend plugin initialization /*! Backend plugin initialization
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @retval NULL Error with clicon_err set * @retval NULL Error
* @retval api Pointer to API struct * @retval api Pointer to API struct
*/ */
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
char *nacm_mode; char *nacm_mode;
int argc; /* command-line options (after --) */ int argc; /* command-line options (after --) */
@ -259,7 +259,7 @@ clixon_plugin_init(clicon_handle h)
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE"); nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){ if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){
clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__); clixon_log(h, LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
/* Skip nacm module if not enabled _unless_ we use transaction tests */ /* Skip nacm module if not enabled _unless_ we use transaction tests */
if (_transaction_log == 0) if (_transaction_log == 0)
return NULL; return NULL;

View file

@ -50,7 +50,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <signal.h> /* matching strings */ #include <signal.h> /* matching strings */
/* clicon */ /* clixon */
#include <cligen/cligen.h> #include <cligen/cligen.h>
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include <clixon/clixon_cli.h> #include <clixon/clixon_cli.h>
@ -67,7 +67,9 @@ static char *_mount_namespace = NULL;
/*! Example cli function /*! Example cli function
*/ */
int int
mycallback(clicon_handle h, cvec *cvv, cvec *argv) mycallback(clixon_handle h,
cvec *cvv,
cvec *argv)
{ {
int retval = -1; int retval = -1;
cxobj *xret = NULL; cxobj *xret = NULL;
@ -101,7 +103,7 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
/*! Example "downcall", ie initiate an RPC to the backend /*! Example "downcall", ie initiate an RPC to the backend
*/ */
int int
example_client_rpc(clicon_handle h, example_client_rpc(clixon_handle h,
cvec *cvv, cvec *cvv,
cvec *argv) cvec *argv)
{ {
@ -129,7 +131,7 @@ example_client_rpc(clicon_handle h,
if (clicon_rpc_netconf_xml(h, xrpc, &xret, NULL) < 0) if (clicon_rpc_netconf_xml(h, xrpc, &xret, NULL) < 0)
goto done; goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){ if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get configuration", NULL); clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done; goto done;
} }
/* Print result */ /* Print result */
@ -168,7 +170,7 @@ cli_incstr(cligen_handle h,
if (cv == NULL || cv_type_get(cv) != CGV_STRING) if (cv == NULL || cv_type_get(cv) != CGV_STRING)
return 0; return 0;
if ((str = cv_string_get(cv)) == NULL){ if ((str = cv_string_get(cv)) == NULL){
clicon_err(OE_PLUGIN, EINVAL, "cv string is NULL"); clixon_err(OE_PLUGIN, EINVAL, "cv string is NULL");
return -1; return -1;
} }
for (i=0; i<strlen(str); i++) for (i=0; i<strlen(str); i++)
@ -190,7 +192,7 @@ cli_incstr(cligen_handle h,
* @see RFC 8528 * @see RFC 8528
*/ */
int int
example_cli_yang_mount(clicon_handle h, example_cli_yang_mount(clixon_handle h,
cxobj *xt, cxobj *xt,
int *config, int *config,
validate_level *vl, validate_level *vl,
@ -205,7 +207,7 @@ example_cli_yang_mount(clicon_handle h,
*vl = VL_FULL; *vl = VL_FULL;
if (yanglib && _mount_yang){ if (yanglib && _mount_yang){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"); cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">");
@ -242,7 +244,7 @@ example_cli_yang_mount(clicon_handle h,
* @see netconf_err2cb this errmsg is the same as the default * @see netconf_err2cb this errmsg is the same as the default
*/ */
int int
example_cli_errmsg(clicon_handle h, example_cli_errmsg(clixon_handle h,
cxobj *xerr, cxobj *xerr,
cbuf *cberr) cbuf *cberr)
{ {
@ -281,7 +283,7 @@ example_cli_errmsg(clicon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
int int
example_version(clicon_handle h, example_version(clixon_handle h,
FILE *f) FILE *f)
{ {
cligen_output(f, "Clixon main example version 0\n"); cligen_output(f, "Clixon main example version 0\n");
@ -302,11 +304,11 @@ static clixon_plugin_api api = {
/*! CLI plugin initialization /*! CLI plugin initialization
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @retval NULL Error with clicon_err set * @retval NULL Error
* @retval api Pointer to API struct * @retval api Pointer to API struct
*/ */
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
struct timeval tv; struct timeval tv;
int c; int c;
@ -330,7 +332,7 @@ clixon_plugin_init(clicon_handle h)
break; break;
} }
if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){ if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){
clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
goto done; goto done;
} }
/* XXX Not implemented: CLI completion for mountpoints, see clixon-controller /* XXX Not implemented: CLI completion for mountpoints, see clixon-controller

View file

@ -55,13 +55,13 @@
* @param[in] h Clixon handle * @param[in] h Clixon handle
*/ */
int int
plugin_start(clicon_handle h) plugin_start(clixon_handle h)
{ {
return 0; return 0;
} }
int int
plugin_exit(clicon_handle h) plugin_exit(clixon_handle h)
{ {
return 0; return 0;
} }
@ -69,7 +69,7 @@ plugin_exit(clicon_handle h)
/*! Local example netconf rpc callback /*! Local example netconf rpc callback
*/ */
int int
netconf_client_rpc(clicon_handle h, netconf_client_rpc(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -81,7 +81,7 @@ netconf_client_rpc(clicon_handle h,
/* get namespace from rpc name, return back in each output parameter */ /* get namespace from rpc name, return back in each output parameter */
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
goto done; goto done;
} }
cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE); cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE);
@ -103,7 +103,7 @@ netconf_client_rpc(clicon_handle h,
return 0; return 0;
} }
clixon_plugin_api * clixon_plugin_init(clicon_handle h); clixon_plugin_api * clixon_plugin_init(clixon_handle h);
static struct clixon_plugin_api api = { static struct clixon_plugin_api api = {
"example", /* name */ "example", /* name */
@ -115,11 +115,11 @@ static struct clixon_plugin_api api = {
/*! Netconf plugin initialization /*! Netconf plugin initialization
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @retval NULL Error with clicon_err set * @retval NULL Error
* @retval api Pointer to API struct * @retval api Pointer to API struct
*/ */
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__);
/* Register local netconf rpc client (note not backend rpc client) */ /* Register local netconf rpc client (note not backend rpc client) */

View file

@ -45,7 +45,7 @@
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
/* clicon */ /* clixon */
#include <clixon/clixon.h> #include <clixon/clixon.h>
#include <clixon/clixon_restconf.h> /* minor use */ #include <clixon/clixon_restconf.h> /* minor use */
@ -206,7 +206,7 @@ b64_decode(const char *src,
* @note: Three hardwired users: andy, wilma, guest w password "bar". * @note: Three hardwired users: andy, wilma, guest w password "bar".
*/ */
static int static int
example_basic_auth(clicon_handle h, example_basic_auth(clixon_handle h,
void *req, void *req,
char **authp) char **authp)
{ {
@ -222,7 +222,7 @@ example_basic_auth(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (authp == NULL){ if (authp == NULL){
clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL"); clixon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
goto done; goto done;
} }
/* At this point in the code we must use HTTP basic authentication */ /* At this point in the code we must use HTTP basic authentication */
@ -235,7 +235,7 @@ example_basic_auth(clicon_handle h,
auth += strlen("Basic "); auth += strlen("Basic ");
authlen = strlen(auth)*2; authlen = strlen(auth)*2;
if ((user = malloc(authlen)) == NULL){ if ((user = malloc(authlen)) == NULL){
clicon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
memset(user, 0, authlen); memset(user, 0, authlen);
@ -289,7 +289,7 @@ example_basic_auth(clicon_handle h,
* @note authp should be malloced * @note authp should be malloced
*/ */
int int
example_restconf_credentials(clicon_handle h, example_restconf_credentials(clixon_handle h,
void *req, void *req,
clixon_auth_type_t auth_type, clixon_auth_type_t auth_type,
char **authp) char **authp)
@ -317,7 +317,7 @@ example_restconf_credentials(clicon_handle h,
/*! Local example restconf rpc callback /*! Local example restconf rpc callback
*/ */
int int
restconf_client_rpc(clicon_handle h, restconf_client_rpc(clixon_handle h,
cxobj *xe, cxobj *xe,
cbuf *cbret, cbuf *cbret,
void *arg, void *arg,
@ -329,7 +329,7 @@ restconf_client_rpc(clicon_handle h,
/* get namespace from rpc name, return back in each output parameter */ /* get namespace from rpc name, return back in each output parameter */
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
goto done; goto done;
} }
cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE); cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE);
@ -352,7 +352,7 @@ restconf_client_rpc(clicon_handle h,
/*! Start example restonf plugin. Set authentication method /*! Start example restonf plugin. Set authentication method
*/ */
int int
example_restconf_start(clicon_handle h) example_restconf_start(clixon_handle h)
{ {
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0; return 0;
@ -372,7 +372,7 @@ example_restconf_start(clicon_handle h)
* @see RFC 8528 * @see RFC 8528
*/ */
int int
restconf_yang_mount(clicon_handle h, restconf_yang_mount(clixon_handle h,
cxobj *xt, cxobj *xt,
int *config, int *config,
validate_level *vl, validate_level *vl,
@ -387,7 +387,7 @@ restconf_yang_mount(clicon_handle h,
*vl = VL_FULL; *vl = VL_FULL;
if (yanglib && _mount_yang){ if (yanglib && _mount_yang){
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"); cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">");
@ -414,7 +414,7 @@ restconf_yang_mount(clicon_handle h,
return retval; return retval;
} }
clixon_plugin_api * clixon_plugin_init(clicon_handle h); clixon_plugin_api * clixon_plugin_init(clixon_handle h);
static clixon_plugin_api api = { static clixon_plugin_api api = {
"example", /* name */ "example", /* name */
@ -428,12 +428,12 @@ static clixon_plugin_api api = {
/*! Restconf plugin initialization /*! Restconf plugin initialization
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @retval NULL Error with clicon_err set * @retval NULL Error
* @retval api Pointer to API struct * @retval api Pointer to API struct
* Arguments are argc/argv after -- * Arguments are argc/argv after --
*/ */
clixon_plugin_api * clixon_plugin_api *
clixon_plugin_init(clicon_handle h) clixon_plugin_init(clixon_handle h)
{ {
int argc; /* command-line options (after --) */ int argc; /* command-line options (after --) */
char **argv = NULL; char **argv = NULL;
@ -457,7 +457,7 @@ clixon_plugin_init(clicon_handle h)
break; break;
} }
if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){ if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){
clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
goto done; goto done;
} }
/* Register local netconf rpc client (note not backend rpc client) */ /* Register local netconf rpc client (note not backend rpc client) */

View file

@ -203,3 +203,10 @@
* Plan is to remove this (undef:d) in next release * Plan is to remove this (undef:d) in next release
*/ */
#undef RESTCONF_INLINE #undef RESTCONF_INLINE
/*! Backward compatible with 6.5
*
* Note: many(most) not covered by this constant need to GREP
* This includes lots of clicon->clixon namechanges, see CHANGELOG for whole list
*/
#define COMPAT_6_5

View file

@ -68,11 +68,12 @@ extern "C" {
#include <clixon/clixon_sig.h> #include <clixon/clixon_sig.h>
#include <clixon/clixon_uid.h> #include <clixon/clixon_uid.h>
#include <clixon/clixon_err.h>
#include <clixon/clixon_queue.h> #include <clixon/clixon_queue.h>
#include <clixon/clixon_hash.h> #include <clixon/clixon_hash.h>
#include <clixon/clixon_handle.h> #include <clixon/clixon_handle.h>
#include <clixon/clixon_err.h>
#include <clixon/clixon_log.h> #include <clixon/clixon_log.h>
#include <clixon/clixon_debug.h>
#include <clixon/clixon_netns.h> #include <clixon/clixon_netns.h>
#include <clixon/clixon_yang.h> #include <clixon/clixon_yang.h>
#include <clixon/clixon_yang_type.h> #include <clixon/clixon_yang_type.h>

View file

@ -63,87 +63,87 @@ typedef struct {
* Prototypes * Prototypes
*/ */
/* Generic clixon data API the form <name>=<val> where <val> is string */ /* Generic clixon data API the form <name>=<val> where <val> is string */
int clicon_data_get(clicon_handle h, const char *name, char **val); int clicon_data_get(clixon_handle h, const char *name, char **val);
int clicon_data_set(clicon_handle h, const char *name, char *val); int clicon_data_set(clixon_handle h, const char *name, char *val);
int clicon_data_del(clicon_handle h, const char *name); int clicon_data_del(clixon_handle h, const char *name);
/* Get generic clixon data on the form <name>=<ptr> where <ptr> is void* */ /* Get generic clixon data on the form <name>=<ptr> where <ptr> is void* */
int clicon_ptr_get(clicon_handle h, const char *name, void **ptr); int clicon_ptr_get(clixon_handle h, const char *name, void **ptr);
int clicon_ptr_set(clicon_handle h, const char *name, void *ptr); int clicon_ptr_set(clixon_handle h, const char *name, void *ptr);
int clicon_ptr_del(clicon_handle h, const char *name); int clicon_ptr_del(clixon_handle h, const char *name);
cvec *clicon_data_cvec_get(clicon_handle h, const char *name); cvec *clicon_data_cvec_get(clixon_handle h, const char *name);
int clicon_data_cvec_set(clicon_handle h, const char *name, cvec *cvv); int clicon_data_cvec_set(clixon_handle h, const char *name, cvec *cvv);
int clicon_data_cvec_del(clicon_handle h, const char *name); int clicon_data_cvec_del(clixon_handle h, const char *name);
/* String options, default NULL */ /* String options, default NULL */
int clicon_data_int_get(clicon_handle h, const char *name); int clicon_data_int_get(clixon_handle h, const char *name);
int clicon_data_int_set(clicon_handle h, const char *name, int val); int clicon_data_int_set(clixon_handle h, const char *name, int val);
int clicon_data_int_del(clicon_handle h, const char *name); int clicon_data_int_del(clixon_handle h, const char *name);
yang_stmt * clicon_dbspec_yang(clicon_handle h); yang_stmt * clicon_dbspec_yang(clixon_handle h);
int clicon_dbspec_yang_set(clicon_handle h, yang_stmt *ys); int clicon_dbspec_yang_set(clixon_handle h, yang_stmt *ys);
yang_stmt * clicon_config_yang(clicon_handle h); yang_stmt * clicon_config_yang(clixon_handle h);
int clicon_config_yang_set(clicon_handle h, yang_stmt *ys); int clicon_config_yang_set(clixon_handle h, yang_stmt *ys);
yang_stmt * clicon_nacm_ext_yang(clicon_handle h); yang_stmt * clicon_nacm_ext_yang(clixon_handle h);
int clicon_nacm_ext_yang_set(clicon_handle h, yang_stmt *ys); int clicon_nacm_ext_yang_set(clixon_handle h, yang_stmt *ys);
cvec *clicon_nsctx_global_get(clicon_handle h); cvec *clicon_nsctx_global_get(clixon_handle h);
int clicon_nsctx_global_set(clicon_handle h, cvec *nsctx); int clicon_nsctx_global_set(clixon_handle h, cvec *nsctx);
cxobj * clicon_nacm_ext(clicon_handle h); cxobj * clicon_nacm_ext(clixon_handle h);
int clicon_nacm_ext_set(clicon_handle h, cxobj *xn); int clicon_nacm_ext_set(clixon_handle h, cxobj *xn);
cxobj *clicon_nacm_cache(clicon_handle h); cxobj *clicon_nacm_cache(clixon_handle h);
int clicon_nacm_cache_set(clicon_handle h, cxobj *xn); int clicon_nacm_cache_set(clixon_handle h, cxobj *xn);
cxobj *clicon_conf_xml(clicon_handle h); cxobj *clicon_conf_xml(clixon_handle h);
int clicon_conf_xml_set(clicon_handle h, cxobj *x); int clicon_conf_xml_set(clixon_handle h, cxobj *x);
cxobj *clicon_conf_restconf(clicon_handle h); cxobj *clicon_conf_restconf(clixon_handle h);
cxobj *clicon_conf_autocli(clicon_handle h); cxobj *clicon_conf_autocli(clixon_handle h);
db_elmnt *clicon_db_elmnt_get(clicon_handle h, const char *db); db_elmnt *clicon_db_elmnt_get(clixon_handle h, const char *db);
int clicon_db_elmnt_set(clicon_handle h, const char *db, db_elmnt *xc); int clicon_db_elmnt_set(clixon_handle h, const char *db, db_elmnt *xc);
/**/ /**/
/* Set and get authorized user name */ /* Set and get authorized user name */
char *clicon_username_get(clicon_handle h); char *clicon_username_get(clixon_handle h);
int clicon_username_set(clicon_handle h, void *username); int clicon_username_set(clixon_handle h, void *username);
/* Set and get startup status */ /* Set and get startup status */
enum startup_status clicon_startup_status_get(clicon_handle h); enum startup_status clicon_startup_status_get(clixon_handle h);
int clicon_startup_status_set(clicon_handle h, enum startup_status status); int clicon_startup_status_set(clixon_handle h, enum startup_status status);
/* Set and get server socket fd (ie backend server socket / restconf fcgi socket */ /* Set and get server socket fd (ie backend server socket / restconf fcgi socket */
int clicon_socket_get(clicon_handle h); int clicon_socket_get(clixon_handle h);
int clicon_socket_set(clicon_handle h, int s); int clicon_socket_set(clixon_handle h, int s);
/* Set and get client socket fd (ie client cli / netconf / restconf / client-api socket */ /* Set and get client socket fd (ie client cli / netconf / restconf / client-api socket */
int clicon_client_socket_get(clicon_handle h); int clicon_client_socket_get(clixon_handle h);
int clicon_client_socket_set(clicon_handle h, int s); int clicon_client_socket_set(clixon_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); cxobj *clicon_modst_cache_get(clixon_handle h, int brief);
int clicon_modst_cache_set(clicon_handle h, int brief, cxobj *xms); int clicon_modst_cache_set(clixon_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); cxobj *clicon_xml_changelog_get(clixon_handle h);
int clicon_xml_changelog_set(clicon_handle h, cxobj *xchlog); int clicon_xml_changelog_set(clixon_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_get(clixon_handle h, int *argc, char ***argv);
int clicon_argv_set(clicon_handle h, char *argv0, int argc, char **argv); int clicon_argv_set(clixon_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_set(clixon_handle h, uint32_t id);
int clicon_session_id_get(clicon_handle h, uint32_t *id); int clicon_session_id_get(clixon_handle h, uint32_t *id);
int clicon_session_id_del(clicon_handle h); int clicon_session_id_del(clixon_handle h);
/* If set, quit startup directly after upgrade */ /* If set, quit startup directly after upgrade */
int clicon_quit_upgrade_get(clicon_handle h); int clicon_quit_upgrade_get(clixon_handle h);
int clicon_quit_upgrade_set(clicon_handle h, int val); int clicon_quit_upgrade_set(clixon_handle h, int val);
#endif /* _CLIXON_DATA_H_ */ #endif /* _CLIXON_DATA_H_ */

View file

@ -43,39 +43,39 @@
* API * API
*/ */
/* Internal functions */ /* Internal functions */
int xmldb_db2file(clicon_handle h, const char *db, char **filename); int xmldb_db2file(clixon_handle h, const char *db, char **filename);
/* API */ /* API */
int xmldb_connect(clicon_handle h); int xmldb_connect(clixon_handle h);
int xmldb_disconnect(clicon_handle h); int xmldb_disconnect(clixon_handle h);
/* in clixon_datastore_read.[ch] */ /* in clixon_datastore_read.[ch] */
int xmldb_get(clicon_handle h, const char *db, cvec *nsc, char *xpath, cxobj **xtop); int xmldb_get(clixon_handle h, const char *db, cvec *nsc, char *xpath, cxobj **xtop);
int xmldb_get0(clicon_handle h, const char *db, yang_bind yb, int xmldb_get0(clixon_handle h, const char *db, yang_bind yb,
cvec *nsc, const char *xpath, int copy, withdefaults_type wdef, cvec *nsc, const char *xpath, int copy, withdefaults_type wdef,
cxobj **xtop, modstate_diff_t *msd, cxobj **xerr); cxobj **xtop, modstate_diff_t *msd, cxobj **xerr);
int xmldb_get0_clear(clicon_handle h, cxobj *x); int xmldb_get0_clear(clixon_handle h, cxobj *x);
int xmldb_get0_free(clicon_handle h, cxobj **xp); int xmldb_get0_free(clixon_handle h, cxobj **xp);
int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); /* in clixon_datastore_write.[ch] */ int xmldb_put(clixon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); /* in clixon_datastore_write.[ch] */
int xmldb_copy(clicon_handle h, const char *from, const char *to); int xmldb_copy(clixon_handle h, const char *from, const char *to);
int xmldb_lock(clicon_handle h, const char *db, uint32_t id); int xmldb_lock(clixon_handle h, const char *db, uint32_t id);
int xmldb_unlock(clicon_handle h, const char *db); int xmldb_unlock(clixon_handle h, const char *db);
int xmldb_unlock_all(clicon_handle h, uint32_t id); int xmldb_unlock_all(clixon_handle h, uint32_t id);
uint32_t xmldb_islocked(clicon_handle h, const char *db); uint32_t xmldb_islocked(clixon_handle h, const char *db);
int xmldb_lock_timestamp(clicon_handle h, const char *db, struct timeval *tv); int xmldb_lock_timestamp(clixon_handle h, const char *db, struct timeval *tv);
int xmldb_exists(clicon_handle h, const char *db); int xmldb_exists(clixon_handle h, const char *db);
int xmldb_clear(clicon_handle h, const char *db); int xmldb_clear(clixon_handle h, const char *db);
int xmldb_delete(clicon_handle h, const char *db); int xmldb_delete(clixon_handle h, const char *db);
int xmldb_create(clicon_handle h, const char *db); int xmldb_create(clixon_handle h, const char *db);
/* utility functions */ /* utility functions */
int xmldb_db_reset(clicon_handle h, const char *db); int xmldb_db_reset(clixon_handle h, const char *db);
cxobj *xmldb_cache_get(clicon_handle h, const char *db); cxobj *xmldb_cache_get(clixon_handle h, const char *db);
int xmldb_modified_get(clicon_handle h, const char *db); int xmldb_modified_get(clixon_handle h, const char *db);
int xmldb_modified_set(clicon_handle h, const char *db, int value); int xmldb_modified_set(clixon_handle h, const char *db, int value);
int xmldb_empty_get(clicon_handle h, const char *db); int xmldb_empty_get(clixon_handle h, const char *db);
int xmldb_dump(clicon_handle h, FILE *f, cxobj *xt); int xmldb_dump(clixon_handle h, FILE *f, cxobj *xt);
int xmldb_print(clicon_handle h, FILE *f); int xmldb_print(clixon_handle h, FILE *f);
int xmldb_rename(clicon_handle h, const char *db, const char *newdb, const char *suffix); int xmldb_rename(clixon_handle h, const char *db, const char *newdb, const char *suffix);
#endif /* _CLIXON_DATASTORE_H */ #endif /* _CLIXON_DATASTORE_H */

60
lib/clixon/clixon_debug.h Normal file
View file

@ -0,0 +1,60 @@
/*
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC (Netgate)
This file is part of CLIXON.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 3 or later (the "GPL"),
in which case the provisions of the GPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of the GPL, and not to allow others to
use your version of this file under the terms of Apache License version 2,
indicate your decision by deleting the provisions above and replace them with
the notice and other provisions required by the GPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK *****
*
* Clixon debugging
*/
#ifndef _CLIXON_DEBUG_H_
#define _CLIXON_DEBUG_H_
/*
* Constants
*/
/* Debug-level masks */
#define CLIXON_DBG_DEFAULT 1 /* Default logs */
#define CLIXON_DBG_MSG 2 /* In/out messages and datastore reads */
#define CLIXON_DBG_DETAIL 4 /* Details: traces, parse trees, etc */
#define CLIXON_DBG_EXTRA 8 /* Extra Detailed logs */
/*
* Prototypes
*/
int clixon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int clixon_debug_init(clixon_handle h, int dbglevel);
int clixon_debug_get(void);
#endif /* _CLIXON_DEBUG_H_ */

View file

@ -35,9 +35,9 @@
* *
* Errors may be syslogged using LOG_ERR, and printed to stderr, as controlled by * Errors may be syslogged using LOG_ERR, and printed to stderr, as controlled by
* clicon_log_init * clixon_log_init
* global error variables are set: * Details about the errors may be retreievd by access functions
* clicon_errno, clicon_suberrno, clicon_err_reason. * clixon_err_reason(), clixon_err_subnr(), etc
*/ */
#ifndef _CLIXON_ERR_H_ #ifndef _CLIXON_ERR_H_
@ -58,7 +58,7 @@
* Add error category here, * Add error category here,
* @see EV variable in clixon_err.c but must also add an entry there * @see EV variable in clixon_err.c but must also add an entry there
*/ */
enum clicon_err{ enum clixon_err{
/* 0 means error not set) */ /* 0 means error not set) */
OE_DB = 1, /* database registries */ OE_DB = 1, /* database registries */
OE_DAEMON, /* daemons: pidfiles, etc */ OE_DAEMON, /* daemons: pidfiles, etc */
@ -91,28 +91,35 @@ enum clicon_err{
*/ */
typedef int (clixon_cat_log_cb)(void *handle, int suberr, cbuf *cb); typedef int (clixon_cat_log_cb)(void *handle, int suberr, cbuf *cb);
/*
* Variables
* XXX: should not be global
*/
extern int clicon_errno; /* CLICON errors (see clicon_err) */
extern int clicon_suberrno; /* Eg orig errno */
extern char clicon_err_reason[ERR_STRLEN];
/* /*
* Macros * Macros
*/ */
#define clicon_err(e,s,_fmt, args...) clicon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args) #define clixon_err(e,s,_fmt, args...) clixon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args)
/* /*
* Prototypes * Prototypes
*/ */
int clicon_err_reset(void); int clixon_err_init(clixon_handle h);
int clicon_err_fn(const char *fn, const int line, int category, int err, const char *format, ...) __attribute__ ((format (printf, 5, 6))); int clixon_err_category(void);
char *clicon_strerror(int err); int clixon_err_subnr(void);
void *clicon_err_save(void); char *clixon_err_reason(void);
int clicon_err_restore(void *handle); char *clixon_err_str(void);
int clixon_err_cat_reg(enum clicon_err category, void *handle, clixon_cat_log_cb logfn); int clixon_err_reset(void);
int clixon_err_args(clixon_handle h, const char *fn, const int line, int category, int suberr, char *msg);
int clixon_err_fn(const char *fn, const int line, int category, int err, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
void *clixon_err_save(void);
int clixon_err_restore(void *handle);
int clixon_err_cat_reg(enum clixon_err category, void *handle, clixon_cat_log_cb logfn);
int clixon_err_exit(void); int clixon_err_exit(void);
#if 1 /* COMPAT_6_5 */
#define clicon_err(e,s,_fmt, args...) clixon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args)
#define clicon_err_reset() clixon_err_reset()
#define clicon_errno clixon_err_category()
#define clicon_suberrno clixon_err_subnr()
#define clicon_err_reason clixon_err_reason()
#endif
#endif /* _CLIXON_ERR_H_ */ #endif /* _CLIXON_ERR_H_ */

View file

@ -66,7 +66,7 @@ int clixon_event_unreg_timeout(int (*fn)(int, void*), void *arg);
int clixon_event_poll(int fd); int clixon_event_poll(int fd);
int clixon_event_loop(clicon_handle h); int clixon_event_loop(clixon_handle h);
int clixon_event_exit(void); int clixon_event_exit(void);

View file

@ -47,7 +47,6 @@
cli/backend/netconf or other plugin. But this is hidden under-the-hood. cli/backend/netconf or other plugin. But this is hidden under-the-hood.
*/ */
typedef void *clixon_handle; typedef void *clixon_handle;
typedef void *clicon_handle;
/* The dynamicically loadable plugin object handle (should be in clixon_plugin.h) */ /* The dynamicically loadable plugin object handle (should be in clixon_plugin.h) */
typedef void *plghndl_t; typedef void *plghndl_t;
@ -67,30 +66,37 @@ typedef int (clicon_output_cb)(
* Prototypes * Prototypes
*/ */
/* Basic CLICON init functions returning a handle for API access. */ /* Basic CLICON init functions returning a handle for API access. */
clicon_handle clicon_handle_init(void); clixon_handle clixon_handle_init(void);
/* Internal call to allocate a CLICON handle. */ /* Internal call to allocate a CLICON handle. */
clicon_handle clicon_handle_init0(int size); clixon_handle clixon_handle_init0(int size);
/* Deallocate handle */ /* Deallocate handle */
int clicon_handle_exit(clicon_handle h); int clixon_handle_exit(clixon_handle h);
/* Check struct magic number for sanity checks */ /* Check struct magic number for sanity checks */
int clicon_handle_check(clicon_handle h); int clixon_handle_check(clixon_handle h);
/* Return clicon options (hash-array) given a handle.*/ /* Return clicon options (hash-array) given a handle.*/
clicon_hash_t *clicon_options(clicon_handle h); clicon_hash_t *clicon_options(clixon_handle h);
/* Return internal clicon data (hash-array) given a handle.*/ /* Return internal clicon data (hash-array) given a handle.*/
clicon_hash_t *clicon_data(clicon_handle h); clicon_hash_t *clicon_data(clixon_handle h);
/* Return internal clicon db_elmnt (hash-array) given a handle.*/ /* Return internal clicon db_elmnt (hash-array) given a handle.*/
clicon_hash_t *clicon_db_elmnt(clicon_handle h); clicon_hash_t *clicon_db_elmnt(clixon_handle h);
/* Return internal stream hash-array given a handle.*/ /* Return internal stream hash-array given a handle.*/
struct event_stream *clicon_stream(clicon_handle h); struct event_stream *clicon_stream(clixon_handle h);
struct event_stream; struct event_stream;
int clicon_stream_set(clicon_handle h, struct event_stream *es); int clicon_stream_set(clixon_handle h, struct event_stream *es);
int clicon_stream_append(clicon_handle h, struct event_stream *es); int clicon_stream_append(clixon_handle h, struct event_stream *es);
/* COMPAT_6_5 */
#if 1
typedef void *clicon_handle;
#define clicon_handle_init() clixon_handle_init()
#define clicon_handle_exit(h) clixon_handle_exit(h)
#endif
#endif /* _CLIXON_HANDLE_H_ */ #endif /* _CLIXON_HANDLE_H_ */

View file

@ -34,7 +34,7 @@
***** END LICENSE BLOCK ***** ***** END LICENSE BLOCK *****
* *
* Regular logging and debugging. Syslog using levels. * Regular logging, syslog using levels.
*/ */
#ifndef _CLIXON_LOG_H_ #ifndef _CLIXON_LOG_H_
@ -44,38 +44,38 @@
* Constants * Constants
*/ */
/* Where to log (masks) */ /* Where to log (masks) */
#define CLICON_LOG_SYSLOG 1 /* print logs on syslog */ #define CLIXON_LOG_SYSLOG 1 /* print logs on syslog */
#define CLICON_LOG_STDERR 2 /* print logs on stderr */ #define CLIXON_LOG_STDERR 2 /* print logs on stderr */
#define CLICON_LOG_STDOUT 4 /* print logs on stdout */ #define CLIXON_LOG_STDOUT 4 /* print logs on stdout */
#define CLICON_LOG_FILE 8 /* print logs on clicon_log_filename */ #define CLIXON_LOG_FILE 8 /* print logs on clicon_log_filename */
/* Debug-level masks */
#define CLIXON_DBG_DEFAULT 1 /* Default logs */
#define CLIXON_DBG_MSG 2 /* In/out messages and datastore reads */
#define CLIXON_DBG_DETAIL 4 /* Details: traces, parse trees, etc */
#define CLIXON_DBG_EXTRA 8 /* Extra Detailed logs */
/* /*
* Prototypes * Prototypes
*/ */
int clicon_log_init(char *ident, int upto, int flags); int clixon_log_init(clixon_handle h, char *ident, int upto, int flags);
int clicon_log_exit(void); int clixon_log_exit(void);
int clicon_log_opt(char c); int clixon_log_opt(char c);
int clicon_log_file(char *filename); int clixon_log_file(char *filename);
int clicon_log_string_limit_set(size_t sz); int clixon_log_string_limit_set(size_t sz);
size_t clicon_log_string_limit_get(void); size_t clixon_log_string_limit_get(void);
int clicon_get_logflags(void); int clixon_get_logflags(void);
int clicon_log_str(int level, char *msg); int clixon_log_str(int level, char *msg);
int clicon_log(int level, const char *format, ...) __attribute__ ((format (printf, 2, 3))); int clixon_log(clixon_handle h, int level, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int clixon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3))); char *clixon_log_mon2name(int md);
int clixon_debug_init(int dbglevel, FILE *f);
int clixon_debug_get(void); #if 1 /* COMPAT_6_5 */
char *mon2name(int md); #define CLICON_LOG_SYSLOG CLIXON_LOG_SYSLOG
#define CLICON_LOG_STDERR CLIXON_LOG_STDERR
#define CLICON_LOG_STDOUT CLIXON_LOG_STDOUT
#define CLICON_LOG_FILE CLIXON_LOG_FILE
#define clicon_log(l, f, args...) clixon_log(NULL, (l), (f), ##args)
#define clicon_log_exit() clixon_log_exit()
#define clicon_log_opt(c) clixon_log_opt((c))
#define clicon_log_file(f) clixon_log_file((f))
int clicon_log_init(char *ident, int upto, int flags);
#endif /* COMPAT_6_5 */
/* 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_ */ #endif /* _CLIXON_LOG_H_ */

View file

@ -57,12 +57,12 @@ enum nacm_access{
* Prototypes * Prototypes
*/ */
int nacm_rpc(char *rpc, char *module, char *username, cxobj *xnacm, cbuf *cbret); int nacm_rpc(char *rpc, char *module, char *username, cxobj *xnacm, cbuf *cbret);
int nacm_datanode_read(clicon_handle h, cxobj *xt, cxobj **xvec, size_t xlen, char *username, int nacm_datanode_read(clixon_handle h, cxobj *xt, cxobj **xvec, size_t xlen, char *username,
cxobj *nacm_xtree); cxobj *nacm_xtree);
int nacm_datanode_write(clicon_handle h, cxobj *xr, cxobj *xt, int nacm_datanode_write(clixon_handle h, cxobj *xr, cxobj *xt,
enum nacm_access access, enum nacm_access access,
char *username, cxobj *xnacm, cbuf *cbret); char *username, cxobj *xnacm, cbuf *cbret);
int nacm_access_pre(clicon_handle h, char *peername, char *username, cxobj **xnacmp); int nacm_access_pre(clixon_handle h, char *peername, char *username, cxobj **xnacmp);
int verify_nacm_user(clicon_handle h, enum nacm_credentials_t cred, char *peername, char *nacmname, cbuf *cbret); int verify_nacm_user(clixon_handle h, enum nacm_credentials_t cred, char *peername, char *nacmname, cbuf *cbret);
#endif /* _CLIXON_NACM_H */ #endif /* _CLIXON_NACM_H */

View file

@ -147,14 +147,6 @@ typedef enum withdefaults_type withdefaults_type;
/* /*
* Macros * 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)
*/
#define clixon_netconf_error(h, x, f, a) clixon_netconf_error_fn((h), __FUNCTION__, __LINE__, (x), (f), (a))
/* /*
* Prototypes * Prototypes
*/ */
@ -196,24 +188,34 @@ int netconf_data_not_unique(cbuf *cb, cxobj *x, cvec *cvk);
int netconf_data_not_unique_xml(cxobj **xret, cxobj *x, cvec *cvk); int netconf_data_not_unique_xml(cxobj **xret, cxobj *x, cvec *cvk);
int netconf_minmax_elements_xml(cxobj **xret, cxobj *xp, char *name, int max); int netconf_minmax_elements_xml(cxobj **xret, cxobj *xp, char *name, int max);
int netconf_trymerge(cxobj *x, yang_stmt *yspec, cxobj **xret); int netconf_trymerge(cxobj *x, yang_stmt *yspec, cxobj **xret);
int netconf_module_features(clicon_handle h); int netconf_module_features(clixon_handle h);
int netconf_module_load(clicon_handle h); int netconf_module_load(clixon_handle h);
char *netconf_db_find(cxobj *xn, char *name); char *netconf_db_find(cxobj *xn, char *name);
int netconf_err2cb(clicon_handle h, cxobj *xerr, cbuf *cberr);
const netconf_content netconf_content_str2int(char *str); const netconf_content netconf_content_str2int(char *str);
const char *netconf_content_int2str(netconf_content nr); const char *netconf_content_int2str(netconf_content nr);
int netconf_capabilites(clicon_handle h, cbuf *cb); int netconf_capabilites(clixon_handle h, cbuf *cb);
int netconf_hello_server(clicon_handle h, cbuf *cb, uint32_t session_id); int netconf_hello_server(clixon_handle h, cbuf *cb, uint32_t session_id);
int netconf_hello_req(clicon_handle h, cbuf *cb); int netconf_hello_req(clixon_handle h, cbuf *cb);
int clixon_netconf_error_fn(clicon_handle h, const char *fn, const int line, cxobj *xerr, const char *fmt, const char *arg);
int clixon_netconf_internal_error(cxobj *xerr, char *msg, char *arg); int clixon_netconf_internal_error(cxobj *xerr, char *msg, char *arg);
int netconf_parse_uint32(char *name, char *valstr, char *defaultstr, uint32_t defaultval, cbuf *cbret, uint32_t *value); int netconf_parse_uint32(char *name, char *valstr, char *defaultstr, uint32_t defaultval, cbuf *cbret, uint32_t *value);
int netconf_parse_uint32_xml(char *name, char *valstr, char *defaultstr, uint32_t defaultval, cxobj **xerr, uint32_t *value); int netconf_parse_uint32_xml(char *name, char *valstr, char *defaultstr, uint32_t defaultval, cxobj **xerr, uint32_t *value);
int netconf_message_id_next(clicon_handle h); int netconf_message_id_next(clixon_handle h);
int netconf_framing_preamble(netconf_framing_type framing, cbuf *cb); int netconf_framing_preamble(netconf_framing_type framing, cbuf *cb);
int netconf_framing_postamble(netconf_framing_type framing, cbuf *cb); int netconf_framing_postamble(netconf_framing_type framing, cbuf *cb);
int netconf_output(int s, cbuf *xf, char *msg); int netconf_output(int s, cbuf *xf, char *msg);
int netconf_output_encap(netconf_framing_type framing, cbuf *cb); int netconf_output_encap(netconf_framing_type framing, cbuf *cb);
int netconf_input_chunked_framing(char ch, int *state, size_t *size); int netconf_input_chunked_framing(char ch, int *state, size_t *size);
/* Netconf error handling */
#define clixon_err_netconf(h,c,s,x,_fmt, args...) clixon_err_netconf_fn((h), __FUNCTION__, __LINE__, (c), (s), (x), _fmt , ##args)
int netconf_err2cb(clixon_handle h, cxobj *xerr, cbuf *cberr);
int clixon_err_netconf_fn(clixon_handle h, const char *fn, const int line, int category,
int suberr, cxobj *xerr, const char *format, ...) __attribute__ ((format (printf, 7, 8)));;
#if 1 /* COMPAT_6_5 */
/* doesnt work if arg != NULL */
#define clixon_netconf_error(h, x, f, a) clixon_err_netconf_fn((h), __FUNCTION__, __LINE__, OE_XML, 0,(x), (f) , NULL)
#endif
#endif /* _CLIXON_NETCONF_LIB_H */ #endif /* _CLIXON_NETCONF_LIB_H */

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