gvfs r1515 - in trunk: . daemon
- From: gicmo svn gnome org
- To: svn-commits-list gnome org
- Subject: gvfs r1515 - in trunk: . daemon
- Date: Mon, 3 Mar 2008 21:01:13 +0000 (GMT)
Author: gicmo
Date: Mon Mar 3 21:01:13 2008
New Revision: 1515
URL: http://svn.gnome.org/viewvc/gvfs?rev=1515&view=rev
Log:
2008-03-03 Christian Kellner <gicmo gnome org>
* daemon/gvfsbackendhttp.c:
* daemon/gvfsbackendhttp.h:
Remove unecessary message_new_from_xxx functions. Prefix all
public utility functions that need the backend with
http_backend_, i.e. rename g_vfs_backend_uri_for_filename() to
http_backend_uri_for_filename().
Create http_backend_send_message(), http_backend_queue_message()
convenience functions which will pick up the right SoupSession.
* daemon/gvfsbackenddav.c:
Port to new utility functions and http_backend_xx namespace.
Clean up error handling and remove the const keyword from most
SoupURI variables.
Modified:
trunk/ChangeLog
trunk/daemon/gvfsbackenddav.c
trunk/daemon/gvfsbackendhttp.c
trunk/daemon/gvfsbackendhttp.h
Modified: trunk/daemon/gvfsbackenddav.c
==============================================================================
--- trunk/daemon/gvfsbackenddav.c (original)
+++ trunk/daemon/gvfsbackenddav.c Mon Mar 3 21:01:13 2008
@@ -126,18 +126,6 @@
return soup_message_headers_get (msg->response_headers, header) != NULL;
}
-static inline void
-send_message (GVfsBackend *backend,
- SoupMessage *message,
- SoupSessionCallback callback,
- gpointer user_data)
-{
-
- soup_session_queue_message (G_VFS_BACKEND_HTTP (backend)->session,
- message,
- callback, user_data);
-}
-
static char *
path_get_parent_dir (const char *path)
{
@@ -331,7 +319,7 @@
xmlDocPtr doc;
xmlNodePtr root;
- const SoupURI *target;
+ SoupURI *target;
};
@@ -441,18 +429,18 @@
const char *text;
text = node_get_content (response->href);
- return uri_get_basename (text);
+ return http_uri_get_basename (text);
}
static gboolean
ms_response_is_target (MsResponse *response)
{
- const char *text;
- const char *path;
- const SoupURI *target;
- SoupURI *uri;
- gboolean res;
+ const char *text;
+ const char *path;
+ SoupURI *target;
+ SoupURI *uri;
+ gboolean res;
res = FALSE;
uri = NULL;
@@ -728,11 +716,13 @@
const PropName *properties)
{
SoupMessage *msg;
+ SoupURI *uri;
const char *header_depth;
GString *body;
- msg = message_new_from_filename_full (backend, SOUP_METHOD_PROPFIND,
- filename, (depth > 0));
+ uri = http_backend_uri_for_filename (backend, filename, depth > 0);
+ msg = soup_message_new_from_uri (SOUP_METHOD_PROPFIND, uri);
+ soup_uri_free (uri);
if (msg == NULL)
return NULL;
@@ -793,8 +783,8 @@
}
static SoupMessage *
-stat_location_begin (const SoupURI *uri,
- gboolean count_children)
+stat_location_begin (SoupURI *uri,
+ gboolean count_children)
{
SoupMessage *msg;
const char *depth;
@@ -876,28 +866,24 @@
}
static gboolean
-stat_location (GVfsBackend *backend,
- const SoupURI *uri,
- GFileType *target_type,
- guint *num_children,
- GError **error)
+stat_location (GVfsBackend *backend,
+ SoupURI *uri,
+ GFileType *target_type,
+ guint *num_children,
+ GError **error)
{
- SoupSession *session;
SoupMessage *msg;
guint status;
gboolean count_children;
gboolean res;
- session = G_VFS_BACKEND_HTTP (backend)->session;
-
count_children = num_children != NULL;
-
msg = stat_location_begin (uri, count_children);
if (msg == NULL)
return FALSE;
- status = soup_session_send_message (session, msg);
+ status = http_backend_send_message (backend, msg);
if (status != 207)
{
@@ -912,11 +898,9 @@
res = stat_location_finish (msg, target_type, num_children);
if (res == FALSE)
- {
- g_set_error (error,
- G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Response invalid"));
- }
+ g_set_error (error,
+ G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Response invalid"));
return res;
}
@@ -1013,8 +997,8 @@
if (have_auth == FALSE && g_vfs_keyring_is_available ())
{
- const SoupURI *uri;
- SoupURI *uri_free = NULL;
+ SoupURI *uri;
+ SoupURI *uri_free = NULL;
pw_ask_flags |= G_ASK_PASSWORD_SAVING_SUPPORTED;
@@ -1207,11 +1191,11 @@
data);
last_good_path = NULL;
- msg_opts = message_new_from_uri (SOUP_METHOD_OPTIONS, mount_base);
+ msg_opts = soup_message_new_from_uri (SOUP_METHOD_OPTIONS, mount_base);
msg_stat = stat_location_begin (mount_base, FALSE);
do {
- status = soup_session_send_message (session, msg_opts);
+ status = http_backend_send_message (backend, msg_opts);
is_success = SOUP_STATUS_IS_SUCCESSFUL (status);
is_webdav = is_success && sm_has_header (msg_opts, "DAV");
@@ -1227,7 +1211,7 @@
cur_uri = soup_message_get_uri (msg_opts);
soup_message_set_uri (msg_stat, cur_uri);
- soup_session_send_message (session, msg_stat);
+ http_backend_send_message (backend, msg_stat);
res = stat_location_finish (msg_stat, &file_type, NULL);
if (res && file_type == G_FILE_TYPE_DIRECTORY)
@@ -1338,7 +1322,7 @@
message_add_apply_to_redirect_header (msg, flags);
- soup_session_send_message (G_VFS_BACKEND_HTTP (backend)->session, msg);
+ http_backend_send_message (backend, msg);
res = multistatus_parse (msg, &ms, &error);
@@ -1388,17 +1372,15 @@
GFileAttributeMatcher *matcher,
GFileQueryInfoFlags flags)
{
- GVfsBackendHttp *backend_http;
- SoupMessage *msg;
- Multistatus ms;
- xmlNodeIter iter;
- gboolean res;
- SoupURI *base;
- GError *error;
+ SoupMessage *msg;
+ Multistatus ms;
+ xmlNodeIter iter;
+ gboolean res;
+ SoupURI *base;
+ GError *error;
- backend_http = G_VFS_BACKEND_HTTP (backend);
- base = backend_http->mount_base;
- error = NULL;
+ base = G_VFS_BACKEND_HTTP (backend)->mount_base;
+ error = NULL;
msg = propfind_request_new (backend, filename, 1, NULL);
@@ -1413,7 +1395,7 @@
message_add_apply_to_redirect_header (msg, flags);
- soup_session_send_message (backend_http->session, msg);
+ http_backend_send_message (backend, msg);
res = multistatus_parse (msg, &ms, &error);
@@ -1465,6 +1447,7 @@
GVfsBackendHttp *op_backend = job->backend_data;
GOutputStream *stream;
SoupMessage *put_msg;
+ SoupURI *uri;
if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
{
@@ -1476,7 +1459,8 @@
}
/* TODO: other errors */
- put_msg = message_new_from_uri ("PUT", soup_message_get_uri (msg));
+ uri = soup_message_get_uri (msg);
+ put_msg = soup_message_new_from_uri (SOUP_METHOD_PUT, uri);
soup_message_headers_append (put_msg->request_headers, "If-None-Match", "*");
stream = soup_output_stream_new (op_backend->session, put_msg, -1);
@@ -1492,20 +1476,19 @@
const char *filename,
GFileCreateFlags flags)
{
- GVfsBackendHttp *op_backend;
- SoupMessage *msg;
+ SoupMessage *msg;
+ SoupURI *uri;
/* TODO: if SoupOutputStream supported chunked requests, we could
* use a PUT with "If-None-Match: *" and "Expect: 100-continue"
*/
+ uri = http_backend_uri_for_filename (backend, filename, FALSE);
+ msg = soup_message_new_from_uri (SOUP_METHOD_HEAD, uri);
+ soup_uri_free (uri);
- op_backend = G_VFS_BACKEND_HTTP (backend);
-
- msg = message_new_from_filename (backend, "HEAD", filename);
+ g_vfs_job_set_backend_data (G_VFS_JOB (job), backend, NULL);
- g_vfs_job_set_backend_data (G_VFS_JOB (job), op_backend, NULL);
- soup_session_queue_message (op_backend->session, msg,
- try_create_tested_existence, job);
+ http_backend_queue_message (backend, msg, try_create_tested_existence, job);
return TRUE;
}
@@ -1517,7 +1500,7 @@
SoupMessage *put_msg;
GOutputStream *stream;
- put_msg = message_new_from_uri (SOUP_METHOD_PUT, uri);
+ put_msg = soup_message_new_from_uri (SOUP_METHOD_PUT, uri);
if (etag)
soup_message_headers_append (put_msg->request_headers, "If-Match", etag);
@@ -1578,7 +1561,7 @@
- uri = g_vfs_backend_uri_for_filename (backend, filename, FALSE);
+ uri = http_backend_uri_for_filename (backend, filename, FALSE);
if (etag)
{
@@ -1706,18 +1689,25 @@
GVfsJobMakeDirectory *job,
const char *filename)
{
- SoupMessage *msg;
- guint status;
+ SoupMessage *msg;
+ SoupURI *uri;
+ guint status;
- msg = message_new_from_filename_full (backend, "MKCOL", filename, TRUE);
+ uri = http_backend_uri_for_filename (backend, filename, TRUE);
+ msg = soup_message_new_from_uri (SOUP_METHOD_MKCOL, uri);
+ soup_uri_free (uri);
- status = soup_session_send_message (G_VFS_BACKEND_HTTP (backend)->session, msg);
+ status = http_backend_send_message (backend, msg);
- /* TODO: error reporting sucks */
if (! SOUP_STATUS_IS_SUCCESSFUL (status))
- g_vfs_job_failed (G_VFS_JOB (job),
- G_IO_ERROR, G_IO_ERROR_FAILED,
- _("HTTP Error: %s"), msg->reason_phrase);
+ if (status == SOUP_STATUS_METHOD_NOT_ALLOWED)
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
+ G_IO_ERROR_EXISTS,
+ _("Target file already exists"));
+ else
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
+ http_error_code_from_status (status),
+ msg->reason_phrase);
else
g_vfs_job_succeeded (G_VFS_JOB (job));
@@ -1741,12 +1731,13 @@
error = NULL;
session = G_VFS_BACKEND_HTTP (backend)->session;
- uri = g_vfs_backend_uri_for_filename (backend, filename, FALSE);
+ uri = http_backend_uri_for_filename (backend, filename, FALSE);
res = stat_location (backend, uri, &file_type, &num_children, &error);
if (res == FALSE)
{
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_error_free (error);
return;
}
@@ -1760,7 +1751,7 @@
msg = soup_message_new_from_uri (SOUP_METHOD_DELETE, uri);
- status = soup_session_send_message (session, msg);
+ status = http_backend_send_message (backend, msg);
if (!SOUP_STATUS_IS_SUCCESSFUL (status))
g_vfs_job_failed (G_VFS_JOB (job),
Modified: trunk/daemon/gvfsbackendhttp.c
==============================================================================
--- trunk/daemon/gvfsbackendhttp.c (original)
+++ trunk/daemon/gvfsbackendhttp.c Mon Mar 3 21:01:13 2008
@@ -80,13 +80,20 @@
{
g_vfs_backend_set_user_visible (G_VFS_BACKEND (backend), FALSE);
- backend->session = soup_session_sync_new ();
- backend->session_async = soup_session_async_new ();
+ backend->session = soup_session_sync_new_with_options ("user-agent",
+ "gvfs/" VERSION,
+ NULL);
+
+ backend->session_async = soup_session_async_new_with_options ("user-agent",
+ "gvfs/" VERSION,
+ NULL);
}
+/* ************************************************************************* */
+/* public utility functions */
SoupURI *
-g_vfs_backend_uri_for_filename (GVfsBackend *backend,
+http_backend_uri_for_filename (GVfsBackend *backend,
const char *filename,
gboolean is_dir)
{
@@ -121,7 +128,7 @@
}
char *
-uri_get_basename (const char *uri_str)
+http_uri_get_basename (const char *uri_str)
{
const char *parent;
const char *path;
@@ -163,8 +170,6 @@
return basename;
}
-/* ************************************************************************* */
-/* */
guint
http_error_code_from_status (guint status)
{
@@ -216,49 +221,25 @@
}
}
-/* ************************************************************************* */
-/* public utility functions */
-
-SoupMessage *
-message_new_from_uri (const char *method,
- SoupURI *uri)
+guint
+http_backend_send_message (GVfsBackend *backend,
+ SoupMessage *msg)
{
- SoupMessage *msg;
-
- msg = soup_message_new_from_uri (method, uri);
-
- /* Add standard headers */
- soup_message_headers_append (msg->request_headers,
- "User-Agent", "gvfs/" VERSION);
- return msg;
+ GVfsBackendHttp *op_backend = G_VFS_BACKEND_HTTP (backend);
+ return soup_session_send_message (op_backend->session, msg);
}
-SoupMessage *
-message_new_from_filename_full (GVfsBackend *backend,
- const char *method,
- const char *filename,
- gboolean is_dir)
+void
+http_backend_queue_message (GVfsBackend *backend,
+ SoupMessage *msg,
+ SoupSessionCallback callback,
+ gpointer user_data)
{
- SoupMessage *msg;
- SoupURI *uri;
-
- uri = g_vfs_backend_uri_for_filename (backend, filename, is_dir);
- msg = message_new_from_uri (method, uri);
-
- soup_uri_free (uri);
- return msg;
-}
-
-
-SoupMessage *
-message_new_from_filename (GVfsBackend *backend,
- const char *method,
- const char *filename)
-{
- return message_new_from_filename_full (backend, method, filename, FALSE);
+ GVfsBackendHttp *op_backend = G_VFS_BACKEND_HTTP (backend);
+
+ soup_session_queue_message (op_backend->session_async, msg,
+ callback, user_data);
}
-
-
/* ************************************************************************* */
/* virtual functions overrides */
@@ -357,9 +338,12 @@
GVfsBackendHttp *op_backend;
GInputStream *stream;
SoupMessage *msg;
+ SoupURI *uri;
op_backend = G_VFS_BACKEND_HTTP (backend);
- msg = message_new_from_filename (backend, "GET", filename);
+ uri = http_backend_uri_for_filename (backend, filename, FALSE);
+ msg = soup_message_new_from_uri (SOUP_METHOD_GET, uri);
+ soup_uri_free (uri);
stream = soup_input_stream_new (op_backend->session_async, msg);
g_object_unref (msg);
@@ -532,7 +516,7 @@
}
uri = soup_message_get_uri (msg);
- basename = uri_get_basename (uri->path);
+ basename = http_uri_get_basename (uri->path);
g_print ("basename:%s\n", basename);
@@ -625,15 +609,15 @@
GFileInfo *info,
GFileAttributeMatcher *attribute_matcher)
{
- GVfsBackendHttp *op_backend;
- SoupMessage *msg;
+ SoupMessage *msg;
+ SoupURI *uri;
- op_backend = G_VFS_BACKEND_HTTP (backend);
+ uri = http_backend_uri_for_filename (backend, filename, FALSE);
+ msg = soup_message_new_from_uri (SOUP_METHOD_HEAD, uri);
+ soup_uri_free (uri);
- msg = message_new_from_filename (backend, "HEAD", filename);
+ http_backend_queue_message (backend, msg, query_info_ready, job);
- soup_session_queue_message (op_backend->session, msg,
- query_info_ready, job);
return TRUE;
}
Modified: trunk/daemon/gvfsbackendhttp.h
==============================================================================
--- trunk/daemon/gvfsbackendhttp.h (original)
+++ trunk/daemon/gvfsbackendhttp.h Mon Mar 3 21:01:13 2008
@@ -55,24 +55,24 @@
};
GType g_vfs_backend_http_get_type (void) G_GNUC_CONST;
-SoupURI * g_vfs_backend_uri_for_filename (GVfsBackend *backend,
+
+SoupURI * http_backend_uri_for_filename (GVfsBackend *backend,
const char *filename,
gboolean is_dir);
-SoupMessage * message_new_from_filename_full (GVfsBackend *backend,
- const char *method,
- const char *filename,
- gboolean is_dir);
-
-SoupMessage * message_new_from_filename (GVfsBackend *backend,
- const char *method,
- const char *filename);
-SoupMessage * message_new_from_uri (const char *method,
- SoupURI *uri);
-char * uri_get_basename (const char *uri_str);
+
+char * http_uri_get_basename (const char *uri_str);
guint http_error_code_from_status (guint status);
+guint http_backend_send_message (GVfsBackend *backend,
+ SoupMessage *msg);
+
+void http_backend_queue_message (GVfsBackend *backend,
+ SoupMessage *msg,
+ SoupSessionCallback callback,
+ gpointer user_data);
+
G_END_DECLS
#endif /* __G_VFS_BACKEND_HTTP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]