]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-encoding.c
Implement new IRC+ "CHARCONV" command
[ngircd-alex.git] / src / ngircd / irc-encoding.c
diff --git a/src/ngircd/irc-encoding.c b/src/ngircd/irc-encoding.c
new file mode 100644 (file)
index 0000000..b1d3a69
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * ngIRCd -- The Next Generation IRC Daemon
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * Please read the file COPYING, README and AUTHORS for more information.
+ */
+
+#include "portab.h"
+
+/**
+ * @file
+ * IRC encoding commands
+ */
+
+#include "imp.h"
+#include <assert.h>
+#include <string.h>
+
+#include "conn-func.h"
+#include "channel.h"
+#include "conn-encoding.h"
+#include "irc-write.h"
+#include "messages.h"
+#include "parse.h"
+#include "tool.h"
+
+#include "exp.h"
+#include "irc-encoding.h"
+
+#ifdef ICONV
+
+/**
+ * Handler for the IRC+ "CHARCONV" command.
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @returns CONNECTED or DISCONNECTED.
+ */
+GLOBAL bool
+IRC_CHARCONV(CLIENT *Client, REQUEST *Req)
+{
+       char encoding[20];
+
+       assert (Client != NULL);
+       assert (Req != NULL);
+
+       if (Req->argc != 1)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
+
+       strlcpy(encoding, Req->argv[0], sizeof(encoding));
+       ngt_UpperStr(encoding);
+
+       if (!Conn_SetEncoding(Client_Conn(Client), encoding))
+               return IRC_WriteStrClient(Client, ERR_IP_CHARCONV_MSG,
+                                         Client_ID(Client), encoding);
+
+       return IRC_WriteStrClient(Client, RPL_IP_CHARCONV_MSG,
+                                 Client_ID(Client), encoding);
+} /* IRC_CHARCONV */
+
+#endif
+
+/* -eof- */