Changeset 4843:05ca8907fa35 in roaraudio
- Timestamp:
- 04/05/11 00:18:34 (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r4824 r4843 10 10 * Added Record Bridge to roard. 11 11 * Added VIOs and DSTR elements: null:, zero:, nrandom: 12 * Added support for HTTP Basic Auth 12 13 13 14 v. 0.4beta4 - Sun Mar 20 2011 12:15 CET -
include/libroar/vio_proto.h
r4828 r4843 73 73 int roar_vio_proto_close (struct roar_vio_calls * vio); 74 74 75 int roar_vio_open_proto_http (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file );75 int roar_vio_open_proto_http (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file, struct roar_userpass * up); 76 76 int roar_vio_open_proto_gopher (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file); 77 77 #endif -
libroar/vio_proto.c
r4839 r4843 45 45 int ret; 46 46 char * ed; 47 char * tmp; 47 48 48 49 if ( def == NULL ) … … 72 73 *ed = 0; 73 74 75 if ( (tmp = strstr(dstr, "@")) != NULL ) 76 dstr = tmp + 1; 77 74 78 ROAR_DBG("roar_vio_proto_init_def(*): def->o_flags=%i", def->o_flags); 75 79 … … 92 96 char * dstr, int proto, struct roar_vio_defaults * odef) { 93 97 #ifndef ROAR_WITHOUT_VIO_PROTO 98 struct roar_userpass userpass = {.subtype = -1, .user = NULL, .pass = NULL}; 94 99 struct roar_vio_proto * self; 95 100 char * host; … … 151 156 } 152 157 158 if ( (tmp = strstr(host, "@")) != NULL ) { 159 userpass.user = host; 160 *tmp = 0; 161 host = tmp + 1; 162 if ( (tmp = strstr(userpass.user, ":")) != NULL ) { 163 *tmp = 0; 164 userpass.pass = tmp + 1; 165 } 166 } 167 153 168 ROAR_DBG("roar_vio_open_proto(*) = ?"); 154 ROAR_DBG("roar_vio_open_proto(*): proto=%i, host='%s', file='%s' ", proto, host, dstr);169 ROAR_DBG("roar_vio_open_proto(*): proto=%i, host='%s', file='%s', userpass={.user='%s', .pass='%s'}", proto, host, dstr, userpass.user, userpass.pass); 155 170 156 171 self->proto = proto; … … 159 174 case ROAR_VIO_PROTO_P_HTTP: 160 175 case ROAR_VIO_PROTO_P_ICY: 161 return roar_vio_open_proto_http(calls, dst, host, dstr );176 return roar_vio_open_proto_http(calls, dst, host, dstr, userpass.user != NULL ? &userpass : NULL); 162 177 break; 163 178 case ROAR_VIO_PROTO_P_GOPHER: … … 180 195 size_t len; 181 196 197 ROAR_DBG("roar_vio_proto_read(*): have=%lli, count=%lli", (long long int)have, (long long int)count); 198 182 199 if ( self->reader.buffer != NULL ) { 183 200 len = count; … … 193 210 } 194 211 } 212 213 ROAR_DBG("roar_vio_proto_read(*): have=%lli, count=%lli", (long long int)have, (long long int)count); 195 214 196 215 if ( count == 0 ) … … 327 346 return -1; 328 347 348 /* 349 if ( *p == '\r' || *p == '\n' ) 350 return 0; 351 */ 352 329 353 kv->key = p; 330 354 … … 409 433 } 410 434 411 int roar_vio_open_proto_http (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file) { 435 static inline char * _up2http_auth (struct roar_userpass * up) { 436 char * inbuf, * outbuf; 437 size_t inlen, outlen; 438 ssize_t ret; 439 //Authorization: Basic dXNlcjpwdw== 440 441 if ( up == NULL ) 442 return NULL; 443 444 if ( up->subtype != -1 ) 445 return NULL; 446 447 if ( up->user == NULL || up->pass == NULL ) 448 return NULL; 449 450 inlen = strlen(up->user) + strlen(up->pass) + 2; 451 inbuf = roar_mm_malloc(inlen); 452 if ( inbuf == NULL ) 453 return NULL; 454 455 inbuf[0] = 0; 456 strcat(inbuf, up->user); 457 strcat(inbuf, ":"); 458 strcat(inbuf, up->pass); 459 460 outlen = ((inlen * 3) / 2) + 3 /* padding... */ + 6 /* 'Basic ' */; 461 outbuf = roar_mm_malloc(outlen); 462 if ( outbuf == NULL ) { 463 roar_mm_free(inbuf); 464 return NULL; 465 } 466 467 strncpy(outbuf, "Basic ", 7); 468 469 ROAR_DBG("_up2http_auth(up=%p{.subtype=%i, .user='%s', .pass='%s'): inbuf='%s', outbuf='%s'", up, up->subtype, up->user, up->pass, inbuf, outbuf); 470 ret = roar_base64_encode(NULL, outbuf + 6, outlen - 6, inbuf, inlen - 1, NULL, 1); 471 ROAR_DBG("_up2http_auth(up=%p{.subtype=%i, .user='%s', .pass='%s'): inbuf='%s', outbuf='%s'", up, up->subtype, up->user, up->pass, inbuf, outbuf); 472 473 roar_mm_free(inbuf); 474 475 if ( ret == -1 ) { 476 roar_mm_free(outbuf); 477 return NULL; 478 } 479 480 return outbuf; 481 } 482 483 int roar_vio_open_proto_http (struct roar_vio_calls * calls, struct roar_vio_calls * dst, char * host, char * file, struct roar_userpass * up) { 412 484 struct roar_keyval kv; 413 485 struct roar_vio_proto * self; 414 486 struct roar_buffer * bufbuf; 415 487 void * vpbuf; 488 char * authbuf; 416 489 char * buf; 417 490 char * endofheader = NULL; … … 442 515 roar_vio_printf(dst, "User-Agent: roar_vio_open_proto_http() $Revision$\r\n"); 443 516 roar_vio_printf(dst, "Connection: close\r\n"); 517 if ( up != NULL ) { 518 if ( (authbuf = _up2http_auth(up)) != NULL ) { 519 roar_vio_printf(dst, "Authorization: %s\r\n", authbuf); 520 roar_mm_free(authbuf); 521 } 522 } 444 523 roar_vio_printf(dst, "\r\n"); 445 524 … … 529 608 if ( bufbuf != NULL ) { 530 609 roar_buffer_set_offset(bufbuf, endofheader - buf + oeflen); 531 roar_buffer_set_len(bufbuf, len - (endofheader - buf + oeflen) - 1);610 roar_buffer_set_len(bufbuf, len - (endofheader - buf + oeflen) - 0 /* ??? */); 532 611 } 533 612 self->reader.buffer = bufbuf;
Note: See TracChangeset
for help on using the changeset viewer.