Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
67ff0782
提交
67ff0782
authored
5月 05, 2006
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@1379
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
93345ede
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
25 行删除
+29
-25
switch_xml.h
src/include/switch_xml.h
+3
-3
switch_xml.c
src/switch_xml.c
+26
-22
没有找到文件。
src/include/switch_xml.h
浏览文件 @
67ff0782
...
...
@@ -43,7 +43,7 @@ struct switch_xml {
char
*
name
;
// tag name
char
**
attr
;
// tag attributes { name, value, name, value, ... NULL }
char
*
txt
;
// tag character content, empty string if none
size_t
off
;
// tag offset from start of parent tag character content
s
witch_s
ize_t
off
;
// tag offset from start of parent tag character content
switch_xml_t
next
;
// next tag with same name in this section at this depth
switch_xml_t
sibling
;
// next tag with different name in same section and depth
switch_xml_t
ordered
;
// next tag, same section and depth, in original order
...
...
@@ -56,7 +56,7 @@ struct 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
,
size_t
len
);
switch_xml_t
switch_xml_parse_str
(
char
*
s
,
s
witch_s
ize_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.
...
...
@@ -122,7 +122,7 @@ switch_xml_t switch_xml_new(const char *name);
// Adds a child tag. off is the offset of the child tag relative to the start
// of the parent tag's character content. Returns the child tag.
switch_xml_t
switch_xml_add_child
(
switch_xml_t
xml
,
const
char
*
name
,
size_t
off
);
switch_xml_t
switch_xml_add_child
(
switch_xml_t
xml
,
const
char
*
name
,
s
witch_s
ize_t
off
);
// wrapper for switch_xml_add_child() that strdup()s name
#define switch_xml_add_child_d(xml, name, off) \
...
...
src/switch_xml.c
浏览文件 @
67ff0782
...
...
@@ -226,11 +226,11 @@ static void switch_xml_open_tag(switch_xml_root_t root, char *name, char **attr)
}
// called when parser finds character content between open and closing tag
static
void
switch_xml_char_content
(
switch_xml_root_t
root
,
char
*
s
,
size_t
len
,
char
t
)
static
void
switch_xml_char_content
(
switch_xml_root_t
root
,
char
*
s
,
s
witch_s
ize_t
len
,
char
t
)
{
switch_xml_t
xml
=
root
->
cur
;
char
*
m
=
s
;
size_t
l
;
s
witch_s
ize_t
l
;
if
(
!
xml
||
!
xml
->
name
||
!
len
)
return
;
// sanity check
...
...
@@ -275,7 +275,7 @@ static int switch_xml_ent_ok(char *name, char *s, char **ent)
}
// called when the parser finds a processing instruction
static
void
switch_xml_proc_inst
(
switch_xml_root_t
root
,
char
*
s
,
size_t
len
)
static
void
switch_xml_proc_inst
(
switch_xml_root_t
root
,
char
*
s
,
s
witch_s
ize_t
len
)
{
int
i
=
0
,
j
=
1
;
char
*
target
=
s
;
...
...
@@ -312,7 +312,7 @@ static void switch_xml_proc_inst(switch_xml_root_t root, char *s, size_t len)
}
// called when the parser finds an internal doctype subset
static
short
switch_xml_internal_dtd
(
switch_xml_root_t
root
,
char
*
s
,
size_t
len
)
static
short
switch_xml_internal_dtd
(
switch_xml_root_t
root
,
char
*
s
,
s
witch_s
ize_t
len
)
{
char
q
,
*
c
,
*
t
,
*
n
=
NULL
,
*
v
,
**
ent
,
**
pe
;
int
i
,
j
;
...
...
@@ -415,10 +415,10 @@ static short switch_xml_internal_dtd(switch_xml_root_t root, char *s, size_t len
// Converts a UTF-16 string to UTF-8. Returns a new string that must be freed
// or NULL if no conversion was needed.
static
char
*
switch_xml_str2utf8
(
char
**
s
,
size_t
*
len
)
static
char
*
switch_xml_str2utf8
(
char
**
s
,
s
witch_s
ize_t
*
len
)
{
char
*
u
;
size_t
l
=
0
,
sl
,
max
=
*
len
;
s
witch_s
ize_t
l
=
0
,
sl
,
max
=
*
len
;
long
c
,
d
;
int
b
,
be
=
(
**
s
==
'\xFE'
)
?
1
:
(
**
s
==
'\xFF'
)
?
0
:
-
1
;
...
...
@@ -463,7 +463,7 @@ static void switch_xml_free_attr(char **attr) {
}
// parse the given xml string and return an switch_xml structure
switch_xml_t
switch_xml_parse_str
(
char
*
s
,
size_t
len
)
switch_xml_t
switch_xml_parse_str
(
char
*
s
,
s
witch_s
ize_t
len
)
{
switch_xml_root_t
root
=
(
switch_xml_root_t
)
switch_xml_new
(
NULL
);
char
q
,
e
,
*
d
,
**
attr
,
**
a
=
NULL
;
// initialize a to avoid compile warning
...
...
@@ -601,7 +601,7 @@ switch_xml_t switch_xml_parse_str(char *s, size_t len)
switch_xml_t
switch_xml_parse_fp
(
FILE
*
fp
)
{
switch_xml_root_t
root
;
size_t
l
,
len
=
0
;
s
witch_s
ize_t
l
,
len
=
0
;
char
*
s
;
if
(
!
(
s
=
malloc
(
SWITCH_XML_BUFSIZE
)))
return
NULL
;
...
...
@@ -623,7 +623,7 @@ switch_xml_t switch_xml_parse_fd(int fd)
{
switch_xml_root_t
root
;
struct
stat
st
;
size_t
l
;
s
witch_s
ize_t
l
;
void
*
m
;
if
(
fd
<
0
)
return
NULL
;
...
...
@@ -660,12 +660,15 @@ switch_xml_t switch_xml_parse_file(const char *file)
// Encodes ampersand sequences appending the results to *dst, reallocating *dst
// if length excedes max. a is non-zero for attribute encoding. Returns *dst
static
char
*
switch_xml_ampencode
(
const
char
*
s
,
size_t
len
,
char
**
dst
,
size_t
*
dlen
,
size_t
*
max
,
short
a
)
static
char
*
switch_xml_ampencode
(
const
char
*
s
,
switch_size_t
len
,
char
**
dst
,
switch_size_t
*
dlen
,
switch_size_t
*
max
,
short
a
)
{
const
char
*
e
;
const
char
*
e
=
NULL
;
if
(
len
)
{
e
=
s
+
len
;
}
for
(
e
=
s
+
len
;
s
!=
e
;
s
++
)
{
while
(
s
!=
e
)
{
while
(
*
dlen
+
10
>
*
max
)
*
dst
=
realloc
(
*
dst
,
*
max
+=
SWITCH_XML_BUFSIZE
);
switch
(
*
s
)
{
...
...
@@ -679,6 +682,7 @@ static char *switch_xml_ampencode(const char *s, size_t len, char **dst, size_t
case
'\r'
:
*
dlen
+=
sprintf
(
*
dst
+
*
dlen
,
"
"
);
break
;
default:
(
*
dst
)[(
*
dlen
)
++
]
=
*
s
;
}
s
++
;
}
return
*
dst
;
}
...
...
@@ -686,12 +690,12 @@ static char *switch_xml_ampencode(const char *s, size_t len, char **dst, size_t
// Recursively converts each tag to xml appending it to *s. Reallocates *s if
// its length excedes max. start is the location of the previous tag in the
// parent tag's character content. Returns *s.
static
char
*
switch_xml_toxml_r
(
switch_xml_t
xml
,
char
**
s
,
s
ize_t
*
len
,
size_t
*
max
,
size_t
start
,
char
***
attr
)
static
char
*
switch_xml_toxml_r
(
switch_xml_t
xml
,
char
**
s
,
s
witch_size_t
*
len
,
switch_
size_t
*
max
,
s
witch_s
ize_t
start
,
char
***
attr
)
{
int
i
,
j
;
char
*
txt
=
(
xml
->
parent
)
?
xml
->
parent
->
txt
:
""
;
size_t
off
=
0
;
s
witch_s
ize_t
off
=
0
;
// parent character content up to this tag
*
s
=
switch_xml_ampencode
(
txt
+
start
,
xml
->
off
-
start
,
s
,
len
,
max
,
0
);
...
...
@@ -706,7 +710,7 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, size_t *len, size_t
*
s
=
realloc
(
*
s
,
*
max
+=
SWITCH_XML_BUFSIZE
);
*
len
+=
sprintf
(
*
s
+
*
len
,
" %s=
\"
"
,
xml
->
attr
[
i
]);
switch_xml_ampencode
(
xml
->
attr
[
i
+
1
],
-
1
,
s
,
len
,
max
,
1
);
switch_xml_ampencode
(
xml
->
attr
[
i
+
1
],
0
,
s
,
len
,
max
,
1
);
*
len
+=
sprintf
(
*
s
+
*
len
,
"
\"
"
);
}
...
...
@@ -718,13 +722,13 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, size_t *len, size_t
*
s
=
realloc
(
*
s
,
*
max
+=
SWITCH_XML_BUFSIZE
);
*
len
+=
sprintf
(
*
s
+
*
len
,
" %s=
\"
"
,
attr
[
i
][
j
]);
switch_xml_ampencode
(
attr
[
i
][
j
+
1
],
-
1
,
s
,
len
,
max
,
1
);
switch_xml_ampencode
(
attr
[
i
][
j
+
1
],
0
,
s
,
len
,
max
,
1
);
*
len
+=
sprintf
(
*
s
+
*
len
,
"
\"
"
);
}
*
len
+=
sprintf
(
*
s
+
*
len
,
">"
);
*
s
=
(
xml
->
child
)
?
switch_xml_toxml_r
(
xml
->
child
,
s
,
len
,
max
,
0
,
attr
)
//child
:
switch_xml_ampencode
(
xml
->
txt
,
-
1
,
s
,
len
,
max
,
0
);
//data
:
switch_xml_ampencode
(
xml
->
txt
,
0
,
s
,
len
,
max
,
0
);
//data
while
(
*
len
+
strlen
(
xml
->
name
)
+
4
>
*
max
)
// reallocate s
*
s
=
realloc
(
*
s
,
*
max
+=
SWITCH_XML_BUFSIZE
);
...
...
@@ -733,7 +737,7 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, size_t *len, size_t
while
(
txt
[
off
]
&&
off
<
xml
->
off
)
off
++
;
// make sure off is within bounds
return
(
xml
->
ordered
)
?
switch_xml_toxml_r
(
xml
->
ordered
,
s
,
len
,
max
,
off
,
attr
)
:
switch_xml_ampencode
(
txt
+
off
,
-
1
,
s
,
len
,
max
,
0
);
:
switch_xml_ampencode
(
txt
+
off
,
0
,
s
,
len
,
max
,
0
);
}
// converts an switch_xml structure back to xml, returning it as a string that must
...
...
@@ -742,7 +746,7 @@ char *switch_xml_toxml(switch_xml_t xml)
{
switch_xml_t
p
=
(
xml
)
?
xml
->
parent
:
NULL
,
o
=
(
xml
)
?
xml
->
ordered
:
NULL
;
switch_xml_root_t
root
=
(
switch_xml_root_t
)
xml
;
size_t
len
=
0
,
max
=
SWITCH_XML_BUFSIZE
;
s
witch_s
ize_t
len
=
0
,
max
=
SWITCH_XML_BUFSIZE
;
char
*
s
=
strcpy
(
malloc
(
max
),
""
),
*
t
,
*
n
;
int
i
,
j
,
k
;
...
...
@@ -843,7 +847,7 @@ switch_xml_t switch_xml_new(const char *name)
// Adds a child tag. off is the offset of the child tag relative to the start
// of the parent tag's character content. returns the child tag
switch_xml_t
switch_xml_add_child
(
switch_xml_t
xml
,
const
char
*
name
,
size_t
off
)
switch_xml_t
switch_xml_add_child
(
switch_xml_t
xml
,
const
char
*
name
,
s
witch_s
ize_t
off
)
{
switch_xml_t
cur
,
head
,
child
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论