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
26 #include "conn-func.h"
28 #include "conn-encoding.h"
29 #include "irc-write.h"
36 #include "irc-metadata.h"
39 * Handler for the IRC+ "METADATA" command.
41 * @param Client The client from which this command has been received.
42 * @param Req Request structure with prefix and all parameters.
43 * @returns CONNECTED or DISCONNECTED.
46 IRC_METADATA(CLIENT *Client, REQUEST *Req)
48 CLIENT *prefix, *target;
49 char new_flags[COMMAND_LEN];
51 assert(Client != NULL);
54 prefix = Client_Search(Req->prefix);
56 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
57 Client_ID(Client), Req->prefix);
59 target = Client_Search(Req->argv[0]);
61 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
62 Client_ID(Client), Req->argv[0]);
64 LogDebug("Got \"METADATA\" command from \"%s\" for client \"%s\": \"%s=%s\".",
65 Client_ID(prefix), Client_ID(target),
66 Req->argv[1], Req->argv[2]);
68 /* Mark client: it has received a METADATA command */
69 if (!Client_HasFlag(target, 'M')) {
70 snprintf(new_flags, sizeof new_flags, "%sM",
71 Client_Flags(target));
72 Client_SetFlags(target, new_flags);
75 if (strcasecmp(Req->argv[1], "cloakhost") == 0) {
76 Client_UpdateCloakedHostname(target, prefix, Req->argv[2]);
77 if (Client_Conn(target) > NONE && Client_HasMode(target, 'x'))
78 IRC_WriteStrClientPrefix(target, prefix,
79 RPL_HOSTHIDDEN_MSG, Client_ID(target),
80 Client_HostnameDisplayed(target));
81 /* The Client_UpdateCloakedHostname() function already
82 * forwarded the METADATA command, don't do it twice: */
85 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "host") == 0) {
86 Client_SetHostname(target, Req->argv[2]);
87 if (Client_Conn(target) > NONE && !Client_HasMode(target, 'x'))
88 IRC_WriteStrClientPrefix(target, prefix,
89 RPL_HOSTHIDDEN_MSG, Client_ID(target),
90 Client_HostnameDisplayed(target));
91 } else if (strcasecmp(Req->argv[1], "info") == 0)
92 Client_SetInfo(target, Req->argv[2]);
93 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "user") == 0)
94 Client_SetUser(target, Req->argv[2], true);
95 else if (strcasecmp(Req->argv[1], "accountname") == 0)
96 Client_SetAccountName(target, Req->argv[2]);
97 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "certfp") == 0)
98 Conn_SetCertFp(Client_Conn(target), Req->argv[2]);
101 "Ignored metadata update from \"%s\" for client \"%s\": \"%s=%s\" - unknown key!",
102 Client_ID(Client), Client_ID(target),
103 Req->argv[1], Req->argv[2]);
105 /* Forward the METADATA command to peers that support it: */
106 IRC_WriteStrServersPrefixFlag(Client, prefix, 'M', "METADATA %s %s :%s",
107 Client_ID(target), Req->argv[1], Req->argv[2]);