gboolean midgard_core_object_parameters_purge_with_blob( MidgardConnection *mgd, const gchar *class_name, const gchar *guid, guint n_params, const GParameter *parameters) { g_assert(mgd != NULL); g_assert(class_name != NULL); g_assert(guid != NULL); GObject **objects = __fetch_parameter_objects( mgd, class_name, guid, n_params, parameters); /* nothing to purge */ if(!objects) return FALSE; gboolean rv = FALSE; guint i = 0; MidgardBlob *blob = NULL; while (objects[i] != NULL ) { /* ! IMPORTANT ! * Blob on filesystem must be deleted first. * In any other case, if something goes wrong, we won't be able * to check which file is orphaned. * If file is removed and record's deletion failed, on is able * to check file with blob's file_exists method */ blob = midgard_blob_new(MIDGARD_OBJECT(objects[i]), NULL); if(!blob) { g_warning("Can not handle blob for given attachment"); continue; } if(midgard_blob_exists(blob)) midgard_blob_remove_file(blob, NULL); midgard_object_purge(MIDGARD_OBJECT(objects[i]), FALSE); g_object_unref(blob); g_object_unref(objects[i]); i++; } g_free(objects); return rv; }
/** * midgard_replicator_serialize_blob: * @object: #MidgardObject of MIDGARD_TYPE_ATTACHMENT type * * Serialize midgard_blob binary data. * * Returns: Newly allocated xml buffer, which holds blob data base64 encoded, or %NULL. */ gchar * midgard_replicator_serialize_blob (MidgardObject *object) { GType attachment_type = g_type_from_name ("midgard_attachment"); g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (object), attachment_type), NULL); MidgardBlob *blob = midgard_blob_new(object, NULL); if(!blob) return NULL; gsize bytes_read = 0; gchar *content = midgard_blob_read_content(blob, &bytes_read); if(!content) { g_object_unref(blob); return NULL; } gchar *encoded = g_base64_encode((const guchar *)content, bytes_read); g_free(content); xmlDoc *doc = midgard_core_object_create_xml_doc(); xmlNode *root_node = xmlDocGetRootElement(doc); xmlNode *blob_node = xmlNewTextChild(root_node, NULL, (const xmlChar*) "midgard_blob", BAD_CAST encoded); xmlNewProp(blob_node, BAD_CAST "guid", BAD_CAST MGD_OBJECT_GUID (object)); g_free(encoded); g_object_unref (blob); xmlChar *buf; gint size; xmlDocDumpFormatMemoryEnc(doc, &buf, &size, "UTF-8", 1); xmlFreeDoc(doc); xmlCleanupParser(); return (gchar*) buf; }
/** * midgard_blob_create_blob: * * Invokes midgard_blob_new() and it's designed for language bindings, in whic, * that function can not be invoked explicitly. * * Since: 10.05.1 */ MidgardBlob* midgard_blob_create_blob (MidgardObject *attachment, const gchar *encoding) { return midgard_blob_new (attachment, encoding); }