summaryrefslogtreecommitdiffstats
path: root/nsplugins/wrapper/wrapper.c
blob: 73421941316c21ad536afc765abd99e478c45fb8 (plain)
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
#include <stdio.h>
#include <string.h>

#include <X11/Xlib.h>
#include <X11/Xlibint.h>

#ifdef __hpux
#include <dl.h>
#else
#include <dlfcn.h>
#endif

#define XP_UNIX 1
#include "sdk/npupp.h"


NPNetscapeFuncs gNetscapeFuncs;	/* Netscape Function table */
NPNetscapeFuncs gExtNetscapeFuncs;	/* table that is passed to the plugin*/
NPPluginFuncs gPluginFuncs;

typedef char* NP_GetMIMEDescription_t(void);
typedef NPError NP_Initialize_t(NPNetscapeFuncs*, NPPluginFuncs*);
typedef NPError NP_Shutdown_t(void);
typedef NPError NP_GetValue_t(void *future, NPPVariable variable, void *value);

NP_GetMIMEDescription_t *gNP_GetMIMEDescription = NULL;
NP_Initialize_t *gNP_Initialize = NULL;
NP_Shutdown_t *gNP_Shutdown = NULL;
NP_GetValue_t *gNP_GetValue = NULL;

#ifdef __hpux
shl_t gLib;
#else
void *gLib = 0L;
#endif
FILE *ef = 0L;

#define DEB fprintf

static
void UnloadPlugin() {
#ifdef __hpux
   if (gLib) {
		DEB( ef, "-> UnloadPlugin\n" );
      shl_unload(gLib);
		DEB( ef, "<- UnloadPlugin\n" );
               
      gLib=0L;
   }
#else
	if ( gLib )	{
		DEB( ef, "-> UnloadPlugin\n" );
		dlclose( gLib );
		gLib = 0L;
		
		DEB( ef, "<- UnloadPlugin\n" );
		
		if (ef) fclose( ef );
	}
#endif
}

static
void LoadPlugin() {
	if ( !gLib ) {
		ef = fopen( "/tmp/plugin.log", "a" );
		DEB( ef, "-------------------------------\n" );
		fclose( ef );
		ef = fopen( "/tmp/plugin.log", "a" );
		setvbuf( ef, NULL, _IONBF, 0 );
		DEB( ef, "-> LoadPlugin\n" );
		
#ifdef __hpux
                gLib = shl_load("/tmp/plugin.so", BIND_IMMEDIATE, 0L);
                if (shl_findsym(&gLib, "/tmp/plugin.so", (short) TYPE_PROCEDURE, (void *) &gNP_GetMIMEDescription))
                   gNP_GetMIMEDescription = NULL;
                if (shl_findsym(&gLib, "/tmp/plugin.so", (short) TYPE_PROCEDURE, (void *) &gNP_Initialize))
                   gNP_Initialize = NULL;
                if (shl_findsym(&gLib, "/tmp/plugin.so", (short) TYPE_PROCEDURE, (void *) &gNP_Shutdown))
                   gNP_Shutdown = NULL;
                if (shl_findsym(&gLib, "/tmp/plugin.so", (short) TYPE_PROCEDURE, (void *) &gNP_GetValue))
                   gNP_GetValue = NULL;
#else
		gLib = dlopen( "/tmp/plugin.so", RTLD_NOW );
		DEB( ef, "gLib = %x\n", gLib );

		gNP_GetMIMEDescription = dlsym( gLib, "NP_GetMIMEDescription" );
		gNP_Initialize = dlsym( gLib, "NP_Initialize" );
		gNP_Shutdown = dlsym( gLib, "NP_Shutdown" );
		gNP_GetValue = dlsym( gLib, "NP_GetValue" );
#endif
		DEB( ef, "gNP_GetMIMEDescription = %x\n", NP_GetMIMEDescription );
		DEB( ef, "gNP_Initialize = %x\n", gNP_Initialize );
		DEB( ef, "gNP_Shutdown = %x\n", gNP_Shutdown );
		DEB( ef, "gNP_GetValue = %x\n", gNP_GetValue );
		
		if ( !gNP_GetMIMEDescription || !gNP_Initialize || !gNP_Initialize || !gNP_GetValue ) {
			DEB( ef, "<- LoadPlugin - will unload before\n" );
		 	UnloadPlugin();
		} else
				DEB( ef, "<- LoadPlugin\n" );
	}
}

extern char *NP_GetMIMEDescription(void);
char *NP_GetMIMEDescription(void)
{
	char * ret;
	
	LoadPlugin();
	if ( !gLib ) return NULL;	
	DEB(ef, "-> NP_GetMIMEDescription()\n" );
	
	ret = gNP_GetMIMEDescription();
	DEB(ef, "<- NP_GetMIMEDescription = %s\n", ret );
	return ret;
}

/*static
NPError MyNPP_Initialize(void)
{
	NPError err;	
	DEB(ef, "-> NPP_Initialize( )\n");
	
	err = gPluginFuncs.initialize( );
	DEB(ef, "<- NPP_Initialize = %d\n", err);
	return err;
}*/

/*static
void MyNPP_Shutdown(void)
{
	DEB(ef, "-> NPP_Shutdown( )\n");
	gPluginFuncs.shutdown( );
	DEB(ef, "<- NPP_Shutdown\n");
} */

static
NPError MyNPP_New(NPMIMEType pluginType, NPP instance,
                uint16 mode, int16 argc, char* argn[],
                char* argv[], NPSavedData* saved)
{
	NPError err;	
	int n;
	DEB(ef, "-> NPP_New( %s, 0x%x, %d, %d, .., .., 0x%x )\n", pluginType, instance, mode, argc, saved);

	for ( n=0; n<argc; n++ ) {
	    DEB(ef, "%s=%s\n", argn[n], argv[n] );
	}

	err = gPluginFuncs.newp( pluginType, instance, mode, argc, argn, argv, saved );
	DEB(ef, "<- NPP_New = %d\n", err);
	return err;
}

static
NPError MyNPP_Destroy(NPP instance, NPSavedData** save)
{
	NPError err;	
	DEB(ef, "-> NPP_Destrpy( %x, 0x%x )\n", instance, save);
	
	err = gPluginFuncs.destroy( instance, save );
	DEB(ef, "<- NPP_Destroy = %d\n", err);
	return err;
}

static
NPError MyNPP_SetWindow(NPP instance, NPWindow* window)
{
	NPError err;	
	NPSetWindowCallbackStruct *win_info;
	DEB(ef, "-> NPP_SetWindow( %x, 0x%x )\n", instance, window);
	
	DEB(ef, "window->window = 0x%x\n", window->window);
	DEB(ef, "window->x = %d\n", window->x);
	DEB(ef, "window->y = %d\n", window->y);
	DEB(ef, "window->width = %d\n", window->width);
	DEB(ef, "window->height = %d\n", window->height);
	DEB(ef, "window->ws_info = 0x%x\n", window->ws_info);
	DEB(ef, "window->type = 0x%x\n", window->type);
		
	win_info = (NPSetWindowCallbackStruct*)window->ws_info;
	DEB(ef, "win_info->type = %d\n", win_info->type);
	DEB(ef, "win_info->display = 0x%x\n", win_info->display);
	DEB(ef, "win_info->visual = 0x%x\n", win_info->visual);
 	DEB(ef, "win_info->colormap = 0x%x\n", win_info->colormap);
  	DEB(ef, "win_info->depth = %d\n", win_info->depth);
	
	err = gPluginFuncs.setwindow( instance, window );	
	DEB(ef, "<- NPP_SetWindow = %d\n", err);
	return err;
}

static
NPError MyNPP_NewStream(NPP instance, NPMIMEType type,
        	            NPStream* stream, NPBool seekable,
          	          uint16* stype)
{
	NPError err;	
	DEB(ef, "-> NPP_NewStream( %x, %s, 0x%x, %d, 0x%x )\n", instance, type, stream, seekable, stype);

	DEB(ef, "stream->ndata = 0x%x\n", stream->ndata);
	DEB(ef, "stream->url = %s\n", stream->url );
        DEB(ef, "stream->end = %d\n", stream->end );
	DEB(ef, "stream->pdata = 0x%x\n", stream->pdata );
	DEB(ef, "stream->lastmodified = %d\n", stream->lastmodified );
	DEB(ef, "stream->notifyData = 0x%x\n", stream->notifyData );
	
	err = gPluginFuncs.newstream( instance, type, stream, seekable, stype );		
	DEB(ef, "<- NPP_NewStream = %d\n", err);
	DEB(ef, "stype = %d\n", *stype);	
	return err;
}
          	
static
NPError MyNPP_DestroyStream(NPP instance, NPStream* stream,
		                      NPReason reason)
{
	NPError err;	
	DEB(ef, "-> NPP_DestroyStream( %x, 0x%x, %d )\n", instance, stream, reason);	
	
	err = gPluginFuncs.destroystream( instance, stream, reason );		
	DEB(ef, "<- NPP_DestroyStream = %d\n", err);
	return err;
}		

static
int32 MyNPP_WriteReady(NPP instance, NPStream* stream)
{
	int32 ret;	
	DEB(ef, "-> NPP_WriteReady( %x, 0x%x )\n", instance, stream);	
	
	ret = gPluginFuncs.writeready( instance, stream );		
	DEB(ef, "<- NPP_WriteReady = %d\n", ret);
	return ret;
}

static
int32 MyNPP_Write(NPP instance, NPStream* stream, int32 offset,
                  int32 len, void* buffer)
{
	int32 ret;	
	DEB(ef, "-> NPP_Write( %x, 0x%x, %d, %d, 0x%x )\n", instance, stream, offset, len, buffer);	
	
	ret = gPluginFuncs.write( instance, stream, offset, len, buffer );		
	DEB(ef, "<- NPP_Write = %d\n", ret);
	return ret;
}

static
void MyNPP_StreamAsFile(NPP instance, NPStream* stream,
                     const char* fname)
{	
	DEB(ef, "-> NPP_StreamAsFile( %x, 0x%x, %s )\n", instance, stream, fname);	
	
	gPluginFuncs.asfile( instance, stream, fname );		
	DEB(ef, "<- NPP_StreamAsFile\n");
}

static
void MyNPP_Print(NPP instance, NPPrint* platformPrint)
{
	DEB(ef, "-> NPP_Print( %x, 0x%x )\n", instance, platformPrint );		
	gPluginFuncs.print( instance, platformPrint );		
	DEB(ef, "<- NPP_Print\n");	
}

static
int16 MyNPP_HandleEvent(NPP instance, void* event)
{
	int16 ret;
	DEB(ef, "-> NPP_HandleEvent( %x, 0x%x )\n", instance, event);	
	
	ret = gPluginFuncs.event( instance, event );		
	DEB(ef, "<- NPP_HandleEvent = %d\n", ret);
	return ret;
}

static
void MyNPP_URLNotify(NPP instance, const char* url,
                    NPReason reason, void* notifyData)
{	
	DEB(ef, "-> NPP_URLNotify( %x, %s, %d, 0x%x )\n", instance, url, reason, notifyData );	
	gPluginFuncs.urlnotify( instance, url, reason, notifyData );		
	DEB(ef, "<- NPP_URLNotify\n");	
}

#if 0
static
jref MyNPP_GetJavaClass(void)
{
  jref ret;
	DEB(ef, "-> NPP_GetJavaClass( )\n" );	
	
/*	ret = gPluginFuncs.javaClass( );*/
	DEB(ef, "<- NPP_GetJavaClass = %d\n", ret);
	return ret;
}
#endif

static
NPError MyNPP_GetValue(void *instance, NPPVariable variable, void *value)
{
	NPError err;	
	DEB(ef, "-> NPP_GetValue( %x, %d, 0x%x )\n", instance, variable, value);	
	
	err = gPluginFuncs.getvalue( instance, variable, value );			
	DEB(ef, "<- NPP_GetValue = %d\n", err);
	return err;
}

static
NPError MyNPP_SetValue(void *instance, NPNVariable variable, void *value)
{
	NPError err;	
	DEB(ef, "-> NPP_SetValue( %x, %d, 0x%x )\n", instance, variable, value);	
	
	err = gPluginFuncs.getvalue( instance, variable, value );		
	DEB(ef, "<- NPP_SetValue = %d\n", err);
	return err;
}

/*static
void MyNPN_Version(int* plugin_major, int* plugin_minor,
              int* netscape_major, int* netscape_minor)
{	
	DEB(ef, "-> NPN_Version( %d, %d, %d, %d )\n", *plugin_major, *plugin_minor, *netscape_major, *netscape_minor);	
	
	gNetscapeFuncs.version( plugin_major, plugin_minor, netscape_major, netscape_minor );		
	DEB(ef, "<- NPN_Version\n");	
	DEB(ef, "plugin_major = %d\n", *plugin_major);
	DEB(ef, "plugin_minor = %d\n", *plugin_minor);
	DEB(ef, "netscape_major = %d\n", *plugin_major);
	DEB(ef, "netscape_minor = %d\n", *plugin_minor);
}*/

