]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-encoding.c
Reorder checks
[ngircd-alex.git] / src / ngircd / irc-encoding.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  */
11
12 #include "portab.h"
13
14 /**
15  * @file
16  * IRC encoding commands
17  */
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <string.h>
22
23 #include "conn-func.h"
24 #include "channel.h"
25 #include "conn-encoding.h"
26 #include "irc-write.h"
27 #include "messages.h"
28 #include "parse.h"
29 #include "tool.h"
30
31 #include "exp.h"
32 #include "irc-encoding.h"
33
34 #ifdef ICONV
35
36 /**
37  * Handler for the IRC+ "CHARCONV" command.
38  *
39  * @param Client The client from which this command has been received.
40  * @param Req Request structure with prefix and all parameters.
41  * @returns CONNECTED or DISCONNECTED.
42  */
43 GLOBAL bool
44 IRC_CHARCONV(CLIENT *Client, REQUEST *Req)
45 {
46         char encoding[20];
47
48         assert (Client != NULL);
49         assert (Req != NULL);
50
51         if (Req->argc != 1)
52                 return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
53                                           Client_ID(Client), Req->command);
54
55         strlcpy(encoding, Req->argv[0], sizeof(encoding));
56         ngt_UpperStr(encoding);
57
58         if (!Conn_SetEncoding(Client_Conn(Client), encoding))
59                 return IRC_WriteErrClient(Client, ERR_IP_CHARCONV_MSG,
60                                           Client_ID(Client), encoding);
61
62         return IRC_WriteStrClient(Client, RPL_IP_CHARCONV_MSG,
63                                   Client_ID(Client), encoding);
64 } /* IRC_CHARCONV */
65
66 #endif
67
68 /* -eof- */