From b711faade9a110b2f252ae617c87a74676b69709 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 11 Jun 2021 14:38:48 +0200 Subject: [PATCH] grpc in shape --- lib/src/clixon_datastore_write.c | 1 + util/Makefile.in | 31 +++++++++++++++++-------------- util/clixon_util_grpc.c | 19 +++++++++---------- util/clixon_util_ssl.c | 6 +++--- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 4c78d41b..a90259fb 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -452,6 +452,7 @@ text_modify(clicon_handle h, * Check if namespace exists in x0 parent * if not add new binding and replace in x0. * See also xmlns copying of attributes in the body section below + * Note that this may add "unnecessary" namespace declarations */ if (assign_namespace_element(x1, x0, x0p) < 0) goto done; diff --git a/util/Makefile.in b/util/Makefile.in index 6b51773a..6528f195 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -86,14 +86,17 @@ APPSRC += clixon_util_xpath.c APPSRC += clixon_util_path.c APPSRC += clixon_util_datastore.c APPSRC += clixon_util_regexp.c -ifdef with_restconf -APPSRC += clixon_util_stream.c # Needs curl -endif APPSRC += clixon_util_socket.c APPSRC += clixon_netconf_ssh_callhome.c APPSRC += clixon_netconf_ssh_callhome_client.c -#APPSRC += clixon_util_ssl.c -#APPSRC += clixon_util_grpc.c +ifdef with_restconf +APPSRC += clixon_util_stream.c # Needs curl +endif +ifdef with_http2 +APPSRC += clixon_util_ssl.c # requires http/2 +#APPSRC += clixon_util_grpc.c # work in progress +endif + APPS = $(APPSRC:.c=) @@ -132,19 +135,19 @@ clixon_util_xml_mod: clixon_util_xml_mod.c $(LIBDEPS) clixon_util_regexp: clixon_util_regexp.c $(LIBDEPS) $(CC) $(INCLUDES) -I /usr/include/libxml2 $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -o $@ -ifdef with_restconf -clixon_util_stream: clixon_util_stream.c $(LIBDEPS) - $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lcurl -o $@ -endif - clixon_util_socket: clixon_util_socket.c $(LIBDEPS) $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -o $@ -#clixon_util_ssl: clixon_util_ssl.c $(LIBDEPS) -# $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lnghttp2 -lssl -lcrypto -o $@ +ifdef with_restconf +clixon_util_stream: clixon_util_stream.c $(LIBDEPS) + $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lcurl -o $@ -#clixon_util_grpc: clixon_util_grpc.c $(LIBDEPS) -# $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lnghttp2 -lssl -lcrypto -o $@ +clixon_util_ssl: clixon_util_ssl.c $(LIBDEPS) + $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -o $@ + +clixon_util_grpc: clixon_util_grpc.c $(LIBDEPS) + $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -o $@ +endif distclean: clean rm -f Makefile *~ .depend diff --git a/util/clixon_util_grpc.c b/util/clixon_util_grpc.c index 922926d9..ff2fe75f 100644 --- a/util/clixon_util_grpc.c +++ b/util/clixon_util_grpc.c @@ -33,14 +33,11 @@ ***** END LICENSE BLOCK ***** - * XML support functions. - * @see https://www.w3.org/TR/2008/REC-xml-20081126 - * https://www.w3.org/TR/2009/REC-xml-names-20091208 - * The function can do yang validation, process xml and json, etc. - * On success, nothing is printed and exitcode 0 - * On failure, an error is printed on stderr and exitcode != 0 - * Failure error prints are different, it would be nice to make them more - * uniform. (see clixon_netconf_error) + * + * HTTP2 + OPENSSL client integrated with clixon events + * Ubuntu package: + * apt install libnghttp2-dev + * Example run: clixon_util_ssl -H nghttp2.org */ #ifdef HAVE_CONFIG_H @@ -130,7 +127,7 @@ send_callback(nghttp2_session *session, int ret; - clicon_debug(1, "%s %d:", __FUNCTION__, length); + clicon_debug(1, "%s %zu:", __FUNCTION__, length); #if 0 { int i; @@ -481,6 +478,7 @@ main(int argc, int ret; nghttp2_session *session = NULL; session_data *sd = NULL; + int dbg = 0; /* In the startup, logs to stderr & debug flag set later */ clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); @@ -493,7 +491,7 @@ main(int argc, usage(argv[0]); break; case 'D': - if (sscanf(optarg, "%d", &debug) != 1) + if (sscanf(optarg, "%d", &dbg) != 1) usage(argv[0]); break; case 'H': /* hostname */ @@ -507,6 +505,7 @@ main(int argc, fprintf(stderr, "-H is mandatory\n"); usage(argv[0]); } + clicon_debug_init(dbg, NULL); SSL_library_init(); if ((ctx = InitCTX()) == NULL) goto done; diff --git a/util/clixon_util_ssl.c b/util/clixon_util_ssl.c index facc6ba0..68a17aa1 100644 --- a/util/clixon_util_ssl.c +++ b/util/clixon_util_ssl.c @@ -33,8 +33,7 @@ ***** END LICENSE BLOCK ***** - * - * HTTP2 + OPENSSL client integrated with clixon events + * Actually HTTP2 + OPENSSL client integrated with clixon events * Ubuntu package: * apt install libnghttp2-dev * Example run: clixon_util_ssl -H nghttp2.org @@ -54,9 +53,10 @@ #include /* inet_pton */ #include /* TCP_NODELAY */ - #include +#ifdef HAVE_LIBNGHTTP2 #include +#endif /* cligen */ #include