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
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <mms.h>
#include <unistd.h>
#include <ctype.h>
void asx_find_entries(char* buff, char** fname,
int *IsNotFinished);
char *strupr(char *string);
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 asx_parse (char* mrl, char** rname) {
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 (strncasecmp (mrl, "mmshttp://", 10)) {
return 0;
}
ptr=strstr(mrl,"//");
if(!ptr)
return 0;
l=ptr-mrl+2;
url = strdup (mrl);
/* 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");
l=sizeof(buff);
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);
write(s,buff,l);
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;
}
void asx_find_entries (char* buff, char** fname,
int *is_not_finished ) {
int res;
char *ptr;
char *uptr;
char* ptre;
/*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;
printf("asxparser path is %s \n", *fname);
return ;
}
char *strupr(char *string) {
char *s;
if (string){
for (s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}
|