/Home/aooliver/work/stagersvc/org.glite.data.lcg_gfal/src/gfal_api.h File Reference

#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>

Go to the source code of this file.

Classes

struct  srm_filestatus

Defines

#define GFAL_LONG64_FORMAT   "%lld"
#define GFAL_LONG64   long long

Functions

int gfal_access (const char *, int)
int gfal_chmod (const char *, mode_t)
int gfal_close (int)
int gfal_closedir (DIR *)
int gfal_creat (const char *, mode_t)
int gfal_creat64 (const char *, mode_t)
int gfal_errmsg (char *, int, const char *)
off_t gfal_lseek (int, off_t, int)
int gfal_lstat (const char *, struct stat *)
int gfal_mkdir (const char *, mode_t)
int gfal_open (const char *, int, mode_t)
int gfal_open64 (const char *, int, mode_t)
DIR * gfal_opendir (const char *)
ssize_t gfal_read (int, void *, size_t)
dirent * gfal_readdir (DIR *)
int gfal_rename (const char *, const char *)
int gfal_rmdir (const char *)
ssize_t gfal_setfilchg (int, const void *, size_t)
int gfal_stat (const char *, struct stat *)
int gfal_unlink (const char *)
ssize_t gfal_write (int, const void *, size_t)
off64_t gfal_lseek64 (int, off64_t, int)
int gfal_lstat64 (const char *, struct stat64 *)
int gfal_stat64 (const char *, struct stat64 *)
int create_alias (const char *, const char *, GFAL_LONG64, char *, int)
char * getbestfile (char **, int size, char *, int)
char * get_catalog_endpoint (char *, int)
int getfilesizeg (const char *, GFAL_LONG64 *, char *, int)
int guid_exists (const char *, char *, int)
char * guidforpfn (const char *, char *, int)
char * guidfromlfn (const char *, char *, int)
char ** lfnsforguid (const char *, char *, int)
int register_alias (const char *, const char *, char *, int)
int register_pfn (const char *, const char *, char *, int)
int unregister_alias (const char *, const char *, char *, int)
int unregister_pfn (const char *, const char *, char *, int)
char * surlfromguid (const char *, char *, int)
char ** surlsfromguid (const char *, char *, int)
int setfilesize (const char *, GFAL_LONG64, char *, int)
int deletesurl (const char *, char *, int, int)
char * get_default_se (char *, char *, int)
int getfilemd (const char *, struct stat64 *, char *, int, int)
int set_xfer_done (const char *, int, int, char *, int, char *, int, int)
int set_xfer_running (const char *, int, int, char *, char *, int, int)
char * turlfromsurl (const char *, char **, int, int *, int *, char **, char *, int, int)
char * turlfromsurlx (const char *, GFAL_LONG64, char **, int, int *, int *, char **, char *, int, int)
int deletepfn (const char *, const char *, char *, int)
int get_bdii (char *, int, int *, char *, int)
int get_cat_type (char **)
int get_ce_ap (const char *, char **)
int get_ce_apx (const char *, char **, char *, int)
int get_lfc_endpoint (char **, char *, int)
int get_rls_endpoints (char **, char **)
int get_rls_endpointsx (char **, char **, char *, int)
int get_sa_root (const char *, const char *, char **)
int get_sa_rootx (const char *, const char *, char **, char *, int)
int get_se_endpoint (const char *, char **)
int get_se_endpointx (const char *, char **, char *, int)
int get_sa_path (const char *, const char *, char **, char **, char *, int)
int get_se_port (const char *, int *)
int get_se_portx (const char *, int *, char *, int)
int get_se_type (const char *, char **)
int get_se_typex (const char *, char **, char *, int)
int get_seap_info (const char *, char ***, int **)
int get_seap_infox (const char *, char ***, int **, char *, int)
int se_getfilemd (const char *, struct stat64 *, char *, int, int)
int srm_getfilemd (const char *, struct stat64 *, char *, int, int)
int lfc_getfilesizeg (const char *, GFAL_LONG64 *, char *, int)
int lfc_create_alias (const char *, const char *, GFAL_LONG64, char *, int)
int lfc_deletepfn (const char *, const char *, char *, int)
int lfc_deletesurl (const char *, char *, int)
char * lfc_get_catalog_endpoint (char *, int)
char * lfc_guidforpfn (const char *, char *, int)
char * lfc_guidfromlfn (const char *, char *, int)
int lfc_guid_exists (const char *, char *, int)
char ** lfc_lfnsforguid (const char *, char *, int)
int lfc_mkdirp (const char *, mode_t, char *, int)
int lfc_register_alias (const char *, const char *, char *, int)
int lfc_register_pfn (const char *, const char *, char *, int)
int lfc_replica_exists (const char *, char *, int)
char * lfc_surlfromguid (const char *, char *, int)
char ** lfc_surlsfromguid (const char *, char *, int)
int lfc_unregister_alias (const char *, const char *, char *, int)
int lfc_unregister_pfn (const char *, const char *, char *, int)
int lrc_deletepfn (const char *, const char *, char *, int)
int lrc_deletesurl (const char *, char *, int)
char * lrc_get_catalog_endpoint (char *, int)
char * lrc_guidforpfn (const char *, char *, int)
int lrc_guid_exists (const char *, char *, int)
int lrc_replica_exists (const char *, char *, int)
int lrc_setfilesize (const char *, GFAL_LONG64, char *, int)
char * lrc_surlfromguid (const char *, char *, int)
char ** lrc_surlsfromguid (const char *, char *, int)
int parsesurl (const char *, char *, int, char **, char *, int)
int parseturl (const char *, char *, int, char *, int, char **, char *, int)
int replica_exists (const char *, char *, int)
char * rmc_guidfromlfn (const char *, char *, int)
char ** rmc_lfnsforguid (const char *, char *, int)
int rmc_register_alias (const char *, const char *, char *, int)
int rmc_register_pfn (const char *, const char *, char *, int)
int rmc_unregister_alias (const char *, const char *, char *, int)
int rmc_unregister_pfn (const char *, const char *, char *, int)
int se_deletesurl (const char *, char *, int, int)
int se_set_xfer_done (const char *, int, int, char *, int, char *, int, int)
int se_set_xfer_running (const char *, int, int, char *, char *, int)
char * se_turlfromsurl (const char *, char **, int, int *, int *, char **, char *, int, int)
int setypefromsurl (const char *, char **, char *, int)
int srm_deletesurl (const char *, char *, int, int)
int srm_get (int, char **, int, char **, int *, char **, struct srm_filestatus **, int)
int srm_getx (int, char **, int, char **, int *, char **, struct srm_filestatus **, char *, int, int)
int srm_getstatus (int, char **, int, char *, struct srm_filestatus **, int)
int srm_getstatusx (int, char **, int, char *, struct srm_filestatus **, char *, int, int)
int srm_set_xfer_done (const char *, int, int, char *, int, char *, int, int)
int srm_set_xfer_running (const char *, int, int, char *, char *, int, int)
char * srm_turlfromsurl (const char *, char **, int, int *, int *, char **, char *, int, int)
int srm_turlsfromsurls (int, const char **, GFAL_LONG64 *, char **, int, int *, int **, char **, char ***, char *, int, int)
char * turlfromsfn (const char *, char **, char *, int)


Define Documentation

#define GFAL_LONG64   long long
 

Definition at line 30 of file gfal_api.h.

Referenced by turlfromsurl().

#define GFAL_LONG64_FORMAT   "%lld"
 

Definition at line 21 of file gfal_api.h.

Referenced by lrc_setfilesize().


Function Documentation

int create_alias const char *  ,
const char *  ,
GFAL_LONG64  ,
char *  ,
int 
 

Definition at line 1417 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_create_alias(), and rmc_register_alias().

01419 {
01420         char *cat_type;
01421         if (get_cat_type (&cat_type) < 0) {
01422                 return (-1);
01423         }
01424         if (strcmp (cat_type, "edg") == 0) {
01425                 free (cat_type);
01426                 return (rmc_register_alias (guid, lfn, errbuf, errbufsz));
01427         } else if (strcmp (cat_type, "lfc") == 0) {
01428                 free (cat_type);
01429                 return (lfc_create_alias (guid, lfn, size, errbuf, errbufsz));
01430         } else {
01431                 free (cat_type);
01432                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01433                 errno = EINVAL;
01434                 return (-1);
01435         }
01436 }

int deletepfn const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 739 of file gfal.c.

References deletesurl(), find_pops(), proto_ops::maperror, parseturl(), turlfromsfn(), and proto_ops::unlink.

Referenced by gfal_unlink().

00740 {
00741         char pathbuf[1024];
00742         char *pfn;
00743         struct proto_ops *pops;
00744         char protocol[64];
00745         int rc;
00746         char *turl;
00747 
00748         if (strncmp (fn, "srm:", 4) == 0) {
00749                 if (deletesurl (fn, errbuf, errbufsz, 0) < 0)
00750                         return (-1);
00751         } else {
00752                 if (strncmp (fn, "sfn:", 4) == 0) {
00753                         if ((turl = turlfromsfn (fn, NULL, errbuf, errbufsz)) == NULL)
00754                                 return (-1);
00755                 } else          /* assume that is a pfn */
00756                         turl = (char *)fn;
00757                 if ((rc = parseturl (turl, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf))) == 0) {
00758                         if ((pops = find_pops (protocol)) != NULL) {
00759                                 if ((rc = pops->unlink (pfn)) < 0)
00760                                         errno = pops->maperror (pops, 0);
00761                         }
00762                 }
00763                 if (turl != fn) free (turl);
00764                 if (rc < 0 || pops == NULL)
00765                         return (-1);
00766         }
00767         return (0);
00768 }

int deletesurl const char *  ,
char *  ,
int  ,
int 
 

Definition at line 770 of file gfal.c.

References gfal_errmsg(), se_deletesurl(), setypefromsurl(), and srm_deletesurl().

Referenced by deletepfn().

00771 {
00772         char *se_type;
00773 
00774         if (setypefromsurl (surl, &se_type, errbuf, errbufsz) < 0)
00775                 return (-1);
00776         if (strcmp (se_type, "srm_v1") == 0) {
00777                 free (se_type);
00778                 return (srm_deletesurl (surl, errbuf, errbufsz, timeout));
00779         } else if (strcmp (se_type, "edg-se") == 0) {
00780                 free (se_type);
00781                 return (se_deletesurl (surl, errbuf, errbufsz, timeout));
00782         } else {
00783                 free (se_type);
00784                 gfal_errmsg(errbuf, errbufsz, "The Storage Element type is neither 'srm_v1' nor 'edg-se'.");
00785                 errno = EINVAL;
00786                 return (-1);
00787         }
00788 }

int get_bdii char *  ,
int  ,
int *  ,
char *  ,
int 
 

Definition at line 20 of file mds_ifce.c.

References gfal_errmsg().

Referenced by get_ce_apx(), get_lfc_endpoint(), get_rls_endpointsx(), get_sa_path(), get_sa_rootx(), get_se_endpointx(), get_se_portx(), get_se_typex(), and get_seap_infox().

00021 {
00022         char *bdii_env;
00023         char *p;
00024 
00025         if ((bdii_env = getenv ("LCG_GFAL_INFOSYS")) == NULL ||
00026             strlen (bdii_env) >= buflen) {
00027                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_INFOSYS not set or invalid");
00028                 errno = EINVAL;
00029                 return (-1);
00030         }
00031         strcpy (bdii_server, bdii_env);
00032         if ((p = strchr (bdii_server, ':')) == NULL) {
00033                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_INFOSYS invalid");
00034                 errno = EINVAL;
00035                 return (-1);
00036         }
00037         *p = '\0';
00038         *bdii_port = atoi (p + 1);
00039         return (0);
00040 }

int get_cat_type char **   ) 
 

Definition at line 1155 of file gfal.c.

References GFAL_DEFAULT_CATALOG_TYPE.

Referenced by create_alias(), get_catalog_endpoint(), getfilesizeg(), guid_exists(), guidforpfn(), guidfromlfn(), lfnsforguid(), register_alias(), register_pfn(), replica_exists(), setfilesize(), surlfromguid(), surlsfromguid(), unregister_alias(), and unregister_pfn().

01155                                {
01156         char *cat_env;
01157         char *default_cat = GFAL_DEFAULT_CATALOG_TYPE;
01158 
01159         if((cat_env = getenv ("LCG_CATALOG_TYPE")) == NULL) {
01160                 /* default catalogs if no environment variable specified */
01161                 cat_env = default_cat;          
01162         }
01163         if((*cat_type = strdup(cat_env)) == NULL) {
01164                 return (-1);
01165         }
01166         return 0;
01167 }

char* get_catalog_endpoint char *  ,
int 
 

Definition at line 1190 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_get_catalog_endpoint(), and lrc_get_catalog_endpoint().

01191 {
01192         char *cat_type;
01193         if (get_cat_type (&cat_type) < 0) {
01194                 return (NULL);
01195         }
01196         if (strcmp (cat_type, "edg") == 0) {
01197                 free (cat_type);
01198                 return (lrc_get_catalog_endpoint (errbuf, errbufsz));
01199         } else if (strcmp (cat_type, "lfc") == 0) {
01200                 free (cat_type);
01201                 return (lfc_get_catalog_endpoint (errbuf, errbufsz));
01202         } else {
01203                 free (cat_type);
01204                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01205                 errno = EINVAL;
01206                 return (NULL);
01207         }
01208 }

int get_ce_ap const char *  ,
char ** 
 

Definition at line 44 of file mds_ifce.c.

References get_ce_apx().

00045 {
00046         return (get_ce_apx (host, ce_ap, NULL, 0));
00047 }

int get_ce_apx const char *  ,
char **  ,
char *  ,
int 
 

Definition at line 49 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_ce_ap().

00050 {
00051         static char ce_ap_atnm[] = "GlueCESEBindCEAccesspoint";
00052         static char *template = "(GlueCESEBindSEUniqueID=%s)";
00053         char *attr;
00054         static char *attrs[] = {ce_ap_atnm, NULL};
00055         int bdii_port;
00056         char bdii_server[75];
00057         LDAPMessage *entry;
00058         char filter[128];
00059         LDAP *ld;
00060         int rc = 0;
00061         LDAPMessage *reply;
00062         struct timeval timeout;
00063         char **value;
00064         char error_str[ERROR_STR_LEN];
00065 
00066         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00067                 return (-1);
00068         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00069                 snprintf(error_str, ERROR_STR_LEN, "BDII Hostname too long: %s:%d", bdii_server, bdii_port);
00070                 gfal_errmsg (errbuf, errbufsz, error_str);
00071                 errno = EINVAL;
00072                 return (-1);
00073         }
00074         sprintf (filter, template, host);
00075 
00076         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00077                 return (-1);
00078         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00079                 ldap_unbind (ld);
00080                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00081                 gfal_errmsg(errbuf, errbufsz, error_str);
00082                 errno = ECONNREFUSED;
00083         return (-1);
00084         }
00085         timeout.tv_sec = 15;
00086         timeout.tv_usec = 0;
00087         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00088             &timeout, &reply)) != LDAP_SUCCESS) {
00089                 ldap_unbind (ld);
00090                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00091                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00092                         gfal_errmsg(errbuf, errbufsz, error_str);
00093                         errno = ETIMEDOUT;
00094                 } else {
00095                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00096                                   ldap_err2string(rc));
00097                         gfal_errmsg(errbuf, errbufsz, error_str);
00098                         errno = EINVAL;
00099                 }
00100                 return (-1);
00101 
00102         }
00103         entry = ldap_first_entry (ld, reply);
00104         if (entry) {
00105                 value = ldap_get_values (ld, entry, ce_ap_atnm);
00106                 if (value == NULL) {
00107                         snprintf(error_str, ERROR_STR_LEN, "CE Accesspoint not found for host : %s", host);
00108                         gfal_errmsg (errbuf, errbufsz, error_str);
00109                         errno = EINVAL;
00110                         rc = -1;
00111 
00112                 } else {
00113                   if ((*ce_ap = strdup (value[0])) == NULL)
00114                     rc = -1;
00115                   ldap_value_free (value);
00116                 }
00117         } else {
00118                 snprintf(error_str, ERROR_STR_LEN, "No GlueCESEBind found for host : %s", host);
00119                 gfal_errmsg (errbuf, errbufsz, error_str);
00120                 errno = EINVAL;
00121                 rc = -1;
00122         }
00123         ldap_msgfree (reply);
00124         ldap_unbind (ld);
00125         return (rc);
00126 }

char* get_default_se char *  ,
char *  ,
int 
 

Definition at line 1578 of file gfal.c.

References gfal_errmsg().

Referenced by getbestfile().

01579 {
01580         char *default_se;
01581         int i;
01582         char se_env[64];
01583         char *vo_env;
01584         char error_str[128];
01585 
01586         if(vo == NULL) {
01587                 if ((vo_env = getenv ("LCG_GFAL_VO")) == NULL) {
01588                         gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO not set");
01589                         errno = EINVAL;
01590                         return (NULL);
01591                 }
01592                 vo = vo_env;
01593         }
01594         if(strlen(vo) + 15 >= 64) {
01595                 errno = ENAMETOOLONG;
01596                 gfal_errmsg(errbuf, errbufsz, "VO Name too long");
01597                 return (NULL);
01598         }
01599         sprintf(se_env, "VO_%s_DEFAULT_SE", vo);
01600         for(i = 3; i < 3 + strlen(vo); ++i) {
01601                 if (se_env[i] == '.' || se_env[i] == '-') 
01602                         se_env[i] = '_';
01603                 else
01604                         se_env[i] = toupper(se_env[i]);
01605         } 
01606         default_se = getenv(se_env);
01607         if(default_se == NULL) {
01608                 snprintf(error_str, 128, "No Default SE: %s not set", se_env);
01609                 gfal_errmsg(errbuf, errbufsz, error_str);
01610                 errno = EINVAL;
01611                 return (NULL);
01612         }
01613         return default_se;
01614 }

int get_lfc_endpoint char **  ,
char *  ,
int 
 

Definition at line 248 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by lfc_init().

