Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
af5281e9
提交
af5281e9
authored
12月 11, 2015
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert commit from PR 585
上级
0363be40
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
64 行删除
+31
-64
switch_xml.c
src/switch_xml.c
+31
-64
没有找到文件。
src/switch_xml.c
浏览文件 @
af5281e9
...
@@ -2955,91 +2955,58 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *tx
...
@@ -2955,91 +2955,58 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *tx
of NULL will remove the specified attribute. Returns the tag given */
of NULL will remove the specified attribute. Returns the tag given */
SWITCH_DECLARE
(
switch_xml_t
)
switch_xml_set_attr
(
switch_xml_t
xml
,
const
char
*
name
,
const
char
*
value
)
SWITCH_DECLARE
(
switch_xml_t
)
switch_xml_set_attr
(
switch_xml_t
xml
,
const
char
*
name
,
const
char
*
value
)
{
{
int
l
=
0
,
attr_number
,
c
;
int
l
=
0
,
c
;
/* After adding the first attribute, xml->attr = { name1, val1, name2, val2,
* ..., nameN, valN, NULL, alloc_flags }. alloc_flags tracks how the memory
* for each attr and value is managed. */
char
*
alloc_flags
;
if
(
!
xml
)
if
(
!
xml
)
return
NULL
;
return
NULL
;
while
(
xml
->
attr
[
l
]
&&
strcmp
(
xml
->
attr
[
l
],
name
))
while
(
xml
->
attr
[
l
]
&&
strcmp
(
xml
->
attr
[
l
],
name
))
l
+=
2
;
l
+=
2
;
attr_number
=
l
/
2
;
if
(
!
xml
->
attr
[
l
])
{
/* not found, add as new attribute */
if
(
!
xml
->
attr
[
l
])
{
/* not found, add as new attribute */
if
(
!
value
)
if
(
!
value
)
goto
cleanup
;
/* not found, no need to remove attribute
*/
return
xml
;
/* nothing to do
*/
if
(
xml
->
attr
==
SWITCH_XML_NIL
)
{
/* first attribute */
if
(
xml
->
attr
==
SWITCH_XML_NIL
)
{
/* first attribute */
char
**
tmp
=
(
char
**
)
malloc
(
4
*
sizeof
(
char
*
));
xml
->
attr
=
(
char
**
)
malloc
(
4
*
sizeof
(
char
*
));
if
(
!
tmp
)
if
(
!
xml
->
attr
)
goto
cleanup
;
return
NULL
;
xml
->
attr
=
tmp
;
xml
->
attr
[
1
]
=
strdup
(
""
);
/* empty list of malloced names/vals */
assert
(
l
==
0
);
/* name of SWITCH_XML_NIL is assumed to be empty */
xml
->
attr
[
0
]
=
NULL
;
/* terminator */
xml
->
attr
[
1
]
=
NULL
;
/* empty list of malloced names/vals */
}
else
{
}
else
{
char
**
tmp
=
(
char
**
)
realloc
(
xml
->
attr
,
(
l
+
4
)
*
sizeof
(
char
*
));
char
**
tmp
=
(
char
**
)
realloc
(
xml
->
attr
,
(
l
+
4
)
*
sizeof
(
char
*
));
if
(
!
tmp
)
if
(
!
tmp
)
goto
cleanup
;
return
xml
;
xml
->
attr
=
tmp
;
xml
->
attr
=
tmp
;
}
}
/* Extend list of allocation flags for the new attribute */
alloc_flags
=
(
char
*
)
realloc
(
xml
->
attr
[
l
+
1
],
attr_number
+
1
);
if
(
!
alloc_flags
)
goto
cleanup
;
alloc_flags
[
attr_number
+
1
]
=
'\0'
;
/* terminate list */
/* Add new attribute, the value will be set further below. */
xml
->
attr
[
l
]
=
(
char
*
)
name
;
/* set attribute name */
xml
->
attr
[
l
]
=
(
char
*
)
name
;
/* set attribute name */
name
=
NULL
;
/* control of memory is transferred */
xml
->
attr
[
l
+
2
]
=
NULL
;
/* null terminate attribute list */
l
+=
2
;
xml
->
attr
[
l
+
3
]
=
(
char
*
)
realloc
(
xml
->
attr
[
l
+
1
],
(
c
=
(
int
)
strlen
(
xml
->
attr
[
l
+
1
]))
+
2
);
strcpy
(
xml
->
attr
[
l
+
3
]
+
c
,
" "
);
/* set name/value as not malloced */
xml
->
attr
[
l
]
=
NULL
;
/* null terminate attribute list */
xml
->
attr
[
l
+
1
]
=
alloc_flags
;
if
(
xml
->
flags
&
SWITCH_XML_DUP
)
if
(
xml
->
flags
&
SWITCH_XML_DUP
)
alloc_flags
[
attr_number
]
=
SWITCH_XML_NAMEM
;
xml
->
attr
[
l
+
3
][
c
]
=
SWITCH_XML_NAMEM
;
else
}
else
if
(
xml
->
flags
&
SWITCH_XML_DUP
)
alloc_flags
[
attr_number
]
=
' '
;
/* dummy value */
free
((
char
*
)
name
);
/* name was strduped */
}
else
{
while
(
xml
->
attr
[
l
])
l
+=
2
;
alloc_flags
=
xml
->
attr
[
l
+
1
];
}
c
=
2
*
attr_number
;
/* index of the current attribute name */
/* l points to the index of the terminator name */
if
(
alloc_flags
[
attr_number
]
&
SWITCH_XML_TXTM
)
for
(
c
=
l
;
xml
->
attr
[
c
];
c
+=
2
);
/* find end of attribute list */
free
(
xml
->
attr
[
c
+
1
]);
/* old val */
if
(
xml
->
attr
[
c
+
1
][
l
/
2
]
&
SWITCH_XML_TXTM
)
free
(
xml
->
attr
[
l
+
1
]);
/* old val */
if
(
xml
->
flags
&
SWITCH_XML_DUP
)
if
(
xml
->
flags
&
SWITCH_XML_DUP
)
alloc_flags
[
attr_number
]
|=
SWITCH_XML_TXTM
;
xml
->
attr
[
c
+
1
][
l
/
2
]
|=
SWITCH_XML_TXTM
;
else
else
alloc_flags
[
attr_number
]
&=
~
SWITCH_XML_TXTM
;
xml
->
attr
[
c
+
1
][
l
/
2
]
&=
~
SWITCH_XML_TXTM
;
if
(
value
)
{
if
(
value
)
xml
->
attr
[
c
+
1
]
=
(
char
*
)
value
;
/* set attribute value */
xml
->
attr
[
l
+
1
]
=
(
char
*
)
value
;
/* set attribute value */
value
=
NULL
;
/* control of memory is transferred */
else
{
/* remove attribute */
}
else
{
/* remove attribute */
char
**
tmp
;
char
**
tmp
;
/* free name if it was dynamically allocated (value is handled above) */
if
(
xml
->
attr
[
c
+
1
][
l
/
2
]
&
SWITCH_XML_NAMEM
)
if
(
alloc_flags
[
attr_number
]
&
SWITCH_XML_NAMEM
)
free
(
xml
->
attr
[
l
]);
free
(
xml
->
attr
[
c
]);
memmove
(
xml
->
attr
+
l
,
xml
->
attr
+
l
+
2
,
(
c
-
l
+
2
)
*
sizeof
(
char
*
));
tmp
=
(
char
**
)
realloc
(
xml
->
attr
,
(
c
+
2
)
*
sizeof
(
char
*
));
/* drop (name, value) pair from attribute list */
if
(
!
tmp
)
memmove
(
xml
->
attr
+
c
,
xml
->
attr
+
c
+
2
,
(
l
-
c
)
*
sizeof
(
char
*
));
return
xml
;
tmp
=
(
char
**
)
realloc
(
xml
->
attr
,
l
*
sizeof
(
char
*
));
if
(
tmp
)
/* try to shrink when possible */
xml
->
attr
=
tmp
;
xml
->
attr
=
tmp
;
memmove
(
xml
->
attr
[
c
+
1
]
+
(
l
/
2
),
xml
->
attr
[
c
+
1
]
+
(
l
/
2
)
+
1
,
(
c
/
2
)
-
(
l
/
2
));
/* fix list of which name/vals are malloced */
memmove
(
alloc_flags
+
attr_number
,
alloc_flags
+
attr_number
+
1
,
(
l
-
c
)
/
2
);
/* shrink allocation info */
}
}
cleanup
:
if
(
xml
->
flags
&
SWITCH_XML_DUP
)
{
free
((
char
*
)
name
);
/* name was strduped */
free
((
char
*
)
value
);
/* name was strduped, but an error occurred */
xml
->
flags
&=
~
SWITCH_XML_DUP
;
/* clear strdup() flag */
xml
->
flags
&=
~
SWITCH_XML_DUP
;
/* clear strdup() flag */
}
return
xml
;
return
xml
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论