///////////////////////////////////////////////////////////////////////////////
// GetNoun
//      note -- you can only call this once after the verb (it eats the rest
//          of the line!)
///////////////////////////////////////////////////////////////////////////////
static void GetNoun( TSTRING& noun )
{
    static TSTRING prevNoun;
    TCHAR buf[1024];

    TCIN.getline( buf, 1024 );
    //
    // find the end of the noun...
    //
    TCHAR* pStart   = buf;
    TCHAR* end      = &buf[1023];
    while( IsSpace(*pStart) && (! IsEnd(*pStart)) && (pStart < end) )
        pStart++;

    if( IsEnd( *pStart ) || (pStart >= end) )
    {
        // no noun!
        noun = _T("");
        return;
    }
    TCHAR* pCur     = pStart;
    bool bQuote = false;
    if( *pCur == _T('\"') )
    {
        bQuote = true;
        pCur++;
        pStart++;
    }
    while( pCur < end )
    {
        if( (! bQuote) && IsSpace(*pCur) )
            break;

        if( *pCur == _T('\"') && bQuote)
            break;

        pCur++;
    }
    noun.assign(pStart, (pCur - pStart));

    if( noun.compare( _T("!$") ) == 0 )
    {
        noun = prevNoun;
    }
    prevNoun = noun;
}
Example #2
0
bool cFSParserUtil::MapStringToProperty( const TSTRING& str, int& propIndex ) const
{
    bool fMappedChar = true; // assume we'll recognize this char
                             // and set false if we don't

    // for short names
    if( str.length() == 1 )
    {
        switch( str[0] )
        {
	        case 'p': propIndex = cFSPropSet::PROP_MODE;    break;
	        case 'i': propIndex = cFSPropSet::PROP_INODE;   break;
	        case 'n': propIndex = cFSPropSet::PROP_NLINK;   break;
	        case 'u': propIndex = cFSPropSet::PROP_UID;     break;
	        case 'g': propIndex = cFSPropSet::PROP_GID;     break;
	        case 's': propIndex = cFSPropSet::PROP_SIZE;    break;
	        case 't': propIndex = cFSPropSet::PROP_FILETYPE;break;
	        case 'd': propIndex = cFSPropSet::PROP_DEV;		break;
            case 'r': propIndex = cFSPropSet::PROP_RDEV;	break;                
	        case 'b': propIndex = cFSPropSet::PROP_BLOCKS;  break;
            case 'a': propIndex = cFSPropSet::PROP_ATIME;   break;
	        case 'm': propIndex = cFSPropSet::PROP_MTIME;   break;
	        case 'c': propIndex = cFSPropSet::PROP_CTIME;   break;
	        case 'C': propIndex = cFSPropSet::PROP_CRC32;   break;
	        case 'M': propIndex = cFSPropSet::PROP_MD5;		break;
	        case 'S': propIndex = cFSPropSet::PROP_SHA;		break;
	        case 'H': propIndex = cFSPropSet::PROP_HAVAL;   break;
	        case 'l': propIndex = cFSPropSet::PROP_GROWING_FILE; break;
            default:  fMappedChar = false;                  break;
        }
    }
    else
    {
        if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MODE ) ) )
            propIndex = cFSPropSet::PROP_MODE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_INODE ) ) )
            propIndex = cFSPropSet::PROP_INODE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_UID ) ) )
            propIndex = cFSPropSet::PROP_UID;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_GID ) ) )
            propIndex = cFSPropSet::PROP_GID;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_SIZE ) ) )
            propIndex = cFSPropSet::PROP_SIZE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_FILETYPE ) ) )
            propIndex = cFSPropSet::PROP_FILETYPE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_DEV ) ) )
            propIndex = cFSPropSet::PROP_DEV;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_RDEV ) ) )
            propIndex = cFSPropSet::PROP_RDEV;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_BLOCKS ) ) )
            propIndex = cFSPropSet::PROP_BLOCKS;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_ATIME ) ) )
            propIndex = cFSPropSet::PROP_ATIME;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MTIME ) ) )
            propIndex = cFSPropSet::PROP_MTIME;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_CTIME ) ) )
            propIndex = cFSPropSet::PROP_CTIME;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_CRC32 ) ) )
            propIndex = cFSPropSet::PROP_CRC32;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MD5 ) ) )
            propIndex = cFSPropSet::PROP_MD5;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_SHA ) ) )
            propIndex = cFSPropSet::PROP_SHA;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_HAVAL ) ) )
            propIndex = cFSPropSet::PROP_HAVAL;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_GROWING_FILE ) ) )
            propIndex = cFSPropSet::PROP_GROWING_FILE;
        else
            fMappedChar = false;
    }

    return( fMappedChar );
}
/// <summary>
/// <para name='Name'>ResolveDisplayName</para>
/// <para name='Purpose'>Get an email address from a Display Name</para>
/// </summary>
/// <param name='szName'>Display Name to resolve</param>
/// <param name='szEmailAddress'>[out] Returned email address</param>
/// <returns>HRESULT</returns>
/// <remarks>
/// <para name='Notes'></para>
/// <para name='Author'>Kenn Guilstorf</para>
/// <para name='LastModified'>28Jan2016</para>
/// </remarks>
STDMETHODIMP ZybraxiSoft::CMailbox::ResolveDisplayName(TSTRING szName, TSTRING &szEmailAddress)
{
	HRESULT hr = S_OK;
	LPADRBOOK lpAdrBook = NULL;
	LPADRLIST lpAdrList = NULL;
	TSTRING szEX = TSTRING(_T("EX"));
	bool isExchange = false;

	enum
	{
		prDISPLAY_NAME,
		NUM_PROPS
	};

	// Check to make sure we have something in szName
	if (szName.empty() || szName.size() <= 0)
	{
		hr = MAPI_E_INVALID_PARAMETER;
		goto EXIT;
	}

	// Log what we're trying to resolve
	m_log << output::both << level::Informational <<
		"Attempting to resolve '" << szName.c_str() << "'" << endl;

	// Open the address book
	// See: https://msdn.microsoft.com/en-us/library/office/cc815381.aspx
	if (SUCCEEDED(hr = m_lpSession->OpenAddressBook(
		NULL,				// ulUIParam [may be NULL]
		NULL,				// lpInterface [may be NULL; returns IAddrBook:IMAPIProp]
		NULL,				// ulFlags [NULL means no flags]
		&lpAdrBook)))		// lppAdrBook [out]
	{
		// Allocate the address list
		// Note: I like to use 'this' so I know which functions I'm responsible
		//       for if I ever have to work on this...
		if (SUCCEEDED(hr = this->AllocAdrList(
			NUM_PROPS,
			&lpAdrList)))
		{
			// Even though we succeeded, do a check to make sure we have
			//  an address list
			if (lpAdrList)
			{
				lpAdrList->cEntries = 1;	// only looking for 1 entry
				lpAdrList->aEntries[0].cValues = NUM_PROPS;		// Number of props

				// Set the SPropValue to whom we're looking for
				lpAdrList->aEntries[0].rgPropVals[prDISPLAY_NAME].ulPropTag =
					PR_DISPLAY_NAME;
				lpAdrList->aEntries[0].rgPropVals[prDISPLAY_NAME].Value.LPSZ =
					(LPTSTR)szName.c_str();

				// Let's try to resolve the name now
				if (SUCCEEDED(hr = lpAdrBook->ResolveName(
					0L,
					MAPI_UNICODE,
					NULL,
					lpAdrList)))
				{
					m_log << output::both << level::Informational <<
						"Resolve name yielded " <<
						lpAdrList->aEntries[0].cValues <<
						" properties." << endl;

					for (UINT i = 0; i < lpAdrList->aEntries[0].cValues; i++)
					{
						// Store the property so I don't have to type so much...
						SPropValue spvCurrent = lpAdrList->aEntries[0].rgPropVals[i];

						m_log << output::both << level::Informational <<
							"Found Property '0x" <<
							setfill(_T('0')) << setw(8) << setbase(16) <<
							spvCurrent.ulPropTag << "'";

						switch (spvCurrent.ulPropTag)
						{
						case PR_ADDRTYPE:
							if (szEX.compare(spvCurrent.Value.LPSZ) == 0)
								isExchange = true;
							break;
						case PR_DISPLAY_NAME:
							m_log << ": " << spvCurrent.Value.LPSZ;
							break;
						case PR_EMAIL_ADDRESS:
							m_log << ": " << spvCurrent.Value.LPSZ;
							szEmailAddress = TSTRING(spvCurrent.Value.LPSZ);
							break;
						default:
							if (((spvCurrent.ulPropTag & 0x1f) == 0x1f) ||
								((spvCurrent.ulPropTag & 0x1e) == 0x1e))
								m_log << ": " << spvCurrent.Value.LPSZ;
							break;
						}

						m_log << endl;
					}

					if (!isExchange || (szEmailAddress.empty()))
					{
						hr = MAPI_E_NOT_FOUND;
						goto CLEANUP;
					}
				}
				else
				{
					FATAL(_T("lpAdrBook->ResolveName()"), hr);
					goto CLEANUP;
				}
			}
		}
		else
		{
			FATAL(_T("AllocAdrList()"), hr);
			goto CLEANUP;
		}
	}
	else
	{
		FATAL(_T("OpenAddressBook()"), hr);
	}

CLEANUP:
	if (lpAdrList)
	{
		FreePadrlist(lpAdrList);
		lpAdrList = NULL;
	}

	if (lpAdrBook)
	{
		lpAdrBook->Release();
		lpAdrBook = NULL;
	}

EXIT:
	return hr;
}
// case sensitive-matching
bool cParseNamedAttr::NamesMatch( int nString, const TSTRING& strName ) const
{
    return ( 0 == strName.compare( TSS_GetString( cTWParser, nString ) ) );
}
///////////////////////////////////////////////////////////////////////////////
// Function name    : cUnixFSServices::FullPath
// Description      :
//
// Return type      : bool
// Argument         :  TSTRING& strFullPath
// Argument         : const TSTRING& strRelPathC
// Argument         : const TSTRING& pathRelFromC
//
// TODO -- is throwing an exception the more appropriate alternative to returning
//      a bool? I think it is ... mdb
///////////////////////////////////////////////////////////////////////////////
bool cUnixFSServices::FullPath(TSTRING& strFullPath, const TSTRING& strRelPathC, const TSTRING& pathRelFromC) const
{
    cDebug d("cUnixFSServices::FullPath");
    d.TraceDebug("strRelPathC = %s, pathRelFromC = %s\n", strRelPathC.c_str(), pathRelFromC.c_str());

    // don't do anything with an empty path
    if (strRelPathC.empty())
        return false;

#if USES_DEVICE_PATH
    TSTRING strRelPath = cDevicePath::AsPosix(strRelPathC); // make non-const temp var
#else
    TSTRING strRelPath = strRelPathC; // make non-const temp var
#endif
    //
    // get base name (where strRelPath will be relative to), which will either be;
    //  1. the root directory if strRelPath is an absolute path
    //  2. pathRelFrom if it's not empty
    //  3. otherwise ( not abs path AND no rel path ) the current working directory
    //

    if (strRelPath[0] == TW_SLASH) // if is absolute path
    {
        if (IsRoot(strRelPath)) // if it's root, don't monkey with it, just return it.
        {
            strFullPath = strRelPath;
            d.TraceDebug("Is root; returning %s\n", strFullPath.c_str());
            return true;
        }
        else
        {
            strFullPath = _T(""); // push root, then add path elements from strRelPathC
                                  // one by one (in while loop below)
        }
    }
    else // is a relative path, so check pathRelFromC
    {
        if (pathRelFromC.empty()) // if we're relative to CWD...
        {
            //
            // get the current working directory
            //
            try
            {
                GetCurrentDir(strFullPath);
#if USES_DEVICE_PATH
                strFullPath = cDevicePath::AsPosix(strFullPath);
#endif
                util_TrailingSep(strFullPath, false);
            }
            catch (eFSServices&)
            {
                return false;
            }

            d.TraceDebug("Creating prefix relative to CWD: %s\n", strFullPath.c_str());
        }
        else // we're relative to a given dir
        {

#if USES_DEVICE_PATH
            strFullPath = cDevicePath::AsPosix(pathRelFromC);
#else
            strFullPath = pathRelFromC;
#endif
            util_RemoveDuplicateSeps(strFullPath);
            util_TrailingSep(strFullPath, false);

            d.TraceDebug("Creating prefix from supplied path: %s\n", strFullPath.c_str());
        }
    }

    //
    // start adding path elements from strRelPath to the base name
    // ( which already has an absolute starting point.  see above. )
    //

    TSTRING strElem;
    int     index = 0;
    while (util_GetNextPathElement(strRelPath, strElem, index++))
    {
        d.TraceDebug("Path element = %s\n", strElem.c_str());
        if (0 == strElem.compare(_T(".")))
        {
            // ignore it
        }
        else if (0 == strElem.compare(_T("..")))
        {
            // go up a dir ( the function takes care of root dir case )
            TSTRING strDummy;
            util_RemoveLastPathElement(strFullPath, strDummy);
        }
        else // just a regular old path element
        {
            strFullPath += TW_SLASH;
            strFullPath += strElem;
        }

        d.TraceDebug("FullPath is now %s\n", strFullPath.c_str());
    }

#if IS_AROS || IS_REDOX
    strFullPath = cDevicePath::AsNative(strFullPath);
#endif

    d.TraceDebug("Done, returning %s\n", strFullPath.c_str());
    return true;
}