XRootD
Loading...
Searching...
No Matches
XrdPssUtils.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P s s U t i l s . c c */
4/* */
5/* (c) 2020 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <cstring>
32#include <strings.h>
33
34#include "XrdPss/XrdPssUtils.hh"
35
36/******************************************************************************/
37/* L o c a l S t a t i c s */
38/******************************************************************************/
39
40namespace
41{
42 struct pEnt {const char *pname; int pnlen;} pTab[] =
43 {{ "https://", 8}, { "http://", 7},
44 { "roots://", 8}, { "root://", 7},
45 {"xroots://", 9}, {"xroot://", 8},
46 {"pelican://", 10}
47 };
48 int pTNum = sizeof(pTab)/sizeof(pEnt);
49 int xrBeg = 2;
50}
51
52/******************************************************************************/
53/* g e t D o m a i n */
54/******************************************************************************/
55
56const char *XrdPssUtils::getDomain(const char *hName)
57{
58 const char *dot = index(hName, '.');
59
60 if (dot) return dot+1;
61 return hName;
62}
63
64/******************************************************************************/
65/* i s 4 X r o o t d */
66/******************************************************************************/
67
68bool XrdPssUtils::is4Xrootd(const char *pname)
69{
70// Find out of protocol is for xroot protocol
71//
72 if (*pname == 'x' || *pname == 'r')
73 for (int i = xrBeg; i < pTNum; i++)
74 if (!strncmp(pname, pTab[i].pname, pTab[i].pnlen)) return true;
75 return false;
76}
77
78/******************************************************************************/
79/* v a l P r o t */
80/******************************************************************************/
81
82const char *XrdPssUtils::valProt(const char *pname, int &plen, int adj)
83{
84 int i;
85
86// Find a match
87//
88 for (i = 0; i < pTNum; i++)
89 {if (!strncmp(pname, pTab[i].pname, pTab[i].pnlen-adj)) break;}
90 if (i >= pTNum) return 0;
91 plen = pTab[i].pnlen-adj;
92 return pTab[i].pname;
93}
94
95/******************************************************************************/
96/* V e c t o r i z e */
97/******************************************************************************/
98
99bool XrdPssUtils::Vectorize(char *str, std::vector<char *> &vec, char sep)
100{
101 char *seppos;
102
103// Get each element and place it in the vecor. Null elements are not allowed.
104//
105 do {seppos = index(str, sep);
106 if (seppos)
107 {if (!(*(seppos+1))) return false;
108 *seppos = '\0';
109 }
110 if (!strlen(str)) return false;
111 vec.push_back(str);
112 str = seppos+1;
113 } while(seppos && *str);
114 return true;
115}
static const char * getDomain(const char *hName)
static const char * valProt(const char *pname, int &plen, int adj=0)
static bool is4Xrootd(const char *pname)
static bool Vectorize(char *str, std::vector< char * > &vec, char sep)