00249 {
00250         static char ep[] = "GlueServiceAccessPointURL";
00251         static char type[] = "GlueServiceType";
00252         static char *template = "(&(GlueServiceType=*)(GlueServiceAccessControlRule=%s))";
00253         char *attr;
00254         static char *attrs[] = {type, ep, NULL};
00255         int bdii_port;
00256         char bdii_server[75];
00257         BerElement *ber;
00258         LDAPMessage *entry;
00259         char filter[128];
00260         LDAP *ld;
00261         int rc = 0;
00262         LDAPMessage *reply;
00263         char *service_type;
00264         char *service_url;
00265         struct timeval timeout;
00266         char **value;
00267         char *vo;
00268         char error_str[ERROR_STR_LEN];
00269         
00270         *lfc_endpoint = NULL;
00271         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00272                 return (-1);
00273         if ((vo = getenv ("LCG_GFAL_VO")) == NULL) {
00274                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO not set");
00275                 errno = EINVAL;
00276                 return (-1);
00277         }
00278         if (strlen (template) + strlen (vo) - 2 >= sizeof(filter)) {
00279                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO too long");
00280                 errno = EINVAL;
00281                 return (-1);
00282         }
00283         sprintf (filter, template, vo);
00284 
00285         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00286                 return (-1);
00287         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00288                 ldap_unbind (ld);
00289                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00290                 gfal_errmsg(errbuf, errbufsz, error_str);
00291                 errno = ECONNREFUSED;
00292                 return (-1);
00293         }
00294         timeout.tv_sec = 15;
00295         timeout.tv_usec = 0;
00296         if (ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00297             &timeout, &reply) != LDAP_SUCCESS) {
00298                 ldap_unbind (ld);
00299                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00300                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00301                         gfal_errmsg(errbuf, errbufsz, error_str);
00302                         errno = ETIMEDOUT;
00303                 } else {
00304                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00305                                  ldap_err2string(rc));
00306                         gfal_errmsg(errbuf, errbufsz, error_str);
00307                         errno = EINVAL;
00308                 }
00309                 return (-1);
00310         }
00311         for (entry = ldap_first_entry (ld, reply);
00312              entry != NULL;
00313              entry = ldap_next_entry (ld, entry)) {
00314                 service_type = NULL;
00315                 service_url = NULL;
00316                 for (attr = ldap_first_attribute (ld, entry, &ber);
00317                      attr != NULL;
00318                      attr = ldap_next_attribute (ld, entry, ber)) {
00319                         value = ldap_get_values (ld, entry, attr);
00320                         if (value == NULL) {
00321                                 rc = -1;
00322                                 continue;
00323                         }
00324                         if (strcmp (attr, "GlueServiceType") == 0) {
00325                                 if((service_type = strdup (value[0])) == NULL)
00326                                         rc = -1;
00327                         } else {        /* GlueServiceAccessPointURL */
00328                                 if((service_url = strdup (value[0])) == NULL)
00329                                         rc = -1;
00330                         }
00331                         ldap_value_free (value);
00332                 }
00333                 if (rc == 0) {
00334                         if (strcmp (service_type, "lcg-file-catalog") == 0) {
00335                           if ((*lfc_endpoint = strdup (service_url)) == NULL)
00336                             rc = -1;
00337                         }
00338                 }
00339                 free (service_type);
00340                 free (service_url);
00341         }
00342         if (*lfc_endpoint == NULL) {
00343                 gfal_errmsg (errbuf, errbufsz, "LFC endpoint not found");
00344                 errno = EINVAL;
00345                 rc = -1;
00346         }
00347         ldap_msgfree (reply);
00348         ldap_unbind (ld);
00349         return (rc);
00350 }

int get_rls_endpoints char **  ,
char ** 
 

Definition at line 130 of file mds_ifce.c.

References get_rls_endpointsx().

00131 {
00132         return (get_rls_endpointsx (lrc_endpoint, rmc_endpoint, NULL, 0));
00133 }

int get_rls_endpointsx char **  ,
char **  ,
char *  ,
int 
 

Definition at line 135 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_rls_endpoints(), lrc_init(), and rmc_init().

00136 {
00137         static char rls_ep[] = "GlueServiceAccessPointURL";
00138         static char rls_type[] = "GlueServiceType";
00139         static char *template = "(&(GlueServiceType=*)(GlueServiceAccessControlRule=%s))";
00140         char *attr;
00141         static char *attrs[] = {rls_type, rls_ep, NULL};
00142         int bdii_port;
00143         char bdii_server[75];
00144         BerElement *ber;
00145         LDAPMessage *entry;
00146         char filter[128];
00147         LDAP *ld;
00148         int rc = 0;
00149         LDAPMessage *reply;
00150         char *service_type;
00151         char *service_url;
00152         struct timeval timeout;
00153         char **value;
00154         char *vo;
00155         char error_str[ERROR_STR_LEN];
00156 
00157         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00158                 return (-1);
00159         if ((vo = getenv ("LCG_GFAL_VO")) == NULL) {
00160                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO not set");
00161                 errno = EINVAL;
00162                 return (-1);
00163         }
00164         if (strlen (template) + strlen (vo) - 2 >= sizeof(filter)) {
00165                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO too long");
00166                 errno = EINVAL;
00167                 return (-1);
00168         }
00169         sprintf (filter, template, vo);
00170 
00171         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00172                 return (-1);
00173         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00174                 ldap_unbind (ld);
00175                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00176                 gfal_errmsg(errbuf, errbufsz, error_str);
00177                 errno = ECONNREFUSED;
00178                 return (-1);
00179         }
00180         timeout.tv_sec = 15;
00181         timeout.tv_usec = 0;
00182         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00183             &timeout, &reply)) != LDAP_SUCCESS) {
00184                 ldap_unbind (ld);
00185                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00186                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00187                         gfal_errmsg(errbuf, errbufsz, error_str);
00188                         errno = ETIMEDOUT;
00189                 } else {
00190                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00191                                  ldap_err2string(rc));
00192                         gfal_errmsg(errbuf, errbufsz, error_str);
00193                         errno = EINVAL;
00194                 }
00195                 return (-1);
00196         }
00197         for (entry = ldap_first_entry (ld, reply);
00198              entry != NULL;
00199              entry = ldap_next_entry (ld, entry)) {
00200                 service_type = NULL;
00201                 service_url = NULL;
00202                 for (attr = ldap_first_attribute (ld, entry, &ber);
00203                      attr != NULL;
00204                      attr = ldap_next_attribute (ld, entry, ber)) {
00205                         value = ldap_get_values (ld, entry, attr);
00206                         if (value != NULL) {
00207                                 if (strcmp (attr, "GlueServiceType") == 0) {
00208                                         if((service_type = strdup (value[0])) == NULL)
00209                                                 rc = -1;
00210                                 } else {        /* GlueServiceAccessPointURL */
00211                                         if((service_url = strdup (value[0])) == NULL)
00212                                                 rc = -1;
00213                                 }
00214                                 ldap_value_free (value);
00215                         }
00216                         else 
00217                                 rc = -1;
00218                 }
00219                 if (rc == 0) {
00220                         if (strcmp (service_type, "edg-replica-metadata-catalog") == 0) {
00221                                 if ((*rmc_endpoint = strdup (service_url)) == NULL)
00222                                         rc = -1;
00223                         } else if (strcmp (service_type, "edg-local-replica-catalog") == 0) {
00224                                 if ((*lrc_endpoint = strdup (service_url)) == NULL)
00225                                         rc = -1;
00226                         }
00227                 }
00228                 free (service_type);
00229                 free (service_url);
00230         }
00231         if (*lrc_endpoint == NULL) {
00232                 gfal_errmsg (errbuf, errbufsz, "LRC endpoint not found");
00233                 errno = EINVAL;
00234                 rc = -1;
00235         }
00236         if (*rmc_endpoint == NULL) {
00237                 gfal_errmsg (errbuf, errbufsz, "RMC endpoint not found");
00238                 errno = EINVAL;
00239                 rc = -1;
00240         }
00241         ldap_msgfree (reply);
00242         ldap_unbind (ld);
00243         return (rc);
00244 }

int get_sa_path const char *  ,
const char *  ,
char **  ,
char **  ,
char *  ,
int 
 

Definition at line 432 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), get_sa_rootx(), and gfal_errmsg().

00433 {
00434         static char sa_path_atnm[] = "GlueSAPath";
00435         static char sa_root_atnm[] = "GlueSARoot";
00436         static char *template = "(&(GlueSALocalID=%s)(GlueChunkKey=GlueSEUniqueID=%s))";
00437         char *attr;
00438         static char *attrs[] = {sa_root_atnm, sa_path_atnm, NULL};
00439         int bdii_port;
00440         char bdii_server[75];
00441         LDAPMessage *entry;
00442         char filter[128];
00443         LDAP *ld;
00444         int rc = 0;
00445         LDAPMessage *reply;
00446         struct timeval timeout;
00447         char **value;
00448         char error_str[ERROR_STR_LEN];
00449 
00450         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00451                 return (-1);
00452         if (strlen (template) + strlen (vo) + strlen (host) - 4 >= sizeof(filter)) {
00453                 gfal_errmsg (errbuf, errbufsz, "vo or host too long");
00454                 errno = EINVAL;
00455                 return (-1);
00456         }
00457         sprintf (filter, template, vo, host);
00458 
00459         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00460                 return (-1);
00461         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00462                 ldap_unbind (ld);
00463                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00464                 gfal_errmsg(errbuf, errbufsz, error_str);
00465                 errno = ECONNREFUSED;
00466                 return (-1);
00467         }
00468         timeout.tv_sec = 15;
00469         timeout.tv_usec = 0;
00470         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00471             &timeout, &reply)) != LDAP_SUCCESS) {
00472                 ldap_unbind (ld);
00473                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00474                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00475                         gfal_errmsg(errbuf, errbufsz, error_str);
00476                         errno = ETIMEDOUT;
00477                 } else {
00478                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00479                                  ldap_err2string(rc));
00480                         gfal_errmsg(errbuf, errbufsz, error_str);
00481                         errno = EINVAL;
00482                 }
00483                 return (-1);
00484         }
00485         *sa_path = NULL;
00486         *sa_root = NULL;
00487         entry = ldap_first_entry (ld, reply);
00488         if (entry) {
00489                 value = ldap_get_values (ld, entry, sa_path_atnm);
00490                 if (value != NULL) {
00491                         /* We deal with pre-LCG 2.7.0 where SA Path was incorrect and had vo: prefix */
00492                         if ((strncmp(value[0], vo, strlen(vo)) == 0) && (*(value[0] + strlen(vo)) == ':')) {
00493                                 if ((*sa_path = strdup (value[0] + strlen (vo) + 1)) == NULL)
00494                                         rc = -1;
00495                         } else
00496                                 if ((*sa_path = strdup (value[0])) == NULL)
00497                                         rc = -1;
00498                 }
00499                 ldap_value_free (value);
00500                 
00501                 value = ldap_get_values (ld, entry, sa_root_atnm);
00502                 if (value != NULL) {
00503                         if ((*sa_root = strdup (value[0] + strlen (vo) + 1)) == NULL)
00504                                 rc = -1;
00505                 }
00506                 ldap_value_free (value);
00507 
00508         } else {
00509                 /* try and get SA root via old method for pre-2.5 SEs */
00510                 if (get_sa_rootx (host, vo, sa_root, errbuf, errbufsz) < 0 ) {
00511                         snprintf(error_str, ERROR_STR_LEN, "No GlueSA information found for SE (vo) : %s (%s)", host, vo);
00512                         gfal_errmsg (errbuf, errbufsz, error_str);
00513                         errno = EINVAL;
00514                         rc = -1;               
00515                 } 
00516                 
00517         }
00518         if (rc == 0) 
00519                 if (*sa_path == NULL && *sa_root == NULL) {
00520                         snprintf(error_str, ERROR_STR_LEN, 
00521                                  "Both SAPath and SARoot not set for SE (vo) : %s (%s)", 
00522                                  host, vo);
00523                         gfal_errmsg (errbuf, errbufsz, error_str);
00524                         errno = EINVAL;
00525                         rc = -1;
00526                 }
00527         ldap_msgfree (reply);
00528         ldap_unbind (ld);
00529         return (rc);
00530 }

int get_sa_root const char *  ,
const char *  ,
char ** 
 

Definition at line 354 of file mds_ifce.c.

References get_sa_rootx().

00355 {
00356         return (get_sa_rootx (host, vo, sa_root, NULL, 0));
00357 }

int get_sa_rootx const char *  ,
const char *  ,
char **  ,
char *  ,
int 
 

Definition at line 359 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_sa_path(), and get_sa_root().

00360 {
00361         static char sa_root_atnm[] = "GlueSARoot";
00362         static char *template = "(&(GlueSARoot=%s:*)(GlueChunkKey=GlueSEUniqueID=%s))";
00363         char *attr;
00364         static char *attrs[] = {sa_root_atnm, NULL};
00365         int bdii_port;
00366         char bdii_server[75];
00367         LDAPMessage *entry;
00368         char filter[128];
00369         LDAP *ld;
00370         int rc = 0;
00371         LDAPMessage *reply;
00372         struct timeval timeout;
00373         char **value;
00374         char error_str[ERROR_STR_LEN];
00375 
00376         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00377                 return (-1);
00378         if (strlen (template) + strlen (vo) + strlen (host) - 4 >= sizeof(filter)) {
00379                 gfal_errmsg (errbuf, errbufsz, "vo or host too long");
00380                 errno = EINVAL;
00381                 return (-1);
00382         }
00383         sprintf (filter, template, vo, host);
00384 
00385         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00386                 return (-1);
00387         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00388                 ldap_unbind (ld);
00389                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00390                 gfal_errmsg(errbuf, errbufsz, error_str);
00391                 errno = ECONNREFUSED;
00392                 return (-1);
00393         }
00394         timeout.tv_sec = 15;
00395         timeout.tv_usec = 0;
00396         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00397             &timeout, &reply)) != LDAP_SUCCESS) {
00398                 ldap_unbind (ld);
00399                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00400                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00401                         gfal_errmsg(errbuf, errbufsz, error_str);
00402                         errno = ETIMEDOUT;
00403                 } else {
00404                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00405                                  ldap_err2string(rc));
00406                         gfal_errmsg(errbuf, errbufsz, error_str);
00407                         errno = EINVAL;
00408                 }
00409                 return (-1);
00410         }
00411         entry = ldap_first_entry (ld, reply);
00412         if (entry) {
00413                 value = ldap_get_values (ld, entry, sa_root_atnm);
00414                 if (value == NULL) 
00415                         goto notfound;
00416                 if ((*sa_root = strdup (value[0] + strlen (vo) + 1)) == NULL)
00417                         rc = -1;
00418                 ldap_value_free (value);
00419         } else {
00420 notfound:       snprintf(error_str, ERROR_STR_LEN, "SA Root not found for host : %s", host);
00421                 gfal_errmsg (errbuf, errbufsz, error_str);
00422                 errno = EINVAL;
00423                 rc = -1;
00424         }
00425         ldap_msgfree (reply);
00426         ldap_unbind (ld);
00427         return (rc);
00428 }

int get_se_endpoint const char *  ,
char ** 
 

Definition at line 535 of file mds_ifce.c.

References get_se_endpointx().

00536 {
00537         return (get_se_endpointx (host, se_endpoint, NULL, 0));
00538 }

int get_se_endpointx const char *  ,
char **  ,
char *  ,
int 
 

Definition at line 540 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_se_endpoint().

00541 {
00542         static char se_ep_atnm[] = "GlueServiceURI";
00543         static char *template = "(&(GlueServiceURI=*%s*)(GlueServiceType=srm_v1))";
00544         char *attr;
00545         static char *attrs[] = {se_ep_atnm, NULL};
00546         int bdii_port;
00547         char bdii_server[75];
00548         LDAPMessage *entry;
00549         char filter[128];
00550         LDAP *ld;
00551         int rc = 0;
00552         LDAPMessage *reply;
00553         struct timeval timeout;
00554         char **value;
00555         char error_str[ERROR_STR_LEN];
00556         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00557                 return (-1);
00558         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00559                 gfal_errmsg (errbuf, errbufsz, "host too long");
00560                 errno = EINVAL;
00561                 return (-1);
00562         }
00563         sprintf (filter, template, host);
00564 
00565         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00566                 return (-1);
00567         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00568                 ldap_unbind (ld);
00569                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00570                 gfal_errmsg(errbuf, errbufsz, error_str);
00571                 errno = ECONNREFUSED;
00572                 return (-1);
00573         }
00574         timeout.tv_sec = 15;
00575         timeout.tv_usec = 0;
00576         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00577             &timeout, &reply)) != LDAP_SUCCESS) {
00578                 ldap_unbind (ld);
00579                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00580                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00581                         gfal_errmsg(errbuf, errbufsz, error_str);
00582                         errno = ETIMEDOUT;
00583                 } else {
00584                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00585                                  ldap_err2string(rc));
00586                         gfal_errmsg(errbuf, errbufsz, error_str);
00587                         errno = EINVAL;
00588                 }
00589                 return (-1);
00590         }
00591         entry = ldap_first_entry (ld, reply);
00592         if (entry) {
00593                 value = ldap_get_values (ld, entry, se_ep_atnm);
00594                 if (value == NULL) {
00595                         snprintf(error_str, ERROR_STR_LEN, "SE (SRM) endpoint not set for host : %s", host);
00596                         gfal_errmsg (errbuf, errbufsz, "SE (SRM) endpoint not set for host : %s");
00597                         errno = EINVAL;         
00598                         rc = -1;
00599                 }
00600                 else {
00601                         if ((*se_endpoint = strdup (value[0])) == NULL)
00602                                 rc = -1;
00603                         ldap_value_free (value);
00604                 }
00605         } else {
00606                 snprintf(error_str, ERROR_STR_LEN, "SE (SRM) service not found for host : %s", host);
00607                 gfal_errmsg (errbuf, errbufsz, error_str);
00608                 errno = EINVAL;
00609                 rc = -1;
00610         }
00611         ldap_msgfree (reply);
00612         ldap_unbind (ld);
00613         return (rc);
00614 }

int get_se_port const char *  ,
int * 
 

Definition at line 618 of file mds_ifce.c.

References get_se_portx().

00619 {
00620         return (get_se_portx (host, se_port, NULL, 0));
00621 }

int get_se_portx const char *  ,
int *  ,
char *  ,
int 
 

Definition at line 623 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_se_port().

00624 {
00625         static char se_port_atnm[] = "GlueSEPort";
00626         static char *template = "(GlueSEUniqueID=%s)";
00627         char *attr;
00628         static char *attrs[] = {se_port_atnm, NULL};
00629         int bdii_port;
00630         char bdii_server[75];
00631         LDAPMessage *entry;
00632         char filter[128];
00633         LDAP *ld;
00634         int rc = 0;
00635         LDAPMessage *reply;
00636         struct timeval timeout;
00637         char **value;
00638         char error_str[ERROR_STR_LEN];
00639 
00640         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00641                 return (-1);
00642         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00643                 gfal_errmsg (errbuf, errbufsz, "host too long");
00644                 errno = EINVAL;
00645                 return (-1);
00646         }
00647         sprintf (filter, template, host);
00648 
00649         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00650                 return (-1);
00651         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00652                 ldap_unbind (ld);
00653                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00654                 gfal_errmsg(errbuf, errbufsz, error_str);
00655                 errno = ECONNREFUSED;
00656                 return (-1);
00657         }
00658         timeout.tv_sec = 15;
00659         timeout.tv_usec = 0;
00660         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00661             &timeout, &reply)) != LDAP_SUCCESS) {
00662                 ldap_unbind (ld);
00663                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00664                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00665                         gfal_errmsg(errbuf, errbufsz, error_str);
00666                         errno = ETIMEDOUT;
00667                 } else {
00668                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00669                                  ldap_err2string(rc));
00670                         gfal_errmsg(errbuf, errbufsz, error_str);
00671                         errno = EINVAL;
00672                 }
00673                 return (-1);
00674         }
00675         entry = ldap_first_entry (ld, reply);
00676         if (entry) {
00677                 value = ldap_get_values (ld, entry, se_port_atnm);
00678                 if (value == NULL) {
00679                         snprintf(error_str, ERROR_STR_LEN, "SE port not found for host : %s", host);
00680                         gfal_errmsg (errbuf, errbufsz, error_str);
00681                         errno = EINVAL;
00682                         rc = -1;
00683                 } else {
00684                         *se_port = atoi (value[0]);
00685                         ldap_value_free (value);
00686                 }
00687         } else {
00688                 snprintf(error_str, ERROR_STR_LEN,"No information found for SE : %s", host);
00689                 gfal_errmsg (errbuf, errbufsz, error_str);
00690                 errno = EINVAL;
00691                 rc = -1;
00692         }
00693         ldap_msgfree (reply);
00694         ldap_unbind (ld);
00695         return (rc);
00696 }

