Inital commit

This commit is contained in:
Olof hagsand 2016-02-22 22:17:30 +01:00
parent edc5e091bb
commit d6e393ea58
145 changed files with 58117 additions and 0 deletions

44
lib/clicon/Makefile.in Normal file
View file

@ -0,0 +1,44 @@
#
# Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
#
# This file is part of CLICON.
#
# CLICON is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# CLICON is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CLICON; see the file COPYING. If not, see
# <http://www.gnu.org/licenses/>.
#
prefix = @prefix@
includedir = @includedir@
.PHONY: install-include
all:
depend:
install:
install-include:
install -m 755 -d $(DESTDIR)$(includedir)/clicon
install -m 644 *.h $(DESTDIR)$(includedir)/clicon
uninstall:
rm -f $(includedir)/clicon
clean:
distclean:
rm -f Makefile clicon.h

78
lib/clicon/clicon.h.in Normal file
View file

@ -0,0 +1,78 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
* Meta-include file that includes all sub-files in control-lib
* Note: this include files is for external purposes. Do not include this
* file in clicon lib-routines.
*/
/* This include file requires the following include file dependencies */
#include <stdio.h>
#include <stdint.h>
#include <dirent.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
/*
* CLICON version macros
*/
#undef CLICON_VERSION_STRING
#undef CLICON_VERSION_MAJOR
#undef CLICON_VERSION_MINOR
#undef CLICON_VERSION_PATCH
/*
* Use this constant to disable some prototypes that should not be visible outside the lib.
* This is an alternative to use separate internal include files.
*/
#define LIBCLICON_API 1
#include <clicon/clicon_sig.h>
#include <clicon/clicon_log.h>
#include <clicon/clicon_err.h>
#include <clicon/clicon_queue.h>
#include <clicon/clicon_hash.h>
#include <clicon/clicon_handle.h>
#include <clicon/clicon_qdb.h>
#include <clicon/clicon_yang.h>
#include <clicon/clicon_yang_type.h>
#include <clicon/clicon_chunk.h>
#include <clicon/clicon_event.h>
#include <clicon/clicon_string.h>
#include <clicon/clicon_file.h>
#include <clicon/clicon_xml.h>
#include <clicon/clicon_proto.h>
#include <clicon/clicon_proto_encode.h>
#include <clicon/clicon_proto_client.h>
#include <clicon/clicon_proc.h>
#include <clicon/clicon_options.h>
#include <clicon/clicon_xml_map.h>
#include <clicon/clicon_xml_db.h>
#include <clicon/clicon_xsl.h>
#include <clicon/clicon_plugin.h>
#include <clicon/clicon_plugin.h>
/*
* Global variables generated by Makefile
*/
extern const char CLICON_BUILDSTR[];
extern const char CLICON_VERSION[];

166
lib/clicon/clicon_chunk.h Normal file
View file

@ -0,0 +1,166 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Copyright (C) 2002 Benny Holmgren, All rights reserved
*/
#ifndef _CLICON_CHUNK_H_
#define _CLICON_CHUNK_H_
/*
* Compile with chunk diagnostics. XXX Should be in Makefile.in ??
*/
#define CHUNK_DIAG
/*
* Base number of bits to shift getting the size of a chunk_head.
*/
#define CHUNK_BASE 6
/*
* Number of predefined chunk sizes. I.e. the number of chunk heads in the
* chunk_heads vector.
*/
#define CHUNK_HEADS (32 - CHUNK_BASE)
#ifdef CHUNK_DIAG
/*
* Chunk diagnostics
*/
typedef struct _chunk_diag_t {
const char *cd_file; /* File which requested chunk */
int cd_line; /* Line in requesting file */
} chunk_diag_t;
#endif /* CHUNK_DIAG */
/*
* The block header.
*/
struct _chunk_head_t;
typedef struct _chunk_head_t chunk_head_t;
typedef struct _chunk_block_t {
qelem_t cb_qelem; /* Circular queue of blocks */
chunk_head_t *cb_head; /* The chunk head I belong to */
void *cb_blk; /* Allocated memory block */
uint16_t cb_ref; /* Number of used chunks of block */
} chunk_block_t;
/*
* The chunk header.
*/
struct _chunk_grpent_t;
typedef struct _chunk_grpent_t chunk_grpent_t;
typedef struct _chunk_t {
qelem_t c_qelem; /* Circular queue of chunks */
chunk_block_t *c_blk; /* The block I belong to */
#ifdef CHUNK_DIAG
chunk_diag_t c_diag; /* The diagnostics structure */
#endif /* CHUNK_DIAG */
chunk_grpent_t *c_grpent;
} chunk_t;
/*
* The head of a chunk size. Each predefined size has it's own head keeping
* track of all blocks and chunks for the size.
*/
struct _chunk_head_t {
size_t ch_size; /* Chunk size */
int ch_nchkperblk; /* Number pf chunks per block */
size_t ch_blksz; /* Size of a block */
int ch_nblks; /* Number of allocated blocks */
chunk_block_t *ch_blks; /* Circular list of blocks */
chunk_t *ch_cnks; /* Circular list of chunks in use */
size_t ch_nfree; /* Number of free chunks */
chunk_t *ch_free; /* Circular list of free chunks */
};
/*
* The chunk group structure.
*/
typedef struct _chunk_group_t {
qelem_t cg_qelem; /* List of chunk groups */
char *cg_name; /* Name of group */
chunk_grpent_t *cg_ent; /* List of chunks in the group */
} chunk_group_t;
/*
* The chunk group entry structure.
*/
struct _chunk_grpent_t {
qelem_t ce_qelem; /* Circular list of entries */
chunk_group_t *ce_grp; /* The group I belong to */
chunk_t *ce_cnk; /* Pointer to the chunk */
};
/*
* Public function declarations
*/
#ifdef CHUNK_DIAG
void *_chunk (size_t, const char *, const char *, int);
#define chunk(siz,label) _chunk((siz),(label),__FILE__,__LINE__)
void *_rechunk (void *, size_t, const char *, const char *, int);
#define rechunk(ptr,siz,label) _rechunk((ptr),(siz),(label),__FILE__,__LINE__)
void *_chunkdup (const void *, size_t, const char *, const char *, int);
#define chunkdup(ptr,siz,label) _chunkdup((ptr),(siz),(label),__FILE__,__LINE__)
char *_chunk_strncat (const char *, const char *, size_t, const char *, const char *, int);
#define chunk_strncat(str,new,n,label) _chunk_strncat((str),(new),(n),(label),__FILE__,__LINE__)
char *_chunk_sprintf (const char *, const char *, int, const char *, ...);
#define chunk_sprintf(label,fmt,...) _chunk_sprintf((label),__FILE__,__LINE__,(fmt),__VA_ARGS__)
#else /* CHUNK_DIAG */
void *chunk (size_t, const char *);
void *rechunk (void *, size_t, const char *);
void *chunkdup (void *, size_t, const char *);
char *chunk_strncat (const char *, const char *, size_t, const char *);
char *chunk_sprintf (const char *, char *, ...);
#endif /* CHUNK_DIAG */
void unchunk (void *);
void unchunk_group (const char *);
void chunk_check (FILE *, const char *);
size_t chunksize (void *);
#endif /* _CLICON_CHUNK_H_ */

