Url.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 $Header$
00004 
00005 */
00006 
00007 #include "Error.h"
00008 
00009 #include "Url.h"
00010 
00011 Url::Url(const String &url) : Object()
00012 {
00013   unsigned int i1, i2;
00014   String u;
00015 
00016   i1 = url.find("://");
00017   _protocol = i1 == String::npos ? URL_PROTOCOL_DEFAULT : url.substr(0, i1);
00018   i1 = i1 == String::npos ? 0 : i1 + 3;
00019 
00020   if ((i2 = url.find('/', i1)) == String::npos) {
00021     _host = url.substr(i1);
00022     _path = "";
00023   } else {
00024       _host = url.substr(i1, i2 - i1);
00025       _path = url.substr(i2);
00026       if ((i2 = _path.rfind('/')) != String::npos)
00027         _fileName = _path.substr(i2 + 1);
00028       else
00029         _fileName = _path;
00030     }
00031 
00032   if ((i2 = _host.find(':')) != String::npos) {
00033     _port = atoi(_host.substr(i2 + 1).c_str());
00034     _host = _host.substr(0, i2);
00035   } else
00036       _port = URL_PORT_DEFAULT;
00037 
00038   if (_host.empty())
00039     _host = URL_HOST_DEFAULT;
00040   if (_path.empty())
00041     _path = "/";
00042 
00043   DEBUG("Protocol: '%s', host: '%s', port: %u, path: '%s', file name: '%s'", CSTRING(_protocol), CSTRING(_host), _port, CSTRING(_path), CSTRING(_fileName));
00044 }
00045 
00046 Url::~Url()
00047 {
00048 }
00049 
00050 String Url::protocol() const
00051 {
00052   return _protocol;
00053 }
00054 
00055 String Url::host() const
00056 {
00057   return _host;
00058 }
00059 
00060 unsigned int Url::port() const
00061 {
00062   return _port;
00063 }
00064 
00065 String Url::path() const
00066 {
00067   return _path;
00068 }
00069 
00070 String Url::fileName() const
00071 {
00072   return _fileName;
00073 }
00074 
00075 String Url::encode(const String &url)
00076 {
00077   return url;
00078 }

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1