XrdMonDecUserInfo.cc

Go to the documentation of this file.
00001 
00002 /*****************************************************************************/
00003 /*                                                                           */
00004 /*                           XrdMonDecUserInfo.cc                            */
00005 /*                                                                           */
00006 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
00007 /*                            All Rights Reserved                            */
00008 /*       Produced by Jacek Becla for Stanford University under contract      */
00009 /*              DE-AC02-76SF00515 with the Department of Energy              */
00010 /*****************************************************************************/
00011 
00012 // $Id: XrdMonDecUserInfo.cc 22437 2008-03-04 14:35:16Z rdm $
00013 
00014 #include "XrdMon/XrdMonException.hh"
00015 #include "XrdMon/XrdMonDecUserInfo.hh"
00016 #include "XrdMon/XrdMonErrors.hh"
00017 #include "XrdMon/XrdMonSenderInfo.hh"
00018 #include "XrdMon/XrdMonUtils.hh"
00019 #include "XrdMon/XrdMonDecTraceInfo.hh"
00020 #include "XrdSys/XrdSysPlatform.hh"
00021 #include <netinet/in.h>
00022 #include <stdio.h>
00023 #include <sys/time.h>
00024 
00025 using std::cout;
00026 using std::cerr;
00027 using std::endl;
00028 
00029 XrdMonDecUserInfo::XrdMonDecUserInfo()
00030     : _myXrdId(0),
00031       _myUniqueId(0),
00032       _user("InvalidUser"),
00033       _pid(-1),
00034       _cHost("InvalidHost"),
00035       _senderId(INVALID_SENDER_ID),
00036       _sec(0),
00037       _dTime(0)
00038 {}
00039 
00040 XrdMonDecUserInfo::XrdMonDecUserInfo(dictid_t id,
00041                                      dictid_t uniqueId,
00042                                      const char* s, 
00043                                      int len,
00044                                      senderid_t senderId)
00045     : _myXrdId(id),
00046       _myUniqueId(uniqueId),
00047       _senderId(senderId),
00048       _sec(0),
00049       _dTime(0)
00050 {
00051     // uncomment all 3 below if you want to print the string
00052     //char*b = new char [len+1];strncpy(b, s, len);b[len] = '\0';
00053     //cout << "Decoding string in UserInfo " << b << endl;
00054     //delete [] b;
00055     
00056     // decode theString, format: <user>.<pid>:<fd>@<host>
00057     int x1 = 0, x2 = 0;
00058     char* buf = new char [len+1];
00059 
00060     x1 = doOne(s, buf, len, '.');
00061     if (x1 == -1 ) {
00062         delete [] buf;
00063         string es("Cannot find "); es+='.'; es+=" in "; es+=s;
00064         throw XrdMonException(ERR_INVDICTSTRING, es);
00065     }
00066     _user = (x1 != 0 ? buf : "unknown");
00067 
00068     x2 += x1+1;
00069     x1 = doOne(s+x2, buf, len-x2, ':');
00070     if ( x1 == -1 ) {
00071         delete [] buf;
00072         string es("Cannot find "); es+=':'; es+=" in "; es+=s;
00073         throw XrdMonException(ERR_INVDICTSTRING, es);
00074     }
00075     _pid = atoi(buf);
00076 
00077     x2 += x1+1;
00078     x1 = doOne(s+x2, buf, len-x2, '@');
00079     if ( x1 == -1 ) {
00080         delete [] buf;
00081         string es("Cannot find "); es+='@'; es+=" in "; es+=s;
00082         throw XrdMonException(ERR_INVDICTSTRING, es);
00083     }
00084     //kXR_int16 fd = atoi(buf);
00085 
00086     x2 += x1+1;
00087     memcpy(buf, s+x2, len-x2);
00088     *(buf+len-x2) = '\0';
00089     _cHost = buf;
00090 
00091     delete [] buf;
00092 }
00093 
00094 void
00095 XrdMonDecUserInfo::setDisconnectInfo(kXR_int32 sec,
00096                                      kXR_int32 timestamp)
00097 {
00098     _sec   = sec;
00099     _dTime = timestamp;
00100 }
00101 
00102 // this goes to history data ascii file
00103 const char*
00104 XrdMonDecUserInfo::convert2string() const
00105 {
00106     static char buf[512];
00107     char tBuf[24];
00108     timestamp2string(_dTime, tBuf, GMT);
00109     
00110     sprintf(buf, "%s\t%i\t%s\t%i\t%s\t%s\n", 
00111             _user.c_str(), _pid, _cHost.c_str(), 
00112             _sec, tBuf, XrdMonSenderInfo::id2Host(_senderId));
00113 
00114     return buf;
00115 }
00116 
00117 int
00118 XrdMonDecUserInfo::mySize()
00119 {
00120     return sizeof(*this) + _user.size() + _cHost.size();
00121 }
00122 
00123 // this goes to real time log file
00124 const char*
00125 XrdMonDecUserInfo::writeRT2Buffer(TYPE t) const
00126 {
00127     static char buf[512];
00128     
00129     if ( t == CONNECT ) {
00130         struct timeval tv;
00131         gettimeofday(&tv, 0);
00132         static char timeNow[24];
00133         timestamp2string(tv.tv_sec, timeNow, GMT);
00134         sprintf(buf, "u\t%i\t%s\t%i\t%s\t%s\t%s\n", 
00135                 _myUniqueId, _user.c_str(), _pid, _cHost.c_str(), 
00136                 XrdMonSenderInfo::id2Host(_senderId), timeNow);
00137     } else {
00138         static char b[24];
00139         timestamp2string(_dTime, b, GMT);
00140         sprintf(buf, "d\t%i\t%i\t%s\n", _myUniqueId, _sec, b);
00141     }
00142     return buf;
00143 }
00144 
00145 // this is for debugging
00146 ostream& 
00147 operator<<(ostream& o, const XrdMonDecUserInfo& m)
00148 {
00149    o << ' ' << m._myXrdId
00150      << ' ' << m._myUniqueId
00151      << ' ' << m._user
00152      << ' ' << m._pid
00153      << ' ' << m._cHost
00154      << ' ' << m._senderId 
00155      << " (" << XrdMonSenderInfo::id2Host(m._senderId) << ")";
00156       
00157     return o;
00158 }

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