Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "DcFileAttrib.h"
00026
00027 void CdcFileAttrib::Attach (const CdcFileAttrib& fa)
00028 {
00029
00030 pInnerData = fa.pInnerData;
00031 pRefCount = fa.pRefCount;
00032
00033 if (pRefCount != NULL)
00034 (*pRefCount)++;
00035 }
00036
00037
00038 void CdcFileAttrib::Detach ()
00039 {
00040
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
00077 pInnerData->sURL = url;
00078
00079 if (pInnerData->sURL.Find ("../") != -1)
00080 return;
00081
00082 int dot = pInnerData->sURL.ReverseFind ('.');
00083 if (dot == -1 && pInnerData->sURL[pInnerData->sURL.GetLength () - 1] != '/')
00084 {
00085 pInnerData->isRedirect = true;
00086 pInnerData->sURL += '/';
00087 }
00088 else if (dot == -1)
00089 {
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
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