gcjwebplugin.cc 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  1. /* gcjwebplugin.cc -- web browser plugin to execute Java applets
  2. Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. // System includes.
  32. #include <errno.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <sys/stat.h>
  36. #include <sys/types.h>
  37. #include <unistd.h>
  38. // Netscape plugin API includes.
  39. #include <npapi.h>
  40. #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
  41. #include <npupp.h>
  42. #else
  43. #include <npfunctions.h>
  44. #endif
  45. // GLib includes.
  46. #include <glib.h>
  47. #include <glib/gstdio.h>
  48. // GTK includes.
  49. #include <gtk/gtk.h>
  50. // gcjwebplugin includes.
  51. #include "config.h"
  52. // Documentbase retrieval includes.
  53. #include <nsIPluginInstance.h>
  54. #include <nsIPluginInstancePeer.h>
  55. #include <nsIPluginTagInfo2.h>
  56. // Debugging macros.
  57. #define PLUGIN_DEBUG(message) \
  58. g_print ("GCJ PLUGIN: thread %p: %s\n", g_thread_self (), message)
  59. #define PLUGIN_DEBUG_TWO(first, second) \
  60. g_print ("GCJ PLUGIN: thread %p: %s %s\n", g_thread_self (), \
  61. first, second)
  62. // Error reporting macros.
  63. #define PLUGIN_ERROR(message) \
  64. g_printerr ("%s:%d: thread %p: Error: %s\n", __FILE__, __LINE__, \
  65. g_thread_self (), message)
  66. #define PLUGIN_ERROR_TWO(first, second) \
  67. g_printerr ("%s:%d: thread %p: Error: %s: %s\n", __FILE__, __LINE__, \
  68. g_thread_self (), first, second)
  69. #define PLUGIN_ERROR_THREE(first, second, third) \
  70. g_printerr ("%s:%d: thread %p: Error: %s: %s: %s\n", __FILE__, \
  71. __LINE__, g_thread_self (), first, second, third)
  72. // Plugin information passed to about:plugins.
  73. #define PLUGIN_NAME "GCJ Web Browser Plugin"
  74. #define PLUGIN_DESC "The " PLUGIN_NAME " executes Java applets."
  75. #define PLUGIN_MIME_DESC \
  76. "application/x-java-vm:class,jar:GCJ;" \
  77. "application/x-java-applet:class,jar:GCJ;" \
  78. "application/x-java-applet;version=1.1:class,jar:GCJ;" \
  79. "application/x-java-applet;version=1.1.1:class,jar:GCJ;" \
  80. "application/x-java-applet;version=1.1.2:class,jar:GCJ;" \
  81. "application/x-java-applet;version=1.1.3:class,jar:GCJ;" \
  82. "application/x-java-applet;version=1.2:class,jar:GCJ;" \
  83. "application/x-java-applet;version=1.2.1:class,jar:GCJ;" \
  84. "application/x-java-applet;version=1.2.2:class,jar:GCJ;" \
  85. "application/x-java-applet;version=1.3:class,jar:GCJ;" \
  86. "application/x-java-applet;version=1.3.1:class,jar:GCJ;" \
  87. "application/x-java-applet;version=1.4:class,jar:GCJ;" \
  88. "application/x-java-applet;version=1.4.1:class,jar:GCJ;" \
  89. "application/x-java-applet;version=1.4.2:class,jar:GCJ;" \
  90. "application/x-java-applet;jpi-version=1.4.2_01:class,jar:GCJ;" \
  91. "application/x-java-bean:class,jar:GCJ;" \
  92. "application/x-java-bean;version=1.1:class,jar:GCJ;" \
  93. "application/x-java-bean;version=1.1.1:class,jar:GCJ;" \
  94. "application/x-java-bean;version=1.1.2:class,jar:GCJ;" \
  95. "application/x-java-bean;version=1.1.3:class,jar:GCJ;" \
  96. "application/x-java-bean;version=1.2:class,jar:GCJ;" \
  97. "application/x-java-bean;version=1.2.1:class,jar:GCJ;" \
  98. "application/x-java-bean;version=1.2.2:class,jar:GCJ;" \
  99. "application/x-java-bean;version=1.3:class,jar:GCJ;" \
  100. "application/x-java-bean;version=1.3.1:class,jar:GCJ;" \
  101. "application/x-java-bean;version=1.4:class,jar:GCJ;" \
  102. "application/x-java-bean;version=1.4.1:class,jar:GCJ;" \
  103. "application/x-java-bean;version=1.4.2:class,jar:GCJ;" \
  104. "application/x-java-bean;jpi-version=1.4.2_01:class,jar:GCJ;"
  105. #define PLUGIN_URL NS_INLINE_PLUGIN_CONTRACTID_PREFIX NS_JVM_MIME_TYPE
  106. #define PLUGIN_MIME_TYPE "application/x-java-vm"
  107. #define PLUGIN_FILE_EXTS "class,jar,zip"
  108. #define PLUGIN_MIME_COUNT 1
  109. // Security dialog messages.
  110. #define RESPONSE_TRUST_APPLET "Trust Applet"
  111. #define RESPONSE_TRUST_APPLET_ADD_TO_LIST "Trust Applet and Add to Whitelist"
  112. #define SECURITY_WARNING \
  113. "%s wants to load an applet.\n" \
  114. "GNU Classpath's security implementation is not complete.\n" \
  115. "HOSTILE APPLETS WILL STEAL AND/OR DESTROY YOUR DATA!\n"
  116. #define SECURITY_DESCRIPTION \
  117. "Click \"Cancel\" if you do not trust the source of this applet.\n" \
  118. "Click \"Trust Applet\" to load and run this applet now.\n" \
  119. "Click \"Trust Applet and Add To Whitelist\" to always load" \
  120. " and run this applet from now on, without asking.\n" \
  121. "The whitelist is a list of the URLs from which you trust" \
  122. " applets.\n" \
  123. "Your whitelist file is \" %s \"."
  124. #define FAILURE_MESSAGE \
  125. "This page wants to load an applet.\n" \
  126. "The appletviewer is missing or not installed properly in \"" \
  127. APPLETVIEWER_EXECUTABLE "\"."
  128. // Documentbase retrieval required definition.
  129. static NS_DEFINE_IID (kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
  130. // Browser function table.
  131. static NPNetscapeFuncs browserFunctions;
  132. // Data directory for plugin.
  133. static gchar* data_directory;
  134. // Whitelist filename
  135. static gchar* whitelist_filename;
  136. // Keeps track of initialization. NP_Initialize should only be
  137. // called once.
  138. gboolean initialized = false;
  139. // GCJPluginData stores all the data associated with a single plugin
  140. // instance. A separate plugin instance is created for each <APPLET>
  141. // tag. For now, each plugin instance spawns its own applet viewer
  142. // process but this may need to change if we find pages containing
  143. // multiple applets that expect to be running in the same VM.
  144. struct GCJPluginData
  145. {
  146. // A unique identifier for this plugin window.
  147. gchar* instance_string;
  148. // Applet viewer input pipe name.
  149. gchar* in_pipe_name;
  150. // Applet viewer input channel.
  151. GIOChannel* in_from_appletviewer;
  152. // Applet viewer input watch source.
  153. gint in_watch_source;
  154. // Applet viewer output pipe name.
  155. gchar* out_pipe_name;
  156. // Applet viewer output channel.
  157. GIOChannel* out_to_appletviewer;
  158. // Applet viewer output watch source.
  159. gint out_watch_source;
  160. // Mutex to protect appletviewer_alive.
  161. GMutex* appletviewer_mutex;
  162. // Back-pointer to the plugin instance to which this data belongs.
  163. // This should not be freed but instead simply set to NULL.
  164. NPP owner;
  165. // FALSE if the applet viewer process has died. All code
  166. // communicating with the applet viewer should check this flag
  167. // before attempting to read from/write to the applet viewer pipes.
  168. gboolean appletviewer_alive;
  169. // The address of the plugin window. This should not be freed but
  170. // instead simply set to NULL.
  171. gpointer window_handle;
  172. // The last plugin window width sent to us by the browser.
  173. guint32 window_width;
  174. // The last plugin window height sent to us by the browser.
  175. guint32 window_height;
  176. };
  177. // Documentbase retrieval type-punning union.
  178. typedef union
  179. {
  180. void** void_field;
  181. nsIPluginTagInfo2** info_field;
  182. } info_union;
  183. // Static instance helper functions.
  184. // Have the browser allocate a new GCJPluginData structure.
  185. static void plugin_data_new (GCJPluginData** data);
  186. // Documentbase retrieval.
  187. static gchar* plugin_get_documentbase (NPP instance);
  188. // plugin failure handling.
  189. static bool plugin_failed ();
  190. // Whitelist handling.
  191. static bool plugin_user_trusts_documentbase (char* documentbase);
  192. static bool plugin_ask_user_about_documentbase (char* documentbase);
  193. static void plugin_add_documentbase_to_whitelist (char* documentbase);
  194. // Callback used to monitor input pipe status.
  195. static gboolean plugin_in_pipe_callback (GIOChannel* source,
  196. GIOCondition condition,
  197. gpointer plugin_data);
  198. // Callback used to monitor output pipe status.
  199. static gboolean plugin_out_pipe_callback (GIOChannel* source,
  200. GIOCondition condition,
  201. gpointer plugin_data);
  202. static NPError plugin_start_appletviewer (GCJPluginData* data);
  203. static gchar* plugin_create_applet_tag (int16 argc, char* argn[],
  204. char* argv[]);
  205. static void plugin_send_message_to_appletviewer (GCJPluginData* data,
  206. gchar const* message);
  207. static void plugin_stop_appletviewer (GCJPluginData* data);
  208. // Uninitialize GCJPluginData structure and delete pipes.
  209. static void plugin_data_destroy (GCJPluginData** data);
  210. // Global instance counter.
  211. // Mutex to protect plugin_instance_counter.
  212. static GMutex* plugin_instance_mutex = NULL;
  213. // A counter used to create uniquely named pipes.
  214. static gulong plugin_instance_counter = 0;
  215. // The user's documentbase whitelist.
  216. static GIOChannel* whitelist_file = NULL;
  217. // A global variable for reporting GLib errors. This must be free'd
  218. // and set to NULL after each use.
  219. static GError* channel_error = NULL;
  220. // Functions prefixed by GCJ_ are instance functions. They are called
  221. // by the browser and operate on instances of GCJPluginData.
  222. // Functions prefixed by plugin_ are static helper functions.
  223. // Functions prefixed by NP_ are factory functions. They are called
  224. // by the browser and provide functionality needed to create plugin
  225. // instances.
  226. // INSTANCE FUNCTIONS
  227. // Creates a new gcjwebplugin instance. This function creates a
  228. // GCJPluginData* and stores it in instance->pdata. The following
  229. // GCJPluginData fiels are initialized: instance_string, in_pipe_name,
  230. // in_from_appletviewer, in_watch_source, out_pipe_name,
  231. // out_to_appletviewer, out_watch_source, appletviewer_mutex, owner,
  232. // appletviewer_alive. In addition two pipe files are created. All
  233. // of those fields must be properly destroyed, and the pipes deleted,
  234. // by GCJ_Destroy. If an error occurs during initialization then this
  235. // function will free anything that's been allocated so far, set
  236. // instance->pdata to NULL and return an error code.
  237. NPError
  238. GCJ_New (NPMIMEType pluginType, NPP instance, uint16 mode,
  239. int16 argc, char* argn[], char* argv[],
  240. NPSavedData* saved)
  241. {
  242. PLUGIN_DEBUG ("GCJ_New");
  243. NPError np_error = NPERR_NO_ERROR;
  244. GCJPluginData* data = NULL;
  245. gchar* documentbase = NULL;
  246. gchar* read_message = NULL;
  247. gchar* applet_tag = NULL;
  248. gchar* tag_message = NULL;
  249. if (!instance)
  250. {
  251. PLUGIN_ERROR ("Browser-provided instance pointer is NULL.");
  252. np_error = NPERR_INVALID_INSTANCE_ERROR;
  253. goto cleanup_done;
  254. }
  255. // data
  256. plugin_data_new (&data);
  257. if (data == NULL)
  258. {
  259. PLUGIN_ERROR ("Failed to allocate plugin data.");
  260. np_error = NPERR_OUT_OF_MEMORY_ERROR;
  261. goto cleanup_done;
  262. }
  263. // Initialize data->instance_string.
  264. //
  265. // instance_string should be unique for this process so we use a
  266. // combination of getpid and plugin_instance_counter.
  267. //
  268. // Critical region. Reference and increment plugin_instance_counter
  269. // global.
  270. g_mutex_lock (plugin_instance_mutex);
  271. // data->instance_string
  272. data->instance_string = g_strdup_printf ("instance-%d-%ld",
  273. getpid (),
  274. plugin_instance_counter++);
  275. g_mutex_unlock (plugin_instance_mutex);
  276. // data->appletviewer_mutex
  277. data->appletviewer_mutex = g_mutex_new ();
  278. // Documentbase retrieval.
  279. documentbase = plugin_get_documentbase (instance);
  280. if (!documentbase)
  281. {
  282. PLUGIN_ERROR ("Documentbase retrieval failed."
  283. " Browser not Mozilla-based?");
  284. goto cleanup_appletviewer_mutex;
  285. }
  286. // Open the user's documentbase whitelist.
  287. whitelist_file = g_io_channel_new_file (whitelist_filename,
  288. "a+", &channel_error);
  289. if (!whitelist_file)
  290. {
  291. if (channel_error)
  292. {
  293. PLUGIN_ERROR_THREE ("Failed to open whitelist file",
  294. whitelist_filename,
  295. channel_error->message);
  296. g_error_free (channel_error);
  297. channel_error = NULL;
  298. }
  299. else
  300. PLUGIN_ERROR_TWO ("Failed to open whitelist file",
  301. whitelist_filename);
  302. return NPERR_GENERIC_ERROR;
  303. }
  304. if (!plugin_user_trusts_documentbase (documentbase))
  305. {
  306. PLUGIN_ERROR ("User does not trust applet.");
  307. np_error = NPERR_GENERIC_ERROR;
  308. goto cleanup_appletviewer_mutex;
  309. }
  310. // Create appletviewer-to-plugin pipe which we refer to as the input
  311. // pipe.
  312. // data->in_pipe_name
  313. data->in_pipe_name = g_strdup_printf ("%s/gcj-%s-appletviewer-to-plugin",
  314. data_directory, data->instance_string);
  315. if (!data->in_pipe_name)
  316. {
  317. PLUGIN_ERROR ("Failed to create input pipe name.");
  318. np_error = NPERR_OUT_OF_MEMORY_ERROR;
  319. // If data->in_pipe_name is NULL then the g_free at
  320. // cleanup_in_pipe_name will simply return.
  321. goto cleanup_in_pipe_name;
  322. }
  323. if (mkfifo (data->in_pipe_name, 0700) == -1 && errno != EEXIST)
  324. {
  325. PLUGIN_ERROR_TWO ("Failed to create input pipe", strerror (errno));
  326. np_error = NPERR_GENERIC_ERROR;
  327. goto cleanup_in_pipe_name;
  328. }
  329. // Create plugin-to-appletviewer pipe which we refer to as the
  330. // output pipe.
  331. // data->out_pipe_name
  332. data->out_pipe_name = g_strdup_printf ("%s/gcj-%s-plugin-to-appletviewer",
  333. data_directory, data->instance_string);
  334. if (!data->out_pipe_name)
  335. {
  336. PLUGIN_ERROR ("Failed to create output pipe name.");
  337. np_error = NPERR_OUT_OF_MEMORY_ERROR;
  338. goto cleanup_out_pipe_name;
  339. }
  340. if (mkfifo (data->out_pipe_name, 0700) == -1 && errno != EEXIST)
  341. {
  342. PLUGIN_ERROR_TWO ("Failed to create output pipe", strerror (errno));
  343. np_error = NPERR_GENERIC_ERROR;
  344. goto cleanup_out_pipe_name;
  345. }
  346. // Start a separate appletviewer process for each applet, even if
  347. // there are multiple applets in the same page. We may need to
  348. // change this behaviour if we find pages with multiple applets that
  349. // rely on being run in the same VM.
  350. // Critical region. Hold appletviewer_mutex while we start the
  351. // appletviewer, create the IO channels and install the channel
  352. // watch callbacks.
  353. g_mutex_lock (data->appletviewer_mutex);
  354. np_error = plugin_start_appletviewer (data);
  355. // If the appletviewer is not installed, then a dialog box will
  356. // show up and the plugin will be killed.
  357. if (np_error != NPERR_NO_ERROR)
  358. {
  359. if (plugin_failed ())
  360. goto cleanup_applet_failure;
  361. }
  362. // Create plugin-to-appletviewer channel. The default encoding for
  363. // the file is UTF-8.
  364. // data->out_to_appletviewer
  365. data->out_to_appletviewer = g_io_channel_new_file (data->out_pipe_name,
  366. "w", &channel_error);
  367. if (!data->out_to_appletviewer)
  368. {
  369. if (channel_error)
  370. {
  371. PLUGIN_ERROR_TWO ("Failed to create output channel",
  372. channel_error->message);
  373. g_error_free (channel_error);
  374. channel_error = NULL;
  375. }
  376. else
  377. PLUGIN_ERROR ("Failed to create output channel");
  378. np_error = NPERR_GENERIC_ERROR;
  379. goto cleanup_out_to_appletviewer;
  380. }
  381. // Watch for hangup and error signals on the output pipe.
  382. data->out_watch_source =
  383. g_io_add_watch (data->out_to_appletviewer,
  384. (GIOCondition) (G_IO_ERR | G_IO_HUP),
  385. plugin_out_pipe_callback, (gpointer) data);
  386. // Create appletviewer-to-plugin channel. The default encoding for
  387. // the file is UTF-8.
  388. // data->in_from_appletviewer
  389. data->in_from_appletviewer = g_io_channel_new_file (data->in_pipe_name,
  390. "r", &channel_error);
  391. if (!data->in_from_appletviewer)
  392. {
  393. if (channel_error)
  394. {
  395. PLUGIN_ERROR_TWO ("Failed to create input channel",
  396. channel_error->message);
  397. g_error_free (channel_error);
  398. channel_error = NULL;
  399. }
  400. else
  401. PLUGIN_ERROR ("Failed to create input channel");
  402. np_error = NPERR_GENERIC_ERROR;
  403. goto cleanup_in_from_appletviewer;
  404. }
  405. // Watch for hangup and error signals on the input pipe.
  406. data->in_watch_source =
  407. g_io_add_watch (data->in_from_appletviewer,
  408. (GIOCondition) (G_IO_IN | G_IO_ERR | G_IO_HUP),
  409. plugin_in_pipe_callback, (gpointer) data);
  410. // Wait until we receive confirmation that the appletviewer has
  411. // started.
  412. if (g_io_channel_read_line (data->in_from_appletviewer,
  413. &read_message, NULL, NULL,
  414. &channel_error)
  415. != G_IO_STATUS_NORMAL)
  416. {
  417. if (channel_error)
  418. {
  419. PLUGIN_ERROR_TWO ("Receiving confirmation from appletviewer failed",
  420. channel_error->message);
  421. g_error_free (channel_error);
  422. channel_error = NULL;
  423. }
  424. else
  425. PLUGIN_ERROR ("Receiving confirmation from appletviewer failed");
  426. np_error = NPERR_GENERIC_ERROR;
  427. goto cleanup_in_watch_source;
  428. }
  429. PLUGIN_DEBUG ("GCJ_New: got confirmation that appletviewer is running.");
  430. data->appletviewer_alive = TRUE;
  431. // Send applet tag message to appletviewer.
  432. applet_tag = plugin_create_applet_tag (argc, argn, argv);
  433. tag_message = g_strconcat ("tag ", documentbase, " ", applet_tag, NULL);
  434. plugin_send_message_to_appletviewer (data, data->instance_string);
  435. plugin_send_message_to_appletviewer (data, tag_message);
  436. g_mutex_unlock (data->appletviewer_mutex);
  437. // If initialization succeeded entirely then we store the plugin
  438. // data in the instance structure and return. Otherwise we free the
  439. // data we've allocated so far and set instance->pdata to NULL.
  440. // Set back-pointer to owner instance.
  441. data->owner = instance;
  442. instance->pdata = data;
  443. goto cleanup_done;
  444. // An error occurred while initializing the plugin data or spawning
  445. // the appletviewer so we free the data we've already allocated.
  446. cleanup_in_watch_source:
  447. // Removing a source is harmless if it fails since it just means the
  448. // source has already been removed.
  449. g_source_remove (data->in_watch_source);
  450. data->in_watch_source = 0;
  451. cleanup_in_from_appletviewer:
  452. if (data->in_from_appletviewer)
  453. g_io_channel_unref (data->in_from_appletviewer);
  454. data->in_from_appletviewer = NULL;
  455. // cleanup_out_watch_source:
  456. g_source_remove (data->out_watch_source);
  457. data->out_watch_source = 0;
  458. cleanup_out_to_appletviewer:
  459. if (data->out_to_appletviewer)
  460. g_io_channel_unref (data->out_to_appletviewer);
  461. data->out_to_appletviewer = NULL;
  462. // cleanup_out_pipe:
  463. // Delete output pipe.
  464. unlink (data->out_pipe_name);
  465. cleanup_applet_failure:
  466. cleanup_out_pipe_name:
  467. g_free (data->out_pipe_name);
  468. data->out_pipe_name = NULL;
  469. // cleanup_in_pipe:
  470. // Delete input pipe.
  471. unlink (data->in_pipe_name);
  472. cleanup_in_pipe_name:
  473. g_free (data->in_pipe_name);
  474. data->in_pipe_name = NULL;
  475. cleanup_appletviewer_mutex:
  476. g_free (data->appletviewer_mutex);
  477. data->appletviewer_mutex = NULL;
  478. // cleanup_instance_string:
  479. g_free (data->instance_string);
  480. data->instance_string = NULL;
  481. // cleanup_data:
  482. // Eliminate back-pointer to plugin instance.
  483. data->owner = NULL;
  484. (*browserFunctions.memfree) (data);
  485. data = NULL;
  486. // Initialization failed so return a NULL pointer for the browser
  487. // data.
  488. instance->pdata = NULL;
  489. cleanup_done:
  490. g_free (tag_message);
  491. tag_message = NULL;
  492. g_free (applet_tag);
  493. applet_tag = NULL;
  494. g_free (read_message);
  495. read_message = NULL;
  496. g_free (documentbase);
  497. documentbase = NULL;
  498. PLUGIN_DEBUG ("GCJ_New return");
  499. return np_error;
  500. }
  501. NPError
  502. GCJ_GetValue (NPP instance, NPPVariable variable, void* value)
  503. {
  504. PLUGIN_DEBUG ("GCJ_GetValue");
  505. NPError np_error = NPERR_NO_ERROR;
  506. switch (variable)
  507. {
  508. // This plugin needs XEmbed support.
  509. case NPPVpluginNeedsXEmbed:
  510. {
  511. PLUGIN_DEBUG ("GCJ_GetValue: returning TRUE for NeedsXEmbed.");
  512. PRBool* bool_value = (PRBool*) value;
  513. *bool_value = PR_TRUE;
  514. }
  515. break;
  516. default:
  517. PLUGIN_ERROR ("Unknown plugin value requested.");
  518. np_error = NPERR_GENERIC_ERROR;
  519. break;
  520. }
  521. PLUGIN_DEBUG ("GCJ_GetValue return");
  522. return np_error;
  523. }
  524. NPError
  525. GCJ_Destroy (NPP instance, NPSavedData** save)
  526. {
  527. PLUGIN_DEBUG ("GCJ_Destroy");
  528. GCJPluginData* data = (GCJPluginData*) instance->pdata;
  529. if (data)
  530. {
  531. // Critical region. Stop the appletviewer.
  532. g_mutex_lock (data->appletviewer_mutex);
  533. // Tell the appletviewer to destroy its embedded plugin window.
  534. plugin_send_message_to_appletviewer (data, "destroy");
  535. // Shut down the appletviewer.
  536. plugin_stop_appletviewer (data);
  537. g_mutex_unlock (data->appletviewer_mutex);
  538. // Free plugin data.
  539. plugin_data_destroy (&data);
  540. }
  541. PLUGIN_DEBUG ("GCJ_Destroy return");
  542. return NPERR_NO_ERROR;
  543. }
  544. NPError
  545. GCJ_SetWindow (NPP instance, NPWindow* window)
  546. {
  547. PLUGIN_DEBUG ("GCJ_SetWindow");
  548. if (instance == NULL)
  549. {
  550. PLUGIN_ERROR ("Invalid instance.");
  551. return NPERR_INVALID_INSTANCE_ERROR;
  552. }
  553. GCJPluginData* data = (GCJPluginData*) instance->pdata;
  554. // Simply return if we receive a NULL window.
  555. if ((window == NULL) || (window->window == NULL))
  556. {
  557. PLUGIN_DEBUG ("GCJ_SetWindow: got NULL window.");
  558. return NPERR_NO_ERROR;
  559. }
  560. if (data->window_handle)
  561. {
  562. // The window already exists.
  563. if (data->window_handle == window->window)
  564. {
  565. // The parent window is the same as in previous calls.
  566. PLUGIN_DEBUG ("GCJ_SetWindow: window already exists.");
  567. // Critical region. Read data->appletviewer_mutex and send
  568. // a message to the appletviewer.
  569. g_mutex_lock (data->appletviewer_mutex);
  570. if (data->appletviewer_alive)
  571. {
  572. // The window is the same as it was for the last
  573. // SetWindow call.
  574. if (window->width != data->window_width)
  575. {
  576. PLUGIN_DEBUG ("GCJ_SetWindow: window width changed.");
  577. // The width of the plugin window has changed.
  578. // Send the new width to the appletviewer.
  579. plugin_send_message_to_appletviewer (data,
  580. data->instance_string);
  581. gchar* width_message = g_strdup_printf ("width %d",
  582. window->width);
  583. plugin_send_message_to_appletviewer (data, width_message);
  584. g_free (width_message);
  585. width_message = NULL;
  586. // Store the new width.
  587. data->window_width = window->width;
  588. }
  589. if (window->height != data->window_height)
  590. {
  591. PLUGIN_DEBUG ("GCJ_SetWindow: window height changed.");
  592. // The height of the plugin window has changed.
  593. // Send the new height to the appletviewer.
  594. plugin_send_message_to_appletviewer (data,
  595. data->instance_string);
  596. gchar* height_message = g_strdup_printf ("height %d",
  597. window->height);
  598. plugin_send_message_to_appletviewer (data, height_message);
  599. g_free (height_message);
  600. height_message = NULL;
  601. // Store the new height.
  602. data->window_height = window->height;
  603. }
  604. }
  605. else
  606. {
  607. // The appletviewer is not running.
  608. PLUGIN_DEBUG ("GCJ_SetWindow: appletviewer is not running.");
  609. }
  610. g_mutex_unlock (data->appletviewer_mutex);
  611. }
  612. else
  613. {
  614. // The parent window has changed. This branch does run but
  615. // doing nothing in response seems to be sufficient.
  616. PLUGIN_DEBUG ("GCJ_SetWindow: parent window changed.");
  617. }
  618. }
  619. else
  620. {
  621. PLUGIN_DEBUG ("GCJ_SetWindow: setting window.");
  622. // Critical region. Send messages to appletviewer.
  623. g_mutex_lock (data->appletviewer_mutex);
  624. plugin_send_message_to_appletviewer (data, data->instance_string);
  625. gchar *window_message = g_strdup_printf ("handle %ld",
  626. (gulong) window->window);
  627. plugin_send_message_to_appletviewer (data, window_message);
  628. g_free (window_message);
  629. window_message = NULL;
  630. g_mutex_unlock (data->appletviewer_mutex);
  631. // Store the window handle.
  632. data->window_handle = window->window;
  633. }
  634. PLUGIN_DEBUG ("GCJ_SetWindow return");
  635. return NPERR_NO_ERROR;
  636. }
  637. NPError
  638. GCJ_NewStream (NPP instance, NPMIMEType type, NPStream* stream,
  639. NPBool seekable, uint16* stype)
  640. {
  641. PLUGIN_DEBUG ("GCJ_NewStream");
  642. PLUGIN_DEBUG ("GCJ_NewStream return");
  643. return NPERR_NO_ERROR;
  644. }
  645. void
  646. GCJ_StreamAsFile (NPP instance, NPStream* stream, const char* filename)
  647. {
  648. PLUGIN_DEBUG ("GCJ_StreamAsFile");
  649. PLUGIN_DEBUG ("GCJ_StreamAsFile return");
  650. }
  651. NPError
  652. GCJ_DestroyStream (NPP instance, NPStream* stream, NPReason reason)
  653. {
  654. PLUGIN_DEBUG ("GCJ_DestroyStream");
  655. PLUGIN_DEBUG ("GCJ_DestroyStream return");
  656. return NPERR_NO_ERROR;
  657. }
  658. int32
  659. GCJ_WriteReady (NPP instance, NPStream* stream)
  660. {
  661. PLUGIN_DEBUG ("GCJ_WriteReady");
  662. PLUGIN_DEBUG ("GCJ_WriteReady return");
  663. return 0;
  664. }
  665. int32
  666. GCJ_Write (NPP instance, NPStream* stream, int32 offset, int32 len,
  667. void* buffer)
  668. {
  669. PLUGIN_DEBUG ("GCJ_Write");
  670. PLUGIN_DEBUG ("GCJ_Write return");
  671. return 0;
  672. }
  673. void
  674. GCJ_Print (NPP instance, NPPrint* platformPrint)
  675. {
  676. PLUGIN_DEBUG ("GCJ_Print");
  677. PLUGIN_DEBUG ("GCJ_Print return");
  678. }
  679. int16
  680. GCJ_HandleEvent (NPP instance, void* event)
  681. {
  682. PLUGIN_DEBUG ("GCJ_HandleEvent");
  683. PLUGIN_DEBUG ("GCJ_HandleEvent return");
  684. return 0;
  685. }
  686. void
  687. GCJ_URLNotify (NPP instance, const char* url, NPReason reason,
  688. void* notifyData)
  689. {
  690. PLUGIN_DEBUG ("GCJ_URLNotify");
  691. PLUGIN_DEBUG ("GCJ_URLNotify return");
  692. }
  693. #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
  694. jref
  695. #else
  696. void*
  697. #endif
  698. GCJ_GetJavaClass (void)
  699. {
  700. PLUGIN_DEBUG ("GCJ_GetJavaClass");
  701. PLUGIN_DEBUG ("GCJ_GetJavaClass return");
  702. return 0;
  703. }
  704. // HELPER FUNCTIONS
  705. static void
  706. plugin_data_new (GCJPluginData** data)
  707. {
  708. PLUGIN_DEBUG ("plugin_data_new");
  709. *data = (GCJPluginData*)
  710. (*browserFunctions.memalloc) (sizeof (struct GCJPluginData));
  711. // appletviewer_alive is false until the applet viewer is spawned.
  712. if (*data)
  713. memset (*data, 0, sizeof (struct GCJPluginData));
  714. PLUGIN_DEBUG ("plugin_data_new return");
  715. }
  716. // Documentbase retrieval. This function gets the current document's
  717. // documentbase. This function relies on browser-private data so it
  718. // will only work when the plugin is loaded in a Mozilla-based
  719. // browser. We could not find a way to retrieve the documentbase
  720. // using the original Netscape plugin API so we use the XPCOM API
  721. // instead.
  722. static gchar*
  723. plugin_get_documentbase (NPP instance)
  724. {
  725. PLUGIN_DEBUG ("plugin_get_documentbase");
  726. nsIPluginInstance* xpcom_instance = NULL;
  727. nsIPluginInstancePeer* peer = NULL;
  728. nsresult result = 0;
  729. nsIPluginTagInfo2* pluginTagInfo2 = NULL;
  730. info_union u = { NULL };
  731. char const* documentbase = NULL;
  732. gchar* documentbase_copy = NULL;
  733. xpcom_instance = (nsIPluginInstance*) (instance->ndata);
  734. if (!xpcom_instance)
  735. {
  736. PLUGIN_ERROR ("xpcom_instance is NULL.");
  737. goto cleanup_done;
  738. }
  739. xpcom_instance->GetPeer (&peer);
  740. if (!peer)
  741. {
  742. PLUGIN_ERROR ("peer is NULL.");
  743. goto cleanup_done;
  744. }
  745. u.info_field = &pluginTagInfo2;
  746. result = peer->QueryInterface (kIPluginTagInfo2IID,
  747. u.void_field);
  748. if (result || !pluginTagInfo2)
  749. {
  750. PLUGIN_ERROR ("pluginTagInfo2 retrieval failed.");
  751. goto cleanup_peer;
  752. }
  753. pluginTagInfo2->GetDocumentBase (&documentbase);
  754. if (!documentbase)
  755. {
  756. PLUGIN_ERROR ("documentbase is NULL.");
  757. goto cleanup_plugintaginfo2;
  758. }
  759. documentbase_copy = g_strdup (documentbase);
  760. // Release references.
  761. cleanup_plugintaginfo2:
  762. NS_RELEASE (pluginTagInfo2);
  763. cleanup_peer:
  764. NS_RELEASE (peer);
  765. cleanup_done:
  766. PLUGIN_DEBUG ("plugin_get_documentbase return");
  767. return documentbase_copy;
  768. }
  769. // This function shows a error message if the appletviewer has
  770. // not been installed. It returns true, if the user presses the
  771. // ok button.
  772. static bool
  773. plugin_failed ()
  774. {
  775. GtkWidget* dialog = NULL;
  776. GtkWidget* ok_button = NULL;
  777. dialog = gtk_message_dialog_new (NULL,
  778. GTK_DIALOG_MODAL,
  779. GTK_MESSAGE_WARNING,
  780. GTK_BUTTONS_NONE,
  781. FAILURE_MESSAGE);
  782. ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
  783. GTK_STOCK_OK,
  784. GTK_RESPONSE_OK);
  785. gtk_widget_show_all (dialog);
  786. if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
  787. {
  788. gtk_widget_destroy (dialog);
  789. return true;
  790. }
  791. return false;
  792. }
  793. // plugin_user_trusts_documentbase returns true if the given
  794. // documentbase is in the documentbase whitelist. Otherwise it asks
  795. // the user if he trusts the given documentbase by calling
  796. // plugin_ask_user_about_documentbase.
  797. static bool
  798. plugin_user_trusts_documentbase (char* documentbase)
  799. {
  800. bool applet_in_whitelist = false;
  801. // Check if documentbase is in whitelist.
  802. while (true)
  803. {
  804. gchar* whitelist_entry = NULL;
  805. gchar* newline_documentbase = NULL;
  806. // If reading fails, break out of this loop with
  807. // applet_in_whitelist still set to false.
  808. if (g_io_channel_read_line (whitelist_file, &whitelist_entry,
  809. NULL, NULL, &channel_error)
  810. != G_IO_STATUS_NORMAL)
  811. {
  812. if (channel_error)
  813. {
  814. PLUGIN_ERROR_TWO ("Failed to read line from whitelist file",
  815. channel_error->message);
  816. g_error_free (channel_error);
  817. channel_error = NULL;
  818. }
  819. else
  820. PLUGIN_ERROR ("Failed to read line from whitelist file.");
  821. g_free (whitelist_entry);
  822. whitelist_entry = NULL;
  823. break;
  824. }
  825. newline_documentbase = g_strdup_printf ("%s\n", documentbase);
  826. if (!strcmp (newline_documentbase, whitelist_entry))
  827. {
  828. applet_in_whitelist = true;
  829. g_free (newline_documentbase);
  830. newline_documentbase = NULL;
  831. g_free (whitelist_entry);
  832. whitelist_entry = NULL;
  833. break;
  834. }
  835. g_free (whitelist_entry);
  836. whitelist_entry = NULL;
  837. g_free (newline_documentbase);
  838. newline_documentbase = NULL;
  839. }
  840. return applet_in_whitelist ? true
  841. : plugin_ask_user_about_documentbase (documentbase);
  842. }
  843. // plugin_add_documentbase_to_whitelist adds the given documentbase to
  844. // the user's documentbase whitelist.
  845. static void
  846. plugin_add_documentbase_to_whitelist (char* documentbase)
  847. {
  848. gsize bytes_written = 0;
  849. char* newline_documentbase = NULL;
  850. GIOStatus status = G_IO_STATUS_NORMAL;
  851. newline_documentbase = g_strdup_printf ("%s\n", documentbase);
  852. status = g_io_channel_write_chars (whitelist_file,
  853. newline_documentbase, -1, &bytes_written,
  854. &channel_error);
  855. g_free (newline_documentbase);
  856. newline_documentbase = NULL;
  857. if (status != G_IO_STATUS_NORMAL)
  858. {
  859. if (channel_error)
  860. {
  861. PLUGIN_ERROR_TWO ("Error writing to whitelist file",
  862. channel_error->message);
  863. g_error_free (channel_error);
  864. channel_error = NULL;
  865. }
  866. else
  867. PLUGIN_ERROR ("Error writing to whitelist file.");
  868. }
  869. if (g_io_channel_flush (whitelist_file, &channel_error)
  870. != G_IO_STATUS_NORMAL)
  871. {
  872. if (channel_error)
  873. {
  874. PLUGIN_ERROR_TWO ("Failed to write whitelist file",
  875. channel_error->message);
  876. g_error_free (channel_error);
  877. channel_error = NULL;
  878. }
  879. else
  880. PLUGIN_ERROR ("Failed to write whitelist file.");
  881. }
  882. if (g_io_channel_shutdown (whitelist_file, TRUE, &channel_error)
  883. != G_IO_STATUS_NORMAL)
  884. {
  885. if (channel_error)
  886. {
  887. PLUGIN_ERROR_TWO ("Failed to close whitelist file",
  888. channel_error->message);
  889. g_error_free (channel_error);
  890. channel_error = NULL;
  891. }
  892. else
  893. PLUGIN_ERROR ("Failed to close whitelist file.");
  894. }
  895. }
  896. // plugin_ask_user_about_documentbase puts up a dialog box that asks if the
  897. // user trusts applets from this documentbase. The user has three
  898. // options: "Cancel", "Trust Applet" and "Trust Applet and Add to
  899. // Whitelist". If the user selects Cancel (the default) then a
  900. // generic error code is returned from GCJ_New, telling the browser
  901. // that the applet failed to load. If the user selects "Trust Applet"
  902. // then plugin loading proceeds. If the user selects "Trust Applet
  903. // and Add to Whitelist" then this documentbase is added to the user's
  904. // applet whitelist and plugin loading proceeds.
  905. static bool
  906. plugin_ask_user_about_documentbase (char* documentbase)
  907. {
  908. GtkWidget* dialog = NULL;
  909. GtkWidget* ok_button = NULL;
  910. GtkWidget* cancel_button = NULL;
  911. GtkWidget* whitelist_button = NULL;
  912. gint dialog_response = GTK_RESPONSE_NONE;
  913. dialog = gtk_message_dialog_new (NULL,
  914. GTK_DIALOG_MODAL,
  915. GTK_MESSAGE_WARNING,
  916. GTK_BUTTONS_NONE,
  917. SECURITY_WARNING,
  918. documentbase);
  919. gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
  920. SECURITY_DESCRIPTION, whitelist_filename);
  921. cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
  922. GTK_STOCK_CANCEL,
  923. GTK_RESPONSE_CANCEL);
  924. ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
  925. RESPONSE_TRUST_APPLET,
  926. GTK_RESPONSE_OK);
  927. whitelist_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
  928. RESPONSE_TRUST_APPLET_ADD_TO_LIST,
  929. GTK_RESPONSE_APPLY);
  930. gtk_widget_grab_focus (cancel_button);
  931. gtk_widget_show_all (dialog);
  932. dialog_response = gtk_dialog_run (GTK_DIALOG (dialog));
  933. gtk_widget_destroy (dialog);
  934. if (dialog_response == GTK_RESPONSE_CANCEL)
  935. {
  936. // The user does not trust this documentbase.
  937. return false;
  938. }
  939. else if (dialog_response == GTK_RESPONSE_APPLY)
  940. {
  941. // The user wants this documentbase added to his documentbase
  942. // whitelist.
  943. plugin_add_documentbase_to_whitelist (documentbase);
  944. }
  945. // The user trusts this documentbase.
  946. return true;
  947. }
  948. // plugin_in_pipe_callback is called when data is available on the
  949. // input pipe, or when the appletviewer crashes or is killed. It may
  950. // be called after data has been destroyed in which case it simply
  951. // returns FALSE to remove itself from the glib main loop.
  952. static gboolean
  953. plugin_in_pipe_callback (GIOChannel* source,
  954. GIOCondition condition,
  955. gpointer plugin_data)
  956. {
  957. PLUGIN_DEBUG ("plugin_in_pipe_callback");
  958. GCJPluginData* data = (GCJPluginData*) plugin_data;
  959. gboolean keep_installed = TRUE;
  960. // If data is NULL then GCJ_Destroy has already been called and
  961. // plugin_in_pipe_callback is being called after plugin
  962. // destruction. In that case all we need to do is return FALSE so
  963. // that the plugin_in_pipe_callback watch is removed.
  964. if (data)
  965. {
  966. // Critical region. Set or clear data->appletviewer_alive.
  967. g_mutex_lock (data->appletviewer_mutex);
  968. if (condition & G_IO_IN)
  969. {
  970. gchar* message = NULL;
  971. if (g_io_channel_read_line (data->in_from_appletviewer,
  972. &message, NULL, NULL,
  973. &channel_error)
  974. != G_IO_STATUS_NORMAL)
  975. {
  976. if (channel_error)
  977. {
  978. PLUGIN_ERROR_TWO ("Failed to read line from input channel",
  979. channel_error->message);
  980. g_error_free (channel_error);
  981. channel_error = NULL;
  982. }
  983. else
  984. PLUGIN_ERROR ("Failed to read line from input channel");
  985. }
  986. else
  987. {
  988. if (g_str_has_prefix (message, "url "))
  989. {
  990. gchar** parts = g_strsplit (message, " ", 3);
  991. PLUGIN_DEBUG_TWO ("plugin_in_pipe_callback:"
  992. " opening URL", parts[1]);
  993. PLUGIN_DEBUG_TWO ("plugin_in_pipe_callback:"
  994. " URL target", parts[2]);
  995. // Open the URL in a new browser window.
  996. NPError np_error =
  997. (*browserFunctions.geturl) (data->owner, parts[1], parts[2]);
  998. if (np_error != NPERR_NO_ERROR)
  999. PLUGIN_ERROR ("Failed to load URL.");
  1000. g_strfreev (parts);
  1001. parts = NULL;
  1002. }
  1003. else if (g_str_has_prefix (message, "status "))
  1004. {
  1005. gchar** parts = g_strsplit (message, " ", 2);
  1006. PLUGIN_DEBUG_TWO ("plugin_in_pipe_callback:"
  1007. " setting status", parts[1]);
  1008. (*browserFunctions.status) (data->owner, parts[1]);
  1009. g_strfreev (parts);
  1010. parts = NULL;
  1011. }
  1012. g_print (" PIPE: plugin read %s\n", message);
  1013. }
  1014. g_free (message);
  1015. message = NULL;
  1016. keep_installed = TRUE;
  1017. }
  1018. if (condition & (G_IO_ERR | G_IO_HUP))
  1019. {
  1020. PLUGIN_DEBUG ("appletviewer has stopped.");
  1021. data->appletviewer_alive = FALSE;
  1022. keep_installed = FALSE;
  1023. }
  1024. g_mutex_unlock (data->appletviewer_mutex);
  1025. }
  1026. PLUGIN_DEBUG ("plugin_in_pipe_callback return");
  1027. return keep_installed;
  1028. }
  1029. // plugin_out_pipe_callback is called when the appletviewer crashes or
  1030. // is killed. It may be called after data has been destroyed in which
  1031. // case it simply returns FALSE to remove itself from the glib main
  1032. // loop.
  1033. static gboolean
  1034. plugin_out_pipe_callback (GIOChannel* source,
  1035. GIOCondition condition,
  1036. gpointer plugin_data)
  1037. {
  1038. PLUGIN_DEBUG ("plugin_out_pipe_callback");
  1039. GCJPluginData* data = (GCJPluginData*) plugin_data;
  1040. // If data is NULL then GCJ_Destroy has already been called and
  1041. // plugin_out_pipe_callback is being called after plugin
  1042. // destruction. In that case all we need to do is return FALSE so
  1043. // that the plugin_out_pipe_callback watch is removed.
  1044. if (data)
  1045. {
  1046. // Critical region. Clear data->appletviewer_alive.
  1047. g_mutex_lock (data->appletviewer_mutex);
  1048. PLUGIN_DEBUG ("plugin_out_pipe_callback: appletviewer has stopped.");
  1049. data->appletviewer_alive = FALSE;
  1050. g_mutex_unlock (data->appletviewer_mutex);
  1051. }
  1052. PLUGIN_DEBUG ("plugin_out_pipe_callback return");
  1053. return FALSE;
  1054. }
  1055. static NPError
  1056. plugin_start_appletviewer (GCJPluginData* data)
  1057. {
  1058. PLUGIN_DEBUG ("plugin_start_appletviewer");
  1059. NPError error = NPERR_NO_ERROR;
  1060. if (!data->appletviewer_alive)
  1061. {
  1062. gchar* command_line[3] = { NULL, NULL, NULL };
  1063. command_line[0] = g_strdup (APPLETVIEWER_EXECUTABLE);
  1064. // Output from plugin's perspective is appletviewer's input.
  1065. // Input from plugin's perspective is appletviewer's output.
  1066. command_line[1] = g_strdup_printf ("--plugin=%s,%s",
  1067. data->out_pipe_name,
  1068. data->in_pipe_name);
  1069. command_line[2] = NULL;
  1070. if (!g_spawn_async (NULL, command_line, NULL, (GSpawnFlags) 0,
  1071. NULL, NULL, NULL, &channel_error))
  1072. {
  1073. if (channel_error)
  1074. {
  1075. PLUGIN_ERROR_TWO ("Failed to spawn applet viewer",
  1076. channel_error->message);
  1077. g_error_free (channel_error);
  1078. channel_error = NULL;
  1079. }
  1080. else
  1081. PLUGIN_ERROR ("Failed to spawn applet viewer");
  1082. error = NPERR_GENERIC_ERROR;
  1083. goto cleanup;
  1084. }
  1085. cleanup:
  1086. g_free (command_line[0]);
  1087. command_line[0] = NULL;
  1088. g_free (command_line[1]);
  1089. command_line[1] = NULL;
  1090. g_free (command_line[2]);
  1091. command_line[2] = NULL;
  1092. }
  1093. PLUGIN_DEBUG ("plugin_start_appletviewer return");
  1094. return error;
  1095. }
  1096. // Build up the applet tag string that we'll send to the applet
  1097. // viewer.
  1098. static gchar*
  1099. plugin_create_applet_tag (int16 argc, char* argn[], char* argv[])
  1100. {
  1101. PLUGIN_DEBUG ("plugin_create_applet_tag");
  1102. gchar* applet_tag = g_strdup ("<EMBED ");
  1103. gchar* parameters = g_strdup ("");
  1104. for (int16 i = 0; i < argc; i++)
  1105. {
  1106. if (!g_ascii_strcasecmp (argn[i], "code"))
  1107. {
  1108. gchar* code = g_strdup_printf ("CODE=\"%s\" ", argv[i]);
  1109. applet_tag = g_strconcat (applet_tag, code, NULL);
  1110. g_free (code);
  1111. code = NULL;
  1112. }
  1113. else if (!g_ascii_strcasecmp (argn[i], "codebase"))
  1114. {
  1115. gchar* codebase = g_strdup_printf ("CODEBASE=\"%s\" ", argv[i]);
  1116. applet_tag = g_strconcat (applet_tag, codebase, NULL);
  1117. g_free (codebase);
  1118. codebase = NULL;
  1119. }
  1120. else if (!g_ascii_strcasecmp (argn[i], "archive"))
  1121. {
  1122. gchar* archive = g_strdup_printf ("ARCHIVE=\"%s\" ", argv[i]);
  1123. applet_tag = g_strconcat (applet_tag, archive, NULL);
  1124. g_free (archive);
  1125. archive = NULL;
  1126. }
  1127. else if (!g_ascii_strcasecmp (argn[i], "width"))
  1128. {
  1129. gchar* width = g_strdup_printf ("WIDTH=\"%s\" ", argv[i]);
  1130. applet_tag = g_strconcat (applet_tag, width, NULL);
  1131. g_free (width);
  1132. width = NULL;
  1133. }
  1134. else if (!g_ascii_strcasecmp (argn[i], "height"))
  1135. {
  1136. gchar* height = g_strdup_printf ("HEIGHT=\"%s\" ", argv[i]);
  1137. applet_tag = g_strconcat (applet_tag, height, NULL);
  1138. g_free (height);
  1139. height = NULL;
  1140. }
  1141. else
  1142. {
  1143. // Escape the parameter value so that line termination
  1144. // characters will pass through the pipe.
  1145. if (argv[i] != '\0')
  1146. {
  1147. gchar* escaped = NULL;
  1148. escaped = g_strescape (argv[i], NULL);
  1149. parameters = g_strconcat (parameters, "<PARAM NAME=\"", argn[i],
  1150. "\" VALUE=\"", escaped, "\">", NULL);
  1151. g_free (escaped);
  1152. escaped = NULL;
  1153. }
  1154. }
  1155. }
  1156. applet_tag = g_strconcat (applet_tag, ">", parameters, "</EMBED>", NULL);
  1157. g_free (parameters);
  1158. parameters = NULL;
  1159. PLUGIN_DEBUG ("plugin_create_applet_tag return");
  1160. return applet_tag;
  1161. }
  1162. // plugin_send_message_to_appletviewer must be called while holding
  1163. // data->appletviewer_mutex.
  1164. static void
  1165. plugin_send_message_to_appletviewer (GCJPluginData* data, gchar const* message)
  1166. {
  1167. PLUGIN_DEBUG ("plugin_send_message_to_appletviewer");
  1168. if (data->appletviewer_alive)
  1169. {
  1170. gchar* newline_message = NULL;
  1171. gsize bytes_written = 0;
  1172. // Send message to appletviewer.
  1173. newline_message = g_strdup_printf ("%s\n", message);
  1174. // g_io_channel_write_chars will return something other than
  1175. // G_IO_STATUS_NORMAL if not all the data is written. In that
  1176. // case we fail rather than retrying.
  1177. if (g_io_channel_write_chars (data->out_to_appletviewer,
  1178. newline_message, -1, &bytes_written,
  1179. &channel_error)
  1180. != G_IO_STATUS_NORMAL)
  1181. {
  1182. if (channel_error)
  1183. {
  1184. PLUGIN_ERROR_TWO ("Failed to write bytes to output channel",
  1185. channel_error->message);
  1186. g_error_free (channel_error);
  1187. channel_error = NULL;
  1188. }
  1189. else
  1190. PLUGIN_ERROR ("Failed to write bytes to output channel");
  1191. }
  1192. if (g_io_channel_flush (data->out_to_appletviewer, &channel_error)
  1193. != G_IO_STATUS_NORMAL)
  1194. {
  1195. if (channel_error)
  1196. {
  1197. PLUGIN_ERROR_TWO ("Failed to flush bytes to output channel",
  1198. channel_error->message);
  1199. g_error_free (channel_error);
  1200. channel_error = NULL;
  1201. }
  1202. else
  1203. PLUGIN_ERROR ("Failed to flush bytes to output channel");
  1204. }
  1205. g_free (newline_message);
  1206. newline_message = NULL;
  1207. g_print (" PIPE: plugin wrote %s\n", message);
  1208. }
  1209. PLUGIN_DEBUG ("plugin_send_message_to_appletviewer return");
  1210. }
  1211. // Stop the appletviewer process. When this is called the
  1212. // appletviewer can be in any of three states: running, crashed or
  1213. // hung. If the appletviewer is running then sending it "shutdown"
  1214. // will cause it to exit. This will cause
  1215. // plugin_out_pipe_callback/plugin_in_pipe_callback to be called and
  1216. // the input and output channels to be shut down. If the appletviewer
  1217. // has crashed then plugin_out_pipe_callback/plugin_in_pipe_callback
  1218. // would already have been called and data->appletviewer_alive cleared
  1219. // in which case this function simply returns. If the appletviewer is
  1220. // hung then this function will be successful and the input and output
  1221. // watches will be removed by plugin_data_destroy.
  1222. // plugin_stop_appletviewer must be called with
  1223. // data->appletviewer_mutex held.
  1224. static void
  1225. plugin_stop_appletviewer (GCJPluginData* data)
  1226. {
  1227. PLUGIN_DEBUG ("plugin_stop_appletviewer");
  1228. if (data->appletviewer_alive)
  1229. {
  1230. // Shut down the appletviewer.
  1231. gsize bytes_written = 0;
  1232. if (data->out_to_appletviewer)
  1233. {
  1234. if (g_io_channel_write_chars (data->out_to_appletviewer, "shutdown",
  1235. -1, &bytes_written, &channel_error)
  1236. != G_IO_STATUS_NORMAL)
  1237. {
  1238. if (channel_error)
  1239. {
  1240. PLUGIN_ERROR_TWO ("Failed to write shutdown message to"
  1241. " appletviewer", channel_error->message);
  1242. g_error_free (channel_error);
  1243. channel_error = NULL;
  1244. }
  1245. else
  1246. PLUGIN_ERROR ("Failed to write shutdown message to");
  1247. }
  1248. if (g_io_channel_flush (data->out_to_appletviewer, &channel_error)
  1249. != G_IO_STATUS_NORMAL)
  1250. {
  1251. if (channel_error)
  1252. {
  1253. PLUGIN_ERROR_TWO ("Failed to write shutdown message to"
  1254. " appletviewer", channel_error->message);
  1255. g_error_free (channel_error);
  1256. channel_error = NULL;
  1257. }
  1258. else
  1259. PLUGIN_ERROR ("Failed to write shutdown message to");
  1260. }
  1261. if (g_io_channel_shutdown (data->out_to_appletviewer,
  1262. TRUE, &channel_error)
  1263. != G_IO_STATUS_NORMAL)
  1264. {
  1265. if (channel_error)
  1266. {
  1267. PLUGIN_ERROR_TWO ("Failed to shut down appletviewer"
  1268. " output channel", channel_error->message);
  1269. g_error_free (channel_error);
  1270. channel_error = NULL;
  1271. }
  1272. else
  1273. PLUGIN_ERROR ("Failed to shut down appletviewer");
  1274. }
  1275. }
  1276. if (data->in_from_appletviewer)
  1277. {
  1278. if (g_io_channel_shutdown (data->in_from_appletviewer,
  1279. TRUE, &channel_error)
  1280. != G_IO_STATUS_NORMAL)
  1281. {
  1282. if (channel_error)
  1283. {
  1284. PLUGIN_ERROR_TWO ("Failed to shut down appletviewer"
  1285. " input channel", channel_error->message);
  1286. g_error_free (channel_error);
  1287. channel_error = NULL;
  1288. }
  1289. else
  1290. PLUGIN_ERROR ("Failed to shut down appletviewer");
  1291. }
  1292. }
  1293. }
  1294. PLUGIN_DEBUG ("plugin_stop_appletviewer return");
  1295. }
  1296. static void
  1297. plugin_data_destroy (GCJPluginData** data)
  1298. {
  1299. PLUGIN_DEBUG ("plugin_data_destroy");
  1300. GCJPluginData* tofree = *data;
  1301. tofree->window_handle = NULL;
  1302. tofree->window_height = 0;
  1303. tofree->window_width = 0;
  1304. // Copied from GCJ_New.
  1305. // cleanup_in_watch_source:
  1306. // Removing a source is harmless if it fails since it just means the
  1307. // source has already been removed.
  1308. g_source_remove (tofree->in_watch_source);
  1309. tofree->in_watch_source = 0;
  1310. // cleanup_in_from_appletviewer:
  1311. if (tofree->in_from_appletviewer)
  1312. g_io_channel_unref (tofree->in_from_appletviewer);
  1313. tofree->in_from_appletviewer = NULL;
  1314. // cleanup_out_watch_source:
  1315. g_source_remove (tofree->out_watch_source);
  1316. tofree->out_watch_source = 0;
  1317. // cleanup_out_to_appletviewer:
  1318. if (tofree->out_to_appletviewer)
  1319. g_io_channel_unref (tofree->out_to_appletviewer);
  1320. tofree->out_to_appletviewer = NULL;
  1321. // cleanup_out_pipe:
  1322. // Delete output pipe.
  1323. unlink (tofree->out_pipe_name);
  1324. // cleanup_out_pipe_name:
  1325. g_free (tofree->out_pipe_name);
  1326. tofree->out_pipe_name = NULL;
  1327. // cleanup_in_pipe:
  1328. // Delete input pipe.
  1329. unlink (tofree->in_pipe_name);
  1330. // cleanup_in_pipe_name:
  1331. g_free (tofree->in_pipe_name);
  1332. tofree->in_pipe_name = NULL;
  1333. // cleanup_appletviewer_mutex:
  1334. g_free (tofree->appletviewer_mutex);
  1335. tofree->appletviewer_mutex = NULL;
  1336. // cleanup_instance_string:
  1337. g_free (tofree->instance_string);
  1338. tofree->instance_string = NULL;
  1339. // cleanup_data:
  1340. // Eliminate back-pointer to plugin instance.
  1341. tofree->owner = NULL;
  1342. (*browserFunctions.memfree) (tofree);
  1343. tofree = NULL;
  1344. PLUGIN_DEBUG ("plugin_data_destroy return");
  1345. }
  1346. // FACTORY FUNCTIONS
  1347. // Provides the browser with pointers to the plugin functions that we
  1348. // implement and initializes a local table with browser functions that
  1349. // we may wish to call. Called once, after browser startup and before
  1350. // the first plugin instance is created.
  1351. // The field 'initialized' is set to true once this function has
  1352. // finished. If 'initialized' is already true at the beginning of
  1353. // this function, then it is evident that NP_Initialize has already
  1354. // been called. There is no need to call this function more than once and
  1355. // this workaround avoids any duplicate calls.
  1356. NPError
  1357. NP_Initialize (NPNetscapeFuncs* browserTable, NPPluginFuncs* pluginTable)
  1358. {
  1359. PLUGIN_DEBUG ("NP_Initialize");
  1360. if (initialized)
  1361. return NPERR_NO_ERROR;
  1362. else if ((browserTable == NULL) || (pluginTable == NULL))
  1363. {
  1364. PLUGIN_ERROR ("Browser or plugin function table is NULL.");
  1365. return NPERR_INVALID_FUNCTABLE_ERROR;
  1366. }
  1367. // Ensure that the major version of the plugin API that the browser
  1368. // expects is not more recent than the major version of the API that
  1369. // we've implemented.
  1370. if ((browserTable->version >> 8) > NP_VERSION_MAJOR)
  1371. {
  1372. PLUGIN_ERROR ("Incompatible version.");
  1373. return NPERR_INCOMPATIBLE_VERSION_ERROR;
  1374. }
  1375. // Ensure that the plugin function table we've received is large
  1376. // enough to store the number of functions that we may provide.
  1377. if (pluginTable->size < sizeof (NPPluginFuncs))
  1378. {
  1379. PLUGIN_ERROR ("Invalid plugin function table.");
  1380. return NPERR_INVALID_FUNCTABLE_ERROR;
  1381. }
  1382. // Ensure that the browser function table is large enough to store
  1383. // the number of browser functions that we may use.
  1384. if (browserTable->size < sizeof (NPNetscapeFuncs))
  1385. {
  1386. PLUGIN_ERROR ("Invalid browser function table.");
  1387. return NPERR_INVALID_FUNCTABLE_ERROR;
  1388. }
  1389. data_directory = g_strconcat(getenv("HOME"), "/.gcjwebplugin", NULL);
  1390. whitelist_filename = g_strconcat (data_directory, "/whitelist.txt", NULL);
  1391. // Make sure the plugin data directory exists, creating it if
  1392. // necessary.
  1393. if (!g_file_test (data_directory,
  1394. (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
  1395. {
  1396. int file_error = 0;
  1397. file_error = g_mkdir (data_directory, 0700);
  1398. if (file_error != 0)
  1399. {
  1400. PLUGIN_ERROR_THREE ("Failed to create data directory",
  1401. data_directory,
  1402. strerror (errno));
  1403. return NPERR_GENERIC_ERROR;
  1404. }
  1405. }
  1406. // Store in a local table the browser functions that we may use.
  1407. browserFunctions.version = browserTable->version;
  1408. browserFunctions.size = browserTable->size;
  1409. browserFunctions.posturl = browserTable->posturl;
  1410. browserFunctions.geturl = browserTable->geturl;
  1411. browserFunctions.geturlnotify = browserTable->geturlnotify;
  1412. browserFunctions.requestread = browserTable->requestread;
  1413. browserFunctions.newstream = browserTable->newstream;
  1414. browserFunctions.write = browserTable->write;
  1415. browserFunctions.destroystream = browserTable->destroystream;
  1416. browserFunctions.status = browserTable->status;
  1417. browserFunctions.uagent = browserTable->uagent;
  1418. browserFunctions.memalloc = browserTable->memalloc;
  1419. browserFunctions.memfree = browserTable->memfree;
  1420. browserFunctions.memflush = browserTable->memflush;
  1421. browserFunctions.reloadplugins = browserTable->reloadplugins;
  1422. browserFunctions.getvalue = browserTable->getvalue;
  1423. // Return to the browser the plugin functions that we implement.
  1424. pluginTable->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
  1425. pluginTable->size = sizeof (NPPluginFuncs);
  1426. #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
  1427. pluginTable->newp = NewNPP_NewProc (GCJ_New);
  1428. pluginTable->destroy = NewNPP_DestroyProc (GCJ_Destroy);
  1429. pluginTable->setwindow = NewNPP_SetWindowProc (GCJ_SetWindow);
  1430. pluginTable->newstream = NewNPP_NewStreamProc (GCJ_NewStream);
  1431. pluginTable->destroystream = NewNPP_DestroyStreamProc (GCJ_DestroyStream);
  1432. pluginTable->asfile = NewNPP_StreamAsFileProc (GCJ_StreamAsFile);
  1433. pluginTable->writeready = NewNPP_WriteReadyProc (GCJ_WriteReady);
  1434. pluginTable->write = NewNPP_WriteProc (GCJ_Write);
  1435. pluginTable->print = NewNPP_PrintProc (GCJ_Print);
  1436. pluginTable->urlnotify = NewNPP_URLNotifyProc (GCJ_URLNotify);
  1437. pluginTable->getvalue = NewNPP_GetValueProc (GCJ_GetValue);
  1438. #else
  1439. pluginTable->newp = (NPP_NewProcPtr) (GCJ_New);
  1440. pluginTable->destroy = (NPP_DestroyProcPtr) (GCJ_Destroy);
  1441. pluginTable->setwindow = (NPP_SetWindowProcPtr) (GCJ_SetWindow);
  1442. pluginTable->newstream = (NPP_NewStreamProcPtr) (GCJ_NewStream);
  1443. pluginTable->destroystream = (NPP_DestroyStreamProcPtr) (GCJ_DestroyStream);
  1444. pluginTable->asfile = (NPP_StreamAsFileProcPtr) (GCJ_StreamAsFile);
  1445. pluginTable->writeready = (NPP_WriteReadyProcPtr) (GCJ_WriteReady);
  1446. pluginTable->write = (NPP_WriteProcPtr) (GCJ_Write);
  1447. pluginTable->print = (NPP_PrintProcPtr) (GCJ_Print);
  1448. pluginTable->urlnotify = (NPP_URLNotifyProcPtr) (GCJ_URLNotify);
  1449. pluginTable->getvalue = (NPP_GetValueProcPtr) (GCJ_GetValue);
  1450. #endif
  1451. initialized = true;
  1452. // Initialize threads (needed for mutexes).
  1453. if (!g_thread_supported ())
  1454. g_thread_init (NULL);
  1455. plugin_instance_mutex = g_mutex_new ();
  1456. PLUGIN_DEBUG ("NP_Initialize: using " APPLETVIEWER_EXECUTABLE ".");
  1457. PLUGIN_DEBUG ("NP_Initialize return");
  1458. return NPERR_NO_ERROR;
  1459. }
  1460. // Returns a string describing the MIME type that this plugin
  1461. // handles.
  1462. char*
  1463. NP_GetMIMEDescription (void)
  1464. {
  1465. PLUGIN_DEBUG ("NP_GetMIMEDescription");
  1466. PLUGIN_DEBUG ("NP_GetMIMEDescription return");
  1467. return (char*) PLUGIN_MIME_DESC;
  1468. }
  1469. // Returns a value relevant to the plugin as a whole. The browser
  1470. // calls this function to obtain information about the plugin.
  1471. NPError
  1472. NP_GetValue (void* future, NPPVariable variable, void* value)
  1473. {
  1474. PLUGIN_DEBUG ("NP_GetValue");
  1475. NPError result = NPERR_NO_ERROR;
  1476. gchar** char_value = (gchar**) value;
  1477. switch (variable)
  1478. {
  1479. case NPPVpluginNameString:
  1480. PLUGIN_DEBUG ("NP_GetValue: returning plugin name.");
  1481. *char_value = g_strdup (PLUGIN_NAME " " PACKAGE_VERSION);
  1482. break;
  1483. case NPPVpluginDescriptionString:
  1484. PLUGIN_DEBUG ("NP_GetValue: returning plugin description.");
  1485. *char_value = g_strdup (PLUGIN_DESC);
  1486. break;
  1487. default:
  1488. PLUGIN_ERROR ("Unknown plugin value requested.");
  1489. result = NPERR_GENERIC_ERROR;
  1490. break;
  1491. }
  1492. PLUGIN_DEBUG ("NP_GetValue return");
  1493. return result;
  1494. }
  1495. // Shuts down the plugin. Called after the last plugin instance is
  1496. // destroyed.
  1497. NPError
  1498. NP_Shutdown (void)
  1499. {
  1500. PLUGIN_DEBUG ("NP_Shutdown");
  1501. // Free mutex.
  1502. if (plugin_instance_mutex)
  1503. {
  1504. g_mutex_free (plugin_instance_mutex);
  1505. plugin_instance_mutex = NULL;
  1506. }
  1507. if (whitelist_file)
  1508. {
  1509. g_io_channel_close (whitelist_file);
  1510. whitelist_file = NULL;
  1511. }
  1512. if (data_directory)
  1513. {
  1514. g_free (data_directory);
  1515. data_directory = NULL;
  1516. }
  1517. if (whitelist_filename)
  1518. {
  1519. g_free (whitelist_filename);
  1520. whitelist_filename = NULL;
  1521. }
  1522. initialized = false;
  1523. PLUGIN_DEBUG ("NP_Shutdown return");
  1524. return NPERR_NO_ERROR;
  1525. }