Browse Source

Removed Jupiter::IRC::Client::Config

release/0.19
Jessica James 9 years ago
parent
commit
f52413a0f8
  1. 114
      Jupiter/IRC_Client.cpp
  2. 53
      Jupiter/IRC_Client.h
  3. BIN
      Release/Jupiter.lib

114
Jupiter/IRC_Client.cpp

@ -40,9 +40,6 @@
using namespace Jupiter::literals; using namespace Jupiter::literals;
Jupiter::INIFile _Config;
Jupiter::INIFile *Jupiter::IRC::Client::Config = &_Config;
template class JUPITER_API Jupiter::Reference_String<char>; template class JUPITER_API Jupiter::Reference_String<char>;
template class JUPITER_API Jupiter::String_Strict<char>; template class JUPITER_API Jupiter::String_Strict<char>;
template class JUPITER_API Jupiter::CString_Type<char>; template class JUPITER_API Jupiter::CString_Type<char>;
@ -59,7 +56,9 @@ struct JUPITER_API Jupiter::IRC::Client::Data
Jupiter::StringS saslAccount; Jupiter::StringS saslAccount;
Jupiter::StringS saslPass; Jupiter::StringS saslPass;
int connectionStatus; int connectionStatus;
Jupiter::StringS configSectionName; Jupiter::StringS primary_section_name;
const Jupiter::INIFile::Section *primary_section;
const Jupiter::INIFile::Section *secondary_section;
Jupiter::CStringS logFileName; Jupiter::CStringS logFileName;
Jupiter::StringS last_line; Jupiter::StringS last_line;
unsigned short serverPort; unsigned short serverPort;
@ -133,15 +132,16 @@ struct Jupiter::IRC::Client::Channel::Data
bool isAddingNames; bool isAddingNames;
}; };
Jupiter::IRC::Client::Client(const Jupiter::ReadableString &configSection) Jupiter::IRC::Client::Client(const Jupiter::INIFile::Section *in_primary_section, const Jupiter::INIFile::Section *in_secondary_section)
{ {
Jupiter::IRC::Client::data_ = new Jupiter::IRC::Client::Data(this); Jupiter::IRC::Client::data_ = new Jupiter::IRC::Client::Data(this);
if (Jupiter::IRC::Client::Config == nullptr)
{ Jupiter::IRC::Client::data_->primary_section = in_primary_section;
Jupiter::IRC::Client::Config = new INIFile(); Jupiter::IRC::Client::data_->secondary_section = in_secondary_section;
Jupiter::IRC::Client::Config->readFile(CONFIG_INI);
} if (Jupiter::IRC::Client::data_->primary_section != nullptr)
Jupiter::IRC::Client::data_->configSectionName = configSection; Jupiter::IRC::Client::data_->primary_section_name = Jupiter::IRC::Client::data_->primary_section->getName();
Jupiter::IRC::Client::data_->serverHostname = Jupiter::IRC::Client::readConfigValue("Hostname"_jrs, "irc.cncirc.net"_jrs); Jupiter::IRC::Client::data_->serverHostname = Jupiter::IRC::Client::readConfigValue("Hostname"_jrs, "irc.cncirc.net"_jrs);
Jupiter::IRC::Client::data_->logFileName = Jupiter::IRC::Client::readConfigValue("LogFile"_jrs); Jupiter::IRC::Client::data_->logFileName = Jupiter::IRC::Client::readConfigValue("LogFile"_jrs);
@ -302,7 +302,35 @@ void Jupiter::IRC::Client::OnMode(const Jupiter::ReadableString &, const Jupiter
const Jupiter::ReadableString &Jupiter::IRC::Client::getConfigSection() const const Jupiter::ReadableString &Jupiter::IRC::Client::getConfigSection() const
{ {
return Jupiter::IRC::Client::data_->configSectionName; if (Jupiter::IRC::Client::data_->primary_section != nullptr)
return Jupiter::IRC::Client::data_->primary_section_name;
return Jupiter::ReferenceString::empty;
}
const Jupiter::INIFile::Section *Jupiter::IRC::Client::getPrimaryConfigSection() const
{
return Jupiter::IRC::Client::data_->primary_section;
}
const Jupiter::INIFile::Section *Jupiter::IRC::Client::getSecondaryConfigSection() const
{
return Jupiter::IRC::Client::data_->primary_section;
}
void Jupiter::IRC::Client::setPrimaryConfigSection(const Jupiter::INIFile::Section *in_primary_section)
{
Jupiter::IRC::Client::data_->primary_section = in_primary_section;
if (Jupiter::IRC::Client::data_->primary_section != nullptr)
Jupiter::IRC::Client::data_->primary_section_name = Jupiter::IRC::Client::data_->primary_section->getName();
else
Jupiter::IRC::Client::data_->primary_section_name.erase();
}
void Jupiter::IRC::Client::setSecondaryConfigSection(const Jupiter::INIFile::Section *in_secondary_section)
{
Jupiter::IRC::Client::data_->secondary_section = in_secondary_section;
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::getLogFile() const const Jupiter::ReadableString &Jupiter::IRC::Client::getLogFile() const
@ -1387,42 +1415,82 @@ int Jupiter::IRC::Client::think()
const Jupiter::ReadableString &Jupiter::IRC::Client::readConfigValue(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue) const const Jupiter::ReadableString &Jupiter::IRC::Client::readConfigValue(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue) const
{ {
const Jupiter::ReadableString &val = Jupiter::IRC::Client::Config->get(Jupiter::IRC::Client::data_->configSectionName, key); if (Jupiter::IRC::Client::data_->primary_section != nullptr)
{
const Jupiter::ReadableString &val = Jupiter::IRC::Client::data_->primary_section->get(key);
if (val.isNotEmpty()) if (val.isNotEmpty())
return val; return val;
return Jupiter::IRC::Client::Config->get("Default"_jrs, key, defaultValue); }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->get(key, defaultValue);
return defaultValue;
} }
bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bool defaultValue) const bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bool defaultValue) const
{ {
const Jupiter::ReadableString &val = Jupiter::IRC::Client::Config->get(Jupiter::IRC::Client::data_->configSectionName, key); if (Jupiter::IRC::Client::data_->primary_section != nullptr)
{
const Jupiter::ReadableString &val = Jupiter::IRC::Client::data_->primary_section->get(key);
if (val.isNotEmpty()) if (val.isNotEmpty())
return val.asBool(); return val.asBool();
return Jupiter::IRC::Client::Config->getBool("Default"_jrs, key, defaultValue); }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getBool(key, defaultValue);
return defaultValue;
} }
int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int defaultValue) const int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int defaultValue) const
{ {
const Jupiter::ReadableString &val = Jupiter::IRC::Client::Config->get(Jupiter::IRC::Client::data_->configSectionName, key); if (Jupiter::IRC::Client::data_->primary_section != nullptr)
{
const Jupiter::ReadableString &val = Jupiter::IRC::Client::data_->primary_section->get(key);
if (val.isNotEmpty()) if (val.isNotEmpty())
return val.asInt(); return val.asInt();
return Jupiter::IRC::Client::Config->getInt("Default"_jrs, key, defaultValue); }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getInt(key, defaultValue);
return defaultValue;
} }
long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, long defaultValue) const long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, long defaultValue) const
{ {
const Jupiter::ReadableString &val = Jupiter::IRC::Client::Config->get(Jupiter::IRC::Client::data_->configSectionName, key); if (Jupiter::IRC::Client::data_->primary_section != nullptr)
{
const Jupiter::ReadableString &val = Jupiter::IRC::Client::data_->primary_section->get(key);
if (val.isNotEmpty()) if (val.isNotEmpty())
return val.asInt(); return val.asInt();
return Jupiter::IRC::Client::Config->getInt("Default"_jrs, key, defaultValue); }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getLong(key, defaultValue);
return defaultValue;
} }
double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key, double defaultValue) const double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key, double defaultValue) const
{ {
const Jupiter::ReadableString &val = Jupiter::IRC::Client::Config->get(Jupiter::IRC::Client::data_->configSectionName, key); if (Jupiter::IRC::Client::data_->primary_section != nullptr)
{
const Jupiter::ReadableString &val = Jupiter::IRC::Client::data_->primary_section->get(key);
if (val.isNotEmpty()) if (val.isNotEmpty())
return val.asDouble(); return val.asDouble();
return Jupiter::IRC::Client::Config->getDouble("Default"_jrs, key, defaultValue); }
if (Jupiter::IRC::Client::data_->secondary_section != nullptr)
return Jupiter::IRC::Client::data_->secondary_section->getDouble(key, defaultValue);
return defaultValue;
} }
void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message)
@ -1519,7 +1587,7 @@ bool Jupiter::IRC::Client::Data::startCAP()
Jupiter::IRC::Client::Data::connectionStatus = 2; Jupiter::IRC::Client::Data::connectionStatus = 2;
return Jupiter::IRC::Client::Data::sock->send("CAP LS" ENDL, 8) > 0; return Jupiter::IRC::Client::Data::sock->send("CAP LS" ENDL, 8) > 0;
} }
//Jupiter::ReferenceString &
bool Jupiter::IRC::Client::Data::registerClient() bool Jupiter::IRC::Client::Data::registerClient()
{ {
bool r = true; bool r = true;

53
Jupiter/IRC_Client.h

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2015 Jessica James. * Copyright (C) 2013-2016 Jessica James.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -30,21 +30,17 @@
#include "Thinker.h" #include "Thinker.h"
#include "IRC.h" #include "IRC.h"
#include "Reference_String.h" #include "Reference_String.h"
#include "INIFile.h"
#define CONFIG_INI "Config.ini" /** Default location of the Config file. */
namespace Jupiter namespace Jupiter
{ {
class INIFile; /** Forward declaration for Jupiter::INIFile. See Jupiter::INIFile in INIFile.h. */
namespace IRC namespace IRC
{ {
/** /**
* @brief Provides connectivity to IRC servers. * @brief Provides connectivity to IRC servers.
*/ */
class JUPITER_API Client : public Thinker class JUPITER_API Client : public Jupiter::Thinker
{ {
protected: protected:
@ -198,8 +194,6 @@ namespace Jupiter
*/ */
virtual void OnMode(const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &modeString); virtual void OnMode(const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &modeString);
public: public:
static INIFile *Config; /** IRC client config file. This is automatically instantiated upon library initialization. */
class Channel; class Channel;
/** /**
@ -474,12 +468,42 @@ namespace Jupiter
}; // Jupiter::IRC::Client::Channel class }; // Jupiter::IRC::Client::Channel class
/** /**
* @brief Returns the config section this refers to. * @brief Returns the name of the primary config section this client reads from.
* *
* @return String containing a config section. * @return String containing a config section's name.
*/ */
const Jupiter::ReadableString &getConfigSection() const; const Jupiter::ReadableString &getConfigSection() const;
/**
* @brief Fetches the primary config section
*
* @return The primary config section if it exists, nullptr otherwise.
*/
const Jupiter::INIFile::Section *getPrimaryConfigSection() const;
/**
* @brief Fetches the primary config section
*
* @return The primary config section if it exists, nullptr otherwise.
*/
const Jupiter::INIFile::Section *getSecondaryConfigSection() const;
/**
* @brief Sets the primary config section
* Note: This is useful when the higher config file is reloaded
*
* @param in_primary_section Primary config section to begin using
*/
virtual void setPrimaryConfigSection(const Jupiter::INIFile::Section *in_primary_section);
/**
* @brief Sets the secondary config section
* Note: This is useful when the higher config file is reloaded
*
* @param in_secondary_section Secondary config section to begin using
*/
virtual void setSecondaryConfigSection(const Jupiter::INIFile::Section *in_secondary_section);
/** /**
* @brief Returns the name of the file this logs to. * @brief Returns the name of the file this logs to.
* *
@ -855,14 +879,15 @@ namespace Jupiter
* *
* @return 0 if the client should still exist, error code otherwise. * @return 0 if the client should still exist, error code otherwise.
*/ */
virtual int think(); virtual int think() override;
/** /**
* @brief Constructor for a client. * @brief Constructor for a client.
* *
* @param configSection String containing the config section for the client to read from, before defaulting to "Default". * @param in_primary_section INIFile section to search first for a configuration option
* @param in_secondary_section INIFile section to search second for a configuration, before using a pre-defined default value
*/ */
Client(const Jupiter::ReadableString &configSection); Client(const Jupiter::INIFile::Section *in_primary_section, const Jupiter::INIFile::Section *in_secondary_section);
/** /**
* @brief Destructor for a client. * @brief Destructor for a client.

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save