Exemplo n.º 1
0
DWORD CParams::Load( LPBYTE buf, DWORD size, BOOL bMerge )
{_STT();
	if ( !bMerge ) Destroy();

	CCfgFile	cfg;
	cfg.LoadFromMem( buf, size );
	return Load( &cfg );
}
Exemplo n.º 2
0
void CDlgProductUpdate::Evaluate( HWND hWnd, double ver )
{
    CCfgFile	cfg;

    // Load the data
    cfg.LoadFromMem( m_nf.GetMem(), m_nf.GetDataRead() );

    double avail = 0;

    cfg.GetValue( "Product Information", "Last Version", &avail );
    if ( avail == 0 )
    {
        SetStatus( "Product information unavailable." );
        return;
    } // end if

    if ( avail > ver )
    {
        SetStatus( "Update available" );

        // Does the user want to get the update?
        CDlgMsgBox dlg( this );
        if ( dlg.ShowMessage(	"Update Available!",
                                "An update is available!\r\n\r\n"
                                "Would you like to go there now?",
                                LoadIcon( NULL, IDI_QUESTION ),
                                MB_YESNO ) != IDOK ) return;


        char url[ CWF_STRSIZE ] = { 0 };
        if ( !cfg.GetValue( "Product Information", "URL", url, sizeof( url ) ) || *url == 0 )
            strcpy( url, "http://www.wheresjames.com/" );

        ShellExecute( NULL, "open", url, NULL, NULL, SW_SHOWNORMAL );

    } // end if

    else if ( !m_bSilent )
    {
        SetStatus( "Update not available" );

        ::MessageBox( hWnd,	"You have the latest version",
                      "Update Not Available.", MB_OK );

    } // end else

}
Exemplo n.º 3
0
DWORD CParams::Save( LPBYTE buf, DWORD size )
{_STT();
	CCfgFile	cfg;
	if ( !Save( &cfg ) ) return 0;
	return cfg.SaveToMem( buf, size );
}
Exemplo n.º 4
0
BOOL CMime::ReadBlock(LPBYTE buf, DWORD size, LPDWORD bsize)
{_STT();
	BOOL endvars = FALSE;
	DWORD i = 0;
	char token[ MIME_STRSIZE ];

	// Allocate memory for block header
	LPMIMEBLOCK node = new MIMEBLOCK;
	if ( node == NULL ) return FALSE;
	ZeroMimeBlock( node );

	while ( !endvars && i < size )
	{
		// Forgive one CRLF
		if ( i < size && buf[ i ] == 0x0d ) i++;
		if ( i < size && buf[ i ] == 0x0a ) i++;

		// Skip white space
		while ( i < size && ( buf[ i ] <= ' ' || buf[ i ] > '~' ) &&
				buf[ i ] != 0x0d && buf[ i ] != 0x0a ) 
			i++;

		// Are there any variables?
		if ( buf[ i ] != 0x0d && buf[ i ] != 0x0a )
		{
			// Punt if end of data
			if ( i >= size ) { delete node; return FALSE; }

			// Copy token
			DWORD x = 0;
			while (	i < size &&
					buf[ i ] != ':' && 
					buf[ i ] > ' ' && 
					buf[ i ] <= '~' && 
					x < sizeof( token ) - 1 )
				token[ x++ ] = buf[ i++ ];
			token[ x ] = NULL;

			// Did we get the separator?
			if ( buf[ i++ ] == ':' )
			{
				// Skip white space
				while ( ( buf[ i ] <= ' ' || buf[ i ] > '~' ) &&
						buf[ i ] != 0x0d && buf[ i ] != 0x0a ) i++;

				DWORD e = i, skip;

				// Find the end 
				BOOL end = FALSE;
				while ( !end && !endvars ) 
				{
					// Find the end
					while ( buf[ e ] != 0x0d && buf[ e ] != 0x0a && e < size ) e++;
					if( buf[ e ] != 0x0d && buf[ e ] != 0x0a ) return FALSE;
					if ( buf[ ++e ] == 0x0a ) e++;
					if ( buf[ e ] > ' ' || buf[ e ] == 0x0d || buf[ e ] == 0x0a ) 
						end = TRUE;

					// Check for end of variables
					if ( buf[ e ] == 0x0d || buf[ e ] == 0x0a ) endvars = TRUE;

				} // end while

				// Remember where the end is
				skip = e;

				// +++
				e--; 

				// Lose trailing white space
				while ( e > i && ( buf[ e ] <= ' ' || buf[ e ] > '~' ) ) e--;

				if ( e > i ) 
				{
					// Add this variable
					node->var.AddVar( token, (LPVOID)&buf[ i ], e - i + 1 );

				} // end if

				// Encoding type
				if ( !strcmpi( token, "Content-Type" ) )
				{
					// Save the content-type
					DWORD c;
					for ( c = 0; c < sizeof( node->ctype ) && 
										buf[ i + c ] > ' ' && 
										buf[ i + c ] != ';'; c++ )
						node->ctype[ c ] = buf[ i + c ];
					node->ctype[ c ] = 0;

					if ( buf[ i + c ] == ';' ) c++;

					// Skip to next var
					while( ( i + c ) < size && 
							( buf[ i + c ] <= ' ' || buf[ i + c ] > '~' ) ) c++;

					if ( e > ( i + c ) )
					{
						// Is their a boundry string?
						CCfgFile	cfg;
						cfg.SetTerminator( ';' );
						cfg.LoadFromMem( &buf[ i + c ], e - ( i + c ) );

						// Get file name if specified
						cfg.GetValue( (LPCTSTR)NULL, "name", node->fname, sizeof( node->fname ) );

						// Get boundry string
						cfg.GetValue(	(LPCTSTR)NULL, "boundary", 
										(LPSTR)&node->boundry, sizeof( node->boundry ) );
					} // end if

				} // end if

				// Encoding type
				if ( !strcmpi( token, "Content-Transfer-Encoding" ) )
				{
					if ( !strnicmp( (LPCTSTR)&buf[ i ], "base64", strlen( "base64" ) ) )
						node->encode |= MBEN_BASE64;
					else if ( !strnicmp( (LPCTSTR)&buf[ i ], "quoted-printable", strlen( "quoted-printable" ) ) )
						node->encode |= MBEN_QP;
				} // end if

				// Attachment?
				if ( !strcmpi( token, "Content-Disposition" ) )
				{
					if ( !strnicmp( (LPCTSTR)&buf[ i ], "attachment", strlen( "attachment" ) ) )
						node->f1 |= MBF1_ATTACHMENT;

					CCfgFile	cfg;
					cfg.LoadFromMem( &buf[ i ], e - i );

					// Get filename
					cfg.GetValue( (LPCTSTR)NULL, "filename", node->fname, sizeof( node->fname ) );
					
				} // end if

				// cid:
				if ( !strcmpi( token, "Content-ID" ) )
				{
					DWORD s = i;
					while( s < e && buf[ s ] != '<' ) s++;

					// Copy the cid
					if ( buf[ s ] == '<' )
					{	DWORD x = 0;
						s++;
						while( s < e && buf[ s ] != '>' ) node->cid[ x++ ] = buf[ s++ ];
						node->cid[ x ] = 0;
					} // end if
					
				} // end if

				// Forge ahead
				i = skip;

			} // end if

			// Skip to next line
			else while ( i < size && buf[ i ] != 0x0d && buf[ i ] != 0x0a ) i++;

		} // end if

		else endvars = TRUE;

	} // end while	

	// Skip next CRLF
	if ( buf[ i ] == 0x0d ) i++;
	if ( buf[ i ] == 0x0a ) i++;

	// Save header if non attached multipart
	if (	m_header != NULL &&
			( node->f1 & MBF1_ATTACHMENT ) == 0 &&
			!strnicmp( node->ctype, "multipart/", strlen( "multipart/" ) ) )
		i = 0;

	// Was this the header info?
	if ( m_header == NULL ) m_header = node;

	DWORD done = FALSE;
	DWORD start = i;
	DWORD end = i;
	DWORD blen = strlen( m_header->boundry );
	while( !done && i < size )
	{
		// This may be the end
		end = i;

		// Check for end tag ( some of this here for efficiency )
		if (	buf[ i ] == '-' && ( i + 1 + blen ) < size && 
				buf[ i + 1 ] == m_header->boundry[ 0 ] &&
				!strnicmp( (LPCTSTR)&buf[ i + 1 ], m_header->boundry, blen ) )
		{
			// Forget this line
			while ( end > start && buf[ end ] != '\r' && buf[ end ] != '\n' ) end--;

			if ( bsize != NULL )
				*bsize += i + 1 + strlen( m_header->boundry );
			done = TRUE;
		} // end if	

		if ( !done ) i++;

	} // end while

	// Attempt to allocate memory for block
	node->dsize = end - start + 1;
	node->pdata = new BYTE[ node->dsize + 1 ];
	if ( node->pdata == NULL ) { delete node; return done; }
	memcpy( node->pdata, &buf[ start ], node->dsize );

	// Attempt to add the block to the list
	if ( !AddBlock( node ) ) delete node;

	return done;
}