80
lib/clicon/clicon_err.h Normal file
View file

@ -0,0 +1,80 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Errors may be syslogged using LOG_ERR, and printed to stderr, as controlled by
* clicon_log_init
* global error variables are set:
* clicon_errno, clicon_suberrno, clicon_err_reason.
*/
#ifndef _CLICON_ERR_H_
#define _CLICON_ERR_H_
/*
* Constants
*/
#define ERR_STRLEN 256
/*
* Types
* Add error here, but must also add an entry in EV variable.
*/
enum clicon_err{
/* 0 means error not set) */
OE_DB = 1, /* database registries */
OE_DEMON, /* demons: pidfiles, etc */
OE_EVENTS, /* events, filedescriptors, timeouts */
OE_CFG, /* config commit / quagga */
OE_PROTO, /* config/client communication */
OE_REGEX, /* Regexp error */
OE_UNIX, /* unix/linux syscall error */
OE_SYSLOG, /* syslog error */
OE_ROUTING, /* routing daemon error (eg quagga) */
OE_XML, /* xml parsing etc */
OE_PLUGIN, /* plugin loading, etc */
OE_YANG , /* Yang error */
OE_FATAL, /* Fatal error */
OE_UNDEF,
};
/*
* Variables
* XXX: should not be global
*/
extern int clicon_errno; /* CLICON errors (see clicon_err) */
extern int clicon_suberrno; /* Eg orig errno */
extern char clicon_err_reason[ERR_STRLEN];
/*
* Macros
*/
#define clicon_err(e,s,_fmt, args...) clicon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args)
/*
* Prototypes
*/
int clicon_err_reset(void);
int clicon_err_fn(const char *fn, const int line, int level, int err, char *format, ...);
char *clicon_strerror(int err);
void *clicon_err_save(void);
int clicon_err_restore(void *handle);
#endif /* _CLICON_ERR_H_ */

46
lib/clicon/clicon_event.h Normal file
View file

@ -0,0 +1,46 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Event handling and loop
*/
#ifndef _CLICON_EVENT_H_
#define _CLICON_EVENT_H_
/*
* Prototypes
*/
int clicon_exit_set(void);
int clicon_exit_get(void);
int event_reg_fd(int fd, int (*fn)(int, void*), void *arg, char *str);
int event_unreg_fd(int s, int (*fn)(int, void*));
int event_reg_timeout(struct timeval t, int (*fn)(int, void*),
void *arg, char *str);
int event_unreg_timeout(int (*fn)(int, void*), void *arg);
int event_loop(void);
#endif /* _CLICON_EVENT_H_ */

36
lib/clicon/clicon_file.h Normal file
View file

@ -0,0 +1,36 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_FILE_H_
#define _CLICON_FILE_H_
char **clicon_realpath(const char *cwd, char *path, const char *label);
int clicon_file_dirent(const char *dir, struct dirent **ent,
const char *regexp, mode_t type, const char *label);
char *clicon_tmpfile(const char *label);
int file_cp(char *src, char *target);
#endif /* _CLICON_FILE_H_ */

View file

@ -0,0 +1,61 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_HANDLE_H_
#define _CLICON_HANDLE_H_
/*
* Types
*/
/* Common handle used in most clicon calls that you get from clicon_init().
Note that its contents is different dependending on if invoked from a
cli/backend/netconf or other plugin. But this is hidden under-the-hood.
*/
#if 1 /* SANITY CHECK */
typedef struct {float a;} *clicon_handle;
#else
typedef void *clicon_handle;
#endif
/*
* Prototypes
*/
/* Basic CLICON init functions returning a handle for API access. */
clicon_handle clicon_handle_init(void);
/* Internal call to allocate a CLICON handle. */
clicon_handle clicon_handle_init0(int size);
/* Deallocate handle */
int clicon_handle_exit(clicon_handle h);
/* Check struct magic number for sanity checks */
int clicon_handle_check(clicon_handle h);
/* Return clicon options (hash-array) given a handle.*/
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);
#endif /* _CLICON_HANDLE_H_ */

70
lib/clicon/clicon_hash.h Normal file
View file

