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 */
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@
|
|||
/*
|
||||
* Types
|
||||
*/
|
||||
|
||||
|
||||
/*! Registered RPC callback function
|
||||
* @param[in] h Clicon handle
|
||||
|
|
@ -201,8 +200,8 @@ 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
|
||||
* XPath binding is stricter, similar to the pagination API.
|
||||
* 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
|
||||
* @param[in] xpath Part of state requested
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue