1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
#include "srmv2H.h"
#include "srmSoapBinding.nsmap"
#define DEFPOLLINT 10
#define SRM_EP_PATH "/v2_1_1/srm"
#ifdef GFAL_SECURE
#include "cgsi_plugin.h"
#endif
parsesurl (const char *surl, char **endpoint, char **sfn)
{
int len;
int lenp;
char *p;
static char srm_ep[256];
if (strncmp (surl, "srm://", 6)) {
errno = EINVAL;
return (-1);
}
if (p = strstr (surl + 6, "?SFN=")) {
*sfn = p + 5;
} else if (p = strchr (surl + 6, '/')) {
*sfn = p;
} else {
errno = EINVAL;
return (-1);
}
#ifdef GFAL_SECURE
strcpy (srm_ep, "https://");
lenp = 8;
#else
strcpy (srm_ep, "http://");
lenp = 7;
#endif
len = p - surl - 6;
if (lenp + len >= sizeof(srm_ep)) {
errno = EINVAL;
return (-1);
}
strncpy (srm_ep + lenp, surl + 6, len);
*(srm_ep + lenp + len) = '\0';
if (strchr (srm_ep + lenp, '/') == NULL) {
if (strlen (SRM_EP_PATH) + lenp + len >= sizeof(srm_ep)) {
errno = EINVAL;
return (-1);
}
strcat (srm_ep, SRM_EP_PATH);
}
*endpoint = srm_ep;
return (0);
}
main(argc, argv)
int argc;
char **argv;
{
int flags;
int i;
int nbfiles;
int nbproto = 0;
static char *protocols[] = {
#if GFAL_ENABLE_RFIO
"rfio",
#endif
#if GFAL_ENABLE_DCAP
"gsidcap",
#endif
""
};
int r = 0;
char *r_token;
struct ns1__srmPrepareToGetResponse_ rep;
struct ns1__ArrayOfTGetRequestFileStatus *repfs;
struct ns1__srmPrepareToGetRequest req;
struct ns1__TGetFileRequest *reqfilep;
struct ns1__TReturnStatus *reqstatp;
char *sfn;
struct soap soap;
struct ns1__srmStatusOfGetRequestResponse_ srep;
struct ns1__srmStatusOfGetRequestRequest sreq;
char *srm_endpoint;
if (argc < 2) {
fprintf (stderr, "usage: %s SURLs\n", argv[0]);
exit (1);
}
nbfiles = argc - 1;
if (parsesurl (argv[1], &srm_endpoint, &sfn) < 0) {
perror ("parsesurl");
exit (1);
}
while (*protocols[nbproto]) nbproto++;
soap_init (&soap);
#ifdef GFAL_SECURE
flags = CGSI_OPT_DISABLE_NAME_CHECK;
soap_register_plugin_arg (&soap, client_cgsi_plugin, &flags);
#endif
memset (&req, 0, sizeof(req));
if ((req.arrayOfFileRequests =
soap_malloc (&soap, sizeof(struct ns1__ArrayOfTGetFileRequest))) == NULL ||
(req.arrayOfFileRequests->getRequestArray =
soap_malloc (&soap, nbfiles * sizeof(struct ns1__TGetFileRequest *))) == NULL ||
(req.arrayOfTransferProtocols =
soap_malloc (&soap, sizeof(struct ns1__ArrayOf_USCORExsd_USCOREstring))) == NULL) {
perror ("malloc");
soap_end (&soap);
exit (1);
}
for (i = 0; i < nbfiles; i++) {
if ((req.arrayOfFileRequests->getRequestArray[i] =
soap_malloc (&soap, sizeof(struct ns1__TGetFileRequest))) == NULL) {
perror ("malloc");
soap_end (&soap);
exit (1);
}
}
req.arrayOfFileRequests->__sizegetRequestArray = nbfiles;
req.arrayOfTransferProtocols->stringArray = protocols;
req.arrayOfTransferProtocols->__sizestringArray = nbproto;
for (i = 0; i < nbfiles; i++) {
reqfilep = req.arrayOfFileRequests->getRequestArray[i];
if ((reqfilep->fromSURLInfo =
soap_malloc (&soap, sizeof(struct ns1__TSURLInfo))) == NULL ||
(reqfilep->fromSURLInfo->SURLOrStFN =
soap_malloc (&soap, sizeof(struct ns1__TSURL))) == NULL) {
perror ("malloc");
soap_end (&soap);
exit (1);
}
reqfilep->fromSURLInfo->SURLOrStFN->value = argv[i+1];
}
if (soap_call_ns1__srmPrepareToGet (&soap, srm_endpoint, "PrepareToGet",
&req, &rep)) {
soap_print_fault (&soap, stderr);
soap_print_fault_location (&soap, stderr);
soap_end (&soap);
exit (1);
}
reqstatp = rep.srmPrepareToGetResponse->returnStatus;
repfs = rep.srmPrepareToGetResponse->arrayOfFileStatuses;
if (rep.srmPrepareToGetResponse->requestToken) {
r_token = rep.srmPrepareToGetResponse->requestToken->value;
printf ("soap_call_ns1__srmPrepareToGet returned r_token %s\n",
r_token);
}
memset (&sreq, 0, sizeof(sreq));
sreq.requestToken = rep.srmPrepareToGetResponse->requestToken;
/* wait for file "ready" */
while (reqstatp->statusCode == SRM_USCOREREQUEST_USCOREQUEUED ||
reqstatp->statusCode == SRM_USCOREREQUEST_USCOREINPROGRESS ||
reqstatp->statusCode == SRM_USCOREREQUEST_USCORESUSPENDED) {
printf("request state %d\n", reqstatp->statusCode);
sleep ((r++ == 0) ? 1 : DEFPOLLINT);
if (soap_call_ns1__srmStatusOfGetRequest (&soap, srm_endpoint,
"StatusOfGetRequest", &sreq, &srep)) {
soap_print_fault (&soap, stderr);
soap_end (&soap);
exit (1);
}
reqstatp = srep.srmStatusOfGetRequestResponse->returnStatus;
repfs = srep.srmStatusOfGetRequestResponse->arrayOfFileStatuses;
}
printf ("request state %d\n", reqstatp->statusCode);
if (reqstatp->statusCode != SRM_USCORESUCCESS &&
reqstatp->statusCode != SRM_USCOREDONE) {
if (reqstatp->explanation)
printf ("explanation: %s\n", reqstatp->explanation);
soap_end (&soap);
exit (1);
}
if (! repfs) {
printf ("arrayOfFileStatuses is NULL\n");
soap_end (&soap);
exit (1);
}
for (i = 0; i < repfs->__sizegetStatusArray; i++) {
if (repfs->getStatusArray[i]->transferURL)
printf ("state[%d] = %d, TURL = %s\n", i,
(repfs->getStatusArray[i])->status->statusCode,
(repfs->getStatusArray[i])->transferURL->value);
else if ((repfs->getStatusArray[i])->status->explanation)
printf ("state[%d] = %d, explanation = %s\n", i,
(repfs->getStatusArray[i])->status->statusCode,
(repfs->getStatusArray[i])->status->explanation);
else
printf ("state[%d] = %d\n", i,
(repfs->getStatusArray[i])->status->statusCode);
}
soap_end (&soap);
exit (0);
}
|