@ -0,0 +1,70 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_HASH_H_
#define _CLICON_HASH_H_
struct clicon_hash {
qelem_t h_qelem;
char *h_key;
size_t h_vlen;
void *h_val;
};
typedef struct clicon_hash *clicon_hash_t;
clicon_hash_t *hash_init (void);
void hash_free (clicon_hash_t *);
clicon_hash_t hash_lookup (clicon_hash_t *head, const char *key);
void *hash_value (clicon_hash_t *head, const char *key, size_t *vlen);
clicon_hash_t hash_add (clicon_hash_t *head, const char *key, void *val, size_t vlen);
int hash_del (clicon_hash_t *head, const char *key);
void hash_dump(clicon_hash_t *head, FILE *f);
char **hash_keys(clicon_hash_t *hash, size_t *nkeys);
/*
* Macros to iterate over hash contents.
* XXX A bit crude. Just as easy for app to loop through the keys itself.
*
* Example:
* char *k;
* clicon_hash_t *h = hash_init();
*
* hash_add(h, "colour", "red", 6);
* hash_add(h, "name", "rudolf" 7);
* hash_add(h, "species", "reindeer" 9);
*
* hash_each(h, k) {
* printf ("%s = %s\n", k, (char *)hash_value(h, k, NULL));
* } hash_each_end();
*/
#define hash_each(__hash__, __key__) \
{ \
int __i__; \
size_t __n__; \
char **__k__ = hash_keys((__hash__),&__n__); \
if (__k__) { \
for(__i__ = 0; __i__ < __n__ && ((__key__) = __k__[__i__]); __i__++)
#define hash_each_end(__hash__) if (__k__) free(__k__); } }
#endif /* _CLICON_HASH_H_ */

57
lib/clicon/clicon_log.h Normal file
View file

@ -0,0 +1,57 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Regular logging and debugging. Syslog using levels.
*/
#ifndef _CLICON_LOG_H_
#define _CLICON_LOG_H_
/*
* Constants
*/
#define CLICON_LOG_SYSLOG 1 /* print logs on syslog */
#define CLICON_LOG_STDERR 2 /* print logs on stderr */
#define CLICON_LOG_STDOUT 4 /* print logs on stdout */
/*
* Types
*/
typedef int (clicon_log_notify_t)(int level, char *msg, void *arg);
/*
* Variables
*/
extern int debug;
/*
* Prototypes
*/
int clicon_log_init(char *ident, int upto, int flags);
int clicon_log_str(int level, char *msg);
int clicon_log(int level, char *format, ...);
clicon_log_notify_t *clicon_log_register_callback(clicon_log_notify_t *cb, void *arg);
int clicon_debug_init(int dbglevel, FILE *f);
int clicon_debug(int dbglevel, char *format, ...);
char *mon2name(int md);
#endif /* _CLICON_LOG_H_ */

114
lib/clicon/clicon_options.h Normal file
View file

@ -0,0 +1,114 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Configuration file and Options.
*/
#ifndef _CLICON_OPTIONS_H_
#define _CLICON_OPTIONS_H_
/*
* Constants
*/
/* default group membership to access config unix socket */
#define CLICON_SOCK_GROUP "clicon"
/* Default name of master plugin */
#define CLICON_MASTER_PLUGIN "master"
/*
* Types
*/
/*
* enum gensyntx
* Controls how keywords a generated in CLI syntax / prints from obhect model
* Example syntax a.b[] $!x $y:
* NONE: a b <x> <y>;
* VARS: a b <x> y <y>;
* ALL: a b x <x> y <y>;
*/
enum genmodel_type{
GT_ERR =-1, /* Error */
GT_NONE=0, /* No extra keywords */
GT_VARS, /* Keywords on non-index variables */
GT_ALL, /* Keywords on all variables */
};
/*
* Prototypes
*/
/* Initialize options: set defaults, read config-file, etc */
int clicon_options_main(clicon_handle h);
void clicon_option_dump(clicon_handle h, int dblevel);
int clicon_option_exists(clicon_handle h, const char *name);
/* Get a single option via handle */
char *clicon_option_str(clicon_handle h, const char *name);
int clicon_option_int(clicon_handle h, const char *name);
/* Set a single option via handle */
int clicon_option_str_set(clicon_handle h, const char *name, char *val);
int clicon_option_int_set(clicon_handle h, const char *name, int val);
/* Delete a single option via handle */
int clicon_option_del(clicon_handle h, const char *name);
char *clicon_configfile(clicon_handle h);
char *clicon_yang_dir(clicon_handle h);
char *clicon_yang_module_main(clicon_handle h);
char *clicon_yang_module_revision(clicon_handle h);
char *clicon_running_db(clicon_handle h);
char *clicon_candidate_db(clicon_handle h);
char *clicon_backend_dir(clicon_handle h);
char *clicon_cli_dir(clicon_handle h);
char *clicon_clispec_dir(clicon_handle h);
char *clicon_netconf_dir(clicon_handle h);
char *clicon_archive_dir(clicon_handle h);
char *clicon_startup_config(clicon_handle h);
int clicon_sock_family(clicon_handle h);
char *clicon_sock(clicon_handle h);
int clicon_sock_port(clicon_handle h);
char *clicon_backend_pidfile(clicon_handle h);
char *clicon_sock_group(clicon_handle h);
char *clicon_master_plugin(clicon_handle h);
char *clicon_cli_mode(clicon_handle h);
int clicon_cli_genmodel(clicon_handle h);
int clicon_cli_varonly(clicon_handle h);
int clicon_cli_varonly_set(clicon_handle h, int val);
int clicon_cli_genmodel_completion(clicon_handle h);
char *clicon_quiet_mode(clicon_handle h);
enum genmodel_type clicon_cli_genmodel_type(clicon_handle h);
int clicon_autocommit(clicon_handle h);
int clicon_autocommit_set(clicon_handle h, int val);
int clicon_commit_order(clicon_handle h);
yang_spec * clicon_dbspec_yang(clicon_handle h);
int clicon_dbspec_yang_set(clicon_handle h, struct yang_spec *ys);
char *clicon_dbspec_name(clicon_handle h);
int clicon_dbspec_name_set(clicon_handle h, char *name);
#endif /* _CLICON_OPTIONS_H_ */

View file

@ -0,0 +1,67 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
/*
* Internal prototypes, not accessed by plugin client code
*/
#ifndef _CLICON_PLUGIN_H_
#define _CLICON_PLUGIN_H_
/*
* Types
*/
/* The dynamicically loadable plugin object handle */
typedef void *plghndl_t;
/* Find plugin by name callback. XXX Should be clicon internal */
typedef void *(find_plugin_t)(clicon_handle, char *);
/*
* Prototypes
*/
/* Common plugin function names, function types and signatures.
* This set of plugins is extended in
* Cli see cli_plugin.c
* Backend see config_plugin.c
*/
/*! Called when plugin loaded. Only mandadory callback. All others optional
* @see plginit_t
*/
#define PLUGIN_INIT "plugin_init"
typedef int (plginit_t)(clicon_handle); /* Plugin Init */
/* Called when backend started with cmd-line arguments from daemon call.
* @see plgstart_t
*/
#define PLUGIN_START "plugin_start"
typedef int (plgstart_t)(clicon_handle, int, char **); /* Plugin start */
/* Called just before plugin unloaded.
* @see plgexit_t
*/
#define PLUGIN_EXIT "plugin_exit"
typedef int (plgexit_t)(clicon_handle); /* Plugin exit */
/* Find a function in global namespace or a plugin. XXX clicon internal */
void *clicon_find_func(clicon_handle h, char *plugin, char *func);
#endif /* _CLICON_PLUGIN_H_ */

33
lib/clicon/clicon_proc.h Normal file
View file

@ -0,0 +1,33 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_PROC_H_
#define _CLICON_PROC_H_
/*
* Prototypes
*/
int clicon_proc_run (char *, void (outcb)(char *), int doerr);
int clicon_proc_daemon (char *);
int group_name2gid(char *name, gid_t *gid);
#endif /* _CLICON_PROC_H_ */

183
lib/clicon/clicon_proto.h Normal file
View file

@ -0,0 +1,183 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Protocol to communicate with CLICON config daemon
*/
#ifndef _CLICON_PROTO_H_
#define _CLICON_PROTO_H_
/*
* Types
*/
enum format_enum{
MSG_NOTIFY_TXT, /* means filter works on strings */
MSG_NOTIFY_XML, /* means filter works on xml */
};
/* See also map_type2str in clicon_proto.c */
enum clicon_msg_type{
CLICON_MSG_COMMIT = 1, /* Commit a configuration db->running_db
current state, set running_db. Body is:
1. uint32: (1)snapshot while doing commit, (0) dont
2. uint32: (1)save to startup-config, (0) dont
3. string: name of 'from' database (eg candidate)
4. string: name of 'to' database (eg current)
*/
CLICON_MSG_VALIDATE, /* Validate settings in a database. Body is:
1. string: name of database
*/
CLICON_MSG_CHANGE, /* Change a (single) database entry:
1. uint32: operation: OP_MERGE/OP_REPLACE/OP_REMOVE
2. uint32: length of value string
3. string: name of database to change (eg current)
4. string: key
5. string: value
*/
CLICON_MSG_XMLPUT, /* Send database entries as XML to backend daemon
1. uint32: operation: LV_SET/LV_DELETE
2. string: name of database to change (eg current)
3. string: XML data
*/
CLICON_MSG_SAVE, /* Save config state from db to a file in backend. Body is:
1. uint32: make snapshot (1), dont(0)
2. string: name of database to save from (eg running)
3. string: filename to write. If snapshot=1, then this
is empty.
*/
CLICON_MSG_LOAD, /* Load config state from file in backend to db via XML. Body is:
1. uint32: whether to replace/initdb before load (1) or
merge (0).
2. string: name of database to load into (eg running)
3. string: filename to load from
*/
CLICON_MSG_COPY, /* Copy from file to file in backend. Body is:
1. string: filename to copy from
2. string: filename to copy to
*/
CLICON_MSG_RM , /* Delete file. Body is:
1. string: filename to delete
*/
CLICON_MSG_INITDB , /* (Re-)Initialize a database. Body is:
1. string: filename of db to initialize
*/
CLICON_MSG_LOCK , /* Lock a database. Body is
1. name of db
The reply will be OK, or ERROR. If error is
lock-denied, the session-id of the locking
entity is returned (cf netconf)
*/
CLICON_MSG_UNLOCK , /* Unlock a database. Body is:
1. name of db *
*/
CLICON_MSG_KILL, /* Kill (other) session:
1. session-id
*/
CLICON_MSG_DEBUG, /* Debug
1. session-id
*/
CLICON_MSG_CALL , /* Backend plugin call request. Body is:
1. struct clicon_msg_call_req *
*/
CLICON_MSG_SUBSCRIPTION, /* Create a new notification subscription.
Body is:
1. int: status off/on
1. int: format (enum format_enum)
2. string: name of notify stream
3. string: filter, if format=xml: xpath, if text: fnmatch */
CLICON_MSG_OK, /* server->client reply */
CLICON_MSG_NOTIFY, /* Notification. Body is:
1. int: loglevel
2. event: log message. */
CLICON_MSG_ERR /* server->client reply.
Body is:
1. uint32: man error category
2. uint32: sub-error
3. string: reason
*/
};
/* Protocol message header */
struct clicon_msg {
uint16_t op_len; /* length of message. */
uint16_t op_type; /* message type, see enum clicon_msg_type */
char op_body[0]; /* rest of message, actual data */
};
/* Generic clicon message. Either generic/internal message
or application-specific backend plugin downcall request */
struct clicon_msg_call_req {
uint16_t cr_len; /* Length of total request */
uint16_t cr_op; /* Generic application-defined operation */
char *cr_plugin; /* Name of backend plugin, NULL -> internal
functions */
char *cr_func; /* Function name in plugin (or internal) */
uint16_t cr_arglen; /* App specific argument length */
char *cr_arg; /* App specific argument */
char cr_data[0]; /* Allocated data containng the above */
};
/*
* Prototypes
*/
#ifndef LIBCLICON_API
int clicon_connect_unix(char *sockpath);
int clicon_rpc_connect_unix(struct clicon_msg *msg,
char *sockpath,
char **data,
uint16_t *datalen,
int *sock0,
const char *label);
int clicon_rpc_connect_inet(struct clicon_msg *msg,
char *dst,
uint16_t port,
char **data,
uint16_t *datalen,
int *sock0,
const char *label);
int clicon_rpc(int s, struct clicon_msg *msg, char **data, uint16_t *datalen,
const char *label);
#endif
int clicon_msg_send(int s, struct clicon_msg *msg);
int clicon_msg_rcv(int s, struct clicon_msg **msg,
int *eof, const char *label);
int send_msg_notify(int s, int level, char *event);
int send_msg_reply(int s, uint16_t type, char *data, uint16_t datalen);
int send_msg_ok(int s);
int send_msg_err(int s, int err, int suberr, char *format, ...);
#endif /* _CLICON_PROTO_H_ */

View file

@ -0,0 +1,57 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Client-side functions for clicon_proto protocol
* Historically this code was part of the clicon_cli application. But
* it should (is?) be general enough to be used by other applications.
*/
#ifndef _CLICON_PROTO_CLIENT_H_
#define _CLICON_PROTO_CLIENT_H_
int clicon_rpc_commit(clicon_handle h, char *running_db, char *db,
int snapshot, int startup);
int clicon_rpc_validate(clicon_handle h, char *db);
int clicon_rpc_change(clicon_handle h, char *db,
enum operation_type op, char *key, char *val);
int clicon_rpc_xmlput(clicon_handle h, char *db, enum operation_type op, char *xml);
int clicon_rpc_dbitems(clicon_handle h, char *db, char *rx,
char *attr, char *val,
cvec ***cvv, size_t *cvvlen);
int clicon_rpc_save(clicon_handle h, char *dbname, int snapshot, char *filename);
int clicon_rpc_load(clicon_handle h, int replace, char *db, char *filename);
int clicon_rpc_copy(clicon_handle h, char *filename1, char *filename2);
int clicon_rpc_rm(clicon_handle h, char *filename);
int clicon_rpc_initdb(clicon_handle h, char *filename);
int clicon_rpc_lock(clicon_handle h, char *dbname);
int clicon_rpc_unlock(clicon_handle h, char *dbname);
int clicon_rpc_kill(clicon_handle h, int session_id);
int clicon_rpc_debug(clicon_handle h, int level);
int clicon_rpc_call(clicon_handle h, uint16_t op, char *plugin, char *func,
void *param, uint16_t paramlen,
char **ret, uint16_t *retlen,
const void *label);
int clicon_rpc_subscription(clicon_handle h, int status, char *stream,
enum format_enum format, char *filter, int *s);
#endif /* _CLICON_PROTO_CLIENT_H_ */

View file

@ -0,0 +1,189 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Protocol to communicate between clients (eg clicon_cli, clicon_netconf)
* and server (clicon_backend)
*/
#ifndef _CLICON_PROTO_ENCODE_H_
#define _CLICON_PROTO_ENCODE_H_
/*
* Prototypes
*/
struct clicon_msg *
clicon_msg_commit_encode(char *dbsrc, char *dbdst,
uint32_t snapshot, uint32_t startup,
const char *label);
int
clicon_msg_commit_decode(struct clicon_msg *msg,
char **dbsrc, char **dbdst,
uint32_t *snapshot, uint32_t *startup,
const char *label);
struct clicon_msg *
clicon_msg_validate_encode(char *db,
const char *label);
int
clicon_msg_validate_decode(struct clicon_msg *msg, char **db,
const char *label);
struct clicon_msg *
clicon_msg_change_encode(char *db, uint32_t op, char *key,
char *lvec, uint32_t lvec_len,
const char *label);
int
clicon_msg_change_decode(struct clicon_msg *msg,
char **db, uint32_t *op, char **key,
char **lvec, uint32_t *lvec_len,
const char *label);
struct clicon_msg *
clicon_msg_xmlput_encode(char *db,
uint32_t op,
char *xml,
const char *label);
int
clicon_msg_xmlput_decode(struct clicon_msg *msg,
char **db,
uint32_t *op,
char **filename,
const char *label);
struct clicon_msg *
clicon_msg_dbitems_get_reply_encode(cvec **cvecv,
int cveclen,
const char *label);
int
clicon_msg_dbitems_get_reply_decode(char *data,
uint16_t datalen,
cvec ***cvecv,
size_t *cveclen,
const char *label);
struct clicon_msg *
clicon_msg_save_encode(char *db, uint32_t snapshot, char *filename,
const char *label);
int
clicon_msg_save_decode(struct clicon_msg *msg,
char **db, uint32_t *snapshot, char **filename,
const char *label);
struct clicon_msg *
clicon_msg_load_encode(int replace, char *db, char *filename,
const char *label);
int
clicon_msg_load_decode(struct clicon_msg *msg,
int *replace, char **db, char **filename,
const char *label);
struct clicon_msg *
clicon_msg_initdb_encode(char *filename_src, const char *label);
int
clicon_msg_initdb_decode(struct clicon_msg *msg, char **filename_src,
const char *label);
struct clicon_msg *
clicon_msg_rm_encode(char *filename_src, const char *label);
int
clicon_msg_rm_decode(struct clicon_msg *msg, char **filename_src,
const char *label);
struct clicon_msg *
clicon_msg_copy_encode(char *filename_src, char *filename_dst,
const char *label);
int
clicon_msg_copy_decode(struct clicon_msg *msg,
char **filename_src, char **filename_dst,
const char *label);
struct clicon_msg *
clicon_msg_lock_encode(char *db, const char *label);
int
clicon_msg_lock_decode(struct clicon_msg *msg, char **db, const char *label);
struct clicon_msg *
clicon_msg_unlock_encode(char *db, const char *label);
int
clicon_msg_unlock_decode(struct clicon_msg *msg, char **db, const char *label);
struct clicon_msg *
clicon_msg_kill_encode(uint32_t session_id, const char *label);
int
clicon_msg_kill_decode(struct clicon_msg *msg, uint32_t *session_id,
const char *label);
struct clicon_msg *
clicon_msg_debug_encode(uint32_t level, const char *label);
int
clicon_msg_debug_decode(struct clicon_msg *msg, uint32_t *level,
const char *label);
struct clicon_msg *
clicon_msg_call_encode(uint16_t op, char *plugin, char *func,
uint16_t arglen, void *arg,
const char *label);
int
clicon_msg_call_decode(struct clicon_msg *msg,
struct clicon_msg_call_req **req,
const char *label);
struct clicon_msg *
clicon_msg_subscription_encode(int status,
char *stream,
enum format_enum format,
char *filter,
const char *label);
int clicon_msg_subscription_decode(struct clicon_msg *msg,
int *status,
char **stream,
enum format_enum *format,
char **filter,
const char *label);
struct clicon_msg *
clicon_msg_notify_encode(int level, char *event, const char *label);
int
clicon_msg_notify_decode(struct clicon_msg *msg, int *level,
char **event, const char *label);
struct clicon_msg *clicon_msg_err_encode(uint32_t err, uint32_t suberr,
char *reason, const char *label);
int clicon_msg_err_decode(struct clicon_msg *msg, uint32_t *err, uint32_t *suberr,
char **reason, const char *label);
#endif /* _CLICON_PROTO_ENCODE_H_ */

58
lib/clicon/clicon_qdb.h Normal file
View file

@ -0,0 +1,58 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_QDB_H_
#define _CLICON_QDB_H_
/*
* Low level API
*/
struct db_pair {
char *dp_key; /* database key */
char *dp_matched; /* Matched component of key */
char *dp_val; /* pointer to vector of lvalues */
int dp_vlen; /* length of vector of lvalues */
};
/*
* Prototypes
*/
int db_init(char *file);
int db_set(char *file, char *key, void *data, size_t datalen);
int db_get(char *file, char *key, void *data, size_t *datalen);
int db_get_alloc(char *file, char *key, void **data, size_t *datalen);
int db_del(char *file, char *key);
int db_exists(char *file, char *key);
int db_regexp(char *file, char *regexp, const char *label,
struct db_pair **pairs, int noval);
char *db_sanitize(char *rx, const char *label);
#endif /* _CLICON_QDB_H_ */

89
lib/clicon/clicon_queue.h Normal file
View file

@ -0,0 +1,89 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* Copyright (C) 2002 Benny Holmgren, All rights reserved
*/
#ifndef _CLICON_QUEUE_H_
#define _CLICON_QUEUE_H_
/*
* Circular queue structure for use as first entry in a parent structure.
*/
typedef struct _qelem_t {
struct _qelem_t *q_next;
struct _qelem_t *q_prev;
} qelem_t;
/*
* Append element 'elem' to queue.
*/
#define ADDQ(elem, pred) { \
register qelem_t *Xe = (qelem_t *) (elem); \
register qelem_t *Xp = (qelem_t *) (pred); \
if (pred) { \
Xe->q_next = Xp; \
Xe->q_prev = Xp->q_prev; \
Xp->q_prev->q_next = Xe; \
Xp->q_prev = Xe; \
} else { \
Xe->q_next = Xe->q_prev = Xe; \
pred = elem; \
} \
}
/*
* Insert element 'elem' in queue after 'pred'
*/
#define INSQ(elem, pred) { \
register qelem_t *Xe = (qelem_t *) (elem); \
register qelem_t *Xp = (qelem_t *) (pred); \
if (pred) { \
Xe->q_next = Xp; \
Xe->q_prev = Xp->q_prev; \
Xp->q_prev->q_next = Xe; \
Xp->q_prev = Xe; \
} else { \
Xe->q_next = Xe->q_prev = Xe; \
} \
pred = elem; \
}
/*
* Remove element 'elem' from queue. 'head' is the pointer to the queue and
* is of 'type'.
*/
#define DELQ(elem, head, type) { \
register qelem_t *Xe = (qelem_t *) elem; \
if (Xe->q_next == Xe) \
head = NULL; \
(Xe->q_prev->q_next = Xe->q_next)->q_prev = Xe->q_prev; \
if (elem == head) \
head = (type)Xe->q_next; \
}
/*
* Get next entry in list
*/
#define NEXTQ(type, elem) ((type)((elem)?((qelem_t *)(elem))->q_next:NULL))
#endif /* _CLICON_QUEUE_H_ */

