00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "midgard/midgard_blob.h"
00020
00021 struct MidgardBlobPrivate {
00022 MgdObject *attachment;
00023 const gchar *filename;
00024 MidgardConnection *mgd;
00025 };
00026
00027
00028 MidgardBlob midgard_object_new(MidgardConection *mgd,
00029 MidgardObject *attachment)
00030 {
00031 MidgardBlob *self = g_object_new(MIDGARD_TYPE_BLOB, NULL);
00032 self->private->attachment = attachment;
00033
00034 const gchar *location;
00035 g_object_get(G_OBJECT(attachment),
00036 "location",
00037 (gchar)&location,
00038 NULL);
00039
00040
00041 if(location)
00042 self->private->attachment = location;
00043 }
00044
00045
00046 GIOChannel midgard_blob_read(MidgardBlob *self)
00047 {
00048 g_assert(self);
00049
00050 if(self->private->filename) {
00051 midgard_set_error(self->private->mgd->_mgd,
00052 MGD_GENERIC_ERROR,
00053 MGD_ERR_USER_DATA,
00054 "Invalid attachment. "
00055 "Can not read file from empty location");
00056 return NULL;
00057 }
00058
00059
00060 const gchar *blobdir = "";
00061 gchar *filepath = g_strconcat(blobdir,
00062 self->private->filename,
00063 NULL);
00064
00065 GError *err = NULL;
00066 GIOChannel *channel =
00067 g_io_channel_new_file(
00068 filepath,
00069 "r",
00070 &err);
00071 g_free(filepath);
00072
00073 if(!channel){
00074 midgard_set_error(self->mgd->_mgd,
00075 MGD_GENERIC_ERROR,
00076 MGD_ERR_USER_DATA,
00077 " %s ",
00078 err->message);
00079 g_clear_error(&err);
00080 return NULL;
00081 }
00082 }
00083
00084
00085 extern GIOChannel midgard_blob_write(MidgardBlob *self,
00086 const gchar *content);
00087
00088
00089 extern void midgard_blob_destroy(MidgardBlob *self);
00090
00091
00092
00093 static void _midgard_blob_instance_init(
00094 GTypeInstance *instance, gpointer g_class)
00095 {
00096 MidgardBlob *self = (MidgardBlob *) instance;
00097 self->private = g_new(MidgardBlobPrivate, 1);
00098
00099 self->private->attachment = NULL;
00100 self->private->filename = NULL;
00101 }
00102
00103 static void _midgard_blob_finalize(GObject *object)
00104 {
00105 g_assert(object);
00106
00107 g_free(self->private->filename);
00108 g_free(self->private);
00109
00110 }
00111
00112 static void _midgard_blob_class_init(
00113 gpointer g_class, gpointer g_class_data)
00114 {
00115 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
00116 MidgardBlobClass *klass = MIDGARD_BLOB_CLASS (g_class);
00117
00118 gobject_class->finalize = _midgard_collector_finalize;
00119 klass->read = midgard_blob_read;
00120 klass->write = midgard_blob_write;
00121 klass->destroy = midgard_blob_destroy;
00122
00123 }
00124
00125
00126 extern GType midgard_blob_get_type(void)
00127 {
00128 static GType type = 0;
00129 if (type == 0) {
00130 static const GTypeInfo info = {
00131 sizeof (MidgardBlobClass),
00132 NULL,
00133 NULL,
00134 (GClassInitFunc) _midgard_blob_class_init,
00135 NULL,
00136 NULL,
00137 sizeof (MidgardCollector),
00138 0,
00139 (GInstanceInitFunc) _midgard_blob_instance_init
00140 };
00141 type = g_type_register_static (G_TYPE_OBJECT,
00142 "midgard_blob",
00143 &info, 0);
00144 }
00145 return type;
00146 }
00147
00148
00149