int get_se_type const char *  ,
char ** 
 

Definition at line 700 of file mds_ifce.c.

References get_se_typex().

00701 {
00702         return (get_se_typex (host, se_type, NULL, 0));
00703 }

int get_se_typex const char *  ,
char **  ,
char *  ,
int 
 

Definition at line 705 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_se_type(), and setypefromsurl().

00706 {
00707         static char se_type_atnm[] = "GlueSEName";
00708         static char *template = "(GlueSEUniqueID=%s)";
00709         char *attr;
00710         static char *attrs[] = {se_type_atnm, NULL};
00711         int bdii_port;
00712         char bdii_server[75];
00713         LDAPMessage *entry;
00714         char filter[128];
00715         LDAP *ld;
00716         char *p;
00717         int rc = 0;
00718         LDAPMessage *reply;
00719         struct timeval timeout;
00720         char **value;
00721         char error_str[ERROR_STR_LEN];
00722 
00723         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00724                 return (-1);
00725         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00726                 gfal_errmsg (errbuf, errbufsz, "host too long");
00727                 errno = EINVAL;
00728                 return (-1);
00729         }
00730         sprintf (filter, template, host);
00731 
00732         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00733                 return (-1);
00734         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00735                 ldap_unbind (ld);
00736                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00737                 gfal_errmsg(errbuf, errbufsz, error_str);
00738                 errno = ECONNREFUSED;
00739                 return (-1);
00740         }
00741         timeout.tv_sec = 15;
00742         timeout.tv_usec = 0;
00743         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00744             &timeout, &reply)) != LDAP_SUCCESS) {
00745                 ldap_unbind (ld);
00746                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00747                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00748                         gfal_errmsg(errbuf, errbufsz, error_str);
00749                         errno = ETIMEDOUT;
00750                 } else {
00751                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00752                                  ldap_err2string(rc));
00753                         gfal_errmsg(errbuf, errbufsz, error_str);
00754                         errno = EINVAL;
00755                 }
00756                 return (-1);
00757         }
00758         entry = ldap_first_entry (ld, reply);
00759         if (entry) {
00760                 value = ldap_get_values (ld, entry, se_type_atnm);
00761                 if (value == NULL) {
00762                   snprintf(error_str, ERROR_STR_LEN,  "SE type not found for host : %s", host);
00763                   gfal_errmsg (errbuf, errbufsz, error_str);
00764                   errno = EINVAL;
00765                   rc = -1;
00766 
00767                 } else { 
00768                   if ((p = strchr (value[0], ':')))
00769                     p++;
00770                   else
00771                     p = value[0];
00772                   if ((*se_type = strdup (p)) == NULL)
00773                     rc = -1;
00774                   ldap_value_free (value);
00775                 }
00776         } else {
00777                 snprintf(error_str, ERROR_STR_LEN,  "No information found for SE : %s", host);
00778                 gfal_errmsg (errbuf, errbufsz, error_str);
00779                 errno = EINVAL;
00780                 rc = -1;
00781         }
00782         ldap_msgfree (reply);
00783         ldap_unbind (ld);
00784         return (rc);
00785 }

int get_seap_info const char *  ,
char ***  ,
int ** 
 

Definition at line 791 of file mds_ifce.c.

References get_seap_infox().

00792 {
00793         return (get_seap_infox (host, access_protocol, port, NULL, 0));
00794 }

int get_seap_infox const char *  ,
char ***  ,
int **  ,
char *  ,
int 
 

Definition at line 796 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_seap_info().

00797 {
00798         static char proto_port[] = "GlueSEAccessProtocolPort";
00799         static char proto_type[] = "GlueSEAccessProtocolType";
00800         static char *template = "(&(GlueSEAccessProtocolType=*)(GlueChunkKey=GlueSEUniqueID=%s))";
00801         char **ap;
00802         char *attr;
00803         static char *attrs[] = {proto_type, proto_port, NULL};
00804         int bdii_port;
00805         char bdii_server[75];
00806         BerElement *ber;
00807         LDAPMessage *entry;
00808         char filter[128];
00809         int i;
00810         int j;
00811         LDAP *ld;
00812         int nbentries;
00813         int *pn;
00814         int rc = 0;
00815         LDAPMessage *reply;
00816         struct timeval timeout;
00817         char **value;
00818         char error_str[ERROR_STR_LEN];
00819 
00820         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00821                 return (-1);
00822         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00823                 gfal_errmsg (errbuf, errbufsz, "host too long");
00824                 errno = EINVAL;
00825                 return (-1);
00826         }
00827         sprintf (filter, template, host);
00828 
00829         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00830                 return (-1);
00831         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00832                 ldap_unbind (ld);
00833                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00834                 gfal_errmsg(errbuf, errbufsz, error_str);
00835                 errno = ECONNREFUSED;
00836                 return (-1);
00837         }
00838         timeout.tv_sec = 15;
00839         timeout.tv_usec = 0;
00840         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00841             &timeout, &reply)) != LDAP_SUCCESS) {
00842                 ldap_unbind (ld);
00843                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00844                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00845                         gfal_errmsg(errbuf, errbufsz, error_str);
00846                         errno = ETIMEDOUT;
00847                 } else {
00848                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00849                                  ldap_err2string(rc));
00850                         gfal_errmsg(errbuf, errbufsz, error_str);
00851                         errno = EINVAL;
00852                 }
00853                 return (-1);
00854         }
00855         nbentries = ldap_count_entries (ld, reply);
00856         nbentries++;
00857         if ((ap = calloc (nbentries, sizeof(char *))) == NULL) {
00858                 ldap_unbind (ld);
00859                 return (-1);
00860         }
00861         if ((pn = calloc (nbentries, sizeof(int))) == NULL) {
00862                 free (ap);
00863                 ldap_unbind (ld);
00864                 return (-1);
00865         }
00866         for (entry = ldap_first_entry (ld, reply), i = 0;
00867              entry != NULL;
00868              entry = ldap_next_entry (ld, entry), i++) {
00869                 for (attr = ldap_first_attribute (ld, entry, &ber);
00870                      attr != NULL;
00871                      attr = ldap_next_attribute (ld, entry, ber)) {
00872                         value = ldap_get_values (ld, entry, attr);
00873                         if (value == NULL) {
00874                                 rc = -1;
00875                                 continue;
00876                         }
00877                         if (strcmp (attr, "GlueSEAccessProtocolType") == 0) {
00878                                 if ((ap[i] = strdup (value[0])) == NULL)
00879                                         rc = -1;
00880                         } else
00881                                 pn[i] = atoi (value[0]);
00882                         ldap_value_free (value);
00883                 }
00884         }
00885         ldap_msgfree (reply);
00886         ldap_unbind (ld);
00887         if (rc) {
00888                 for (j = 0; j < i; j++)
00889                         free (ap[i]);
00890                 free (ap);
00891                 free (pn);
00892         } else {
00893                 *access_protocol = ap;
00894                 *port = pn;
00895         }
00896         return (rc);
00897 }

char* getbestfile char **  ,
int  size,
char *  ,
int 
 

Definition at line 1516 of file gfal.c.

References get_default_se(), and getdomainnm().

Referenced by lfc_surlfromguid(), and lrc_surlfromguid().

01517 {
01518   char dname[64];
01519   int first;
01520   int i;
01521   char  *p1, *p2;
01522   char *p;
01523   int ret;
01524   char *default_se;
01525   int  localsurl, default_match;
01526 
01527   /* skip entries not in the form srm: or sfn:
01528    * take entry on same domain if it exists else
01529    * take the first supported entry
01530    */
01531   first = -1;
01532   localsurl = -1;
01533   *dname = '\0';
01534   (void) getdomainnm (dname, sizeof(dname));
01535 
01536   /* and get the default SE, it there is one */
01537   if((default_se = get_default_se(NULL, errbuf, errbufsz)) == NULL) 
01538           return (NULL);
01539 
01540   for (i = 0; i < size; i++) {
01541     p = surls[i];
01542     if (strncmp (p, "srm://", 6) && strncmp (p, "sfn://", 6))
01543       continue;
01544     if ((p1 = strchr (p + 6, '/')) == NULL) continue;
01545     *p1 = '\0';
01546     if ((p2 = strchr (p + 6, ':')))
01547       *p2 = '\0';
01548     if (first < 0) first = i;
01549     default_match = -1;
01550     if(default_se != NULL) {
01551       default_match = strcmp(p + 6, default_se);
01552     }
01553     if ((p = strchr (p + 6, '.')) == NULL) continue;
01554     ret = strcmp (p + 1, dname);
01555     *p1 = '/';
01556     if (p2) *p2 = ':';
01557     if (default_match == 0) break; /* default se match => replica on default SE */
01558     if (ret == 0) localsurl = i;        /* domains match ==> local replica */
01559   }
01560   if (i == size) {      /* no default SE entry */
01561     if (first < 0) {    /* only non suported entries */
01562       gfal_errmsg(errbuf, errbufsz, "Only non supported entries. No replica entry starting with \"srm://\" or \"sfn://\".");
01563       errno = EINVAL;
01564       return (NULL);
01565     } else if(localsurl >= 0) {
01566       i = localsurl;
01567     } else {
01568       /* seed with current time */
01569       srand( (unsigned)time( NULL ) );
01570       i = (int)((double)size * rand()/(RAND_MAX));
01571     }
01572   }
01573   return surls[i];
01574 }

int getfilemd const char *  ,
struct stat64 *  ,
char *  ,
int  ,
int 
 

Definition at line 790 of file gfal.c.

References gfal_errmsg(), se_getfilemd(), setypefromsurl(), and srm_getfilemd().

Referenced by gfal_lstat(), gfal_lstat64(), gfal_stat(), and gfal_stat64().

00791 {
00792         char *se_type;
00793         int ret;
00794         ret=setypefromsurl (surl, &se_type, errbuf, errbufsz);
00795         if (ret < 0)
00796                 return (-1);
00797         if (strcmp (se_type, "srm_v1") == 0) {
00798                 free (se_type);
00799                 return (srm_getfilemd (surl, statbuf, errbuf, errbufsz, timeout));
00800         } else if (strcmp (se_type, "edg-se") == 0) {
00801                 free (se_type);
00802                 return (se_getfilemd (surl, statbuf, errbuf, errbufsz, timeout));
00803         } else {
00804                 free (se_type);
00805                 gfal_errmsg(errbuf, errbufsz, "The Storage Element type is neither 'srm_v1' nor 'edg-se'.");
00806                 errno = EINVAL;
00807                 return (-1);
00808         }
00809 }

int getfilesizeg const char *  ,
GFAL_LONG64 *  ,
char *  ,
int 
 

Definition at line 1169 of file gfal.c.

References get_cat_type(), gfal_errmsg(), and lfc_getfilesizeg().

01170 {
01171         char *cat_type;
01172         if (get_cat_type (&cat_type) < 0) {
01173                 return (-1);
01174         }
01175         if (strcmp (cat_type, "edg") == 0) {
01176                 free (cat_type);
01177                 gfal_errmsg(errbuf, errbufsz, "The EDG catalog doesn't support the getfilesizeg() method.");
01178                 errno = EINVAL;
01179         } else if (strcmp (cat_type, "lfc") == 0) {
01180                 free (cat_type);
01181                 return (lfc_getfilesizeg (guid, filesize, errbuf, errbufsz));
01182         } else {
01183                 free (cat_type);
01184                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01185                 errno = EINVAL;
01186                 return (-1);
01187         }
01188 }

int gfal_access const char *  ,
int 
 

Definition at line 97 of file gfal.c.

References proto_ops::access, find_pops(), proto_ops::maperror, and parseturl().

00098 {
00099         char errbuf[256];
00100         char pathbuf[1024];
00101         char *pfn;
00102         struct proto_ops *pops;
00103         char protocol[64];
00104 
00105         if (strncmp (path, "lfn:", 4) == 0 ||
00106             strncmp (path, "guid:", 5) == 0 ||
00107             strncmp (path, "srm:", 4) == 0 ||
00108             strncmp (path, "sfn:", 4) == 0) {
00109                 errno = EPROTONOSUPPORT;
00110                 return (-1);
00111         }
00112         if (parseturl (path, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf)) < 0)
00113                 return (-1);
00114         if ((pops = find_pops (protocol)) == NULL)
00115                 return (-1);
00116         if (pops->access (pfn, amode) < 0) {
00117                 errno = pops->maperror (pops, 0);
00118                 return (-1);
00119         }
00120         return (0);
00121 }

int gfal_chmod const char *  ,
mode_t 
 

Definition at line 123 of file gfal.c.

References proto_ops::chmod, find_pops(), proto_ops::maperror, and parseturl().

00124 {
00125         char errbuf[256];
00126         char pathbuf[1024];
00127         char *pfn;
00128         struct proto_ops *pops;
00129         char protocol[64];
00130 
00131         if (strncmp (path, "lfn:", 4) == 0 ||
00132             strncmp (path, "guid:", 5) == 0 ||
00133             strncmp (path, "srm:", 4) == 0 ||
00134             strncmp (path, "sfn:", 4) == 0) {
00135                 errno = EPROTONOSUPPORT;
00136                 return (-1);
00137         }
00138         if (parseturl (path, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf)) < 0)
00139                 return (-1);
00140         if ((pops = find_pops (protocol)) == NULL)
00141                 return (-1);
00142         if (pops->chmod (pfn, mode) < 0) {
00143                 errno = pops->maperror (pops, 0);
00144                 return (-1);
00145         }
00146         return (0);
00147 }

int gfal_close int   ) 
 

Definition at line 149 of file gfal.c.

References proto_ops::close, xfer_info::fileid, find_xi(), free_xi(), proto_ops::maperror, xfer_info::oflag, xfer_info::pops, xfer_info::reqid, set_xfer_done(), xfer_info::surl, and xfer_info::token.

Referenced by main().

00150 {
00151         char errbuf[256];
00152         int rc;
00153         int rc1 = 0;
00154         int sav_errno;
00155         struct xfer_info *xi;
00156 
00157         if ((xi = find_xi (fd)) == NULL)
00158                 return (-1);
00159         if ((rc = xi->pops->close (fd)) < 0)
00160                 sav_errno = xi->pops->maperror (xi->pops, 1);
00161 
00162         /* set status "done" */
00163 
00164         if (xi->surl) {
00165                 rc1 = set_xfer_done (xi->surl, xi->reqid, xi->fileid,
00166                     xi->token, xi->oflag, errbuf, sizeof(errbuf), 0);
00167                 free (xi->surl);
00168                 if (xi->token) free (xi->token);
00169         }
00170         (void) free_xi (fd);
00171         if (rc) {
00172                 errno = sav_errno;
00173                 return (-1);
00174         }
00175         return (rc1);
00176 }

int gfal_closedir DIR *   ) 
 

Definition at line 178 of file gfal.c.

References proto_ops::closedir, find_di(), free_di(), proto_ops::maperror, and dir_info::pops.

Referenced by main().

00179 {
00180         struct dir_info *di;
00181         int rc;
00182 
00183         if (di = find_di (dir)) {
00184                 if ((rc = di->pops->closedir (dir)) < 0)
00185                         errno = di->pops->maperror (di->pops, 0);
00186                 (void) free_di (di);
00187                 return (rc);
00188         } else
00189                 return (-1);
00190 }

int gfal_creat const char *  ,
mode_t 
 

Definition at line 192 of file gfal.c.

References gfal_open().

00193 {
00194         return (gfal_open (filename, O_WRONLY|O_CREAT|O_TRUNC, mode));
00195 }

int gfal_creat64 const char *  ,
mode_t 
 

Definition at line 197 of file gfal.c.

References gfal_open64().

00198 {
00199         return (gfal_open64 (filename, O_WRONLY|O_CREAT|O_TRUNC, mode));
00200 }

int gfal_errmsg char *  ,
int  ,
const char * 
 

Definition at line 202 of file gfal.c.

Referenced by create_alias(), deletesurl(), get_bdii(), get_catalog_endpoint(), get_ce_apx(), get_default_se(), get_hostname(), get_lfc_endpoint(), get_rls_endpointsx(), get_sa_path(), get_sa_rootx(), get_se_endpointx(), get_se_portx(), get_se_typex(), get_seap_infox(), getfilemd(), getfilesizeg(), guid_exists(), guidforpfn(), guidfromlfn(), lfc_create_alias(), lfc_getfilesizeg(), lfc_guid_exists(), lfc_guidforpfn(), lfc_guidfromlfn(), lfc_init(), lfc_mkdirp(), lfc_register_alias(), lfc_register_pfn(), lfc_unregister_alias(), lfc_unregister_pfn(), lfnsforguid(), lrc_guid_exists(), lrc_guidforpfn(), lrc_register_pfn(), lrc_replica_exists(), lrc_setfilesize(), lrc_surlfromguid(), lrc_surlsfromguid(), lrc_unregister_pfn(), parsesurl(), parseturl(), register_alias(), register_pfn(), replica_exists(), rmc_guidfromlfn(), rmc_lfnsforguid(), rmc_register_alias(), rmc_unregister_alias(), se_deletesurl(), se_getfilemd(), se_makedirp(), se_mkdir(), se_set_xfer_done(), se_turlfromsurl(), set_xfer_done(), set_xfer_running(), setfilesize(), setypefromsurl(), srm_deletesurl(), srm_getfilemd(), srm_getstatusx(), srm_getx(), srm_set_xfer_done(), srm_set_xfer_running(), srm_turlsfromsurls(), surlfromguid(), surlsfromguid(), turlfromsfn(), turlfromsurlx(), unregister_alias(), and unregister_pfn().

00203 {
00204         if (errbuf == NULL)
00205                 fprintf (stderr, "%s\n", errmsg);
00206         else {
00207                 strncpy (errbuf, errmsg, errbufsz - 1);
00208                 *(errbuf+errbufsz-1) = '\0';
00209         }
00210 }

off_t gfal_lseek int  ,
off_t  ,
int 
 

Definition at line 213 of file gfal.c.

References find_xi(), proto_ops::lseek, proto_ops::maperror, and xfer_info::pops.

00214 {
00215         off_t offset_out;
00216         struct xfer_info *xi;
00217 
00218         if ((xi = find_xi (fd)) == NULL)
00219                 return (-1);
00220         if ((offset_out = xi->pops->lseek (fd, offset, whence)) < 0)
00221                 errno = xi->pops->maperror (xi->pops, 1);
00222         return (offset_out);
00223 }

off64_t gfal_lseek64 int  ,
off64_t  ,
int 
 

Definition at line 226 of file gfal.c.

References find_xi(), proto_ops::lseek64, proto_ops::maperror, and xfer_info::pops.

00227 {
00228         off64_t offset_out;
00229         struct xfer_info *xi;
00230 
00231         if ((xi = find_xi (fd)) == NULL)
00232                 return (-1);
00233         if ((offset_out = xi->pops->lseek64 (fd, offset, whence)) < 0)
00234                 errno = xi->pops->maperror (xi->pops, 1);
00235         return (offset_out);
00236 }

int gfal_lstat const char *  ,
struct stat * 
 

Definition at line 238 of file gfal.c.

References find_pops(), getfilemd(), guidfromlfn(), proto_ops::lstat, proto_ops::maperror, mdtomd32(), parseturl(), surlfromguid(), and turlfromsfn().

00239 {
00240         char errbuf[256];
00241         char *fn;
00242         char *guid;
00243         char pathbuf[1024];
00244         char *pfn;
00245         struct proto_ops *pops;
00246         char protocol[64];
00247         int rc;
00248         struct stat64 statb64;
00249         char *turl;
00250 
00251         if (strncmp (filename, "lfn:", 4) == 0) {
00252                 if ((guid = guidfromlfn (filename + 4, errbuf, sizeof(errbuf))) == NULL)
00253                         return (-1);
00254                 if ((fn = surlfromguid (guid, errbuf, sizeof(errbuf))) == NULL) {
00255                         free (guid);
00256                         return (-1);
00257                 }
00258                 free (guid);
00259         } else if (strncmp (filename, "guid:", 5) == 0) {
00260                 if ((fn = surlfromguid (filename + 5, errbuf, sizeof(errbuf))) == NULL)
00261                         return (-1);
00262         } else
00263                 fn = (char *)filename;
00264         if (strncmp (fn, "srm:", 4) == 0) {
00265                 if ((rc = getfilemd (fn, &statb64, errbuf, sizeof(errbuf), 0)) == 0)
00266                         rc = mdtomd32 (&statb64, statbuf);
00267                 if (fn != filename) free (fn);
00268                 return (rc);
00269         }
00270         if (strncmp (fn, "sfn:", 4) == 0) {
00271                 if ((turl = turlfromsfn (fn, NULL, errbuf, sizeof(errbuf))) == NULL) {
00272                         if (fn != filename) free (fn);
00273                         return (-1);
00274                 }
00275         } else          /* assume that is a pfn */
00276                 turl = fn;
00277         if ((rc = parseturl (turl, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf))) == 0) {
00278                 if ((pops = find_pops (protocol)) != NULL) {
00279                         if ((rc = pops->lstat (pfn, statbuf)) < 0)
00280                                 errno = pops->maperror (pops, 0);
00281                 }
00282         }
00283         if (fn != filename) free (fn);
00284         if (turl != fn) free (turl);
00285         if (rc < 0 || pops == NULL)
00286                 return (-1);
00287         return (0);
00288 }

int gfal_lstat64 const char *  ,
struct stat64 * 
 

Definition at line 290 of file gfal.c.

References find_pops(), getfilemd(), guidfromlfn(), proto_ops::lstat64, proto_ops::maperror, parseturl(), surlfromguid(), and turlfromsfn().

00291 {
00292         char errbuf[256];
00293         char *fn;
00294         char *guid;
00295         char pathbuf[1024];
00296         char *pfn;
00297         struct proto_ops *pops;
00298         char protocol[64];
00299         int rc;
00300         char *turl;
00301 
00302         if (strncmp (filename, "lfn:", 4) == 0) {
00303                 if ((guid = guidfromlfn (filename + 4, errbuf, sizeof(errbuf))) == NULL)
00304                         return (-1);
00305                 if ((fn = surlfromguid (guid, errbuf, sizeof(errbuf))) == NULL) {
00306                         free (guid);
00307                         return (-1);
00308                 }
00309                 free (guid);
00310         } else if (strncmp (filename, "guid:", 5) == 0) {
00311                 if ((fn = surlfromguid (filename + 5, errbuf, sizeof(errbuf))) == NULL)
00312                         return (-1);
00313         } else
00314                 fn = (char *)filename;
00315         if (strncmp (fn, "srm:", 4) == 0) {
00316                 rc = getfilemd (fn, statbuf, errbuf, sizeof(errbuf), 0);
00317                 if (fn != filename) free (fn);
00318                 return (rc);
00319         }
00320         if (strncmp (fn, "sfn:", 4) == 0) {
00321                 if ((turl = turlfromsfn (fn, NULL, errbuf, sizeof(errbuf))) == NULL) {
00322                         if (fn != filename) free (fn);
00323                         return (-1);
00324                 }
00325         } else          /* assume that is a pfn */
00326                 turl = fn;
00327         if ((rc = parseturl (turl, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf))) == 0) {
00328                 if ((pops = find_pops (protocol)) != NULL) {
00329                         if ((rc = pops->lstat64 (pfn, statbuf)) < 0)
00330                                 errno = pops->maperror (pops, 0);
00331                 }
00332         }
00333         if (fn != filename) free (fn);
00334         if (turl != fn) free (turl);
00335         if (rc < 0 || pops == NULL)
00336                 return (-1);
00337         return (0);
00338 }

int gfal_mkdir const char *  ,
mode_t 
 

Definition at line 340 of file gfal.c.

References find_pops(), proto_ops::maperror, proto_ops::mkdir, and parseturl().

00341 {
00342         char errbuf[256];
00343         char pathbuf[1024];
00344         char *pfn;
00345         struct proto_ops *pops;
00346         char protocol[64];
00347 
00348         if (strncmp (dirname, "lfn:", 4) == 0 ||
00349             strncmp (dirname, "guid:", 5) == 0 ||
00350             strncmp (dirname, "srm:", 4) == 0 ||
00351             strncmp (dirname, "sfn:", 4) == 0) {
00352                 errno = EPROTONOSUPPORT;
00353                 return (-1);
00354         }
00355         if (parseturl (dirname, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf)) < 0)
00356                 return (-1);
00357         if ((pops = find_pops (protocol)) == NULL)
00358                 return (-1);
00359         if (pops->mkdir (pfn, mode) < 0) {
00360                 errno = pops->maperror (pops, 0);
00361                 return (-1);
00362         }
00363         return (0);
00364 }

int gfal_open const char *  ,
int  ,
mode_t 
 

Definition at line 366 of file gfal.c.

References alloc_xi(), xfer_info::fd, xfer_info::fileid, find_pops(), get_sup_proto(), guidfromlfn(), proto_ops::maperror, xfer_info::oflag, proto_ops::open, parseturl(), xfer_info::pops, xfer_info::reqid, set_xfer_running(), xfer_info::surl, surlfromguid(), xfer_info::token, turlfromsfn(), and turlfromsurl().

Referenced by gfal_creat(), gfal_open64(), and main().

00367 {
00368         char errbuf[256];
00369         int fd;
00370         int fileid;
00371         char *fn;
00372         char *guid = NULL;
00373         char pathbuf[1024];
00374         char *pfn;
00375         struct proto_ops *pops;
00376         char protocol[64];
00377         int reqid;
00378         char **supported_protocols;
00379         char *token = NULL;
00380         char *turl = NULL;
00381         struct xfer_info *xi;
00382 
00383         supported_protocols = get_sup_proto ();
00384 
00385         if (strncmp (filename, "lfn:", 4) == 0) {
00386                 if ((guid = guidfromlfn (filename + 4, errbuf, sizeof(errbuf))) == NULL)
00387                         return (-1);
00388                 if ((fn = surlfromguid (guid, errbuf, sizeof(errbuf))) == NULL) {
00389                         free (guid);
00390                         return (-1);
00391                 }
00392         } else if (strncmp (filename, "guid:", 5) == 0) {
00393                 if ((fn = surlfromguid (filename + 5, errbuf, sizeof(errbuf))) == NULL)
00394                         return (-1);
00395         } else
00396                 fn = (char *)filename;
00397         if (strncmp (fn, "srm:", 4) == 0) {
00398                 if ((turl = turlfromsurl (fn, supported_protocols, flags,
00399                     &reqid, &fileid, &token, errbuf, sizeof(errbuf), 0)) == NULL)
00400                         goto err;
00401         } else if (strncmp (fn, "sfn:", 4) == 0) {
00402                 if ((turl = turlfromsfn (fn, supported_protocols, errbuf, sizeof(errbuf))) == NULL)
00403                         goto err;
00404         } else          /* assume that is a pfn */
00405                 turl = fn;
00406         if (parseturl (turl, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf)) < 0)
00407                 goto err;
00408         if ((pops = find_pops (protocol)) == NULL)
00409                 goto err;
00410         if ((fd = pops->open (pfn, flags, mode)) < 0) {
00411                 errno = pops->maperror (pops, 1);
00412                 goto err;
00413         }
00414         if ((xi = alloc_xi (fd)) == NULL)
00415                 goto err;
00416         xi->fd = fd;
00417         xi->oflag = flags;
00418         xi->pops = pops;
00419         if (strncmp (fn, "srm:", 4) == 0) {
00420                 xi->surl = strdup (fn);
00421                 xi->reqid = reqid;
00422                 xi->fileid = fileid;
00423                 if (token) {
00424                         xi->token = strdup (token);
00425                         free (token);
00426                 }
00427                 (void) set_xfer_running (xi->surl, xi->reqid, xi->fileid,
00428                     xi->token, errbuf, sizeof(errbuf), 0);
00429         }
00430 
00431         if (guid) free (guid);
00432         if (fn != filename) free (fn);
00433         if (turl != fn) free (turl);
00434         return (fd);
00435 err:
00436         if (guid) free (guid);
00437         if (fn != filename) free (fn);
00438         if (turl && turl != fn) free (turl);
00439         return (-1);
00440 }

int gfal_open64 const char *  ,
int  ,
mode_t 
 

Definition at line 442 of file gfal.c.

References gfal_open().

Referenced by gfal_creat64().

00443 {
00444         return (gfal_open (filename, flags | O_LARGEFILE, mode));
00445 }

DIR* gfal_opendir const char *   ) 
 

Definition at line 448 of file gfal.c.

References alloc_di(), dir_info::dir, find_pops(), proto_ops::maperror, proto_ops::opendir, parseturl(), and dir_info::pops.

Referenced by main().

00449 {
00450         struct dir_info *di;
00451         DIR *dir;
00452         char errbuf[256];
00453         char pathbuf[1024];
00454         char *pfn;
00455         struct proto_ops *pops;
00456         char protocol[64];
00457 
00458         if (strncmp (dirname, "lfn:", 4) == 0 ||
00459             strncmp (dirname, "guid:", 5) == 0 ||
00460             strncmp (dirname, "srm:", 4) == 0 ||
00461             strncmp (dirname, "sfn:", 4) == 0) {
00462                 errno = EPROTONOSUPPORT;
00463                 return (NULL);
00464         }
00465         if (parseturl (dirname, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf)) < 0)
00466                 return (NULL);
00467         if ((pops = find_pops (protocol)) == NULL)
00468                 return (NULL);
00469         if ((dir = pops->opendir (pfn)) == NULL) {
00470                 errno = pops->maperror (pops, 0);
00471                 return (NULL);
00472         }
00473         if ((di = alloc_di (dir)) == NULL)
00474                 return (NULL);
00475         di->pops = pops;
00476         return (dir);
00477 }

ssize_t gfal_read int  ,
void *  ,
size_t 
 

Definition at line 480 of file gfal.c.

References find_xi(), proto_ops::maperror, xfer_info::pops, and proto_ops::read.

Referenced by main().

00481 {
00482         int rc;
00483         struct xfer_info *xi;
00484 
00485         if ((xi = find_xi (fd)) == NULL)
00486                 return (-1);
00487         if ((rc = xi->pops->read (fd, buf, size)) < 0)
00488                 errno = xi->pops->maperror (xi->pops, 1);
00489         return (rc);
00490 }

struct dirent* gfal_readdir DIR *   ) 
 

Definition at line 493 of file gfal.c.

References find_di(), proto_ops::maperror, dir_info::pops, and proto_ops::readdir.

Referenced by main().

00494 {
00495         struct dirent *de;
00496         struct dir_info *di;
00497 
00498         if ((di = find_di (dir)) == NULL)
00499                 return (NULL);
00500         if ((de = di->pops->readdir (dir)) == NULL)
00501                 errno = di->pops->maperror (di->pops, 0);
00502         return (de);
00503 }

int gfal_rename const char *  ,
const char * 
 

Definition at line 518 of file gfal.c.

References find_pops(), proto_ops::maperror, parseturl(), and proto_ops::rename.

00519 {
00520         char *new_pfn;
00521         char *old_pfn;
00522         char errbuf[256];
00523         char pathbuf1[1024];
00524         char pathbuf2[1024];
00525         struct proto_ops *pops;
00526         char protocol1[64];
00527         char protocol2[64];
00528 
00529         if (strncmp (old_name, "lfn:", 4) == 0 ||
00530             strncmp (old_name, "guid:", 5) == 0 ||
00531             strncmp (old_name, "srm:", 4) == 0 ||
00532             strncmp (old_name, "sfn:", 4) == 0) {
00533                 errno = EPROTONOSUPPORT;
00534                 return (-1);
00535         }
00536         if (strncmp (new_name, "lfn:", 4) == 0 ||
00537             strncmp (new_name, "guid:", 5) == 0 ||
00538             strncmp (new_name, "srm:", 4) == 0 ||
00539             strncmp (new_name, "sfn:", 4) == 0) {
00540                 errno = EPROTONOSUPPORT;
00541                 return (-1);
00542         }
00543         if (parseturl (old_name, protocol1, sizeof(protocol1), pathbuf1, sizeof(pathbuf1), &old_pfn, errbuf, sizeof(errbuf)) < 0)
00544                 return (-1);
00545         if (parseturl (new_name, protocol2, sizeof(protocol2), pathbuf2, sizeof(pathbuf2), &new_pfn, errbuf, sizeof(errbuf)) < 0)
00546                 return (-1);
00547         if (strcmp (protocol1, protocol2)) {
00548                 errno = EINVAL;
00549                 return (-1);
00550         }
00551         if ((pops = find_pops (protocol1)) == NULL)
00552                 return (-1);
00553         if (pops->rename (old_pfn, new_pfn) < 0) {
00554                 errno = pops->maperror (pops, 0);
00555                 return (-1);
00556         }
00557         return (0);
00558 }

int gfal_rmdir const char *   ) 
 

Definition at line 560 of file gfal.c.

References find_pops(), proto_ops::maperror, parseturl(), and proto_ops::rmdir.

00561 {
00562         char errbuf[256];
00563         char pathbuf[1024];
00564         char *pfn;
00565         struct proto_ops *pops;
00566         char protocol[64];
00567 
00568         if (strncmp (dirname, "lfn:", 4) == 0 ||
00569             strncmp (dirname, "guid:", 5) == 0 ||
00570             strncmp (dirname, "srm:", 4) == 0 ||
00571             strncmp (dirname, "sfn:", 4) == 0) {
00572                 errno = EPROTONOSUPPORT;
00573                 return (-1);
00574         }
00575         if (parseturl (dirname, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf)) < 0)
00576                 return (-1);
00577         if ((pops = find_pops (protocol)) == NULL)
00578                 return (-1);
00579         if (pops->rmdir (pfn) < 0) {
00580                 errno = pops->maperror (pops, 0);
00581                 return (-1);
00582         }
00583         return (0);
00584 }

ssize_t gfal_setfilchg int  ,
const void *  ,
size_t 
 

Definition at line 587 of file gfal.c.

References find_xi(), proto_ops::maperror, xfer_info::pops, and proto_ops::setfilchg.

00588 {
00589         int rc;
00590         struct xfer_info *xi;
00591 
00592         if ((xi = find_xi (fd)) == NULL)
00593                 return (-1);
00594         if ((rc = xi->pops->setfilchg (fd, buf, size)) < 0)
00595                 errno = xi->pops->maperror (xi->pops, 1);
00596         return (rc);
00597 }

int gfal_stat const char *  ,
struct stat * 
 

Definition at line 599 of file gfal.c.

References find_pops(), getfilemd(), guidfromlfn(), proto_ops::maperror, mdtomd32(), parseturl(), proto_ops::stat, surlfromguid(), and turlfromsfn().

Referenced by main().

00600 {
00601         char errbuf[256];
00602         char *fn;
00603         char *guid;
00604         char pathbuf[1024];
00605         char *pfn;
00606         struct proto_ops *pops;
00607         char protocol[64];
00608         int rc;
00609         struct stat64 statb64;
00610         char *turl;
00611 
00612         if (strncmp (filename, "lfn:", 4) == 0) {
00613                 if ((guid = guidfromlfn (filename + 4, errbuf, sizeof(errbuf))) == NULL)
00614                         return (-1);
00615                 if ((fn = surlfromguid (guid, errbuf, sizeof(errbuf))) == NULL) {
00616                         free (guid);
00617                         return (-1);
00618                 }
00619                 free (guid);
00620         } else if (strncmp (filename, "guid:", 5) == 0) {
00621                 if ((fn = surlfromguid (filename + 5, errbuf, sizeof(errbuf))) == NULL)
00622                         return (-1);
00623         } else
00624                 fn = (char *)filename;
00625         if (strncmp (fn, "srm:", 4) == 0) {
00626                 if ((rc = getfilemd (fn, &statb64, errbuf, sizeof(errbuf), 0)) == 0)
00627                         rc = mdtomd32 (&statb64, statbuf);
00628                 if (fn != filename) free (fn);
00629                 return (rc);
00630         }
00631         if (strncmp (fn, "sfn:", 4) == 0) {
00632                 if ((turl = turlfromsfn (fn, NULL, errbuf, sizeof(errbuf))) == NULL) {
00633                         if (fn != filename) free (fn);
00634                         return (-1);
00635                 }
00636         } else          /* assume that is a pfn */
00637                 turl = fn;
00638         if ((rc = parseturl (turl, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf), &pfn, errbuf, sizeof(errbuf))) == 0) {
00639                 if ((pops = find_pops (protocol)) != NULL) {
00640                         if ((rc = pops->stat (pfn, statbuf)) < 0)
00641                                 errno = pops->maperror (pops, 0);
00642                 }
00643         }
00644         if (fn != filename) free (fn);
00645         if (turl != fn) free (turl);
00646         if (rc < 0 || pops == NULL)
00647                 return (-1);
00648         return (0);
00649 }

int gfal_stat64 const char *  ,
struct stat64 * 
 

Definition at line 651 of file gfal.c.

References find_pops(), getfilemd(), guidfromlfn(), proto_ops::maperror, parseturl(), proto_ops::stat64, surlfromguid(), and turlfromsfn().

00652 {
00653         char errbuf[256];
00654         char *fn;
00655         char *guid;
00656         char pathbuf[1024];
00657         char *pfn;
00658         struct proto_ops *pops;
00659         char protocol[64];
00660         int rc;
00661         char *turl;
00662 
00663         if (strncmp (filename, "lfn:", 4) == 0) {
00664                 if ((guid = guidfromlfn (filename + 4, errbuf, sizeof(errbuf))) == NULL)
00665                         return (-1);
00666                 if ((fn = surlfromguid (guid, errbuf, sizeof(errbuf))) == NULL) {
00667                         free (guid);
00668                         return (-1);
00669                 }
00670                 free (guid);
00671         } else if (strncmp (filename, "guid:", 5) == 0) {
00672                 if ((fn = surlfromguid (filename + 5, errbuf, sizeof(errbuf))) == NULL)
00673                         return (-1);
00674         } else
00675                 fn = (char *)filename;
00676         if (strncmp (fn, "srm:", 4) == 0) {
00677                 rc = getfilemd (fn, statbuf, errbuf, sizeof(errbuf), 0);
00678                 if (fn != filename) free (fn);
00679                 return (rc);
00680         }
00681         if (strncmp (fn, "sfn:", 4) == 0) {
00682                 if ((turl = turlfromsfn (fn, NULL, errbuf, sizeof(errbuf))) == NULL) {
00683                         if (fn != filename) free (fn);
00684                         return (-1);
00685                 }
00686         } else          /* assume that is a pfn */
00687                 turl = fn;
00688         if ((rc = parseturl (turl, protocol, sizeof(protocol), pathbuf, sizeof(pathbuf),
00689             &pfn, errbuf, sizeof(errbuf))) == 0) {
00690                 if ((pops = find_pops (protocol)) != NULL) {
00691                         if ((rc = pops->stat64 (pfn, statbuf)) < 0)
00692                                 errno = pops->maperror (pops, 0);
00693                 }
00694         }
00695         if (fn != filename) free (fn);
00696         if (turl != fn) free (turl);
00697         if (rc < 0 || pops == NULL)
00698                 return (-1);
00699         return (0);
00700 }

