[gvfs] afp: output the textual representation of undhandled error codes



commit 199973156a5b1975fa8ecccedf4fb93a32cac7b4
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Tue Aug 30 23:18:47 2011 +0200

    afp: output the textual representation of undhandled error codes
    
    add a new function afp_result_to_gerror which does a generic AfpResultCode
    to GError mapping

 daemon/Makefile.am            |    2 +
 daemon/gvfsafpconnection.h    |   36 +-----------
 daemon/gvfsafpserver.c        |   10 +--
 daemon/gvfsafputils.c         |  128 +++++++++++++++++++++++++++++++++++++++++
 daemon/gvfsafputils.h         |   90 +++++++++++++++++++++++++++++
 daemon/gvfsbackendafp.c       |   93 ++++++++++++------------------
 daemon/gvfsbackendafpbrowse.c |    3 +-
 7 files changed, 264 insertions(+), 98 deletions(-)
---
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 79da018..954b67e 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -481,6 +481,7 @@ gvfsd_afp_browse_SOURCES = \
 	gvfsbackendafpbrowse.c gvfsbackendafpbrowse.h \
 	daemon-main.c daemon-main.h \
 	daemon-main-generic.c \
+	gvfsafputils.c gvfsafputils.h \
 	gvfsafpconnection.h \
 	gvfsafpconnection.c \
 	gvfsafpserver.h \
@@ -500,6 +501,7 @@ gvfsd_afp_SOURCES = \
 	gvfsbackendafp.c gvfsbackendafp.h \
 	daemon-main.c daemon-main.h \
 	daemon-main-generic.c \
+	gvfsafputils.c gvfsafputils.h \
 	gvfsafpconnection.h \
 	gvfsafpconnection.c \
 	gvfsafpserver.h \
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index f5cde13..b4282eb 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -25,6 +25,8 @@
 
 #include <gio/gio.h>
 
+#include "gvfsafputils.h"
+
 G_BEGIN_DECLS
 
 enum
@@ -220,40 +222,6 @@ typedef enum
   AFP_COMMAND_ENUMERATE_EXT2     = 68
 } AfpCommandType;
 
-typedef enum
-{
-  AFP_RESULT_NO_ERROR             = 0,
-  AFP_RESULT_NO_MORE_SESSIONS     = -1068,
-  AFP_RESULT_ACCESS_DENIED        = -5000, 
-  AFP_RESULT_AUTH_CONTINUE        = -5001,
-  AFP_RESULT_BAD_UAM              = -5002,
-  AFP_RESULT_CANT_MOVE            = -5005,
-  AFP_RESULT_DENY_CONFLICT        = -5006,
-  AFP_RESULT_DIR_NOT_EMPTY        = -5007,
-  AFP_RESULT_DISK_FULL            = -5008,
-  AFP_RESULT_EOF_ERR              = -5009,
-  AFP_RESULT_FILE_BUSY            = -5010,
-  AFP_RESULT_FLAT_VOL             = -5011,
-  AFP_RESULT_ITEM_NOT_FOUND       = -5012,
-  AFP_RESULT_LOCK_ERR             = -5013,
-  AFP_RESULT_OBJECT_EXISTS        = -5017,
-  AFP_RESULT_OBJECT_NOT_FOUND     = -5018,
-  AFP_RESULT_PARAM_ERR            = -5019,
-  AFP_RESULT_USER_NOT_AUTH        = -5023,
-  AFP_RESULT_CALL_NOT_SUPPORTED   = -5024,
-  AFP_RESULT_OBJECT_TYPE_ERR      = -5025,
-  AFP_RESULT_TOO_MANY_FILES_OPEN  = -5026,
-  AFP_RESULT_CANT_RENAME          = -5028,
-  AFP_RESULT_DIR_NOT_FOUND        = -5029,
-  AFP_RESULT_VOL_LOCKED           = -5031,
-  AFP_RESULT_OBJECT_LOCKED        = -5032,
-  AFP_RESULT_ID_NOT_FOUND         = -5034,
-  AFP_RESULT_PWD_EXPIRED_ERR      = -5042,
-  AFP_RESULT_INSIDE_SHARE_ERR     = -5043,
-  AFP_RESULT_INSIDE_TRASH_ERR     = -5044,
-  AFP_RESULT_PWD_NEEDS_CHANGE_ERR = -5045
-} AfpResultCode;
-
 /*
  * GVfsAfpName
  */
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c
index cfc2a7e..d77130f 100644
--- a/daemon/gvfsafpserver.c
+++ b/daemon/gvfsafpserver.c
@@ -361,8 +361,7 @@ error:
   goto cleanup;
   
 generic_error:
-  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-               _("Login to AFP server %s failed"), afp_serv->server_name);
+  g_propagate_error (error, afp_result_code_to_gerror (res_code));
   goto error;
 }
 
@@ -581,8 +580,7 @@ error:
   goto done;
   
 generic_error:
-  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-               _("Login to AFP server %s failed"), afp_serv->server_name);
+  g_propagate_error (error, afp_result_code_to_gerror (res_code));
   res = FALSE;
   goto done;
 }
@@ -641,9 +639,7 @@ do_login (GVfsAfpServer *afp_serv,
           break;
           
         default:
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                       _("Anonymous login to AFP server %s failed, got error code: %d"),
-                       afp_serv->server_name, res_code);
+          g_propagate_error (error, afp_result_code_to_gerror (res_code));
           break;
       }
       
diff --git a/daemon/gvfsafputils.c b/daemon/gvfsafputils.c
new file mode 100644
index 0000000..9d0872d
--- /dev/null
+++ b/daemon/gvfsafputils.c
@@ -0,0 +1,128 @@
+ /* GIO - GLib Input, Output and Streaming Library
+ * 
+ * Copyright (C) Carl-Anton Ingmarsson 2011 <ca ingmarsson gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
+ */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "gvfsafputils.h"
+
+static const char *
+afp_result_code_to_string (AfpResultCode res_code)
+{
+  struct AfpResults
+  {
+    AfpResultCode  res_code;
+    char          *string;
+  };
+
+
+  struct AfpResults results[] = {
+    { AFP_RESULT_NO_ERROR,             "kFPNoErr" },
+    { AFP_RESULT_NO_MORE_SESSIONS,     "kFPNoMoreSessions" },
+    { AFP_RESULT_ASP_SESS_CLOSED,      "kASPSessClosed" },
+    { AFP_RESULT_ACCESS_DENIED,        "kFPAccessDenied" },
+    { AFP_RESULT_AUTH_CONTINUE,        "kFPAuthContinue" },
+    { AFP_RESULT_BAD_UAM,              "kFPBadUAM" },
+    { AFP_RESULT_BAD_VERS_NUM,         "kFPBadVersNum" },
+    { AFP_RESULT_CANT_MOVE,            "kFPCantMove" },
+    { AFP_RESULT_DENY_CONFLICT,        "kFPDenyConflict" },
+    { AFP_RESULT_DIR_NOT_EMPTY,        "kFPDirNotEmpty" },
+    { AFP_RESULT_DISK_FULL,            "kFPDiskFull" },
+    { AFP_RESULT_EOF_ERR,              "kFPEOFErr" },
+    { AFP_RESULT_FILE_BUSY,            "kFPFileBusy" },
+    { AFP_RESULT_FLAT_VOL,             "kFPFlatVol" },
+    { AFP_RESULT_ITEM_NOT_FOUND,       "kFPItemNotFound" },
+    { AFP_RESULT_LOCK_ERR,             "kFPLockErr" },
+    { AFP_RESULT_MISC_ERR,             "kFPMiscErr" },
+    { AFP_RESULT_NO_MORE_LOCKS,        "kFPNoMoreLocks" },
+    { AFP_RESULT_NO_SERVER,            "kFPNoServer" },
+    { AFP_RESULT_OBJECT_EXISTS,        "kFPObjectExists" },
+    { AFP_RESULT_OBJECT_NOT_FOUND,     "kFPObjectNotFound" },
+    { AFP_RESULT_PARAM_ERR,            "kFPParamErr" },
+    { AFP_RESULT_RANGE_NOT_LOCKED,     "kFPRangeNotLocked" },
+    { AFP_RESULT_RANGE_OVERLAP,        "kFPRangeOverlap" },
+    { AFP_RESULT_SESS_CLOSED,          "kFPSessClosed" },
+    { AFP_RESULT_USER_NOT_AUTH,        "kFPUserNotAuth" },
+    { AFP_RESULT_CALL_NOT_SUPPORTED,   "kFPCallNotSupported" },
+    { AFP_RESULT_OBJECT_TYPE_ERR,      "kFPObjectTypeErr" },
+    { AFP_RESULT_TOO_MANY_FILES_OPEN,  "kFPTooManyFilesOpen" },
+    { AFP_RESULT_SERVER_GOING_DOWN,    "kFPServerGoingDown" },
+    { AFP_RESULT_CANT_RENAME,          "kFPCantRename" },
+    { AFP_RESULT_DIR_NOT_FOUND,        "kFPDirNotFound" },
+    { AFP_RESULT_ICON_TYPE_ERR,        "kFPIconTypeError" },
+    { AFP_RESULT_VOL_LOCKED,           "kFPVolLocked" },
+    { AFP_RESULT_OBJECT_LOCKED,        "kFPObjectLocked" },
+    { AFP_RESULT_CONTAINS_SHARED_ERR,  "kFPContainsSharedErr" },
+    { AFP_RESULT_ID_NOT_FOUND,         "kFPObjectLocked" },
+    { AFP_RESULT_ID_EXISTS,            "kFPIDExists" },
+    { AFP_RESULT_DIFF_VOL_ERR,         "kFPDiffVolErr" },
+    { AFP_RESULT_CATALOG_CHANGED,      "kFPCatalogChanged" },
+    { AFP_RESULT_SAME_OBJECT_ERR,      "kFPSameObjectErr" },
+    { AFP_RESULT_BAD_ID_ERR,           "kFPBadIDErr" },
+    { AFP_RESULT_PWD_SAME_ERR,         "kFPPwdSameErr" },
+    { AFP_RESULT_PWD_TOO_SHORT_ERR,    "kFPPwdTooShortErr" },
+    { AFP_RESULT_PWD_EXPIRED_ERR,      "kFPPwdExpiredErr" },
+    { AFP_RESULT_INSIDE_SHARE_ERR,     "kFPInsideSharedErr" },
+    { AFP_RESULT_INSIDE_TRASH_ERR,     "kFPInsideTrashErr" },
+    { AFP_RESULT_PWD_NEEDS_CHANGE_ERR, "kFPPwdNeedsChangeErr" },
+    { AFP_RESULT_PWD_POLICY_ERR,       "kFPPwdNeedsChangeErr" },
+    { AFP_RESULT_DISK_QUOTA_EXCEEDED,  "kFPDiskQuotaExceeded" }
+  };
+
+  int start, end, mid;
+
+  /* Do a "reversed" binary search,
+   * the result codes are stored in declining order */
+  start = 0;
+  end = G_N_ELEMENTS (results) - 1;
+  while (start <= end)
+  {
+    mid = (start + end) / 2;
+
+    if (res_code < results[mid].res_code)
+      start = mid + 1;
+    
+    else if (res_code > results[mid].res_code)
+      end = mid - 1;
+
+    else
+      return results[mid].string;
+  }
+
+  return NULL;
+}
+
+GError *
+afp_result_code_to_gerror (AfpResultCode res_code)
+{
+  const char   *res_string;
+
+  g_return_val_if_fail (res_code != AFP_RESULT_NO_ERROR, NULL);
+  res_string = afp_result_code_to_string (res_code);
+
+  if (res_string)
+    return g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
+                        _("Got error \"%s\" from server"), res_string);
+  else
+    return g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
+                        _("Got unknown error code %d from server"), res_code);
+}
diff --git a/daemon/gvfsafputils.h b/daemon/gvfsafputils.h
new file mode 100644
index 0000000..467cc13
--- /dev/null
+++ b/daemon/gvfsafputils.h
@@ -0,0 +1,90 @@
+ /* GIO - GLib Input, Output and Streaming Library
+ * 
+ * Copyright (C) Carl-Anton Ingmarsson 2011 <ca ingmarsson gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
+ */
+
+#ifndef _GVFSAFPUTILS_H_
+#define _GVFSAFPUTILS_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+  AFP_RESULT_NO_ERROR             = 0,
+  AFP_RESULT_NO_MORE_SESSIONS     = -1068,
+  AFP_RESULT_ASP_SESS_CLOSED      = -1072,
+  AFP_RESULT_ACCESS_DENIED        = -5000, 
+  AFP_RESULT_AUTH_CONTINUE        = -5001,
+  AFP_RESULT_BAD_UAM              = -5002,
+  AFP_RESULT_BAD_VERS_NUM         = -5003,
+  AFP_RESULT_BITMAP_ERR           = -5004,
+  AFP_RESULT_CANT_MOVE            = -5005,
+  AFP_RESULT_DENY_CONFLICT        = -5006,
+  AFP_RESULT_DIR_NOT_EMPTY        = -5007,
+  AFP_RESULT_DISK_FULL            = -5008,
+  AFP_RESULT_EOF_ERR              = -5009,
+  AFP_RESULT_FILE_BUSY            = -5010,
+  AFP_RESULT_FLAT_VOL             = -5011,
+  AFP_RESULT_ITEM_NOT_FOUND       = -5012,
+  AFP_RESULT_LOCK_ERR             = -5013,
+  AFP_RESULT_MISC_ERR             = -5014,
+  AFP_RESULT_NO_MORE_LOCKS        = -5015,
+  AFP_RESULT_NO_SERVER            = -5016,
+  AFP_RESULT_OBJECT_EXISTS        = -5017,
+  AFP_RESULT_OBJECT_NOT_FOUND     = -5018,
+  AFP_RESULT_PARAM_ERR            = -5019,
+  AFP_RESULT_RANGE_NOT_LOCKED     = -5020,
+  AFP_RESULT_RANGE_OVERLAP        = -5021,
+  AFP_RESULT_SESS_CLOSED          = -5022,
+  AFP_RESULT_USER_NOT_AUTH        = -5023,
+  AFP_RESULT_CALL_NOT_SUPPORTED   = -5024,
+  AFP_RESULT_OBJECT_TYPE_ERR      = -5025,
+  AFP_RESULT_TOO_MANY_FILES_OPEN  = -5026,
+  AFP_RESULT_SERVER_GOING_DOWN    = -5027,
+  AFP_RESULT_CANT_RENAME          = -5028,
+  AFP_RESULT_DIR_NOT_FOUND        = -5029,
+  AFP_RESULT_ICON_TYPE_ERR        = -5030,
+  AFP_RESULT_VOL_LOCKED           = -5031,
+  AFP_RESULT_OBJECT_LOCKED        = -5032,
+  AFP_RESULT_CONTAINS_SHARED_ERR  = -5033,
+  AFP_RESULT_ID_NOT_FOUND         = -5034,
+  AFP_RESULT_ID_EXISTS            = -5035,
+  AFP_RESULT_DIFF_VOL_ERR         = -5036,
+  AFP_RESULT_CATALOG_CHANGED      = -5037,
+  AFP_RESULT_SAME_OBJECT_ERR      = -5038,
+  AFP_RESULT_BAD_ID_ERR           = -5039,
+  AFP_RESULT_PWD_SAME_ERR         = -5040,
+  AFP_RESULT_PWD_TOO_SHORT_ERR    = -5041,
+  AFP_RESULT_PWD_EXPIRED_ERR      = -5042,
+  AFP_RESULT_INSIDE_SHARE_ERR     = -5043,
+  AFP_RESULT_INSIDE_TRASH_ERR     = -5044,
+  AFP_RESULT_PWD_NEEDS_CHANGE_ERR = -5045,
+  AFP_RESULT_PWD_POLICY_ERR       = -5046,
+  AFP_RESULT_DISK_QUOTA_EXCEEDED  = -5047
+} AfpResultCode;
+
+GError *
+afp_result_code_to_gerror (AfpResultCode res_code);
+
+G_END_DECLS
+
+#endif /* _GVFSAFPUTILS_H_ */
diff --git a/daemon/gvfsbackendafp.c b/daemon/gvfsbackendafp.c
index 5355216..b244506 100644
--- a/daemon/gvfsbackendafp.c
+++ b/daemon/gvfsbackendafp.c
@@ -96,6 +96,16 @@ G_DEFINE_TYPE (GVfsBackendAfp, g_vfs_backend_afp, G_VFS_TYPE_BACKEND);
 /*
  * Utility functions
  */
+static void
+job_failed_from_afp_result_code (GVfsJob *job, AfpResultCode res_code)
+{
+  GError *err;
+  
+  err = afp_result_code_to_gerror (res_code);
+  g_vfs_job_failed_from_error (job, err);
+  g_error_free (err);
+}
+
 static gboolean
 is_root (const char *filename)
 {
@@ -475,8 +485,7 @@ open_fork_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                          _("Too many files open"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
     goto done;
@@ -595,10 +604,7 @@ close_fork_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
   g_object_unref (reply);
   
   if (res_code != AFP_RESULT_NO_ERROR)
-  {
-    g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                     _("Got error code: %d from server"), res_code);
-  }
+    g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
 
 done:
   g_simple_async_result_complete (simple);
@@ -677,8 +683,7 @@ get_fork_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data
   {
     g_object_unref (reply);
 
-    g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                      _("Got error code: %d from server"), res_code);
+    g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
     goto done;
   }
 
@@ -780,8 +785,7 @@ get_filedir_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_d
                                          _("File doesn't exist"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
     goto done;
@@ -891,8 +895,7 @@ get_vol_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
   {
     g_object_unref (reply);
 
-    g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                      _("Got error code: %d from server"), res_code);
+    g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
     goto done;
   }
 
@@ -1069,8 +1072,7 @@ create_file_cb (GObject *object, GAsyncResult *res, gpointer user_data)
                                   _("Volume is read-only"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
   }
@@ -1223,8 +1225,7 @@ delete_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                   _("Volume is read-only"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
   }
@@ -1319,8 +1320,7 @@ map_id_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                          _("ID not found"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
 
@@ -1472,8 +1472,7 @@ move_and_rename_cb (GObject *source_object, GAsyncResult *res, gpointer user_dat
                                          _("Object being moved doesn't exist"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
   }
@@ -1601,8 +1600,7 @@ copy_file_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                          _("Source file is a directory"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
   }
@@ -1712,8 +1710,7 @@ set_unix_privs_cb (GObject *source_object, GAsyncResult *res, gpointer user_data
                                          _("Volume is read-only"));
         break;
       default:
-        g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                         _("Got error code: %d from server"), res_code);
+        g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
         break;
     }
     goto done;
@@ -2230,8 +2227,7 @@ rename_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                   _("Volume is read-only"));
         break;
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     return;
@@ -2366,8 +2362,7 @@ make_directory_cb (GObject *source_object, GAsyncResult *res, gpointer user_data
                                   _("Volume is read-only"));
         break;
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     return;
@@ -2505,8 +2500,7 @@ write_ext_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                   _("Not enough space on volume"));
         break;
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     return;
@@ -2742,8 +2736,7 @@ read_ext_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
                                   _("File is not open for read access"));
         break;
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     
@@ -2873,8 +2866,7 @@ close_replace_exchange_files_cb (GObject *source_object, GAsyncResult *res, gpoi
                                   _("File is a directory"));
         break;   
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     return;
@@ -2973,8 +2965,7 @@ close_replace_set_fork_parms_cb (GObject *source_object, GAsyncResult *res, gpoi
                                   _("Range lock conflict exists"));
         break;
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     afp_handle_free (afp_handle);
@@ -3547,8 +3538,7 @@ enumerate_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
         g_vfs_job_enumerate_done (job);
         break;
       default:
-        g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
-                          _("Got error code: %d from server"), res_code);
+        job_failed_from_afp_result_code (G_VFS_JOB (job), res_code);
         break;
     }
     return;
@@ -4077,39 +4067,32 @@ get_userinfo (GVfsBackendAfp *afp_backend,
   res_code = g_vfs_afp_reply_get_result_code (reply);
   if (res_code != AFP_RESULT_NO_ERROR)
   {
-    gint code;
-    char *errstr;
-
     g_object_unref (reply);
 
     switch (res_code)
     {
       case AFP_RESULT_ACCESS_DENIED:
-        code = G_IO_ERROR_PERMISSION_DENIED;
-        errstr = g_strdup (_("Permission denied"));
+        g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+                     _("Permission denied"));
+        break;
         break;
       case AFP_RESULT_CALL_NOT_SUPPORTED:
-        code = G_IO_ERROR_NOT_SUPPORTED;
-        errstr = g_strdup (_("Command not supported"));
+        g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                     _("FPGetUserInfo is not supported by server"));
         break;
       case AFP_RESULT_PWD_EXPIRED_ERR:
-        code = G_IO_ERROR_PERMISSION_DENIED;
-        errstr = g_strdup (_("User's password has expired"));
+        g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+                     _("User's password has expired"));
         break;
       case AFP_RESULT_PWD_NEEDS_CHANGE_ERR:
-        code = G_IO_ERROR_PERMISSION_DENIED;
-        errstr = g_strdup (_("User's password needs to be changed"));
+        g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+                     _("User's password needs to be changed"));
         break;
 
       default:
-        code = G_IO_ERROR_FAILED;
-        errstr = g_strdup_printf (_("Got error code: %d from server"), res_code);
+        g_propagate_error (error, afp_result_code_to_gerror (res_code));
         break;
     }
-
-    g_set_error (error, G_IO_ERROR, code,
-                 _("FPGetUserInfo failed (%s)"), errstr);
-    g_free (errstr);
     return FALSE;
   }
 
diff --git a/daemon/gvfsbackendafpbrowse.c b/daemon/gvfsbackendafpbrowse.c
index bf54a6d..b86f253 100644
--- a/daemon/gvfsbackendafpbrowse.c
+++ b/daemon/gvfsbackendafpbrowse.c
@@ -117,8 +117,7 @@ get_srvr_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data
   {
     g_object_unref (reply);
 
-    g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                     _("Got error code: %d from server"), res_code);
+    g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code));
     goto done;
   }
   



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