Merge branch 'master' of https://github.com/clicon/clixon.
Added new API function `xpath_parse()` to split parsing and xml evaluation.
This commit is contained in:
commit
1f8c759f3d
64 changed files with 2282 additions and 1350 deletions
|
|
@ -44,14 +44,14 @@ struct clicon_hash {
|
|||
};
|
||||
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);
|
||||
int hash_dump(clicon_hash_t *head, FILE *f);
|
||||
int hash_keys(clicon_hash_t *hash, char ***vector, size_t *nkeys);
|
||||
clicon_hash_t *clicon_hash_init (void);
|
||||
void clicon_hash_free (clicon_hash_t *);
|
||||
clicon_hash_t clicon_hash_lookup (clicon_hash_t *head, const char *key);
|
||||
void *clicon_hash_value (clicon_hash_t *head, const char *key, size_t *vlen);
|
||||
clicon_hash_t clicon_hash_add (clicon_hash_t *head, const char *key, void *val, size_t vlen);
|
||||
int clicon_hash_del (clicon_hash_t *head, const char *key);
|
||||
int clicon_hash_dump(clicon_hash_t *head, FILE *f);
|
||||
int clicon_hash_keys(clicon_hash_t *hash, char ***vector, size_t *nkeys);
|
||||
|
||||
/*
|
||||
* Macros to iterate over hash contents.
|
||||
|
|
@ -59,24 +59,23 @@ int hash_keys(clicon_hash_t *hash, char ***vector, size_t *nkeys);
|
|||
*
|
||||
* Example:
|
||||
* char *k;
|
||||
* clicon_hash_t *h = hash_init();
|
||||
* clicon_hash_t *h = clicon_hash_init();
|
||||
*
|
||||
* hash_add(h, "colour", "red", 6);
|
||||
* hash_add(h, "name", "rudolf" 7);
|
||||
* hash_add(h, "species", "reindeer" 9);
|
||||
* clicon_hash_add(h, "colour", "red", 6);
|
||||
* clicon_hash_add(h, "name", "rudolf" 7);
|
||||
* clicon_hash_add(h, "species", "reindeer" 9);
|
||||
*
|
||||
* hash_each(h, k) {
|
||||
* printf ("%s = %s\n", k, (char *)hash_value(h, k, NULL));
|
||||
* clicon_hash_each(h, k) {
|
||||
* printf ("%s = %s\n", k, (char *)clicon_hash_value(h, k, NULL));
|
||||
* } hash_each_end();
|
||||
*/
|
||||
#define hash_each(__hash__, __key__) \
|
||||
#define clicon_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__); } }
|
||||
|
||||
#define clicon_hash_each_end(__hash__) if (__k__) free(__k__); } }
|
||||
|
||||
#endif /* _CLIXON_HASH_H_ */
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
*/
|
||||
int netconf_in_use(cbuf *cb, char *type, char *message);
|
||||
int netconf_invalid_value(cbuf *cb, char *type, char *message);
|
||||
int netconf_invalid_value_xml(cxobj **xret, char *type, char *message);
|
||||
int netconf_too_big(cbuf *cb, char *type, char *message);
|
||||
int netconf_missing_attribute(cbuf *cb, char *type, char *info, char *message);
|
||||
int netconf_bad_attribute(cbuf *cb, char *type, char *info, char *message);
|
||||
|
|
|
|||
|
|
@ -75,31 +75,61 @@ enum axis_type{
|
|||
A_ROOT /* XXX Not in https://www.w3.org/TR/xpath-10 */
|
||||
};
|
||||
|
||||
/*
|
||||
* Variables
|
||||
*/
|
||||
extern const map_str2int xpopmap[];
|
||||
/* used as non-terminal type in yacc rules */
|
||||
enum xp_type{
|
||||
XP_EXP,
|
||||
XP_AND,
|
||||
XP_RELEX,
|
||||
XP_ADD,
|
||||
XP_UNION,
|
||||
XP_PATHEXPR,
|
||||
XP_LOCPATH,
|
||||
XP_ABSPATH,
|
||||
XP_RELLOCPATH,
|
||||
XP_STEP,
|
||||
XP_NODE, /* s0 is namespace prefix, s1 is name */
|
||||
XP_NODE_FN,
|
||||
XP_PRED,
|
||||
XP_PRI0,
|
||||
XP_PRIME_NR,
|
||||
XP_PRIME_STR,
|
||||
XP_PRIME_FN,
|
||||
};
|
||||
|
||||
extern int xpatherrordiff;
|
||||
/*! XPATH Parsing generates a tree of nodes that is later traversed
|
||||
*/
|
||||
struct xpath_tree{
|
||||
enum xp_type xs_type;
|
||||
int xs_int;
|
||||
double xs_double;
|
||||
char *xs_s0;
|
||||
char *xs_s1;
|
||||
struct xpath_tree *xs_c0; /* child 0 */
|
||||
struct xpath_tree *xs_c1; /* child 1 */
|
||||
};
|
||||
typedef struct xpath_tree xpath_tree;
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
char* xpath_tree_int2str(int nodetype);
|
||||
int xpath_tree_print(cbuf *cb, xpath_tree *xs);
|
||||
int xpath_tree_free(xpath_tree *xs);
|
||||
int xpath_parse(cvec *nsc, char *xpath, xpath_tree **xptree);
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
cxobj *xpath_first(cxobj *xcur, cvec *nsc, char *format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
int xpath_vec(cxobj *xcur, cvec *nsc, char *format, cxobj ***vec, size_t *veclen, ...) __attribute__ ((format (printf, 3, 6)));
|
||||
int xpath_vec_flag(cxobj *xcur, cvec *nsc, char *format, uint16_t flags,
|
||||
cxobj ***vec, size_t *veclen, ...) __attribute__ ((format (printf, 3, 7)));
|
||||
cxobj *xpath_first(cxobj *xcur, cvec *nsc, char *format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
int xpath_vec_bool(cxobj *xcur, cvec *nsc, char *format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
|
||||
#else
|
||||
cxobj *xpath_first(cxobj *xcur, cvec *nsc, char *format, ...);
|
||||
int xpath_vec(cxobj *xcur, cvec *nsc, char *format, cxobj ***vec, size_t *veclen, ...);
|
||||
int xpath_vec_flag(cxobj *xcur, cvec *nsc, char *format, uint16_t flags,
|
||||
cxobj ***vec, size_t *veclen, ...);
|
||||
cxobj *xpath_first(cxobj *xcur, cvec *nsc, char *format, ...);
|
||||
int xpath_vec_bool(cxobj *xcur, cvec *nsc, char *format, ...);
|
||||
#endif
|
||||
|
||||
int xpath_vec_ctx(cxobj *xcur, cvec *nsc, char *xpath, xp_ctx **xrp);
|
||||
|
||||
#endif /* _CLIXON_XPATH_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue