diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ngircd/defines.h | 2 | ||||
| -rw-r--r-- | src/ngircd/irc-metadata.c | 94 | ||||
| -rw-r--r-- | src/ngircd/irc-metadata.h | 24 | ||||
| -rw-r--r-- | src/ngircd/parse.c | 2 |
4 files changed, 121 insertions, 1 deletions
diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index 49abf579..b2de98d5 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -157,7 +157,7 @@ #ifdef IRCPLUS /** Standard IRC+ flags. */ -# define IRCPLUSFLAGS "CHLS" +# define IRCPLUSFLAGS "CHLMS" #endif /** Supported user modes. */ diff --git a/src/ngircd/irc-metadata.c b/src/ngircd/irc-metadata.c new file mode 100644 index 00000000..5cef8333 --- /dev/null +++ b/src/ngircd/irc-metadata.c @@ -0,0 +1,94 @@ +/* + * ngIRCd -- The Next Generation IRC Daemon + * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. + */ + +#define __irc_metadata_c__ + +#include "portab.h" + +/** + * @file + * IRC metadata commands + */ + +#include "imp.h" +#include <assert.h> +#include <string.h> +#include <stdio.h> + +#include "conn-func.h" +#include "channel.h" +#include "conn-encoding.h" +#include "irc-write.h" +#include "log.h" +#include "messages.h" +#include "parse.h" +#include "tool.h" + +#include "exp.h" +#include "irc-metadata.h" + +/** + * Handler for the IRC+ "METADATA" command. + * + * @param Client The client from which this command has been received. + * @param Req Request structure with prefix and all parameters. + * @returns CONNECTED or DISCONNECTED. + */ +GLOBAL bool +IRC_METADATA(CLIENT *Client, REQUEST *Req) +{ + CLIENT *prefix, *target; + char new_flags[COMMAND_LEN]; + + assert(Client != NULL); + assert(Req != NULL); + + if (Req->argc != 3) + return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, + Client_ID(Client), Req->command); + + prefix = Client_Search(Req->prefix); + if (!prefix) + return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, + Client_ID(Client), Req->prefix); + + target = Client_Search(Req->argv[0]); + if (!target) + return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, + Client_ID(Client), Req->argv[0]); + + LogDebug("Got \"METADATA\" command from \"%s\" for client \"%s\": \"%s=%s\".", + Client_ID(Client), Client_ID(target), + Req->argv[1], Req->argv[2]); + + /* Mark client: it has receiveda a METADATA command */ + if (!strchr(Client_Flags(target), 'M')) { + snprintf(new_flags, sizeof new_flags, "%sM", + Client_Flags(target)); + Client_SetFlags(target, new_flags); + } + + if (*Req->argv[2] && strcasecmp(Req->argv[1], "host") == 0) + Client_SetHostname(target, Req->argv[2]); + else if (strcasecmp(Req->argv[1], "info") == 0) + Client_SetInfo(target, Req->argv[2]); + else if (*Req->argv[2] && strcasecmp(Req->argv[1], "user") == 0) + Client_SetUser(target, Req->argv[2], true); + else + Log(LOG_WARNING, + "Ignored metadata update from \"%s\" for client \"%s\": \"%s=%s\" - unknown key!", + Client_ID(Client), Client_ID(target), + Req->argv[1], Req->argv[2]); + + IRC_WriteStrServersPrefixFlag(Client, prefix, 'M', "METADATA %s %s :%s", + Client_ID(target), Req->argv[1], Req->argv[2]); + return CONNECTED; +} diff --git a/src/ngircd/irc-metadata.h b/src/ngircd/irc-metadata.h new file mode 100644 index 00000000..3a2f0bbf --- /dev/null +++ b/src/ngircd/irc-metadata.h @@ -0,0 +1,24 @@ +/* + * ngIRCd -- The Next Generation IRC Daemon + * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. + */ + +#ifndef __irc_metadata_h__ +#define __irc_metadata_h__ + +/** + * @file + * IRC metadata commands (header) + */ + +GLOBAL bool IRC_METADATA PARAMS((CLIENT *Client, REQUEST *Req)); + +#endif + +/* -eof- */ diff --git a/src/ngircd/parse.c b/src/ngircd/parse.c index 446180b5..5ff9fcc2 100644 --- a/src/ngircd/parse.c +++ b/src/ngircd/parse.c @@ -41,6 +41,7 @@ #include "irc-encoding.h" #include "irc-info.h" #include "irc-login.h" +#include "irc-metadata.h" #include "irc-mode.h" #include "irc-op.h" #include "irc-oper.h" @@ -78,6 +79,7 @@ static COMMAND My_Commands[] = { "LINKS", IRC_LINKS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "LIST", IRC_LIST, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "LUSERS", IRC_LUSERS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, + { "METADATA", IRC_METADATA, CLIENT_SERVER, 0, 0, 0 }, { "MODE", IRC_MODE, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "MOTD", IRC_MOTD, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "NAMES", IRC_NAMES, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, |