1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include "mms.h"
extern char *mms_url_s[];
extern char *mms_url_e[];
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,"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 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;
}
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(!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;
}
strncpy(buff1,fname,sizeof(buff1));
/* extract hostname/test/connect */
conn:
url=mms_connect_common(&s,80,buff1,&host,&hostend,NULL,NULL);
if(!url)
return 1;
printf("asxparser: connect passed \n");
notyetconnected=0;
l=sizeof(buff);
first_request(buff, host,hostend, &l);
write(s,buff,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);
}
*/
close(s);
free(host);
if(res<1){
char *ext;
ext=strrchr(buff1,'.');
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;
}
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 *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}
|