char * irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key) { const char *weechat_dir; char *key_path1, *key_path2, *content; if (!sasl_key) return NULL; content = NULL; weechat_dir = weechat_info_get ("weechat_dir", ""); key_path1 = weechat_string_replace (sasl_key, "%h", weechat_dir); key_path2 = (key_path1) ? weechat_string_expand_home (key_path1) : NULL; if (key_path2) content = weechat_file_get_content (key_path2); if (!content) { weechat_printf ( server->buffer, _("%s%s: unable to read private key in file \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, (key_path2) ? key_path2 : ((key_path1) ? key_path1 : sasl_key)); } if (key_path1) free (key_path1); if (key_path2) free (key_path2); return content; }
struct t_plugin_script * weechat_js_load (const char *filename, const char *code) { char *source; /* make C compiler happy */ /* TODO: implement load of code in Javascript */ (void) code; source = weechat_file_get_content (filename); if (!source) { weechat_printf (NULL, weechat_gettext ("%s%s: script \"%s\" not found"), weechat_prefix ("error"), JS_PLUGIN_NAME, filename); return NULL; } if ((weechat_js_plugin->debug >= 2) || !js_quiet) { weechat_printf (NULL, weechat_gettext ("%s: loading script \"%s\""), JS_PLUGIN_NAME, filename); } js_current_script = NULL; js_registered_script = NULL; js_current_interpreter = new WeechatJsV8(); if (!js_current_interpreter) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to create new " "sub-interpreter"), weechat_prefix ("error"), JS_PLUGIN_NAME); free (source); return NULL; } /* load libs */ js_current_interpreter->loadLibs(); js_current_script_filename = filename; if (!js_current_interpreter->load(source)) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to load file \"%s\""), weechat_prefix ("error"), JS_PLUGIN_NAME); delete js_current_interpreter; free (source); /* if script was registered, remove it from list */ if (js_current_script) { plugin_script_remove (weechat_js_plugin, &js_scripts, &last_js_script, js_current_script); js_current_script = NULL; } return NULL; } free (source); if (!js_current_interpreter->execScript()) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to execute file " "\"%s\""), weechat_prefix ("error"), JS_PLUGIN_NAME, filename); delete js_current_interpreter; /* if script was registered, remove it from list */ if (js_current_script) { plugin_script_remove (weechat_js_plugin, &js_scripts, &last_js_script, js_current_script); js_current_script = NULL; } return NULL; } if (!js_registered_script) { weechat_printf (NULL, weechat_gettext ("%s%s: function \"register\" not " "found (or failed) in file \"%s\""), weechat_prefix ("error"), JS_PLUGIN_NAME, filename); delete js_current_interpreter; return NULL; } js_current_script = js_registered_script; /* * set input/close callbacks for buffers created by this script * (to restore callbacks after upgrade) */ plugin_script_set_buffer_callbacks (weechat_js_plugin, js_scripts, js_current_script, &weechat_js_api_buffer_input_data_cb, &weechat_js_api_buffer_close_cb); weechat_hook_signal_send ("javascript_script_loaded", WEECHAT_HOOK_SIGNAL_STRING, js_current_script->filename); return js_current_script; }