Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Protected Attributes
Arc::PayloadGSIStream Class Reference

#include <PayloadGSIStream.h>

Inheritance diagram for Arc::PayloadGSIStream:
Inheritance graph
[legend]
Collaboration diagram for Arc::PayloadGSIStream:
Collaboration graph
[legend]

List of all members.

Public Types

typedef signed long long int Size_t

Public Member Functions

 PayloadGSIStream (PayloadStreamInterface *stream, gss_ctx_id_t &ctx, Logger &logger, bool client)
virtual ~PayloadGSIStream ()
virtual bool Get (char *buf, int &size)
 Extracts information from stream up to 'size' bytes.
virtual bool Get (std::string &buf)
 Read as many as possible (sane amount) of bytes into buf.
virtual std::string Get ()
 Read as many as possible (sane amount) of bytes.
virtual bool Put (const char *buf, Size_t size)
 Push 'size' bytes from 'buf' into stream.
virtual bool Put (const std::string &buf)
 Push information from 'buf' into stream.
virtual bool Put (const char *buf)
 Push null terminated information from 'buf' into stream.
virtual operator bool ()
 Returns true if stream is valid.
virtual bool operator! ()
 Returns true if stream is invalid.
virtual int Timeout () const
 Query current timeout for Get() and Put() operations.
virtual void Timeout (int to)
 Set current timeout for Get() and Put() operations.
virtual Size_t Pos () const
 Returns current position in stream if supported.
virtual Size_t Size (void) const
 Returns size of underlying object if supported.
virtual Size_t Limit (void) const
 Returns position at which stream reading will stop if supported.

Protected Attributes

int timeout
PayloadStreamInterfacestream
char * buffer
int bufferpos
int bufferlen
gss_ctx_id_t & ctx
Loggerlogger
bool client

Detailed Description

Definition at line 16 of file PayloadGSIStream.h.


Member Typedef Documentation

typedef signed long long int Arc::PayloadStreamInterface::Size_t [inherited]

Definition at line 18 of file PayloadStream.h.


Constructor & Destructor Documentation

Arc::PayloadGSIStream::PayloadGSIStream ( PayloadStreamInterface stream,
gss_ctx_id_t &  ctx,
Logger logger,
bool  client 
)

Definition at line 18 of file PayloadGSIStream.cpp.

Definition at line 31 of file PayloadGSIStream.cpp.

                                      {
    if(buffer) delete[] buffer;
  }

Member Function Documentation

bool Arc::PayloadGSIStream::Get ( char *  buf,
int &  size 
) [virtual]

Extracts information from stream up to 'size' bytes.

'size' contains number of read bytes on exit. Returns true in case of success.

Implements Arc::PayloadStreamInterface.

Definition at line 35 of file PayloadGSIStream.cpp.

                                                 {

    if (!buffer) {
      gss_buffer_desc input_tok = GSS_C_EMPTY_BUFFER;
      gss_buffer_desc output_tok = GSS_C_EMPTY_BUFFER;

      int len = 5;
      char readbuf[5];
      stream->Get(&readbuf[0], len);

      input_tok.length = (unsigned char)readbuf[3] * 256 +
                         (unsigned char)readbuf[4] + 5;
      // While allocating buffer with malloc it will be freed using 
      // gssapi's gss_release_buffer()
      input_tok.value = malloc(input_tok.length);
      memcpy(input_tok.value, readbuf, 5);

      logger.msg(VERBOSE, "input token length: %i", input_tok.length);

      int pos = len;
      while (input_tok.length > pos) {
        len = input_tok.length - pos;
        stream->Get(&((char*)input_tok.value)[pos], len);
        pos += len;
      }

      OM_uint32 majstat, minstat;

      if (client) {
        majstat = gss_unwrap(&minstat,
                             ctx,
                             &input_tok,
                             &output_tok,
                             NULL,
                             GSS_C_QOP_DEFAULT);

        logger.msg(INFO, "GSS unwrap: %i/%i", majstat, minstat);
      }
      else {
        majstat = gss_wrap(&minstat,
                           ctx,
                           0,
                           GSS_C_QOP_DEFAULT,
                           &input_tok,
                           NULL,
                           &output_tok);
        logger.msg(INFO, "GSS wrap: %i/%i", majstat, minstat);
      }
      if (GSS_ERROR(majstat)) {
        logger.msg(ERROR, "GSS wrap/unwrap failed: %i/%i%s", majstat, minstat, GSSCredential::ErrorStr(majstat, minstat));
        majstat = gss_release_buffer(&minstat, &input_tok);
        majstat = gss_release_buffer(&minstat, &output_tok);
        return false;
      }

      logger.msg(VERBOSE, "Output token length: %i", output_tok.length);

      bufferlen = output_tok.length;
      bufferpos = 0;
      buffer = new char[bufferlen];
      memcpy(buffer, output_tok.value, bufferlen);

      majstat = gss_release_buffer(&minstat, &input_tok);
      majstat = gss_release_buffer(&minstat, &output_tok);
    }

    if (size > bufferlen - bufferpos)
      size = bufferlen - bufferpos;

    memcpy(buf, &buffer[bufferpos], size);
    bufferpos += size;
    if (bufferpos == bufferlen) {
      delete[] buffer;
      buffer = NULL;
    }

    return true;
  }

Here is the call graph for this function:

bool Arc::PayloadGSIStream::Get ( std::string &  buf) [virtual]

Read as many as possible (sane amount) of bytes into buf.

Implements Arc::PayloadStreamInterface.

Definition at line 114 of file PayloadGSIStream.cpp.

                                           {
    char tbuf[1024];
    int l = sizeof(tbuf);
    bool result = Get(tbuf, l);
    buf.assign(tbuf, l);
    return result;
  }

Here is the call graph for this function:

virtual std::string Arc::PayloadGSIStream::Get ( ) [inline, virtual]

Read as many as possible (sane amount) of bytes.

Implements Arc::PayloadStreamInterface.

Definition at line 29 of file PayloadGSIStream.h.

                            {
      std::string buf;
      Get(buf);
      return buf;
    }

Here is the caller graph for this function:

virtual Size_t Arc::PayloadGSIStream::Limit ( void  ) const [inline, virtual]

Returns position at which stream reading will stop if supported.

That may be not same as Size() if instance is meant to provide access to only part of underlying obejct.

Implements Arc::PayloadStreamInterface.

Definition at line 67 of file PayloadGSIStream.h.

                                     {
      return 0;
   };
virtual Arc::PayloadGSIStream::operator bool ( ) [inline, virtual]

Returns true if stream is valid.

Implements Arc::PayloadStreamInterface.

Definition at line 45 of file PayloadGSIStream.h.

                            {
      return (ctx != GSS_C_NO_CONTEXT);
    }
virtual bool Arc::PayloadGSIStream::operator! ( ) [inline, virtual]

Returns true if stream is invalid.

Implements Arc::PayloadStreamInterface.

Definition at line 49 of file PayloadGSIStream.h.

                             {
      return (ctx == GSS_C_NO_CONTEXT);
    }
virtual Size_t Arc::PayloadGSIStream::Pos ( ) const [inline, virtual]

Returns current position in stream if supported.

Implements Arc::PayloadStreamInterface.

Definition at line 61 of file PayloadGSIStream.h.

                               {
      return 0;
    }
virtual bool Arc::PayloadGSIStream::Put ( const char *  buf,
Size_t  size 
) [inline, virtual]

Push 'size' bytes from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 35 of file PayloadGSIStream.h.

{}

Here is the caller graph for this function:

virtual bool Arc::PayloadGSIStream::Put ( const std::string &  buf) [inline, virtual]

Push information from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 37 of file PayloadGSIStream.h.

                                           {
      return Put(buf.c_str(), buf.length());
    }

Here is the call graph for this function:

virtual bool Arc::PayloadGSIStream::Put ( const char *  buf) [inline, virtual]

Push null terminated information from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 41 of file PayloadGSIStream.h.

                                      {
      return Put(buf, buf ? strlen(buf) : 0);
    }

Here is the call graph for this function:

virtual Size_t Arc::PayloadGSIStream::Size ( void  ) const [inline, virtual]

Returns size of underlying object if supported.

Implements Arc::PayloadStreamInterface.

Definition at line 64 of file PayloadGSIStream.h.

                                    { 
      return 0; 
    }
virtual int Arc::PayloadGSIStream::Timeout ( ) const [inline, virtual]

Query current timeout for Get() and Put() operations.

Implements Arc::PayloadStreamInterface.

Definition at line 53 of file PayloadGSIStream.h.

                                {
      return timeout;
    }
virtual void Arc::PayloadGSIStream::Timeout ( int  to) [inline, virtual]

Set current timeout for Get() and Put() operations.

Implements Arc::PayloadStreamInterface.

Definition at line 57 of file PayloadGSIStream.h.

                                 {
      timeout = to;
    }

Member Data Documentation

char* Arc::PayloadGSIStream::buffer [protected]

Definition at line 74 of file PayloadGSIStream.h.

Definition at line 76 of file PayloadGSIStream.h.

Definition at line 75 of file PayloadGSIStream.h.

Definition at line 79 of file PayloadGSIStream.h.

gss_ctx_id_t& Arc::PayloadGSIStream::ctx [protected]

Definition at line 77 of file PayloadGSIStream.h.

Definition at line 78 of file PayloadGSIStream.h.

Definition at line 73 of file PayloadGSIStream.h.

Definition at line 69 of file PayloadGSIStream.h.


The documentation for this class was generated from the following files: