Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
5fff4b0b
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5fff4b0b
编写于
3月 30, 2006
作者:
D
Daniel Veillard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* src/xend_internal.c: applied patch from Daniel P. Berrange,
plus a bit of code cleanup Daniel
上级
2b4566b5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
84 addition
and
51 deletion
+84
-51
ChangeLog
ChangeLog
+5
-0
src/xend_internal.c
src/xend_internal.c
+79
-51
未找到文件。
ChangeLog
浏览文件 @
5fff4b0b
Thu Mar 30 16:38:18 EST 2006 Daniel Veillard <veillard@redhat.com>
* src/xend_internal.c: applied patch from Daniel P. Berrange,
plus a bit of code cleanup
Thu Mar 30 16:04:47 EST 2006 Daniel Veillard <veillard@redhat.com>
* src/virsh.c: allocation check (Jim Meyering) and adding a
...
...
src/xend_internal.c
浏览文件 @
5fff4b0b
...
...
@@ -287,42 +287,6 @@ swrites(int fd, const char *string)
return
swrite
(
fd
,
string
,
strlen
(
string
));
}
/**
* sreads:
* @fd: the file descriptor
* @buffer: the I/O buffer
* @n_buffer: the size of the I/O buffer
*
* Internal routine to do a synchronous read of a line
*
* Returns the number of bytes read, or -1 in case of error
*/
static
ssize_t
sreads
(
int
fd
,
char
*
buffer
,
size_t
n_buffer
)
{
size_t
offset
;
if
(
n_buffer
<
1
)
return
(
-
1
);
for
(
offset
=
0
;
offset
<
(
n_buffer
-
1
);
offset
++
)
{
ssize_t
ret
;
ret
=
sread
(
fd
,
buffer
+
offset
,
1
);
if
(
ret
==
0
)
break
;
else
if
(
ret
==
-
1
)
return
ret
;
if
(
buffer
[
offset
]
==
'\n'
)
{
offset
++
;
break
;
}
}
buffer
[
offset
]
=
0
;
return
offset
;
}
static
int
istartswith
(
const
char
*
haystack
,
const
char
*
needle
)
...
...
@@ -330,6 +294,7 @@ istartswith(const char *haystack, const char *needle)
return
(
strncasecmp
(
haystack
,
needle
,
strlen
(
needle
))
==
0
);
}
/**
* xend_req:
* @fd: the file descriptor
...
...
@@ -344,32 +309,95 @@ static int
xend_req
(
int
fd
,
char
*
content
,
size_t
n_content
)
{
char
buffer
[
4096
];
int
nbuf
=
-
1
;
int
content_length
=
-
1
;
int
retcode
=
0
;
/*
* Fill buffer with as much as possible to get
* process going
*/
nbuf
=
sread
(
fd
,
buffer
,
sizeof
(
buffer
));
/*
* Extract lines from the buffer, until the
* end of header is found
*/
while
(
nbuf
>
-
1
)
{
/* Seach for offset of first \r\n pair */
int
i
,
offset
=
-
1
;
while
(
sreads
(
fd
,
buffer
,
sizeof
(
buffer
))
>
0
)
{
if
(
strcmp
(
buffer
,
"
\r\n
"
)
==
0
)
for
(
i
=
0
;
i
<
(
nbuf
-
1
);
i
++
)
{
if
(
buffer
[
i
]
==
'\r'
&&
buffer
[
i
+
1
]
==
'\n'
)
{
offset
=
i
;
break
;
}
}
if
(
offset
==
-
1
)
{
/* No newline found, so try to fill more data */
if
(
nbuf
==
sizeof
(
buffer
))
{
/* Already have 4096 bytes of data & no newline,
* get the hell out of this game */
break
;
}
/* Fill remainder of buffer with more data */
int
extra
=
sread
(
fd
,
buffer
+
nbuf
,
sizeof
(
buffer
)
-
nbuf
);
if
(
extra
<
1
)
{
/* Couldn't get more, so quit trying */
break
;
}
nbuf
+=
extra
;
}
else
if
(
!
offset
)
{
/* Immediate newline, indicates end of header */
/* Overwrite the \r\n pair */
offset
+=
2
;
nbuf
-=
offset
;
memmove
(
buffer
,
buffer
+
offset
,
nbuf
);
break
;
}
else
{
/* We have a single line */
buffer
[
offset
]
=
'\0'
;
if
(
istartswith
(
buffer
,
"Content-Length: "
))
content_length
=
atoi
(
buffer
+
16
);
else
if
(
istartswith
(
buffer
,
"HTTP/1.1 "
))
retcode
=
atoi
(
buffer
+
9
);
}
if
(
content_length
>
-
1
)
{
ssize_t
ret
;
/*
* Now move buffer, overwriting first line, to make room for
* more data on next iteration of loop (if needed)
*/
offset
+=
2
;
nbuf
-=
offset
;
memmove
(
buffer
,
buffer
+
offset
,
nbuf
);
}
}
if
(
content_length
>
-
1
)
{
/* Read the header, now get body */
if
((
unsigned
int
)
content_length
>
(
n_content
+
1
))
content_length
=
n_content
-
1
;
ret
=
sread
(
fd
,
content
,
content_length
);
if
(
ret
<
0
)
/*
* Copy across any data left in buffer after
* reading header
*/
if
(
nbuf
>
content_length
)
{
nbuf
=
content_length
;
}
memmove
(
content
,
buffer
,
nbuf
);
if
(
nbuf
<
content_length
)
{
/* Still need more data for body */
size_t
ret
=
sread
(
fd
,
content
+
nbuf
,
content_length
-
nbuf
);
if
(
0
>
(
int
)
ret
)
return
-
1
;
content
[
ret
]
=
0
;
content
[
nbuf
+
ret
+
1
]
=
'\0'
;
}
else
{
content
[
nbuf
+
1
]
=
'\0'
;
}
}
else
{
/* Unable to complete reading header */
content
[
0
]
=
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录