2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2014 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 "irc-write.h"
32 #include "irc-metadata.h"
35 * Handler for the IRC+ "METADATA" command.
37 * @param Client The client from which this command has been received.
38 * @param Req Request structure with prefix and all parameters.
39 * @returns CONNECTED or DISCONNECTED.
42 IRC_METADATA(CLIENT *Client, REQUEST *Req)
44 CLIENT *prefix, *target;
45 char new_flags[COMMAND_LEN];
47 assert(Client != NULL);
50 prefix = Client_Search(Req->prefix);
52 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
53 Client_ID(Client), Req->prefix);
55 target = Client_Search(Req->argv[0]);
57 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
58 Client_ID(Client), Req->argv[0]);
60 LogDebug("Got \"METADATA\" command from \"%s\" for client \"%s\": \"%s=%s\".",
61 Client_ID(prefix), Client_ID(target),
62 Req->argv[1], Req->argv[2]);
64 /* Mark client: it has received a METADATA command */
65 if (!Client_HasFlag(target, 'M')) {
66 snprintf(new_flags, sizeof new_flags, "%sM",
67 Client_Flags(target));
68 Client_SetFlags(target, new_flags);
71 if (strcasecmp(Req->argv[1], "cloakhost") == 0) {
72 Client_UpdateCloakedHostname(target, prefix, Req->argv[2]);
73 if (Client_Conn(target) > NONE && Client_HasMode(target, 'x'))
74 IRC_WriteStrClientPrefix(target, prefix,
75 RPL_HOSTHIDDEN_MSG, Client_ID(target),
76 Client_HostnameDisplayed(target));
77 /* The Client_UpdateCloakedHostname() function already
78 * forwarded the METADATA command, don't do it twice: */
81 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "host") == 0) {
82 Client_SetHostname(target, Req->argv[2]);
83 if (Client_Conn(target) > NONE && !Client_HasMode(target, 'x'))
84 IRC_WriteStrClientPrefix(target, prefix,
85 RPL_HOSTHIDDEN_MSG, Client_ID(target),
86 Client_HostnameDisplayed(target));
87 } else if (strcasecmp(Req->argv[1], "info") == 0)
88 Client_SetInfo(target, Req->argv[2]);
89 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "user") == 0)
90 Client_SetUser(target, Req->argv[2], true);
91 else if (strcasecmp(Req->argv[1], "accountname") == 0)
92 Client_SetAccountName(target, Req->argv[2]);
93 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "certfp") == 0)
94 Conn_SetCertFp(Client_Conn(target), Req->argv[2]);
97 "Ignored metadata update from \"%s\" for client \"%s\": \"%s=%s\" - unknown key!",
98 Client_ID(Client), Client_ID(target),
99 Req->argv[1], Req->argv[2]);
101 /* Forward the METADATA command to peers that support it: */
102 IRC_WriteStrServersPrefixFlag(Client, prefix, 'M', "METADATA %s %s :%s",
103 Client_ID(target), Req->argv[1], Req->argv[2]);