gfal_testget.c

This exemple show how to convert a surl to a turl ex : use case with SRM plugin : ./gfal_testget srm://grid05.lal.in2p3.fr:8446/dpm/lal.in2p3.fr/home/dteam/test_darkvador

00001 
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <unistd.h>
00009 #include <string.h>
00010 #include <sys/types.h>
00011 #include <errno.h>
00012 #include <sys/param.h>
00013 
00014 #define DEFPOLLINT 10
00015 #define TURL_MAX_SIZE 1024
00016 
00017 
00018 #ifndef _GFAL_1_X
00019 
00020 #include <gfal_api.h>
00021 
00022 // GFAL 2.0 use the extended attribute system for the advanced files properties.
00023 
00024 int main(int argc,char **argv)
00025 {
00026 
00027         char turl_buff[TURL_MAX_SIZE];
00028 
00029         if (argc < 2){
00030                 fprintf (stderr, "usage: %s SURLs\n", argv[0]);
00031                 exit (1);
00032         }
00033         gfal_set_verbose (GFAL_VERBOSE_VERBOSE);
00034         
00035         ssize_t res = gfal_getxattr(argv[1], "user.replicas", turl_buff, TURL_MAX_SIZE );
00036         
00037         if (res > 0)
00038                 printf("URL %s Ready - REPLICA: %s\n", argv[1], turl_buff);
00039         else {
00040                 printf("URL %s Failed:\n", argv[1]);
00041                 gfal_posix_check_error();
00042         }
00043                 
00044         return((res>0)?0:-1);
00045 }
00046 
00047 #endif
00048 
00049 
00050 /*  This is the OLD WAY GFAL 1.0 to do IT, DONT USE IT WITH GFAL2.0, IT IS FOR A  EXAMPLE OF MIGRATION 1.X to 2.0
00051 #ifdef _GFAL_1_X 
00052 #define gfal_handle_free(x) gfal_internal_free(x)
00053 
00054 
00055 #include <gfal_api.h>
00056 
00057 main(argc, argv)
00058 int argc;
00059 char **argv;
00060 {
00061         gfal_request req = NULL;
00062         gfal_internal gobj = NULL;
00063         gfal_filestatus *filestatuses = NULL;
00064         int sav_errno = 0, n = 0, i = 0, nberrors = 0;
00065         static char *protos[] = {"rfio", "dcap", "gsiftp"};
00066 
00067         if (argc < 2) {
00068                 fprintf (stderr, "usage: %s SURLs\n", argv[0]);
00069                 exit (1);
00070         }
00071 
00072         gfal_set_verbose (0);
00073 
00074         if ((req = gfal_request_new ()) == NULL)
00075                 exit (1);
00076         req->nbfiles = argc - 1;
00077         req->surls = argv + 1;
00078         req->protocols = protos;
00079 
00080         if (gfal_init (req, &gobj, NULL, 0) < 0) {
00081                 sav_errno = errno;
00082                 free (req);
00083                 errno = sav_errno;
00084                 perror (argv[0]);
00085                 exit (1);
00086         }
00087         free (req);
00088 
00089         if (gfal_turlsfromsurls (gobj, NULL, 0) < 0) {
00090                 sav_errno = errno;
00091                 gfal_internal_free (gobj);
00092                 errno = sav_errno;
00093                 perror (argv[0]);
00094                 exit (1);
00095         }
00096 
00097         if ((n = gfal_get_results (gobj, &filestatuses)) < 0) {
00098                 sav_errno = errno;
00099                 gfal_internal_free (gobj);
00100                 errno = sav_errno;
00101                 perror (argv[0]);
00102                 exit (1);
00103         }
00104 
00105         if (filestatuses == NULL) {
00106                 fprintf (stderr, "%s: Internal error (memory corruption?)\n", argv[0]);
00107                 exit (1);
00108         }
00109 
00110         for (i = 0; i < n; ++i) {
00111                 if (filestatuses[i].status == 0)
00112                         printf("SURL %s Ready - TURL: %s\n", filestatuses[i].surl, filestatuses[i].turl);
00113                 else {
00114                         ++nberrors;
00115                         if (filestatuses[i].explanation)
00116                                 printf("SURL %s Failed:\n%s\n", filestatuses[i].surl, filestatuses[i].explanation);
00117                         else
00118                                 printf("SURL %s Failed:\n%s\n", filestatuses[i].surl, strerror (filestatuses[i].status));
00119                 }
00120         }
00121 
00122         gfal_internal_free (gobj);
00123         exit (nberrors > 0 ? 1 : 0);
00124 }
00125 #endif
00126 */

Generated on 24 Apr 2013 for CERN GFAL 2.0 by  doxygen 1.4.7