@ -497,7 +497,6 @@ int AST_OPTIONAL_API_NAME(ast_websocket_read)(struct ast_websocket *session, cha
if ( ws_safe_read ( session , ( * payload ) , ( * payload_len ) , opcode ) ) {
if ( ws_safe_read ( session , ( * payload ) , ( * payload_len ) , opcode ) ) {
return 0 ;
return 0 ;
}
}
/* If a mask is present unmask the payload */
/* If a mask is present unmask the payload */
if ( mask_present ) {
if ( mask_present ) {
unsigned int pos ;
unsigned int pos ;
@ -1199,19 +1198,13 @@ struct ast_websocket *AST_OPTIONAL_API_NAME(ast_websocket_client_create)
}
}
int AST_OPTIONAL_API_NAME ( ast_websocket_read_string )
int AST_OPTIONAL_API_NAME ( ast_websocket_read_string )
( struct ast_websocket * ws , struct ast_st r * * buf )
( struct ast_websocket * ws , cha r * * buf )
{
{
char * payload ;
char * payload ;
uint64_t payload_len ;
uint64_t payload_len ;
enum ast_websocket_opcode opcode ;
enum ast_websocket_opcode opcode ;
int fragmented = 1 ;
int fragmented = 1 ;
if ( ! * buf & & ! ( * buf = ast_str_create ( 512 ) ) ) {
ast_log ( LOG_ERROR , " Client Websocket string read - "
" Unable to allocate string buffer " ) ;
return - 1 ;
}
while ( fragmented ) {
while ( fragmented ) {
if ( ast_websocket_read ( ws , & payload , & payload_len ,
if ( ast_websocket_read ( ws , & payload , & payload_len ,
& opcode , & fragmented ) ) {
& opcode , & fragmented ) ) {
@ -1220,6 +1213,10 @@ int AST_OPTIONAL_API_NAME(ast_websocket_read_string)
return - 1 ;
return - 1 ;
}
}
if ( opcode = = AST_WEBSOCKET_OPCODE_CONTINUATION ) {
continue ;
}
if ( opcode = = AST_WEBSOCKET_OPCODE_CLOSE ) {
if ( opcode = = AST_WEBSOCKET_OPCODE_CLOSE ) {
return - 1 ;
return - 1 ;
}
}
@ -1229,17 +1226,21 @@ int AST_OPTIONAL_API_NAME(ast_websocket_read_string)
" non string data received \n " ) ;
" non string data received \n " ) ;
return - 1 ;
return - 1 ;
}
}
}
ast_str_append ( buf , 0 , " %s " , payload ) ;
if ( ! ( * buf = ast_malloc ( payload_len + 1 ) ) ) {
return - 1 ;
}
}
return ast_str_size ( * buf ) ;
ast_copy_string ( * buf , payload , payload_len + 1 ) ;
return payload_len + 1 ;
}
}
int AST_OPTIONAL_API_NAME ( ast_websocket_write_string )
int AST_OPTIONAL_API_NAME ( ast_websocket_write_string )
( struct ast_websocket * ws , const struct ast_st r * buf )
( struct ast_websocket * ws , const cha r * buf )
{
{
return ast_websocket_write ( ws , AST_WEBSOCKET_OPCODE_TEXT ,
return ast_websocket_write ( ws , AST_WEBSOCKET_OPCODE_TEXT ,
ast_str_buffer ( buf ) , ast_str_ strlen( buf ) ) ;
( char * ) buf , strlen( buf ) ) ;
}
}
static int load_module ( void )
static int load_module ( void )