yumapro  20.10-12
YumaPro SDK
xmlns.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3  * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4  *
5  * Unless required by applicable law or agreed to in writing,
6  * software distributed under the License is distributed on an
7  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations
10  * under the License.
11  */
12 #ifndef _H_xmlns
13 #define _H_xmlns
14 /* FILE: xmlns.h
15 *********************************************************************
16 * *
17 * P U R P O S E *
18 * *
19 *********************************************************************/
20 
30 /*********************************************************************
31 * *
32 * C H A N G E H I S T O R Y *
33 * *
34 *********************************************************************
35 
36 date init comment
37 ----------------------------------------------------------------------
38 30-apr-05 abb Begun.
39 */
40 
41 #include <xmlstring.h>
42 
43 #ifndef _H_dlq
44 #include "dlq.h"
45 #endif
46 
47 #ifndef _H_status
48 #include "status.h"
49 #endif
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /********************************************************************
56 * *
57 * C O N S T A N T S *
58 * *
59 *********************************************************************/
60 
61 #define XMLNS_NULL_NS_ID 0
62 
63 #define XMLNS ((const xmlChar *)"xmlns")
64 #define XMLNS_LEN 5
65 
66 #define XMLNS_SEPCH ':'
67 
68 /* only compare if both elements have namespaces specified
69  * If either one is 'no namespace', then it is considered a match
70  */
71 #define XMLNS_EQ(NS1,NS2) (((NS1) && (NS2)) && ((NS1)==(NS2)))
72 
73 /********************************************************************
74 * *
75 * T Y P E S *
76 * *
77 *********************************************************************/
78 
79 
89 typedef uint16 xmlns_id_t;
90 
91 
93 typedef struct xmlns_qname_t_ {
95  const xmlChar *name;
96 } xmlns_qname_t;
97 
99 typedef struct xmlns_t_ {
102 
104  xmlChar *ns_pfix;
105 
107  xmlChar *ns_name;
108 
110  xmlChar *ns_module;
111 
114 
118  boolean ns_temporary;
119 
123  boolean ns_deleted;
124 } xmlns_t;
125 
126 
128 typedef struct xmlns_pmap_t_ {
130  dlq_hdr_t qhdr;
131 
134 
136  xmlChar *nm_pfix;
137 
139  boolean nm_topattr;
140 } xmlns_pmap_t;
141 
142 
143 /********************************************************************
144 * *
145 * F U N C T I O N S *
146 * *
147 *********************************************************************/
148 
149 
154 extern void
155  xmlns_init (void);
156 
157 
162 extern void
163  xmlns_cleanup (void);
164 
165 
181 extern status_t
182  xmlns_register_ns (const xmlChar *ns,
183  const xmlChar *pfix,
184  const xmlChar *modname,
185  void *modptr,
186  xmlns_id_t *ns_id);
187 
188 
194 extern void
196 
197 
207 extern status_t
208  xmlns_register_temp_ns (const xmlChar *ns,
209  const xmlChar *pfix,
210  xmlns_id_t *ns_id);
211 
212 
223 extern status_t
225  const xmlChar *pfix,
226  const xmlChar *modname,
227  void *modptr);
228 
229 
236 extern const xmlChar *
238 
239 
246 extern const xmlChar *
248 
249 
256 extern xmlns_id_t
257  xmlns_find_ns_by_module (const xmlChar *modname);
258 
259 
266 extern xmlns_id_t
267  xmlns_find_ns_by_prefix (const xmlChar *pfix);
268 
269 
276 extern xmlns_id_t
277  xmlns_find_ns_by_name (const xmlChar *name);
278 
279 
287 extern xmlns_id_t
288  xmlns_find_ns_by_name_str (const xmlChar *name,
289  uint32 namelen);
290 
291 
297 extern xmlns_id_t
298  xmlns_nc_id (void);
299 
300 
306 extern xmlns_id_t
307  xmlns_ncx_id (void);
308 
309 
315 extern xmlns_id_t
316  xmlns_ns_id (void);
317 
318 
324 extern xmlns_id_t
325  xmlns_inv_id (void);
326 
327 
333 extern xmlns_id_t
334  xmlns_xs_id (void);
335 
336 
342 extern xmlns_id_t
343  xmlns_xsi_id (void);
344 
345 
351 extern xmlns_id_t
352  xmlns_xml_id (void);
353 
354 
361 extern xmlns_id_t
362  xmlns_ncn_id (void);
363 
364 
371 extern xmlns_id_t
372  xmlns_yang_id (void);
373 
374 
381 extern xmlns_id_t
382  xmlns_yin_id (void);
383 
384 
391 extern xmlns_id_t
392  xmlns_wildcard_id (void);
393 
394 
401 extern xmlns_id_t
402  xmlns_wda_id (void);
403 
404 
411 extern xmlns_id_t
412  xmlns_ywattrs_id (void);
413 
414 
421 extern xmlns_id_t
422  xmlns_origin_id (void);
423 
424 
433 extern const xmlChar *
435 
436 
443 extern void *
445 
446 
453 extern void
454  xmlns_set_modptrs (const xmlChar *modname,
455  void *modptr);
456 
457 
463 extern void
464  xmlns_clear_modptrs (void *modptr);
465 
466 
474 extern xmlns_pmap_t *
475  xmlns_new_pmap (uint32 buffsize);
476 
477 
483 extern void
484  xmlns_free_pmap (xmlns_pmap_t *pmap);
485 
486 
492 extern xmlns_qname_t *
493  xmlns_new_qname (void);
494 
495 
501 extern void
502  xmlns_free_qname (xmlns_qname_t *qname);
503 
504 
514 extern boolean
516  xmlns_id_t ns2);
517 
522 extern void
523  xmlns_check_deleted_ns (void);
524 
525 
529 #ifdef __cplusplus
530 } /* end extern 'C' */
531 #endif
532 
533 #endif /* _H_xmlns */
xml_strlen
uint32 xml_strlen(const xmlChar *str)
Get the String len for xmlChar.
Definition: xml_util.c:1406
xmlns_t_::ns_id
xmlns_id_t ns_id
namespace ID is slot number + 1
Definition: xmlns.h:101
xmlns_pmap_t_::nm_id
xmlns_id_t nm_id
namespace ID in mapping
Definition: xmlns.h:133
xmlns_find_ns_by_name_str
xmlns_id_t xmlns_find_ns_by_name_str(const xmlChar *name, uint32 namelen)
Find the NS ID from its name (counted string version)
Definition: xmlns.c:831
xml_strdup
xmlChar * xml_strdup(const xmlChar *copyFrom)
String duplicate for xmlChar.
Definition: xml_util.c:1553
def_reg_find_ns
xmlns_t * def_reg_find_ns(const xmlChar *nsname)
find one xmlns_t in the registry find a xmlns_t by its value (name)
Definition: def_reg.c:397
xmlns_find_ns_by_prefix
xmlns_id_t xmlns_find_ns_by_prefix(const xmlChar *pfix)
Find the NS ID from its prefix.
Definition: xmlns.c:755
xmlns_t_::ns_deleted
boolean ns_deleted
flag that the namespace is deleted and only actually remove this entry when no message processing is ...
Definition: xmlns.h:123
xmlns_init
void xmlns_init(void)
Initialize the module static variables.
Definition: xmlns.c:437
YANG_URN
#define YANG_URN
YANG URN.
Definition: yangconst.h:64
xml_util.h
XML Utilities.
xmlns_clear_modptrs
void xmlns_clear_modptrs(void *modptr)
Clear the module pointer for the namespace ID.
Definition: xmlns.c:1216
xmlns_unregister_ns
void xmlns_unregister_ns(xmlns_id_t ns_id)
Unregister the specified namespace.
Definition: xmlns.c:525
xmlns_register_temp_ns
status_t xmlns_register_temp_ns(const xmlChar *ns, const xmlChar *pfix, xmlns_id_t *ns_id)
Register the specified temporary namespace.
Definition: xmlns.c:561
XML_URN
#define XML_URN
URN for XML.
Definition: ncxconst.h:215
xmlns_ns_id
xmlns_id_t xmlns_ns_id(void)
Get the ID for the XMLNS namespace or 0 if it doesn't exist.
Definition: xmlns.c:914
ERR_TOO_MANY_ENTRIES
@ ERR_TOO_MANY_ENTRIES
012
Definition: status_enum.h:202
xmlns_pmap_t_
represents one namespace prefix mapping
Definition: xmlns.h:128
xmlns_t_::ns_temporary
boolean ns_temporary
temporary flag used for unknown and other runtime namespace assignments
Definition: xmlns.h:118
xmlns_t_::ns_name
xmlChar * ns_name
namespace URI value
Definition: xmlns.h:107
xmlns_ncn_id
xmlns_id_t xmlns_ncn_id(void)
Get the ID for the NETCONF Notifications namespace or 0 if it doesn't exist.
Definition: xmlns.c:999
ncxconst.h
Contains NCX constants.
xmlns_get_module
const xmlChar * xmlns_get_module(xmlns_id_t nsid)
get the module name of the namespace ID
Definition: xmlns.c:1126
xmlns_id_t
uint16 xmlns_id_t
integer handle for registered namespaces
Definition: xmlns.h:89
xmlns_yang_id
xmlns_id_t xmlns_yang_id(void)
Get the ID for the YANG namespace or 0 if it doesn't exist.
Definition: xmlns.c:1017
xmlns_pmap_t_::nm_topattr
boolean nm_topattr
flag set if this xmlns is a top-level attribute
Definition: xmlns.h:139
log_debug2
void void void void void void void void void log_debug2(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG2 log entry.
def_reg.h
Definition Registry module.
xmlns_ywattrs_id
xmlns_id_t xmlns_ywattrs_id(void)
Get the ID for the YumaWorks attributes namespace or 0 if it doesn't exist.
Definition: xmlns.c:1090
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
ERR_NCX_OPERATION_FAILED
@ ERR_NCX_OPERATION_FAILED
274
Definition: status_enum.h:315
NC_WD_ATTR_URN
#define NC_WD_ATTR_URN
URN for with-defaults 'default' XML attribute.
Definition: ncxconst.h:189
LOGDEBUG2
#define LOGDEBUG2
Check if at least log-level=debug2.
Definition: log.h:292
xmlns_xsi_id
xmlns_id_t xmlns_xsi_id(void)
Get the ID for the XSD Instance (XSI) namespace or 0 if it doesn't exist.
Definition: xmlns.c:964
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
xmlns_wda_id
xmlns_id_t xmlns_wda_id(void)
Get the ID for the wd:default XML attribute namespace or 0 if it doesn't exist.
Definition: xmlns.c:1071
xmlns_find_ns_by_module
xmlns_id_t xmlns_find_ns_by_module(const xmlChar *modname)
Find the NS ID from its module name that registered it.
Definition: xmlns.c:712
xmlns_free_qname
void xmlns_free_qname(xmlns_qname_t *qname)
free a xmlns_qname_t struct
Definition: xmlns.c:1334
xmlns_new_pmap
xmlns_pmap_t * xmlns_new_pmap(uint32 buffsize)
malloc and initialize a new xmlns_pmap_t struct
Definition: xmlns.c:1249
xmlns_t_::ns_pfix
xmlChar * ns_pfix
XML prefix for namespace usually same as YANG module prefix.
Definition: xmlns.h:104
xmlns_wildcard_id
xmlns_id_t xmlns_wildcard_id(void)
Get the ID for the base:1.1 wildcard namespace or 0 if it doesn't exist.
Definition: xmlns.c:1053
ORIGIN_URN
#define ORIGIN_URN
URN for ietf-origin module.
Definition: ncxconst.h:232
ERR_NCX_INVALID_VALUE
@ ERR_NCX_INVALID_VALUE
258
Definition: status_enum.h:299
ERR_NCX_WRONG_LEN
@ ERR_NCX_WRONG_LEN
222
Definition: status_enum.h:261
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
xml_strncmp
int xml_strncmp(const xmlChar *s1, const xmlChar *s2, uint32 maxlen)
String compare for xmlChar for at most 'maxlen' xmlChars.
Definition: xml_util.c:1824
xmlns_new_qname
xmlns_qname_t * xmlns_new_qname(void)
malloc and initialize a new xmlns_qname_t struct
Definition: xmlns.c:1310
ERR_INTERNAL_PTR
@ ERR_INTERNAL_PTR
002
Definition: status_enum.h:192
xmlns_get_ns_prefix
const xmlChar * xmlns_get_ns_prefix(xmlns_id_t ns_id)
Get the prefix for the specified namespace.
Definition: xmlns.c:669
yangconst.h
Contains YANG constants separated to prevent H file include loops.
INVALID_URN
#define INVALID_URN
name used for invalid namespace
Definition: ncxconst.h:130
xmlns_t_::ns_module
xmlChar * ns_module
module name associated with this namespace
Definition: xmlns.h:110
xmlns_qname_t_::nsid
xmlns_id_t nsid
namespace ID
Definition: xmlns.h:94
xmlns_t_::ns_mod
struct ncx_module_t_ * ns_mod
module backptr if module loaded for this namespace
Definition: xmlns.h:113
YIN_URN
#define YIN_URN
YIN URN.
Definition: yangconst.h:76
ERR_NCX_NOT_FOUND
@ ERR_NCX_NOT_FOUND
225
Definition: status_enum.h:264
xmlns_pmap_t_::nm_pfix
xmlChar * nm_pfix
namespace prefix in mapping
Definition: xmlns.h:136
NCX_MAX_NUMLEN
#define NCX_MAX_NUMLEN
max number len to use for static buffer allocation only
Definition: ncxconst.h:136
xmlns_xml_id
xmlns_id_t xmlns_xml_id(void)
Get the ID for the 1998 XML namespace or 0 if it doesn't exist.
Definition: xmlns.c:981
ncx_module_t_
representation of one module or submodule during and after parsing
Definition: ncxtypes.h:900
NS_URN
#define NS_URN
XML Namespace URN.
Definition: ncxconst.h:268
xmlns_qname_t_::name
const xmlChar * name
local-name
Definition: xmlns.h:95
EMPTY_STRING
#define EMPTY_STRING
empty string used to get const xmlChar * cast
Definition: ncxconst.h:289
XSD_URN
#define XSD_URN
URN for XSD.
Definition: ncxconst.h:202
xml_strcmp
int xml_strcmp(const xmlChar *s1, const xmlChar *s2)
String compare for xmlChar.
Definition: xml_util.c:1746
xmlns_pmap_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: xmlns.h:130
xmlns_t_
represents one registered namespace
Definition: xmlns.h:99
log.h
NCX System Logging Manager.
def_reg_add_ns
status_t def_reg_add_ns(xmlns_t *ns)
add one xmlns_t to the registry
Definition: def_reg.c:372
xmlns_nc_id
xmlns_id_t xmlns_nc_id(void)
Get the ID for the NETCONF namespace or 0 if it doesn't exist.
Definition: xmlns.c:880
xmlns_yin_id
xmlns_id_t xmlns_yin_id(void)
Get the ID for the YIN namespace or 0 if it doesn't exist.
Definition: xmlns.c:1035
xmlns_xs_id
xmlns_id_t xmlns_xs_id(void)
Get the ID for the XSD namespace or 0 if it doesn't exist.
Definition: xmlns.c:948
XSI_URN
#define XSI_URN
URN for XSI.
Definition: ncxconst.h:208
NC_URN
#define NC_URN
NETCONF namespace used for base:10 and base:1.1.
Definition: ncxconst.h:100
xmlns_get_modptr
void * xmlns_get_modptr(xmlns_id_t nsid)
get the module pointer for the namespace ID
Definition: xmlns.c:1151
ncx.h
YANG module utility functions.
xmlns_convert_temp_ns
status_t xmlns_convert_temp_ns(xmlns_id_t nsid, const xmlChar *pfix, const xmlChar *modname, void *modptr)
Register the specified permanent namespace by converting the specified temporary NSID to a permanent ...
Definition: xmlns.c:597
xmlns_free_pmap
void xmlns_free_pmap(xmlns_pmap_t *pmap)
free a xmlns_pmap_t struct
Definition: xmlns.c:1284
xmlns_qname_t_
represents one QName data element
Definition: xmlns.h:93
NCN_URN
#define NCN_URN
URN for NETCONF Notifications.
Definition: ncxconst.h:222
xmlns_ids_equal
boolean xmlns_ids_equal(xmlns_id_t ns1, xmlns_id_t ns2)
compare 2 namespace IDs only if they are both non-zero and return TRUE if they are equal
Definition: xmlns.c:1363
xmlns_get_ns_name
const xmlChar * xmlns_get_ns_name(xmlns_id_t ns_id)
Get the name for the specified namespace.
Definition: xmlns.c:690
xmlns_inv_id
xmlns_id_t xmlns_inv_id(void)
Get the INVALID namespace ID.
Definition: xmlns.c:931
YWATTRS_URN
#define YWATTRS_URN
URN for YumaWorks XML Attributes.
Definition: ncxconst.h:229
ERR_DUP_NS
@ ERR_DUP_NS
211
Definition: status_enum.h:250
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
xmlns_cleanup
void xmlns_cleanup(void)
Cleanup module static data.
Definition: xmlns.c:458
WILDCARD_URN
#define WILDCARD_URN
base:1.1 subtree wildcard URN
Definition: ncxconst.h:133
xmlns_ncx_id
xmlns_id_t xmlns_ncx_id(void)
Get the ID for the NETCONF Extensions namespace or 0 if it doesn't exist.
Definition: xmlns.c:897
xmlns_find_ns_by_name
xmlns_id_t xmlns_find_ns_by_name(const xmlChar *name)
Find the NS ID from its name.
Definition: xmlns.c:797
xmlns_register_ns
status_t xmlns_register_ns(const xmlChar *ns, const xmlChar *pfix, const xmlChar *modname, void *modptr, xmlns_id_t *ns_id)
Register the specified namespace.
Definition: xmlns.c:494
xmlns.h
XML namespace support.
NCX_URN
#define NCX_URN
URN for NCX extensions.
Definition: ncxconst.h:196
status.h
Global error messages for status code enumerations.
dlq.h
dlq provides general double-linked list and queue support:
xmlns_check_deleted_ns
void xmlns_check_deleted_ns(void)
Check if a deleted namespace is pending and free it.
Definition: xmlns.c:1382
xmlns_origin_id
xmlns_id_t xmlns_origin_id(void)
Get the ID for the ietf-origin namespace or 0 if it doesn't exist.
Definition: xmlns.c:1108
xmlns_set_modptrs
void xmlns_set_modptrs(const xmlChar *modname, void *modptr)
get the module pointer for the namespace ID
Definition: xmlns.c:1176