• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/DcFileAttrib.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 /**
00021  * CdcFileAttrib.cpp: implementation of the CdcFileAttrib class.
00022  * for documentation see the header file.
00023  */
00024 
00025 #include "DcFileAttrib.h"
00026 
00027 void CdcFileAttrib::Attach (const CdcFileAttrib& fa)
00028 {
00029     /* Copy values. */
00030     pInnerData = fa.pInnerData;
00031     pRefCount = fa.pRefCount;
00032     /* Increase reference. */
00033     if (pRefCount != NULL)
00034         (*pRefCount)++;
00035 }
00036 
00037 
00038 void CdcFileAttrib::Detach ()
00039 {
00040     /* Decrease reference counter and delete data if needed. */
00041     if (pRefCount != NULL && --(*pRefCount) == 0)
00042     {
00043         if (pInnerData != NULL)
00044         {
00045             delete pInnerData;
00046             pInnerData = NULL;
00047         }
00048         delete pRefCount;
00049         pRefCount = NULL;
00050     }
00051 }
00052 
00053 
00054 const CdcFileAttrib& CdcFileAttrib::operator = (const CdcFileAttrib& fa)
00055 {
00056     if (pInnerData != fa.pInnerData)
00057     {
00058         Detach ();
00059         Attach (fa);
00060     }
00061 
00062     return *this;
00063 }
00064 
00065 
00066 CdcFileAttrib::CdcFileAttrib (const CdcString& url, const CdcString& host, bool inc)
00067 {
00068     pRefCount = new int (1);
00069     pInnerData = new CdcFileAttribInnerData ();
00070     if (pInnerData == NULL)
00071         throw (CdcException ("Out of memory!"));
00072 
00073     pInnerData->isFound = false;
00074     pInnerData->isRedirect = false;
00075 
00076     /* Parse the url string. */
00077     pInnerData->sURL = url;
00078     /* Protect from going up the diractory tree. */
00079     if (pInnerData->sURL.Find ("../") != -1)
00080         return;
00081     /* Check file extension. */
00082     int dot = pInnerData->sURL.ReverseFind ('.');
00083     if (dot == -1 && pInnerData->sURL[pInnerData->sURL.GetLength () - 1] != '/')
00084     {   /* Need to redirect */
00085         pInnerData->isRedirect = true;
00086         pInnerData->sURL += '/';
00087     }
00088     else if (dot == -1)
00089     {    /* Default file (no file name). */
00090         pInnerData->sURL += CdcParameters::GetParam ("Server->Hosts->" +
00091             host + "->Default-File");
00092         dot = pInnerData->sURL.ReverseFind ('.');
00093     }
00094     if (dot == -1) return;
00095     pInnerData->sFileExtention = pInnerData->sURL.Mid (dot + 1);
00096     pInnerData->sFileExtention.MakeLower ();
00097 
00098     /* Check if host is in the allow list. */
00099     CdcString allow_host = CdcParameters::GetParam (
00100         "Server->File-Types->" + pInnerData->sFileExtention + "->Allow-Host");
00101      if (allow_host.Find ("all") != -1 || allow_host.Find (host) != -1 ||
00102         (inc == true && allow_host.Find ("inc") != -1))
00103      {
00104          CdcString host_root = CdcParameters::GetParam (
00105             "Server->Hosts->" + host + "->Root");
00106         pInnerData->sFullName = CdcFileUtil::GetWorkPath(host_root) + '/' +
00107             pInnerData->sURL;
00108         pInnerData->sFullName.Replace ('/', '\\');
00109         pInnerData->sFullName.Replace ("\\\\", '\\');
00110         pInnerData->isFound = pInnerData->oFileStatus.OpenFile (
00111             pInnerData->sFullName);
00112     }
00113 }
00114 

Generated on Mon Oct 11 2010 16:23:23 for Beesnest by  doxygen 1.7.2