Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
6c31911a
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6c31911a
编写于
10月 07, 2014
作者:
J
Ján Tomko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce virStringStripIPv6Brackets
Helper function to strip the brackets from an IPv6 address. Tested by viruritest.
上级
4d1852c4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
79 addition
and
16 deletion
+79
-16
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/util/virstring.c
src/util/virstring.c
+23
-0
src/util/virstring.h
src/util/virstring.h
+2
-0
src/util/viruri.c
src/util/viruri.c
+4
-16
tests/virstringtest.c
tests/virstringtest.c
+49
-0
未找到文件。
src/libvirt_private.syms
浏览文件 @
6c31911a
...
...
@@ -2004,6 +2004,7 @@ virStringSortCompare;
virStringSortRevCompare;
virStringSplit;
virStringSplitCount;
virStringStripIPv6Brackets;
virStrncpy;
virStrndup;
virStrToDouble;
...
...
src/util/virstring.c
浏览文件 @
6c31911a
...
...
@@ -929,3 +929,26 @@ virStringReplace(const char *haystack,
return
virBufferContentAndReset
(
&
buf
);
}
/**
* virStringStripIPv6Brackets:
* @str: the string to strip
*
* Modify the string in-place to remove the leading and closing brackets
* from an IPv6 address.
*/
void
virStringStripIPv6Brackets
(
char
*
str
)
{
size_t
len
;
if
(
!
str
)
return
;
len
=
strlen
(
str
);
if
(
str
[
0
]
==
'['
&&
str
[
len
-
1
]
==
']'
&&
strchr
(
str
,
':'
))
{
memmove
(
&
str
[
0
],
&
str
[
1
],
len
-
2
);
str
[
len
-
2
]
=
'\0'
;
}
}
src/util/virstring.h
浏览文件 @
6c31911a
...
...
@@ -268,4 +268,6 @@ char *virStringReplace(const char *haystack,
const
char
*
newneedle
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
)
ATTRIBUTE_NONNULL
(
3
);
void
virStringStripIPv6Brackets
(
char
*
str
);
#endif
/* __VIR_STRING_H__ */
src/util/viruri.c
浏览文件 @
6c31911a
...
...
@@ -182,22 +182,10 @@ virURIParse(const char *uri)
if
(
VIR_STRDUP
(
ret
->
user
,
xmluri
->
user
)
<
0
)
goto
error
;
/* First check: does it even make sense to jump inside */
if
(
ret
->
server
!=
NULL
&&
ret
->
server
[
0
]
==
'['
)
{
size_t
length
=
strlen
(
ret
->
server
);
/* We want to modify the server string only if there are
* square brackets on both ends and inside there is IPv6
* address. Otherwise we could make a mistake by modifying
* something other than an IPv6 address. */
if
(
ret
->
server
[
length
-
1
]
==
']'
&&
strchr
(
ret
->
server
,
':'
))
{
memmove
(
&
ret
->
server
[
0
],
&
ret
->
server
[
1
],
length
-
2
);
ret
->
server
[
length
-
2
]
=
'\0'
;
}
/* Even after such modification, it is completely ok to free
* the uri with xmlFreeURI() */
}
/* Strip square bracket from an IPv6 address.
* The function modifies the string in-place. Even after such
* modification, it is OK to free the URI with xmlFreeURI. */
virStringStripIPv6Brackets
(
ret
->
server
);
if
(
virURIParseParams
(
ret
)
<
0
)
goto
error
;
...
...
tests/virstringtest.c
浏览文件 @
6c31911a
...
...
@@ -522,6 +522,36 @@ testVirStringFreeListCount(const void *opaque ATTRIBUTE_UNUSED)
}
struct
testStripIPv6BracketsData
{
const
char
*
string
;
const
char
*
result
;
};
static
int
testStripIPv6Brackets
(
const
void
*
args
)
{
const
struct
testStripIPv6BracketsData
*
data
=
args
;
int
ret
=
-
1
;
char
*
res
=
NULL
;
if
(
VIR_STRDUP
(
res
,
data
->
string
)
<
0
)
goto
cleanup
;
virStringStripIPv6Brackets
(
res
);
if
(
STRNEQ_NULLABLE
(
res
,
data
->
result
))
{
fprintf
(
stderr
,
"Returned '%s', expected '%s'
\n
"
,
NULLSTR
(
res
),
NULLSTR
(
data
->
result
));
goto
cleanup
;
}
ret
=
0
;
cleanup:
VIR_FREE
(
res
);
return
ret
;
}
static
int
mymain
(
void
)
{
...
...
@@ -731,6 +761,25 @@ mymain(void)
NULL
)
<
0
)
ret
=
-
1
;
#define TEST_STRIP_IPV6_BRACKETS(str, res) \
do { \
struct testStripIPv6BracketsData stripData = { \
.string = str, \
.result = res, \
}; \
if (virtTestRun("Strip brackets from IPv6 " #str, \
testStripIPv6Brackets, &stripData) < 0) \
ret = -1; \
} while (0)
TEST_STRIP_IPV6_BRACKETS
(
NULL
,
NULL
);
TEST_STRIP_IPV6_BRACKETS
(
"[]"
,
"[]"
);
TEST_STRIP_IPV6_BRACKETS
(
"[:]"
,
":"
);
TEST_STRIP_IPV6_BRACKETS
(
"[::1]"
,
"::1"
);
TEST_STRIP_IPV6_BRACKETS
(
"[hello:"
,
"[hello:"
);
TEST_STRIP_IPV6_BRACKETS
(
":hello]"
,
":hello]"
);
TEST_STRIP_IPV6_BRACKETS
(
":[]:"
,
":[]:"
);
return
ret
==
0
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录