--- a/src/irc_proto.c Thu Apr 23 17:17:56 2009 +0300
+++ b/src/irc_proto.c Thu Apr 23 21:05:27 2009 +0300
@@ -4,19 +4,29 @@
err_t irc_nm_parse_buf (struct irc_nm *nm, char *prefix)
{
- // XXX: handle server name prefixes
-
- // mangle tokens
- nm->nickname = strsep(&prefix, "!");
- nm->username = strsep(&prefix, "@");
+ const char *token;
- // did we find the ! and @ tokens?
- if (!prefix)
- // probably a server name instead
- return ERR_INVALID_NM;
-
- // the hostname is then the rest of the prefix
- nm->hostname = prefix;
+ // parse the first token to determine if this is a nickmask or server name
+ token = strsep(&prefix, "!");
+
+ // did strsep find that "!"?
+ if (prefix) {
+ // it must be a full nickmask
+ nm->nickname = token;
+ nm->username = strsep(&prefix, "@");
+ nm->hostname = prefix;
+
+ if (!prefix)
+ // something silly, didn't have an @token
+ return ERR_INVALID_NM;
+
+ } else {
+ // handle as a server name
+ nm->nickname = NULL;
+ nm->username = NULL;
+ nm->hostname = token;
+
+ }
// ok
return SUCCESS;