#ifdef HAVE_LIBXML_BUFFERING
#include <libxml/xmlreader.h>
#endif
+#include "lib.h" /* for captive_giochannel_setup(); FIXME: pathname */
/* CONFIG: */
struct captive_giochannel_blind {
GIOChannel iochannel;
- GIOChannel *giochannel_orig;
+ GIOChannel *giochannel_orig; /* reffed by us */
guint64 offset; /* gint64 range */
guint64 size;
GHashTable *buffer_hash; /* (guint64 *) -> (struct blind_block *) (guint8[GIOCHANNEL_BLIND_BLOCK_SIZE]) */
g_return_val_if_fail(validate_giochannel_blind(giochannel_blind),G_IO_STATUS_ERROR);
if (giochannel_blind->giochannel_orig) {
- /* We are not authorized to destroy 'giochannel_blind->giochannel_orig'. */
+ /* Just a sanity if 'giochannel_orig' is already falsely reffed a bit more... */
erriostatus=g_io_channel_flush(
giochannel_blind->giochannel_orig, /* channel */
NULL); /* error */
g_assert(erriostatus==G_IO_STATUS_NORMAL);
+
+ g_io_channel_unref(giochannel_blind->giochannel_orig);
giochannel_blind->giochannel_orig=NULL;
}
return g_io_channel_get_flags(giochannel_blind->giochannel_orig) | G_IO_FLAG_IS_WRITEABLE;
}
-void captive_giochannel_setup(GIOChannel *giochannel)
-{
-GIOStatus erriostatus;
-
- g_return_if_fail(giochannel!=NULL);
-
- if (g_io_channel_get_encoding(giochannel)) {
- if (!g_io_channel_get_buffered(giochannel)) /* Prevent: Need to have NULL encoding to set the buffering state ... */
- g_io_channel_set_buffered(giochannel,TRUE); /* Prevent: Need to set the channel buffered before setting the encoding. */
- erriostatus=g_io_channel_set_encoding(giochannel,
- NULL, /* encoding; force binary data */
- NULL); /* error */
- g_assert(erriostatus==G_IO_STATUS_NORMAL);
- }
- erriostatus=g_io_channel_flush(giochannel,
- NULL); /* error */
- g_assert(erriostatus==G_IO_STATUS_NORMAL);
- g_io_channel_set_buffered(giochannel,FALSE);
-}
-
struct captive_giochannel_blind *captive_giochannel_blind_new(GIOChannel *giochannel_orig,gboolean writeable)
{
if (giochannel_orig)
captive_giochannel_setup(giochannel_orig);
+ g_io_channel_ref(giochannel_orig);
+
captive_new(giochannel_blind);
g_assert(G_STRUCT_OFFSET(struct captive_giochannel_blind,iochannel)==0); /* safely re-type-able */
g_io_channel_init(&giochannel_blind->iochannel);