Dispatcher test additions
This commit is contained in:
parent
d2d3454177
commit
93d1149925
7 changed files with 72 additions and 16 deletions
|
|
@ -105,6 +105,6 @@ struct _dispatcher_entry {
|
|||
int dispatcher_register_handler(dispatcher_entry_t **root, dispatcher_definition *x);
|
||||
int dispatcher_call_handlers(dispatcher_entry_t *root, void *handle, char *path, void *user_args);
|
||||
int dispatcher_free(dispatcher_entry_t *root);
|
||||
int dispatcher_print(FILE *f, dispatcher_entry_t *root);
|
||||
int dispatcher_print(FILE *f, int level, dispatcher_entry_t *root);
|
||||
|
||||
#endif /* _CLIXON_DISPATCH_DISPATCHER_H */
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@
|
|||
* Types
|
||||
*/
|
||||
|
||||
|
||||
/*! Registered RPC callback function
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xn Request: <rpc><xn></rpc>
|
||||
|
|
@ -201,7 +200,7 @@ typedef int (plgreset_t)(clicon_handle h, const char *db);
|
|||
* A complete valid XML tree is created by the plugin and sent back via xtop, which is merged
|
||||
* into a complete state tree by the system.
|
||||
* The plugin should ensure that xpath is matched (using namspace context nsc)
|
||||
* This callback may be replaced with a "dispatcher" type API in the future where the
|
||||
* XXX: This callback may be replaced with a "dispatcher" type API in the future where the
|
||||
* XPath binding is stricter, similar to the pagination API.
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
|
|
|
|||
|
|
@ -1,5 +1,36 @@
|
|||
/*
|
||||
* Copyright 2021 Rubicon Communications LLC (Netgate)
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2021 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 *****
|
||||
|
||||
* @see https://github.com/dcornejo/dispatcher
|
||||
*/
|
||||
|
||||
|
|
@ -285,11 +316,8 @@ get_entry(dispatcher_entry_t *root,
|
|||
|
||||
/* some elements may have keys defined, strip them off */
|
||||
for (int i = 0; i < split_path_len; i++) {
|
||||
char *kptr = strchr(split_path_list[i], '=');
|
||||
|
||||
if ((kptr != NULL) && (*kptr == '=')) {
|
||||
*(kptr + 1) = 0;
|
||||
}
|
||||
char *kptr = split_path_list[i];
|
||||
strsep(&kptr, "=[]");
|
||||
}
|
||||
|
||||
/* search down the tree */
|
||||
|
|
@ -423,8 +451,12 @@ dispatcher_call_handlers(dispatcher_entry_t *root,
|
|||
void *user_args)
|
||||
{
|
||||
int ret = 0;
|
||||
dispatcher_entry_t *best = get_entry(root, path);
|
||||
dispatcher_entry_t *best;
|
||||
|
||||
if ((best = get_entry(root, path)) == NULL){
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (best->children != NULL) {
|
||||
call_handler_helper(best->children, handle, path, user_args);
|
||||
}
|
||||
|
|
@ -450,3 +482,24 @@ dispatcher_free(dispatcher_entry_t *root)
|
|||
free(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Pretty-print dispatcher tree
|
||||
*/
|
||||
#define INDENT 3
|
||||
int
|
||||
dispatcher_print(FILE *f,
|
||||
int level,
|
||||
dispatcher_entry_t *de)
|
||||
{
|
||||
fprintf(f, "%*s%s", level*INDENT, "", de->node_name);
|
||||
if (de->handler)
|
||||
fprintf(f, " %p", de->handler);
|
||||
if (de->arg)
|
||||
fprintf(f, " (%p)", de->arg);
|
||||
fprintf(f, "\n");
|
||||
if (de->children)
|
||||
dispatcher_print(f, level+1, de->children);
|
||||
if (de->peer)
|
||||
dispatcher_print(f, level, de->peer);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3585,7 +3585,7 @@ yang_extension_value(yang_stmt *ys,
|
|||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
yext = NULL; /* This loop gets complicated in trhe case the extension is augmented */
|
||||
yext = NULL; /* This loop gets complicated in the case the extension is augmented */
|
||||
while ((yext = yn_each(ys, yext)) != NULL) {
|
||||
if (yang_keyword_get(yext) != Y_UNKNOWN)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ APPSRC += clixon_util_datastore.c
|
|||
APPSRC += clixon_util_regexp.c
|
||||
APPSRC += clixon_util_socket.c
|
||||
APPSRC += clixon_util_validate.c
|
||||
APPSRC += clixon_util_dispatcher.c
|
||||
APPSRC += clixon_netconf_ssh_callhome.c
|
||||
APPSRC += clixon_netconf_ssh_callhome_client.c
|
||||
ifdef with_restconf
|
||||
|
|
@ -149,6 +150,9 @@ clixon_util_socket: clixon_util_socket.c $(LIBDEPS)
|
|||
clixon_util_validate: clixon_util_validate.c $(LIBDEPS)
|
||||
$(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ -l clixon_backend -o $@ $(LIBS)
|
||||
|
||||
clixon_util_dispatcher: clixon_util_dispatcher.c $(LIBDEPS)
|
||||
$(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ -l clixon_backend -o $@ $(LIBS)
|
||||
|
||||
ifdef with_restconf
|
||||
clixon_util_stream: clixon_util_stream.c $(LIBDEPS)
|
||||
$(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lcurl -o $@
|
||||
|
|
@ -163,7 +167,7 @@ endif
|
|||
distclean: clean
|
||||
rm -f Makefile *~ .depend
|
||||
|
||||
install:
|
||||
install: $(APPS)
|
||||
install -d -m 0755 $(DESTDIR)$(bindir)
|
||||
install -m 0755 $(INSTALLFLAGS) $(APPS) $(DESTDIR)$(bindir)
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -126,7 +126,7 @@ main(int argc,
|
|||
int len;
|
||||
char *buf = NULL;
|
||||
int ret;
|
||||
FILE *fp = stdin; /* unless overriden by argv[1] */
|
||||
FILE *fp = stdin; /* unless overriden by -f */
|
||||
char *yang_file_dir = NULL;
|
||||
yang_stmt *yspec = NULL;
|
||||
char *xpath = NULL;
|
||||
|
|
@ -169,7 +169,7 @@ main(int argc,
|
|||
case 'f': /* XML file */
|
||||
filename = optarg;
|
||||
if ((fp = fopen(filename, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", argv[1]);
|
||||
clicon_err(OE_UNIX, errno, "fopen(%s)", optarg);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue