diff options
| author | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-29 21:15:18 +0000 |
|---|---|---|
| committer | jai <jai@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-29 21:15:18 +0000 |
| commit | b71531b42b3325fd6079a7039aae8641262c8adf (patch) | |
| tree | a5b9aa16924c541fcb424ee9460b1ac7f5a89352 /modules/CIAO/DAnCE/RepositoryManager/URL_Parser.cpp | |
| parent | a0f67cc97c0050d907145e312135b60c0125e56e (diff) | |
| download | ATCD-DS-main.tar.gz | |
branching/taggingDS-main
Diffstat (limited to 'modules/CIAO/DAnCE/RepositoryManager/URL_Parser.cpp')
| -rw-r--r-- | modules/CIAO/DAnCE/RepositoryManager/URL_Parser.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/modules/CIAO/DAnCE/RepositoryManager/URL_Parser.cpp b/modules/CIAO/DAnCE/RepositoryManager/URL_Parser.cpp new file mode 100644 index 00000000000..37187ebff61 --- /dev/null +++ b/modules/CIAO/DAnCE/RepositoryManager/URL_Parser.cpp @@ -0,0 +1,101 @@ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/ARGV.h" +#include "URL_Parser.h" + +#include "ace/ACE.h" +#include "ace/OS_NS_string.h" + +bool +URL_Parser::parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("rwu:h:p:f:d")); + + bool success = true; + int c; + + while ((c = get_opt ()) != -1) + switch (c) + { + case 'd': + this->debug_ = true; + break; + case 'u': + success = parseURL (get_opt.opt_arg ()); + break; + // Usage fallthrough. + default: + success = false; + } + + if (this->hostname_ == 0 || this->filename_ == 0) + { + success = false; + } + + return success; +} + +URL_Parser::URL_Parser (void) + : hostname_ (ACE::strnew ("127.0.0.1")), + port_ (ACE_DEFAULT_HTTP_SERVER_PORT), + filename_ (0), + debug_ (false) +{ +} + +bool URL_Parser::parseURL (char* url) +{ + char* ptr = 0; + bool success = true; + ptr = ACE_OS::strstr (url, "http://"); + if (ptr) + url += ACE_OS::strlen ("http://"); + + if (url[0] == '/') + { + this->filename_ = ACE_OS::strdup (url); + } + else + { + ptr = ACE_OS::strstr (url, ":"); + if (ptr) + this->port_ = ACE_OS::atoi (ptr + 1); + else + ptr = ACE_OS::strstr (url, "/"); + + if(!ptr) + success = false; + else + { + size_t host_len = ptr - url; + ACE::strdelete (this->hostname_); + ACE_NEW_RETURN (this->hostname_, char [host_len + 1], false); + ACE_OS::strncpy (this->hostname_, url, host_len); + this->hostname_ [host_len] = '\0'; + ptr = ACE_OS::strstr (ptr, "/"); + if (ptr) + { + this->filename_ = ACE_OS::strdup(ptr); + } + else + { + success = false; + } + } + } + return success; +} + + +void URL_Parser::Error (void) +{ + ACE_DEBUG ((LM_DEBUG, "./http_client -u http://hostname:port/filename [-d]\n")); +} + +URL_Parser::~URL_Parser() +{ + delete [] this->hostname_; + ACE_OS::free (this->filename_); +} |