static
NPError MyNPN_GetURLNotify(NPP instance, const char* url,
                 const char* target, void* notifyData)
{
	NPError err;	
	DEB(ef, "-> NPN_GetURLNotify( %x, %s, %s, 0x%x )\n", instance, url, target, notifyData);	
	
	err = gNetscapeFuncs.geturlnotify( instance, url, target, notifyData );		
	DEB(ef, "<- NPN_GetURLNotify = %d\n", err);
	return err;
}

static
NPError MyNPN_GetURL(NPP instance, const char* url,
               const char* target)
{
	NPError err;	
	DEB(ef, "-> NPN_GetURL( %x, %s, %s )\n", instance, url, target );	
	
	err = gNetscapeFuncs.geturl( instance, url, target );		
	DEB(ef, "<- NPN_GetURL = %d\n", err);
	return err;
}

static
NPError MyNPN_PostURLNotify(NPP instance, const char* url,
                  const char* target, uint32 len,
                  const char* buf, NPBool file,
                  void* notifyData)
{
	NPError err;	
	DEB(ef, "-> NPN_PostURLNotify( %x, %s, %s, %d, 0x%x, %d, 0x%x )\n", instance, url, target, len, buf, file, notifyData);	
	
	err = gNetscapeFuncs.posturlnotify( instance, url, target, len, buf, file, notifyData );		
	DEB(ef, "<- NPN_PostURLNotify = %d\n", err);
	return err;
}

static
NPError MyNPN_PostURL(NPP instance, const char* url,
              const char* target, uint32 len,
              const char* buf, NPBool file)
{
	NPError err;	
	DEB(ef, "-> NPN_PostURL( %x, %s, %s, %d, 0x%x, %d )\n", instance, url, target, len, buf, file );	
	
	err = gNetscapeFuncs.posturl( instance, url, target, len, buf, file  );		
	DEB(ef, "<- NPN_PostURL = %d\n", err);
	return err;
}

static
NPError MyNPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{
	NPError err;	
	DEB(ef, "-> NPN_RequestRead( %x, 0x%x )\n", stream, rangeList );	
	DEB(ef, "rangeList->offset = %d\n", rangeList->offset);
	DEB(ef, "rangeList->length = %d\n", rangeList->length);
	DEB(ef, "rangeList->next = 0x%x\n", rangeList->next);
	
	err = gNetscapeFuncs.requestread( stream, rangeList );		
	DEB(ef, "<- NPN_RequestRead = %d\n", err);
	DEB(ef, "rangeList->offset = %d\n", rangeList->offset);
	DEB(ef, "rangeList->length = %d\n", rangeList->length);
	DEB(ef, "rangeList->next = 0x%x\n", rangeList->next);
	return err;
}

static
NPError MyNPN_NewStream(NPP instance, NPMIMEType type,
                const char* target, NPStream** stream)
{
	NPError err;	
	DEB(ef, "-> NPN_NewStream( %x, %s, %s, 0x%x )\n", instance, type, target, stream);
	
	err = gNetscapeFuncs.newstream( instance, type, target, stream );		
	DEB(ef, "<- NPN_NewStream = %d\n", err);
	return err;
}

static
int32 MyNPN_Write(NPP instance, NPStream* stream, int32 len,
              void* buffer)
{
	int32 ret;	
	DEB(ef, "-> NPN_Write( %x, 0x%x, %d, 0x%x )\n", instance, stream, len, buffer);	
	
	ret = gNetscapeFuncs.write( instance, stream, len, buffer );		
	DEB(ef, "<- NPN_Write = %d\n", ret);
	return ret;
}

static
NPError MyNPN_DestroyStream(NPP instance, NPStream* stream,
                  NPReason reason)
{
	NPError err;	
	DEB(ef, "-> NPN_DestroyStream( %x, 0x%x, %d )\n", instance, stream, reason);	
	
	err = gNetscapeFuncs.destroystream( instance, stream, reason );		
	DEB(ef, "<- NPN_DestroyStream = %d\n", err);
	return err;
}

