LegacySymmetricProvider::Mode LegacySymmetricProvider::StringToMode(
    const String& Mode)
{
    if (Mode.Compare("aes-128-cbc"))
        return LegacySymmetricProvider::AES_128_CBC;
    if (Mode.Compare("aes-256-cbc"))
        return LegacySymmetricProvider::AES_256_CBC;
    if (Mode.Compare("aes-256-ecb"))
        return LegacySymmetricProvider::AES_256_ECB;
    if (Mode.Compare("aes-128-gcm"))
        return LegacySymmetricProvider::AES_128_GCM;
    if (Mode.Compare("aes-256-gcm"))
        return LegacySymmetricProvider::AES_256_GCM;
    return LegacySymmetricProvider::ERROR_MODE;
}
Esempio n. 2
0
VcfInd::VcfInd(const String& indID, const String& famID, const String& fatID, const String& motID, const String& gender) {
  sIndID = indID;
  sFamID = famID;
  sFatID = (famID.Length() == 0) ? "0" : famID;
  sMotID = (motID.Length() == 0) ? "0" : motID;
  if ( gender.Compare("1") == 0 ) {
    this->gender = MALE;
  }
  else if ( gender.Compare("2") == 0 ) {
    this->gender = FEMALE;
  }
  else {
    this->gender = UNKNOWN;
  }
}
Esempio n. 3
0
bool Settings::Check_bool(const String& strSection, const String& strKey,
                            bool& out_bResult, bool& out_bKeyExist) const
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strSection.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Blank!\n";
        OT_FAIL;
    }

    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strKey.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Blank!\n";
        OT_FAIL;
    }

    const char* szVar =
        pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr);
    String strVar(szVar);

    if (strVar.Exists() &&
        (strVar.Compare("false") || strVar.Compare("true"))) {
        out_bKeyExist = true;
        if (strVar.Compare("true"))
            out_bResult = true;
        else
            out_bResult = false;
    }
    else {
        out_bKeyExist = false;
        out_bResult = false;
    }

    return true;
}
Esempio n. 4
0
int32_t OTMasterkey::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
    int32_t nReturnVal = ot_super::ProcessXMLNode(xml);

    // Here we call the parent class first.
    // If the node is found there, or there is some error,
    // then we just return either way.  But if it comes back
    // as '0', then nothing happened, and we'll continue executing.
    //
    // -- Note you can choose not to call the parent if
    // you don't want to use any of those xml tags.
    // As I do in the case of OTAccount.
    //
    if (0 != nReturnVal) return nReturnVal;
    // else it was 0 (continue...)

    const String strNodeName(xml->getNodeName());

    if (strNodeName.Compare("masterCredential")) {
        m_strNymID = xml->getAttributeValue("nymID");

        m_strMasterCredID.Release();

        otWarn << "Loading masterCredential...\n";

        nReturnVal = 1;
    }

    return nReturnVal;
}
Esempio n. 5
0
bool Settings::LogChange_str(const String& strSection, const String& strKey,
                               const String& strValue)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szValue = (strValue.Exists() && !strValue.Compare(""))
                                    ? strValue.Get()
                                    : "nullptr";

    String strCategory, strOption;
    if (!Log::StringFill(strCategory, strSection.Get(), 12)) return false;
    if (!Log::StringFill(strOption, strKey.Get(), 30, " to:")) return false;

    otWarn << "Setting " << strCategory << " " << strOption << " " << szValue
           << " \n";
    return true;
}
Esempio n. 6
0
bool Settings::CheckSetSection(const String& strSection,
                                 const String& strComment,
                                 bool& out_bIsNewSection)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strComment.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strComment"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szComment =
        (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
                                                         : nullptr;

    const int64_t lSectionSize =
        pvt->iniSimple.GetSectionSize(strSection.Get());

    if (1 > lSectionSize) {
        out_bIsNewSection = true;
        SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), nullptr,
                                              nullptr, szComment, false);
        if (0 > rc) return false;
    }
    else {
        out_bIsNewSection = false;
    }
    return true;
}
Esempio n. 7
0
int VcfFile::getSampleIndex(const String& name) {
  for(int i=0; i < (int)vpVcfInds.size(); ++i) {
    if ( name.Compare(vpVcfInds[i]->sIndID) == 0 ) {
      return i;
    }
  }
  return -1;
}
Esempio n. 8
0
void VcfMarker::setQual(const String& s) {
  if ( s.Compare(".") == 0 ) {
    fQual = -1;
  }
  else {
    fQual = atof(s.c_str());
  }
}
originType OTTransactionType::GetOriginTypeFromString(const String& strType)
{
    originType theType = originType::origin_error_state;

    if (strType.Compare("not_applicable"))
        theType = originType::not_applicable;
    else if (strType.Compare("origin_market_offer"))
        theType = originType::origin_market_offer;
    else if (strType.Compare("origin_payment_plan"))
        theType = originType::origin_payment_plan;
    else if (strType.Compare("origin_smart_contract"))
        theType = originType::origin_smart_contract;
    else if (strType.Compare("origin_pay_dividend"))
        theType = originType::origin_pay_dividend;
    else
        theType = originType::origin_error_state;

    return theType;
}
Esempio n. 10
0
bool Settings::CheckSet_str(const String& strSection, const String& strKey,
                              const String& strDefault, std::string& out_strResult,
                              bool& out_bIsNew, const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szDefault =
        (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get()
                                                         : nullptr;

    String strTempResult;
    bool bKeyExist;
    if (!Check_str(strSection, strKey, strTempResult, bKeyExist)) return false;

    if (bKeyExist) {
        // Already have a key, lets use it's value.
        out_bIsNew = false;
        out_strResult = strTempResult.Get();
        return true;
    }
    else {
        bool bNewKeyCheck;
        if (!Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
            return false;

        if (nullptr == szDefault) // The Default is to have no key.
        {
            // Success
            out_bIsNew = false;
            out_strResult = "";
            return true;
        }

        if (bNewKeyCheck) {
            // Success
            out_bIsNew = true;
            out_strResult = strDefault.Get();
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Esempio n. 11
0
   void
   Base64Tester::Test()
   {
      String s;

      AnsiString input = "Test";
      s = Base64::Encode(input.GetBuffer(), input.GetLength());
      if (s.Compare(_T("VGVzdA==")) != 0)
         throw;

      input = "Test test test test test test test!!!!";
      s = Base64::Encode(input, input.GetLength());
      if (s.Compare(_T("VGVzdCB0ZXN0IHRlc3QgdGVzdCB0ZXN0IHRlc3QgdGVzdCEhISE=")) != 0)
         throw;

      input = "hMailServer is a free e-mail server for Microsoft Windows. It's used by Internet service providers, companies, governments, schools and enthusiasts in all parts of the world. It supports the common e-mail protocols (IMAP, SMTP and POP3) and can easily be integrated with many existing web mail systems. It has flexible score-based spam protection and can attach to your virus scanner to scan all incoming and outgoing email.";
      s = Base64::Encode(input, input.GetLength());
      if (s.Compare(_T("aE1haWxTZXJ2ZXIgaXMgYSBmcmVlIGUtbWFpbCBzZXJ2ZXIgZm9yIE1pY3Jvc29mdCBXaW5kb3dzLiBJdCdzIHVzZWQgYnkgSW50ZXJuZXQgc2VydmljZSBwcm92aWRlcnMsIGNvbXBhbmllcywgZ292ZXJubWVudHMsIHNjaG9vbHMgYW5kIGVudGh1c2lhc3RzIGluIGFsbCBwYXJ0cyBvZiB0aGUgd29ybGQuIEl0IHN1cHBvcnRzIHRoZSBjb21tb24gZS1tYWlsIHByb3RvY29scyAoSU1BUCwgU01UUCBhbmQgUE9QMykgYW5kIGNhbiBlYXNpbHkgYmUgaW50ZWdyYXRlZCB3aXRoIG1hbnkgZXhpc3Rpbmcgd2ViIG1haWwgc3lzdGVtcy4gSXQgaGFzIGZsZXhpYmxlIHNjb3JlLWJhc2VkIHNwYW0gcHJvdGVjdGlvbiBhbmQgY2FuIGF0dGFjaCB0byB5b3VyIHZpcnVzIHNjYW5uZXIgdG8gc2NhbiBhbGwgaW5jb21pbmcgYW5kIG91dGdvaW5nIGVtYWlsLg==")) != 0)
         throw;

      input = "VGVzdA==";
      s = Base64::Decode(input, input.GetLength());
      if (s.Compare(_T("Test")) != 0)
         throw;

      input = "VGVzdCB0ZXN0IHRlc3QgdGVzdCB0ZXN0IHRlc3QgdGVzdCEhISE=";
      s = Base64::Decode(input, input.GetLength());
      if (s.Compare(_T("Test test test test test test test!!!!")) != 0)
         throw;

      input = "aE1haWxTZXJ2ZXIgaXMgYSBmcmVlIGUtbWFpbCBzZXJ2ZXIgZm9yIE1pY3Jvc29mdCBXaW5kb3dzLiBJdCdzIHVzZWQgYnkgSW50ZXJuZXQgc2VydmljZSBwcm92aWRlcnMsIGNvbXBhbmllcywgZ292ZXJubWVudHMsIHNjaG9vbHMgYW5kIGVudGh1c2lhc3RzIGluIGFsbCBwYXJ0cyBvZiB0aGUgd29ybGQuIEl0IHN1cHBvcnRzIHRoZSBjb21tb24gZS1tYWlsIHByb3RvY29scyAoSU1BUCwgU01UUCBhbmQgUE9QMykgYW5kIGNhbiBlYXNpbHkgYmUgaW50ZWdyYXRlZCB3aXRoIG1hbnkgZXhpc3Rpbmcgd2ViIG1haWwgc3lzdGVtcy4gSXQgaGFzIGZsZXhpYmxlIHNjb3JlLWJhc2VkIHNwYW0gcHJvdGVjdGlvbiBhbmQgY2FuIGF0dGFjaCB0byB5b3VyIHZpcnVzIHNjYW5uZXIgdG8gc2NhbiBhbGwgaW5jb21pbmcgYW5kIG91dGdvaW5nIGVtYWlsLg==";
      s = Base64::Decode(input, input.GetLength());
      if (s.Compare(_T("hMailServer is a free e-mail server for Microsoft Windows. It's used by Internet service providers, companies, governments, schools and enthusiasts in all parts of the world. It supports the common e-mail protocols (IMAP, SMTP and POP3) and can easily be integrated with many existing web mail systems. It has flexible score-based spam protection and can attach to your virus scanner to scan all incoming and outgoing email.")) != 0)
         throw;
   }
Esempio n. 12
0
void InsertAlpha(StringVector &container, const String &value)
{
    if (container.Find(value) != container.End())
        return;
    for(auto iter = container.Begin(); iter != container.End(); ++iter)
    {
        if (value.Compare((*iter), false) < 0)
        {
            container.Insert(iter, value);
            return;
        }
    }
    container.Push(value);
}
Esempio n. 13
0
int VcfHelper::chromName2Num(const String & chr) {
  int n = atoi(chr.c_str());
  if ( n > 0 ) { return n; }
  else {
    String s = chr;
    if ( s.Left(3).Compare("chr") == 0 ) {
      n = atoi(s.SubStr(3).c_str());
      if ( n > 0 ) { return n; }
      s = s.SubStr(3);
    }
    for(int i=0; i < asChromNames.Length(); ++i) {
      if ( s.Compare(asChromNames[i]) == 0 ) {
	return vnChromNums[i];
      }
    }
  }
  throw VcfFileException("Cannot recognize chromosome %s",chr.c_str());
}
Esempio n. 14
0
CryptoHash::HashType CryptoHash::StringToHashType(const String& inputString)
{
    if (inputString.Compare("null"))
        return CryptoHash::NONE;
    else if (inputString.Compare("HASH256"))
        return CryptoHash::HASH256;
    else if (inputString.Compare("HASH160"))
        return CryptoHash::HASH160;
    else if (inputString.Compare("SHA224"))
        return CryptoHash::SHA224;
    else if (inputString.Compare("SHA256"))
        return CryptoHash::SHA256;
    else if (inputString.Compare("SHA384"))
        return CryptoHash::SHA384;
    else if (inputString.Compare("SHA512"))
        return CryptoHash::SHA512;
    return CryptoHash::ERROR;
}
Esempio n. 15
0
String TFrmAlarmDetailList::GetFirstWarning()
{

	String szFirstAlarm;

	String szAlarmCode = grdWarningDetail->Cells[ 1 ][ 1 ];
    String szAlarmName = grdWarningDetail->Cells[ 2 ][ 1 ];

    if( szAlarmCode.Compare( "" ) != 0 )
    {
        szFirstAlarm += "[ " + szAlarmCode + " ]" + " " + szAlarmName;
    }
    else
    {
    	szFirstAlarm = "";
    }

    return szFirstAlarm;

}
Esempio n. 16
0
bool Script::BeginCall(const String &sFunctionName, const String &sFunctionSignature, const String &sNamespace)
{
	// Is there a Lua state?
	if (m_pLuaState) {
		// Get a nested Lua table
		if (GetNestedTable(sNamespace)) {
			// Table key
			lua_pushstring(m_pLuaState, sFunctionName);	// Push the function name onto the Lua stack

			// Push the function to be called onto the Lua state stack
			lua_gettable(m_pLuaState, -2);
			if (lua_isfunction(m_pLuaState, -1)) {
				// Backup the name of the current function (we may need it for error log output)
				m_sCurrentFunction = sFunctionName;

				// Has the current function a result?
				m_bFunctionResult = !sFunctionSignature.Compare("void(", 0, 5);

				// Current argument is 0
				m_nCurrentArgument = 0;

				// Done
				return true;
			} else {
				// Error!
				if (sNamespace.GetLength())
					LogOutput(Log::Error, "The function '" + sFunctionName + "' was not found within the namespace '" + sNamespace + '\'');
				else
					LogOutput(Log::Error, "The function '" + sFunctionName + "' was not found");
			}
		} else {
			// Error!
			LogOutput(Log::Error, "The namespace '" + sNamespace + "' of the function '" + sFunctionName + "' was not found");
		}
	}

	// Error!
	return false;
}
Esempio n. 17
0
ECode CAuthorityEntry::Match(
    /* [in] */ IUri* data,
    /* [out] */ Int32* result)
{
    VALIDATE_NOT_NULL(result);

    String host;
    data->GetHost(&host);
    if (host.IsNull()) {
        *result = IntentFilter_NO_MATCH_DATA;
        return NOERROR;
    }
//    if (Config.LOGV) Log.v("IntentFilter",
//            "Match host " + host + ": " + mHost);
    if (mWild) {
        if (host.GetLength() < mHost.GetLength()) {
            *result = IntentFilter_NO_MATCH_DATA;
            return NOERROR;
        }
        host = host.Substring(host.GetLength() - mHost.GetLength());
    }
    if (host.Compare(mHost, StringCase_Insensitive) != 0) {
        *result = IntentFilter_NO_MATCH_DATA;
        return NOERROR;
    }
    if (mPort >= 0) {
        Int32 port;
        data->GetPort(&port);
        if (mPort != port) {
            *result = IntentFilter_NO_MATCH_DATA;
            return NOERROR;
        }
        *result = IntentFilter_MATCH_CATEGORY_PORT;
        return NOERROR;
    }
    *result = IntentFilter_MATCH_CATEGORY_HOST;
    return NOERROR;
}
Esempio n. 18
0
// this function dosn't change the "strRelativePath" so.  It will only fix the
// strBasePath.
// static
bool OTPaths::RelativeToCanonical(String& out_strCanonicalPath,
                                  const String& strBasePath,
                                  const String& strRelativePath)
{
    if (!strBasePath.Exists()) {
        otErr << __FUNCTION__ << ": Null: "
              << "strBasePath"
              << " passed in!\n";
        OT_FAIL;
    }
    if (!strRelativePath.Exists()) {
        otErr << __FUNCTION__ << ": Null: "
              << "strRelativePath"
              << " passed in!\n";
        OT_FAIL;
    }

    String l_strBasePath_fix("");
    if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false;

    if (strRelativePath.Compare(".")) {
        out_strCanonicalPath = strBasePath;
        return true;
    } // if ".", return base path.

    std::string l_strBasePath(l_strBasePath_fix.Get()),
        l_strRelativePath(strRelativePath.Get());

    l_strBasePath.append(l_strRelativePath);

    String l_strPath(l_strBasePath), l_strCanonicalPath("");

    if (!ToReal(l_strPath, l_strCanonicalPath)) return false;

    out_strCanonicalPath = l_strCanonicalPath;

    return true;
}
Esempio n. 19
0
void VcfMarker::setFormat(const String& s, bool upgrade) {
  // if upgrade is set, GT:GD:GQ are converted into GT:DP:GQ:PL
  if ( ( upgrade ) && ( s.Compare("GT:GD:GQ") == 0 ) ) {
    asFormatKeys.Clear();
    asFormatKeys.Add("GT");
    asFormatKeys.Add("DP");
    asFormatKeys.Add("GQ");
    asFormatKeys.Add("PL");
    GTindex = 0;
    GDindex = 1;
    GQindex = 2;
    DSindex = -1;
  }
  else {
    asFormatKeys.ReplaceColumns(s,':');
    GTindex = asFormatKeys.Find("GT");
    DSindex = asFormatKeys.Find("DS");
    GDindex = asFormatKeys.Find("DP");
    if ( GDindex < 0 ) 
      GDindex = asFormatKeys.Find("GD");
    GQindex = asFormatKeys.Find("GQ");
  }
}
Esempio n. 20
0
ECode CContentService::ObserverNode::AddObserverLocked(
    /* [in] */ ObserverNode* node,
    /* [in] */ IUri* uri,
    /* [in] */ Int32 index,
    /* [in] */ IContentObserver* observer,
    /* [in] */ Boolean notifyForDescendents)
{
    // If this is the leaf node add the observer
    if (index == CountUriSegments(uri)) {
        AutoPtr<ObserverEntry> oberverEntry = new ObserverEntry(node, observer, notifyForDescendents);
        mObservers->PushBack(oberverEntry);
        return NOERROR;
    }

    // Look to see if the proper child already exists
    String segment = GetUriSegment(uri, index);

    if (segment.IsNull()) {
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    List<AutoPtr<ObserverNode> >::Iterator it;

    for (it = mChildren->Begin(); it != mChildren->End(); it++) {
        AutoPtr<ObserverNode> pNode = *it;
        if (!segment.Compare(pNode->mName)) {
            FAIL_RETURN(pNode->AddObserverLocked(node, uri, index+1 , observer, notifyForDescendents));
            return NOERROR;
        }
    }

    // No child found, create one
    AutoPtr<ObserverNode> newNode = new ObserverNode(segment);
    mChildren->PushBack(newNode);
    FAIL_RETURN(newNode->AddObserverLocked(newNode, uri, index+1 , observer, notifyForDescendents));
    return NOERROR;
}
Esempio n. 21
0
ECode CContentService::ObserverNode::CollectObserversLocked(
    /* [in] */ ObserverNode* node,
    /* [in] */ IUri* uri,
    /* [in] */ Int32 index,
    /* [in] */ IContentObserver* observer,
    /* [in] */ Boolean selfNotify,
    /* [in] */ List<AutoPtr<ObserverCall> >* calls)
{
    VALIDATE_NOT_NULL(node);
    VALIDATE_NOT_NULL(observer);
    VALIDATE_NOT_NULL(calls);
    String segment;
    Int32 segmentCount = CountUriSegments(uri);
    List<AutoPtr<ObserverNode> >::Iterator it;

    if (index >= segmentCount) {
        // This is the leaf node, notify all observers
        CollectMyObserversLocked(node, TRUE, observer, selfNotify, calls);
    } 
    else if (index < segmentCount){
        segment = GetUriSegment(uri, index);
        // Notify any observers at this level who are interested in descendents
        CollectMyObserversLocked(node, FALSE, observer, selfNotify, calls);
    }

    for (it = mChildren->Begin(); it != mChildren->End(); it++) {
        AutoPtr<ObserverNode> pNode = *it;
        if (segment.IsNull() || !segment.Compare(pNode->mName)) {
            FAIL_RETURN(pNode->CollectObserversLocked(pNode, uri, index+1, observer, selfNotify, calls));
            if (!segment.IsNull()) {
                break;
            }
        }
    }

    return NOERROR;
}
Esempio n. 22
0
bool Settings::Set_long(const String& strSection, const String& strKey,
                          const int64_t& lValue, bool& out_bNewOrUpdate,
                          const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strSection.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Blank!\n";
        OT_FAIL;
    }

    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strKey.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Blank!\n";
        OT_FAIL;
    }

    String strValue;
    strValue.Format("%" PRId64, lValue);

    const char* const szComment =
        (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
                                                         : nullptr;

    String strOldValue, strNewValue;
    bool bOldKeyExist, bNewKeyExist;

    // Check if Old Key exists.
    if (!Check_str(strSection, strKey, strOldValue, bOldKeyExist)) return false;

    if (bOldKeyExist) {
        if (strValue.Compare(strOldValue)) {
            out_bNewOrUpdate = false;
            return true;
        }
    }

    // Log to Output Setting Change
    if (!LogChange_str(strSection, strKey, strValue)) return false;

    // Set New Value
    SI_Error rc = pvt->iniSimple.SetLongValue(strSection.Get(), strKey.Get(),
                                              lValue, szComment, false, true);
    if (0 > rc) return false;

    // Check if the new value is the same as intended.
    if (!Check_str(strSection, strKey, strNewValue, bNewKeyExist)) return false;

    if (bNewKeyExist) {
        if (strValue.Compare(strNewValue)) {
            // Success
            out_bNewOrUpdate = true;
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Esempio n. 23
0
bool Settings::Set_str(const String& strSection, const String& strKey,
                         const String& strValue, bool& out_bNewOrUpdate,
                         const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strSection.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Blank!\n";
        OT_FAIL;
    }

    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strKey.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Blank!\n";
        OT_FAIL;
    }

    // if (nullptr == m_strConfigurationFileExactPath){ otErr << "%s: Error:
    // %s is a nullptr!\n", __FUNCTION__, "p_iniSimple"); OT_FAIL; }

    const char* const szValue =
        (strValue.Exists() && !strValue.Compare("")) ? strValue.Get() : nullptr;
    const char* const szComment =
        (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
                                                         : nullptr;

    String strOldValue, strNewValue;
    bool bOldKeyExist, bNewKeyExist;

    // Check if Old Key exists.
    if (!Check_str(strSection, strKey, strOldValue, bOldKeyExist)) return false;

    if (bOldKeyExist) {
        if (strValue.Compare(strOldValue)) {
            out_bNewOrUpdate = false;
            return true;
        }
    }

    // Log to Output Setting Change
    if (!LogChange_str(strSection, strKey, strValue)) return false;

    // Set New Value
    SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), strKey.Get(),
                                          szValue, szComment, true);
    if (0 > rc) return false;

    if (nullptr == szValue) // We set the key's value to null, thus removing it.
    {
        if (bOldKeyExist)
            out_bNewOrUpdate = true;
        else
            out_bNewOrUpdate = false;

        return true;
    }

    // Check if the new value is the same as intended.
    if (!Check_str(strSection, strKey, strNewValue, bNewKeyExist)) return false;

    if (bNewKeyExist) {
        if (strValue.Compare(strNewValue)) {
            // Success
            out_bNewOrUpdate = true;
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Esempio n. 24
0
void PipeAudioSource::OnAudioDeviceChanged(const String &MonitorDevices, const String &SecMonitor)
{
	if (this->MonitorDevices.Compare(MonitorDevices.Array()) && this->SecMonitor.Compare(SecMonitor.Array()))
	{
		return;
	}

	Log::writeMessage(LOG_RTSPSERV, 1, "%s invoke begin!", __FUNCTION__);
	OSEnterMutex(hAudioMutex);

	bSameDevice = false;

	if (m_pAudioWaveOut)
	{
		m_pAudioWaveOut->Uninitialize();
	}

	if (NULL == m_pAudioWaveOut)
	{
		if (!MonitorDevices.Compare(TEXT("停用")) && !m_pAudioWaveOut)
		{
			m_pAudioWaveOut = new AudioWaveOut;
		}
	}
	else
	{
		if ((MonitorDevices.Compare(TEXT("Disable")) || MonitorDevices.Compare(TEXT("停用"))))
		{
			delete m_pAudioWaveOut;
			m_pAudioWaveOut = NULL;
		}
	}
	if (NULL != m_pAudioWaveOut)
	{
		m_pAudioWaveOut->Initialize(MonitorDevices.Array(), 2, Param.samplesPerSec, Param.bitsPerSample);
	}

	if (m_pSecWaveOut)
	{
		m_pSecWaveOut->Uninitialize();
	}

	if (SecMonitor.CompareI(MonitorDevices.Array()) && (!SecMonitor.Compare(TEXT("Disable")) || !SecMonitor.Compare(TEXT("停用"))))
	{
		bSameDevice = true;
	}
	else if (!SecMonitor.Compare(TEXT("停用")) && !m_pSecWaveOut)
	{
		m_pSecWaveOut = new AudioWaveOut;
	}
	else if (m_pSecWaveOut)
	{
		if ((SecMonitor.Compare(TEXT("Disable")) || SecMonitor.Compare(TEXT("停用"))))
		{
			delete m_pSecWaveOut;
			m_pSecWaveOut = NULL;
		}
	}

	if (m_pSecWaveOut)
	{
		m_pSecWaveOut->Initialize(SecMonitor.Array(), 2, Param.samplesPerSec, Param.bitsPerSample);
	}

	OSLeaveMutex(hAudioMutex);

	this->MonitorDevices = MonitorDevices;
	this->SecMonitor = SecMonitor;

	Log::writeMessage(LOG_RTSPSERV, 1, "%s invoke end!", __FUNCTION__);
}
   IMAPSearchCriteria::CriteriaType 
   IMAPSearchCriteria::GetCriteriaTypeByName(const String &sName)
   {
      String sTmp = sName;
      sTmp.MakeLower();
      
      if (sTmp.Compare(_T("")) == 0)
         return CTUnknown;
      else if (sTmp.Compare(_T("charset")) == 0)
         return CTCharset;
      else if (sTmp == _T("on"))
         return CTOn;
      else if (sTmp == _T("header"))
         return CTHeader;
      else if (sTmp == _T("text"))
         return CTText;
      else if (sTmp == _T("body"))
         return CTBody;
      else if (sTmp == _T("subject"))
         return CTSubject;
      else if (sTmp == _T("from"))
         return CTFrom;
      else if (sTmp == _T("cc"))
         return CTCC;
      else if (sTmp == _T("to"))
         return CTTo;
      else if (sTmp == _T("senton"))
         return CTSentOn;
      else if (sTmp == _T("sentbefore"))
         return CTSentBefore;
      else if (sTmp == _T("sentsince"))
         return CTSentSince;
      else if (sTmp == _T("since"))
         return CTSince;
      else if (sTmp == _T("deleted"))
         return CTDeleted;
      else if (sTmp == _T("recent"))
         return CTRecent;
      else if (sTmp == _T("seen"))
         return CTSeen;
      else if (sTmp == _T("unseen"))
         return CTUnseen;
      else if (sTmp == _T("undeleted"))
         return CTUndeleted;
      else if (sTmp == _T("uid"))
         return CTUID;
      else if (sTmp == _T("answered"))
         return CTAnswered;
      else if (sTmp == _T("before"))
         return CTBefore;
      else if (sTmp == _T("draft"))
         return CTDraft;
      else if (sTmp == _T("flagged"))
         return CTFlagged;
      else if (sTmp == _T("larger"))
         return CTLarger;
      else if (sTmp == _T("new"))
         return CTNew;
      else if (sTmp == _T("old"))
         return CTOld;
      else if (sTmp == _T("smaller"))
         return CTSmaller;
      else if (sTmp == _T("unanswered"))
         return CTUnanswered;
      else if (sTmp == _T("undraft"))
         return CTUndraft;
      else if (sTmp == _T("unflagged"))
         return CTUnflagged;
      else if (sTmp == _T("all"))
         return CTAll;
      else if (IsSequenceSet_(sTmp))
         return CTSequenceSet;

      return CTUnknown;
   }
Esempio n. 26
0
void HttpRequest::ThreadFunction()
{
    String protocol = "http";
    String host;
    String path = "/";
    int port = 80;
    
    unsigned protocolEnd = url_.Find("://");
    if (protocolEnd != String::NPOS)
    {
        protocol = url_.Substring(0, protocolEnd);
        host = url_.Substring(protocolEnd + 3);
    }
    else
        host = url_;
    
    unsigned pathStart = host.Find('/');
    if (pathStart != String::NPOS)
    {
        path = host.Substring(pathStart);
        host = host.Substring(0, pathStart);
    }
    
    unsigned portStart = host.Find(':');
    if (portStart != String::NPOS)
    {
        port = ToInt(host.Substring(portStart + 1));
        host = host.Substring(0, portStart);
    }
    
    char errorBuffer[ERROR_BUFFER_SIZE];
    memset(errorBuffer, 0, sizeof(errorBuffer));
    
    String headersStr;
    for (unsigned i = 0; i < headers_.Size(); ++i)
    {
        // Trim and only add non-empty header strings
        String header = headers_[i].Trimmed();
        if (header.Length())
            headersStr += header + "\r\n";
    }
    
    // Initiate the connection. This may block due to DNS query
    /// \todo SSL mode will not actually work unless Civetweb's SSL mode is initialized with an external SSL DLL
    mg_connection* connection = 0;
    if (postData_.Empty())
    {
        connection = mg_download(host.CString(), port, protocol.Compare("https", false) ? 0 : 1, errorBuffer, sizeof(errorBuffer),
            "%s %s HTTP/1.0\r\n"
            "Host: %s\r\n"
            "%s"
            "\r\n", verb_.CString(), path.CString(), host.CString(), headersStr.CString());
    }
    else
    {
        connection = mg_download(host.CString(), port, protocol.Compare("https", false) ? 0 : 1, errorBuffer, sizeof(errorBuffer),
            "%s %s HTTP/1.0\r\n"
            "Host: %s\r\n"
            "%s"
            "Content-Length: %d\r\n"
            "\r\n"
            "%s", verb_.CString(), path.CString(), host.CString(), headersStr.CString(), postData_.Length(), postData_.CString());
    }
    
    {
        MutexLock lock(mutex_);
        state_ = connection ? HTTP_OPEN : HTTP_ERROR;
        
        // If no connection could be made, store the error and exit
        if (state_ == HTTP_ERROR)
        {
            error_ = String(&errorBuffer[0]);
            return;
        }
    }
    
    // Loop while should run, read data from the connection, copy to the main thread buffer if there is space
    while (shouldRun_)
    {
        // Read less than full buffer to be able to distinguish between full and empty ring buffer. Reading may block
        int bytesRead = mg_read(connection, httpReadBuffer_.Get(), READ_BUFFER_SIZE / 4);
        if (bytesRead <= 0)
            break;
        
        mutex_.Acquire();
        
        // Wait until enough space in the main thread's ring buffer
        for (;;)
        {
            unsigned spaceInBuffer = READ_BUFFER_SIZE - ((writePosition_ - readPosition_) & (READ_BUFFER_SIZE - 1));
            if ((int)spaceInBuffer > bytesRead || !shouldRun_)
                break;
            
            mutex_.Release();
            Time::Sleep(5);
            mutex_.Acquire();
        }
        
        if (!shouldRun_)
        {
            mutex_.Release();
            break;
        }
        
        if (writePosition_ + bytesRead <= READ_BUFFER_SIZE)
            memcpy(readBuffer_.Get() + writePosition_, httpReadBuffer_.Get(), bytesRead);
        else
        {
            // Handle ring buffer wrap
            unsigned part1 = READ_BUFFER_SIZE - writePosition_;
            unsigned part2 = bytesRead - part1;
            memcpy(readBuffer_.Get() + writePosition_, httpReadBuffer_.Get(), part1);
            memcpy(readBuffer_.Get(), httpReadBuffer_.Get() + part1, part2);
        }
        
        writePosition_ += bytesRead;
        writePosition_ &= READ_BUFFER_SIZE - 1;
        
        mutex_.Release();
    }
    
    // Close the connection
    mg_close_connection(connection);
    
    {
        MutexLock lock(mutex_);
        state_ = HTTP_CLOSED;
    }
}
Esempio n. 27
0
bool PipeAudioSource::Initialize(PipeVideo *parent, const AudioParam& param)
{
	m_iLastPts = 0;
	m_iBlockSize = 0;
	Times = 0;
	LimitGetData = 0;
	m_PipeVideo = parent;

	if (!hAudioMutex)
	{
		hAudioMutex = OSCreateMutex();
	}

    bool bFloat = false;
    UINT  inputChannels;
    UINT  inputSamplesPerSec;
    UINT  inputBitsPerSample;
    DWORD inputChannelMask;

	inputBitsPerSample = param.bitsPerSample; // 16;
    inputChannelMask   = 0;
	inputChannels = param.channels; // 1;
	inputSamplesPerSec = param.samplesPerSec; // 8000;

	m_iBlockSize = inputChannels * inputBitsPerSample / 8;

    sampleFrameCount   = inputSamplesPerSec / 100;
	sampleSegmentSize = m_iBlockSize * sampleFrameCount;

	Param = param;
	m_isFirstDiffTimeWithAPI = true;
	m_lTimeDiffWithAPI = 0;
	m_iLastTimeStamp = 0;
    outputBuffer.SetSize(sampleSegmentSize);
	InitAudioData(bFloat, inputChannels, inputSamplesPerSec, inputBitsPerSample, m_iBlockSize, inputChannelMask);

	if (m_pAudioWaveOut)
	{
		m_pAudioWaveOut->Uninitialize();
	}

	String strReanderName = GetDirectorMonitorDevices();
	if (NULL == m_pAudioWaveOut)
	{
		if (!strReanderName.Compare(TEXT("停用")) && !m_pAudioWaveOut)
		{
			m_pAudioWaveOut = new AudioWaveOut;
		}
	}
	else
	{
		if ((strReanderName.Compare(TEXT("Disable")) || strReanderName.Compare(TEXT("停用"))))
		{
			delete m_pAudioWaveOut;
			m_pAudioWaveOut = NULL;
		}
	}

	if (NULL != m_pAudioWaveOut)
	{
		m_pAudioWaveOut->Initialize(strReanderName.Array(), 2, inputSamplesPerSec, inputBitsPerSample);
	}

	String SecRenderName = GetSecMonitorDevices();


	if (m_pSecWaveOut)
	{
		m_pSecWaveOut->Uninitialize();
	}

	if (SecRenderName.CompareI(strReanderName.Array()) && (!SecRenderName.Compare(TEXT("Disable")) || !SecRenderName.Compare(TEXT("停用"))))
	{
		bSameDevice = true;
	}
	else if (!SecRenderName.Compare(TEXT("停用")) && !m_pSecWaveOut)
	{
		m_pSecWaveOut = new AudioWaveOut;
	}
	else if (m_pSecWaveOut)
	{
		if ((SecRenderName.Compare(TEXT("Disable")) || SecRenderName.Compare(TEXT("停用"))))
		{
			delete m_pSecWaveOut;
			m_pSecWaveOut = NULL;
		}
	}

	if (m_pSecWaveOut)
	{
		m_pSecWaveOut->Initialize(SecRenderName.Array(), 2, inputSamplesPerSec, inputBitsPerSample);
	}

    return true;
}
void CDemandMediaAudio::OnAudioDeviceChanged(const String &MonitorDevices, const String &SecMonitor)
{

	if (this->MonitorDevices.Compare(MonitorDevices.Array()) && this->SecMonitor.Compare(SecMonitor.Array()))
	{
		return;
	}

	Log::writeMessage(LOG_RTSPSERV, 1, "%s invoke begin!", __FUNCTION__);
	EnterCriticalSection(&sampleBufferLock);

	m_bisFloat = false;
	bSameDevice = false;

	if (m_pAudioWaveOut)
	{
		m_pAudioWaveOut->Uninitialize();
	}

	if (NULL == m_pAudioWaveOut)
	{
		if (!MonitorDevices.Compare(TEXT("停用")) && !m_pAudioWaveOut)
		{
			m_pAudioWaveOut = new AudioWaveOut;
		}
	}
	else
	{
		if ((MonitorDevices.Compare(TEXT("Disable")) || MonitorDevices.Compare(TEXT("停用"))))
		{
			delete m_pAudioWaveOut;
			m_pAudioWaveOut = NULL;
		}
	}
	if (NULL != m_pAudioWaveOut)
	{
		if (m_sAudioParam.iChannel > 2)
		{
			m_bisFloat = true;
			m_pAudioWaveOut->Initialize(MonitorDevices.Array(), 2, m_sAudioParam.iSamplesPerSec, m_sAudioParam.iBitPerSample * 2);
		}
		else
		{
			m_pAudioWaveOut->Initialize(MonitorDevices.Array(), 2, m_sAudioParam.iSamplesPerSec, m_sAudioParam.iBitPerSample);
		}
	}

	if (m_pSecWaveOut)
	{
		m_pSecWaveOut->Uninitialize();
	}

	if (SecMonitor.CompareI(MonitorDevices.Array()) && (!SecMonitor.Compare(TEXT("Disable")) || !SecMonitor.Compare(TEXT("停用"))))
	{
		bSameDevice = true;
	}
	else if (!SecMonitor.Compare(TEXT("停用")) && !m_pSecWaveOut)
	{
		m_pSecWaveOut = new AudioWaveOut;
	}
	else if (m_pSecWaveOut)
	{
		if ((SecMonitor.Compare(TEXT("Disable")) || SecMonitor.Compare(TEXT("停用"))))
		{
			delete m_pSecWaveOut;
			m_pSecWaveOut = NULL;
		}
	}

	if (m_pSecWaveOut)
	{
		if (m_sAudioParam.iChannel > 2)
		{
			m_bisFloat = true;
			m_pSecWaveOut->Initialize(SecMonitor.Array(), 2, m_sAudioParam.iSamplesPerSec, m_sAudioParam.iBitPerSample * 2);
		}
		else
		{
			m_pSecWaveOut->Initialize(SecMonitor.Array(), 2, m_sAudioParam.iSamplesPerSec, m_sAudioParam.iBitPerSample);
		}
	}

	LeaveCriticalSection(&sampleBufferLock);

	this->MonitorDevices = MonitorDevices;
	this->SecMonitor = SecMonitor;

	Log::writeMessage(LOG_RTSPSERV, 1, "%s invoke end!", __FUNCTION__);
}
Esempio n. 29
0
bool Identifier::operator!=(const Identifier& s2) const
{
    const String ots1(*this), ots2(s2);
    return !(ots1.Compare(ots2));
}
Esempio n. 30
0
//-----------------------------------------------------------------------------------------------------------------------------------------------------
VOID Configuration::LoadCommandLine(String CmdLineString)
{
  Array<String> Tokens;
  String CurrentToken;

  SIZE_T i = 0;
  enum { WHITESPACE, TEXT, QUOTEDTEXT } State = WHITESPACE;

  while (i < CmdLineString.Length())
  {
    switch(State)
    {
    case WHITESPACE:
      if (CmdLineString(i) == '\"')
      {
        State = QUOTEDTEXT;
        break;
      }
      else if (!String::IsWhitespace(CmdLineString(i)))
      {
        State = TEXT;
        CurrentToken += CmdLineString(i);
        break;
      }
      break;
    case QUOTEDTEXT:
      if (CmdLineString(i) == '\\' && CmdLineString(i+1) == '\"')
      {
        CurrentToken += '\"';
        i++;
        break;
      }
      else if (CmdLineString(i) == '\"')
      {
        if (String::IsWhitespace(CmdLineString(i+1)))
        {
          State = WHITESPACE;
          Tokens.Add(CurrentToken);
          CurrentToken = String::Empty;
          break;
        }
        else
          State = TEXT;
      }
      CurrentToken += CmdLineString(i);
      break;
    case TEXT:
      if (String::IsWhitespace(CmdLineString(i)))
      {
        State = WHITESPACE;
        Tokens.Add(CurrentToken);
        CurrentToken = String::Empty;
        break;
      }
      else if (CmdLineString(i) == '\"')
      {
        State = QUOTEDTEXT;
        break;
      }
      CurrentToken += CmdLineString(i);
      break;
      
    };

    i++;
  };

  if (State == TEXT || State == QUOTEDTEXT)
    Tokens.Add(CurrentToken);

  SIZE_T ValueIndex = 0;
  SIZE_T ValueItemIndex = 0;

  for (SIZE_T i=1; i<Tokens.Length(); i++)
  {
    if (Tokens(i)(0) == '/')
    {
      ValueItemIndex = 0;
      ValueIndex++;
      
      String::Iterator Colon = Tokens(i).Find(TEXT(":"));
      if (Colon == Tokens(i).End())
      {
        String FlagName = Tokens(i).Substr(1);
        if (FlagName.Compare( TEXT("?"), FALSE) == 0 || FlagName.Compare( TEXT("Help"), FALSE) == 0 )
          return;

        if (m_NameMapping.Contains(FlagName))
          FlagName = m_NameMapping[FlagName];
        
        if (m_Schema.Contains(FlagName))
        {
          Item& I = m_Schema[FlagName];
          I.m_Count = 1;
          I.m_Present = TRUE;
          SetValue<String>(FlagName, "1");
        }

      }
      else
      {
        String Key = Tokens(i).Substr( Tokens(i).Begin()+1, Colon );
        String Value = Tokens(i).Substr( Colon+1 );

        if (m_NameMapping.Contains(Key))
          Key = m_NameMapping[Key];
        
        if (m_Schema.Contains(Key))
        {
          Item& I = m_Schema[Key];
          I.m_Count = 1;
          I.m_Present = TRUE;
          SetValue<String>(Key, Value);
        }
      }
    }
    else
    {
      if (ValueIndex < m_CommandLineBindings.Length())
      {
        String Name = m_CommandLineBindings[ValueIndex];
        Item& I = m_Schema[Name];

        if (I.m_IsList)
        {
          if (!m_ConfigListValues.Contains(Name))
            m_ConfigListValues.Add(Name, StringArray());
          m_ConfigListValues[Name].Add(Tokens(i));
        }
        else
        {
          SetValue<String>(Name, Tokens(i));
        }
        
        ValueItemIndex++;
        if (ValueItemIndex >= I.m_MaximumCount)
        {
          ValueItemIndex = 0;
          ValueIndex++;
        }
      }
    }

	}

}