--- a/src/irc_chan.c Thu Mar 12 18:35:05 2009 +0200
+++ b/src/irc_chan.c Thu Mar 12 18:48:42 2009 +0200
@@ -1,5 +1,5 @@
#include "irc_chan.h"
-#include "irc_nm.h"
+#include "irc_proto.h"
#include "log.h"
#include <stdlib.h>
--- a/src/irc_cmd.h Thu Mar 12 18:35:05 2009 +0200
+++ b/src/irc_cmd.h Thu Mar 12 18:48:42 2009 +0200
@@ -48,16 +48,4 @@
*/
void irc_cmd_free (irc_cmd_handlers_t *handlers);
-/**
- * @group IRC command numerics
- * @{
- */
-
-/**
- * 001 <nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>
- */
-#define IRC_RPL_WELCOME "001"
-
-// @}
-
#endif /* IRC_CMD_H */
--- a/src/irc_conn.c Thu Mar 12 18:35:05 2009 +0200
+++ b/src/irc_conn.c Thu Mar 12 18:48:42 2009 +0200
@@ -1,6 +1,6 @@
#include "irc_conn.h"
#include "irc_cmd.h"
-#include "irc_nm.h"
+#include "irc_proto.h"
#include "log.h"
#include <stdlib.h>
--- a/src/irc_nm.c Thu Mar 12 18:35:05 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-#include "irc_nm.h"
-
-#include <string.h>
-
-/**
- * Compare two nicknames
- */
-int irc_cmp_nick (const char *nick1, const char *nick2)
-{
- // XXX: just use strcasecmp for now
- return strcasecmp(nick1, nick2);
-}
-
-int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n)
-{
- // XXX: just use strncasecmp for now
- return strncasecmp(nick1, nick2, n);
-}
-
-err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX])
-{
- const char *bang;
-
- // find the !
- if ((bang = strchr(prefix, '!')) == NULL)
- return ERR_INVALID_NM;
-
- // too long?
- if (bang - prefix > IRC_NICK_MAX - 1)
- return ERR_INVALID_NICK_LENGTH;
-
- // copy up to the !
- memcpy(nick, prefix, bang - prefix);
-
- // terminating NUL
- nick[bang - prefix] = '\0';
-
- // ok
- return SUCCESS;
-}
-
-int irc_prefix_cmp_nick (const char *prefix, const char *nick)
-{
- const char *bang;
-
- // find the !
- if ((bang = strchr(prefix, '!')) == NULL)
- return -ERR_INVALID_NM;
-
- // compare up to that
- if (irc_ncmp_nick(prefix, nick, (bang - prefix)) == 0)
- // match
- return 0;
-
- else
- // doesn't match
- return 1;
-}
--- a/src/irc_nm.h Thu Mar 12 18:35:05 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-#ifndef IRC_NM_H
-#define IRC_NM_H
-
-/**
- * @file
- *
- * Support for IRC nickmasks
- */
-#include "error.h"
-#include <stddef.h>
-
-/**
- * Maximum length of an IRC nickname including terminating NUL
- */
-#define IRC_NICK_MAX 31
-
-/**
- * Parsed nickmask
- */
-struct irc_nm {
- /** Nickname, not normalized */
- const char *nickname;
-
- /** Username, including any ident-related prefix from the network */
- const char *username;
-
- /** Hostname, either reverse DNS hostname, literal IPv4 or literal IPv6 */
- const char *hostname;
-};
-
-/**
- * Parse a full nickmask from a prefix. This fails if the prefix is a server name.
- *
- * XXX: not implemented, and memory-management issues
- */
-err_t irc_nm_parse (struct irc_nm *nm, char *prefix);
-
-/**
- * Compare two nicknames for equality, with standard strcmp() semantics.
- */
-int irc_cmp_nick (const char *nick1, const char *nick2);
-
-/**
- * Compare up to the first n chars of the two nickname strings for equality, with standard strcmp() semantics.
- */
-int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n);
-
-/**
- * Parse the nickname portion of a prefix, storing it in the given buffer of IRC_NICK_MAX bytes.
- */
-err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]);
-
-/**
- * Compare the nickname in the given prefix and with the given nickname for equality.
- *
- * @return -err for invalid prefix, 0 for match, >0 for non-match.
- */
-int irc_prefix_cmp_nick (const char *prefix, const char *nick);
-
-#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/irc_proto.c Thu Mar 12 18:48:42 2009 +0200
@@ -0,0 +1,58 @@
+#include "irc_proto.h"
+
+#include <string.h>
+
+/**
+ * Compare two nicknames
+ */
+int irc_cmp_nick (const char *nick1, const char *nick2)
+{
+ // XXX: just use strcasecmp for now
+ return strcasecmp(nick1, nick2);
+}
+
+int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n)
+{
+ // XXX: just use strncasecmp for now
+ return strncasecmp(nick1, nick2, n);
+}
+
+err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX])
+{
+ const char *bang;
+
+ // find the !
+ if ((bang = strchr(prefix, '!')) == NULL)
+ return ERR_INVALID_NM;
+
+ // too long?
+ if (bang - prefix > IRC_NICK_MAX - 1)
+ return ERR_INVALID_NICK_LENGTH;
+
+ // copy up to the !
+ memcpy(nick, prefix, bang - prefix);
+
+ // terminating NUL
+ nick[bang - prefix] = '\0';
+
+ // ok
+ return SUCCESS;
+}
+
+int irc_prefix_cmp_nick (const char *prefix, const char *nick)
+{
+ const char *bang;
+
+ // find the !
+ if ((bang = strchr(prefix, '!')) == NULL)
+ return -ERR_INVALID_NM;
+
+ // compare up to that
+ if (irc_ncmp_nick(prefix, nick, (bang - prefix)) == 0)
+ // match
+ return 0;
+
+ else
+ // doesn't match
+ return 1;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/irc_proto.h Thu Mar 12 18:48:42 2009 +0200
@@ -0,0 +1,72 @@
+#ifndef IRC_PROTO_H
+#define IRC_PROTO_H
+
+/**
+ * @file
+ *
+ * General IRC protocol things, such as prefix/nickmask/nickname parsing
+ */
+#include "error.h"
+#include <stddef.h>
+
+/**
+ * Maximum length of an IRC nickname including terminating NUL
+ */
+#define IRC_NICK_MAX 31
+
+/**
+ * Parsed nickmask
+ */
+struct irc_nm {
+ /** Nickname, not normalized */
+ const char *nickname;
+
+ /** Username, including any ident-related prefix from the network */
+ const char *username;
+
+ /** Hostname, either reverse DNS hostname, literal IPv4 or literal IPv6 */
+ const char *hostname;
+};
+
+/**
+ * Parse a full nickmask from a prefix. This fails if the prefix is a server name.
+ *
+ * XXX: not implemented, and memory-management issues
+ */
+err_t irc_nm_parse (struct irc_nm *nm, char *prefix);
+
+/**
+ * Compare two nicknames for equality, with standard strcmp() semantics.
+ */
+int irc_cmp_nick (const char *nick1, const char *nick2);
+
+/**
+ * Compare up to the first n chars of the two nickname strings for equality, with standard strcmp() semantics.
+ */
+int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n);
+
+/**
+ * Parse the nickname portion of a prefix, storing it in the given buffer of IRC_NICK_MAX bytes.
+ */
+err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]);
+
+/**
+ * Compare the nickname in the given prefix and with the given nickname for equality.
+ *
+ * @return -err for invalid prefix, 0 for match, >0 for non-match.
+ */
+int irc_prefix_cmp_nick (const char *prefix, const char *nick);
+
+/**
+ * @group IRC command numerics
+ * @{
+ */
+
+/**
+ * 001 <nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>
+ */
+#define IRC_RPL_WELCOME "001"
+
+// @}
+
+#endif