* Structural change: removed datastore plugin and directory, and merged into regulat clixon lib code.
* Moved out code from clixon_options.[ch] into a new file: clixon_data.[ch]
This commit is contained in:
parent
a269e26c0d
commit
98a5ebc76e
38 changed files with 1400 additions and 3640 deletions
|
|
@ -83,8 +83,9 @@
|
|||
#include <clixon/clixon_proto_client.h>
|
||||
#include <clixon/clixon_plugin.h>
|
||||
#include <clixon/clixon_options.h>
|
||||
#include <clixon/clixon_data.h>
|
||||
#include <clixon/clixon_xml_map.h>
|
||||
#include <clixon/clixon_xml_db.h>
|
||||
#include <clixon/clixon_datastore.h>
|
||||
#include <clixon/clixon_xpath_ctx.h>
|
||||
#include <clixon/clixon_xpath.h>
|
||||
#include <clixon/clixon_json.h>
|
||||
|
|
|
|||
62
lib/clixon/clixon_datastore.h
Normal file
62
lib/clixon/clixon_datastore.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
|
||||
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 *****
|
||||
|
||||
* Clixon Datastore (XMLDB)
|
||||
* Saves Clixon data as clear-text XML (or JSON)
|
||||
*/
|
||||
#ifndef _CLIXON_DATASTORE_H
|
||||
#define _CLIXON_DATASTORE_H
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
* API
|
||||
*/
|
||||
/* Internal functions */
|
||||
int xmldb_db2file(clicon_handle h, const char *db, char **filename);
|
||||
|
||||
/* API */
|
||||
int xmldb_validate_db(const char *db);
|
||||
int xmldb_connect(clicon_handle h);
|
||||
int xmldb_disconnect(clicon_handle h);
|
||||
int xmldb_get(clicon_handle h, const char *db, char *xpath, int config, cxobj **xtop, modstate_diff_t *msd);
|
||||
int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); /* in clixon_datastore_write.[ch] */
|
||||
int xmldb_copy(clicon_handle h, const char *from, const char *to);
|
||||
int xmldb_lock(clicon_handle h, const char *db, int pid);
|
||||
int xmldb_unlock(clicon_handle h, const char *db);
|
||||
int xmldb_unlock_all(clicon_handle h, int pid);
|
||||
int xmldb_islocked(clicon_handle h, const char *db);
|
||||
int xmldb_exists(clicon_handle h, const char *db);
|
||||
int xmldb_delete(clicon_handle h, const char *db);
|
||||
int xmldb_create(clicon_handle h, const char *db);
|
||||
|
||||
#endif /* _CLIXON_DATASTORE_H */
|
||||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
***** END LICENSE BLOCK *****
|
||||
|
||||
* This file requires dirent.h
|
||||
*/
|
||||
|
||||
#ifndef _CLIXON_FILE_H_
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ clicon_hash_t *clicon_options(clicon_handle h);
|
|||
/* Return internal clicon data (hash-array) given a handle.*/
|
||||
clicon_hash_t *clicon_data(clicon_handle h);
|
||||
|
||||
/* Return internal clicon db_elmnt (hash-array) given a handle.*/
|
||||
clicon_hash_t *clicon_db_elmnt(clicon_handle h);
|
||||
|
||||
/* Return internal stream hash-array given a handle.*/
|
||||
struct event_stream *clicon_stream(clicon_handle h);
|
||||
struct event_stream;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
/*
|
||||
* Types
|
||||
*/
|
||||
|
||||
/*! Controls how keywords a generated in CLI syntax / prints from object model
|
||||
* Example YANG:
|
||||
* list a {
|
||||
|
|
@ -154,9 +153,6 @@ static inline char *clicon_backend_pidfile(clicon_handle h){
|
|||
static inline char *clicon_xmldb_dir(clicon_handle h){
|
||||
return clicon_option_str(h, "CLICON_XMLDB_DIR");
|
||||
}
|
||||
static inline char *clicon_xmldb_plugin(clicon_handle h){
|
||||
return clicon_option_str(h, "CLICON_XMLDB_PLUGIN");
|
||||
}
|
||||
|
||||
/*-- Specific option access functions for YANG options w type conversion--*/
|
||||
int clicon_cli_genmodel(clicon_handle h);
|
||||
|
|
@ -172,50 +168,4 @@ int clicon_startup_mode(clicon_handle h);
|
|||
int clicon_quiet_mode(clicon_handle h);
|
||||
int clicon_quiet_mode_set(clicon_handle h, int val);
|
||||
|
||||
yang_spec * clicon_dbspec_yang(clicon_handle h);
|
||||
int clicon_dbspec_yang_set(clicon_handle h, struct yang_spec *ys);
|
||||
|
||||
cxobj * clicon_nacm_ext(clicon_handle h);
|
||||
int clicon_nacm_ext_set(clicon_handle h, cxobj *xn);
|
||||
|
||||
yang_spec * clicon_config_yang(clicon_handle h);
|
||||
int clicon_config_yang_set(clicon_handle h, struct yang_spec *ys);
|
||||
|
||||
cxobj *clicon_conf_xml(clicon_handle h);
|
||||
int clicon_conf_xml_set(clicon_handle h, cxobj *x);
|
||||
|
||||
plghndl_t clicon_xmldb_plugin_get(clicon_handle h);
|
||||
int clicon_xmldb_plugin_set(clicon_handle h, plghndl_t handle);
|
||||
|
||||
void *clicon_xmldb_api_get(clicon_handle h);
|
||||
int clicon_xmldb_api_set(clicon_handle h, void *xa_api);
|
||||
|
||||
void *clicon_xmldb_handle_get(clicon_handle h);
|
||||
int clicon_xmldb_handle_set(clicon_handle h, void *xh);
|
||||
|
||||
/**/
|
||||
/* Set and get authorized user name */
|
||||
char *clicon_username_get(clicon_handle h);
|
||||
int clicon_username_set(clicon_handle h, void *username);
|
||||
|
||||
/* Set and get startup status */
|
||||
enum startup_status clicon_startup_status_get(clicon_handle h);
|
||||
int clicon_startup_status_set(clicon_handle h, enum startup_status status);
|
||||
|
||||
/* Set and get socket fd (ie backend server socket / restconf fcgx socket */
|
||||
int clicon_socket_get(clicon_handle h);
|
||||
int clicon_socket_set(clicon_handle h, int s);
|
||||
|
||||
/*! Set and get module state cache */
|
||||
cxobj *clicon_module_state_get(clicon_handle h);
|
||||
int clicon_module_state_set(clicon_handle h, cxobj *xms);
|
||||
|
||||
/*! Set and get yang/xml module revision changelog */
|
||||
cxobj *clicon_xml_changelog_get(clicon_handle h);
|
||||
int clicon_xml_changelog_set(clicon_handle h, cxobj *xchlog);
|
||||
|
||||
/*! Set and get user command-line options (after --) */
|
||||
int clicon_argv_get(clicon_handle h, int *argc, char ***argv);
|
||||
int clicon_argv_set(clicon_handle h, char *argv0, int argc, char **argv);
|
||||
|
||||
#endif /* _CLIXON_OPTIONS_H_ */
|
||||
|
|
|
|||
|
|
@ -1,152 +0,0 @@
|
|||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
|
||||
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 *****
|
||||
*/
|
||||
#ifndef _CLIXON_XML_DB_H
|
||||
#define _CLIXON_XML_DB_H
|
||||
|
||||
/* The XMLDB has a handle to keep connected state. To users of the API it is
|
||||
* a void* but it may have structure within a specific plugin.
|
||||
* The handle is independent from clicon so that (in principle) the datastore
|
||||
* can work in other contexts than clicon.
|
||||
* The connect API call sets the handle and disconnect resets it. In principle
|
||||
* there can be several handles at one time.
|
||||
*/
|
||||
#if 1 /* SANITY CHECK */
|
||||
typedef struct {int16_t a;} *xmldb_handle;
|
||||
#else
|
||||
typedef void *xmldb_handle;
|
||||
#endif
|
||||
|
||||
/* Version of clixon datastore plugin API. */
|
||||
#define XMLDB_API_VERSION 1
|
||||
|
||||
/* Magic to ensure plugin sanity. */
|
||||
#define XMLDB_API_MAGIC 0xf386f730
|
||||
|
||||
/* Name of plugin init function (must be called this) */
|
||||
#define XMLDB_PLUGIN_INIT_FN "clixon_xmldb_plugin_init"
|
||||
|
||||
/* Type of plugin init function */
|
||||
typedef void * (plugin_init_t)(int version);
|
||||
|
||||
/* Type of plugin exit function */
|
||||
typedef int (plugin_exit_t)(void);
|
||||
|
||||
/* Type of xmldb connect function */
|
||||
typedef xmldb_handle (xmldb_connect_t)(void);
|
||||
|
||||
/* Type of xmldb disconnect function */
|
||||
typedef int (xmldb_disconnect_t)(xmldb_handle xh);
|
||||
|
||||
/* Type of xmldb getopt function */
|
||||
typedef int (xmldb_getopt_t)(xmldb_handle xh, char *optname, void **value);
|
||||
|
||||
/* Type of xmldb setopt function */
|
||||
typedef int (xmldb_setopt_t)(xmldb_handle xh, char *optname, void *value);
|
||||
|
||||
/* Type of xmldb get function */
|
||||
typedef int (xmldb_get_t)(xmldb_handle xh, const char *db, char *xpath, int config, cxobj **xtop, modstate_diff_t *msd);
|
||||
|
||||
/* Type of xmldb put function */
|
||||
typedef int (xmldb_put_t)(xmldb_handle xh, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret);
|
||||
|
||||
/* Type of xmldb copy function */
|
||||
typedef int (xmldb_copy_t)(xmldb_handle xh, const char *from, const char *to);
|
||||
|
||||
/* Type of xmldb lock function */
|
||||
typedef int (xmldb_lock_t)(xmldb_handle xh, const char *db, int pid);
|
||||
|
||||
/* Type of xmldb unlock function */
|
||||
typedef int (xmldb_unlock_t)(xmldb_handle xh, const char *db);
|
||||
|
||||
/* Type of xmldb unlock_all function */
|
||||
typedef int (xmldb_unlock_all_t)(xmldb_handle xh, int pid);
|
||||
|
||||
/* Type of xmldb islocked function */
|
||||
typedef int (xmldb_islocked_t)(xmldb_handle xh, const char *db);
|
||||
|
||||
/* Type of xmldb exists function */
|
||||
typedef int (xmldb_exists_t)(xmldb_handle xh, const char *db);
|
||||
|
||||
/* Type of xmldb delete function */
|
||||
typedef int (xmldb_delete_t)(xmldb_handle xh, const char *db);
|
||||
|
||||
/* Type of xmldb init function */
|
||||
typedef int (xmldb_create_t)(xmldb_handle xh, const char *db);
|
||||
|
||||
/* plugin init struct for the api */
|
||||
struct xmldb_api{
|
||||
int xa_version;
|
||||
int xa_magic;
|
||||
plugin_init_t *xa_plugin_init_fn; /* XMLDB_PLUGIN_INIT_FN */
|
||||
plugin_exit_t *xa_plugin_exit_fn;
|
||||
xmldb_connect_t *xa_connect_fn;
|
||||
xmldb_disconnect_t *xa_disconnect_fn;
|
||||
xmldb_getopt_t *xa_getopt_fn;
|
||||
xmldb_setopt_t *xa_setopt_fn;
|
||||
xmldb_get_t *xa_get_fn;
|
||||
xmldb_put_t *xa_put_fn;
|
||||
xmldb_copy_t *xa_copy_fn;
|
||||
xmldb_lock_t *xa_lock_fn;
|
||||
xmldb_unlock_t *xa_unlock_fn;
|
||||
xmldb_unlock_all_t *xa_unlock_all_fn;
|
||||
xmldb_islocked_t *xa_islocked_fn;
|
||||
xmldb_exists_t *xa_exists_fn;
|
||||
xmldb_delete_t *xa_delete_fn;
|
||||
xmldb_create_t *xa_create_fn;
|
||||
};
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
* API
|
||||
*/
|
||||
int xmldb_plugin_load(clicon_handle h, char *filename);
|
||||
int xmldb_plugin_unload(clicon_handle h);
|
||||
|
||||
int xmldb_validate_db(const char *db);
|
||||
int xmldb_connect(clicon_handle h);
|
||||
int xmldb_disconnect(clicon_handle h);
|
||||
int xmldb_getopt(clicon_handle h, char *optname, void **value);
|
||||
int xmldb_setopt(clicon_handle h, char *optname, void *value);
|
||||
int xmldb_get(clicon_handle h, const char *db, char *xpath, int config, cxobj **xtop, modstate_diff_t *msd);
|
||||
int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret);
|
||||
int xmldb_copy(clicon_handle h, const char *from, const char *to);
|
||||
int xmldb_lock(clicon_handle h, const char *db, int pid);
|
||||
int xmldb_unlock(clicon_handle h, const char *db);
|
||||
int xmldb_unlock_all(clicon_handle h, int pid);
|
||||
int xmldb_islocked(clicon_handle h, const char *db);
|
||||
int xmldb_exists(clicon_handle h, const char *db);
|
||||
int xmldb_delete(clicon_handle h, const char *db);
|
||||
int xmldb_create(clicon_handle h, const char *db);
|
||||
|
||||
#endif /* _CLIXON_XML_DB_H */
|
||||
|
|
@ -60,12 +60,13 @@ typedef struct {
|
|||
*/
|
||||
modstate_diff_t * modstate_diff_new(void);
|
||||
int modstate_diff_free(modstate_diff_t *);
|
||||
int modules_state_cache_set(clicon_handle h, cxobj *msx);
|
||||
|
||||
int yang_modules_init(clicon_handle h);
|
||||
char *yang_modules_revision(clicon_handle h);
|
||||
|
||||
int yang_modules_state_get(clicon_handle h, yang_spec *yspec, char *xpath,
|
||||
int brief, cxobj **xret);
|
||||
|
||||
int clixon_module_upgrade(clicon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb);
|
||||
|
||||
#endif /* _CLIXON_YANG_MODULE_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue