"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "gxine-0.5.903/browser-plugin/npunix.c" of archive gxine-0.5.903.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2  * npunix.c
    3  *
    4  * Netscape Client Plugin API
    5  * - Wrapper function to interface with the Netscape Navigator
    6  *
    7  * dp Suresh <dp@netscape.com>
    8  *
    9  *----------------------------------------------------------------------
   10  * PLUGIN DEVELOPERS:
   11  *	YOU WILL NOT NEED TO EDIT THIS FILE.
   12  *----------------------------------------------------------------------
   13  */
   14 
   15 #define XP_UNIX 1
   16 
   17 #include <stdio.h>
   18 #include "npapi.h"
   19 #include "npupp.h"
   20 
   21 /*
   22  * Define PLUGIN_TRACE to have the wrapper functions print
   23  * messages to stderr whenever they are called.
   24  */
   25 
   26 /* #define PLUGIN_TRACE */
   27 #ifdef PLUGIN_TRACE
   28 #include <stdio.h>
   29 #define PLUGINDEBUGSTR(msg)	fprintf(stderr, "%s\n", msg)
   30 #else
   31 #define PLUGINDEBUGSTR(msg)
   32 #endif
   33 
   34 
   35 /***********************************************************************
   36  *
   37  * Globals
   38  *
   39  ***********************************************************************/
   40 
   41 static NPNetscapeFuncs   gNetscapeFuncs;	/* Netscape Function table */
   42 
   43 
   44 /***********************************************************************
   45  *
   46  * Wrapper functions : plugin calling Netscape Navigator
   47  *
   48  * These functions let the plugin developer just call the APIs
   49  * as documented and defined in npapi.h, without needing to know
   50  * about the function table and call macros in npupp.h.
   51  *
   52  ***********************************************************************/
   53 
   54 void
   55 NPN_Version(int* plugin_major, int* plugin_minor,
   56 	     int* netscape_major, int* netscape_minor)
   57 {
   58 	*plugin_major = NP_VERSION_MAJOR;
   59 	*plugin_minor = NP_VERSION_MINOR;
   60 
   61 	/* Major version is in high byte */
   62 	*netscape_major = gNetscapeFuncs.version >> 8;
   63 	/* Minor version is in low byte */
   64 	*netscape_minor = gNetscapeFuncs.version & 0xFF;
   65 }
   66 
   67 NPError
   68 NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
   69 {
   70 	return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
   71 					instance, variable, r_value);
   72 }
   73 
   74 NPError
   75 NPN_GetURL(NPP instance, const char* url, const char* window)
   76 {
   77 	return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
   78 }
   79 
   80 NPError
   81 NPN_PostURL(NPP instance, const char* url, const char* window,
   82 	     uint32 len, const char* buf, NPBool file)
   83 {
   84 	return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
   85 					url, window, len, buf, file);
   86 }
   87 
   88 NPError
   89 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
   90 {
   91 	return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
   92 					stream, rangeList);
   93 }
   94 
   95 NPError
   96 NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
   97 	      NPStream** stream_ptr)
   98 {
   99 	return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
  100 					type, window, stream_ptr);
  101 }
  102 
  103 int32
  104 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
  105 {
  106 	return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
  107 					stream, len, buffer);
  108 }
  109 
  110 NPError
  111 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
  112 {
  113 	return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
  114 						instance, stream, reason);
  115 }
  116 
  117 void
  118 NPN_Status(NPP instance, const char* message)
  119 {
  120 	CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
  121 }
  122 
  123 const char*
  124 NPN_UserAgent(NPP instance)
  125 {
  126 	return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
  127 }
  128 
  129 void*
  130 NPN_MemAlloc(uint32 size)
  131 {
  132 	return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
  133 }
  134 
  135 void NPN_MemFree(void* ptr)
  136 {
  137 	CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
  138 }
  139 
  140 uint32 NPN_MemFlush(uint32 size)
  141 {
  142 	return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
  143 }
  144 
  145 void NPN_ReloadPlugins(NPBool reloadPages)
  146 {
  147 	CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
  148 }
  149 
  150 
  151 /***********************************************************************
  152  *
  153  * Wrapper functions : Netscape Navigator -> plugin
  154  *
  155  * These functions let the plugin developer just create the APIs
  156  * as documented and defined in npapi.h, without needing to
  157  * install those functions in the function table or worry about
  158  * setting up globals for 68K plugins.
  159  *
  160  ***********************************************************************/
  161 
  162 static NPError
  163 Private_New(NPMIMEType pluginType, NPP instance, uint16 mode,
  164 		int16 argc, char* argn[], char* argv[], NPSavedData* saved)
  165 {
  166 	NPError ret;
  167 	PLUGINDEBUGSTR("New");
  168 	ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
  169 	return ret;
  170 }
  171 
  172 static NPError
  173 Private_Destroy(NPP instance, NPSavedData** save)
  174 {
  175 	PLUGINDEBUGSTR("Destroy");
  176 	return NPP_Destroy(instance, save);
  177 }
  178 
  179 static NPError
  180 Private_SetWindow(NPP instance, NPWindow* window)
  181 {
  182 	NPError err;
  183 	PLUGINDEBUGSTR("SetWindow");
  184 	err = NPP_SetWindow(instance, window);
  185 	return err;
  186 }
  187 
  188 static NPError
  189 Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
  190 			NPBool seekable, uint16* stype)
  191 {
  192 	NPError err;
  193 	PLUGINDEBUGSTR("NewStream");
  194 	err = NPP_NewStream(instance, type, stream, seekable, stype);
  195 	return err;
  196 }
  197 
  198 static int32
  199 Private_WriteReady(NPP instance, NPStream* stream)
  200 {
  201 	unsigned int result;
  202 	PLUGINDEBUGSTR("WriteReady");
  203 	result = NPP_WriteReady(instance, stream);
  204 	return result;
  205 }
  206 
  207 static int32
  208 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
  209 		void* buffer)
  210 {
  211 	unsigned int result;
  212 	PLUGINDEBUGSTR("Write");
  213 	result = NPP_Write(instance, stream, offset, len, buffer);
  214 	return result;
  215 }
  216 
  217 static void
  218 Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
  219 {
  220 	PLUGINDEBUGSTR("StreamAsFile");
  221 	NPP_StreamAsFile(instance, stream, fname);
  222 }
  223 
  224 
  225 static NPError
  226 Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
  227 {
  228 	NPError err;
  229 	PLUGINDEBUGSTR("DestroyStream");
  230 	err = NPP_DestroyStream(instance, stream, reason);
  231 	return err;
  232 }
  233 
  234 
  235 static void
  236 Private_Print(NPP instance, NPPrint* platformPrint)
  237 {
  238 	PLUGINDEBUGSTR("Print");
  239 	NPP_Print(instance, platformPrint);
  240 }
  241 
  242 /***********************************************************************
  243  *
  244  * These functions are located automagically by netscape.
  245  *
  246  ***********************************************************************/
  247 
  248 /*
  249  * NP_GetMIMEDescription
  250  *	- Netscape needs to know about this symbol
  251  *	- Netscape uses the return value to identify when an object instance
  252  *	  of this plugin should be created.
  253  */
  254 char *
  255 NP_GetMIMEDescription(void)
  256 {
  257 	return NPP_GetMIMEDescription();
  258 }
  259 
  260 /*
  261  * NP_GetValue [optional]
  262  *	- Netscape needs to know about this symbol.
  263  *	- Interfaces with plugin to get values for predefined variables
  264  *	  that the navigator needs.
  265  */
  266 NPError
  267 NP_GetValue(void *future, NPPVariable variable, void *value)
  268 {
  269 	return NPP_GetValue(future, variable, value);
  270 }
  271 
  272 /*
  273  * NP_Initialize
  274  *	- Netscape needs to know about this symbol.
  275  *	- It calls this function after looking up its symbol before it
  276  *	  is about to create the first ever object of this kind.
  277  *
  278  * PARAMETERS
  279  *    nsTable	- The netscape function table. If developers just use these
  280  *		  wrappers, they dont need to worry about all these function
  281  *		  tables.
  282  * RETURN
  283  *    pluginFuncs
  284  *		- This functions needs to fill the plugin function table
  285  *		  pluginFuncs and return it. Netscape Navigator plugin
  286  *		  library will use this function table to call the plugin.
  287  *
  288  */
  289 NPError
  290 NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
  291 {
  292 	NPError err = NPERR_NO_ERROR;
  293 
  294 	PLUGINDEBUGSTR("NP_Initialize");
  295 
  296 	/* validate input parameters */
  297 
  298 	if ((nsTable == NULL) || (pluginFuncs == NULL))
  299 		err = NPERR_INVALID_FUNCTABLE_ERROR;
  300 
  301 	/*
  302 	 * Check the major version passed in Netscape's function table.
  303 	 * We won't load if the major version is newer than what we expect.
  304 	 * Also check that the function tables passed in are big enough for
  305 	 * all the functions we need (they could be bigger, if Netscape added
  306 	 * new APIs, but that's OK with us -- we'll just ignore them).
  307 	 *
  308 	 */
  309 
  310 	if (err == NPERR_NO_ERROR) {
  311 		if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
  312 			err = NPERR_INCOMPATIBLE_VERSION_ERROR;
  313 		if (nsTable->size < sizeof(NPNetscapeFuncs))
  314 			err = NPERR_INVALID_FUNCTABLE_ERROR;
  315 		if (pluginFuncs->size < sizeof(NPPluginFuncs))
  316 			err = NPERR_INVALID_FUNCTABLE_ERROR;
  317 	}
  318 
  319 
  320 	if (err == NPERR_NO_ERROR) {
  321 		/*
  322 		 * Copy all the fields of Netscape function table into our
  323 		 * copy so we can call back into Netscape later.  Note that
  324 		 * we need to copy the fields one by one, rather than assigning
  325 		 * the whole structure, because the Netscape function table
  326 		 * could actually be bigger than what we expect.
  327 		 */
  328 		gNetscapeFuncs.version       = nsTable->version;
  329 		gNetscapeFuncs.size          = nsTable->size;
  330 		gNetscapeFuncs.posturl       = nsTable->posturl;
  331 		gNetscapeFuncs.geturl        = nsTable->geturl;
  332 		gNetscapeFuncs.requestread   = nsTable->requestread;
  333 		gNetscapeFuncs.newstream     = nsTable->newstream;
  334 		gNetscapeFuncs.write         = nsTable->write;
  335 		gNetscapeFuncs.destroystream = nsTable->destroystream;
  336 		gNetscapeFuncs.status        = nsTable->status;
  337 		gNetscapeFuncs.uagent        = nsTable->uagent;
  338 		gNetscapeFuncs.memalloc      = nsTable->memalloc;
  339 		gNetscapeFuncs.memfree       = nsTable->memfree;
  340 		gNetscapeFuncs.memflush      = nsTable->memflush;
  341 		gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
  342 		gNetscapeFuncs.getJavaEnv    = nsTable->getJavaEnv;
  343 		gNetscapeFuncs.getJavaPeer   = nsTable->getJavaPeer;
  344 		gNetscapeFuncs.getvalue      = nsTable->getvalue;
  345 
  346 		/*
  347 		 * Set up the plugin function table that Netscape will use to
  348 		 * call us.  Netscape needs to know about our version and size
  349 		 * and have a UniversalProcPointer for every function we
  350 		 * implement.
  351 		 */
  352 		pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
  353 		pluginFuncs->size       = sizeof(NPPluginFuncs);
  354 		pluginFuncs->newp       = NewNPP_NewProc(Private_New);
  355 		pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
  356 		pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
  357 		pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
  358 		pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
  359 		pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
  360 		pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
  361 		pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
  362 		pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
  363 		pluginFuncs->event      = NULL;
  364 		pluginFuncs->javaClass	= NULL;
  365 
  366 		err = NPP_Initialize();
  367 	}
  368 
  369 	return err;
  370 }
  371 
  372 /*
  373  * NP_Shutdown [optional]
  374  *	- Netscape needs to know about this symbol.
  375  *	- It calls this function after looking up its symbol after
  376  *	  the last object of this kind has been destroyed.
  377  *
  378  */
  379 NPError
  380 NP_Shutdown(void)
  381 {
  382  	PLUGINDEBUGSTR("NP_Shutdown");
  383 	NPP_Shutdown();
  384 	return NPERR_NO_ERROR;
  385 }