2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2012 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);
55 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
56 Client_ID(Client), Req->command);
58 prefix = Client_Search(Req->prefix);
60 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
61 Client_ID(Client), Req->prefix);
63 target = Client_Search(Req->argv[0]);
65 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
66 Client_ID(Client), Req->argv[0]);
68 LogDebug("Got \"METADATA\" command from \"%s\" for client \"%s\": \"%s=%s\".",
69 Client_ID(Client), Client_ID(target),
70 Req->argv[1], Req->argv[2]);
72 /* Mark client: it has receiveda a METADATA command */
73 if (!strchr(Client_Flags(target), 'M')) {
74 snprintf(new_flags, sizeof new_flags, "%sM",
75 Client_Flags(target));
76 Client_SetFlags(target, new_flags);
79 if (*Req->argv[2] && strcasecmp(Req->argv[1], "host") == 0)
80 Client_SetHostname(target, Req->argv[2]);
81 else if (strcasecmp(Req->argv[1], "info") == 0)
82 Client_SetInfo(target, Req->argv[2]);
83 else if (*Req->argv[2] && strcasecmp(Req->argv[1], "user") == 0)
84 Client_SetUser(target, Req->argv[2], true);
87 "Ignored metadata update from \"%s\" for client \"%s\": \"%s=%s\" - unknown key!",
88 Client_ID(Client), Client_ID(target),
89 Req->argv[1], Req->argv[2]);
91 IRC_WriteStrServersPrefixFlag(Client, prefix, 'M', "METADATA %s %s :%s",
92 Client_ID(target), Req->argv[1], Req->argv[2]);