Change internal protocol from clicon_proto.h to netconf.

This commit is contained in:
Olof hagsand 2017-03-25 11:10:50 +01:00
parent 2e09f54d12
commit 2fcefda831
66 changed files with 3012 additions and 5141 deletions

View file

@ -109,9 +109,6 @@ int clicon_cli_varonly_set(clicon_handle h, int val);
int clicon_cli_genmodel_completion(clicon_handle h);
char *clicon_xmldb_dir(clicon_handle h);
int clicon_xmldb_rpc(clicon_handle h);
char *clicon_xmldb_addr(clicon_handle h);
uint16_t clicon_xmldb_port(clicon_handle h);
char *clicon_quiet_mode(clicon_handle h);
enum genmodel_type clicon_cli_genmodel_type(clicon_handle h);

View file

@ -48,16 +48,10 @@ enum format_enum{
/* 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 "running")
CLICON_MSG_NETCONF = 1, /* Generic netconf message (lock/unlock/..) can all
msgs go to this?
1. string: netconf message
*/
CLICON_MSG_VALIDATE, /* Validate settings in a database. Body is:
1. string: name of database (eg "candidate")
*/
CLICON_MSG_CHANGE, /* Change a (single) database entry:
1. uint32: operation: OP_MERGE/OP_REPLACE/OP_REMOVE
2. uint32: length of value string
@ -65,55 +59,6 @@ enum clicon_msg_type{
4. string: key
5. string: value (can be NULL)
*/
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: restconf api path
4. 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_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 */
@ -123,55 +68,37 @@ struct clicon_msg {
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_unix(struct clicon_msg *msg,
char *sockpath,
char **ret,
int *sock0);
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_connect_inet(struct clicon_msg *msg,
char *dst,
uint16_t port,
char **ret,
int *sock0);
int clicon_rpc(int s, struct clicon_msg *msg, char **data, uint16_t *datalen,
const char *label);
int clicon_rpc(int s, struct clicon_msg *msg, char **xret);
#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 clicon_msg_rcv(int s, struct clicon_msg **msg, int *eof);
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_ok(int s, char *data);
int send_msg_err(int s, int err, int suberr, char *format, ...);
int send_msg_netconf_reply(int s, char *format, ...);
#endif /* _CLIXON_PROTO_H_ */

View file

@ -40,27 +40,28 @@
#ifndef _CLIXON_PROTO_CLIENT_H_
#define _CLIXON_PROTO_CLIENT_H_
int clicon_rpc_commit(clicon_handle h, char *from, char *to);
int clicon_rpc_msg(clicon_handle h, struct clicon_msg *msg, cxobj **xret0,
int *sock0);
int clicon_rpc_netconf_xml(clicon_handle h, cxobj *xml, cxobj **xret, int *sp);
int clicon_rpc_generate_error(cxobj *xerr);
int clicon_rpc_get_config(clicon_handle h, char *db, char *xpath, cxobj **xret);
int clicon_rpc_edit_config(clicon_handle h, char *db, enum operation_type op,
char *api_path, char *xml);
int clicon_rpc_copy_config(clicon_handle h, char *db1, char *db2);
int clicon_rpc_delete_config(clicon_handle h, char *db);
int clicon_rpc_lock(clicon_handle h, char *db);
int clicon_rpc_unlock(clicon_handle h, char *db);
int clicon_rpc_close_session(clicon_handle h);
int clicon_rpc_kill_session(clicon_handle h, int session_id);
int clicon_rpc_validate(clicon_handle h, char *db);
int clicon_rpc_commit(clicon_handle h);
// discard-changes
int clicon_rpc_create_subscription(clicon_handle h, char *stream, char *filter,
int *s);
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 *api_path, 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 *db1, char *db2);
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 /* _CLIXON_PROTO_CLIENT_H_ */

View file

@ -42,27 +42,14 @@
/*
* Prototypes
*/
struct clicon_msg *
clicon_msg_commit_encode(char *dbsrc, char *dbdst,
const char *label);
struct clicon_msg *clicon_msg_netconf_encode(char *format, ...);
struct clicon_msg *clicon_msg_netconf_encode_xml(cxobj *xml);
int
clicon_msg_commit_decode(struct clicon_msg *msg,
char **dbsrc, char **dbdst,
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);
int clicon_msg_netconf_decode(struct clicon_msg *msg, cxobj **xml);
struct clicon_msg *
clicon_msg_change_encode(char *db, uint32_t op, char *key,
char *lvec, uint32_t lvec_len,
const char *label);
char *lvec, uint32_t lvec_len);
int
clicon_msg_change_decode(struct clicon_msg *msg,
@ -70,25 +57,9 @@ clicon_msg_change_decode(struct clicon_msg *msg,
char **lvec, uint32_t *lvec_len,
const char *label);
struct clicon_msg *
clicon_msg_xmlput_encode(char *db,
uint32_t op,
char *api_path,
char *xml,
const char *label);
int
clicon_msg_xmlput_decode(struct clicon_msg *msg,
char **db,
uint32_t *op,
char **api_path,
char **xml,
const char *label);
struct clicon_msg *
clicon_msg_dbitems_get_reply_encode(cvec **cvecv,
int cveclen,
const char *label);
int cveclen);
int
clicon_msg_dbitems_get_reply_decode(char *data,
uint16_t datalen,
@ -96,82 +67,4 @@ clicon_msg_dbitems_get_reply_decode(char *data,
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_copy_encode(char *db_src, char *db_dst,
const char *label);
int
clicon_msg_copy_decode(struct clicon_msg *msg,
char **db_src, char **db_dst,
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 /* _CLIXON_PROTO_ENCODE_H_ */

View file

@ -40,7 +40,7 @@
* Types
*/
/* Netconf operation type */
enum operation_type{ /* edit-config */
enum operation_type{ /* edit-configo */
OP_MERGE, /* merge config-data */
OP_REPLACE,/* replace or create config-data */
OP_CREATE, /* create config data, error if exist */
@ -98,6 +98,7 @@ 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);
cxobj **xml_childvec_get(cxobj *x);
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);
@ -124,6 +125,7 @@ int clicon_xml_parse_file(int fd, cxobj **xml_top, char *endtag);
/* XXX obsolete */
#define clicon_xml_parse_string(str, x) clicon_xml_parse_str((*str), x)
int clicon_xml_parse_str(char *str, cxobj **xml_top);
int clicon_xml_parse(cxobj **cxtop, char *format, ...);
int xml_copy(cxobj *x0, cxobj *x1);
cxobj *xml_dup(cxobj *x0);
@ -137,5 +139,7 @@ int xml_apply_ancestor(cxobj *xn, xml_applyfn_t fn, void *arg);
int xml_body_parse(cxobj *xb, enum cv_type type, cg_var **cvp);
int xml_body_int32(cxobj *xb, int32_t *val);
int xml_body_uint32(cxobj *xb, uint32_t *val);
int xml_operation(char *opstr, enum operation_type *op);
char *xml_operation2str(enum operation_type op);
#endif /* _CLIXON_XML_H */

View file

@ -42,18 +42,19 @@
int yang2xmlkeyfmt(yang_stmt *ys, int inclkey, char **xkfmt);
int xmlkeyfmt2key(char *xkfmt, cvec *cvv, char **xk);
int xmlkeyfmt2xpath(char *xkfmt, cvec *cvv, char **xk);
int xmldb_get(clicon_handle h, char *db, char *xpath,
cxobj **xtop, cxobj ***xvec, size_t *xlen);
int xmldb_put(clicon_handle h, char *db, cxobj *xt, enum operation_type op);
int xmldb_put_tree(clicon_handle h, char *db, char *api_path,
cxobj *xt, enum operation_type op);
int xmldb_put_xkey(clicon_handle h, char *db,
char *xkey, char *val,
enum operation_type op);
int xmldb_dump_local(FILE *f, char *dbfilename, char *rxkey);
int xmldb_put(clicon_handle h, char *db, enum operation_type op,
char *api_path, cxobj *xt);
int xmldb_put_xkey(clicon_handle h, char *db, enum operation_type op,
char *xkey, char *val);
int xmldb_dump(FILE *f, char *dbfilename, char *rxkey);
int xmldb_copy(clicon_handle h, char *from, char *to);
int xmldb_lock(clicon_handle h, char *db, int pid);
int xmldb_unlock(clicon_handle h, char *db, int pid);
int xmldb_unlock_all(clicon_handle h, int pid);
int xmldb_islocked(clicon_handle h, char *db);
int xmldb_exists(clicon_handle h, char *db);
int xmldb_delete(clicon_handle h, char *db);