summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input/asxparser.c312
-rw-r--r--src/input/input_mms.c10
2 files changed, 215 insertions, 107 deletions
diff --git a/src/input/asxparser.c b/src/input/asxparser.c
index 9cdd8cdcf..ea58b857d 100644
--- a/src/input/asxparser.c
+++ b/src/input/asxparser.c
@@ -1,19 +1,111 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <unistd.h>
#include <fcntl.h>
#include <string.h>
-#include <mms.h>
#include <unistd.h>
#include <ctype.h>
+#include <errno.h>
+#include "mms.h"
+
-void asx_find_entries(char* buff, char** fname,
- int *IsNotFinished);
+extern char *mms_url_s[];
+extern char *mms_url_e[];
-char *strupr(char *string);
+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;
+
-void first_request(char *buff, char *host, char *file, int *len) {
+
+ 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);
@@ -24,136 +116,146 @@ void first_request(char *buff, char *host, char *file, int *len) {
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");
+
*len =(int)ptr-(int)buff;
}
-int asx_parse (char* mrl, char** rname) {
+int mms_read_nb (int d, char *buf, int blen)
+{
+ int ret;
+ int aread=0;
+
+ fcntl (d, F_SETFL, O_NONBLOCK);
+
+ while (aread < blen){
+ ret = read (d, buf+aread, blen - aread);
+ /* printf ("ret =%d aread =%d \n",ret, aread); */
+
+ if (ret==-1) {
+ if (errno==EAGAIN){
+ continue;
+ }
+ fcntl (d, F_SETFL, ~O_NONBLOCK);
+ return -1;
+ }
+ aread+=ret;
+ if ( ret >0 )
+ continue;
+ if (!ret ){
+ fcntl (d, F_SETFL, ~O_NONBLOCK);
+ /* printf ("aread = %d \n", aread); */
+ return aread;
+ }
+ }
+ fcntl (d, F_SETFL, ~O_NONBLOCK);
+ return aread;
+}
- char* ptr=NULL;
- char buff[1024];
- int res;
- int is_not_finished=0;
- char *url, *host, *hostend;
- char *path, *file;
- int hostlen, s ,l;
+int asx_parse (char* fname, char** rname)
+{
+ char* ptr=NULL;
+ char buff[10000];
+ int res;
+ int IsNotFinished=0;
+ char *url, *host=NULL, *hostend=NULL;
+ char buff1[10000];
+ int s ,l;
+ char notyetconnected=1;
+
+ printf ("in asxparser \n");
+ if(!fname)
+ return 1;
+
+ ptr=(char*)strrchr(fname,'.');
- if (strncasecmp (mrl, "mmshttp://", 10)) {
- return 0;
- }
-
- ptr=strstr(mrl,"//");
if(!ptr)
- return 0;
+ return 1;
- l=ptr-mrl+2;
- url = strdup (mrl);
+
+ 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;
+ }
+
+ strncpy(buff1,fname,sizeof(buff1));
+ /* extract hostname/test/connect */
+ conn:
- /* extract hostname */
+ url=mms_connect_common(&s,80,buff1,&host,&hostend,NULL,NULL);
+ if(!url)
+ return 1;
- 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 %d byte received \n",buff,res);
- if(!strstr(buff,"mms://")) {
- l=sizeof(buff);
- first_request(buff, host, hostend, &l);
+ res=mms_read_nb(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);
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);
- return 1;
+ if(res<1){
+ char *ext;
-}
-
-void asx_find_entries (char* buff, char** fname,
- int *is_not_finished ) {
- int res;
- char *ptr;
- char *uptr;
- char* ptre;
+ ext=strrchr(buff1,'.');
- /*no <ASX VERSION >*/
- uptr=strdup(buff);
- uptr=strupr(uptr);
-
- if (!strstr(uptr,"ASX VERSION")){
- free(uptr);
- return ;
+ 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;
}
- 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;
- printf("asxparser path is %s \n", *fname);
- return ;
+ 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;
+
}
-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;
}
diff --git a/src/input/input_mms.c b/src/input/input_mms.c
index 0c78e3c7f..3822d87e6 100644
--- a/src/input/input_mms.c
+++ b/src/input/input_mms.c
@@ -78,12 +78,18 @@ static int mms_plugin_open (input_plugin_t *this_gen, char *mrl) {
char* nmrl=NULL;
char* uptr;
+ int error_id;
mms_input_plugin_t *this = (mms_input_plugin_t *) this_gen;
- if (!asx_parse (mrl,&nmrl))
- nmrl = mrl;
+ error_id=asx_parse(mrl,&nmrl);
+ if(error_id)
+ return 0;
+
+ if(!nmrl)
+ nmrl=mrl;
+
printf("mms_plugin_open: using mrl <%s> \n", nmrl);
uptr=strdup(nmrl);