changeset 22102:e6e018d0bf03

merge of '464169ffadabb173b3052074b132f38025b2e88d' and '88dc67220e1d61e540c931b9f27f5b4419809137'
author Richard Laager <rlaager@wiktel.com>
date Mon, 14 Jan 2008 04:09:03 +0000
parents 0b823f16162c (current diff) 7ec5b5724a05 (diff)
children 1439274f0852
files pidgin/gtkprefs.c pidgin/gtkstatusbox.c
diffstat 14 files changed, 130 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/dbus-analyze-functions.py	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/dbus-analyze-functions.py	Mon Jan 14 04:09:03 2008 +0000
@@ -525,9 +525,10 @@
             try:
                 self.processfunction(functiontext, paramtexts)
             except MyException:
-                sys.stderr.write(myline + "\n")
+#                sys.stderr.write(myline + "\n")
+                 pass
             except:
-                sys.stderr.write(myline + "\n")
+#                sys.stderr.write(myline + "\n")
                 raise
 
         self.flush()
@@ -586,7 +587,7 @@
 else:
     fprefix = ""
 
-sys.stderr.write("%s: Functions not exported:\n" % sys.argv[0])
+#sys.stderr.write("%s: Functions not exported:\n" % sys.argv[0])
 
 if "client" in options:
     bindings = ClientBindingSet(sys.stdin, fprefix,
--- a/libpurple/example/nullclient.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/example/nullclient.c	Mon Jan 14 04:09:03 2008 +0000
@@ -268,6 +268,7 @@
 	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
 	PurpleAccount *account;
 	PurpleSavedStatus *status;
+	char *res;
 
 	/* libpurple's built-in DNS resolution forks processes to perform
 	 * blocking lookups without blocking the main process.  It does not
@@ -290,12 +291,20 @@
 		}
 	}
 	printf("Select the protocol [0-%d]: ", i-1);
-	fgets(name, sizeof(name), stdin);
+	res = fgets(name, sizeof(name), stdin);
+	if (!res) {
+		fprintf(stderr, "Failed to gets protocol selection.");
+		abort();
+	}
 	sscanf(name, "%d", &num);
 	prpl = g_list_nth_data(names, num);
 
 	printf("Username: ");
-	fgets(name, sizeof(name), stdin);
+	res = fgets(name, sizeof(name), stdin);
+	if (!res) {
+		fprintf(stderr, "Failed to read user name.");
+		abort();
+	}
 	name[strlen(name) - 1] = 0;  /* strip the \n at the end */
 
 	/* Create the account */
--- a/libpurple/ft.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/ft.c	Mon Jan 14 04:09:03 2008 +0000
@@ -32,6 +32,7 @@
 #include "proxy.h"
 #include "request.h"
 #include "util.h"
+#include "debug.h"
 
 #define FT_INITIAL_BUFFER_SIZE 4096
 #define FT_MAX_BUFFER_SIZE     65535
@@ -903,7 +904,12 @@
 	if (condition & PURPLE_INPUT_READ) {
 		r = purple_xfer_read(xfer, &buffer);
 		if (r > 0) {
-			fwrite(buffer, 1, r, xfer->dest_fp);
+			const size_t wc = fwrite(buffer, 1, r, xfer->dest_fp);
+			if (wc != r) {
+				purple_debug_error("filetransfer", "Unable to write whole buffer.\n");
+				purple_xfer_cancel_remote(xfer);
+				return;
+			}
 		} else if(r < 0) {
 			purple_xfer_cancel_remote(xfer);
 			return;
@@ -911,6 +917,7 @@
 	}
 
 	if (condition & PURPLE_INPUT_WRITE) {
+		size_t result;
 		size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size);
 
 		/* this is so the prpl can keep the connection open
@@ -925,7 +932,13 @@
 
 		buffer = g_malloc0(s);
 
-		fread(buffer, 1, s, xfer->dest_fp);
+		result = fread(buffer, 1, s, xfer->dest_fp);
+		if (result != s) {
+			purple_debug_error("filetransfer", "Unable to read whole buffer.\n");
+			purple_xfer_cancel_remote(xfer);
+			g_free(buffer);
+			return;
+		}
 
 		/* Write as much as we're allowed to. */
 		r = purple_xfer_write(xfer, buffer, s);
--- a/libpurple/log.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/log.c	Mon Jan 14 04:09:03 2008 +0000
@@ -1859,11 +1859,15 @@
 
 static char * old_logger_read (PurpleLog *log, PurpleLogReadFlags *flags)
 {
+	size_t result;
 	struct old_logger_data *data = log->logger_data;
-	FILE *file = g_fopen(purple_stringref_value(data->pathref), "rb");
+	const char *path = purple_stringref_value(data->pathref);
+	FILE *file = g_fopen(path, "rb");
 	char *read = g_malloc(data->length + 1);
 	fseek(file, data->offset, SEEK_SET);
-	fread(read, data->length, 1, file);
+	result = fread(read, data->length, 1, file);
+	if (result != 1)
+		purple_debug_error("log", "Unable to read from log file: %s\n", path);
 	fclose(file);
 	read[data->length] = '\0';
 	*flags = 0;
--- a/libpurple/protocols/irc/dcc_send.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/irc/dcc_send.c	Mon Jan 14 04:09:03 2008 +0000
@@ -51,9 +51,14 @@
  */
 static void irc_dccsend_recv_ack(PurpleXfer *xfer, const guchar *data, size_t size) {
 	unsigned long l;
+	size_t result;
 
 	l = htonl(xfer->bytes_sent);
-	write(xfer->fd, &l, sizeof(l));
+	result = write(xfer->fd, &l, sizeof(l));
+	if (result != sizeof(l)) {
+		purple_debug_error("irc", "unable to send acknowledgement: %s\n", strerror(errno));
+		/* TODO: We should probably close the connection here or something. */
+	}
 }
 
 static void irc_dccsend_recv_init(PurpleXfer *xfer) {
--- a/libpurple/protocols/novell/nmfield.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/novell/nmfield.c	Mon Jan 14 04:09:03 2008 +0000
@@ -164,9 +164,7 @@
 		case NMFIELD_TYPE_BINARY:
 		case NMFIELD_TYPE_UTF8:
 		case NMFIELD_TYPE_DN:
-			if (field->ptr_value != NULL) {
-				g_free(field->ptr_value);
-			}
+			g_free(field->ptr_value);
 			break;
 
 		case NMFIELD_TYPE_ARRAY:
--- a/libpurple/protocols/qq/file_trans.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/qq/file_trans.c	Mon Jan 14 04:09:03 2008 +0000
@@ -97,6 +97,7 @@
 	guint8 *buffer;
 	PurpleCipher *cipher;
 	PurpleCipherContext *context;
+	size_t wc;
 
 	const gint QQ_MAX_FILE_MD5_LENGTH = 10002432;
 
@@ -109,15 +110,20 @@
 
 	buffer = g_newa(guint8, filelen);
 	g_return_if_fail(buffer != NULL);
-	fread(buffer, filelen, 1, fp);
+	wc = fread(buffer, filelen, 1, fp);
+	fclose(fp);
+	if (wc != 1) {
+		purple_debug_error("qq", "Unable to read file: %s\n", filename);
+
+		/* TODO: XXX: Really, the caller should be modified to deal with this properly. */
+		return;
+	}
 
 	cipher = purple_ciphers_find_cipher("md5");
 	context = purple_cipher_context_new(cipher, NULL);
 	purple_cipher_context_append(context, buffer, filelen);
 	purple_cipher_context_digest(context, 16, md5, NULL);
 	purple_cipher_context_destroy(context);
-
-	fclose(fp);
 }
 
 static void _qq_get_file_header(guint8 *buf, guint8 **cursor, gint buflen, qq_file_header *fh)
--- a/libpurple/protocols/sametime/sametime.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/sametime/sametime.c	Mon Jan 14 04:09:03 2008 +0000
@@ -2286,6 +2286,7 @@
 
   PurpleXfer *xfer;
   FILE *fp;
+  size_t wc;
 
   xfer = mwFileTransfer_getClientData(ft);
   g_return_if_fail(xfer != NULL);
@@ -2294,7 +2295,12 @@
   g_return_if_fail(fp != NULL);
 
   /* we must collect and save our precious data */
-  fwrite(data->data, 1, data->len, fp);
+  wc = fwrite(data->data, 1, data->len, fp);
+  if (wc != data->len) {
+    DEBUG_ERROR("failed to write data\n");
+    purple_xfer_cancel_local(xfer);
+    return;
+  }
 
   /* update the progress */
   xfer->bytes_sent += data->len;
--- a/libpurple/protocols/zephyr/ZSendList.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/zephyr/ZSendList.c	Mon Jan 14 04:09:03 2008 +0000
@@ -24,7 +24,7 @@
     char *list[];
     int nitems;
     Z_AuthProc cert_routine;
-    Code_t (*send_routine)(void);
+    Code_t (*send_routine)();
 {
     Code_t retval;
     ZNotice_t newnotice;
--- a/libpurple/protocols/zephyr/ZSendNot.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/zephyr/ZSendNot.c	Mon Jan 14 04:09:03 2008 +0000
@@ -20,7 +20,7 @@
 Code_t ZSrvSendNotice(notice, cert_routine, send_routine)
     ZNotice_t *notice;
     Z_AuthProc cert_routine;
-    Code_t (*send_routine)(void);
+    Code_t (*send_routine)();
 {    
     Code_t retval;
     ZNotice_t newnotice;
--- a/libpurple/protocols/zephyr/zephyr.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Mon Jan 14 04:09:03 2008 +0000
@@ -156,13 +156,20 @@
 #endif
 
 static Code_t zephyr_subscribe_to(zephyr_account* zephyr, char* class, char *instance, char *recipient, char* galaxy) {
+	size_t result;
+	Code_t ret_val = -1;
 
 	if (use_tzc(zephyr)) {
 		/* ((tzcfodder . subscribe) ("class" "instance" "recipient")) */
 		gchar *zsubstr = g_strdup_printf("((tzcfodder . subscribe) (\"%s\" \"%s\" \"%s\"))\n",class,instance,recipient);
-		write(zephyr->totzc[ZEPHYR_FD_WRITE],zsubstr,strlen(zsubstr));
+		size_t len = strlen(zsubstr);
+		result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zsubstr,len);
+		if (result != len) {
+			purple_debug_error("zephyr", "Unable to write a message: %s\n", strerror(errno));
+		} else {
+			ret_val = ZERR_NONE;
+		}
 		g_free(zsubstr);
-		return ZERR_NONE;
 	}
 	else {
 		if (use_zeph02(zephyr)) {
@@ -170,13 +177,10 @@
 			sub.zsub_class = class;
 			sub.zsub_classinst = instance;
 			sub.zsub_recipient = recipient; 
-			return ZSubscribeTo(&sub,1,0);
-		} else {
-			/* This should not happen */
-			return -1;
+			ret_val = ZSubscribeTo(&sub,1,0);
 		}
 	}
-	return -1;
+	return ret_val;
 }
 
 char *local_zephyr_normalize(zephyr_account* zephyr,const char *);
@@ -1373,7 +1377,11 @@
 					} else 
 						if (use_tzc(zephyr)) {
 							gchar *zlocstr = g_strdup_printf("((tzcfodder . zlocate) \"%s\")\n",chk);
-							write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,strlen(zlocstr));
+							size_t len = strlen(zlocstr);
+							size_t result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,len);
+							if (result != len) {
+								purple_debug_error("zephyr", "Unable to write a message: %s\n", strerror(errno));
+							}
 							g_free(zlocstr);
 						}
 				}
@@ -2193,6 +2201,8 @@
 	html_buf2 = purple_unescape_html(html_buf);
 
 	if(use_tzc(zephyr)) {
+		size_t len;
+		size_t result;
 		char* zsendstr;
 		/* CMU cclub tzc doesn't grok opcodes for now  */
 		char* tzc_sig = zephyr_tzc_escape_msg(sig);
@@ -2200,7 +2210,14 @@
 		zsendstr = g_strdup_printf("((tzcfodder . send) (class . \"%s\") (auth . t) (recipients (\"%s\" . \"%s\")) (message . (\"%s\" \"%s\"))	) \n",
 					   zclass, instance, recipient, tzc_sig, tzc_body);
 		/*		fprintf(stderr,"zsendstr = %s\n",zsendstr); */
-		write(zephyr->totzc[ZEPHYR_FD_WRITE],zsendstr,strlen(zsendstr));
+		len = strlen(zsendstr);
+		result = write(zephyr->totzc[ZEPHYR_FD_WRITE], zsendstr, len);
+		if (result != len) {
+			g_free(zsendstr);
+			g_free(html_buf2);
+			g_free(html_buf);
+			return errno;
+		}
 		g_free(zsendstr);
 	} else if (use_zeph02(zephyr)) {
 		ZNotice_t notice;
@@ -2221,6 +2238,9 @@
 		purple_debug_info("zephyr","About to send notice\n");
 		if (! ZSendNotice(&notice, ZAUTH) == ZERR_NONE) {
 			/* XXX handle errors here */
+			g_free(buf);
+			g_free(html_buf2);
+			g_free(html_buf);
 			return 0;
 		}
 		purple_debug_info("zephyr","notice sent\n");
@@ -2257,7 +2277,7 @@
 	ZAsyncLocateData_t ald;
 	zephyr_account *zephyr = gc->proto_data;
 	gchar* normalized_who = local_zephyr_normalize(zephyr,who);
-	
+
 	if (use_zeph02(zephyr)) {
 		if (ZRequestLocations(normalized_who, &ald, UNACKED, ZAUTH) == ZERR_NONE) {
 			zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names,
@@ -2266,14 +2286,22 @@
 			/* XXX deal with errors somehow */
 		}
 	} else if (use_tzc(zephyr)) {
+		size_t len;
+		size_t result;
 		char* zlocstr = g_strdup_printf("((tzcfodder . zlocate) \"%s\")\n",normalized_who);
 		zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names, g_strdup(normalized_who));
-		write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,strlen(zlocstr));
+		len = strlen(zlocstr);
+		result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,len);
+		if (result != len) {
+			purple_debug_error("zephyr", "Unable to write a message: %s\n", strerror(errno));
+		}
 		g_free(zlocstr);
 	}
 }
 
 static void zephyr_set_status(PurpleAccount *account, PurpleStatus *status) {
+	size_t len;
+	size_t result;
 	zephyr_account *zephyr = purple_account_get_connection(account)->proto_data;
 	PurpleStatusPrimitive primitive = purple_status_type_get_primitive(purple_status_get_type(status));
 
@@ -2291,7 +2319,11 @@
 		}
 		else {
 			char *zexpstr = g_strdup_printf("((tzcfodder . set-location) (hostname . \"%s\") (exposure . \"%s\"))\n",zephyr->ourhost,zephyr->exposure);
-			write(zephyr->totzc[ZEPHYR_FD_WRITE],zexpstr,strlen(zexpstr));
+			len = strlen(zexpstr);
+			result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zexpstr,len);
+			if (result != len) {
+				purple_debug_error("zephyr", "Unable to write message: %s\n", strerror(errno));
+			}
 			g_free(zexpstr);
 		}
 	} 
