/soc/2013/ankitkv/gobjectification: 0ceef98c4a10: Merged default...

Ankit Vani a at nevitus.org
Mon Dec 23 05:01:13 EST 2013


Changeset: 0ceef98c4a103cecd181c8902ac0724db6dab041
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-12-23 15:30 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/0ceef98c4a10

Description:

Merged default branch

diffstat:

 libpurple/plugins/log_reader.c  |  21 ++++++++++++++----
 libpurple/protocols/jabber/si.c |   2 +-
 libpurple/protocols/msn/ft.c    |   2 +-
 libpurple/protocols/msn/ft.h    |   2 +-
 libpurple/win32/win32dep.c      |  46 +++++++++++++++++++++++++++++++++++++++++
 libpurple/win32/win32dep.h      |   1 +
 libpurple/xfer.c                |   6 ++--
 libpurple/xfer.h                |   2 +-
 8 files changed, 70 insertions(+), 12 deletions(-)

diffs (195 lines):

diff --git a/libpurple/plugins/log_reader.c b/libpurple/plugins/log_reader.c
--- a/libpurple/plugins/log_reader.c
+++ b/libpurple/plugins/log_reader.c
@@ -2431,6 +2431,7 @@ static void amsn_logger_finalize(PurpleL
 static void log_reader_init_prefs(void) {
 	char *path;
 #ifdef _WIN32
+	const gchar *reg_key;
 	char *folder;
 	gboolean found = FALSE;
 #endif
@@ -2521,7 +2522,11 @@ static void log_reader_init_prefs(void) 
 	 */
 
 	path = NULL;
-	if ((folder = wpurple_read_reg_string(HKEY_CLASSES_ROOT, "Trillian.SkinZip\\shell\\Add\\command\\", NULL))) {
+	folder = NULL;
+	reg_key = "Trillian.SkinZip\\shell\\Add\\command\\";
+	if (wpurple_reg_val_exists(HKEY_CLASSES_ROOT, reg_key, NULL))
+		folder = wpurple_read_reg_string(HKEY_CLASSES_ROOT, reg_key, NULL);
+	if (folder) {
 		char *value = folder;
 		char *temp;
 
@@ -2589,15 +2594,21 @@ static void log_reader_init_prefs(void) 
 #else
 		gchar *contents = NULL;
 
-		purple_debug_info("Trillian talk.ini read",
-				  "Reading %s\n", path);
-		if (!g_file_get_contents(path, &contents, NULL, &error)) {
+		if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
+			purple_debug_info("Trillian talk.ini read",
+				"Reading %s\n", path);
+		} else {
+			g_free(path);
+			path = NULL;
+		}
+		
+		if (path && !g_file_get_contents(path, &contents, NULL, &error)) {
 			purple_debug_error("Trillian talk.ini read",
 					   "Error reading talk.ini: %s\n",
 					   (error && error->message) ? error->message : "Unknown error");
 			if (error)
 				g_error_free(error);
-		} else {
+		} else if (contents) {
 			char *cursor, *line;
 			line = cursor = contents;
 			while (*cursor) {
diff --git a/libpurple/protocols/jabber/si.c b/libpurple/protocols/jabber/si.c
--- a/libpurple/protocols/jabber/si.c
+++ b/libpurple/protocols/jabber/si.c
@@ -1024,7 +1024,7 @@ jabber_si_xfer_ibb_recv_data_cb(JabberIB
 }
 
 static gssize
-jabber_si_xfer_ibb_read(guchar **out_buffer, PurpleXfer *xfer)
+jabber_si_xfer_ibb_read(guchar **out_buffer, size_t buf_size, PurpleXfer *xfer)
 {
 	JabberSIXfer *jsx = purple_xfer_get_protocol_data(xfer);
 	guchar *buffer;
diff --git a/libpurple/protocols/msn/ft.c b/libpurple/protocols/msn/ft.c
--- a/libpurple/protocols/msn/ft.c
+++ b/libpurple/protocols/msn/ft.c
@@ -116,7 +116,7 @@ msn_xfer_write(const guchar *data, gsize
 }
 
 gssize
-msn_xfer_read(guchar **data, PurpleXfer *xfer)
+msn_xfer_read(guchar **data, gsize size, PurpleXfer *xfer)
 {
 	MsnSlpCall *slpcall;
 	gsize len;
diff --git a/libpurple/protocols/msn/ft.h b/libpurple/protocols/msn/ft.h
--- a/libpurple/protocols/msn/ft.h
+++ b/libpurple/protocols/msn/ft.h
@@ -55,7 +55,7 @@ void msn_xfer_init(PurpleXfer *xfer);
 void msn_xfer_cancel(PurpleXfer *xfer);
 
 gssize msn_xfer_write(const guchar *data, gsize len, PurpleXfer *xfer);
-gssize msn_xfer_read(guchar **data, PurpleXfer *xfer);
+gssize msn_xfer_read(guchar **data, gsize size, PurpleXfer *xfer);
 
 void msn_xfer_completed_cb(MsnSlpCall *slpcall,
 						   const guchar *body, gsize size);
diff --git a/libpurple/win32/win32dep.c b/libpurple/win32/win32dep.c
--- a/libpurple/win32/win32dep.c
+++ b/libpurple/win32/win32dep.c
@@ -291,6 +291,52 @@ static gboolean _reg_read(HKEY reg_key, 
 	return (rv == ERROR_SUCCESS);
 }
 
+gboolean wpurple_reg_val_exists(HKEY rootkey, const char *subkey, const char *valname)
+{
+	HKEY hkey;
+	LONG retv;
+	DWORD index;
+	wchar_t name_buffer[100];
+	BOOL exists = FALSE;
+	wchar_t *wc_valname = NULL;
+	wchar_t *wc_subkey;
+
+	if (subkey == NULL)
+		return FALSE;
+
+	wc_subkey = g_utf8_to_utf16(subkey, -1, NULL, NULL, NULL);
+	retv = RegOpenKeyExW(rootkey, wc_subkey, 0, KEY_ENUMERATE_SUB_KEYS, &hkey);
+	g_free(wc_subkey);
+
+	if (retv != ERROR_SUCCESS)
+		return FALSE;
+
+	if (valname[0] == '\0' || valname == NULL) {
+		RegCloseKey(hkey);
+		return TRUE;
+	}
+
+	wc_valname = g_utf8_to_utf16(valname, -1, NULL, NULL, NULL);
+	index = 0;
+	while (TRUE)
+	{
+		DWORD name_size = sizeof(name_buffer);
+		retv = RegEnumValueW(hkey, index++, name_buffer, &name_size,
+			NULL, NULL, NULL, NULL);
+		if (retv != ERROR_SUCCESS)
+			break;
+		name_size /= sizeof(wchar_t);
+		if (wcsncmp(name_buffer, wc_valname, name_size) == 0) {
+			exists = TRUE;
+			break;
+		}
+	}
+	g_free(wc_valname);
+
+	RegCloseKey(hkey);
+	return exists;
+}
+
 gboolean wpurple_read_reg_dword(HKEY rootkey, const char *subkey, const char *valname, LPDWORD result) {
 
 	DWORD type;
diff --git a/libpurple/win32/win32dep.h b/libpurple/win32/win32dep.h
--- a/libpurple/win32/win32dep.h
+++ b/libpurple/win32/win32dep.h
@@ -54,6 +54,7 @@ typedef struct {
  **/
 /* Windows helper functions */
 FARPROC wpurple_find_and_loadproc(const char *dllname, const char *procedure);
+gboolean wpurple_reg_val_exists(HKEY rootkey, const char *subkey, const char *valname);
 gboolean wpurple_read_reg_dword(HKEY rootkey, const char *subkey, const char *valname, LPDWORD result);
 char *wpurple_read_reg_string(HKEY rootkey, const char *subkey, const char *valname); /* needs to be g_free'd */
 gboolean wpurple_write_reg_string(HKEY rootkey, const char *subkey, const char *valname, const char *value);
diff --git a/libpurple/xfer.c b/libpurple/xfer.c
--- a/libpurple/xfer.c
+++ b/libpurple/xfer.c
@@ -93,7 +93,7 @@ struct _PurpleXferPrivate {
 		void (*end)(PurpleXfer *xfer);
 		void (*cancel_send)(PurpleXfer *xfer);
 		void (*cancel_recv)(PurpleXfer *xfer);
-		gssize (*read)(guchar **buffer, PurpleXfer *xfer);
+		gssize (*read)(guchar **buffer, size_t size, PurpleXfer *xfer);
 		gssize (*write)(const guchar *buffer, size_t size, PurpleXfer *xfer);
 		void (*ack)(PurpleXfer *xfer, const guchar *buffer, size_t size);
 	} ops;
@@ -1087,7 +1087,7 @@ void purple_xfer_set_request_denied_fnc(
 }
 
 void
-purple_xfer_set_read_fnc(PurpleXfer *xfer, gssize (*fnc)(guchar **, PurpleXfer *))
+purple_xfer_set_read_fnc(PurpleXfer *xfer, gssize (*fnc)(guchar **, size_t, PurpleXfer *))
 {
 	PurpleXferPrivate *priv = PURPLE_XFER_GET_PRIVATE(xfer);
 
@@ -1182,7 +1182,7 @@ purple_xfer_read(PurpleXfer *xfer, gucha
 		s = MIN((gssize)purple_xfer_get_bytes_remaining(xfer), (gssize)priv->current_buffer_size);
 
 	if (priv->ops.read != NULL)	{
-		r = (priv->ops.read)(buffer, xfer);
+		r = (priv->ops.read)(buffer, s, xfer);
 	}
 	else {
 		*buffer = g_malloc0(s);
diff --git a/libpurple/xfer.h b/libpurple/xfer.h
--- a/libpurple/xfer.h
+++ b/libpurple/xfer.h
@@ -503,7 +503,7 @@ PurpleXferUiOps *purple_xfer_get_ui_ops(
  * @param fnc  The read function.
  */
 void purple_xfer_set_read_fnc(PurpleXfer *xfer,
-		gssize (*fnc)(guchar **, PurpleXfer *));
+		gssize (*fnc)(guchar **, size_t, PurpleXfer *));
 
 /**
  * Sets the write function for the file transfer.



More information about the Commits mailing list