int gfal_unlink const char *   ) 
 

Definition at line 702 of file gfal.c.

References deletepfn(), and surlsfromguid().

Referenced by main().

00703 {
00704         char errbuf[256];
00705         int i = 0;
00706         char **pfns;
00707         int rc = 0;
00708 
00709         if (strncmp (filename, "lfn:", 4) == 0) {
00710                 errno = EPROTONOSUPPORT;
00711                 return (-1);
00712         } else if (strncmp (filename, "guid:", 5) == 0) {
00713                 /* must try to delete all PFNs mapped to this guid */
00714                 if ((pfns = surlsfromguid (filename + 5, errbuf, sizeof(errbuf))) == NULL)
00715                         return (-1);
00716                 while (pfns[i]) {
00717                         rc += deletepfn (pfns[i], filename + 5, errbuf, sizeof(errbuf));
00718                         free (pfns[i++]);
00719                 }
00720                 free (pfns);
00721                 return (rc == 0 ? 0 : -1);
00722         } else
00723                 return (deletepfn (filename, NULL, errbuf, sizeof(errbuf)));
00724 }

ssize_t gfal_write int  ,
const void *  ,
size_t 
 

Definition at line 727 of file gfal.c.

References find_xi(), proto_ops::maperror, xfer_info::pops, and proto_ops::write.

Referenced by main().

00728 {
00729         int rc;
00730         struct xfer_info *xi;
00731 
00732         if ((xi = find_xi (fd)) == NULL)
00733                 return (-1);
00734         if ((rc = xi->pops->write (fd, buf, size)) < 0)
00735                 errno = xi->pops->maperror (xi->pops, 1);
00736         return (rc);
00737 }

int guid_exists const char *  ,
char *  ,
int 
 

Definition at line 1231 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_guid_exists(), and lrc_guid_exists().

01232 {
01233         char *cat_type;
01234         if (get_cat_type (&cat_type) < 0) {
01235                 return (-1);
01236         }
01237         if (strcmp (cat_type, "edg") == 0) {
01238                 free (cat_type);
01239                 return (lrc_guid_exists (guid, errbuf, errbufsz));
01240         } else if (strcmp (cat_type, "lfc") == 0) {
01241                 free (cat_type);
01242                 return (lfc_guid_exists (guid, errbuf, errbufsz));
01243         } else {
01244                 free (cat_type);
01245                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01246                 errno = EINVAL;
01247                 return (-1);
01248         }
01249 }

char* guidforpfn const char *  ,
char *  ,
int 
 

Definition at line 1211 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_guidforpfn(), and lrc_guidforpfn().

01212 {
01213         char *cat_type;
01214         if (get_cat_type (&cat_type) < 0) {
01215                 return (NULL);
01216         }
01217         if (strcmp (cat_type, "edg") == 0) {
01218                 free (cat_type);
01219                 return (lrc_guidforpfn (pfn, errbuf, errbufsz));
01220         } else if (strcmp (cat_type, "lfc") == 0) {
01221                 free (cat_type);
01222                 return (lfc_guidforpfn (pfn, errbuf, errbufsz));
01223         } else {
01224                 free (cat_type);
01225                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01226                 errno = EINVAL;
01227                 return (NULL);
01228         }
01229 }

char* guidfromlfn const char *  ,
char *  ,
int 
 

Definition at line 1355 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_guidfromlfn(), and rmc_guidfromlfn().

Referenced by gfal_lstat(), gfal_lstat64(), gfal_open(), gfal_stat(), and gfal_stat64().

01356 {
01357         char *cat_type;
01358         if (get_cat_type (&cat_type) < 0) {
01359                 return (NULL);
01360         }
01361         if (strcmp (cat_type, "edg") == 0) {
01362                 free (cat_type);
01363                 return (rmc_guidfromlfn (lfn, errbuf, errbufsz));
01364         } else if (strcmp (cat_type, "lfc") == 0) {
01365                 free (cat_type);
01366                 return (lfc_guidfromlfn (lfn, errbuf, errbufsz));
01367         } else {
01368                 free (cat_type);
01369                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01370                 errno = EINVAL;
01371                 return (NULL);
01372         }
01373 }

int lfc_create_alias const char *  ,
const char *  ,
GFAL_LONG64  ,
char *  ,
int 
 

Definition at line 466 of file lfc_ifce.c.

References fc_ops::creatg, fcops, gfal_errmsg(), gfal_version, lfc_init(), fc_ops::serrno, fc_ops::sstrerror, and fc_ops::starttrans.

Referenced by create_alias().

00467 {
00468   if(lfc_init(errbuf, errbufsz) < 0)
00469     return (-1);
00470 
00471   fcops.starttrans(NULL, gfal_version);
00472   if(fcops.creatg(lfn, guid, 0666) < 0) {
00473     if(*fcops.serrno < 1000) 
00474       errno = *fcops.serrno;
00475     else {
00476       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00477       errno = ECOMM;
00478     }
00479     return (-1);
00480   }
00481   if(fcops.setfsizeg(guid, size, NULL, NULL) < 0) {
00482     if(*fcops.serrno < 1000)
00483       errno = *fcops.serrno;
00484     else {
00485       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00486       errno = ECOMM;
00487     }
00488     return (-1);
00489   }
00490   fcops.endtrans();
00491   return (0);
00492 }

int lfc_deletepfn const char *  ,
const char *  ,
char *  ,
int 
 

int lfc_deletesurl const char *  ,
char *  ,
int 
 

char* lfc_get_catalog_endpoint char *  ,
int 
 

Definition at line 168 of file lfc_ifce.c.

References lfc_host, and lfc_init().

Referenced by get_catalog_endpoint().

00168                                                      {
00169         if(lfc_init(errbuf, errbufsz) < 0)
00170                 return (NULL);
00171         return lfc_host;
00172 }

int lfc_getfilesizeg const char *  ,
GFAL_LONG64 *  ,
char *  ,
int 
 

Definition at line 191 of file lfc_ifce.c.

References fcops, gfal_errmsg(), lfc_init(), fc_ops::serrno, fc_ops::sstrerror, and fc_ops::statg.

Referenced by getfilesizeg().

00192 {
00193   struct lfc_filestatg statg;
00194 
00195   if(lfc_init(errbuf, errbufsz) < 0)
00196     return (-1);
00197 
00198   if(fcops.statg(NULL, guid, &statg) < 0) {
00199     if (*fcops.serrno < 1000) 
00200       errno = *fcops.serrno;
00201     else {
00202       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00203       errno = ECOMM;
00204     }
00205     return (-1);
00206   }
00207   
00208   *sizep = (u_signed64) statg.filesize;
00209   return (0);
00210 }

int lfc_guid_exists const char *  ,
char *  ,
int 
 

Definition at line 239 of file lfc_ifce.c.

References fcops, gfal_errmsg(), lfc_init(), fc_ops::serrno, fc_ops::sstrerror, and fc_ops::statg.

Referenced by guid_exists().

00240 {
00241   struct lfc_filestatg statg;
00242 
00243   if(lfc_init(errbuf, errbufsz) < 0)
00244     return (-1);
00245 
00246   if(fcops.statg(NULL, guid, &statg) < 0) {
00247     if(*fcops.serrno == ENOENT) 
00248         return (0);
00249     if (*fcops.serrno < 1000) 
00250       errno = *fcops.serrno;
00251     else {
00252       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00253       errno = ECOMM;
00254     }
00255     return (-1);
00256   }
00257   return (1);
00258 }

char* lfc_guidforpfn const char *  pfn,
char *  errbuf,
int  errbufsz
 

lfc_guidforpfn : Get the guid for a replica. If the replica does not exist, fail with ENOENT

Definition at line 215 of file lfc_ifce.c.

References fcops, gfal_errmsg(), lfc_init(), fc_ops::serrno, fc_ops::sstrerror, and fc_ops::statr.

Referenced by guidforpfn().

00216 {
00217   char *p;
00218   struct lfc_filestatg statg;
00219 
00220   if(lfc_init(errbuf, errbufsz) < 0)
00221     return (NULL);
00222 
00223   if(fcops.statr(pfn, &statg) < 0) {
00224     if(*fcops.serrno < 1000)
00225       errno = *fcops.serrno;
00226     else {
00227       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00228       errno = ECOMM;
00229     }
00230     return (NULL);
00231   }
00232   if((p = strdup(statg.guid)) == NULL) {
00233     return (NULL);
00234   }
00235   return (p);
00236 }

char* lfc_guidfromlfn const char *  ,
char *  ,
int 
 

Definition at line 388 of file lfc_ifce.c.

References fcops, gfal_errmsg(), lfc_init(), fc_ops::serrno, fc_ops::sstrerror, and fc_ops::statg.

Referenced by guidfromlfn().

00389 {
00390   struct lfc_filestatg statg;
00391   char *p;
00392 
00393   if(lfc_init(errbuf, errbufsz) < 0)
00394     return (NULL);
00395 
00396   if(fcops.statg(lfn, NULL, &statg) < 0) {
00397     if(*fcops.serrno < 1000)
00398       errno = *fcops.serrno;
00399     else {
00400       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00401       errno = ECOMM;
00402     }
00403     return (NULL);
00404   }
00405   if((p = strdup(statg.guid)) == NULL)
00406     return (NULL);
00407   return (p);
00408 }

char** lfc_lfnsforguid const char *  ,
char *  ,
int 
 

Definition at line 411 of file lfc_ifce.c.

References ALLOC_BLOCK_SIZE, fcops, lfc_init(), and fc_ops::listlinks.

Referenced by lfnsforguid().

00412 {
00413   lfc_list list;
00414   struct lfc_linkinfo* lp;
00415   int flags;
00416   char **p, **pp;
00417   size_t size = ALLOC_BLOCK_SIZE;
00418   size_t i = 0;
00419   
00420   if(lfc_init(errbuf, errbufsz) < 0)
00421     return (NULL);
00422 
00423   /* allocate some memory for the pointers */
00424   if((p = (char**)calloc(size, sizeof(char*))) == NULL) {
00425     return (NULL);
00426   }
00427 
00428   flags = CNS_LIST_BEGIN;
00429   while((lp = fcops.listlinks(NULL, guid, flags, &list)) != NULL) {
00430     if(flags == CNS_LIST_BEGIN) 
00431       flags = CNS_LIST_CONTINUE;
00432     
00433     if((p[i++] = strdup(lp->path)) == NULL) {
00434       (void) fcops.listlinks(NULL, guid, CNS_LIST_END, &list);
00435       free (p);
00436       return (NULL);
00437     }
00438     
00439     if(i == size) {
00440       size += ALLOC_BLOCK_SIZE;
00441       if((pp = (char**)realloc(p, size * sizeof(char*))) == NULL) {
00442         (void) fcops.listlinks(NULL, guid, CNS_LIST_END, &list);
00443         free (p);
00444         return (NULL);
00445       }
00446       p = pp;
00447     }
00448   } 
00449   (void) fcops.listlinks(NULL, guid, CNS_LIST_END, &list);
00450   /* no results */
00451   if( i== 0) {
00452     errno = ENOENT;
00453     free (p);
00454     return (NULL);
00455   }
00456 
00457   if((pp = (char**)realloc(p, (i+1) * sizeof(char*))) == NULL) {
00458     free (p);
00459     return (NULL);
00460   }
00461   pp[i] = NULL;
00462   return (pp);
00463 }

int lfc_mkdirp const char *  ,
mode_t  ,
char *  ,
int 
 

Definition at line 589 of file lfc_ifce.c.

References fcops, gfal_errmsg(), lfc_init(), fc_ops::mkdirg, fc_ops::serrno, fc_ops::sstrerror, and fc_ops::statg.

00590 {
00591   int c;
00592   char *lastslash = NULL;
00593   char *p;
00594   char *p1;
00595   char *q;
00596   char sav_path[CA_MAXPATHLEN+1];
00597   struct lfc_filestatg statbuf;
00598   uuid_t uuid;
00599   char uuid_buf[CA_MAXGUIDLEN+1];
00600 
00601   if(lfc_init(errbuf, errbufsz) < 0)
00602     return (-1);
00603 
00604   if (strlen (path) >= sizeof(sav_path)) {
00605     gfal_errmsg(errbuf, errbufsz, "Path too long");
00606     errno = ENAMETOOLONG;
00607     return (-1);
00608   }
00609   strcpy (sav_path, path);
00610   p1 = strchr (sav_path, '/');
00611   p = strrchr (sav_path, '/');
00612   while (p > p1) {
00613     if (lastslash == NULL) lastslash = p;
00614     *p = '\0';
00615     c = fcops.statg (sav_path, NULL, &statbuf);
00616     if (c == 0) {
00617       *p = '/';
00618       break;
00619     }
00620     if (*fcops.serrno != ENOENT) {
00621       if(*fcops.serrno < 1000) 
00622         errno = *fcops.serrno;
00623       else {
00624         gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00625         errno = ECOMM;
00626       }
00627       return (c);
00628     }
00629     q = strrchr (sav_path, '/');
00630     *p = '/';
00631     p = q;
00632   }
00633   c = 0;
00634   while (c == 0 && (p = strchr (p + 1, '/')) && p <= lastslash) {
00635     *p = '\0';
00636     uuid_generate(uuid);
00637     uuid_unparse(uuid, uuid_buf);
00638     c = fcops.mkdirg (sav_path, uuid_buf, mode);
00639     if(c != 0) {
00640       if (*fcops.serrno < 1000)
00641         errno = *fcops.serrno;
00642       else {
00643         gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00644         errno = ECOMM;
00645       }
00646     }
00647     *p = '/';
00648   }
00649   return (c);
00650 }

int lfc_register_alias const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 495 of file lfc_ifce.c.

References fcops, gfal_errmsg(), gfal_version, lfc_init(), fc_ops::serrno, fc_ops::sstrerror, fc_ops::starttrans, and fc_ops::statg.

Referenced by register_alias().

00496 {
00497   struct lfc_filestatg statg;
00498   char master_lfn[CA_MAXPATHLEN+1];
00499   
00500   if(lfc_init(errbuf, errbufsz) < 0)
00501     return (-1);
00502 
00503   fcops.starttrans(NULL, gfal_version);
00504   if(fcops.statg(NULL, guid, &statg) < 0) {
00505     if(*fcops.serrno < 1000) 
00506       errno = *fcops.serrno;
00507     else {
00508       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00509       errno = ECOMM;
00510     }
00511     return (-1);
00512   }
00513   /* now we do a getpath() to get the master lfn */
00514   if (fcops.getpath(lfc_host, statg.fileid, master_lfn) <0 ) {
00515     if (*fcops.serrno < 1000)
00516       errno = *fcops.serrno;
00517     else {
00518       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00519       errno = ECOMM;
00520     }
00521     return (-1);
00522   }
00523 
00524   /* and finally register */
00525   if(fcops.symlink(master_lfn, lfn) < 0) {
00526     if (*fcops.serrno < 1000)
00527       errno = *fcops.serrno;
00528     else {
00529       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00530       errno = ECOMM;
00531     }
00532     return (-1);
00533   }
00534   fcops.endtrans();
00535   return (0);
00536 }

int lfc_register_pfn const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 261 of file lfc_ifce.c.

References fc_ops::addreplica, fcops, get_hostname(), gfal_errmsg(), lfc_init(), fc_ops::serrno, and fc_ops::sstrerror.

Referenced by register_pfn().

00262 {
00263   char *hostname;
00264 
00265   if(lfc_init(errbuf, errbufsz) < 0)
00266     return (-1);
00267   
00268   if((hostname = get_hostname(pfn, errbuf, errbufsz)) == NULL) {
00269     return (-1);
00270   }
00271   /* We always have available permanent files at the minute */
00272   if(fcops.addreplica(guid, NULL, hostname, pfn, '-', '\0', NULL, NULL) < 0) {
00273     if (*fcops.serrno < 1000)
00274       errno = *fcops.serrno;
00275     else {
00276       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00277       errno = ECOMM;
00278     }
00279     free(hostname);
00280     return (-1);
00281   }
00282   free(hostname);
00283   return (0);
00284 }

int lfc_replica_exists const char *  ,
char *  ,
int 
 

Definition at line 175 of file lfc_ifce.c.

References fcops, lfc_init(), and fc_ops::listreplica.

Referenced by replica_exists().

00175                                                                  {
00176   lfc_list list;
00177   struct lfc_filereplica* rp;
00178 
00179   if(lfc_init(errbuf, errbufsz) < 0)
00180     return (-1);
00181   if((rp = fcops.listreplica(NULL, guid, CNS_LIST_BEGIN, &list)) == NULL) {
00182     (void) fcops.listreplica(NULL, guid, CNS_LIST_END, &list);
00183     return (0);
00184   } else { 
00185     (void) fcops.listreplica(NULL, guid, CNS_LIST_END, &list);
00186     return (1);
00187   }
00188 }

char* lfc_surlfromguid const char *  ,
char *  ,
int 
 

Definition at line 338 of file lfc_ifce.c.

References getbestfile(), lfc_init(), and lfc_surlsfromguid().

Referenced by surlfromguid().

00339 {
00340   char **surls;
00341   char **cp;
00342   char *result;
00343   
00344   if(lfc_init(errbuf, errbufsz) < 0)
00345    return (NULL);
00346 
00347   if((surls = lfc_surlsfromguid(guid, errbuf, errbufsz)) == NULL) {
00348     return (NULL);
00349   } else if (*surls == NULL) {
00350     errno = ENOENT;
00351     return (NULL);
00352   }
00353   result = getbestfile(surls, (sizeof(surls)/sizeof(char*)), errbuf, errbufsz);
00354 
00355   for(cp = surls; *cp != NULL; ++cp) {
00356     if(*cp != result) {
00357       free (*cp);
00358     }
00359   }
00360   free (surls);
00361   return (result);
00362 }

char** lfc_surlsfromguid const char *  ,
char *  ,
int 
 

Definition at line 287 of file lfc_ifce.c.

References ALLOC_BLOCK_SIZE, fcops, lfc_init(), and fc_ops::listreplica.

Referenced by lfc_surlfromguid(), and surlsfromguid().

