| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* resv.c: Functions to reserve(jupe) a nick/channel. |
| 4 |
* |
| 5 |
* Copyright (C) 2001-2002 Hybrid Development Team |
| 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 "ircd.h" |
| 28 |
#include "send.h" |
| 29 |
#include "client.h" |
| 30 |
#include "memory.h" |
| 31 |
#include "numeric.h" |
| 32 |
#include "resv.h" |
| 33 |
#include "hash.h" |
| 34 |
#include "irc_string.h" |
| 35 |
#include "ircd_defs.h" |
| 36 |
#include "conf.h" |
| 37 |
#include "conf_db.h" |
| 38 |
|
| 39 |
dlink_list resv_channel_list = { NULL, NULL, 0 }; |
| 40 |
|
| 41 |
|
| 42 |
/* create_channel_resv() |
| 43 |
* |
| 44 |
* inputs - name of channel to create resv for |
| 45 |
* - reason for resv |
| 46 |
* - flag, 1 for from ircd.conf 0 from elsehwere |
| 47 |
* output - pointer to struct ResvChannel |
| 48 |
* side effects - |
| 49 |
*/ |
| 50 |
struct MaskItem * |
| 51 |
create_channel_resv(char *name, char *reason, int in_conf) |
| 52 |
{ |
| 53 |
struct MaskItem *conf = NULL; |
| 54 |
|
| 55 |
if (name == NULL || reason == NULL) |
| 56 |
return NULL; |
| 57 |
|
| 58 |
if (hash_find_resv(name)) |
| 59 |
return NULL; |
| 60 |
|
| 61 |
if (strlen(reason) > REASONLEN) |
| 62 |
reason[REASONLEN] = '\0'; |
| 63 |
|
| 64 |
conf = conf_make(CONF_CRESV); |
| 65 |
|
| 66 |
DupString(conf->name, name); |
| 67 |
DupString(conf->reason, reason); |
| 68 |
|
| 69 |
dlinkAdd(conf, &conf->node, &resv_channel_list); |
| 70 |
hash_add_resv(conf); |
| 71 |
|
| 72 |
return conf; |
| 73 |
} |
| 74 |
|
| 75 |
/* create_nick_resv() |
| 76 |
* |
| 77 |
* inputs - name of nick to create resv for |
| 78 |
* - reason for resv |
| 79 |
* - 1 if from ircd.conf, 0 if from elsewhere |
| 80 |
* output - pointer to struct ResvNick |
| 81 |
* side effects - |
| 82 |
*/ |
| 83 |
struct MaskItem * |
| 84 |
create_nick_resv(char *name, char *reason, int in_conf) |
| 85 |
{ |
| 86 |
struct MaskItem *conf = NULL; |
| 87 |
|
| 88 |
if (name == NULL || reason == NULL) |
| 89 |
return NULL; |
| 90 |
|
| 91 |
if (find_matching_name_conf(CONF_NRESV, name, NULL, NULL, 0)) |
| 92 |
return NULL; |
| 93 |
|
| 94 |
if (strlen(reason) > REASONLEN) |
| 95 |
reason[REASONLEN] = '\0'; |
| 96 |
|
| 97 |
conf = conf_make(CONF_NRESV); |
| 98 |
|
| 99 |
DupString(conf->name, name); |
| 100 |
DupString(conf->reason, reason); |
| 101 |
|
| 102 |
return conf; |
| 103 |
} |
| 104 |
|
| 105 |
/* clear_conf_resv() |
| 106 |
* |
| 107 |
* inputs - none |
| 108 |
* output - none |
| 109 |
* side effects - All resvs are cleared out |
| 110 |
*/ |
| 111 |
void |
| 112 |
clear_conf_resv(void) |
| 113 |
{ |
| 114 |
dlink_node *ptr = NULL, *next_ptr = NULL; |
| 115 |
|
| 116 |
DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head) |
| 117 |
{ |
| 118 |
struct MaskItem *conf = ptr->data; |
| 119 |
|
| 120 |
if (!IsConfDatabase(conf)) |
| 121 |
delete_channel_resv(conf); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
/* delete_channel_resv() |
| 126 |
* |
| 127 |
* inputs - pointer to channel resv to delete |
| 128 |
* output - none |
| 129 |
* side effects - given struct ResvChannel * is removed |
| 130 |
*/ |
| 131 |
int |
| 132 |
delete_channel_resv(struct MaskItem *conf) |
| 133 |
{ |
| 134 |
hash_del_resv(conf); |
| 135 |
dlinkDelete(&conf->node, &resv_channel_list); |
| 136 |
conf_free(conf); |
| 137 |
|
| 138 |
return 1; |
| 139 |
} |
| 140 |
|
| 141 |
/* match_find_resv() |
| 142 |
* |
| 143 |
* inputs - pointer to name |
| 144 |
* output - pointer to a struct ResvChannel |
| 145 |
* side effects - Finds a reserved channel whose name matches 'name', |
| 146 |
* if can't find one returns NULL. |
| 147 |
*/ |
| 148 |
struct MaskItem * |
| 149 |
match_find_resv(const char *name) |
| 150 |
{ |
| 151 |
dlink_node *ptr = NULL; |
| 152 |
|
| 153 |
if (EmptyString(name)) |
| 154 |
return NULL; |
| 155 |
|
| 156 |
DLINK_FOREACH(ptr, resv_channel_list.head) |
| 157 |
{ |
| 158 |
struct MaskItem *conf = ptr->data; |
| 159 |
|
| 160 |
if (match_chan(name, conf->name)) |
| 161 |
return conf; |
| 162 |
} |
| 163 |
|
| 164 |
return NULL; |
| 165 |
} |
| 166 |
|
| 167 |
/* report_resv() |
| 168 |
* |
| 169 |
* inputs - pointer to client pointer to report to. |
| 170 |
* output - NONE |
| 171 |
* side effects - report all resvs to client. |
| 172 |
*/ |
| 173 |
void |
| 174 |
report_resv(struct Client *source_p) |
| 175 |
{ |
| 176 |
dlink_node *ptr = NULL; |
| 177 |
struct MaskItem *conf = NULL; |
| 178 |
|
| 179 |
DLINK_FOREACH(ptr, resv_channel_list.head) |
| 180 |
{ |
| 181 |
conf = ptr->data; |
| 182 |
sendto_one(source_p, form_str(RPL_STATSQLINE), |
| 183 |
me.name, source_p->name, |
| 184 |
conf->hold ? 'q' : 'Q', |
| 185 |
conf->name, conf->reason); |
| 186 |
} |
| 187 |
|
| 188 |
DLINK_FOREACH(ptr, nresv_items.head) |
| 189 |
{ |
| 190 |
conf = ptr->data;; |
| 191 |
sendto_one(source_p, form_str(RPL_STATSQLINE), |
| 192 |
me.name, source_p->name, |
| 193 |
conf->hold ? 'q' : 'Q', |
| 194 |
conf->name, conf->reason); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
/* valid_wild_card_simple() |
| 199 |
* |
| 200 |
* inputs - data to check for sufficient non-wildcard characters |
| 201 |
* outputs - 1 if valid, else 0 |
| 202 |
* side effects - none |
| 203 |
*/ |
| 204 |
int |
| 205 |
valid_wild_card_simple(const char *data) |
| 206 |
{ |
| 207 |
const unsigned char *p = (const unsigned char *)data; |
| 208 |
int nonwild = 0; |
| 209 |
|
| 210 |
while (*p != '\0') |
| 211 |
{ |
| 212 |
if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p))) |
| 213 |
if (++nonwild == ConfigFileEntry.min_nonwildcard_simple) |
| 214 |
return 1; |
| 215 |
if (*p != '\0') |
| 216 |
++p; |
| 217 |
} |
| 218 |
|
| 219 |
return 0; |
| 220 |
} |