OpenShot Audio Library | OpenShotAudio: juce_URL.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.1

Loading...
Searching...
No Matches
juce_URL.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26class WebInputStream;
27
28//==============================================================================
37 class JUCE_API URL
38{
39public:
40 //==============================================================================
42 URL();
43
49 URL (const String& url);
50
51 URL (const URL&) = default;
52 URL& operator= (const URL&) = default;
53 URL (URL&&) = default;
54 URL& operator= (URL&&) = default;
55
57 explicit URL (File);
58
60 ~URL() = default;
61
66 bool operator== (const URL&) const;
67 bool operator!= (const URL&) const;
68
69 //==============================================================================
76 String toString (bool includeGetParameters) const;
77
79 bool isEmpty() const noexcept;
80
82 bool isWellFormed() const;
83
87 String getDomain() const;
88
96 String getSubPath (bool includeGetParameters = false) const;
97
101 String getQueryString() const;
102
107 String getScheme() const;
108
110 bool isLocalFile() const;
111
121 File getLocalFile() const;
122
130 String getFileName() const;
131
135 int getPort() const;
136
142 URL withNewDomainAndPath (const String& newFullPath) const;
143
149 URL withNewSubPath (const String& newPath) const;
150
154 URL getParentURL() const;
155
166 URL getChildURL (const String& subPath) const;
167
168 //==============================================================================
178 URL withParameter (const String& parameterName,
179 const String& parameterValue) const;
180
185 URL withParameters (const StringPairArray& parametersToAdd) const;
186
198 URL withFileToUpload (const String& parameterName,
199 const File& fileToUpload,
200 const String& mimeType) const;
201
211 URL withDataToUpload (const String& parameterName,
212 const String& filename,
213 const MemoryBlock& fileContentToUpload,
214 const String& mimeType) const;
215
226 const StringArray& getParameterNames() const noexcept { return parameterNames; }
227
240 const StringArray& getParameterValues() const noexcept { return parameterValues; }
241
254 URL withPOSTData (const String& postData) const;
255
268 URL withPOSTData (const MemoryBlock& postData) const;
269
271 String getPostData() const { return postData.toString(); }
272
274 const MemoryBlock& getPostDataAsMemoryBlock() const noexcept { return postData; }
275
276 //==============================================================================
280 bool launchInDefaultBrowser() const;
281
282 //==============================================================================
286 static bool isProbablyAWebsiteURL (const String& possibleURL);
287
291 static bool isProbablyAnEmailAddress (const String& possibleEmailAddress);
292
293 //==============================================================================
299 using OpenStreamProgressCallback = bool (void* context, int bytesSent, int totalBytes);
300
343 InputStream* createInputStream (bool doPostLikeRequest,
344 OpenStreamProgressCallback* progressCallback = nullptr,
345 void* progressCallbackContext = nullptr,
346 String extraHeaders = {},
347 int connectionTimeOutMs = 0,
348 StringPairArray* responseHeaders = nullptr,
349 int* statusCode = nullptr,
350 int numRedirectsToFollow = 5,
351 String httpRequestCmd = {}) const;
352
358 OutputStream* createOutputStream() const;
359
360 //==============================================================================
364 class JUCE_API DownloadTask
365 {
366 public:
368 struct JUCE_API Listener
369 {
370 virtual ~Listener();
371
374 virtual void finished (URL::DownloadTask* task, bool success) = 0;
375
379 virtual void progress (URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength);
380 };
381
384 virtual ~DownloadTask();
385
388 int64 getTotalLength() const { return contentLength; }
389
391 int64 getLengthDownloaded() const { return downloaded; }
392
394 bool isFinished() const { return finished; }
395
400 int statusCode() const { return httpCode; }
401
403 inline bool hadError() const { return error; }
404
406 File getTargetLocation() const { return targetLocation; }
407
408 protected:
409 int64 contentLength = -1, downloaded = 0;
410 bool finished = false, error = false;
411 int httpCode = -1;
412 File targetLocation;
413
414 DownloadTask();
415
416 private:
417 friend class URL;
418 static DownloadTask* createFallbackDownloader (const URL&, const File&, const String&, Listener*, bool);
419
420 public:
421 #if JUCE_IOS
423 static void juce_iosURLSessionNotify (const String&);
424 #endif
425
426 private:
427 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DownloadTask)
428 };
429
439 DownloadTask* downloadToFile (const File& targetLocation,
440 String extraHeaders = String(),
441 DownloadTask::Listener* listener = nullptr,
442 bool usePostCommand = false);
443
444 //==============================================================================
458 bool readEntireBinaryStream (MemoryBlock& destData,
459 bool usePostCommand = false) const;
460
475 String readEntireTextStream (bool usePostCommand = false) const;
476
493 std::unique_ptr<XmlElement> readEntireXmlStream (bool usePostCommand = false) const;
494
495 //==============================================================================
514 static String addEscapeChars (const String& stringToAddEscapeCharsTo,
515 bool isParameter,
516 bool roundBracketsAreLegal = true);
517
527 static String removeEscapeChars (const String& stringToRemoveEscapeCharsFrom);
528
533 static URL createWithoutParsing (const String& url);
534
535private:
536 //==============================================================================
537 friend class WebInputStream;
538
539 String url;
540 MemoryBlock postData;
541 StringArray parameterNames, parameterValues;
542
543 static File fileFromFileSchemeURL (const URL&);
544 String getDomainInternal (bool) const;
545
546 struct Upload : public ReferenceCountedObject
547 {
548 Upload (const String&, const String&, const String&, const File&, MemoryBlock*);
549 String parameterName, filename, mimeType;
550 File file;
551 std::unique_ptr<MemoryBlock> data;
552
553 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Upload)
554 };
555
556 ReferenceCountedArray<Upload> filesToUpload;
557
558 #if JUCE_IOS
559 struct Bookmark : public ReferenceCountedObject
560 {
561 using Ptr = ReferenceCountedObjectPtr<Bookmark>;
562
563 Bookmark (void*);
564 ~Bookmark();
565
566 void* data;
567 };
568
569 Bookmark::Ptr bookmark;
570
571 friend void setURLBookmark (URL&, void*);
572 friend void* getURLBookmark (URL&);
573 #endif
574
575 URL (const String&, int);
576 void init();
577 void addParameter (const String&, const String&);
578 void createHeadersAndPostData (String&, MemoryBlock&) const;
579 URL withUpload (Upload*) const;
580
581 JUCE_LEAK_DETECTOR (URL)
582};
583
584} // namespace juce
juce::File
Definition: juce_File.h:41
juce::InputStream
Definition: juce_InputStream.h:37
juce::MemoryBlock
Definition: juce_MemoryBlock.h:33
juce::ReferenceCountedArray
Definition: juce_ReferenceCountedArray.h:51
juce::ReferenceCountedObjectPtr
Definition: juce_ReferenceCountedObject.h:247
juce::ReferenceCountedObject
Definition: juce_ReferenceCountedObject.h:66
juce::StringArray
Definition: juce_StringArray.h:35
juce::StringPairArray
Definition: juce_StringPairArray.h:35
juce::String
Definition: juce_String.h:39
juce::URL::DownloadTask
Definition: juce_URL.h:365
juce::URL::DownloadTask::hadError
bool hadError() const
Definition: juce_URL.h:403
juce::URL::DownloadTask::getLengthDownloaded
int64 getLengthDownloaded() const
Definition: juce_URL.h:391
juce::URL::DownloadTask::isFinished
bool isFinished() const
Definition: juce_URL.h:394
juce::URL::DownloadTask::getTargetLocation
File getTargetLocation() const
Definition: juce_URL.h:406
juce::URL::DownloadTask::statusCode
int statusCode() const
Definition: juce_URL.h:400
juce::URL::DownloadTask::getTotalLength
int64 getTotalLength() const
Definition: juce_URL.h:388
juce::URL
Definition: juce_URL.h:38
juce::URL::getPostDataAsMemoryBlock
const MemoryBlock & getPostDataAsMemoryBlock() const noexcept
Definition: juce_URL.h:274
juce::URL::getPostData
String getPostData() const
Definition: juce_URL.h:271
juce::URL::getParameterValues
const StringArray & getParameterValues() const noexcept
Definition: juce_URL.h:240
juce::URL::OpenStreamProgressCallback
bool(void *context, int bytesSent, int totalBytes) OpenStreamProgressCallback
Definition: juce_URL.h:299
juce::URL::~URL
~URL()=default
juce::URL::downloadToFile
DownloadTask * downloadToFile(const File &targetLocation, String extraHeaders=String(), DownloadTask::Listener *listener=nullptr, bool usePostCommand=false)
juce::WebInputStream
Definition: juce_WebInputStream.h:33
juce::URL::DownloadTask::Listener
Definition: juce_URL.h:369
juce::URL::DownloadTask::Listener::finished
virtual void finished(URL::DownloadTask *task, bool success)=0