/* $Revision: 18 $ $Date: 18/08/06 17:57 $ Copyright © 2006-2007, FSL Technologies Limited. Contact "http://fost.3.felspar.com/". */ #include "stdafx.h" #include "FOST.internet.hpp" using namespace FSLib; namespace { const FSLib::Revision c_revision( L"$Archive: /FOST.3/F3Util/aspPage.cpp $", __DATE__, L"$Revision: 18 $", L"$Date: 18/08/06 17:57 $" ); const char *c_crlf = "\r\n"; const char *c_crlfcrlf = "\r\n\r\n"; } /* FSLib::Mime */ FSLib::Mime::Mime( const Headers &h, const unsigned char * /*data*/, size_t /*octets*/ ) : headers( h ) { } /* FSLib::Mime::Headers */ std::pair< FSLib::wstring, FSLib::Headers::Value > FSLib::Mime::Headers::value( const FSLib::wstring &name, const FSLib::wstring &value ) { if ( name == L"Content-Disposition" || name == L"content-disposition" || name == L"Content-Type" ) { std::map< wstring, wstring > args; // Parse the value from the format // form-data; name="aname"; extra="value" std::pair< wstring, Nullable< wstring > > disp( partition( value, L";" ) ); if ( !disp.second.isnull() ) { for ( std::pair< wstring, Nullable< wstring > > para( partition( disp.second, L";" ) ); !para.first.empty(); para = partition( para.second, L";" ) ) { // Normally the extra argument values should be surrounded by double quotes, but sometimes not std::pair< wstring, Nullable< wstring > > argument( crack( para.first, L"=\"", L"\"" ) ); if ( argument.second.isnull() ) argument = partition( para.first, L"=" ); if ( argument.second.isnull() ) throw FSLib::Exceptions::ParseError( L"Message header " + name + L" does not have a value for an argument", para.first ); args[ argument.first ] = argument.second.value(); } } if ( name == L"Content-Disposition" ) // RFC 1867 uses lower case return std::make_pair( L"content-disposition", Value( disp.first, args ) ); else return std::make_pair( name, Value( disp.first, args ) ); } else return FSLib::Headers::value( name, value ); }