XRootD
Loading...
Searching...
No Matches
XrdOucVerName.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O u c V e r N a m e . c c */
4/* */
5/* (c) 2014 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Andrew Hanushevsky for Stanford University under contract */
7/* DE-AC02-76-SFO0515 with the Department of Energy */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
30#include <cstdio>
31#include <cstdlib>
32#include <cstring>
33#include <strings.h>
34
35#include "XrdVersionPlugin.hh"
36
38
39/******************************************************************************/
40/* S t a t i c s */
41/******************************************************************************/
42
43namespace
44{
45static const char *StrictName[] = XrdVERSIONPLUGINSTRICT;
46}
47
48/******************************************************************************/
49/* h a s V e r s i o n */
50/******************************************************************************/
51
52int XrdOucVerName::hasVersion(const char *piPath, char **piNoVN)
53{
54 const char *Dash;
55
56// We check for an embeded version number. This is usually used to issue a
57// warning that including a specific version disables automatic versioning.
58// We only return an alternate name if the library is an official one.
59//
60 if ((Dash = rindex(piPath, '-')))
61 {char *endP;
62 int vn = strtol(Dash+1, &endP, 10);
63 if (vn && !strcmp(endP, ".so"))
64 {if (piNoVN)
65 {char buff[2048];
66 snprintf(buff,sizeof(buff),"%.*s%s",int(Dash-piPath),piPath,endP);
67 if (isOurs(buff)) *piNoVN = strdup(buff);
68 else *piNoVN = 0;
69 }
70 return vn;
71 }
72 }
73 if (piNoVN) *piNoVN = 0;
74 return 0;
75}
76
77/******************************************************************************/
78/* Private: i s O u r s */
79/******************************************************************************/
80
81bool XrdOucVerName::isOurs(const char *path)
82{
83 const char *Slash = rindex(path, '/');
84
85 Slash = (Slash ? Slash+1 : path);
86 int n = 0;
87 while(StrictName[n] && strcmp(Slash, StrictName[n])) n++;
88
89 return (StrictName[n] != 0);
90}
91
92/******************************************************************************/
93/* V e r s i o n */
94/******************************************************************************/
95
96int XrdOucVerName::Version(const char *piVers, const char *piPath, bool &noFBK,
97 char *buff, int blen)
98{
99 const char *Dot, *Slash, *fName;
100 int n, pLen;
101
102// Find the markers in the passed path
103//
104 if ((Slash = rindex(piPath, '/')))
105 {pLen = Slash-piPath+1; Dot = rindex(Slash+1, '.'); fName = Slash+1;}
106 else {pLen = 0; Dot = rindex(piPath, '.'); fName = piPath;}
107 if (Dot) pLen += Dot-fName;
108 else {pLen += strlen(fName); Dot = "";}
109
110// Test strict naming and return result
111//
112 n = 0;
113 while(StrictName[n] && strcmp(fName, StrictName[n])) n++;
114 noFBK = (StrictName[n] != 0);
115
116// Format the versioned name
117//
118 n = snprintf(buff, blen-1, "%.*s-%s%s", pLen, piPath, piVers, Dot);
119
120// Return result
121//
122 return (n < blen ? n : 0);
123}
#define XrdVERSIONPLUGINSTRICT
static int Version(const char *piVers, const char *piPath, bool &noFBK, char *buff, int blen)
static int hasVersion(const char *piPath, char **piNoVN=0)