Properly detect message type; don't rely on lookup table ordering if the type is explicitly specified.
authorSenko Rasic <senko.rasic@collabora.co.uk>
Wed, 06 Feb 2008 00:29:05 +0100
changeset 331 884c0d7edefc
parent 330 f606ce2a849e
child 332 6b6ad42cd508
Properly detect message type; don't rely on lookup table ordering if the type is explicitly specified.
loudmouth/lm-message.c
--- a/loudmouth/lm-message.c	Wed Feb 06 00:12:51 2008 +0100
+++ b/loudmouth/lm-message.c	Wed Feb 06 00:29:05 2008 +0100
@@ -36,14 +36,15 @@
 	{ LM_MESSAGE_TYPE_IQ,              "iq"              },
 	{ LM_MESSAGE_TYPE_STREAM,          "stream:stream"   },
 	{ LM_MESSAGE_TYPE_STREAM_FEATURES, "stream:features" },
+	{ LM_MESSAGE_TYPE_STREAM_ERROR,    "stream:error"    },
 	{ LM_MESSAGE_TYPE_AUTH,            "auth"            },
 	{ LM_MESSAGE_TYPE_CHALLENGE,       "challenge"       },
 	{ LM_MESSAGE_TYPE_RESPONSE,        "response"        },
 	{ LM_MESSAGE_TYPE_SUCCESS,         "success"         },
 	{ LM_MESSAGE_TYPE_FAILURE,         "failure"         },
-	{ LM_MESSAGE_TYPE_STREAM_ERROR,    "stream:error"    },
 	{ LM_MESSAGE_TYPE_PROCEED,         "proceed"         },
-	{ LM_MESSAGE_TYPE_STARTTLS,        "starttls"        }
+	{ LM_MESSAGE_TYPE_STARTTLS,        "starttls"        },
+	{ LM_MESSAGE_TYPE_UNKNOWN,         NULL              }
 };
 
 static struct SubTypeNames 
@@ -83,10 +84,10 @@
         }
 
         for (i = LM_MESSAGE_TYPE_MESSAGE;
-	     i <= LM_MESSAGE_TYPE_STARTTLS;
+	     i < LM_MESSAGE_TYPE_UNKNOWN;
 	     ++i) {
                 if (strcmp (type_str, type_names[i].name) == 0) {
-                        return i;
+                        return type_names[i].type;
                 }
         }