]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/wildcard.cpp
Added getrlimit/setrlimit to set process limits to allow a core dump
[user/henk/code/inspircd.git] / src / wildcard.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <string>
18 #include "inspircd_config.h"
19 #include "inspircd.h"
20 #include "inspstring.h"
21
22 void Delete(char* str,int pos)
23 {
24         char moo[MAXBUF];
25         strlcpy(moo,str,MAXBUF);
26         moo[pos] = '\0';
27         strlcpy(str,moo,MAXBUF);
28         strlcat(str,moo+pos+1,MAXBUF);
29 }
30
31 void Insert(char* substr,char* str,int pos)
32 {
33         std::string a = str;
34         a.insert(pos,substr);
35         strlcpy(str,a.c_str(),MAXBUF);
36 }
37
38
39 int MWC = 0;
40
41 bool match2(char* literal,char* mask)
42 {
43
44 char OldM[MAXBUF];
45 int I,I2;
46
47 if (MWC)
48         return true;
49
50 if ((strstr(mask,"*")==0) && (strlen(literal) != strlen(mask)))
51         return 0;
52  I=0;
53  I2=0;
54  while (I < strlen(mask))
55  {
56    if (I2 >= strlen(literal))
57            return 0;
58  
59    if ((mask[I]=='*') && (MWC==0))
60    {
61      strlcpy(OldM,mask,MAXBUF);
62      
63      Delete(mask,I);
64      
65      while (strlen(mask)<255)
66      {
67        match2(literal,mask);
68        if (MWC==2)
69                return 1;
70
71        Insert("?",mask,I);
72      }
73      strlcpy(mask,OldM,MAXBUF);
74      Delete(mask,I);
75      Insert("?",mask,I);
76    }
77    if (mask[I]=='?')
78    {
79      I++;
80      I2++;
81      continue;
82    }
83    if (mask[I] != literal[I2])
84            return 0;
85    if (MWC)
86            return 1;
87    I++;
88    I2++;
89  }
90  if (strlen(literal)==strlen(mask))
91                  MWC=2;
92
93 }
94
95 bool match(const char* literal, const char* mask)
96 {
97         char L[10240];
98         char M[10240];
99         MWC = 0;
100         strlcpy(L,literal,10240);
101         strlcpy(M,mask,10240);
102         strlower(L);
103         strlower(M);
104         // short circuit literals
105         log(DEBUG,"Match '%s' to '%s'",L,M);
106         if ((!strchr(M,'*')) && (!strchr(M,'?')))
107         {
108                 if (!strcasecmp(L,M))
109                 {
110                         return true;
111                 }
112         }
113         match2(L,M);
114         return (MWC == 2);
115 }
116