@@ -2301,7 +2333,11 @@
 			ZSetLocation(EXPOSE_OPSTAFF);
 		} else {
 			char *zexpstr = g_strdup_printf("((tzcfodder . set-location) (hostname . \"%s\") (exposure . \"%s\"))\n",zephyr->ourhost,EXPOSE_OPSTAFF);
-			write(zephyr->totzc[ZEPHYR_FD_WRITE],zexpstr,strlen(zexpstr));
+			len = strlen(zexpstr);
+			result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zexpstr,len);
+			if (result != len) {
+				purple_debug_error("zephyr", "Unable to write message: %s\n", strerror(errno));
+			}
 			g_free(zexpstr);
 		}
 	}
--- a/libpurple/protocols/zephyr/zephyr.h	Mon Jan 14 02:10:26 2008 +0000
+++ b/libpurple/protocols/zephyr/zephyr.h	Mon Jan 14 04:09:03 2008 +0000
@@ -163,9 +163,9 @@
 Code_t ZReadAscii16 ZP((char *, int, unsigned short *));
 Code_t ZSendPacket ZP((char*, int, int));
 Code_t ZSendList ZP((ZNotice_t*, char *[], int, Z_AuthProc));
-Code_t ZSrvSendList ZP((ZNotice_t*, char*[], int, Z_AuthProc, Code_t (*)(void)));
+Code_t ZSrvSendList ZP((ZNotice_t*, char*[], int, Z_AuthProc, Code_t (*)()));
 Code_t ZSendNotice ZP((ZNotice_t *, Z_AuthProc));
