[vlc-commits] [Git][videolan/vlc][master] 4 commits: httpd: use size_t for buffer size results
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Fri Jul 14 07:37:36 UTC 2023
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
f349e8b8 by Steve Lhomme at 2023-07-14T07:24:25+00:00
httpd: use size_t for buffer size results
The value can never be negative and it simplifies code in places.
We also need to change the i_body which is used as a pointer in some cases.
The value can never be negative and it simplifies code in places.
We also need to change the i_body which is used as a pointer in some cases.
- - - - -
84c06874 by Steve Lhomme at 2023-07-14T07:24:25+00:00
chromecast: remove unused parameters
- - - - -
2957b7aa by Steve Lhomme at 2023-07-14T07:24:25+00:00
httpd: remove unused variable
- - - - -
e34463bb by Steve Lhomme at 2023-07-14T07:24:25+00:00
access: rtp: put the libvlc_rtp declaration before it's used
- - - - -
8 changed files:
- include/vlc_httpd.h
- modules/access/rtp/Makefile.am
- modules/lua/libs/httpd.c
- modules/stream_out/chromecast/chromecast.h
- modules/stream_out/chromecast/chromecast_ctrl.cpp
- modules/stream_out/rtp.c
- modules/stream_out/rtsp.c
- src/network/httpd.c
Changes:
=====================================
include/vlc_httpd.h
=====================================
@@ -99,7 +99,7 @@ typedef struct httpd_message_t
/* body */
int64_t i_body_offset;
- int i_body;
+ size_t i_body;
uint8_t *p_body;
} httpd_message_t;
@@ -121,13 +121,13 @@ VLC_API char* httpd_ServerIP( const httpd_client_t *cl, char *, int * );
typedef struct httpd_file_t httpd_file_t;
typedef struct httpd_file_sys_t httpd_file_sys_t;
-typedef int (*httpd_file_callback_t)( httpd_file_sys_t *, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
+typedef int (*httpd_file_callback_t)( httpd_file_sys_t *, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, size_t *pi_data );
VLC_API httpd_file_t * httpd_FileNew( httpd_host_t *, const char *psz_url, const char *psz_mime, const char *psz_user, const char *psz_password, httpd_file_callback_t pf_fill, httpd_file_sys_t * ) VLC_USED;
VLC_API httpd_file_sys_t * httpd_FileDelete( httpd_file_t * );
typedef struct httpd_handler_t httpd_handler_t;
-typedef int (*httpd_handler_callback_t)( void *, httpd_handler_t *, char *psz_url, uint8_t *psz_request, int i_type, uint8_t *p_in, int i_in, char *psz_remote_addr, char *psz_remote_host, uint8_t **pp_data, int *pi_data );
+typedef int (*httpd_handler_callback_t)( void *, httpd_handler_t *, char *psz_url, uint8_t *psz_request, int i_type, uint8_t *p_in, int i_in, char *psz_remote_addr, char *psz_remote_host, uint8_t **pp_data, size_t *pi_data );
VLC_API httpd_handler_t * httpd_HandlerNew( httpd_host_t *, const char *psz_url, const char *psz_user, const char *psz_password, httpd_handler_callback_t pf_fill, void * ) VLC_USED;
VLC_API void * httpd_HandlerDelete( httpd_handler_t * );
=====================================
modules/access/rtp/Makefile.am
=====================================
@@ -1,3 +1,10 @@
+# RTP library
+libvlc_rtp_la_SOURCES = access/rtp/rtpfmt.c access/rtp/rtp.h \
+ access/rtp/session.c
+libvlc_rtp_la_CPPFLAGS = -I$(srcdir)/access/rtp
+libvlc_rtp_la_LDFLAGS = -no-undefined
+noinst_LTLIBRARIES += libvlc_rtp.la
+
# RTP plugin
access_LTLIBRARIES += librtp_plugin.la
librtp_plugin_la_SOURCES = \
@@ -9,13 +16,6 @@ librtp_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/access/rtp
librtp_plugin_la_CFLAGS = $(AM_CFLAGS)
librtp_plugin_la_LIBADD = libvlc_rtp.la $(SOCKET_LIBS)
-# RTP library
-libvlc_rtp_la_SOURCES = access/rtp/rtpfmt.c access/rtp/rtp.h \
- access/rtp/session.c
-libvlc_rtp_la_CPPFLAGS = -I$(srcdir)/access/rtp
-libvlc_rtp_la_LDFLAGS = -no-undefined
-noinst_LTLIBRARIES += libvlc_rtp.la
-
# Secure RTP library
libvlc_srtp_la_SOURCES = access/rtp/srtp.c access/rtp/srtp.h
libvlc_srtp_la_CPPFLAGS = -I$(srcdir)/access/rtp
=====================================
modules/lua/libs/httpd.c
=====================================
@@ -40,7 +40,7 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static uint8_t *vlclua_todata( lua_State *L, int narg, int *i_data );
+static uint8_t *vlclua_todata( lua_State *L, int narg, size_t *i_data );
static int vlclua_httpd_host_delete( lua_State * );
static int vlclua_httpd_handler_new( lua_State * );
@@ -126,7 +126,7 @@ static int vlclua_httpd_handler_callback(
void *opaque, httpd_handler_t *p_handler, char *psz_url,
uint8_t *psz_request, int i_type, uint8_t *p_in, int i_in,
char *psz_remote_addr, char *psz_remote_host,
- uint8_t **pp_data, int *pi_data )
+ uint8_t **pp_data, size_t *pi_data )
{
VLC_UNUSED(p_handler);
httpd_handler_lua_t *p_sys = opaque;
@@ -255,7 +255,7 @@ struct httpd_file_sys_t
static int vlclua_httpd_file_callback(
httpd_file_sys_t *p_sys, httpd_file_t *p_file, uint8_t *psz_request,
- uint8_t **pp_data, int *pi_data )
+ uint8_t **pp_data, size_t *pi_data )
{
VLC_UNUSED(p_file);
lua_State *L = p_sys->L;
@@ -380,18 +380,16 @@ static int vlclua_httpd_redirect_delete( lua_State *L )
/*****************************************************************************
* Utils
*****************************************************************************/
-static uint8_t *vlclua_todata( lua_State *L, int narg, int *pi_data )
+static uint8_t *vlclua_todata( lua_State *L, int narg, size_t *pi_data )
{
- size_t i_data;
- const char *psz_data = lua_tolstring( L, narg, &i_data );
- uint8_t *p_data = malloc( i_data );
- *pi_data = (int)i_data;
+ const char *psz_data = lua_tolstring( L, narg, pi_data );
+ uint8_t *p_data = malloc( *pi_data );
if( !p_data )
{
luaL_error( L, "Error while allocating buffer." );
return NULL; /* To please gcc even though luaL_error longjmp-ed out of here */
}
- memcpy( p_data, psz_data, i_data );
+ memcpy( p_data, psz_data, *pi_data );
return p_data;
}
=====================================
modules/stream_out/chromecast/chromecast.h
=====================================
@@ -191,7 +191,7 @@ struct intf_sys_t
std::string getHttpStreamPath() const;
std::string getHttpArtRoot() const;
- int httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
+ int httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, size_t *pi_data );
void interrupt_wake_up();
private:
void reinit();
=====================================
modules/stream_out/chromecast/chromecast_ctrl.cpp
=====================================
@@ -48,7 +48,7 @@
#define PING_WAIT_RETRIES 1
static int httpd_file_fill_cb( httpd_file_sys_t *data, httpd_file_t *http_file,
- uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
+ uint8_t *psz_request, uint8_t **pp_data, size_t *pi_data );
static const char* StateToStr( States s )
{
@@ -234,10 +234,8 @@ void intf_sys_t::reinit()
}
}
-int intf_sys_t::httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, int *pi_data )
+int intf_sys_t::httpd_file_fill( uint8_t *, uint8_t **pp_data, size_t *pi_data )
{
- (void) psz_request;
-
char *psz_art;
{
vlc::threads::mutex_locker lock( m_lock );
@@ -283,10 +281,9 @@ int intf_sys_t::httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, int *p
return VLC_SUCCESS;
}
-static int httpd_file_fill_cb( httpd_file_sys_t *data, httpd_file_t *http_file,
- uint8_t *psz_request, uint8_t **pp_data, int *pi_data )
+static int httpd_file_fill_cb( httpd_file_sys_t *data, httpd_file_t *,
+ uint8_t *psz_request, uint8_t **pp_data, size_t *pi_data )
{
- (void) http_file;
intf_sys_t *p_sys = static_cast<intf_sys_t*>((void *)data);
return p_sys->httpd_file_fill( psz_request, pp_data, pi_data );
}
=====================================
modules/stream_out/rtp.c
=====================================
@@ -1278,7 +1278,7 @@ static int FileSetup( sout_stream_t *p_stream )
****************************************************************************/
static int HttpCallback( httpd_file_sys_t *p_args,
httpd_file_t *, uint8_t *p_request,
- uint8_t **pp_data, int *pi_data );
+ uint8_t **pp_data, size_t *pi_data );
static int HttpSetup( sout_stream_t *p_stream, const vlc_url_t *url)
{
@@ -1302,7 +1302,7 @@ static int HttpSetup( sout_stream_t *p_stream, const vlc_url_t *url)
static int HttpCallback( httpd_file_sys_t *p_args,
httpd_file_t *f, uint8_t *p_request,
- uint8_t **pp_data, int *pi_data )
+ uint8_t **pp_data, size_t *pi_data )
{
VLC_UNUSED(f); VLC_UNUSED(p_request);
sout_stream_sys_t *p_sys = (sout_stream_sys_t*)p_args;
=====================================
modules/stream_out/rtsp.c
=====================================
@@ -973,7 +973,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
case HTTPD_MSG_GETPARAMETER:
{
- if( query->i_body > 0 )
+ if( query->i_body != 0 )
{
answer->i_status = 451;
break;
@@ -1036,7 +1036,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
httpd_MsgAdd( answer, "Session", "%s", psz_session );
}
- httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
+ httpd_MsgAdd( answer, "Content-Length", "%zu", answer->i_body );
httpd_MsgAdd( answer, "Cache-Control", "no-cache" );
psz = httpd_MsgGet( query, "Cseq" );
=====================================
src/network/httpd.c
=====================================
@@ -327,7 +327,7 @@ httpd_FileCallBack(httpd_callback_sys_t *p_sys, httpd_client_t *cl,
{
httpd_file_t *file = (httpd_file_t*)p_sys;
uint8_t **pp_body, *p_body = NULL;
- int *pi_body, i_body;
+ size_t *pi_body, i_body;
if (!answer || !query )
return VLC_SUCCESS;
@@ -365,7 +365,7 @@ httpd_FileCallBack(httpd_callback_sys_t *p_sys, httpd_client_t *cl,
if (httpd_MsgGet(&cl->query, "Connection") != NULL)
httpd_MsgAdd(answer, "Connection", "close");
- httpd_MsgAdd(answer, "Content-Length", "%d", answer->i_body);
+ httpd_MsgAdd(answer, "Content-Length", "%zu", answer->i_body);
return VLC_SUCCESS;
}
@@ -578,7 +578,7 @@ static int httpd_RedirectCallBack(httpd_callback_sys_t *p_sys,
/* XXX check if it's ok or we need to set an absolute url */
httpd_MsgAdd(answer, "Location", "%s", rdir->dst);
- httpd_MsgAdd(answer, "Content-Length", "%d", answer->i_body);
+ httpd_MsgAdd(answer, "Content-Length", "%zu", answer->i_body);
if (httpd_MsgGet(&cl->query, "Connection") != NULL)
httpd_MsgAdd(answer, "Connection", "close");
@@ -1349,7 +1349,7 @@ static int httpd_ClientRecv(httpd_client_t *cl)
cl->query.i_type = HTTPD_MSG_NONE;
}
}
- } else if (cl->query.i_body > 0) {
+ } else if (cl->query.i_body != 0) {
/* we are reading the body of a request or a channel */
assert (cl->query.p_body != NULL);
i_len = httpd_NetRecv(cl, &cl->query.p_body[cl->i_buffer],
@@ -1357,7 +1357,7 @@ static int httpd_ClientRecv(httpd_client_t *cl)
if (i_len > 0)
cl->i_buffer += i_len;
- if (cl->i_buffer >= cl->query.i_body)
+ if ((size_t)cl->i_buffer >= cl->query.i_body)
cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
} else for (;;) { /* we are reading a header -> char by char */
if (cl->i_buffer == cl->i_buffer_size) {
@@ -1539,7 +1539,7 @@ static int httpd_ClientRecv(httpd_client_t *cl)
}
}
}
- if (cl->query.i_body > 0) {
+ if (cl->query.i_body != 0) {
/* TODO Mhh, handle the case where the client only
* sends a request and closes the connection to
* mark the end of the body (probably only RTSP) */
@@ -1574,7 +1574,7 @@ static int httpd_ClientRecv(httpd_client_t *cl)
if (i_len == 0) {
if (cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE) {
/* connection closed -> end of data */
- if (cl->query.i_body > 0)
+ if (cl->query.i_body != 0)
cl->query.i_body = cl->i_buffer;
cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
}
@@ -1663,7 +1663,7 @@ static int httpd_ClientSend(httpd_client_t *cl)
httpd_UrlCatchCall(cl->url, cl);
}
- if (cl->answer.i_body > 0) {
+ if (cl->answer.i_body != 0) {
/* send the body data */
free(cl->p_buffer);
cl->p_buffer = cl->answer.p_body;
@@ -1862,7 +1862,7 @@ static void httpdLoop(httpd_host_t *host)
char *p;
answer->i_body = httpd_HtmlError (&p, 501, NULL);
answer->p_body = (uint8_t *)p;
- httpd_MsgAdd(answer, "Content-Length", "%d", answer->i_body);
+ httpd_MsgAdd(answer, "Content-Length", "%zu", answer->i_body);
httpd_MsgAdd(answer, "Connection", "close");
cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
@@ -1872,7 +1872,6 @@ static void httpdLoop(httpd_host_t *host)
default: {
httpd_url_t *url;
- int i_msg = query->i_type;
bool b_auth_failed = false;
/* Search the url and trigger callbacks */
@@ -1920,7 +1919,7 @@ static void httpdLoop(httpd_host_t *host)
answer->p_body = (uint8_t *)p;
cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
- httpd_MsgAdd(answer, "Content-Length", "%d", answer->i_body);
+ httpd_MsgAdd(answer, "Content-Length", "%zu", answer->i_body);
httpd_MsgAdd(answer, "Content-Type", "%s", "text/html");
if (httpd_MsgGet(&cl->query, "Connection") != NULL)
httpd_MsgAdd(answer, "Connection", "close");
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8c4d0393ad32688f9811031536e0842c18cda503...e34463bba7de4a2add3b2130c912fc55d03c07e6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8c4d0393ad32688f9811031536e0842c18cda503...e34463bba7de4a2add3b2130c912fc55d03c07e6
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list