00288 {
00289   lfc_list list;
00290  struct lfc_filereplica* rp;
00291   int flags;
00292   char **p, **pp;
00293   size_t size = ALLOC_BLOCK_SIZE;
00294   size_t i = 0;
00295   
00296   if(lfc_init(errbuf, errbufsz) < 0)
00297     return (NULL);
00298 
00299   /* allocate some memory for the pointers */
00300   if((p = (char**)calloc(size, sizeof(char*))) == NULL) {
00301     return (NULL);
00302   }
00303 
00304   flags = CNS_LIST_BEGIN;
00305   while((rp = fcops.listreplica(NULL, guid, flags, &list)) != NULL) {
00306     if(flags == CNS_LIST_BEGIN) 
00307       flags = CNS_LIST_CONTINUE;
00308     
00309     if((p[i++] = strdup(rp->sfn)) == NULL) {
00310       (void) fcops.listreplica(NULL, guid, CNS_LIST_END, &list);
00311       free(p);
00312       return (NULL);
00313     }
00314     
00315     if(i == size) {
00316       size += ALLOC_BLOCK_SIZE;
00317       if((pp = (char**)realloc(p, size * sizeof(char*))) == NULL) {
00318         (void) fcops.listreplica(NULL, guid, CNS_LIST_END, &list);
00319         free(p);
00320         return (NULL);
00321       }
00322       p = pp;
00323     }
00324   } 
00325   (void) fcops.listreplica(NULL, guid, CNS_LIST_END, &list);
00326 
00327   /* and trim */
00328   if((pp = (char**)realloc(p, (i+1) * sizeof(char*))) == NULL) {
00329     free(p);
00330     return (NULL);
00331   }
00332   
00333   pp[i] = NULL;
00334   return (pp);
00335 }

int lfc_unregister_alias const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 539 of file lfc_ifce.c.

References fcops, gfal_errmsg(), gfal_version, lfc_init(), fc_ops::lstat, fc_ops::serrno, fc_ops::sstrerror, fc_ops::starttrans, and fc_ops::statg.

Referenced by unregister_alias().

00540 {
00541   struct lfc_filestatg statg;
00542   struct lfc_filestat stat;
00543 
00544   if(lfc_init(errbuf, errbufsz) < 0)
00545     return (-1);
00546 
00547   fcops.starttrans(NULL, gfal_version);
00548   /*  In the case of the master lfn being unlinked already, statg will
00549       return ENOENT.  We then check lstat in case it's a hanging link ?  */
00550   if(fcops.statg(lfn, guid, &statg) < 0 ) {
00551     if (*fcops.serrno == ENOENT) {
00552       if(fcops.lstat(lfn, &stat) < 0 ) {
00553         if(*fcops.serrno < 1000 ) 
00554           errno = *fcops.serrno;
00555         else {
00556           gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00557           errno = ECOMM;
00558         }
00559         return (-1);
00560       } else {
00561         /* all ok, continue */
00562       }
00563     } else {
00564       if(*fcops.serrno < 1000) 
00565         errno = *fcops.serrno;
00566       else {
00567         gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00568         errno = ECOMM;
00569       }
00570       return (-1);
00571     }
00572   }
00573 
00574   /* lfn maps to the guid - unlink it */
00575   if(fcops.unlink(lfn) < 0) {
00576     if(*fcops.serrno < 1000) 
00577       errno = *fcops.serrno;
00578     else {
00579       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00580       errno = ECOMM;
00581     }
00582     return (-1);
00583   }
00584   fcops.endtrans();
00585   return (0);
00586 }

int lfc_unregister_pfn const char *  guid,
const char *  pfn,
char *  errbuf,
int  errbufsz
 

lfc_unregister_pfn : We unregister a pfn from a guid, but only if it a replica for that guid

Definition at line 367 of file lfc_ifce.c.

References fc_ops::delreplica, fcops, gfal_errmsg(), lfc_init(), fc_ops::serrno, and fc_ops::sstrerror.

Referenced by unregister_pfn().

00368 {
00369   if(lfc_init(errbuf, errbufsz) < 0)
00370     return (-1);
00371   
00372   if(fcops.delreplica(guid, NULL, pfn) < 0) {
00373     if(*fcops.serrno == ENOENT) {
00374       return (0);
00375     }
00376     if(*fcops.serrno < 1000) 
00377       errno = *fcops.serrno;
00378     else {
00379       gfal_errmsg(errbuf, errbufsz, fcops.sstrerror(*fcops.serrno));
00380       errno = ECOMM;
00381     }
00382     return (-1);
00383   }
00384   return (0);
00385 }

char** lfnsforguid const char *  ,
char *  ,
int 
 

Definition at line 1376 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_lfnsforguid(), and rmc_lfnsforguid().

01377 {
01378         char *cat_type;
01379         if (get_cat_type (&cat_type) < 0) {
01380                 return (NULL);
01381         }
01382         if (strcmp (cat_type, "edg") == 0) {
01383                 free (cat_type);
01384                 return (rmc_lfnsforguid (guid, errbuf, errbufsz));
01385         } else if (strcmp (cat_type, "lfc") == 0) {
01386                 free (cat_type);
01387                 return (lfc_lfnsforguid (guid, errbuf, errbufsz));
01388         } else {
01389                 free (cat_type);
01390                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01391                 errno = EINVAL;
01392                 return (NULL);
01393         }
01394 }

int lrc_deletepfn const char *  ,
const char *  ,
char *  ,
int 
 

int lrc_deletesurl const char *  ,
char *  ,
int 
 

char* lrc_get_catalog_endpoint char *  ,
int 
 

Definition at line 54 of file lrc_ifce.c.

References lrc_endpoint, and lrc_init().

Referenced by get_catalog_endpoint().

00054                                                      {
00055         struct soap soap;
00056         if(lrc_init(&soap, errbuf, errbufsz) < 0)
00057                 return (NULL);
00058         return lrc_endpoint;
00059 }

int lrc_guid_exists const char *  ,
char *  ,
int 
 

Definition at line 136 of file lrc_ifce.c.

References gfal_errmsg(), lrc_endpoint, and lrc_init().

Referenced by guid_exists().

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 }

char* lrc_guidforpfn const char *  ,
char *  ,
int 
 

Definition at line 101 of file lrc_ifce.c.

References gfal_errmsg(), lrc_endpoint, and lrc_init().

Referenced by guidforpfn().

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 }

int lrc_replica_exists const char *  ,
char *  ,
int 
 

Definition at line 62 of file lrc_ifce.c.

References gfal_errmsg(), lrc_endpoint, and lrc_init().

Referenced by replica_exists().

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 }

int lrc_setfilesize const char *  ,
GFAL_LONG64  ,
char *  ,
int 
 

Definition at line 194 of file lrc_ifce.c.

References gfal_errmsg(), GFAL_LONG64_FORMAT, lrc_endpoint, and lrc_init().

Referenced by setfilesize().

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 }

char* lrc_surlfromguid const char *  ,
char *  ,
int 
 

Definition at line 230 of file lrc_ifce.c.

References getbestfile(), gfal_errmsg(), lrc_endpoint, and lrc_init().

Referenced by surlfromguid().

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 }

char** lrc_surlsfromguid const char *  ,
char *  ,
int 
 

Definition at line 277 of file lrc_ifce.c.

References gfal_errmsg(), lrc_endpoint, and lrc_init().

Referenced by surlsfromguid().

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 }

int parsesurl const char *  ,
char *  ,
int  ,
char **  ,
char *  ,
int 
 

Definition at line 833 of file gfal.c.

References gfal_errmsg().

Referenced by se_init(), and srm_init().

00835 {
00836         int len;
00837         int len1;
00838         int lenp;
00839         char *p;
00840         char *p1, *p2;
00841         char *se_endpoint;
00842         int se_port;
00843 
00844         if (strncmp (surl, "srm://", 6)) {
00845                 gfal_errmsg(errbuf, errbufsz, "Source URL doesn't start with \"srm://\".");
00846                 errno = EINVAL;
00847                 return (-1);
00848         }
00849         if (p = strstr (surl + 6, "?SFN=")) {
00850                 *sfn = p + 5;
00851                 for (p1 = (char *)surl + 6; p1 < p; p1++)
00852                         if (*p1 == '/') break;
00853         } else if (p = strchr (surl + 6, '/')) {
00854                 *sfn = p;
00855                 p1 = p;
00856         } else {
00857                 gfal_errmsg(errbuf, errbufsz, "Bad Source URL syntax.");
00858                 errno = EINVAL;
00859                 return (-1);
00860         }
00861 #ifdef GFAL_SECURE
00862         strcpy (endpoint, "https://");
00863         lenp = 8;
00864 #else
00865         strcpy (endpoint, "http://");
00866         lenp = 7;
00867 #endif
00868         /* copy hostname */
00869 
00870         len = p1 - surl - 6;
00871         if (lenp + len >= srm_endpointsz) {
00872                 gfal_errmsg(errbuf, errbufsz, "Source URL too long.");
00873                 errno = ENAMETOOLONG;
00874                 return (-1);
00875         }
00876         strncpy (endpoint + lenp, surl + 6, len);
00877         *(endpoint + lenp + len) = '\0';
00878 
00879         if (p1 == p) {  /* no user specified endpoint */
00880 
00881                 /* try to get endpoint from Information Service */
00882 
00883                 if ((p2 = strchr (endpoint + lenp, ':')))
00884                         *p2 = '\0';
00885                 if (get_se_endpoint (endpoint + lenp, &se_endpoint) == 0) {
00886                         strcpy (endpoint, se_endpoint);
00887                         free (se_endpoint);
00888                         return (0);
00889                 } else
00890                         if (p2)
00891                                 *p2 = ':';
00892         }
00893 
00894         /* set port number if not specified by user */
00895 
00896         if ((p2 = strchr (endpoint + lenp, ':')) == NULL) {     /* no port specified */
00897                 if (get_se_port (endpoint + lenp, &se_port) < 0)
00898                         se_port = SRM_PORT;
00899                 if (lenp + len + 6 >= srm_endpointsz) {
00900                         gfal_errmsg(errbuf, errbufsz, "Source URL too long");
00901                         errno = ENAMETOOLONG;
00902                         return (-1);
00903                 }
00904                 len1 = sprintf (endpoint + lenp + len, ":%d", se_port);
00905         } else
00906                 len1 = 0;
00907         len1 += lenp + len;
00908 
00909         /* copy endpoint */
00910 
00911         if (p1 != p) {  /* user specified endpoint */
00912                 if (len1 + (p - p1) >= srm_endpointsz) {
00913                         gfal_errmsg(errbuf, errbufsz, "Source URL too long.");
00914                         errno = ENAMETOOLONG;
00915                         return (-1);
00916                 }
00917                 strncpy (endpoint + len1, p1, p - p1);
00918                 *(endpoint + len1 + (p - p1)) = '\0';
00919         } else {
00920                 if (len1 + strlen (SRM_EP_PATH) >= srm_endpointsz) {
00921                         gfal_errmsg(errbuf, errbufsz, "Source URL too long.");
00922                         errno = ENAMETOOLONG;
00923                         return (-1);
00924                 }
00925                 strcpy (endpoint + len1, SRM_EP_PATH);
00926         }
00927         return (0);
00928 }

int parseturl const char *  ,
char *  ,
int  ,
char *  ,
int  ,
char **  ,
char *  ,
int 
 

Definition at line 930 of file gfal.c.

References gfal_errmsg().

Referenced by deletepfn(), gfal_access(), gfal_chmod(), gfal_lstat(), gfal_lstat64(), gfal_mkdir(), gfal_open(), gfal_opendir(), gfal_rename(), gfal_rmdir(), gfal_stat(), and gfal_stat64().

00931 {
00932         int len;
00933         char *p;
00934 
00935         /* get protocol */
00936 
00937         if ((p = strstr (turl, ":/")) == NULL) {
00938                 gfal_errmsg(errbuf, errbufsz, "Bad destination URL syntax.");
00939                 errno = EINVAL;
00940                 return (-1);
00941         }
00942         if ((len = p - turl) > (protocolsz - 1)) {
00943                 gfal_errmsg(errbuf, errbufsz, "Destination URL too long.");
00944                 errno = ENAMETOOLONG;
00945                 return (-1);
00946         }
00947         strncpy (protocol, turl, len);
00948         *(protocol + len) = '\0';
00949 
00950         if (strcmp (protocol, "file") == 0) {
00951                 *pfn = p + 1;
00952         } else if (strcmp (protocol, "rfio") == 0) {
00953                 p += 2;
00954                 if (*p != '/') {
00955                         gfal_errmsg(errbuf, errbufsz, "Bad destination URL syntax.");
00956                         errno = EINVAL;
00957                         return (-1);
00958                 }
00959                 p++;
00960                 if (*p == '/' && *(p + 1) == '/') {     /* no hostname */
00961                         *pfn = p + 1;
00962                 } else {
00963                         if (strlen (p) > pathbufsz) {
00964                                 gfal_errmsg(errbuf, errbufsz, "Destination URL too long.");
00965                                 errno = ENAMETOOLONG;
00966                                 return (-1);
00967                         }
00968                         strcpy (pathbuf, p);
00969                         if (p = strstr (pathbuf, "//"))
00970                                 *p = ':';
00971                         *pfn = pathbuf;
00972                 }
00973         } else 
00974                 *pfn = (char *) turl;
00975         return (0);
00976 }

int register_alias const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 1438 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_register_alias(), and rmc_register_alias().

01439 {
01440         char *cat_type;
01441         if (get_cat_type (&cat_type) < 0) {
01442                 return (-1);
01443         }
01444         if (strcmp (cat_type, "edg") == 0) {
01445                 free (cat_type);
01446                 return (rmc_register_alias (guid, lfn, errbuf, errbufsz));
01447         } else if (strcmp (cat_type, "lfc") == 0) {
01448                 free (cat_type);
01449                 return (lfc_register_alias (guid, lfn, errbuf, errbufsz));
01450         } else {
01451                 free (cat_type);
01452                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01453                 errno = EINVAL;
01454                 return (-1);
01455         }
01456 }

int register_pfn const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 1251 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_register_pfn(), and lrc_register_pfn().

01252 {
01253         char *cat_type;
01254         if (get_cat_type (&cat_type) < 0) {
01255                 return (-1);
01256         }
01257         if (strcmp (cat_type, "edg") == 0) {
01258                 free (cat_type);
01259                 return (lrc_register_pfn (guid, pfn, errbuf, errbufsz));
01260         } else if (strcmp (cat_type, "lfc") == 0) {
01261                 free (cat_type);
01262                 return (lfc_register_pfn (guid, pfn, errbuf, errbufsz));
01263         } else {
01264                 free (cat_type);
01265                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01266                 errno = EINVAL;
01267                 return (-1);
01268         }
01269 }

int replica_exists const char *  ,
char *  ,
int 
 

Definition at line 1397 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_replica_exists(), and lrc_replica_exists().

01398 {
01399         char *cat_type;
01400         if (get_cat_type (&cat_type) < 0) {
01401                 return (-1);
01402         }
01403         if (strcmp (cat_type, "edg") == 0) {
01404                 free (cat_type);
01405                 return (lrc_replica_exists (guid, errbuf, errbufsz));
01406         } else if (strcmp (cat_type, "lfc") == 0) {
01407                 free (cat_type);
01408                 return (lfc_replica_exists (guid, errbuf, errbufsz));
01409         } else {
01410                 free (cat_type);
01411                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01412                 errno = EINVAL;
01413                 return (-1);
01414         }
01415 }

char* rmc_guidfromlfn const char *  ,
char *  ,
int 
 

Definition at line 52 of file rmc_ifce.c.

References gfal_errmsg(), rmc_endpoint, and rmc_init().

Referenced by guidfromlfn().

00053 {
00054         struct ns3__guidForAliasResponse out;
00055         char *p;
00056         int ret;
00057         int sav_errno;
00058         struct soap soap;
00059 
00060         if (rmc_init (&soap, errbuf, errbufsz) < 0)
00061                 return (NULL);
00062 
00063         if (ret = soap_call_ns3__guidForAlias (&soap, rmc_endpoint, "",
00064             (char *) lfn, &out)) {
00065                 if (ret == SOAP_FAULT) {
00066                         if (strstr (soap.fault->faultcode, "NOSUCHALIAS"))
00067                                 sav_errno = ENOENT;
00068                         else {
00069                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00070                                 sav_errno = ECOMM;
00071                         }
00072                 } else {
00073                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00074                         sav_errno = ECOMM;
00075                 }
00076                 soap_end (&soap);
00077                 soap_done (&soap);
00078                 errno = sav_errno;
00079                 return (NULL);
00080         } else {
00081                 p = strdup (out._guidForAliasReturn);
00082                 soap_end (&soap);
00083                 soap_done (&soap);
00084                 return (p);
00085         }
00086 }

char** rmc_lfnsforguid const char *  ,
char *  ,
int 
 

Definition at line 89 of file rmc_ifce.c.

References gfal_errmsg(), rmc_endpoint, and rmc_init().

Referenced by lfnsforguid().

00090 {
00091         int i;
00092         int j;
00093         char **lfnarray;
00094         struct ns3__getAliasesResponse out;
00095         char *p;
00096         int ret;
00097         int sav_errno;
00098         struct soap soap;
00099 
00100         if (rmc_init (&soap, errbuf, errbufsz) < 0)
00101                 return (NULL);
00102 
00103         if (ret = soap_call_ns3__getAliases (&soap, rmc_endpoint, "",
00104             (char *) guid, &out)) {
00105                 if (ret == SOAP_FAULT) {
00106                         if (strstr (soap.fault->faultcode, "NOSUCHGUID"))
00107                                 sav_errno = ENOENT;
00108                         else {
00109                           gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00110                                 sav_errno = ECOMM;
00111                         }
00112                 } else {
00113                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00114                         sav_errno = ECOMM;
00115                 }
00116                 soap_end (&soap);
00117                 soap_done (&soap);
00118                 errno = sav_errno;
00119                 return (NULL);
00120         }
00121         if ((lfnarray = calloc (out._getAliasesReturn->__size + 1, sizeof(char *))) == NULL) 
00122                 return (NULL);
00123         for (i = 0; i < out._getAliasesReturn->__size; i++) {
00124                 if ((lfnarray[i] = strdup (out._getAliasesReturn->__ptr[i])) == NULL) {
00125                         for (j = 0; j < i; j++)
00126                                 free (lfnarray[j]);
00127                         free (lfnarray);
00128                         return (NULL); 
00129                 }
00130         }
00131         soap_end (&soap);
00132         soap_done (&soap);
00133         return (lfnarray);
00134 }

int rmc_register_alias const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 141 of file rmc_ifce.c.

References gfal_errmsg(), rmc_endpoint, and rmc_init().

Referenced by create_alias(), register_alias(), and rmc_create_alias().

00142 {
00143         struct ns3__addAliasResponse out;
00144         int ret;
00145         int sav_errno;
00146         struct soap soap;
00147 
00148         if (rmc_init (&soap, errbuf, errbufsz) < 0)
00149                 return (-1);
00150 
00151         if (ret = soap_call_ns3__addAlias (&soap, rmc_endpoint, "",
00152             (char *) guid, (char *) lfn, &out)) {
00153                 if (ret == SOAP_FAULT) {
00154                         if (strstr (soap.fault->faultcode, "ALIASEXISTS"))
00155                                 sav_errno = EEXIST;
00156                         else if (strstr (soap.fault->faultcode, "VALUETOOLONG"))
00157                                 sav_errno = ENAMETOOLONG;
00158                         else {
00159                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00160                                 sav_errno = ECOMM;
00161                         }
00162                 } else {
00163                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00164                         sav_errno = ECOMM;
00165                 }
00166                 soap_end (&soap);
00167                 soap_done (&soap);
00168                 errno = sav_errno;
00169                 return (-1);
00170         }
00171         soap_end (&soap);
00172         soap_done (&soap);
00173         return (0);
00174 }

