File: plugin-support.cpp

package info (click to toggle)
mplayerplug-in 3.55-1.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,880 kB
  • ctags: 914
  • sloc: cpp: 12,866; ansic: 2,019; sh: 146; makefile: 137
file content (814 lines) | stat: -rw-r--r-- 17,372 bytes parent folder | download
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
#include "plugin.h"
#include <strings.h>
#include <errno.h>
#include <sys/wait.h>

extern int errno;
extern int DEBUG;

void lowercase(char string[])
{
    int i = 0;

    if (DEBUG > 1)
	printf("in lowercase\n");

    while (string[i]) {
	string[i] = tolower(string[i]);
	i++;
    }

    return;
}

void unEscapeXML(char *string)
{
//    char *p;

    if (DEBUG > 1)
	printf("in unHTML\n");

//    while ((p = strstr(string, "&amp;")) != NULL) {
//	strcpy(p + 1, p + 5);
//    }

    return;
}

int fexists(char *file)
{

    FILE *fp;

    if (DEBUG > 1)
	printf("in fexists\n");

    if (file == NULL)
	return 0;

    fp = fopen(file, "r");
    if (fp != NULL) {
	fclose(fp);
	return 1;
    } else {
	return 0;
    }

}

char *getURLHostname(char *url)
{

    char *hostname;
    char *loc;
    int i, len;

    if (DEBUG > 1)
	printf("entering getURLHostname\n");

    if (url == NULL)
	return NULL;
    len = strlen(url);
    if (len == 0)
	return NULL;
    hostname = (char *) NPN_MemAlloc(sizeof(char) * (len + 1));
    strcpy(hostname, url);

    loc = strstr(url, "://");
    if (loc == NULL) {
	NPN_MemFree(hostname);
	return NULL;
    }
    loc = loc + 3;

    i = 0;

    while (loc[0] != '/') {
	hostname[i] = loc[0];
	loc++;
	i++;
	if (i > len) {
	    i = 0;
	    break;
	}
    }
    if (i == 0) {
	NPN_MemFree(hostname);
	hostname = NULL;
    } else {
	hostname[i] = '\0';
    }
    if (DEBUG > 1)
	printf("exiting getURLHostname with %s\n", hostname);

    return hostname;

}

char *getURLFilename(const char *url)
{

    char *filename;
    char *tmp;
    int len;

    if (DEBUG > 1)
	printf("in getURLFilename\n");

    if (url == NULL)
	return NULL;
    len = strlen(url);
    if (len == 0)
	return NULL;
    filename = (char *) NPN_MemAlloc(sizeof(char) * (len + 1));
    tmp = rindex(url, '/');
    if (tmp == NULL) {
	strcpy(filename, url);
	return filename;
    }
    strcpy(filename, tmp + 1);	// take everything upto, but not including the / starting from the right.
    return filename;
}

char *getURLBase(char *url)
{

    char *base;
    int i, len;

    if (DEBUG > 1)
	printf("in getURLBase\n");

    if (url == NULL)
	return NULL;
    len = strlen(url);
    if (len == 0)
	return NULL;
    base = (char *) NPN_MemAlloc(sizeof(char) * (len + 1));
    strcpy(base, url);
    if (DEBUG > 1)
	printf("in getURLBase base: %s\n", base);

    for (i = len - 1; i >= 0; i--) {
	if (base[i] != '/') {
	    base[i] = '\0';
	} else {
	    break;
	}
    }
    if ((strlen(base) == 0) || (i <= 0)) {
	NPN_MemFree(base);
	base = NULL;
    }
    if (base != NULL) {
	if (DEBUG)
	    printf("exiting URL base with %s\n", base);
    } else {
	if (DEBUG)
	    printf("exiting URL base with NULL\n");
    }
    return base;
}

int isMms(char *url, int nomediacache)
{
    if (url == NULL)
	return 0;
    if ((strncasecmp(url, "mms://", 6) == 0)
	|| (strncasecmp(url, "mmst://", 7) == 0)
	|| (strncasecmp(url, "mmsu://", 7) == 0)
	|| (strncasecmp(url, "dvd://", 6) == 0)
	|| (strncasecmp(url, "smb://", 6) == 0)
	|| (strncasecmp(url, "tv://", 5) == 0)
	|| (strncasecmp(url, "pnm://", 6) == 0)
	|| (strncasecmp(url, "rtsp://", 7) == 0)) {
	if (DEBUG > 1)
	    printf("isMms = true\n");
	return 1;
    } else {
	if (nomediacache) {
	    if ((strncasecmp(url, "file://", 7) == 0)
		|| (strncasecmp(url, "smb://", 6) == 0)
		|| fexists(url)) {
		if (DEBUG > 1)
		    printf("isMms = false\nurl = %s\n", url);
		return 0;

	    } else {
		if (DEBUG > 1)
		    printf("isMms = true\n");
		return 1;
	    }

	} else {
	    if (DEBUG > 1)
		printf("isMms = false\nurl = %s\n", url);
	    return 0;
	}
    }
}

