Mercurial > mplayer.hg
comparison libmpdemux/http.c @ 18879:cc65a585fdcc
rm unnecesary casts from void* - part 3
author | reynaldo |
---|---|
date | Sun, 02 Jul 2006 08:17:07 +0000 |
parents | 4928dd61f136 |
children | a8e681ad7c90 |
comparison
equal
deleted
inserted
replaced
18878:3bf0d70b4c7f | 18879:cc65a585fdcc |
---|---|
109 unsigned char tmp = 0; | 109 unsigned char tmp = 0; |
110 unsigned metalen; | 110 unsigned metalen; |
111 my_read(fd, &tmp, 1, sc); | 111 my_read(fd, &tmp, 1, sc); |
112 metalen = tmp * 16; | 112 metalen = tmp * 16; |
113 if (metalen > 0) { | 113 if (metalen > 0) { |
114 char *info = (char *)malloc(metalen + 1); | 114 char *info = malloc(metalen + 1); |
115 unsigned nlen = my_read(fd, info, metalen, sc); | 115 unsigned nlen = my_read(fd, info, metalen, sc); |
116 info[nlen] = 0; | 116 info[nlen] = 0; |
117 mp_msg(MSGT_DEMUXER, MSGL_INFO, "\nICY Info: %s\n", info); | 117 mp_msg(MSGT_DEMUXER, MSGL_INFO, "\nICY Info: %s\n", info); |
118 free(info); | 118 free(info); |
119 } | 119 } |
280 | 280 |
281 HTTP_header_t * | 281 HTTP_header_t * |
282 http_new_header(void) { | 282 http_new_header(void) { |
283 HTTP_header_t *http_hdr; | 283 HTTP_header_t *http_hdr; |
284 | 284 |
285 http_hdr = (HTTP_header_t*)malloc(sizeof(HTTP_header_t)); | 285 http_hdr = malloc(sizeof(HTTP_header_t)); |
286 if( http_hdr==NULL ) return NULL; | 286 if( http_hdr==NULL ) return NULL; |
287 memset( http_hdr, 0, sizeof(HTTP_header_t) ); | 287 memset( http_hdr, 0, sizeof(HTTP_header_t) ); |
288 | 288 |
289 return http_hdr; | 289 return http_hdr; |
290 } | 290 } |
354 if( hdr_ptr==NULL ) { | 354 if( hdr_ptr==NULL ) { |
355 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. No space separator found.\n"); | 355 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. No space separator found.\n"); |
356 return -1; | 356 return -1; |
357 } | 357 } |
358 len = hdr_ptr-http_hdr->buffer; | 358 len = hdr_ptr-http_hdr->buffer; |
359 http_hdr->protocol = (char*)malloc(len+1); | 359 http_hdr->protocol = malloc(len+1); |
360 if( http_hdr->protocol==NULL ) { | 360 if( http_hdr->protocol==NULL ) { |
361 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 361 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
362 return -1; | 362 return -1; |
363 } | 363 } |
364 strncpy( http_hdr->protocol, http_hdr->buffer, len ); | 364 strncpy( http_hdr->protocol, http_hdr->buffer, len ); |
382 if( hdr_ptr==NULL ) { | 382 if( hdr_ptr==NULL ) { |
383 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n"); | 383 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n"); |
384 return -1; | 384 return -1; |
385 } | 385 } |
386 len = ptr-hdr_ptr; | 386 len = ptr-hdr_ptr; |
387 http_hdr->reason_phrase = (char*)malloc(len+1); | 387 http_hdr->reason_phrase = malloc(len+1); |
388 if( http_hdr->reason_phrase==NULL ) { | 388 if( http_hdr->reason_phrase==NULL ) { |
389 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 389 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
390 return -1; | 390 return -1; |
391 } | 391 } |
392 strncpy( http_hdr->reason_phrase, hdr_ptr, len ); | 392 strncpy( http_hdr->reason_phrase, hdr_ptr, len ); |
446 if( http_hdr==NULL ) return NULL; | 446 if( http_hdr==NULL ) return NULL; |
447 | 447 |
448 if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET"); | 448 if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET"); |
449 if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/"); | 449 if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/"); |
450 else { | 450 else { |
451 uri = (char*)malloc(strlen(http_hdr->uri) + 1); | 451 uri = malloc(strlen(http_hdr->uri) + 1); |
452 if( uri==NULL ) { | 452 if( uri==NULL ) { |
453 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n"); | 453 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n"); |
454 return NULL; | 454 return NULL; |
455 } | 455 } |
456 strcpy(uri,http_hdr->uri); | 456 strcpy(uri,http_hdr->uri); |
474 // Free the buffer if it was previously used | 474 // Free the buffer if it was previously used |
475 if( http_hdr->buffer!=NULL ) { | 475 if( http_hdr->buffer!=NULL ) { |
476 free( http_hdr->buffer ); | 476 free( http_hdr->buffer ); |
477 http_hdr->buffer = NULL; | 477 http_hdr->buffer = NULL; |
478 } | 478 } |
479 http_hdr->buffer = (char*)malloc(len+1); | 479 http_hdr->buffer = malloc(len+1); |
480 if( http_hdr->buffer==NULL ) { | 480 if( http_hdr->buffer==NULL ) { |
481 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n"); | 481 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n"); |
482 return NULL; | 482 return NULL; |
483 } | 483 } |
484 http_hdr->buffer_size = len; | 484 http_hdr->buffer_size = len; |
540 void | 540 void |
541 http_set_field( HTTP_header_t *http_hdr, const char *field_name ) { | 541 http_set_field( HTTP_header_t *http_hdr, const char *field_name ) { |
542 HTTP_field_t *new_field; | 542 HTTP_field_t *new_field; |
543 if( http_hdr==NULL || field_name==NULL ) return; | 543 if( http_hdr==NULL || field_name==NULL ) return; |
544 | 544 |
545 new_field = (HTTP_field_t*)malloc(sizeof(HTTP_field_t)); | 545 new_field = malloc(sizeof(HTTP_field_t)); |
546 if( new_field==NULL ) { | 546 if( new_field==NULL ) { |
547 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 547 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
548 return; | 548 return; |
549 } | 549 } |
550 new_field->next = NULL; | 550 new_field->next = NULL; |
551 new_field->field_name = (char*)malloc(strlen(field_name)+1); | 551 new_field->field_name = malloc(strlen(field_name)+1); |
552 if( new_field->field_name==NULL ) { | 552 if( new_field->field_name==NULL ) { |
553 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 553 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
554 return; | 554 return; |
555 } | 555 } |
556 strcpy( new_field->field_name, field_name ); | 556 strcpy( new_field->field_name, field_name ); |
566 | 566 |
567 void | 567 void |
568 http_set_method( HTTP_header_t *http_hdr, const char *method ) { | 568 http_set_method( HTTP_header_t *http_hdr, const char *method ) { |
569 if( http_hdr==NULL || method==NULL ) return; | 569 if( http_hdr==NULL || method==NULL ) return; |
570 | 570 |
571 http_hdr->method = (char*)malloc(strlen(method)+1); | 571 http_hdr->method = malloc(strlen(method)+1); |
572 if( http_hdr->method==NULL ) { | 572 if( http_hdr->method==NULL ) { |
573 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 573 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
574 return; | 574 return; |
575 } | 575 } |
576 strcpy( http_hdr->method, method ); | 576 strcpy( http_hdr->method, method ); |
578 | 578 |
579 void | 579 void |
580 http_set_uri( HTTP_header_t *http_hdr, const char *uri ) { | 580 http_set_uri( HTTP_header_t *http_hdr, const char *uri ) { |
581 if( http_hdr==NULL || uri==NULL ) return; | 581 if( http_hdr==NULL || uri==NULL ) return; |
582 | 582 |
583 http_hdr->uri = (char*)malloc(strlen(uri)+1); | 583 http_hdr->uri = malloc(strlen(uri)+1); |
584 if( http_hdr->uri==NULL ) { | 584 if( http_hdr->uri==NULL ) { |
585 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 585 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
586 return; | 586 return; |
587 } | 587 } |
588 strcpy( http_hdr->uri, uri ); | 588 strcpy( http_hdr->uri, uri ); |
597 | 597 |
598 if( password!=NULL ) { | 598 if( password!=NULL ) { |
599 pass_len = strlen(password); | 599 pass_len = strlen(password); |
600 } | 600 } |
601 | 601 |
602 usr_pass = (char*)malloc(strlen(username)+pass_len+2); | 602 usr_pass = malloc(strlen(username)+pass_len+2); |
603 if( usr_pass==NULL ) { | 603 if( usr_pass==NULL ) { |
604 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 604 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
605 goto out; | 605 goto out; |
606 } | 606 } |
607 | 607 |
608 sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password ); | 608 sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password ); |
609 | 609 |
610 // Base 64 encode with at least 33% more data than the original size | 610 // Base 64 encode with at least 33% more data than the original size |
611 encoded_len = strlen(usr_pass)*2; | 611 encoded_len = strlen(usr_pass)*2; |
612 b64_usr_pass = (char*)malloc(encoded_len); | 612 b64_usr_pass = malloc(encoded_len); |
613 if( b64_usr_pass==NULL ) { | 613 if( b64_usr_pass==NULL ) { |
614 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 614 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
615 goto out; | 615 goto out; |
616 } | 616 } |
617 | 617 |
621 goto out; | 621 goto out; |
622 } | 622 } |
623 | 623 |
624 b64_usr_pass[out_len]='\0'; | 624 b64_usr_pass[out_len]='\0'; |
625 | 625 |
626 auth = (char*)malloc(encoded_len+22); | 626 auth = malloc(encoded_len+22); |
627 if( auth==NULL ) { | 627 if( auth==NULL ) { |
628 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); | 628 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); |
629 goto out; | 629 goto out; |
630 } | 630 } |
631 | 631 |