url.h

00001 /******************************************************************************
00002 *  url.h  - code for an URL parser utility class
00003 *
00004 * $Id: url.h 1763 2005-04-03 23:57:03Z scribe $
00005 *
00006 * Copyright 2003 CrossWire Bible Society (http://www.crosswire.org)
00007 *       CrossWire Bible Society
00008 *       P. O. Box 2528
00009 *       Tempe, AZ  85280-2528
00010 *
00011 * This program is free software; you can redistribute it and/or modify it
00012 * under the terms of the GNU General Public License as published by the
00013 * Free Software Foundation version 2.
00014 *
00015 * This program is distributed in the hope that it will be useful, but
00016 * WITHOUT ANY WARRANTY; without even the implied warranty of
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 * General Public License for more details.
00019 *
00020 */
00021 
00022 #ifndef URL_H
00023 #define URL_H
00024 
00025 #include <swbuf.h>
00026 #include <map>
00027 
00028 SWORD_NAMESPACE_START
00029 
00033 class SWDLLEXPORT URL {
00034 public:
00035         typedef std::map<SWBuf, SWBuf> ParameterMap;
00036         
00040         URL(const char *url);
00041         
00045         const char *getProtocol() const;
00049         const char *getHostName() const;
00053         const char *getPath() const;
00054         
00058         const ParameterMap &getParameters() const;
00059         
00066         const char *getParameterValue(const char *name) const;
00067         
00075         static const SWBuf encode(const char *urlText); 
00076         static const SWBuf decode(const char *encodedText);
00077         
00078 private:
00082         void parse();
00083                 
00084         SWBuf url;
00085         SWBuf protocol;
00086         SWBuf hostname;
00087         SWBuf path;
00088         ParameterMap parameterMap;
00089 };
00090 
00091 SWORD_NAMESPACE_END
00092 
00093 #endif //URL_H