XRootD
Loading...
Searching...
No Matches
XrdSutPFEntry.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d S u t P F E n t r y . c c */
4/* */
5/* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Gerri Ganis for CERN */
7/* */
8/* This file is part of the XRootD software suite. */
9/* */
10/* XRootD is free software: you can redistribute it and/or modify it under */
11/* the terms of the GNU Lesser General Public License as published by the */
12/* Free Software Foundation, either version 3 of the License, or (at your */
13/* option) any later version. */
14/* */
15/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
16/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
17/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
18/* License for more details. */
19/* */
20/* You should have received a copy of the GNU Lesser General Public License */
21/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
22/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* The copyright holder's institutional names and contributor's names may not */
25/* be used to endorse or promote products derived from this software without */
26/* specific prior written permission of the institution or contributor. */
27/******************************************************************************/
28
29#include <cstdio>
30#include <cstring>
31#include <ctime>
32
33#include "XrdSutAux.hh"
34#include "XrdSutPFEntry.hh"
35
36//__________________________________________________________________
38{
39 // Constructor
40
41 len = 0;
42 buf = 0;
43 if (b) {
44 buf = b;
45 len = l;
46 }
47}
48
49//__________________________________________________________________
51{
52 //Copy constructor
53
54 buf = 0;
55 len = 0;
56 if (b.buf) {
57 buf = new char[b.len];
58 if (buf) {
59 memcpy(buf,b.buf,b.len);
60 len = b.len;
61 }
62 }
63}
64
65//__________________________________________________________________
66void XrdSutPFBuf::SetBuf(const char *b, kXR_int32 l)
67{
68 // Set the buffer
69
70 len = 0;
71 if (buf) {
72 delete[] buf;
73 buf = 0;
74 }
75 if (b && l > 0) {
76 buf = new char[l];
77 if (buf) {
78 memcpy(buf,b,l);
79 len = l;
80 }
81 }
82}
83
84//____________________________________________________________________
85XrdSutPFEntry::XrdSutPFEntry(const char *n, short st, short cn,
86 kXR_int32 mt)
87{
88 // Constructor
89
90 name = 0;
91 status = st;
92 cnt = cn;
93 mtime = (mt > 0) ? mt : (kXR_int32)time(0);
94 if (n) {
95 name = new char[strlen(n)+1];
96 if (name)
97 strcpy(name,n);
98 }
99}
100
101//_____________________________________________________________________
103 buf2(e.buf2), buf3(e.buf3), buf4(e.buf4)
104{
105 // Copy constructor
106
107 name = 0;
108 status = e.status;
109 cnt = e.cnt;
110 mtime = e.mtime;
111 if (e.name) {
112 name = new char[strlen(e.name)+1];
113 if (name)
114 strcpy(name,e.name);
115 }
116}
117
118//____________________________________________________________________
120{
121 // Resetting entry
122
123 if (name)
124 delete[] name;
125 name = 0;
126 status = 0;
127 cnt = 0;
128 mtime = (kXR_int32)time(0);
129 buf1.SetBuf();
130 buf2.SetBuf();
131 buf3.SetBuf();
132 buf4.SetBuf();
133}
134
135//_____________________________________________________________________
136void XrdSutPFEntry::SetName(const char *n)
137{
138 // Set the name
139
140 if (name) {
141 delete[] name;
142 name = 0;
143 }
144 if (n) {
145 name = new char[strlen(n)+1];
146 if (name)
147 strcpy(name,n);
148 }
149}
150
151//_____________________________________________________________________
153{
154 // Return a string with serialized information
155 // For print purposes
156 // The output string points to a static buffer, so it must
157 // not be deleted by the caller
158 static char pbuf[2048];
159
160 char smt[20] = {0};
162
163 sprintf(pbuf,"st:%d cn:%d buf:%d,%d,%d,%d modified:%s name:%s",
165
166 return pbuf;
167}
168
169//______________________________________________________________________________
171{
172 // Assign entry e to local entry.
173
174 SetName(name);
175 status = e.status;
176 cnt = e.cnt; // counter
177 mtime = e.mtime; // time of last modification / creation
178 buf1.SetBuf(e.buf1.buf);
179 buf2.SetBuf(e.buf2.buf);
180 buf3.SetBuf(e.buf3.buf);
181 buf4.SetBuf(e.buf4.buf);
182
183 return (*this);
184}
int kXR_int32
Definition XPtypes.hh:89
int XrdSutTimeString(int t, char *st, int opt)
Definition XrdSutAux.cc:305
void SetBuf(const char *b=0, kXR_int32 l=0)
XrdSutPFBuf(char *b=0, kXR_int32 l=0)
kXR_int32 len
kXR_int32 mtime
XrdSutPFBuf buf3
XrdSutPFBuf buf1
XrdSutPFEntry & operator=(const XrdSutPFEntry &pfe)
char * AsString() const
void SetName(const char *n=0)
XrdSutPFEntry(const char *n=0, short st=0, short cn=0, kXR_int32 mt=0)
XrdSutPFBuf buf2
XrdSutPFBuf buf4