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>
61 #include "inspstring.h"
63 #include "helperfuncs.h"
65 #include "socketengine.h"
66 #include "userprocess.h"
69 #include "command_parse.h"
71 InspIRCd* ServerInstance;
73 extern ModuleList modules;
74 extern FactoryList factory;
76 std::vector<InspSocket*> module_sockets;
77 std::vector<userrec*> local_users;
80 extern char LOG_FILE[MAXBUF];
84 insp_sockaddr client, server;
87 extern InspSocket* socket_ref[MAX_DESCRIPTORS];
88 time_t TIME = time(NULL), OLDTIME = time(NULL);
90 // This table references users by file descriptor.
91 // its an array to make it VERY fast, as all lookups are referenced
92 // by an integer, meaning there is no need for a scan/search operation.
93 userrec* fd_ref_table[MAX_DESCRIPTORS];
94 Server* MyServer = new Server;
95 ServerConfig *Config = new ServerConfig;
98 servernamelist servernames;
101 void AddServerName(const std::string &servername)
103 log(DEBUG,"Adding server name: %s",servername.c_str());
105 if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
106 servernames.push_back(servername); /* Wasn't already there. */
109 const char* FindServerNamePtr(const std::string &servername)
111 servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
113 if(iter == servernames.end())
115 AddServerName(servername);
116 iter = --servernames.end();
119 return iter->c_str();
122 bool FindServerName(const std::string &servername)
124 return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
127 void Exit(int status)
129 if (Config->log_file)
130 fclose(Config->log_file);
131 send_error("Server shutdown.");
135 void InspIRCd::Start()
137 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
138 printf("(C) ChatSpike Development team.\033[0m\n\n");
139 printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\033[0m\n");
140 printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
141 printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n");
144 void Killed(int status)
146 if (Config->log_file)
147 fclose(Config->log_file);
148 send_error("Server terminated.");
152 void Rehash(int status)
154 WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE));
155 fclose(Config->log_file);
157 Config->Read(false,NULL);
158 FOREACH_MOD(I_OnRehash,OnRehash(""));
161 void InspIRCd::SetSignals()
163 signal (SIGALRM, SIG_IGN);
164 signal (SIGHUP, Rehash);
165 signal (SIGPIPE, SIG_IGN);
166 signal (SIGTERM, Exit);
167 signal (SIGSEGV, Error);
170 bool InspIRCd::DaemonSeed()
173 if ((childpid = fork ()) < 0)
175 else if (childpid > 0)
177 /* We wait a few seconds here, so that the shell prompt doesnt come back over the output */
183 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
186 if (getrlimit(RLIMIT_CORE, &rl) == -1)
188 log(DEFAULT,"Failed to getrlimit()!");
193 rl.rlim_cur = rl.rlim_max;
194 if (setrlimit(RLIMIT_CORE, &rl) == -1)
195 log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
201 void InspIRCd::WritePID(const std::string &filename)
203 std::ofstream outfile(filename.c_str());
204 if (outfile.is_open())
211 printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
212 log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
217 std::string InspIRCd::GetRevision()
222 void InspIRCd::MakeLowerMap()
224 // initialize the lowercase mapping table
225 for (unsigned int cn = 0; cn < 256; cn++)
227 // lowercase the uppercase chars
228 for (unsigned int cn = 65; cn < 91; cn++)
229 lowermap[cn] = tolower(cn);
230 // now replace the specific chars for scandanavian comparison
231 lowermap[(unsigned)'['] = '{';
232 lowermap[(unsigned)']'] = '}';
233 lowermap[(unsigned)'\\'] = '|';
236 InspIRCd::InspIRCd(int argc, char** argv)
239 module_sockets.clear();
241 this->startup_time = time(NULL);
243 log(DEBUG,"*** InspIRCd starting up!");
244 if (!FileExists(CONFIG_FILE))
246 printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE);
247 log(DEFAULT,"main: no config");
248 printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n");
253 for (int i = 1; i < argc; i++)
255 if (!strcmp(argv[i],"-nofork"))
257 Config->nofork = true;
259 else if(!strcmp(argv[i],"-debug"))
261 Config->forcedebug = true;
263 else if(!strcmp(argv[i],"-nolog"))
265 Config->writelog = false;
267 else if (!strcmp(argv[i],"-wait"))
271 else if (!strcmp(argv[i],"-nolimit"))
273 printf("WARNING: The `-nolimit' option is deprecated, and now on by default. This behaviour may change in the future.\n");
275 else if (!strcmp(argv[i],"-logfile"))
279 strlcpy(LOG_FILE,argv[i+1],MAXBUF);
280 printf("LOG: Setting logfile to %s\n",LOG_FILE);
284 printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n");
291 strlcpy(Config->MyExecutable,argv[0],MAXBUF);
293 this->MakeLowerMap();
296 this->stats = new serverstats();
297 Config->ClearStack();
298 Config->Read(true,NULL);
300 this->ModeGrok = new ModeParser();
301 this->Parser = new CommandParser();
302 AddServerName(Config->ServerName);
304 stats->BoundPortCount = BindPorts(true);
306 for(int t = 0; t < 255; t++)
307 Config->global_implementation[t] = 0;
309 memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
315 if (!this->DaemonSeed())
317 printf("ERROR: could not go into daemon mode. Shutting down.\n");
322 /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
323 * initialize the socket engine.
325 SE = new SocketEngine();
327 /* We must load the modules AFTER initializing the socket engine, now */
332 std::string InspIRCd::GetVersionString()
334 char versiondata[MAXBUF];
336 char dnsengine[] = "multithread";
338 char dnsengine[] = "singlethread";
340 if (*Config->CustomVersion)
342 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
346 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%lu,%s,%s]",VERSION,Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
351 char* InspIRCd::ModuleError()
356 void InspIRCd::EraseFactory(int j)
359 for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
364 factory.push_back(NULL);
371 void InspIRCd::EraseModule(int j)
374 for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
380 modules.push_back(NULL);
386 for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
390 Config->module_names.erase(v);
398 void InspIRCd::MoveTo(std::string modulename,int slot)
400 unsigned int v2 = 256;
401 for (unsigned int v = 0; v < Config->module_names.size(); v++)
403 if (Config->module_names[v] == modulename)
405 // found an instance, swap it with the item at MODCOUNT
410 if ((v2 != (unsigned int)slot) && (v2 < 256))
412 // Swap the module names over
413 Config->module_names[v2] = Config->module_names[slot];
414 Config->module_names[slot] = modulename;
415 // now swap the module factories
416 ircd_module* temp = factory[v2];
417 factory[v2] = factory[slot];
418 factory[slot] = temp;
419 // now swap the module objects
420 Module* temp_module = modules[v2];
421 modules[v2] = modules[slot];
422 modules[slot] = temp_module;
423 // now swap the implement lists (we dont
424 // need to swap the global or recount it)
425 for (int n = 0; n < 255; n++)
427 char x = Config->implement_lists[v2][n];
428 Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
429 Config->implement_lists[slot][n] = x;
434 log(DEBUG,"Move of %s to slot failed!",modulename.c_str());
438 void InspIRCd::MoveAfter(std::string modulename, std::string after)
440 for (unsigned int v = 0; v < Config->module_names.size(); v++)
442 if (Config->module_names[v] == after)
444 MoveTo(modulename, v);
450 void InspIRCd::MoveBefore(std::string modulename, std::string before)
452 for (unsigned int v = 0; v < Config->module_names.size(); v++)
454 if (Config->module_names[v] == before)
458 MoveTo(modulename, v-1);
462 MoveTo(modulename, v);
469 void InspIRCd::MoveToFirst(std::string modulename)
471 MoveTo(modulename,0);
474 void InspIRCd::MoveToLast(std::string modulename)
476 MoveTo(modulename,MODCOUNT);
479 void InspIRCd::BuildISupport()
481 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
483 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=(ohv)@%+ MAP MAXCHANNELS=" << MAXCHANS << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
484 v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
485 v << MAXAWAY << " CHANMODES=b,k,l,psmnti FNC NETWORK=" << Config->Network << " MAXPARA=32";
486 Config->data005 = v.str();
487 FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
490 bool InspIRCd::UnloadModule(const char* filename)
492 std::string filename_str = filename;
493 for (unsigned int j = 0; j != Config->module_names.size(); j++)
495 if (Config->module_names[j] == filename_str)
497 if (modules[j]->GetVersion().Flags & VF_STATIC)
499 log(DEFAULT,"Failed to unload STATIC module %s",filename);
500 snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
503 /* Give the module a chance to tidy out all its metadata */
504 for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
506 modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
508 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
510 modules[j]->OnCleanup(TYPE_USER,u->second);
513 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
515 for(int t = 0; t < 255; t++)
517 Config->global_implementation[t] -= Config->implement_lists[j][t];
520 /* We have to renumber implement_lists after unload because the module numbers change!
522 for(int j2 = j; j2 < 254; j2++)
524 for(int t = 0; t < 255; t++)
526 Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
531 log(DEBUG,"Deleting module...");
532 this->EraseModule(j);
533 log(DEBUG,"Erasing module entry...");
534 this->EraseFactory(j);
535 log(DEBUG,"Removing dependent commands...");
536 Parser->RemoveCommands(filename);
537 log(DEFAULT,"Module %s unloaded",filename);
543 log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
544 snprintf(MODERR,MAXBUF,"Module not loaded");
548 bool InspIRCd::LoadModule(const char* filename)
550 char modfile[MAXBUF];
552 strlcpy(modfile,filename,MAXBUF);
554 snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
556 std::string filename_str = filename;
559 if (!DirValid(modfile))
561 log(DEFAULT,"Module %s is not within the modules directory.",modfile);
562 snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile);
567 log(DEBUG,"Loading module: %s",modfile);
569 if (FileExists(modfile))
572 for (unsigned int j = 0; j < Config->module_names.size(); j++)
574 if (Config->module_names[j] == filename_str)
576 log(DEFAULT,"Module %s is already loaded, cannot load a module twice!",modfile);
577 snprintf(MODERR,MAXBUF,"Module already loaded");
581 ircd_module* a = new ircd_module(modfile);
582 factory[MODCOUNT+1] = a;
583 if (factory[MODCOUNT+1]->LastError())
585 log(DEFAULT,"Unable to load %s: %s",modfile,factory[MODCOUNT+1]->LastError());
586 snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
591 if (factory[MODCOUNT+1]->factory)
593 Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
594 modules[MODCOUNT+1] = m;
595 /* save the module and the module's classfactory, if
596 * this isnt done, random crashes can occur :/ */
597 Config->module_names.push_back(filename);
599 char* x = &Config->implement_lists[MODCOUNT+1][0];
600 for(int t = 0; t < 255; t++)
603 modules[MODCOUNT+1]->Implements(x);
605 for(int t = 0; t < 255; t++)
606 Config->global_implementation[t] += Config->implement_lists[MODCOUNT+1][t];
610 log(DEFAULT,"Unable to load %s",modfile);
611 snprintf(MODERR,MAXBUF,"Factory function failed!");
615 catch (ModuleException& modexcept)
617 log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason());
618 snprintf(MODERR,MAXBUF,"Factory function threw an exception: %s",modexcept.GetReason());
625 log(DEFAULT,"InspIRCd: startup: Module Not Found %s",modfile);
626 snprintf(MODERR,MAXBUF,"Module file could not be found");
631 FOREACH_MOD(I_OnLoadModule,OnLoadModule(modules[MODCOUNT],filename_str));
632 // now work out which modules, if any, want to move to the back of the queue,
633 // and if they do, move them there.
634 std::vector<std::string> put_to_back;
635 std::vector<std::string> put_to_front;
636 std::map<std::string,std::string> put_before;
637 std::map<std::string,std::string> put_after;
638 for (unsigned int j = 0; j < Config->module_names.size(); j++)
640 if (modules[j]->Prioritize() == PRIORITY_LAST)
642 put_to_back.push_back(Config->module_names[j]);
644 else if (modules[j]->Prioritize() == PRIORITY_FIRST)
646 put_to_front.push_back(Config->module_names[j]);
648 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
650 put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
652 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
654 put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
657 for (unsigned int j = 0; j < put_to_back.size(); j++)
659 MoveToLast(put_to_back[j]);
661 for (unsigned int j = 0; j < put_to_front.size(); j++)
663 MoveToFirst(put_to_front[j]);
665 for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
667 MoveBefore(j->first,j->second);
669 for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
671 MoveAfter(j->first,j->second);
677 void InspIRCd::DoOneIteration(bool process_module_sockets)
679 int activefds[MAX_DESCRIPTORS];
683 InspSocket* s = NULL;
684 InspSocket* s_del = NULL;
685 unsigned int numberactive;
686 insp_sockaddr sock_us; // our port number
687 socklen_t uslen; // length of our port number
689 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
690 * Once per loop iteration is pleanty.
695 /* Run background module timers every few seconds
696 * (the docs say modules shouldnt rely on accurate
697 * timing using this event, so we dont have to
698 * time this exactly).
700 if (((TIME % 5) == 0) && (!expire_run))
703 if (process_module_sockets)
705 /* Fix by brain - the addition of DoOneIteration means that this
706 * can end up getting called recursively in the following pattern:
708 * m_spanningtree DoPingChecks
709 * (server pings out and is squit)
710 * (squit causes call to DoOneIteration)
711 * DoOneIteration enters here
712 * calls DoBackground timer
713 * enters m_spanningtree DoPingChecks... see step 1.
715 * This should do the job and fix the bug.
717 FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME));
719 TickMissedTimers(TIME);
723 else if ((TIME % 5) == 1)
728 if (iterations++ == 15)
731 DoBackgroundUserStuff(TIME);
734 /* Once a second, do the background processing */
738 WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
739 if ((TIME % 3600) == 0)
741 MaintainWhoWas(TIME);
745 /* Process timeouts on module sockets each time around
746 * the loop. There shouldnt be many module sockets, at
747 * most, 20 or so, so this won't be much of a performance
750 if (process_module_sockets)
751 DoSocketTimeouts(TIME);
755 /* Call the socket engine to wait on the active
756 * file descriptors. The socket engine has everything's
757 * descriptors in its list... dns, modules, users,
758 * servers... so its nice and easy, just one call.
760 if (!(numberactive = SE->Wait(activefds)))
764 * Now process each of the fd's. For users, we have a fast
765 * lookup table which can find a user by file descriptor, so
766 * processing them by fd isnt expensive. If we have a lot of
767 * listening ports or module sockets though, things could get
770 log(DEBUG,"There are %d fd's to process.",numberactive);
772 for (unsigned int activefd = 0; activefd < numberactive; activefd++)
774 int socket_type = SE->GetType(activefds[activefd]);
779 log(DEBUG,"Type: X_ESTAB_CLIENT: fd=%d",activefds[activefd]);
780 cu = fd_ref_table[activefds[activefd]];
788 log(DEBUG,"Type: X_ESTAB_MODULE: fd=%d",activefds[activefd]);
790 if (!process_module_sockets)
793 /* Process module-owned sockets.
794 * Modules are encouraged to inherit their sockets from
795 * InspSocket so we can process them neatly like this.
797 s = socket_ref[activefds[activefd]];
799 if ((s) && (!s->Poll()))
801 log(DEBUG,"Socket poll returned false, close and bail");
802 SE->DelFd(s->GetFd());
803 socket_ref[activefds[activefd]] = NULL;
804 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
807 if ((s_del) && (s_del->GetFd() == activefds[activefd]))
809 module_sockets.erase(a);
818 log(DEBUG,"WTF, X_ESTAB_MODULE for nonexistent InspSocket, removed!");
819 SE->DelFd(s->GetFd());
824 /* When we are using single-threaded dns,
825 * the sockets for dns end up in our mainloop.
826 * When we are using multi-threaded dns,
827 * each thread has its own basic poll() loop
828 * within it, making them 'fire and forget'
829 * and independent of the mainloop.
832 log(DEBUG,"Type: X_ESTAB_DNS: fd=%d",activefds[activefd]);
833 dns_poll(activefds[activefd]);
837 case X_ESTAB_CLASSDNS:
838 /* Handles instances of the Resolver class,
839 * a simple class extended by modules for
840 * nonblocking resolving of addresses.
843 dns_deal_with_classes(activefds[activefd]);
848 log(DEBUG,"Type: X_LISTEN_MODULE: fd=%d",activefds[activefd]);
850 /* It's a listener */
851 uslen = sizeof(sock_us);
852 length = sizeof(client);
853 incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
855 if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
857 in_port = ntohs(sock_us.sin_port);
858 log(DEBUG,"Accepted socket %d",incomingSockfd);
859 /* Years and years ago, we used to resolve here
860 * using gethostbyaddr(). That is sucky and we
861 * don't do that any more...
863 NonBlocking(incomingSockfd);
864 if (Config->GetIOHook(in_port))
868 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, inet_ntoa(client.sin_addr), in_port);
870 catch (ModuleException& modexcept)
872 log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
875 stats->statsAccept++;
876 AddClient(incomingSockfd, in_port, false, client.sin_addr);
877 log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
881 log(DEBUG,"Accept failed on fd %lu: %s",(unsigned long)incomingSockfd,strerror(errno));
882 shutdown(incomingSockfd,2);
883 close(incomingSockfd);
884 stats->statsRefused++;
889 /* Something went wrong if we're in here.
890 * In fact, so wrong, im not quite sure
891 * what we would do, so for now, its going
892 * to safely do bugger all.
894 log(DEBUG,"Type: X_WHAT_THE_FUCK_BBQ: fd=%d",activefds[activefd]);
895 SE->DelFd(activefds[activefd]);
903 /* Until THIS point, ServerInstance == NULL */
905 LoadAllModules(this);
907 /* Just in case no modules were loaded - fix for bug #101 */
908 this->BuildISupport();
910 printf("\nInspIRCd is now running!\n");
919 /* Add the listening sockets used for client inbound connections
920 * to the socket engine
922 for (int count = 0; count < stats->BoundPortCount; count++)
923 SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
925 this->WritePID(Config->PID);
927 /* main loop, this never returns */
933 DoOneIteration(true);
935 /* This is never reached -- we hope! */
939 /**********************************************************************************/
942 * An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
945 int main(int argc, char** argv)
947 /* TEST SUITE FOR TOKENSTREAM
951 * String: 'PRIVMSG #test FOO BAR'
952 * Token 0 = 'PRIVMSG'
956 * String: 'PRIVMSG #test :FOO BAR BAZ'
957 * Token 0 = 'PRIVMSG'
959 * Token 2 = 'FOO BAR BAZ'
960 * String: ':PRIVMSG #test :FOO BAR BAZ'
961 * Token 0 = ':PRIVMSG'
963 * Token 0 = 'AAAAAAA'
967 std::string a = "PRIVMSG #test FOO BAR";
968 printf("String: '%s'\n",a.c_str());
969 irc::tokenstream test(a);
970 printf("Token 0 = '%s'\n",test.GetToken().c_str());
971 printf("Token 1 = '%s'\n",test.GetToken().c_str());
972 printf("Token 2 = '%s'\n",test.GetToken().c_str());
973 printf("Token 3 = '%s'\n",test.GetToken().c_str());
974 printf("Token 4 = '%s'\n",test.GetToken().c_str());
976 std::string b = "PRIVMSG #test :FOO BAR BAZ";
977 printf("String: '%s'\n",b.c_str());
978 irc::tokenstream test2(b);
979 printf("Token 0 = '%s'\n",test2.GetToken().c_str());
980 printf("Token 1 = '%s'\n",test2.GetToken().c_str());
981 printf("Token 2 = '%s'\n",test2.GetToken().c_str());
982 printf("Token 3 = '%s'\n",test2.GetToken().c_str());
984 std::string c = ":PRIVMSG #test :FOO BAR BAZ";
985 printf("String: '%s'\n",c.c_str());
986 irc::tokenstream test3(c);
987 printf("Token 0 = '%s'\n",test3.GetToken().c_str());
990 printf("String: '%s'\n",c.c_str());
991 irc::tokenstream test4(c);
992 printf("Token 0 = '%s'\n",test4.GetToken().c_str());
993 printf("Token 1 = '%s'\n",test4.GetToken().c_str());
996 printf("String: '%s'\n",c.c_str());
997 irc::tokenstream test5(c);
998 printf("Token 0 = '%s'\n",test5.GetToken().c_str());
1004 ServerInstance = new InspIRCd(argc, argv);
1005 ServerInstance->Run();
1006 DELETE(ServerInstance);
1008 catch (std::bad_alloc)
1010 log(DEFAULT,"You are out of memory! (got exception std::bad_alloc!)");
1011 send_error("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
1012 printf("Out of memory! (got exception std::bad_alloc!");