30
lib/clicon/clicon_sha1.h Normal file
View file

@ -0,0 +1,30 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_SHA1_H_
#define _CLICON_SHA1_H_
/*
* Function Prototypes
*/
char *clicon_sha1hex(const char *str);
#endif /* _CLICON_SHA1_H_ */

42
lib/clicon/clicon_sig.h Normal file
View file

@ -0,0 +1,42 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_SIG_H_
#define _CLICON_SIG_H_
/*
* Types
*/
typedef void (*sigfn_t)(int);
/*
* Prototypes
*/
int set_signal(int signo, void (*handler)(int), void (**oldhandler)(int));
void clicon_signal_block(int);
void clicon_signal_unblock(int);
int pidfile_get(char *pidfile, pid_t *pid0);
int pidfile_write(char *pidfile);
int pidfile_zapold(pid_t pid);
#endif /* _CLICON_SIG_H_ */

View file

@ -0,0 +1,56 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_STRING_H_
#define _CLICON_STRING_H_
/*! A malloc version that aligns on 4 bytes. To avoid warning from valgrind */
#define align4(s) (((s)/4)*4 + 4)
/*! A strdup version that aligns on 4 bytes. To avoid warning from valgrind */
static inline char * strdup4(char *str)
{
char *dup;
int len;
len = align4(strlen(str)+1);
if ((dup = malloc(len)) == NULL)
return NULL;
strncpy(dup, str, len);
return dup;
}
/*
* Prototypes
*/
char **clicon_sepsplit (char *string, char *delim, int *nvec, const char *label);
char **clicon_strsplit (char *string, char *delim, int *nvec, const char *label);
char *clicon_strjoin (int argc, char **argv, char *delim, const char *label);
char *clicon_strtrim(char *str, const char *label);
int clicon_sep(char *s, const char sep[2], const char *label, char**a0, char **b0);
#ifndef HAVE_STRNDUP
char *clicon_strndup (const char *, size_t);
#endif /* ! HAVE_STRNDUP */
int clicon_strmatch(const char *str, const char *regexp, char **match);
char *clicon_strsub(char *str, char *from, char *to);
#endif /* _CLICON_STRING_H_ */

