File indexing completed on 2025-01-05 04:37:19

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "portlist.h"
0007 #include <QtAlgorithms>
0008 
0009 namespace net
0010 {
0011 Port::Port()
0012     : number(0)
0013     , proto(TCP)
0014     , forward(false)
0015 {
0016 }
0017 
0018 Port::Port(bt::Uint16 number, Protocol proto, bool forward)
0019     : number(number)
0020     , proto(proto)
0021     , forward(forward)
0022 {
0023 }
0024 
0025 Port::Port(const Port &p)
0026     : number(p.number)
0027     , proto(p.proto)
0028     , forward(p.forward)
0029 {
0030 }
0031 
0032 bool Port::operator==(const Port &p) const
0033 {
0034     return number == p.number && proto == p.proto;
0035 }
0036 
0037 PortList::PortList()
0038     : lst(nullptr)
0039 {
0040 }
0041 
0042 PortList::~PortList()
0043 {
0044 }
0045 
0046 void PortList::addNewPort(bt::Uint16 number, Protocol proto, bool forward)
0047 {
0048     Port p = Port(number, proto, forward);
0049     append(p);
0050     if (lst)
0051         lst->portAdded(p);
0052 }
0053 
0054 void PortList::removePort(bt::Uint16 number, Protocol proto)
0055 {
0056     PortList::iterator itr = std::find(begin(), end(), Port(number, proto, false));
0057     if (itr == end())
0058         return;
0059 
0060     if (lst)
0061         lst->portRemoved(*itr);
0062 
0063     erase(itr);
0064 }
0065 
0066 }