|
18 | 18 | #include <absl/strings/escaping.h>
|
19 | 19 | #include <absl/strings/numbers.h>
|
20 | 20 | #include <absl/strings/str_format.h>
|
| 21 | +#include <curl/curl.h> |
21 | 22 | #include <libxml/tree.h>
|
22 | 23 |
|
23 | 24 | #include <packager/macros/compiler.h>
|
@@ -53,6 +54,18 @@ const char kDTSCCodec[] = "dtsc";
|
53 | 54 | const char kDTSECodec[] = "dtse";
|
54 | 55 | const char kDTSXCodec[] = "dtsx";
|
55 | 56 |
|
| 57 | +std::string urlEncode(const std::string& input) { |
| 58 | + // NOTE: According to the docs, "Since 7.82.0, the curl parameter is ignored". |
| 59 | + CURL* curl = NULL; |
| 60 | + char* output = curl_easy_escape(curl, input.c_str(), input.length()); |
| 61 | + if (output) { |
| 62 | + std::string encodedUrl(output); |
| 63 | + curl_free(output); // Free the output string when done |
| 64 | + return encodedUrl; |
| 65 | + } |
| 66 | + return ""; // Return empty string if initialization fails |
| 67 | +} |
| 68 | + |
56 | 69 | std::string RangeToString(const Range& range) {
|
57 | 70 | return absl::StrFormat("%u-%u", range.begin(), range.end());
|
58 | 71 | }
|
@@ -220,11 +233,19 @@ void XmlNode::AddContent(const std::string& content) {
|
220 | 233 | xmlNodeAddContent(impl_->node.get(), BAD_CAST content.c_str());
|
221 | 234 | }
|
222 | 235 |
|
| 236 | +void XmlNode::AddUrlEncodedContent(const std::string& content) { |
| 237 | + AddContent(urlEncode(content)); |
| 238 | +} |
| 239 | + |
223 | 240 | void XmlNode::SetContent(const std::string& content) {
|
224 | 241 | DCHECK(impl_->node);
|
225 | 242 | xmlNodeSetContent(impl_->node.get(), BAD_CAST content.c_str());
|
226 | 243 | }
|
227 | 244 |
|
| 245 | +void XmlNode::SetUrlEncodedContent(const std::string& content) { |
| 246 | + SetContent(urlEncode(content)); |
| 247 | +} |
| 248 | + |
228 | 249 | std::set<std::string> XmlNode::ExtractReferencedNamespaces() const {
|
229 | 250 | std::set<std::string> namespaces;
|
230 | 251 | TraverseNodesAndCollectNamespaces(impl_->node.get(), &namespaces);
|
@@ -400,7 +421,7 @@ bool RepresentationXmlNode::AddVODOnlyInfo(const MediaInfo& media_info,
|
400 | 421 |
|
401 | 422 | if (media_info.has_media_file_url() && !use_single_segment_url_with_media) {
|
402 | 423 | XmlNode base_url("BaseURL");
|
403 |
| - base_url.SetContent(media_info.media_file_url()); |
| 424 | + base_url.SetUrlEncodedContent(media_info.media_file_url()); |
404 | 425 |
|
405 | 426 | RCHECK(AddChild(std::move(base_url)));
|
406 | 427 | }
|
@@ -452,7 +473,8 @@ bool RepresentationXmlNode::AddVODOnlyInfo(const MediaInfo& media_info,
|
452 | 473 |
|
453 | 474 | if (use_single_segment_url_with_media) {
|
454 | 475 | XmlNode media_url("SegmentURL");
|
455 |
| - RCHECK(media_url.SetStringAttribute("media", media_info.media_file_url())); |
| 476 | + RCHECK(media_url.SetStringAttribute( |
| 477 | + "media", urlEncode(media_info.media_file_url()))); |
456 | 478 | RCHECK(child.AddChild(std::move(media_url)));
|
457 | 479 | }
|
458 | 480 |
|
|
0 commit comments