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)
34 while (*mask != '\0') {
36 if (*wildcards) return TRUE;
40 if (*mask == '?' || *mask == '*') {
50 static int check_mask(SERVER_REC *server, const char *mask,
51 const char *str, int wildcards)
53 if (server != NULL && server->mask_match_func != NULL) {
54 /* use server specified mask match function */
55 return server->mask_match_func(mask, str);
58 return wildcards ? match_wildcards(mask, str) :
59 g_strcasecmp(mask, str) == 0;
62 int mask_match(SERVER_REC *server, const char *mask,
63 const char *nick, const char *user, const char *host)
68 g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE);
69 g_return_val_if_fail(mask != NULL && nick != NULL &&
70 nick != NULL && host != NULL, FALSE);
72 str = !check_address(mask, &wildcards) ? (char *) nick :
73 g_strdup_printf("%s!%s@%s", nick, user, host);
74 ret = check_mask(server, mask, str, wildcards);
75 if (str != nick) g_free(str);
80 int mask_match_address(SERVER_REC *server, const char *mask,
81 const char *nick, const char *address)
86 g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE);
87 g_return_val_if_fail(mask != NULL && nick != NULL, FALSE);
88 if (address == NULL) address = "";
90 str = !check_address(mask, &wildcards) ? (char *) nick :
91 g_strdup_printf("%s!%s", nick, address);
92 ret = check_mask(server, mask, str, wildcards);
93 if (str != nick) g_free(str);
98 int masks_match(SERVER_REC *server, const char *masks,
99 const char *nick, const char *address)
101 int (*mask_match_func)(const char *, const char *);
102 char **list, **tmp, *mask;
105 g_return_val_if_fail(server == NULL || IS_SERVER(server), FALSE);
106 g_return_val_if_fail(masks != NULL &&
107 nick != NULL && address != NULL, FALSE);
112 mask_match_func = server != NULL && server->mask_match_func != NULL ?
113 server->mask_match_func : match_wildcards;
116 mask = g_strdup_printf("%s!%s", nick, address);
117 list = g_strsplit(masks, " ", -1);
118 for (tmp = list; *tmp != NULL; tmp++) {
119 if (g_strcasecmp(*tmp, nick) == 0) {
124 if (mask_match_func(*tmp, mask)) {