]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
Stability fixes, some DELETEs here that dont belong any more.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "configreader.h"
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "commands/cmd_whois.h"
20 #include "commands/cmd_stats.h"
21 #include "socket.h"
22 #include "wildcard.h"
23 #include "xline.h"
24 #include "transport.h"
25 #include "socketengine.h"
26
27 #include "m_spanningtree/main.h"
28 #include "m_spanningtree/utils.h"
29 #include "m_spanningtree/treeserver.h"
30 #include "m_spanningtree/link.h"
31 #include "m_spanningtree/treesocket.h"
32 #include "m_spanningtree/resolvers.h"
33
34 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
35
36 /** Yay for fast searches!
37  * This is hundreds of times faster than recursion
38  * or even scanning a linked list, especially when
39  * there are more than a few servers to deal with.
40  * (read as: lots).
41  */
42 TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
43 {
44         server_hash::iterator iter = serverlist.find(ServerName.c_str());
45         if (iter != serverlist.end())
46         {
47                 return iter->second;
48         }
49         else
50         {
51                 return NULL;
52         }
53 }
54
55 TreeServer* SpanningTreeUtilities::FindRemoteBurstServer(TreeServer* Server)
56 {
57         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
58         if (iter != RemoteServersBursting.end())
59                 return iter->second;
60         else
61                 return NULL;
62 }
63
64 TreeSocket* SpanningTreeUtilities::FindBurstingServer(const std::string &ServerName)
65 {
66         std::map<irc::string,TreeSocket*>::iterator iter;
67         iter = burstingserverlist.find(ServerName.c_str());
68         if (iter != burstingserverlist.end())
69         {
70                 return iter->second;
71         }
72         else
73         {
74                 return NULL;
75         }
76 }
77
78 void SpanningTreeUtilities::SetRemoteBursting(TreeServer* Server, bool bursting)
79 {
80         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
81         if (bursting)
82         {
83                 if (iter == RemoteServersBursting.end())
84                         RemoteServersBursting.insert(make_pair(Server->GetName(), Server));
85                 else return;
86         }
87         else
88         {
89                 if (iter != RemoteServersBursting.end())
90                         RemoteServersBursting.erase(iter);
91                 else return;
92         }
93         ServerInstance->Log(DEBUG,"Server %s is %sbursting nicknames", Server->GetName().c_str(), bursting ? "" : "no longer ");
94 }
95
96 void SpanningTreeUtilities::AddBurstingServer(const std::string &ServerName, TreeSocket* s)
97 {
98         std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.find(ServerName.c_str());
99         if (iter == burstingserverlist.end())
100                 burstingserverlist[ServerName.c_str()] = s;
101 }
102
103 void SpanningTreeUtilities::DelBurstingServer(TreeSocket* s)
104 {
105          for (std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.begin(); iter != burstingserverlist.end(); iter++)
106          {
107                  if (iter->second == s)
108                  {
109                          burstingserverlist.erase(iter);
110                          return;
111                  }
112          }
113 }
114
115 /** Returns the locally connected server we must route a
116  * message through to reach server 'ServerName'. This
117  * only applies to one-to-one and not one-to-many routing.
118  * See the comments for the constructor of TreeServer
119  * for more details.
120  */
121 TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
122 {
123         if (ServerName.c_str() == TreeRoot->GetName())
124                 return NULL;
125         TreeServer* Found = FindServer(ServerName);
126         if (Found)
127         {
128                 return Found->GetRoute();
129         }
130         else
131         {
132                 return NULL;
133         }
134 }
135
136 /** Find the first server matching a given glob mask.
137  * Theres no find-using-glob method of hash_map [awwww :-(]
138  * so instead, we iterate over the list using an iterator
139  * and match each one until we get a hit. Yes its slow,
140  * deal with it.
141  */
142 TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
143 {
144         for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
145         {
146                 if (match(i->first.c_str(),ServerName.c_str()))
147                         return i->second;
148         }
149         return NULL;
150 }
151
152 /* A convenient wrapper that returns true if a server exists */
153 bool SpanningTreeUtilities::IsServer(const std::string &ServerName)
154 {
155         return (FindServer(ServerName) != NULL);
156 }
157
158 SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
159 {
160         Bindings.clear();
161
162         lines_to_apply = 0;
163
164         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
165
166         modulelist* ml = ServerInstance->FindInterface("InspSocketHook");
167
168         /* Did we find any modules? */
169         if (ml)
170         {
171                 /* Yes, enumerate them all to find out the hook name */
172                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
173                 {
174                         /* Make a request to it for its name, its implementing
175                          * InspSocketHook so we know its safe to do this
176                          */
177                         std::string name = InspSocketNameRequest((Module*)Creator, *m).Send();
178                         /* Build a map of them */
179                         hooks[name.c_str()] = *m;
180                         hooknames.push_back(name);
181                 }
182         }
183
184         this->ReadConfiguration(true);
185 }
186
187 SpanningTreeUtilities::~SpanningTreeUtilities()
188 {
189         for (unsigned int i = 0; i < Bindings.size(); i++)
190         {
191                 ServerInstance->SE->DelFd(Bindings[i]);
192                 Bindings[i]->Close();
193         }
194         while (TreeRoot->ChildCount())
195         {
196                 TreeServer* child_server = TreeRoot->GetChild(0);
197                 if (child_server)
198                 {
199                         TreeSocket* sock = child_server->GetSocket();
200                         ServerInstance->SE->DelFd(sock);
201                         sock->Close();
202                 }
203         }
204         delete TreeRoot;
205 }
206
207 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
208 {
209         if (list.find(server) == list.end())
210                 list[server] = server;
211 }
212
213 /* returns a list of DIRECT servernames for a specific channel */
214 void SpanningTreeUtilities::GetListOfServersForChannel(chanrec* c, TreeServerList &list, char status, const CUList &exempt_list)
215 {
216         CUList *ulist;
217         switch (status)
218         {
219                 case '@':
220                         ulist = c->GetOppedUsers();
221                 break;
222                 case '%':
223                         ulist = c->GetHalfoppedUsers();
224                 break;
225                 case '+':
226                         ulist = c->GetVoicedUsers();
227                 break;
228                 default:
229                         ulist = c->GetUsers();
230                 break;
231         }
232         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
233         {
234                 if ((i->first->GetFd() < 0) && (exempt_list.find(i->first) == exempt_list.end()))
235                 {
236                         TreeServer* best = this->BestRouteTo(i->first->server);
237                         if (best)
238                                 AddThisServer(best,list);
239                 }
240         }
241         return;
242 }
243
244 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params)
245 {
246         char pfx = 0;
247         TreeServer* omitroute = this->BestRouteTo(omit);
248         if ((command == "NOTICE") || (command == "PRIVMSG"))
249         {
250                 if (params.size() >= 2)
251                 {
252                         /* Prefixes */
253                         if ((*(params[0].c_str()) == '@') || (*(params[0].c_str()) == '%') || (*(params[0].c_str()) == '+'))
254                         {
255                                 pfx = params[0][0];
256                                 params[0] = params[0].substr(1, params[0].length()-1);
257                         }
258                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
259                         {
260                                 // special routing for private messages/notices
261                                 userrec* d = ServerInstance->FindNick(params[0]);
262                                 if (d)
263                                 {
264                                         std::deque<std::string> par;
265                                         par.push_back(params[0]);
266                                         par.push_back(":"+params[1]);
267                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
268                                         return true;
269                                 }
270                         }
271                         else if (*(params[0].c_str()) == '$')
272                         {
273                                 std::deque<std::string> par;
274                                 par.push_back(params[0]);
275                                 par.push_back(":"+params[1]);
276                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
277                                 return true;
278                         }
279                         else
280                         {
281                                 chanrec* c = ServerInstance->FindChan(params[0]);
282                                 userrec* u = ServerInstance->FindNick(prefix);
283                                 if (c && u)
284                                 {
285                                         CUList elist;
286                                         TreeServerList list;
287                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist));
288                                         GetListOfServersForChannel(c,list,pfx,elist);
289
290                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
291                                         {
292                                                 TreeSocket* Sock = i->second->GetSocket();
293                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
294                                                 {
295                                                         Sock->WriteLine(data);
296                                                 }
297                                         }
298                                         return true;
299                                 }
300                         }
301                 }
302         }
303         unsigned int items =this->TreeRoot->ChildCount();
304         for (unsigned int x = 0; x < items; x++)
305         {
306                 TreeServer* Route = this->TreeRoot->GetChild(x);
307                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
308                 {
309                         TreeSocket* Sock = Route->GetSocket();
310                         if (Sock)
311                                 Sock->WriteLine(data);
312                 }
313         }
314         return true;
315 }
316
317 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit)
318 {
319         TreeServer* omitroute = this->BestRouteTo(omit);
320         std::string FullLine = ":" + prefix + " " + command;
321         unsigned int words = params.size();
322         for (unsigned int x = 0; x < words; x++)
323         {
324                 FullLine = FullLine + " " + params[x];
325         }
326         unsigned int items = this->TreeRoot->ChildCount();
327         for (unsigned int x = 0; x < items; x++)
328         {
329                 TreeServer* Route = this->TreeRoot->GetChild(x);
330                 // Send the line IF:
331                 // The route has a socket (its a direct connection)
332                 // The route isnt the one to be omitted
333                 // The route isnt the path to the one to be omitted
334                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
335                 {
336                         TreeSocket* Sock = Route->GetSocket();
337                         if (Sock)
338                                 Sock->WriteLine(FullLine);
339                 }
340         }
341         return true;
342 }
343
344 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params)
345 {
346         std::string FullLine = ":" + prefix + " " + command;
347         unsigned int words = params.size();
348         for (unsigned int x = 0; x < words; x++)
349         {
350                 FullLine = FullLine + " " + params[x];
351         }
352         unsigned int items = this->TreeRoot->ChildCount();
353         for (unsigned int x = 0; x < items; x++)
354         {
355                 TreeServer* Route = this->TreeRoot->GetChild(x);
356                 if (Route && Route->GetSocket())
357                 {
358                         TreeSocket* Sock = Route->GetSocket();
359                         if (Sock)
360                                 Sock->WriteLine(FullLine);
361                 }
362         }
363         return true;
364 }
365
366 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params)
367 {
368         std::string spfx = prefix;
369         std::string scmd = command;
370         return this->DoOneToMany(spfx, scmd, params);
371 }
372
373 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit)
374 {
375         std::string spfx = prefix;
376         std::string scmd = command;
377         return this->DoOneToAllButSender(spfx, scmd, params, omit);
378 }
379
380 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target)
381 {
382         TreeServer* Route = this->BestRouteTo(target);
383         if (Route)
384         {
385                 std::string FullLine = ":" + prefix + " " + command;
386                 unsigned int words = params.size();
387                 for (unsigned int x = 0; x < words; x++)
388                 {
389                         FullLine = FullLine + " " + params[x];
390                 }
391                 if (Route && Route->GetSocket())
392                 {
393                         TreeSocket* Sock = Route->GetSocket();
394                         if (Sock)
395                                 Sock->WriteLine(FullLine);
396                 }
397                 return true;
398         }
399         else
400         {
401                 return false;
402         }
403 }
404
405 void SpanningTreeUtilities::RefreshIPCache()
406 {
407         ValidIPs.clear();
408         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
409         {
410                 if ((!L->IPAddr.empty()) && (!L->RecvPass.empty()) && (!L->SendPass.empty()) && (!L->Name.empty()) && (L->Port))
411                 {
412                         ValidIPs.push_back(L->IPAddr);
413
414                         if (L->AllowMask.length())
415                                 ValidIPs.push_back(L->AllowMask);
416
417                         /* Needs resolving */
418                         bool ipvalid = true;
419                         QueryType start_type = DNS_QUERY_A;
420 #ifdef IPV6
421                         start_type = DNS_QUERY_AAAA;
422                         if (strchr(L->IPAddr.c_str(),':'))
423                         {
424                                 in6_addr n;
425                                 if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
426                                         ipvalid = false;
427                         }
428                         else
429 #endif
430                         {
431                                 in_addr n;
432                                 if (inet_aton(L->IPAddr.c_str(),&n) < 1)
433                                         ipvalid = false;
434                         }
435                         if (!ipvalid)
436                         {
437                                 try
438                                 {
439                                         bool cached;
440                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type);
441                                         ServerInstance->AddResolver(sr, cached);
442                                 }
443                                 catch (...)
444                                 {
445                                 }
446                         }
447                 }
448         }
449 }
450
451 void SpanningTreeUtilities::ReadConfiguration(bool rebind)
452 {
453         ConfigReader* Conf = new ConfigReader(ServerInstance);
454         if (rebind)
455         {
456                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
457                 {
458                         std::string Type = Conf->ReadValue("bind","type",j);
459                         std::string IP = Conf->ReadValue("bind","address",j);
460                         std::string Port = Conf->ReadValue("bind","port",j);
461                         std::string transport = Conf->ReadValue("bind","transport",j);
462                         if (Type == "servers")
463                         {
464                                 irc::portparser portrange(Port, false);
465                                 int portno = -1;
466                                 while ((portno = portrange.GetToken()))
467                                 {
468                                         if (IP == "*")
469                                                 IP.clear();
470
471                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
472                                         {
473                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for port %s:%s - maybe you forgot to load it BEFORE m_spanningtree in your config file? - Skipping this port binding", transport.c_str(), IP.c_str(), Port.c_str());
474                                                 break;
475                                         }
476
477                                         TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
478                                         if (listener->GetState() == I_LISTENING)
479                                         {
480                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
481                                                 Bindings.push_back(listener);
482                                         }
483                                         else
484                                         {
485                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port: %s:%d: %s",IP.c_str(), portno, strerror(errno));
486                                                 listener->Close();
487                                         }
488                                 }
489                         }
490                 }
491         }
492         FlatLinks = Conf->ReadFlag("options","flatlinks",0);
493         HideULines = Conf->ReadFlag("options","hideulines",0);
494         AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
495         EnableTimeSync = Conf->ReadFlag("timesync","enable",0);
496         MasterTime = Conf->ReadFlag("timesync", "master", 0);
497         ChallengeResponse = !Conf->ReadFlag("options", "disablehmac", 0);
498         quiet_bursts = Conf->ReadFlag("options", "quietbursts", 0);
499         PingWarnTime = Conf->ReadInteger("options", "pingwarning", 0, true);
500
501         if (PingWarnTime < 0 || PingWarnTime > 59)
502                 PingWarnTime = 0;
503
504         LinkBlocks.clear();
505         ValidIPs.clear();
506         for (int j = 0; j < Conf->Enumerate("link"); j++)
507         {
508                 Link L;
509                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
510                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
511                 L.AllowMask = Allow;
512                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
513                 L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
514                 L.Port = Conf->ReadInteger("link", "port", j, true);
515                 L.SendPass = Conf->ReadValue("link", "sendpass", j);
516                 L.RecvPass = Conf->ReadValue("link", "recvpass", j);
517                 L.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
518                 L.HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
519                 L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
520                 L.Hook = Conf->ReadValue("link", "transport", j);
521                 L.Bind = Conf->ReadValue("link", "bind", j);
522                 L.Hidden = Conf->ReadFlag("link", "hidden", j);
523
524                 if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) ==  hooks.end()))
525                 {
526                         ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for link '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.",
527                         L.Hook.c_str(), L.Name.c_str());
528                         continue;
529
530                 }
531
532                 L.NextConnectTime = time(NULL) + L.AutoConnect;
533                 /* Bugfix by brain, do not allow people to enter bad configurations */
534                 if (L.Name != ServerInstance->Config->ServerName)
535                 {
536                         if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
537                         {
538                                 ValidIPs.push_back(L.IPAddr);
539
540                                 if (Allow.length())
541                                         ValidIPs.push_back(Allow);
542
543                                 /* Needs resolving */
544                                 bool ipvalid = true;
545                                 QueryType start_type = DNS_QUERY_A;
546 #ifdef IPV6
547                                 start_type = DNS_QUERY_AAAA;
548                                 if (strchr(L.IPAddr.c_str(),':'))
549                                 {
550                                         in6_addr n;
551                                         if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
552                                                 ipvalid = false;
553                                 }
554                                 else
555                                 {
556                                         in_addr n;
557                                         if (inet_aton(L.IPAddr.c_str(),&n) < 1)
558                                                 ipvalid = false;
559                                 }
560 #else
561                                 in_addr n;
562                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
563                                         ipvalid = false;
564 #endif
565
566                                 if (!ipvalid)
567                                 {
568                                         try
569                                         {
570                                                 bool cached;
571                                                 SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
572                                                 ServerInstance->AddResolver(sr, cached);
573                                         }
574                                         catch (...)
575                                         {
576                                         }
577                                 }
578
579                                 LinkBlocks.push_back(L);
580                         }
581                         else
582                         {
583                                 if (L.IPAddr.empty())
584                                 {
585                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', IP address not defined!",L.Name.c_str());
586                                 }
587                                 else if (L.RecvPass.empty())
588                                 {
589                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', recvpass not defined!",L.Name.c_str());
590                                 }
591                                 else if (L.SendPass.empty())
592                                 {
593                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', sendpass not defined!",L.Name.c_str());
594                                 }
595                                 else if (L.Name.empty())
596                                 {
597                                         ServerInstance->Log(DEFAULT,"Invalid configuration, link tag without a name!");
598                                 }
599                                 else if (!L.Port)
600                                 {
601                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', no port specified!",L.Name.c_str());
602                                 }
603                         }
604                 }
605                 else
606                 {
607                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', link tag has the same server name as the local server!",L.Name.c_str());
608                 }
609         }
610         DELETE(Conf);
611 }
612
613 void SpanningTreeUtilities::DoFailOver(Link* x)
614 {
615         if (x->FailOver.length())
616         {
617                 if (x->FailOver == x->Name)
618                 {
619                         ServerInstance->SNO->WriteToSnoMask('l',"FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Name.c_str());
620                         return;
621                 }
622                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
623                 if (TryThisOne)
624                 {
625                         ServerInstance->SNO->WriteToSnoMask('l',"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
626                         Creator->ConnectServer(TryThisOne);
627                 }
628                 else
629                 {
630                         ServerInstance->SNO->WriteToSnoMask('l',"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
631                 }
632         }
633 }
634
635 Link* SpanningTreeUtilities::FindLink(const std::string& name)
636 {
637         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
638         {
639                 if (ServerInstance->MatchText(x->Name.c_str(), name.c_str()))
640                 {
641                         return &(*x);
642                 }
643         }
644         return NULL;
645 }
646