irc-metadata.c 3.3 KB

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