| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_list.c: List channel given or all channels. |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "list.h" |
| 27 |
#include "channel.h" |
| 28 |
#include "channel_mode.h" |
| 29 |
#include "client.h" |
| 30 |
#include "hash.h" |
| 31 |
#include "irc_string.h" |
| 32 |
#include "ircd.h" |
| 33 |
#include "numeric.h" |
| 34 |
#include "conf.h" |
| 35 |
#include "s_serv.h" |
| 36 |
#include "send.h" |
| 37 |
#include "parse.h" |
| 38 |
#include "modules.h" |
| 39 |
#include "s_user.h" |
| 40 |
#include "memory.h" |
| 41 |
|
| 42 |
|
| 43 |
static void |
| 44 |
do_list(struct Client *source_p, int parc, char *parv[]) |
| 45 |
{ |
| 46 |
struct ListTask *lt; |
| 47 |
int no_masked_channels; |
| 48 |
|
| 49 |
if (source_p->localClient->list_task != NULL) |
| 50 |
{ |
| 51 |
free_list_task(source_p->localClient->list_task, source_p); |
| 52 |
sendto_one(source_p, RPL_LISTEND, me.name, source_p->name); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
lt = MyMalloc(sizeof(struct ListTask)); |
| 57 |
lt->users_max = UINT_MAX; |
| 58 |
lt->created_max = UINT_MAX; |
| 59 |
lt->topicts_max = UINT_MAX; |
| 60 |
source_p->localClient->list_task = lt; |
| 61 |
|
| 62 |
no_masked_channels = 1; |
| 63 |
|
| 64 |
if (parc > 1) |
| 65 |
{ |
| 66 |
char *opt, *save = NULL; |
| 67 |
dlink_list *list; |
| 68 |
int i, errors = 0; |
| 69 |
|
| 70 |
for (opt = strtoken(&save, parv[1], ","); opt != NULL; |
| 71 |
opt = strtoken(&save, NULL, ",")) |
| 72 |
switch (*opt) |
| 73 |
{ |
| 74 |
case '<': if ((i = atoi(opt + 1)) > 0) |
| 75 |
lt->users_max = (unsigned int) i - 1; |
| 76 |
else |
| 77 |
errors = 1; |
| 78 |
break; |
| 79 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
| 80 |
lt->users_min = (unsigned int) i + 1; |
| 81 |
else |
| 82 |
errors = 1; |
| 83 |
break; |
| 84 |
case '-': break; |
| 85 |
case 'C': |
| 86 |
case 'c': switch (*++opt) |
| 87 |
{ |
| 88 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
| 89 |
lt->created_max = (unsigned int) (CurrentTime |
| 90 |
- 60 * i); |
| 91 |
else |
| 92 |
errors = 1; |
| 93 |
break; |
| 94 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
| 95 |
lt->created_min = (unsigned int) (CurrentTime |
| 96 |
- 60 * i); |
| 97 |
else |
| 98 |
errors = 1; |
| 99 |
break; |
| 100 |
default: errors = 1; |
| 101 |
} |
| 102 |
break; |
| 103 |
case 'T': |
| 104 |
case 't': switch (*++opt) |
| 105 |
{ |
| 106 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
| 107 |
lt->topicts_min = (unsigned int) (CurrentTime |
| 108 |
- 60 * i); |
| 109 |
else |
| 110 |
errors = 1; |
| 111 |
break; |
| 112 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
| 113 |
lt->topicts_max = (unsigned int) (CurrentTime |
| 114 |
- 60 * i); |
| 115 |
else |
| 116 |
errors = 1; |
| 117 |
break; |
| 118 |
default: errors = 1; |
| 119 |
} |
| 120 |
break; |
| 121 |
default: if (*opt == '!') |
| 122 |
{ |
| 123 |
list = <->hide_mask; |
| 124 |
opt++; |
| 125 |
} |
| 126 |
else list = <->show_mask; |
| 127 |
|
| 128 |
if (has_wildcards(opt + !!IsChanPrefix(*opt))) |
| 129 |
{ |
| 130 |
if (list == <->show_mask) |
| 131 |
no_masked_channels = 0; |
| 132 |
} |
| 133 |
else if (!IsChanPrefix(*opt)) |
| 134 |
errors = 1; |
| 135 |
if (!errors) |
| 136 |
{ |
| 137 |
char *s = xstrdup(opt); |
| 138 |
dlinkAdd(s, make_dlink_node(), list); |
| 139 |
} |
| 140 |
} |
| 141 |
if (errors) |
| 142 |
{ |
| 143 |
free_list_task(lt, source_p); |
| 144 |
sendto_one(source_p, ERR_LISTSYNTAX, |
| 145 |
me.name, source_p->name); |
| 146 |
return; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
dlinkAdd(source_p, make_dlink_node(), &listing_client_list); |
| 152 |
|
| 153 |
sendto_one(source_p, RPL_LISTSTART, |
| 154 |
me.name, source_p->name); |
| 155 |
safe_list_channels(source_p, lt, no_masked_channels && |
| 156 |
lt->show_mask.head != NULL); |
| 157 |
} |
| 158 |
|
| 159 |
/* |
| 160 |
** mo_list |
| 161 |
** parv[0] = sender prefix |
| 162 |
** parv[1] = channel |
| 163 |
*/ |
| 164 |
static void |
| 165 |
m_list(struct Client *client_p, struct Client *source_p, |
| 166 |
int parc, char *parv[]) |
| 167 |
{ |
| 168 |
do_list(source_p, parc, parv); |
| 169 |
} |
| 170 |
|
| 171 |
static struct Message list_msgtab = { |
| 172 |
"LIST", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 173 |
{ m_unregistered, m_list, m_ignore, m_ignore, m_list, m_ignore } |
| 174 |
}; |
| 175 |
|
| 176 |
static void |
| 177 |
module_init(void) |
| 178 |
{ |
| 179 |
mod_add_cmd(&list_msgtab); |
| 180 |
add_isupport("ELIST", "CMNTU", -1); |
| 181 |
add_isupport("SAFELIST", NULL, -1); |
| 182 |
} |
| 183 |
|
| 184 |
static void |
| 185 |
module_exit(void) |
| 186 |
{ |
| 187 |
mod_del_cmd(&list_msgtab); |
| 188 |
delete_isupport("ELIST"); |
| 189 |
delete_isupport("SAFELIST"); |
| 190 |
} |
| 191 |
|
| 192 |
struct module module_entry = { |
| 193 |
.node = { NULL, NULL, NULL }, |
| 194 |
.name = NULL, |
| 195 |
.version = "$Revision$", |
| 196 |
.handle = NULL, |
| 197 |
.modinit = module_init, |
| 198 |
.modexit = module_exit, |
| 199 |
.flags = 0 |
| 200 |
}; |