Back to index

nordugrid-arc-nox  1.1.0~rc6
HTTPSClientSoap.cpp
Go to the documentation of this file.
00001 #include "HTTPSClient.h"
00002 
00003 namespace Arc {
00004   
00005   int HTTPSClientSOAP::local_fsend(struct soap *sp, const char* buf, size_t l) {
00006     if(sp->socket != 0) return SOAP_SSL_ERROR;
00007     HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
00008   
00009     // do not register read - so cond will be set by writer only
00010     if(!it->c->write(buf,l)) {
00011       return SOAP_SSL_ERROR;
00012     };
00013     bool isread,iswritten;
00014     if(!it->c->transfer(isread,iswritten,it->timeout)) {
00015       logger.msg(ERROR, "Timeout while sending SOAP request");
00016       return SOAP_SSL_ERROR;
00017     };
00018     if(!iswritten) {
00019       logger.msg(ERROR, "Error sending data to server");
00020       return SOAP_SSL_ERROR;
00021     };
00022     return SOAP_OK;
00023   }
00024   
00025   size_t HTTPSClientSOAP::local_frecv(struct soap* sp, char* buf, size_t l) {
00026     if(sp->socket != 0) return 0;
00027     HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
00028     it->answer_size = l;
00029     if(!it->c->read(buf,&(it->answer_size))) {
00030       return 0;
00031     };
00032     bool isread,iswritten;
00033     if(!it->c->transfer(isread,iswritten,it->timeout)) {
00034       return 0;
00035     };
00036     if(!isread) return 0;
00037     return it->answer_size;
00038   }
00039 
00040 #ifndef WIN32  
00041   int HTTPSClientSOAP::local_fopen(struct soap* sp, const char* endpoint, const char* host, int port) {
00042 #else
00043   SOCKET HTTPSClientSOAP::local_fopen(struct soap* sp, const char* endpoint, const char* host, int port) {
00044 #endif
00045 
00046     if(sp->socket == 0) return 0;
00047     HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
00048     if(it->connect() != 0) return -1;
00049     sp->socket=0;
00050     return 0;
00051   };
00052   
00053   int HTTPSClientSOAP::local_fclose(struct soap* sp) {
00054     if(sp->socket == -1) return 0;
00055     HTTPSClientSOAP *it = (HTTPSClientSOAP*)(sp->user);
00056     if(it->disconnect() != 0) return -1;
00057     sp->socket=-1;
00058     return 0;
00059   };
00060   
00061   
00062   HTTPSClientSOAP::HTTPSClientSOAP(const char* base,struct soap *sp,bool gssapi_server, int soap_timeout, bool check_host_cert):HTTPSClient(base,true,gssapi_server,soap_timeout, check_host_cert),soap(sp) {
00063     /* intialize soap */
00064     namespaces=NULL;
00065     soap_init(soap);
00066     soap->fsend=&local_fsend;
00067     soap->frecv=&local_frecv;
00068     soap->fopen=&local_fopen;
00069     soap->fclose=&local_fclose;
00070     soap->http_version="1.1";
00071     soap->socket=-1;
00072     soap->keep_alive=1;
00073     soap_set_imode(soap,SOAP_IO_KEEPALIVE);
00074     soap_set_omode(soap,SOAP_IO_KEEPALIVE);
00075     soap->user=this;
00076     soap_url=base;
00077     std::string::size_type n = soap_url.find(':');
00078     if(n != std::string::npos) soap_url.replace(0,n,"http"); // fake url for gSOAP
00079   }  
00080   
00081   HTTPSClientSOAP::~HTTPSClientSOAP(void) {
00082     soap_destroy(soap);
00083     soap_end(soap);
00084     soap_done(soap);
00085   }
00086   
00087   void HTTPSClientSOAP::reset(void) {
00088     soap_destroy(soap);
00089     soap_end(soap);
00090   }
00091   
00092   void HTTPSClientSOAP::AddSOAPNamespaces(struct Namespace* namespaces_) {
00093     if(!namespaces_) return;
00094     int n = 0;
00095     int n_ = 0;
00096     struct Namespace *ns;
00097     if(namespaces) for(ns=namespaces;ns->id;ns++) { n++; };
00098     for(ns=namespaces_;ns->id;ns++) { n_++; };
00099     ns=(struct Namespace*)realloc(namespaces,sizeof(struct Namespace)*(n+n_+1));
00100     if(ns == NULL) return;
00101     memcpy(ns+n,namespaces_,sizeof(struct Namespace)*(n_+1));
00102     namespaces=ns;
00103     if(soap) soap->namespaces=namespaces;
00104   }
00105   
00106   std::string HTTPSClientSOAP::SOAP_URL(const char* path) {
00107     std::string s = soap_url;
00108     if(s.length() <= 0) return s;
00109     if(s[s.length()-1] != '/') s+="/";
00110     if(path == NULL) return s;
00111     if(path[0] == '/') path++;
00112     s+=path;
00113     return s;
00114   }
00115   
00116   const struct Namespace* HTTPSClientSOAP::Namespaces(void) {
00117     if(namespaces) return namespaces;
00118     if(soap) return soap->namespaces;
00119     return NULL;
00120   }
00121 }  // namespace Arc