diff --git a/apps/restconf/Makefile.in b/apps/restconf/Makefile.in index 45a7f62d..6443f7be 100644 --- a/apps/restconf/Makefile.in +++ b/apps/restconf/Makefile.in @@ -56,6 +56,7 @@ HOST_VENDOR = @host_vendor@ wwwdir = @wwwdir@ wwwuser = @wwwuser@ with_libhttp = @with_libhttp@ +with_evhtp = @with_evhtp@ SH_SUFFIX = @SH_SUFFIX@ CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@ @@ -71,6 +72,9 @@ LIBS = -L$(top_srcdir)/lib/src @LIBS@ $(top_srcdir)/lib/src/$(CLIXON_LI ifeq ($(with_libhttp),yes) LIBS += -ldl -lpthread endif +ifeq ($(with_evhtp),yes) +LIBS += -lpthread -levent -levent_openssl -lssl -lcrypto +endif CPPFLAGS = @CPPFLAGS@ -fPIC @@ -81,6 +85,9 @@ APPLS = clixon_restconf # fcgi / nginx ifeq ($(with_libhttp),yes) APPLS += clixon_restconf_libhttp endif +ifeq ($(with_evhtp),yes) +APPLS += clixon_restconf_evhtp +endif # Common source - not accessible from plugin - independent of fcgi APPSRC = restconf_lib.c @@ -100,6 +107,11 @@ ifeq ($(with_libhttp),yes) APPLIBH = restconf_libhttp_main.c APPLIBHOBJ = $(APPLIBH:.c=.o) endif +ifeq ($(with_evhtp),yes) +# Evhtp-specific source including main +APPEVHTPH = restconf_evhtp_main.c +APPEVHTPOBJ = $(APPEVHTPH:.c=.o) +endif all: $(APPLS) @@ -112,6 +124,9 @@ clean: ifeq ($(with_libhttp),yes) rm -f $(APPLIBHOBJ) endif +ifeq ($(with_evhtp),yes) + rm -f $(APPEVHTPOBJ) +endif distclean: clean rm -f Makefile *~ .depend @@ -148,6 +163,11 @@ clixon_restconf_libhttp : $(APPOBJ) $(APPLIBHOBJ) $(LIBDEPS) $(CC) $(LDFLAGS) $(APPOBJ) $(APPLIBHOBJ) -L. $(LIBS) -o $@ endif +ifeq ($(with_evhtp),yes) +clixon_restconf_evhtp : $(APPOBJ) $(APPEVHTPOBJ) $(LIBDEPS) + $(CC) $(LDFLAGS) $(APPOBJ) $(APPEVHTPOBJ) -L. $(LIBS) -o $@ +endif + TAGS: find . -name '*.[chyl]' -print | etags - diff --git a/apps/restconf/restconf_evhtp_main.c b/apps/restconf/restconf_evhtp_main.c new file mode 100644 index 00000000..d2a1be3c --- /dev/null +++ b/apps/restconf/restconf_evhtp_main.c @@ -0,0 +1,497 @@ +/* + * + ***** BEGIN LICENSE BLOCK ***** + + Copyright (C) 2009-2019 Olof Hagsand + Copyright (C) 2020 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 ***** + + */ + +/* XXX temp constant should go away, */ +#undef _EVHTP_NYI + +#ifdef HAVE_CONFIG_H +#include "clixon_config.h" /* generated by config & autoconf */ +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* chmod */ + +/* evhtp */ +#include +#include + +/* cligen */ +#include + +/* clicon */ +#include + +/* restconf */ + +#include "restconf_lib.h" +#if 0 /* These are all dependent on FCGX */ +#include "restconf_methods.h" +#include "restconf_methods_get.h" +#include "restconf_methods_post.h" +#include "restconf_stream.h" +#endif + +/* Command line options to be passed to getopt(3) */ +#define RESTCONF_OPTS "hD:f:l:p:d:y:a:u:o:P:c:k:" + +/* Need global variable to for signal handler XXX */ +static clicon_handle _CLICON_HANDLE = NULL; + +/*! Signall terminates process + */ +static void +restconf_sig_term(int arg) +{ + static int i=0; + + if (i++ == 0) + clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", + __PROGRAM__, __FUNCTION__, getpid(), arg); + else + exit(-1); + if (_CLICON_HANDLE){ +#ifdef _EVHTP_NYI + stream_child_freeall(_CLICON_HANDLE); +#endif + restconf_terminate(_CLICON_HANDLE); + } + clicon_exit_set(); /* checked in event_loop() */ + exit(-1); +} + +static void +restconf_sig_child(int arg) +{ + int status; + int pid; + + if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status)){ +#ifdef _EVHTP_NYI + ; +#endif + } +} + +/*! Generic callback called if no other callbacks are matched + */ +static void +cx_generic_callback(evhtp_request_t *req, + void *arg) +{ + evhtp_connection_t * conn; + + fprintf(stderr, "%s\n", __FUNCTION__); + if (req == NULL){ + errno = EINVAL; + return; + } + if ((conn = evhtp_request_get_connection(req)) == NULL) + return; + + htp_sslutil_add_xheaders( + req->headers_out, + conn->ssl, + HTP_SSLUTILS_XHDR_ALL); + + return evhtp_send_reply(req, EVHTP_RES_OK); +} + +/*! Usage help routine + * @param[in] argv0 command line + * @param[in] h Clicon handle + */ +static void +usage(clicon_handle h, + char *argv0) + +{ + fprintf(stderr, "usage:%s [options]\n" + "where options are\n" + "\t-h \t\t Help\n" + "\t-D \t Debug level\n" + "\t-f \t Configuration file (mandatory)\n" + "\t-l > \t Log on (s)yslog, (f)ile (syslog is default)\n" + "\t-p \t Yang directory path (see CLICON_YANG_DIR)\n" + "\t-d \t Specify restconf plugin directory dir (default: %s)\n" + "\t-y \t Load yang spec file (override yang main module)\n" + "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n" + "\t-u \t Internal socket domain path or IP addr (see -a)\n" + "\t-o \"