2 Copyright Red Hat, Inc. 2002-2003
4 The Red Hat Cluster Manager API Library is free software; you can
5 redistribute it and/or modify it under the terms of the GNU Lesser
6 General Public License as published by the Free Software Foundation;
7 either version 2.1 of the License, or (at your option) any later
10 The Red Hat Cluster Manager API Library is distributed in the hope
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * Header for xmlconfig.c.
30 #include <libxml/xmlmemory.h>
31 #include <libxml/parser.h>
32 #include <sys/queue.h>
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <regex.h> /* Regular Expression Matching */
37 #include <fnmatch.h> /* Glob pattern matching */
39 #define MAX_TOKEN_LEN 2048
42 * A node in a list of token,value pairs.
44 * This is used to extract information from the database using a regex or
47 typedef struct _token_list_node
{
48 TAILQ_ENTRY(_token_list_node
) tl_chain
; /**< See sys/queue.h */
49 char *tl_token
; /**< Actual config token */
50 char *tl_value
; /**< for thread safety, create a copy */
51 xmlAttrPtr tl_terminal
; /**< INTERNAL use only; use tl_value */
55 * Define token list head.
57 TAILQ_HEAD(_token_list_head
,_token_list_node
);
59 typedef struct _token_list_head token_list_head
;
65 #define MATCH(str, pattern, type) \
67 ((type == MATCH_REGEX) && \
68 !regexec(&rx##pattern, str, 0, NULL, 0)) ||\
69 ((type == MATCH_GLOB) && \
70 !fnmatch(pattern, str, 0)) || \
71 ((type == MATCH_EXACT) && \
72 !strcmp(pattern, str)))
74 #define MATCH_INIT(pattern, type) \
75 regex_t rx##pattern; \
76 if (pattern && (type == MATCH_REGEX)) \
77 regcomp(&rx##pattern, pattern, REG_EXTENDED | REG_NOSUB | REG_ICASE)
79 #define MATCH_FREE(pattern, type) \
80 if (pattern && (type == MATCH_REGEX)) \
83 /* XML Get/Set/etc. APIs */
84 int xtree_del(xmlDocPtr xtree
, const char *token
);
85 int xtree_set(xmlDocPtr xtree
, const char *token
, char *value
);
86 int xtree_get(xmlDocPtr xtree
, const char *token
, char *dflt
, char **value
);
87 int xtree_readfile(const char *filename
, xmlDocPtr
*xtreep
);
88 int xtree_readbuffer(const char *buffer
, size_t size
, xmlDocPtr
*xtreep
);
89 int xtree_writefile(const char *filename
, xmlDocPtr xtree
);
90 int xtree_writebuffer(xmlDocPtr xtree
, char **buf
, size_t *bufsize
);
93 * Token List Operations
95 int xtree_tl_build(xmlDocPtr xtree
, struct _token_list_head
*head
,
96 const char *m_pat
, int m_type
);
97 void xtree_tl_free(struct _token_list_head
*head
);
99 #define xtree_tl_walk(ptr, head) \
100 for(ptr = head->lh_first; ptr; ptr = ptr->tl_chain.le_next)
101 #define xtree_tl_token(ptr) ptr->tl_token
102 #define xtree_tl_value(ptr) ptr->tl_value
106 void tlist_dump(struct _token_list_head
*lh
);