Example #1
0
std::vector<CChan*> CIRCNetwork::FindChans(const CString& sWild) const {
    std::vector<CChan*> vChans;
    vChans.reserve(m_vChans.size());
    const CString sLower = sWild.AsLower();
    for (CChan* pChan : m_vChans) {
        if (pChan->GetName().AsLower().WildCmp(sLower)) vChans.push_back(pChan);
    }
    return vChans;
}
Example #2
0
	bool ChannelMatches(const CString& sChan) const {
		for (set<CString>::const_iterator it = m_ssChans.begin(); it != m_ssChans.end(); ++it) {
			if (sChan.AsLower().WildCmp(*it)) {
				return true;
			}
		}

		return false;
	}
Example #3
0
	virtual void OnNick(const CNick& OldNick, const CString& sNewNick, const vector<CChan*>& vChans) {
		// Update the queue with nick changes
		MCString::iterator it = m_msQueue.find(OldNick.GetNick().AsLower());

		if (it != m_msQueue.end()) {
			m_msQueue[sNewNick.AsLower()] = it->second;
			m_msQueue.erase(it);
		}
	}
Example #4
0
std::vector<CQuery*> CIRCNetwork::FindQueries(const CString& sWild) const {
	std::vector<CQuery*> vQueries;
	vQueries.reserve(m_vQueries.size());
	const CString sLower = sWild.AsLower();
	for (CQuery* pQuery : m_vQueries) {
		if (pQuery->GetName().AsLower().WildCmp(sLower))
			vQueries.push_back(pQuery);
	}
	return vQueries;
}
Example #5
0
    bool AddKey(CUser* pUser, const CString& sKey) {
        const pair<SCString::const_iterator, bool> pair =
            m_PubKeys[pUser->GetUserName()].insert(sKey.AsLower());

        if (pair.second) {
            Save();
        }

        return pair.second;
    }
Example #6
0
bool CString::WildCmp(const CString& sWild, const CString& sString, CaseSensitivity cs) {
	// avoid a copy when cs == CaseSensitive (C++ deliberately specifies that binding
	// a temporary object to a reference to const on the stack lengthens the lifetime
	// of the temporary to the lifetime of the reference itself)
	const CString& sWld = (cs == CaseSensitive ? sWild : sWild.AsLower());
	const CString& sStr = (cs == CaseSensitive ? sString : sString.AsLower());

	// Written by Jack Handy - jakkhandy@hotmail.com
	const char *wild = sWld.c_str(), *CString = sStr.c_str();
	const char *cp = nullptr, *mp = nullptr;

	while ((*CString) && (*wild != '*')) {
		if ((*wild != *CString) && (*wild != '?')) {
			return false;
		}

		wild++;
		CString++;
	}

	while (*CString) {
		if (*wild == '*') {
			if (!*++wild) {
				return true;
			}

			mp = wild;
			cp = CString+1;
		} else if ((*wild == *CString) || (*wild == '?')) {
			wild++;
			CString++;
		} else {
			wild = mp;
			CString = cp++;
		}
	}

	while (*wild == '*') {
		wild++;
	}

	return (*wild == 0);
}
Example #7
0
	bool SendIRCMsgToSkype(const CString& a_nick, const CString& a_channel, const CString& a_message)
	{
		if(m_chanNameMap.find(a_channel.AsLower()) != m_chanNameMap.end() && !a_message.empty())
		{
			CString l_message = stripIRCColorCodes(a_message);

			if(!IsStrValidUTF8(l_message))
			{
				l_message = AnsiToUtf8(l_message);
			}

			if(!a_nick.empty())
			{
				l_message = "<" + a_nick + "> " + l_message;
			}

			return SendSkypeCommand("CHATMESSAGE " + m_chanNameMap[a_channel.AsLower()] + " " + l_message);
		}
		return false;
	}
Example #8
0
	void DelUser(const CString& sUser) {
		map<CString, CAutoVoiceUser*>::iterator it = m_msUsers.find(sUser.AsLower());

		if (it == m_msUsers.end()) {
			PutModule("That user does not exist");
			return;
		}

		delete it->second;
		m_msUsers.erase(it);
		PutModule("User [" + sUser + "] removed");
	}
Example #9
0
	void OnDelKeyCommand(const CString& sCommand) {
		CString sTarget = sCommand.Token(1);

		if (!sTarget.empty()) {
			if (DelNV(sTarget.AsLower())) {
				PutModule("Target [" + sTarget + "] deleted");
			} else {
				PutModule("Target [" + sTarget + "] not found");
			}
		} else {
			PutModule("Usage DelKey <#chan|Nick>");
		}
	}
Example #10
0
	void OnSetKeyCommand(const CString& sCommand) {
		CString sTarget = sCommand.Token(1);
		CString sKey = sCommand.Token(2, true);

		// Strip "cbc:" from beginning of string incase someone pastes directly from mircryption
		sKey.TrimPrefix("cbc:");

		if (!sKey.empty()) {
			SetNV(sTarget.AsLower(), sKey);
			PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
		} else {
			PutModule("Usage: SetKey <#chan|Nick> <Key>");
		}
	}
Example #11
0
	void FilterIncoming(const CString& sTarget, CNick& Nick, CString& sMessage) {
		if (sMessage.TrimPrefix("+OK *")) {
			MCString::iterator it = FindNV(sTarget.AsLower());

			if (it != EndNV()) {
				sMessage.Base64Decode();
				sMessage.Decrypt(it->second);
				sMessage.LeftChomp(8);
				sMessage = sMessage.c_str();
				Nick.SetNick(NickPrefix() + Nick.GetNick());
			}
		}

	}
Example #12
0
    CString GetKey(Csock* pSock) {
        CString sRes;
        long int res = pSock->GetPeerFingerprint(sRes);

        DEBUG("GetKey() returned status " << res << " with key " << sRes);

        // This is 'inspired' by charybdis' libratbox
        switch (res) {
            case X509_V_OK:
            case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
            case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
            case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
                return sRes.AsLower();
            default:
                return "";
        }
    }
Example #13
0
	EModRet OnUserTopic(CString& sTarget, CString& sMessage) override {
		sTarget.TrimPrefix(NickPrefix());

		if (sMessage.TrimPrefix("``")) {
			return CONTINUE;
		}

		MCString::iterator it = FindNV(sTarget.AsLower());

		if (it != EndNV()) {
			sMessage = MakeIvec() + sMessage;
			sMessage.Encrypt(it->second);
			sMessage.Base64Encode();
			sMessage = "+OK *" + sMessage;
		}

		return CONTINUE;
	}
Example #14
0
    bool SendNotification(CNick& Nick, CString& sMessage){
        /*
         * Being passed in the nick name and the message, return true if an
         * email notification should be sent to the user or not. At the moment
         * this is a simple test that checks for a case insenstive username
         * match which is a bit flawed as 1d0ugal1 still matches d0ugal.
         */

        // Don't send notifications if DebugMode is off and the ConnectedUser is not attached.
        if (!DebugMode && ConnectedUser->IsUserAttached()){
            return false;
        }

        CString UserNick = ConnectedUser->GetNick().AsLower();

        size_t found = sMessage.AsLower().find(UserNick);

        if (found!=string::npos){
            return true;
        } else {
            return false;
        }

    }
Example #15
0
// Config Parser. Might drop this.
bool CConfig::Parse(CFile& file, CString& sErrorMsg)
{
	CString sLine;
	unsigned int uLineNum = 0;
	CConfig *pActiveConfig = this;
	std::stack<ConfigStackEntry> ConfigStack;
	bool bCommented = false;     // support for /**/ style comments

	if (!file.Seek(0)) {
		sErrorMsg = "Could not seek to the beginning of the config.";
		return false;
	}

	while (file.ReadLine(sLine)) {
		uLineNum++;

#define ERROR(arg) do { \
	std::stringstream stream; \
	stream << "Error on line " << uLineNum << ": " << arg; \
	sErrorMsg = stream.str(); \
	m_SubConfigs.clear(); \
	m_ConfigEntries.clear(); \
	return false; \
} while (0)

		// Remove all leading spaces and trailing line endings
		sLine.TrimLeft();
		sLine.TrimRight("\r\n");

		if (bCommented || sLine.Left(2) == "/*") {
			/* Does this comment end on the same line again? */
			bCommented = (sLine.Right(2) != "*/");

			continue;
		}

		if ((sLine.empty()) || (sLine[0] == '#') || (sLine.Left(2) == "//")) {
			continue;
		}

		if ((sLine.Left(1) == "<") && (sLine.Right(1) == ">")) {
			sLine.LeftChomp();
			sLine.RightChomp();
			sLine.Trim();

			CString sTag = sLine.Token(0);
			CString sValue = sLine.Token(1, true);

			sTag.Trim();
			sValue.Trim();

			if (sTag.Left(1) == "/") {
				sTag = sTag.substr(1);

				if (!sValue.empty())
					ERROR("Malformated closing tag. Expected \"</" << sTag << ">\".");
				if (ConfigStack.empty())
					ERROR("Closing tag \"" << sTag << "\" which is not open.");

				const struct ConfigStackEntry& entry = ConfigStack.top();
				CConfig myConfig(entry.Config);
				CString sName(entry.sName);

				if (!sTag.Equals(entry.sTag))
					ERROR("Closing tag \"" << sTag << "\" which is not open.");

				// This breaks entry
				ConfigStack.pop();

				if (ConfigStack.empty())
					pActiveConfig = this;
				else
					pActiveConfig = &ConfigStack.top().Config;

				SubConfig &conf = pActiveConfig->m_SubConfigs[sTag.AsLower()];
				SubConfig::const_iterator it = conf.find(sName);

				if (it != conf.end())
					ERROR("Duplicate entry for tag \"" << sTag << "\" name \"" << sName << "\".");

				conf[sName] = CConfigEntry(myConfig);
			} else {
				if (sValue.empty())
					ERROR("Empty block name at begin of block.");
				ConfigStack.push(ConfigStackEntry(sTag.AsLower(), sValue));
				pActiveConfig = &ConfigStack.top().Config;
			}

			continue;
		}

		// If we have a regular line, figure out where it goes
		CString sName = sLine.Token(0, false, "=");
		CString sValue = sLine.Token(1, true, "=");

		// Only remove the first space, people might want
		// leading spaces (e.g. in the MOTD).
		if (sValue.Left(1) == " ")
			sValue.LeftChomp();

		// We don't have any names with spaces, trim all
		// leading/trailing spaces.
		sName.Trim();

		if (sName.empty() || sValue.empty())
			ERROR("Malformed line");

		CString sNameLower = sName.AsLower();
		pActiveConfig->m_ConfigEntries[sNameLower].push_back(sValue);
	}

	if (bCommented)
		ERROR("Comment not closed at end of file.");

	if (!ConfigStack.empty()) {
		const CString& sTag = ConfigStack.top().sTag;
		ERROR("Not all tags are closed at the end of the file. Inner-most open tag is \"" << sTag << "\".");
	}

	return true;
}
Example #16
0
TEST(StringTest, Case) {
	CString x = CS("xx");
	CString X = CS("XX");
	EXPECT_EQ(X, x.AsUpper());
	EXPECT_EQ(x, X.AsLower());
}