static
void MyNPN_tqStatus(NPP instance, const char* message)
{	
	DEB(ef, "-> NPN_tqStatus( %x, %s )\n", instance, message);	
	gNetscapeFuncs.status( instance, message );		
	DEB(ef, "<- NPN_tqStatus\n");	
}

static
const char* MyNPN_UserAgent(NPP instance)
{
	const char *ret;
	DEB(ef, "-> NPN_UserAgent( %x )\n", instance);	
	
	ret = gNetscapeFuncs.uagent( instance );		
	DEB(ef, "<- NPN_UserAgent = %s\n", ret);
	return ret;
}

static
void* MyNPN_MemAlloc(uint32 size)
{
	void *ret;
	DEB(ef, "-> NPN_MemAlloc( %d )\n", size);	

	ret = gNetscapeFuncs.memalloc( size );		
	DEB(ef, "<- NPN_MemAlloc = 0x%x\n", ret);
	return ret;
}

static
void MyNPN_MemFree(void* ptr)
{	
	DEB(ef, "-> NPN_MemFree( 0x%x )\n", ptr);	
	gNetscapeFuncs.memfree( ptr );		
	DEB(ef, "<- NPN_MemFree\n");
}

static
uint32 MyNPN_MemFlush(uint32 size)
{
	uint ret;
	DEB(ef, "-> NPN_MemFlush( %d )\n", size);	

	ret = gNetscapeFuncs.memflush( size );		
	DEB(ef, "<- NPN_MemFlush = %d\n", ret);
	return ret;
}

static
void MyNPN_ReloadPlugins(NPBool reloadPages)
{	
	DEB(ef, "-> NPN_ReloadPlugins( %d )\n", reloadPages);	
	gNetscapeFuncs.reloadplugins( reloadPages );		
	DEB(ef, "<- NPN_ReloadPlugins\n");
}

static
JRIEnv* MyNPN_GetJavaEnv(void)
{
	JRIEnv *ret;
	DEB(ef, "-> NPN_GetJavaEnv( )\n");	

	ret = gNetscapeFuncs.getJavaEnv( );		
	DEB(ef, "<- NPN_GetJavaEnv = 0x%x\n", ret);
	return ret;
}

static
jref MyNPN_GetJavaPeer(NPP instance)
{
	jref ret;
	DEB(ef, "-> NPN_GetJavaPeer( %x )\n", instance);	

	ret = gNetscapeFuncs.getJavaPeer( instance );		
	DEB(ef, "<- NPN_GetJavaPeer = 0x%x\n", ret);
	return ret;	
}

static
NPError MyNPN_GetValue(NPP instance, NPNVariable variable,
               void *value)
{
	NPError ret;
	DEB(ef, "-> NPN_GetValue( %x, %d, 0x%x)\n", instance, variable, value);		
	ret = gNetscapeFuncs.getvalue( instance, variable, value );
	DEB(ef, "<- NPN_GetValue = %d\n", ret);
	return ret;
}

static
NPError MyNPN_SetValue(NPP instance, NPPVariable variable,
               void *value)
{
	NPError ret;
	DEB(ef, "-> NPN_SetValue( %x, %d, 0x%x)\n", instance, variable, value);	

	ret = gNetscapeFuncs.setvalue( instance, variable, value );		
	DEB(ef, "<- NPN_SetValue = %d\n", ret);
	return ret;
}

static
void MyNPN_InvalidateRect(NPP instance, NPRect *invalidRect)
{
	DEB(ef, "-> NPN_InvalidateRect( %x, 0x%x )\n", instance, invalidRect);	
	gNetscapeFuncs.tqinvalidaterect( instance, invalidRect );		
	DEB(ef, "<- NPN_InvalidateRect\n");	
}

static
void MyNPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
{
	DEB(ef, "-> NPN_InvalidateRegion( %x, 0x%x )\n", instance, invalidRegion);	
	gNetscapeFuncs.tqinvalidateregion( instance, invalidRegion );		
	DEB(ef, "<- NPN_InvalidateRegion\n");	
}

static
void MyNPN_ForceRedraw(NPP instance)
{
	DEB(ef, "-> NPN_ForceRedraw( %x )\n", instance);	
	gNetscapeFuncs.forceredraw( instance );		
	DEB(ef, "<- NPN_ForceRedraw\n");	
}

extern NPError NP_GetValue(void *future, NPPVariable variable, void *value);
NPError NP_GetValue(void *future, NPPVariable variable, void *value)
{
	NPError err;
	LoadPlugin();	
	if ( !gLib ) return NPERR_GENERIC_ERROR;
	DEB(ef, "-> NP_GetValue( %x, %d, %x )\n", future, variable, value );

	err = gNP_GetValue( future, variable, value );
	DEB(ef, "<- NP_GetValue = %d\n", err );
	return err;
}

extern NPError NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs);
NPError NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
{	
	NPError err;
	LoadPlugin();
	if ( !gLib ) return NPERR_GENERIC_ERROR;	
	DEB(ef, "-> NP_Initialize( %x, %x )\n", nsTable, pluginFuncs );
	
	DEB(ef, "nsTable->size = %d\n", nsTable->size);
	DEB(ef, "nsTable->version = 0x%x\n", nsTable->version);
	DEB(ef, "nsTable->geturl = 0x%x\n", nsTable->geturl);
	DEB(ef, "nsTable->posturl = 0x%x\n", nsTable->posturl);
	DEB(ef, "nsTable->requestread = 0x%x\n", nsTable->requestread);
	DEB(ef, "nsTable->newstream = 0x%x\n", nsTable->newstream);
	DEB(ef, "nsTable->write = 0x%x\n", nsTable->write);
	DEB(ef, "nsTable->destroystream = 0x%x\n", nsTable->destroystream);
	DEB(ef, "nsTable->status = 0x%x\n", nsTable->status);
	DEB(ef, "nsTable->uagent = 0x%x\n", nsTable->uagent);
	DEB(ef, "nsTable->memalloc = 0x%x\n", nsTable->memalloc);
	DEB(ef, "nsTable->memfree = 0x%x\n", nsTable->memfree);
	DEB(ef, "nsTable->memflush = 0x%x\n", nsTable->memflush);
	DEB(ef, "nsTable->reloadplugins = 0x%x\n", nsTable->reloadplugins);
	DEB(ef, "nsTable->getJavaEnv = 0x%x\n", nsTable->getJavaEnv);
	DEB(ef, "nsTable->getJavaPeer = 0x%x\n", nsTable->getJavaPeer);
	DEB(ef, "nsTable->geturlnotify = 0x%x\n", nsTable->geturlnotify);
	DEB(ef, "nsTable->posturlnotify = 0x%x\n", nsTable->posturlnotify);
	DEB(ef, "nsTable->getvalue = 0x%x\n", nsTable->getvalue);
	DEB(ef, "nsTable->setvalue = 0x%x\n", nsTable->setvalue);
	DEB(ef, "nsTable->tqinvalidaterect = 0x%x\n", nsTable->tqinvalidaterect);
	DEB(ef, "nsTable->tqinvalidateregion = 0x%x\n", nsTable->tqinvalidateregion);
	DEB(ef, "nsTable->forceredraw = 0x%x\n", nsTable->forceredraw);

	DEB(ef, "pluginFuncs->size = %d\n", pluginFuncs->size);
	DEB(ef, "pluginFuncs->version = 0x%x\n", pluginFuncs->version);
	DEB(ef, "pluginFuncs->newp = 0x%x\n", pluginFuncs->newp);
	DEB(ef, "pluginFuncs->destroy = 0x%x\n", pluginFuncs->destroy);
	DEB(ef, "pluginFuncs->setwindow = 0x%x\n", pluginFuncs->setwindow);
	DEB(ef, "pluginFuncs->newstream = 0x%x\n", pluginFuncs->newstream);
	DEB(ef, "pluginFuncs->destroystream = 0x%x\n", pluginFuncs->destroystream);
	DEB(ef, "pluginFuncs->asfile = 0x%x\n", pluginFuncs->asfile);
	DEB(ef, "pluginFuncs->writeready = 0x%x\n", pluginFuncs->writeready);
	DEB(ef, "pluginFuncs->write = 0x%x\n", pluginFuncs->write);
	DEB(ef, "pluginFuncs->print = 0x%x\n", pluginFuncs->print);
	DEB(ef, "pluginFuncs->event = 0x%x\n", pluginFuncs->event);
	DEB(ef, "pluginFuncs->urlnotify = 0x%x\n", pluginFuncs->urlnotify);
	DEB(ef, "pluginFuncs->javaClass = 0x%x\n", pluginFuncs->javaClass);
	DEB(ef, "pluginFuncs->getvalue = 0x%x\n", pluginFuncs->getvalue);
	DEB(ef, "pluginFuncs->setvalue = 0x%x\n", pluginFuncs->setvalue);
	
	if ( pluginFuncs->size>sizeof(gPluginFuncs) )
	{
		DEB(ef, "Plugin function table too big\n");
		return NPERR_GENERIC_ERROR;
	}
	
	if ( nsTable->size>sizeof(gNetscapeFuncs) )
	{
		DEB(ef, "Netscape function table too big\n");
		return NPERR_GENERIC_ERROR;
	}
	
	memcpy(&gNetscapeFuncs, nsTable, sizeof(gNetscapeFuncs));
	memcpy(&gExtNetscapeFuncs, nsTable, sizeof(gExtNetscapeFuncs));
		
	gExtNetscapeFuncs.geturl = MyNPN_GetURL;
	gExtNetscapeFuncs.posturl = MyNPN_PostURL;
	gExtNetscapeFuncs.requestread = MyNPN_RequestRead;
	gExtNetscapeFuncs.newstream = MyNPN_NewStream;
	gExtNetscapeFuncs.write = MyNPN_Write;
	gExtNetscapeFuncs.destroystream = MyNPN_DestroyStream;
	gExtNetscapeFuncs.status = MyNPN_tqStatus;
  	gExtNetscapeFuncs.uagent = MyNPN_UserAgent;
	/*gExtNetscapeFuncs.memalloc = MyNPN_MemAlloc;
	gExtNetscapeFuncs.memfree = MyNPN_MemFree;
	gExtNetscapeFuncs.memflush = MyNPN_MemFlush;*/
	gExtNetscapeFuncs.reloadplugins = MyNPN_ReloadPlugins;
	gExtNetscapeFuncs.getJavaEnv = MyNPN_GetJavaEnv;
	gExtNetscapeFuncs.getJavaPeer = MyNPN_GetJavaPeer;
	gExtNetscapeFuncs.geturlnotify = MyNPN_GetURLNotify;
	gExtNetscapeFuncs.posturlnotify = MyNPN_PostURLNotify;
	gExtNetscapeFuncs.getvalue = MyNPN_GetValue;
	gExtNetscapeFuncs.setvalue = MyNPN_SetValue;
	gExtNetscapeFuncs.tqinvalidaterect = MyNPN_InvalidateRect;
	gExtNetscapeFuncs.tqinvalidateregion = MyNPN_InvalidateRegion;
	gExtNetscapeFuncs.forceredraw = MyNPN_ForceRedraw;	
	
	gPluginFuncs.size = sizeof( gPluginFuncs );

	DEB(ef, "call\n");

	err = gNP_Initialize( &gExtNetscapeFuncs, &gPluginFuncs );
	
	if (!err) {	
		/*memcpy(&pluginFuncs, gPluginFuncs, sizeof(gPluginFuncs));*/
				
		/*pluginFuncs->initialize = MyNPP_Initialize;
		pluginFuncs->shutdown = MyNPP_Shutdown;*/
		pluginFuncs->newp = MyNPP_New;
		pluginFuncs->destroy = MyNPP_Destroy;
		pluginFuncs->setwindow = MyNPP_SetWindow;
		pluginFuncs->newstream = MyNPP_NewStream;
		pluginFuncs->destroystream = MyNPP_DestroyStream;
		pluginFuncs->asfile = MyNPP_StreamAsFile;
		pluginFuncs->writeready = MyNPP_WriteReady;
		pluginFuncs->write = MyNPP_Write;
		pluginFuncs->print = MyNPP_Print;
		pluginFuncs->event = MyNPP_HandleEvent;
		pluginFuncs->urlnotify = MyNPP_URLNotify;
		pluginFuncs->javaClass = 0; /* MyNPP_GetJavaClass; */
		pluginFuncs->getvalue = (NPP_GetValueUPP)MyNPP_GetValue;
		pluginFuncs->setvalue = (NPP_SetValueUPP)MyNPP_SetValue;
	
		DEB(ef, "nsTable->size = %d\n", gExtNetscapeFuncs.size);
		DEB(ef, "nsTable->version = 0x%x\n", gExtNetscapeFuncs.version);
		DEB(ef, "nsTable->geturl = 0x%x\n", gExtNetscapeFuncs.geturl);
		DEB(ef, "nsTable->posturl = 0x%x\n", gExtNetscapeFuncs.posturl);
		DEB(ef, "nsTable->requestread = 0x%x\n", gExtNetscapeFuncs.requestread);
		DEB(ef, "nsTable->newstream = 0x%x\n", gExtNetscapeFuncs.newstream);
		DEB(ef, "nsTable->write = 0x%x\n", gExtNetscapeFuncs.write);
		DEB(ef, "nsTable->destroystream = 0x%x\n", gExtNetscapeFuncs.destroystream);
		DEB(ef, "nsTable->status = 0x%x\n", gExtNetscapeFuncs.status);
		DEB(ef, "nsTable->uagent = 0x%x\n", gExtNetscapeFuncs.uagent);
		DEB(ef, "nsTable->memalloc = 0x%x\n", gExtNetscapeFuncs.memalloc);
		DEB(ef, "nsTable->memfree = 0x%x\n", gExtNetscapeFuncs.memfree);
		DEB(ef, "nsTable->memflush = 0x%x\n", gExtNetscapeFuncs.memflush);
		DEB(ef, "nsTable->reloadplugins = 0x%x\n", gExtNetscapeFuncs.reloadplugins);
		DEB(ef, "nsTable->getJavaEnv = 0x%x\n", gExtNetscapeFuncs.getJavaEnv);
		DEB(ef, "nsTable->getJavaPeer = 0x%x\n", gExtNetscapeFuncs.getJavaPeer);
		DEB(ef, "nsTable->geturlnotify = 0x%x\n", gExtNetscapeFuncs.geturlnotify);
		DEB(ef, "nsTable->posturlnotify = 0x%x\n", gExtNetscapeFuncs.posturlnotify);
		DEB(ef, "nsTable->getvalue = 0x%x\n", gExtNetscapeFuncs.getvalue);
		DEB(ef, "nsTable->setvalue = 0x%x\n", gExtNetscapeFuncs.setvalue);
		DEB(ef, "nsTable->tqinvalidaterect = 0x%x\n", gExtNetscapeFuncs.tqinvalidaterect);
		DEB(ef, "nsTable->tqinvalidateregion = 0x%x\n", gExtNetscapeFuncs.tqinvalidateregion);
		DEB(ef, "nsTable->forceredraw = 0x%x\n", gExtNetscapeFuncs.forceredraw);

		DEB(ef, "pluginFuncs->size = %d\n", pluginFuncs->size);
		DEB(ef, "pluginFuncs->version = 0x%x\n", pluginFuncs->version);
		DEB(ef, "pluginFuncs->newp = 0x%x\n", pluginFuncs->newp);
		DEB(ef, "pluginFuncs->destroy = 0x%x\n", pluginFuncs->destroy);
		DEB(ef, "pluginFuncs->setwindow = 0x%x\n", pluginFuncs->setwindow);
		DEB(ef, "pluginFuncs->newstream = 0x%x\n", pluginFuncs->newstream);
		DEB(ef, "pluginFuncs->destroystream = 0x%x\n", pluginFuncs->destroystream);
		DEB(ef, "pluginFuncs->asfile = 0x%x\n", pluginFuncs->asfile);
		DEB(ef, "pluginFuncs->writeready = 0x%x\n", pluginFuncs->writeready);
		DEB(ef, "pluginFuncs->write = 0x%x\n", pluginFuncs->write);
		DEB(ef, "pluginFuncs->print = 0x%x\n", pluginFuncs->print);
		DEB(ef, "pluginFuncs->event = 0x%x\n", pluginFuncs->event);
		DEB(ef, "pluginFuncs->urlnotify = 0x%x\n", pluginFuncs->urlnotify);
		DEB(ef, "pluginFuncs->javaClass = 0x%x\n", pluginFuncs->javaClass);
		DEB(ef, "pluginFuncs->getvalue = 0x%x\n", pluginFuncs->getvalue);
		DEB(ef, "pluginFuncs->setvalue = 0x%x\n", pluginFuncs->setvalue);
	}
		
	DEB(ef, "<- NP_Initialize = %d\n", err );
	return err;
}

extern NPError NP_Shutdown(void);
NPError NP_Shutdown(void)
{
	NPError err;
	LoadPlugin();	
	if ( !gLib ) return NPERR_GENERIC_ERROR;	
	DEB(ef, "-> NP_Shutdown()\n" );
	
	err = gNP_Shutdown( );
	DEB(ef, "<- NP_Shutdown = %d\n", err );
	return err;
}