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 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; }
gboolean go_xml_node_get_bool (xmlNodePtr node, char const *name, gboolean *val) { xmlChar *buf = go_xml_node_get_cstr (node, name); if (buf == NULL) return FALSE; *val = (!strcmp (CXML2C (buf), "1") || 0 == g_ascii_strcasecmp (CXML2C (buf), "true")); xmlFree (buf); return TRUE; }
gboolean go_xml_node_get_double (xmlNodePtr node, char const *name, double *val) { xmlChar *buf; char *end; gboolean ok; buf = go_xml_node_get_cstr (node, name); if (buf == NULL) return FALSE; errno = 0; /* strto(ld) sets errno, but does not clear it. */ *val = strtod (CXML2C (buf), &end); ok = (CXML2C (buf) != end) && *end == 0 && errno != ERANGE; xmlFree (buf); return ok; }
gboolean go_xml_node_get_int (xmlNodePtr node, char const *name, int *val) { xmlChar *buf; char *end; gboolean ok; long l; buf = go_xml_node_get_cstr (node, name); if (buf == NULL) return FALSE; errno = 0; /* strto(ld) sets errno, but does not clear it. */ *val = l = strtol (CXML2C (buf), &end, 10); ok = (CXML2C (buf) != end) && *end == 0 && errno != ERANGE && (*val == l); xmlFree (buf); return ok; }