Ticket #1479: patch.diff.1479

File patch.diff.1479, 4.9 KB (added by kragen@…, 17 years ago)

patch

Line 
1Index: stream/asf_mmst_streaming.c
2===================================================================
3--- stream/asf_mmst_streaming.c (Revision 29358)
4+++ stream/asf_mmst_streaming.c (Arbeitskopie)
5@@ -104,7 +104,7 @@
6 return ret;
7 }
8
9-static void send_command (int s, int command, uint32_t switches,
10+static int send_command (int s, int command, uint32_t switches,
11 uint32_t extra, int length,
12 char *data)
13 {
14@@ -135,7 +135,9 @@
15
16 if (send (s, cmd.buf, len8*8+48, 0) != (len8*8+48)) {
17 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_WriteError);
18+ return -1;
19 }
20+ return 1;
21 }
22
23 #ifdef CONFIG_ICONV
24@@ -172,7 +174,7 @@
25 #endif
26 }
27
28-static void get_answer (int s)
29+static int get_answer (int s)
30 {
31 char data[BUF_SIZE];
32 int command = 0x1b;
33@@ -181,16 +183,21 @@
34 int len;
35
36 len = recv (s, data, BUF_SIZE, 0) ;
37- if (!len) {
38+ if (len <= 0) {
39 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_EOFAlert);
40- return;
41+ return len;
42 }
43
44 command = get_32 (data, 36) & 0xFFFF;
45
46- if (command == 0x1b)
47- send_command (s, 0x1b, 0, 0, 0, data);
48+ if (command == 0x1b) {
49+ len = send_command (s, 0x1b, 0, 0, 0, data);
50+ if (len < 0) {
51+ return len;
52+ }
53+ }
54 }
55+ return 1;
56 }
57
58 static int get_data (int s, char *buf, size_t count)
59@@ -296,7 +303,8 @@
60 // mp_msg(MSGT_NETWORK,MSGL_INFO,"command: %02x\n", command);
61
62 if (command == 0x1b)
63- send_command (s, 0x1b, 0, 0, 0, data);
64+ if (send_command (s, 0x1b, 0, 0, 0, data) < 0)
65+ return 0;
66
67 }
68
69@@ -526,7 +534,7 @@
70 char data[BUF_SIZE];
71 uint8_t asf_header[HDR_BUF_SIZE];
72 int asf_header_len;
73- int len, i, packet_length;
74+ int i, packet_length;
75 char *path, *unescpath;
76 URL_t *url1 = stream->streaming_ctrl->url;
77 int s = stream->fd;
78@@ -577,9 +585,13 @@
79 snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname);
80 string_utf16 (data, str, strlen(str));
81 // send_command(s, commandno ....)
82- send_command (s, 1, 0, 0x0004000b, strlen(str)*2+2, data);
83+ if (send_command (s, 1, 0, 0x0004000b, strlen(str)*2+2, data) < 0) {
84+ goto err_out;
85+ }
86
87- len = recv (s, data, BUF_SIZE, 0) ;
88+ if (recv (s, data, BUF_SIZE, 0) <= 0) {
89+ goto err_out;
90+ }
91
92 /*This sends details of the local machine IP address to a Funnel system at the server.
93 * Also, the TCP or UDP transport selection is sent.
94@@ -591,19 +603,29 @@
95
96 string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24);
97 memset (data, 0, 8);
98- send_command (s, 2, 0, 0, 24*2+10, data);
99+ if (send_command (s, 2, 0, 0, 24*2+10, data) < 0) {
100+ goto err_out;
101+ }
102
103- len = recv (s, data, BUF_SIZE, 0) ;
104+ if (recv (s, data, BUF_SIZE, 0) <= 0) {
105+ goto err_out;
106+ }
107
108 /* This command sends file path (at server) and file name request to the server.
109 * 0x5 */
110
111 string_utf16 (&data[8], path, strlen(path));
112 memset (data, 0, 8);
113- send_command (s, 5, 0, 0, strlen(path)*2+10, data);
114+ if (send_command (s, 5, 0, 0, strlen(path)*2+10, data) < 0) {
115+ goto err_out;
116+ }
117+
118 free(path);
119+ path = NULL;
120
121- get_answer (s);
122+ if (get_answer (s) <= 0) {
123+ goto err_out;
124+ }
125
126 /* The ASF header chunk request. Includes ?session' variable for pre header value.
127 * After this command is sent,
128@@ -613,7 +635,9 @@
129 memset (data, 0, 40);
130 data[32] = 2;
131
132- send_command (s, 0x15, 1, 0, 40, data);
133+ if (send_command (s, 0x15, 1, 0, 40, data) < 0) {
134+ goto err_out;
135+ }
136
137 num_stream_ids = 0;
138 /* get_headers(s, asf_header); */
139@@ -643,7 +667,9 @@
140 data[2] = 0xFF;
141 data[3] = 0xFF;
142 data[4] = audio_id;
143- send_command(s, 0x33, num_stream_ids, 0xFFFF | audio_id << 16, 8, data);
144+ if (send_command(s, 0x33, num_stream_ids, 0xFFFF | audio_id << 16, 8, data) < 0) {
145+ goto err_out;
146+ }
147 } else {
148 for (i=1; i<num_stream_ids; i++) {
149 data [ (i-1) * 6 + 2 ] = 0xFF;
150@@ -652,10 +678,14 @@
151 data [ (i-1) * 6 + 5 ] = 0x00;
152 }
153
154- send_command (s, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data);
155+ if (send_command (s, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data) < 0) {
156+ goto err_out;
157 }
158+ }
159
160- get_answer (s);
161+ if (get_answer (s) <= 0) {
162+ goto err_out;
163+ }
164
165 /* Start sending file from packet xx.
166 * This command is also used for resume downloads or requesting a lost packet.
167@@ -670,7 +700,9 @@
168
169 data[20] = 0x04;
170
171- send_command (s, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data);
172+ if (send_command (s, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data) < 0) {
173+ goto err_out;
174+ }
175
176 stream->fd = s;
177 stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read;
178@@ -687,4 +719,14 @@
179 #endif
180
181 return 0;
182+
183+ err_out:
184+ if (s > 0)
185+ closesocket(s);
186+
187+ if (path) {
188+ free(path);
189+ }
190+ stream->fd = -1;
191+ return -1;
192 }