void mmsToHttp(char *dest, char *src)
{
    char *temp;

    if (strncasecmp(src, "mms", 3) == 0) {
	temp = (char *) NPN_MemAlloc(sizeof(char) * (strlen(src) + 1 +
						     sizeof("http") -
						     sizeof("mms")));
	strcpy(temp, "http");
	strcat(temp, src + 3);
	strcpy(dest, temp);
	NPN_MemFree(temp);
    }
    return;
}



int URLcmp(const char *url1, const char *url2)
{
    char *buffer1, *buffer2;
    char *tmp1;
    char *tmp2;
    char *q1;			// question mark in tmp
    char *q2;			// question mark in tmp2
    int tmp1hasq = 0;		// tmp1 has a ?
    int tmp2hasq = 0;		// tmp2 has a ?
    char *hostname1 = NULL;	// hostname1
    char *hostname2 = NULL;	// hostname2
    char *protocol1 = NULL;
    char *protocol2 = NULL;
    int ret;

    if (DEBUG > 1)
	printf("in URLcmp\n");

    if (strcmp(url1, url2) == 0)
	return 0;

    // replace %20 with spaces in both strings
    buffer1 = strdup(url1);
    buffer2 = strdup(url2);

    while ((tmp1 = strstr(buffer1, "%20"))) {
	if (tmp1 != NULL) {
	    *tmp1 = ' ';
	    tmp1++;
	    *tmp1 = '\0';
	    strcat(buffer1, tmp1 + 2);
	}
    }

    while ((tmp1 = strstr(buffer2, "%20"))) {
	if (tmp1 != NULL) {
	    *tmp1 = ' ';
	    tmp1++;
	    *tmp1 = '\0';
	    strcat(buffer2, tmp1 + 2);
	}
    }

    if (strcmp(buffer1, buffer2) == 0) {
	//if (DEBUG) printf("URL's match\n buffer1 %s len:%i\n buffer2 %s len %i\n",buffer1,strlen(buffer1),buffer2,strlen(buffer2));
	free(buffer1);
	free(buffer2);
	ret = 0;
    } else {
	//if (DEBUG) printf("URL's don't match\n buffer1 %s len:%i\n buffer2 %s len%i\n",buffer1,strlen(buffer1),buffer2,strlen(buffer2));
	ret = -1;
    }

    if (strncasecmp(buffer1, "file://", 7) == 0) {
	if (strcmp(buffer1 + 7, buffer2) == 0) {
	    free(buffer1);
	    free(buffer2);
	    ret = 0;
	}
    }

    if (strncasecmp(buffer2, "file://", 7) == 0) {
	if (strcmp(buffer1, buffer2 + 7) == 0) {
	    free(buffer1);
	    free(buffer2);
	    ret = 0;
	}
    }

    if (ret == -1) {
	hostname1 = getURLHostname(buffer1);
	hostname2 = getURLHostname(buffer2);

	if (hostname1 != NULL && hostname2 != NULL
	    && strstr(hostname2, hostname1) == NULL) {
	    // hostname1 is a not substring of hostname2
	    // this is done for the case where the playlist has two urls that basically point to the same site
	    // one of the sites is an internal URL and the other is an external. We want to be able to play either
	    // site. So as long as the hostnames are completly different we should be ok. 
	    if (DEBUG > 1)
		printf("URLcmp: hostnames do not match\n");
	    ret = -1;
	} else {
	    // url1 is a substring of url2, so continue comparing
	    if (DEBUG > 1)
		printf("hostname1 = %s\nhostname2 = %s\n", hostname1,
		       hostname2);
	    // compare the paths, some sites change the hostname mid stream (like cartoonnetwork.com -> www.cartoonnetwork.com);
	    tmp1 = strstr(buffer1, "://");
	    if (tmp1 != NULL) {
		protocol1 =
		    (char *) malloc((long) tmp1 - (long) buffer1 + 1);
		strncpy(protocol1, buffer1,
			(long) tmp1 - (long) buffer1 + 1);
		protocol1[(long) tmp1 - (long) buffer1] = '\0';
	    }

	    if (DEBUG > 1)
		printf("protocol1: %s\n", protocol1);

	    if (tmp1 != NULL) {
		tmp1 = tmp1 + 3;
		while (tmp1[0] != '/') {
		    if (tmp1[0] == '\0')
			break;
		    tmp1++;
		}
	    }
	    tmp2 = strstr(buffer2, "://");
	    if (tmp2 != NULL) {
		protocol2 =
		    (char *) malloc((long) tmp2 - (long) buffer2 + 1);
		strncpy(protocol2, buffer2,
			(long) tmp2 - (long) buffer2 + 1);
		protocol2[(long) tmp2 - (long) buffer2] = '\0';
	    }

	    if (DEBUG > 1)
		printf("protocol2: %s\n", protocol2);

	    if (tmp2 != NULL) {
		tmp2 = tmp2 + 3;
		while (tmp2[0] != '/') {
		    if (tmp2[0] == '\0')
			break;
		    tmp2++;
		}
	    }
	    if (tmp1 != NULL && tmp2 != NULL) {
		if (strcmp(tmp1, tmp2) == 0) {
		    // if either protocol is file:// then they are the same at this point usually one will be NULL and the other file://
		    if ((strncmp(protocol1, "file://", 7) == 0)
			|| (strncmp(protocol2, "file://", 7) == 0)) {
			ret = 0;
		    } else {
			// NetFlix puts out the same preview on multiple protocols, we have to add them all to the playlist
			if (strcmp(protocol1, protocol2) == 0) {
			    ret = 0;
			} else {
			    ret = -1;
			}
		    }
		} else {
		    ret = -1;
		    q1 = strchr(tmp1, '?');
		    q2 = strchr(tmp2, '?');
		    if (q1 != NULL || q2 != NULL) {
			if (q1 != NULL) {
			    q1[0] = '\0';
			    tmp1hasq = 1;
			}
			if (q2 != NULL) {
			    q2[0] = '\0';
			    tmp2hasq = 1;
			}
			if (strcmp(tmp1, tmp2) == 0) {
			    if (tmp1hasq != tmp2hasq) {
				ret = -1;
			    } else {
				if (strcmp(q1 + 1, q2 + 1) == 0) {
				    ret = 0;
				} else {
				    ret = -1;
				}
			    }
			} else {
			    ret = -1;
			}
		    }
		}
	    }
	}
	free(buffer1);
	free(buffer2);

    }
    if (hostname1 != NULL)
	NPN_MemFree(hostname1);
    if (hostname2 != NULL)
	NPN_MemFree(hostname2);
    if (protocol1 != NULL)
	free(protocol1);
    if (protocol2 != NULL)
	free(protocol2);

    if (DEBUG > 1)
	printf("exiting URLcmp\n");

    return ret;

}

// Remove all single quotes from url to prevent remote execution
void remove_quotes(char *url)
{
    char *p;

    if (DEBUG > 1)
	printf("in remove_quotes\n");

    // don't scan the string if it not in there, this should be a bit faster than the while loop

    if (url == NULL)
	return;

    p = strchr(url, '`');

    if (p == NULL) {
	return;
    } else {
	if (DEBUG) {
	    printf("single quotes in url (%s), truncating\n"
		   "WARNING: probably won't work! FIXME!\n", url);
	}
	*p = '\0';
    }
}



//  sendCommand is safe to use only with control_mutex held
//  (and in player thread surounded by cleanup_push/cleanup_pop)

// command will be ignored if js_state is JS_STATE_TRANSITIONING

// in cleanup routines (like destroyCB and shut), when we know that
// the player thread is not running, it is safe to call without locking

int sendCommand(nsPluginInstance * instance, char *command)
{
    int retval;
    char buffer[1024];

    if (DEBUG > 1)
	printf("in sendcommand - command %s\n", command);

    buffer[1023] = '\0';
    retval = 0;

    if (command == NULL || instance == NULL || instance->cancelled == 1)
	return 0;

    if (instance->threadsignaled == 0)
	return 0;

    if (instance->control == -1)
	return 0;


    if (instance->js_state != JS_STATE_TRANSITIONING) {

	snprintf(buffer, 1023, "%s\n", command);

	retval = write(instance->control, buffer, strlen(buffer));
	//operations on pipes are atomic

	if (retval < (int) strlen(buffer)) {
	    if (DEBUG)
		printf("*****sendCommand Truncated*****\n");

	}

    }

    return retval;

}

