"Fossies" - the Fresh Open Source Software Archive

Member "tvnserver-2.0.4/http-server-lib/AppletParameter.cpp" (3 Aug 2011, 2219 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 "AppletParameter.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 "AppletParameter.h"
   26 
   27 #include "util/CommonHeader.h"
   28 
   29 #include <crtdbg.h>
   30 
   31 AppletParameter::AppletParameter(const char *name, const char *value)
   32 : m_isValid(false), m_formattedString(NULL)
   33 {
   34   _ASSERT(name != NULL);
   35   _ASSERT(value != NULL);
   36 
   37   m_isValid = isStringValid(name) && isStringValid(value);
   38 
   39   if (isValid()) {
   40     const char *format = "<PARAM NAME=\"%s\" VALUE=\"%s\" >\n";
   41 
   42     int len = _scprintf(format, name, value) + 1;
   43 
   44     m_formattedString = new char[len];
   45 
   46     sprintf_s(m_formattedString, (size_t)(len), format, name, value);
   47   }
   48 }
   49 
   50 AppletParameter::~AppletParameter()
   51 {
   52   if (m_formattedString != NULL) {
   53     delete[] m_formattedString;
   54   }
   55 }
   56 
   57 const char *AppletParameter::getFormattedString() const
   58 {
   59   return m_formattedString;
   60 }
   61 
   62 bool AppletParameter::isValid() const
   63 {
   64   return m_isValid;
   65 }
   66 
   67 bool AppletParameter::isStringValid(const char *str) const
   68 {
   69   for (size_t i = 0; i < strlen(str); i++) {
   70     if (!(isalnum(str[i]) || str[i] == '_' || str[i] == '.' || str[i] == ' ')) {
   71       return false;
   72     } 
   73   } 
   74 
   75   return true;
   76 }