FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
URI.h
1 /**********************************************************\
2 Original Author: Dan Weatherford
3 
4 Imported into FireBreath: Oct 4, 2010
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2010 Dan Weatherford and Facebook, Inc
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_FB_URI
17 #define H_FB_URI
18 #include <string>
19 #include <map>
20 #include <set>
21 #include <boost/cstdint.hpp>
22 #include "APITypes.h"
23 
24 namespace FB {
42  class URI {
43  public:
58  static std::string url_decode(const std::string& in);
73  static std::string url_encode(const std::string& in);
74 
75  public:
77  URI() : port(0) {}
78 
80  URI(const std::string& str_uri);
81 
83  bool operator==(const URI& right) const;
84 
105  std::string toString(bool include_domain_part = true) const;
115  static URI fromString(const std::string& in_str);
116 
117  void addQueryData(const std::string& key, const std::string& val) {
118  query_data[key] = val;
119  }
120 
121  // The protocol used. e.g. "http", "https", "file", "ftp", etc
122  std::string protocol;
123  // The login name in the URI (if any)
124  std::string login;
125  // The URI domain. e.g. "www.firebreath.org"
126  std::string domain;
127  // The port; a value of 0 indicates the default port for that protocol
128  boost::uint16_t port;
129  // The path of the request. e.g. "/some/filename.php"
130  std::string path;
131  // A std::map<string,string> of GET variables => values
132  std::map<std::string, std::string> query_data;
133  // The anchor fragment of the url (the part after # in /path/to/something.html#CoolStuff)
134  std::string fragment;
135 
136  protected:
137  typedef std::map<std::string, std::string> StringStringMap;
138  static StringStringMap m_lhMap;
139 
140  public:
147  static void resetValidLocalhost();
156  static void registerValidLocalhost(std::string domain, std::string ip = "");
157 
170  void appendPathComponent(const std::string& pc);
175  std::string filename() const; // last path component; if the URI ends in a trailing slash, returns the empty string.
176 
180  std::string UrlDirectory() const;
181 
182 
189  bool isLocalhost() const;
190 
207  void parse_query_data(const std::string& in_str);
208  };
209 };
210 
211 #endif // H_FB_URI
212 
std::string filename() const
Definition: URI.cpp:172
static URI fromString(const std::string &in_str)
Returns a URI object from the given string.
Definition: URI.cpp:90
static void registerValidLocalhost(std::string domain, std::string ip="")
Definition: URI.cpp:183
static std::string url_decode(const std::string &in)
Decodes the given urlencoded URL.
Definition: URI.cpp:53
void appendPathComponent(const std::string &pc)
Definition: URI.cpp:164
std::string UrlDirectory() const
Returns current Directory from the url of the page.
Definition: URI.cpp:231
Data structure for dealing with URI strings.
Definition: URI.h:42
bool isLocalhost() const
Definition: URI.cpp:191
void parse_query_data(const std::string &in_str)
Parses a urlencoded QueryString and stores the results in the URI.
Definition: URI.cpp:219
static void resetValidLocalhost()
Definition: URI.cpp:179
std::string toString(bool include_domain_part=true) const
converts the FB::URI object to a string
Definition: URI.cpp:66
URI()
Initializes an empty FB::URI object.
Definition: URI.h:77
bool operator==(const URI &right) const
Compares two FB::URI objects.
Definition: URI.cpp:153
static std::string url_encode(const std::string &in)
Encodes the given URL for transmission.
Definition: URI.cpp:37