[Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)

* Applies to all c/h/y/l/sh files and .editorconfig
This commit is contained in:
Olof hagsand 2022-10-27 14:21:17 +02:00
parent a9d1ab006c
commit d84c529ff1
376 changed files with 38147 additions and 38133 deletions

View file

@ -73,7 +73,7 @@
*/
static int
restconf_pseudo_set_log(clicon_handle h,
cxobj *xt)
cxobj *xt)
{
int retval = -1;
char **argv;
@ -84,47 +84,47 @@ restconf_pseudo_set_log(clicon_handle h,
cxobj *xb;
if ((xb = xpath_first(xt, NULL, "/restconf/log-destination")) != NULL)
log = xml_body(xb);
log = xml_body(xb);
if ((xb = xpath_first(xt, NULL, "/restconf/debug")) != NULL)
dbg = xml_body(xb);
dbg = xml_body(xb);
if (dbg == NULL && log == NULL)
goto ok;
goto ok;
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
goto done;
goto done;
for (i=0; i<argc; i++){
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-l") == 0 && argc > i+1 && argv[i+1]){
if (log){
if (strcmp(log, "syslog") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("s")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
else if (strcmp(log, "file") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
}
i++;
}
if (strcmp(argv[i], "-D") == 0 && argc > i+1 && argv[i+1]){
if (dbg){
free(argv[i+1]);
if ((argv[i+1] = strdup(dbg)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
i++;
}
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-l") == 0 && argc > i+1 && argv[i+1]){
if (log){
if (strcmp(log, "syslog") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("s")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
else if (strcmp(log, "file") == 0){
if (argv[i+1])
free(argv[i+1]);
if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
}
i++;
}
if (strcmp(argv[i], "-D") == 0 && argc > i+1 && argv[i+1]){
if (dbg){
free(argv[i+1]);
if ((argv[i+1] = strdup(dbg)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
}
i++;
}
}
ok:
retval = 0;
@ -141,7 +141,7 @@ restconf_pseudo_set_log(clicon_handle h,
*/
static int
restconf_pseudo_set_inline(clicon_handle h,
cxobj *xt)
cxobj *xt)
{
int retval = -1;
char **argv;
@ -153,33 +153,33 @@ restconf_pseudo_set_inline(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0)
goto done;
goto done;
if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL)
for (i=0; i<argc; i++){
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0)
goto done;
if ((str = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_XML, errno, "stdup");
goto done;
}
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
if (argv[i+1])
free(argv[i+1]);
argv[i+1] = str;
break;
}
}
for (i=0; i<argc; i++){
if (argv[i] == NULL)
break;
if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0)
goto done;
if ((str = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_XML, errno, "stdup");
goto done;
}
clicon_debug(1, "%s str:%s", __FUNCTION__, str);
if (argv[i+1])
free(argv[i+1]);
argv[i+1] = str;
break;
}
}
retval = 0;
done:
if (cb)
cbuf_free(cb);
cbuf_free(cb);
return retval;
}
@ -190,8 +190,8 @@ restconf_pseudo_set_inline(clicon_handle h,
*/
int
restconf_rpc_wrapper(clicon_handle h,
process_entry_t *pe,
proc_operation *operation)
process_entry_t *pe,
proc_operation *operation)
{
int retval = -1;
cxobj *xt = NULL;
@ -199,36 +199,36 @@ restconf_rpc_wrapper(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
switch (*operation){
case PROC_OP_STOP:
/* if RPC op is stop, stop the service */
break;
/* if RPC op is stop, stop the service */
break;
case PROC_OP_START:
/* RPC op is start & enable is true, then start the service,
/* RPC op is start & enable is true, then start the service,
& enable is false, error or ignore it */
if (xmldb_get(h, "running", NULL, "/restconf", &xt) < 0)
goto done;
if (xt != NULL &&
xpath_first(xt, NULL, "/restconf[enable='false']") != NULL) {
*operation = PROC_OP_NONE;
}
else{
/* Get debug flag of restconf config, set the restconf start -D daemon flag according
* to it. The restconf daemon cannoit read its debug flag from config initially,
* but in this way it is set directly in its input args.
* Its a trick.
*/
if (restconf_pseudo_set_log(h, xt) < 0)
goto done;
if (restconf_pseudo_set_inline(h, xt) < 0)
goto done;
}
break;
if (xmldb_get(h, "running", NULL, "/restconf", &xt) < 0)
goto done;
if (xt != NULL &&
xpath_first(xt, NULL, "/restconf[enable='false']") != NULL) {
*operation = PROC_OP_NONE;
}
else{
/* Get debug flag of restconf config, set the restconf start -D daemon flag according
* to it. The restconf daemon cannoit read its debug flag from config initially,
* but in this way it is set directly in its input args.
* Its a trick.
*/
if (restconf_pseudo_set_log(h, xt) < 0)
goto done;
if (restconf_pseudo_set_inline(h, xt) < 0)
goto done;
}
break;
default:
break;
break;
}
retval = 0;
done:
if (xt)
xml_free(xt);
xml_free(xt);
return retval;
}
@ -255,13 +255,13 @@ restconf_pseudo_process_control(clicon_handle h)
nr = 10;
if ((argv = calloc(nr, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
goto done;
clicon_err(OE_UNIX, errno, "calloc");
goto done;
}
i = 0;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
/* Try to figure out where clixon_restconf is installed
* If config option CLICON_RESTCONF_INSTALLDIR is installed, use that.
@ -269,32 +269,32 @@ restconf_pseudo_process_control(clicon_handle h)
* Use PATH?
*/
if ((dir0 = clicon_option_str(h, "CLICON_RESTCONF_INSTALLDIR")) != NULL){
cprintf(cb, "%s/clixon_restconf", dir0);
pgm = cbuf_get(cb);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
cprintf(cb, "%s/clixon_restconf", dir0);
pgm = cbuf_get(cb);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
}
if (!found &&
(dir1 = CLIXON_CONFIG_SBINDIR) != NULL){
cbuf_reset(cb);
cprintf(cb, "%s/clixon_restconf", dir1);
pgm = cbuf_get(cb);
clicon_debug(1, "Looking for %s", pgm);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
(dir1 = CLIXON_CONFIG_SBINDIR) != NULL){
cbuf_reset(cb);
cprintf(cb, "%s/clixon_restconf", dir1);
pgm = cbuf_get(cb);
clicon_debug(1, "Looking for %s", pgm);
if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */
clicon_debug(1, "Found %s", pgm);
found++;
}
else
clicon_debug(1, "Not found: %s", pgm);
}
if (!found){
clicon_err(OE_RESTCONF, 0, "clixon_restconf not found in neither CLICON_RESTCONF_INSTALLDIR(%s) nor CLIXON_CONFIG_SBINDIR(%s). Try overriding with CLICON_RESTCONF_INSTALLDIR",
dir0, dir1);
goto done;
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",
dir0, dir1);
goto done;
}
argv[i++] = pgm;
argv[i++] = "-f";
@ -312,17 +312,17 @@ restconf_pseudo_process_control(clicon_handle h)
argv[i++] = NULL;
assert(i==nr);
if (clixon_process_register(h, RESTCONF_PROCESS,
"Clixon RESTCONF process",
NULL /* XXX network namespace */,
restconf_rpc_wrapper,
argv, nr) < 0)
goto done;
"Clixon RESTCONF process",
NULL /* XXX network namespace */,
restconf_rpc_wrapper,
argv, nr) < 0)
goto done;
if (argv != NULL)
free(argv);
free(argv);
retval = 0;
done:
if (cb)
cbuf_free(cb);
cbuf_free(cb);
return retval;
}
@ -330,7 +330,7 @@ restconf_pseudo_process_control(clicon_handle h)
*/
static int
restconf_pseudo_process_validate(clicon_handle h,
transaction_data td)
transaction_data td)
{
int retval = -1;
cxobj *xtarget;
@ -340,16 +340,16 @@ restconf_pseudo_process_validate(clicon_handle h,
/* If ssl-enable is true and (at least a) socket has ssl,
* then server-cert-path and server-key-path must exist */
if (xpath_first(xtarget, NULL, "restconf/enable[.='true']") &&
xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){
/* Should filepath be checked? One could claim this is a runtime system,... */
if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set");
return -1; /* induce fail */
}
if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-key-path not set");
return -1; /* induce fail */
}
xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){
/* Should filepath be checked? One could claim this is a runtime system,... */
if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set");
return -1; /* induce fail */
}
if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){
clicon_err(OE_CFG, 0, "SSL enabled but server-key-path not set");
return -1; /* induce fail */
}
}
retval = 0;
return retval;
@ -359,7 +359,7 @@ restconf_pseudo_process_validate(clicon_handle h,
*/
static int
restconf_pseudo_process_commit(clicon_handle h,
transaction_data td)
transaction_data td)
{
int retval = -1;
cxobj *xtarget;
@ -371,45 +371,45 @@ restconf_pseudo_process_commit(clicon_handle h,
xtarget = transaction_target(td);
xsource = transaction_src(td);
if (xpath_first(xtarget, NULL, "/restconf[enable='true']") != NULL)
enabled++;
enabled++;
/* Get debug flag of restconf config, set the restconf start -D daemon flag according
* to it. The restconf daemon cannoit read its debug flag from config initially,
* but in this way it is set directly in its input args.
* Its a trick.
*/
if (restconf_pseudo_set_log(h, xtarget) < 0)
goto done;
goto done;
if (restconf_pseudo_set_inline(h, xtarget) < 0)
goto done;
goto done;
/* Toggle start/stop if enable flag changed */
if ((cx = xpath_first(xtarget, NULL, "/restconf/enable")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
if (clixon_process_operation(h, RESTCONF_PROCESS,
enabled?PROC_OP_START:PROC_OP_STOP, 0) < 0)
goto done;
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
if (clixon_process_operation(h, RESTCONF_PROCESS,
enabled?PROC_OP_START:PROC_OP_STOP, 0) < 0)
goto done;
}
else if (enabled){ /* If something changed and running, restart process */
if (transaction_dlen(td) != 0 ||
transaction_alen(td) != 0 ||
transaction_clen(td) != 0){
if ((cx = xpath_first(xtarget, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
/* A restart can terminate a restconf connection (cut the tree limb you are sitting on)
* Specifically, the socket is terminated where the reply is sent, which will
* cause the curl to fail.
* Note that it should really be a START if the process is stopped, but the
* commit code need not know any of that
*/
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
else if ((cx = xpath_first(xsource, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_DEL)){
/* Or something deleted */
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
}
if (transaction_dlen(td) != 0 ||
transaction_alen(td) != 0 ||
transaction_clen(td) != 0){
if ((cx = xpath_first(xtarget, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_ADD)){
/* A restart can terminate a restconf connection (cut the tree limb you are sitting on)
* Specifically, the socket is terminated where the reply is sent, which will
* cause the curl to fail.
* Note that it should really be a START if the process is stopped, but the
* commit code need not know any of that
*/
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
else if ((cx = xpath_first(xsource, NULL, "/restconf")) != NULL &&
xml_flag(cx, XML_FLAG_CHANGE|XML_FLAG_DEL)){
/* Or something deleted */
if (clixon_process_operation(h, RESTCONF_PROCESS, PROC_OP_RESTART, 0) < 0)
goto done;
}
}
}
retval = 0;
done:
@ -421,20 +421,20 @@ restconf_pseudo_process_commit(clicon_handle h,
*/
int
backend_plugin_restconf_register(clicon_handle h,
yang_stmt *yspec)
yang_stmt *yspec)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
if (clixon_pseudo_plugin(h, "restconf pseudo plugin", &cp) < 0)
goto done;
goto done;
clixon_plugin_api_get(cp)->ca_trans_validate = restconf_pseudo_process_validate;
clixon_plugin_api_get(cp)->ca_trans_commit = restconf_pseudo_process_commit;
/* Register generic process-control of restconf daemon, ie start/stop restconf */
if (restconf_pseudo_process_control(h) < 0)
goto done;
goto done;
retval = 0;
done:
return retval;