--- a/libpurple/protocols/novell/nmconn.c Mon Nov 04 02:24:02 2019 +0000
+++ b/libpurple/protocols/novell/nmconn.c Mon Nov 04 03:58:59 2019 +0000
@@ -20,9 +20,11 @@
@@ -34,27 +36,6 @@
#define NO_ESCAPE(ch) ((ch == 0x20) || (ch >= 0x30 && ch <= 0x39) || \
(ch >= 0x41 && ch <= 0x5a) || (ch >= 0x61 && ch <= 0x7a))
-/* Read data from conn until the end of a line */
-read_line(NMConn * conn, char *buff, int len)
- while ((rc == NM_OK) && (total_bytes < (len - 1))) {
- rc = nm_read_all(conn, &buff[total_bytes], 1);
- if (buff[total_bytes - 1] == '\n') {
- buff[total_bytes] = '\0';
url_escape_string(char *src)
@@ -180,100 +161,27 @@
void nm_release_conn(NMConn *conn)
- g_slist_free_full(conn->requests, (GDestroyNotify)nm_release_request);
+ g_return_if_fail(conn != NULL); + g_slist_free_full(conn->requests, (GDestroyNotify)nm_release_request);
-nm_tcp_write(NMConn * conn, const void *buff, int len)
- if (conn == NULL || buff == NULL)
+ purple_gio_graceful_close(conn->stream, G_INPUT_STREAM(conn->input), + g_clear_object(&conn->input); + g_clear_object(&conn->output); + g_clear_object(&conn->stream); - return conn->write(conn->data, buff, len);
-nm_tcp_read(NMConn * conn, void *buff, int len)
- if (conn == NULL || buff == NULL)
- return conn->read(conn->data, buff, len);
+ g_clear_pointer(&conn->addr, g_free); -nm_read_all(NMConn * conn, char *buff, int len)
+nm_write_fields(NMUser *user, NMField *fields)
- if (conn == NULL || buff == NULL)
- /* Keep reading until buffer is full */
- bytes_read = nm_tcp_read(conn, &buff[total_bytes], bytes_left);
- bytes_left -= bytes_read;
- total_bytes += bytes_read;
-nm_read_uint32(NMConn *conn, guint32 *val)
- rc = nm_read_all(conn, (char *)val, sizeof(*val));
- *val = GUINT32_FROM_LE(*val);
-nm_read_uint16(NMConn *conn, guint16 *val)
- rc = nm_read_all(conn, (char *)val, sizeof(*val));
- *val = GUINT16_FROM_LE(*val);
-nm_write_fields(NMConn * conn, NMField * fields)
@@ -283,9 +191,11 @@
- if (conn == NULL || fields == NULL) {
+ g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(fields != NULL, NMERR_BAD_PARM); /* Format each field as valid "post" data and write it out */
for (field = fields; (rc == NM_OK) && (field->tag); field++) {
@@ -298,7 +208,8 @@
/* Write the field tag */
bytes_to_send = g_snprintf(buffer, sizeof(buffer), "&tag=%s", field->tag);
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, bytes_to_send, + user->cancellable, NULL); @@ -307,7 +218,8 @@
method = encode_method(field->method);
bytes_to_send = g_snprintf(buffer, sizeof(buffer), "&cmd=%s", method);
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, bytes_to_send, + user->cancellable, NULL); @@ -323,9 +235,13 @@
bytes_to_send = g_snprintf(buffer, sizeof(buffer),
if (bytes_to_send > (int)sizeof(buffer)) {
- ret = nm_tcp_write(conn, buffer, sizeof(buffer));
+ ret = g_output_stream_write(conn->output, buffer, + user->cancellable, NULL); - ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, + user->cancellable, NULL); @@ -342,7 +258,9 @@
val = nm_count_fields((NMField *) field->ptr_value);
bytes_to_send = g_snprintf(buffer, sizeof(buffer),
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, + user->cancellable, NULL); @@ -353,7 +271,9 @@
bytes_to_send = g_snprintf(buffer, sizeof(buffer),
"&val=%u", field->value);
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, + user->cancellable, NULL); @@ -366,7 +286,8 @@
bytes_to_send = g_snprintf(buffer, sizeof(buffer),
"&type=%u", field->type);
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, bytes_to_send, + user->cancellable, NULL); @@ -377,8 +298,7 @@
if (field->type == NMFIELD_TYPE_ARRAY ||
field->type == NMFIELD_TYPE_MV) {
- rc = nm_write_fields(conn, (NMField *) field->ptr_value);
+ rc = nm_write_fields(user, (NMField *)field->ptr_value); @@ -387,9 +307,10 @@
-nm_send_request(NMConn *conn, char *cmd, NMField *fields,
- nm_response_cb cb, gpointer data, NMRequest **request)
+nm_send_request(NMUser *user, char *cmd, NMField *fields, nm_response_cb cb, + gpointer data, NMRequest **request) @@ -397,13 +318,17 @@
NMField *request_fields = NULL;
- if (conn == NULL || cmd == NULL)
+ g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(cmd != NULL, NMERR_BAD_PARM); bytes_to_send = g_snprintf(buffer, sizeof(buffer),
"POST /%s HTTP/1.0\r\n", cmd);
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, bytes_to_send, + user->cancellable, NULL); @@ -413,13 +338,15 @@
if (purple_strequal("login", cmd)) {
bytes_to_send = g_snprintf(buffer, sizeof(buffer),
"Host: %s:%d\r\n\r\n", conn->addr, conn->port);
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, bytes_to_send, + user->cancellable, NULL); bytes_to_send = g_snprintf(buffer, sizeof(buffer), "\r\n");
- ret = nm_tcp_write(conn, buffer, bytes_to_send);
+ ret = g_output_stream_write(conn->output, buffer, bytes_to_send, + user->cancellable, NULL); @@ -439,12 +366,13 @@
/* Send the request to the server */
- rc = nm_write_fields(conn, request_fields);
+ rc = nm_write_fields(user, request_fields); /* Write the CRLF to terminate the data */
- ret = nm_tcp_write(conn, "\r\n", strlen("\r\n"));
+ ret = g_output_stream_write(conn->output, "\r\n", strlen("\r\n"), + user->cancellable, NULL); @@ -470,22 +398,25 @@
-nm_read_header(NMConn * conn)
+nm_read_header(NMUser *user)
+ g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM);
- rc = read_line(conn, buffer, sizeof(buffer));
+ buffer = g_data_input_stream_read_line(conn->input, NULL, user->cancellable, /* Find the return code */
ptr = strchr(buffer, ' ');
@@ -506,8 +437,19 @@
/* Finish reading header, in the future we might want to do more processing here */
/* TODO: handle more general redirects in the future */
- while ((rc == NM_OK) && (!purple_strequal(buffer, "\r\n"))) {
- rc = read_line(conn, buffer, sizeof(buffer));
+ while ((error == NULL) && !purple_strequal(buffer, "\r")) { + buffer = g_data_input_stream_read_line(conn->input, NULL, + user->cancellable, &error); + if (error->code != G_IO_ERROR_WOULD_BLOCK && + error->code != G_IO_ERROR_CANCELLED) { if (rc == NM_OK && rtn_code == 301)
@@ -517,8 +459,9 @@
-nm_read_fields(NMConn * conn, int count, NMField ** fields)
+nm_read_fields(NMUser *user, int count, NMField **fields) @@ -526,9 +469,13 @@
NMField *sub_fields = NULL;
- if (conn == NULL || fields == NULL)
+ g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); + g_return_val_if_fail(fields != NULL, NMERR_BAD_PARM); @@ -536,36 +483,46 @@
/* Read the field type, method, and tag */
- rc = nm_read_all(conn, (char *)&type, sizeof(type));
- if (rc != NM_OK || type == 0)
+ type = g_data_input_stream_read_byte(conn->input, user->cancellable, + if (error != NULL || type == 0) { - rc = nm_read_all(conn, (char *)&method, sizeof(method));
+ method = g_data_input_stream_read_byte(conn->input, user->cancellable, - rc = nm_read_uint32(conn, &val);
+ val = g_data_input_stream_read_uint32(conn->input, user->cancellable, - rc = nm_read_all(conn, tag, val);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), tag, val, NULL, + user->cancellable, &error); if (type == NMFIELD_TYPE_MV || type == NMFIELD_TYPE_ARRAY) {
/* Read the subarray (first read the number of items in the array) */
- rc = nm_read_uint32(conn, &val);
+ val = g_data_input_stream_read_uint32(conn->input, + user->cancellable, &error); - rc = nm_read_fields(conn, val, &sub_fields);
+ rc = nm_read_fields(user, val, &sub_fields); @@ -578,9 +535,11 @@
} else if (type == NMFIELD_TYPE_UTF8 || type == NMFIELD_TYPE_DN) {
/* Read the string (first read the length) */
- rc = nm_read_uint32(conn, &val);
+ val = g_data_input_stream_read_uint32(conn->input, + user->cancellable, &error); if (val >= NMFIELD_MAX_STR_LENGTH) {
@@ -590,9 +549,11 @@
str = g_new0(char, val + 1);
- rc = nm_read_all(conn, str, val);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), str, val, + NULL, user->cancellable, &error); *fields = nm_field_add_pointer(*fields, tag, 0, method,
@@ -602,9 +563,11 @@
/* Read the numerical value */
- rc = nm_read_uint32(conn, &val);
+ val = g_data_input_stream_read_uint32(conn->input, + user->cancellable, &error); *fields = nm_field_add_number(*fields, tag, 0, method,
@@ -618,6 +581,13 @@
nm_free_fields(&sub_fields);
+ if (error->code != G_IO_ERROR_WOULD_BLOCK && error->code != G_IO_ERROR_CANCELLED) { --- a/libpurple/protocols/novell/nmconn.h Mon Nov 04 02:24:02 2019 +0000
+++ b/libpurple/protocols/novell/nmconn.h Mon Nov 04 03:58:59 2019 +0000
@@ -21,6 +21,8 @@
#ifndef PURPLE_NOVELL_NMCONN_H
#define PURPLE_NOVELL_NMCONN_H
typedef struct _NMConn NMConn;
@@ -44,12 +46,11 @@
/* A list of requests currently awaiting a response. */
- /* Data to pass to the callbacks */
- /* Callbacks for reading/writing */
+ /* Connections to server. */ + GDataInputStream *input; @@ -72,64 +73,9 @@
void nm_release_conn(NMConn *conn);
- * Write len bytes from the given buffer.
- * @param conn The connection to write to.
- * @param buff The buffer to write from.
- * @param len The number of bytes to write.
- * @return The number of bytes written.
-int nm_tcp_write(NMConn * conn, const void *buff, int len);
- * Read at most len bytes into the given buffer.
- * @param conn The connection to read from.
- * @param buff The buffer to write to.
- * @param len The maximum number of bytes to read.
- * @return The number of bytes read.
-int nm_tcp_read(NMConn * conn, void *buff, int len);
- * Read exactly len bytes into the given buffer.
- * @param conn The connection to read from.
- * @param buff The buffer to write to.
- * @param len The number of bytes to read.
- * @return NM_OK on success, NMERR_TCP_READ if read fails.
-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.
-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.
-nm_read_uint16(NMConn *conn, guint16 *val);
* Dispatch a request to the server.
- * @param conn The connection.
+ * @param user The logged-in user. * @param cmd The request to dispatch.
* @param fields The field list for the request.
* @param cb The response callback for the new request object.
@@ -139,32 +85,32 @@
* @return NM_OK on success.
-nm_send_request(NMConn *conn, char *cmd, NMField *fields,
- nm_response_cb cb, gpointer data, NMRequest **request);
+nm_send_request(NMUser *user, char *cmd, NMField *fields, nm_response_cb cb, + gpointer data, NMRequest **request); * Write out the given field list.
- * @param conn The connection to write to.
+ * @param user The logged-in user. * @param fields The field list to write.
* @return NM_OK on success.
-NMERR_T nm_write_fields(NMConn * conn, NMField * fields);
+NMERR_T nm_write_fields(NMUser *user, NMField *fields); * Read the headers for a response.
- * @param conn The connection to read from.
+ * @param user The logged-in user. * @return NM_OK on success.
-NMERR_T nm_read_header(NMConn * conn);
+NMERR_T nm_read_header(NMUser *user); * Read a field list from the connection.
- * @param conn The connection to read from.
+ * @param user The logged-in user. * @param count The maximum number of fields to read (or -1 for no max).
* @param fields The field list. This is an out param. It
* should be freed by calling nm_free_fields
@@ -172,7 +118,7 @@
* @return NM_OK on success.
-NMERR_T nm_read_fields(NMConn * conn, int count, NMField ** fields);
+NMERR_T nm_read_fields(NMUser *user, int count, NMField **fields); * Add a request to the connections request list.
--- a/libpurple/protocols/novell/nmevent.c Mon Nov 04 02:24:02 2019 +0000
+++ b/libpurple/protocols/novell/nmevent.c Mon Nov 04 03:58:59 2019 +0000
@@ -144,31 +144,43 @@
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); /* Read the conference flags */
- rc = nm_read_uint32(conn, &flags);
+ flags = g_data_input_stream_read_uint32(conn->input, user->cancellable, /* Read the message text */
- rc = nm_read_uint32(conn, &size);
- if (size > 100000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
msg = g_new0(char, size + 1);
- rc = nm_read_all(conn, msg, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), msg, size, + NULL, user->cancellable, &error); purple_debug(PURPLE_DEBUG_INFO, "novell", "Message is %s\n", msg);
@@ -194,6 +206,16 @@
+ if (error->code == G_IO_ERROR_CANCELLED) { /* Check to see if we already know about the conference */
conference = nm_conference_list_find(user, guid);
@@ -260,31 +282,42 @@
NMUserRecord *user_record;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); /* Read the the message */
- rc = nm_read_uint32(conn, &size);
- if (size > 100000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
msg = g_new0(char, size + 1);
- rc = nm_read_all(conn, msg, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), msg, size, + NULL, user->cancellable, &error); /* Store the event data */
NMConference *conference;
nm_event_set_text(event, msg);
@@ -316,6 +349,11 @@
nm_release_conference(conference);
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -336,16 +374,32 @@
NMConference *conference;
NMUserRecord *user_record;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); + if (error->code == G_IO_ERROR_CANCELLED) { conference = nm_conference_list_find(user, guid);
@@ -387,25 +441,36 @@
NMConference *conference;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
- guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
+ guid = g_new0(char, size + 1); + g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); conference = nm_conference_list_find(user, guid);
nm_event_set_conference(event, conference);
rc = NMERR_CONFERENCE_NOT_FOUND;
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -425,24 +490,31 @@
NMConference *conference;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); /* Read the conference flags */
- rc = nm_read_uint32(conn, &flags);
+ flags = g_data_input_stream_read_uint32(conn->input, user->cancellable,
conference = nm_conference_list_find(user, guid);
nm_event_set_conference(event, conference);
@@ -456,6 +528,11 @@
rc = NMERR_CONFERENCE_NOT_FOUND;
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -474,19 +551,25 @@
NMConference *conference;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
- guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
+ guid = g_new0(char, size + 1); + g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); conference = nm_conference_list_find(user, guid);
nm_event_set_conference(event, conference);
@@ -494,6 +577,11 @@
rc = NMERR_CONFERENCE_NOT_FOUND;
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -513,24 +601,31 @@
NMConference *conference;
NMUserRecord *user_record;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); /* Read the conference flags */
- rc = nm_read_uint32(conn, &flags);
+ flags = g_data_input_stream_read_uint32(conn->input, user->cancellable,
conference = nm_conference_list_find(user, guid);
nm_conference_set_flags(conference, flags);
@@ -555,6 +650,11 @@
rc = NMERR_CONFERENCE_NOT_FOUND;
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -571,25 +671,36 @@
NMConference *conference;
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
- guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
+ guid = g_new0(char, size + 1); + g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, NULL, + user->cancellable, &error); conference = nm_conference_list_find(user, guid);
nm_event_set_conference(event, conference);
rc = NMERR_CONFERENCE_NOT_FOUND;
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -609,24 +720,31 @@
NMUserRecord *user_record;
conn = nm_user_get_conn(user);
- rc = nm_read_uint16(conn, &status);
+ status = g_data_input_stream_read_uint16(conn->input, user->cancellable, /* Read the status text */
- rc = nm_read_uint32(conn, &size);
- if (size > 10000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
text = g_new0(char, size + 1);
- rc = nm_read_all(conn, text, size);
+ g_input_stream_read_all(G_INPUT_STREAM(conn->input), text, size, + NULL, user->cancellable, &error);
nm_event_set_text(event, text);
/* Get a reference to the user record and store the new status */
@@ -635,6 +753,11 @@
nm_event_set_user_record(event, user_record);
nm_user_record_set_status(user_record, status, text);
+ if (error->code != G_IO_ERROR_CANCELLED) { @@ -650,16 +773,27 @@
conn = nm_user_get_conn(user);
/* Read the conference guid */
- rc = nm_read_uint32(conn, &size);
- if (size > 1000) return NMERR_PROTOCOL;
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable,
guid = g_new0(char, size + 1);
- rc = nm_read_all(conn, guid, size);
+ rc = g_input_stream_read_all(G_INPUT_STREAM(conn->input), guid, size, + NULL, user->cancellable, &error); + if (error->code != G_IO_ERROR_CANCELLED) { @@ -803,6 +937,7 @@
@@ -813,20 +948,22 @@
conn = nm_user_get_conn(user);
/* Read the event source */
- rc = nm_read_uint32(conn, &size);
+ size = g_data_input_stream_read_uint32(conn->input, user->cancellable, /* Size is larger than our 1MB sanity check. Ignore it. */
source = g_new0(char, size);
- rc = nm_read_all(conn, source, size);
+ rc = g_input_stream_read_all(G_INPUT_STREAM(conn->input), source, + size, NULL, user->cancellable, &error); /* Read the event data */
event = nm_create_event(type, source, time(0));
@@ -901,6 +1038,11 @@
+ if (error->code != G_IO_ERROR_CANCELLED) { --- a/libpurple/protocols/novell/nmuser.c Mon Nov 04 02:24:02 2019 +0000
+++ b/libpurple/protocols/novell/nmuser.c Mon Nov 04 03:58:59 2019 +0000
@@ -56,7 +56,7 @@
user = g_new0(NMUser, 1);
+ user->cancellable = g_cancellable_new(); g_hash_table_new_full(g_str_hash, nm_utf8_str_equal,
@@ -81,6 +81,8 @@
nm_deinitialize_user(NMUser * user)
+ g_cancellable_cancel(user->cancellable); nm_release_conn(user->conn);
@@ -104,6 +106,8 @@
nm_conference_list_free(user);
nm_destroy_contact_list(user);
+ g_object_unref(user->cancellable); @@ -135,7 +139,7 @@
- rc = nm_send_request(user->conn, "login", fields, callback, data, NULL);
+ rc = nm_send_request(user, "login", fields, callback, data, NULL); @@ -168,7 +172,7 @@
- rc = nm_send_request(user->conn, "setstatus", fields, callback, data, NULL);
+ rc = nm_send_request(user, "setstatus", fields, callback, data, NULL); @@ -191,7 +195,7 @@
g_strdup(node->data), NMFIELD_TYPE_UTF8);
- rc = nm_send_request(user->conn, "getdetails", fields, callback, data, NULL);
+ rc = nm_send_request(user, "getdetails", fields, callback, data, NULL); @@ -225,7 +229,7 @@
- rc = nm_send_request(user->conn, "getdetails", fields, callback, data, NULL);
+ rc = nm_send_request(user, "getdetails", fields, callback, data, NULL); @@ -277,7 +281,7 @@
- rc = nm_send_request(user->conn, "createconf", fields, callback, data, &req);
+ rc = nm_send_request(user, "createconf", fields, callback, data, &req); if (rc == NM_OK && req) {
nm_conference_add_ref(conference);
nm_request_set_data(req, conference);
@@ -313,7 +317,7 @@
/* Send the request to the server */
- rc = nm_send_request(user->conn, "leaveconf", fields, callback, data, &req);
+ rc = nm_send_request(user, "leaveconf", fields, callback, data, &req); nm_request_set_data(req, conference);
@@ -346,7 +350,7 @@
/* Send the request to the server */
- rc = nm_send_request(user->conn, "joinconf", fields, callback, data, &req);
+ rc = nm_send_request(user, "joinconf", fields, callback, data, &req); nm_request_set_data(req, conference);
@@ -380,7 +384,7 @@
/* Send the request to the server */
- rc = nm_send_request(user->conn, "rejectconf", fields, callback, data, &req);
+ rc = nm_send_request(user, "rejectconf", fields, callback, data, &req); nm_request_set_data(req, conference);
@@ -424,7 +428,7 @@
g_strdup(message), NMFIELD_TYPE_UTF8);
/* Send the request to the server */
- rc = nm_send_request(user->conn, "sendinvite", fields, callback, data, &req);
+ rc = nm_send_request(user, "sendinvite", fields, callback, data, &req); nm_request_set_data(req, conference);
@@ -501,7 +505,7 @@
- rc = nm_send_request(user->conn, "sendmessage", fields, callback, NULL, NULL);
+ rc = nm_send_request(user, "sendmessage", fields, callback, NULL, NULL); @@ -541,7 +545,7 @@
tmp, NMFIELD_TYPE_ARRAY);
- rc = nm_send_request(user->conn, "sendtyping", fields, callback, NULL, NULL);
+ rc = nm_send_request(user, "sendtyping", fields, callback, NULL, NULL); @@ -592,7 +596,7 @@
g_strdup(display_name), NMFIELD_TYPE_UTF8);
/* Dispatch the request */
- rc = nm_send_request(user->conn, "createcontact", fields, callback, data, &req);
+ rc = nm_send_request(user, "createcontact", fields, callback, data, &req); nm_request_set_data(req, contact);
@@ -627,7 +631,7 @@
/* Dispatch the request */
- rc = nm_send_request(user->conn, "deletecontact", fields, callback, data, &req);
+ rc = nm_send_request(user, "deletecontact", fields, callback, data, &req); nm_request_set_data(req, contact);
@@ -665,7 +669,7 @@
g_strdup("-1"), NMFIELD_TYPE_UTF8);
/* Dispatch the request */
- rc = nm_send_request(user->conn, "createfolder", fields, callback, data, &req);
+ rc = nm_send_request(user, "createfolder", fields, callback, data, &req); nm_request_set_data(req, g_strdup(name));
@@ -694,7 +698,7 @@
/* Dispatch the request */
- rc = nm_send_request(user->conn, "deletecontact", fields, callback, data, &req);
+ rc = nm_send_request(user, "deletecontact", fields, callback, data, &req); nm_request_set_data(req, folder);
@@ -726,7 +730,7 @@
g_strdup(dn), NMFIELD_TYPE_UTF8);
/* Dispatch the request */
- rc = nm_send_request(user->conn, "getstatus", fields, callback, data, &req);
+ rc = nm_send_request(user, "getstatus", fields, callback, data, &req); nm_request_set_data(req, user_record);
@@ -775,7 +779,8 @@
0, fields, NMFIELD_TYPE_ARRAY);
- rc = nm_send_request(user->conn, "updateitem", list, callback, data, &req);
+ rc = nm_send_request(user, "updateitem", list, callback, data, nm_request_set_data(req, contact);
@@ -828,7 +833,8 @@
0, fields, NMFIELD_TYPE_ARRAY);
- rc = nm_send_request(user->conn, "updateitem", list, callback, data, &req);
+ rc = nm_send_request(user, "updateitem", list, callback, data, nm_request_set_data(req, folder);
@@ -877,7 +883,7 @@
/* Dispatch the request */
- rc = nm_send_request(user->conn, "movecontact", list, callback, data, &req);
+ rc = nm_send_request(user, "movecontact", list, callback, data, &req); nm_request_set_data(req, contact);
@@ -912,7 +918,7 @@
fields = nm_field_add_pointer(fields, tag, 0, NMFIELD_METHOD_ADD, 0,
g_strdup(who), NMFIELD_TYPE_UTF8);
- rc = nm_send_request(user->conn, "createblock", fields, callback, data, NULL);
+ rc = nm_send_request(user, "createblock", fields, callback, data, NULL); @@ -946,7 +952,7 @@
fields = nm_field_add_pointer(fields, tag, 0, NMFIELD_METHOD_DELETE, 0,
g_strdup(dn), NMFIELD_TYPE_DN);
- rc = nm_send_request(user->conn, "updateblocks", fields, callback, data, NULL);
+ rc = nm_send_request(user, "updateblocks", fields, callback, data, NULL); @@ -967,7 +973,7 @@
(default_deny ? g_strdup("1") : g_strdup("0")),
- rc = nm_send_request(user->conn, "updateblocks", fields, callback, data, NULL);
+ rc = nm_send_request(user, "updateblocks", fields, callback, data, NULL); @@ -981,7 +987,7 @@
- rc = nm_send_request(user->conn, "ping", NULL, callback, data, NULL);
+ rc = nm_send_request(user, "ping", NULL, callback, data, NULL); @@ -992,6 +998,7 @@
@@ -999,18 +1006,22 @@
/* Check to see if this is an event or a response */
- rc = nm_read_all(conn, (char *) &val, sizeof(val));
- if (strncmp((char *) &val, "HTTP", strlen("HTTP")) == 0)
+ val = g_data_input_stream_read_uint32(conn->input, user->cancellable, + if (val == ('H' + ('T' << 8) + ('T' << 16) + ('P' << 24))) { rc = nm_process_response(user);
- rc = nm_process_event(user, GUINT32_FROM_LE(val));
+ rc = nm_process_event(user, val);
+ if (error->code == G_IO_ERROR_WOULD_BLOCK || error->code == G_IO_ERROR_CANCELLED) { + /* Try again later or ignore. */
@@ -1753,9 +1764,9 @@
NMConn *conn = user->conn;
- rc = nm_read_header(conn);
+ rc = nm_read_header(user); - rc = nm_read_fields(conn, -1, &fields);
+ rc = nm_read_fields(user, -1, &fields); --- a/libpurple/protocols/novell/novell.c Mon Nov 04 02:24:02 2019 +0000
+++ b/libpurple/protocols/novell/novell.c Mon Nov 04 03:58:59 2019 +0000
@@ -27,9 +27,9 @@
#include "purpleaccountoption.h"
@@ -1672,22 +1672,7 @@
******************************************************************************/
-novell_ssl_connect_error(PurpleSslConnection * gsc,
- PurpleSslErrorType error, gpointer data)
- user = purple_connection_get_protocol_data(gc);
- user->conn->data = NULL;
- purple_connection_ssl_error (gc, error);
-novell_ssl_recv_cb(gpointer data, PurpleSslConnection * gsc,
- PurpleInputCondition condition)
+novell_ssl_recv_cb(GObject *stream, gpointer data) PurpleConnection *gc = data;
@@ -1716,19 +1701,28 @@
-novell_ssl_connected_cb(gpointer data, PurpleSslConnection * gsc,
- PurpleInputCondition cond)
+novell_login_callback(GObject *source_object, GAsyncResult *res, gpointer data) + GSocketClient *client = G_SOCKET_CLIENT(source_object); PurpleConnection *gc = data;
+ GSocketConnection *sockconn; - const char *my_addr = NULL;
- if (gc == NULL || gsc == NULL)
+ sockconn = g_socket_client_connect_to_host_finish(client, res, &error); + if (sockconn == NULL) { + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + purple_connection_take_error(gc, error); user = purple_connection_get_protocol_data(gc);
if ((user == NULL) || (conn = user->conn) == NULL)
@@ -1737,13 +1731,27 @@
purple_connection_update_progress(gc, _("Authenticating..."),
2, NOVELL_CONNECT_STEPS);
- my_addr = purple_network_get_my_ip(gsc->fd);
+ conn->stream = G_IO_STREAM(sockconn); + g_data_input_stream_new(g_io_stream_get_input_stream(conn->stream)); + conn->output = g_io_stream_get_output_stream(conn->stream); + g_data_input_stream_set_byte_order(conn->input, + G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN); + g_data_input_stream_set_newline_type(conn->input, + G_DATA_STREAM_NEWLINE_TYPE_LF); + my_addr = purple_network_get_my_ip_from_gio(sockconn); pwd = purple_connection_get_password(gc);
ua = _user_agent_string();
rc = nm_send_login(user, pwd, my_addr, ua, _login_resp_cb, NULL);
- purple_ssl_input_add(gsc, novell_ssl_recv_cb, gc);
+ source = g_pollable_input_stream_create_source( + G_POLLABLE_INPUT_STREAM(conn->input), user->cancellable); + g_source_set_callback(source, (GSourceFunc)novell_ssl_recv_cb, gc, purple_connection_error(gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
@@ -1754,6 +1762,7 @@
3, NOVELL_CONNECT_STEPS);
/*******************************************************************************
@@ -2167,6 +2176,7 @@
@@ -2204,17 +2214,16 @@
purple_connection_update_progress(gc, _("Connecting"),
1, NOVELL_CONNECT_STEPS);
- user->conn->read = (nm_ssl_read_cb)purple_ssl_read;
- user->conn->write = (nm_ssl_write_cb)purple_ssl_write;
- user->conn->data = purple_ssl_connect(
- user->client_data, user->conn->addr, user->conn->port,
- novell_ssl_connected_cb, novell_ssl_connect_error, gc);
- if (user->conn->data == NULL) {
- purple_connection_error(gc,
- PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
- _("SSL support unavailable"));
+ user->conn->client = purple_gio_socket_client_new(account, &error); + if (user->conn->client == NULL) { + purple_connection_take_error(gc, error); + g_socket_client_set_tls(user->conn->client, TRUE); + g_socket_client_connect_to_host_async( + user->conn->client, user->conn->addr, user->conn->port, + user->cancellable, novell_login_callback, gc); @@ -2231,7 +2240,7 @@
- purple_ssl_close(user->conn->data);
nm_deinitialize_user(user);