llmediaentry.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /**
  2. * @file llmediaentry.cpp
  3. * @brief This is a single instance of media data related to the face of a prim
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include <regex>
  34. #include "llmediaentry.h"
  35. // LLSD key defines
  36. // DO NOT REORDER OR REMOVE THESE!
  37. // Some LLSD keys. Do not change!
  38. #define MEDIA_ALT_IMAGE_ENABLE_KEY_STR "alt_image_enable"
  39. #define MEDIA_CONTROLS_KEY_STR "controls"
  40. #define MEDIA_CURRENT_URL_KEY_STR "current_url"
  41. #define MEDIA_HOME_URL_KEY_STR "home_url"
  42. #define MEDIA_AUTO_LOOP_KEY_STR "auto_loop"
  43. #define MEDIA_AUTO_PLAY_KEY_STR "auto_play"
  44. #define MEDIA_AUTO_SCALE_KEY_STR "auto_scale"
  45. #define MEDIA_AUTO_ZOOM_KEY_STR "auto_zoom"
  46. #define MEDIA_FIRST_CLICK_INTERACT_KEY_STR "first_click_interact"
  47. #define MEDIA_WIDTH_PIXELS_KEY_STR "width_pixels"
  48. #define MEDIA_HEIGHT_PIXELS_KEY_STR "height_pixels"
  49. // "security" fields
  50. #define MEDIA_WHITELIST_ENABLE_KEY_STR "whitelist_enable"
  51. #define MEDIA_WHITELIST_KEY_STR "whitelist"
  52. // "permissions" fields
  53. #define MEDIA_PERMS_INTERACT_KEY_STR "perms_interact"
  54. #define MEDIA_PERMS_CONTROL_KEY_STR "perms_control"
  55. #define PERMS_OWNER_INTERACT_KEY_STR "perms_owner_interact"
  56. #define PERMS_OWNER_CONTROL_KEY_STR "perms_owner_control"
  57. #define PERMS_GROUP_INTERACT_KEY_STR "perms_group_interact"
  58. #define PERMS_GROUP_CONTROL_KEY_STR "perms_group_control"
  59. #define PERMS_ANYONE_INTERACT_KEY_STR "perms_anyone_interact"
  60. #define PERMS_ANYONE_CONTROL_KEY_STR "perms_anyone_control"
  61. #define TENTATIVE_SUFFIX_STR "_tentative"
  62. // "general" fields
  63. const char* LLMediaEntry::ALT_IMAGE_ENABLE_KEY = MEDIA_ALT_IMAGE_ENABLE_KEY_STR;
  64. const char* LLMediaEntry::CONTROLS_KEY = MEDIA_CONTROLS_KEY_STR;
  65. const char* LLMediaEntry::CURRENT_URL_KEY = MEDIA_CURRENT_URL_KEY_STR;
  66. const char* LLMediaEntry::HOME_URL_KEY = MEDIA_HOME_URL_KEY_STR;
  67. const char* LLMediaEntry::AUTO_LOOP_KEY = MEDIA_AUTO_LOOP_KEY_STR;
  68. const char* LLMediaEntry::AUTO_PLAY_KEY = MEDIA_AUTO_PLAY_KEY_STR;
  69. const char* LLMediaEntry::AUTO_SCALE_KEY = MEDIA_AUTO_SCALE_KEY_STR;
  70. const char* LLMediaEntry::AUTO_ZOOM_KEY = MEDIA_AUTO_ZOOM_KEY_STR;
  71. const char* LLMediaEntry::FIRST_CLICK_INTERACT_KEY = MEDIA_FIRST_CLICK_INTERACT_KEY_STR;
  72. const char* LLMediaEntry::WIDTH_PIXELS_KEY = MEDIA_WIDTH_PIXELS_KEY_STR;
  73. const char* LLMediaEntry::HEIGHT_PIXELS_KEY = MEDIA_HEIGHT_PIXELS_KEY_STR;
  74. // "security" fields
  75. const char* LLMediaEntry::WHITELIST_ENABLE_KEY = MEDIA_WHITELIST_ENABLE_KEY_STR;
  76. const char* LLMediaEntry::WHITELIST_KEY = MEDIA_WHITELIST_KEY_STR;
  77. // "permissions" fields
  78. const char* LLMediaEntry::PERMS_INTERACT_KEY = MEDIA_PERMS_INTERACT_KEY_STR;
  79. const char* LLMediaEntry::PERMS_CONTROL_KEY = MEDIA_PERMS_CONTROL_KEY_STR;
  80. const char* LLMediaEntry::PERMS_OWNER_INTERACT_KEY = PERMS_OWNER_INTERACT_KEY_STR;
  81. const char* LLMediaEntry::PERMS_OWNER_CONTROL_KEY = PERMS_OWNER_CONTROL_KEY_STR;
  82. const char* LLMediaEntry::PERMS_GROUP_INTERACT_KEY = PERMS_GROUP_INTERACT_KEY_STR;
  83. const char* LLMediaEntry::PERMS_GROUP_CONTROL_KEY = PERMS_GROUP_CONTROL_KEY_STR;
  84. const char* LLMediaEntry::PERMS_ANYONE_INTERACT_KEY = PERMS_ANYONE_INTERACT_KEY_STR;
  85. const char* LLMediaEntry::PERMS_ANYONE_CONTROL_KEY = PERMS_ANYONE_CONTROL_KEY_STR;
  86. const char* LLMediaEntry::TENTATIVE_SUFFIX = TENTATIVE_SUFFIX_STR;
  87. #define DEFAULT_URL_PREFIX "http://"
  88. // Constructor(s)
  89. LLMediaEntry::LLMediaEntry()
  90. : mAltImageEnable(false),
  91. mControls(STANDARD),
  92. mCurrentURL(""),
  93. mHomeURL(""),
  94. mAutoLoop(false),
  95. mAutoPlay(false),
  96. mAutoScale(false),
  97. mAutoZoom(false),
  98. mFirstClickInteract(false),
  99. mWidthPixels(0),
  100. mHeightPixels(0),
  101. mWhiteListEnable(false),
  102. // mWhiteList
  103. mPermsInteract(PERM_ALL),
  104. mPermsControl(PERM_ALL),
  105. mMediaIDp(NULL)
  106. {
  107. }
  108. LLMediaEntry::LLMediaEntry(const LLMediaEntry& rhs)
  109. : mMediaIDp(NULL)
  110. {
  111. // "general" fields
  112. mAltImageEnable = rhs.mAltImageEnable;
  113. mControls = rhs.mControls;
  114. mCurrentURL = rhs.mCurrentURL;
  115. mHomeURL = rhs.mHomeURL;
  116. mAutoLoop = rhs.mAutoLoop;
  117. mAutoPlay = rhs.mAutoPlay;
  118. mAutoScale = rhs.mAutoScale;
  119. mAutoZoom = rhs.mAutoZoom;
  120. mFirstClickInteract = rhs.mFirstClickInteract;
  121. mWidthPixels = rhs.mWidthPixels;
  122. mHeightPixels = rhs.mHeightPixels;
  123. // "security" fields
  124. mWhiteListEnable = rhs.mWhiteListEnable;
  125. mWhiteList = rhs.mWhiteList;
  126. // "permissions" fields
  127. mPermsInteract = rhs.mPermsInteract;
  128. mPermsControl = rhs.mPermsControl;
  129. }
  130. LLMediaEntry::~LLMediaEntry()
  131. {
  132. if (mMediaIDp)
  133. {
  134. delete mMediaIDp;
  135. }
  136. }
  137. LLSD LLMediaEntry::asLLSD() const
  138. {
  139. LLSD sd;
  140. asLLSD(sd);
  141. return sd;
  142. }
  143. //
  144. // LLSD functions
  145. //
  146. void LLMediaEntry::asLLSD(LLSD& sd) const
  147. {
  148. // "general" fields
  149. sd[ALT_IMAGE_ENABLE_KEY] = mAltImageEnable;
  150. sd[CONTROLS_KEY] = (LLSD::Integer)mControls;
  151. sd[CURRENT_URL_KEY] = mCurrentURL;
  152. sd[HOME_URL_KEY] = mHomeURL;
  153. sd[AUTO_LOOP_KEY] = mAutoLoop;
  154. sd[AUTO_PLAY_KEY] = mAutoPlay;
  155. sd[AUTO_SCALE_KEY] = mAutoScale;
  156. sd[AUTO_ZOOM_KEY] = mAutoZoom;
  157. sd[FIRST_CLICK_INTERACT_KEY] = mFirstClickInteract;
  158. sd[WIDTH_PIXELS_KEY] = mWidthPixels;
  159. sd[HEIGHT_PIXELS_KEY] = mHeightPixels;
  160. // "security" fields
  161. sd[WHITELIST_ENABLE_KEY] = mWhiteListEnable;
  162. sd.erase(WHITELIST_KEY);
  163. for (U32 i = 0, count = mWhiteList.size(); i < count; ++i)
  164. {
  165. sd[WHITELIST_KEY].append(mWhiteList[i]);
  166. }
  167. // "permissions" fields
  168. sd[PERMS_INTERACT_KEY] = mPermsInteract;
  169. sd[PERMS_CONTROL_KEY] = mPermsControl;
  170. }
  171. // static
  172. bool LLMediaEntry::checkLLSD(const LLSD& sd)
  173. {
  174. if (sd.isUndefined()) return true;
  175. LLMediaEntry temp;
  176. return temp.fromLLSDInternal(sd, true);
  177. }
  178. void LLMediaEntry::fromLLSD(const LLSD& sd)
  179. {
  180. (void)fromLLSDInternal(sd, true);
  181. }
  182. void LLMediaEntry::mergeFromLLSD(const LLSD& sd)
  183. {
  184. (void)fromLLSDInternal(sd, false);
  185. }
  186. // *NOTE: returns true if NO failures to set occurred, false otherwise.
  187. // However, be aware that if a failure to set does occur, it does
  188. // not stop setting fields from the LLSD!
  189. bool LLMediaEntry::fromLLSDInternal(const LLSD& sd, bool overwrite)
  190. {
  191. // *HACK: we sort of cheat here and assume that status is a
  192. // bit field. We "or" into status and instead of returning
  193. // it, we return whether it finishes off as LSL_STATUS_OK or not.
  194. U32 status = LSL_STATUS_OK;
  195. // "general" fields
  196. if (overwrite || sd.has(ALT_IMAGE_ENABLE_KEY))
  197. {
  198. status |= setAltImageEnable(sd[ALT_IMAGE_ENABLE_KEY]);
  199. }
  200. if (overwrite || sd.has(CONTROLS_KEY))
  201. {
  202. status |= setControls((MediaControls)(LLSD::Integer)sd[CONTROLS_KEY]);
  203. }
  204. if (overwrite || sd.has(CURRENT_URL_KEY))
  205. {
  206. // Don't check whitelist
  207. status |= setCurrentURLInternal(sd[CURRENT_URL_KEY], false);
  208. }
  209. if (overwrite || sd.has(HOME_URL_KEY))
  210. {
  211. status |= setHomeURL(sd[HOME_URL_KEY]);
  212. }
  213. if (overwrite || sd.has(AUTO_LOOP_KEY))
  214. {
  215. status |= setAutoLoop(sd[AUTO_LOOP_KEY]);
  216. }
  217. if (overwrite || sd.has(AUTO_PLAY_KEY))
  218. {
  219. status |= setAutoPlay(sd[AUTO_PLAY_KEY]);
  220. }
  221. if (overwrite || sd.has(AUTO_SCALE_KEY))
  222. {
  223. status |= setAutoScale(sd[AUTO_SCALE_KEY]);
  224. }
  225. if (overwrite || sd.has(AUTO_ZOOM_KEY))
  226. {
  227. status |= setAutoZoom(sd[AUTO_ZOOM_KEY]);
  228. }
  229. if (overwrite || sd.has(FIRST_CLICK_INTERACT_KEY))
  230. {
  231. status |= setFirstClickInteract(sd[FIRST_CLICK_INTERACT_KEY]);
  232. }
  233. if (overwrite || sd.has(WIDTH_PIXELS_KEY))
  234. {
  235. status |= setWidthPixels((LLSD::Integer)sd[WIDTH_PIXELS_KEY]);
  236. }
  237. if (overwrite || sd.has(HEIGHT_PIXELS_KEY))
  238. {
  239. status |= setHeightPixels((LLSD::Integer)sd[HEIGHT_PIXELS_KEY]);
  240. }
  241. // "security" fields
  242. if (overwrite || sd.has(WHITELIST_ENABLE_KEY))
  243. {
  244. status |= setWhiteListEnable(sd[WHITELIST_ENABLE_KEY]);
  245. }
  246. if (overwrite || sd.has(WHITELIST_KEY))
  247. {
  248. status |= setWhiteList(sd[WHITELIST_KEY]);
  249. }
  250. // "permissions" fields
  251. if (overwrite || sd.has(PERMS_INTERACT_KEY))
  252. {
  253. status |= setPermsInteract(0xff & (LLSD::Integer)sd[PERMS_INTERACT_KEY]);
  254. }
  255. if (overwrite || sd.has(PERMS_CONTROL_KEY))
  256. {
  257. status |= setPermsControl(0xff & (LLSD::Integer)sd[PERMS_CONTROL_KEY]);
  258. }
  259. return LSL_STATUS_OK == status;
  260. }
  261. LLMediaEntry& LLMediaEntry::operator=(const LLMediaEntry& rhs)
  262. {
  263. if (this != &rhs)
  264. {
  265. // "general" fields
  266. mAltImageEnable = rhs.mAltImageEnable;
  267. mControls = rhs.mControls;
  268. mCurrentURL = rhs.mCurrentURL;
  269. mHomeURL = rhs.mHomeURL;
  270. mAutoLoop = rhs.mAutoLoop;
  271. mAutoPlay = rhs.mAutoPlay;
  272. mAutoScale = rhs.mAutoScale;
  273. mAutoZoom = rhs.mAutoZoom;
  274. mFirstClickInteract = rhs.mFirstClickInteract;
  275. mWidthPixels = rhs.mWidthPixels;
  276. mHeightPixels = rhs.mHeightPixels;
  277. // "security" fields
  278. mWhiteListEnable = rhs.mWhiteListEnable;
  279. mWhiteList = rhs.mWhiteList;
  280. // "permissions" fields
  281. mPermsInteract = rhs.mPermsInteract;
  282. mPermsControl = rhs.mPermsControl;
  283. }
  284. return *this;
  285. }
  286. bool LLMediaEntry::operator==(const LLMediaEntry& rhs) const
  287. {
  288. return // "general" fields
  289. mAltImageEnable == rhs.mAltImageEnable &&
  290. mControls == rhs.mControls &&
  291. mCurrentURL == rhs.mCurrentURL &&
  292. mHomeURL == rhs.mHomeURL &&
  293. mAutoLoop == rhs.mAutoLoop &&
  294. mAutoPlay == rhs.mAutoPlay &&
  295. mAutoScale == rhs.mAutoScale &&
  296. mAutoZoom == rhs.mAutoZoom &&
  297. mFirstClickInteract == rhs.mFirstClickInteract &&
  298. mWidthPixels == rhs.mWidthPixels &&
  299. mHeightPixels == rhs.mHeightPixels &&
  300. // "security" fields
  301. mWhiteListEnable == rhs.mWhiteListEnable &&
  302. mWhiteList == rhs.mWhiteList &&
  303. // "permissions" fields
  304. mPermsInteract == rhs.mPermsInteract &&
  305. mPermsControl == rhs.mPermsControl;
  306. }
  307. bool LLMediaEntry::operator!=(const LLMediaEntry& rhs) const
  308. {
  309. return // "general" fields
  310. mAltImageEnable != rhs.mAltImageEnable ||
  311. mControls != rhs.mControls ||
  312. mCurrentURL != rhs.mCurrentURL ||
  313. mHomeURL != rhs.mHomeURL ||
  314. mAutoLoop != rhs.mAutoLoop ||
  315. mAutoPlay != rhs.mAutoPlay ||
  316. mAutoScale != rhs.mAutoScale ||
  317. mAutoZoom != rhs.mAutoZoom ||
  318. mFirstClickInteract != rhs.mFirstClickInteract ||
  319. mWidthPixels != rhs.mWidthPixels ||
  320. mHeightPixels != rhs.mHeightPixels ||
  321. // "security" fields
  322. mWhiteListEnable != rhs.mWhiteListEnable ||
  323. mWhiteList != rhs.mWhiteList ||
  324. // "permissions" fields
  325. mPermsInteract != rhs.mPermsInteract ||
  326. mPermsControl != rhs.mPermsControl;
  327. }
  328. U32 LLMediaEntry::setWhiteList(const std::vector<std::string>& whitelist)
  329. {
  330. // *NOTE: This code is VERY similar to the setWhitelist below.
  331. // IF YOU CHANGE THIS IMPLEMENTATION, BE SURE TO CHANGE THE OTHER!
  332. U32 size = 0;
  333. U32 count = 0;
  334. // First count to make sure the size constraint is not violated
  335. std::vector<std::string>::const_iterator iter = whitelist.begin();
  336. std::vector<std::string>::const_iterator end = whitelist.end();
  337. for ( ; iter < end; ++iter)
  338. {
  339. const std::string& entry = *iter;
  340. size += entry.length() + 1; // Include one for \0
  341. ++count;
  342. if (size > MAX_WHITELIST_SIZE || count > MAX_WHITELIST_COUNT)
  343. {
  344. return LSL_STATUS_BOUNDS_ERROR;
  345. }
  346. }
  347. // Next clear the vector
  348. mWhiteList.clear();
  349. // Then re-iterate and copy entries
  350. iter = whitelist.begin();
  351. for ( ; iter < end; ++iter)
  352. {
  353. const std::string& entry = *iter;
  354. mWhiteList.push_back(entry);
  355. }
  356. return LSL_STATUS_OK;
  357. }
  358. U32 LLMediaEntry::setWhiteList(const LLSD& whitelist)
  359. {
  360. // If whitelist is undef, the whitelist is cleared
  361. if (whitelist.isUndefined())
  362. {
  363. mWhiteList.clear();
  364. return LSL_STATUS_OK;
  365. }
  366. // However, if the whitelist is an empty array, erase it.
  367. if (whitelist.isArray())
  368. {
  369. // *NOTE: This code is VERY similar to the setWhitelist above.
  370. // IF YOU CHANGE THIS IMPLEMENTATION, BE SURE TO CHANGE THE OTHER!
  371. U32 size = 0;
  372. U32 count = 0;
  373. // First check to make sure the size and count constraints are not
  374. // violated
  375. LLSD::array_const_iterator iter = whitelist.beginArray();
  376. LLSD::array_const_iterator end = whitelist.endArray();
  377. for ( ; iter < end; ++iter)
  378. {
  379. const std::string& entry = (*iter).asString();
  380. size += entry.length() + 1; // Include one for \0
  381. count ++;
  382. if (size > MAX_WHITELIST_SIZE || count > MAX_WHITELIST_COUNT)
  383. {
  384. return LSL_STATUS_BOUNDS_ERROR;
  385. }
  386. }
  387. // Next clear the vector
  388. mWhiteList.clear();
  389. // Then re-iterate and copy entries
  390. iter = whitelist.beginArray();
  391. for ( ; iter < end; ++iter)
  392. {
  393. const std::string& entry = (*iter).asString();
  394. mWhiteList.push_back(entry);
  395. }
  396. return LSL_STATUS_OK;
  397. }
  398. else
  399. {
  400. return LSL_STATUS_MALFORMED_PARAMS;
  401. }
  402. }
  403. static void prefix_with(std::string& str, const char* chars, const char* prefix)
  404. {
  405. // Given string 'str', prefix all instances of any character in 'chars'
  406. // with 'prefix'
  407. size_t found = str.find_first_of(chars);
  408. size_t prefix_len = strlen(prefix);
  409. while (found != std::string::npos)
  410. {
  411. str.insert(found, prefix, prefix_len);
  412. found = str.find_first_of(chars, found+prefix_len+1);
  413. }
  414. }
  415. static bool pattern_match(const std::string& candidate_str,
  416. const std::string& pattern)
  417. {
  418. // If the pattern is empty, it matches
  419. if (pattern.empty()) return true;
  420. // 'pattern' is a glob pattern, we only accept '*' chars. Copy it.
  421. std::string expression = pattern;
  422. // Escape perl's regexp chars with a backslash, except all "*" chars
  423. prefix_with(expression, ".[{()\\+?|^$", "\\");
  424. prefix_with(expression, "*", ".");
  425. bool result = false;
  426. try
  427. {
  428. // Case-insensitive matching:
  429. std::regex regexp(expression,
  430. std::regex::ECMAScript | std::regex::icase);
  431. result = std::regex_match(candidate_str, regexp);
  432. }
  433. catch (std::regex_error& e)
  434. {
  435. llwarns << "Regex error: " << e.what() << llendl;
  436. }
  437. return result;
  438. }
  439. bool LLMediaEntry::checkCandidateUrl(const std::string& url) const
  440. {
  441. if (getWhiteListEnable())
  442. {
  443. return checkUrlAgainstWhitelist(url, getWhiteList());
  444. }
  445. else
  446. {
  447. return true;
  448. }
  449. }
  450. // static
  451. bool LLMediaEntry::checkUrlAgainstWhitelist(const std::string& url,
  452. const std::vector<std::string>& whitelist)
  453. {
  454. bool passes = true;
  455. // *NOTE: no entries? Don't check
  456. if (whitelist.size() > 0)
  457. {
  458. passes = false;
  459. // Case insensitive: the reason why we toUpper both this and the filter
  460. std::string candidate_url = url;
  461. // Use lluri to see if there is a path part in the candidate URL.
  462. // No path ? Assume "/"
  463. LLURI candidate_uri(candidate_url);
  464. std::vector<std::string>::const_iterator iter = whitelist.begin();
  465. std::vector<std::string>::const_iterator end = whitelist.end();
  466. for ( ; iter < end; ++iter)
  467. {
  468. std::string filter = *iter;
  469. LLURI filter_uri(filter);
  470. bool scheme_passes = pattern_match(candidate_uri.scheme(),
  471. filter_uri.scheme());
  472. if (filter_uri.scheme().empty())
  473. {
  474. filter_uri = LLURI(DEFAULT_URL_PREFIX + filter);
  475. }
  476. bool authority_passes = pattern_match(candidate_uri.authority(),
  477. filter_uri.authority());
  478. bool path_passes = pattern_match(candidate_uri.escapedPath(),
  479. filter_uri.escapedPath());
  480. if (scheme_passes && authority_passes && path_passes)
  481. {
  482. passes = true;
  483. break;
  484. }
  485. }
  486. }
  487. return passes;
  488. }
  489. U32 LLMediaEntry::setStringFieldWithLimit(std::string& field,
  490. const std::string& value,
  491. U32 limit)
  492. {
  493. if (value.length() > limit)
  494. {
  495. return LSL_STATUS_BOUNDS_ERROR;
  496. }
  497. else
  498. {
  499. field = value;
  500. return LSL_STATUS_OK;
  501. }
  502. }
  503. U32 LLMediaEntry::setControls(LLMediaEntry::MediaControls controls)
  504. {
  505. if (controls == STANDARD ||
  506. controls == MINI)
  507. {
  508. mControls = controls;
  509. return LSL_STATUS_OK;
  510. }
  511. return LSL_STATUS_BOUNDS_ERROR;
  512. }
  513. U32 LLMediaEntry::setPermsInteract(U8 val)
  514. {
  515. mPermsInteract = val & PERM_MASK;
  516. return LSL_STATUS_OK;
  517. }
  518. U32 LLMediaEntry::setPermsControl(U8 val)
  519. {
  520. mPermsControl = val & PERM_MASK;
  521. return LSL_STATUS_OK;
  522. }
  523. U32 LLMediaEntry::setCurrentURL(const std::string& current_url)
  524. {
  525. return setCurrentURLInternal(current_url, true);
  526. }
  527. U32 LLMediaEntry::setCurrentURLInternal(const std::string& current_url,
  528. bool check_whitelist)
  529. {
  530. if (!check_whitelist || checkCandidateUrl(current_url))
  531. {
  532. return setStringFieldWithLimit(mCurrentURL, current_url, MAX_URL_LENGTH);
  533. }
  534. else
  535. {
  536. return LSL_STATUS_WHITELIST_FAILED;
  537. }
  538. }
  539. U32 LLMediaEntry::setHomeURL(const std::string& home_url)
  540. {
  541. return setStringFieldWithLimit(mHomeURL, home_url, MAX_URL_LENGTH);
  542. }
  543. U32 LLMediaEntry::setWidthPixels(U16 width)
  544. {
  545. if (width > MAX_WIDTH_PIXELS) return LSL_STATUS_BOUNDS_ERROR;
  546. mWidthPixels = width;
  547. return LSL_STATUS_OK;
  548. }
  549. U32 LLMediaEntry::setHeightPixels(U16 height)
  550. {
  551. if (height > MAX_HEIGHT_PIXELS) return LSL_STATUS_BOUNDS_ERROR;
  552. mHeightPixels = height;
  553. return LSL_STATUS_OK;
  554. }
  555. const LLUUID& LLMediaEntry::getMediaID() const
  556. {
  557. // Lazily generate media ID
  558. if (!mMediaIDp)
  559. {
  560. mMediaIDp = new LLUUID();
  561. mMediaIDp->generate();
  562. }
  563. return *mMediaIDp;
  564. }