Back to index

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

#include <HTTPSClient.h>

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

List of all members.

Public Types

typedef int(* get_callback_t )(unsigned long long offset, unsigned long long size, unsigned char **buf, unsigned long long *bufsize, void *arg)
typedef int(* put_callback_t )(unsigned long long offset, unsigned long long *size, char *buf)

Public Member Functions

 HTTPSClientSOAP (const char *base, struct soap *sp, bool gssapi_server=false, int soap_timeout=60, bool check_host_cert=true)
 ~HTTPSClientSOAP (void)
const char * SOAP_URL (void)
std::string SOAP_URL (const char *path)
void reset (void)
void AddSOAPNamespaces (struct Namespace *namespaces)
struct NamespaceNamespaces (void)
 operator bool (void)
bool credentials (const char *filename)
int connect (void)
 Returns 0 on success, 1 on timeout and -1 on other error.
int disconnect (void)
int PUT (const char *path, unsigned long long int offset, unsigned long long int size, const unsigned char *buf, unsigned long long int fd_size, bool wait=true)
int GET (const char *path, unsigned long long int offset, unsigned long long int size, get_callback_t callback, void *arg, unsigned char *buf=NULL, unsigned long long int bufsize=0)
bool keep_alive (void) const
const HTTPResponseHeaderresponse (void)

Static Private Member Functions

static int local_fsend (struct soap *sp, const char *buf, size_t l)
static size_t local_frecv (struct soap *sp, char *buf, size_t l)
static int local_fopen (struct soap *sp, const char *endpoint, const char *host, int port)
static int local_fclose (struct soap *sp)

Private Attributes

struct::soap * soap
struct Namespacenamespaces
std::string soap_url

Detailed Description

Definition at line 223 of file HTTPSClient.h.


Member Typedef Documentation

typedef int(* Arc::HTTPSClient::get_callback_t)(unsigned long long offset, unsigned long long size, unsigned char **buf, unsigned long long *bufsize, void *arg) [inherited]

Definition at line 207 of file HTTPSClient.h.

typedef int(* Arc::HTTPSClient::put_callback_t)(unsigned long long offset, unsigned long long *size, char *buf) [inherited]

Definition at line 208 of file HTTPSClient.h.


Constructor & Destructor Documentation

Arc::HTTPSClientSOAP::HTTPSClientSOAP ( const char *  base,
struct soap sp,
bool  gssapi_server = false,
int  soap_timeout = 60,
bool  check_host_cert = true 
)

Definition at line 62 of file HTTPSClientSoap.cpp.

                                                                                                                             :HTTPSClient(base,true,gssapi_server,soap_timeout, check_host_cert),soap(sp) {
    /* intialize soap */
    namespaces=NULL;
    soap_init(soap);
    soap->fsend=&local_fsend;
    soap->frecv=&local_frecv;
    soap->fopen=&local_fopen;
    soap->fclose=&local_fclose;
    soap->http_version="1.1";
    soap->socket=-1;
    soap->keep_alive=1;
    soap_set_imode(soap,SOAP_IO_KEEPALIVE);
    soap_set_omode(soap,SOAP_IO_KEEPALIVE);
    soap->user=this;
    soap_url=base;
    std::string::size_type n = soap_url.find(':');
    if(n != std::string::npos) soap_url.replace(0,n,"http"); // fake url for gSOAP
  }  

Here is the call graph for this function:

Definition at line 81 of file HTTPSClientSoap.cpp.

                                        {
    soap_destroy(soap);
    soap_end(soap);
    soap_done(soap);
  }

Member Function Documentation

void Arc::HTTPSClientSOAP::AddSOAPNamespaces ( struct Namespace namespaces)

Definition at line 92 of file HTTPSClientSoap.cpp.

                                                                       {
    if(!namespaces_) return;
    int n = 0;
    int n_ = 0;
    struct Namespace *ns;
    if(namespaces) for(ns=namespaces;ns->id;ns++) { n++; };
    for(ns=namespaces_;ns->id;ns++) { n_++; };
    ns=(struct Namespace*)realloc(namespaces,sizeof(struct Namespace)*(n+n_+1));
    if(ns == NULL) return;
    memcpy(ns+n,namespaces_,sizeof(struct Namespace)*(n_+1));
    namespaces=ns;
    if(soap) soap->namespaces=namespaces;
  }
int Arc::HTTPSClient::connect ( void  ) [inherited]

Returns 0 on success, 1 on timeout and -1 on other error.

Definition at line 62 of file HTTPSClient.cpp.

                               {
    if(connected) return 0;
    if(!valid) return -1;
    bool timeout = false;
    if(!c->connect(timeout)) {
      if (timeout) return 1;
      return -1;
    }
    connected=true;
    return 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::HTTPSClient::credentials ( const char *  filename) [inherited]

Definition at line 47 of file HTTPSClient.cpp.

                                                    {
    if(!filename) return false;
    cred = new GSSCredential(filename, "", "");
    //gss_cred_id_t cred_new = *cred;
    if(*cred == GSS_C_NO_CREDENTIAL) {
      delete cred;
      return false;
    }
    if(!c->credentials(*cred)) {
      delete cred;
      return false;
    };
    return true;
  }

Here is the call graph for this function:

int Arc::HTTPSClient::disconnect ( void  ) [inherited]

Definition at line 74 of file HTTPSClient.cpp.

                                  {
    if(!connected) return 0;
    c->disconnect();
    connected=false;
    return 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

int Arc::HTTPSClient::GET ( const char *  path,
unsigned long long int  offset,
unsigned long long int  size,
get_callback_t  callback,
void *  arg,
unsigned char *  buf = NULL,
unsigned long long int  bufsize = 0 
) [inherited]

cond_read.reset();

Definition at line 393 of file HTTPSClient.cpp.

                                                           {
    if(!connected) {
      logger.msg(ERROR, "Not connected");
      return -1;
    };
    // send header
    if(GET_header(path,offset,size)) {
      // There are servers which close connection even if they shouldn't - retry here
      if(connect()) return -1;
      if(GET_header(path,offset,size)) return -1;
    };
    // read server response
    if(read_response_header() != 0) {
      logger.msg(ERROR, "No response from server received");
      disconnect();
      return -1;
    };
    if(answer_code == 416) { // out of range
      if(skip_response_entity() != 0) {
        disconnect(); return -1;
      };
      if(!fields.KeepAlive()) {
        logger.msg(VERBOSE, "GET: connection to be closed");
        disconnect();
      };
      return 0;
    };
    if((answer_code != 200) && (answer_code != 206)) {
      if(skip_response_entity() != 0) {
        disconnect(); return -1;
      };
      if(!fields.KeepAlive()) {
      logger.msg(VERBOSE, "GET: connection to be closed");
        disconnect();
      };
      return -1;
    };
    logger.msg(VERBOSE, "GET: header is read - rest: %u", answer_size);
    unsigned long long c_offset = 0;
    if(fields.haveContentRange()) c_offset=fields.ContentStart();
    bool have_length = fields.haveContentLength() || fields.haveContentRange();
    unsigned long long length = fields.ContentLength();
    // take rest of already read data
    if(answer_size) {
      if(have_length) if(answer_size > length) answer_size=length;
      logger.msg(DEBUG, "GET: calling callback(rest): content: %s", answer_buf);
      logger.msg(DEBUG, "GET: calling callback(rest): size: %u", answer_size);
      logger.msg(DEBUG, "GET: calling callback(rest): offset: %llu", c_offset);
      unsigned char* in_buf = (unsigned char*)answer_buf;
      unsigned long  in_size = answer_size;
      for(;;) {
        if(in_size == 0) break;
        if(buf) {
          unsigned long l = in_size;
          if(l>bufsize) l=bufsize;
          memcpy(buf,in_buf,l);
          if(callback(c_offset,l,&buf,&bufsize,arg) != 0) {
            logger.msg(ERROR, "GET callback returned error");
            disconnect(); // ?????????????????
            return -1;
          };
          in_buf+=l; c_offset+=l; in_size-=l;
        } else {
          unsigned char* in_buf_ = in_buf;
          if(callback(c_offset,in_size,&in_buf_,&bufsize,arg) != 0) {
            logger.msg(ERROR, "GET callback returned error");
            disconnect(); // ?????????????????
            return -1;
          };
          if(in_buf_ != in_buf) buf=in_buf_;
          in_buf+=in_size; c_offset+=in_size; in_size=0;
        };
      };
      if(have_length) length-=answer_size;
    };
    unsigned char* in_buf = NULL;
    for(;;) {
      if(have_length) if(length == 0) break; 
      if(buf == NULL) {
        if(in_buf == NULL) in_buf=(unsigned char*)malloc(65536);
        if(in_buf == NULL) {
          logger.msg(ERROR, "Failed to allocate memory");
          disconnect();
          return -1;
        };
        buf=in_buf; bufsize=65536;
      };
      answer_size=bufsize;
      if(!c->read((char*)buf,&answer_size)) {
        logger.msg(ERROR, "Failed while reading response content");
        disconnect();
        if(in_buf) free(in_buf);
        return -1;
      };
      bool isread,iswritten;
      if(!c->transfer(isread,iswritten,timeout)) {
        logger.msg(ERROR, "Timeout while reading response content");
        disconnect();
        if(in_buf) free(in_buf);
        return -1; // timeout
      };
      if(!isread) { // failure
        if(c->eofread()) { // eof - ok if length not specified
          if(!have_length) { disconnect(); break; };
        };
        logger.msg(ERROR, "Error while reading response content");
        disconnect();
        if(in_buf) free(in_buf);
        return -1;
      };
      logger.msg(DEBUG, "GET: calling callback: content: %s", buf);
      logger.msg(DEBUG, "GET: calling callback: size: %u", answer_size);
      logger.msg(DEBUG, "GET: calling callback: offset: %llu", c_offset);
      if(callback(c_offset,answer_size,&buf,&bufsize,arg) != 0) {
        logger.msg(ERROR, "GET callback returned error");
        disconnect();
        if(in_buf) free(in_buf);
        return -1;
      };
      c_offset+=answer_size;
      if(have_length) length-=answer_size;
    };
    // cancel? - just in case
    if(in_buf) free(in_buf);
    if(!fields.KeepAlive()) {
      logger.msg(VERBOSE, "GET: connection to be closed");
      disconnect();
    };
    return 0;
  }

Here is the call graph for this function:

bool Arc::HTTPSClient::keep_alive ( void  ) const [inline, inherited]

Definition at line 218 of file HTTPSClient.h.

{ return fields.KeepAlive(); };

Here is the call graph for this function:

int Arc::HTTPSClientSOAP::local_fclose ( struct soap sp) [static, private]

Definition at line 53 of file HTTPSClientSoap.cpp.

                                                   {
    if(sp->socket == -1) return 0;
    HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
    if(it->disconnect() != 0) return -1;
    sp->socket=-1;
    return 0;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

int Arc::HTTPSClientSOAP::local_fopen ( struct soap sp,
const char *  endpoint,
const char *  host,
int  port 
) [static, private]

Definition at line 41 of file HTTPSClientSoap.cpp.

                                                                                                    {
#else
  SOCKET HTTPSClientSOAP::local_fopen(struct soap* sp, const char* endpoint, const char* host, int port) {
#endif

    if(sp->socket == 0) return 0;
    HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
    if(it->connect() != 0) return -1;
    sp->socket=0;
    return 0;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

size_t Arc::HTTPSClientSOAP::local_frecv ( struct soap sp,
char *  buf,
size_t  l 
) [static, private]

Definition at line 25 of file HTTPSClientSoap.cpp.

                                                                          {
    if(sp->socket != 0) return 0;
    HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
    it->answer_size = l;
    if(!it->c->read(buf,&(it->answer_size))) {
      return 0;
    };
    bool isread,iswritten;
    if(!it->c->transfer(isread,iswritten,it->timeout)) {
      return 0;
    };
    if(!isread) return 0;
    return it->answer_size;
  }

Here is the caller graph for this function:

int Arc::HTTPSClientSOAP::local_fsend ( struct soap sp,
const char *  buf,
size_t  l 
) [static, private]

Definition at line 5 of file HTTPSClientSoap.cpp.

                                                                             {
    if(sp->socket != 0) return SOAP_SSL_ERROR;
    HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
  
    // do not register read - so cond will be set by writer only
    if(!it->c->write(buf,l)) {
      return SOAP_SSL_ERROR;
    };
    bool isread,iswritten;
    if(!it->c->transfer(isread,iswritten,it->timeout)) {
      logger.msg(ERROR, "Timeout while sending SOAP request");
      return SOAP_SSL_ERROR;
    };
    if(!iswritten) {
      logger.msg(ERROR, "Error sending data to server");
      return SOAP_SSL_ERROR;
    };
    return SOAP_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

struct Namespace * Arc::HTTPSClientSOAP::Namespaces ( void  ) [read]

Definition at line 116 of file HTTPSClientSoap.cpp.

                                                          {
    if(namespaces) return namespaces;
    if(soap) return soap->namespaces;
    return NULL;
  }
Arc::HTTPSClient::operator bool ( void  ) [inline, inherited]

Definition at line 211 of file HTTPSClient.h.

{ return valid; };
int Arc::HTTPSClient::PUT ( const char *  path,
unsigned long long int  offset,
unsigned long long int  size,
const unsigned char *  buf,
unsigned long long int  fd_size,
bool  wait = true 
) [inherited]

Definition at line 278 of file HTTPSClient.cpp.

                                                                           {
    if(!connected) {
      logger.msg(ERROR, "Not connected");
      return -1;
    };
    // send header
    // create header
    std::string header;
    make_header(path,offset,size,fd_size,header);
    c->clear();
    answer_size=sizeof(answer_buf)-1;
    if(!c->read(answer_buf,&answer_size)) {
      disconnect(); return -1;
    };
    // send header
    if(!c->write(header.c_str(),header.length())) {
      disconnect(); return -1;
    };
    bool isread,iswritten;
    if(!c->transfer(isread,iswritten,timeout)) {
      logger.msg(ERROR, "Timeout sending header");
      disconnect(); return -1;
    };
    if(!iswritten) { // Server responded too early
      logger.msg(ERROR, "Early response from server");
      disconnect(); return -1;
    };
    // send body
    if(!c->write((const char*)buf,size)) {
      disconnect(); return -1;
    };
    // read server response
    if(read_response_header() != 0) {
      logger.msg(ERROR, "No response from server received");
      disconnect(); return -1;
    };
    if(!c->eofwrite()) {
      logger.msg(ERROR, "Failed to send body");
      disconnect(); return -1;
    };
    if(fields.KeepAlive()) {  // skip entity only if trying to keep connection
      if(skip_response_entity() != 0) {
        logger.msg(ERROR, "Failure while receiving entity");
        disconnect();
        return -1;
      };
      c->read(); // just in case
    } else {
      disconnect();
    };
    if(answer_code != HTTP_OK) return -1;
    return 0;
  }

Here is the call graph for this function:

void Arc::HTTPSClientSOAP::reset ( void  )

Definition at line 87 of file HTTPSClientSoap.cpp.

                                  {
    soap_destroy(soap);
    soap_end(soap);
  }

Here is the caller graph for this function:

const HTTPResponseHeader& Arc::HTTPSClient::response ( void  ) [inline, inherited]

Definition at line 220 of file HTTPSClient.h.

{ return fields; };
const char* Arc::HTTPSClientSOAP::SOAP_URL ( void  ) [inline]

Definition at line 241 of file HTTPSClient.h.

{ return soap_url.c_str(); };

Here is the caller graph for this function:

std::string Arc::HTTPSClientSOAP::SOAP_URL ( const char *  path)

Definition at line 106 of file HTTPSClientSoap.cpp.

                                                      {
    std::string s = soap_url;
    if(s.length() <= 0) return s;
    if(s[s.length()-1] != '/') s+="/";
    if(path == NULL) return s;
    if(path[0] == '/') path++;
    s+=path;
    return s;
  }

Member Data Documentation

Definition at line 226 of file HTTPSClient.h.

struct ::soap* Arc::HTTPSClientSOAP::soap [private]

Definition at line 225 of file HTTPSClient.h.

std::string Arc::HTTPSClientSOAP::soap_url [private]

Definition at line 237 of file HTTPSClient.h.


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