Commit 0fc60fee authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

remoteosd: remove I/O buffer casts

parent b7f9a4c0
...@@ -318,21 +318,15 @@ static void DestroyFilter( vlc_object_t *p_this ) ...@@ -318,21 +318,15 @@ static void DestroyFilter( vlc_object_t *p_this )
free( p_sys ); free( p_sys );
} }
static bool read_exact( filter_t *p_filter, static bool read_exact( filter_t *obj, int fd, void *buf, size_t len )
int i_socket,
char* p_readbuf,
int i_bytes )
{ {
return i_bytes == net_Read( p_filter, i_socket, p_readbuf, i_bytes ); return (ssize_t)len == net_Read( obj, fd, buf, len );
} }
static bool write_exact( filter_t *p_filter, static bool write_exact( filter_t *obj, int fd, const void *buf, size_t len )
int i_socket,
char* p_writebuf,
int i_bytes )
{ {
return i_bytes == net_Write( p_filter, i_socket, p_writebuf, i_bytes ); return (ssize_t)len == net_Write( obj, fd, buf, len );
} }
static int vnc_connect( filter_t *p_filter ) static int vnc_connect( filter_t *p_filter )
...@@ -370,7 +364,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -370,7 +364,7 @@ static int vnc_connect( filter_t *p_filter )
msg_Dbg( p_filter, "Reading authentication scheme" ); msg_Dbg( p_filter, "Reading authentication scheme" );
uint32_t i_authScheme; uint32_t i_authScheme;
if( !read_exact( p_filter, fd, (char*)&i_authScheme, 4 ) ) if( !read_exact( p_filter, fd, &i_authScheme, 4 ) )
{ {
msg_Err( p_filter, "Could not read authentication scheme" ); msg_Err( p_filter, "Could not read authentication scheme" );
goto error; goto error;
...@@ -386,7 +380,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -386,7 +380,7 @@ static int vnc_connect( filter_t *p_filter )
if (i_authScheme == rfbVncAuth) if (i_authScheme == rfbVncAuth)
{ {
unsigned char challenge[CHALLENGESIZE]; unsigned char challenge[CHALLENGESIZE];
if ( !read_exact( p_filter, fd, (char*)challenge, CHALLENGESIZE ) ) if ( !read_exact( p_filter, fd, challenge, CHALLENGESIZE ) )
{ {
msg_Err( p_filter, "Could not read password challenge" ); msg_Err( p_filter, "Could not read password challenge" );
goto error; goto error;
...@@ -394,13 +388,13 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -394,13 +388,13 @@ static int vnc_connect( filter_t *p_filter )
vnc_encrypt_bytes( challenge, p_sys->psz_passwd ); vnc_encrypt_bytes( challenge, p_sys->psz_passwd );
if( !write_exact(p_filter, fd, (char*)challenge, CHALLENGESIZE ) ) if( !write_exact(p_filter, fd, challenge, CHALLENGESIZE ) )
{ {
msg_Err( p_filter, "Could not write password" ); msg_Err( p_filter, "Could not write password" );
goto error; goto error;
} }
uint32_t i_authResult; uint32_t i_authResult;
if( !read_exact( p_filter, fd, (char*)&i_authResult, 4 ) ) if( !read_exact( p_filter, fd, &i_authResult, 4 ) )
{ {
msg_Err( p_filter, "Could not read authentication result" ); msg_Err( p_filter, "Could not read authentication result" );
goto error; goto error;
...@@ -416,7 +410,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -416,7 +410,7 @@ static int vnc_connect( filter_t *p_filter )
msg_Dbg( p_filter, "Writing client init message" ); msg_Dbg( p_filter, "Writing client init message" );
rfbClientInitMsg ci; rfbClientInitMsg ci;
ci.shared = 1; ci.shared = 1;
if( !write_exact( p_filter, fd, (char*)&ci, sz_rfbClientInitMsg ) ) if( !write_exact( p_filter, fd, &ci, sz_rfbClientInitMsg ) )
{ {
msg_Err( p_filter, "Could not write client init message" ); msg_Err( p_filter, "Could not write client init message" );
goto error; goto error;
...@@ -424,7 +418,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -424,7 +418,7 @@ static int vnc_connect( filter_t *p_filter )
msg_Dbg( p_filter, "Reading server init message" ); msg_Dbg( p_filter, "Reading server init message" );
rfbServerInitMsg si; rfbServerInitMsg si;
if( !read_exact( p_filter, fd, (char*)&si, sz_rfbServerInitMsg ) ) if( !read_exact( p_filter, fd, &si, sz_rfbServerInitMsg ) )
{ {
msg_Err( p_filter, "Could not read server init message" ); msg_Err( p_filter, "Could not read server init message" );
goto error; goto error;
...@@ -497,7 +491,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -497,7 +491,7 @@ static int vnc_connect( filter_t *p_filter )
sp.format.blueShift = 0; sp.format.blueShift = 0;
sp.format.pad1 = sp.format.pad2 = 0; sp.format.pad1 = sp.format.pad2 = 0;
if( !write_exact( p_filter, fd, (char*)&sp, sz_rfbSetPixelFormatMsg) ) if( !write_exact( p_filter, fd, &sp, sz_rfbSetPixelFormatMsg) )
{ {
msg_Err( p_filter, "Could not write SetPixelFormat message" ); msg_Err( p_filter, "Could not write SetPixelFormat message" );
goto error; goto error;
...@@ -510,7 +504,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -510,7 +504,7 @@ static int vnc_connect( filter_t *p_filter )
se.pad = 0; se.pad = 0;
se.nEncodings = htons( p_sys->b_alpha_from_vnc ? 3 : 2 ); se.nEncodings = htons( p_sys->b_alpha_from_vnc ? 3 : 2 );
if( !write_exact( p_filter, fd, (char*)&se, sz_rfbSetEncodingsMsg) ) if( !write_exact( p_filter, fd, &se, sz_rfbSetEncodingsMsg) )
{ {
msg_Err( p_filter, "Could not write SetEncodings message begin" ); msg_Err( p_filter, "Could not write SetEncodings message begin" );
goto error; goto error;
...@@ -520,7 +514,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -520,7 +514,7 @@ static int vnc_connect( filter_t *p_filter )
msg_Dbg( p_filter, "Writing SetEncodings rfbEncodingCopyRect" ); msg_Dbg( p_filter, "Writing SetEncodings rfbEncodingCopyRect" );
i_encoding = htonl(rfbEncodingCopyRect); i_encoding = htonl(rfbEncodingCopyRect);
if( !write_exact( p_filter, fd, (char*)&i_encoding, 4) ) if( !write_exact( p_filter, fd, &i_encoding, 4) )
{ {
msg_Err( p_filter, "Could not write encoding type rfbEncodingCopyRect." ); msg_Err( p_filter, "Could not write encoding type rfbEncodingCopyRect." );
goto error; goto error;
...@@ -528,7 +522,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -528,7 +522,7 @@ static int vnc_connect( filter_t *p_filter )
msg_Dbg( p_filter, "Writing SetEncodings rfbEncodingRRE" ); msg_Dbg( p_filter, "Writing SetEncodings rfbEncodingRRE" );
i_encoding = htonl(rfbEncodingRRE); i_encoding = htonl(rfbEncodingRRE);
if( !write_exact(p_filter, fd, (char*)&i_encoding, 4) ) if( !write_exact(p_filter, fd, &i_encoding, 4) )
{ {
msg_Err( p_filter, "Could not write encoding type rfbEncodingRRE." ); msg_Err( p_filter, "Could not write encoding type rfbEncodingRRE." );
goto error; goto error;
...@@ -539,7 +533,7 @@ static int vnc_connect( filter_t *p_filter ) ...@@ -539,7 +533,7 @@ static int vnc_connect( filter_t *p_filter )
msg_Dbg( p_filter, "Writing SetEncodings rfbEncSpecialUseAlpha" ); msg_Dbg( p_filter, "Writing SetEncodings rfbEncSpecialUseAlpha" );
i_encoding = 0x00F0FFFF; /* rfbEncSpecialUseAlpha is 0xFFFFF000 i_encoding = 0x00F0FFFF; /* rfbEncSpecialUseAlpha is 0xFFFFF000
* before we swap it */ * before we swap it */
if( !write_exact(p_filter, fd, (char*)&i_encoding, 4) ) if( !write_exact(p_filter, fd, &i_encoding, 4) )
{ {
msg_Err( p_filter, "Could not write encoding type rfbEncSpecialUseAlpha." ); msg_Err( p_filter, "Could not write encoding type rfbEncSpecialUseAlpha." );
goto error; goto error;
...@@ -564,7 +558,7 @@ static int write_update_request(filter_t *p_filter, bool incremental) ...@@ -564,7 +558,7 @@ static int write_update_request(filter_t *p_filter, bool incremental)
udr.w = htons(p_sys->i_vnc_width); udr.w = htons(p_sys->i_vnc_width);
udr.h = htons(p_sys->i_vnc_height); udr.h = htons(p_sys->i_vnc_height);
int w = write_exact(p_filter, p_sys->i_socket, (char*)&udr, int w = write_exact(p_filter, p_sys->i_socket, &udr,
sz_rfbFramebufferUpdateRequestMsg); sz_rfbFramebufferUpdateRequestMsg);
if( !w ) if( !w )
msg_Err( p_filter, "Could not write rfbFramebufferUpdateRequestMsg." ); msg_Err( p_filter, "Could not write rfbFramebufferUpdateRequestMsg." );
...@@ -619,7 +613,7 @@ static void* vnc_worker_thread( void *obj ) ...@@ -619,7 +613,7 @@ static void* vnc_worker_thread( void *obj )
memset( &msg, 0, sizeof(msg) ); memset( &msg, 0, sizeof(msg) );
if( !read_exact(p_filter, fd, (char*)&msg, 1 ) ) if( !read_exact(p_filter, fd, &msg, 1 ) )
{ {
msg_Err( p_filter, "Error while waiting for next server message"); msg_Err( p_filter, "Error while waiting for next server message");
break; break;
...@@ -652,7 +646,7 @@ static void* vnc_worker_thread( void *obj ) ...@@ -652,7 +646,7 @@ static void* vnc_worker_thread( void *obj )
if( --i_msgSize > 0 ) if( --i_msgSize > 0 )
{ {
if ( !read_exact( p_filter, fd, ((char*)&msg)+1, i_msgSize ) ) if ( !read_exact( p_filter, fd, ((char *)&msg) + 1, i_msgSize ) )
{ {
msg_Err( p_filter, "Error while reading message of type %u", msg_Err( p_filter, "Error while reading message of type %u",
msg.type ); msg.type );
...@@ -721,8 +715,8 @@ static bool process_server_message ( filter_t *p_filter, ...@@ -721,8 +715,8 @@ static bool process_server_message ( filter_t *p_filter,
for (int i_rect = 0; i_rect < msg->fu.nRects; i_rect++) for (int i_rect = 0; i_rect < msg->fu.nRects; i_rect++)
{ {
if (!read_exact(p_filter, p_sys->i_socket, (char*)&hdr, if (!read_exact(p_filter, p_sys->i_socket, &hdr,
sz_rfbFramebufferUpdateRectHeader ) ) sz_rfbFramebufferUpdateRectHeader ) )
{ {
msg_Err( p_filter, "Could not read FrameBufferUpdate header" ); msg_Err( p_filter, "Could not read FrameBufferUpdate header" );
return false; return false;
...@@ -766,8 +760,7 @@ static bool process_server_message ( filter_t *p_filter, ...@@ -766,8 +760,7 @@ static bool process_server_message ( filter_t *p_filter,
rfbCopyRect rect; rfbCopyRect rect;
if ( !read_exact( p_filter, p_sys->i_socket, if ( !read_exact( p_filter, p_sys->i_socket,
(char*)&rect, &rect, sz_rfbCopyRect ) )
sz_rfbCopyRect ) )
{ {
msg_Err( p_filter, "Could not read rfbCopyRect" ); msg_Err( p_filter, "Could not read rfbCopyRect" );
return false; return false;
...@@ -793,15 +786,14 @@ static bool process_server_message ( filter_t *p_filter, ...@@ -793,15 +786,14 @@ static bool process_server_message ( filter_t *p_filter,
{ {
rfbRREHeader rrehdr; rfbRREHeader rrehdr;
if ( !read_exact( p_filter, p_sys->i_socket, if ( !read_exact( p_filter, p_sys->i_socket,
(char*)&rrehdr, &rrehdr, sz_rfbRREHeader ) )
sz_rfbRREHeader ) )
{ {
msg_Err( p_filter, "Could not read rfbRREHeader" ); msg_Err( p_filter, "Could not read rfbRREHeader" );
return false; return false;
} }
uint8_t i_pixcolor; uint8_t i_pixcolor;
if ( !read_exact(p_filter, p_sys->i_socket, if ( !read_exact( p_filter, p_sys->i_socket,
(char*)&i_pixcolor, 1 ) ) &i_pixcolor, 1 ) )
{ {
msg_Err( p_filter, "Could not read RRE pixcolor" ); msg_Err( p_filter, "Could not read RRE pixcolor" );
return false; return false;
...@@ -830,7 +822,7 @@ static bool process_server_message ( filter_t *p_filter, ...@@ -830,7 +822,7 @@ static bool process_server_message ( filter_t *p_filter,
return false; return false;
} }
if ( !read_exact( p_filter, p_sys->i_socket, if ( !read_exact( p_filter, p_sys->i_socket,
p_sys->read_buffer, i_datasize ) ) p_sys->read_buffer, i_datasize ) )
{ {
msg_Err( p_filter, msg_Err( p_filter,
"Could not read RRE subrect data" ); "Could not read RRE subrect data" );
...@@ -943,8 +935,8 @@ static bool process_server_message ( filter_t *p_filter, ...@@ -943,8 +935,8 @@ static bool process_server_message ( filter_t *p_filter,
msg_Err( p_filter, "Buffer too small, need %u bytes", msg->sct.length ); msg_Err( p_filter, "Buffer too small, need %u bytes", msg->sct.length );
return false; return false;
} }
if ( !read_exact(p_filter, p_sys->i_socket, if ( !read_exact( p_filter, p_sys->i_socket,
p_sys->read_buffer, msg->sct.length ) ) p_sys->read_buffer, msg->sct.length ) )
{ {
msg_Err( p_filter, "Could not read Reading rfbServerCutText data" ); msg_Err( p_filter, "Could not read Reading rfbServerCutText data" );
return false; return false;
...@@ -1226,8 +1218,7 @@ static int MouseEvent( filter_t *p_filter, ...@@ -1226,8 +1218,7 @@ static int MouseEvent( filter_t *p_filter,
ev.x = htons(i_x); ev.x = htons(i_x);
ev.y = htons(i_y); ev.y = htons(i_y);
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbPointerEventMsg);
(char*)&ev, sz_rfbPointerEventMsg);
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -1271,51 +1262,43 @@ static int KeyEvent( vlc_object_t *p_this, char const *psz_var, ...@@ -1271,51 +1262,43 @@ static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
if (newval.i_int & KEY_MODIFIER_CTRL) if (newval.i_int & KEY_MODIFIER_CTRL)
{ {
ev.key = 0xffe3; ev.key = 0xffe3;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
} }
if (newval.i_int & KEY_MODIFIER_SHIFT) if (newval.i_int & KEY_MODIFIER_SHIFT)
{ {
ev.key = 0xffe1; ev.key = 0xffe1;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
} }
if (newval.i_int & KEY_MODIFIER_ALT) if (newval.i_int & KEY_MODIFIER_ALT)
{ {
ev.key = 0xffe9; ev.key = 0xffe9;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
} }
/* then key-down for the pressed key */ /* then key-down for the pressed key */
ev.key = i_key32; ev.key = i_key32;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
ev.down = 0; ev.down = 0;
/* then key-up for the pressed key */ /* then key-up for the pressed key */
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
/* last key-down for modifier-keys */ /* last key-down for modifier-keys */
if (newval.i_int & KEY_MODIFIER_CTRL) if (newval.i_int & KEY_MODIFIER_CTRL)
{ {
ev.key = 0xffe3; ev.key = 0xffe3;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
} }
if (newval.i_int & KEY_MODIFIER_SHIFT) if (newval.i_int & KEY_MODIFIER_SHIFT)
{ {
ev.key = 0xffe1; ev.key = 0xffe1;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
} }
if (newval.i_int & KEY_MODIFIER_ALT) if (newval.i_int & KEY_MODIFIER_ALT)
{ {
ev.key = 0xffe9; ev.key = 0xffe9;
write_exact( p_filter, p_sys->i_socket, write_exact( p_filter, p_sys->i_socket, &ev, sz_rfbKeyEventMsg );
(char*)&ev, sz_rfbKeyEventMsg);
} }
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment