[gvfs] afp: read UTF-8 Server Name from server info
- From: Christian Kellner <gicmo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] afp: read UTF-8 Server Name from server info
- Date: Thu, 25 Aug 2011 19:22:37 +0000 (UTC)
commit 4b505fd08dd144dc3393833ff83bcd2207568ff9
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date: Mon Jun 20 00:18:29 2011 +0200
afp: read UTF-8 Server Name from server info
daemon/gvfsafpconnection.c | 97 +++++++++++++++++++++++++++++++++
daemon/gvfsafpconnection.h | 128 +++++++++++++++++++++++++++++++++++++++++++-
daemon/gvfsafpserver.c | 24 ++++++--
daemon/gvfsafpserver.h | 2 +-
4 files changed, 243 insertions(+), 8 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.c b/daemon/gvfsafpconnection.c
index 9146e48..4745406 100644
--- a/daemon/gvfsafpconnection.c
+++ b/daemon/gvfsafpconnection.c
@@ -26,6 +26,64 @@
#include "gvfsafpconnection.h"
+/*
+ * GVfsAfpName
+ */
+
+static void
+_g_vfs_afp_name_free (GVfsAfpName *afp_name)
+{
+ g_free (afp_name->str);
+ g_slice_free (GVfsAfpName, afp_name);
+}
+
+void
+g_vfs_afp_name_unref (GVfsAfpName *afp_name)
+{
+ if (g_atomic_int_dec_and_test (&afp_name->ref_count))
+ _g_vfs_afp_name_free (afp_name);
+}
+
+void
+g_vfs_afp_name_ref (GVfsAfpName *afp_name)
+{
+ g_atomic_int_inc (&afp_name->ref_count);
+}
+
+GVfsAfpName *
+g_vfs_afp_name_new (guint32 text_encoding, const gchar *str, gsize len)
+{
+ GVfsAfpName *afp_name;
+
+ afp_name = g_slice_new (GVfsAfpName);
+ afp_name->ref_count = 1;
+
+ afp_name->text_encoding = text_encoding;
+
+ afp_name->str = g_malloc (len);
+ memcpy (afp_name->str, str, len);
+
+ afp_name->len = len;
+
+ return afp_name;
+}
+
+GVfsAfpName *
+g_vfs_afp_name_new_from_gstring (guint32 text_encoding, GString *string)
+{
+ GVfsAfpName *afp_name;
+
+ afp_name = g_slice_new (GVfsAfpName);
+ afp_name->ref_count = 1;
+
+ afp_name->text_encoding = text_encoding;
+ afp_name->str = string->str;
+ afp_name->len = string->len;
+
+ g_string_free (string, FALSE);
+
+ return afp_name;
+}
/*
* GVfsAfpReply
@@ -204,6 +262,45 @@ g_vfs_afp_reply_read_pascal (GVfsAfpReply *reply, char **str)
}
gboolean
+g_vfs_afp_reply_read_afp_name (GVfsAfpReply *reply, gboolean read_text_encoding,
+ GVfsAfpName **afp_name)
+{
+ gint old_pos;
+
+ guint32 text_encoding;
+ guint16 len;
+ gchar *str;
+
+ old_pos = reply->pos;
+
+ if (read_text_encoding)
+ {
+ if (!g_vfs_afp_reply_read_uint32 (reply, &text_encoding))
+ return FALSE;
+ }
+ else
+ text_encoding = kTextEncodingUnicodeDefault;
+
+ if (!g_vfs_afp_reply_read_uint16 (reply, &len))
+ {
+ reply->pos = old_pos;
+ return FALSE;
+ }
+
+ if (!g_vfs_afp_reply_get_data (reply, len, (guint8 **)&str))
+ {
+ reply->pos = old_pos;
+ return FALSE;
+ }
+
+ if (afp_name)
+ *afp_name = g_vfs_afp_name_new (text_encoding, str, len);
+
+ return TRUE;
+
+}
+
+gboolean
g_vfs_afp_reply_seek (GVfsAfpReply *reply, gint offset, GSeekType type)
{
gint absolute;
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index bb8b5f1..f508bc0 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -27,6 +27,110 @@
G_BEGIN_DECLS
+enum {
+ kTextEncodingMacRoman = 0,
+ kTextEncodingMacJapanese = 1,
+ kTextEncodingMacChineseTrad = 2,
+ kTextEncodingMacKorean = 3,
+ kTextEncodingMacArabic = 4,
+ kTextEncodingMacHebrew = 5,
+ kTextEncodingMacGreek = 6,
+ kTextEncodingMacCyrillic = 7,
+ kTextEncodingMacDevanagari = 9,
+ kTextEncodingMacGurmukhi = 10,
+ kTextEncodingMacGujarati = 11,
+ kTextEncodingMacOriya = 12,
+ kTextEncodingMacBengali = 13,
+ kTextEncodingMacTamil = 14,
+ kTextEncodingMacTelugu = 15,
+ kTextEncodingMacKannada = 16,
+ kTextEncodingMacMalayalam = 17,
+ kTextEncodingMacSinhalese = 18,
+ kTextEncodingMacBurmese = 19,
+ kTextEncodingMacKhmer = 20,
+ kTextEncodingMacThai = 21,
+ kTextEncodingMacLaotian = 22,
+ kTextEncodingMacGeorgian = 23,
+ kTextEncodingMacArmenian = 24,
+ kTextEncodingMacChineseSimp = 25,
+ kTextEncodingMacTibetan = 26,
+ kTextEncodingMacMongolian = 27,
+ kTextEncodingMacEthiopic = 28,
+ kTextEncodingMacCentralEurRoman = 29,
+ kTextEncodingMacVietnamese = 30,
+ kTextEncodingMacExtArabic = 31,
+ kTextEncodingMacSymbol = 33,
+ kTextEncodingMacDingbats = 34,
+ kTextEncodingMacTurkish = 35,
+ kTextEncodingMacCroatian = 36,
+ kTextEncodingMacIcelandic = 37,
+ kTextEncodingMacRomanian = 38,
+ kTextEncodingMacCeltic = 39,
+ kTextEncodingMacGaelic = 40,
+ kTextEncodingMacKeyboardGlyphs = 41,
+ kTextEncodingMacUnicode = 126,
+ kTextEncodingMacFarsi = 140,
+ kTextEncodingMacUkrainian = 152,
+ kTextEncodingMacInuit = 236,
+ kTextEncodingMacVT100 = 252,
+ kTextEncodingMacHFS = 255,
+ kTextEncodingUnicodeDefault = 256,
+ kTextEncodingUnicodeV1_1 = 257,
+ kTextEncodingISO10646_1993 = 257,
+ kTextEncodingUnicodeV2_0 = 259,
+ kTextEncodingUnicodeV2_1 = 259,
+ kTextEncodingUnicodeV3_0 = 260,
+ kTextEncodingISOLatin1 = 513,
+ kTextEncodingISOLatin2 = 514,
+ kTextEncodingISOLatin3 = 515,
+ kTextEncodingISOLatin4 = 516,
+ kTextEncodingISOLatinCyrillic = 517,
+ kTextEncodingISOLatinArabic = 518,
+ kTextEncodingISOLatinGreek = 519,
+ kTextEncodingISOLatinHebrew = 520,
+ kTextEncodingISOLatin5 = 521,
+ kTextEncodingISOLatin6 = 522,
+ kTextEncodingISOLatin7 = 525,
+ kTextEncodingISOLatin8 = 526,
+ kTextEncodingISOLatin9 = 527,
+ kTextEncodingDOSLatinUS = 1024,
+ kTextEncodingDOSGreek = 1029,
+ kTextEncodingDOSBalticRim = 1030,
+ kTextEncodingDOSLatin1 = 1040,
+ kTextEncodingDOSGreek1 = 1041,
+ kTextEncodingDOSLatin2 = 1042,
+ kTextEncodingDOSCyrillic = 1043,
+ kTextEncodingDOSTurkish = 1044,
+ kTextEncodingDOSPortuguese = 1045,
+ kTextEncodingDOSIcelandic = 1046,
+ kTextEncodingDOSHebrew = 1047,
+ kTextEncodingDOSCanadianFrench = 1048,
+ kTextEncodingDOSArabic = 1049,
+ kTextEncodingDOSNordic = 1050,
+ kTextEncodingDOSRussian = 1051,
+ kTextEncodingDOSGreek2 = 1052,
+ kTextEncodingDOSThai = 1053,
+ kTextEncodingDOSJapanese = 1056,
+ kTextEncodingDOSChineseSimplif = 1057,
+ kTextEncodingDOSKorean = 1058,
+ kTextEncodingDOSChineseTrad = 1059,
+ kTextEncodingWindowsLatin1 = 1280,
+ kTextEncodingWindowsANSI = 1280,
+ kTextEncodingWindowsLatin2 = 1281,
+ kTextEncodingWindowsCyrillic = 1282,
+ kTextEncodingWindowsGreek = 1283,
+ kTextEncodingWindowsLatin5 = 1284,
+ kTextEncodingWindowsHebrew = 1285,
+ kTextEncodingWindowsArabic = 1286,
+ kTextEncodingWindowsBalticRim = 1287,
+ kTextEncodingWindowsVietnamese = 1288,
+ kTextEncodingWindowsKoreanJohab = 1296,
+ kTextEncodingUS_ASCII = 1536,
+ kTextEncodingJIS_X0201_76 = 1568,
+ kTextEncodingJIS_X0208_83 = 1569,
+ kTextEncodingJIS_X0208_90 = 1570
+};
+
typedef enum
{
AFP_DIR_BITMAP_ATTRIBUTE_BIT = 0x1,
@@ -106,6 +210,26 @@ typedef enum
} AfpResultCode;
/*
+ * GVfsAfpName
+ */
+typedef struct _GVfsAfpName GVfsAfpName;
+
+struct _GVfsAfpName
+{
+ guint32 text_encoding;
+ gchar *str;
+ gsize len;
+
+ gint ref_count;
+};
+
+GVfsAfpName* g_vfs_afp_name_new (guint32 text_encoding, const gchar *str, gsize len);
+GVfsAfpName* g_vfs_afp_name_new_from_gstring (guint32 text_encoding, GString *string);
+
+void g_vfs_afp_name_unref (GVfsAfpName *afp_name);
+void g_vfs_afp_name_ref (GVfsAfpName *afp_name);
+
+/*
* GVfsAfpReply
*/
#define G_VFS_TYPE_AFP_REPLY (g_vfs_afp_reply_get_type ())
@@ -126,10 +250,12 @@ gboolean g_vfs_afp_reply_read_int16 (GVfsAfpReply *reply, gint16 *
gboolean g_vfs_afp_reply_read_uint32 (GVfsAfpReply *reply, guint32 *val);
gboolean g_vfs_afp_reply_read_uint16 (GVfsAfpReply *reply, guint16 *val);
-gboolean g_vfs_afp_reply_get_data (GVfsAfpReply *reply, guint size, guint8 **data);
+gboolean g_vfs_afp_reply_get_data (GVfsAfpReply *reply, guint size, guint8 **data);
gboolean g_vfs_afp_reply_dup_data (GVfsAfpReply *reply, guint size, guint8 **data);
gboolean g_vfs_afp_reply_read_pascal (GVfsAfpReply *reply, char **str);
+gboolean g_vfs_afp_reply_read_afp_name (GVfsAfpReply *reply, gboolean read_text_encoding, GVfsAfpName **afp_name);
+
gboolean g_vfs_afp_reply_seek (GVfsAfpReply *reply, gint offset, GSeekType type);
gboolean g_vfs_afp_reply_skip_to_even (GVfsAfpReply *reply);
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c
index 0bcd897..504e25c 100644
--- a/daemon/gvfsafpserver.c
+++ b/daemon/gvfsafpserver.c
@@ -673,6 +673,7 @@ get_server_info (GVfsAfpServer *afp_serv,
GVfsAfpReply *reply;
guint16 MachineType_offset, AFPVersionCount_offset, UAMCount_offset;
+
guint8 count;
guint i;
@@ -690,7 +691,19 @@ get_server_info (GVfsAfpServer *afp_serv,
g_vfs_afp_reply_read_uint16 (reply, &afp_serv->flags);
g_vfs_afp_reply_read_pascal (reply, &afp_serv->server_name);
-
+
+ /* Parse UTF-8 ServerName */
+ if (afp_serv->flags & (0x1 << 8)) {
+ guint16 UTF8ServerName_offset;
+
+ g_vfs_afp_reply_skip_to_even (reply);
+ g_vfs_afp_reply_seek (reply, 6, G_SEEK_CUR);
+ g_vfs_afp_reply_read_uint16 (reply, &UTF8ServerName_offset);
+
+ g_vfs_afp_reply_seek (reply, UTF8ServerName_offset, G_SEEK_SET);
+ g_vfs_afp_reply_read_afp_name (reply, FALSE, &afp_serv->utf8_server_name);
+ }
+
/* Parse MachineType */
g_vfs_afp_reply_seek (reply, MachineType_offset, G_SEEK_SET);
g_vfs_afp_reply_read_pascal (reply, &afp_serv->machine_type);
@@ -704,7 +717,6 @@ get_server_info (GVfsAfpServer *afp_serv,
AfpVersion afp_version;
g_vfs_afp_reply_read_pascal (reply, &version);
- g_debug ("version: %s\n", version);
afp_version = string_to_afp_version (version);
if (afp_version > afp_serv->version)
afp_serv->version = afp_version;
@@ -730,8 +742,7 @@ get_server_info (GVfsAfpServer *afp_serv,
afp_serv->uams = g_slist_prepend (afp_serv->uams, uam);
}
- g_object_unref (reply);
-
+
return TRUE;
}
@@ -876,9 +887,7 @@ try_login:
g_free (user);
g_free (password);
- g_debug ("ASDASD!!!\n");
g_propagate_error (error, err);
- g_debug ("ASDASD2!!!\n");
return FALSE;
}
@@ -933,6 +942,9 @@ g_vfs_afp_server_finalize (GObject *object)
g_free (afp_serv->machine_type);
g_free (afp_serv->server_name);
+ if (afp_serv->utf8_server_name)
+ g_vfs_afp_name_unref (afp_serv->utf8_server_name);
+
g_slist_free_full (afp_serv->uams, g_free);
G_OBJECT_CLASS (g_vfs_afp_server_parent_class)->finalize (object);
diff --git a/daemon/gvfsafpserver.h b/daemon/gvfsafpserver.h
index 545997a..0357ddf 100644
--- a/daemon/gvfsafpserver.h
+++ b/daemon/gvfsafpserver.h
@@ -64,7 +64,7 @@ struct _GVfsAfpServer
guint16 flags;
char *machine_type;
char *server_name;
- char *utf8_server_name;
+ GVfsAfpName *utf8_server_name;
GSList *uams;
AfpVersion version;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]