108
lib/clicon/clicon_xml.h Normal file
View file

@ -0,0 +1,108 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
* XML support functions.
*/
#ifndef _CLICON_XML_H
#define _CLICON_XML_H
/*
* Types
*/
/* Netconf operation type */
enum operation_type{ /* edit-config */
OP_MERGE, /* merge config-data */
OP_REPLACE,/* replace or create config-data */
OP_CREATE, /* create config data, error if exist */
OP_DELETE, /* delete config data, error if it does not exist */
OP_REMOVE, /* delete config data */
OP_NONE
};
enum cxobj_type {CX_ERROR=-1,
CX_ELMNT,
CX_ATTR,
CX_BODY};
#define CX_ANY CX_ERROR /* catch all and error is same */
typedef struct xml cxobj; /* struct defined in clicon_xml.c */
/*! Callback function type for xml_apply */
typedef int (xml_applyfn_t)(cxobj *yn, void *arg);
/*
* xml_flag() flags:
*/
#define XML_FLAG_MARK 0x01 /* Marker for dynamic algorithms, eg expand */
/*
* Prototypes
*/
char *xml_name(cxobj *xn);
int xml_name_set(cxobj *xn, char *name);
char *xml_namespace(cxobj *xn);
int xml_namespace_set(cxobj *xn, char *name);
cxobj *xml_parent(cxobj *xn);
int xml_parent_set(cxobj *xn, cxobj *parent);
uint16_t xml_flag(cxobj *xn, uint16_t flag);
int xml_flag_set(cxobj *xn, uint16_t flag);
int xml_flag_reset(cxobj *xn, uint16_t flag);
char *xml_value(cxobj *xn);
int xml_value_set(cxobj *xn, char *val);
char *xml_value_append(cxobj *xn, char *val);
enum cxobj_type xml_type(cxobj *xn);
int xml_type_set(cxobj *xn, enum cxobj_type type);
int xml_index(cxobj *xn);
int xml_index_set(cxobj *xn, int index);
int xml_child_nr(cxobj *xn);
cxobj *xml_child_i(cxobj *xn, int i);
cxobj *xml_child_i_set(cxobj *xt, int i, cxobj *xc);
cxobj *xml_child_each(cxobj *xparent, cxobj *xprev, enum cxobj_type type);
int xml_childvec_set(cxobj *x, int len);
cxobj *xml_new(char *name, cxobj *xn_parent);
cxobj *xml_new_spec(char *name, cxobj *xn_parent, void *spec);
void *xml_spec(cxobj *x);
cxobj *xml_find(cxobj *xn_parent, char *name);
char *xml_body(cxobj *xn);
char *xml_find_value(cxobj *xn_parent, char *name);
char *xml_find_body(cxobj *xn, char *name);
int xml_free(cxobj *xn);
int xml_prune(cxobj *xp, cxobj *xc, int freeit);
int clicon_xml2file(FILE *f, cxobj *xn, int level, int prettyprint);
int clicon_xml2cbuf(cbuf *xf, cxobj *xn, int level, int prettyprint);
int clicon_xml_parse_file(int fd, cxobj **xml_top, char *endtag);
int clicon_xml_parse_string(char **str, cxobj **xml_top);
int xml_copy(cxobj *x0, cxobj *x1);
cxobj *xml_dup(cxobj *x0);
int xml_addsub(cxobj *xp, cxobj *xc);
cxobj *xml_insert(cxobj *xt, char *tag);
int cxvec_dup(cxobj **vec0, size_t len0, cxobj ***vec1, size_t *len1);
int cxvec_append(cxobj *x, cxobj ***vec, size_t *len);
int xml_apply(cxobj *xn, enum cxobj_type type, xml_applyfn_t fn, void *arg);
#endif /* _CLICON_XML_H */

