~ubuntu-branches/ubuntu/vivid/mplayerplug-in/vivid

« back to all changes in this revision

Viewing changes to Source/plugin-support.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2005-09-16 14:46:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050916144655-f38cmp9o3kwepjl5
Tags: 3.05-1ubuntu1
* Sync with debian
* Build against gtk2
* Adjusted Build-Depends / Depends for firefox

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
            break;
79
79
        }
80
80
    }
81
 
    hostname[i] = '\0';
 
81
    if (i == 0) {
 
82
        NPN_MemFree(hostname);
 
83
        hostname = NULL;
 
84
    } else {
 
85
        hostname[i] = '\0';
 
86
    }
82
87
    if (DEBUG > 1)
83
88
        printf("exiting getURLHostname with %s\n", hostname);
84
89
 
107
112
        strcpy(filename, url);
108
113
        return filename;
109
114
    }
110
 
    strcpy(filename, tmp);
 
115
    strcpy(filename, tmp + 1);  // take everything upto, but not including the / starting from the right.
111
116
    return filename;
112
117
}
113
118
 
127
132
        return NULL;
128
133
    base = (char *) NPN_MemAlloc(sizeof(char) * (len + 1));
129
134
    strcpy(base, url);
130
 
    if (0)
 
135
    if (DEBUG > 1)
131
136
        printf("in getURLBase base: %s\n", base);
132
137
 
133
138
    for (i = len - 1; i >= 0; i--) {
137
142
            break;
138
143
        }
139
144
    }
140
 
    if (strlen(base) == 0) {
 
145
    if ((strlen(base) == 0) || (i <= 0)) {
141
146
        NPN_MemFree(base);
142
147
        base = NULL;
143
148
    }
153
158
 
154
159
int isMms(char *url)
155
160
{
156
 
    if (DEBUG > 1)
157
 
        printf("in isMms\n");
158
 
 
159
161
    if (url == NULL)
160
162
        return 0;
161
163
    if ((strncasecmp(url, "mms://", 6) == 0)
162
164
        || (strncasecmp(url, "mmst://", 7) == 0)
163
165
        || (strncasecmp(url, "mmsu://", 7) == 0)
164
166
        || (strncasecmp(url, "dvd://", 6) == 0)
 
167
        || (strncasecmp(url, "smb://", 6) == 0)
165
168
        || (strncasecmp(url, "rtsp://", 7) == 0)) {
 
169
        if (DEBUG > 1)
 
170
            printf("isMms = true\n");
166
171
        return 1;
167
172
    } else {
 
173
        if (DEBUG > 1)
 
174
            printf("isMms = false\nurl = %s\n", url);
168
175
        return 0;
169
176
    }
170
177
}
192
199
    char *tmp2;
193
200
    char *q1;                   // question mark in tmp
194
201
    char *q2;                   // question mark in tmp2
195
 
    char *hostname1;            // hostname1
196
 
    char *hostname2;            // hostname2
 
202
    int tmp1hasq = 0;           // tmp1 has a ?
 
203
    int tmp2hasq = 0;           // tmp2 has a ?
 
204
    char *hostname1 = NULL;     // hostname1
 
205
    char *hostname2 = NULL;     // hostname2
 
206
    char *protocol1 = NULL;
 
207
    char *protocol2 = NULL;
197
208
    int ret;
198
209
 
199
210
    if (DEBUG > 1)
234
245
        ret = -1;
235
246
    }
236
247
 
 
248
    if (strncasecmp(buffer1, "file://", 7) == 0) {
 
249
        if (strcmp(buffer1 + 7, buffer2) == 0) {
 
250
            free(buffer1);
 
251
            free(buffer2);
 
252
            ret = 0;
 
253
        }
 
254
    }
 
255
 
 
256
    if (strncasecmp(buffer2, "file://", 7) == 0) {
 
257
        if (strcmp(buffer1, buffer2 + 7) == 0) {
 
258
            free(buffer1);
 
259
            free(buffer2);
 
260
            ret = 0;
 
261
        }
 
262
    }
237
263
 
238
264
    if (ret == -1) {
239
265
        hostname1 = getURLHostname(buffer1);
242
268
        if (hostname1 != NULL && hostname2 != NULL
243
269
            && strstr(hostname2, hostname1) == NULL) {
244
270
            // hostname1 is a not substring of hostname2
 
271
            // this is done for the case where the playlist has two urls that basically point to the same site
 
272
            // one of the sites is an internal URL and the other is an external. We want to be able to play either
 
273
            // site. So as long as the hostnames are completly different we should be ok. 
 
274
            if (DEBUG > 1)
 
275
                printf("URLcmp: hostnames do not match\n");
245
276
            ret = -1;
246
277
        } else {
247
278
            // url1 is a substring of url2, so continue comparing
248
 
 
 
279
            if (DEBUG > 1)
 
280
                printf("hostname1 = %s\nhostname2 = %s\n", hostname1,
 
281
                       hostname2);
249
282
            // compare the paths, some sites change the hostname mid stream (like cartoonnetwork.com -> www.cartoonnetwork.com);
250
283
            tmp1 = strstr(buffer1, "://");
251
284
            if (tmp1 != NULL) {
 
285
                protocol1 =
 
286
                    (char *) malloc((long) tmp1 - (long) buffer1 + 1);
 
287
                strncpy(protocol1, buffer1,
 
288
                        (long) tmp1 - (long) buffer1 + 1);
 
289
                protocol1[(long) tmp1 - (long) buffer1] = '\0';
 
290
            }
 
291
 
 
292
            if (DEBUG > 1)
 
293
                printf("protocol1: %s\n", protocol1);
 
294
 
 
295
            if (tmp1 != NULL) {
252
296
                tmp1 = tmp1 + 3;
253
297
                while (tmp1[0] != '/') {
254
298
                    if (tmp1[0] == '\0')
258
302
            }
259
303
            tmp2 = strstr(buffer2, "://");
260
304
            if (tmp2 != NULL) {
 
305
                protocol2 =
 
306
                    (char *) malloc((long) tmp2 - (long) buffer2 + 1);
 
307
                strncpy(protocol2, buffer2,
 
308
                        (long) tmp2 - (long) buffer2 + 1);
 
309
                protocol2[(long) tmp2 - (long) buffer2] = '\0';
 
310
            }
 
311
 
 
312
            if (DEBUG > 1)
 
313
                printf("protocol2: %s\n", protocol2);
 
314
 
 
315
            if (tmp2 != NULL) {
261
316
                tmp2 = tmp2 + 3;
262
317
                while (tmp2[0] != '/') {
263
318
                    if (tmp2[0] == '\0')
267
322
            }
268
323
            if (tmp1 != NULL && tmp2 != NULL) {
269
324
                if (strcmp(tmp1, tmp2) == 0) {
270
 
                    ret = 0;
 
325
                    // if either protocol is file:// then they are the same at this point usually one will be NULL and the other file://
 
326
                    if ((strncmp(protocol1, "file://", 7) == 0)
 
327
                        || (strncmp(protocol2, "file://", 7) == 0)) {
 
328
                        ret = 0;
 
329
                    } else {
 
330
                        // NetFlix puts out the same preview on multiple protocols, we have to add them all to the playlist
 
331
                        if (strcmp(protocol1, protocol2) == 0) {
 
332
                            ret = 0;
 
333
                        } else {
 
334
                            ret = -1;
 
335
                        }
 
336
                    }
271
337
                } else {
272
338
                    ret = -1;
273
339
                    q1 = strchr(tmp1, '?');
274
340
                    q2 = strchr(tmp2, '?');
275
341
                    if (q1 != NULL || q2 != NULL) {
276
 
                        if (q1 != NULL)
 
342
                        if (q1 != NULL) {
277
343
                            q1[0] = '\0';
278
 
                        if (q2 != NULL)
 
344
                            tmp1hasq = 1;
 
345
                        }
 
346
                        if (q2 != NULL) {
279
347
                            q2[0] = '\0';
 
348
                            tmp2hasq = 1;
 
349
                        }
280
350
                        if (strcmp(tmp1, tmp2) == 0) {
281
 
                            ret = 0;
 
351
                            if (tmp1hasq != tmp2hasq) {
 
352
                                ret = -1;
 
353
                            } else {
 
354
                                if (strcmp(q1+1,q2+1) == 0) {
 
355
                                    ret = 0;
 
356
                                } else { 
 
357
                                    ret = -1;
 
358
                                }
 
359
                            }
282
360
                        } else {
283
361
                            ret = -1;
284
362
                        }
286
364
                }
287
365
            }
288
366
        }
 
367
        free(buffer1);
 
368
        free(buffer2);
 
369
 
 
370
    }
 
371
    if (hostname1 != NULL)
289
372
        NPN_MemFree(hostname1);
 
373
    if (hostname2 != NULL)
290
374
        NPN_MemFree(hostname2);
291
 
        free(buffer1);
292
 
        free(buffer2);
293
 
    }
 
375
    if (protocol1 != NULL)
 
376
        free(protocol1);
 
377
    if (protocol2 != NULL)
 
378
        free(protocol2);
 
379
 
 
380
    if (DEBUG > 1)
 
381
        printf("exiting URLcmp\n");
294
382
 
295
383
    return ret;
296
384
 
338
426
    char buffer[1024];
339
427
 
340
428
    if (DEBUG > 1)
341
 
        printf("in sendcommand\n");
 
429
        printf("in sendcommand - command %s\n", command);
342
430
 
343
431
    buffer[1023] = '\0';
344
432
    retval = 0;
346
434
    if (command == NULL || instance == NULL || instance->cancelled == 1)
347
435
        return 0;
348
436
 
 
437
    if (instance->threadsignaled == 0)
 
438
        return 0;
 
439
 
 
440
    if (instance->control == -1)
 
441
        return 0;
 
442
 
 
443
 
349
444
    if (instance->js_state != JS_STATE_TRANSITIONING) {
350
445
 
351
446
        snprintf(buffer, 1023, "%s\n", command);
397
492
 
398
493
    count = 0;
399
494
    while (instance->player != NULL && count < 10) {
 
495
        if (DEBUG)
 
496
            printf("waiting for player to go NULL\n");
400
497
        usleep(100);
401
498
        count++;
402
499
    }
405
502
    if (instance->player == NULL) {
406
503
        instance->pid = 0;
407
504
    } else {
408
 
/*      
409
 
        fclose(instance->player);
 
505
        if (DEBUG > 1)
 
506
            printf("closing player\n");
 
507
//      fclose(instance->player);
410
508
        instance->player = NULL;
411
509
 
 
510
        if (DEBUG > 1)
 
511
            printf("closing control pipe\n");
412
512
        if (instance->control > 0) {
413
513
            close(instance->control);
414
514
            instance->control = -1;
415
515
        }
416
 
*/
417
516
    }
418
517
 
 
518
    if (DEBUG > 1)
 
519
        printf("player should be closed\n");
 
520
 
419
521
    if (instance->pid != 0) {
420
522
        count = 0;
421
523
        status = 1;
445
547
        }
446
548
        //wait(&status);
447
549
    }
448
 
#ifdef DPMSEnabled
 
550
#ifdef DPMSExtension
449
551
    if (instance->DPMSEnabled)
450
552
        DPMSReenable(instance);
451
553
#endif
478
580
        if ((strncasecmp(item, "http", 4) != 0)
479
581
            && (strncasecmp(item, "file", 4) != 0)) {
480
582
 
 
583
            if (DEBUG > 1)
 
584
                printf("not http and not file\n");
 
585
 
481
586
            if (item[0] != '/') {
482
587
                strlcpy(tmpdir, item, 1024);    // reuse the buffer
483
588
                if (instance->baseurl != NULL) {
484
589
                    strlcpy(localitem, instance->baseurl, 1024);
 
590
                } else {
 
591
                    strlcpy(localitem, "", 1024);
485
592
                }
486
593
                strlcat(localitem, tmpdir, 1024);
487
594
            } else {
488
595
                if (instance->hostname != NULL) {
489
 
                    snprintf(tmpdir, 1024, "http://%s%s",
490
 
                             instance->hostname, item);
491
 
                    strlcpy(localitem, tmpdir, 1024);
 
596
                    if (fexists(item) == 0) {
 
597
                        snprintf(tmpdir, 1024, "http://%s%s",
 
598
                                 instance->hostname, item);
 
599
                        strlcpy(localitem, tmpdir, 1024);
 
600
                    } else {
 
601
                        // first char == / and hostname is null, sounds like a filename
 
602
                        strlcpy(localitem, item, 1024);
 
603
                    }
 
604
                } else {
 
605
                    // first char == / and hostname is null, sounds like a filename
 
606
                    strlcpy(localitem, item, 1024);
492
607
                }
493
608
            }
494
609
 
495
 
 
496
610
        } else {
 
611
 
497
612
            // if :80 is in the URL, cut it out
498
613
            strlcpy(localitem, item, 1024);
499
614
            tmp = strstr(localitem, ":8080");
520
635
                        }
521
636
                    }
522
637
                }
 
638
                // check and see if the file exists, if it does not then prepend smb:// to the filename
 
639
                if (fexists(localitem) == 0) {
 
640
                    strlcpy(tmpdir, "smb://", 1024);
 
641
                    strlcat(tmpdir, localitem, 1024);
 
642
                    strlcpy(localitem, tmpdir, 1024);
 
643
                }
 
644
 
523
645
            }
 
646
 
524
647
        }
 
648
 
525
649
    } else {
 
650
 
526
651
        strlcpy(localitem, item, 1024);
 
652
 
527
653
    }
528
654
 
529
655
    if (DEBUG >= 2)
530
656
        printf("fqu result: %s\n", localitem);
 
657
 
531
658
}
532
659
 
533
660
int toolkitOk(NPP instance, int *mozilla_toolkit, int *plugin_toolkit)