diff options
author | Guenter Bartsch <guenter@users.sourceforge.net> | 2002-03-19 02:12:49 +0000 |
---|---|---|
committer | Guenter Bartsch <guenter@users.sourceforge.net> | 2002-03-19 02:12:49 +0000 |
commit | 45e8d9079bac057741810a62bb41215e575ce56c (patch) | |
tree | 8c848a4dfdb8283f53ec91637145364ab6c77222 /src/input/asxparser.c | |
parent | 31bb532cd84320a72f10e72cc6ca9c062ecfc948 (diff) | |
download | xine-lib-45e8d9079bac057741810a62bb41215e575ce56c.tar.gz xine-lib-45e8d9079bac057741810a62bb41215e575ce56c.tar.bz2 |
improved buffering for audio-only streams
(wanna try? gnome-xine mms://live5-ms.unbn.unit.net/radio_project )
forced asx-parser back to a (hopefully) working state
fixed warning about wrong audio_instance type
CVS patchset: 1591
CVS date: 2002/03/19 02:12:49
Diffstat (limited to 'src/input/asxparser.c')
-rw-r--r-- | src/input/asxparser.c | 284 |
1 files changed, 107 insertions, 177 deletions
diff --git a/src/input/asxparser.c b/src/input/asxparser.c index b23a3529a..b094b5f49 100644 --- a/src/input/asxparser.c +++ b/src/input/asxparser.c @@ -3,227 +3,157 @@ #include <sys/types.h> #include <fcntl.h> #include <string.h> -#include "mms.h" +#include <mms.h> #include <unistd.h> #include <ctype.h> +void asx_find_entries(char* buff, char** fname, + int *IsNotFinished); +char *strupr(char *string); -extern char *mms_url_s[]; -extern char *mms_url_e[]; +void first_request(char *buff, char *host, char *file, int *len) { -void asx_find_entries(char* buff,char *url, char** fname, - int *IsNotFinished ) -{ - int res; - int delta; - int delta1=0; - char *ptr; - char* ptre=NULL; - char* ptre1=NULL; - - - - delta=mms_start_where(buff); - if(delta < 0) - return ; - - ptr=buff+delta; - if(!strncasecmp(ptr,"HREF",4)){ - char* lastsl; - lastsl=(char*)strchr(ptr,'/'); - if(lastsl) - ptr=lastsl; - lastsl=(char*)strrchr(url,'/'); - if(lastsl) - delta1=lastsl-url; - } - ptre1=(char*)strstr(ptr, "#"); - if (!ptre1) - ptre1=(char*)strstr(ptr, "?"); - if (!ptre) - ptre=(char*)strstr(ptr, "\"/>"); - if (!ptre) - ptre=(char*)strstr(ptr, "\" "); - if (!ptre) - ptre=(char*)strstr(ptr, "\"\t"); - if (!ptre) - ptre=(char*)strstr(ptr, "\"\n"); - if (!ptre) - ptre=(char*)strstr(ptr, "\t"); - if (!ptre) - ptre=(char*)strstr(ptr, "\r"); - if (!ptre) - ptre=(char*)strstr(ptr, "\n"); - if (!ptre) - ptre=(char*)strstr(ptr, " "); - - if( ((ptre > ptre1) && ptre1) || (!ptre && ptre1) ) - ptre=ptre1; - - if(!ptre){ - char *ptr1; - - ptr1=(char*)strrchr(ptr,'.'); - - if(!ptr1) - goto cont; - - - if (!mms_url_is(ptr1+1, mms_url_e)) { - - } - else - ptre=ptr1+4; - - - - } - cont: - printf("TEST 1 \n"); - if (!ptre) - return ; - - printf("TEST 2 \n"); - res=(int)(ptre-ptr); - if(res<=0) - return ; - if ( !delta1 ){ - (*fname)=(char*)realloc((*fname),res+2); - memcpy(*fname,ptr,res); - (*fname)[res]=0; - } - else{ - (*fname)=(char*)realloc((*fname),res+2+delta1+1); - memcpy(*fname,url,delta1+1); - memcpy(*fname+delta1,ptr,res+2); - (*fname)[res+delta1+1]=0; - } - - printf("asxparser path is %s \n", *fname); - return ; -} -void first_request(char* buff,char* host, char* file,int *len) -{ char *ptr; bzero(buff,*len); ptr=buff; ptr+=sprintf(ptr,"GET %s HTTP/1.0\r\n",file); ptr+=sprintf(ptr,"Accept: */*\r\n"); - ptr+=sprintf(ptr,"User-Agent: NSPlayer/7.0.0.1956\r\n"); + ptr+=sprintf(ptr,"User-Agent: xine/0.9.8\r\n"); ptr+=sprintf(ptr,"Host: %s\r\n", host); ptr+=sprintf(ptr,"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=1,max-duration=0\r\n"); ptr+=sprintf(ptr,"Pragma: xClientGUID=%s\r\n", "{33715801-BAB3-9D85-24E9-03B90328270A}"); - - ptr+=sprintf(ptr,"Connection: Keep-Alive\r\n\r\n"); - + ptr+=sprintf(ptr,"Connection: Close\r\n\r\n"); *len =(int)ptr-(int)buff; } +int asx_parse (char* mrl, char** rname) { -int asx_parse (char* fname, char** rname) -{ - char* ptr=NULL; - char buff[1024]; - int res; - int IsNotFinished=0; - char *url, *host=NULL, *hostend=NULL; - char buff1[1024]; - int s ,l; - char notyetconnected=1; - - if(!fname) - return 1; - - ptr=(char*)strrchr(fname,'.'); + char* ptr=NULL; + char buff[1024]; + int res; + int is_not_finished=0; + char *url, *host, *hostend; + char *path, *file; + int hostlen, s ,l; - if(!ptr) - return 1; - - - if( mms_start_where(fname) < 0 ){ - FILE *fp; - /* probably it is asx file on the disk*/ - fp=fopen(fname,"r"); - if(!fp) - return 1; - fread(buff,sizeof(buff),1,fp); - fclose(fp); - printf ("asxparser: buff =%s \n",buff ); - goto proc; - } + if (strncasecmp (mrl, "mmshttp://", 10)) { + return 0; + } - strncpy(buff1,fname,sizeof(buff1)); - /* extract hostname/test/connect */ - conn: + ptr=strstr(mrl,"//"); + if(!ptr) + return 0; + + l=ptr-mrl+2; + url = strdup (mrl); - url=mms_connect_common(&s,80,buff1,&host,&hostend,NULL,NULL); - if(!url) - return 1; + /* extract hostname */ + hostend = strchr(&url[l],'/'); + if (!hostend) { + printf ("asxparser: invalid url >%s<, failed to find hostend \n", url); + free(url); + return 0; + } + hostlen = hostend - url - l; + host = malloc (hostlen+1); + strncpy (host, &url[l], hostlen); + host[hostlen]=0; + + /* extract path and file */ + + path = url+hostlen+l+1; + file = strrchr (url, '/'); + + /* + * try to connect + */ + + printf("asxparser host=%s \n",host); + printf("asxparser file=%s \n",hostend); + s = host_connect (host, 80); + if (s == -1) { + printf ("asxparser: failed to connect\n"); + free (host); + free (url); + return 0; + } printf("asxparser: connect passed \n"); - notyetconnected=0; l=sizeof(buff); - first_request(buff, host,hostend, &l); + first_request(buff, host, hostend, &l); write(s,buff,l); res=read(s,buff, sizeof(buff)); - printf("asxparser: answer1=::%s:: \n %d byte received \n",buff,res); - - - if(mms_start_where(buff) < 0){ - l=sizeof(buff); - /* second_request(buff, host,hostend, &l); + printf("asxparser: answer1=%s %d byte received \n",buff,res); + if(!strstr(buff,"mms://")) { + l=sizeof(buff); + first_request(buff, host, hostend, &l); write(s,buff,l); -*/ - res=read(s,buff, sizeof(buff)); - printf("asxparser: answer2=%s %d byte received\n",buff,res); -} - - + res=read(s,buff, sizeof(buff)); + printf("asxparser: answer2=%s %d byte received\n",buff,res); + } close(s); + free(url); free(host); + if(res<1) + return 0; + + printf ("asxparser: finding entries...\n"); + + asx_find_entries(buff,rname,&is_not_finished); - if(res<1){ - char *ext; + return 1; - ext=strrchr(buff1,'.'); +} + +void asx_find_entries (char* buff, char** fname, + int *is_not_finished ) { + int res; + char *ptr; + char *uptr; + char* ptre; - if(mms_url_is(buff1,mms_url_s) - && ext && mms_url_is(ext+1, mms_url_e)){ - printf("asxparser: using url received from browser \n"); - return 0; - } - printf("asxparser: no success fname=%s ext=%s \n",fname,ext); - return 1; + /*no <ASX VERSION >*/ + uptr=strdup(buff); + uptr=strupr(uptr); + + if (!strstr(uptr,"ASX VERSION")){ + free(uptr); + return ; } + free(uptr); + + ptr=(char*)strstr(buff, "mms://"); + if(!ptr) + return ; + ptre=(char*)strstr(ptr, "\""); + if (!ptre) + return ; + + res=(int)(ptre-ptr); + if(res<=0) + return ; + (*fname)=(char*)malloc(res+2); + memcpy(*fname,ptr,res); + (*fname)[res]=0; - proc: - asx_find_entries(buff,fname,rname,&IsNotFinished); - if(notyetconnected && *rname){ - strncpy(buff1,*rname,sizeof(buff1)); - goto conn; - } - printf("asx_parser passed \n"); - return 0; - + printf("asxparser path is %s \n", *fname); + return ; } - -char *strupr(char *string) -{ +char *strupr(char *string) { char *s; - if (string) - { - for (s = string; *s; ++s) - *s = toupper(*s); - } + if (string){ + for (s = string; *s; ++s) + *s = toupper(*s); + } return string; } |