CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
clixon_xml_map.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <arpa/inet.h>
#include <assert.h>
#include <syslog.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <cligen/cligen.h>
#include "clixon_string.h"
#include "clixon_queue.h"
#include "clixon_hash.h"
#include "clixon_chunk.h"
#include "clixon_handle.h"
#include "clixon_yang.h"
#include "clixon_yang_type.h"
#include "clixon_options.h"
#include "clixon_xml.h"
#include "clixon_xsl.h"
#include "clixon_log.h"
#include "clixon_err.h"
#include "clixon_xml_map.h"

Functions

static cxobj * leaf (cxobj *xn)
 
static int tleaf (cxobj *x)
 
int xml2txt (FILE *f, cxobj *x, int level)
 
int xml2cli (FILE *f, cxobj *x, char *prepend0, enum genmodel_type gt)
 
int xml_yang_validate (cxobj *xt, yang_stmt *ys0)
 
int xml2cvec (cxobj *xt, yang_stmt *yt, cvec **cvv0)
 
int cvec2xml_1 (cvec *cvv, char *toptag, cxobj *xp, cxobj **xt0)
 
static int xml_is_body (cxobj *xt, char *name, char *val)
 
static int xml_diff1 (yang_stmt *ys, cxobj *xt1, cxobj *xt2, cxobj ***first, size_t *firstlen, cxobj ***second, size_t *secondlen, cxobj ***changed1, cxobj ***changed2, size_t *changedlen)
 
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)
 

Function Documentation

int cvec2xml_1 ( cvec *  cvv,
char *  toptag,
cxobj *  xp,
cxobj **  xt0 
)

Translate a cligen variable vector to an XML tree with depth one

Parameters
[in]cvvCLIgen variable vector. Should be freed by cvec_free()
[in]toptagThe XML tree in xt will have this XML tag
[in]xtParent, or NULL
[out]xtPointer to XML tree containing one top node. Should be freed with xml_free
Return values
0Everything OK, cvv allocated and set
-1Something wrong, clicon_err() called to set error. No xt returned
See Also
xml2cvec
cvec2xml This does more but has an internal xml2cvec translation
static cxobj* leaf ( cxobj *  xn)
static
static int tleaf ( cxobj *  x)
static

x is element and has eactly one child which in turn has none

int xml2cli ( FILE *  f,
cxobj *  x,
char *  prepend0,
enum genmodel_type  gt 
)

Translate from XML to CLI commands Howto: join strings and pass them down. Identify unique/index keywords for correct set syntax. Args:

Parameters
[in]fWhere to print cli commands
[in]xXML Parse-tree (to translate)
[in]prepend0Print this text in front of all commands.
[in]gtoption to steer cli syntax
int xml2cvec ( cxobj *  xt,
yang_stmt *  yt,
cvec **  cvv0 
)

Translate a single xml node to a cligen variable vector. Note not recursive

Parameters
[in]xtXML tree containing one top node
[in]ysYang spec containing type specification of top-node of xt
[out]cvvCLIgen variable vector. Should be freed by cvec_free()
Return values
0Everything OK, cvv allocated and set
-1Something wrong, clicon_err() called to set error. No cvv returned 'Not recursive' means that only one level of XML bodies is translated to cvec:s. yang is needed to know which type an xml element has. Example: 23 88 <d> <e>99</e> </d> –> b:23, c:88
See Also
cvec2xml
int xml2txt ( FILE *  f,
cxobj *  x,
int  level 
)

Translate XML -> TEXT

Parameters
[in]levelprint 4 spaces per level in front of each line
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 
)

Compute differences between two xml trees

Parameters
[in]yspecYang specification
[in]xt1First XML tree
[in]xt2Second XML tree
[out]firstPointervector to XML nodes existing in only first tree
[out]firstlenLength of first vector
[out]secondPointervector to XML nodes existing in only second tree
[out]secondlenLength of second vector
[out]changed1Pointervector to XML nodes changed value
[out]changed2Pointervector to XML nodes changed value
[out]changedlenLength of changed vector All xml vectors should be freed after use. Bot xml trees should be freed with xml_free()
static int xml_diff1 ( yang_stmt *  ys,
cxobj *  xt1,
cxobj *  xt2,
cxobj ***  first,
size_t *  firstlen,
cxobj ***  second,
size_t *  secondlen,
cxobj ***  changed1,
cxobj ***  changed2,
size_t *  changedlen 
)
static

Recursive help function to compute differences between two xml trees

See Also
dbdiff_vector.
static int xml_is_body ( cxobj *  xt,
char *  name,
char *  val 
)
static

Return 1 if value is a body of one of the named children of xt

int xml_yang_validate ( cxobj *  xt,
yang_stmt *  ys0 
)

Validate a single XML node with yang specification

  • If no value and mandatory flag set in spec, report error.
  • Validate value versus spec, and report error if no match. Currently only int ranges and string regexp checked.
    Return values
    0OK