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

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

View file

@ -150,21 +150,24 @@ fdpass(int nfd)
}
/*! Create and bind stream socket
*
* @param[in] sa Socketaddress
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
* @param[in] backlog Listen backlog, queie of pending connections
* @param[out] sock Server socket (bound for accept)
* @retval 0 OK
* @retval -1 Error
*/
int
callhome_bind(struct sockaddr *sa,
size_t sin_len,
size_t sin_len,
int backlog,
int *sock)
{
int retval = -1;
int s = -1;
int on = 1;
if (sock == NULL){
errno = EINVAL;
perror("sock");
@ -274,7 +277,7 @@ main(int argc,
sin6.sin6_port = htons(port);
sin6.sin6_family = AF_INET6;
inet_pton(AF_INET6, addr, &sin6.sin6_addr);
sa = (struct sockaddr *)&sin6;
sa = (struct sockaddr *)&sin6;
}
else if (strcmp(family, "ipv4") == 0){
sin_len = sizeof(struct sockaddr_in);
@ -288,7 +291,7 @@ main(int argc,
goto done;
}
/* Bind port */
if (callhome_bind(sa, sin_len, 1, &ss) < 0)
if (callhome_bind(sa, sin_len, 1, &ss) < 0)
goto done;
/* Wait until connect */
len = sizeof(from);

View file

@ -136,21 +136,24 @@ static int _event_trace = 0;
static FILE *_event_f = NULL; /* set to stdout in main */
/*! Create and bind stream socket
*
* @param[in] sa Socketaddress
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
* @param[in] backlog Listen backlog, queie of pending connections
* @param[out] sock Server socket (bound for accept)
* @retval 0 OK
* @retval -1 Error
*/
int
callhome_bind(struct sockaddr *sa,
size_t sin_len,
size_t sin_len,
int backlog,
int *sock)
{
int retval = -1;
int s = -1;
int on = 1;
if (sock == NULL){
errno = EINVAL;
perror("sock");
@ -193,6 +196,7 @@ callhome_bind(struct sockaddr *sa,
}
/*! read data from file return a malloced buffer
*
* Note same file is reread multiple times: same request/reply is made each iteration
* Also, the file read is limited to 1024 bytes
*/
@ -243,13 +247,13 @@ tls_write_file(FILE *fp,
size_t len = 0;
int ret;
int sslerr;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (read_data_file(fp, &buf, &len) < 0)
goto done;
if ((ret = SSL_write(ssl, buf, len)) < 1){
sslerr = SSL_get_error(ssl, ret);
clicon_debug(1, "%s SSL_write() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_write() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
}
retval = 0;
done:
@ -259,12 +263,13 @@ tls_write_file(FILE *fp,
}
/*! Client data socket, receive reply from server
*
* Print info on stdout
* If keep_open = 0, then close socket directly after 1st reply (client close)
* If keep_open = 1, then keep socket open (server close)
*/
static int
tls_server_reply_cb(int s,
tls_server_reply_cb(int s,
void *arg)
{
int retval = -1;
@ -276,15 +281,15 @@ tls_server_reply_cb(int s,
struct timeval now;
struct timeval td;
static int seq = 0; // from start
// clicon_debug(1, "%s", __FUNCTION__);
// clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
ssl = sd->sd_ssl;
/* get reply & decrypt */
if ((n = SSL_read(ssl, buf, sizeof(buf))) < 0){
clicon_err(OE_XML, errno, "SSL_read");
goto done;
}
clicon_debug(1, "%s n:%d", __FUNCTION__, n);
clixon_debug(CLIXON_DBG_DEFAULT, "%s n:%d", __FUNCTION__, n);
gettimeofday(&now, NULL);
timersub(&now, &sd->sd_t0, &td); /* from start of connection */
if (n == 0){ /* Server closed socket */
@ -317,11 +322,10 @@ tls_server_reply_cb(int s,
usleep(100000); /* XXX This is a blocking timeout */
/* Write HTTP request on socket */
if (tls_write_file(_input_file, sd->sd_ssl) < 0)
goto done;
goto done;
}
else if (!_idle){
clicon_debug(1, "%s idle", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s idle", __FUNCTION__);
SSL_shutdown(ssl);
SSL_free(ssl);
clixon_event_unreg_fd(s, tls_server_reply_cb);
@ -331,7 +335,7 @@ tls_server_reply_cb(int s,
if (_accepts == 0)
;
else if (_accepts == 1){
clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */
clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */
fprintf(_event_f, "Exit: %s idle\n", __FUNCTION__);
}
else
@ -343,7 +347,7 @@ tls_server_reply_cb(int s,
done:
if (expbuf)
free(expbuf);
clicon_debug(1, "%s ret:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s ret:%d", __FUNCTION__, retval);
return retval;
}
@ -360,7 +364,7 @@ tls_ssl_init_connect(SSL_CTX *ctx,
int ret;
int verify;
int sslerr;
/* create new SSL connection state */
if ((ssl = SSL_new(ctx)) == NULL){
clicon_err(OE_SSL, 0, "SSL_new.");
@ -380,7 +384,7 @@ tls_ssl_init_connect(SSL_CTX *ctx,
SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len);
#endif
/* perform the connection
/* perform the connection
TLSEXT_TYPE_application_layer_protocol_negotiation
int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
unsigned int protos_len);
@ -389,7 +393,7 @@ tls_ssl_init_connect(SSL_CTX *ctx,
*/
if ((ret = SSL_connect(ssl)) < 1){
sslerr = SSL_get_error(ssl, ret);
clicon_debug(1, "%s SSL_read() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_read() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr);
switch (sslerr){
case SSL_ERROR_SSL: /* 1 */
@ -453,7 +457,7 @@ tls_client_timeout(void *arg)
/*! Callhome-server accept socket
*/
static int
tls_server_accept_cb(int ss,
tls_server_accept_cb(int ss,
void *arg)
{
int retval = -1;
@ -464,17 +468,17 @@ tls_server_accept_cb(int ss,
socklen_t len;
SSL *ssl = NULL;
struct timeval td;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
len = sizeof(from);
if ((s = accept(ss, &from, &len)) < 0){
perror("accept");
goto done;
}
clicon_debug(1, "accepted");
clixon_debug(CLIXON_DBG_DEFAULT, "accepted");
if (tls_ssl_init_connect(ta->ta_ctx, s, &ssl) < 0)
goto done;
clicon_debug(1, "connected");
clixon_debug(CLIXON_DBG_DEFAULT, "connected");
if ((sd = malloc(sizeof(*sd))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -502,8 +506,7 @@ tls_server_accept_cb(int ss,
return retval;
}
/*!
* out must be set to point to the selected protocol (which may be within in).
/*! Out must be set to point to the selected protocol (which may be within in).
*/
static int
tls_proto_select_cb(SSL *s,
@ -513,11 +516,12 @@ tls_proto_select_cb(SSL *s,
unsigned int inlen,
void *arg)
{
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
/*! Verify tls auth
*
* @see tlsauth_verify_callback
* This code needs a "X509 store", see X509_STORE_new()
* crl_file / crl_dir
@ -535,7 +539,7 @@ tls_ctx_init(const char *cert_path,
const char *ca_cert_path)
{
SSL_CTX *ctx = NULL;
if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) {
clicon_err(OE_SSL, 0, "SSL_CTX_new");
goto done;
@ -611,7 +615,7 @@ main(int argc,
char *family = "inet:ipv4-address";
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
goto done;
while ((c = getopt(argc, argv, UTIL_TLS_OPTS)) != -1)
@ -685,11 +689,11 @@ main(int argc,
fprintf(stderr, "-c <cert path> and -k <key path> -C <ca-cert> are mandatory\n");
usage(argv[0]);
}
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
if (input_filename){
if ((_input_file = fopen(input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
goto done;
}
}
@ -708,9 +712,9 @@ main(int argc,
if (clixon_inet2sin(family, addr, port, sa, &sa_len) < 0)
goto done;
/* Bind port */
if (callhome_bind(sa, sa_len, 1, &ss) < 0)
if (callhome_bind(sa, sa_len, 1, &ss) < 0)
goto done;
clicon_debug(1, "callhome_bind %s:%hu", addr, port);
clixon_debug(CLIXON_DBG_DEFAULT, "callhome_bind %s:%hu", addr, port);
if ((ta = malloc(sizeof(*ta))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -739,7 +743,7 @@ main(int argc,
SSL_CTX_free(ctx); /* release context */
clicon_handle_exit(h); /* frees h and options (and streams) */
clixon_err_exit();
clicon_debug(1, "clixon_restconf_callhome_client pid:%u done", getpid());
clicon_log_exit(); /* Must be after last clicon_debug */
clixon_debug(CLIXON_DBG_DEFAULT, "clixon_restconf_callhome_client pid:%u done", getpid());
clicon_log_exit(); /* Must be after last clixon_debug */
return retval;
}

View file

@ -180,8 +180,8 @@ main(int argc, char **argv)
/*
* Logs, error and debug to stderr, set debug level
*/
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_debug_init(dbg, NULL);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clixon_debug_init(dbg, NULL);
argc -= optind;
argv += optind;

View file

@ -141,10 +141,8 @@ main(int argc,
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init("xpath", dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
/* Now rest of options */
clixon_debug_init(dbg, NULL);
/* Now rest of options */
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, DISPATCHER_OPTS)) != -1){
@ -167,7 +165,7 @@ main(int argc,
case 'r' :{ /* register callback based on -a/-i/-p*/
dispatcher_definition x = {regpath, fn, arg};
if (dispatcher_register_handler(&htable, &x) < 0)
goto done;
goto done;
break;
}
case 'c':{ /* Execute a call using path */

View file

@ -95,7 +95,7 @@ print_header(const uint8_t *name,
const uint8_t *value,
size_t valuelen)
{
clicon_debug(1, "%s %s", name, value);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", name, value);
}
/* Print HTTP headers to |f|. Please note that this function does not
@ -107,7 +107,7 @@ print_headers(nghttp2_nv *nva,
{
size_t i;
for (i = 0; i < nvlen; ++i)
for (i = 0; i < nvlen; ++i)
print_header(nva[i].name, nva[i].namelen, nva[i].value, nva[i].valuelen);
}
#endif /* DEBUG */
@ -126,8 +126,7 @@ send_callback(nghttp2_session *session,
session_data *sd = (session_data*)user_data;
int ret;
clicon_debug(1, "%s %zu:", __FUNCTION__, length);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %zu:", __FUNCTION__, length);
#if 0
{
int i;
@ -150,11 +149,11 @@ on_frame_recv_callback(nghttp2_session *session,
void *user_data)
{
//session_data *sd = (session_data*)user_data;
clicon_debug(1, "%s %d", __FUNCTION__, frame->hd.stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, frame->hd.stream_id);
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_RESPONSE)
clicon_debug(1, "All headers received %d", frame->hd.stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "All headers received %d", frame->hd.stream_id);
return 0;
}
@ -170,8 +169,8 @@ on_data_chunk_recv_callback(nghttp2_session *session,
void *user_data)
{
session_data *sd = (session_data*)user_data;
clicon_debug(1, "%s %d", __FUNCTION__, stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, stream_id);
if (sd->sd_session == session &&
sd->sd_stream_id == stream_id)
fwrite(data, 1, len, stdout); /* This is where data is printed */
@ -187,8 +186,8 @@ on_stream_close_callback(nghttp2_session *session,
void *user_data)
{
//session_data *sd = (session_data*)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -205,10 +204,10 @@ on_header_callback(nghttp2_session *session,
void *user_data)
{
// session_data *sd = (session_data*)user_data;
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_RESPONSE){
clicon_debug(1, "%s %d:", __FUNCTION__, frame->hd.stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d:", __FUNCTION__, frame->hd.stream_id);
print_header(name, namelen, value, valuelen);
}
return 0;
@ -225,7 +224,7 @@ on_begin_headers_callback(nghttp2_session *session,
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_RESPONSE)
clicon_debug(1, "%s Response headers %d",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Response headers %d",
__FUNCTION__, frame->hd.stream_id);
return 0;
}
@ -264,7 +263,7 @@ send_client_connection_header(nghttp2_session *session)
{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}};
int rv;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* client 24 bytes magic string will be sent by nghttp2 library */
rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, ARRLEN(iv));
if (rv != 0) {
@ -277,8 +276,7 @@ send_client_connection_header(nghttp2_session *session)
}
/*!
* Sets sd->sd_stream_id
/*! Sets sd->sd_stream_id
*/
static int
submit_request(session_data *sd,
@ -294,7 +292,7 @@ submit_request(session_data *sd,
MAKE_NV(":path", path, strlen(path))
};
clicon_debug(1, "%s Request headers:", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Request headers:", __FUNCTION__);
print_headers(hdrs, ARRLEN(hdrs));
if ((sd->sd_stream_id = nghttp2_submit_request(sd->sd_session,
NULL,
@ -324,7 +322,7 @@ socket_connect_inet(char *hostname,
struct hostent *host;
int one = 1;
clicon_debug(1, "%s to %s:%hu", __FUNCTION__, hostname, port);
clixon_debug(CLIXON_DBG_DEFAULT, "%s to %s:%hu", __FUNCTION__, hostname, port);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
@ -371,10 +369,10 @@ select_next_proto_cb(SSL *ssl,
unsigned int inlen,
void *arg)
{
clicon_debug(1, "%s", __FUNCTION__);
if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0)
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0)
return -1;
clicon_debug(1, "%s out: %s in:%s", __FUNCTION__, *out, in);
clixon_debug(CLIXON_DBG_DEFAULT, "%s out: %s in:%s", __FUNCTION__, *out, in);
return SSL_TLSEXT_ERR_OK;
}
@ -384,7 +382,7 @@ InitCTX(void)
{
const SSL_METHOD *method;
SSL_CTX *ctx;
#if 1
method = SSLv23_client_method();
#else
@ -414,7 +412,7 @@ InitCTX(void)
}
static int
ssl_input_cb(int s,
ssl_input_cb(int s,
void *arg)
{
int retval = -1;
@ -424,7 +422,7 @@ ssl_input_cb(int s,
int n;
nghttp2_session *session;
int readlen;
ssl = sd->sd_ssl;
session = sd->sd_session;
/* get reply & decrypt */
@ -481,8 +479,7 @@ main(int argc,
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
goto done;
while ((c = getopt(argc, argv, UTIL_GRPC_OPTS)) != -1)
@ -505,7 +502,7 @@ main(int argc,
fprintf(stderr, "-H <hostname> is mandatory\n");
usage(argv[0]);
}
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
SSL_library_init();
if ((ctx = InitCTX()) == NULL)
goto done;

View file

@ -99,7 +99,7 @@ main(int argc,
int ret;
int pretty = 0;
int dbg = 0;
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, "hD:jl:py:")) != -1)
@ -129,7 +129,7 @@ main(int argc,
break;
}
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
if (yang_filename){
if ((yspec = yspec_new()) == NULL)

View file

@ -111,9 +111,9 @@ main(int argc,
cxobj *xerr = NULL; /* malloced must be freed */
int nr = 1;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init("api-path", LOG_DEBUG, CLICON_LOG_STDERR);
clicon_log_init("api-path", LOG_DEBUG, CLICON_LOG_STDERR);
/* Initialize clixon handle */
if ((h = clicon_handle_init()) == NULL)
goto done;
@ -122,7 +122,6 @@ main(int argc,
goto done;
if (clicon_conf_xml_set(h, xcfg) < 0)
goto done;
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, UTIL_PATH_OPTS)) != -1)
@ -161,7 +160,7 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Parse yang */
@ -191,7 +190,7 @@ main(int argc,
}
memset(buf, 0, len);
i = 0;
while (1){
while (1){
if ((ret = read(0, &c, 1)) < 0){
perror("read");
goto done;
@ -204,7 +203,7 @@ main(int argc,
if ((buf = realloc(buf, 2*len)) == NULL){
fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno));
return -1;
}
}
memset(buf+len, 0, len);
len *= 2;
}
@ -213,7 +212,7 @@ main(int argc,
path = buf;
}
/*
/*
* If fp=stdin, then continue reading from stdin (after CR)
* XXX Note 0 above, stdin here
*/
@ -245,7 +244,7 @@ main(int argc,
/* Add default values */
if (xml_default_recurse(x, 0) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0)
if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0)
goto done;

View file

@ -60,10 +60,11 @@
#include "clixon/clixon.h"
/*! libxml2 regex implementation
*
* @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028
* @retval -1 Error
* @retval 0 Not match
* @retval 1 Match
* @retval 0 Not match
* @retval -1 Error
*/
static int
regex_libxml2(char *regexp0,
@ -110,7 +111,7 @@ regex_posix(char *regexp,
if (regexp_xsd2posix(regexp, &posix) < 0)
goto done;
clicon_debug(1, "posix: %s", posix);
clixon_debug(CLIXON_DBG_DEFAULT, "posix: %s", posix);
len0 = strlen(posix);
if (len0 > sizeof(pattern)-5){
fprintf(stderr, "pattern too long\n");
@ -200,8 +201,8 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_debug_init(dbg, NULL);
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clixon_debug_init(dbg, NULL);
if (regexp == NULL){
fprintf(stderr, "-r mandatory\n");
@ -215,8 +216,8 @@ main(int argc,
fprintf(stderr, "Neither posix or libxml2 set\n");
usage(argv0);
}
clicon_debug(1, "regexp:%s", regexp);
clicon_debug(1, "content:%s", content);
clixon_debug(CLIXON_DBG_DEFAULT, "regexp:%s", regexp);
clixon_debug(CLIXON_DBG_DEFAULT, "content:%s", content);
if (mode == 0){
if ((ret = regex_posix(regexp, content, nr, dbg)) < 0)
goto done;

View file

@ -103,11 +103,9 @@ main(int argc,
int eof = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
goto done;
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, "hD:s:f:Ja:")) != -1)
@ -136,7 +134,7 @@ main(int argc,
break;
}
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
if (sockpath == NULL){
fprintf(stderr, "Mandatory option missing: -s <sockpath>\n");
@ -144,7 +142,7 @@ main(int argc,
}
if (input_filename){
if ((fp = fopen(input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
goto done;
}
}

View file

@ -96,7 +96,7 @@ print_header(const uint8_t *name,
const uint8_t *value,
size_t valuelen)
{
clicon_debug(1, "%s %s", name, value);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", name, value);
}
/* Print HTTP headers to |f|. Please note that this function does not
@ -108,7 +108,7 @@ print_headers(nghttp2_nv *nva,
{
size_t i;
for (i = 0; i < nvlen; ++i)
for (i = 0; i < nvlen; ++i)
print_header(nva[i].name, nva[i].namelen, nva[i].value, nva[i].valuelen);
}
#endif /* DEBUG */
@ -126,8 +126,8 @@ send_callback(nghttp2_session *session,
{
session_data *sd = (session_data*)user_data;
int ret;
clicon_debug(1, "%s %zu:", __FUNCTION__, length);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %zu:", __FUNCTION__, length);
#if 0
{
int i;
@ -150,11 +150,10 @@ on_frame_recv_callback(nghttp2_session *session,
void *user_data)
{
//session_data *sd = (session_data*)user_data;
clicon_debug(1, "%s %d", __FUNCTION__, frame->hd.stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, frame->hd.stream_id);
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_RESPONSE)
clicon_debug(1, "All headers received %d", frame->hd.stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "All headers received %d", frame->hd.stream_id);
return 0;
}
@ -170,8 +169,8 @@ on_data_chunk_recv_callback(nghttp2_session *session,
void *user_data)
{
session_data *sd = (session_data*)user_data;
clicon_debug(1, "%s %d", __FUNCTION__, stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, stream_id);
if (sd->sd_session == session &&
sd->sd_stream_id == stream_id)
fwrite(data, 1, len, stdout); /* This is where data is printed */
@ -187,8 +186,8 @@ on_stream_close_callback(nghttp2_session *session,
void *user_data)
{
//session_data *sd = (session_data*)user_data;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
return 0;
}
@ -205,10 +204,10 @@ on_header_callback(nghttp2_session *session,
void *user_data)
{
// session_data *sd = (session_data*)user_data;
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_RESPONSE){
clicon_debug(1, "%s %d:", __FUNCTION__, frame->hd.stream_id);
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d:", __FUNCTION__, frame->hd.stream_id);
print_header(name, namelen, value, valuelen);
}
return 0;
@ -225,7 +224,7 @@ on_begin_headers_callback(nghttp2_session *session,
if (frame->hd.type == NGHTTP2_HEADERS &&
frame->headers.cat == NGHTTP2_HCAT_RESPONSE)
clicon_debug(1, "%s Response headers %d",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Response headers %d",
__FUNCTION__, frame->hd.stream_id);
return 0;
}
@ -264,7 +263,7 @@ send_client_connection_header(nghttp2_session *session)
{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}};
int rv;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* client 24 bytes magic string will be sent by nghttp2 library */
rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, ARRLEN(iv));
if (rv != 0) {
@ -277,8 +276,7 @@ send_client_connection_header(nghttp2_session *session)
}
/*!
* Sets sd->sd_stream_id
/*! Sets sd->sd_stream_id
*/
static int
submit_request(session_data *sd,
@ -294,7 +292,7 @@ submit_request(session_data *sd,
MAKE_NV(":path", path, strlen(path))
};
clicon_debug(1, "%s Request headers:", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Request headers:", __FUNCTION__);
print_headers(hdrs, ARRLEN(hdrs));
if ((sd->sd_stream_id = nghttp2_submit_request(sd->sd_session,
NULL,
@ -324,7 +322,7 @@ socket_connect_inet(char *hostname,
struct hostent *host;
int one = 1;
clicon_debug(1, "%s to %s:%hu", __FUNCTION__, hostname, port);
clixon_debug(CLIXON_DBG_DEFAULT, "%s to %s:%hu", __FUNCTION__, hostname, port);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
@ -371,10 +369,10 @@ select_next_proto_cb(SSL *ssl,
unsigned int inlen,
void *arg)
{
clicon_debug(1, "%s", __FUNCTION__);
if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0)
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0)
return -1;
clicon_debug(1, "%s out: %s in:%s", __FUNCTION__, *out, in);
clixon_debug(CLIXON_DBG_DEFAULT, "%s out: %s in:%s", __FUNCTION__, *out, in);
return SSL_TLSEXT_ERR_OK;
}
@ -384,7 +382,7 @@ InitCTX(void)
{
const SSL_METHOD *method;
SSL_CTX *ctx;
#if 1
method = SSLv23_client_method();
#else
@ -414,7 +412,7 @@ InitCTX(void)
}
static int
ssl_input_cb(int s,
ssl_input_cb(int s,
void *arg)
{
int retval = -1;
@ -424,7 +422,7 @@ ssl_input_cb(int s,
int n;
nghttp2_session *session;
int readlen;
ssl = sd->sd_ssl;
session = sd->sd_session;
/* get reply & decrypt */
@ -481,8 +479,7 @@ main(int argc,
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
goto done;
while ((c = getopt(argc, argv, UTIL_SSL_OPTS)) != -1)
@ -505,7 +502,7 @@ main(int argc,
fprintf(stderr, "-H <hostname> is mandatory\n");
usage(argv[0]);
}
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
SSL_library_init();
if ((ctx = InitCTX()) == NULL)
goto done;

View file

@ -73,9 +73,9 @@ struct curlbuf{
* realloc. Therefore, we append new data to the userdata buffer.
*/
static size_t
curl_get_cb(void *ptr,
size_t size,
size_t nmemb,
curl_get_cb(void *ptr,
size_t size,
size_t nmemb,
void *userdata)
{
struct curlbuf *buf = (struct curlbuf *)userdata;
@ -96,17 +96,17 @@ curl_get_cb(void *ptr,
* If getdata is set, return the (malloced) data (which should be freed).
*
* @param[in] start 'start-time' parameter that will be URL-encoded
* @retval -1 fatal error
* @retval 1 ok
* @retval -1 fatal error
*
* @note curl_easy_perform blocks
* @note New handle is created every time, the handle can be re-used for
* better TCP performance
*/
int
stream_url_get(char *url,
stream_url_get(char *url,
char *start,
char *stop,
char *stop,
int timeout,
char **getdata)
{
@ -119,7 +119,7 @@ stream_url_get(char *url,
struct curl_slist *list = NULL;
int ret;
clicon_debug(1, "%s: curl -G %s start-time=%s stop-time=%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s: curl -G %s start-time=%s stop-time=%s",
__FUNCTION__, url, start?start:"", stop?stop:"");
/* Set up curl for doing the communication with the controller */
if ((curl = curl_easy_init()) == NULL) {
@ -130,7 +130,7 @@ stream_url_get(char *url,
goto done;
if ((err = malloc(CURL_ERROR_SIZE)) == NULL) {
clicon_debug(1, "%s: malloc", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: malloc", __FUNCTION__);
goto done;
}
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
@ -139,7 +139,7 @@ stream_url_get(char *url,
// list = curl_slist_append(list, "Cache-Control: no-cache");
// list = curl_slist_append(list, "Connection: keep-alive");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
/* specify URL to get */
/* specify URL to get */
cprintf(cbf, "%s", url);
if (strlen(start)||strlen(stop))
cprintf(cbf, "?");
@ -159,17 +159,16 @@ stream_url_get(char *url,
curl_free(encoded);
encoded = NULL;
}
clicon_debug(1, "url: %s\n", cbuf_get(cbf));
clixon_debug(CLIXON_DBG_DEFAULT, "url: %s\n", cbuf_get(cbf));
curl_easy_setopt(curl, CURLOPT_URL, cbuf_get(cbf));
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_get_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cb);
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
ret = curl_easy_perform(curl);
if (ret != CURLE_OPERATION_TIMEDOUT && ret != CURLE_OK){
fprintf(stderr, "curl: %s %d", err, ret);
@ -190,7 +189,7 @@ stream_url_get(char *url,
if (cb.b_buf)
free(cb.b_buf);
if (curl)
curl_easy_cleanup(curl); /* cleanup */
curl_easy_cleanup(curl); /* cleanup */
return retval;
}
@ -224,7 +223,7 @@ main(int argc, char **argv)
struct timeval now;
int dbg = 0;
clicon_log_init("xpath", LOG_DEBUG, CLICON_LOG_STDERR);
clicon_log_init("xpath", LOG_DEBUG, CLICON_LOG_STDERR);
gettimeofday(&now, NULL);
optind = 1;
opterr = 0;
@ -266,7 +265,7 @@ main(int argc, char **argv)
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
if (url == NULL)
usage(argv[0]);
curl_global_init(0);

View file

@ -101,7 +101,7 @@ main(int argc,
cbuf *cb = NULL;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
/* Initialize clixon handle */
if ((h = clicon_handle_init()) == NULL)
@ -133,7 +133,7 @@ main(int argc,
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Find and read configfile */
if (clicon_options_main(h) < 0)
@ -172,7 +172,7 @@ main(int argc,
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);
/* Add (hardcoded) netconf features in case ietf-netconf loaded here
* Otherwise it is loaded in netconf_module_load below
*/
@ -182,7 +182,7 @@ main(int argc,
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
goto done;
clicon_dbspec_yang_set(h, yspec);
clicon_dbspec_yang_set(h, yspec);
/* Load backend plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_backend_dir(h)) != NULL &&
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir,

View file

@ -85,7 +85,7 @@ validate_tree(clicon_handle h,
goto done;
if (xml_apply(xt, -1, xml_sort_verify, h) < 0)
clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__);
if ((ret = xml_yang_validate_all_top(h, xt, &xerr)) < 0)
if ((ret = xml_yang_validate_all_top(h, xt, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, xt, &xerr)) < 0)
goto done;
@ -163,12 +163,12 @@ main(int argc,
cxobj *xtop = NULL; /* Top tree if any */
char *top_path = NULL;
cxobj *xbot; /* Place in xtop where base cxobj is parsed */
cvec *nsc = NULL;
cvec *nsc = NULL;
yang_bind yb;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
/* Initialize clixon handle */
if ((h = clicon_handle_init()) == NULL)
@ -245,9 +245,8 @@ main(int argc,
usage(argv[0]);
}
clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* 1. Parse yang */
if (yang_file_dir){
if ((yspec = yspec_new()) == NULL)
@ -271,7 +270,7 @@ main(int argc,
*/
if (top_input_filename){
if ((tfp = fopen(top_input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename);
clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename);
goto done;
}
if ((ret = clixon_xml_parse_file(tfp, YB_MODULE, yspec, &xtop, &xerr)) < 0){
@ -296,7 +295,7 @@ main(int argc,
}
if (input_filename){
if ((fp = fopen(input_filename, "r")) == NULL){
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
clicon_err(OE_YANG, errno, "open(%s)", input_filename);
goto done;
}
}

View file

@ -133,8 +133,8 @@ main(int argc, char **argv)
char *reason = NULL;
int dbg = 0;
cxobj *xcfg = NULL;
clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR);
clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR);
if ((h = clicon_handle_init()) == NULL)
goto done;
if ((xcfg = xml_new("clixon-config", NULL, CX_ELMNT)) == NULL)
@ -168,7 +168,7 @@ main(int argc, char **argv)
case 'x': /* XML to insert */
x1str = optarg;
break;
case 'p': /* XPATH base */
case 'p': /* XPath base */
xpath = optarg;
break;
case 's': /* sort output after insert */
@ -181,9 +181,9 @@ main(int argc, char **argv)
/* Sanity check: check mandatory arguments */
if (x1str == NULL || x0str == NULL || yangfile == NULL)
usage(argv0);
if (opx == OPX_ERROR)
if (opx == OPX_ERROR)
usage(argv0);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_spec_parse_file(h, yangfile, yspec) < 0)
@ -204,8 +204,8 @@ main(int argc, char **argv)
clicon_err(OE_XML, 0, "xpath: %s not found in x0", xpath);
goto done;
}
if (clicon_debug_get()){
clicon_debug(1, "xb:");
if (clixon_debug_get()){
clixon_debug(CLIXON_DBG_DEFAULT, "xb:");
xml_print(stderr, xb);
}
switch (opx){
@ -236,7 +236,7 @@ main(int argc, char **argv)
clicon_err(OE_XML, 0, "xpath: %s not found in xi", xpath);
goto done;
}
if ((ret = xml_merge(xb, xi, yspec, &reason)) < 0)
if ((ret = xml_merge(xb, xi, yspec, &reason)) < 0)
goto done;
if (ret == 0){
clicon_err(OE_XML, 0, "%s", reason);
@ -269,14 +269,14 @@ main(int argc, char **argv)
/* Remove it from parent */
if (xml_rm(xi1) < 0)
goto done;
if (xml_insert(xb, xi1, INS_LAST, NULL, NULL) < 0)
if (xml_insert(xb, xi1, INS_LAST, NULL, NULL) < 0)
goto done;
break;
default:
usage(argv0);
}
if (clicon_debug_get()){
clicon_debug(1, "x0:");
if (clixon_debug_get()){
clixon_debug(CLIXON_DBG_DEFAULT, "x0:");
xml_print(stderr, x0);
}
if (sort)

View file

@ -70,8 +70,8 @@ usage(char *argv0)
"\t-h \t\tHelp\n"
"\t-D <level> \tDebug\n"
"\t-f <file> \tXML file\n"
"\t-p <xpath> \tPrimary XPATH string\n"
"\t-i <xpath0>\t(optional) Initial XPATH string\n"
"\t-p <xpath> \tPrimary XPath string\n"
"\t-i <xpath0>\t(optional) Initial XPath string\n"
"\t-I \t\tCheck inverse, map back xml result to xpath and check if equal\n"
"\t-n <pfx:id>\tNamespace binding (pfx=NULL for default)\n"
"\t-c \t\tMap xpath to canonical form\n"
@ -179,10 +179,10 @@ main(int argc,
goto done;
}
break;
case 'p': /* Primary XPATH string */
case 'p': /* Primary XPath string */
xpath = optarg;
break;
case 'i': /* Optional initial XPATH string */
case 'i': /* Optional initial XPath string */
xpath0 = optarg;
break;
case 'I': /* Check inverse */
@ -234,10 +234,8 @@ main(int argc,
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init("xpath", dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Parse yang */
if (yang_file_dir){
if ((yspec = yspec_new()) == NULL)
@ -265,7 +263,7 @@ main(int argc,
}
memset(buf, 0, len);
i = 0;
while (1){
while (1){
if ((ret = read(0, &c, 1)) < 0){
perror("read");
goto done;
@ -278,7 +276,7 @@ main(int argc,
if ((buf = realloc(buf, 2*len)) == NULL){
fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno));
return -1;
}
}
memset(buf+len, 0, len);
len *= 2;
}
@ -292,7 +290,7 @@ main(int argc,
char *xpath1 = NULL;
cvec *nsc1 = NULL;
cbuf *cbreason = NULL;
if ((ret = xpath2canonical(xpath, nsc, yspec, &xpath1, &nsc1, &cbreason)) < 0)
goto done;
if (ret == 0){
@ -309,7 +307,7 @@ main(int argc,
cvec_print(stdout, nsc);
goto ok; /* need a switch to continue, now just print and quit */
}
/*
/*
* If fp=stdin, then continue reading from stdin (after CR)
* XXX Note 0 above, stdin here
*/
@ -342,7 +340,7 @@ main(int argc,
goto done;
if (xml_apply0(x0, -1, xml_sort_verify, h) < 0)
clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__);
if ((ret = xml_yang_validate_all_top(h, x0, &xerr)) < 0)
if ((ret = xml_yang_validate_all_top(h, x0, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, x0, &xerr)) < 0)
goto done;
@ -357,7 +355,6 @@ main(int argc,
goto done;
}
}
/* If xpath0 given, position current x (ie somewhere else than root) */
if (xpath0){
if ((x = xpath_first(x0, NULL, "%s", xpath0)) == NULL){

View file

@ -104,7 +104,7 @@ main(int argc, char **argv)
break;
}
clicon_log_init("clixon_util_yang", dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_parse_file(stdin, "yang test", yspec) == NULL){