pidgin: ab5ea3be: Separate the parsing of data into a sepa...
markdoliner at pidgin.im
markdoliner at pidgin.im
Sat Nov 15 11:20:22 EST 2008
-----------------------------------------------------------------
Revision: ab5ea3be38a8eba7531174ceccca3023e12880f6
Ancestor: 3ae49ca1a268aa770e70e984052bb869bcb28f39
Author: markdoliner at pidgin.im
Date: 2008-11-15T16:15:33
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ab5ea3be38a8eba7531174ceccca3023e12880f6
Modified files:
libpurple/protocols/msn/httpconn.c
libpurple/protocols/msn/servconn.c
libpurple/protocols/msn/servconn.h
ChangeLog:
Separate the parsing of data into a separate function from the reading of
data, to remove a big chunk of duplicate code in the read_cb callbacks
for servconn and httpconn
-------------- next part --------------
============================================================
--- libpurple/protocols/msn/httpconn.c 8ffcbf5c8c6a3e93428f66e85738c27e9cb2f460
+++ libpurple/protocols/msn/httpconn.c 95775bac8ce400e3d4c8befd69789162ba9580ae
@@ -269,21 +269,17 @@ read_cb(gpointer data, gint source, Purp
{
MsnHttpConn *httpconn;
MsnServConn *servconn;
- MsnSession *session;
char buf[MSN_BUF_LEN];
- char *cur, *end, *old_rx_buf;
gssize len;
- int cur_len;
char *result_msg = NULL;
size_t result_len = 0;
gboolean error = FALSE;
httpconn = data;
servconn = httpconn->servconn;
- session = httpconn->session;
if (servconn->type == MSN_SERVCONN_NS)
- session->account->gc->last_received = time(NULL);
+ servconn->session->account->gc->last_received = time(NULL);
len = read(httpconn->fd, buf, sizeof(buf) - 1);
if (len < 0 && errno == EAGAIN)
@@ -339,64 +335,7 @@ read_cb(gpointer data, gint source, Purp
servconn->rx_buf = result_msg;
servconn->rx_len = result_len;
- end = old_rx_buf = servconn->rx_buf;
-
- servconn->processing = TRUE;
-
- do
- {
- cur = end;
-
- if (servconn->payload_len)
- {
- if (servconn->payload_len > servconn->rx_len)
- /* The payload is still not complete. */
- break;
-
- cur_len = servconn->payload_len;
- end += cur_len;
- }
- else
- {
- end = strstr(cur, "\r\n");
-
- if (end == NULL)
- /* The command is still not complete. */
- break;
-
- *end = '\0';
- end += 2;
- cur_len = end - cur;
- }
-
- servconn->rx_len -= cur_len;
-
- if (servconn->payload_len)
- {
- msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len);
- servconn->payload_len = 0;
- }
- else
- {
- msn_cmdproc_process_cmd_text(servconn->cmdproc, cur);
- servconn->payload_len = servconn->cmdproc->last_cmd->payload_len;
- }
- } while (servconn->connected && !servconn->wasted && servconn->rx_len > 0);
-
- if (servconn->connected && !servconn->wasted)
- {
- if (servconn->rx_len > 0)
- servconn->rx_buf = g_memdup(cur, servconn->rx_len);
- else
- servconn->rx_buf = NULL;
- }
-
- servconn->processing = FALSE;
-
- if (servconn->wasted)
- msn_servconn_destroy(servconn);
-
- g_free(old_rx_buf);
+ msn_servconn_process_data(servconn);
}
static void
============================================================
--- libpurple/protocols/msn/servconn.c cede462f3948ed80de75053518092bdad5ba9376
+++ libpurple/protocols/msn/servconn.c 83b030ababe1574d247cb956bcfab2de3a372eac
@@ -366,17 +366,13 @@ read_cb(gpointer data, gint source, Purp
read_cb(gpointer data, gint source, PurpleInputCondition cond)
{
MsnServConn *servconn;
- MsnSession *session;
char buf[MSN_BUF_LEN];
- char *cur, *end, *old_rx_buf;
gssize len;
- int cur_len;
servconn = data;
- session = servconn->session;
if (servconn->type == MSN_SERVCONN_NS)
- session->account->gc->last_received = time(NULL);
+ servconn->session->account->gc->last_received = time(NULL);
len = read(servconn->fd, buf, sizeof(buf) - 1);
if (len < 0 && errno == EAGAIN)
@@ -396,6 +392,14 @@ read_cb(gpointer data, gint source, Purp
memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1);
servconn->rx_len += len;
+ msn_servconn_process_data(servconn);
+}
+
+void msn_servconn_process_data(MsnServConn *servconn)
+{
+ char *cur, *end, *old_rx_buf;
+ int cur_len;
+
end = old_rx_buf = servconn->rx_buf;
servconn->processing = TRUE;
============================================================
--- libpurple/protocols/msn/servconn.h ccee459310165a18eded24ac0c9d800380cac03b
+++ libpurple/protocols/msn/servconn.h 76b54b003f24fdfd45c7feae03a71d0046f5d21a
@@ -170,4 +170,12 @@ void msn_servconn_got_error(MsnServConn
*/
void msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error);
+/**
+ * Process the data in servconn->rx_buf. This is called after reading
+ * data from the socket.
+ *
+ * @param servconn The servconn.
+ */
+void msn_servconn_process_data(MsnServConn *servconn);
+
#endif /* _MSN_SERVCONN_H_ */
More information about the Commits
mailing list