src/irc_proto.c
changeset 45 71e65564afd2
parent 39 a4891d71aca9
child 72 43084f103c2a
--- a/src/irc_proto.c	Thu Mar 12 22:06:01 2009 +0200
+++ b/src/irc_proto.c	Thu Mar 12 22:50:08 2009 +0200
@@ -2,6 +2,31 @@
 
 #include <string.h>
 
+err_t irc_nm_parse (struct irc_nm *nm, char *buf, const char *prefix)
+{
+    // too long?
+    if (strlen(prefix) >= IRC_PREFIX_MAX)
+        return ERR_INVALID_NM;
+
+    // copy to mutable buffer
+    strcpy(buf, prefix);
+
+    // mangle tokens
+    nm->nickname = strsep(&buf, "!");
+    nm->username = strsep(&buf, "@");
+
+    // did we find the ! and @ tokens?
+    if (!buf)
+        // probably a server name instead
+        return ERR_INVALID_NM;
+    
+    // the hostname is then the rest of the prefix
+    nm->hostname = buf;
+
+    // ok
+    return SUCCESS;
+}
+
 /**
  * Compare two nicknames
  */