void killmplayer(nsPluginInstance * instance)
{
    void *thread_return;
    int count, status;

    if (DEBUG > 1)
	printf("in killmplayer\n");

    if (instance->paused == 1)
	sendCommand(instance, "pause\n");
    sendCommand(instance, "quit\n");
    pthread_mutex_lock(&(instance->read_mutex));
    instance->cancelled = 1;
    pthread_mutex_unlock(&(instance->read_mutex));

/*    count = 0;
    while (count < 500) {
	if (DEBUG)
	    printf("waiting for quit to be handled\n");
	usleep(100);
	count++;
    	if (instance->player == NULL)
	    break;
    }
*/
    //we can do the following twice on the same thread with no ill effects
    pthread_cancel(instance->player_thread);
    pthread_join(instance->player_thread, &thread_return);
    instance->js_state = JS_STATE_UNDEFINED;

    if (DEBUG)
	printf
	    ("Trying to kill mplayer process(%d), if it still exists\n",
	     instance->pid);

    count = 0;
    while (instance->player != NULL && count < 10) {
	if (DEBUG)
	    printf("waiting for player to go NULL\n");
	usleep(100);
	count++;
    }


    if (instance->player == NULL) {
	instance->pid = 0;
    } else {
	if (DEBUG > 1)
	    printf("closing player\n");
	if (instance->player != NULL) {
            fclose(instance->player);
	}
	instance->player = NULL;

	if (DEBUG > 1)
	    printf("closing control pipe\n");
	if (instance->control > 0) {
	    close(instance->control);
	    instance->control = -1;
	}
    }

    if (DEBUG > 1)
	printf("player should be closed\n");

    instance->threadlaunched = 0;

    if (instance->pid != 0) {
	count = 0;
	status = 1;

	while ((status != 0) && (count < 10)) {
	    status = kill(instance->pid, 15);
	    if (DEBUG)
		printf("kill(15) status = %i\n", status);
	    if (status == -1) {
		if (errno == ESRCH) {
		    status = 0;
		    break;
		}

		usleep(100);
	    }
	    count++;
	}

	if (status != 0) {
	    status = kill(instance->pid, 9);
	    if (DEBUG)
		printf("kill(9) status = %i\n", status);
	    if (status == 0) {
		instance->pid = 0;
	    }
	}
	//wait(&status);
    }
#ifdef DPMSExtension
    if (instance->DPMSEnabled)
	DPMSReenable(instance);
#endif

    if (instance->threadsetup == 1) {
	count = 0;
	while (count < 50) {
	    if (instance->td->argv[count] != NULL)
		free(instance->td->argv[count]);
	    instance->td->argv[count++] = NULL;
	}
	instance->threadsetup = 0;
#ifdef GTK_ENABLED
//      if (GTK_IS_WIDGET(instance->drawing_area)) {
//          gtk_widget_destroy(instance->drawing_area);
//          instance->drawing_area = NULL;
//      }
#endif
    }
}

