static void gsf_output_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GsfOutput *output = GSF_OUTPUT (object); /* gsf_off_t is typedef'd to gint64 */ switch (property_id) { case PROP_NAME: g_value_set_string (value, gsf_output_name (output)); break; case PROP_SIZE: g_value_set_int64 (value, gsf_output_size (output)); break; case PROP_CLOSED: g_value_set_boolean (value, gsf_output_is_closed (output)); break; case PROP_POS: g_value_set_int64 (value, gsf_output_tell (output)); break; case PROP_MODTIME: g_value_set_boxed (value, gsf_output_get_modtime (output)); break; case PROP_CONTAINER: g_value_set_object (value, output->container); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void gsf_outfile_msole_finalize (GObject *obj) { GsfOutfileMSOle *ole = GSF_OUTFILE_MSOLE (obj); GsfOutput *output = GSF_OUTPUT (obj); if (!gsf_output_is_closed (output)) gsf_output_close (output); if (ole->sink != NULL) { g_object_unref (G_OBJECT (ole->sink)); ole->sink = NULL; } switch (ole->type) { case MSOLE_DIR: g_slist_free (ole->content.dir.children); ole->content.dir.children = NULL; if (ole->content.dir.root_order != NULL) g_warning ("Finalizing a MSOle Outfile without closing it."); break; case MSOLE_SMALL_BLOCK: g_free (ole->content.small_block.buf); ole->content.small_block.buf = NULL; break; case MSOLE_BIG_BLOCK: break; default : g_warning ("Unknown file type"); } parent_class->finalize (obj); }
static void gsf_output_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { /* gsf_off_t is typedef'd to gint64 */ switch (property_id) { case PROP_NAME: g_value_set_string (value, gsf_output_name (GSF_OUTPUT (object))); break; case PROP_SIZE: g_value_set_int64 (value, gsf_output_size (GSF_OUTPUT (object))); break; case PROP_POS: g_value_set_int64 (value, gsf_output_tell (GSF_OUTPUT (object))); break; case PROP_CLOSED: g_value_set_boolean (value, gsf_output_is_closed (GSF_OUTPUT (object))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static gboolean zip_close_root (GsfOutput *output) { GsfOutfileZip *zip = GSF_OUTFILE_ZIP (output); GsfOutfileZip *child; gsf_off_t dirpos = gsf_output_tell (zip->sink); GPtrArray *elem = zip->root_order; unsigned entries = elem->len; unsigned i; /* Check that children are closed */ for (i = 0 ; i < elem->len ; i++) { child = g_ptr_array_index (elem, i); if (!gsf_output_is_closed (GSF_OUTPUT (child))) { g_warning ("Child still open"); return FALSE; } } /* Write directory */ for (i = 0 ; i < entries ; i++) { child = g_ptr_array_index (elem, i); if (!zip_dirent_write (zip->sink, child->vdir->dirent)) return FALSE; } disconnect_children (zip); return zip_trailer_write (zip, entries, dirpos); }
/* Close all dirs, non-NULL on error. */ static void * vips_gsf_tree_close( VipsGsfDirectory *tree ) { vips_slist_map2( tree->children, (VipsSListMap2Fn) vips_gsf_tree_close, NULL, NULL ); if( tree->out && !gsf_output_is_closed( tree->out ) && !gsf_output_close( tree->out ) ) { vips_error( "vips_gsf", "%s", _( "unable to close stream" ) ); return( tree ); } if( tree->container && !gsf_output_is_closed( tree->container ) && !gsf_output_close( tree->container ) ) { vips_error( "vips_gsf", "%s", _( "unable to close stream" ) ); return( tree ); } return( NULL ); }
/* Close and unref everything, can't fail. Call vips_gsf_tree_close() to get * an error return. */ static void * vips_gsf_tree_free( VipsGsfDirectory *tree ) { vips_slist_map2( tree->children, (VipsSListMap2Fn) vips_gsf_tree_free, NULL, NULL ); g_slist_free( tree->children ); g_free( (char *) tree->name ); if( tree->out ) { if( !gsf_output_is_closed( tree->out ) ) (void) gsf_output_close( tree->out ); g_object_unref( tree->out ); } if( tree->container ) { if( !gsf_output_is_closed( tree->container ) ) (void) gsf_output_close( tree->container ); g_object_unref( tree->container ); } g_free( tree ); return( NULL ); }
static void gsf_output_stdio_finalize (GObject *obj) { GsfOutput *output = (GsfOutput *)obj; GsfOutputStdio *stdio = GSF_OUTPUT_STDIO (output); if (!gsf_output_is_closed (output)) gsf_output_close (output); g_free (stdio->real_filename); stdio->real_filename = NULL; g_free (stdio->temp_filename); stdio->temp_filename = NULL; parent_class->finalize (obj); }
static gboolean gsf_outfile_open_pkg_close (GsfOutput *output) { GsfOutfileOpenPkg *open_pkg = GSF_OUTFILE_OPEN_PKG (output); GsfOutput *dir; gboolean res = FALSE; char *rels_name; if (NULL == open_pkg->sink || gsf_output_is_closed (open_pkg->sink)) return TRUE; /* Generate [Content_types].xml when we close the root dir */ if (NULL == gsf_output_name (output)) { GsfOutput *out = gsf_outfile_new_child (GSF_OUTFILE (open_pkg->sink), "[Content_Types].xml", FALSE); GsfXMLOut *xml = gsf_xml_out_new (out); gsf_xml_out_start_element (xml, "Types"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", "http://schemas.openxmlformats.org/package/2006/content-types"); gsf_open_pkg_write_content_default (xml, "rels", "application/vnd.openxmlformats-package.relationships+xml"); gsf_open_pkg_write_content_default (xml, "xlbin", "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings"); gsf_open_pkg_write_content_default (xml, "xml", "application/xml"); gsf_open_pkg_write_content_override (open_pkg, "/", xml); gsf_xml_out_end_element (xml); /* </Types> */ g_object_unref (xml); gsf_output_close (out); g_object_unref (out); dir = open_pkg->sink; rels_name = g_strdup (".rels"); } else { res = gsf_output_close (open_pkg->sink); dir = (GsfOutput *)gsf_output_container (open_pkg->sink); rels_name = g_strconcat (gsf_output_name (output), ".rels", NULL); } if (NULL != open_pkg->relations) { GsfOutput *rels; GsfXMLOut *xml; GsfOpenPkgRel *rel; GSList *ptr; dir = gsf_outfile_new_child (GSF_OUTFILE (dir), "_rels", TRUE); rels = gsf_outfile_new_child (GSF_OUTFILE (dir), rels_name, FALSE); xml = gsf_xml_out_new (rels); gsf_xml_out_start_element (xml, "Relationships"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", "http://schemas.openxmlformats.org/package/2006/relationships"); for (ptr = open_pkg->relations ; ptr != NULL ; ptr = ptr->next) { rel = ptr->data; gsf_xml_out_start_element (xml, "Relationship"); gsf_xml_out_add_cstr (xml, "Id", rel->id); gsf_xml_out_add_cstr (xml, "Type", rel->type); gsf_xml_out_add_cstr (xml, "Target", rel->target); if (rel->is_extern) gsf_xml_out_add_cstr_unchecked (xml, "TargetMode", "External"); gsf_xml_out_end_element (xml); /* </Relationship> */ g_free (rel->id); g_free (rel->type); g_free (rel->target); g_free (rel); } g_slist_free (open_pkg->relations); gsf_xml_out_end_element (xml); /* </Relationships> */ g_object_unref (xml); gsf_output_close (rels); g_object_unref (rels); g_object_unref (dir); } g_free (rels_name); /* close the container */ if (NULL == gsf_output_name (output)) return gsf_output_close (open_pkg->sink); return res; }