1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-23 06:25:24 +00:00

Update: Moved _update_client_request_body_length() into new client_complete()

This commit is contained in:
Philipp Schafft 2018-07-20 11:12:13 +00:00
parent c0155e2404
commit c40d12a1c7
3 changed files with 46 additions and 45 deletions

View File

@ -103,6 +103,50 @@ int client_create(client_t **c_ptr, connection_t *con, http_parser_t *parser)
return ret;
}
void client_complete(client_t *client)
{
const char *header;
long long unsigned int scannumber;
int have = 0;
if (!have) {
if (client->parser->req_type == httpp_req_source) {
client->request_body_length = -1; /* streaming */
have = 1;
}
}
if (!have) {
header = httpp_getvar(client->parser, "transfer-encoding");
if (header) {
if (strcasecmp(header, "identity") != 0) {
client->request_body_length = -1; /* streaming */
have = 1;
}
}
}
if (!have) {
header = httpp_getvar(client->parser, "content-length");
if (header) {
if (sscanf(header, "%llu", &scannumber) == 1) {
client->request_body_length = scannumber;
have = 1;
}
}
}
if (!have) {
if (client->parser->req_type == httpp_req_put) {
/* As we don't know yet, we asume this PUT is in streaming mode */
client->request_body_length = -1; /* streaming */
have = 1;
}
}
ICECAST_LOG_DEBUG("Client %p has request_body_length=%zi", client, client->request_body_length);
}
static inline void client_reuseconnection(client_t *client) {
connection_t *con;
reuse_t reuse;

View File

@ -137,6 +137,7 @@ struct _client_tag {
};
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser);
void client_complete(client_t *client);
void client_destroy(client_t *client);
void client_send_error_by_id(client_t *client, icecast_error_id_t id);
void client_send_101(client_t *client, reuse_t reuse);

View File

@ -1429,50 +1429,6 @@ static void __prepare_shoutcast_admin_cgi_request(client_t *client)
global_unlock();
}
static void _update_client_request_body_length(client_t *client)
{
const char *header;
long long unsigned int scannumber;
int have = 0;
if (!have) {
if (client->parser->req_type == httpp_req_source) {
client->request_body_length = -1; /* streaming */
have = 1;
}
}
if (!have) {
header = httpp_getvar(client->parser, "transfer-encoding");
if (header) {
if (strcasecmp(header, "identity") != 0) {
client->request_body_length = -1; /* streaming */
have = 1;
}
}
}
if (!have) {
header = httpp_getvar(client->parser, "content-length");
if (header) {
if (sscanf(header, "%llu", &scannumber) == 1) {
client->request_body_length = scannumber;
have = 1;
}
}
}
if (!have) {
if (client->parser->req_type == httpp_req_put) {
/* As we don't know yet, we asume this PUT is in streaming mode */
client->request_body_length = -1; /* streaming */
have = 1;
}
}
ICECAST_LOG_DEBUG("Client %p has request_body_length=%zi", client, client->request_body_length);
}
/* Check if we need body of client */
static int _need_body(client_queue_t *node)
{
@ -1537,7 +1493,7 @@ static void _handle_connection(void)
client->refbuf->len = 0;
/* early check if we need more data */
_update_client_request_body_length(client);
client_complete(client);
if (_need_body(node)) {
/* Just calling _add_body_client() would do the job.
* However, if the client only has a small body this might work without moving it between queues.