/Home/aooliver/work/stagersvc/org.glite.data.lcg_gfal/src/lrc_ifce.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005-2006 by CERN
00003  */
00004 
00005 /*
00006  * @(#)$RCSfile: lrc_ifce.c,v $ $Revision: 1.1.1.1 $ $Date: 2006/09/06 08:54:53 $ CERN Jean-Philippe Baud
00007  */
00008 
00009 #include <errno.h>
00010 #include <string.h>
00011 #include "stdsoap2.h"
00012 #undef SOAP_FMAC3
00013 #define SOAP_FMAC3 static
00014 #undef SOAP_FMAC5
00015 #define SOAP_FMAC5 static
00016 #include "lrcH.h"
00017 #include "edg_local_replica_catalogSoapBinding+.nsmap"
00018 #ifdef GFAL_SECURE
00019 #include "cgsi_plugin.h"
00020 #endif
00021 #include "lrcC.c"
00022 #include "lrcClient.c"
00023 char *lrc_endpoint;
00024 extern char *rmc_endpoint;
00025 
00026 #include "gfal_api.h"
00027 
00028 static int
00029 lrc_init (struct soap *soap, char *errbuf, int errbufsz)
00030 {
00031         int flags;
00032 
00033         soap_init (soap);
00034         soap->namespaces = namespaces_lrc;
00035 
00036         if (lrc_endpoint == NULL &&
00037             (lrc_endpoint = getenv ("LRC_ENDPOINT")) == NULL &&
00038             get_rls_endpointsx (&lrc_endpoint, &rmc_endpoint, errbuf, errbufsz)) {
00039                 errno = EINVAL;
00040                 return (-1);
00041         }
00042 
00043 #ifdef GFAL_SECURE
00044         if (strncmp (lrc_endpoint, "https", 5) == 0) {
00045                 flags = CGSI_OPT_SSL_COMPATIBLE;
00046                 soap_register_plugin_arg (soap, client_cgsi_plugin, &flags);
00047         }
00048 #endif
00049         return (0);
00050 }
00051 
00052 
00053 char *
00054 lrc_get_catalog_endpoint(char *errbuf, int errbufsz) {
00055         struct soap soap;
00056         if(lrc_init(&soap, errbuf, errbufsz) < 0)
00057                 return (NULL);
00058         return lrc_endpoint;
00059 }
00060 
00061 int
00062 lrc_replica_exists (const char *guid, char *errbuf, int errbufsz)
00063 {
00064         struct ns3__getPfnsResponse out;
00065         int ret;
00066         int sav_errno;
00067         struct soap soap;
00068         char **surlarray;
00069 
00070         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00071                 return (-1);
00072 
00073         if (ret = soap_call_ns3__getPfns (&soap, lrc_endpoint, "",
00074             (char *) guid, &out)) {
00075                 if (ret == SOAP_FAULT) {
00076                   if (strstr (soap.fault->faultcode, "NOSUCHGUID"))
00077                                 sav_errno = 0;
00078                   else {
00079                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00080                                 sav_errno = ECOMM;
00081                   }
00082                 } else {
00083                   gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00084                         sav_errno = ECOMM;
00085                 }
00086                 soap_end (&soap);
00087                 soap_done (&soap);
00088                 // return 'false' if guid does not exist in LRC
00089                 if(sav_errno == 0)
00090                   return (0);
00091                 
00092                 errno = sav_errno;
00093                 return (-1);
00094         }
00095         soap_end (&soap);
00096         soap_done (&soap);
00097         return (out._getPfnsReturn->__size==0?0:1);
00098 }
00099 
00100 char *
00101 lrc_guidforpfn (const char *pfn, char *errbuf, int errbufsz)
00102 {
00103         struct ns3__guidForPfnResponse out;
00104         char *p;
00105         int ret;
00106         int sav_errno;
00107         struct soap soap;
00108 
00109         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00110                 return (NULL);
00111 
00112         if (ret = soap_call_ns3__guidForPfn (&soap, lrc_endpoint, "",
00113             (char *) pfn, &out)) {
00114                 if (ret == SOAP_FAULT) {
00115                         if (strstr (soap.fault->faultcode, "NOSUCHPFN"))
00116                                 sav_errno = ENOENT;
00117                         else {
00118                           gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00119                                 sav_errno = ECOMM;
00120                         }
00121                 } else {
00122                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00123                         sav_errno = ECOMM;
00124                 }
00125                 soap_end (&soap);
00126                 soap_done (&soap);
00127                 errno = sav_errno;
00128                 return (NULL);
00129         }
00130         p = strdup (out._guidForPfnReturn);
00131         soap_end (&soap);
00132         soap_done (&soap);
00133         return (p);
00134 }
00135 
00136 lrc_guid_exists (const char *guid, char *errbuf, int errbufsz)
00137 {
00138         struct ns3__guidExistsResponse out;
00139         int ret;
00140         struct soap soap;
00141 
00142         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00143                 return (-1);
00144 
00145         if (ret = soap_call_ns3__guidExists (&soap, lrc_endpoint, "",
00146             (char *) guid, &out)) {
00147                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00148                 soap_end (&soap);
00149                 soap_done (&soap);      
00150                 errno = ECOMM;
00151                 return (-1);
00152         }
00153         ret = out._guidExistsReturn ? 1 : 0;
00154         soap_end (&soap);
00155         soap_done (&soap);
00156         return (ret);
00157 }
00158 
00159 lrc_register_pfn (const char *guid, const char *pfn, char *errbuf, int errbufsz)
00160 {
00161         struct ns3__addMappingResponse out;
00162         int ret;
00163         int sav_errno;
00164         struct soap soap;
00165 
00166         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00167                 return (-1);
00168 
00169         if (ret = soap_call_ns3__addMapping (&soap, lrc_endpoint, "",
00170             (char *) guid, (char *) pfn, &out)) {
00171                 if (ret == SOAP_FAULT) {
00172                         if (strstr (soap.fault->faultcode, "PFNEXISTS"))
00173                                 sav_errno = EEXIST;
00174                         else if (strstr (soap.fault->faultcode, "VALUETOOLONG"))
00175                                 sav_errno = ENAMETOOLONG;
00176                         else {
00177                           gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00178                                 sav_errno = ECOMM;
00179                         }
00180                 } else {
00181                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00182                         sav_errno = ECOMM;
00183                 }
00184                 soap_end (&soap);
00185                 soap_done (&soap);
00186                 errno = sav_errno;
00187                 return (-1);
00188         }
00189         soap_end (&soap);
00190         soap_done (&soap);
00191         return (0);
00192 }
00193 
00194 lrc_setfilesize (const char *pfn, GFAL_LONG64 filesize, char *errbuf, int errbufsz)
00195 {
00196         struct ns3__setStringPfnAttributeResponse out;
00197         int ret;
00198         int sav_errno;
00199         struct soap soap;
00200         char tmpbuf[21];
00201 
00202         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00203                 return (-1);
00204 
00205         sprintf (tmpbuf, GFAL_LONG64_FORMAT, filesize);
00206         if (ret = soap_call_ns3__setStringPfnAttribute (&soap, lrc_endpoint,
00207             "", (char *) pfn, "size", tmpbuf, &out)) {
00208                 if (ret == SOAP_FAULT) {
00209                         if (strstr (soap.fault->faultcode, "NOSUCHPFN"))
00210                                 sav_errno = ENOENT;
00211                         else {
00212                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00213                                 sav_errno = ECOMM;
00214                         }
00215                 } else {
00216                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00217                         sav_errno = ECOMM;
00218                 }
00219                 soap_end (&soap);
00220                 soap_done (&soap);
00221                 errno = sav_errno;
00222                 return (-1);
00223         }
00224         soap_end (&soap);
00225         soap_done (&soap);
00226         return (0);
00227 }
00228 
00229 char *
00230 lrc_surlfromguid (const char *guid, char *errbuf, int errbufsz)
00231 {
00232         struct ns3__getPfnsResponse out;
00233         char *p, *result;
00234         int ret;
00235         int sav_errno;
00236         struct soap soap;
00237         char **surls;
00238 
00239         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00240                 return (NULL);
00241 
00242         if (ret = soap_call_ns3__getPfns (&soap, lrc_endpoint, "",
00243             (char *) guid, &out)) {
00244                 if (ret == SOAP_FAULT) {
00245                         if (strstr (soap.fault->faultcode, "NOSUCHGUID"))
00246                                 sav_errno = ENOENT;
00247                         else {
00248                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00249                                 sav_errno = ECOMM;
00250                         }
00251                 } else {
00252                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00253                         sav_errno = ECOMM;
00254                 }
00255                 soap_end (&soap);
00256                 soap_done (&soap);
00257                 errno = sav_errno;
00258                 return (NULL);
00259         } else {
00260           result = getbestfile (out._getPfnsReturn->__ptr, 
00261                                 out._getPfnsReturn->__size, errbuf, errbufsz);
00262           if(result == NULL) {
00263             soap_end (&soap);
00264             soap_done (&soap);
00265             errno = EPROTONOSUPPORT;
00266             return (NULL);
00267           }
00268           p = strdup (result);
00269           soap_end (&soap);
00270           soap_done (&soap);
00271           return (p);
00272         }
00273           
00274 }
00275 
00276 char **
00277 lrc_surlsfromguid (const char *guid, char *errbuf, int errbufsz)
00278 {
00279         int i;
00280         int j;
00281         struct ns3__getPfnsResponse out;
00282         int ret;
00283         int sav_errno;
00284         struct soap soap;
00285         char **surlarray;
00286 
00287         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00288                 return (NULL);
00289 
00290         if (ret = soap_call_ns3__getPfns (&soap, lrc_endpoint, "",
00291             (char *) guid, &out)) {
00292                 if (ret == SOAP_FAULT) {
00293                         if (strstr (soap.fault->faultcode, "NOSUCHGUID"))
00294                                 sav_errno = ENOENT;
00295                         else {
00296                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00297                                 sav_errno = ECOMM;
00298                         }
00299                 } else {
00300                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00301                         sav_errno = ECOMM;
00302                 }
00303                 soap_end (&soap);
00304                 soap_done (&soap);
00305                 errno = sav_errno;
00306                 return (NULL);
00307         }
00308         if ((surlarray = calloc (out._getPfnsReturn->__size + 1, sizeof(char *))) == NULL) {
00309                 soap_end (&soap);
00310                 soap_done (&soap);
00311                 errno = ENOMEM;
00312                 return (NULL);
00313         }
00314         for (i = 0; i < out._getPfnsReturn->__size; i++) {
00315                 if ((surlarray[i] = strdup (out._getPfnsReturn->__ptr[i])) == NULL) {
00316                         for (j = 0; j < i; j++)
00317                                 free (surlarray[j]);
00318                         free (surlarray);
00319                         soap_end (&soap);
00320                         soap_done (&soap);
00321                         errno = ENOMEM;
00322                         return (NULL);
00323                 }
00324         }
00325         soap_end (&soap);
00326         soap_done (&soap);
00327         return (surlarray);
00328 }
00329 
00330 lrc_unregister_pfn (const char *guid, const char *pfn, char *errbuf, int errbufsz)
00331 {
00332         struct ns3__removeMappingResponse out;
00333         int ret;
00334         struct soap soap;
00335 
00336         if (lrc_init (&soap, errbuf, errbufsz) < 0)
00337                 return (-1);
00338 
00339         if (ret = soap_call_ns3__removeMapping (&soap, lrc_endpoint, "",
00340             (char *) guid, (char *) pfn, &out)) {
00341                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00342                 soap_end (&soap);
00343                 soap_done (&soap);
00344                 errno = ECOMM;
00345                 return (-1);
00346         }
00347         soap_end (&soap);
00348         soap_done (&soap);
00349         return (0);
00350 }

Generated on Fri Sep 8 20:20:47 2006 for GFAL by  doxygen 1.4.6