home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / os2plug.exe / COMMON / npos2.cpp
Text File  |  1996-11-06  |  8KB  |  254 lines

  1. /* npos2.cpp */
  2.  
  3. //\\// INCLUDE
  4. #include <os2.h>
  5. #define DWORD ULONG
  6. #define LPVOID PVOID
  7.  
  8. // netscape
  9. #ifndef _NPAPI_H_
  10. #include "npapi.h"
  11. #endif
  12. #ifndef _NPUPP_H_
  13. #include "npupp.h"
  14. #endif
  15.  
  16. //\\// DEFINE
  17. #define NP_EXPORT _Export
  18.  
  19. //\\// GLOBAL DATA
  20. NPNetscapeFuncs* g_pNavigatorFuncs = NULL;
  21.  
  22. #ifdef _cplusplus
  23. extern "C" {
  24. #endif
  25.  
  26. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  27. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  28. // DllEntryPoint
  29. //
  30. //
  31. BOOL DLLInitTerm( HMODULE hmod, int Flag)
  32. {
  33.    return 0;
  34. }
  35.  
  36.  
  37. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  38. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  39. //                                              PLUGIN DLL entry points
  40. //
  41. // These are the OS/2 specific DLL entry points. They must be exoprted
  42. //
  43.  
  44. // we need these to be global since we have to fill one of its field
  45. // with a data (class) which requires knowlwdge of the navigator
  46. // jump-table. This jump table is known at Initialize time (NP_Initialize)
  47. // which is called after NP_GetEntryPoint
  48. static NPPluginFuncs* g_pluginFuncs;
  49.  
  50. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  51. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  52. // NP_GetEntryPoints
  53. //
  54. //      fills in the func table used by Navigator to call entry points in
  55. //  plugin DLL.  Note that these entry points ensure that DS is loaded
  56. //  by using the NP_LOADDS macro, when compiling for Win16
  57. //
  58. NPError OSCALL NP_EXPORT
  59. NP_GetEntryPoints(NPPluginFuncs* pFuncs)
  60. {
  61.     // trap a NULL ptr
  62.     if(pFuncs == NULL)
  63.         return NPERR_INVALID_FUNCTABLE_ERROR;
  64.  
  65.     // if the plugin's function table is smaller than the plugin expects,
  66.     // then they are incompatible, and should return an error
  67.     if(pFuncs->size < sizeof( NPPluginFuncs))
  68.         return NPERR_INVALID_FUNCTABLE_ERROR;
  69.  
  70.     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
  71.     pFuncs->newp          = NPP_New;
  72.     pFuncs->destroy       = NPP_Destroy;
  73.     pFuncs->setwindow     = NPP_SetWindow;
  74.     pFuncs->newstream     = NPP_NewStream;
  75.     pFuncs->destroystream = NPP_DestroyStream;
  76.     pFuncs->asfile        = NPP_StreamAsFile;
  77.     pFuncs->writeready    = NPP_WriteReady;
  78.     pFuncs->write         = NPP_Write;
  79.     pFuncs->print         = NPP_Print;
  80.     pFuncs->event         = NULL;       /// reserved
  81.  
  82.         g_pluginFuncs             = pFuncs;
  83.  
  84.     return NPERR_NO_ERROR;
  85. }
  86.  
  87. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  88. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  89. // NP_Initialize
  90. //
  91. //      called immediately after the plugin DLL is loaded
  92. //
  93. NPError OSCALL NP_EXPORT
  94. NP_Initialize(NPNetscapeFuncs* pFuncs)
  95. {
  96.     // trap a NULL ptr
  97.     if(pFuncs == NULL)
  98.         return NPERR_INVALID_FUNCTABLE_ERROR;
  99.  
  100.     g_pNavigatorFuncs = pFuncs; // save it for future reference
  101.  
  102.     // if the plugin's major ver level is lower than the Navigator's,
  103.     // then they are incompatible, and should return an error
  104.     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
  105.         return NPERR_INCOMPATIBLE_VERSION_ERROR;
  106.  
  107.     // if the Navigator's function table is smaller than the plugin expects,
  108.     // then they are incompatible, and should return an error
  109.     if(pFuncs->size < sizeof (NPNetscapeFuncs))
  110.         return NPERR_INVALID_FUNCTABLE_ERROR;
  111.  
  112.     return NPP_Initialize();
  113. }
  114.  
  115. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  116. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  117. // NP_Shutdown
  118. //
  119. //      called immediately before the plugin DLL is unloaded.
  120. //      This function should check for some ref count on the dll to see if it is
  121. //      unloadable or it needs to stay in memory.
  122. //
  123. NPError OSCALL NP_EXPORT
  124. NP_Shutdown()
  125. {
  126.     NPP_Shutdown();
  127.  
  128.     g_pNavigatorFuncs = NULL;
  129.  
  130.     return NPERR_NO_ERROR;
  131. }
  132.  
  133. #ifdef _cplusplus
  134. }
  135. #endif
  136.  
  137. //                                              END - PLUGIN DLL entry points
  138. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  139. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  140.  
  141. /*    NAVIGATOR Entry points    */
  142.  
  143. /* These entry points expect to be called from within the plugin.  The
  144.    noteworthy assumption is that DS has already been set to point to the
  145.    plugin's DLL data segment.  Don't call these functions from outside
  146.    the plugin without ensuring DS is set to the DLLs data segment first,
  147.    typically using the NP_LOADDS macro
  148. */
  149.  
  150. /* returns the major/minor version numbers of the Plugin API for the plugin
  151.    and the Navigator
  152. */
  153. void OSCALL
  154. NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
  155. {
  156.     *plugin_major   = NP_VERSION_MAJOR;
  157.     *plugin_minor   = NP_VERSION_MINOR;
  158.     *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
  159.     *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
  160. }
  161.  
  162. /* causes the specified URL to be fetched and streamed in
  163. */
  164. NPError OSCALL
  165. NPN_GetURL(NPP instance, const char *url, const char *window)
  166. {
  167.     return g_pNavigatorFuncs->geturl(instance, url, window);
  168. }
  169.  
  170. NPError OSCALL
  171. NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
  172. {
  173.     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
  174. }
  175.  
  176. /* Requests that a number of bytes be provided on a stream.  Typically
  177.    this would be used if a stream was in "pull" mode.  An optional
  178.    position can be provided for streams which are seekable.
  179. */
  180. NPError OSCALL
  181. NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
  182. {
  183.     return g_pNavigatorFuncs->requestread(stream, rangeList);
  184. }
  185.  
  186. /* Creates a new stream of data from the plug-in to be interpreted
  187.    by Netscape in the current window.
  188. */
  189. NPError OSCALL
  190. NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
  191. {
  192.     return g_pNavigatorFuncs->newstream(instance, type, target, stream);
  193. //  return g_pNavigatorFuncs->newstream(instance, type, stream);
  194. }
  195.  
  196. /* Provides len bytes of data.
  197. */
  198. int32 OSCALL
  199. NPN_Write(NPP instance, NPStream *stream,
  200.                 int32 len, void *buffer)
  201. {
  202.     return g_pNavigatorFuncs->write(instance, stream, len, buffer);
  203. }
  204.  
  205. /* Closes a stream object.
  206. reason indicates why the stream was closed.
  207. */
  208. NPError OSCALL
  209. NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
  210. {
  211.     return g_pNavigatorFuncs->destroystream(instance, stream, reason);
  212. }
  213.  
  214. /* Provides a text status message in the Netscape client user interface
  215. */
  216. void OSCALL
  217. NPN_Status(NPP instance, const char *message)
  218. {
  219.     g_pNavigatorFuncs->status(instance, message);
  220. }
  221.  
  222. /* returns the user agent string of Navigator, which contains version info
  223. */
  224. const char* OSCALL
  225. NPN_UserAgent(NPP instance)
  226. {
  227.     return g_pNavigatorFuncs->uagent(instance);
  228. }
  229.  
  230. /* allocates memory from the Navigator's memory space.  Necessary so that
  231.    saved instance data may be freed by Navigator when exiting.
  232. */
  233. void* OSCALL
  234. NPN_MemAlloc(uint32 size)
  235. {
  236.     return g_pNavigatorFuncs->memalloc(size);
  237. }
  238.  
  239. /* reciprocal of MemAlloc() above
  240. */
  241. void OSCALL
  242. NPN_MemFree(void* ptr)
  243. {
  244.     g_pNavigatorFuncs->memfree(ptr);
  245. }
  246.  
  247. /* private function to Netscape.  do not use!
  248. */
  249. void OSCALL
  250. NPN_ReloadPlugins(NPBool reloadPages)
  251. {
  252.     g_pNavigatorFuncs->reloadplugins(reloadPages);
  253. }
  254.