/** * go_error_info_new_str_with_details: * @msg: error message * @details: #GOErrorInfo to add * * Creates a new #GOErrorInfo from @message and an existing #GOErrorInfo * instance to add to the message. * Returns: (transfer full): the newly created #GOErrorInfo **/ GOErrorInfo * go_error_info_new_str_with_details (char const *msg, GOErrorInfo *details) { GOErrorInfo *error = go_error_info_new_str (msg); go_error_info_add_details (error, details); return error; }
static void gplp_func_exec_action (GOPluginService *service, GnmAction const *action, WorkbookControl *wbc, GOErrorInfo **ret_error) { ServiceLoaderDataUI *loader_data; PyObject *fn, *ret; g_return_if_fail (_PyGObject_API != NULL); GO_INIT_RET_ERROR_INFO (ret_error); loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); fn = PyDict_GetItemString (loader_data->ui_actions, action->id); if (fn == NULL) { *ret_error = go_error_info_new_printf (_("Unknown action: %s"), action->id); return; } else if (!PyCallable_Check (fn)) { *ret_error = go_error_info_new_printf ( _("Not a valid function for action: %s"), action->id); return; } ret = PyObject_CallFunction (fn, (char *) "N", py_new_Gui_object (WBC_GTK (wbc))); if (ret == NULL) { *ret_error = go_error_info_new_str (py_exc_to_string ()); PyErr_Clear (); } else { Py_DECREF (ret); } }
void go_io_error_string (GOIOContext *context, const gchar *str) { GOErrorInfo *error; g_return_if_fail (context != NULL); g_return_if_fail (str != NULL); error = go_error_info_new_str (str); go_io_error_info_set (context, error); }
void psiconv_read (GOIOContext *io_context, Workbook *wb, GsfInput *input) { psiconv_buffer buf ; psiconv_config config = NULL; psiconv_file psi_file = NULL; if ((buf = psiconv_stream_to_buffer (input, -1)) == NULL) { go_io_error_info_set (io_context, go_error_info_new_str(_("Error while reading psiconv file."))); goto out; } if ((config = psiconv_config_default()) == NULL) goto out; config->verbosity = PSICONV_VERB_ERROR; psiconv_config_read(NULL,&config); if (psiconv_parse(config, buf, &psi_file) != 0) { psi_file = NULL; go_io_error_info_set (io_context, go_error_info_new_str(_("Error while parsing Psion file."))); goto out; } if (psi_file->type == psiconv_sheet_file) add_sheetfile(wb,psi_file->file); else go_io_error_info_set (io_context, go_error_info_new_str(_("This Psion file is not a Sheet file."))); out: if (config) psiconv_config_free(config); if (buf) psiconv_buffer_free(buf); if (psi_file) psiconv_free_file(psi_file); }
static void go_plugin_service_file_saver_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error) { xmlNode *information_node; gchar *description; GO_INIT_RET_ERROR_INFO (ret_error); information_node = go_xml_get_child_by_name (tree, "information"); if (information_node != NULL) { xmlNode *node = go_xml_get_child_by_name_by_lang (information_node, "description"); description = node ? xml2c (xmlNodeGetContent (node)) : NULL; } else { description = NULL; } if (description != NULL) { int scope = GO_FILE_SAVE_WORKBOOK; int level = GO_FILE_FL_WRITE_ONLY; GOPluginServiceFileSaver *psfs = GO_PLUGIN_SERVICE_FILE_SAVER (service); psfs->file_extension = xml2c (go_xml_node_get_cstr (tree, "file_extension")); psfs->mime_type = xml2c (go_xml_node_get_cstr (tree, "mime_type")); psfs->description = description; (void)go_xml_node_get_enum (tree, "format_level", GO_TYPE_FILE_FORMAT_LEVEL, &level); psfs->format_level = (GOFileFormatLevel)level; if (!go_xml_node_get_int (tree, "default_saver_priority", &(psfs->default_saver_priority))) psfs->default_saver_priority = -1; (void)go_xml_node_get_enum (tree, "save_scope", GO_TYPE_FILE_SAVE_SCOPE, &scope); psfs->save_scope = (GOFileSaveScope)scope; if (!go_xml_node_get_bool (tree, "overwrite_files", &(psfs->overwrite_files))) psfs->overwrite_files = TRUE; } else { *ret_error = go_error_info_new_str (_("File saver has no description")); } }
static void gplp_set_attributes (GOPluginLoader *loader, GHashTable *attrs, GOErrorInfo **ret_error) { GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader); gchar *module_name = NULL; GO_INIT_RET_ERROR_INFO (ret_error); module_name = g_hash_table_lookup (attrs, "module_name"); if (module_name != NULL) { loader_python->module_name = g_strdup (module_name); } else { *ret_error = go_error_info_new_str ( _("Python module name not given.")); } }
static void go_plugin_service_resource_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error) { GOPluginServiceResource *sr = GO_PLUGIN_SERVICE_RESOURCE (service); char *data = NULL; gsize length; xmlChar *file; GO_INIT_RET_ERROR_INFO (ret_error); sr->id = xml2c (go_xml_node_get_cstr (tree, "id")); if (!sr->id) goto error; file = go_xml_node_get_cstr (tree, "file"); if (file) { char *absfile; gboolean ok; if (!g_path_is_absolute (CXML2C (file))) { char const *dir = go_plugin_get_dir_name (go_plugin_service_get_plugin (service)); absfile = g_build_filename (dir, CXML2C (file), NULL); } else absfile = g_strdup (CXML2C (file)); xmlFree (file); ok = g_file_get_contents (absfile, &data, &length, NULL); g_free (absfile); if (!ok) goto error; } else { data = xml2c (go_xml_node_get_cstr (tree, "data")); length = strlen (data); } if (!data) goto error; /* No encoding case */ sr->value = g_string_sized_new (length); g_string_append_len (sr->value, data, length); g_free (data); return; error: *ret_error = go_error_info_new_str (_("Invalid resource service")); g_free (data); }
GOPluginService * go_plugin_service_new (GOPlugin *plugin, xmlNode *tree, GOErrorInfo **ret_error) { GOPluginService *service = NULL; char *type_str; GOErrorInfo *service_error = NULL; GOPluginServiceCreate ctor; g_return_val_if_fail (GO_IS_PLUGIN (plugin), NULL); g_return_val_if_fail (tree != NULL, NULL); g_return_val_if_fail (strcmp (tree->name, "service") == 0, NULL); GO_INIT_RET_ERROR_INFO (ret_error); type_str = go_xml_node_get_cstr (tree, "type"); if (type_str == NULL) { *ret_error = go_error_info_new_str (_("No \"type\" attribute on \"service\" element.")); return NULL; } ctor = g_hash_table_lookup (services, type_str); if (ctor == NULL) { *ret_error = go_error_info_new_printf (_("Unknown service type: %s."), type_str); xmlFree (type_str); return NULL; } xmlFree (type_str); service = g_object_new (ctor(), NULL); service->plugin = plugin; service->id = xml2c (go_xml_node_get_cstr (tree, "id")); if (service->id == NULL) service->id = xmlStrdup ("default"); if (GO_PLUGIN_SERVICE_GET_CLASS (service)->read_xml != NULL) { GO_PLUGIN_SERVICE_GET_CLASS (service)->read_xml (service, tree, &service_error); if (service_error != NULL) { *ret_error = go_error_info_new_str_with_details ( _("Error reading service information."), service_error); g_object_unref (service); service = NULL; } } return service; }
void dif_file_open (GOFileOpener const *fo, GOIOContext *io_context, WorkbookView *wbv, GsfInput *input) { Workbook *wb = wb_view_get_workbook (wbv); DifInputContext *ctxt = dif_input_context_new (io_context, wb, input); workbook_set_saveinfo (wb, GO_FILE_FL_MANUAL_REMEMBER, go_file_saver_for_id ("Gnumeric_dif:dif")); if (ctxt != NULL) { dif_parse_sheet (ctxt); if (go_io_error_occurred (io_context)) go_io_error_push (io_context, go_error_info_new_str (_("Error while reading DIF file."))); dif_input_context_destroy (ctxt); } else if (!go_io_error_occurred (io_context)) go_io_error_unknown (io_context); }
static void go_plugin_file_saver_save (GOFileSaver const *fs, GOIOContext *io_context, GoView const *view, GsfOutput *output) { GOPluginFileSaver *pfs = GO_PLUGIN_FILE_SAVER (fs); GOPluginServiceFileSaver *service_file_saver = GO_PLUGIN_SERVICE_FILE_SAVER (pfs->service); GOErrorInfo *error = NULL; g_return_if_fail (GSF_IS_OUTPUT (output)); go_plugin_service_load (pfs->service, &error); if (error != NULL) { go_io_error_info_set (io_context, error); go_io_error_push (io_context, go_error_info_new_str ( _("Error while loading plugin for saving."))); if (!gsf_output_error (output)) gsf_output_set_error (output, 0, _("Failed to load plugin for saving")); return; } g_return_if_fail (service_file_saver->cbs.plugin_func_file_save != NULL); service_file_saver->cbs.plugin_func_file_save (fs, pfs->service, io_context, view, output); }
static void go_plugin_file_opener_open (GOFileOpener const *fo, gchar const *enc, GOIOContext *io_context, GoView *view, GsfInput *input) { GOPluginFileOpener *pfo = GO_PLUGIN_FILE_OPENER (fo); GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (pfo->service); GOErrorInfo *error = NULL; g_return_if_fail (GSF_IS_INPUT (input)); go_plugin_service_load (pfo->service, &error); if (error != NULL) { go_io_error_info_set (io_context, error); go_io_error_push (io_context, go_error_info_new_str ( _("Error while reading file."))); return; } g_return_if_fail (service_file_opener->cbs.plugin_func_file_open != NULL); service_file_opener->cbs.plugin_func_file_open (fo, pfo->service, io_context, view, input, enc); }
static void go_plugin_service_file_opener_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error) { int priority; gboolean has_probe; gboolean encoding_dependent; xmlNode *information_node; gchar *description; GO_INIT_RET_ERROR_INFO (ret_error); if (go_xml_node_get_int (tree, "priority", &priority)) priority = CLAMP (priority, 0, 100); else priority = 50; if (!go_xml_node_get_bool (tree, "probe", &has_probe)) has_probe = TRUE; if (!go_xml_node_get_bool (tree, "encoding_dependent", &encoding_dependent)) encoding_dependent = FALSE; information_node = go_xml_get_child_by_name (tree, "information"); if (information_node != NULL) { xmlNode *node = go_xml_get_child_by_name_by_lang (information_node, "description"); description = node ? xml2c (xmlNodeGetContent (node)) : NULL; } else { description = NULL; } if (description != NULL) { GSList *suffixes = NULL, *mimes = NULL; xmlNode *list, *node; GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (service); list = go_xml_get_child_by_name (tree, "suffixes"); if (list != NULL) { for (node = list->xmlChildrenNode; node != NULL; node = node->next) { char *tmp; if (strcmp (node->name, "suffix")) continue; tmp = xml2c (xmlNodeGetContent (node)); if (!tmp) continue; GO_SLIST_PREPEND (suffixes, tmp); } } GO_SLIST_REVERSE (suffixes); list = go_xml_get_child_by_name (tree, "mime-types"); if (list != NULL) { for (node = list->xmlChildrenNode; node != NULL; node = node->next) { char *tmp; if (strcmp (node->name, "mime-type")) continue; tmp = xml2c (xmlNodeGetContent (node)); if (!tmp) continue; GO_SLIST_PREPEND (mimes, tmp); } } GO_SLIST_REVERSE (mimes); service_file_opener->priority = priority; service_file_opener->has_probe = has_probe; service_file_opener->encoding_dependent = encoding_dependent; service_file_opener->description = description; service_file_opener->suffixes = suffixes; service_file_opener->mimes = mimes; } else { *ret_error = go_error_info_new_str (_("File opener has no description")); } }
static void gplp_load_base (GOPluginLoader *loader, GOErrorInfo **ret_error) { static gchar const *python_file_extensions[] = {"py", "pyc", "pyo", NULL}; GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader); gchar const **file_ext; GnmPython *py_object; GnmPyInterpreter *py_interpreter_info; gchar *full_module_file_name = NULL; FILE *f; GOPlugin *plugin = go_plugin_loader_get_plugin (loader); GOErrorInfo *open_error = NULL; PyObject *modules, *main_module, *main_module_dict; GO_INIT_RET_ERROR_INFO (ret_error); g_object_set_data (G_OBJECT (plugin), "python-loader", loader); py_object = gnm_python_object_get (ret_error); if (py_object == NULL) return; /* gnm_python_object_get sets ret_error */ py_interpreter_info = gnm_python_new_interpreter (py_object, plugin); if (py_interpreter_info == NULL) { *ret_error = go_error_info_new_str (_("Cannot create new Python interpreter.")); gnm_python_clear_error_if_needed (py_object); g_object_unref (py_object); return; } for (file_ext = python_file_extensions; *file_ext != NULL; file_ext++) { gchar *file_name = g_strconcat ( loader_python->module_name, ".", *file_ext, NULL); gchar *path = g_build_filename ( go_plugin_get_dir_name (plugin), file_name, NULL); g_free (file_name); if (g_file_test (path, G_FILE_TEST_EXISTS)) { full_module_file_name = path; break; } else g_free (path); } if (full_module_file_name == NULL) { *ret_error = go_error_info_new_printf ( _("Module \"%s\" doesn't exist."), loader_python->module_name); gnm_python_destroy_interpreter (py_object, py_interpreter_info); g_object_unref (py_object); return; } f = gnumeric_fopen_error_info (full_module_file_name, "r", &open_error); g_free (full_module_file_name); if (f == NULL) { *ret_error = open_error; gnm_python_destroy_interpreter (py_object, py_interpreter_info); g_object_unref (py_object); return; } if (PyRun_SimpleFile (f, loader_python->module_name) != 0) { (void) fclose (f); *ret_error = go_error_info_new_printf ( _("Execution of module \"%s\" failed."), loader_python->module_name); gnm_python_destroy_interpreter (py_object, py_interpreter_info); g_object_unref (py_object); return; } (void) fclose (f); modules = PyImport_GetModuleDict (); g_return_if_fail (modules != NULL); main_module = PyDict_GetItemString (modules, (char *) "__main__"); g_return_if_fail (main_module != NULL); main_module_dict = PyModule_GetDict (main_module); g_return_if_fail (main_module_dict != NULL); loader_python->py_object = py_object; loader_python->py_interpreter_info = py_interpreter_info; loader_python->main_module = main_module; loader_python->main_module_dict = main_module_dict; }
void html_file_open (G_GNUC_UNUSED GOFileOpener const *fo, GOIOContext *io_context, WorkbookView *wb_view, GsfInput *input) { guint8 const *buf; gsf_off_t size; int len, bomlen; htmlParserCtxtPtr ctxt; htmlDocPtr doc = NULL; xmlCharEncoding enc; GnmHtmlTableCtxt tc; g_return_if_fail (input != NULL); if (gsf_input_seek (input, 0, G_SEEK_SET)) return; size = gsf_input_size (input); if (size >= 4) { size -= 4; buf = gsf_input_read (input, 4, NULL); if (buf != NULL) { enc = xmlDetectCharEncoding(buf, 4); switch (enc) { /* Skip byte order mark */ case XML_CHAR_ENCODING_UCS4BE: case XML_CHAR_ENCODING_UCS4LE: case XML_CHAR_ENCODING_UCS4_2143: case XML_CHAR_ENCODING_UCS4_3412: case XML_CHAR_ENCODING_EBCDIC: bomlen = 4; break; case XML_CHAR_ENCODING_UTF16BE: case XML_CHAR_ENCODING_UTF16LE: bomlen = 2; break; case XML_CHAR_ENCODING_UTF8: if (buf[0] == 0xef) bomlen = 3; else if (buf[0] == 0x3c) bomlen = 4; else bomlen = 0; break; case XML_CHAR_ENCODING_NONE: bomlen = 0; /* Try to detect unmarked UTF16LE (Firefox Windows clipboard, drag data all platforms) */ if ((buf[0] >= 0x20 || g_ascii_isspace(buf[0])) && buf[1] == 0 && (buf[2] >= 0x20 || g_ascii_isspace(buf[2])) && buf[3] == 0) enc = XML_CHAR_ENCODING_UTF16LE; break; default: bomlen = 0; } ctxt = htmlCreatePushParserCtxt ( NULL, NULL, (char const *)(buf + bomlen), 4 - bomlen, gsf_input_name (input), enc); for (; size > 0 ; size -= len) { len = MIN (4096, size); buf = gsf_input_read (input, len, NULL); if (buf == NULL) break; htmlParseChunk ( ctxt, (char const *)buf, len, 0); } htmlParseChunk (ctxt, (char const *)buf, 0, 1); doc = ctxt->myDoc; htmlFreeParserCtxt (ctxt); } } if (doc != NULL) { xmlNodePtr ptr; tc.sheet = NULL; tc.row = -1; tc.wb_view = wb_view; for (ptr = doc->children; ptr != NULL ; ptr = ptr->next) html_search_for_tables (ptr, doc, wb_view, &tc); xmlFreeDoc (doc); } else go_io_error_info_set (io_context, go_error_info_new_str (_("Unable to parse the html."))); }
GOErrorInfo * go_error_info_new_from_errno (void) { return go_error_info_new_str (g_strerror (errno)); }