summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index 4665408..7978805 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -151,210 +151,213 @@ LibMadPlugin::LibMadPlugin() {
151 151
152LibMadPlugin::~LibMadPlugin() { 152LibMadPlugin::~LibMadPlugin() {
153 close(); 153 close();
154 delete d; 154 delete d;
155} 155}
156 156
157 157
158bool LibMadPlugin::isFileSupported( const QString& path ) { 158bool LibMadPlugin::isFileSupported( const QString& path ) {
159 debugMsg( "LibMadPlugin::isFileSupported" ); 159 debugMsg( "LibMadPlugin::isFileSupported" );
160 160
161 // Mpeg file extensions 161 // Mpeg file extensions
162 // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" 162 // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3"
163 // Other media extensions 163 // Other media extensions
164 // "wav","mid","mod","s3m","ogg","avi","mov","sid" 164 // "wav","mid","mod","s3m","ogg","avi","mov","sid"
165 165
166 char *ext = strrchr( path.latin1(), '.' ); 166 char *ext = strrchr( path.latin1(), '.' );
167 167
168 // Test file extension 168 // Test file extension
169 if ( ext ) { 169 if ( ext ) {
170 if ( strncasecmp(ext, ".mp2", 4) == 0 ) 170 if ( strncasecmp(ext, ".mp2", 4) == 0 )
171 return TRUE; 171 return TRUE;
172 if ( strncasecmp(ext, ".mp3", 4) == 0 ) 172 if ( strncasecmp(ext, ".mp3", 4) == 0 )
173 return TRUE; 173 return TRUE;
174 } 174 }
175 // UGLY - just for fast testing 175 // UGLY - just for fast testing
176 if ( path.left(4) == "http") { 176 if ( path.left(4) == "http") {
177 return TRUE; 177 return TRUE;
178 } 178 }
179 179
180 180
181 return FALSE; 181 return FALSE;
182} 182}
183 183
184 184
185int LibMadPlugin::tcp_open(char *address, int port) { 185int LibMadPlugin::tcp_open(char *address, int port) {
186 struct sockaddr_in stAddr; 186 struct sockaddr_in stAddr;
187 struct hostent *host; 187 struct hostent *host;
188 int sock; 188 int sock;
189 struct linger l; 189 struct linger l;
190 190
191 memset(&stAddr, 0, sizeof(stAddr)); 191 memset(&stAddr, 0, sizeof(stAddr));
192 stAddr.sin_family = AF_INET; 192 stAddr.sin_family = AF_INET;
193 stAddr.sin_port = htons(port); 193 stAddr.sin_port = htons(port);
194 194
195 if ((host = gethostbyname(address)) == NULL) 195 if ((host = gethostbyname(address)) == NULL)
196 return (0); 196 return (0);
197 197
198 stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); 198 stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]);
199 199
200 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 200 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
201 return (0); 201 return (0);
202 202
203 l.l_onoff = 1; 203 l.l_onoff = 1;
204 l.l_linger = 5; 204 l.l_linger = 5;
205 if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) 205 if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0)
206 return (0); 206 return (0);
207 207
208 if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) 208 if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0)
209 return (0); 209 return (0);
210 210
211 return (sock); 211 return (sock);
212} 212}
213 213
214 214
215/** 215/**
216 * Read a http line header. 216 * Read a http line header.
217 * This function read character by character. 217 * This function read character by character.
218 * @param tcp_sock the socket use to read the stream 218 * @param tcp_sock the socket use to read the stream
219 * @param buf a buffer to receive the data 219 * @param buf a buffer to receive the data
220 * @param size size of the buffer 220 * @param size size of the buffer
221 * @return the size of the stream read or -1 if an error occured 221 * @return the size of the stream read or -1 if an error occured
222 */ 222 */
223int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { 223int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) {
224 int offset = 0; 224 int offset = 0;
225 225
226 do 226 do
227 { 227 {
228 if (std::read(tcp_sock, buf + offset, 1) < 0) 228 if (std::read(tcp_sock, buf + offset, 1) < 0)
229 return -1; 229 return -1;
230 if (buf[offset] != '\r') /* Strip \r from answer */ 230 if (buf[offset] != '\r') /* Strip \r from answer */
231 offset++; 231 offset++;
232 } 232 }
233 while (offset < size - 1 && buf[offset - 1] != '\n'); 233 while (offset < size - 1 && buf[offset - 1] != '\n');
234 234
235 buf[offset] = 0; 235 buf[offset] = 0;
236 return offset; 236 return offset;
237} 237}
238 238
239int LibMadPlugin::http_open(const QString& path ) { 239int LibMadPlugin::http_open(const QString& path ) {
240 qDebug("Open http"); 240 qDebug("Open http");
241 char *host; 241 char *host;
242 int port; 242 int port;
243 char *request; 243 char *request;
244 int tcp_sock; 244 int tcp_sock;
245 char http_request[PATH_MAX]; 245 char http_request[PATH_MAX];
246 char filename[PATH_MAX]; 246 char filename[PATH_MAX];
247 char c; 247 // char c;
248 char *arg =strdup(path.latin1()); 248 char *arg =strdup(path.latin1());
249 249
250 QString errorMsg; 250 QString errorMsg;
251 251
252 /* Check for URL syntax */ 252 /* Check for URL syntax */
253// if (strncmp(arg, "http://", strlen("http://"))) { 253// if (strncmp(arg, "http://", strlen("http://"))) {
254// qDebug("Url syntax error"); 254// qDebug("Url syntax error");
255// return (0); 255// return (0);
256// } 256// }
257 257
258 qDebug("Parse URL"); 258 qDebug("Parse URL");
259 port = 80; 259 port = 80;
260 host = arg + strlen("http://"); 260 host = arg + strlen("http://");
261 if ((request = strchr(host, '/')) == NULL) { 261
262 qDebug("Url syntax 2error %s", host); 262 // we need to think of something better than that
263 return (0); 263 //if ((request = strchr(host, '/')) == NULL) {
264 } 264 // qDebug("Url syntax 2error %s", host);
265 // return (0);
266 // }
267
265 *request++ = 0; 268 *request++ = 0;
266 269
267 if (strchr(host, ':') != NULL) /* port is specified */ 270 if (strchr(host, ':') != NULL) /* port is specified */
268 { 271 {
269 port = atoi(strchr(host, ':') + 1); 272 port = atoi(strchr(host, ':') + 1);
270 *strchr(host, ':') = 0; 273 *strchr(host, ':') = 0;
271 } 274 }
272 275
273 qDebug("Open a TCP socket"); 276 qDebug("Open a TCP socket");
274 if (!(tcp_sock = tcp_open(host, port))) { 277 if (!(tcp_sock = tcp_open(host, port))) {
275 perror("http_open"); 278 perror("http_open");
276 errorMsg="http_open "+(QString)strerror(errno); 279 errorMsg="http_open "+(QString)strerror(errno);
277 QMessageBox::message("OPiePlayer",errorMsg); 280 QMessageBox::message("OPiePlayer",errorMsg);
278 return (0); 281 return (0);
279 } 282 }
280 283
281 snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request); 284 snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request);
282 285
283 /* Send HTTP GET request */ 286 /* Send HTTP GET request */
284 /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print 287 /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print
285 * a html page and not the stream */ 288 * a html page and not the stream */
286 snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n" 289 snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n"
287/* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */ 290/* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */
288 "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host); 291 "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host);
289 qDebug("send"); 292 qDebug("send");
290 send(tcp_sock, http_request, strlen(http_request), 0); 293 send(tcp_sock, http_request, strlen(http_request), 0);
291 294
292 qDebug("Parse server reply"); 295 qDebug("Parse server reply");
293#if 0 296#if 0
294 qDebug("do 0"); 297 qDebug("do 0");
295 do 298 do
296 read(tcp_sock, &c, sizeof(char)); 299 read(tcp_sock, &c, sizeof(char));
297 while (c != ' '); 300 while (c != ' ');
298 read(tcp_sock, http_request, 4 * sizeof(char)); 301 read(tcp_sock, http_request, 4 * sizeof(char));
299 http_request[4] = 0; 302 http_request[4] = 0;
300 if (strcmp(http_request, "200 ")) 303 if (strcmp(http_request, "200 "))
301 { 304 {
302 fprintf(stderr, "http_open: "); 305 fprintf(stderr, "http_open: ");
303 do 306 do
304 { 307 {
305 read(tcp_sock, &c, sizeof(char)); 308 read(tcp_sock, &c, sizeof(char));
306 fprintf(stderr, "%c", c); 309 fprintf(stderr, "%c", c);
307 } 310 }
308 while (c != '\r'); 311 while (c != '\r');
309 fprintf(stderr, "\n"); 312 fprintf(stderr, "\n");
310 return (0); 313 return (0);
311 } 314 }
312#endif 315#endif
313 316
314 do 317 do
315 { 318 {
316 int len; 319 int len;
317 320
318 len = http_read_line(tcp_sock, http_request, sizeof(http_request)); 321 len = http_read_line(tcp_sock, http_request, sizeof(http_request));
319 322
320 if (len == -1) 323 if (len == -1)
321 { 324 {
322 fprintf(stderr, "http_open: %s\n", strerror(errno)); 325 fprintf(stderr, "http_open: %s\n", strerror(errno));
323 return 0; 326 return 0;
324 } 327 }
325 328
326 if (strncmp(http_request, "Location:", 9) == 0) 329 if (strncmp(http_request, "Location:", 9) == 0)
327 { 330 {
328 qDebug("redirect"); 331 qDebug("redirect");
329 std::close(tcp_sock); 332 std::close(tcp_sock);
330 333
331 http_request[strlen(http_request) - 1] = '\0'; 334 http_request[strlen(http_request) - 1] = '\0';
332 335
333 return http_open(&http_request[10]); 336 return http_open(&http_request[10]);
334 } 337 }
335 338
336 if (strncmp(http_request, "ICY ", 4) == 0) 339 if (strncmp(http_request, "ICY ", 4) == 0)
337 { 340 {
338 qDebug(" This is icecast streaming"); 341 qDebug(" This is icecast streaming");
339 if (strncmp(http_request + 4, "200 ", 4)) 342 if (strncmp(http_request + 4, "200 ", 4))
340 { 343 {
341 fprintf(stderr, "http_open: %s\n", http_request); 344 fprintf(stderr, "http_open: %s\n", http_request);
342 return 0; 345 return 0;
343 } 346 }
344 } 347 }
345 else if (strncmp(http_request, "icy-", 4) == 0) 348 else if (strncmp(http_request, "icy-", 4) == 0)
346 { 349 {
347 /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ 350 /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */
348 /* Don't print these - mpg123 doesn't */ 351 /* Don't print these - mpg123 doesn't */
349 /* fprintf(stderr,"%s\n",http_request); */ 352 /* fprintf(stderr,"%s\n",http_request); */
350 } 353 }
351 } 354 }
352 while (strcmp(http_request, "\n") != 0); 355 while (strcmp(http_request, "\n") != 0);
353 356
354 return (tcp_sock); 357 return (tcp_sock);
355} 358}
356 359
357 360
358bool LibMadPlugin::open( const QString& path ) { 361bool LibMadPlugin::open( const QString& path ) {
359 debugMsg( "LibMadPlugin::open" ); 362 debugMsg( "LibMadPlugin::open" );
360 Config cfg("OpiePlayer"); 363 Config cfg("OpiePlayer");