[mw-devel] MW3 r960 - trunk/src

psycodom at sucs.org psycodom at sucs.org
Tue May 1 17:37:28 BST 2007


Author: psycodom
Date: 2007-05-01 17:37:27 +0100 (Tue, 01 May 2007)
New Revision: 960

Modified:
   trunk/src/iconv.c
   trunk/src/iconv.h
   trunk/src/ipc.c
   trunk/src/main.c
Log:
Updates the ipc functions to always send a cleaned up utf-8 message that doesn't contain any invalid chars.



Modified: trunk/src/iconv.c
===================================================================
--- trunk/src/iconv.c	2007-05-01 10:44:36 UTC (rev 959)
+++ trunk/src/iconv.c	2007-05-01 16:37:27 UTC (rev 960)
@@ -252,6 +252,23 @@
 	return retval;
 }
 
+int utf8_cleanup(char *buff)
+{
+	// useful after various dirty things (snprintf/gags etc.) might have been employed.
+	char *buffcpy;
+	int conversion_result=-1;
+	
+	buffcpy=malloc(strlen(buff)+1);
+	if(buffcpy!=NULL)
+	{
+		strcpy(buffcpy, buff);
+		conversion_result=convert_string_charset(buffcpy, "UTF-8", strlen(buffcpy), buff, "UTF-8", strlen(buff)+1, NULL, NULL, NULL, NULL, NULL);
+		
+	}
+	return conversion_result;
+}
+
+
 /* convert string in given encoding to wide string */
 wchar_t * any2wcs(char * s, char * charset, int report_error)
 {

Modified: trunk/src/iconv.h
===================================================================
--- trunk/src/iconv.h	2007-05-01 10:44:36 UTC (rev 959)
+++ trunk/src/iconv.h	2007-05-01 16:37:27 UTC (rev 960)
@@ -5,6 +5,7 @@
 							size_t *output_bytes_used,  size_t *irreversible_count,
 							size_t *unconverted_bytes, size_t *invalid_count, char *substitute);
 
+int utf8_cleanup(char *buff);
 
 /* convert string in given encoding to wide string */
 //wchar_t * any2wcs(char * s, char * charset);

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2007-05-01 10:44:36 UTC (rev 959)
+++ trunk/src/ipc.c	2007-05-01 16:37:27 UTC (rev 960)
@@ -7,6 +7,7 @@
 
 #include "proto.h"
 #include "ipc.h"
+#include "iconv.h"
 
 /*
  * Send a message to a remote process addressed by PID
@@ -47,12 +48,18 @@
 		free(qdata);
 		strip_quote(buff);
 		strcat(buff,"|");
-		dgram_len = strlen(buff);
 		mypid = getpid();
 		memcpy(buff + 1, &mypid, 4);
-		if (write(fd, buff, dgram_len) <= 0) {
-			fprintf(stderr, "Write to %s failed: %s\n", fifo_path, strerror(errno));
-			return -2;
+		//ensure text (everything after the first 5 bytes) going into the pipes is clean utf-8 after all the truncating etc. that might have happened to it.
+		if(utf8_cleanup(buff+5)>=0) {
+			// the first 5 bytes are binary data that break strlen
+			dgram_len = strlen(buff+5)+5;
+			if (write(fd, buff, dgram_len) <= 0) {
+				fprintf(stderr, "Write to %s failed: %s\n", fifo_path, strerror(errno));
+				return -2;
+			}
+		} else {
+			fprintf(stderr, "Failed to utf8_clean the message to, %s (not sent)\n", fifo_path); 
 		}
 	}
 	close(fd);

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2007-05-01 10:44:36 UTC (rev 959)
+++ trunk/src/main.c	2007-05-01 16:37:27 UTC (rev 960)
@@ -1405,7 +1405,7 @@
 	}
 	if(convert_warnings & WINVALIDCHARS)
 	{
-		printf("Warning: There were invalid characters in the message just printed that were replaced with '#'\n");
+		printf("Warning: There were invalid characters in the previous message that were replaced with '#'\n");
 	}
 	if(convert_warnings & WICONVFAIL)
 	{





More information about the mw-devel mailing list