XRootD
Loading...
Searching...
No Matches
XrdPssCks.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P s s C k s . c c */
4/* */
5/* (c) 2011 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 <cstdio>
32
33#include "XrdPss/XrdPss.hh"
34#include "XrdPss/XrdPssCks.hh"
35#include "XrdPss/XrdPssTrace.hh"
36
37#include "XrdVersion.hh"
38
42
43#ifndef ENODATA
44#define ENODATA ENOATTR
45#endif
46
47/******************************************************************************/
48/* G l o b a l s */
49/******************************************************************************/
50
51namespace XrdProxy
52{
53
55
56}
57
58using namespace XrdProxy;
59
60/******************************************************************************/
61/* X r d C k s I n i t */
62/******************************************************************************/
63
65
66// Return the proxy checksum object created by the storage system interface.
67//
68extern "C"
69{XrdCks *XrdCksInit(XrdSysError *eDest, // The error msg object
70 const char *cFN, // Config file name
71 const char *Parms // Parms via lib directive
72 ) {return (XrdCks *)new XrdPssCks(eDest);}
73}
74
75/******************************************************************************/
76/* C o n s t r u c t o r */
77/******************************************************************************/
78
80{
81
82// Prefill the native digests we support
83//
84 csTab[0].Len = 4; strcpy(csTab[0].Name, "adler32");
85 csTab[1].Len = 4; strcpy(csTab[1].Name, "crc32");
86 csTab[2].Len = 16; strcpy(csTab[2].Name, "md5");
87 csLast = 2;
88}
89
90/******************************************************************************/
91/* Private: F i n d */
92/******************************************************************************/
93
94XrdPssCks::csInfo *XrdPssCks::Find(const char *Name)
95{
96 int i;
97 for (i = 0; i <= csLast; i++)
98 if (!strcmp(Name, csTab[i].Name)) return &csTab[i];
99 return 0;
100}
101
102/******************************************************************************/
103/* G e t */
104/******************************************************************************/
105
106int XrdPssCks::Get(const char *Pfn, XrdCksData &Cks)
107{
108 EPNAME("GetCks");
109 static const int cksBLen = 256;
110 static const int urlBLen = 2048;
111 char cksBuff[cksBLen], pBuff[urlBLen], cgiBuff[32], *tP;
112 XrdOucTokenizer Resp(cksBuff);
113 time_t Mtime;
114 int rc, n;
115
116// Construct the cgi for digest type
117//
118 n = snprintf(cgiBuff, sizeof(cgiBuff), "cks.type=%s", Cks.Name);
119 if (n >= (int)sizeof(cgiBuff)) return -ENAMETOOLONG;
120
121// Construct the correct url info
122//
123 XrdPssUrlInfo uInfo(Cks.envP, Pfn, cgiBuff, false);
124 uInfo.setID();
125
126// Direct the path to the origin
127//
128 if ((rc = XrdPssSys::P2URL(pBuff, sizeof(pBuff), uInfo))) return rc;
129
130// Do some debugging
131//
132 DEBUG(uInfo.Tident(),"url="<<pBuff);
133
134// First step is to getthe checksum value
135//
136 if ((rc = XrdPosixXrootd::QueryChksum(pBuff, Mtime, cksBuff, cksBLen)) <= 0)
137 return (rc ? -errno : -ENOTSUP);
138
139// Get the checksum name
140//
141 if (!Resp.GetLine() || !(tP = Resp.GetToken()) || !(*tP)) return -ENOMSG;
142 if (!Cks.Set(tP)) return -ENOTSUP;
143
144// Now get the checksum value
145//
146 if (!(tP = Resp.GetToken()) || !(*tP)) return -ENODATA;
147 if (!Cks.Set(tP, strlen(tP))) return -ENOTSUP;
148
149// Set remaining fields and return success
150//
151 Cks.fmTime = static_cast<long long>(Mtime);
152 Cks.csTime = 0;
153 return Cks.Length;
154}
155
156/******************************************************************************/
157/* I n i t */
158/******************************************************************************/
159
160int XrdPssCks::Init(const char *ConfigFN, const char *DfltCalc)
161{
162 int i;
163
164// See if we need to set the default calculation
165//
166 if (DfltCalc)
167 {for (i = 0; i < csLast; i++) if (!strcmp(csTab[i].Name, DfltCalc)) break;
168 if (i >= csMax)
169 {eDest->Emsg("Config", DfltCalc, "cannot be made the default; "
170 "not supported.");
171 return 0;
172 }
173 if (i) {csInfo Temp = csTab[i]; csTab[i] = csTab[0]; csTab[0] = Temp;}
174 }
175
176// All done
177//
178 return 1;
179}
180
181/******************************************************************************/
182/* N a m e */
183/******************************************************************************/
184
185const char *XrdPssCks::Name(int seqNum)
186{
187
188 return (seqNum < 0 || seqNum > csLast ? 0 : csTab[seqNum].Name);
189}
190
191/******************************************************************************/
192/* S i z e */
193/******************************************************************************/
194
195int XrdPssCks::Size(const char *Name)
196{
197 csInfo *iP = (Name != 0 ? Find(Name) : &csTab[0]);
198 return (iP != 0 ? iP->Len : 0);
199}
200
201/******************************************************************************/
202/* V e r */
203/******************************************************************************/
204
205int XrdPssCks::Ver(const char *Pfn, XrdCksData &Cks)
206{
207 XrdCksData fCks;
208 csInfo *csIP = &csTab[0];
209 int rc;
210
211// Determine which checksum to get
212//
213 if (!(*Cks.Name)) strcpy(Cks.Name, csTab[0].Name);
214 else if (!(csIP = Find(Cks.Name))) return -ENOTSUP;
215
216// Get the file checksum
217//
218 if ((rc = Get(Pfn, fCks))) return rc;
219
220// Compare the checksums
221//
222 return (!strcmp(fCks.Name, Cks.Name) && fCks.Length == Cks.Length
223 && !memcmp(fCks.Value, Cks.Value, csIP->Len));
224}
#define DEBUG(x)
#define EPNAME(x)
#define ENODATA
XrdCks * XrdCksInit(XrdSysError *eDest, const char *cFN, const char *Parms)
Definition XrdPssCks.cc:69
XrdVERSIONINFO(XrdCksInit, PssCks)
char Value[ValuSize]
Definition XrdCksData.hh:53
int Set(const char *csName)
Definition XrdCksData.hh:81
char Name[NameSize]
Definition XrdCksData.hh:44
XrdSysError * eDest
Definition XrdCks.hh:289
char * GetToken(char **rest=0, int lowcase=0)
static int QueryChksum(const char *path, time_t &mtime, char *buff, int blen)
virtual int Get(const char *Pfn, XrdCksData &Cks)
Definition XrdPssCks.cc:106
virtual int Ver(const char *Pfn, XrdCksData &Cks)
Definition XrdPssCks.cc:205
virtual int Init(const char *ConfigFN, const char *DfltCalc=0)
Definition XrdPssCks.cc:160
virtual const char * Name(int seqNum=0)
Definition XrdPssCks.cc:185
XrdPssCks(XrdSysError *erP)
Definition XrdPssCks.cc:79
virtual int Size(const char *Name=0)
Definition XrdPssCks.cc:195
static int P2URL(char *pbuff, int pblen, XrdPssUrlInfo &uInfo, bool doN2N=true)
Definition XrdPss.cc:1376
const char * Tident()
void setID(const char *tid=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysTrace SysTrace("Pss", 0)
Definition XrdPssCks.cc:54
XrdSysError eDest(0, "pss_")