[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[555] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-13 09:34:40
|
Revision: 555 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=555&view=rev Author: nickols_k Date: 2012-12-13 09:34:32 +0000 (Thu, 13 Dec 2012) Log Message: ----------- use more object-oriented programming in HTTP_Header + infinite.loop-- Modified Paths: -------------- mplayerxp/libmpdemux/demuxer.cpp mplayerxp/libmpstream2/asf_streaming.cpp mplayerxp/libmpstream2/cookies.cpp mplayerxp/libmpstream2/http.cpp mplayerxp/libmpstream2/http.h mplayerxp/libmpstream2/network.cpp Modified: mplayerxp/libmpdemux/demuxer.cpp =================================================================== --- mplayerxp/libmpdemux/demuxer.cpp 2012-12-13 07:22:44 UTC (rev 554) +++ mplayerxp/libmpdemux/demuxer.cpp 2012-12-13 09:34:32 UTC (rev 555) @@ -366,6 +366,7 @@ unsigned i=0; while(mime_type_table[i].driver!=&demux_null) { if(name==mime_type_table[i].mime_type) return mime_type_table[i].driver; + i++; } return &demux_null; } Modified: mplayerxp/libmpstream2/asf_streaming.cpp =================================================================== --- mplayerxp/libmpstream2/asf_streaming.cpp 2012-12-13 07:22:44 UTC (rev 554) +++ mplayerxp/libmpstream2/asf_streaming.cpp 2012-12-13 09:34:32 UTC (rev 555) @@ -583,7 +583,7 @@ // Common header for all requests. http_hdr->set_field("Accept: */*" ); http_hdr->set_field("User-Agent: NSPlayer/4.1.0.3856" ); - http_hdr->add_basic_authentication(url->username, url->password ); + http_hdr->add_basic_authentication(url->username?url->username:"", url->password?url->password:"" ); // Check if we are using a proxy if( !strcasecmp( url->protocol, "http_proxy" ) ) { @@ -721,7 +721,7 @@ HTTP_Header *http_hdr=NULL; URL *url = networking->url; asf_http_networking_t *asf_http_ctrl; - char buffer[BUFFER_SIZE]; + uint8_t buffer[BUFFER_SIZE]; int i, ret; int done; int auth_retry = 0; @@ -762,7 +762,7 @@ delete http_hdr; http_hdr = new(zeromem) HTTP_Header; do { - i = tcp.read((uint8_t*)buffer, BUFFER_SIZE); + i = tcp.read(buffer, BUFFER_SIZE); if( i<=0 ) { perror("read"); delete http_hdr; Modified: mplayerxp/libmpstream2/cookies.cpp =================================================================== --- mplayerxp/libmpstream2/cookies.cpp 2012-12-13 07:22:44 UTC (rev 554) +++ mplayerxp/libmpstream2/cookies.cpp 2012-12-13 09:34:32 UTC (rev 555) @@ -221,7 +221,7 @@ } /* Take an HTTP_header_t, and insert the correct headers. The cookie files are read if necessary. */ -void HTTP_Header::cookies_set(const char *domain, const char *url) +void HTTP_Header::cookies_set(const std::string& domain, const std::string& url) { int found_cookies = 0; struct cookie_list_type *cookies[MAX_COOKIES]; @@ -230,7 +230,7 @@ const char *path; char *buf; - path = strchr(url, '/'); + path = strchr(url.c_str(), '/'); if (!path) path = ""; @@ -243,7 +243,7 @@ /* Find which cookies we want, removing duplicates. Cookies with the longest domain, then longest path take priority */ while (list) { /* Check the cookie domain and path. Also, we never send "secure" cookies. These should only be sent over HTTPS. */ - if ((right_hand_strcmp(list->domain, domain) == 0) + if ((right_hand_strcmp(list->domain, domain.c_str()) == 0) && (left_hand_strcmp(list->path, path) == 0) && !list->secure) { int replacing = 0; for (i = 0; i < found_cookies; i++) { Modified: mplayerxp/libmpstream2/http.cpp =================================================================== --- mplayerxp/libmpstream2/http.cpp 2012-12-13 07:22:44 UTC (rev 554) +++ mplayerxp/libmpstream2/http.cpp 2012-12-13 09:34:32 UTC (rev 555) @@ -21,18 +21,17 @@ namespace mpxp { HTTP_Header::HTTP_Header() {} HTTP_Header::~HTTP_Header() { - if( reason_phrase!=NULL ) delete reason_phrase ; if( buffer!=NULL ) delete buffer ; } -int HTTP_Header::response_append(const char *response, int length ) { - if( response==NULL || length<0 ) return -1; +int HTTP_Header::response_append(const uint8_t* response, size_t length ) { + if( response==NULL) return -1; if( (unsigned)length > std::numeric_limits<size_t>::max() - buffer_size - 1) { MSG_FATAL("Bad size in memory (re)allocation\n"); return -1; } - buffer = (char*)mp_realloc( buffer, buffer_size+length+1 ); + buffer = (uint8_t*)mp_realloc( buffer, buffer_size+length+1 ); if(buffer ==NULL ) { MSG_FATAL("Memory allocation failed\n"); return -1; @@ -46,8 +45,8 @@ int HTTP_Header::is_header_entire() const { if( buffer==NULL ) return 0; // empty - if( strstr(buffer, "\r\n\r\n")==NULL && - strstr(buffer, "\n\n")==NULL ) return 0; + if( strstr((char*)buffer, "\r\n\r\n")==NULL && + strstr((char*)buffer, "\n\n")==NULL ) return 0; return 1; } @@ -59,13 +58,13 @@ if( is_parsed ) return 0; // Get the protocol - hdr_ptr = strstr( buffer, " " ); + hdr_ptr = strstr( (char*)buffer, " " ); if( hdr_ptr==NULL ) { MSG_FATAL("Malformed answer. No space separator found.\n"); return -1; } - len = hdr_ptr-buffer; - protocol.assign(buffer,len); + len = hdr_ptr-(char*)buffer; + protocol.assign((char*)buffer,len); std::string sstr=protocol.substr(0,4); std::transform(sstr.begin(), sstr.end(),sstr.begin(), ::toupper); if(sstr=="HTTP") { @@ -89,32 +88,28 @@ return -1; } len = ptr-hdr_ptr; - reason_phrase = new char[len+1]; - if( reason_phrase==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return -1; - } - strncpy( reason_phrase, hdr_ptr, len ); + reason_phrase.assign(hdr_ptr, len); if( reason_phrase[len-1]=='\r' ) { len--; + reason_phrase.resize(len); } reason_phrase[len]='\0'; // Set the position of the header separator: \r\n\r\n hdr_sep_len = 4; - ptr = strstr( buffer, "\r\n\r\n" ); + ptr = strstr( (char*)buffer, "\r\n\r\n" ); if( ptr==NULL ) { - ptr = strstr( buffer, "\n\n" ); + ptr = strstr( (char*)buffer, "\n\n" ); if( ptr==NULL ) { MSG_ERR("Header may be incomplete. No CRLF CRLF found.\n"); return -1; } hdr_sep_len = 2; } - pos_hdr_sep = ptr-buffer; + pos_hdr_sep = ptr-(char*)buffer; // Point to the first line after the method line. - hdr_ptr = strstr( buffer, "\n" )+1; + hdr_ptr = strstr( (char*)buffer, "\n" )+1; do { ptr = hdr_ptr; while( *ptr!='\r' && *ptr!='\n' ) ptr++; @@ -129,14 +124,13 @@ field[len]='\0'; set_field( field ); hdr_ptr = ptr+((*ptr=='\r')?2:1); - } while( hdr_ptr<(buffer+pos_hdr_sep) ); + } while( hdr_ptr<((char*)buffer+pos_hdr_sep) ); if( field!=NULL ) delete field ; if( pos_hdr_sep+hdr_sep_len<buffer_size ) { // Response has data! - body = buffer+pos_hdr_sep+hdr_sep_len; - body_size = buffer_size-(pos_hdr_sep+hdr_sep_len); + body.assign((char*)buffer+pos_hdr_sep+hdr_sep_len,buffer_size-(pos_hdr_sep+hdr_sep_len)); } is_parsed = 1; @@ -159,15 +153,15 @@ // Add the CRLF len += 2; // Add the body - if( body!=NULL ) { - len += body_size; + if( !body.empty() ) { + len += body.length(); } // Free the buffer if it was previously used if( buffer!=NULL ) { delete buffer ; buffer = NULL; } - buffer = new char [len+1]; + buffer = new uint8_t [len+1]; if( buffer==NULL ) { MSG_FATAL("Memory allocation failed\n"); return NULL; @@ -175,21 +169,21 @@ buffer_size = len; //*** Building the request - ptr = buffer; + ptr = (char*)buffer; // Add the method line ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", method.c_str(),uri.c_str(), http_minor_version ); // Add the field for(unsigned i=0;i<sz;i++) ptr += sprintf( ptr, "%s\r\n", fields[i].c_str()); ptr += sprintf( ptr, "\r\n" ); // Add the body - if( body!=NULL ) { - memcpy( ptr, body, body_size ); + if( !body.empty()) { + memcpy( ptr, body.c_str(), body.size()); } - return buffer; + return (char *)buffer; } -const char* HTTP_Header::get_field(const char *field_name ) { +const char* HTTP_Header::get_field(const std::string& field_name ) { search_pos=0; field_search=field_name; return get_next_field(); @@ -215,36 +209,34 @@ return NULL; } -void HTTP_Header::set_field(const char *field_name ) { - if( field_name==NULL ) return; +void HTTP_Header::set_field(const std::string& field_name ) { + if(field_name.empty()) return; fields.push_back(field_name); } -void HTTP_Header::set_method( const char *_method ) { - if( _method==NULL ) return; +void HTTP_Header::set_method( const std::string& _method ) { method=_method; } -void HTTP_Header::set_uri(const char *_uri ) { - if(_uri==NULL ) return; +void HTTP_Header::set_uri(const std::string& _uri ) { uri=_uri; } -int HTTP_Header::add_basic_authentication( const char *username, const char *password ) { +int HTTP_Header::add_basic_authentication( const std::string& username, const std::string& password ) { char *auth=NULL, *usr_pass=NULL, *b64_usr_pass=NULL; int encoded_len, pass_len=0, out_len; int res = -1; - if( username==NULL ) return -1; + if( username.empty() ) return -1; - if( password!=NULL ) pass_len = strlen(password); + if( !password.empty() ) pass_len = password.length(); - usr_pass = new char [strlen(username)+pass_len+2]; + usr_pass = new char [username.length()+pass_len+2]; if( usr_pass==NULL ) { MSG_FATAL("Memory allocation failed\n"); goto out; } - sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password ); + sprintf( usr_pass, "%s:%s", username.c_str(), password.c_str() ); // Base 64 encode with at least 33% more data than the original size encoded_len = strlen(usr_pass)*2; @@ -280,8 +272,7 @@ } void HTTP_Header::erase_body() { - body=NULL; - body_size=0; + body.clear(); } void HTTP_Header::debug_hdr( ) { @@ -300,8 +291,8 @@ ,uri.c_str() ,method.c_str() ,status_code - ,reason_phrase - ,body_size ); + ,reason_phrase.c_str() + ,body.length() ); MSG_V("Fields:\n"); std::vector<std::string>::size_type sz = fields.size(); Modified: mplayerxp/libmpstream2/http.h =================================================================== --- mplayerxp/libmpstream2/http.h 2012-12-13 07:22:44 UTC (rev 554) +++ mplayerxp/libmpstream2/http.h 2012-12-13 09:34:32 UTC (rev 555) @@ -10,6 +10,7 @@ #include <string> #include <vector> +#include <stdint.h> namespace mpxp { class HTTP_Header : public Opaque { @@ -17,33 +18,33 @@ HTTP_Header(); virtual ~HTTP_Header(); - virtual int response_append(const char *data, int length ); + virtual int response_append(const uint8_t* data,size_t length); virtual int response_parse(); virtual int is_header_entire() const; virtual const char* build_request(); - virtual const char* get_field(const char *field_name ); + virtual const char* get_field(const std::string& field_name ); virtual const char* get_next_field(); - virtual void set_field(const char *field_name ); - virtual void set_method(const char *method ); - virtual void set_uri(const char *uri ); - virtual int add_basic_authentication(const char *username, const char *password ); + virtual void set_field(const std::string& field_name ); + virtual void set_method(const std::string& method ); + virtual void set_uri(const std::string& uri ); + virtual int add_basic_authentication(const std::string& username, const std::string& password ); virtual void debug_hdr(); - virtual void cookies_set(const char *hostname, const char *url); + virtual void cookies_set(const std::string& hostname, const std::string& url); - const char* get_reason_phrase() const { return reason_phrase; } + const char* get_reason_phrase() const { return reason_phrase.c_str(); } const char* get_protocol() const { return protocol.c_str(); } unsigned get_status() const { return status_code; } - const char* get_body() const { return body; } - size_t get_body_size() const { return body_size; } + const char* get_body() const { return body.c_str(); } + size_t get_body_size() const { return body.length(); } virtual void erase_body(); - const char* get_buffer() const { return buffer; } + const uint8_t* get_buffer() const { return buffer; } size_t get_buffer_size() const { return buffer_size; } private: std::string protocol; std::string method; std::string uri; - char* reason_phrase; + std::string reason_phrase; unsigned int http_minor_version; // Field variables std::vector<std::string> fields; @@ -51,11 +52,10 @@ std::vector<std::string>::size_type search_pos; // Body variables unsigned int status_code; - char* body; - size_t body_size; + std::string body; unsigned int is_parsed; - char* buffer; - size_t buffer_size; + uint8_t* buffer; + unsigned buffer_size; }; extern int base64_encode(const any_t*enc, int encLen, char *out, int outMax); Modified: mplayerxp/libmpstream2/network.cpp =================================================================== --- mplayerxp/libmpstream2/network.cpp 2012-12-13 07:22:44 UTC (rev 554) +++ mplayerxp/libmpstream2/network.cpp 2012-12-13 09:34:32 UTC (rev 555) @@ -171,7 +171,7 @@ if (net_conf.cookies_enabled) http_hdr.cookies_set( server_url->hostname, server_url->url ); http_hdr.set_field( "Connection: closed"); - http_hdr.add_basic_authentication( url->username, url->password ); + http_hdr.add_basic_authentication( url->username?url->username:"", url->password?url->password:""); if( http_hdr.build_request( )==NULL ) { goto err_out; } @@ -207,13 +207,13 @@ HTTP_Header* http_read_response( Tcp& tcp ) { HTTP_Header* http_hdr = new(zeromem) HTTP_Header; - char response[BUFFER_SIZE]; + uint8_t response[BUFFER_SIZE]; int i; if( http_hdr==NULL ) return NULL; do { - i = tcp.read((uint8_t*)response, BUFFER_SIZE); + i = tcp.read(response, BUFFER_SIZE); if( i<0 ) { MSG_ERR("Read failed\n"); delete http_hdr; @@ -224,7 +224,7 @@ delete http_hdr; return NULL; } - http_hdr->response_append(response, i ); + http_hdr->response_append(response,i); } while( !http_hdr->is_header_entire() ); http_hdr->response_parse(); return http_hdr; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |