@@ -68,19 +68,19 @@ static inline guchar *buffer_incr(struct buffer *b, size_t n) {
6868}
6969
7070void purple_websocket_abort (PurpleWebsocket * ws ) {
71+ if (ws == NULL )
72+ return ;
73+
7174 if (ws -> ssl_connection != NULL )
7275 purple_ssl_close (ws -> ssl_connection );
7376
7477 if (ws -> connection != NULL )
7578 purple_proxy_connect_cancel (ws -> connection );
7679
77- purple_debug_misc ("websocket" , "removing input %d \n" , ws -> inpa );
80+ purple_debug_misc ("websocket" , "removing input %u \n" , ws -> inpa );
7881 if (ws -> inpa > 0 )
7982 purple_input_remove (ws -> inpa );
8083
81- if (ws -> fd >= 0 )
82- close (ws -> fd );
83-
8484 g_free (ws -> key );
8585 g_free (ws -> output .buf );
8686 g_free (ws -> input .buf );
@@ -105,6 +105,7 @@ static const char *skip_lws(const char *s) {
105105 s += 3 ;
106106 break ;
107107 }
108+ return NULL ;
108109 case '\n' :
109110 case '\0' :
110111 return NULL ;
@@ -129,11 +130,11 @@ static const char *find_header_content(const char *data, const char *name) {
129130
130131static gboolean ws_read_headers (PurpleWebsocket * ws , const char * headers ) {
131132 const char * upgrade = skip_lws (find_header_content (headers , "Upgrade" ));
132- if (upgrade && (g_ascii_strncasecmp (upgrade , "websocket" , 9 ) || skip_lws (upgrade + 9 )))
133+ if (upgrade && (g_ascii_strncasecmp (upgrade , "websocket" , 9 ) != 0 || skip_lws (upgrade + 9 )))
133134 upgrade = NULL ;
134135
135136 const char * connection = find_header_content (headers , "Connection" );
136- while ((connection = skip_lws (connection )) && g_ascii_strncasecmp (connection , "Upgrade" , 7 ))
137+ while ((connection = skip_lws (connection )) && g_ascii_strncasecmp (connection , "Upgrade" , 7 ) != 0 )
137138 while (* connection ++ != ',' && (connection = skip_lws (connection )));
138139 if (connection ) {
139140 const char * e = skip_lws (connection + 7 );
@@ -150,14 +151,14 @@ static gboolean ws_read_headers(PurpleWebsocket *ws, const char *headers) {
150151 g_free (k );
151152 gchar * b = g_base64_encode (s , l );
152153 l = strlen (b );
153- if (strncmp (accept , b , l ) || skip_lws (accept + l ))
154+ if (strncmp (accept , b , l ) != 0 || skip_lws (accept + l ))
154155 accept = NULL ;
155156 g_free (b );
156157 }
157158
158159 /* TODO: Sec-WebSocket-Extensions, Sec-WebSocket-Protocol */
159160
160- if (strncmp (headers , "HTTP/1.1 101 " , 13 ) || !upgrade || !connection || !accept ) {
161+ if (strncmp (headers , "HTTP/1.1 101 " , 13 ) != 0 || !upgrade || !connection || !accept ) {
161162 ws_error (ws , headers );
162163 return FALSE;
163164 }
@@ -249,6 +250,7 @@ static size_t ws_read_message(PurpleWebsocket *ws) {
249250 break ;
250251 default :
251252 ws_error (ws , "Unknown frame op" );
253+ return 0 ;
252254 }
253255 return off ;
254256 }
@@ -281,7 +283,7 @@ static gboolean ws_input(PurpleWebsocket *ws) {
281283 return FALSE;
282284 }
283285
284- if (cond )
286+ if (cond != 0 )
285287 ws -> inpa = purple_input_add (ws -> fd , cond , ws_input_cb , ws );
286288 return TRUE;
287289}
@@ -290,9 +292,9 @@ static void ws_input_cb(gpointer data, G_GNUC_UNUSED gint source, PurpleInputCon
290292 PurpleWebsocket * ws = data ;
291293
292294 if (cond & PURPLE_INPUT_WRITE ) {
293- ssize_t len = ws -> output .off >= ws -> output .len ? 0 :
295+ gssize len = ws -> output .off >= ws -> output .len ? 0 :
294296 ws -> ssl_connection
295- ? ( ssize_t ) purple_ssl_write (ws -> ssl_connection , ws -> output .buf + ws -> output .off , ws -> output .len - ws -> output .off )
297+ ? purple_ssl_write (ws -> ssl_connection , ws -> output .buf + ws -> output .off , ws -> output .len - ws -> output .off )
296298 : write (ws -> fd , ws -> output .buf + ws -> output .off , ws -> output .len - ws -> output .off );
297299
298300 if (len < 0 ) {
@@ -315,8 +317,8 @@ static void ws_input_cb(gpointer data, G_GNUC_UNUSED gint source, PurpleInputCon
315317
316318 while (cond & PURPLE_INPUT_READ ) {
317319 g_return_if_fail (ws -> input .off < ws -> input .len );
318- ssize_t len = ws -> ssl_connection
319- ? ( ssize_t ) purple_ssl_read (ws -> ssl_connection , ws -> input .buf + ws -> input .off , ws -> input .siz - ws -> input .off )
320+ gssize len = ws -> ssl_connection
321+ ? purple_ssl_read (ws -> ssl_connection , ws -> input .buf + ws -> input .off , ws -> input .siz - ws -> input .off )
320322 : read (ws -> fd , ws -> input .buf + ws -> input .off , ws -> input .siz - ws -> input .off );
321323
322324 if (len < 0 ) {
@@ -382,6 +384,7 @@ static void ws_input_cb(gpointer data, G_GNUC_UNUSED gint source, PurpleInputCon
382384}
383385
384386void purple_websocket_send (PurpleWebsocket * ws , PurpleWebsocketOp op , const guchar * msg , size_t len ) {
387+ g_return_if_fail (ws );
385388 g_return_if_fail (ws -> connected && !(ws -> closed & PURPLE_INPUT_WRITE ));
386389 g_return_if_fail (!(op & ~WS_OP_MASK ));
387390 gboolean buf = ws -> output .len ;
0 commit comments