"Fossies" - the Fresh Open Source Software Archive

Member "tvnserver-2.0.4/server-config-lib/PortMapping.cpp" (3 Aug 2011, 2797 Bytes) of archive /windows/misc/tvnserver-2.0.4-src.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PortMapping.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2008, 2009, 2010 GlavSoft LLC.
    2 // All rights reserved.
    3 //
    4 //-------------------------------------------------------------------------
    5 // This file is part of the TightVNC software.  Please visit our Web site:
    6 //
    7 //                       http://www.tightvnc.com/
    8 //
    9 // This program is free software; you can redistribute it and/or modify
   10 // it under the terms of the GNU General Public License as published by
   11 // the Free Software Foundation; either version 2 of the License, or
   12 // (at your option) any later version.
   13 //
   14 // This program is distributed in the hope that it will be useful,
   15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17 // GNU General Public License for more details.
   18 //
   19 // You should have received a copy of the GNU General Public License along
   20 // with this program; if not, write to the Free Software Foundation, Inc.,
   21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   22 //-------------------------------------------------------------------------
   23 //
   24 
   25 #include "PortMapping.h"
   26 #include "util/StringParser.h"
   27 
   28 #include <tchar.h>
   29 #include <stdio.h>
   30 
   31 PortMapping::PortMapping()
   32 : m_port(0)
   33 {
   34 }
   35 
   36 PortMapping::PortMapping(int nport, PortMappingRect nrect)
   37 : m_port(nport), m_rect(nrect)
   38 {
   39 }
   40 
   41 PortMapping::PortMapping(const PortMapping &other)
   42 : m_port(other.m_port), m_rect(other.m_rect)
   43 {
   44 }
   45 
   46 PortMapping::~PortMapping()
   47 {
   48 }
   49 
   50 PortMapping &PortMapping::operator=(const PortMapping &other)
   51 {
   52   m_port = other.m_port;
   53   m_rect = other.m_rect;
   54   return *this;
   55 }
   56 
   57 bool PortMapping::isEqualTo(const PortMapping *other) const
   58 {
   59   return other->m_port == m_port && other->m_rect.isEqualTo(&m_rect);
   60 }
   61 
   62 void PortMapping::setPort(int nport)
   63 {
   64   m_port = nport;
   65 }
   66 
   67 void PortMapping::setRect(PortMappingRect nrect)
   68 {
   69   m_rect = nrect;
   70 }
   71 
   72 int PortMapping::getPort() const
   73 {
   74   return m_port;
   75 }
   76 
   77 PortMappingRect PortMapping::getRect() const
   78 {
   79   return m_rect;
   80 }
   81 
   82 void PortMapping::toString(StringStorage *string) const
   83 {
   84 
   85   StringStorage rectString;
   86   m_rect.toString(&rectString);
   87 
   88   string->format(_T("%d:%s"), m_port, rectString.getString());
   89 }
   90 
   91 bool PortMapping::parse(const TCHAR *str, PortMapping *mapping)
   92 {
   93   int port;
   94   TCHAR c;
   95   PortMappingRect rect;
   96   const TCHAR *rectString = _tcschr(str, _T(':')) + 1;
   97   if (rectString == NULL) {
   98     return false;
   99   }
  100   if ((_stscanf(str, _T("%d%c"), &port, &c) != 2) || (c != _T(':'))) {
  101     return false;
  102   }
  103   if (port < 0) {
  104     return false;
  105   }
  106   if (!PortMappingRect::parse(rectString, &rect)) {
  107     return false;
  108   }
  109   if (mapping != NULL) {
  110     mapping->setPort(port);
  111     mapping->setRect(rect);
  112   }
  113   return true;
  114 }