XrdSecProtocolsslProc.cc

Go to the documentation of this file.
00001 //          $Id: XrdSecProtocolsslProc.cc 38011 2011-02-08 18:35:57Z ganis $
00002 
00003 #include "XrdSecssl/XrdSecProtocolsslProc.hh"
00004 #include <string.h>
00005 
00006 bool
00007 XrdSecProtocolsslProcFile::Open() {
00008   if (procsync) {
00009     fd = open(fname.c_str(),O_CREAT| O_SYNC|O_RDWR, S_IRWXU | S_IROTH | S_IRGRP );
00010   } else {
00011     fd = open(fname.c_str(),O_CREAT|O_RDWR, S_IRWXU | S_IROTH | S_IRGRP);
00012   }
00013 
00014   if (fd<0) {
00015     return false;
00016   }
00017   return true;
00018 }
00019 
00020 bool 
00021 XrdSecProtocolsslProcFile::Write(long long val, int writedelay) {
00022   char pbuf[1024];
00023   sprintf(pbuf,"%lld\n",val);
00024   return Write(pbuf,writedelay);
00025 }
00026 
00027 bool 
00028 XrdSecProtocolsslProcFile::Write(double val, int writedelay) {
00029   char pbuf[1024];
00030   sprintf(pbuf,"%.02f\n",val);
00031   return Write(pbuf,writedelay);
00032 }
00033 
00034 bool 
00035 XrdSecProtocolsslProcFile::Write(const char* pbuf, int writedelay) {
00036   time_t now = time(NULL);
00037   if (writedelay) { 
00038 
00039     if (now-lastwrite <writedelay) {
00040       return true;
00041     }
00042   }
00043 
00044   int result;
00045   lseek(fd,0,SEEK_SET);
00046   while ( (result=::ftruncate(fd,0)) && (errno == EINTR ) ) {}
00047   lastwrite = now;
00048   if ( (write(fd,pbuf,strlen(pbuf))) == (int)(strlen(pbuf))) {
00049     return true;
00050   } else {
00051     return false;
00052   }
00053 }
00054 
00055 bool
00056 XrdSecProtocolsslProcFile::WriteKeyVal(const char* key, unsigned long long value, int writedelay, bool dotruncate) {
00057   if (dotruncate) {
00058     time_t now = time(NULL);
00059     if (writedelay) {
00060       
00061       if (now-lastwrite <writedelay) {
00062         return false;
00063       }
00064     }
00065 
00066     //    printf("Truncating FD %d for %s\n",fd,key);
00067     lseek(fd,0,SEEK_SET);
00068     while ( (::ftruncate(fd,0)) && (errno == EINTR ) ) {}
00069     lastwrite = now;
00070   }
00071   char pbuf[1024];
00072   sprintf(pbuf,"%u %-32s %lld\n",(unsigned int)time(NULL),key,value);
00073   if ( (write(fd,pbuf,strlen(pbuf))) == (int)(strlen(pbuf))) {
00074     return true;
00075   } else {
00076     return false;
00077   }
00078 }
00079 
00080 long long
00081 XrdSecProtocolsslProcFile::Read() {
00082   char pbuf[1024];
00083   lseek(fd,0,SEEK_SET);
00084   ssize_t rb = read(fd,pbuf,sizeof(pbuf));
00085   if (rb<=0) 
00086     return -1;
00087 
00088   return strtoll(pbuf,(char**)NULL,10);
00089 }
00090 
00091 bool 
00092 XrdSecProtocolsslProcFile::Read(XrdOucString &str) {
00093   char pbuf[1024];
00094   pbuf[0] = 0;
00095   lseek(fd,0,SEEK_SET);
00096   ssize_t rb = read(fd,pbuf,sizeof(pbuf));
00097   str = pbuf;
00098   if (rb<=0)
00099     return false;
00100   else
00101     return true;
00102 }
00103 
00104 XrdSecProtocolsslProcFile*
00105 XrdSecProtocolsslProc::Handle(const char* name) {
00106   XrdSecProtocolsslProcFile* phandle=0;
00107   if (( phandle = files.Find(name))) {
00108     return phandle;
00109   } else {
00110     XrdOucString pfname=procdirectory;
00111     pfname += "/";
00112     pfname += name;
00113     phandle = new XrdSecProtocolsslProcFile(pfname.c_str());
00114     if (phandle && phandle->Open()) {
00115       files.Add(name,phandle);
00116       return phandle;
00117     }
00118   }
00119   return NULL;
00120 }
00121 
00122 

Generated on Tue Jul 5 14:47:01 2011 for ROOT_528-00b_version by  doxygen 1.5.1