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
|
/*
* Copyright (C) 2004-2005 by CERN/IT/GD/CT & CNRS/IN2P3/LAL
* All rights reserved
*/
// $Id: parsesurl.ic,v 1.2 2007/01/17 14:18:38 grodid Exp $
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://");
strcpy (srm_ep, "httpg://");
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);
}
|