2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
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.
12 #define __irc_metadata_c__
18 * IRC metadata commands
25 #include "conn-func.h"
27 #include "conn-encoding.h"
28 #include "irc-write.h"
34 #include "irc-metadata.h"
37 * Handler for the IRC+ "METADATA" command.
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.
44 IRC_METADATA(CLIENT *Client, REQUEST *Req)
46 CLIENT *prefix, *target;
47 char new_flags[COMMAND_LEN];
49 assert(Client != NULL);
52 prefix = Client_Search(Req->prefix);
54 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
55 Client_ID(Client), Req->prefix);
57 target = Client_Search(Req->argv[0]);
59 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
60 Client_ID(Client), Req->argv[0]);
62 LogDebug("Got \"METADATA\" command from \"%s\" for client \"%s\": \"%s=%s\".",
63 Client_ID(prefix), Client_ID(target),
64 Req->argv[1], Req->argv[2]);
66 /* Mark client: it has received a METADATA command */
67 if (!Client_HasFlag(target, 'M')) {
68 snprintf(new_flags, sizeof new_flags, "%sM",
69 Client_Flags(target));
70 Client_SetFlags(target, new_flags);
73 if (strcasecmp(Req->argv[1], "cloakhost") == 0) {
74 Client_UpdateCloakedHostname(target, prefix, Req->argv[2]);
75 if (Client_Conn(target) > NONE && Client_HasMode(target, 'x'))
76 IRC_WriteStrClientPrefix(target, prefix,
77 RPL_HOSTHIDDEN_MSG, Client_ID(target),
78 Client_HostnameDisplayed(target));
79 /* The Client_UpdateCloakedHostname() function already
80 * forwarded the METADATA command, don't do it twice: */
83 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "host") == 0) {
84 Client_SetHostname(target, Req->argv[2]);
85 if (Client_Conn(target) > NONE && !Client_HasMode(target, 'x'))
86 IRC_WriteStrClientPrefix(target, prefix,
87 RPL_HOSTHIDDEN_MSG, Client_ID(target),
88 Client_HostnameDisplayed(target));
89 } else if (strcasecmp(Req->argv[1], "info") == 0)
90 Client_SetInfo(target, Req->argv[2]);
91 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "user") == 0)
92 Client_SetUser(target, Req->argv[2], true);
93 else if (strcasecmp(Req->argv[1], "accountname") == 0)
94 Client_SetAccountName(target, Req->argv[2]);
95 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "certfp") == 0)
96 Conn_SetCertFp(Client_Conn(target), Req->argv[2]);
99 "Ignored metadata update from \"%s\" for client \"%s\": \"%s=%s\" - unknown key!",
100 Client_ID(Client), Client_ID(target),
101 Req->argv[1], Req->argv[2]);
103 /* Forward the METADATA command to peers that support it: */
104 IRC_WriteStrServersPrefixFlag(Client, prefix, 'M', "METADATA %s %s :%s",
105 Client_ID(target), Req->argv[1], Req->argv[2]);