Mercurial > pidgin
changeset 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 | 82f0d88ada18 |
children | 39c06f943767 |
files | src/protocols/novell/nmconn.c src/protocols/novell/nmconn.h src/protocols/novell/nmevent.c src/protocols/novell/nmuser.c |
diffstat | 4 files changed, 77 insertions(+), 24 deletions(-) [+] |
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;
--- a/src/protocols/novell/nmconn.h Tue May 04 17:45:59 2004 +0000 +++ b/src/protocols/novell/nmconn.h Wed May 05 20:29:21 2004 +0000 @@ -110,6 +110,28 @@ NMERR_T nm_read_all(NMConn * conn, char *buf, int len); /** + * Read a 32 bit value and convert it to the host byte order. + * + * @param conn The connection to read from. + * @param val A pointer to unsigned 32 bit integer + * + * @return NM_OK on success, NMERR_TCP_READ if read fails. + */ +NMERR_T +nm_read_uint32(NMConn *conn, guint32 *val); + +/** + * Read a 16 bit value and convert it to the host byte order. + * + * @param conn The connection to read from. + * @param val A pointer to unsigned 16 bit integer + * + * @return NM_OK on success, NMERR_TCP_READ if read fails. + */ +NMERR_T +nm_read_uint16(NMConn *conn, guint16 *val); + +/** * Dispatch a request to the server. * * @param conn The connection.
--- a/src/protocols/novell/nmevent.c Tue May 04 17:45:59 2004 +0000 +++ b/src/protocols/novell/nmevent.c Wed May 05 20:29:21 2004 +0000 @@ -207,7 +207,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -215,12 +215,12 @@ /* Read the conference flags */ if (rc == NM_OK) { - rc = nm_read_all(conn, (char *) &flags, sizeof(flags)); + rc = nm_read_uint32(conn, &flags); } /* Read the message text */ if (rc == NM_OK) { - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { msg = g_new0(char, size + 1); @@ -322,7 +322,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -330,7 +330,7 @@ /* Read the the message */ if (rc == NM_OK) { - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { msg = g_new0(char, size + 1); rc = nm_read_all(conn, msg, size); @@ -397,7 +397,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -447,7 +447,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -484,7 +484,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -492,7 +492,7 @@ /* Read the conference flags */ if (rc == NM_OK) { - rc = nm_read_all(conn, (char *) &flags, sizeof(flags)); + rc = nm_read_uint32(conn, &flags); } if (rc == NM_OK) { @@ -532,7 +532,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -570,7 +570,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -578,7 +578,7 @@ /* Read the conference flags */ if (rc == NM_OK) { - rc = nm_read_all(conn, (char *) &flags, sizeof(flags)); + rc = nm_read_uint32(conn, &flags); } if (rc == NM_OK) { @@ -625,7 +625,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -662,11 +662,11 @@ conn = nm_user_get_conn(user); /* Read new status */ - rc = nm_read_all(conn, (char *) &status, sizeof(status)); + rc = nm_read_uint16(conn, &status); if (rc == NM_OK) { /* Read the status text */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { if (size > 0) { text = g_new0(char, size + 1); @@ -704,7 +704,7 @@ conn = nm_user_get_conn(user); /* Read the conference guid */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { guid = g_new0(char, size + 1); rc = nm_read_all(conn, guid, size); @@ -864,7 +864,7 @@ conn = nm_user_get_conn(user); /* Read the event source */ - rc = nm_read_all(conn, (char *) &size, sizeof(size)); + rc = nm_read_uint32(conn, &size); if (rc == NM_OK) { if (size > 0) { source = g_new0(char, size);
--- a/src/protocols/novell/nmuser.c Tue May 04 17:45:59 2004 +0000 +++ b/src/protocols/novell/nmuser.c Wed May 05 20:29:21 2004 +0000 @@ -980,7 +980,7 @@ if (strncmp((char *) &val, "HTTP", strlen("HTTP")) == 0) rc = nm_process_response(user); else - rc = nm_process_event(user, val); + rc = nm_process_event(user, GUINT32_FROM_LE(val)); } else { rc = NMERR_PROTOCOL;