Changeset 4470:2188ebba6907 in roaraudio


Ignore:
Timestamp:
10/10/10 22:05:19 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added code for reading and writing auth messages

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/auth.h

    r4296 r4470  
    5252int roar_auth   (struct roar_connection * con); 
    5353 
     54int roar_auth_from_mes(struct roar_auth_message * ames, struct roar_message * mes, void * data); 
     55int roar_auth_to_mes(struct roar_message * mes, void ** data, struct roar_auth_message * ames); 
     56 
     57int roar_auth_init_mes(struct roar_message * mes, struct roar_auth_message * ames); 
     58 
     59 
    5460int    roar_str2autht(const char * str); 
    5561const char * roar_autht2str(const int auth); 
  • libroar/auth.c

    r4296 r4470  
    194194 return -1; 
    195195} 
     196 
     197 
     198int roar_auth_from_mes(struct roar_auth_message * ames, struct roar_message * mes, void * data) { 
     199 void * ibuf; 
     200 char header[4] = {0, 0, 0, 0}; 
     201 
     202 if ( ames == NULL || mes == NULL ) 
     203  return -1; 
     204 
     205 if ( data == NULL ) { 
     206  ibuf = data; 
     207 } else { 
     208  ibuf = mes->data; 
     209 } 
     210 
     211 memset(ames, 0, sizeof(struct roar_auth_message)); 
     212 
     213 memcpy(header, ibuf, mes->datalen < 4 ? mes->datalen : 4); 
     214 
     215 ames->type          = header[0]; 
     216 ames->stage         = header[1]; 
     217 ames->reserved.c[0] = header[2]; 
     218 ames->reserved.c[1] = header[3]; 
     219 
     220 if ( mes->datalen > 4 ) { 
     221  ames->data = ibuf + 4; 
     222  ames->len  = mes->datalen - 4; 
     223 } else { 
     224  ames->data = NULL; 
     225  ames->len  = 0; 
     226 } 
     227 
     228 return 0; 
     229} 
     230 
     231int roar_auth_to_mes(struct roar_message * mes, void ** data, struct roar_auth_message * ames) { 
     232 char * obuf; 
     233 
     234 if ( mes == NULL || ames == NULL ) 
     235  return -1; 
     236 
     237 if ( data != NULL ) 
     238  *data = NULL; 
     239 
     240 memset(mes, 0, sizeof(struct roar_message)); 
     241 
     242 if ( (ames->len + 4) > sizeof(mes->data) ) { 
     243  *data = malloc(ames->len + 4); 
     244  if ( *data == NULL ) 
     245   return -1; 
     246  obuf = *data; 
     247 } else { 
     248  obuf = mes->data; 
     249 } 
     250 
     251 obuf[0] = ames->type; 
     252 obuf[1] = ames->stage; 
     253 obuf[2] = ames->reserved.c[0]; 
     254 obuf[3] = ames->reserved.c[1]; 
     255 
     256 memcpy(obuf + 8, ames->data, ames->len); 
     257 
     258 mes->datalen = ames->len + 4; 
     259 
     260 return 0; 
     261} 
     262 
     263int roar_auth_init_mes(struct roar_message * mes, struct roar_auth_message * ames) { 
     264 if ( mes == NULL || ames == NULL ) 
     265  return -1; 
     266 
     267 if ( (ames->len + 4) > sizeof(mes->data) ) 
     268  return -1; 
     269 
     270 memset(mes, 0, sizeof(struct roar_message)); 
     271 
     272 mes->data[0] = ames->type; 
     273 mes->data[1] = ames->stage; 
     274 mes->data[2] = ames->reserved.c[0]; 
     275 mes->data[3] = ames->reserved.c[1]; 
     276 
     277 ames->data = &(mes->data[4]); 
     278 
     279 mes->datalen = ames->len + 4; 
     280 
     281 return 0; 
     282} 
     283 
     284 
    196285 
    197286// String functions: 
Note: See TracChangeset for help on using the changeset viewer.