[libsoup/new-io] Add URI to directory stream so it can generate absolute URLs
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libsoup/new-io] Add URI to directory stream so it can generate absolute URLs
- Date: Sun, 20 Dec 2009 22:55:43 +0000 (UTC)
commit 1cafd48efea10b476df13ee468206292b01010c4
Author: Benjamin Otte <otte gnome org>
Date: Sun Dec 20 23:54:47 2009 +0100
Add URI to directory stream so it can generate absolute URLs
libsoup/soup-directory-input-stream.c | 26 ++++++++++++++++++--------
libsoup/soup-directory-input-stream.h | 4 +++-
libsoup/soup-request-file.c | 3 ++-
3 files changed, 23 insertions(+), 10 deletions(-)
---
diff --git a/libsoup/soup-directory-input-stream.c b/libsoup/soup-directory-input-stream.c
index 48fcfd0..43990f1 100644
--- a/libsoup/soup-directory-input-stream.c
+++ b/libsoup/soup-directory-input-stream.c
@@ -15,6 +15,7 @@
#include <string.h>
#include "soup-message-body.h"
+#include "soup-uri.h"
#define INIT_STRING "<html><head><title>OMG!</title></head><body><table>"
@@ -29,23 +30,26 @@ soup_directory_input_stream_parse_info (SoupDirectoryInputStream *stream,
SoupBuffer *buffer;
GString *string;
const char *s;
- char *escaped, *xml_string;
+ char *escaped, *path, *xml_string;
if (!g_file_info_get_name (info))
return NULL;
- string = g_string_new ("<tr>");
s = g_file_info_get_display_name (info);
if (!s) {
s = g_file_info_get_name (info);
- /* FIXME: convert somehow */
+ /* FIXME: convert somehow? */
if (!g_utf8_validate (s, -1, NULL))
- s = "Invalid filename";
+ return NULL;
}
- escaped = g_uri_escape_string (s, NULL, FALSE);
- xml_string = g_markup_escape_text (g_file_info_get_display_name (info), -1);
- g_string_append_printf (string, "<td><a href=\"%s\">%s</a></td>", escaped, xml_string);
+ string = g_string_new ("<tr>");
+
+ xml_string = g_markup_escape_text (s, -1);
+ escaped = g_uri_escape_string (g_file_info_get_name (info), NULL, FALSE);
+ path = g_strconcat (stream->uri, "/", escaped, NULL);
g_free (escaped);
+ g_string_append_printf (string, "<td><a href=\"%s\">%s</a></td>", path, xml_string);
+ g_free (path);
g_free (xml_string);
g_string_append (string, "</tr>");
@@ -142,6 +146,9 @@ soup_directory_input_stream_close (GInputStream *input,
error);
g_object_unref (stream->enumerator);
stream->enumerator = NULL;
+
+ g_free (stream->uri);
+ stream->uri = NULL;
return result;
}
@@ -164,15 +171,18 @@ soup_directory_input_stream_init (SoupDirectoryInputStream *stream)
}
GInputStream *
-soup_directory_input_stream_new (GFileEnumerator *enumerator)
+soup_directory_input_stream_new (GFileEnumerator *enumerator,
+ SoupURI *uri)
{
GInputStream *stream;
g_return_val_if_fail (G_IS_FILE_ENUMERATOR (enumerator), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
stream = g_object_new (SOUP_TYPE_DIRECTORY_INPUT_STREAM, NULL);
SOUP_DIRECTORY_INPUT_STREAM (stream)->enumerator = g_object_ref (enumerator);
+ SOUP_DIRECTORY_INPUT_STREAM (stream)->uri = soup_uri_to_string (uri, FALSE);
return stream;
}
diff --git a/libsoup/soup-directory-input-stream.h b/libsoup/soup-directory-input-stream.h
index 5d1040e..0a7bad7 100644
--- a/libsoup/soup-directory-input-stream.h
+++ b/libsoup/soup-directory-input-stream.h
@@ -26,6 +26,7 @@ struct _SoupDirectoryInputStream {
GInputStream parent;
GFileEnumerator *enumerator;
+ char *uri;
SoupBuffer *buffer;
gboolean done;
};
@@ -36,7 +37,8 @@ struct _SoupDirectoryInputStreamClass {
GType soup_directory_input_stream_get_type (void);
-GInputStream * soup_directory_input_stream_new (GFileEnumerator *enumerator);
+GInputStream * soup_directory_input_stream_new (GFileEnumerator *enumerator,
+ SoupURI *uri);
G_END_DECLS
diff --git a/libsoup/soup-request-file.c b/libsoup/soup-request-file.c
index 6bcbdaa..e50c06e 100644
--- a/libsoup/soup-request-file.c
+++ b/libsoup/soup-request-file.c
@@ -182,7 +182,8 @@ soup_request_file_send (SoupRequest *request,
cancellable,
error);
if (enumerator) {
- stream = soup_directory_input_stream_new (enumerator);
+ stream = soup_directory_input_stream_new (enumerator,
+ soup_request_get_uri (request));
g_object_unref (enumerator);
file->priv->mime_type = g_strdup ("text/html");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]