Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Icecast-common
Compare Revisions
001667626c3b214d8815d435e4d2190e9e20a676...fca416b126cb842034ac3468362c044895975b5a
Commits (3)
Update: Fixed typo
· 829cd5f3
Philipp Schafft
authored
Apr 13, 2018
829cd5f3
Feature: Allow checking for transfer encoding EOF
· 308e7313
Philipp Schafft
authored
Apr 17, 2018
308e7313
Feature: Allow %z[ui] in logging format strings
· fca416b1
Philipp Schafft
authored
Apr 28, 2018
fca416b1
Hide whitespace changes
Inline
Side-by-side
httpp/encoding.c
View file @
fca416b1
...
...
@@ -56,6 +56,7 @@ struct httpp_encoding_tag {
size_t
buf_write_encoded_offset
,
buf_write_encoded_len
;
/* backend specific stuff */
ssize_t
bytes_till_eof
;
size_t
read_bytes_till_header
;
};
...
...
@@ -182,6 +183,7 @@ httpp_encoding_t *httpp_encoding_new(const char *encoding) {
return
NULL
;
ret
->
refc
=
1
;
ret
->
bytes_till_eof
=
-
1
;
if
(
strcasecmp
(
encoding
,
HTTPP_ENCODING_IDENTITY
)
==
0
)
{
ret
->
process_read
=
__enc_identity_read
;
...
...
@@ -279,6 +281,23 @@ ssize_t httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t
return
done
;
}
int
httpp_encoding_eof
(
httpp_encoding_t
*
self
,
int
(
*
cb
)(
void
*
),
void
*
userdata
)
{
if
(
!
self
)
return
-
1
;
if
(
self
->
buf_read_decoded_len
-
self
->
buf_read_decoded_offset
)
return
0
;
if
(
self
->
bytes_till_eof
==
0
)
return
1
;
if
(
cb
)
return
cb
(
userdata
);
return
0
;
}
/* Read any meta data that is in buffer.
* After a call to this function the meta data is released from the
* encoding object and the caller is responsible to free it.
...
...
@@ -493,7 +512,11 @@ static ssize_t __enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len,
/* ok. now we should have 2 or less bytes till next header.
* We just read a few bytes into our decoding buffer and see what we got.
*/
buflen
=
1024
;
if
(
self
->
bytes_till_eof
!=
-
1
)
{
buflen
=
self
->
bytes_till_eof
;
}
else
{
buflen
=
1024
;
}
if
(
self
->
buf_read_raw
)
{
bufptr
=
realloc
(
self
->
buf_read_raw
,
self
->
buf_read_raw_len
+
buflen
);
...
...
@@ -540,8 +563,17 @@ static ssize_t __enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len,
self
->
read_bytes_till_header
=
0
;
}
/* Check if we reached EOF */
if
(
self
->
bytes_till_eof
!=
-
1
)
{
if
(
self
->
read_bytes_till_header
==
0
)
self
->
bytes_till_eof
=
0
;
if
(
self
->
bytes_till_eof
==
0
)
return
0
;
}
/* ok. next we have at least a little bit if a header.
* Now we need to find out
o
f the header is complet.
* Now we need to find out
i
f the header is complet.
* If it is we will process it. If it isn't we will
* just return a short read and try again later!
*
...
...
@@ -608,6 +640,10 @@ static ssize_t __enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len,
/* ok, Now we move the offset forward to the body. */
self
->
buf_read_raw_offset
=
offset_LF
+
1
;
if
(
!
bodylen
)
{
self
->
bytes_till_eof
=
2
;
/* 2 = tailing "\r\n" */
}
/* Do we still have some data in buffer?
* If not free the buffer and set the counters
* to point to the next header.
...
...
@@ -649,6 +685,20 @@ static ssize_t __enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len,
self
->
buf_read_raw_offset
+=
bodylen
;
self
->
read_bytes_till_header
=
2
;
/* tailing "\r\n" */
if
((
self
->
buf_read_raw_len
-
self
->
buf_read_raw_offset
)
>=
2
)
{
self
->
buf_read_raw_offset
+=
2
;
self
->
read_bytes_till_header
=
0
;
if
(
self
->
bytes_till_eof
!=
-
1
)
self
->
bytes_till_eof
=
0
;
if
((
self
->
buf_read_raw_len
-
self
->
buf_read_raw_offset
)
==
0
)
{
free
(
self
->
buf_read_raw
);
self
->
buf_read_raw
=
NULL
;
self
->
buf_read_raw_len
=
0
;
self
->
buf_read_raw_offset
=
0
;
}
}
return
0
;
}
...
...
httpp/encoding.h
View file @
fca416b1
...
...
@@ -60,6 +60,11 @@ int httpp_encoding_release(httpp_encoding_t *self);
*/
ssize_t
httpp_encoding_read
(
httpp_encoding_t
*
self
,
void
*
buf
,
size_t
len
,
ssize_t
(
*
cb
)(
void
*
,
void
*
,
size_t
),
void
*
userdata
);
/* Check if EOF is reached.
* If cb is not NULL this also considers backend state.
*/
int
httpp_encoding_eof
(
httpp_encoding_t
*
self
,
int
(
*
cb
)(
void
*
),
void
*
userdata
);
/* Read any meta data that is in buffer.
* After a call to this function the meta data is released from the
* encoding object and the caller is responsible to free it.
...
...
log/log.c
View file @
fca416b1
...
...
@@ -473,6 +473,9 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
case
'l'
:
block_size
++
;
break
;
case
'z'
:
block_size
=
'z'
;
break
;
case
'.'
:
// just ignore '.'. If somebody cares: fix it.
break
;
...
...
@@ -523,6 +526,13 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
else
snprintf
(
buf
,
sizeof
(
buf
),
"%lli"
,
(
long
long
int
)
va_arg
(
ap
,
long
long
int
));
break
;
case
'z'
:
/* We do not use 'z' type of snprintf() here as it is not safe to use on a few outdated platforms. */
if
(
*
format
==
'u'
)
snprintf
(
buf
,
sizeof
(
buf
),
"%llu"
,
(
unsigned
long
long
int
)
va_arg
(
ap
,
size_t
));
else
snprintf
(
buf
,
sizeof
(
buf
),
"%lli"
,
(
long
long
int
)
va_arg
(
ap
,
ssize_t
));
break
;
default:
snprintf
(
buf
,
sizeof
(
buf
),
"<<<invalid>>>"
);
break
;
...
...