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