diff src/protocols/novell/nmconn.c @ 8874:a2affcdf8e01

[gaim-migrate @ 9643] "This patch fixes the Novell protocol plugin on big endian platforms (Bug #947017). It also includes a fix for disconnects when sending large messages." --Mike Stoddard (novell) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 05 May 2004 20:29:21 +0000
parents c7e9687bfd79
children 6663ad2386d9
line wrap: on
line diff
--- a/src/protocols/novell/nmconn.c	Tue May 04 17:45:59 2004 +0000
+++ b/src/protocols/novell/nmconn.c	Wed May 05 20:29:21 2004 +0000
@@ -237,13 +237,39 @@
 }
 
 NMERR_T
+nm_read_uint32(NMConn *conn, guint32 *val)
+{
+	NMERR_T rc = NM_OK;
+
+	rc = nm_read_all(conn, (char *)val, sizeof(*val));
+	if (rc == NM_OK) {
+		*val = GUINT32_FROM_LE(*val);
+	}
+
+	return rc;
+}
+
+NMERR_T
+nm_read_uint16(NMConn *conn, guint16 *val)
+{
+	NMERR_T rc = NM_OK;
+
+	rc = nm_read_all(conn, (char *)val, sizeof(*val));
+	if (rc == NM_OK) {
+		*val = GUINT16_FROM_LE(*val);
+	}
+
+	return rc;
+}
+
+NMERR_T
 nm_write_fields(NMConn * conn, NMField * fields)
 {
 	NMERR_T rc = NM_OK;
 	NMField *field;
 	char *value = NULL;
 	char *method = NULL;
-	char buffer[512];
+	char buffer[4096];
 	int ret;
 	int bytes_to_send;
 	int val = 0;
@@ -287,7 +313,12 @@
 					value = url_escape_string((char *) field->value);
 					bytes_to_send = g_snprintf(buffer, sizeof(buffer),
 											   "&val=%s", value);
-					ret = nm_tcp_write(conn, buffer, bytes_to_send);
+					if (bytes_to_send > (int)sizeof(buffer)) {
+						ret = nm_tcp_write(conn, buffer, sizeof(buffer));
+					} else {
+						ret = nm_tcp_write(conn, buffer, bytes_to_send);
+					}
+
 					if (ret < 0) {
 						rc = NMERR_TCP_WRITE;
 					}
@@ -499,7 +530,7 @@
 		if (rc != NM_OK)
 			break;
 
-		rc = nm_read_all(conn, (char *) &val, sizeof(val));
+		rc = nm_read_uint32(conn, &val);
 		if (rc != NM_OK)
 			break;
 
@@ -515,7 +546,7 @@
 		if (type == NMFIELD_TYPE_MV || type == NMFIELD_TYPE_ARRAY) {
 
 			/* Read the subarray (first read the number of items in the array) */
-			rc = nm_read_all(conn, (char *) &val, sizeof(val));
+			rc = nm_read_uint32(conn, &val);
 			if (rc != NM_OK)
 				break;
 
@@ -533,7 +564,7 @@
 		} else if (type == NMFIELD_TYPE_UTF8 || type == NMFIELD_TYPE_DN) {
 
 			/* Read the string (first read the length) */
-			rc = nm_read_all(conn, (char *) &val, sizeof(val));
+			rc = nm_read_uint32(conn, &val);
 			if (rc != NM_OK)
 				break;
 
@@ -557,7 +588,7 @@
 		} else {
 
 			/* Read the numerical value */
-			rc = nm_read_all(conn, (char *) &val, sizeof(val));
+			rc = nm_read_uint32(conn, &val);
 			if (rc != NM_OK)
 				break;