//----------------------------------------------------------------//
void MOAIHttpTaskNaCl::Prepare ( GetURLHandler *handler ) {

	// until we get a header indicating otherwise, assume we won't
	// know the final length of the stream, so default to use the
	// USMemStream which will grow dynamically
	this->mStream = &this->mMemStream;

	char buffer [ MAX_HEADER_LENGTH ];

	int written = 0;

	// prepare the custom headers (if any)
	HeaderMapIt headerMapIt = this->mHeaderMap.begin ();
	for ( ; headerMapIt != this->mHeaderMap.end (); ++headerMapIt ) {
	
		STLString key = headerMapIt->first;
		STLString value = headerMapIt->second;
	
		assert (( written + ( key.size () + value.size () + 3 )) < MAX_HEADER_LENGTH );
	
		if ( value.size ()) {
			written += sprintf ( buffer + written, "%s: %s\n", key.c_str (), value.c_str ());
		}
		else {
			written += sprintf ( buffer + written, "%s:\n", key.c_str ());
		}
		
	}

	//append headers
	handler->SetHeaders ( buffer );

}
//----------------------------------------------------------------//
void MOAIHttpTaskCurl::Prepare () {

	// until we get a header indicating otherwise, assume we won't
	// know the final length of the stream, so default to use the
	// USMemStream which will grow dynamically
	if ( this->mUserStream ) {
		
		this->mStream = this->mUserStream->GetUSStream();
	}
	else {
		
		this->mStream = &this->mMemStream;	
	}

	char buffer [ MAX_HEADER_LENGTH ];

	// prepare the custom headers (if any)
	HeaderMapIt headerMapIt = this->mHeaderMap.begin ();
	for ( ; headerMapIt != this->mHeaderMap.end (); ++headerMapIt ) {
	
		STLString key = headerMapIt->first;
		STLString value = headerMapIt->second;
	
		assert (( key.size () + value.size () + 3 ) < MAX_HEADER_LENGTH );
	
		if ( value.size ()) {
			sprintf ( buffer, "%s: %s", key.c_str (), value.c_str ());
		}
		else {
			sprintf ( buffer, "%s:", key.c_str ());
		}
		
		this->mHeaderList = curl_slist_append ( this->mHeaderList, buffer );
	}
	
	if ( this->mHeaderList ) {
		CURLcode result = curl_easy_setopt ( this->mEasyHandle, CURLOPT_HTTPHEADER, this->mHeaderList );
		PrintError ( result );
	}

	CURLcode result = curl_easy_setopt ( this->mEasyHandle, CURLOPT_CONNECTTIMEOUT, this->mDefaultTimeout );
	
	// follow redirects based on settings in base class (default is to NOT follow redirects)
	result = curl_easy_setopt ( this->mEasyHandle, CURLOPT_FOLLOWLOCATION, this->mFollowRedirects );
	
	// set the timeout for this task
	result = curl_easy_setopt ( this->mEasyHandle, CURLOPT_TIMEOUT, this->mTimeout );
	
	PrintError ( result );
}
Example #3
0
	//----------------------------------------------------------------//
	void Load ( u32 transform = 0 ) {
	
		if ( this->mType != TYPE_UNKNOWN ) {
			return;
		}
		
		this->mTransform |= transform;
		
		if ( !this->mImage.IsOK ()) {
	
			if ( this->mFileData ) {
				this->mImage.Load ( this->mFileData, ( u32 )this->mFileDataSize, this->mTransform );
				free ( this->mFileData );
				this->mFileData = 0;
			}
			else if ( mFilename.size ()) {
				this->mImage.Load ( this->mFilename, this->mTransform );
			}
		}
		
		if ( this->mImage.IsOK ()) {
			this->mType = TYPE_MOAI_IMAGE;
		}
		#ifdef MOAI_TEST_PVR
			else {
				// get file data, check if PVR
				USFileStream stream;
				stream.OpenRead ( this->mFilename );
	
				if ( this->mFileData ) {
					free ( this->mFileData );
					this->mFileData = 0;
				}
				
				this->mFileDataSize = stream.GetLength ();
				this->mFileData = malloc ( this->mFileDataSize );
				stream.ReadBytes ( this->mFileData, this->mFileDataSize );
	
				stream.Close ();
				
				if ( MOAIPvrHeader::GetHeader( this->mFileData, this->mFileDataSize )) {				
					this->mType = TYPE_PVR;
				}
			}
		#endif
		
		if ( this->mType == TYPE_UNKNOWN ) {
			this->mType = TYPE_FAIL;
			this->Release ();
		}
	}
Example #4
0
	//----------------------------------------------------------------//
	void Load ( u32 transform = 0 ) {
	
		if ( this->mType != TYPE_UNKNOWN ) {
			return;
		}
		
		this->mTransform |= transform;
		
		if ( !this->mImage.IsOK ()) {
	
			if ( this->mFileData ) {
				this->mImage.Load ( this->mFileData, ( u32 )this->mFileDataSize, this->mTransform );
				free ( this->mFileData );
				this->mFileData = 0;
			}
			else if ( mFilename.size ()) {
				this->mImage.Load ( this->mFilename, this->mTransform );
			}
		}
		
		if ( this->mImage.IsOK ()) {
			this->mType = TYPE_MOAI_IMAGE;
		}
		#ifdef MOAI_TEST_PVR
			else if ( USPvrHeader::GetHeader ( this->mFileData, this->mFileDataSize )) {
				this->mType = TYPE_PVR;
			}
		#endif
		
		if ( this->mType == TYPE_UNKNOWN ) {
			this->mType = TYPE_FAIL;
			
			if ( this->mFileData ) {
				free ( this->mFileData );
				this->mFileData = 0;
			}
		}
	}