Changeset 4440:970fdb88487b in roaraudio


Ignore:
Timestamp:
10/09/10 15:56:35 (8 years ago)
Author:
phi
Branch:
default
Message:

added support for lage messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/serverinfo.c

    r4433 r4440  
    4343 
    4444struct roar_server_info * roar_server_info(struct roar_connection * con) { 
     45 struct roar_server_info * ret; 
    4546 struct roar_message mes; 
    4647 uint16_t * d16; 
     48 char * data = NULL; 
    4749 
    4850 memset(&mes, 0, sizeof(mes)); 
     
    5557 d16[1] = ROAR_HOST2NET16(ROAR_IT_SERVER); 
    5658 
    57  if ( roar_req(con, &mes, NULL) != 0 ) 
     59 if ( roar_req(con, &mes, &data) != 0 ) 
    5860  return NULL; 
    5961 
     
    6163  return NULL; 
    6264 
    63  return roar_server_info_from_mes(&mes); 
     65 ret = roar_server_info_from_mes(&mes, data); 
     66 
     67 if ( data != NULL ) 
     68  free(data); 
     69 
     70 return ret; 
    6471} 
    6572 
     
    7582#define _add(t, m) do { if ( info->m != NULL && (sl = strlen(info->m)) != 0 ) { iebuf[idx].type = (t); iebuf[idx].len = sl; iebuf[idx].buf = (info->m); idx++; needlen += 4 + sl; } } while (0) 
    7683 
    77 int roar_server_info_to_mes(struct roar_message * mes, struct roar_server_info * info) { 
     84int roar_server_info_to_mes(struct roar_message * mes, struct roar_server_info * info, void ** data) { 
    7885 size_t needlen = 4; 
    7986 size_t sl; 
     
    8390 char * textpart; 
    8491 int i; 
     92 char * mesdata; 
    8593 
    8694 if ( mes == NULL || info == NULL ) 
     
    100108 
    101109 if ( needlen > LIBROAR_BUFFER_MSGDATA ) { 
    102   return -1; 
     110  if ( data == NULL ) 
     111   return -1; 
     112 
     113  mesdata = malloc(needlen); 
     114 
     115  if ( mesdata == NULL ) 
     116   return -1; 
     117 } else { 
     118  mesdata = mes->data; 
    103119 } 
    104120 
     
    107123 mes->datalen = needlen; 
    108124 
    109  d16 = (uint16_t*)mes->data; 
    110  
    111  mes->data[0] = 0; // version 
    112  mes->data[1] = 0; // reserved 
     125 d16 = (uint16_t*)mesdata; 
     126 
     127 mesdata[0] = 0; // version 
     128 mesdata[1] = 0; // reserved 
    113129 
    114130 d16[1] = ROAR_HOST2NET16(idx); 
     
    122138 } 
    123139 
    124  textpart = mes->data + (4 + 4*idx); 
     140 textpart = mesdata + (4 + 4*idx); 
    125141 
    126142 for (i = 0; i < idx; i++) { 
     
    132148} 
    133149 
    134 struct roar_server_info * roar_server_info_from_mes(struct roar_message * mes) { 
     150struct roar_server_info * roar_server_info_from_mes(struct roar_message * mes, void * data) { 
    135151 struct ie iebuf[sizeof(struct roar_server_info)/sizeof(char*)]; 
    136152 struct ie * ieptr; 
     
    143159 char * textbuf; 
    144160 char ** tptr; 
     161 char * mesdata; 
    145162 
    146163 ROAR_DBG("roar_server_info(mes=%p{.datalen=%llu) = ?", mes, (long long unsigned int)mes->datalen); 
     
    148165 if ( mes == NULL ) 
    149166  return NULL; 
     167 
     168 if ( data == NULL ) { 
     169  mesdata = mes->data; 
     170 } else { 
     171  mesdata = data; 
     172 } 
    150173 
    151174 memset(iebuf, 0, sizeof(iebuf)); 
     
    159182 ROAR_DBG("roar_server_info(mes=%p) = ?", mes); 
    160183 
    161  if ( mes->data[0] != 0 ) /* version */ 
    162   return NULL; 
    163  
    164  ROAR_DBG("roar_server_info(mes=%p) = ?", mes); 
    165  
    166  if ( mes->data[1] != 0 ) /* reserved */ 
    167   return NULL; 
    168  
    169  ROAR_DBG("roar_server_info(mes=%p) = ?", mes); 
    170  
    171  d16 = (uint16_t*)mes->data; 
     184 if ( mesdata[0] != 0 ) /* version */ 
     185  return NULL; 
     186 
     187 ROAR_DBG("roar_server_info(mes=%p) = ?", mes); 
     188 
     189 if ( mesdata[1] != 0 ) /* reserved */ 
     190  return NULL; 
     191 
     192 ROAR_DBG("roar_server_info(mes=%p) = ?", mes); 
     193 
     194 d16 = (uint16_t*)mesdata; 
    172195 
    173196 idx = ROAR_NET2HOST16(d16[1]); 
     
    191214 ROAR_DBG("roar_server_info(mes=%p) = ?", mes); 
    192215 
    193  d16 = (uint16_t*)mes->data; 
     216 d16 = (uint16_t*)mesdata; 
    194217 dptr = &(d16[2]); 
    195218 
    196  textpart = mes->data + (4 + 4*idx); 
     219 textpart = mesdata + (4 + 4*idx); 
    197220 
    198221 ROAR_DBG("roar_server_info(mes=%p): needlen=%llu", mes, (long long unsigned int)needlen); 
Note: See TracChangeset for help on using the changeset viewer.