Mercurial > mplayer.hg
comparison stream/http.c @ 32547:6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
author | cboesch |
---|---|
date | Thu, 18 Nov 2010 20:20:39 +0000 |
parents | 84bdbf9e9c48 |
children | 683199947822 |
comparison
equal
deleted
inserted
replaced
32546:e21aa887e9df | 32547:6a629e6fdb09 |
---|---|
600 return; | 600 return; |
601 } | 601 } |
602 strcpy( http_hdr->uri, uri ); | 602 strcpy( http_hdr->uri, uri ); |
603 } | 603 } |
604 | 604 |
605 int | 605 static int |
606 http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { | 606 http_add_authentication( HTTP_header_t *http_hdr, const char *username, const char *password, const char *auth_str ) { |
607 char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL; | 607 char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL; |
608 int encoded_len, pass_len=0, out_len; | 608 int encoded_len, pass_len=0, out_len; |
609 size_t auth_len; | |
609 int res = -1; | 610 int res = -1; |
610 if( http_hdr==NULL || username==NULL ) return -1; | 611 if( http_hdr==NULL || username==NULL ) return -1; |
611 | 612 |
612 if( password!=NULL ) { | 613 if( password!=NULL ) { |
613 pass_len = strlen(password); | 614 pass_len = strlen(password); |
635 goto out; | 636 goto out; |
636 } | 637 } |
637 | 638 |
638 b64_usr_pass[out_len]='\0'; | 639 b64_usr_pass[out_len]='\0'; |
639 | 640 |
640 auth = malloc(encoded_len+22); | 641 auth_len = encoded_len + 100; |
642 auth = malloc(auth_len); | |
641 if( auth==NULL ) { | 643 if( auth==NULL ) { |
642 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); | 644 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
643 goto out; | 645 goto out; |
644 } | 646 } |
645 | 647 |
646 sprintf( auth, "Authorization: Basic %s", b64_usr_pass); | 648 snprintf(auth, auth_len, "%s: Basic %s", auth_str, b64_usr_pass); |
647 http_set_field( http_hdr, auth ); | 649 http_set_field( http_hdr, auth ); |
648 res = 0; | 650 res = 0; |
649 | 651 |
650 out: | 652 out: |
651 free( usr_pass ); | 653 free( usr_pass ); |
652 free( b64_usr_pass ); | 654 free( b64_usr_pass ); |
653 free( auth ); | 655 free( auth ); |
654 | 656 |
655 return res; | 657 return res; |
658 } | |
659 | |
660 int | |
661 http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { | |
662 return http_add_authentication(http_hdr, username, password, "Authorization"); | |
663 } | |
664 | |
665 int | |
666 http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { | |
667 return http_add_authentication(http_hdr, username, password, "Proxy-Authorization"); | |
656 } | 668 } |
657 | 669 |
658 void | 670 void |
659 http_debug_hdr( HTTP_header_t *http_hdr ) { | 671 http_debug_hdr( HTTP_header_t *http_hdr ) { |
660 HTTP_field_t *field; | 672 HTTP_field_t *field; |