Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ZerXes
Tor
Commits
bd32982c
Commit
bd32982c
authored
Dec 29, 2007
by
Nick Mathewson
🐻
Browse files
r17426@catbus: nickm | 2007-12-28 21:12:29 -0500
Remove need for buf_pullup in fetch_line_from_buf(). svn:r13002
parent
c03ef9c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/or/buffers.c
View file @
bd32982c
...
@@ -1398,6 +1398,22 @@ peek_buf_has_control0_command(buf_t *buf)
...
@@ -1398,6 +1398,22 @@ peek_buf_has_control0_command(buf_t *buf)
return
0
;
return
0
;
}
}
/** DOCDOC */
static
int
buf_find_offset_of_char
(
buf_t
*
buf
,
char
ch
)
{
chunk_t
*
chunk
;
int
offset
=
0
;
for
(
chunk
=
buf
->
head
;
chunk
;
chunk
=
chunk
->
next
)
{
char
*
cp
=
memchr
(
chunk
->
data
,
ch
,
chunk
->
datalen
);
if
(
cp
)
return
offset
+
(
cp
-
chunk
->
data
);
else
offset
+=
chunk
->
datalen
;
}
return
-
1
;
}
/** Try to read a single LF-terminated line from <b>buf</b>, and write it,
/** Try to read a single LF-terminated line from <b>buf</b>, and write it,
* NUL-terminated, into the *<b>data_len</b> byte buffer at <b>data_out</b>.
* NUL-terminated, into the *<b>data_len</b> byte buffer at <b>data_out</b>.
* Set *<b>data_len</b> to the number of bytes in the line, not counting the
* Set *<b>data_len</b> to the number of bytes in the line, not counting the
...
@@ -1408,21 +1424,18 @@ peek_buf_has_control0_command(buf_t *buf)
...
@@ -1408,21 +1424,18 @@ peek_buf_has_control0_command(buf_t *buf)
int
int
fetch_from_buf_line
(
buf_t
*
buf
,
char
*
data_out
,
size_t
*
data_len
)
fetch_from_buf_line
(
buf_t
*
buf
,
char
*
data_out
,
size_t
*
data_len
)
{
{
char
*
cp
;
size_t
sz
;
size_t
sz
;
int
offset
;
if
(
!
buf
->
head
)
if
(
!
buf
->
head
)
return
0
;
return
0
;
/* XXXX020 pull up less aggressively. And implement setting *data_len
* properly in cases where we return -1. */
offset
=
buf_find_offset_of_char
(
buf
,
'\n'
);
buf_pullup
(
buf
,
*
data_len
,
0
);
if
(
offset
<
0
)
cp
=
memchr
(
buf
->
head
->
data
,
'\n'
,
buf
->
head
->
datalen
);
if
(
!
cp
)
{
return
0
;
return
0
;
}
sz
=
(
size_t
)
offset
;
sz
=
cp
-
buf
->
head
->
data
;
if
(
sz
+
2
>
*
data_len
)
{
if
(
sz
+
2
>
*
data_len
)
{
*
data_len
=
sz
+
2
;
*
data_len
=
sz
+
2
;
return
-
1
;
return
-
1
;
}
}
fetch_from_buf
(
data_out
,
sz
+
1
,
buf
);
fetch_from_buf
(
data_out
,
sz
+
1
,
buf
);
...
...
src/or/control.c
View file @
bd32982c
...
@@ -2631,10 +2631,11 @@ connection_control_process_inbuf(control_connection_t *conn)
...
@@ -2631,10 +2631,11 @@ connection_control_process_inbuf(control_connection_t *conn)
/* Line not all here yet. Wait. */
/* Line not all here yet. Wait. */
return
0
;
return
0
;
else
if
(
r
==
-
1
)
{
else
if
(
r
==
-
1
)
{
while
(
conn
->
incoming_cmd_len
<
data_len
+
conn
->
incoming_cmd_cur_len
)
/*XXXX020 impose some maximum on length! */
conn
->
incoming_cmd_len
*=
2
;
while
(
conn
->
incoming_cmd_len
<
data_len
+
conn
->
incoming_cmd_cur_len
)
conn
->
incoming_cmd
=
tor_realloc
(
conn
->
incoming_cmd
,
conn
->
incoming_cmd_len
*=
2
;
conn
->
incoming_cmd_len
);
conn
->
incoming_cmd
=
tor_realloc
(
conn
->
incoming_cmd
,
conn
->
incoming_cmd_len
);
}
}
}
while
(
r
!=
1
);
}
while
(
r
!=
1
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment