[BACK]Return to irc-metadata.c CVS log [TXT][DIR] Up to [local] / ircnowd / src / ngircd

Annotation of ircnowd/src/ngircd/irc-metadata.c, Revision 1.1.1.1

1.1       tomglok     1: /*
                      2:  * ngIRCd -- The Next Generation IRC Daemon
                      3:  * Copyright (c)2001-2015 Alexander Barton (alex@barton.de) and Contributors.
                      4:  *
                      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.
                     10:  */
                     11:
                     12: #define __irc_metadata_c__
                     13:
                     14: #include "portab.h"
                     15:
                     16: /**
                     17:  * @file
                     18:  * IRC metadata commands
                     19:  */
                     20:
                     21: #include <assert.h>
                     22: #include <strings.h>
                     23: #include <stdio.h>
                     24:
                     25: #include "conn-func.h"
                     26: #include "channel.h"
                     27: #include "irc-macros.h"
                     28: #include "irc-write.h"
                     29: #include "log.h"
                     30: #include "messages.h"
                     31: #include "parse.h"
                     32:
                     33: #include "irc-metadata.h"
                     34:
                     35: /**
                     36:  * Handler for the IRC+ "METADATA" command.
                     37:  *
                     38:  * @param Client The client from which this command has been received.
                     39:  * @param Req Request structure with prefix and all parameters.
                     40:  * @returns CONNECTED or DISCONNECTED.
                     41:  */
                     42: GLOBAL bool
                     43: IRC_METADATA(CLIENT *Client, REQUEST *Req)
                     44: {
                     45:        CLIENT *prefix, *target;
                     46:        char new_flags[COMMAND_LEN];
                     47:
                     48:        assert(Client != NULL);
                     49:        assert(Req != NULL);
                     50:
                     51:        _IRC_REQUIRE_PREFIX_OR_RETURN_(Client, Req)
                     52:
                     53:        prefix = Client_Search(Req->prefix);
                     54:        if (!prefix)
                     55:                return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
                     56:                                          Client_ID(Client), Req->prefix);
                     57:
                     58:        target = Client_Search(Req->argv[0]);
                     59:        if (!target)
                     60:                return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
                     61:                                          Client_ID(Client), Req->argv[0]);
                     62:
                     63:        LogDebug("Got \"METADATA\" command from \"%s\" for client \"%s\": \"%s=%s\".",
                     64:                 Client_ID(prefix), Client_ID(target),
                     65:                 Req->argv[1], Req->argv[2]);
                     66:
                     67:        /* Mark client: it has received a METADATA command */
                     68:        if (!Client_HasFlag(target, 'M')) {
                     69:                snprintf(new_flags, sizeof new_flags, "%sM",
                     70:                         Client_Flags(target));
                     71:                Client_SetFlags(target, new_flags);
                     72:        }
                     73:
                     74:        if (strcasecmp(Req->argv[1], "cloakhost") == 0) {
                     75:                Client_UpdateCloakedHostname(target, prefix, Req->argv[2]);
                     76:                if (Client_Conn(target) > NONE && Client_HasMode(target, 'x'))
                     77:                        IRC_WriteStrClientPrefix(target, prefix,
                     78:                                        RPL_HOSTHIDDEN_MSG, Client_ID(target),
                     79:                                        Client_HostnameDisplayed(target));
                     80:                /* The Client_UpdateCloakedHostname() function already
                     81:                 * forwarded the METADATA command, don't do it twice: */
                     82:                return CONNECTED;
                     83:        }
                     84:        else if (*Req->argv[2] && strcasecmp(Req->argv[1], "host") == 0) {
                     85:                Client_SetHostname(target, Req->argv[2]);
                     86:                if (Client_Conn(target) > NONE && !Client_HasMode(target, 'x'))
                     87:                        IRC_WriteStrClientPrefix(target, prefix,
                     88:                                                 RPL_HOSTHIDDEN_MSG, Client_ID(target),
                     89:                                                 Client_HostnameDisplayed(target));
                     90:        } else if (strcasecmp(Req->argv[1], "info") == 0)
                     91:                Client_SetInfo(target, Req->argv[2]);
                     92:        else if (*Req->argv[2] && strcasecmp(Req->argv[1], "user") == 0)
                     93:                Client_SetUser(target, Req->argv[2], true);
                     94:        else if (strcasecmp(Req->argv[1], "accountname") == 0)
                     95:                Client_SetAccountName(target, Req->argv[2]);
                     96:        else if (*Req->argv[2] && strcasecmp(Req->argv[1], "certfp") == 0)
                     97:                Conn_SetCertFp(Client_Conn(target), Req->argv[2]);
                     98:        else
                     99:                Log(LOG_WARNING,
                    100:                    "Ignored metadata update from \"%s\" for client \"%s\": \"%s=%s\" - unknown key!",
                    101:                    Client_ID(Client), Client_ID(target),
                    102:                    Req->argv[1], Req->argv[2]);
                    103:
                    104:        /* Forward the METADATA command to peers that support it: */
                    105:        IRC_WriteStrServersPrefixFlag(Client, prefix, 'M', "METADATA %s %s :%s",
                    106:                                Client_ID(target), Req->argv[1], Req->argv[2]);
                    107:        return CONNECTED;
                    108: }

CVSweb