bool testWindowOpen(NPP npp) { NPIdentifier openId = browser->getstringidentifier("open"); NPObject* windowObject = 0; browser->getvalue(npp, NPNVWindowNPObject, &windowObject); if (!windowObject) return false; NPVariant openArgs[2]; STRINGZ_TO_NPVARIANT("about:blank", openArgs[0]); STRINGZ_TO_NPVARIANT("_blank", openArgs[1]); NPVariant result; if (!browser->invoke(npp, windowObject, openId, openArgs, 2, &result)) { browser->releaseobject(windowObject); return false; } if (result.type != NPVariantType_Object) { browser->releaseobject(windowObject); browser->releasevariantvalue(&result); return false; } pluginLogWithWindowObjectVariableArgs(windowObject, npp, "WINDOW OPEN SUCCESS"); notifyTestCompletion(npp, result.value.objectValue); browser->releaseobject(result.value.objectValue); browser->releaseobject(windowObject); return true; }
static void on_shell_signal (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { PluginObject *obj = user_data; if (strcmp (signal_name, "ExtensionStatusChanged") == 0) { gchar *uuid; gint32 status; gchar *error; NPVariant args[3]; NPVariant result; g_variant_get (parameters, "(sis)", &uuid, &status, &error); STRINGZ_TO_NPVARIANT (uuid, args[0]); INT32_TO_NPVARIANT (status, args[1]); STRINGZ_TO_NPVARIANT (error, args[2]); funcs.invokeDefault (obj->instance, obj->listener, args, 3, &result); funcs.releasevariantvalue (&result); g_free (uuid); g_free (error); } }
static bool pluginGetProperty(NPObject* obj, NPIdentifier name, NPVariant* result) { PluginObject* plugin = reinterpret_cast<PluginObject*>(obj); if (name == pluginPropertyIdentifiers[ID_PROPERTY_PROPERTY]) { static const char* originalString = "property"; char* buf = static_cast<char*>(browser->memalloc(strlen(originalString) + 1)); strcpy(buf, originalString); STRINGZ_TO_NPVARIANT(buf, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) { BOOLEAN_TO_NPVARIANT(plugin->eventLogging, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) { BOOLEAN_TO_NPVARIANT(plugin->logDestroy, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_HAS_STREAM]) { BOOLEAN_TO_NPVARIANT(plugin->stream != 0, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT]) { NPObject* testObject = plugin->testObject; browser->retainobject(testObject); OBJECT_TO_NPVARIANT(testObject, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) { BOOLEAN_TO_NPVARIANT(plugin->returnErrorFromNewStream, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_NEGATIVE_ONE_FROM_WRITE]) { BOOLEAN_TO_NPVARIANT(plugin->returnNegativeOneFromWrite, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_PRIVATE_BROWSING_ENABLED]) { NPBool privateBrowsingEnabled = FALSE; browser->getvalue(plugin->npp, NPNVprivateModeBool, &privateBrowsingEnabled); BOOLEAN_TO_NPVARIANT(privateBrowsingEnabled, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_CACHED_PRIVATE_BROWSING_ENABLED]) { BOOLEAN_TO_NPVARIANT(plugin->cachedPrivateBrowsingMode, *result); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_THROW_EXCEPTION_PROPERTY]) { browser->setexception(obj, "plugin object testThrowExceptionProperty SUCCESS"); return true; } else if (name == pluginPropertyIdentifiers[ID_LAST_SET_WINDOW_ARGUMENTS]) { char* buf = static_cast<char*>(browser->memalloc(256)); snprintf(buf, 256, "x: %d, y: %d, width: %u, height: %u, clipRect: (%u, %u, %u, %u)", (int)plugin->lastWindow.x, (int)plugin->lastWindow.y, (unsigned)plugin->lastWindow.width, (unsigned)plugin->lastWindow.height, plugin->lastWindow.clipRect.left, plugin->lastWindow.clipRect.top, plugin->lastWindow.clipRect.right - plugin->lastWindow.clipRect.left, plugin->lastWindow.clipRect.bottom - plugin->lastWindow.clipRect.top); STRINGZ_TO_NPVARIANT(buf, *result); return true; } return false; }
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (name == sFoo_id) { printf ("foo called!\n"); NPVariant docv; NPN_GetProperty(mNpp, sWindowObj, sDocument_id, &docv); NPObject *doc = NPVARIANT_TO_OBJECT(docv); NPVariant strv; STRINGZ_TO_NPVARIANT("div", strv); NPVariant divv; NPN_Invoke(mNpp, doc, sCreateElement_id, &strv, 1, &divv); STRINGZ_TO_NPVARIANT("I'm created by a plugin!", strv); NPVariant textv; NPN_Invoke(mNpp, doc, sCreateTextNode_id, &strv, 1, &textv); NPVariant v; NPN_Invoke(mNpp, NPVARIANT_TO_OBJECT(divv), sAppendChild_id, &textv, 1, &v); NPN_ReleaseVariantValue(&v); NPN_ReleaseVariantValue(&textv); NPVariant bodyv; NPN_GetProperty(mNpp, doc, sBody_id, &bodyv); NPN_Invoke(mNpp, NPVARIANT_TO_OBJECT(bodyv), sAppendChild_id, &divv, 1, &v); NPN_ReleaseVariantValue(&v); NPN_ReleaseVariantValue(&divv); NPN_ReleaseVariantValue(&bodyv); NPN_ReleaseVariantValue(&docv); STRINGZ_TO_NPVARIANT(strdup("foo return val"), *result); return PR_TRUE; } return PR_FALSE; }
bool ScriptablePluginObject::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result) { CString strMessage(_T("Welcome to use the IEMode Plugin for firefox!")); STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strMessage), *result); return true; }
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (name == sendCmd_id) { if ( argCount < 1 ) { return false; } PString strParam = ""; NPString npStr = NPVARIANT_TO_STRING( args[0] ); for (unsigned int i=0; i<npStr.utf8length; i++) { strParam += npStr.utf8characters[ i ]; } PString strResult = g_NativeLogic.InvokeFunction( strParam ); char* pszName = (char*)NPN_MemAlloc( strResult.GetSize() + 1 ); strcpy( pszName, strResult ); STRINGZ_TO_NPVARIANT(pszName, *result); return PR_TRUE; } return PR_FALSE; }
static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant) { if (name == pluginPropertyIdentifiers[ID_PROPERTY_PROPERTY]) { char* mem = static_cast<char*>(browser->memalloc(9)); strcpy(mem, "property"); STRINGZ_TO_NPVARIANT(mem, *variant); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) { BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->eventLogging, *variant); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) { BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->logDestroy, *variant); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_HAS_STREAM]) { BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->stream != 0, *variant); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT]) { NPObject *testObject = ((PluginObject *)obj)->testObject; browser->retainobject(testObject); OBJECT_TO_NPVARIANT(testObject, *variant); return true; } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT_COUNT]) { INT32_TO_NPVARIANT(getTestObjectCount(), *variant); return true; } return false; }
void ShockerScriptableControlObject::GetTestDefinition (const NPVariant *args, uint32_t arg_count, NPVariant *result) { char *test_definition; bool free_test_definition = false; char *retval; bool isJson = false; g_assert (arg_count <= 1); LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::GetTestDefinition ()\n", getpid ()); test_definition = getenv ("MOONLIGHT_HARNESS_TESTDEFINITION"); if (test_definition == NULL) { if (arg_count > 0) { g_assert (NPVARIANT_IS_BOOLEAN (args [0])); isJson = NPVARIANT_TO_BOOLEAN (args [0]); } test_definition = LogProvider::GetInstance ()->GetTestDefinition (isJson); free_test_definition = true; } retval = NPN_strdup (test_definition == NULL ? "" : test_definition); STRINGZ_TO_NPVARIANT (retval, *result); if (free_test_definition) g_free (test_definition); }
static bool plugin_get_metadata (PluginObject *obj, NPString uuid, NPVariant *result) { GError *error = NULL; GVariant *res; const gchar *json; gchar *buffer; res = g_dbus_proxy_call_sync (obj->proxy, "GetExtensionInfo", g_variant_new ("(s)", uuid.UTF8Characters), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */ NULL, /* cancellable */ &error); if (!res) { g_warning ("Failed to retrieve extension list: %s", error->message); g_error_free (error); return FALSE; } g_variant_get(res, "(&s)", &json); buffer = funcs.memalloc (strlen (json)); strcpy(buffer, json); STRINGZ_TO_NPVARIANT (buffer, *result); g_variant_unref (res); return TRUE; }
static void retrieve_highres_icon (WebappMonitor *monitor, const gchar *desktop_file) { GKeyFile *key_file; gchar *s; GError *error = NULL; /* Get URL to get icon for */ key_file = g_key_file_new (); if (!g_key_file_load_from_data (key_file, desktop_file, strlen (desktop_file), 0, &error)) { g_warning ("Could not parse desktop file: %s", error->message); g_error_free (error); goto out; } if (get_icon_size (key_file) >= 64) goto out; s = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL); if (s != NULL) { gint n_args, i; gchar **args, *url = NULL; g_debug ("Parsing command line %s", s); if (!g_shell_parse_argv (s, &n_args, &args, &error)) { g_debug ("Failed parsing command line %s", s); goto out; } for (i = 0; i < n_args && args[i] != NULL; i++) { g_debug ("Processing argument %s", args[i]); if (g_str_has_prefix (args[i], "--app=")) { url = g_strdup (args[i] + 6); g_debug ("Found URL %s", url); break; } } if (url != NULL) { NPVariant url_varg, result; STRINGZ_TO_NPVARIANT(url, url_varg); NULL_TO_NPVARIANT(result); if (!NPN_InvokeDefault (monitor->instance, monitor->icon_loader_callback, &url_varg, 1, &result)) g_debug ("Failed calling JS callback"); g_free (url); NPN_ReleaseVariantValue (&result); } g_strfreev (args); g_free (s); } out: g_key_file_free (key_file); }
static bool testEnumerate(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 2 || !NPVARIANT_IS_OBJECT(args[0]) || !NPVARIANT_IS_OBJECT(args[1])) return false; uint32_t count; NPIdentifier* identifiers; if (browser->enumerate(obj->npp, NPVARIANT_TO_OBJECT(args[0]), &identifiers, &count)) { NPObject* outArray = NPVARIANT_TO_OBJECT(args[1]); NPIdentifier pushIdentifier = browser->getstringidentifier("push"); for (uint32_t i = 0; i < count; i++) { NPUTF8* string = browser->utf8fromidentifier(identifiers[i]); if (!string) continue; NPVariant args[1]; STRINGZ_TO_NPVARIANT(string, args[0]); NPVariant browserResult; if (browser->invoke(obj->npp, outArray, pushIdentifier, args, 1, &browserResult)) browser->releasevariantvalue(&browserResult); browser->memfree(string); } browser->memfree(identifiers); } VOID_TO_NPVARIANT(*result); return true; }
static bool testGetProperty(NPObject* npobj, NPIdentifier name, NPVariant* result) { if (name == testIdentifiers[ID_PROPERTY_FOO]) { char* mem = static_cast<char*>(browser->memalloc(4)); strcpy(mem, "foo"); STRINGZ_TO_NPVARIANT(mem, *result); return true; } if (name == testIdentifiers[ID_PROPERTY_OBJECT_POINTER]) { int32_t objectPointer = static_cast<int32_t>(reinterpret_cast<long long>(npobj)); INT32_TO_NPVARIANT(objectPointer, *result); return true; } if (name == testIdentifiers[ID_PROPERTY_TEST_OBJECT]) { TestObject* testObject = reinterpret_cast<TestObject*>(npobj); if (!testObject->testObject) testObject->testObject = browser->createobject(0, &testClass); browser->retainobject(testObject->testObject); OBJECT_TO_NPVARIANT(testObject->testObject, *result); return true; } if (name == testIdentifiers[ID_PROPERTY_REF_COUNT]) { INT32_TO_NPVARIANT(npobj->referenceCount, *result); return true; } return false; }
CPlugin::CPlugin(NPP pNPInstance, int16_t argc, char* argn[], char* argv[]): m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(false), m_pScriptableObject(NULL) { #ifdef XP_WIN m_hWnd = NULL; #endif // code from npruntime, get browser version const char *ua = NPN_UserAgent(m_pNPInstance); strcpy(m_String, ua); // Here is an example of passing parameters from plugin to ScriptablePlugin // initialize id NPIdentifier code_id = NPN_GetStringIdentifier("code"); NPVariant v1; VOID_TO_NPVARIANT(v1); for (int16_t i = 0;i < argc;i++) { printf("%s = %s\n", argn[i], argv[i]); if (!strcmp(argn[i],"code")) { STRINGZ_TO_NPVARIANT(m_strdup(argv[i]),v1); } } NPObject *myobj = this->GetScriptableObject(); NPN_SetProperty(m_pNPInstance, myobj, code_id, &v1); NPN_ReleaseObject(myobj); }
static bool systemGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant) { if (name == systemPropertyIdentifiers[SYSTEM_PROPERTY_VERSION]) { STRINGZ_TO_NPVARIANT(strdup(SYSTEM_VERSION), *variant); return true; } return false; }
void ShockerScriptableControlObject::GetPlatformVersion (const NPVariant *args, uint32_t arg_count, NPVariant *result) { char *retval; retval = NPN_strdup (LogProvider::GetInstance ()->GetPlatformVersion ()); LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::GetPlatformVersion (): %s\n", getpid (), retval); STRINGZ_TO_NPVARIANT (retval, *result); }
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result) { VOID_TO_NPVARIANT(*result); //kk /*if (name == sBar_id) { static int a = 17; INT32_TO_NPVARIANT(a, *result); a += 5; return true; }*/ char *pProp = NPN_UTF8FromIdentifier(name); if( !strcmp( "Version", pProp ) ) { char *p = (char*) NPN_MemAlloc( "Version 1.0" );//allocating Memory for the string with invocation of Browser-API STRINGZ_TO_NPVARIANT( p, *result); return true; } if( !strcmp( "Name", pProp ) ) { char *p = (char*) NPN_MemAlloc( m_pszName );//allocating Memory for the string with invocation of Browser-API STRINGZ_TO_NPVARIANT( p, *result); return true; } if (name == sPluginType_id) { NPObject *myobj = NPN_CreateObject(mNpp, GET_NPOBJECT_CLASS(ConstructablePluginObject)); if (!myobj) { return false; } OBJECT_TO_NPVARIANT(myobj, *result); return true; } return true; }
gboolean mmp_script_element_set_property_string (NPP npp, NPVariant *element, const gchar *property_name, const gchar *property_value) { NPVariant string; STRINGZ_TO_NPVARIANT (property_value, string); return NPN_SetProperty (npp, NPVARIANT_TO_OBJECT (*element), NPN_GetStringIdentifier (property_name), &string); }
bool scriptGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result) { DEBUG_TRACE("scriptGetProperty"); DEBUG_NPIDENTIFIER(DEBUG_LEVEL_INFO, name); STRINGZ_TO_NPVARIANT("HELLO", *result); DEBUG_NPVARIANT(DEBUG_LEVEL_INFO, *result); return true; }
bool testDocumentOpen(NPP npp) { NPIdentifier documentId = browser->getstringidentifier("document"); NPIdentifier openId = browser->getstringidentifier("open"); NPObject* windowObject = 0; browser->getvalue(npp, NPNVWindowNPObject, &windowObject); if (!windowObject) return false; NPVariant docVariant; browser->getproperty(npp, windowObject, documentId, &docVariant); if (docVariant.type != NPVariantType_Object) { browser->releaseobject(windowObject); return false; } NPObject* documentObject = NPVARIANT_TO_OBJECT(docVariant); NPVariant openArgs[2]; STRINGZ_TO_NPVARIANT("text/html", openArgs[0]); STRINGZ_TO_NPVARIANT("_blank", openArgs[1]); NPVariant result; if (!browser->invoke(npp, documentObject, openId, openArgs, 2, &result)) { browser->releaseobject(windowObject); browser->releaseobject(documentObject); return false; } browser->releaseobject(documentObject); if (result.type != NPVariantType_Object) { browser->releaseobject(windowObject); browser->releasevariantvalue(&result); return false; } pluginLogWithWindowObjectVariableArgs(windowObject, npp, "DOCUMENT OPEN SUCCESS"); notifyTestCompletion(npp, result.value.objectValue); browser->releaseobject(result.value.objectValue); browser->releaseobject(windowObject); return true; }
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result) { VOID_TO_NPVARIANT(*result);// set result to void if (!HasProperty(name)) { return false; } NPIdentifier keyword_id = NPN_GetStringIdentifier("keyword"); NPIdentifier code_id = NPN_GetStringIdentifier("code"); if (name == keyword_id) { if (keyword) STRINGZ_TO_NPVARIANT(m_strdup(keyword), *result);// add reference here } else if (name == code_id) { if (code) STRINGZ_TO_NPVARIANT(m_strdup(code), *result);// add reference here } return true; }
bool CNPPluginMisc::SetRetValue(char *psz_ret,NPVariant *result) { int len = strlen(psz_ret); char *tmp = (char*)NPN_MemAlloc(len+1); strncpy(tmp,psz_ret,len); tmp[len] = '\0'; STRINGZ_TO_NPVARIANT(tmp,*result); return true; }
bool ScriptablePluginObject::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result) { printf ("ScriptablePluginObject default method called!\n"); STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result); return TRUE; }
bool scriptInvokeDefaultMethod(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result) { DEBUG_TRACE("scriptInvokeDefaultMethod"); STRINGZ_TO_NPVARIANT("HELLO", *result); DEBUG_NPVARIANT(DEBUG_LEVEL_INFO, *result); return true; }
/** * invoke method +name+ on +npobj+ with +argCount+ arguments specified * in array +args+; return the result in +result+ */ bool scriptInvokeMethod(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { DEBUG_TRACE("scriptInvokeMethod"); DEBUG_NPIDENTIFIER(DEBUG_LEVEL_INFO, name); STRINGZ_TO_NPVARIANT("HELLO", *result); DEBUG_NPVARIANT(DEBUG_LEVEL_INFO, *result); return true; }
static bool testIdentifierToString(PluginObject*, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 1) return true; NPIdentifier identifier = variantToIdentifier(args[0]); if (!identifier) return true; NPUTF8* utf8String = browser->utf8fromidentifier(identifier); if (!utf8String) return true; STRINGZ_TO_NPVARIANT(utf8String, *result); return true; }
// This function is equivalent to the following JavaScript function: // function FireEvent(strEventType, strDetail) { // FireIEContainer.dispatchEvent(strEventType, strDetail) // } // // Uses following JavaScript code to listen to the event fired: // pluginObject.addEventListener(strEventType, function(event) { // alert(event.detail); // } BOOL CPlugin::FireEvent(const CString &strEventType, const CString &strDetail) { // Fast event dispatching, requires helper function in container object try { // FireIEContainer.dispatchEvent(strEventType, strDetail); NPObject* pContainer = GetContainer(); NPVariant args[2]; STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strEventType), args[0]); STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strDetail), args[1]); NPVariant vSucceeded; VOID_TO_NPVARIANT(vSucceeded); BOOL bOK = NPN_Invoke(m_pNPInstance, pContainer, GetIdentifier("dispatchEvent"), args, 2, &vSucceeded); for (int i = 0; i < 2; i++) NPN_ReleaseVariantValue(&args[i]); if (!bOK || !NPVARIANT_IS_BOOLEAN(vSucceeded)) { NPN_ReleaseVariantValue(&vSucceeded); throw CString(_T("Cannot invoke dispatchEvent")); } bool bSucceeded = NPVARIANT_TO_BOOLEAN(vSucceeded); NPN_ReleaseVariantValue(&vSucceeded); if (!bSucceeded) throw CString(_T("Event dispatch failed")); return TRUE; } catch (const CString& strMessage) { UNUSED(strMessage); TRACE(_T("[CPlugin::FireEvent Exception] Fast event dispatching failed: %s\n"), strMessage); return FALSE; } }
bool ScriptablePluginObject::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result) { printf ("ScriptablePluginObject default method called!\n"); const char* outString = "default method return val"; char* npOutString = (char *)NPN_MemAlloc(strlen(outString) + 1); if (!npOutString) return false; strcpy(npOutString, outString); STRINGZ_TO_NPVARIANT(npOutString, *result); return true; }
static gboolean invoke_in_s_out_o (NPP npp, NPVariant *object, NPIdentifier method, const gchar *in_s, NPVariant *out_o) { NPVariant string; STRINGZ_TO_NPVARIANT (in_s, string); VOID_TO_NPVARIANT (*out_o); if (!NPN_Invoke (npp, NPVARIANT_TO_OBJECT (*object), method, &string, 1, out_o) || !NPVARIANT_IS_OBJECT (*out_o)) { NPN_ReleaseVariantValue (out_o); return FALSE; } return TRUE; }
static bool do_exec(const NPVariant cmd, NPVariant *result) { bool ret = false; const char *cmd_str; char *out_str; FILE *fp = NULL; char buf[1024 * 1024]; /* set default return value */ NULL_TO_NPVARIANT(*result); /* init algor */ if (!NPVARIANT_IS_STRING(cmd)) { fprintf(stderr, "%s (%s %d): invalid argument type\n", prog, __FILE__, __LINE__); goto end; } if (!(cmd_str = NPVARIANT_TO_STRING(cmd).UTF8Characters)) { fprintf(stderr, "%s (%s %d): invalid argument value\n", prog, __FILE__, __LINE__); goto end; } if (strlen(cmd_str) <= 0) { fprintf(stderr, "%s (%s %d): invalid argument value\n", prog, __FILE__, __LINE__); goto end; } if (!(fp = popen(cmd_str, "r"))) { fprintf(stderr, "%s (%s %d): execute `%s' failed\n", prog, __FILE__, __LINE__, cmd_str); goto end; } buf[0] = 0; fread(buf, 1, sizeof(buf), fp); if (!(out_str = strdup(buf))) { fprintf(stderr, "%s (%s %d): inner error\n", prog, __FILE__, __LINE__); goto end; } /* set output */ STRINGZ_TO_NPVARIANT(out_str, *result); ret = true; end: if (fp) pclose(fp); return ret; }
static void cloud_spy_log (const gchar * log_domain, GLogLevelFlags log_level, const gchar * message, gpointer user_data) { NPNetscapeFuncs * browser = cloud_spy_nsfuncs; NPP instance = static_cast<NPP> (user_data); NPObject * window = NULL, * console = NULL; NPVariant variant, result; NPError error; (void) log_domain; (void) log_level; error = browser->getvalue (instance, NPNVWindowNPObject, &window); if (error != NPERR_NO_ERROR) goto beach; VOID_TO_NPVARIANT (variant); if (!browser->getproperty (instance, window, browser->getstringidentifier ("console"), &variant)) goto beach; console = NPVARIANT_TO_OBJECT (variant); STRINGZ_TO_NPVARIANT (message, variant); VOID_TO_NPVARIANT (result); if (!browser->invoke (instance, console, browser->getstringidentifier ("log"), &variant, 1, &result)) goto beach; browser->releasevariantvalue (&result); beach: if (console != NULL) browser->releaseobject (console); if (window != NULL) browser->releaseobject (window); }