ServerPath.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. // ServerPath.cpp: Implementierung der Klasse CServerPath.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ServerPath.h"
  19. #include "structures.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char THIS_FILE[]=__FILE__;
  23. #define new DEBUG_NEW
  24. #endif
  25. #define FTP_MVS_DOUBLE_QUOTA (TCHAR)0xDC
  26. //////////////////////////////////////////////////////////////////////
  27. // Konstruktion/Destruktion
  28. //////////////////////////////////////////////////////////////////////
  29. CServerPath::CServerPath()
  30. {
  31. m_nServerType = 0;
  32. m_bEmpty = TRUE;
  33. }
  34. CServerPath::CServerPath(int nServerType)
  35. {
  36. m_nServerType = nServerType;
  37. m_bEmpty = TRUE;
  38. }
  39. CServerPath::CServerPath(CString path)
  40. {
  41. m_nServerType = FZ_SERVERTYPE_FTP;
  42. path.TrimLeft( _T(" ") );
  43. path.TrimRight( _T(" ") );
  44. if (path == _MPT(""))
  45. {
  46. m_bEmpty = TRUE;
  47. return;
  48. }
  49. else
  50. m_bEmpty = FALSE;
  51. int pos1 = path.Find( _T(":[") );
  52. if (pos1 != -1 && path.Right(1) == _MPT("]") && pos1 != (path.GetLength()-1))
  53. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_VMS;
  54. else if (path.GetLength() >= 3 && _istalpha(path[0]) && path[1] == _MPT(':') && (path[2] == _MPT('\\') || path[2] == _MPT('/')))
  55. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
  56. else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
  57. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  58. else if (path.GetLength() > 2 && path[0] == _MPT('\'') && path.Right(1) == _T("'") && path.Find(_MPT('/')) == -1 && path.Find(_MPT('\\')) == -1)
  59. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  60. else if (path.GetLength() >= 2 && path[0] != _MPT('/') && path.Right(1) == _T("."))
  61. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_UNKNOWN;
  62. *this = CServerPath(path, m_nServerType);
  63. }
  64. CServerPath::CServerPath(CString path, int nServerType)
  65. {
  66. m_nServerType = nServerType;
  67. path.TrimLeft( _T(" ") );
  68. path.TrimRight( _T(" ") );
  69. if (path == _MPT(""))
  70. {
  71. m_bEmpty = TRUE;
  72. return;
  73. }
  74. else
  75. m_bEmpty = FALSE;
  76. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  77. {
  78. case FZ_SERVERTYPE_FTP:
  79. switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
  80. {
  81. case FZ_SERVERTYPE_SUB_FTP_MVS:
  82. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  83. {
  84. path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  85. path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  86. path.TrimLeft(_MPT('\''));
  87. path.TrimRight(_MPT('\''));
  88. path.TrimLeft(_MPT('.'));
  89. while (path.Replace(_T(".."), _T(".")));
  90. int pos = path.Find(_T("."));
  91. while (pos != -1)
  92. {
  93. m_Segments.push_back(path.Left(pos));
  94. path = path.Mid(pos + 1);
  95. pos = path.Find( _T(".") );
  96. }
  97. if (path != _T(""))
  98. m_Segments.push_back(path);
  99. else
  100. m_Prefix = _T(".");
  101. }
  102. break;
  103. case FZ_SERVERTYPE_SUB_FTP_VMS:
  104. {
  105. int pos1 = path.Find( _T("[") );
  106. if (pos1 == -1 || path.Right(1) != _T("]"))
  107. {
  108. ASSERT(FALSE);
  109. m_bEmpty = TRUE;
  110. return;
  111. }
  112. path.TrimRight( _T("]") );
  113. if (pos1)
  114. m_Prefix = path.Left(pos1);
  115. path = path.Mid(pos1 + 1);
  116. int pos = path.Find( _T(".") );
  117. while (pos != -1)
  118. {
  119. m_Segments.push_back(path.Left(pos));
  120. path = path.Mid(pos+1);
  121. pos = path.Find( _T(".") );
  122. }
  123. if (path != _MPT(""))
  124. m_Segments.push_back(path);
  125. }
  126. break;
  127. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  128. while (path.Replace(_MPT('.'), _MPT('/')));
  129. default:
  130. path.Replace( _T("\\"), _T("/") );
  131. while (path.Replace( _T("//"), _T("/") ));
  132. path.TrimLeft( _T("/") );
  133. path.TrimRight( _T("/") );
  134. int pos = path.Find( _T("/") );
  135. while (pos != -1)
  136. {
  137. m_Segments.push_back(path.Left(pos));
  138. path = path.Mid(pos+1);
  139. pos = path.Find( _T("/") );
  140. }
  141. if (path != _MPT(""))
  142. m_Segments.push_back(path);
  143. break;
  144. }
  145. break;
  146. case FZ_SERVERTYPE_LOCAL:
  147. {
  148. path.TrimRight( _T("\\") );
  149. while (path.Replace( _T("\\\\"), _T("\\") ));
  150. int pos = path.Find( _T("\\") );
  151. if (pos == -1)
  152. {
  153. m_Prefix = path;
  154. return;
  155. }
  156. ASSERT(pos == 2);
  157. m_Prefix = path.Left(pos);
  158. path = path.Mid(pos + 1);
  159. pos = path.Find( _T("\\") );
  160. while (pos != -1)
  161. {
  162. m_Segments.push_back(path.Left(pos));
  163. path=path.Mid(pos + 1);
  164. pos=path.Find( _T("\\") );
  165. }
  166. if (path != _MPT(""))
  167. m_Segments.push_back(path);
  168. }
  169. break;
  170. default:
  171. ASSERT(FALSE);
  172. }
  173. }
  174. CServerPath::CServerPath(const CServerPath &path)
  175. {
  176. m_nServerType = path.m_nServerType;
  177. m_Prefix = path.m_Prefix;
  178. m_bEmpty = path.m_bEmpty;
  179. m_Segments = path.m_Segments;
  180. }
  181. CServerPath::~CServerPath()
  182. {
  183. }
  184. void CServerPath::SetServer(const t_server &server)
  185. {
  186. m_nServerType=server.nServerType;
  187. }
  188. BOOL CServerPath::SetPath(CString &newpath, BOOL bIsFile /*=FALSE*/)
  189. {
  190. CString file;
  191. CString path=newpath;
  192. path.TrimLeft( _T(" ") );
  193. path.TrimRight( _T(" ") );
  194. if (path != _MPT(""))
  195. m_bEmpty = FALSE;
  196. else
  197. m_bEmpty = TRUE;
  198. if (!(m_nServerType & FZ_SERVERTYPE_HIGHMASK))
  199. m_nServerType = FZ_SERVERTYPE_FTP;
  200. if (!(m_nServerType&FZ_SERVERTYPE_SUBMASK) && (m_nServerType&FZ_SERVERTYPE_HIGHMASK)==FZ_SERVERTYPE_FTP)
  201. {
  202. int pos1 = path.Find( _T(":[") );
  203. if (pos1!=-1 && pos1!=(path.GetLength()-2))
  204. {
  205. if (!bIsFile && path.Right(1)==_T("]"))
  206. m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
  207. else if (bIsFile && path.ReverseFind(']')>(pos1+1))
  208. m_nServerType|=FZ_SERVERTYPE_SUB_FTP_VMS;
  209. }
  210. if (newpath.GetLength() >= 3 && _istalpha(newpath[0]) && newpath[1] == _MPT(':') && (newpath[2] == _MPT('\\') || newpath[2] == _MPT('/')))
  211. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_WINDOWS;
  212. else if (path[0] == FTP_MVS_DOUBLE_QUOTA && path[path.GetLength() - 1] == FTP_MVS_DOUBLE_QUOTA)
  213. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
  214. else if (path.GetLength() >= 2 && path[0] != _MPT('/') && path.Right(1) == _T("."))
  215. m_nServerType |= FZ_SERVERTYPE_SUB_FTP_UNKNOWN;
  216. }
  217. m_Segments.clear();
  218. m_Prefix = _MPT("");
  219. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  220. {
  221. case FZ_SERVERTYPE_FTP:
  222. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  223. {
  224. case FZ_SERVERTYPE_SUB_FTP_MVS:
  225. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  226. {
  227. path.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  228. path.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  229. path.TrimLeft(_MPT('\''));
  230. path.TrimRight(_MPT('\''));
  231. path.TrimLeft(_MPT('.'));
  232. while (path.Replace(_T(".."), _T(".")));
  233. int pos = path.Find(_T("."));
  234. while (pos != -1)
  235. {
  236. m_Segments.push_back(path.Left(pos));
  237. path = path.Mid(pos + 1);
  238. pos = path.Find( _T(".") );
  239. }
  240. if (path != _MPT(""))
  241. m_Segments.push_back(path);
  242. else
  243. m_Prefix = _T(".");
  244. if (bIsFile)
  245. {
  246. if (m_Segments.empty())
  247. return FALSE;
  248. file = m_Segments.back();
  249. m_Segments.pop_back();
  250. if (file.Right(1) == _T("."))
  251. return FALSE;
  252. int pos = file.Find(_MPT('('));
  253. int pos2 = file.Find(_MPT(')'));
  254. if (pos != -1)
  255. {
  256. if (!pos || pos2 != file.GetLength() - 2)
  257. return FALSE;
  258. m_Prefix = _T("");
  259. m_Segments.push_back(file.Left(pos));
  260. file = file.Mid(pos + 1, pos2 - pos - 1);
  261. }
  262. else if (pos2 != -1)
  263. return FALSE;
  264. }
  265. }
  266. break;
  267. case FZ_SERVERTYPE_SUB_FTP_VMS:
  268. {
  269. int pos1=path.Find( _T("[") );
  270. if (pos1==-1)
  271. return FALSE;
  272. if (bIsFile)
  273. {
  274. int rpos=path.ReverseFind(_MPT(']'));
  275. if (rpos==-1)
  276. return FALSE;
  277. else if (rpos!=(path.GetLength()-1) )
  278. {
  279. file=file.Mid(rpos+1);
  280. path=path.Left(rpos+1);
  281. }
  282. else
  283. return FALSE;
  284. }
  285. if (path.Right(1)!=_MPT("]"))
  286. return FALSE;
  287. path.TrimRight( _T("]") );
  288. if (pos1)
  289. m_Prefix=path.Left(pos1);
  290. path=path.Mid(pos1+1);
  291. int pos=path.Find( _T(".") );
  292. while(pos!=-1)
  293. {
  294. m_Segments.push_back(path.Left(pos));
  295. path=path.Mid(pos+1);
  296. pos=path.Find( _T(".") );
  297. }
  298. if (path!=_MPT(""))
  299. m_Segments.push_back(path);
  300. }
  301. break;
  302. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  303. while (path.Replace(_MPT('.'), _MPT('/')));
  304. default:
  305. path.Replace( _T("\\"), _T("/") );
  306. while(path.Replace( _T("//"), _T("/") ));
  307. path.TrimLeft( _T("/") );
  308. if (bIsFile)
  309. {
  310. if (path.Right(1)!= _T("/") )
  311. {
  312. int rpos=path.ReverseFind(_MPT('/'));
  313. if (rpos==-1)
  314. {
  315. newpath=path;
  316. m_bEmpty=TRUE;
  317. return TRUE;
  318. }
  319. file=path.Mid(rpos+1);
  320. path=path.Left(rpos);
  321. }
  322. else
  323. return FALSE;
  324. }
  325. path.TrimRight( _T("/") );
  326. int pos=path.Find( _T("/") );
  327. while(pos!=-1)
  328. {
  329. m_Segments.push_back(path.Left(pos));
  330. path=path.Mid(pos+1);
  331. pos=path.Find( _T("/") );
  332. }
  333. if (path!=_MPT(""))
  334. m_Segments.push_back(path);
  335. break;
  336. }
  337. break;
  338. case FZ_SERVERTYPE_LOCAL:
  339. {
  340. if (bIsFile)
  341. {
  342. if (path.Right(1)!= _T("\\") )
  343. {
  344. int rpos=path.ReverseFind(_MPT('\\'));
  345. if (rpos==-1)
  346. return FALSE;
  347. file=path.Mid(rpos+1);
  348. path=path.Left(rpos);
  349. }
  350. else
  351. return FALSE;
  352. }
  353. path.TrimRight( _T("\\") );
  354. while (path.Replace( _T("\\\\"), _T("\\") ));
  355. int pos=path.Find( _T(":\\") );
  356. if (pos==-1 || pos!=1)
  357. return FALSE;
  358. else
  359. {
  360. m_Prefix=path.Left(pos+1);
  361. path=path.Mid(pos+2);
  362. }
  363. pos=path.Find( _T("\\") );
  364. while (pos!=-1)
  365. {
  366. m_Segments.push_back(path.Left(pos));
  367. path=path.Mid(pos+1);
  368. pos=path.Find( _T("\\") );
  369. }
  370. if (path!=_MPT(""))
  371. m_Segments.push_back(path);
  372. }
  373. break;
  374. }
  375. if (bIsFile)
  376. newpath = file;
  377. return TRUE;
  378. }
  379. const CString CServerPath::GetPath() const
  380. {
  381. if (m_bEmpty)
  382. return _MPT("");
  383. CString path;
  384. tConstIter iter;
  385. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  386. {
  387. case FZ_SERVERTYPE_FTP:
  388. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  389. {
  390. case FZ_SERVERTYPE_SUB_FTP_MVS:
  391. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  392. path = _MPT("'");
  393. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  394. {
  395. if (iter != m_Segments.begin())
  396. path += _T(".");
  397. path += *iter;
  398. }
  399. path += m_Prefix + _MPT("'");
  400. break;
  401. case FZ_SERVERTYPE_SUB_FTP_VMS:
  402. path = m_Prefix + _MPT("[");
  403. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  404. path += *iter + _T(".");
  405. path.TrimRight( _T(".") );
  406. path += _MPT("]");
  407. break;
  408. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  409. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  410. path+=*iter + _T(".");
  411. break;
  412. default:
  413. if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
  414. path=_MPT("/");
  415. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  416. path+=*iter + _T("/");
  417. break;
  418. }
  419. break;
  420. case FZ_SERVERTYPE_LOCAL:
  421. path=m_Prefix;
  422. if (!m_Segments.empty())
  423. path+=_MPT("\\");
  424. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  425. path+=*iter + _T("\\");
  426. break;
  427. default:
  428. ASSERT(FALSE);
  429. }
  430. return path;
  431. }
  432. CServerPath& CServerPath::operator=(const CServerPath &op)
  433. {
  434. if (this == &op)
  435. return *this;
  436. m_Segments.clear();
  437. m_nServerType = op.m_nServerType;
  438. m_Prefix = op.m_Prefix;
  439. m_bEmpty = op.m_bEmpty;
  440. m_Segments = op.m_Segments;
  441. return *this;
  442. }
  443. const bool CServerPath::operator==(const CServerPath &op) const
  444. {
  445. if (this == &op)
  446. return true;
  447. if (m_bEmpty != op.m_bEmpty)
  448. return false;
  449. if (m_Prefix != op.m_Prefix)
  450. return false;
  451. // excluding FZ_SERVERTYPE_LAYERMASK from comparison,
  452. // as this part of server type is not set in TFileZillaIntf
  453. const int CompareMask = FZ_SERVERTYPE_HIGHMASK | FZ_SERVERTYPE_SUBMASK;
  454. if ((m_nServerType & CompareMask) != (op.m_nServerType & CompareMask))
  455. return false;
  456. tConstIter iter1 = m_Segments.begin();
  457. tConstIter iter2 = op.m_Segments.begin();
  458. while (iter1 != m_Segments.end())
  459. {
  460. if (iter2 == op.m_Segments.end())
  461. return false;
  462. if (*iter1 != *iter2)
  463. return false;
  464. iter1++;
  465. iter2++;
  466. }
  467. if (iter2 != op.m_Segments.end())
  468. return false;
  469. return true;
  470. }
  471. const BOOL operator==(const CServerPath &a, const CString &b)
  472. {
  473. CServerPath path(b);
  474. return a==path;
  475. }
  476. const bool CServerPath::operator!=(const CServerPath &op) const
  477. {
  478. if (!this)
  479. return false;
  480. if (*this == op)
  481. return false;
  482. else
  483. return true;
  484. }
  485. CString CServerPath::GetLastSegment() const
  486. {
  487. if (!HasParent())
  488. return _T("");
  489. if (m_Segments.empty())
  490. return _T("");
  491. else
  492. return m_Segments.back();
  493. }
  494. CServerPath CServerPath::GetParent() const
  495. {
  496. ASSERT(HasParent());
  497. CServerPath path;
  498. path = *this;
  499. path.m_Segments.pop_back();
  500. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000))
  501. path.m_Prefix = _T(".");
  502. return path;
  503. }
  504. BOOL CServerPath::HasParent() const
  505. {
  506. if (!m_Segments.empty())
  507. return TRUE;
  508. else
  509. return FALSE;
  510. }
  511. const BOOL CServerPath::IsEmpty() const
  512. {
  513. return m_bEmpty;
  514. }
  515. CString CServerPath::GetSafePath() const
  516. {
  517. if (m_bEmpty)
  518. return _T("");
  519. CString safepath;
  520. safepath.Format(_T("%d %d "), m_nServerType, m_Prefix.GetLength());
  521. if (m_Prefix!=_MPT(""))
  522. safepath+=m_Prefix+_MPT(" ");
  523. tConstIter iter = m_Segments.begin();
  524. while(iter!=m_Segments.end())
  525. {
  526. CString len;
  527. len.Format(_T("%d "), iter->GetLength());
  528. safepath+=len;
  529. safepath+=*iter;
  530. iter++;
  531. if (iter!=m_Segments.end())
  532. safepath+=_MPT(" ");
  533. }
  534. return safepath;
  535. }
  536. BOOL CServerPath::AddSubdir(CString subdir)
  537. {
  538. subdir.TrimLeft( _T(" ") );
  539. subdir.TrimRight( _T(" ") );
  540. if (subdir == _MPT(""))
  541. return FALSE;
  542. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && m_Prefix != _T("."))
  543. return FALSE;
  544. m_Segments.push_back(subdir);
  545. if (m_nServerType & (FZ_SERVERTYPE_SUB_FTP_MVS | FZ_SERVERTYPE_SUB_FTP_BS2000) && !m_Segments.empty())
  546. {
  547. if (m_Segments.back().Right(1) == _T("."))
  548. {
  549. m_Segments.back().TrimRight(_MPT('.'));
  550. m_Prefix = _T(".");
  551. }
  552. else
  553. m_Prefix = _T("");
  554. }
  555. m_bEmpty = FALSE;
  556. return TRUE;
  557. }
  558. CServerPath::CServerPath(CString subdir, const CServerPath &parent)
  559. {
  560. *this=parent;
  561. subdir.TrimLeft( _T(" ") );
  562. subdir.TrimRight( _T(" ") );
  563. if ( subdir==_T("") )
  564. {
  565. if (IsEmpty())
  566. ASSERT(FALSE);
  567. else
  568. return;
  569. }
  570. if (!(m_nServerType&FZ_SERVERTYPE_HIGHMASK))
  571. m_nServerType=FZ_SERVERTYPE_FTP;
  572. m_bEmpty = FALSE;
  573. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  574. {
  575. case FZ_SERVERTYPE_FTP:
  576. switch(m_nServerType&FZ_SERVERTYPE_SUBMASK)
  577. {
  578. case FZ_SERVERTYPE_SUB_FTP_MVS:
  579. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  580. {
  581. subdir.TrimLeft(FTP_MVS_DOUBLE_QUOTA);
  582. subdir.TrimRight(FTP_MVS_DOUBLE_QUOTA);
  583. if (subdir.Left(1) == _MPT("'"))
  584. {
  585. if (subdir.Right(1) == _MPT("'"))
  586. {
  587. if (!SetPath(subdir))
  588. m_bEmpty = true;
  589. }
  590. else
  591. m_bEmpty = true;
  592. }
  593. else if (subdir.Right(1) == _MPT("'"))
  594. m_bEmpty = true;
  595. else if (!m_bEmpty)
  596. {
  597. if (m_Prefix != _T("."))
  598. m_bEmpty = true;
  599. else
  600. {
  601. subdir.TrimLeft(_MPT('.'));
  602. while (subdir.Replace(_T(".."), _T(".")));
  603. int pos = subdir.Find(_MPT('.'));
  604. while (pos != -1)
  605. {
  606. m_Segments.push_back(subdir.Left(pos));
  607. subdir = subdir.Mid(pos + 1);
  608. }
  609. if (subdir != _T(""))
  610. {
  611. m_Prefix = _T("");
  612. m_Segments.push_back(subdir);
  613. }
  614. }
  615. }
  616. else if (!SetPath(subdir))
  617. m_bEmpty = true;
  618. }
  619. break;
  620. case FZ_SERVERTYPE_SUB_FTP_VMS:
  621. {
  622. int pos1=subdir.Find( _T("[") );
  623. if (pos1==-1)
  624. {
  625. ASSERT( subdir.Right(1)!=_T("]") );
  626. while ( subdir.Replace( _T(".."), _T(".") ) );
  627. }
  628. else
  629. {
  630. if (subdir.Right(1)!=_MPT("]"))
  631. ASSERT(FALSE);
  632. subdir=subdir.Left(subdir.GetLength()-1);
  633. if (pos1)
  634. m_Prefix=subdir.Left(pos1);
  635. else
  636. m_Prefix=_MPT("");
  637. m_Segments.clear();
  638. subdir=subdir.Mid(pos1+1);
  639. pos1=subdir.Find( _T("[") );
  640. int pos2=subdir.Find( _T("]") );
  641. if (pos1!=-1 || pos2!=-1)
  642. ASSERT(FALSE);
  643. }
  644. int pos=subdir.Find( _T(".") );
  645. while(pos!=-1)
  646. {
  647. m_Segments.push_back(subdir.Left(pos));
  648. subdir=subdir.Mid(pos+1);
  649. pos=subdir.Find( _T(".") );
  650. }
  651. if (subdir!=_MPT(""))
  652. m_Segments.push_back(subdir);
  653. }
  654. break;
  655. case FZ_SERVERTYPE_SUB_FTP_WINDOWS:
  656. {
  657. subdir.Replace( _T("\\"), _T("/") );
  658. while(subdir.Replace( _T("//"), _T("/") ));
  659. if (subdir.GetLength() >= 2 && subdir[1] == _MPT(':'))
  660. m_Segments.clear();
  661. else if (subdir[0]==_MPT('/'))
  662. {
  663. CString firstSegment;
  664. if (m_Segments.empty())
  665. firstSegment = _MPT("C:");
  666. else
  667. firstSegment = m_Segments.front();
  668. m_Segments.clear();
  669. m_Segments.push_back(firstSegment);
  670. subdir.TrimLeft( _T("/") );
  671. }
  672. subdir.TrimRight( _T("/") );
  673. int pos = subdir.Find( _T("/") );
  674. while(pos!=-1)
  675. {
  676. m_Segments.push_back(subdir.Left(pos));
  677. subdir=subdir.Mid(pos+1);
  678. pos=subdir.Find( _T("/") );
  679. }
  680. if (subdir!=_MPT(""))
  681. m_Segments.push_back(subdir);
  682. break;
  683. }
  684. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  685. subdir.Replace(_MPT('.'), _MPT('/'));
  686. default:
  687. subdir.Replace( _T("\\"), _T("/") );
  688. while(subdir.Replace( _T("//"), _T("/") ));
  689. if (subdir[0]==_MPT('/'))
  690. {
  691. m_Segments.clear();
  692. subdir.TrimLeft( _T("/") );
  693. }
  694. subdir.TrimRight( _T("/") );
  695. int pos=subdir.Find( _T("/") );
  696. while(pos!=-1)
  697. {
  698. m_Segments.push_back(subdir.Left(pos));
  699. subdir=subdir.Mid(pos+1);
  700. pos=subdir.Find( _T("/") );
  701. }
  702. if (subdir!=_MPT(""))
  703. m_Segments.push_back(subdir);
  704. break;
  705. }
  706. break;
  707. case FZ_SERVERTYPE_LOCAL:
  708. {
  709. subdir.TrimRight( _T("\\") );
  710. while (subdir.Replace( _T("\\\\"), _T("\\") ));
  711. subdir.TrimLeft( _T("\\") );
  712. int pos=subdir.Find( _T(":") );
  713. if (pos==1) //subdir is absolute path
  714. {
  715. m_Segments.clear();
  716. m_Prefix=subdir.Left(pos+1);
  717. subdir=subdir.Mid(pos+1);
  718. subdir.TrimLeft( _T("\\") );
  719. if (subdir.Find( _T(":") )!=-1)
  720. ASSERT(FALSE);
  721. }
  722. if (pos==-1 || pos==1)
  723. {
  724. pos=subdir.Find( _T("\\") );
  725. while (pos!=-1)
  726. {
  727. m_Segments.push_back(subdir.Left(pos));
  728. subdir=subdir.Mid(pos+1);
  729. pos=subdir.Find( _T("\\") );
  730. }
  731. if ( subdir!=_T("") )
  732. m_Segments.push_back(subdir);
  733. }
  734. else
  735. ASSERT(FALSE);
  736. }
  737. break;
  738. default:
  739. ASSERT(FALSE);
  740. }
  741. }
  742. BOOL CServerPath::SetPath(CString newpath)
  743. {
  744. return SetPath(newpath, FALSE);
  745. }
  746. CString CServerPath::FormatFilename(CString fn, bool omitPath /*=false*/) const
  747. {
  748. if (m_bEmpty)
  749. return fn;
  750. if (fn == _MPT(""))
  751. return _MPT("");
  752. CString path;
  753. tConstIter iter;
  754. switch (m_nServerType&FZ_SERVERTYPE_HIGHMASK)
  755. {
  756. case FZ_SERVERTYPE_FTP:
  757. switch (m_nServerType&FZ_SERVERTYPE_SUBMASK)
  758. {
  759. case FZ_SERVERTYPE_SUB_FTP_MVS:
  760. case FZ_SERVERTYPE_SUB_FTP_BS2000:
  761. if (omitPath && m_Prefix == _T("."))
  762. return fn;
  763. path = _MPT("'");
  764. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  765. path += *iter + _T(".");
  766. if (m_Prefix != _T("."))
  767. {
  768. path.TrimRight(_MPT('.'));
  769. path += _T("(") + fn + _T(")");
  770. }
  771. else
  772. path += fn;
  773. path += _MPT("'");
  774. break;
  775. case FZ_SERVERTYPE_SUB_FTP_VMS:
  776. if (omitPath)
  777. return fn;
  778. path = m_Prefix + _MPT("[");
  779. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  780. path += *iter + _T(".");
  781. path.TrimRight( _T(".") );
  782. path += _MPT("]");
  783. path += fn;
  784. break;
  785. case FZ_SERVERTYPE_SUB_FTP_UNKNOWN:
  786. if (omitPath)
  787. return fn;
  788. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  789. path+=*iter + _T(".");
  790. path += fn;
  791. break;
  792. default:
  793. if (omitPath)
  794. return fn;
  795. if (!(m_nServerType & FZ_SERVERTYPE_SUB_FTP_WINDOWS))
  796. path=_MPT("/");
  797. for (iter = m_Segments.begin(); iter != m_Segments.end(); iter++)
  798. path+=*iter + _T("/");
  799. path += fn;
  800. break;
  801. }
  802. break;
  803. case FZ_SERVERTYPE_LOCAL:
  804. if (omitPath)
  805. return fn;
  806. path=m_Prefix;
  807. if (!m_Segments.empty())
  808. path+=_MPT("\\");
  809. for (iter=m_Segments.begin(); iter!=m_Segments.end(); iter++)
  810. path+=*iter + _T("\\");
  811. path += fn;
  812. break;
  813. default:
  814. ASSERT(FALSE);
  815. }
  816. return path;
  817. }