Logo Search packages:      
Sourcecode: sbnc version File versions  Download package

CCore::CCore ( CConfig Config,
int  argc,
char **  argv,
bool  Daemonized 
)

CCore

Creates a new shroudBNC application object.

Parameters:
Config the main config object
argc argument counts
argv program arguments

Definition at line 58 of file Core.cpp.

References AddHostAllow(), BuildPath(), CLog::Clear(), CConfigModule::CreateConfigObject(), Fatal(), CConfigModule::GetError(), CConfigModule::Init(), Log(), m_Args, m_Config, m_ConfigModule, m_Daemonized, m_Ident, m_ListenerV6, m_LoadingListeners, m_LoadingModules, m_Log, m_PollFds, m_SSLContext, m_SSLListenerV6, m_Startup, m_Status, m_Users, MakeConfig(), CVector< Type >::Preallocate(), CConfig::ReadString(), and CVector< Type >::SetList().

                                                                    {
      int i;
      char *Out;
      const char *Hostmask;

      m_Daemonized = Daemonized;

      m_OriginalConfig = Config;

      m_SSLContext = NULL;

      m_Status = STATUS_RUN;

      CacheInitialize(m_ConfigCache, Config, "system.");

      char *SourcePath = strdup(BuildPath("sbnc.log"));
      rename(SourcePath, BuildPath("sbnc.log.old"));
      free(SourcePath);

      m_PollFds.Preallocate(SFD_SETSIZE);

      m_Log = new CLog("sbnc.log", true);

      if (m_Log == NULL) {
            safe_printf("Log system could not be initialized. Shutting down.");

            exit(EXIT_FAILURE);
      }

      m_Log->Clear();
      Log("Log system initialized.");

      g_Bouncer = this;

      m_Config = Config;

      m_Args.SetList(argv, argc);

      m_Ident = new CIdentSupport();

      const char *ConfigModule = m_Config->ReadString("system.configmodule");

      m_ConfigModule = new CConfigModule(ConfigModule);

      CResult<bool> Error = m_ConfigModule->GetError();

      if (IsError(Error)) {
            LOGERROR(GETDESCRIPTION(Error));

            Fatal();
      }

      m_ConfigModule->Init(this);

      m_Config = m_ConfigModule->CreateConfigObject("sbnc.conf", NULL);
      CacheInitialize(m_ConfigCache, m_Config, "system.");

      const char *Users;
      CUser *User;

      if ((Users = m_Config->ReadString("system.users")) == NULL) {
            if (IsDaemonized()) {
                  LOGERROR("Configuration file does not contain any users. please re-run shroudBNC with --foreground");

                  Fatal();
            }

            if (!MakeConfig()) {
                  LOGERROR("Configuration file could not be created.");

                  Fatal();
            }

            safe_print("Configuration has been successfully saved. Please restart shroudBNC now.\n");
            safe_exit(0);
      }

      const char *Args;
      int Count;

      Args = ArgTokenize(Users);

      CHECK_ALLOC_RESULT(Args, ArgTokenize) {
            Fatal();
      } CHECK_ALLOC_RESULT_END;

      Count = ArgCount(Args);

      safe_box_t UsersBox = safe_put_box(NULL, "Users");

      for (i = 0; i < Count; i++) {
            safe_box_t UserBox = NULL;
            const char *Name = ArgGet(Args, i + 1);

            if (UsersBox != NULL) {
                  UserBox = safe_put_box(UsersBox, Name);
            }

            User = new CUser(Name, UserBox);

            CHECK_ALLOC_RESULT(User, new) {
                  Fatal();
            } CHECK_ALLOC_RESULT_END;

            m_Users.Add(Name, User);
      }

      ArgFree(Args);

      m_Listener = NULL;
      m_ListenerV6 = NULL;
      m_SSLListener = NULL;
      m_SSLListenerV6 = NULL;

      time(&m_Startup);

      i = 0;
      while (true) {
            asprintf(&Out, "system.hosts.host%d", i++);

            CHECK_ALLOC_RESULT(Out, asprintf) {
                  Fatal();
            } CHECK_ALLOC_RESULT_END;

            Hostmask = m_Config->ReadString(Out);

            free(Out);

            if (Hostmask != NULL) {
                  AddHostAllow(Hostmask, false);
            } else {
                  break;
            }
      }

      m_LoadingModules = false;
      m_LoadingListeners = false;
}


Generated by  Doxygen 1.6.0   Back to index