View file

@ -0,0 +1,42 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
* XML support functions.
*/
#ifndef _CLICON_XML_DB_H
#define _CLICON_XML_DB_H
/*
* Prototypes
*/
int yang2xmlkeyfmt(yang_stmt *ys, char **xkfmt);
int xmlkeyfmt2key(char *xkfmt, cvec *cvv, char **xk);
int xmlkeyfmt2key2(char *xkfmt, cvec *cvv, char **xk);
int xmlkey2xml(char *xkey, yang_spec *yspec, char **xml);
int xmldb_get(char *dbname, char *xpath,
yang_spec *yspec, cxobj **xtop);
int xmldb_get_xpath(char *dbname, char *xpath, yang_spec *yspec,
cxobj **xtop, cxobj ***xvec, int *xlen);
int xmldb_put( char *dbname, cxobj *xt,
yang_spec *yspec, enum operation_type op);
int xmldb_put_xkey(char *dbname, char *xkey, char *val, yang_spec *yspec,
enum operation_type op);
#endif /* _CLICON_XML_DB_H */

View file

@ -0,0 +1,53 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*
* XML code
*/
#ifndef _CLICON_XML_MAP_H_
#define _CLICON_XML_MAP_H_
/*
* lvmap_xml op codes
*/
enum {
LVXML, /* a.b{x=1} -> <a><b>1 */
LVXML_VAL, /* a.b{x=1} -> <a><b><x>1 */
LVXML_VECVAL, /* key: a.b.0{x=1} -> <a><b><x>1</x></b></a> och */
LVXML_VECVAL2, /* key: a.b.0{x=1} -> <a><x>1</x></a> och */
};
/*
* Prototypes
*/
int xml2txt(FILE *f, cxobj *x, int level);
int xml2cli(FILE *f, cxobj *x, char *prepend, enum genmodel_type gt, const char *label);
int xml2json(FILE *f, cxobj *x, int level);
int xml_yang_validate(cxobj *xt, yang_stmt *ys) ;
int xml2cvec(cxobj *xt, yang_stmt *ys, cvec **cvv0);
int cvec2xml_1(cvec *cvv, char *toptag, cxobj **xt0);
int xml_diff(yang_spec *yspec, cxobj *xt1, cxobj *xt2,
cxobj ***first, size_t *firstlen,
cxobj ***second, size_t *secondlen,
cxobj ***changed1, cxobj ***changed2, size_t *changedlen);
#endif /* _CLICON_XML_MAP_H_ */

33
lib/clicon/clicon_xsl.h Normal file
View file

@ -0,0 +1,33 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
* XML XPATH and XSLT functions.
*/
#ifndef _CLICON_XSL_H
#define _CLICON_XSL_H
/*
* Prototypes
*/
cxobj *xpath_first(cxobj *xn_top, char *xpath);
cxobj *xpath_each(cxobj *xn_top, char *xpath, cxobj *prev);
cxobj **xpath_vec(cxobj *xn_top, char *xpath, int *xv_len);
#endif /* _CLICON_XSL_H */

206
lib/clicon/clicon_yang.h Normal file
View file

@ -0,0 +1,206 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_YANG_H_
#define _CLICON_YANG_H_
/*
* Actually cligen variable stuff XXX
*/
#define V_UNIQUE 0x01 /* Variable flag */
#define V_UNSET 0x08 /* Variable is unset, ie no default */
/*
* Types
*/
/*! YANG keywords from RFC6020.
* See also keywords generated by yacc/bison in clicon_yang_parse.tab.h, but they start with K_
* instead of Y_
* Wanted to unify these (K_ and Y_) but gave up for several reasons:
* - Dont want to expose a generated yacc file to the API
* - Cant use the symbols in this file because yacc needs token definitions
*/
enum rfc_6020{
Y_ANYXML,
Y_ARGUMENT,
Y_AUGMENT,
Y_BASE,
Y_BELONGS_TO,
Y_BIT,
Y_CASE,
Y_CHOICE,
Y_CONFIG,
Y_CONTACT,
Y_CONTAINER,
Y_DEFAULT,
Y_DESCRIPTION,
Y_DEVIATE,
Y_DEVIATION,
Y_ENUM,
Y_ERROR_APP_TAG,
Y_ERROR_MESSAGE,
Y_EXTENSION,
Y_FEATURE,
Y_FRACTION_DIGITS,
Y_GROUPING,
Y_IDENTITY,
Y_IF_FEATURE,
Y_IMPORT,
Y_INCLUDE,
Y_INPUT,
Y_KEY,
Y_LEAF,
Y_LEAF_LIST,
Y_LENGTH,
Y_LIST,
Y_MANDATORY,
Y_MAX_ELEMENTS,
Y_MIN_ELEMENTS,
Y_MODULE,
Y_MUST,
Y_NAMESPACE,
Y_NOTIFICATION,
Y_ORDERED_BY,
Y_ORGANIZATION,
Y_OUTPUT,
Y_PATH,
Y_PATTERN,
Y_POSITION,
Y_PREFIX,
Y_PRESENCE,
Y_RANGE,
Y_REFERENCE,
Y_REFINE,
Y_REQUIRE_INSTANCE,
Y_REVISION,
Y_REVISION_DATE,
Y_RPC,
Y_STATUS,
Y_SUBMODULE,
Y_TYPE,
Y_TYPEDEF,
Y_UNIQUE,
Y_UNITS,
Y_USES,
Y_VALUE,
Y_WHEN,
Y_YANG_VERSION,
Y_YIN_ELEMENT,
Y_SPEC /* XXX: NOTE NOT YANG STATEMENT, reserved for top level spec */
};
#define YANG_FLAG_MARK 0x01 /* Marker for dynamic algorithms, eg expand */
typedef struct yang_stmt yang_stmt; /* forward */
/*! Yang type cache. Yang type statements can cache all typedef info here
*/
struct yang_type_cache{
int yc_options;
cg_var *yc_mincv;
cg_var *yc_maxcv;
char *yc_pattern;
uint8_t yc_fraction;
yang_stmt *yc_resolved; /* Resolved type object, can be NULL - note direct ptr */
};
typedef struct yang_type_cache yang_type_cache;
/*! yang statement
*/
struct yang_stmt{
int ys_len; /* Number of children */
struct yang_stmt **ys_stmt; /* Vector of children statement pointers */
struct yang_node *ys_parent; /* Backpointer to parent: yang-stmt or yang-spec */
enum rfc_6020 ys_keyword; /* See clicon_yang_parse.tab.h */
char *ys_argument; /* String / argument depending on keyword */
int ys_flags; /* Flags according to YANG_FLAG_* above */
cg_var *ys_cv; /* cligen variable. The following stmts have cvs::
leaf, leaf-list, mandatory, fraction-digits */
cvec *ys_cvec; /* List of stmt-specific variables
Y_RANGE: range_min, range_max */
yang_type_cache *ys_typecache; /* If ys_keyword==Y_TYPE, cache all typedef data */
};
/*! top-level yang parse-tree */
struct yang_spec{
int yp_len; /* Number of children */
struct yang_stmt **yp_stmt; /* Vector of children statement pointers */
struct yang_node *yp_parent; /* Backpointer to parent: always NULL. See yang_stmt */
enum rfc_6020 yp_keyword; /* SHOULD BE Y_SPEC */
char *yp_argument; /* XXX String / argument depending on keyword */
int yp_flags; /* Flags according to YANG_FLAG_* above */
};
typedef struct yang_spec yang_spec;
/*! super-class of yang_stmt and yang_spec: it must start exactly as those two classes */
struct yang_node{
int yn_len; /* Number of children */
struct yang_stmt **yn_stmt; /* Vector of children statement pointers */
struct yang_node *yn_parent; /* Backpointer to parent: yang-stmt or yang-spec */
enum rfc_6020 yn_keyword; /* See clicon_yang_parse.tab.h */
char *yn_argument; /* XXX String / argument depending on keyword */
int yn_flags; /* Flags according to YANG_FLAG_* above */
};
typedef struct yang_node yang_node;
typedef int (yang_applyfn_t)(yang_stmt *ys, void *arg);
/*
* Prototypes
*/
yang_spec *yspec_new(void);
yang_stmt *ys_new(enum rfc_6020 keyw);
int ys_free(yang_stmt *ys);
int yspec_free(yang_spec *yspec);
int ys_cp(yang_stmt *new, yang_stmt *old);
yang_stmt *ys_dup(yang_stmt *old);
int yn_insert(yang_node *yn_parent, yang_stmt *ys_child);
yang_stmt *yn_each(yang_node *yn, yang_stmt *ys);
char *yang_key2str(int keyword);
char *ytype_prefix(yang_stmt *ys);
char *ytype_id(yang_stmt *ys);
yang_stmt *ys_module(yang_stmt *ys);
yang_spec *ys_spec(yang_stmt *ys);
yang_stmt *ys_module_import(yang_stmt *ymod, char *prefix);
yang_stmt *yang_find(yang_node *yn, int keyword, char *argument);
yang_stmt *yang_find_syntax(yang_node *yn, char *argument);
yang_stmt *yang_find_topnode(yang_spec *ysp, char *name);
int yang_print(FILE *f, yang_node *yn, int marginal);
int yang_parse(clicon_handle h, const char *yang_dir,
const char *module, const char *revision, yang_spec *ysp);
int yang_apply(yang_node *yn, yang_applyfn_t fn, void *arg);
yang_stmt *dbkey2yang(yang_node *yn, char *dbkey);
yang_node *yang_xpath_abs(yang_node *yn, char *xpath);
yang_node *yang_xpath(yang_node *yn, char *xpath);
cg_var *ys_parse(yang_stmt *ys, enum cv_type cvtype);
int ys_parse_sub(yang_stmt *ys);
int yang_mandatory(yang_stmt *ys);
int yang_config(yang_stmt *ys);
int yang_spec_main(clicon_handle h, FILE *f, int printspec);
cvec *yang_arg2cvec(yang_stmt *ys, char *delimi);
int yang_key_match(yang_node *yn, char *name);
#endif /* _CLICON_YANG_H_ */

View file

@ -0,0 +1,68 @@
/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLICON.
CLICON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLICON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLICON; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CLICON_YANG_TYPE_H_
#define _CLICON_YANG_TYPE_H_
/*
* Constants
*/
/*! Bit-fields used in options argument in yang_type_get()
*/
#define YANG_OPTIONS_LENGTH 0x01
#define YANG_OPTIONS_RANGE 0x02
#define YANG_OPTIONS_PATTERN 0x04
#define YANG_OPTIONS_FRACTION_DIGITS 0x08
/*
* Types
*/
/*
* Prototypes
*/
int yang_type_cache_set(yang_type_cache **ycache,
yang_stmt *resolved, int options, cg_var *mincv,
cg_var *maxcv, char *pattern, uint8_t fraction);
int yang_type_cache_get(yang_type_cache *ycache,
yang_stmt **resolved, int *options, cg_var **mincv,
cg_var **maxcv, char **pattern, uint8_t *fraction);
int yang_type_cache_cp(yang_type_cache **ycnew, yang_type_cache *ycold);
int yang_type_cache_free(yang_type_cache *ycache);
int ys_resolve_type(yang_stmt *ys, void *arg);
int yang2cv_type(char *ytype, enum cv_type *cv_type);
char *cv2yang_type(enum cv_type cv_type);
yang_stmt *yang_find_identity(yang_stmt *ys, char *identity);
int ys_cv_validate(cg_var *cv, yang_stmt *ys, char **reason);
int clicon_type2cv(char *type, char *rtype, enum cv_type *cvtype);
char *ytype_id(yang_stmt *ys);
int yang_type_get(yang_stmt *ys, char **otype, yang_stmt **restype,
int *options, cg_var **mincv, cg_var **maxcv, char **pattern,
uint8_t *fraction_digits);
int yang_type_resolve(yang_stmt *ys, yang_stmt *ytype,
yang_stmt **restype, int *options,
cg_var **mincv, cg_var **maxcv,
char **pattern, uint8_t *fraction);
#endif /* _CLICON_YANG_TYPE_H_ */