michael@1: // michael@1: // OSSP asgui - Accounting system graphical user interface michael@1: // Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) michael@1: // Copyright (c) 2002-2004 Ralf S. Engelschall michael@1: // Copyright (c) 2002-2004 Michael Schloh von Bennewitz michael@1: // Copyright (c) 2002-2004 Cable & Wireless Telecommunications Services GmbH michael@1: // michael@1: // This file is part of OSSP asgui, an accounting system graphical user michael@1: // interface which can be found at http://www.ossp.org/pkg/tool/asgui/. michael@1: // michael@1: // Permission to use, copy, modify, and distribute this software for michael@1: // any purpose with or without fee is hereby granted, provided that michael@1: // the above copyright notice and this permission notice appear in all michael@1: // copies. michael@1: // michael@1: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED michael@1: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@1: // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. michael@1: // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR michael@1: // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@1: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@1: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF michael@1: // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND michael@1: // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, michael@1: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT michael@1: // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@1: // SUCH DAMAGE. michael@1: // michael@1: // as_uuid.cpp: ISO C++ implementation michael@1: // michael@1: michael@1: // System headers michael@1: #include michael@1: #include michael@1: michael@1: // Local headers michael@1: #include "as_uuid.h" michael@1: #include "as_rand.h" michael@1: michael@1: // All of these are for detecting michael@1: // the MAC address in setMac() michael@1: #ifdef HAVE_UNISTD_H michael@1: #include michael@1: #endif // HAVE_UNISTD_H michael@1: #ifdef HAVE_SYS_SOCKIO_H michael@1: #include michael@1: #endif // HAVE_SYS_SOCKIO_H michael@1: #ifdef HAVE_NET_IF_H michael@1: #include michael@1: #endif // HAVE_NET_IF_H michael@1: #ifdef HAVE_NETINET_IN_H michael@1: #include michael@1: #endif // HAVE_NETINET_IN_H michael@1: michael@1: michael@1: namespace AS { michael@1: michael@1: // michael@1: // Generate a DCE standard UUID michael@1: // michael@1: void Uuid::genId(void) michael@1: { michael@1: Rand Temprand; // For random numbers michael@1: unsigned char szChardata[16]; // Intermediate data michael@1: michael@1: // Generate random data and fill in our UUID member fields with it michael@1: Temprand.genData(szChardata, sizeof(szChardata)); michael@1: setId(szChardata); michael@1: michael@1: // Since we don't just want random data, lets take some clock sequences also michael@1: this->clock_seq = (this->clock_seq & 0x3FFF) | 0x8000; michael@1: this->time_hi_and_version = (this->time_hi_and_version & 0x0FFF) | 0x4000; michael@1: michael@1: // In every case that we can, set the node ID to the real MAC address michael@1: setMac(this->node); michael@1: michael@1: setString(); // Set the human readable string michael@1: } michael@1: michael@1: // michael@1: // Helper method to set the UUID private member data michael@1: // michael@1: void Uuid::setId(const unsigned char *pkucData) michael@1: { michael@1: const U8 *pOctet = pkucData; michael@1: U32 Tmpdat; michael@1: michael@1: Tmpdat = *pOctet++; // Tmpdat is our iterator michael@1: michael@1: // Copy data chunks one octet at a time michael@1: Tmpdat = (Tmpdat << 8) | *pOctet++; michael@1: Tmpdat = (Tmpdat << 8) | *pOctet++; michael@1: Tmpdat = (Tmpdat << 8) | *pOctet++; michael@1: this->time_low = Tmpdat; michael@1: michael@1: Tmpdat = *pOctet++; michael@1: Tmpdat = (Tmpdat << 8) | *pOctet++; michael@1: this->time_mid = Tmpdat; michael@1: michael@1: Tmpdat = *pOctet++; michael@1: Tmpdat = (Tmpdat << 8) | *pOctet++; michael@1: this->time_hi_and_version = Tmpdat; michael@1: michael@1: Tmpdat = *pOctet++; michael@1: Tmpdat = (Tmpdat << 8) | *pOctet++; michael@1: this->clock_seq = Tmpdat; michael@1: michael@1: // Put in the MAC address michael@1: memcpy(this->node, pOctet, 6); michael@1: } michael@1: michael@1: // michael@1: // Helper method to set up the MAC address node ID member data michael@1: // michael@1: int Uuid::setMac(unsigned char *pucNode) michael@1: { michael@1: return 0; michael@1: } michael@1: michael@1: // michael@1: // Returns a formatted representation of a DCE standard UUID michael@1: // michael@1: std::string Uuid::getString(void) michael@1: { michael@1: return m_Fmtstr; michael@1: } michael@1: michael@1: // michael@1: // Helper method to set the private formatted michael@1: // representation of a DCE standard UUID michael@1: // michael@1: void Uuid::setString(void) michael@1: { michael@1: char szTemp[48]; // To perform intermediate manipulation michael@1: michael@1: sprintf(szTemp, // The DCE standard UUID format michael@1: "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", michael@1: this->time_low, this->time_mid, this->time_hi_and_version, michael@1: this->clock_seq >> 8, this->clock_seq & 0xFF, michael@1: node[0], node[1], node[2], michael@1: node[3], node[4], node[5]); michael@1: michael@1: m_Fmtstr = szTemp; // Finally copy the temporary to our object michael@1: } michael@1: } // namespace AS