mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
XMLification (wave 1)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1401 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -1,4 +1,35 @@
|
||||
/* switch_xml.h
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
||||
*
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Anthony Minessale II <anthmct@yahoo.com>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Anthony Minessale II <anthmct@yahoo.com>
|
||||
*
|
||||
*
|
||||
* switch_xml.h -- XML PARSER
|
||||
*
|
||||
* Derived from EZXML http://ezxml.sourceforge.net
|
||||
* Original Copyright
|
||||
*
|
||||
* Copyright 2004, 2005 Aaron Voisine <aaron@voisine.org>
|
||||
*
|
||||
@@ -24,7 +55,7 @@
|
||||
|
||||
#ifndef _SWITCH_XML_H
|
||||
#define _SWITCH_XML_H
|
||||
|
||||
#include <switch_types.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@@ -34,11 +65,14 @@ BEGIN_EXTERN_C
|
||||
|
||||
#define SWITCH_XML_BUFSIZE 1024 // size of internal memory buffers
|
||||
|
||||
#define SWITCH_XML_NAMEM 0x80 // name is malloced
|
||||
#define SWITCH_XML_TXTM 0x40 // txt is malloced
|
||||
#define SWITCH_XML_DUP 0x20 // attribute name and value are strduped
|
||||
typedef enum {
|
||||
SWITCH_XML_ROOT = (1 << 0), // root
|
||||
SWITCH_XML_NAMEM = (1 << 1), // name is malloced
|
||||
SWITCH_XML_TXTM = (1 << 2), // txt is malloced
|
||||
SWITCH_XML_DUP = (1 << 3) // attribute name and value are strduped
|
||||
} switch_xml_flag_t;
|
||||
|
||||
|
||||
typedef struct switch_xml *switch_xml_t;
|
||||
struct switch_xml {
|
||||
char *name; // tag name
|
||||
char **attr; // tag attributes { name, value, name, value, ... NULL }
|
||||
@@ -49,31 +83,33 @@ struct switch_xml {
|
||||
switch_xml_t ordered; // next tag, same section and depth, in original order
|
||||
switch_xml_t child; // head of sub tag list, NULL if none
|
||||
switch_xml_t parent; // parent tag, NULL if current tag is root tag
|
||||
short flags; // additional information
|
||||
uint32_t flags; // additional information
|
||||
};
|
||||
|
||||
// Given a string of xml data and its length, parses it and creates an switch_xml
|
||||
// structure. For efficiency, modifies the data by adding null terminators
|
||||
// and decoding ampersand sequences. If you don't want this, copy the data and
|
||||
// pass in the copy. Returns NULL on failure.
|
||||
switch_xml_t switch_xml_parse_str(char *s, switch_size_t len);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len);
|
||||
|
||||
// A wrapper for switch_xml_parse_str() that accepts a file descriptor. First
|
||||
// attempts to mem map the file. Failing that, reads the file into memory.
|
||||
// Returns NULL on failure.
|
||||
switch_xml_t switch_xml_parse_fd(int fd);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd);
|
||||
|
||||
// a wrapper for switch_xml_parse_fd() that accepts a file name
|
||||
switch_xml_t switch_xml_parse_file(const char *file);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file);
|
||||
|
||||
// Wrapper for switch_xml_parse_str() that accepts a file stream. Reads the entire
|
||||
// stream into memory and then parses it. For xml files, use switch_xml_parse_file()
|
||||
// or switch_xml_parse_fd()
|
||||
switch_xml_t switch_xml_parse_fp(FILE *fp);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE *fp);
|
||||
|
||||
// returns the first child tag (one level deeper) with the given name or NULL
|
||||
// if not found
|
||||
switch_xml_t switch_xml_child(switch_xml_t xml, const char *name);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_child(switch_xml_t xml, const char *name);
|
||||
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_find_child(switch_xml_t node, char *childname, char *attrname, char *value);
|
||||
|
||||
// returns the next tag of the same name in the same section and depth or NULL
|
||||
// if not found
|
||||
@@ -90,7 +126,7 @@ switch_xml_t switch_xml_idx(switch_xml_t xml, int idx);
|
||||
#define switch_xml_txt(xml) ((xml) ? xml->txt : "")
|
||||
|
||||
// returns the value of the requested tag attribute, or NULL if not found
|
||||
const char *switch_xml_attr(switch_xml_t xml, const char *attr);
|
||||
SWITCH_DECLARE(const char *) switch_xml_attr(switch_xml_t xml, const char *attr);
|
||||
|
||||
// Traverses the switch_xml sturcture to retrieve a specific subtag. Takes a
|
||||
// variable length list of tag names and indexes. The argument list must be
|
||||
@@ -98,24 +134,24 @@ const char *switch_xml_attr(switch_xml_t xml, const char *attr);
|
||||
// title = switch_xml_get(library, "shelf", 0, "book", 2, "title", -1);
|
||||
// This retrieves the title of the 3rd book on the 1st shelf of library.
|
||||
// Returns NULL if not found.
|
||||
switch_xml_t switch_xml_get(switch_xml_t xml, ...);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml, ...);
|
||||
|
||||
// Converts an switch_xml structure back to xml. Returns a string of xml data that
|
||||
// must be freed.
|
||||
char *switch_xml_toxml(switch_xml_t xml);
|
||||
SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml);
|
||||
|
||||
// returns a NULL terminated array of processing instructions for the given
|
||||
// target
|
||||
const char **switch_xml_pi(switch_xml_t xml, const char *target);
|
||||
SWITCH_DECLARE(const char **) switch_xml_pi(switch_xml_t xml, const char *target);
|
||||
|
||||
// frees the memory allocated for an switch_xml structure
|
||||
void switch_xml_free(switch_xml_t xml);
|
||||
|
||||
// returns parser error message or empty string if none
|
||||
const char *switch_xml_error(switch_xml_t xml);
|
||||
SWITCH_DECLARE(const char *) switch_xml_error(switch_xml_t xml);
|
||||
|
||||
// returns a new empty switch_xml structure with the given root tag name
|
||||
switch_xml_t switch_xml_new(const char *name);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_new(const char *name);
|
||||
|
||||
// wrapper for switch_xml_new() that strdup()s name
|
||||
#define switch_xml_new_d(name) switch_xml_set_flag(switch_xml_new(strdup(name)), SWITCH_XML_NAMEM)
|
||||
@@ -137,17 +173,33 @@ switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt);
|
||||
|
||||
// Sets the given tag attribute or adds a new attribute if not found. A value
|
||||
// of NULL will remove the specified attribute.
|
||||
void switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value);
|
||||
SWITCH_DECLARE(void) switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value);
|
||||
|
||||
// Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL
|
||||
#define switch_xml_set_attr_d(xml, name, value) \
|
||||
switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value))
|
||||
|
||||
// sets a flag for the given tag and returns the tag
|
||||
switch_xml_t switch_xml_set_flag(switch_xml_t xml, short flag);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_set_flag(switch_xml_t xml, switch_xml_flag_t flag);
|
||||
|
||||
|
||||
// removes a tag along with all its subtags
|
||||
void switch_xml_remove(switch_xml_t xml);
|
||||
SWITCH_DECLARE(void) switch_xml_remove(switch_xml_t xml);
|
||||
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload);
|
||||
SWITCH_DECLARE(switch_status_t) switch_xml_init(switch_memory_pool_t *pool);
|
||||
SWITCH_DECLARE(switch_status_t) switch_xml_destroy(void);
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_root(void);
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_xml_locate(char *section,
|
||||
char *tag_name,
|
||||
char *key_name,
|
||||
char *key_value,
|
||||
switch_xml_t *root,
|
||||
switch_xml_t *node);
|
||||
|
||||
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *node);
|
||||
SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function);
|
||||
|
||||
END_EXTERN_C
|
||||
|
||||
|
Reference in New Issue
Block a user