[5284] | 1 | /// ----------------------------------------*- mode: C++; -*--
|
---|
| 2 | /// @file connectionmap_uds.h
|
---|
| 3 | /// maintains connection mapping of application addresses to
|
---|
| 4 | /// UNIX domain sockets and vice versa
|
---|
| 5 | /// ----------------------------------------------------------
|
---|
| 6 | /// $Id: connectionmap_uds.h 2549 2007-04-02 22:17:37Z bless $
|
---|
| 7 | /// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/include/connectionmap_uds.h $
|
---|
| 8 | // ===========================================================
|
---|
| 9 | //
|
---|
| 10 | // Copyright (C) 2005-2007, all rights reserved by
|
---|
| 11 | // - Institute of Telematics, Universitaet Karlsruhe (TH)
|
---|
| 12 | //
|
---|
| 13 | // More information and contact:
|
---|
| 14 | // https://projekte.tm.uka.de/trac/NSIS
|
---|
| 15 | //
|
---|
| 16 | // This program is free software; you can redistribute it and/or modify
|
---|
| 17 | // it under the terms of the GNU General Public License as published by
|
---|
| 18 | // the Free Software Foundation; version 2 of the License
|
---|
| 19 | //
|
---|
| 20 | // This program is distributed in the hope that it will be useful,
|
---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 23 | // GNU General Public License for more details.
|
---|
| 24 | //
|
---|
| 25 | // You should have received a copy of the GNU General Public License along
|
---|
| 26 | // with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
| 27 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
| 28 | //
|
---|
| 29 | // ===========================================================
|
---|
| 30 | #ifndef CONNECTION_MAP_UDS_H
|
---|
| 31 | #define CONNECTION_MAP_UDS_H
|
---|
| 32 |
|
---|
| 33 | #include "assocdata_uds.h"
|
---|
| 34 | #include <ext/hash_map>
|
---|
| 35 |
|
---|
| 36 | namespace protlib {
|
---|
| 37 |
|
---|
| 38 | /* @class ConnectionMap
|
---|
| 39 | * maintains connection mapping of application addresses to sockets and vice versa
|
---|
| 40 | * @ingroup network
|
---|
| 41 | * @{
|
---|
| 42 | */
|
---|
| 43 | class ConnectionMapUDS {
|
---|
| 44 | public:
|
---|
| 45 | // a constructor may be needed here in this class
|
---|
| 46 | /// Insert a new AssocDataUDS element into the ConnectionMapUDS
|
---|
| 47 | bool insert(AssocDataUDS* assoc);
|
---|
| 48 | /// Search for existing connections to this specific socket
|
---|
| 49 | AssocDataUDS* lookup(socketfd_t socketfd) const;
|
---|
| 50 | /// Search for existing connections to this specific assoc id
|
---|
| 51 | AssocDataUDS* lookup(associd_t associd) const;
|
---|
| 52 | ///Search for existing connections to this address
|
---|
| 53 | AssocDataUDS* lookup(const udsaddress& addr) const;
|
---|
| 54 | /// Erase the AssocDataUDS-element associated with this socket
|
---|
| 55 | bool erase(socketfd_t socketfd);
|
---|
| 56 | /// Erase the AssocDataUDS-element associated with this socket
|
---|
| 57 | bool erase(associd_t associd);
|
---|
| 58 | /// Erase the AssocDataUDS-element
|
---|
| 59 | bool erase(AssocDataUDS* assoc);
|
---|
| 60 | /// clear all
|
---|
| 61 | void clear();
|
---|
| 62 | /// get number of records
|
---|
| 63 | size_t get_size() const;
|
---|
| 64 | private:
|
---|
| 65 | // this hash_map uses the standard hashfunction on the first entry, int
|
---|
| 66 |
|
---|
| 67 | // only typedefs
|
---|
| 68 | typedef hash_map<socketfd_t ,AssocDataUDS*> ass2data_t;
|
---|
| 69 | typedef ass2data_t::const_iterator const_ass2data_it_t;
|
---|
| 70 | typedef hash_map<udsaddress,AssocDataUDS*> addr2data_t;
|
---|
| 71 | typedef addr2data_t::const_iterator const_addr2data_it_t;
|
---|
| 72 |
|
---|
| 73 | // internal hashmaps
|
---|
| 74 | ass2data_t ass2data; ///< map: socket fd to association data
|
---|
| 75 | addr2data_t addr2data; ///< map: (application) address to association data
|
---|
| 76 | public:
|
---|
| 77 | /// connection map iterator
|
---|
| 78 | typedef const_ass2data_it_t const_it_t;
|
---|
| 79 | const_it_t begin() const;
|
---|
| 80 | const_it_t end() const;
|
---|
| 81 | }; // end class ConnectionMapUDS
|
---|
| 82 |
|
---|
| 83 | inline
|
---|
| 84 | size_t
|
---|
| 85 | ConnectionMapUDS::get_size() const { return ass2data.size(); }
|
---|
| 86 |
|
---|
| 87 | inline
|
---|
| 88 | ConnectionMapUDS::const_it_t ConnectionMapUDS::begin() const {
|
---|
| 89 | return ass2data.begin();
|
---|
| 90 | } // end begin
|
---|
| 91 |
|
---|
| 92 | inline
|
---|
| 93 | ConnectionMapUDS::const_it_t ConnectionMapUDS::end() const {
|
---|
| 94 | return ass2data.end();
|
---|
| 95 | } // end end
|
---|
| 96 |
|
---|
| 97 | inline
|
---|
| 98 | bool
|
---|
| 99 | ConnectionMapUDS::erase(AssocDataUDS* assoc) {
|
---|
| 100 | return assoc ? erase(assoc->socketfd) : false;
|
---|
| 101 | } // end erase
|
---|
| 102 |
|
---|
| 103 | //@}
|
---|
| 104 |
|
---|
| 105 | } // end namespace protlib
|
---|
| 106 | #endif
|
---|