[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[572] mplayerxp/libmpstream2
Brought to you by:
olov
From: <nic...@us...> - 2012-12-18 13:04:39
|
Revision: 572 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=572&view=rev Author: nickols_k Date: 2012-12-18 13:04:29 +0000 (Tue, 18 Dec 2012) Log Message: ----------- make class URL full-featured and use references on it + constantization Modified Paths: -------------- mplayerxp/libmpstream2/cddb.cpp mplayerxp/libmpstream2/http.cpp mplayerxp/libmpstream2/http.h mplayerxp/libmpstream2/librtsp/rtsp.cpp mplayerxp/libmpstream2/librtsp/rtsp.h mplayerxp/libmpstream2/librtsp/rtsp_session.cpp mplayerxp/libmpstream2/librtsp/rtsp_session.h mplayerxp/libmpstream2/network.cpp mplayerxp/libmpstream2/network.h mplayerxp/libmpstream2/network_asf.cpp mplayerxp/libmpstream2/network_asf_mmst.cpp mplayerxp/libmpstream2/network_nop.cpp mplayerxp/libmpstream2/network_pnm.cpp mplayerxp/libmpstream2/network_real_rtsp.cpp mplayerxp/libmpstream2/network_rtsp.cpp mplayerxp/libmpstream2/network_rtsp.h mplayerxp/libmpstream2/realrtsp/real.cpp mplayerxp/libmpstream2/realrtsp/real.h mplayerxp/libmpstream2/s_ftp.cpp mplayerxp/libmpstream2/s_network.cpp mplayerxp/libmpstream2/s_rtsp.cpp mplayerxp/libmpstream2/s_udp.cpp mplayerxp/libmpstream2/tcp.cpp mplayerxp/libmpstream2/tcp.h mplayerxp/libmpstream2/udp.cpp mplayerxp/libmpstream2/udp.h mplayerxp/libmpstream2/url.cpp mplayerxp/libmpstream2/url.h Modified: mplayerxp/libmpstream2/cddb.cpp =================================================================== --- mplayerxp/libmpstream2/cddb.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/cddb.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -145,16 +145,15 @@ char request[4096]; int ret = 0; Tcp tcp(cddb_data->libinput,-1); - URL *url; + URL& url=*new(zeromem) URL(""); if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; sprintf( request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello.c_str(), cddb_data->freedb_proto_level ); MSG_V("Request[%s]\n", request ); - url = url_new(request); - if( url==NULL ) { - MSG_ERR("Not a valid URL\n"); + if(url.redirect(request)!=MPXP_Ok) { + MSG_ERR("Not valid URL: '%s'\n",request); return -1; } @@ -183,7 +182,7 @@ } delete http_hdr; - delete url; + delete &url; return ret; } Modified: mplayerxp/libmpstream2/http.cpp =================================================================== --- mplayerxp/libmpstream2/http.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/http.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -302,54 +302,32 @@ MSG_V("--- HTTP DEBUG HEADER --- END ---\n"); } -int HTTP_Header::authenticate(URL *url, int *auth_retry) { +int HTTP_Header::authenticate(URL& url, int *auth_retry) { const char *aut; - if( *auth_retry==1 ) { - MSG_ERR(MSGTR_ConnAuthFailed); - return -1; - } - if( *auth_retry>0 ) { - if( url->username ) { - delete url->username ; - url->username = NULL; - } - if( url->password ) { - delete url->password ; - url->password = NULL; - } - } + if( *auth_retry==1 ) { + MSG_ERR(MSGTR_ConnAuthFailed); + return -1; + } + if( *auth_retry>0 ) url.clear_login(); - aut = get_field("WWW-Authenticate"); - if( aut!=NULL ) { - 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); - } else { - MSG_INFO("Authentication required\n"); - } - if( net_conf.username ) { - url->username = mp_strdup(net_conf.username); - if( url->username==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return -1; - } - } else { - MSG_ERR(MSGTR_ConnAuthFailed); - return -1; - } - if( net_conf.password ) { - url->password = mp_strdup(net_conf.password); - if( url->password==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return -1; - } - } else { - MSG_INFO("No password provided, trying blank password\n"); - } - (*auth_retry)++; - return 0; + aut = get_field("WWW-Authenticate"); + if( aut!=NULL ) { + 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); + } else { + MSG_INFO("Authentication required\n"); + } + if( !net_conf.username ) { + MSG_ERR(MSGTR_ConnAuthFailed); + return -1; + } + if( !net_conf.password ) MSG_INFO("No password provided, trying blank password\n"); + url.set_login(net_conf.username,net_conf.password?net_conf.password:""); + (*auth_retry)++; + return 0; } Modified: mplayerxp/libmpstream2/http.h =================================================================== --- mplayerxp/libmpstream2/http.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/http.h 2012-12-18 13:04:29 UTC (rev 572) @@ -30,7 +30,7 @@ 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 int authenticate(URL *url, int *auth_retry); + virtual int authenticate(URL& url, int *auth_retry); virtual void debug_hdr(); virtual void cookies_set(const std::string& hostname, const std::string& url); Modified: mplayerxp/libmpstream2/librtsp/rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -70,24 +70,24 @@ struct rtsp_t { - Tcp* tcp; + Tcp* tcp; - char *host; - int port; - char *path; - char *param; - char *mrl; - char *user_agent; + const char* host; + int port; + const char* path; + const char* param; + char* mrl; + const char* user_agent; - char *server; - unsigned int server_state; - uint32_t server_caps; + const char* server; + unsigned server_state; + uint32_t server_caps; - unsigned int cseq; - char *session; + unsigned cseq; + const char* session; - char *answers[MAX_FIELDS]; /* data of last message */ - char *scheduled[MAX_FIELDS]; /* will be sent with next message */ + char* answers[MAX_FIELDS]; /* data of last message */ + char* scheduled[MAX_FIELDS]; /* will be sent with next message */ }; /* @@ -558,7 +558,7 @@ */ //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) { -rtsp_t *rtsp_connect(Tcp& tcp, char* mrl, char *path, char *host, int port, char *user_agent) { +rtsp_t *rtsp_connect(Tcp& tcp, char* mrl,const char *path,const char *host, int port,const char *user_agent) { rtsp_t *s=new rtsp_t; int i; @@ -676,7 +676,7 @@ } -char *rtsp_get_session(rtsp_t *s) { +const char *rtsp_get_session(rtsp_t *s) { return s->session; @@ -688,9 +688,9 @@ } -char *rtsp_get_param(rtsp_t *s, const char *p) { +char *rtsp_get_param(rtsp_t *s,const char *p) { int len; - char *param; + const char *param; if (!s->param) return NULL; if (!p) @@ -698,14 +698,14 @@ len = strlen(p); param = s->param; while (param && *param) { - char *nparam = strchr(param, '&'); + const char *nparam = strchr(param, '&'); if (strncmp(param, p, len) == 0 && param[len] == '=') { param += len + 1; len = nparam ? nparam - param : strlen(param); - nparam = new char [len + 1]; - memcpy(nparam, param, len); - nparam[len] = 0; - return nparam; + char* _nparam = new char [len + 1]; + memcpy(_nparam, param, len); + _nparam[len] = 0; + return _nparam; } param = nparam ? nparam + 1 : NULL; } Modified: mplayerxp/libmpstream2/librtsp/rtsp.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp.h 2012-12-18 13:04:29 UTC (rev 572) @@ -47,7 +47,7 @@ struct rtsp_t; -rtsp_t* rtsp_connect (Tcp& tcp, char *mrl, char *path, char *host, int port, char *user_agent); +rtsp_t* rtsp_connect (Tcp& tcp, char *mrl, const char *path, const char *host, int port, const char *user_agent); int rtsp_request_options(rtsp_t *s, const char *what); int rtsp_request_describe(rtsp_t *s, const char *what); @@ -69,10 +69,10 @@ void rtsp_close (rtsp_t *self); void rtsp_set_session(rtsp_t *s, const char *id); -char *rtsp_get_session(rtsp_t *s); +const char *rtsp_get_session(rtsp_t *s); char *rtsp_get_mrl(rtsp_t *s); -char *rtsp_get_param(rtsp_t *s, const char *param); +char *rtsp_get_param(rtsp_t *s,const char *param); /*int rtsp_peek_header (rtsp_t *self, char *data); */ Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.cpp =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -73,8 +73,10 @@ #define RTSP_SERVER_TYPE_UNKNOWN "unknown" //Rtsp_Session *rtsp_session_start(char *mrl) { -Rtsp_Session *rtsp_session_start(Tcp& tcp, char **mrl, char *path, char *host, - int port, int *redir, uint32_t bandwidth, char *user, char *pass) { +Rtsp_Session *rtsp_session_start(Tcp& tcp, char **mrl, const std::string& path, + const std::string& host, + int port, int *redir, uint32_t bandwidth, + const std::string& user, const std::string& pass) { Rtsp_Session *rtsp_session = NULL; char *server; @@ -90,10 +92,10 @@ *redir = 0; /* connect to server */ - rtsp_session->s=rtsp_connect(tcp,*mrl,path,host,port,NULL); + rtsp_session->s=rtsp_connect(tcp,*mrl,path.c_str(),host.c_str(),port,NULL); if (!rtsp_session->s) { - MSG_ERR("rtsp_session: failed to connect to server %s\n", path); + MSG_ERR("rtsp_session: failed to connect to server %s\n", path.c_str()); delete rtsp_session; return NULL; } @@ -111,7 +113,7 @@ { /* we are talking to a real server ... */ - h=real_setup_and_get_header(rtsp_session->s, bandwidth, user, pass); + h=real_setup_and_get_header(rtsp_session->s, bandwidth, user.c_str(), pass.c_str()); if (!h) { /* got an redirect? */ if (rtsp_search_answers(rtsp_session->s, RTSP_OPTIONS_LOCATION)) Modified: mplayerxp/libmpstream2/librtsp/rtsp_session.h =================================================================== --- mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/librtsp/rtsp_session.h 2012-12-18 13:04:29 UTC (rev 572) @@ -51,7 +51,7 @@ rtp_rtsp_session_t* rtp_session; }; - Rtsp_Session* rtsp_session_start(Tcp& tcp, char **mrl, char *path, char *host, - int port, int *redir, uint32_t bandwidth, char *user, char *pass); + Rtsp_Session* rtsp_session_start(Tcp& tcp, char **mrl, const std::string& path, const std::string& host, + int port, int *redir, uint32_t bandwidth, const std::string& user, const std::string& pass); } // namespace mpxp #endif Modified: mplayerxp/libmpstream2/network.cpp =================================================================== --- mplayerxp/libmpstream2/network.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -62,131 +62,72 @@ net_config_t::~net_config_t() {} net_config_t net_conf; -URL* -check4proxies( URL *url ) { - URL *url_out = NULL; - if( url==NULL ) return NULL; - url_out = url_new( url->url ); - if( !strcasecmp(url->protocol, "http_proxy") ) { - MSG_V("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); - return url_out; - } - // Check if the http_proxy environment variable is set. - if( !strcasecmp(url->protocol, "http") ) { - char *proxy; - proxy = getenv("http_proxy"); - if( proxy!=NULL ) { - // We got a proxy, build the URL to use it - int len; - char *new_url; - URL *tmp_url; - URL *proxy_url = url_new( proxy ); +MPXP_Rc http_send_request(Tcp& tcp, URL& url, off_t pos ) { + HTTP_Header& http_hdr = *new(zeromem) HTTP_Header; + URL server_url(""); + char str[256]; + int ret; + int proxy = 0; // Boolean - if( proxy_url==NULL ) { - MSG_WARN("Invalid proxy setting...Trying without proxy.\n"); - return url_out; - } - -#ifdef HAVE_AF_INET6 - if (net_conf.ipv4_only_proxy && (gethostbyname(url->hostname)==NULL)) { - MSG_WARN( - "Could not find resolve remote hostname for AF_INET. Trying without proxy.\n"); - return url_out; - } -#endif - - MSG_V("Using HTTP proxy: %s\n", proxy_url->url ); - len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20; // 20 = http_proxy:// + port - new_url = new char [len+1]; - if( new_url==NULL ) { - MSG_FATAL(MSGTR_OutOfMemory); - return url_out; - } - sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url ); - tmp_url = url_new( new_url ); - if( tmp_url==NULL ) { - return url_out; - } - delete url_out; - url_out = tmp_url; - delete new_url ; - delete proxy_url; - } - } - return url_out; -} - -MPXP_Rc http_send_request(Tcp& tcp, URL *url, off_t pos ) { - HTTP_Header& http_hdr = *new(zeromem) HTTP_Header; - URL *server_url; - char str[256]; - int ret; - int proxy = 0; // Boolean - - if( !strcasecmp(url->protocol, "http_proxy") ) { - proxy = 1; - server_url = url_new( (url->file)+1 ); - http_hdr.set_uri(server_url->url ); - } else { - server_url = url; - 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 ); + if( url.protocol2lower()=="http_proxy") { + proxy = 1; + server_url.redirect(url.file()); + http_hdr.set_uri(server_url.url()); + } else { + server_url = url; + http_hdr.set_uri( server_url.file()); + } + if (server_url.port() && server_url.port() != 80) + snprintf(str, 256, "Host: %s:%d", server_url.host().c_str(), server_url.port()); + else + snprintf(str, 256, "Host: %s", server_url.host().c_str()); + http_hdr.set_field(str); + if (net_conf.useragent) { + snprintf(str, 256, "User-Agent: %s", net_conf.useragent); http_hdr.set_field(str); - if (net_conf.useragent) - { - snprintf(str, 256, "User-Agent: %s", net_conf.useragent); - http_hdr.set_field(str); - } - else - http_hdr.set_field("User-Agent: MPlayerXP/"VERSION); + } + else + 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) { + 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); - } + snprintf(str, 256, "Range: bytes=%d-", (int)pos); + 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.host(), server_url.url()); - http_hdr.set_field( "Connection: closed"); - http_hdr.add_basic_authentication( url->username?url->username:"", url->password?url->password:""); - if( http_hdr.build_request( )==NULL ) { - goto err_out; - } + http_hdr.set_field( "Connection: closed"); + http_hdr.add_basic_authentication( url.user(), url.password()); + if( http_hdr.build_request( )==NULL ) { + goto err_out; + } - if( proxy ) { - if( url->port==0 ) url->port = 8080; // Default port for the proxy server - tcp.close(); - tcp.open(url->hostname, url->port, Tcp::IP4); - delete server_url; - server_url = NULL; - } else { - if( server_url->port==0 ) server_url->port = 80; // Default port for the web server - tcp.close(); - tcp.open(server_url->hostname, server_url->port, Tcp::IP4); - } - if(!tcp.established()) { MSG_ERR("Cannot establish connection\n"); goto err_out; } - MSG_DBG2("Request: [%s]\n", http_hdr.get_buffer() ); + if( proxy ) { + tcp.close(); + url.assign_port(8080); + tcp.open(url, Tcp::IP4); + } else { + tcp.close(); + server_url.assign_port(80); + tcp.open(server_url, Tcp::IP4); + } + 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.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; - } + 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; - - return MPXP_Ok; + delete &http_hdr; + return MPXP_Ok; err_out: - delete &http_hdr; - if (proxy && server_url) delete server_url; - return MPXP_False; + delete &http_hdr; + return MPXP_False; } HTTP_Header* http_read_response( Tcp& tcp ) { @@ -247,10 +188,10 @@ } Networking::Networking() - :mime("application/octet-stream") {} + :mime("application/octet-stream"), + url("") {} Networking::~Networking() { - if( url ) delete url; if( buffer ) delete buffer; if( data ) delete data; } @@ -266,7 +207,7 @@ const char *content_type; const char *next_url; - URL *url = networking.url; + URL& url = networking.url; do { next_url = NULL; @@ -274,16 +215,12 @@ content_type = NULL; redirect = 0; - if( url==NULL ) { - goto err_out; - } - #ifndef STREAMING_LIVE_DOT_COM // Old, hacked RTP support, which works for MPEG Program Streams // RTP streams only: // Checking for RTP - if( !strcasecmp(url->protocol, "rtp") ) { - if( url->port==0 ) { + if( url.protocol2lower()=="rtp") { + if( url.port()==0 ) { MSG_ERR("You must enter a port number for RTP streams!\n"); goto err_out; } @@ -291,7 +228,7 @@ } #endif // HTTP based protocol - if( !strcasecmp(url->protocol, "http") || !strcasecmp(url->protocol, "http_proxy") ) { + if( url.protocol2lower()=="http" || url.protocol2lower()=="http_proxy") { http_send_request(tcp, url, 0 ); if(!tcp.established()) goto err_out; @@ -366,10 +303,10 @@ // TODO: RFC 2616, recommand to detect infinite redirection loops next_url = http_hdr->get_field("Location" ); if( next_url!=NULL ) { - 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->get_status(), url->protocol); + url.redirect(next_url); + if (url.protocol2lower()=="mms") goto err_out; + if (url.protocol2lower()=="http") { + MSG_WARN("Unsupported http %d redirect to %s protocol\n", http_hdr->get_status(), url.protocol().c_str()); goto err_out; } redirect = 1; @@ -384,7 +321,7 @@ goto err_out; } } else { - MSG_ERR("Unknown protocol '%s'\n", url->protocol ); + MSG_ERR("Unknown protocol '%s'\n", url.protocol().c_str()); goto err_out; } } while( redirect ); @@ -418,29 +355,28 @@ } } -Networking* Networking::start(Tcp& tcp, URL *_url) { +Networking* Networking::start(Tcp& tcp, const URL& _url) { Networking* rc; network_protocol_t net_protocol; - URL* url = check4proxies( _url ); + net_protocol.url=_url; + net_protocol.url.check4proxies(); - net_protocol.url=url; - if( autodetectProtocol(net_protocol,tcp)!=MPXP_Ok ) return NULL; rc = NULL; - url=net_protocol.url; + URL url=net_protocol.url; // For RTP streams, we usually don't know the stream type until we open it. - if( !strcasecmp( url->protocol, "rtp")) { + if( url.protocol2lower()=="rtp") { if(tcp.established()) tcp.close(); rc = Rtp_Networking::start(tcp, net_protocol, 0); - } else if( !strcasecmp( url->protocol, "pnm")) { + } else if( url.protocol2lower()=="pnm") { tcp.close(); rc = Pnm_Networking::start(tcp, net_protocol); if (!rc) { MSG_INFO("Can't connect with pnm, retrying with http.\n"); return NULL; } - } else if( !strcasecmp( url->protocol, "rtsp")) { + } else if( url.protocol2lower()=="rtsp") { if ((rc = RealRtsp_Networking::start( tcp, net_protocol )) == NULL) { MSG_INFO("Not a Realmedia rtsp url. Trying standard rtsp protocol.\n"); #ifdef STREAMING_LIVE_DOT_COM @@ -452,16 +388,16 @@ return NULL; #endif } - } else if(!strcasecmp( url->protocol, "udp")) { + } else if(url.protocol2lower()=="udp") { tcp.close(); rc = Rtp_Networking::start(tcp, net_protocol, 1); if(!rc) { MSG_ERR("rtp_networking_start(udp) failed\n"); return NULL; } - } else if(!strncasecmp(url->protocol, "mms", 3) || - !strncasecmp(url->protocol, "mmst", 4) || - !strncasecmp(url->protocol, "mmsu", 4)) { + } else if(url.protocol2lower()=="mms" || + url.protocol2lower()=="mmst" || + url.protocol2lower()=="mmsu") { rc=Asf_Mmst_Networking::start(tcp,net_protocol); if(!rc) { MSG_ERR("asf_mmst_networking_start() failed\n"); @@ -477,7 +413,7 @@ if( !rc ) { //sometimes a file is just on a webserver and it is not streamed. //try loading them default method as last resort for http protocol - if ( !strcasecmp(url->protocol, "http") ) { + if (url.protocol2lower()=="http") { MSG_STATUS("Trying default networking for http protocol\n "); //reset stream tcp.close(); Modified: mplayerxp/libmpstream2/network.h =================================================================== --- mplayerxp/libmpstream2/network.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network.h 2012-12-18 13:04:29 UTC (rev 572) @@ -57,16 +57,16 @@ }; struct network_protocol_t { - URL* url; - Opaque* data; + URL url; std::string mime; + Opaque* data; }; struct Networking : public Opaque { public: virtual ~Networking(); - static Networking* start(Tcp& tcp, URL *url); + static Networking* start(Tcp& tcp,const URL& url); virtual int stop(); virtual void fixup_cache(); virtual int bufferize(unsigned char *buffer, int size); @@ -75,7 +75,7 @@ virtual int seek( Tcp& fd, off_t pos) = 0; std::string mime; - URL* url; + URL url; networking_status status; unsigned int bandwidth; // The downstream available protected: @@ -90,9 +90,7 @@ static MPXP_Rc autodetectProtocol(network_protocol_t& protocol,Tcp& tcp); }; - extern URL* check4proxies( URL* url ); - - MPXP_Rc http_send_request(Tcp& tcp,URL* url, off_t pos); + MPXP_Rc http_send_request(Tcp& tcp,URL& url, off_t pos); HTTP_Header* http_read_response(Tcp& fd); /* Modified: mplayerxp/libmpstream2/network_asf.cpp =================================================================== --- mplayerxp/libmpstream2/network_asf.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_asf.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -1,6 +1,7 @@ #include "mp_config.h" #include "osdep/mplib.h" using namespace mpxp; +#include <algorithm> #include <limits> #include <stdio.h> @@ -152,7 +153,7 @@ return MPXP_False; } // audit: do not overflow buffer_size - if (size > std::numeric_limits<size_t>::max() - _buffer_size) return MPXP_False; + if (unsigned(size) > std::numeric_limits<size_t>::max() - _buffer_size) return MPXP_False; _buffer = (char*) mp_malloc(size+_buffer_size); if(_buffer == NULL) { MSG_FATAL("Error can't allocate %d bytes buffer\n",size+_buffer_size); @@ -436,219 +437,201 @@ static ASF_StreamType_e 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 - !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request - !strcasecmp(content_type, "video/x-ms-asf")) { + 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 + !strcasecmp(content_type, "application/x-mms-framed") || // New in Corana, second request + !strcasecmp(content_type, "video/x-ms-asf")) { - if( strstr(features, "broadcast") ) { - MSG_V("=====> ASF Live stream\n"); - return ASF_Live_e; - } else { - MSG_V("=====> ASF Prerecorded\n"); - return ASF_Prerecorded_e; - } + if( strstr(features, "broadcast") ) { + MSG_V("=====> ASF Live stream\n"); + return ASF_Live_e; } else { - // Ok in a perfect world, web servers should be well configured - // 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.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; - } else if( (!strcasecmp(content_type, "text/html")) ) { - MSG_V("=====> HTML, mplayer is not a browser...yet!\n"); - return ASF_Unknown_e; - } else { - MSG_V("=====> ASF Redirector\n"); - return ASF_Redirector_e; - } - } else { - if( (!strcasecmp(content_type, "audio/x-ms-wax")) || - (!strcasecmp(content_type, "audio/x-ms-wma")) || - (!strcasecmp(content_type, "video/x-ms-asf")) || - (!strcasecmp(content_type, "video/x-ms-afs")) || - (!strcasecmp(content_type, "video/x-ms-wvx")) || - (!strcasecmp(content_type, "video/x-ms-wmv")) || - (!strcasecmp(content_type, "video/x-ms-wma")) ) { - MSG_ERR("=====> ASF Redirector\n"); - return ASF_Redirector_e; - } else if( !strcasecmp(content_type, "text/plain") ) { - MSG_V("=====> ASF Plain text\n"); - return ASF_PlainText_e; - } else { - MSG_V("=====> ASF unknown content-type: %s\n", content_type ); - return ASF_Unknown_e; - } - } + MSG_V("=====> ASF Prerecorded\n"); + return ASF_Prerecorded_e; } - return ASF_Unknown_e; + } else { + // Ok in a perfect world, web servers should be well configured + // 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.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; + } else if( (!strcasecmp(content_type, "text/html")) ) { + MSG_V("=====> HTML, mplayer is not a browser...yet!\n"); + return ASF_Unknown_e; + } else { + MSG_V("=====> ASF Redirector\n"); + return ASF_Redirector_e; + } + } else { + if((!strcasecmp(content_type, "audio/x-ms-wax")) || + (!strcasecmp(content_type, "audio/x-ms-wma")) || + (!strcasecmp(content_type, "video/x-ms-asf")) || + (!strcasecmp(content_type, "video/x-ms-afs")) || + (!strcasecmp(content_type, "video/x-ms-wvx")) || + (!strcasecmp(content_type, "video/x-ms-wmv")) || + (!strcasecmp(content_type, "video/x-ms-wma")) ) { + MSG_ERR("=====> ASF Redirector\n"); + return ASF_Redirector_e; + } else if( !strcasecmp(content_type, "text/plain") ) { + MSG_V("=====> ASF Plain text\n"); + return ASF_PlainText_e; + } else { + MSG_V("=====> ASF unknown content-type: %s\n", content_type ); + return ASF_Unknown_e; + } + } + } + return ASF_Unknown_e; } HTTP_Header* Asf_Networking::http_request() const { - HTTP_Header* http_hdr = new(zeromem) HTTP_Header; + HTTP_Header* http_hdr = new(zeromem) HTTP_Header; // URL *url = NULL; - URL *server_url = NULL; - char str[250]; - char *ptr; - int i, enable; + URL server_url; + char str[250]; + char *ptr; + int i, enable; - int offset_hi=0, offset_lo=0, length=0; - int asf_nb_stream=0, stream_id; + int offset_hi=0, offset_lo=0, length=0; + int asf_nb_stream=0, stream_id; - // Sanity check - if( url==NULL ) return NULL; + // 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.user(), url.password()); - // 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->username:"", url->password?url->password:"" ); + // Check if we are using a proxy + if( url.protocol2lower()=="http_proxy") { + server_url.redirect(url.file()); + http_hdr->set_uri(server_url.url()); + sprintf( str, "Host: %.220s:%d", server_url.host().c_str(), server_url.port()); + } else { + http_hdr->set_uri(url.file()); + sprintf( str, "Host: %.220s:%d", url.host().c_str(), url.port()); + } - // Check if we are using a proxy - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - server_url = url_new( (url->file)+1 ); - if( server_url==NULL ) { - MSG_ERR("Invalid proxy URL\n"); - delete http_hdr; - return NULL; - } - http_hdr->set_uri(server_url->url ); - sprintf( str, "Host: %.220s:%d", server_url->hostname, server_url->port ); - delete server_url; - } else { - http_hdr->set_uri(url->file ); - sprintf( str, "Host: %.220s:%d", url->hostname, url->port ); - } - - http_hdr->set_field(str ); - http_hdr->set_field("Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); - sprintf(str, - "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", + http_hdr->set_field(str ); + http_hdr->set_field("Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); + sprintf(str,"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", offset_hi, offset_lo, request, length ); - http_hdr->set_field( str ); + http_hdr->set_field( str ); - switch( networking_type ) { - case ASF_Live_e: - case ASF_Prerecorded_e: - http_hdr->set_field("Pragma: xPlayStrm=1" ); - ptr = str; - ptr += sprintf( ptr, "Pragma: stream-switch-entry="); - if(n_audio > 0) { - for( i=0; i<n_audio ; i++ ) { - stream_id = audio_streams[i]; - if(stream_id == audio_id) { - enable = 0; - } else { - enable = 2; - continue; - } - asf_nb_stream++; - ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); - } - } - if(n_video > 0) { - for( i=0; i<n_video ; i++ ) { - stream_id = video_streams[i]; - if(stream_id == video_id) { - enable = 0; - } else { - enable = 2; - continue; - } - asf_nb_stream++; - ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); - } - } - http_hdr->set_field(str ); - sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); - http_hdr->set_field( str ); - break; - case ASF_Redirector_e: - break; - case ASF_Unknown_e: - // First request goes here. - break; - default: - MSG_ERR("Unknown asf stream type\n"); - } + switch( networking_type ) { + case ASF_Live_e: + case ASF_Prerecorded_e: + http_hdr->set_field("Pragma: xPlayStrm=1" ); + ptr = str; + ptr += sprintf( ptr, "Pragma: stream-switch-entry="); + if(n_audio > 0) { + for( i=0; i<n_audio ; i++ ) { + stream_id = audio_streams[i]; + if(stream_id == audio_id) enable = 0; + else { + enable = 2; + continue; + } + asf_nb_stream++; + ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); + } + } + if(n_video > 0) { + for( i=0; i<n_video ; i++ ) { + stream_id = video_streams[i]; + if(stream_id == video_id) enable = 0; + else { + enable = 2; + continue; + } + asf_nb_stream++; + ptr += sprintf(ptr, "ffff:%d:%d ", stream_id, enable); + } + } + http_hdr->set_field(str ); + sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); + http_hdr->set_field( str ); + break; + case ASF_Redirector_e: break; + case ASF_Unknown_e: // First request goes here. + break; + default: + MSG_ERR("Unknown asf stream type\n"); + } - http_hdr->set_field("Connection: Close" ); - http_hdr->build_request( ); + http_hdr->set_field("Connection: Close" ); + http_hdr->build_request( ); - return http_hdr; + return http_hdr; } int Asf_Networking::parse_response(HTTP_Header& http_hdr ) { - 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.get_status()) { - case 200: - break; - case 401: // Authentication required - return ASF_Authenticate_e; - default: - MSG_ERR("Server return %d:%s\n", http_hdr.get_status(), http_hdr.get_reason_phrase()); - return -1; - } + 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.get_status()) { + case 200: + break; + case 401: // Authentication required + return ASF_Authenticate_e; + default: + MSG_ERR("Server return %d:%s\n", http_hdr.get_status(), http_hdr.get_reason_phrase()); + return -1; + } - content_type = http_hdr.get_field("Content-Type"); + content_type = http_hdr.get_field("Content-Type"); - pragma = http_hdr.get_field("Pragma"); - while( pragma!=NULL ) { - const char *comma_ptr=NULL; - const char *end; - // The pragma line can get severals attributes - // separeted with a comma ','. - do { - if( !strncasecmp( pragma, "features=", 9) ) { - pragma += 9; - end = strstr( pragma, "," ); - if( end==NULL ) { - size_t s = strlen(pragma); - if(s > sizeof(features)) { - MSG_WARN("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); - len = sizeof(features); - } else { - len = s; - } - } else { - len = MIN((unsigned int)(end-pragma),sizeof(features)); - } - strncpy( features, pragma, len ); - features[len]='\0'; - break; - } - comma_ptr = strstr( pragma, "," ); - if( comma_ptr!=NULL ) { - pragma = comma_ptr+1; - if( pragma[0]==' ' ) pragma++; - } - } while( comma_ptr!=NULL ); - pragma = http_hdr.get_next_field(); - } - networking_type = asf_http_networking_type( content_type, features, http_hdr ); - return 0; + pragma = http_hdr.get_field("Pragma"); + while( pragma!=NULL ) { + const char *comma_ptr=NULL; + const char *end; + // The pragma line can get severals attributes + // separeted with a comma ','. + do { + if( !strncasecmp( pragma, "features=", 9) ) { + pragma += 9; + end = strstr( pragma, "," ); + if( end==NULL ) { + size_t s = strlen(pragma); + if(s > sizeof(features)) { + MSG_WARN("ASF HTTP PARSE WARNING : Pragma %s cuted from %d bytes to %d\n",pragma,s,sizeof(features)); + len = sizeof(features); + } else len = s; + } else len = std::min((unsigned long)(end-pragma),sizeof(features)); + strncpy( features, pragma, len ); + features[len]='\0'; + break; + } + comma_ptr = strstr( pragma, "," ); + if( comma_ptr!=NULL ) { + pragma = comma_ptr+1; + if( pragma[0]==' ' ) pragma++; + } + } while( comma_ptr!=NULL ); + pragma = http_hdr.get_next_field(); + } + networking_type = asf_http_networking_type( content_type, features, http_hdr ); + return 0; } Networking* Asf_Networking::start(Tcp& tcp, network_protocol_t& protocol) { HTTP_Header *http_hdr=NULL; - URL *url = protocol.url; + URL& url = protocol.url; uint8_t buffer[BUFFER_SIZE]; int i, ret; int done; int auth_retry = 0; - const char *proto = protocol.url->protocol; + const char *proto = protocol.url.protocol().c_str(); // sanity check - if (!(!strncasecmp(proto, "http_proxy", 10) || - !strncasecmp(proto, "http", 4))) { + if (!(protocol.url.protocol2lower()=="http_proxy" || + protocol.url.protocol2lower()=="http")) { MSG_ERR("Unknown protocol: %s\n", proto ); return NULL; } @@ -668,12 +651,9 @@ done = 1; tcp.close(); - if( !strcasecmp( url->protocol, "http_proxy" ) ) { - if( url->port==0 ) url->port = 8080; - } else { - if( url->port==0 ) url->port = 80; - } - tcp.open(url->hostname, url->port, Tcp::IP4); + if( url.protocol2lower()=="http_proxy") url.assign_port(8080); + else url.assign_port(80); + tcp.open(url, Tcp::IP4); if( !tcp.established()) { delete rv; return NULL; @@ -778,7 +758,6 @@ return Nop_Networking::start(tcp,protocol); } else rv->buffering = 1; rv->status = networking_playing_e; - rv->url->port=protocol.url->port; delete http_hdr; return rv; Modified: mplayerxp/libmpstream2/network_asf_mmst.cpp =================================================================== --- mplayerxp/libmpstream2/network_asf_mmst.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_asf_mmst.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -362,7 +362,7 @@ int Asf_Mmst_Networking::get_media_packet (Tcp& tcp, int padding) { unsigned char pre_header[8]; - unsigned char data[BUF_SIZE]; + unsigned char _data[BUF_SIZE]; if (!get_data (tcp, pre_header, 8)) { MSG_ERR ("pre-header read failed\n"); @@ -386,12 +386,12 @@ return 0; } - if (!get_data (tcp, data, packet_len)) { + if (!get_data (tcp, _data, packet_len)) { MSG_ERR ("media data read failed\n"); return 0; } - bufferize(data, padding); + bufferize(_data, padding); } else { @@ -410,7 +410,7 @@ return 0; } - if (!get_data (tcp, data, packet_len)) { + if (!get_data (tcp, _data, packet_len)) { MSG_ERR ("command data read failed\n"); return 0; } @@ -422,12 +422,12 @@ return -1; } - command = get_32 (data, 24) & 0xFFFF; + command = get_32 (_data, 24) & 0xFFFF; // printf ("\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); if (command == 0x1b) - send_command (tcp, 0x1b, 0, 0, 0, data); + send_command (tcp, 0x1b, 0, 0, 0, _data); else if (command == 0x1e) { MSG_OK ("everything done. Thank you for downloading a media file containing proprietary and patentend technology.\n"); return 0; @@ -490,19 +490,20 @@ uint8_t asf_header[HDR_BUF_SIZE]; int asf_header_len; int len, i, packet_length; - char* path, *unescpath; - URL* url1 = protocol.url; - const char *proto = protocol.url->protocol; + const char* path; + char* unescpath; + URL url1 = protocol.url; // Is protocol even valid mms,mmsu,mmst,http,http_proxy? - if (!(!strncasecmp(proto, "mmst", 4) || !strncasecmp(proto, "mmsu", 4) || - !strncasecmp(proto, "mms", 3))) { - MSG_ERR("Unknown protocol: %s\n", proto ); + if (!(protocol.url.protocol2lower()=="mmst" || + protocol.url.protocol2lower()=="mmsu" || + protocol.url.protocol2lower()=="mms")) { + MSG_ERR("Unknown protocol: %s\n", protocol.url.protocol().c_str() ); return NULL; } // Is protocol mms or mmsu? - if (!strncasecmp(proto, "mmsu", 4) || !strncasecmp(proto, "mms", 3)) { + if (protocol.url.protocol2lower()=="mmsu" || protocol.url.protocol2lower()=="mms") { MSG_V("Trying ASF/UDP...\n"); //fd = asf_mmsu_networking_start( stream ); //mmsu support is not implemented yet - using this code @@ -513,7 +514,7 @@ tcp.close(); /* parse url */ - path = strchr(url1->file,'/') + 1; + path = strchr(url1.file().c_str(),'/') + 1; /* mmst filename are not url_escaped by MS MediaPlayer and are expected as * "plain text" by the server, so need to decode it here @@ -526,8 +527,8 @@ url2string(unescpath,path); path=unescpath; - if( url1->port==0 ) url1->port=1755; - tcp.open(url1->hostname, url1->port, Tcp::IP4); + url1.assign_port(1755); + tcp.open(url1, Tcp::IP4); if( !tcp.established()) { delete path; return NULL; @@ -551,7 +552,7 @@ #endif #endif - snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); + snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1.host().c_str()); string_utf16 (data, str, strlen(str)); // send_command(s, commandno ....) send_command (tcp, 1, 0, 0x0004000b, strlen(str) * 2+2, data); @@ -649,7 +650,6 @@ rv->buffering = 1; rv->status = networking_playing_e; - rv->url->port=protocol.url->port; packet_length1 = packet_length; MSG_V("mmst packet_length = %d\n",packet_length); Modified: mplayerxp/libmpstream2/network_nop.cpp =================================================================== --- mplayerxp/libmpstream2/network_nop.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_nop.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -50,7 +50,7 @@ Networking* Nop_Networking::start(Tcp& tcp,network_protocol_t& protocol) { HTTP_Header *http_hdr = NULL; const char *next_url=NULL; - URL *rd_url=NULL; + URL& rd_url=protocol.url; Nop_Networking* rv = new(zeromem) Nop_Networking; if( !tcp.established() ) { @@ -82,12 +82,9 @@ case 302: // Temporarily next_url = http_hdr->get_field("Location" ); - if (next_url != NULL) - rd_url=url_new(next_url); - - if (next_url != NULL && rd_url != NULL) { + if (next_url != NULL && rd_url.redirect(next_url)==MPXP_Ok) { MSG_STATUS("Redirected: Using this url instead %s\n",next_url); - protocol.url=check4proxies(rd_url); + rd_url.check4proxies(); delete rv; rv=static_cast<Nop_Networking*>(Nop_Networking::start(tcp,protocol)); //recursively get networking started } else { Modified: mplayerxp/libmpstream2/network_pnm.cpp =================================================================== --- mplayerxp/libmpstream2/network_pnm.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_pnm.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -22,11 +22,11 @@ Networking* Pnm_Networking::start(Tcp& tcp,network_protocol_t& protocol ) { Pnm* pnm = new(zeromem) Pnm(tcp); - tcp.open(protocol.url->hostname, - protocol.url->port ? protocol.url->port : 7070); + protocol.url.assign_port(7070); + tcp.open(protocol.url); if(!tcp.established()) return NULL; - if(pnm->connect(protocol.url->file)!=MPXP_Ok) { + if(pnm->connect(protocol.url.file())!=MPXP_Ok) { delete pnm; return NULL; } Modified: mplayerxp/libmpstream2/network_real_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_real_rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -21,33 +21,33 @@ Networking* RealRtsp_Networking::start( Tcp& tcp, network_protocol_t& protocol ) { Rtsp_Session* rtsp; char *mrl; - char *file; - int port; + const char *file; int redirected, temp; temp = 5; // counter so we don't get caught in infinite redirections (you never know) do { redirected = 0; - port = protocol.url->port ? protocol.url->port : 554; + protocol.url.assign_port(554); tcp.close(); - tcp.open( protocol.url->hostname, port, Tcp::IP4); - if(!tcp.established() && !protocol.url->port) - tcp.open( protocol.url->hostname,port = 7070, Tcp::IP4); + tcp.open( protocol.url, Tcp::IP4); + if(!tcp.established() && !protocol.url.port()) { + protocol.url.assign_port(7070); + tcp.open( protocol.url, Tcp::IP4); + } if(!tcp.established()) return NULL; - file = protocol.url->file; + file = protocol.url.file().c_str(); if (file[0] == '/') file++; - mrl = new char [strlen(protocol.url->hostname)+strlen(file)+16]; - sprintf(mrl,"rtsp://%s:%i/%s",protocol.url->hostname,port,file); + mrl = new char [protocol.url.host().length()+strlen(file)+16]; + sprintf(mrl,"rtsp://%s:%i/%s",protocol.url.host().c_str(),protocol.url.port(),file); rtsp = rtsp_session_start(tcp,&mrl, file, - protocol.url->hostname, port, &redirected, - net_conf.bandwidth,protocol.url->username, - protocol.url->password); + protocol.url.host(), protocol.url.port(), &redirected, + net_conf.bandwidth,protocol.url.user(), + protocol.url.password()); if ( redirected == 1 ) { - delete protocol.url; - protocol.url = url_new(mrl); + protocol.url.redirect(mrl); tcp.close(); } delete mrl; Modified: mplayerxp/libmpstream2/network_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -7,13 +7,11 @@ #include "librtsp/rtsp_session.h" namespace mpxp { -#define RTSP_DEFAULT_PORT 554 -Networking* Rtsp_Networking::start(Tcp& tcp, URL* url,unsigned bandwidth) +Networking* Rtsp_Networking::start(Tcp& tcp, URL& url,unsigned bandwidth) { Rtsp_Session *rtsp; char *mrl; - char *file; - int port; + const char *file; int redirected, temp; /* counter so we don't get caught in infinite redirections */ @@ -22,30 +20,28 @@ do { redirected = 0; - tcp.open(url->hostname, - port = (url->port ? - url->port : - RTSP_DEFAULT_PORT)); - if (!tcp.established() && !url->port) - tcp.open(url->hostname, - port = 7070); + url.assign_port(554); + tcp.open(url); + if (!tcp.established()) { + url.assign_port(7070); + tcp.open(url); + } if (!tcp.established()) return NULL; - file = url->file; + file = url.file().c_str(); if (file[0] == '/') file++; - mrl = new char [strlen (url->hostname) + strlen (file) + 16]; + mrl = new char [url.host().length() + strlen (file) + 16]; - sprintf (mrl, "rtsp://%s:%i/%s",url->hostname, port, file); + sprintf (mrl, "rtsp://%s:%i/%s",url.host().c_str(), url.port(), file); rtsp = rtsp_session_start (tcp, &mrl, file, - url->hostname, - port, &redirected, + url.host(), + url.port(), &redirected, bandwidth, - url->username, - url->password); + url.user(), + url.password()); if (redirected == 1) { - delete url; - url = url_new (mrl); + url.redirect(mrl); tcp.close(); } delete mrl; Modified: mplayerxp/libmpstream2/network_rtsp.h =================================================================== --- mplayerxp/libmpstream2/network_rtsp.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/network_rtsp.h 2012-12-18 13:04:29 UTC (rev 572) @@ -8,7 +8,7 @@ public: virtual ~Rtsp_Networking(); - static Networking* start(Tcp& tcp, URL* url,unsigned bandwidth); + static Networking* start(Tcp& tcp, URL& url,unsigned bandwidth); virtual int read( Tcp& fd, char *buffer, int buffer_size); virtual int seek( Tcp& fd, off_t pos); private: Modified: mplayerxp/libmpstream2/realrtsp/real.cpp =================================================================== --- mplayerxp/libmpstream2/realrtsp/real.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/realrtsp/real.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -428,7 +428,7 @@ //! maximum size of the rtsp description, must be < INT_MAX #define MAX_DESC_BUF (20 * 1024 * 1024) rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth, - char *username, char *password) { + const char *username, const char *password) { char *description=NULL; char *session_id=NULL; Modified: mplayerxp/libmpstream2/realrtsp/real.h =================================================================== --- mplayerxp/libmpstream2/realrtsp/real.h 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/realrtsp/real.h 2012-12-18 13:04:29 UTC (rev 572) @@ -53,7 +53,7 @@ int real_get_rdt_chunk(rtsp_t *rtsp_session, char **buffer, int rdt_rawdata); rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth, - char *username, char *password); + const char *username, const char *password); struct real_rtsp_session_t *init_real_rtsp_session (void); void free_real_rtsp_session (struct real_rtsp_session_t* real_session); Modified: mplayerxp/libmpstream2/s_ftp.cpp =================================================================== --- mplayerxp/libmpstream2/s_ftp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_ftp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -47,12 +47,7 @@ int OpenData(size_t newpos); int SendCmd(const std::string& cmd,char* rsp); - const char* user; - const char* pass; - const char* host; - int port; - const char* filename; - URL* url; + URL url; char* cput,*cget; Tcp tcp; @@ -196,7 +191,6 @@ int Ftp_Stream_Interface::OpenPort() { int resp; - net_fd_t fd; char rsp_txt[256]; char* par,str[128]; int num[6]; @@ -212,10 +206,11 @@ return 0; } sscanf(par+1,"%u,%u,%u,%u,%u,%u",&num[0],&num[1],&num[2],&num[3],&num[4],&num[5]); - snprintf(str,127,"%d.%d.%d.%d",num[0],num[1],num[2],num[3]); - tcp.open(str,(num[4]<<8)+num[5]); + snprintf(str,127,"ftp://%d.%d.%d.%d:%d",num[0],num[1],num[2],num[3],(num[4]<<8)+num[5]); + url.redirect(str); + tcp.open(url); - if(fd < 0) MSG_ERR("[ftp] failed to create data connection\n"); + if(!tcp.established()) MSG_ERR("[ftp] failed to create data connection\n"); return 1; } @@ -237,7 +232,7 @@ } } // Get the file - snprintf(str,255,"RETR %s",filename); + snprintf(str,255,"RETR %s",url.file().c_str()); resp = SendCmd(str,rsp_txt); if(resp != 1) { @@ -323,51 +318,46 @@ UNUSED(flags); uname=std::string("ftp://")+_filename; - if(!(url=url_new(uname))) goto bad_url; + if(url.redirect(uname)!=MPXP_Ok) goto bad_url; // url = check4proxies (rurl); - if(!(url->hostname && url->file)) { + if(url.host().empty() && !url.file().empty()) { bad_url: MSG_ERR("[ftp] Bad url\n"); return MPXP_False; } - user=url->username?url->username:"anonymous"; - pass=url->password?url->password:"no@spam"; - host=url->hostname; - port=url->port?url->port:21; - filename=url->file; - MSG_V("FTP: Opening ~%s :%s @%s :%i %s\n",user,pass,host,port,filename); + if(url.user().empty()) url.set_login("anonymous","no@spam"); + url.assign_port(21); + MSG_V("FTP: Opening ~%s :%s @%s :%i %s\n" + ,url.user().c_str(),url.password().c_str(),url.host().c_str(), + url.port(),url.file().c_str()); // Open the control connection - tcp.open(host,port); + tcp.open(url); if(!tcp.established()) { - delete url; return MPXP_False; } // We got a connection, let's start serious things buf = new char [BUFSIZE]; if (readresp(NULL) == 0) { close(); - delete url; return MPXP_False; } // Login - snprintf(str,255,"USER %s",user); + snprintf(str,255,"USER %s",url.user().c_str()); resp = SendCmd(str,rsp_txt); // password needed if(resp == 3) { - snprintf(str,255,"PASS %s",pass); + snprintf(str,255,"PASS %s",url.password().c_str()); resp = SendCmd(str,rsp_txt); if(resp != 2) { MSG_ERR("[ftp] command '%s' failed: %s\n",str,rsp_txt); close(); - delete url; return MPXP_False; } } else if(resp != 2) { MSG_ERR("[ftp] command '%s' failed: %s\n",str,rsp_txt); close(); - delete url; return MPXP_False; } @@ -376,7 +366,6 @@ if(resp != 2) { MSG_ERR("[ftp] command 'TYPE I' failed: %s\n",rsp_txt); close(); - delete url; return MPXP_False; } @@ -385,7 +374,6 @@ if(resp != 2) { MSG_ERR("[ftp] command 'SYST' failed: %s\n",rsp_txt); close(); - delete url; return MPXP_False; } MSG_INFO("[ftp] System: %s\n",rsp_txt); @@ -393,13 +381,12 @@ if(resp != 2) { MSG_ERR("[ftp] command 'STAT' failed: %s\n",rsp_txt); close(); - delete url; return MPXP_False; } file_len=0; // Get the filesize - snprintf(str,255,"SIZE %s",filename); + snprintf(str,255,"SIZE %s",url.file().c_str()); resp = SendCmd(str,rsp_txt); if(resp != 2) { MSG_WARN("[ftp] command '%s' failed: %s\n",str,rsp_txt); @@ -414,7 +401,6 @@ // because the connection would stay open in the main process, // preventing correct abort with many servers. - delete url; return MPXP_Ok; } Stream::type_e Ftp_Stream_Interface::type() const { return file_len?Stream::Type_Seekable:Stream::Type_Stream; } Modified: mplayerxp/libmpstream2/s_network.cpp =================================================================== --- mplayerxp/libmpstream2/s_network.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_network.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -37,7 +37,7 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; private: - URL* url; + URL url; off_t spos; Tcp tcp; Networking* networking; @@ -46,22 +46,17 @@ Network_Stream_Interface::Network_Stream_Interface(libinput_t& libinput) :Stream_Interface(libinput), tcp(libinput,-1) {} -Network_Stream_Interface::~Network_Stream_Interface() { - if(url) delete url; -} +Network_Stream_Interface::~Network_Stream_Interface() {} MPXP_Rc Network_Stream_Interface::open(const std::string& filename,unsigned flags) { UNUSED(flags); - url = url_new(filename); - if(url) { + if(url.redirect(filename)==MPXP_Ok) { if((networking=Networking::start(tcp,url))==NULL){ MSG_ERR(MSGTR_UnableOpenURL, filename.c_str()); - delete url; - url=NULL; return MPXP_False; } - MSG_INFO(MSGTR_ConnToServer, url->hostname); + MSG_INFO(MSGTR_ConnToServer, url.host().c_str()); spos = 0; return MPXP_Ok; } Modified: mplayerxp/libmpstream2/s_rtsp.cpp =================================================================== --- mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_rtsp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -76,14 +76,14 @@ MPXP_Rc Rtsp_Stream_Interface::open(const std::string& filename,unsigned flags) { - URL *url; + URL url; UNUSED(flags); if(filename.substr(0,7)!="rtsp://") return MPXP_False; MSG_V("STREAM_RTSP, URL: %s\n", filename.c_str()); - url = url_new (filename); - url = check4proxies (url); + url.redirect (filename); + url.check4proxies (); tcp.close(); if ((networking=Rtsp_Networking::start(tcp,url,net_conf.bandwidth)) == NULL) { Modified: mplayerxp/libmpstream2/s_udp.cpp =================================================================== --- mplayerxp/libmpstream2/s_udp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/s_udp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -43,9 +43,9 @@ virtual off_t sector_size() const; virtual std::string mime_type() const; private: - MPXP_Rc start (URL*,unsigned); + MPXP_Rc start (const URL&,unsigned); - Networking* networking; + Networking* networking; Udp udp; Tcp tcp; }; @@ -77,7 +77,7 @@ networking=NULL; } -MPXP_Rc Udp_Stream_Interface::start (URL* url,unsigned bandwidth) +MPXP_Rc Udp_Stream_Interface::start (const URL& url,unsigned bandwidth) { if (!udp.established()) { udp.open(networking->url); @@ -95,13 +95,13 @@ MPXP_Rc Udp_Stream_Interface::open(const std::string& filename,unsigned flags) { - URL *url; + URL url; UNUSED(flags); MSG_V("STREAM_UDP, URL: %s\n", filename.c_str()); - url = url_new (filename); - url = check4proxies (url); - if (url->port == 0) { + url.redirect(filename); + url.check4proxies (); + if (url.port() == 0) { MSG_ERR("You must enter a port number for UDP streams!\n"); return MPXP_False; } Modified: mplayerxp/libmpstream2/tcp.cpp =================================================================== --- mplayerxp/libmpstream2/tcp.cpp 2012-12-17 17:36:01 UTC (rev 571) +++ mplayerxp/libmpstream2/tcp.cpp 2012-12-18 13:04:29 UTC (rev 572) @@ -51,7 +51,7 @@ // return -2 for fatal error, like unable to resolve name, connection timeout... // return -1 is unable to connect to a particular port -void Tcp::open(const std::string& host, int port, tcp_af_e af) { +void Tcp::open(const URL& __url, tcp_af_e af) { socklen_t err_len; int ret,count = 0; fd_set set; @@ -64,6 +64,7 @@ any_t*our_s_addr; // Pointer to sin_addr or sin6_addr struct hostent *hp=NULL; char buf[255]; + _url=__url; #ifdef HAVE_WINSOCK2 u_long val; @@ -73,7 +74,7 @@ #endif buf[0]=0; - MSG_V("[tcp%s] Trying to resolv host '%s'\n", af2String(af), host.c_str()); + MSG_V("[tcp%s] Trying to resolv host '%s'\n", af2String(af), _url.host().c_str()); _fd = ::socket(af==Tcp::IP4?AF_INET:AF_INET6, SOCK_STREAM, 0); if( _fd==-1 ) { @@ -104,26 +105,26 @@ memset(&server_address, 0, sizeof(server_address)); - MSG_V("[tcp%s] PreResolving Host '%s'\n",af2String(af), host.c_str()); + MSG_V("[tcp%s] PreResolving Host '%s'\n",af2String(af), _url.host().c_str()); #ifndef HAVE_WINSOCK2 #ifdef USE_ATON - if (::inet_aton(host.c_str(), our_s_addr)!=1) + if (::inet_aton(_url.host().c_str(), our_s_addr)!=1) #else - if (::inet_pton(af==Tcp::IP4?AF_INET:AF_INET6, host.c_str(), our_s_addr)!=1) + if (::inet_pton(af==Tcp::IP4?AF_INET:AF_INET6, _url.host().c_str(), our_s_addr)!=1) #endif #else - if (::inet_addr(host.c_str())==INADDR_NONE ) + if (::inet_addr(_url.host().c_str())==INADDR_NONE ) #endif { - MSG_V("[tcp%s] Resolving Host '%s'\n",af2String(af), host.c_str()); + MSG_V("[tcp%s] Resolving Host '%s'\n",af2String(af), _url.host().c_str()); #ifdef HAVE_GETHOSTBYNAME2 - hp=(struct hostent*)::gethostbyname2( host.c_str(), af==Tcp::IP4?AF_INET:AF_INET6 ); + hp=(struct hostent*)::gethostbyname2( _url.host().c_str(), af==Tcp::IP4?AF_INET:AF_INET6 ); #else - hp=(struct hostent*)::gethostbyname( host.c_str() ); + hp=(struct hostent*)::gethostbyname( _url.host().c_str() ); #endif if( hp==NULL ) { - MSG_V("[tcp%s] Can't resolv: %s\n",af2String(af), host.c_str()); + MSG_V("[tcp%s] Can't resolv: %s\n",af2String(af), _url.host().c_str()); _error=Tcp::Err_Fatal; return; } @@ -132,7 +133,7 @@ } #ifdef HAVE_WINSOCK2 else { - unsigned long addr = inet_addr(host.c_str()); + unsigned long addr = inet_addr(_url.host().c_str()); memcpy( our_s_addr, (any_t*)&addr, sizeof(addr) ); } #endif @@ -140,12 +141,12 @@ switch (af) { case Tcp::IP4: server_address.four.sin_family=AF_INET; - server_address.four.sin_port=htons(port); + server_address.four.sin_port=htons(_url.port()); server_address_size = sizeof(server_address.four); break; case Tcp::IP6: server_address.six.sin6_family=AF_INET6; - server_address.six.sin6_port=htons(port); + server_address.six.sin6_port=htons(_url.port()); server_address_size = sizeof(server_address.six); break; default: @@ -159,7 +160,7 @@ #else ::inet_ntop(af==Tcp::IP4?AF_INET:AF_INET6, our_s_addr, buf, 255); #endif - MSG_INFO("[tcp%s] Connecting to server: %s (%s:%i)\n",af2String(af),host.c_str(),buf,port); + MSG_INFO("[tcp%s] Connecting to server: %s (%s:%i)\n",af2String(af),_url.host().c_str(),buf,_url.port()); // Turn the socket as non blocking so we can timeout on the connection #ifndef HAVE_WINSOCK2 @@ -174,7 +175,7 @@ #else if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) { #endif - MSG_V("[tcp%s] Can't connect to server: %s\n",af2String(af),host.c_str()); + MSG_V("[tcp%s] Can't connect to server: %s\n",af2String(af),_url.host().c_str()); ::closesocket(_fd); _fd=-1; _error=Tcp::Err_Port; @@ -225,12 +226,12 @@ } } -Tcp::Tcp(libinput_t& _libinput,const std::string& host,int port,tcp_af_e af) +Tcp::Tcp(libinput_t... [truncated message content] |