STDMETHODIMP InterfaceAccount::put_VacationMessageExpiresDate(BSTR newVal)
{
   try
   {
      if (!m_pObject)
         return GetAccessDenied();

      HM::String string = newVal;
      
      // Validate input date.
      if (string.Left(4) == _T("0000"))
         string = "";
   
      if (string.GetLength() == 0)
         string = Time::GetCurrentDate();
      else if (string.GetLength() != 10 || !Time::IsValidSystemDate(string))
         return COMError::GenerateError("Invalid auto-reply expiry date");
   
      m_pObject->SetVacationExpiresDate(string);
   
      return S_OK;
   }
   catch (...)
   {
      return COMError::GenerateGenericMessage();
   }
}
Example #2
0
AnsiString HashCreator::_GetHashRaw(const unsigned char *input, int inputLength, HashCreator::RequestedEncoding encoding)
{
    int digestLength = 0;

    switch (_hashType)
    {
    case SHA1:
        digestLength = SHA_DIGEST_LENGTH;
        break;
    case SHA256:
        digestLength = SHA256_DIGEST_LENGTH;
        break;
    case MD5:
        digestLength = MD5_DIGEST_LENGTH;
        break;
    }

    unsigned char *results = new unsigned char[digestLength];

    switch (_hashType)
    {
    case SHA1:
    {
        SHA_CTX context;
        SHA1_Init(&context);
        SHA1_Update(&context, input, inputLength);
        SHA1_Final(results, &context);
        break;
    }
    case MD5:
    {
        MD5_CTX context;
        MD5_Init(&context);
        MD5_Update(&context, input, inputLength);
        MD5_Final(results, &context);
        break;
    }
    case SHA256:
    {
        SHA256_CTX context;
        SHA256_Init(&context);
        SHA256_Update(&context, input, inputLength);
        SHA256_Final(results, &context);
        break;
    }

    }


    HM::String retVal;
    if (encoding == hex)
    {
        char *s = new char[digestLength*2+1];

        for (int i=0; i<digestLength; i++)
            sprintf(s+i*2, "%02x", results[i]);

        s[digestLength*2]='\0';

        retVal = s;

        delete [] s;
    }
    else if (encoding == base64)
    {
        MimeCodeBase64 encoder;
        encoder.SetInput((const char*) results, digestLength, true);

        AnsiString sEncodedValue;
        encoder.GetOutput(sEncodedValue);

        retVal = sEncodedValue;
        retVal = retVal.Mid(0, retVal.GetLength()-2);
    }

    delete [] results;

    return retVal;
}