char * irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key) { const char *dogechat_dir; char *key_path1, *key_path2, *content; if (!sasl_key) return NULL; content = NULL; dogechat_dir = dogechat_info_get ("dogechat_dir", ""); key_path1 = dogechat_string_replace (sasl_key, "%h", dogechat_dir); key_path2 = (key_path1) ? dogechat_string_expand_home (key_path1) : NULL; if (key_path2) content = dogechat_file_get_content (key_path2); if (!content) { dogechat_printf ( server->buffer, _("%s%s: unable to read private key in file \"%s\""), dogechat_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; }
int dogechat_js_load (const char *filename) { char *source; source = dogechat_file_get_content (filename); if (!source) { dogechat_printf (NULL, dogechat_gettext ("%s%s: script \"%s\" not found"), dogechat_prefix ("error"), JS_PLUGIN_NAME, filename); return 0; } if ((dogechat_js_plugin->debug >= 2) || !js_quiet) { dogechat_printf (NULL, dogechat_gettext ("%s: loading script \"%s\""), JS_PLUGIN_NAME, filename); } js_current_script = NULL; js_registered_script = NULL; js_current_interpreter = new DogechatJsV8(); if (!js_current_interpreter) { dogechat_printf (NULL, dogechat_gettext ("%s%s: unable to create new " "sub-interpreter"), dogechat_prefix ("error"), JS_PLUGIN_NAME); free (source); return 0; } /* load libs */ js_current_interpreter->loadLibs(); js_current_script_filename = filename; if (!js_current_interpreter->load(source)) { dogechat_printf (NULL, dogechat_gettext ("%s%s: unable to load file \"%s\""), dogechat_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 (dogechat_js_plugin, &js_scripts, &last_js_script, js_current_script); js_current_script = NULL; } return 0; } free (source); if (!js_current_interpreter->execScript()) { dogechat_printf (NULL, dogechat_gettext ("%s%s: unable to execute file " "\"%s\""), dogechat_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 (dogechat_js_plugin, &js_scripts, &last_js_script, js_current_script); js_current_script = NULL; } return 0; } if (!js_registered_script) { dogechat_printf (NULL, dogechat_gettext ("%s%s: function \"register\" not " "found (or failed) in file \"%s\""), dogechat_prefix ("error"), JS_PLUGIN_NAME, filename); delete js_current_interpreter; return 0; } 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 (dogechat_js_plugin, js_scripts, js_current_script, &dogechat_js_api_buffer_input_data_cb, &dogechat_js_api_buffer_close_cb); dogechat_hook_signal_send ("javascript_script_loaded", DOGECHAT_HOOK_SIGNAL_STRING, js_current_script->filename); return 1; }