int rmc_register_pfn const char *  ,
const char *  ,
char *  ,
int 
 

int rmc_unregister_alias const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 176 of file rmc_ifce.c.

References gfal_errmsg(), rmc_endpoint, and rmc_init().

Referenced by unregister_alias().

00177 {
00178         struct ns3__removeAliasResponse out;
00179         int ret;
00180         struct soap soap;
00181 
00182         if (rmc_init (&soap, errbuf, errbufsz) < 0)
00183                 return (-1);
00184 
00185         if (ret = soap_call_ns3__removeAlias (&soap, rmc_endpoint, "",
00186             (char *) guid, (char *) lfn, &out)) {
00187                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00188                 soap_end (&soap);
00189                 soap_done (&soap);
00190                 errno = ECOMM;
00191                 return (-1);
00192         }
00193         soap_end (&soap);
00194         soap_done (&soap);
00195         return (0);
00196 }

int rmc_unregister_pfn const char *  ,
const char *  ,
char *  ,
int 
 

int se_deletesurl const char *  ,
char *  ,
int  ,
int 
 

Definition at line 47 of file se_ifce.c.

References gfal_errmsg(), and se_init().

Referenced by deletesurl().

00048 {
00049         struct ns1__deleteResponse out;
00050         struct soap soap;
00051         char srm_endpoint[256];
00052 
00053         if (se_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00054             errbuf, errbufsz) < 0)
00055                 return (-1);
00056         soap.send_timeout = timeout ;
00057         soap.recv_timeout = timeout ;
00058 
00059         /* issue "delete" request */
00060 
00061         if (soap_call_ns1__delete (&soap, srm_endpoint,
00062             "delete", (char *)surl + 6, &out)) {
00063                 if (soap.error == SOAP_EOF) {
00064                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00065                         soap_end (&soap);
00066                         soap_done (&soap);
00067                         return (-1);
00068                 }
00069                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00070                 soap_end (&soap);
00071                 soap_done (&soap);
00072                 return (-1);
00073         }
00074         soap_end (&soap);
00075         soap_done (&soap);
00076         return (0);
00077 }

int se_getfilemd const char *  ,
struct stat64 *  ,
char *  ,
int  ,
int 
 

Definition at line 277 of file se_ifce.c.

References gfal_errmsg(), and se_init().

Referenced by getfilemd(), and se_makedirp().

00278 {
00279         char *dp;
00280         struct group *gr;
00281         int i;
00282         struct ns1__getMetadataResponse out;
00283         char *p;
00284         struct passwd *pw;
00285         char *q;
00286         int ret;
00287         int sav_errno;
00288         struct soap soap;
00289         char srm_endpoint[256];
00290 
00291         if (se_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00292             errbuf, errbufsz) < 0)
00293                 return (-1);
00294         soap.send_timeout = timeout;
00295         soap.recv_timeout = timeout;
00296 
00297         /* issue "getMetadata" request */
00298 
00299         if ((ret = soap_call_ns1__getMetadata (&soap, srm_endpoint,
00300             "getMetadata", (char *)surl + 6, &out))) {
00301                 if (soap.error == SOAP_EOF) {
00302                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00303                         soap_end (&soap);
00304                         soap_done (&soap);
00305                         return (-1);
00306                 }
00307 
00308                 if (ret == SOAP_FAULT || ret == SOAP_CLI_FAULT) {
00309                         if (strstr (soap.fault->faultstring, "does not exist"))
00310                                 sav_errno = ENOENT;
00311                         else if (strstr (soap.fault->faultstring, "expired")) {
00312                                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00313                                 sav_errno = EACCES;
00314                         } else
00315                                 sav_errno = ECOMM;
00316                 } else
00317                         sav_errno = ECOMM;
00318                 if (sav_errno == ECOMM)
00319                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00320                 soap_end (&soap);
00321                 soap_done (&soap);
00322                 errno = sav_errno;
00323                 return (-1);
00324         }
00325         memset (statbuf, 0, sizeof(struct stat64));
00326         statbuf->st_nlink = 1;
00327         statbuf->st_uid = 2;
00328         statbuf->st_gid = 2;
00329         for (i = 0; i < out._getMetadataReturn->__size; i++) {
00330                 p = out._getMetadataReturn->__ptr[i];
00331                 if ((q = strchr (p, ':'))) {
00332                         *q = '\0';
00333                         if (strcmp (p, "filesize") == 0)
00334                                 statbuf->st_size = strtoll (q + 1, &dp, 10);
00335                         else if (strcmp (p, "atime") == 0)
00336                                 statbuf->st_atime = strtol (q + 1, &dp, 10);
00337                         else if (strcmp (p, "mtime") == 0)
00338                                 statbuf->st_mtime = strtol (q + 1, &dp, 10);
00339                         else if (strcmp (p, "ctime") == 0)
00340                                 statbuf->st_ctime = strtol (q + 1, &dp, 10);
00341                 }
00342         }
00343         soap_end (&soap);
00344         soap_done (&soap);
00345         return (0);
00346 }

int se_set_xfer_done const char *  ,
int  ,
int  ,
char *  ,
int  ,
char *  ,
int  ,
int 
 

Definition at line 348 of file se_ifce.c.

References gfal_errmsg(), and se_init().

Referenced by set_xfer_done().

00350 {
00351         struct ns1__abandonResponse outa;
00352         struct ns1__commitResponse outc;
00353         struct soap soap;
00354         char srm_endpoint[256];
00355 
00356         if (se_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00357             errbuf, errbufsz) < 0)
00358                 return (-1);
00359         soap.send_timeout = timeout ;
00360         soap.recv_timeout = timeout ;
00361 
00362 
00363         if ((oflag & O_ACCMODE) == 0) {
00364 /*              not implemented yet 
00365                 if (soap_call_ns1__abandon (&soap, srm_endpoint,
00366                     "abandon", token, &outa)) {
00367                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00368                         soap_end (&soap);
00369                         soap_done (&soap);
00370                         return (-1);
00371                 }
00372 */
00373         } else {
00374                 if (soap_call_ns1__commit (&soap, srm_endpoint,
00375                     "commit", token, &outc)) {
00376                        if (soap.error == SOAP_EOF) {
00377                                 gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00378                                 soap_end (&soap);
00379                                 soap_done (&soap);
00380                                 return (-1);
00381                         }
00382                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00383                         soap_end (&soap);
00384                         soap_done (&soap);
00385                         return (-1);
00386                 }
00387         }
00388         soap_end (&soap);
00389         soap_done (&soap);
00390         return (0);
00391 }

int se_set_xfer_running const char *  ,
int  ,
int  ,
char *  ,
char *  ,
int 
 

Definition at line 393 of file se_ifce.c.

Referenced by set_xfer_running().

00395 {
00396         return (0);
00397 }

char* se_turlfromsurl const char *  ,
char **  ,
int  ,
int *  ,
int *  ,
char **  ,
char *  ,
int  ,
int 
 

Definition at line 165 of file se_ifce.c.

References gfal_errmsg(), se_init(), and se_makedirp().

Referenced by turlfromsurlx().

00167 {
00168         int nbproto = 0;
00169         struct ns1__cacheResponse outg;
00170         struct ns1__createResponse outp;
00171         struct ns1__getTurlResponse outq;
00172         char *p;
00173         struct ArrayOf_USCORExsd_USCOREstring protoarray;
00174         int ret;
00175         int sav_errno;
00176         struct soap soap;
00177         char srm_endpoint[256];
00178         LONG64 zero = 0;
00179 
00180         if (se_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00181             errbuf, errbufsz) < 0)
00182                 return (NULL);
00183         soap.send_timeout = timeout ;
00184         soap.recv_timeout = timeout ;
00185 
00186         while (*protocols[nbproto]) nbproto++;
00187 
00188         /* issue "cache" or the "create" request */
00189 
00190         protoarray.__ptr = protocols;
00191         protoarray.__size = nbproto;
00192 
00193         if ((oflag & O_ACCMODE) == 0) {
00194                 if ((ret = soap_call_ns1__cache (&soap, srm_endpoint, "cache",
00195                     (char *)surl + 6, "read", 36000, &outg))) {
00196                         if (soap.error == SOAP_EOF) {
00197                                 gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00198                                 soap_end (&soap);
00199                                 soap_done (&soap);
00200                                 return (NULL);
00201                         }
00202 
00203                         if (ret == SOAP_FAULT || ret == SOAP_CLI_FAULT) {
00204                                 if (strstr (soap.fault->faultstring, "STFN not found"))
00205                                         sav_errno = ENOENT;
00206                                 else
00207                                         sav_errno = ECOMM;
00208                         } else
00209                                 sav_errno = ECOMM;
00210                         if (errno == ECOMM)
00211                                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00212                         soap_end (&soap);
00213                         soap_done (&soap);
00214                         errno = sav_errno;
00215                         return (NULL);
00216                 }
00217                 if ((*token = strdup (outg._cacheReturn)) == NULL) {
00218                         soap_end (&soap);
00219                         soap_done (&soap);
00220                         return (NULL);
00221                 }
00222         } else {
00223 retry:
00224                 if ((ret = soap_call_ns1__create (&soap, srm_endpoint, "create",
00225                     (char *)surl + 6, zero, "x", 36000, &outp))) {
00226                         if (soap.error == SOAP_EOF) {
00227                                 gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00228                                 soap_end (&soap);
00229                                 soap_done (&soap);
00230                                 return (NULL);
00231                         }
00232                         if (ret == SOAP_FAULT || ret == SOAP_CLI_FAULT) {
00233                                 if (strstr (soap.fault->faultstring, "o such file"))
00234                                         sav_errno = ENOENT;
00235                                         if (se_makedirp (surl, errbuf, errbufsz, timeout) == 0)
00236                                                 goto retry;
00237                                 else if (strstr (soap.fault->faultstring, "File exists"))
00238                                         sav_errno = EEXIST;
00239                                 else
00240                                         sav_errno = ECOMM;
00241                         } else
00242                                 sav_errno = ECOMM;
00243                         if (errno == ECOMM)
00244                                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00245                         soap_end (&soap);
00246                         soap_done (&soap);
00247                         errno = sav_errno;
00248                         return (NULL);
00249                 }
00250                 if ((*token = strdup (outp._createReturn)) == NULL) {
00251                         soap_end (&soap);
00252                         soap_done (&soap);
00253                         return (NULL);
00254                 }
00255         }
00256         if (soap_call_ns1__getTurl (&soap, srm_endpoint, "getTurl", *token,
00257             &protoarray, &outq)) {
00258                 if (soap.error == SOAP_EOF) {
00259                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00260                         soap_end (&soap);
00261                         soap_done (&soap);
00262                         return (NULL);
00263                 }
00264                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00265                 soap_end (&soap);
00266                 soap_done (&soap);
00267                 return (NULL);
00268         }
00269         *reqid = 0;
00270         *fileid = 0;
00271         p = strdup (outq._getTurlReturn);
00272         soap_end (&soap);
00273         soap_done (&soap);
00274         return (p);
00275 }

int set_xfer_done const char *  ,
int  ,
int  ,
char *  ,
int  ,
char *  ,
int  ,
int 
 

Definition at line 978 of file gfal.c.

References gfal_errmsg(), se_set_xfer_done(), setypefromsurl(), and srm_set_xfer_done().

Referenced by gfal_close().

00980 {
00981         char *se_type;
00982 
00983         if (setypefromsurl (surl, &se_type, errbuf, errbufsz) < 0)
00984                 return (-1);
00985         if (strcmp (se_type, "srm_v1") == 0) {
00986                 free (se_type);
00987                 return (srm_set_xfer_done (surl, reqid, fileid, token, oflag,
00988                     errbuf, errbufsz, timeout));
00989         } else if (strcmp (se_type, "edg-se") == 0) {
00990                 free (se_type);
00991                 return (se_set_xfer_done (surl, reqid, fileid, token, oflag,
00992                     errbuf, errbufsz, timeout));
00993         } else {
00994                 free (se_type);
00995                 gfal_errmsg(errbuf, errbufsz, "The Storage Element type is neither 'srm_v1' nor 'edg-se'.");
00996                 errno = EINVAL;
00997                 return (-1);
00998         }
00999 }

int set_xfer_running const char *  ,
int  ,
int  ,
char *  ,
char *  ,
int  ,
int 
 

Definition at line 1001 of file gfal.c.

References gfal_errmsg(), se_set_xfer_running(), setypefromsurl(), and srm_set_xfer_running().

Referenced by gfal_open().

01003 {
01004         char *se_type;
01005 
01006         if (setypefromsurl (surl, &se_type, errbuf, errbufsz) < 0)
01007                 return (-1);
01008         if (strcmp (se_type, "srm_v1") == 0) {
01009                 free (se_type);
01010                 return (srm_set_xfer_running (surl, reqid, fileid, token,
01011                     errbuf, errbufsz, timeout));
01012         } else if (strcmp (se_type, "edg-se") == 0) {
01013                 free (se_type);
01014                 return (se_set_xfer_running (surl, reqid, fileid, token,
01015                     errbuf, errbufsz));
01016         } else {
01017                 free (se_type);
01018                 gfal_errmsg(errbuf, errbufsz, "The Storage Element type is neither 'srm_v1' nor 'edg-se'.");
01019                 errno = EINVAL;
01020                 return (-1);
01021         }
01022 }

int setfilesize const char *  ,
GFAL_LONG64  ,
char *  ,
int 
 

Definition at line 1271 of file gfal.c.

References get_cat_type(), gfal_errmsg(), and lrc_setfilesize().

01272 {
01273         char *cat_type;
01274         if (get_cat_type (&cat_type) < 0) {
01275                 return (-1);
01276         }
01277         if (strcmp (cat_type, "edg") == 0) {
01278                 free (cat_type);
01279                 return (lrc_setfilesize (pfn, filesize, errbuf, errbufsz));
01280         } else if (strcmp (cat_type, "lfc") == 0) {
01281                 free (cat_type);
01282                 gfal_errmsg(errbuf, errbufsz, "The LFC catalog doesn't support the setfilesize() method.");
01283                 errno = EINVAL;
01284         } else {
01285                 free (cat_type);
01286                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01287                 errno = EINVAL;
01288                 return (-1);
01289         }
01290 }

int setypefromsurl const char *  ,
char **  ,
char *  ,
int 
 

Definition at line 1024 of file gfal.c.

References get_se_typex(), and gfal_errmsg().

Referenced by deletesurl(), getfilemd(), set_xfer_done(), set_xfer_running(), and turlfromsurlx().

01026 {
01027         int len;
01028         char *p;
01029         char server[256];
01030 
01031         if ((p = strchr (surl + 6, '/')) == NULL) {
01032                 gfal_errmsg(errbuf, errbufsz, "Bad source URL syntax.");
01033                 errno = EINVAL;
01034                 return (-1);
01035         }
01036         if ((len = p - surl - 6) >= sizeof(server)) {
01037                 gfal_errmsg(errbuf, errbufsz, "Host name too long.");
01038                 errno = ENAMETOOLONG;
01039                 return (-1);
01040         }
01041         strncpy (server, surl + 6, len);
01042         server[len] = '\0';
01043         if ((p = strchr (server, ':'))) *p = '\0';
01044         return (get_se_typex (server, se_type, errbuf, errbufsz));
01045 }

int srm_deletesurl const char *  ,
char *  ,
int  ,
int 
 

Definition at line 43 of file srm_ifce.c.

References gfal_errmsg(), and srm_init().

Referenced by deletesurl().

00044 {
00045         struct ns5__advisoryDeleteResponse out;
00046         int ret;
00047         struct soap soap;
00048         char srm_endpoint[256];
00049         struct ArrayOfstring surlarray;
00050 
00051 
00052         if (srm_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00053             errbuf, errbufsz) < 0)
00054                 return (-1);
00055         soap.send_timeout = timeout ;
00056         soap.recv_timeout = timeout ;
00057 
00058 
00059         /* issue "advisoryDelete" request */
00060 
00061         surlarray.__ptr = (char **)&surl;
00062         surlarray.__size = 1;
00063 
00064         if (ret = soap_call_ns5__advisoryDelete (&soap, srm_endpoint,
00065             "advisoryDelete", &surlarray, &out)) {
00066                 if (soap.error == SOAP_EOF) {
00067                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00068                         soap_end (&soap);
00069                         soap_done (&soap);
00070                         return (-1);
00071                 }
00072                 if(ret == SOAP_FAULT || ret == SOAP_CLI_FAULT)
00073                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00074                 soap_end (&soap);
00075                 soap_done (&soap);
00076                 return (-1);
00077         }
00078         soap_end (&soap);
00079         soap_done (&soap);
00080         return (0);
00081 }

int srm_get int  ,
char **  ,
int  ,
char **  ,
int *  ,
char **  ,
struct srm_filestatus **  ,
int 
 

Definition at line 83 of file srm_ifce.c.

References srm_getx().

Referenced by main().

00085 {
00086         return (srm_getx (nbfiles, surls, nbprotocols, protocols, reqid, token,
00087                           filestatuses, NULL, 0, timeout));
00088 }

int srm_getfilemd const char *  ,
struct stat64 *  ,
char *  ,
int  ,
int 
 

Definition at line 445 of file srm_ifce.c.

References gfal_errmsg(), and srm_init().

Referenced by getfilemd().

00446 {
00447         struct group *gr;
00448         struct ns5__getFileMetaDataResponse out;
00449         struct passwd *pw;
00450         int ret;
00451         int sav_errno;
00452         struct soap soap;
00453         char srm_endpoint[256];
00454         struct ArrayOfstring surlarray;
00455 
00456         if (srm_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00457             errbuf, errbufsz) < 0)
00458                 return (-1);
00459         soap.send_timeout = timeout ;
00460         soap.recv_timeout = timeout ;
00461 
00462 
00463         /* issue "getFileMetaData" request */
00464 
00465         surlarray.__ptr = (char **)&surl;
00466         surlarray.__size = 1;
00467 
00468         if ((ret = soap_call_ns5__getFileMetaData (&soap, srm_endpoint,
00469             "getFileMetaData", &surlarray, &out))) {
00470                 if (soap.error == SOAP_EOF) {
00471                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00472                         soap_end (&soap);
00473                         soap_done (&soap);
00474                         return (-1);
00475                 }
00476                 if (ret == SOAP_FAULT || ret == SOAP_CLI_FAULT) {
00477                         if (strstr (soap.fault->faultstring, "No such file") ||
00478                             strstr (soap.fault->faultstring, "could not get storage info by path"))
00479                                 sav_errno = ENOENT;
00480                         else {
00481                                 sav_errno = ECOMM;
00482                                 gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00483                         }                               
00484                 } else {
00485                         sav_errno = ECOMM;
00486                         gfal_errmsg(errbuf, errbufsz, "Error calling getFileMetaData on SRM, but no error message returned");
00487                 }
00488                 soap_end (&soap);
00489                 soap_done (&soap);
00490                 errno = sav_errno;
00491                 return (-1);
00492         }
00493         if (out._Result->__size == 0 || out._Result->__ptr[0]->SURL == NULL) {
00494                 soap_end (&soap);
00495                 soap_done (&soap);
00496                 errno = ENOENT;
00497                 return (-1);
00498         }
00499         memset (statbuf, 0, sizeof(struct stat64));
00500         statbuf->st_mode = out._Result->__ptr[0]->permMode;
00501         if ((statbuf->st_mode & S_IFMT) == 0)
00502                 statbuf->st_mode |= S_IFREG;
00503         statbuf->st_nlink = 1;
00504         if (out._Result->__ptr[0]->owner && (pw = getpwnam (out._Result->__ptr[0]->owner)))
00505                 statbuf->st_uid = pw->pw_uid;
00506         else
00507                 statbuf->st_uid = 2;
00508         if (out._Result->__ptr[0]->group && (gr = getgrnam (out._Result->__ptr[0]->group)))
00509                 statbuf->st_gid = gr->gr_gid;
00510         else
00511                 statbuf->st_gid = 2;
00512         statbuf->st_size = out._Result->__ptr[0]->size;
00513         soap_end (&soap);
00514         soap_done (&soap);
00515         return (0);
00516 }

