Hi Kan,

> I have huge lack of understanding source/filters/sink concept.
We were all there once (I still am).

> to parse xml file from crypto filters
Two separate and distinct operations. It is similar to the
Unicode/MBCS set stuff in Windows. Though coupled, two separate and
distinct operations.

> int callbackFunc(void *context, const char *buffer, int len)
Operation one - if this works with your program, it should work with
Crypto++ objects on the stack. Are you able to save the context
properly to a file when _not_ using Sources and Sinks?

>  FileSource * source  = (FileSource *)context;
>  source->Pump(len);
>  return source->Get(buffer, len);
Try Creating the FileSource on the stack. When the object dtor gets
called, all filters in the chain are flushed.

What you are probably are looking for (forgive me if my presumptions
are not correct - I make a lot of mistakes ;):

{
   //  Place 'Context' in a File
   string s (context, context.length);
   FileSink( new StringSource( s ) );
}

or

{
   // Read a File, send off to the callback...
   //   s is created on the heap. Callback function must delete
   //    delete s when complete...
   string* s = new string();
   FileSource( filename, new StringSink( *s ) );

   CallbackFunction( ..., s, ... );
}

Jeff

On 1/25/07, kan <[EMAIL PROTECTED]> wrote:
>
> I have huge lack of understanding source/filters/sink concept. I want
> to parse xml file from crypto filters.
> libxml2 has a function to parse an input from callback-based stream. It
> looks like:
>
> int callbackFunc(void *context, const char *buffer, int len)
> {
> // function must read a data, put it in the buffer (not more than len
> bytes) and return real amount of read bytes.
> // at the end of the stream it must return 0
> // -1 for error indication.
> }
>
> then I call library function:
>
> xmlDocPtr = xmlReadIO(..., callbackFunc, context, ...);
>
> The library invokes the callback as it wants.
> I want to feed a data from crypto++.
> If I use just FileSource as source object, it work fine. Something like
> this:
>
> int callbackFunc(void *context, const char *buffer, int len)
> {
>  FileSource * source  = (FileSource *)context;
>  source->Pump(len);
>  return source->Get(buffer, len);
> }
> ...
> FileSource source("a file");
> xmlDocPtr = xmlReadIO(..., callbackFunc, &source, ...);
>
> But if I try to use filters (e.g. encryption+compression) this method
> doesn't work, because I don't know how much I have to Pump, without
> pumping Get doesn't give any data.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to