00001
00002
00003 const char *XrdSutPFEntryCVSID = "$Id: XrdSutPFEntry.cc 30949 2009-11-02 16:37:58Z ganis $";
00004 #include <stdio.h>
00005 #include <string.h>
00006 #include <time.h>
00007
00008 #include "XrdSutAux.hh"
00009 #include "XrdSutPFEntry.hh"
00010
00011
00012 XrdSutPFBuf::XrdSutPFBuf(char *b, kXR_int32 l)
00013 {
00014
00015
00016 len = 0;
00017 buf = 0;
00018 if (b) {
00019 buf = b;
00020 len = l;
00021 }
00022 }
00023
00024
00025 XrdSutPFBuf::XrdSutPFBuf(const XrdSutPFBuf &b)
00026 {
00027
00028
00029 buf = 0;
00030 len = 0;
00031 if (b.buf) {
00032 buf = new char[b.len];
00033 if (buf) {
00034 memcpy(buf,b.buf,b.len);
00035 len = b.len;
00036 }
00037 }
00038 }
00039
00040
00041 void XrdSutPFBuf::SetBuf(const char *b, kXR_int32 l)
00042 {
00043
00044
00045 len = 0;
00046 if (buf) {
00047 delete[] buf;
00048 buf = 0;
00049 }
00050 if (b && l > 0) {
00051 buf = new char[l];
00052 if (buf) {
00053 memcpy(buf,b,l);
00054 len = l;
00055 }
00056 }
00057 }
00058
00059
00060 XrdSutPFEntry::XrdSutPFEntry(const char *n, short st, short cn,
00061 kXR_int32 mt)
00062 {
00063
00064
00065 name = 0;
00066 status = st;
00067 cnt = cn;
00068 mtime = (mt > 0) ? mt : (kXR_int32)time(0);
00069 if (n) {
00070 name = new char[strlen(n)+1];
00071 if (name)
00072 strcpy(name,n);
00073 }
00074 }
00075
00076
00077 XrdSutPFEntry::XrdSutPFEntry(const XrdSutPFEntry &e) : buf1(e.buf1),
00078 buf2(e.buf2), buf3(e.buf3), buf4(e.buf4)
00079 {
00080
00081
00082 name = 0;
00083 status = e.status;
00084 cnt = e.cnt;
00085 mtime = e.mtime;
00086 if (e.name) {
00087 name = new char[strlen(e.name)+1];
00088 if (name)
00089 strcpy(name,e.name);
00090 }
00091 }
00092
00093
00094 void XrdSutPFEntry::Reset()
00095 {
00096
00097
00098 if (name)
00099 delete[] name;
00100 name = 0;
00101 status = 0;
00102 cnt = 0;
00103 mtime = (kXR_int32)time(0);
00104 buf1.SetBuf();
00105 buf2.SetBuf();
00106 buf3.SetBuf();
00107 buf4.SetBuf();
00108 }
00109
00110
00111 void XrdSutPFEntry::SetName(const char *n)
00112 {
00113
00114
00115 if (name) {
00116 delete[] name;
00117 name = 0;
00118 }
00119 if (n) {
00120 name = new char[strlen(n)+1];
00121 if (name)
00122 strcpy(name,n);
00123 }
00124 }
00125
00126
00127 char *XrdSutPFEntry::AsString() const
00128 {
00129
00130
00131
00132
00133 static char pbuf[2048];
00134
00135 char smt[20] = {0};
00136 XrdSutTimeString(mtime,smt);
00137
00138 sprintf(pbuf,"st:%d cn:%d buf:%d,%d,%d,%d modified:%s name:%s",
00139 status,cnt,buf1.len,buf2.len,buf3.len,buf4.len,smt,name);
00140
00141 return pbuf;
00142 }
00143
00144
00145 XrdSutPFEntry& XrdSutPFEntry::operator=(const XrdSutPFEntry &e)
00146 {
00147
00148
00149 SetName(name);
00150 status = e.status;
00151 cnt = e.cnt;
00152 mtime = e.mtime;
00153 buf1.SetBuf(e.buf1.buf);
00154 buf2.SetBuf(e.buf2.buf);
00155 buf3.SetBuf(e.buf3.buf);
00156 buf4.SetBuf(e.buf4.buf);
00157
00158 return (*this);
00159 }