as_uuid.cpp

Thu, 06 Aug 2009 13:21:30 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 06 Aug 2009 13:21:30 +0200
changeset 15
0e0eb7c91312
parent 3
c1941114ca88
permissions
-rw-r--r--

Remove seemingly declarations unnecessary according to Qt 4.5.2 headers.

michael@1 1 //
michael@1 2 // OSSP asgui - Accounting system graphical user interface
michael@12 3 // Copyright (c) 2002-2009 The OSSP Project (http://www.ossp.org/)
michael@12 4 // Copyright (c) 2002-2009 Ralf S. Engelschall <rse@engelschall.com>
michael@12 5 // Copyright (c) 2002-2009 Michael Schloh von Bennewitz <michael@schloh.com>
michael@12 6 // Copyright (c) 2002-2009 Cable & Wireless Telecommunications Services GmbH
michael@1 7 //
michael@1 8 // This file is part of OSSP asgui, an accounting system graphical user
michael@3 9 // interface which can be found at http://asgui.europalab.com/.
michael@1 10 //
michael@1 11 // Permission to use, copy, modify, and distribute this software for
michael@1 12 // any purpose with or without fee is hereby granted, provided that
michael@1 13 // the above copyright notice and this permission notice appear in all
michael@1 14 // copies.
michael@1 15 //
michael@1 16 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
michael@1 17 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@1 18 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@1 19 // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@1 20 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@1 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@1 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@1 23 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@1 24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@1 25 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@1 26 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@1 27 // SUCH DAMAGE.
michael@1 28 //
michael@1 29 // as_uuid.cpp: ISO C++ implementation
michael@1 30 //
michael@1 31
michael@1 32 // System headers
michael@1 33 #include <string>
michael@1 34 #include <sys/socket.h>
michael@1 35
michael@1 36 // Local headers
michael@1 37 #include "as_uuid.h"
michael@1 38 #include "as_rand.h"
michael@1 39
michael@1 40 // All of these are for detecting
michael@1 41 // the MAC address in setMac()
michael@1 42 #ifdef HAVE_UNISTD_H
michael@1 43 #include <unistd.h>
michael@1 44 #endif // HAVE_UNISTD_H
michael@1 45 #ifdef HAVE_SYS_SOCKIO_H
michael@1 46 #include <sys/sockio.h>
michael@1 47 #endif // HAVE_SYS_SOCKIO_H
michael@1 48 #ifdef HAVE_NET_IF_H
michael@1 49 #include <net/if.h>
michael@1 50 #endif // HAVE_NET_IF_H
michael@1 51 #ifdef HAVE_NETINET_IN_H
michael@1 52 #include <netinet/in.h>
michael@1 53 #endif // HAVE_NETINET_IN_H
michael@1 54
michael@1 55
michael@1 56 namespace AS {
michael@1 57
michael@1 58 //
michael@1 59 // Generate a DCE standard UUID
michael@1 60 //
michael@1 61 void Uuid::genId(void)
michael@1 62 {
michael@1 63 Rand Temprand; // For random numbers
michael@1 64 unsigned char szChardata[16]; // Intermediate data
michael@1 65
michael@1 66 // Generate random data and fill in our UUID member fields with it
michael@1 67 Temprand.genData(szChardata, sizeof(szChardata));
michael@1 68 setId(szChardata);
michael@1 69
michael@1 70 // Since we don't just want random data, lets take some clock sequences also
michael@1 71 this->clock_seq = (this->clock_seq & 0x3FFF) | 0x8000;
michael@1 72 this->time_hi_and_version = (this->time_hi_and_version & 0x0FFF) | 0x4000;
michael@1 73
michael@1 74 // In every case that we can, set the node ID to the real MAC address
michael@1 75 setMac(this->node);
michael@1 76
michael@1 77 setString(); // Set the human readable string
michael@1 78 }
michael@1 79
michael@1 80 //
michael@1 81 // Helper method to set the UUID private member data
michael@1 82 //
michael@1 83 void Uuid::setId(const unsigned char *pkucData)
michael@1 84 {
michael@1 85 const U8 *pOctet = pkucData;
michael@1 86 U32 Tmpdat;
michael@1 87
michael@1 88 Tmpdat = *pOctet++; // Tmpdat is our iterator
michael@1 89
michael@1 90 // Copy data chunks one octet at a time
michael@1 91 Tmpdat = (Tmpdat << 8) | *pOctet++;
michael@1 92 Tmpdat = (Tmpdat << 8) | *pOctet++;
michael@1 93 Tmpdat = (Tmpdat << 8) | *pOctet++;
michael@1 94 this->time_low = Tmpdat;
michael@1 95
michael@1 96 Tmpdat = *pOctet++;
michael@1 97 Tmpdat = (Tmpdat << 8) | *pOctet++;
michael@1 98 this->time_mid = Tmpdat;
michael@1 99
michael@1 100 Tmpdat = *pOctet++;
michael@1 101 Tmpdat = (Tmpdat << 8) | *pOctet++;
michael@1 102 this->time_hi_and_version = Tmpdat;
michael@1 103
michael@1 104 Tmpdat = *pOctet++;
michael@1 105 Tmpdat = (Tmpdat << 8) | *pOctet++;
michael@1 106 this->clock_seq = Tmpdat;
michael@1 107
michael@1 108 // Put in the MAC address
michael@1 109 memcpy(this->node, pOctet, 6);
michael@1 110 }
michael@1 111
michael@1 112 //
michael@1 113 // Helper method to set up the MAC address node ID member data
michael@1 114 //
michael@1 115 int Uuid::setMac(unsigned char *pucNode)
michael@1 116 {
michael@1 117 return 0;
michael@1 118 }
michael@1 119
michael@1 120 //
michael@1 121 // Returns a formatted representation of a DCE standard UUID
michael@1 122 //
michael@1 123 std::string Uuid::getString(void)
michael@1 124 {
michael@1 125 return m_Fmtstr;
michael@1 126 }
michael@1 127
michael@1 128 //
michael@1 129 // Helper method to set the private formatted
michael@1 130 // representation of a DCE standard UUID
michael@1 131 //
michael@1 132 void Uuid::setString(void)
michael@1 133 {
michael@1 134 char szTemp[48]; // To perform intermediate manipulation
michael@1 135
michael@1 136 sprintf(szTemp, // The DCE standard UUID format
michael@1 137 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
michael@1 138 this->time_low, this->time_mid, this->time_hi_and_version,
michael@1 139 this->clock_seq >> 8, this->clock_seq & 0xFF,
michael@1 140 node[0], node[1], node[2],
michael@1 141 node[3], node[4], node[5]);
michael@1 142
michael@1 143 m_Fmtstr = szTemp; // Finally copy the temporary to our object
michael@1 144 }
michael@1 145 } // namespace AS

mercurial