[libsoup] SoupContentProcessor: new interface



commit 4bec9ebc81ffb5d20dc121ee7818272c697faaa6
Author: Sergio Villar Senin <svillar igalia com>
Date:   Mon Jul 30 13:31:05 2012 +0200

    SoupContentProcessor: new interface
    
    New SoupContentProcessor interface. It defines a _wrap_input() function which
    implementors will use to add their own stream on top of the given base
    stream.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682112

 libsoup/Makefile.am              |    2 +
 libsoup/soup-content-processor.c |   51 ++++++++++++++++++++++++++++++++++
 libsoup/soup-content-processor.h |   56 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/libsoup/Makefile.am b/libsoup/Makefile.am
index 7eebe9d..98f0b4b 100644
--- a/libsoup/Makefile.am
+++ b/libsoup/Makefile.am
@@ -115,6 +115,8 @@ libsoup_2_4_la_SOURCES =		\
 	soup-connection.h		\
 	soup-connection.c		\
 	soup-content-decoder.c		\
+	soup-content-processor.h	\
+	soup-content-processor.c	\
 	soup-content-sniffer.c		\
 	soup-content-sniffer-stream.h	\
 	soup-content-sniffer-stream.c	\
diff --git a/libsoup/soup-content-processor.c b/libsoup/soup-content-processor.c
new file mode 100644
index 0000000..8b959eb
--- /dev/null
+++ b/libsoup/soup-content-processor.c
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Igalia, S.L.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "soup-content-processor.h"
+#include "soup.h"
+
+static void soup_content_processor_default_init (SoupContentProcessorInterface *interface);
+
+G_DEFINE_INTERFACE (SoupContentProcessor, soup_content_processor, G_TYPE_OBJECT)
+
+static GInputStream *
+soup_content_processor_real_wrap_input (SoupContentProcessor *processor,
+					GInputStream *base_stream,
+					SoupMessage *msg,
+					GError **error)
+{
+	g_return_val_if_reached (NULL);
+}
+
+static void
+soup_content_processor_default_init (SoupContentProcessorInterface *interface)
+{
+	interface->processing_stage = SOUP_STAGE_INVALID;
+	interface->wrap_input = soup_content_processor_real_wrap_input;
+}
+
+GInputStream *
+soup_content_processor_wrap_input (SoupContentProcessor *processor,
+				   GInputStream *base_stream,
+				   SoupMessage *msg,
+				   GError **error)
+{
+	g_return_val_if_fail (SOUP_IS_CONTENT_PROCESSOR (processor), NULL);
+
+	return SOUP_CONTENT_PROCESSOR_GET_INTERFACE (processor)->wrap_input (processor, base_stream, msg, error);
+}
+
+SoupProcessingStage
+soup_content_processor_get_processing_stage (SoupContentProcessor *processor)
+{
+	g_return_val_if_fail (SOUP_IS_CONTENT_PROCESSOR (processor), SOUP_STAGE_INVALID);
+
+	return SOUP_CONTENT_PROCESSOR_GET_INTERFACE (processor)->processing_stage;
+}
diff --git a/libsoup/soup-content-processor.h b/libsoup/soup-content-processor.h
new file mode 100644
index 0000000..8ee04b2
--- /dev/null
+++ b/libsoup/soup-content-processor.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Igalia, S.L.
+ */
+
+
+#ifndef SOUP_CONTENT_PROCESSOR_H
+#define SOUP_CONTENT_PROCESSOR_H 1
+
+#include <libsoup/soup-types.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define SOUP_TYPE_CONTENT_PROCESSOR                 (soup_content_processor_get_type ())
+#define SOUP_CONTENT_PROCESSOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_CONTENT_PROCESSOR, SoupContentProcessor))
+#define SOUP_IS_CONTENT_PROCESSOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_CONTENT_PROCESSOR))
+#define SOUP_CONTENT_PROCESSOR_GET_INTERFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), SOUP_TYPE_CONTENT_PROCESSOR, SoupContentProcessorInterface))
+
+typedef enum {
+	SOUP_STAGE_INVALID,
+
+	SOUP_STAGE_MESSAGE_BODY,      /* Raw network data */
+	SOUP_STAGE_TRANSFER_ENCODING, /* SoupBodyInputStream is here */
+	SOUP_STAGE_ENTITY_BODY,       /* Has Transfer-Encoding removed */
+	SOUP_STAGE_CONTENT_ENCODING,  /* SoupContentDecoder works here */
+	SOUP_STAGE_BODY_DATA          /* Actual body data */
+} SoupProcessingStage;
+
+typedef struct _SoupContentProcessor             SoupContentProcessor;
+typedef struct _SoupContentProcessorInterface    SoupContentProcessorInterface;
+
+struct _SoupContentProcessorInterface {
+	GTypeInterface parent;
+
+	SoupProcessingStage processing_stage;
+
+	/* methods */
+	GInputStream*       (*wrap_input)             (SoupContentProcessor *processor,
+						       GInputStream         *base_stream,
+						       SoupMessage          *msg,
+						       GError              **error);
+};
+
+GType soup_content_processor_get_type (void);
+
+GInputStream       *soup_content_processor_wrap_input           (SoupContentProcessor *processor,
+								 GInputStream         *base_stream,
+								 SoupMessage          *msg,
+								 GError              **error);
+
+SoupProcessingStage soup_content_processor_get_processing_stage (SoupContentProcessor *processor);
+
+G_END_DECLS
+
+#endif /* SOUP_CONTENT_PROCESSOR_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]