1 /* ---------------------------------------------------------------------
3 * +------------------------------------+
4 * | Inspire Internet Relay Chat Daemon |
5 * +------------------------------------+
7 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
9 * <brain@chatspike.net>
10 * <Craig@chatspike.net>
12 * Written by Craig Edwards, Craig McLure, and others.
13 * This program is free but copyrighted software; you can redistribute
14 * it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * ---------------------------------------------------------------------
31 #include "inspircd_config.h"
33 #include "configreader.h"
35 #include <sys/errno.h>
36 #include <sys/ioctl.h>
58 #include "inspstring.h"
59 #include "helperfuncs.h"
61 #include "socketengine.h"
62 #include "inspircd_se_config.h"
63 #include "userprocess.h"
66 #include "command_parse.h"
68 InspIRCd* ServerInstance;
70 extern ModuleList modules;
71 extern FactoryList factory;
73 std::vector<InspSocket*> module_sockets;
74 std::vector<userrec*> local_users;
77 extern char LOG_FILE[MAXBUF];
81 insp_sockaddr client, server;
84 extern InspSocket* socket_ref[MAX_DESCRIPTORS];
85 time_t TIME = time(NULL), OLDTIME = time(NULL);
87 // This table references users by file descriptor.
88 // its an array to make it VERY fast, as all lookups are referenced
89 // by an integer, meaning there is no need for a scan/search operation.
90 userrec* fd_ref_table[MAX_DESCRIPTORS];
91 Server* MyServer = new Server;
92 ServerConfig *Config = new ServerConfig;
95 servernamelist servernames;
98 void AddServerName(const std::string &servername)
100 log(DEBUG,"Adding server name: %s",servername.c_str());
102 if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
103 servernames.push_back(servername); /* Wasn't already there. */
106 const char* FindServerNamePtr(const std::string &servername)
108 servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
110 if(iter == servernames.end())
112 AddServerName(servername);
113 iter = --servernames.end();
116 return iter->c_str();
119 bool FindServerName(const std::string &servername)
121 return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
124 void Exit(int status)
126 if (Config->log_file)
127 fclose(Config->log_file);
128 send_error("Server shutdown.");
132 void InspIRCd::Start()
134 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
135 printf("(C) ChatSpike Development team.\033[0m\n\n");
136 printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\033[0m\n");
137 printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
138 printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n");
141 void Killed(int status)
143 if (Config->log_file)
144 fclose(Config->log_file);
145 send_error("Server terminated.");
149 void Rehash(int status)
151 WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE));
152 fclose(Config->log_file);
154 Config->Read(false,NULL);
155 FOREACH_MOD(I_OnRehash,OnRehash(""));
158 void InspIRCd::SetSignals()
160 signal (SIGALRM, SIG_IGN);
161 signal (SIGHUP, Rehash);
162 signal (SIGPIPE, SIG_IGN);
163 signal (SIGTERM, Exit);
164 signal (SIGSEGV, Error);
167 bool InspIRCd::DaemonSeed()
170 if ((childpid = fork ()) < 0)
172 else if (childpid > 0)
174 /* We wait a few seconds here, so that the shell prompt doesnt come back over the output */
180 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
183 if (getrlimit(RLIMIT_CORE, &rl) == -1)
185 log(DEFAULT,"Failed to getrlimit()!");
190 rl.rlim_cur = rl.rlim_max;
191 if (setrlimit(RLIMIT_CORE, &rl) == -1)
192 log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
198 void InspIRCd::WritePID(const std::string &filename)
200 std::ofstream outfile(filename.c_str());
201 if (outfile.is_open())
208 printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
209 log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
214 std::string InspIRCd::GetRevision()
219 void InspIRCd::MakeLowerMap()
221 // initialize the lowercase mapping table
222 for (unsigned int cn = 0; cn < 256; cn++)
224 // lowercase the uppercase chars
225 for (unsigned int cn = 65; cn < 91; cn++)
226 lowermap[cn] = tolower(cn);
227 // now replace the specific chars for scandanavian comparison
228 lowermap[(unsigned)'['] = '{';
229 lowermap[(unsigned)']'] = '}';
230 lowermap[(unsigned)'\\'] = '|';
233 InspIRCd::InspIRCd(int argc, char** argv)
236 module_sockets.clear();
237 this->startup_time = time(NULL);
239 log(DEBUG,"*** InspIRCd starting up!");
240 if (!FileExists(CONFIG_FILE))
242 printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE);
243 log(DEFAULT,"main: no config");
244 printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n");
249 for (int i = 1; i < argc; i++)
251 if (!strcmp(argv[i],"-nofork"))
253 Config->nofork = true;
255 else if(!strcmp(argv[i],"-debug"))
257 Config->forcedebug = true;
259 else if(!strcmp(argv[i],"-nolog"))
261 Config->writelog = false;
263 else if (!strcmp(argv[i],"-wait"))
267 else if (!strcmp(argv[i],"-nolimit"))
269 printf("WARNING: The `-nolimit' option is deprecated, and now on by default. This behaviour may change in the future.\n");
271 else if (!strcmp(argv[i],"-logfile"))
275 strlcpy(LOG_FILE,argv[i+1],MAXBUF);
276 printf("LOG: Setting logfile to %s\n",LOG_FILE);
280 printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n");
287 strlcpy(Config->MyExecutable,argv[0],MAXBUF);
289 this->MakeLowerMap();
292 this->stats = new serverstats();
293 this->Parser = new CommandParser();
294 Config->ClearStack();
295 Config->Read(true,NULL);
297 this->ModeGrok = new ModeParser();
298 AddServerName(Config->ServerName);
300 InitializeDisabledCommands(Config->DisabledCommands, this);
301 stats->BoundPortCount = BindPorts(true);
303 for(int t = 0; t < 255; t++)
304 Config->global_implementation[t] = 0;
306 memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
312 if (!this->DaemonSeed())
314 printf("ERROR: could not go into daemon mode. Shutting down.\n");
319 /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
320 * initialize the socket engine.
322 SocketEngineFactory* SEF = new SocketEngineFactory();
326 /* We must load the modules AFTER initializing the socket engine, now */
331 std::string InspIRCd::GetVersionString()
333 char versiondata[MAXBUF];
334 char dnsengine[] = "singlethread-object";
335 if (*Config->CustomVersion)
337 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
341 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%lu,%s,%s]",VERSION,Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
346 char* InspIRCd::ModuleError()
351 void InspIRCd::EraseFactory(int j)
354 for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
359 factory.push_back(NULL);
366 void InspIRCd::EraseModule(int j)
369 for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
375 modules.push_back(NULL);
381 for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
385 Config->module_names.erase(v);
393 void InspIRCd::MoveTo(std::string modulename,int slot)
395 unsigned int v2 = 256;
396 for (unsigned int v = 0; v < Config->module_names.size(); v++)
398 if (Config->module_names[v] == modulename)
400 // found an instance, swap it with the item at MODCOUNT
405 if ((v2 != (unsigned int)slot) && (v2 < 256))
407 // Swap the module names over
408 Config->module_names[v2] = Config->module_names[slot];
409 Config->module_names[slot] = modulename;
410 // now swap the module factories
411 ircd_module* temp = factory[v2];
412 factory[v2] = factory[slot];
413 factory[slot] = temp;
414 // now swap the module objects
415 Module* temp_module = modules[v2];
416 modules[v2] = modules[slot];
417 modules[slot] = temp_module;
418 // now swap the implement lists (we dont
419 // need to swap the global or recount it)
420 for (int n = 0; n < 255; n++)
422 char x = Config->implement_lists[v2][n];
423 Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
424 Config->implement_lists[slot][n] = x;
429 log(DEBUG,"Move of %s to slot failed!",modulename.c_str());
433 void InspIRCd::MoveAfter(std::string modulename, std::string after)
435 for (unsigned int v = 0; v < Config->module_names.size(); v++)
437 if (Config->module_names[v] == after)
439 MoveTo(modulename, v);
445 void InspIRCd::MoveBefore(std::string modulename, std::string before)
447 for (unsigned int v = 0; v < Config->module_names.size(); v++)
449 if (Config->module_names[v] == before)
453 MoveTo(modulename, v-1);
457 MoveTo(modulename, v);
464 void InspIRCd::MoveToFirst(std::string modulename)
466 MoveTo(modulename,0);
469 void InspIRCd::MoveToLast(std::string modulename)
471 MoveTo(modulename,MODCOUNT);
474 void InspIRCd::BuildISupport()
476 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
478 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=(ohv)@%+ MAP MAXCHANNELS=" << MAXCHANS << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
479 v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
480 v << MAXAWAY << " CHANMODES=b,k,l,psmnti FNC NETWORK=" << Config->Network << " MAXPARA=32";
481 Config->data005 = v.str();
482 FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
485 bool InspIRCd::UnloadModule(const char* filename)
487 std::string filename_str = filename;
488 for (unsigned int j = 0; j != Config->module_names.size(); j++)
490 if (Config->module_names[j] == filename_str)
492 if (modules[j]->GetVersion().Flags & VF_STATIC)
494 log(DEFAULT,"Failed to unload STATIC module %s",filename);
495 snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
498 /* Give the module a chance to tidy out all its metadata */
499 for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
501 modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
503 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
505 modules[j]->OnCleanup(TYPE_USER,u->second);
508 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
510 for(int t = 0; t < 255; t++)
512 Config->global_implementation[t] -= Config->implement_lists[j][t];
515 /* We have to renumber implement_lists after unload because the module numbers change!
517 for(int j2 = j; j2 < 254; j2++)
519 for(int t = 0; t < 255; t++)
521 Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
526 log(DEBUG,"Deleting module...");
527 this->EraseModule(j);
528 log(DEBUG,"Erasing module entry...");
529 this->EraseFactory(j);
530 log(DEBUG,"Removing dependent commands...");
531 Parser->RemoveCommands(filename);
532 log(DEFAULT,"Module %s unloaded",filename);
538 log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
539 snprintf(MODERR,MAXBUF,"Module not loaded");
543 bool InspIRCd::LoadModule(const char* filename)
545 char modfile[MAXBUF];
547 strlcpy(modfile,filename,MAXBUF);
549 snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
551 std::string filename_str = filename;
554 if (!DirValid(modfile))
556 log(DEFAULT,"Module %s is not within the modules directory.",modfile);
557 snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile);
562 log(DEBUG,"Loading module: %s",modfile);
564 if (FileExists(modfile))
567 for (unsigned int j = 0; j < Config->module_names.size(); j++)
569 if (Config->module_names[j] == filename_str)
571 log(DEFAULT,"Module %s is already loaded, cannot load a module twice!",modfile);
572 snprintf(MODERR,MAXBUF,"Module already loaded");
576 ircd_module* a = new ircd_module(modfile);
577 factory[MODCOUNT+1] = a;
578 if (factory[MODCOUNT+1]->LastError())
580 log(DEFAULT,"Unable to load %s: %s",modfile,factory[MODCOUNT+1]->LastError());
581 snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
586 if (factory[MODCOUNT+1]->factory)
588 Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
589 modules[MODCOUNT+1] = m;
590 /* save the module and the module's classfactory, if
591 * this isnt done, random crashes can occur :/ */
592 Config->module_names.push_back(filename);
594 char* x = &Config->implement_lists[MODCOUNT+1][0];
595 for(int t = 0; t < 255; t++)
598 modules[MODCOUNT+1]->Implements(x);
600 for(int t = 0; t < 255; t++)
601 Config->global_implementation[t] += Config->implement_lists[MODCOUNT+1][t];
605 log(DEFAULT,"Unable to load %s",modfile);
606 snprintf(MODERR,MAXBUF,"Factory function failed!");
610 catch (ModuleException& modexcept)
612 log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason());
613 snprintf(MODERR,MAXBUF,"Factory function threw an exception: %s",modexcept.GetReason());
620 log(DEFAULT,"InspIRCd: startup: Module Not Found %s",modfile);
621 snprintf(MODERR,MAXBUF,"Module file could not be found");
626 FOREACH_MOD(I_OnLoadModule,OnLoadModule(modules[MODCOUNT],filename_str));
627 // now work out which modules, if any, want to move to the back of the queue,
628 // and if they do, move them there.
629 std::vector<std::string> put_to_back;
630 std::vector<std::string> put_to_front;
631 std::map<std::string,std::string> put_before;
632 std::map<std::string,std::string> put_after;
633 for (unsigned int j = 0; j < Config->module_names.size(); j++)
635 if (modules[j]->Prioritize() == PRIORITY_LAST)
637 put_to_back.push_back(Config->module_names[j]);
639 else if (modules[j]->Prioritize() == PRIORITY_FIRST)
641 put_to_front.push_back(Config->module_names[j]);
643 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
645 put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
647 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
649 put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
652 for (unsigned int j = 0; j < put_to_back.size(); j++)
654 MoveToLast(put_to_back[j]);
656 for (unsigned int j = 0; j < put_to_front.size(); j++)
658 MoveToFirst(put_to_front[j]);
660 for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
662 MoveBefore(j->first,j->second);
664 for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
666 MoveAfter(j->first,j->second);
672 void InspIRCd::DoOneIteration(bool process_module_sockets)
674 int activefds[MAX_DESCRIPTORS];
678 InspSocket* s = NULL;
679 InspSocket* s_del = NULL;
680 unsigned int numberactive;
681 insp_sockaddr sock_us; // our port number
682 socklen_t uslen; // length of our port number
684 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
685 * Once per loop iteration is pleanty.
690 /* Run background module timers every few seconds
691 * (the docs say modules shouldnt rely on accurate
692 * timing using this event, so we dont have to
693 * time this exactly).
695 if (((TIME % 5) == 0) && (!expire_run))
698 if (process_module_sockets)
700 /* Fix by brain - the addition of DoOneIteration means that this
701 * can end up getting called recursively in the following pattern:
703 * m_spanningtree DoPingChecks
704 * (server pings out and is squit)
705 * (squit causes call to DoOneIteration)
706 * DoOneIteration enters here
707 * calls DoBackground timer
708 * enters m_spanningtree DoPingChecks... see step 1.
710 * This should do the job and fix the bug.
712 FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME));
714 TickMissedTimers(TIME);
718 else if ((TIME % 5) == 1)
723 if (iterations++ == 15)
726 DoBackgroundUserStuff(TIME);
729 /* Once a second, do the background processing */
733 WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
734 if ((TIME % 3600) == 0)
736 MaintainWhoWas(TIME);
740 /* Process timeouts on module sockets each time around
741 * the loop. There shouldnt be many module sockets, at
742 * most, 20 or so, so this won't be much of a performance
745 if (process_module_sockets)
746 DoSocketTimeouts(TIME);
750 /* Call the socket engine to wait on the active
751 * file descriptors. The socket engine has everything's
752 * descriptors in its list... dns, modules, users,
753 * servers... so its nice and easy, just one call.
755 if (!(numberactive = SE->Wait(activefds)))
759 * Now process each of the fd's. For users, we have a fast
760 * lookup table which can find a user by file descriptor, so
761 * processing them by fd isnt expensive. If we have a lot of
762 * listening ports or module sockets though, things could get
765 log(DEBUG,"There are %d fd's to process.",numberactive);
767 for (unsigned int activefd = 0; activefd < numberactive; activefd++)
769 int socket_type = SE->GetType(activefds[activefd]);
774 log(DEBUG,"Type: X_ESTAB_CLIENT: fd=%d",activefds[activefd]);
775 cu = fd_ref_table[activefds[activefd]];
783 log(DEBUG,"Type: X_ESTAB_MODULE: fd=%d",activefds[activefd]);
785 if (!process_module_sockets)
788 /* Process module-owned sockets.
789 * Modules are encouraged to inherit their sockets from
790 * InspSocket so we can process them neatly like this.
792 s = socket_ref[activefds[activefd]];
794 if ((s) && (!s->Poll()))
796 log(DEBUG,"Socket poll returned false, close and bail");
797 SE->DelFd(s->GetFd());
798 socket_ref[activefds[activefd]] = NULL;
799 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
802 if ((s_del) && (s_del->GetFd() == activefds[activefd]))
804 module_sockets.erase(a);
813 log(DEBUG,"WTF, X_ESTAB_MODULE for nonexistent InspSocket, removed!");
814 SE->DelFd(s->GetFd());
819 /* Handles instances of the Resolver class,
820 * a simple class extended by modules and the core for
821 * nonblocking resolving of addresses.
823 this->Res->MarshallReads(activefds[activefd]);
828 log(DEBUG,"Type: X_LISTEN: fd=%d",activefds[activefd]);
830 /* It's a listener */
831 uslen = sizeof(sock_us);
832 length = sizeof(client);
833 incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
835 if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
838 in_port = ntohs(sock_us.sin6_port);
840 in_port = ntohs(sock_us.sin_port);
842 log(DEBUG,"Accepted socket %d",incomingSockfd);
843 /* Years and years ago, we used to resolve here
844 * using gethostbyaddr(). That is sucky and we
845 * don't do that any more...
847 NonBlocking(incomingSockfd);
848 if (Config->GetIOHook(in_port))
853 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin6_addr), in_port);
855 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port);
858 catch (ModuleException& modexcept)
860 log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
863 stats->statsAccept++;
865 AddClient(incomingSockfd, in_port, false, client.sin6_addr);
867 AddClient(incomingSockfd, in_port, false, client.sin_addr);
869 log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
873 log(DEBUG,"Accept failed on fd %lu: %s",(unsigned long)incomingSockfd,strerror(errno));
874 shutdown(incomingSockfd,2);
875 close(incomingSockfd);
876 stats->statsRefused++;
881 /* Something went wrong if we're in here.
882 * In fact, so wrong, im not quite sure
883 * what we would do, so for now, its going
884 * to safely do bugger all.
886 log(DEBUG,"Type: X_WHAT_THE_FUCK_BBQ: fd=%d",activefds[activefd]);
887 SE->DelFd(activefds[activefd]);
895 /* Until THIS point, ServerInstance == NULL */
897 this->Res = new DNS();
899 LoadAllModules(this);
901 /* Just in case no modules were loaded - fix for bug #101 */
902 this->BuildISupport();
904 printf("\nInspIRCd is now running!\n");
913 /* Add the listening sockets used for client inbound connections
914 * to the socket engine
916 for (unsigned long count = 0; count < stats->BoundPortCount; count++)
917 SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
919 this->WritePID(Config->PID);
921 /* main loop, this never returns */
927 DoOneIteration(true);
929 /* This is never reached -- we hope! */
933 /**********************************************************************************/
936 * An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
939 int main(int argc, char** argv)
941 /* TEST SUITE FOR TOKENSTREAM
945 * String: 'PRIVMSG #test FOO BAR'
946 * Token 0 = 'PRIVMSG'
950 * String: 'PRIVMSG #test :FOO BAR BAZ'
951 * Token 0 = 'PRIVMSG'
953 * Token 2 = 'FOO BAR BAZ'
954 * String: ':PRIVMSG #test :FOO BAR BAZ'
955 * Token 0 = ':PRIVMSG'
957 * Token 0 = 'AAAAAAA'
961 std::string a = "PRIVMSG #test FOO BAR";
962 printf("String: '%s'\n",a.c_str());
963 irc::tokenstream test(a);
964 printf("Token 0 = '%s'\n",test.GetToken().c_str());
965 printf("Token 1 = '%s'\n",test.GetToken().c_str());
966 printf("Token 2 = '%s'\n",test.GetToken().c_str());
967 printf("Token 3 = '%s'\n",test.GetToken().c_str());
968 printf("Token 4 = '%s'\n",test.GetToken().c_str());
970 std::string b = "PRIVMSG #test :FOO BAR BAZ";
971 printf("String: '%s'\n",b.c_str());
972 irc::tokenstream test2(b);
973 printf("Token 0 = '%s'\n",test2.GetToken().c_str());
974 printf("Token 1 = '%s'\n",test2.GetToken().c_str());
975 printf("Token 2 = '%s'\n",test2.GetToken().c_str());
976 printf("Token 3 = '%s'\n",test2.GetToken().c_str());
978 std::string c = ":PRIVMSG #test :FOO BAR BAZ";
979 printf("String: '%s'\n",c.c_str());
980 irc::tokenstream test3(c);
981 printf("Token 0 = '%s'\n",test3.GetToken().c_str());
984 printf("String: '%s'\n",c.c_str());
985 irc::tokenstream test4(c);
986 printf("Token 0 = '%s'\n",test4.GetToken().c_str());
987 printf("Token 1 = '%s'\n",test4.GetToken().c_str());
990 printf("String: '%s'\n",c.c_str());
991 irc::tokenstream test5(c);
992 printf("Token 0 = '%s'\n",test5.GetToken().c_str());
998 ServerInstance = new InspIRCd(argc, argv);
999 ServerInstance->Run();
1000 DELETE(ServerInstance);
1002 catch (std::bad_alloc)
1004 log(DEFAULT,"You are out of memory! (got exception std::bad_alloc!)");
1005 send_error("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
1006 printf("Out of memory! (got exception std::bad_alloc!");