4 Copyright (C) 1999-2000 Timo Sirainen
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 /* Returns TRUE if mask contains '!' ie. address should be checked too.
28 Also checks if mask contained any wildcards. */
29 static int check_address(const char *mask, int *wildcards)
35 while (*mask != '\0') {
37 if (*wildcards) return TRUE;
41 if (*mask == '?' || *mask == '*') {
51 static int check_mask(SERVER_REC *server, const char *mask,
52 const char *str, int wildcards)
54 if (server != NULL && server->mask_match_func != NULL) {
55 /* use server specified mask match function */
56 return server->mask_match_func(mask, str);
59 return wildcards ? match_wildcards(mask, str) :
60 g_strcasecmp(mask, str) == 0;
63 int mask_match(SERVER_REC *server, const char *mask,
64 const char *nick, const char *user, const char *host)
69 g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE);
70 g_return_val_if_fail(mask != NULL && nick != NULL &&
71 nick != NULL && host != NULL, FALSE);
73 str = !check_address(mask, &wildcards) ? (char *) nick :
74 g_strdup_printf("%s!%s@%s", nick, user, host);
75 ret = check_mask(server, mask, str, wildcards);
76 if (str != nick) g_free(str);
81 int mask_match_address(SERVER_REC *server, const char *mask,
82 const char *nick, const char *address)
87 g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE);
88 g_return_val_if_fail(mask != NULL && nick != NULL, FALSE);
89 if (address == NULL) address = "";
91 str = !check_address(mask, &wildcards) ? (char *) nick :
92 g_strdup_printf("%s!%s", nick, address);
93 ret = check_mask(server, mask, str, wildcards);
94 if (str != nick) g_free(str);
99 int masks_match(SERVER_REC *server, const char *masks,
100 const char *nick, const char *address)
102 int (*mask_match_func)(const char *, const char *);
103 char **list, **tmp, *mask;
106 g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE);
107 g_return_val_if_fail(masks != NULL &&
108 nick != NULL && address != NULL, FALSE);
113 mask_match_func = server != NULL && server->mask_match_func != NULL ?
114 server->mask_match_func : match_wildcards;
117 mask = g_strdup_printf("%s!%s", nick, address);
118 list = g_strsplit(masks, " ", -1);
119 for (tmp = list; *tmp != NULL; tmp++) {
120 if (g_strcasecmp(*tmp, nick) == 0) {
125 if (mask_match_func(*tmp, mask)) {