int srm_getstatus int  ,
char **  ,
int  ,
char *  ,
struct srm_filestatus **  ,
int 
 

Definition at line 176 of file srm_ifce.c.

References srm_getstatusx().

Referenced by main().

00178 {
00179         return (srm_getstatusx (nbfiles, surls, reqid, token, filestatuses,
00180             NULL, 0, timeout));
00181 }

int srm_getstatusx int  ,
char **  ,
int  ,
char *  ,
struct srm_filestatus **  ,
char *  ,
int  ,
int 
 

Definition at line 183 of file srm_ifce.c.

References gfal_errmsg(), srm_init(), srm_filestatus::status, and srm_filestatus::surl.

Referenced by srm_getstatus().

00185 {
00186         int errflag = 0;
00187         struct ns1__RequestFileStatus *f;
00188         struct srm_filestatus *fs;
00189         int i;
00190         int n;
00191         struct ns5__getRequestStatusResponse outq;
00192         char *p;
00193         struct ns1__RequestStatus *reqstatp;
00194         int ret;
00195         int sav_errno;
00196         struct soap soap;
00197         char srm_endpoint[256];
00198         struct ArrayOfstring surlarray;
00199 
00200         if (srm_init (&soap, surls[0], srm_endpoint, sizeof(srm_endpoint),
00201             errbuf, errbufsz) < 0)
00202                 return (-1);
00203         soap.send_timeout = timeout;
00204         soap.recv_timeout = timeout;
00205 
00206 
00207         if (ret = soap_call_ns5__getRequestStatus (&soap, srm_endpoint,
00208             "getRequestStatus", reqid, &outq)) {
00209                 if (soap.error == SOAP_EOF) {
00210                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00211                         soap_end (&soap);
00212                         soap_done (&soap);
00213                         return (-1);
00214                 }
00215                 if(ret == SOAP_FAULT || ret == SOAP_CLI_FAULT)
00216                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00217                 soap_end (&soap);
00218                 soap_done (&soap);
00219                 return (-1);
00220         }
00221         reqstatp = outq._Result;
00222         n = reqstatp->fileStatuses->__size;
00223         if ((*filestatuses = calloc (n, sizeof(struct srm_filestatus))) == NULL) {
00224                 soap_end (&soap);
00225                 soap_done (&soap);
00226                 errno = ENOMEM;
00227                 return (-1);
00228         }
00229         fs = *filestatuses;
00230         for (i = 0; i < n; i++) {
00231                 f = reqstatp->fileStatuses->__ptr[i];
00232                 if (f->SURL && (fs->surl = strdup (f->SURL)) == NULL)
00233                         errflag++;
00234                 if (f->state) {
00235                         if (strcmp (f->state, "Pending") == 0 ||
00236                             strcmp (f->state, "pending") == 0)
00237                                 fs->status = 0;
00238                         else if (strcmp (f->state, "Failed") == 0 ||
00239                             strcmp (f->state, "failed") == 0)
00240                                 fs->status = -1;
00241                         else
00242                                 fs->status = 1;
00243                 }
00244                 fs->fileid = f->fileId;
00245                 if (f->TURL && (fs->turl = strdup (f->TURL)) == NULL)
00246                         errflag++;
00247                 fs++;
00248         }
00249         soap_end (&soap);
00250         soap_done (&soap);
00251         return (n);
00252 }

int srm_getx int  ,
char **  ,
int  ,
char **  ,
int *  ,
char **  ,
struct srm_filestatus **  ,
char *  ,
int  ,
int 
 

Definition at line 90 of file srm_ifce.c.

References gfal_errmsg(), srm_init(), srm_filestatus::status, and srm_filestatus::surl.

Referenced by srm_get().

00093 {
00094         int errflag = 0;
00095         struct ns1__RequestFileStatus *f;
00096         struct srm_filestatus *fs;
00097         int i;
00098         int n;
00099         struct ns5__getResponse outg;
00100         char *p;
00101         struct ArrayOfstring protoarray;
00102         struct ns1__RequestStatus *reqstatp;
00103         int ret;
00104         int sav_errno;
00105         struct soap soap;
00106         char srm_endpoint[256];
00107         struct ArrayOfstring surlarray;
00108 
00109         if (srm_init (&soap, surls[0], srm_endpoint, sizeof(srm_endpoint),
00110             errbuf, errbufsz) < 0)
00111                 return (-1);
00112         soap.send_timeout = timeout ;
00113         soap.recv_timeout = timeout ;
00114 
00115         surlarray.__ptr = (char **)surls;
00116         surlarray.__size = nbfiles;
00117         protoarray.__ptr = protocols;
00118         protoarray.__size = nbprotocols;
00119 
00120         if (ret = soap_call_ns5__get (&soap, srm_endpoint, "get", &surlarray,
00121             &protoarray, &outg)) {
00122                 if (soap.error == SOAP_EOF) {
00123                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00124                         soap_end (&soap);
00125                         soap_done (&soap);
00126                         return (-1);
00127                 }
00128                 if(ret == SOAP_FAULT || ret == SOAP_CLI_FAULT)
00129                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00130                 soap_end (&soap);
00131                 soap_done (&soap);
00132                 return (-1);
00133         }
00134         reqstatp = outg._Result;
00135         if (reqstatp->fileStatuses == NULL) {
00136                 soap_end (&soap);
00137                 soap_done (&soap);
00138                 errno = EPROTONOSUPPORT;
00139                 return (-1);
00140         }
00141         *reqid = reqstatp->requestId;
00142         if (token)
00143                 *token = NULL;
00144         n = reqstatp->fileStatuses->__size;
00145         if ((*filestatuses = calloc (n, sizeof(struct srm_filestatus))) == NULL) {
00146                 soap_end (&soap);
00147                 soap_done (&soap);
00148                 errno = ENOMEM;
00149                 return (-1);
00150         }
00151         fs = *filestatuses;
00152         for (i = 0; i < n; i++) {
00153                 f = reqstatp->fileStatuses->__ptr[i];
00154                 if (f->SURL && (fs->surl = strdup (f->SURL)) == NULL)
00155                         errflag++;
00156                 if (f->state) {
00157                         if (strcmp (f->state, "Pending") == 0 ||
00158                             strcmp (f->state, "pending") == 0)
00159                                 fs->status = 0;
00160                         else if (strcmp (f->state, "Failed") == 0 ||
00161                             strcmp (f->state, "failed") == 0)
00162                                 fs->status = -1;
00163                         else
00164                                 fs->status = 1;
00165                 }
00166                 fs->fileid = f->fileId;
00167                 if (f->TURL && (fs->turl = strdup (f->TURL)) == NULL)
00168                         errflag++;
00169                 fs++;
00170         }
00171         soap_end (&soap);
00172         soap_done (&soap);
00173         return (n);
00174 }

int srm_set_xfer_done const char *  ,
int  ,
int  ,
char *  ,
int  ,
char *  ,
int  ,
int 
 

Definition at line 518 of file srm_ifce.c.

References gfal_errmsg(), and srm_init().

Referenced by set_xfer_done().

00519 {
00520         struct ns5__setFileStatusResponse out;
00521         int ret;
00522         struct soap soap;
00523         char srm_endpoint[256];
00524 
00525         if (srm_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00526             errbuf, errbufsz) < 0)
00527                 return (-1);
00528         soap.send_timeout = timeout ;
00529         soap.recv_timeout = timeout ;
00530 
00531 
00532         if (ret = soap_call_ns5__setFileStatus (&soap, srm_endpoint,
00533             "setFileStatus", reqid, fileid, "Done", &out)) {
00534                 if (soap.error == SOAP_EOF) {
00535                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00536                         soap_end (&soap);
00537                         soap_done (&soap);
00538                         return (-1);
00539                 }
00540                 if(ret == SOAP_FAULT || ret == SOAP_CLI_FAULT)
00541                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00542                 soap_end (&soap);
00543                 soap_done (&soap);
00544                 return (-1);
00545         }
00546         soap_end (&soap);
00547         soap_done (&soap);
00548         return (0);
00549 }

int srm_set_xfer_running const char *  ,
int  ,
int  ,
char *  ,
char *  ,
int  ,
int 
 

Definition at line 551 of file srm_ifce.c.

References gfal_errmsg(), and srm_init().

Referenced by set_xfer_running().

00552 {
00553         struct ns5__setFileStatusResponse out;
00554         int ret;
00555         struct soap soap;
00556         char srm_endpoint[256];
00557 
00558         if (srm_init (&soap, surl, srm_endpoint, sizeof(srm_endpoint),
00559             errbuf, errbufsz) < 0)
00560                 return (-1);
00561         soap.send_timeout = timeout ;
00562         soap.recv_timeout = timeout ;
00563 
00564 
00565         if (ret = soap_call_ns5__setFileStatus (&soap, srm_endpoint,
00566             "setFileStatus", reqid, fileid, "Running", &out)) {
00567                 if (soap.error == SOAP_EOF) {
00568                         gfal_errmsg(errbuf, errbufsz, "connection fails or timeout");
00569                         soap_end (&soap);
00570                         soap_done (&soap);
00571                         return (-1);
00572                 }
00573                 if(ret == SOAP_FAULT || ret == SOAP_CLI_FAULT)
00574                         gfal_errmsg(errbuf, errbufsz, soap.fault->faultstring);
00575                 soap_end (&soap);
00576                 soap_done (&soap);
00577                 return (-1);
00578         }
00579         soap_end (&soap);
00580         soap_done (&soap);
00581         return (0);
00582 }

char* srm_turlfromsurl const char *  ,
char **  ,
int  ,
int *  ,
int *  ,
char **  ,
char *  ,
int  ,
int 
 

Definition at line 427 of file srm_ifce.c.

References srm_turlsfromsurls().

00429 {
00430         int *fileids;
00431         char *p;
00432         char **turls;
00433         LONG64 zero = 0;
00434 
00435         if (srm_turlsfromsurls (1, &surl, &zero, protocols, oflag,
00436             reqid, &fileids, token, &turls, errbuf, errbufsz, timeout) <= 0)
00437                 return (NULL);
00438         *fileid = fileids[0];
00439         p = turls[0];
00440         free (fileids);
00441         free (turls);
00442         return (p);
00443 }

int srm_turlsfromsurls int  ,
const char **  ,
GFAL_LONG64 *  ,
char **  ,
int  ,
int *  ,
int **  ,
char **  ,
char ***  ,
char *  ,
int  ,
int 
 

Referenced by srm_turlfromsurl(), and turlfromsurlx().

char* surlfromguid const char *  ,
char *  ,
int 
 

Definition at line 1293 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_surlfromguid(), and lrc_surlfromguid().

Referenced by gfal_lstat(), gfal_lstat64(), gfal_open(), gfal_stat(), and gfal_stat64().

01294 {
01295         char *cat_type;
01296         if (get_cat_type (&cat_type) < 0) {
01297                 return (NULL);
01298         }
01299         if (strcmp (cat_type, "edg") == 0) {
01300                 free (cat_type);
01301                 return (lrc_surlfromguid (guid, errbuf, errbufsz));
01302         } else if (strcmp (cat_type, "lfc") == 0) {
01303                 free (cat_type);
01304                 return (lfc_surlfromguid (guid, errbuf, errbufsz));
01305         } else {
01306                 free (cat_type);
01307                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01308                 errno = EINVAL;
01309                 return (NULL);
01310         }
01311 }

char** surlsfromguid const char *  ,
char *  ,
int 
 

Definition at line 1314 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_surlsfromguid(), and lrc_surlsfromguid().

Referenced by gfal_unlink().

01315 {
01316         char *cat_type;
01317         if (get_cat_type (&cat_type) < 0) {
01318                 return (NULL);
01319         }
01320         if (strcmp (cat_type, "edg") == 0) {
01321                 free (cat_type);
01322                 return (lrc_surlsfromguid (guid, errbuf, errbufsz));
01323         } else if (strcmp (cat_type, "lfc") == 0) {
01324                 free (cat_type);
01325                 return (lfc_surlsfromguid (guid, errbuf, errbufsz));
01326         } else {
01327                 free (cat_type);
01328                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01329                 errno = EINVAL;
01330                 return (NULL);
01331         }
01332 }

char* turlfromsfn const char *  ,
char **  ,
char *  ,
int 
 

Definition at line 1048 of file gfal.c.

References get_sup_proto(), and gfal_errmsg().

Referenced by deletepfn(), gfal_lstat(), gfal_lstat64(), gfal_open(), gfal_stat(), and gfal_stat64().

01049 {
01050         char **ap;
01051         int i;
01052         int len;
01053         char *p;
01054         int *pn;
01055         int port = 0;
01056         char **protoarray;
01057         char server[64];
01058         char *turl;
01059 
01060         if (strncmp (sfn, "sfn://", 6)) {
01061                 gfal_errmsg(errbuf, errbufsz, "File doesn't start with \"sfn://\".");
01062                 errno = EINVAL;
01063                 return (NULL);
01064         }
01065         if ((p = strchr (sfn + 6, '/')) == NULL ||
01066             (len = p - (sfn + 6)) > sizeof(server)) {
01067                 gfal_errmsg(errbuf, errbufsz, "Host name too long.");
01068                 errno = ENAMETOOLONG;
01069                 return (NULL);
01070         }
01071 
01072         /* check that RFIO library is available */
01073 
01074         if (protocols == NULL)
01075                 protoarray = get_sup_proto ();
01076         else
01077                 protoarray = protocols;
01078         for (i = 0; *protoarray[i]; i++)
01079                 if (strcmp (protoarray[i], "rfio") == 0) break;
01080         if (*protoarray[i] == '\0') {
01081                 errno = EPROTONOSUPPORT;
01082                 return (NULL);
01083         }
01084 
01085         /* check that the SE supports RFIO */
01086 
01087         strncpy (server, sfn + 6, len);
01088         *(server + len) = '\0';
01089         if (get_seap_infox (server, &ap, &pn, errbuf, errbufsz) < 0)
01090                 return (NULL);
01091         i = 0;
01092         while (ap[i]) {
01093                 if (strcmp (ap[i], "rfio") == 0) port = pn[i];
01094                 free (ap[i]);
01095                 i++;
01096         }
01097         free (ap);
01098         free (pn);
01099         if (! port) {
01100                 gfal_errmsg(errbuf, errbufsz, "rfio protocol not supported by Storage Element.");
01101                 errno = EPROTONOSUPPORT;
01102                 return (NULL);
01103         }
01104         if ((turl = malloc (strlen (sfn) + 2)) == NULL)
01105                 return (NULL);
01106         strcpy (turl, "rfio");
01107         strcpy (turl + 4, sfn + 3);
01108         return (turl);
01109 }

char* turlfromsurl const char *  ,
char **  ,
int  ,
int *  ,
int *  ,
char **  ,
char *  ,
int  ,
int 
 

Definition at line 1146 of file gfal.c.

References GFAL_LONG64, and turlfromsurlx().

Referenced by gfal_open().

01148 {
01149         GFAL_LONG64 zero = 0;
01150 
01151         return (turlfromsurlx (surl, zero, protocols, oflag, reqid, fileid,
01152             token, errbuf, errbufsz, timeout));
01153 }

char* turlfromsurlx const char *  ,
GFAL_LONG64  ,
char **  ,
int  ,
int *  ,
int *  ,
char **  ,
char *  ,
int  ,
int 
 

Definition at line 1112 of file gfal.c.

References gfal_errmsg(), se_turlfromsurl(), setypefromsurl(), and srm_turlsfromsurls().

Referenced by turlfromsurl().

01115 {
01116         int *fileids;
01117         char *p;
01118         char *se_type;
01119         char **turls;
01120 
01121         if (setypefromsurl (surl, &se_type, errbuf, errbufsz) < 0)
01122                 return (NULL);
01123         if (strcmp (se_type, "srm_v1") == 0) {
01124                 free (se_type);
01125                 if (srm_turlsfromsurls (1, &surl, &filesize, protocols, oflag,
01126                     reqid, &fileids, token, &turls, errbuf, errbufsz, timeout) <= 0)
01127                         return (NULL);
01128                 *fileid = fileids[0];
01129                p = turls[0];
01130                free (fileids);
01131                free (turls);
01132                return (p);
01133         } else if (strcmp (se_type, "edg-se") == 0) {
01134                 free (se_type);
01135                 return (se_turlfromsurl (surl, protocols, oflag, reqid, fileid,
01136                     token, errbuf, errbufsz, timeout));
01137         } else {
01138                 free (se_type);
01139                 gfal_errmsg(errbuf, errbufsz, "The Storage Element type is neither 'srm_v1' nor 'edg-se'.");
01140                 errno = EINVAL;
01141                 return (NULL);
01142         }
01143 }

int unregister_alias const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 1458 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_unregister_alias(), and rmc_unregister_alias().

01459 {
01460         char *cat_type;
01461         if (get_cat_type (&cat_type) < 0) {
01462                 return (-1);
01463         }
01464         if (strcmp (cat_type, "edg") == 0) {
01465                 free (cat_type);
01466                 return (rmc_unregister_alias (guid, lfn, errbuf, errbufsz));
01467         } else if (strcmp (cat_type, "lfc") == 0) {
01468                 free (cat_type);
01469                 return (lfc_unregister_alias (guid, lfn, errbuf, errbufsz));
01470         } else {
01471                 free (cat_type);
01472                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01473                 errno = EINVAL;
01474                 return (-1);
01475         }
01476 }

int unregister_pfn const char *  ,
const char *  ,
char *  ,
int 
 

Definition at line 1334 of file gfal.c.

References get_cat_type(), gfal_errmsg(), lfc_unregister_pfn(), and lrc_unregister_pfn().

01335 {
01336         char *cat_type;
01337         if (get_cat_type (&cat_type) < 0) {
01338                 return (-1);
01339         }
01340         if (strcmp (cat_type, "edg") == 0) {
01341                 free (cat_type);
01342                 return (lrc_unregister_pfn (guid, pfn, errbuf, errbufsz));
01343         } else if (strcmp (cat_type, "lfc") == 0) {
01344                 free (cat_type);
01345                 return (lfc_unregister_pfn (guid, pfn, errbuf, errbufsz));
01346         } else {
01347                 free (cat_type);
01348                 gfal_errmsg(errbuf, errbufsz, "The catalog type is neither 'edg' nor 'lfc'.");
01349                 errno = EINVAL;
01350                 return (-1);
01351         }
01352 }


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