void fullyQualifyURL(nsPluginInstance * instance, char *initem,
		     char *localitem)
{
    char tmpdir[4096];
    char *tmp;
    char *item;

    if (DEBUG > 1)
	printf("in fullyQualifyURL\n");

    item = strdup(initem);

    tmp = strstr(item, "<");
    if (tmp != NULL) {
	strlcpy(item, tmp + 1, 4096);
	tmp = strstr(item, ">");
	if (DEBUG > 1)
	    printf("item = %p tmp = %p   diff = %i\n", item, tmp,
		   (tmp - item));
	if (tmp != NULL) {
	    strlcpy(tmp, "", 4096);
	}
	if (DEBUG > 1)
	    printf("item = %s\n", item);
    }

    if (DEBUG > 1)
	printf("item: %s\nbaseurl: %s\nhostname: %s\n",
	       item, instance->baseurl, instance->hostname);

    if (!isMms(item, instance->nomediacache)) {
	if ((strncasecmp(item, "http", 4) != 0)
	    && (strncasecmp(item, "file", 4) != 0)) {

	    if (DEBUG > 1)
		printf("not http and not file\n");

	    if (item[0] != '/') {
		strlcpy(tmpdir, item, 4096);	// reuse the buffer
		if (instance->baseurl != NULL) {
		    strlcpy(localitem, instance->baseurl, 4096);
		} else {
		    strlcpy(localitem, "", 4096);
		}
		strlcat(localitem, tmpdir, 4096);
	    } else {
		if (instance->hostname != NULL) {
		    if (fexists(item) == 0) {
			snprintf(tmpdir, 4096, "http://%s%s",
				 instance->hostname, item);
			strlcpy(localitem, tmpdir, 4096);
		    } else {
			// first char == / and hostname is null, sounds like a filename
			strlcpy(localitem, item, 4096);
		    }
		} else {
		    // first char == / and hostname is null, sounds like a filename
		    strlcpy(localitem, item, 4096);
		}
	    }

	} else {

	    // if :80 is in the URL, cut it out
	    strlcpy(localitem, item, 4096);
	    tmp = strstr(localitem, ":8080");
	    if (tmp == NULL) {
		tmp = strstr(localitem, ":80/");
		if (tmp != NULL) {
		    *tmp = '\0';
		    strlcat(localitem, tmp + 3, 4096);
		}
	    }


	    if (strncasecmp(localitem, "file://", 7) == 0) {
		// chop off file://
		strlcpy(tmpdir, localitem, 4096);
		strlcpy(localitem, tmpdir + 7, 4096);
		// replace %20's in url with a space
		if (strstr(localitem, "%20") != NULL) {
		    while ((tmp = strstr(localitem, "%20"))) {
			if (tmp != NULL) {
			    *tmp = ' ';
			    tmp++;
			    *tmp = '\0';
			    strcat(localitem, tmp + 2);
			}
		    }
		}
		// check and see if the file exists, if it does not then prepend smb:// to the filename
		if (fexists(localitem) == 0) {
		    strlcpy(tmpdir, "smb://", 4096);
		    strlcat(tmpdir, localitem, 4096);
		    strlcpy(localitem, tmpdir, 4096);
		}

	    }

	}

    } else {

	strlcpy(localitem, item, 4096);

    }

    free(item);
    if (DEBUG > 1)
	printf("fqu result: %s\n", localitem);

}

int toolkitOk(NPP instance, int *mozilla_toolkit, int *plugin_toolkit)
{

#ifdef X_ENABLED
    *plugin_toolkit = 0;
#endif

#ifdef GTK1_ENABLED
    *plugin_toolkit = 1;
#endif

#ifdef GTK2_ENABLED
    *plugin_toolkit = 2;
#endif

    if (DEBUG)
	printf("checking toolkit\n");
    NPN_GetValue(instance, NPNVToolkit, mozilla_toolkit);

    if (DEBUG)
	printf("toolkitOk? mozilla = %i, plugin = %i\n", *mozilla_toolkit,
	       *plugin_toolkit);

#ifdef OO_GTK2_ENABLED

    // this is an openoffice workaround, but it does not seem to work.
    if (*mozilla_toolkit == 0) {
	if (DEBUG)
	    printf("initializing GDK/GTK\n");
	//g_type_init();
	//gdk_init(NULL,NULL);
	gtk_init(NULL, NULL);
	gtk_main();
    }
#endif

    if (*mozilla_toolkit == 0 || *mozilla_toolkit == 1
	|| *mozilla_toolkit == 2) {

	if (*plugin_toolkit == 0 || *mozilla_toolkit == 0
	    || (*mozilla_toolkit == *plugin_toolkit))
	    return 0;
	else
	    return 1;

    } else {
	printf("Unknown Mozilla toolkit (%i), assuming toolkit is GTK%i\n",
	       *mozilla_toolkit, *plugin_toolkit);
	printf
	    ("This may cause Mozilla to crash. If it crashes recompile mplayerplug-in with a different toolkit.\n");
	return 0;
    }
}

#ifdef DPMSExtension
int DPMSIsEnabled(nsPluginInstance * instance)
{
    int dummy;
    BOOL onoff;
    CARD16 state;

    if (DEBUG > 1)
	printf("Checking if DPMS is enabled\n");

    if (DPMSQueryExtension(instance->display, &dummy, &dummy)) {
	if (DPMSCapable(instance->display))
	    DPMSInfo(instance->display, &state, &onoff);
    }

    if (DEBUG > 1)
	printf("DPMS is enabled = %i\n", onoff);
    return onoff;
}

void DPMSReenable(nsPluginInstance * instance)
{
    int dummy;

    if (DEBUG > 1)
	printf("DPMS is enabled\n");

    if (DPMSQueryExtension(instance->display, &dummy, &dummy)) {
	if (DPMSCapable(instance->display))
	    DPMSEnable(instance->display);
    }
}
#endif