ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_tburst.c
Revision: 7329
Committed: Thu Feb 18 21:07:50 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 4659 byte(s)
Log Message:
- Now that we got time_t to work nicely on openbsd with snprintf's conversion specifiers,
  we ran into a similiar issue on Raspbian/ARMv7's time_t which is of signed 32 bit and
  doesn't cope at all with %j. Instead of doing tricks, get rid of time_t everywhere and
  forever and use uintmax_t instead which has at least a 'standardized' conversion specifier
  associated with it.

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2002-2016 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_tburst.c
23 * \brief Includes required functions for processing the TBURST command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "ircd.h"
30 #include "send.h"
31 #include "modules.h"
32 #include "hash.h"
33 #include "server.h"
34 #include "conf.h"
35 #include "parse.h"
36
37
38 /*! \brief TBURST command handler
39 *
40 * \param source_p Pointer to allocated Client struct from which the message
41 * originally comes from. This can be a local or remote client.
42 * \param parc Integer holding the number of supplied arguments.
43 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
44 * pointers.
45 * \note Valid arguments for this command are:
46 * - parv[0] = command
47 * - parv[1] = channel timestamp
48 * - parv[2] = channel name
49 * - parv[3] = topic timestamp
50 * - parv[4] = topic setter
51 * - parv[5] = topic (can be an empty string)
52 */
53 static int
54 ms_tburst(struct Client *source_p, int parc, char *parv[])
55 {
56 struct Channel *chptr = NULL;
57 int accept_remote = 0;
58 uintmax_t remote_channel_ts = strtoumax(parv[1], NULL, 10);
59 uintmax_t remote_topic_ts = strtoumax(parv[3], NULL, 10);
60 const char *topic = parv[5];
61 const char *setby = parv[4];
62
63 /*
64 * Do NOT test parv[5] for an empty string and return if true!
65 * parv[5] CAN be an empty string, i.e. if the other side wants
66 * to unset our topic. Don't forget: an empty topic is also a
67 * valid topic.
68 */
69
70
71 if ((chptr = hash_find_channel(parv[2])) == NULL)
72 return 0;
73
74 /*
75 * The logic for accepting and rejecting channel topics was
76 * always a bit hairy, so now we got exactly 3 cases where
77 * we would accept a topic
78 *
79 * Case 1:
80 * A services client/server wants to set a topic
81 * Case 2:
82 * The TS of the remote channel is older than ours
83 * Case 3:
84 * The TS of the remote channel is equal to ours AND
85 * the TS of the remote topic is newer than ours
86 */
87 if (HasFlag(source_p, FLAGS_SERVICE))
88 accept_remote = 1;
89 else if (remote_channel_ts < chptr->creationtime)
90 accept_remote = 1;
91 else if (remote_channel_ts == chptr->creationtime)
92 if (remote_topic_ts > chptr->topic_time)
93 accept_remote = 1;
94
95 if (accept_remote)
96 {
97 int topic_differs = strncmp(chptr->topic, topic, sizeof(chptr->topic) - 1);
98 int hidden_server = (ConfigServerHide.hide_servers || IsHidden(source_p));
99
100 channel_set_topic(chptr, topic, setby, remote_topic_ts, 0);
101
102 sendto_server(source_p, CAPAB_TBURST, 0, ":%s TBURST %s %s %s %s :%s",
103 source_p->id, parv[1], parv[2], parv[3], setby, topic);
104
105 if (topic_differs)
106 {
107 if (!IsClient(source_p))
108 sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s TOPIC %s :%s",
109 hidden_server ? me.name : source_p->name,
110 chptr->name, chptr->topic);
111 else
112 sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s",
113 source_p->name, source_p->username, source_p->host,
114 chptr->name, chptr->topic);
115 }
116 }
117
118 return 0;
119 }
120
121 static struct Message tburst_msgtab =
122 {
123 .cmd = "TBURST",
124 .args_min = 6,
125 .args_max = MAXPARA,
126 .handlers[UNREGISTERED_HANDLER] = m_ignore,
127 .handlers[CLIENT_HANDLER] = m_ignore,
128 .handlers[SERVER_HANDLER] = ms_tburst,
129 .handlers[ENCAP_HANDLER] = m_ignore,
130 .handlers[OPER_HANDLER] = m_ignore
131 };
132
133 static void
134 module_init(void)
135 {
136 mod_add_cmd(&tburst_msgtab);
137 add_capability("TBURST", CAPAB_TBURST);
138 }
139
140 static void
141 module_exit(void)
142 {
143 mod_del_cmd(&tburst_msgtab);
144 delete_capability("TBURST");
145 }
146
147 struct module module_entry =
148 {
149 .version = "$Revision$",
150 .modinit = module_init,
151 .modexit = module_exit,
152 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision