~ubuntu-branches/debian/sid/ircd-hybrid/sid

« back to all changes in this revision

Viewing changes to src/watch.c

  • Committer: Package Import Robot
  • Author(s): Dominic Hargreaves
  • Date: 2015-04-19 15:53:09 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20150419155309-06y59x2at2ax5ou3
Tags: 1:8.2.7+dfsg.1-1
* Remove Suggests: hybserv since it doesn't really work with
  ircd-hybrid 8 and above
* New upstream release
  - update debian/copyright with minor changes
  - update config files from new reference.conf
  - fixes DoS from localhost clients (Closes: #782859)
  - supports SSL certficate chaining (Closes: #769741)
* Debconf configuration script no longer ignores the result of
  upgrade questions (Closes: #779082)
* Don't display upgrade warnings on new installs (Closes: #782883)
* Add NEWS item about updated configuration

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3
3
 *
4
4
 *  Copyright (c) 1997 Jukka Santala (Donwulff)
5
 
 *  Copyright (c) 2005-2014 ircd-hybrid development team
 
5
 *  Copyright (c) 2005-2015 ircd-hybrid development team
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License as published by
22
22
 
23
23
/*! \file watch.c
24
24
 * \brief File including functions for WATCH support
25
 
 * \version $Id: watch.c 4564 2014-08-24 10:24:47Z michael $
 
25
 * \version $Id: watch.c 5346 2015-01-11 12:41:14Z michael $
26
26
 */
27
27
 
28
28
#include "stdinc.h"
79
79
 * \param reply Numeric to send. Either RPL_LOGON or RPL_LOGOFF
80
80
 */
81
81
void
82
 
watch_check_hash(struct Client *client_p, const enum irc_numerics reply)
 
82
watch_check_hash(const struct Client *client_p, const enum irc_numerics reply)
83
83
{
84
 
  struct Watch *anptr = NULL;
85
 
  dlink_node *ptr = NULL;
 
84
  struct Watch *watch = NULL;
 
85
  dlink_node *node = NULL;
86
86
 
87
87
  assert(IsClient(client_p));
88
88
 
89
 
  if ((anptr = watch_find_hash(client_p->name)) == NULL)
 
89
  if ((watch = watch_find_hash(client_p->name)) == NULL)
90
90
    return;  /* This nick isn't on watch */
91
91
 
92
92
  /* Update the time of last change to item */
93
 
  anptr->lasttime = CurrentTime;
 
93
  watch->lasttime = CurrentTime;
94
94
 
95
95
  /* Send notifies out to everybody on the list in header */
96
 
  DLINK_FOREACH(ptr, anptr->watched_by.head)
97
 
    sendto_one_numeric(ptr->data, &me, reply, client_p->name,
 
96
  DLINK_FOREACH(node, watch->watched_by.head)
 
97
    sendto_one_numeric(node->data, &me, reply, client_p->name,
98
98
                       client_p->username, client_p->host,
99
 
                       anptr->lasttime, client_p->info);
 
99
                       watch->lasttime, client_p->info);
100
100
}
101
101
 
102
102
/*! \brief Looks up the watch table for a given nick
105
105
struct Watch *
106
106
watch_find_hash(const char *name)
107
107
{
108
 
  dlink_node *ptr = NULL;
 
108
  dlink_node *node = NULL;
109
109
 
110
 
  DLINK_FOREACH(ptr, watchTable[strhash(name)].head)
 
110
  DLINK_FOREACH(node, watchTable[strhash(name)].head)
111
111
  {
112
 
    struct Watch *anptr = ptr->data;
 
112
    struct Watch *watch = node->data;
113
113
 
114
 
    if (!irccmp(anptr->nick, name))
115
 
      return anptr;
 
114
    if (!irccmp(watch->nick, name))
 
115
      return watch;
116
116
  }
117
117
 
118
118
  return NULL;
125
125
void
126
126
watch_add_to_hash_table(const char *nick, struct Client *client_p)
127
127
{
128
 
  struct Watch *anptr = NULL;
129
 
  dlink_node *ptr = NULL;
 
128
  struct Watch *watch = NULL;
 
129
  dlink_node *node = NULL;
130
130
 
131
131
  /* If found NULL (no header for this nick), make one... */
132
 
  if ((anptr = watch_find_hash(nick)) == NULL)
 
132
  if ((watch = watch_find_hash(nick)) == NULL)
133
133
  {
134
 
    anptr = mp_pool_get(watch_pool);
135
 
 
136
 
    anptr->lasttime = CurrentTime;
137
 
    strlcpy(anptr->nick, nick, sizeof(anptr->nick));
138
 
 
139
 
    dlinkAdd(anptr, &anptr->node, &watchTable[strhash(anptr->nick)]);
 
134
    watch = mp_pool_get(watch_pool);
 
135
 
 
136
    watch->lasttime = CurrentTime;
 
137
    strlcpy(watch->nick, nick, sizeof(watch->nick));
 
138
 
 
139
    dlinkAdd(watch, &watch->node, &watchTable[strhash(watch->nick)]);
140
140
  }
141
141
  else
142
142
  {
143
143
    /* Is this client already on the watch-list? */
144
 
    ptr = dlinkFind(&anptr->watched_by, client_p);
 
144
    node = dlinkFind(&watch->watched_by, client_p);
145
145
  }
146
146
 
147
 
  if (ptr == NULL)
 
147
  if (node == NULL)
148
148
  {
149
 
    /* No it isn't, so add it in the bucket and client addint it */
150
 
    dlinkAdd(client_p, make_dlink_node(), &anptr->watched_by);
151
 
    dlinkAdd(anptr, make_dlink_node(), &client_p->localClient->watches);
 
149
    /* No it isn't, so add it in the bucket and client adding it */
 
150
    dlinkAdd(client_p, make_dlink_node(), &watch->watched_by);
 
151
    dlinkAdd(watch, make_dlink_node(), &client_p->connection->watches);
152
152
  }
153
153
}
154
154
 
159
159
void
160
160
watch_del_from_hash_table(const char *nick, struct Client *client_p)
161
161
{
162
 
  struct Watch *anptr = NULL;
163
 
  dlink_node *ptr = NULL;
 
162
  struct Watch *watch = NULL;
 
163
  dlink_node *node = NULL;
164
164
 
165
 
  if ((anptr = watch_find_hash(nick)) == NULL)
 
165
  if ((watch = watch_find_hash(nick)) == NULL)
166
166
    return;  /* No header found for that nick. i.e. it's not being watched */
167
167
 
168
 
  if ((ptr = dlinkFind(&anptr->watched_by, client_p)) == NULL)
 
168
  if ((node = dlinkFind(&watch->watched_by, client_p)) == NULL)
169
169
    return;  /* This nick isn't being watched by client_p */
170
170
 
171
 
  dlinkDelete(ptr, &anptr->watched_by);
172
 
  free_dlink_node(ptr);
 
171
  dlinkDelete(node, &watch->watched_by);
 
172
  free_dlink_node(node);
173
173
 
174
 
  if ((ptr = dlinkFindDelete(&client_p->localClient->watches, anptr)))
175
 
    free_dlink_node(ptr);
 
174
  if ((node = dlinkFindDelete(&client_p->connection->watches, watch)))
 
175
    free_dlink_node(node);
176
176
 
177
177
  /* In case this header is now empty of notices, remove it */
178
 
  if (anptr->watched_by.head == NULL)
 
178
  if (watch->watched_by.head == NULL)
179
179
  {
180
 
    assert(dlinkFind(&watchTable[strhash(anptr->nick)], anptr));
181
 
    dlinkDelete(&anptr->node, &watchTable[strhash(anptr->nick)]);
182
 
    mp_pool_release(anptr);
 
180
    assert(dlinkFind(&watchTable[strhash(watch->nick)], watch));
 
181
    dlinkDelete(&watch->node, &watchTable[strhash(watch->nick)]);
 
182
    mp_pool_release(watch);
183
183
  }
184
184
}
185
185
 
190
190
void
191
191
watch_del_watch_list(struct Client *client_p)
192
192
{
193
 
  dlink_node *ptr = NULL, *ptr_next = NULL;
194
 
  dlink_node *tmp = NULL;
 
193
  dlink_node *node = NULL, *node_next = NULL;
 
194
  dlink_node *temp = NULL;
195
195
 
196
 
  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->watches.head)
 
196
  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->watches.head)
197
197
  {
198
 
    struct Watch *anptr = ptr->data;
199
 
 
200
 
    assert(dlinkFind(&anptr->watched_by, client_p));
201
 
 
202
 
    if ((tmp = dlinkFindDelete(&anptr->watched_by, client_p)))
203
 
      free_dlink_node(tmp);
 
198
    struct Watch *watch = node->data;
 
199
 
 
200
    assert(dlinkFind(&watch->watched_by, client_p));
 
201
 
 
202
    if ((temp = dlinkFindDelete(&watch->watched_by, client_p)))
 
203
      free_dlink_node(temp);
204
204
 
205
205
    /* If this leaves a header without notifies, remove it. */
206
 
    if (anptr->watched_by.head == NULL)
 
206
    if (watch->watched_by.head == NULL)
207
207
    {
208
 
      assert(dlinkFind(&watchTable[strhash(anptr->nick)], anptr));
209
 
      dlinkDelete(&anptr->node, &watchTable[strhash(anptr->nick)]);
 
208
      assert(dlinkFind(&watchTable[strhash(watch->nick)], watch));
 
209
      dlinkDelete(&watch->node, &watchTable[strhash(watch->nick)]);
210
210
 
211
 
      mp_pool_release(anptr);
 
211
      mp_pool_release(watch);
212
212
    }
213
213
 
214
 
    dlinkDelete(ptr, &client_p->localClient->watches);
215
 
    free_dlink_node(ptr);
 
214
    dlinkDelete(node, &client_p->connection->watches);
 
215
    free_dlink_node(node);
216
216
  }
217
217
 
218
 
  assert(client_p->localClient->watches.head == NULL);
219
 
  assert(client_p->localClient->watches.tail == NULL);
 
218
  assert(client_p->connection->watches.head == NULL);
 
219
  assert(client_p->connection->watches.tail == NULL);
220
220
}