lluri.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /**
  2. * @file lluri.cpp
  3. * @author Phoenix
  4. * @date 2006-02-08
  5. * @brief Implementation of the LLURI class.
  6. *
  7. * $LicenseInfo:firstyear=2006&license=viewergpl$
  8. *
  9. * Copyright (c) 2006-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #include "linden_common.h"
  35. #include <iomanip>
  36. #include "boost/tokenizer.hpp"
  37. #include "lluri.h"
  38. #include "llsd.h"
  39. #define UNRESERVED_CHARS \
  40. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._~"
  41. #define SUB_DELIMS "!$&'()*+,;="
  42. // Note: I had to remove "-" from UNRESERVED_CHARS since some CEF versions did
  43. // not like it in path components... But then, it is now (2024-03) apparently
  44. // the other way around, and I re-added it... Go figure !!! HB
  45. #if 1
  46. # define UNRESERVED_DASH "-"
  47. #else
  48. # define UNRESERVED_DASH ""
  49. #endif
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // Helper functions
  52. ///////////////////////////////////////////////////////////////////////////////
  53. LL_NO_INLINE static bool is_char_hex(char hex)
  54. {
  55. if (hex >= '0' && hex <= '9')
  56. {
  57. return true;
  58. }
  59. if (hex >= 'a' && hex <='f')
  60. {
  61. return true;
  62. }
  63. if (hex >= 'A' && hex <='F')
  64. {
  65. return true;
  66. }
  67. return false;
  68. }
  69. LL_NO_INLINE static std::string escapeHostAndPort(const std::string& s)
  70. {
  71. static std::string allowed;
  72. if (allowed.empty())
  73. {
  74. allowed = UNRESERVED_CHARS SUB_DELIMS "-:";
  75. std::sort(allowed.begin(), allowed.end());
  76. }
  77. return LLURI::escape(s, allowed, true);
  78. }
  79. LL_NO_INLINE static std::string escapePathComponent(const std::string& s)
  80. {
  81. static std::string allowed;
  82. if (allowed.empty())
  83. {
  84. allowed = UNRESERVED_CHARS SUB_DELIMS UNRESERVED_DASH ":@";
  85. std::sort(allowed.begin(), allowed.end());
  86. }
  87. return LLURI::escape(s, allowed, true);
  88. }
  89. LL_NO_INLINE static std::string escapeQueryVariable(const std::string& s)
  90. {
  91. static std::string allowed;
  92. if (allowed.empty())
  93. {
  94. // sub_delims - "&;=" + ":@"
  95. allowed = UNRESERVED_CHARS "-:@!$'()*+,";
  96. std::sort(allowed.begin(), allowed.end());
  97. }
  98. return LLURI::escape(s, allowed, true);
  99. }
  100. LL_NO_INLINE static std::string escapeQueryValue(const std::string& s)
  101. {
  102. static std::string allowed;
  103. if (allowed.empty())
  104. {
  105. // sub_delims - "&;" + ":@"
  106. allowed = UNRESERVED_CHARS "-:@!$'()*+,=";
  107. std::sort(allowed.begin(), allowed.end());
  108. }
  109. return LLURI::escape(s, allowed, true);
  110. }
  111. LL_NO_INLINE static std::string escapeUriQuery(const std::string& s)
  112. {
  113. static std::string allowed;
  114. if (allowed.empty())
  115. {
  116. allowed = UNRESERVED_CHARS "-:@?&$;*+=%/";
  117. std::sort(allowed.begin(), allowed.end());
  118. }
  119. return LLURI::escape(s, allowed, true);
  120. }
  121. LL_NO_INLINE static std::string escapeUriData(const std::string& s)
  122. {
  123. static std::string allowed;
  124. if (allowed.empty())
  125. {
  126. allowed = UNRESERVED_CHARS "-";
  127. std::sort(allowed.begin(), allowed.end());
  128. }
  129. return LLURI::escape(s, allowed, true);
  130. }
  131. LL_NO_INLINE static std::string escapeUriPath(const std::string& s)
  132. {
  133. static std::string allowed;
  134. if (allowed.empty())
  135. {
  136. allowed =
  137. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  138. "$_.+!*'(),{}|\\^~[]`<>#%;/?:@&=" UNRESERVED_DASH;
  139. std::sort(allowed.begin(), allowed.end());
  140. }
  141. return LLURI::escape(s, allowed, true);
  142. }
  143. LL_NO_INLINE static bool is_default(const std::string& scheme, U16 port)
  144. {
  145. if (scheme == "http")
  146. {
  147. return port == 80;
  148. }
  149. else if (scheme == "https")
  150. {
  151. return port == 443;
  152. }
  153. else if (scheme == "ftp")
  154. {
  155. return port == 21;
  156. }
  157. return false;
  158. }
  159. LL_NO_INLINE static void find_authority_parts(const std::string& authority,
  160. std::string& user,
  161. std::string& host,
  162. std::string& port)
  163. {
  164. size_t start_pos = authority.find('@');
  165. if (start_pos == std::string::npos)
  166. {
  167. user.clear();
  168. start_pos = 0;
  169. }
  170. else
  171. {
  172. user = authority.substr(0, start_pos++);
  173. }
  174. size_t end_pos = authority.find(':', start_pos);
  175. if (end_pos == std::string::npos)
  176. {
  177. host = authority.substr(start_pos);
  178. port.clear();
  179. }
  180. else
  181. {
  182. host = authority.substr(start_pos, end_pos - start_pos);
  183. port = authority.substr(end_pos + 1);
  184. }
  185. }
  186. ///////////////////////////////////////////////////////////////////////////////
  187. // LLURI class
  188. ///////////////////////////////////////////////////////////////////////////////
  189. LLURI::LLURI(const std::string& escaped_str)
  190. {
  191. size_t delim_pos;
  192. delim_pos = escaped_str.find(':');
  193. std::string temp;
  194. if (delim_pos == std::string::npos)
  195. {
  196. mScheme.clear();
  197. mEscapedOpaque = escaped_str;
  198. }
  199. else
  200. {
  201. mScheme = escaped_str.substr(0, delim_pos);
  202. mEscapedOpaque = escaped_str.substr(delim_pos + 1);
  203. }
  204. parseAuthorityAndPathUsingOpaque();
  205. delim_pos = mEscapedPath.find('?');
  206. if (delim_pos != std::string::npos)
  207. {
  208. mEscapedQuery = mEscapedPath.substr(delim_pos + 1);
  209. mEscapedPath = mEscapedPath.substr(0,delim_pos);
  210. }
  211. }
  212. LLURI::LLURI(const std::string& scheme, const std::string& user_name,
  213. const std::string& password, const std::string& host_name,
  214. U16 port, const std::string& escaped_path,
  215. const std::string& escaped_query)
  216. : mScheme(scheme),
  217. mEscapedPath(escaped_path),
  218. mEscapedQuery(escaped_query)
  219. {
  220. std::ostringstream auth;
  221. std::ostringstream opaque;
  222. opaque << "//";
  223. if (!user_name.empty())
  224. {
  225. auth << escape(user_name);
  226. if (!password.empty())
  227. {
  228. auth << ':' << escape(password);
  229. }
  230. auth << '@';
  231. }
  232. auth << host_name;
  233. if (!is_default(scheme, port))
  234. {
  235. auth << ':' << port;
  236. }
  237. mEscapedAuthority = auth.str();
  238. opaque << mEscapedAuthority << escaped_path << escaped_query;
  239. mEscapedOpaque = opaque.str();
  240. }
  241. //static
  242. void LLURI::encodeCharacter(std::ostream& ostr, std::string::value_type val)
  243. {
  244. ostr << "%" << std::uppercase << std::hex << std::setw(2)
  245. << std::setfill('0')
  246. // VWR-4010 Cannot cast to U32 because sign-extension on
  247. // chars > 128 will result in FFFFFFC3 instead of F3.
  248. << static_cast<S32>(static_cast<U8>(val))
  249. // reset stream state
  250. << std::nouppercase << std::dec << std::setfill(' ');
  251. }
  252. //static
  253. std::string LLURI::escape(const std::string& str, const std::string& allowed,
  254. bool is_allowed_sorted)
  255. {
  256. // Note: This size determination feels like a good value to me. If someone
  257. // wants to come up with a more precise heuristic with some data to back up
  258. // the assertion that 'sort is good' then feel free to change this test a
  259. // bit.
  260. if (!is_allowed_sorted && (str.size() > 2 * allowed.size()))
  261. {
  262. // If it is not already sorted, or if the url is quite long, we want to
  263. // optimize this process.
  264. std::string sorted_allowed(allowed);
  265. std::sort(sorted_allowed.begin(), sorted_allowed.end());
  266. return escape(str, sorted_allowed, true);
  267. }
  268. std::ostringstream ostr;
  269. std::string::const_iterator it = str.begin();
  270. std::string::const_iterator end = str.end();
  271. std::string::value_type c;
  272. if (is_allowed_sorted)
  273. {
  274. for (std::string::const_iterator allowed_begin = allowed.begin(),
  275. allowed_end = allowed.end();
  276. it != end; ++it)
  277. {
  278. c = *it;
  279. if (std::binary_search(allowed_begin, allowed_end, c))
  280. {
  281. ostr << c;
  282. }
  283. else
  284. {
  285. encodeCharacter(ostr, c);
  286. }
  287. }
  288. }
  289. else
  290. {
  291. for ( ; it != end; ++it)
  292. {
  293. c = *it;
  294. if (allowed.find(c) == std::string::npos)
  295. {
  296. encodeCharacter(ostr, c);
  297. }
  298. else
  299. {
  300. ostr << c;
  301. }
  302. }
  303. }
  304. return ostr.str();
  305. }
  306. //static
  307. std::string LLURI::escapePathAndData(const std::string& str)
  308. {
  309. std::string result;
  310. if (str.compare(0, 5, "data:") == 0)
  311. {
  312. // This is not an URL, but data, data part needs to be properly
  313. // escaped; data part is separated by ',' from header. Minimal data URI
  314. // is: "data:,"
  315. size_t i = str.find(',');
  316. if (i != std::string::npos)
  317. {
  318. std::string header = str.substr(0, ++i);
  319. if (header.find("base64") != std::string::npos)
  320. {
  321. // base64 is URL-safe
  322. result = str;
  323. }
  324. else
  325. {
  326. std::string data = str.substr(i, str.length() - i);
  327. // Note: file can be partially pre-escaped, that is why
  328. // escaping ignores '%'. It somewhat limits user from
  329. // displaying strings like "%20" in text but that is how the
  330. // viewer worked for a while and user can double-encode it.
  331. // 'header' does not need escaping
  332. result = header + escapeUriData(data);
  333. }
  334. }
  335. }
  336. else
  337. {
  338. // Try processing it as path with query separator mark("?") character
  339. // and terminated by a number sign("#")
  340. size_t i = str.find('?');
  341. if (i == std::string::npos)
  342. {
  343. // Alternate separator
  344. i = str.find(';');
  345. }
  346. if (i != std::string::npos)
  347. {
  348. size_t path_size = i + 1;
  349. std::string query, fragment;
  350. size_t j = str.find('#');
  351. if (j != std::string::npos && j > i)
  352. {
  353. query = str.substr(path_size, j - path_size);
  354. fragment = str.substr(j);
  355. }
  356. else
  357. {
  358. query = str.substr(path_size);
  359. }
  360. result = escapeUriPath(str.substr(0, path_size)) +
  361. escapeUriQuery(query) + escapeUriPath(fragment);
  362. }
  363. }
  364. if (result.empty())
  365. {
  366. // Not a known scheme or no data part, try just escaping as URI path
  367. result = escapeUriPath(str);
  368. }
  369. return result;
  370. }
  371. //static
  372. std::string LLURI::unescape(const std::string& str)
  373. {
  374. std::ostringstream ostr;
  375. for (std::string::const_iterator it = str.begin(), end = str.end();
  376. it != end; ++it)
  377. {
  378. if (*it == '%')
  379. {
  380. if (++it == end) break;
  381. if (is_char_hex(*it))
  382. {
  383. U8 c = hex_as_nybble(*it++);
  384. c = c << 4;
  385. if (it == end) break;
  386. if (is_char_hex(*it))
  387. {
  388. c |= hex_as_nybble(*it);
  389. ostr.put((char)c);
  390. }
  391. else
  392. {
  393. ostr.put((char)c);
  394. ostr.put(*it);
  395. }
  396. }
  397. else
  398. {
  399. ostr.put('%');
  400. ostr.put(*it);
  401. }
  402. }
  403. else
  404. {
  405. ostr.put(*it);
  406. }
  407. }
  408. return ostr.str();
  409. }
  410. //static
  411. std::string LLURI::escape(const std::string& str)
  412. {
  413. static std::string allowed;
  414. if (allowed.empty())
  415. {
  416. allowed = UNRESERVED_CHARS "-";
  417. std::sort(allowed.begin(), allowed.end());
  418. }
  419. return escape(str, allowed, true);
  420. }
  421. void LLURI::parseAuthorityAndPathUsingOpaque()
  422. {
  423. if (mScheme == "http" || mScheme == "https" || mScheme == "ftp" ||
  424. mScheme == "secondlife" || mScheme == "hop" ||
  425. mScheme == "x-grid-info" || mScheme == "x-grid-location-info")
  426. {
  427. if (mEscapedOpaque.substr(0, 2) != "//")
  428. {
  429. return;
  430. }
  431. size_t delim_pos, delim_pos2;
  432. delim_pos = mEscapedOpaque.find('/', 2);
  433. delim_pos2 = mEscapedOpaque.find('?', 2);
  434. // No path, no query
  435. if (delim_pos == std::string::npos && delim_pos2 == std::string::npos)
  436. {
  437. mEscapedAuthority = mEscapedOpaque.substr(2);
  438. mEscapedPath.clear();
  439. }
  440. // Path exist, no query
  441. else if (delim_pos2 == std::string::npos)
  442. {
  443. mEscapedAuthority = mEscapedOpaque.substr(2, delim_pos - 2);
  444. mEscapedPath = mEscapedOpaque.substr(delim_pos);
  445. }
  446. // No path, only query
  447. else if (delim_pos == std::string::npos || delim_pos2 < delim_pos)
  448. {
  449. mEscapedAuthority = mEscapedOpaque.substr(2, delim_pos2 - 2);
  450. // Query part will be broken out later
  451. mEscapedPath = mEscapedOpaque.substr(delim_pos2);
  452. }
  453. // Path and query
  454. else
  455. {
  456. mEscapedAuthority = mEscapedOpaque.substr(2, delim_pos - 2);
  457. // Query part will be broken out later
  458. mEscapedPath = mEscapedOpaque.substr(delim_pos);
  459. }
  460. }
  461. else if (mScheme == "about")
  462. {
  463. mEscapedPath = mEscapedOpaque;
  464. }
  465. }
  466. //static
  467. LLURI LLURI::buildHTTP(const std::string& prefix, const LLSD& path)
  468. {
  469. LLURI result;
  470. // *TODO: deal with '/' '?' '#' in host_port
  471. if (prefix.find("://") != prefix.npos)
  472. {
  473. // It is a prefix
  474. result = LLURI(prefix);
  475. }
  476. else
  477. {
  478. // It is just a host and optional port
  479. result.mScheme = "http";
  480. result.mEscapedAuthority = escapeHostAndPort(prefix);
  481. }
  482. if (path.isArray())
  483. {
  484. // Break out and escape each path component
  485. for (LLSD::array_const_iterator it = path.beginArray();
  486. it != path.endArray();
  487. ++it)
  488. {
  489. LL_DEBUGS("URI") << "PATH: inserting " << it->asString()
  490. << LL_ENDL;
  491. result.mEscapedPath += "/" + escapePathComponent(it->asString());
  492. }
  493. }
  494. else if (path.isString())
  495. {
  496. result.mEscapedPath += "/" + escapePathComponent(path.asString());
  497. }
  498. else if (!path.isUndefined())
  499. {
  500. llwarns << "Valid path arguments are array, string, or undef, you passed type "
  501. << path.type() << llendl;
  502. }
  503. result.mEscapedOpaque = "//" + result.mEscapedAuthority +
  504. result.mEscapedPath;
  505. return result;
  506. }
  507. //static
  508. LLURI LLURI::buildHTTP(const std::string& prefix, const LLSD& path,
  509. const LLSD& query)
  510. {
  511. LLURI uri = buildHTTP(prefix, path);
  512. // Break out and escape each query component
  513. uri.mEscapedQuery = mapToQueryString(query);
  514. uri.mEscapedOpaque += uri.mEscapedQuery ;
  515. uri.mEscapedQuery.erase(0, 1); // trim the leading '?'
  516. return uri;
  517. }
  518. //static
  519. LLURI LLURI::buildHTTP(const std::string& host, const U32& port,
  520. const LLSD& path)
  521. {
  522. return LLURI::buildHTTP(llformat("%s:%u", host.c_str(), port), path);
  523. }
  524. //static
  525. LLURI LLURI::buildHTTP(const std::string& host, const U32& port,
  526. const LLSD& path, const LLSD& query)
  527. {
  528. return LLURI::buildHTTP(llformat("%s:%u", host.c_str(), port),
  529. path, query);
  530. }
  531. std::string LLURI::asString() const
  532. {
  533. return mScheme.empty() ? mEscapedOpaque : mScheme + ":" + mEscapedOpaque;
  534. }
  535. std::string LLURI::opaque() const
  536. {
  537. return unescape(mEscapedOpaque);
  538. }
  539. std::string LLURI::authority() const
  540. {
  541. return unescape(mEscapedAuthority);
  542. }
  543. std::string LLURI::hostName() const
  544. {
  545. std::string user, host, port;
  546. find_authority_parts(mEscapedAuthority, user, host, port);
  547. return unescape(host);
  548. }
  549. std::string LLURI::userName() const
  550. {
  551. std::string user, user_pass, host, port;
  552. find_authority_parts(mEscapedAuthority, user_pass, host, port);
  553. size_t pos = user_pass.find(':');
  554. if (pos != std::string::npos)
  555. {
  556. user = user_pass.substr(0, pos);
  557. }
  558. return unescape(user);
  559. }
  560. std::string LLURI::password() const
  561. {
  562. std::string pass, user_pass, host, port;
  563. find_authority_parts(mEscapedAuthority, user_pass, host, port);
  564. size_t pos = user_pass.find(':');
  565. if (pos != std::string::npos)
  566. {
  567. pass = user_pass.substr(pos + 1);
  568. }
  569. return unescape(pass);
  570. }
  571. bool LLURI::defaultPort() const
  572. {
  573. return is_default(mScheme, hostPort());
  574. }
  575. U16 LLURI::hostPort() const
  576. {
  577. std::string user, host, port;
  578. find_authority_parts(mEscapedAuthority, user, host, port);
  579. if (port.empty())
  580. {
  581. if (mScheme == "http")
  582. {
  583. return 80;
  584. }
  585. else if (mScheme == "https")
  586. {
  587. return 443;
  588. }
  589. else if (mScheme == "ftp")
  590. {
  591. return 21;
  592. }
  593. return 0;
  594. }
  595. return atoi(port.c_str());
  596. }
  597. std::string LLURI::path() const
  598. {
  599. return unescape(mEscapedPath);
  600. }
  601. LLSD LLURI::pathArray() const
  602. {
  603. typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
  604. boost::char_separator<char> sep("/", "", boost::drop_empty_tokens);
  605. tokenizer tokens(mEscapedPath, sep);
  606. LLSD params;
  607. for (tokenizer::iterator it = tokens.begin(), end = tokens.end();
  608. it != end; ++it)
  609. {
  610. params.append(*it);
  611. }
  612. return params;
  613. }
  614. std::string LLURI::query() const
  615. {
  616. return unescape(mEscapedQuery);
  617. }
  618. LLSD LLURI::queryMap() const
  619. {
  620. return queryMap(mEscapedQuery);
  621. }
  622. //static
  623. LLSD LLURI::queryMap(std::string escaped_query_string)
  624. {
  625. LL_DEBUGS("URI") << "LLURI::queryMap query params: "
  626. << escaped_query_string << LL_ENDL;
  627. LLSD result = LLSD::emptyArray();
  628. while (!escaped_query_string.empty())
  629. {
  630. // Get tuple first
  631. std::string tuple;
  632. size_t tuple_begin = escaped_query_string.find('&');
  633. if (tuple_begin != std::string::npos)
  634. {
  635. tuple = escaped_query_string.substr(0, tuple_begin);
  636. escaped_query_string =
  637. escaped_query_string.substr(tuple_begin + 1);
  638. }
  639. else
  640. {
  641. tuple = escaped_query_string;
  642. escaped_query_string.clear();
  643. }
  644. if (tuple.empty()) continue;
  645. // Parse tuple
  646. size_t key_end = tuple.find('=');
  647. if (key_end != std::string::npos)
  648. {
  649. std::string key = unescape(tuple.substr(0, key_end));
  650. std::string value = unescape(tuple.substr(key_end + 1));
  651. LL_DEBUGS("URI") << "inserting key " << key << " value " << value
  652. << LL_ENDL;
  653. result[key] = value;
  654. }
  655. else
  656. {
  657. LL_DEBUGS("URI") << "inserting key " << unescape(tuple)
  658. << " value true" << LL_ENDL;
  659. result[unescape(tuple)] = true;
  660. }
  661. }
  662. return result;
  663. }
  664. std::string LLURI::mapToQueryString(const LLSD& query_map)
  665. {
  666. std::string query_string;
  667. if (query_map.isMap())
  668. {
  669. bool first_element = true;
  670. std::ostringstream ostr;
  671. for (LLSD::map_const_iterator iter = query_map.beginMap(),
  672. end = query_map.endMap();
  673. iter != end; ++iter)
  674. {
  675. if (first_element)
  676. {
  677. ostr << "?";
  678. first_element = false;
  679. }
  680. else
  681. {
  682. ostr << "&";
  683. }
  684. ostr << escapeQueryVariable(iter->first);
  685. if (iter->second.isDefined())
  686. {
  687. ostr << "=" << escapeQueryValue(iter->second.asString());
  688. }
  689. }
  690. query_string = ostr.str();
  691. }
  692. return query_string;
  693. }
  694. bool operator!=(const LLURI& first, const LLURI& second)
  695. {
  696. return first.asString() != second.asString();
  697. }