-Code_t ZSrvSendNotice ZP((ZNotice_t*, Z_AuthProc, Code_t (*)(void)));
+Code_t ZSrvSendNotice ZP((ZNotice_t*, Z_AuthProc, Code_t (*)()));
 Code_t ZFormatNotice ZP((ZNotice_t*, char**, int*, Z_AuthProc));
 Code_t ZFormatSmallNotice ZP((ZNotice_t*, ZPacket_t, int*, Z_AuthProc));
 Code_t ZFormatRawNoticeList ZP((ZNotice_t *notice, char *list[], int nitems,
--- a/pidgin/gtkprefs.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/pidgin/gtkprefs.c	Mon Jan 14 04:09:03 2008 +0000
@@ -478,12 +478,20 @@
 {
 	FILE *f;
 	gchar *path;
+	size_t wc;
 
 	if ((error_message != NULL) || (len == 0))
 		return;
 
 	f = purple_mkstemp(&path, TRUE);
-	fwrite(themedata, len, 1, f);
+	wc = fwrite(themedata, len, 1, f);
+	if (wc != 1) {
+		purple_debug_warning("theme_got_url", "Unable to write theme data.\n");
+		fclose(f);
+		g_unlink(path);
+		g_free(path);
+		return;
+	}
 	fclose(f);
 
 	theme_install_theme(path, user_data);
@@ -1718,9 +1726,6 @@
 	int j;
 	const char *file;
 	char *pref;
-#if !defined _WIN32 || defined USE_GSTREAMER
-	GtkWidget *label;
-#endif
 #ifndef _WIN32
 	GtkWidget *dd;
 	GtkWidget *entry;
--- a/pidgin/gtkstatusbox.c	Mon Jan 14 02:10:26 2008 +0000
+++ b/pidgin/gtkstatusbox.c	Mon Jan 14 04:09:03 2008 +0000
@@ -320,12 +320,20 @@
 {
 	FILE *f;
 	gchar *path;
+	size_t wc;
 
 	if ((error_message != NULL) || (len == 0))
 		return;
 
 	f = purple_mkstemp(&path, TRUE);
-	fwrite(themedata, len, 1, f);
+	wc = fwrite(themedata, len, 1, f);
+	if (wc != 1) {
+		purple_debug_warning("theme_got_url", "Unable to write theme data.\n");
+		fclose(f);
+		g_unlink(path);
+		g_free(path);
+		return;
+	}
 	fclose(f);
 
 	icon_choose_cb(path, user_data);