summaryrefslogtreecommitdiffstats
path: root/src/modules/mask/libkvimask.cpp
blob: 0e810c3469396a978ef971b1d92e21ed0595ab75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
//   File : libkvistr.cpp
//   Creation date : Thu Dec 27 2001 17:13:12 GMT by Szymon Stefanek
//
//   This str is part of the KVirc irc client distribution
//   Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//


#include "kvi_module.h"

#include "kvi_locale.h"
#include "kvi_string.h"
#include "kvi_ircmask.h"

	/*
		@doc: tqmask.match
		@type:
			function
		@title:
			$tqmask.match
		@short:
			Matches a tqmask agains a wildcarded one
		@syntax:
			<boolean> $tqmask.match(<wildcard_tqmask:string>,<fixed_tqmask:string>)
		@description:
			Returns 1 if the <wildcard_tqmask> matches <fixed_tqmask> and 0 otherwise.
			<wildcard_tqmask> can obviously contain wildcards ('*' and '?').
		@example:
			[example]
			[cmd]if[/cmd]($tqmask.match(*!*@*.linux.it,$0))
				[cmd]op[/cmd] [fnc]$tqmask.nick[/fnc]($0)
			[/example]
	*/

static bool tqmask_kvs_fnc_match(KviKvsModuleFunctionCall * c)
{ 

	TQString wildtqmask,fixedtqmask;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("wildcard tqmask",KVS_PT_STRING,0,wildtqmask)
		KVSM_PARAMETER("fixed tqmask",KVS_PT_STRING,0,fixedtqmask)
	KVSM_PARAMETERS_END(c)
	KviIrcMask mk1(wildtqmask);
	KviIrcMask mk2(fixedtqmask);
	c->returnValue()->setBoolean(mk1.matchesFixed(mk2.nick(),mk2.user(),mk2.host()));
	return true;
}

	/*
		@doc: tqmask.nick
		@type:
			function
		@title:
			$tqmask.nick
		@short:
			Returns the nick part of an IRC tqmask
		@syntax:
			<string> $tqmask.nick(<tqmask:string>)
		@description:
			Returns the nickname part of an IRC tqmask.
	*/

static bool tqmask_kvs_fnc_nick(KviKvsModuleFunctionCall * c)
{

	TQString tqmask;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("tqmask",KVS_PT_STRING,0,tqmask)
	KVSM_PARAMETERS_END(c)
	KviIrcMask mk(tqmask);
	c->returnValue()->setString(mk.nick());
	return true;
}

	/*
		@doc: tqmask.user
		@type:
			function
		@title:
			$tqmask.user
		@short:
			Returns the username part of an IRC tqmask
		@syntax:
			<string> $tqmask.user(<tqmask:string>)
		@description:
			Returns the username part of an IRC tqmask.
	*/

static bool tqmask_kvs_fnc_user(KviKvsModuleFunctionCall * c)
{

	TQString tqmask;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("tqmask",KVS_PT_STRING,0,tqmask)
	KVSM_PARAMETERS_END(c)
	KviIrcMask mk(tqmask);
	c->returnValue()->setString(mk.user());
	return true;
}


	/*
		@doc: tqmask.host
		@type:
			function
		@title:
			$tqmask.host
		@short:
			Returns the hostname part of an IRC tqmask
		@syntax:
			<string> $tqmask.host(<tqmask:string>)
		@description:
			Returns the hostname part of an IRC tqmask.
	*/

static bool tqmask_kvs_fnc_host(KviKvsModuleFunctionCall * c)
{
	TQString tqmask;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("tqmask",KVS_PT_STRING,0,tqmask)
	KVSM_PARAMETERS_END(c)
	KviIrcMask mk(tqmask);
	c->returnValue()->setString(mk.host());
	return true;
}


	/*
		@doc: tqmask.hasnumerichost
		@type:
			function
		@title:
			$tqmask.hasNumericHost
		@short:
			Checks if a host part of a tqmask is numeric
		@syntax:
			<boolean> $tqmask.hasNumericHost(<tqmask: string>)
		@description:
			Returns 1 if the hostname part of the tqmask is numeric (e.g : unresolved IPV4 or IPV6 address)
	*/


static bool tqmask_kvs_fnc_hasnumerichost(KviKvsModuleFunctionCall * c)
{
	TQString tqmask;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("tqmask",KVS_PT_STRING,0,tqmask)
	KVSM_PARAMETERS_END(c)
	KviIrcMask mk(tqmask);
	c->returnValue()->setBoolean(mk.hasNumericHost());
	return true;
}


/*********************************************************************/
//              Module stuff
/********************************************************************/



static bool tqmask_module_init(KviModule * m)
{
	KVSM_REGISTER_FUNCTION(m,"match",tqmask_kvs_fnc_match);
	KVSM_REGISTER_FUNCTION(m,"nick",tqmask_kvs_fnc_nick);
	KVSM_REGISTER_FUNCTION(m,"user",tqmask_kvs_fnc_user);
	KVSM_REGISTER_FUNCTION(m,"host",tqmask_kvs_fnc_host);
	KVSM_REGISTER_FUNCTION(m,"hasnumerichost",tqmask_kvs_fnc_hasnumerichost);

	return true;
}

static bool tqmask_module_cleanup(KviModule *m)
{
	return true;
}

KVIRC_MODULE(
	"File",                                                 // module name
	"1.0.0",                                                // module version
	"Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)",
	"Mask manipulation functions",
	tqmask_module_init,
	0,
	0,
	tqmask_module_cleanup
)