1 /* 2 * Generic XML helper functions 3 * Copyright (c) 2012-2013, Qualcomm Atheros, Inc. 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #ifndef XML_UTILS_H 10 #define XML_UTILS_H 11 12 struct xml_node_ctx; 13 typedef struct xml_node xml_node_t; 14 typedef struct xml_namespace_foo xml_namespace_t; 15 16 /* XML library wrappers */ 17 18 void xml_node_free(struct xml_node_ctx *ctx, xml_node_t *node); 19 xml_node_t * xml_node_from_buf(struct xml_node_ctx *ctx, const char *buf); 20 const char * xml_node_get_localname(struct xml_node_ctx *ctx, 21 xml_node_t *node); 22 char * xml_node_to_str(struct xml_node_ctx *ctx, xml_node_t *node); 23 xml_node_t * xml_node_create_root(struct xml_node_ctx *ctx, const char *ns_uri, 24 const char *ns_prefix, 25 xml_namespace_t **ret_ns, const char *name); 26 xml_node_t * xml_node_create(struct xml_node_ctx *ctx, xml_node_t *parent, 27 xml_namespace_t *ns, const char *name); 28 xml_node_t * xml_node_create_text(struct xml_node_ctx *ctx, 29 xml_node_t *parent, xml_namespace_t *ns, 30 const char *name, const char *value); 31 xml_node_t * xml_node_create_text_ns(struct xml_node_ctx *ctx, 32 xml_node_t *parent, const char *ns_uri, 33 const char *name, const char *value); 34 void xml_node_set_text(struct xml_node_ctx *ctx, xml_node_t *node, 35 const char *value); 36 xml_node_t * xml_node_first_child(struct xml_node_ctx *ctx, 37 xml_node_t *parent); 38 xml_node_t * xml_node_next_sibling(struct xml_node_ctx *ctx, 39 xml_node_t *node); 40 int xml_node_is_element(struct xml_node_ctx *ctx, xml_node_t *node); 41 char * xml_node_get_text(struct xml_node_ctx *ctx, xml_node_t *node); 42 void xml_node_get_text_free(struct xml_node_ctx *ctx, char *val); 43 char * xml_node_get_base64_text(struct xml_node_ctx *ctx, xml_node_t *node, 44 int *ret_len); 45 46 #define xml_node_for_each_child(ctx, child, parent) \ 47 for (child = xml_node_first_child(ctx, parent); \ 48 child; \ 49 child = xml_node_next_sibling(ctx, child)) 50 51 #define xml_node_for_each_sibling(ctx, node) \ 52 for (; \ 53 node; \ 54 node = xml_node_next_sibling(ctx, node)) 55 56 #define xml_node_for_each_check(ctx, child) \ 57 if (!xml_node_is_element(ctx, child)) \ 58 continue 59 60 61 struct xml_node_ctx * xml_node_init_ctx(void *upper_ctx, 62 const void *env); 63 void xml_node_deinit_ctx(struct xml_node_ctx *ctx); 64 65 66 xml_node_t * get_node_uri(struct xml_node_ctx *ctx, xml_node_t *root, 67 const char *uri); 68 xml_node_t * get_node(struct xml_node_ctx *ctx, xml_node_t *root, 69 const char *path); 70 xml_node_t * get_child_node(struct xml_node_ctx *ctx, xml_node_t *root, 71 const char *path); 72 xml_node_t * node_from_file(struct xml_node_ctx *ctx, const char *name); 73 int node_to_file(struct xml_node_ctx *ctx, const char *fname, xml_node_t *node); 74 xml_node_t * mo_to_tnds(struct xml_node_ctx *ctx, xml_node_t *mo, 75 int use_path, const char *urn, const char *ns_uri); 76 xml_node_t * tnds_to_mo(struct xml_node_ctx *ctx, xml_node_t *tnds); 77 78 #endif /* XML_UTILS_H */ 79