Changeset 3882:8dceab4d1382 in roaraudio


Ignore:
Timestamp:
05/21/10 21:58:19 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

moved message functions into new proto.c

Location:
libroar
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/Makefile

    r3877 r3882  
    88VIO_BRIDGE=vio_bio.o vio_stdio.o 
    99VIO=$(VIO_META) $(VIO_BRIDGE) vio_cmd.o vio_magic.o vio_pipe.o vio_socket.o vio_winsock.o vio_stack.o vio_jumbo.o vio_proto.o vio_dstr.o vio_tantalos.o vio_rtp.o 
    10 OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o pinentry.o sshaskpass.o $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o 
     10OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o pinentry.o sshaskpass.o $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o proto.o 
    1111 
    1212#DEFINES        = -DDEBUG 
  • libroar/basic.c

    r3875 r3882  
    355355} 
    356356 
    357 #define _ROAR_MESS_BUF_LEN (1 /* version */ + 1 /* cmd */ + 2 /* stream */ + 4 /* pos */ + 2 /* datalen */) 
    358 int roar_send_message (struct roar_connection * con, struct roar_message * mes, char * data) { 
    359  struct roar_vio_calls * vio; 
    360  
    361  if ( (vio = roar_get_connection_vio2(con)) == NULL ) 
    362   return -1; 
    363  
    364  return roar_vsend_message(vio, mes, data); 
    365 } 
    366  
    367 int roar_vsend_message(struct roar_vio_calls * vio, struct roar_message * mes, char *  data) { 
    368  char buf[_ROAR_MESS_BUF_LEN]; 
    369  
    370  roar_errno = ROAR_ERROR_UNKNOWN; 
    371  
    372  ROAR_DBG("roar_send_message(*): try to send an request..."); 
    373  
    374  buf[0] = _ROAR_MESSAGE_VERSION; 
    375  buf[1] = (unsigned char) mes->cmd; 
    376  *(uint16_t*)(buf+2) = ROAR_HOST2NET16(mes->stream); 
    377  *(uint32_t*)(buf+4) = ROAR_HOST2NET32(mes->pos); 
    378  *(uint16_t*)(buf+8) = ROAR_HOST2NET16(mes->datalen); 
    379  
    380  if ( roar_vio_write(vio, buf, _ROAR_MESS_BUF_LEN) != _ROAR_MESS_BUF_LEN ) { 
    381   roar_errno = ROAR_ERROR_PIPE; 
    382   return -1; 
    383  } 
    384  
    385  if ( mes->datalen != 0 ) { 
    386   if ( roar_vio_write(vio, data == NULL ? mes->data : data, mes->datalen) != mes->datalen ) { 
    387    roar_errno = ROAR_ERROR_PIPE; 
    388    return -1; 
    389   } 
    390  } 
    391  
    392  roar_errno = ROAR_ERROR_NONE; 
    393  
    394  ROAR_DBG("roar_send_message(*) = 0"); 
    395  return 0; 
    396 } 
    397  
    398 int roar_recv_message (struct roar_connection * con, struct roar_message * mes, char ** data) { 
    399  struct roar_vio_calls * vio; 
    400  
    401  if ( (vio = roar_get_connection_vio2(con)) == NULL ) 
    402   return -1; 
    403  
    404  return roar_vrecv_message(vio, mes, data); 
    405 } 
    406  
    407 int roar_vrecv_message(struct roar_vio_calls * vio, struct roar_message * mes, char ** data) { 
    408  char buf[_ROAR_MESS_BUF_LEN]; 
    409  
    410  roar_errno = ROAR_ERROR_UNKNOWN; 
    411  
    412  ROAR_DBG("roar_recv_message(*): try to get a response form the server..."); 
    413  
    414  if ( mes == NULL ) 
    415   return -1; 
    416  
    417  if ( data != NULL ) 
    418   *data = NULL; 
    419  
    420  memset(mes, 0, sizeof(struct roar_message)); 
    421  
    422  if ( roar_vio_read(vio, buf, _ROAR_MESS_BUF_LEN) != _ROAR_MESS_BUF_LEN ) { 
    423   roar_errno = ROAR_ERROR_PROTO; 
    424   return -1; 
    425  } 
    426  
    427  ROAR_DBG("roar_recv_message(*): Got a header"); 
    428  
    429  if ( buf[0] != _ROAR_MESSAGE_VERSION ) { 
    430   roar_errno = ROAR_ERROR_PROTO; 
    431   return -1; 
    432  } 
    433  
    434  mes->cmd     = (unsigned char)buf[1]; 
    435  mes->stream  = ROAR_NET2HOST16(*(uint16_t*)(buf+2)); 
    436  mes->pos     = ROAR_NET2HOST32(*(uint32_t*)(buf+4)); 
    437  mes->datalen = ROAR_NET2HOST16(*(uint16_t*)(buf+8)); 
    438  
    439  if ( (int16_t)mes->stream == -1 ) 
    440   mes->stream = -1; 
    441  
    442  ROAR_DBG("roar_recv_message(*): command=%i(%s)", mes->cmd, 
    443            mes->cmd == ROAR_CMD_OK ? "OK" : (mes->cmd == ROAR_CMD_ERROR ? "ERROR" : "UNKNOWN")); 
    444  
    445  if ( mes->datalen == 0 ) { 
    446   ROAR_DBG("roar_recv_message(*): no data in this pkg"); 
    447   ROAR_DBG("roar_recv_message(*) = 0"); 
    448   roar_errno = ROAR_ERROR_NONE; 
    449   return 0; 
    450  } 
    451  
    452  if ( mes->datalen <= LIBROAR_BUFFER_MSGDATA ) { 
    453   if ( roar_vio_read(vio, mes->data, mes->datalen) == mes->datalen ) { 
    454    ROAR_DBG("roar_recv_message(*): Got data!"); 
    455    ROAR_DBG("roar_recv_message(*) = 0"); 
    456    roar_errno = ROAR_ERROR_NONE; 
    457    return 0; 
    458   } 
    459  
    460   roar_errno = ROAR_ERROR_PIPE; 
    461   return -1; 
    462  } else { 
    463   if ( data == NULL ) { 
    464    roar_errno = ROAR_ERROR_MSGSIZE; 
    465    return -1; 
    466   } 
    467  
    468   if ( (*data = malloc(mes->datalen)) == NULL ) { 
    469    roar_errno = ROAR_ERROR_NOMEM; 
    470    return -1; 
    471   } 
    472  
    473   if ( mes->datalen == 0 ) { 
    474    roar_errno = ROAR_ERROR_NONE; 
    475    return 0; 
    476   } 
    477  
    478   if ( roar_vio_read(vio, *data, mes->datalen) == mes->datalen ) { 
    479    ROAR_DBG("roar_recv_message(*): Got data!"); 
    480    ROAR_DBG("roar_recv_message(*) = 0"); 
    481    roar_errno = ROAR_ERROR_NONE; 
    482    return 0; 
    483   } 
    484  
    485   roar_errno = ROAR_ERROR_PIPE; 
    486   return -1; 
    487  } 
    488  
    489  // what happened here? 
    490  return -1; 
    491 } 
    492  
    493 int roar_req (struct roar_connection * con, struct roar_message * mes, char ** data) { 
    494  struct roar_vio_calls * vio; 
    495  
    496  if ( (vio = roar_get_connection_vio2(con)) == NULL ) 
    497   return -1; 
    498  
    499  return roar_vreq(vio, mes, data); 
    500 } 
    501  
    502 int roar_vreq         (struct roar_vio_calls * vio, struct roar_message * mes, char ** data) { 
    503  if ( roar_vsend_message(vio, mes, data ? *data : NULL) != 0 ) 
    504   return -1; 
    505  
    506  if ( data ) 
    507   free(*data); 
    508  
    509  roar_vio_sync(vio); // we need to do this becasue of ssl/compressed links 
    510  
    511  return roar_vrecv_message(vio, mes, data); 
    512 } 
    513  
    514357int roar_debug_message_print (struct roar_message * mes) { 
    515358 if ( mes == NULL ) 
Note: See TracChangeset for help on using the changeset viewer.