Example #1
0
/*#
   @method open Uploaded
   @brief Opens a read-only Falcon Stream pointing to the uploaed file.
   @return A Falcon stream.
   @raise IoError on open or write error.
   @raise TypeError if the storage property is not a valid filename.
   
   If @b data is filled, this method creates a memory
   read-only StringStream accessing the data as a file. If it was
   stored in a temporary file named as reported by the @b storage
   property, that file is open in read-only/shared mode.

   This method allows to obtain a valid readable stream no matter if the
   uploaded file was cached in memory or temporarily stored to disk.
*/
FALCON_FUNC Uploaded_open( Falcon::VMachine *vm )
{
   Falcon::CoreObject *self = vm->self().asObject();
   Falcon::Item i_data;

   // try to read the data.
   Falcon::Stream *ret = 0;
   
   if ( self->getProperty( "data", i_data ) )
   {
      
      if ( i_data.isMemBuf() )
      {
         ret = new Falcon::StringStream();
         Falcon::MemBuf *mb = i_data.asMemBuf();
         ret->write( mb->data(), mb->size() );
         ret->seekBegin(0);
      }
      else if ( i_data.isString() )
      {
         ret = new Falcon::StringStream( *i_data.asString() );
      }
   }

   // try to load from storage if we didn't create a stream.
   if ( ret == 0 )
   {
      Falcon::Item i_storage;
      if ( ! self->getProperty( "storage", i_storage ) || ! i_storage.isString() )
      {
         // invalid storage?
         throw new Falcon::TypeError( Falcon::ErrorParam( Falcon::e_inv_params, __LINE__ )
               .extra( ".storage" ) );
      }

      Falcon::FileStream *temp = new Falcon::FileStream();
      if ( ! temp->open( *i_storage.asString(), Falcon::BaseFileStream::e_omReadOnly ) )
      {
         Falcon::int64 le = temp->lastError();
         delete temp;
         throw new Falcon::IoError(
            Falcon::ErrorParam( Falcon::e_io_error, __LINE__ )
            .sysError( (uint32) le ) );
      }
      
      ret = temp;
   }

   // create the stream.
   Falcon::Item *stream_cls = vm->findWKI( "Stream" );
   fassert( stream_cls != 0 );
   fassert( stream_cls->isClass() );
   Falcon::CoreObject *oret = stream_cls->asClass()->createInstance();
   oret->setUserData( ret );
   vm->retval( oret );
}
Example #2
0
void ScriptData::unhookAll()
{
   cancelSleep();

   for( int i = 0; i < m_hooks->length(); i++ )
   {
      Falcon::CoreObject *hook = m_hooks->at( i ).asObject();
      XChatHook *xh = (XChatHook *) hook->getUserData();

      // the hook may have already dis-hooked itself.
      if ( xh != 0 )
      {
         xchat_unhook( the_plugin, xh->hook() );
         // void the hook
         hook->setUserData( (Falcon::FalconData*)0 );
         delete xh;
      }
   }

   // empty the array of hooks
   m_hooks->resize( 0 );
   // notice that this also causes the hook object to be reclaimable,
   // in case the script has dropped them too.
}