Added disconnect error for resource conflict. Fixes LM-55.
Added a disconnection reason for resource conflict (when another client
connects with the same resource) and XML errors.
Patch for LM1.2 from Martyn Russell, forward-ported to LM1.3 by Senko Rasic.
--- a/loudmouth/lm-connection.c Tue Oct 30 18:37:18 2007 +0100
+++ b/loudmouth/lm-connection.c Tue Oct 30 23:14:48 2007 +0100
@@ -145,6 +145,8 @@
static void connection_stream_received (LmConnection *connection,
LmMessage *m);
+static void connection_stream_error (LmConnection *connection,
+ LmMessage *m);
static gint connection_handler_compare_func (HandlerData *a,
HandlerData *b);
@@ -256,6 +258,11 @@
connection_stream_received (connection, m);
goto out;
}
+
+ if (lm_message_get_type (m) == LM_MESSAGE_TYPE_STREAM_ERROR) {
+ connection_stream_error (connection, m);
+ goto out;
+ }
if ((lm_message_get_sub_type (m) == LM_MESSAGE_SUB_TYPE_ERROR) ||
(lm_message_get_sub_type (m) == LM_MESSAGE_SUB_TYPE_RESULT)) {
@@ -736,6 +743,41 @@
}
}
+static void
+connection_stream_error (LmConnection *connection, LmMessage *m)
+{
+ LmMessageNode *node;
+ LmDisconnectReason reason;
+
+ g_return_if_fail (connection != NULL);
+ g_return_if_fail (m != NULL);
+
+ node = m->node;
+
+ /* Resource conflict */
+ node = lm_message_node_get_child (node, "conflict");
+ if (node) {
+ lm_verbose ("Stream error: Conflict (resource connected elsewhere)\n");
+ reason = LM_DISCONNECT_REASON_RESOURCE_CONFLICT;
+ return;
+ }
+
+ /* XML is crack */
+ node = lm_message_node_get_child (node, "xml-not-well-formed");
+ if (node) {
+ lm_verbose ("Stream error: XML not well formed\n");
+ reason = LM_DISCONNECT_REASON_INVALID_XML;
+ return;
+ }
+
+ lm_verbose ("Stream error: Unrecognised error\n");
+ reason = LM_DISCONNECT_REASON_ERROR;
+ connection->stream_id = g_strdup (lm_message_node_get_attribute (m->node,
+ "id"));;
+ connection_do_close (connection);
+ connection_signal_disconnect (connection, reason);
+}
+
static gint
connection_handler_compare_func (HandlerData *a, HandlerData *b)
{
--- a/loudmouth/lm-connection.h Tue Oct 30 18:37:18 2007 +0100
+++ b/loudmouth/lm-connection.h Tue Oct 30 23:14:48 2007 +0100
@@ -56,6 +56,8 @@
LM_DISCONNECT_REASON_PING_TIME_OUT,
LM_DISCONNECT_REASON_HUP,
LM_DISCONNECT_REASON_ERROR,
+ LM_DISCONNECT_REASON_RESOURCE_CONFLICT,
+ LM_DISCONNECT_REASON_INVALID_XML,
LM_DISCONNECT_REASON_UNKNOWN
} LmDisconnectReason;