[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[536] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-11 11:31:35
|
Revision: 536 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=536&view=rev Author: nickols_k Date: 2012-12-11 11:31:23 +0000 (Tue, 11 Dec 2012) Log Message: ----------- simplify logic of HTTP_Header: use std::vector<std::string> instead of HTTP_field_t + move variables into private Modified Paths: -------------- mplayerxp/Makefile mplayerxp/libmpstream/asf_streaming.cpp mplayerxp/libmpstream/cddb.cpp mplayerxp/libmpstream/http.cpp mplayerxp/libmpstream/http.h mplayerxp/libmpstream/network.cpp mplayerxp/libmpstream/tcp.cpp Modified: mplayerxp/Makefile =================================================================== --- mplayerxp/Makefile 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/Makefile 2012-12-11 11:31:23 UTC (rev 536) @@ -68,7 +68,7 @@ $(DO_MAKE_ALL) $(CXX) -o $(TARGET_EXE) $(OBJS) $(LDFLAGS) $(LDXXFLAGS) $(LIBS) #-Xlinker --export-dynamic -Xlinker --gc-sections -Xlinker --sort-common -$(SRCS): dep +$(SRCS): .depend install: $(TARGET_EXE) ifeq ($(INSTALL),) @@ -103,7 +103,7 @@ -rm -f mp_config.h mp_config.mak mp_conf_lavc.h version.h -rm -f cpuinfo help_mp.h -dep: version.h +.depend: $(CXX) -MM $(CXXFLAGS) $(SRCS) 1>.depend $(DO_MAKE) Modified: mplayerxp/libmpstream/asf_streaming.cpp =================================================================== --- mplayerxp/libmpstream/asf_streaming.cpp 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/libmpstream/asf_streaming.cpp 2012-12-11 11:31:23 UTC (rev 536) @@ -502,15 +502,15 @@ static int asf_header_check( HTTP_Header& http_hdr ) { ASF_obj_header_t *objh; - if( http_hdr.body==NULL || http_hdr.body_size<sizeof(ASF_obj_header_t) ) return -1; + if( http_hdr.get_body()==NULL || http_hdr.get_body_size()<sizeof(ASF_obj_header_t) ) return -1; - objh = (ASF_obj_header_t*)http_hdr.body; + objh = (ASF_obj_header_t*)http_hdr.get_body(); if( ASF_LOAD_GUID_PREFIX(objh->guid)==0x75B22630 ) return 0; return -1; } static ASF_StreamType_e -asf_http_networking_type(char *content_type, char *features, HTTP_Header& http_hdr ) { +asf_http_networking_type(const char *content_type,const char *features, HTTP_Header& http_hdr ) { if( content_type==NULL ) return ASF_Unknown_e; if( !strcasecmp(content_type, "application/octet-stream") || !strcasecmp(content_type, "application/vnd.ms.wms-hdr.asfv1") || // New in Corona, first request @@ -529,7 +529,7 @@ // so we could used mime type to know the stream type, // but guess what? All of them are not well configured. // So we have to check for an asf header :(, but it works :p - if( http_hdr.body_size>sizeof(ASF_obj_header_t) ) { + if( http_hdr.get_body_size()>sizeof(ASF_obj_header_t) ) { if( asf_header_check( http_hdr )==0 ) { MSG_V("=====> ASF Plain text\n"); return ASF_PlainText_e; @@ -661,20 +661,20 @@ static int asf_http_parse_response(asf_http_networking_t *asf_http_ctrl, HTTP_Header& http_hdr ) { - char *content_type, *pragma; + const char *content_type, *pragma; char features[64] = "\0"; size_t len; if( http_hdr.response_parse()<0 ) { MSG_ERR("Failed to parse HTTP response\n"); return -1; } - switch( http_hdr.status_code ) { + switch( http_hdr.get_status()) { case 200: break; case 401: // Authentication required return ASF_Authenticate_e; default: - MSG_ERR("Server return %d:%s\n", http_hdr.status_code, http_hdr.get_reason_phrase()); + MSG_ERR("Server return %d:%s\n", http_hdr.get_status(), http_hdr.get_reason_phrase()); return -1; } @@ -682,8 +682,8 @@ pragma = http_hdr.get_field("Pragma"); while( pragma!=NULL ) { - char *comma_ptr=NULL; - char *end; + const char *comma_ptr=NULL; + const char *end; // The pragma line can get severals attributes // separeted with a comma ','. do { @@ -750,9 +750,9 @@ if( !tcp.established()) return MPXP_False; http_hdr = asf_http_request( networking ); - MSG_DBG2("Request [%s]\n", http_hdr->buffer ); - for(i=0; i < (int)http_hdr->buffer_size ; ) { - int r = tcp.write((uint8_t*)(http_hdr->buffer+i), http_hdr->buffer_size-i); + MSG_DBG2("Request [%s]\n", http_hdr->get_buffer() ); + for(i=0; i < (int)http_hdr->get_buffer_size() ; ) { + int r = tcp.write((uint8_t*)(http_hdr->get_buffer()+i), http_hdr->get_buffer_size()-i); if(r<0) { MSG_ERR("Socket write error : %s\n",strerror(errno)); return MPXP_False; @@ -771,8 +771,7 @@ http_hdr->response_append(buffer,i); } while( !http_hdr->is_header_entire()); if( mp_conf.verbose>0 ) { - http_hdr->buffer[http_hdr->buffer_size]='\0'; - MSG_DBG2("Response [%s]\n", http_hdr->buffer ); + MSG_DBG2("Response [%s]\n", http_hdr->get_buffer() ); } ret = asf_http_parse_response(asf_http_ctrl, *http_hdr); if( ret<0 ) { @@ -784,8 +783,8 @@ case ASF_Live_e: case ASF_Prerecorded_e: case ASF_PlainText_e: - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { + if( http_hdr->get_body_size()>0 ) { + if( networking_bufferize( networking, (unsigned char *)(http_hdr->get_body()), http_hdr->get_body_size())<0 ) { delete http_hdr; return MPXP_False; } @@ -805,8 +804,8 @@ } break; case ASF_Redirector_e: - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { + if( http_hdr->get_body_size()>0 ) { + if( networking_bufferize( networking, (unsigned char*)http_hdr->get_body(), http_hdr->get_body_size())<0 ) { delete http_hdr; return MPXP_False; } Modified: mplayerxp/libmpstream/cddb.cpp =================================================================== --- mplayerxp/libmpstream/cddb.cpp 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/libmpstream/cddb.cpp 2012-12-11 11:31:23 UTC (rev 536) @@ -171,7 +171,7 @@ http_hdr->debug_hdr(); - switch(http_hdr->status_code) { + switch(http_hdr->get_status()) { case 200: ret = reply_parser(*http_hdr, cddb_data); break; @@ -271,7 +271,7 @@ if( cddb_data==NULL ) return -1; - ret = sscanf((char*)http_hdr.body, "%d ", &status); + ret = sscanf(http_hdr.get_body(), "%d ", &status); if( ret!=1 ) { MSG_ERR("Parse error\n"); return -1; @@ -279,13 +279,13 @@ switch(status) { case 210: - ret = sscanf((char*)http_hdr.body, "%d %s %08lx", &status, category, &disc_id); + ret = sscanf(http_hdr.get_body(), "%d %s %08lx", &status, category, &disc_id); if( ret!=3 ) { MSG_ERR("Parse error\n"); return -1; } // Check if it's a xmcd database file - ptr = strstr((char*)http_hdr.body, "# xmcd"); + ptr = strstr(const_cast<char*>(http_hdr.get_body()), "# xmcd"); if( ptr==NULL ) { MSG_ERR("Invalid xmcd database file returned\n"); return -1; @@ -302,7 +302,7 @@ } // Ok found the end // do a sanity check - if( http_hdr.body_size<(unsigned long)(ptr2-ptr) ) { + if( http_hdr.get_body_size()<(unsigned long)(ptr2-ptr) ) { MSG_ERR("Unexpected fix me\n"); return -1; } @@ -310,8 +310,7 @@ cddb_data->xmcd_file_size = ptr2-ptr+2; cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; // Avoid the http_free function to mp_free the xmcd file...save a mempcy... - http_hdr.body = NULL; - http_hdr.body_size = 0; + http_hdr.erase_body(); return cddb_write_cache(cddb_data); default: MSG_ERR("Unhandled code\n"); @@ -330,7 +329,7 @@ char *ptr = NULL; int ret, status; - ret = sscanf((char*)http_hdr.body, "%d ", &status); + ret = sscanf(http_hdr.get_body(), "%d ", &status); if( ret!=1 ) { MSG_ERR("Parse error\n"); return -1; @@ -339,18 +338,18 @@ switch(status) { case 200: // Found exact match - ret = sscanf((char*)http_hdr.body, "%d %s %08lx %s", &status, cddb_data->category.c_str(), &(cddb_data->disc_id), album_title); + ret = sscanf(http_hdr.get_body(), "%d %s %08lx %s", &status, cddb_data->category.c_str(), &(cddb_data->disc_id), album_title); if( ret!=4 ) { MSG_ERR("Parse error\n"); return -1; } - ptr = strstr((char*)http_hdr.body, album_title); + ptr = strstr(const_cast<char*>(http_hdr.get_body()), album_title); if( ptr!=NULL ) { char *ptr2; int len; ptr2 = strstr(ptr, "\n"); if( ptr2==NULL ) { - len = (http_hdr.body_size)-(ptr-(char*)(http_hdr.body)); + len = http_hdr.get_body_size()-(ptr-http_hdr.get_body()); } else { len = ptr2-ptr+1; } @@ -365,7 +364,7 @@ break; case 210: // Found exact matches, list follows - ptr = strstr((char*)http_hdr.body, "\n"); + ptr = strstr(const_cast<char*>(http_hdr.get_body()), "\n"); if( ptr==NULL ) { MSG_ERR("Unable to find end of line\n"); return -1; @@ -378,13 +377,13 @@ MSG_ERR("Parse error\n"); return -1; } - ptr = strstr((char*)http_hdr.body, album_title); + ptr = strstr(const_cast<char*>(http_hdr.get_body()), album_title); if( ptr!=NULL ) { char *ptr2; int len; ptr2 = strstr(ptr, "\n"); if( ptr2==NULL ) { - len = (http_hdr.body_size)-(ptr-(char*)(http_hdr.body)); + len = (http_hdr.get_body_size())-(ptr-http_hdr.get_body()); } else { len = ptr2-ptr+1; } @@ -415,7 +414,7 @@ int ret, status; char *ptr; - ret = sscanf((char*)http_hdr.body, "%d ", &status); + ret = sscanf(http_hdr.get_body(), "%d ", &status); if( ret!=1 ) { MSG_ERR("Parse error\n"); return -1; @@ -423,7 +422,7 @@ switch(status) { case 210: - ptr = strstr((char*)http_hdr.body, "max proto:"); + ptr = strstr(const_cast<char*>(http_hdr.get_body()), "max proto:"); if( ptr==NULL ) { MSG_ERR("Parse error\n"); return -1; @@ -448,7 +447,7 @@ static int cddb_freedb_sites_parse(HTTP_Header& http_hdr, cddb_data_t *cddb_data) { int ret, status; UNUSED(cddb_data); - ret = sscanf((char*)http_hdr.body, "%d ", &status); + ret = sscanf((const char*)http_hdr.get_body(), "%d ", &status); if( ret!=1 ) { MSG_ERR("Parse error\n"); return -1; Modified: mplayerxp/libmpstream/http.cpp =================================================================== --- mplayerxp/libmpstream/http.cpp 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/libmpstream/http.cpp 2012-12-11 11:31:23 UTC (rev 536) @@ -6,6 +6,8 @@ * by Bertrand Baudet <ber...@ya...> * (C) 2001, MPlayer team. */ +#include <algorithm> +#include <ctype.h> #include <limits> #include <stdio.h> @@ -19,20 +21,8 @@ namespace mpxp { HTTP_Header::HTTP_Header() {} HTTP_Header::~HTTP_Header() { - HTTP_field_t *field, *field2free; - if( protocol!=NULL ) delete protocol ; - if( uri!=NULL ) delete uri ; if( reason_phrase!=NULL ) delete reason_phrase ; - if( field_search!=NULL ) delete field_search ; - if( method!=NULL ) delete method ; if( buffer!=NULL ) delete buffer ; - field = first_field; - while( field!=NULL ) { - field2free = field; - if (field->field_name) delete field->field_name; - field = field->next; - delete field2free; - } } int HTTP_Header::response_append(const char *response, int length ) { @@ -75,15 +65,11 @@ return -1; } len = hdr_ptr-buffer; - protocol = new char [len+1]; - if( protocol==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return -1; - } - strncpy( protocol, buffer, len ); - protocol[len]='\0'; - if( !strncasecmp( protocol, "HTTP", 4) ) { - if( sscanf( protocol+5,"1.%d", &(http_minor_version) )!=1 ) { + protocol.assign(buffer,len); + std::string sstr=protocol.substr(0,4); + std::transform(sstr.begin(), sstr.end(),sstr.begin(), ::toupper); + if(sstr=="HTTP") { + if( sscanf( &protocol.c_str()[5],"1.%d", &(http_minor_version) )!=1 ) { MSG_FATAL("Malformed answer. Unable to get HTTP minor version.\n"); return -1; } @@ -149,7 +135,7 @@ if( pos_hdr_sep+hdr_sep_len<buffer_size ) { // Response has data! - body = (unsigned char*)buffer+pos_hdr_sep+hdr_sep_len; + body = buffer+pos_hdr_sep+hdr_sep_len; body_size = buffer_size-(pos_hdr_sep+hdr_sep_len); } @@ -157,23 +143,19 @@ return 0; } -char* HTTP_Header::build_request() { +const char* HTTP_Header::build_request() { char *ptr; int len; - HTTP_field_t *field; - if( method==NULL ) set_method( "GET"); - if( uri==NULL ) set_uri( "/"); + if( method.empty() ) set_method( "GET"); + if( uri.empty() ) set_uri( "/"); //**** Compute the request length // Add the Method line - len = strlen(method)+strlen(uri)+12; + len = method.length()+uri.length()+12; // Add the fields - field = first_field; - while( field!=NULL ) { - len += strlen(field->field_name)+2; - field = field->next; - } + std::vector<std::string>::size_type sz = fields.size(); + for(unsigned i=0;i<sz;i++) len+= fields[i].length()+2; // Add the CRLF len += 2; // Add the body @@ -195,13 +177,9 @@ //*** Building the request ptr = buffer; // Add the method line - ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", method,uri, http_minor_version ); - field = first_field; + ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", method.c_str(),uri.c_str(), http_minor_version ); // Add the field - while( field!=NULL ) { - ptr += sprintf( ptr, "%s\r\n", field->field_name ); - field = field->next; - } + 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 ) { @@ -211,72 +189,45 @@ return buffer; } -char* HTTP_Header::get_field(const char *field_name ) { - if( field_name==NULL ) return NULL; - field_search_pos = first_field; - field_search = (char*)mp_realloc( field_search, strlen(field_name)+1 ); - if( field_search==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return NULL; - } - strcpy( field_search, field_name ); +const char* HTTP_Header::get_field(const char *field_name ) { + search_pos=0; + field_search=field_name; return get_next_field(); } -char* HTTP_Header::get_next_field() { - char *ptr; - HTTP_field_t *field; - - field = field_search_pos; - while( field!=NULL ) { - ptr = strstr( field->field_name, ":" ); - if( ptr==NULL ) return NULL; - if( !strncasecmp( field->field_name, field_search, ptr-(field->field_name) ) ) { - ptr++; // Skip the column - while( ptr[0]==' ' ) ptr++; // Skip the spaces if there is some - field_search_pos = field->next; - return ptr; // return the value without the field name +const char* HTTP_Header::get_next_field() { + std::vector<std::string>::size_type sz = fields.size(); + for(unsigned i=search_pos;i<sz;i++) { + size_t pos,epos; + const std::string& str = fields[i]; + pos=0; + epos=str.find(':',pos); + if(epos!=std::string::npos) { + if(str.substr(pos,epos)==field_search) { + epos++; // skip the column + pos=epos; + while(::isspace(str[epos])) epos++; + search_pos=i+1; + return &str[epos]; + } } - field = field->next; } return NULL; } void HTTP_Header::set_field(const char *field_name ) { - HTTP_field_t *new_field; if( field_name==NULL ) return; - - new_field = new(zeromem) HTTP_field_t; - if( new_field==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - return; - } - new_field->next = NULL; - new_field->field_name = new char [strlen(field_name)+1]; - if( new_field->field_name==NULL ) { - MSG_FATAL("Memory allocation failed\n"); - delete new_field; - return; - } - strcpy( new_field->field_name, field_name ); - - if( last_field==NULL ) { - first_field = new_field; - } else { - last_field->next = new_field; - } - last_field = new_field; - field_nb++; + fields.push_back(field_name); } void HTTP_Header::set_method( const char *_method ) { if( _method==NULL ) return; - method=mp_strdup(_method); + method=_method; } void HTTP_Header::set_uri(const char *_uri ) { if(_uri==NULL ) return; - uri=mp_strdup(_uri); + uri=_uri; } int HTTP_Header::add_basic_authentication( const char *username, const char *password ) { @@ -328,9 +279,13 @@ return res; } +void HTTP_Header::erase_body() { + body=NULL; + body_size=0; +} + void HTTP_Header::debug_hdr( ) { - HTTP_field_t *field; - int i = 0; + unsigned i = 0; MSG_V( "--- HTTP DEBUG HEADER --- START ---\n" "protocol: [%s]\n" @@ -340,20 +295,17 @@ "status code: [%d]\n" "reason phrase: [%s]\n" "body size: [%d]\n" - ,protocol + ,protocol.c_str() ,http_minor_version - ,uri - ,method + ,uri.c_str() + ,method.c_str() ,status_code ,reason_phrase ,body_size ); MSG_V("Fields:\n"); - field = first_field; - while( field!=NULL ) { - MSG_V(" %d - %s\n", i++, field->field_name ); - field = field->next; - } + std::vector<std::string>::size_type sz = fields.size(); + for(i=0;i<sz;i++) MSG_V(" %d - %s\n", i, fields[i].c_str()); MSG_V("--- HTTP DEBUG HEADER --- END ---\n"); } Modified: mplayerxp/libmpstream/http.h =================================================================== --- mplayerxp/libmpstream/http.h 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/libmpstream/http.h 2012-12-11 11:31:23 UTC (rev 536) @@ -6,15 +6,12 @@ #ifndef __HTTP_H_INCLUDED #define __HTTP_H_INCLUDED 1 - #include "mp_config.h" +#include <string> +#include <vector> + namespace mpxp { - struct HTTP_field_t { - char *field_name; - HTTP_field_t *next; - }; - class HTTP_Header : public Opaque { public: HTTP_Header(); @@ -23,9 +20,9 @@ virtual int response_append(const char *data, int length ); virtual int response_parse(); virtual int is_header_entire() const; - virtual char* build_request(); - virtual char* get_field(const char *field_name ); - virtual char* get_next_field(); + virtual const char* build_request(); + virtual const char* get_field(const char *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 ); @@ -34,27 +31,31 @@ virtual void debug_hdr(); virtual void cookies_set(const char *hostname, const char *url); - char* buffer; - size_t buffer_size; - unsigned int status_code; - unsigned char* body; - size_t body_size; const char* get_reason_phrase() const { return reason_phrase; } - const char* get_protocol() const { return protocol; } + 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; } + virtual void erase_body(); + const char* get_buffer() const { return buffer; } + size_t get_buffer_size() const { return buffer_size; } private: - char* protocol; - char* method; - char* uri; + std::string protocol; + std::string method; + std::string uri; char* reason_phrase; unsigned int http_minor_version; // Field variables - HTTP_field_t* first_field; - HTTP_field_t* last_field; - unsigned int field_nb; - char* field_search; - HTTP_field_t* field_search_pos; + std::vector<std::string> fields; + std::string field_search; + std::vector<std::string>::size_type search_pos; // Body variables + unsigned int status_code; + char* body; + size_t body_size; unsigned int is_parsed; + char* buffer; + size_t buffer_size; }; extern int base64_encode(const any_t*enc, int encLen, char *out, int outMax); Modified: mplayerxp/libmpstream/network.cpp =================================================================== --- mplayerxp/libmpstream/network.cpp 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/libmpstream/network.cpp 2012-12-11 11:31:23 UTC (rev 536) @@ -172,7 +172,7 @@ } MPXP_Rc http_send_request(Tcp& tcp, URL_t *url, off_t pos ) { - HTTP_Header* http_hdr = new(zeromem) HTTP_Header; + HTTP_Header& http_hdr = *new(zeromem) HTTP_Header; URL_t *server_url; char str[256]; int ret; @@ -181,37 +181,37 @@ if( !strcasecmp(url->protocol, "http_proxy") ) { proxy = 1; server_url = url_new( (url->file)+1 ); - http_hdr->set_uri(server_url->url ); + http_hdr.set_uri(server_url->url ); } else { server_url = url; - http_hdr->set_uri( server_url->file ); + http_hdr.set_uri( server_url->file ); } if (server_url->port && server_url->port != 80) snprintf(str, 256, "Host: %s:%d", server_url->hostname, server_url->port ); else snprintf(str, 256, "Host: %s", server_url->hostname ); - http_hdr->set_field(str); + http_hdr.set_field(str); if (net_conf.useragent) { snprintf(str, 256, "User-Agent: %s", net_conf.useragent); - http_hdr->set_field(str); + http_hdr.set_field(str); } else - http_hdr->set_field("User-Agent: MPlayerXP/"VERSION); + http_hdr.set_field("User-Agent: MPlayerXP/"VERSION); - http_hdr->set_field("Icy-MetaData: 1"); + http_hdr.set_field("Icy-MetaData: 1"); if(pos>0) { // Extend http_send_request with possibility to do partial content retrieval snprintf(str, 256, "Range: bytes=%d-", (int)pos); - http_hdr->set_field(str); + http_hdr.set_field(str); } - if (net_conf.cookies_enabled) http_hdr->cookies_set( server_url->hostname, server_url->url ); + 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 ); - if( http_hdr->build_request( )==NULL ) { + http_hdr.set_field( "Connection: closed"); + http_hdr.add_basic_authentication( url->username, url->password ); + if( http_hdr.build_request( )==NULL ) { goto err_out; } @@ -226,20 +226,20 @@ tcp.close(); tcp.open(server_url->hostname, server_url->port, Tcp::IP4); } - if(!tcp.established()) goto err_out; - MSG_DBG2("Request: [%s]\n", http_hdr->buffer ); + if(!tcp.established()) { MSG_ERR("Cannot establish connection\n"); goto err_out; } + MSG_DBG2("Request: [%s]\n", http_hdr.get_buffer() ); - ret = tcp.write((uint8_t*)(http_hdr->buffer), http_hdr->buffer_size); - if( ret!=(int)http_hdr->buffer_size ) { + ret = tcp.write((uint8_t*)(http_hdr.get_buffer()), http_hdr.get_buffer_size()); + if( ret!=(int)http_hdr.get_buffer_size() ) { MSG_ERR("Error while sending HTTP request: didn't sent all the request\n"); goto err_out; } - delete http_hdr; + delete &http_hdr; return MPXP_Ok; err_out: - delete http_hdr; + delete &http_hdr; if (proxy && server_url) url_free(server_url); return MPXP_False; @@ -272,7 +272,7 @@ int http_authenticate(HTTP_Header& http_hdr, URL_t *url, int *auth_retry) { - char *aut; + const char *aut; if( *auth_retry==1 ) { MSG_ERR(MSGTR_ConnAuthFailed); @@ -291,7 +291,7 @@ aut = http_hdr.get_field("WWW-Authenticate"); if( aut!=NULL ) { - char *aut_space; + const char *aut_space; aut_space = strstr(aut, "realm="); if( aut_space!=NULL ) aut_space += 6; MSG_INFO("Authentication required for %s\n", aut_space); @@ -331,20 +331,20 @@ if( http_hdr==NULL ) return 0; - switch( http_hdr->status_code ) { + switch( http_hdr->get_status() ) { case 200: case 206: // OK MSG_V("Content-Type: [%s]\n", http_hdr->get_field("Content-Type") ); MSG_V("Content-Length: [%s]\n", http_hdr->get_field("Content-Length") ); - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { + if( http_hdr->get_body_size()>0 ) { + if( networking_bufferize( networking, (unsigned char *)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { delete http_hdr; return 0; } } break; default: - MSG_ERR("Server return %d: %s\n", http_hdr->status_code, http_hdr->get_reason_phrase()); + MSG_ERR("Server return %d: %s\n", http_hdr->get_status(), http_hdr->get_reason_phrase()); tcp.close(); } @@ -364,9 +364,9 @@ int redirect; int auth_retry=0; MPXP_Rc seekable=MPXP_False; - char *extension; - char *content_type; - char *next_url; + const char *extension; + const char *content_type; + const char *next_url; URL_t *url = networking->url; @@ -403,16 +403,16 @@ networking->data = (any_t*)http_hdr; // Check if we can make partial content requests and thus seek in http-streams - if( http_hdr->status_code==200 ) { - char *accept_ranges; + if( http_hdr->get_status()==200 ) { + const char *accept_ranges; if( (accept_ranges = http_hdr->get_field("Accept-Ranges")) != NULL ) seekable = strncmp(accept_ranges,"bytes",5)==0?MPXP_Ok:MPXP_False; } - // Check if the response is an ICY status_code reason_phrase + // Check if the response is an ICY get_status() reason_phrase if( !strcasecmp(http_hdr->get_protocol(), "ICY") ) { - switch( http_hdr->status_code ) { + switch( http_hdr->get_status() ) { case 200: { // OK - char *field_data = NULL; + const char *field_data = NULL; // note: I skip icy-notice1 and 2, as they contain html <BR> // and are IMHO useless info ::atmos if( (field_data = http_hdr->get_field("icy-name")) != NULL ) @@ -449,7 +449,7 @@ } // Assume standard http if not ICY - switch( http_hdr->status_code ) { + switch( http_hdr->get_status() ) { case 200: // OK // Look if we can use the Content-Type content_type = http_hdr->get_field("Content-Type" ); @@ -477,7 +477,7 @@ networking->url = url = url_redirect( &url, next_url ); if (!strcasecmp(url->protocol, "mms")) goto err_out; if (strcasecmp(url->protocol, "http")) { - MSG_WARN("Unsupported http %d redirect to %s protocol\n", http_hdr->status_code, url->protocol); + MSG_WARN("Unsupported http %d redirect to %s protocol\n", http_hdr->get_status(), url->protocol); goto err_out; } redirect = 1; @@ -488,7 +488,7 @@ redirect = 1; break; default: - MSG_ERR("Server returned %d: %s\n", http_hdr->status_code, http_hdr->get_reason_phrase()); + MSG_ERR("Server returned %d: %s\n", http_hdr->get_status(), http_hdr->get_reason_phrase()); goto err_out; } } else { @@ -557,7 +557,7 @@ MPXP_Rc nop_networking_start(Tcp& tcp,networking_t* networking ) { HTTP_Header *http_hdr = NULL; - char *next_url=NULL; + const char *next_url=NULL; URL_t *rd_url=NULL; MPXP_Rc ret; @@ -567,12 +567,12 @@ http_hdr = http_read_response(tcp); if( http_hdr==NULL ) return MPXP_False; - switch( http_hdr->status_code ) { + switch( http_hdr->get_status() ) { case 200: // OK MSG_V("Content-Type: [%s]\n", http_hdr->get_field("Content-Type") ); MSG_V("Content-Length: [%s]\n", http_hdr->get_field("Content-Length") ); - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { + if( http_hdr->get_body_size()>0 ) { + if( networking_bufferize( networking, (unsigned char *)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { delete http_hdr; return MPXP_False; } @@ -602,15 +602,15 @@ case 404: //Not found case 500: //Server Error default: - MSG_ERR("Server return %d: %s\n", http_hdr->status_code, http_hdr->get_reason_phrase()); + MSG_ERR("Server return %d: %s\n", http_hdr->get_status(), http_hdr->get_reason_phrase()); tcp.close(); return MPXP_False; break; } } else { http_hdr = (HTTP_Header*)networking->data; - if( http_hdr->body_size>0 ) { - if( networking_bufferize( networking, http_hdr->body, http_hdr->body_size )<0 ) { + if( http_hdr->get_body_size()>0 ) { + if( networking_bufferize( networking, (unsigned char*)http_hdr->get_body(), http_hdr->get_body_size() )<0 ) { delete http_hdr; networking->data = NULL; return MPXP_False; Modified: mplayerxp/libmpstream/tcp.cpp =================================================================== --- mplayerxp/libmpstream/tcp.cpp 2012-12-10 17:44:11 UTC (rev 535) +++ mplayerxp/libmpstream/tcp.cpp 2012-12-11 11:31:23 UTC (rev 536) @@ -72,6 +72,7 @@ struct timeval to; #endif + buf[0]=0; MSG_V("[tcp%s] Trying to resolv host '%s'\n", af2String(af), host.c_str()); _fd = ::socket(af==Tcp::IP4?AF_INET:AF_INET6, SOCK_STREAM, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |