Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Protected Member Functions | Static Protected Attributes | Static Private Member Functions | Private Attributes
Arc::HTTPSClientConnectorGlobus Class Reference

#include <HTTPSClient.h>

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

List of all members.

Public Member Functions

 HTTPSClientConnectorGlobus (const char *base, bool heavy_encryption, int timeout=60000, gss_cred_id_t cred=GSS_C_NO_CREDENTIAL)
virtual ~HTTPSClientConnectorGlobus (void)
virtual bool credentials (gss_cred_id_t cred)

Protected Member Functions

virtual bool connect (bool &timedout)
 Establish connection and context (if needed)
virtual bool disconnect (void)
 Close connection to remote host.
virtual bool read (char *buf=NULL, unsigned int *size=NULL)
 Set buffer for reading data.
virtual bool write (const char *buf=NULL, unsigned int size=0)
 Set data to be sent.
virtual bool clear (void)
 Read all pending data.
virtual bool transfer (bool &read, bool &write, int timeout)
 Transfer data set by read() and write(). Reset set buffers if operation complete.
virtual bool eofread (void)
 If network connection was closed.
virtual bool eofwrite (void)
 If there is pending buffer set by write()

Static Protected Attributes

static SimpleConditionconnect_lock = new SimpleCondition()
 Lock for mutex on connection (bug 1613)
static Logger logger
 logger

Static Private Member Functions

static void general_callback (void *arg, globus_io_handle_t *handle, globus_result_t result)
static void read_callback (void *arg, globus_io_handle_t *handle, globus_result_t result, globus_byte_t *buf, globus_size_t nbytes)
static void write_callback (void *arg, globus_io_handle_t *handle, globus_result_t result, globus_byte_t *buf, globus_size_t nbytes)
static globus_bool_t authorization_callback (void *arg, globus_io_handle_t *h, globus_result_t result, char *identity, gss_ctx_id_t context_handle)

Private Attributes

bool valid
URL base_url
bool connected
gss_cred_id_t cred
int timeout
bool read_registered
bool write_registered
unsigned int * read_size
SimpleCondition cond
globus_io_handle_t s
globus_io_attr_t attr
globus_io_secure_authorization_data_t auth
int read_done
int write_done

Detailed Description

Definition at line 112 of file HTTPSClient.h.


Constructor & Destructor Documentation

Arc::HTTPSClientConnectorGlobus::HTTPSClientConnectorGlobus ( const char *  base,
bool  heavy_encryption,
int  timeout = 60000,
gss_cred_id_t  cred = GSS_C_NO_CREDENTIAL 
)

Definition at line 64 of file HTTPSClientConnector.cpp.

                                                                                                                                   : base_url(base) {
    valid=false; connected=false;
    read_registered=false;
    write_registered=false;
    read_size=NULL;
    cred=cred_;
    timeout=timeout_; // 1 min.
    /* initialize globus io connection related objects */
    globus_io_tcpattr_init(&attr);
    globus_io_secure_authorization_data_initialize(&auth);
    globus_io_secure_authorization_data_set_callback(&auth,&authorization_callback,NULL);
    if(strcasecmp(base_url.Protocol().c_str(),"http") == 0) {
      globus_io_attr_set_secure_authentication_mode(&attr,
                GLOBUS_IO_SECURE_AUTHENTICATION_MODE_NONE,GSS_C_NO_CREDENTIAL);
      globus_io_attr_set_secure_authorization_mode(&attr,
                GLOBUS_IO_SECURE_AUTHORIZATION_MODE_NONE,GLOBUS_NULL);
      globus_io_attr_set_secure_channel_mode(&attr,
                                   GLOBUS_IO_SECURE_CHANNEL_MODE_CLEAR);
      globus_io_attr_set_secure_protection_mode(&attr,
                                   GLOBUS_IO_SECURE_PROTECTION_MODE_NONE);
      globus_io_attr_set_secure_delegation_mode(&attr,
                                   GLOBUS_IO_SECURE_DELEGATION_MODE_NONE);
    } else if(strcasecmp(base_url.Protocol().c_str(),"https") == 0) {
      globus_io_attr_set_secure_authentication_mode(&attr,
                GLOBUS_IO_SECURE_AUTHENTICATION_MODE_MUTUAL,cred);
      globus_io_attr_set_secure_authorization_mode(&attr,
                GLOBUS_IO_SECURE_AUTHORIZATION_MODE_HOST,GLOBUS_NULL);
      globus_io_attr_set_secure_channel_mode(&attr,
                                   GLOBUS_IO_SECURE_CHANNEL_MODE_SSL_WRAP);
      if(heavy_encryption) {
        globus_io_attr_set_secure_protection_mode(&attr,
                                   GLOBUS_IO_SECURE_PROTECTION_MODE_PRIVATE);
      } else {
        globus_io_attr_set_secure_protection_mode(&attr,
                                   GLOBUS_IO_SECURE_PROTECTION_MODE_SAFE);
      };
      globus_io_attr_set_secure_delegation_mode(&attr,
                                   GLOBUS_IO_SECURE_DELEGATION_MODE_NONE);
    } else if(strcasecmp(base_url.Protocol().c_str(),"httpg") == 0) {
      globus_io_attr_set_secure_authentication_mode(&attr,
                GLOBUS_IO_SECURE_AUTHENTICATION_MODE_GSSAPI,cred);
      globus_io_attr_set_secure_authorization_mode(&attr,
                GLOBUS_IO_SECURE_AUTHORIZATION_MODE_HOST,GLOBUS_NULL);
      globus_io_attr_set_secure_channel_mode(&attr,
                                   GLOBUS_IO_SECURE_CHANNEL_MODE_GSI_WRAP);
      if(heavy_encryption) {
        globus_io_attr_set_secure_protection_mode(&attr,
                                   GLOBUS_IO_SECURE_PROTECTION_MODE_PRIVATE);
      } else {
        globus_io_attr_set_secure_protection_mode(&attr,
                                   GLOBUS_IO_SECURE_PROTECTION_MODE_SAFE);
      };
      globus_io_attr_set_secure_delegation_mode(&attr,
                                   ChooseDelegationMode(cred));
    } else {
      return;
    };
    globus_io_attr_set_secure_proxy_mode(&attr,GLOBUS_IO_SECURE_PROXY_MODE_NONE);
    valid=true;
  } catch(std::exception e) {
    timeout=timeout_; // 1 min.
    valid=false; connected=false;
    /* initialize globus io connection related objects */
    globus_io_tcpattr_init(&attr);
    globus_io_secure_authorization_data_initialize(&auth);
    globus_io_secure_authorization_data_set_callback(&auth,&authorization_callback,NULL);
  }

Here is the call graph for this function:

Definition at line 132 of file HTTPSClientConnector.cpp.

                                                              {
    disconnect();
    globus_io_secure_authorization_data_destroy(&auth);
    globus_io_tcpattr_destroy(&attr);
  }

Here is the call graph for this function:


Member Function Documentation

globus_bool_t Arc::HTTPSClientConnectorGlobus::authorization_callback ( void *  arg,
globus_io_handle_t *  h,
globus_result_t  result,
char *  identity,
gss_ctx_id_t  context_handle 
) [static, private]

Definition at line 324 of file HTTPSClientConnector.cpp.

                                                                                                                                                                    {
    logger.msg(DEBUG, "Authenticating: %s", identity);
    return GLOBUS_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::HTTPSClientConnectorGlobus::clear ( void  ) [protected, virtual]

Read all pending data.

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 263 of file HTTPSClientConnector.cpp.

                                             {
    if(!valid) return false;
    globus_byte_t buf[256];
    globus_size_t l;
    for(;;) {
      if(globus_io_read(&s,buf,256,0,&l) != GLOBUS_SUCCESS) return false;
      if(l == 0) break;
      std::string buf_str;
      for(globus_size_t n=0;n<l;n++) buf_str += buf[n];
      logger.msg(DEBUG, "clear_input: %s", buf_str);
    };
    return true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::HTTPSClientConnectorGlobus::connect ( bool &  timedout) [protected, virtual]

Establish connection and context (if needed)

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 210 of file HTTPSClientConnector.cpp.

                                                         {
    if(!valid) return false;
    if(connected) return true;
    globus_result_t res;
    read_registered=false; write_registered=false;
    read_done=-1; write_done=-1;
    cond.reset();
    connect_lock->lock();
    if((res=globus_io_tcp_register_connect(
                      (char*)(base_url.Host().c_str()),base_url.Port(),
                      &attr,&general_callback,this,&s)) != GLOBUS_SUCCESS) {
      logger.msg(ERROR, "Connect to %s failed: %s", base_url.str(), GlobusResult(res).str());
      connect_lock->unlock();
      return false;
    };
    globus_thread_blocking_will_block(); // ????
    if(!cond.wait(timeout)) {  // timeout
      logger.msg(ERROR, "Connection to %s timed out after %i seconds", base_url.str(), timeout/1000);
      globus_io_cancel(&s,GLOBUS_FALSE);
      globus_io_close(&s);
      connect_lock->unlock();
      timedout = true;
      return false;
    };
    connect_lock->unlock();
    connected=true;
    return true;
  }

Here is the call graph for this function:

bool Arc::HTTPSClientConnectorGlobus::credentials ( gss_cred_id_t  cred) [virtual]

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 138 of file HTTPSClientConnector.cpp.

                                                                  {
    if(cred_ == GSS_C_NO_CREDENTIAL) return false;
    gss_cred_id_t cred_old;
    globus_io_secure_authentication_mode_t mode;
    if(globus_io_attr_get_secure_authentication_mode(&attr,&mode,&cred_old) !=
                                         GLOBUS_SUCCESS) return false;
    if(globus_io_attr_set_secure_authentication_mode(&attr,mode,cred_) !=
                                         GLOBUS_SUCCESS) return false;
    cred=cred_;
    return true;
  }
bool Arc::HTTPSClientConnectorGlobus::disconnect ( void  ) [protected, virtual]

Close connection to remote host.

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 239 of file HTTPSClientConnector.cpp.

                                                  {
    if(!connected) return true;
    globus_io_cancel(&s,GLOBUS_FALSE);
    globus_io_close(&s);
    connected=false;
    return true;
  }

Here is the caller graph for this function:

bool Arc::HTTPSClientConnectorGlobus::eofread ( void  ) [protected, virtual]

If network connection was closed.

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 329 of file HTTPSClientConnector.cpp.

                                               {
    return (read_done==2);
  }
bool Arc::HTTPSClientConnectorGlobus::eofwrite ( void  ) [protected, virtual]

If there is pending buffer set by write()

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 333 of file HTTPSClientConnector.cpp.

                                                {
    return (!write_registered);
  }
void Arc::HTTPSClientConnectorGlobus::general_callback ( void *  arg,
globus_io_handle_t *  handle,
globus_result_t  result 
) [static, private]

Definition at line 277 of file HTTPSClientConnector.cpp.

                                                                                                                {
    HTTPSClientConnectorGlobus* it = (HTTPSClientConnectorGlobus*)arg;
    if(result != GLOBUS_SUCCESS) logger.msg(ERROR, "Globus error: %s", GlobusResult(result).str());
    it->cond.signal();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::HTTPSClientConnectorGlobus::read ( char *  buf = NULL,
unsigned int *  size = NULL 
) [protected, virtual]

Set buffer for reading data.

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 150 of file HTTPSClientConnector.cpp.

                                                                    {
    if(!connected) return false;
    globus_result_t res;
    unsigned int size_=size?*size:0;
    if(size) *size=0;
    if((buf == NULL) || (size_ == 0)) {
      // cancel request
      if(read_registered) {
        res=globus_io_cancel(&s,GLOBUS_FALSE);
        if(res != GLOBUS_SUCCESS) {
          logger.msg(ERROR, "globus_io_cancel failed: %s", GlobusResult(res).str());
          return false;
        };
        read_registered=false;
        write_registered=false;
      };
      return true;
    };
    if(read_registered) return false;
    read_size=size;
    read_registered=true;
    read_done=-1; cond.reset();
    res=globus_io_register_read(&s,(globus_byte_t*)buf,size_,1,
                                                       &read_callback,this);
    if(res != GLOBUS_SUCCESS) {
      read_registered=false;
      logger.msg(ERROR, "globus_io_register_read failed: %s", GlobusResult(res).str());
      return false;
    };
    return true;
  }

Here is the call graph for this function:

void Arc::HTTPSClientConnectorGlobus::read_callback ( void *  arg,
globus_io_handle_t *  handle,
globus_result_t  result,
globus_byte_t *  buf,
globus_size_t  nbytes 
) [static, private]

Definition at line 283 of file HTTPSClientConnector.cpp.

                                                                                                                                                    {
    HTTPSClientConnectorGlobus* it = (HTTPSClientConnectorGlobus*)arg;
    int res = 0;
    if(result != GLOBUS_SUCCESS) {
      globus_object_t* err = globus_error_get(result);
      char* tmp=globus_object_printable_to_string(err);
      if(strstr(tmp,"end-of-file") != NULL) {
        logger.msg(DEBUG, "Connection closed");
        res=2; // eof
      } else {
        logger.msg(ERROR, "Globus error (read): %s", tmp);
        res=1;
      };
      free(tmp); globus_object_free(err);
    } else {
      std::string buf_str;
      for(globus_size_t n=0;n<nbytes;n++) buf_str += buf[n];
      logger.msg(DEBUG, "*** Server response: %s", buf_str);
      if(it->read_size) *(it->read_size)=nbytes;
    };
    it->cond.lock();
    it->read_done=res; it->cond.signal_nonblock();
    it->cond.unlock();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::HTTPSClientConnectorGlobus::transfer ( bool &  read,
bool &  write,
int  timeout 
) [protected, virtual]

Transfer data set by read() and write(). Reset set buffers if operation complete.

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 247 of file HTTPSClientConnector.cpp.

                                                                              {
    read=false; write=false;
    if((!read_registered) && (!write_registered)) return true;
    for(;;) {
      if(read_registered && (read_done!=-1)) {
        read_registered=false; read=(read_done==0); break;
      };
      if(write_registered && (write_done!=-1)) {
        write_registered=false; write=(write_done==0); break;
      };
      if(!cond.wait(timeout)) return false; // timeout
    };
    return true;
  }

Here is the call graph for this function:

bool Arc::HTTPSClientConnectorGlobus::write ( const char *  buf = NULL,
unsigned int  size = 0 
) [protected, virtual]

Set data to be sent.

Reimplemented from Arc::HTTPSClientConnector.

Definition at line 182 of file HTTPSClientConnector.cpp.

                                                                          {
    if(!connected) return false;
    globus_result_t res;
    if((buf == NULL) || (size == 0)) {
      // cancel request
      if(write_registered) {
        res=globus_io_cancel(&s,GLOBUS_FALSE);
        if(res != GLOBUS_SUCCESS) {
          logger.msg(ERROR, "globus_io_cancel failed: %s", GlobusResult(res).str());
          return false;
        };
        read_registered=false;
        write_registered=false;
      };
      return true;
    };
    if(write_registered) return false;
    write_registered=true;
    write_done=-1; cond.reset();
    res=globus_io_register_write(&s,(globus_byte_t*)buf,size,&write_callback,this);
    if(res != GLOBUS_SUCCESS) {
      write_registered=false;
      logger.msg(ERROR, "globus_io_register_write failed: %s", GlobusResult(res).str());
      return false;
    };
    return true;
  }

Here is the call graph for this function:

void Arc::HTTPSClientConnectorGlobus::write_callback ( void *  arg,
globus_io_handle_t *  handle,
globus_result_t  result,
globus_byte_t *  buf,
globus_size_t  nbytes 
) [static, private]

Definition at line 308 of file HTTPSClientConnector.cpp.

                                                                                                                                                     {
    HTTPSClientConnectorGlobus* it = (HTTPSClientConnectorGlobus*)arg;
    int res = 0;
    if(result != GLOBUS_SUCCESS) {
      logger.msg(ERROR, "Globus error (write): %s", GlobusResult(result).str());
      res=1;
    } else {
      std::string buf_str;
      for(globus_size_t n=0;n<nbytes;n++) buf_str += buf[n];
      logger.msg(DEBUG, "*** Client request: %s", buf_str);
    };
    it->cond.lock();
    it->write_done=res; it->cond.signal_nonblock();
    it->cond.unlock();
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

globus_io_attr_t Arc::HTTPSClientConnectorGlobus::attr [private]

Definition at line 124 of file HTTPSClient.h.

globus_io_secure_authorization_data_t Arc::HTTPSClientConnectorGlobus::auth [private]

Definition at line 125 of file HTTPSClient.h.

Definition at line 115 of file HTTPSClient.h.

Definition at line 122 of file HTTPSClient.h.

Lock for mutex on connection (bug 1613)

Definition at line 86 of file HTTPSClient.h.

Definition at line 116 of file HTTPSClient.h.

gss_cred_id_t Arc::HTTPSClientConnectorGlobus::cred [private]

Definition at line 117 of file HTTPSClient.h.

Logger Arc::HTTPSClientConnector::logger [static, protected, inherited]

logger

Definition at line 105 of file HTTPSClient.h.

Definition at line 126 of file HTTPSClient.h.

Definition at line 119 of file HTTPSClient.h.

Definition at line 121 of file HTTPSClient.h.

globus_io_handle_t Arc::HTTPSClientConnectorGlobus::s [private]

Definition at line 123 of file HTTPSClient.h.

Definition at line 118 of file HTTPSClient.h.

Definition at line 114 of file HTTPSClient.h.

Definition at line 127 of file HTTPSClient.h.

Definition at line 120 of file HTTPSClient.h.


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