libaria2cpp 0.2.0
Basic CPP library to connect to an ARIA2 daemon via the RPC interface.
downloadoptions.h
1/*
2 * ARIA2CPP: Basic CPP library to connect to an ARIA2 daemon
3 * via the RPC interface.
4 *
5 * *ALPHA VERSION!*
6 *
7 * Copyright (C) 2021 Dennis Katsonis dennisk@netspace.net.au
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#ifndef DOWNLOADOPTIONS_H_
25#define DOWNLOADOPTIONS_H_
26
27#include <string>
28#include <memory>
29#include <utility>
30#include "client.h"
31#include "func.h"
32#include "download.h"
33
34
35struct boolOption {
36 bool first = false;
37 bool second;
38 std::string asJson()
39 {
40 return BoolToString(second);
41 }
42};
43
44
46 bool first = false;
47 float second;
48 std::string asJson()
49 {
50 return std::to_string(second);
51 }
52};
53
54struct intOption {
55 bool first = false;
56 int second;
57 std::string asJson()
58 {
59 return std::to_string(second);
60 }
61};
62
63
65 bool first = false;
66 size_t second;
67 std::string asJson()
68 {
69 return std::to_string(second);
70 }
71};
72
74 bool first = false;
75 std::string second;
76 std::string asJson()
77 {
78 return second;
79 }
80};
81
83 bool first = false;
84 URISelector second;
85 std::string asJson()
86 {
87 if (second == URISelector::inorder) {
88 return "inorder";
89 } else if (second == URISelector::feedback) {
90 return "feedback";
91 } else if (second == URISelector::adaptive) {
92 return "adaptive";
93 }
94 return "inorder";
95 }
96};
97
99 bool first = false;
100 ProxyMethod second;
101 std::string asJson()
102 {
103 if (second == ProxyMethod::get) {
104 return "get";
105 } else if (second == ProxyMethod::tunnel) {
106 return "tunnel";
107 }
108 return "get";
109 }
110};
111
113 bool first = false;
114 CryptoLevel second;
115 std::string asJson()
116 {
117 if (second == CryptoLevel::plain) {
118 return "plain";
119 } else if (second == CryptoLevel::arc4) {
120 return "arc4";
121 }
122 return "plain";
123 }
124};
125
126
128 bool first = false;
129 MetalinkProtocol second;
130 std::string asJson()
131 {
132 if (second == MetalinkProtocol::http) {
133 return "http";
134 } else if (second == MetalinkProtocol::https) {
135 return "https";
136 } else if (second == MetalinkProtocol::ftp) {
137 return "ftp";
138 } else if (second == MetalinkProtocol::none) {
139 return "none";
140 }
141 return "none";
142 }
143};
144
145
147 bool first = false;
148 FileAllocation second;
149 std::string asJson()
150 {
151 if (second == FileAllocation::none) {
152 return "none";
153 } else if (second == FileAllocation::prealloc) {
154 return "prealloc";
155 } else if (second == FileAllocation::falloc) {
156 return "falloc";
157 } else if (second == FileAllocation::trunc) {
158 return "trunc";
159 }
160 return "none";
161 }
162};
163
164
166 bool first = false;
167 FTPType second;
168 std::string asJson()
169 {
170 if (second == FTPType::binary) {
171 return "binary";
172 } else if (second == FTPType::ascii) {
173 return "ascii";
174 }
175 return "binary";
176 }
177};
178
179
181 bool first = false;
182 PieceSelectionAlgorithm second;
183 std::string asJson()
184 {
185 if (second == PieceSelectionAlgorithm::def) {
186 return "default";
187 } else if (second == PieceSelectionAlgorithm::inorder) {
188 return "inorder";
189 } else if (second == PieceSelectionAlgorithm::geom) {
190 return "geom";
191 } else if (second == PieceSelectionAlgorithm::random) {
192 return "random";
193 }
194 return "default";
195 }
196};
197
198
200 bool first = false;
201 stringList second;
202 Json::Value asJson()
203 {
204 Json::Value uris(Json::arrayValue);
205 for(auto const &x : second) {
206 uris.append(x.c_str());
207 }
208 return uris;
209 }
210};
211
212//using boolOption = std::pair<bool, bool>;
213//using floatOption = std::pair<bool, float>;
214//using intOption = std::pair<bool, int>;
215//using size_tOption = std::pair<bool, size_t>;
216//using stringOption = std::pair<bool, std::string>;
217//using stringListOption = std::pair<bool, stringList>;
218
219
220using namespace jsonrpc;
235{
236public:
237 Json::Value m_options;
244 bool update();
246 Json::Value asJsonArray();
247
248
249 /******************
250 * SETTER METHODS
251 ****************/
252
253
254
255
257 void setBtMaxPeers(int value);
259 void setBtRemoveUnselectedFile(bool value);
261 void setForceSave(bool value);
263 void setMaxDownloadLimit(int value);
265 void setMaxUploadLimit(int value);
267 void setPieceLength(int value);
269 void setRpcSaveUploadMetadata(bool value);
271 void setBtRequestPeerSpeedLimit(int value);
273 void setDryRun(bool value);
275 void setDir(std::string value);
281 void setBtMinCryptoLevel(CryptoLevel value);
282 void setFtpType(FTPType value);
283 void setFileAllocation(FileAllocation value);
284 void setMetalinkPreferredProtocol(MetalinkProtocol value);
285 void setStreamPieceSelector(PieceSelectionAlgorithm value);
286 void setProxyMethod(ProxyMethod value);
287 void setUriSelector(URISelector value);
288 void setAllowOverwrite(bool value);
289 void setAllowPieceLengthChange(bool value);
290 void setAlwaysResume(bool value);
291 void setAsyncDns(bool value);
292 void setAutoFileRenaming(bool value);
293 void setBtEnableHookAfterHashCheck(bool value);
294 void setBtEnablelpd(bool value);
295 void setBtForceEncryption(bool value);
296 void setBtHashCheckSeed(bool value);
297 void setBtLoadSavedMetadata(bool value);
298 void setBtMetadataOnly(bool value);
299 void setBtRequireCrypto(bool value);
300 void setBtSaveMetadata(bool value);
301 void setBtSeedUnverified(bool value);
302 void setBtStopTimeout(bool value);
303 void setCheckIntegrity(bool value);
304 void setConditionalGet(bool value);
305 void setCont(bool value);
306 void setEnableHttpKeepAlive(bool value);
307 void setEnableHttpPipelining(bool value);
308 void setEnableMmap(bool value);
309 void setEnablePeerExchange(bool value);
310 void setFollowMetalink(bool value);
311 void setFollowTorrent(bool value);
312 void setFtpPasv(bool value);
313 void setFtpReuseConnection(bool value);
314 void setHashCheckOnly(bool value);
315 void setHttpAcceptGzip(bool value);
316 void setHttpAuthChallenge(bool value);
317 void setHttpNoCache(bool value);
318 void setMetalinkEnableUniqueProtocol(bool value);
319 void setNoNetrc(bool value);
320 void setParameterizedUri(bool value);
321 void setPause(bool value);
322 void setPauseMetadata(bool value);
323 void setRealtimeChunkChecksum(bool value);
324 void setRemoteTime(bool value);
325 void setRemoveControlFile(bool value);
326 void setReuseUri(bool value);
327 void setUseHead(bool value);
328 void setSeedRatio(float value);
329 void setSeedTime(float value);
330 void setBtTrackerConnectTimeout(int value);
331 void setBtTrackerInterval(int value);
332 void setBtTrackerTimeout(int value);
333 void setConnectTimeout(int value);
334 void setLowestSpeedLimit(int value);
335 void setMaxConnectionPerServer(int value);
336 void setMaxResumeFailureTries(int value);
337 void setMaxTries(int value);
338 void setRetryWait(int value);
339 void setSplit(int value);
340 void setStop(int value);
341 void setTimeout(int value);
342 void setMaxMmapLimit(size_t value);
343 void setMinSplitSize(size_t value);
344 void setNoFileAllocationLimit(size_t value);
345 void setBtTracker(stringList value);
346 void setBtExternalIp(std::string value);
347 void setFtpPasswd(std::string value);
348 void setFtpProxy(std::string value);
349 void setFtpProxyPasswd(std::string value);
350 void setFtpProxyUser(std::string value);
351 void setFtpUser(std::string value);
352 void setGid(std::string value);
353 void setHttpPasswd(std::string value);
354 void setHttpProxy(std::string value);
355 void setHttpProxyPasswd(std::string value);
356 void setHttpProxyUser(std::string value);
357 void setHttpUser(std::string value);
358 void setHttpsProxy(std::string value);
359 void setHttpsProxyPasswd(std::string value);
360 void setHttpsProxyUser(std::string value);
361 void setMetalinkLanguage(std::string value);
362 void setMetalinkLocation(std::string value);
363 void setMetalinkOs(std::string value);
364 void setMetalinkVersion(std::string value);
365 void setOut(std::string value);
366 void setUserAgent(std::string value);
367
368
369
370 /******************
371 * GETTER METHODS
372 ****************/
373
374
375
376
377 bool getDryRun() const;
379 bool getForceSave() const;
381 bool getRpcSaveUploadMetadata() const;
383 int getBtMaxPeers() const;
385 int getBtRequestPeerSpeedLimit() const;
387 int getMaxDownloadLimit() const;
389 int getMaxUploadLimit() const;
391 size_t getPieceLength() const;
393 bool getBtRemoveUnselectedFile() const;
395 std::string getDir() const;
396
397 CryptoLevel getBtMinCryptoLevel() const;
398 FTPType getFtpType() const;
399 FileAllocation getFileAllocation() const;
400 MetalinkProtocol getMetalinkPreferredProtocol() const;
401 PieceSelectionAlgorithm getStreamPieceSelector() const;
402 ProxyMethod getProxyMethod() const;
403 URISelector getUriSelector() const;
404 bool getAllowOverwrite() const;
405 bool getAllowPieceLengthChange() const;
406 bool getAlwaysResume() const;
407 bool getAsyncDns() const;
408 bool getAutoFileRenaming() const;
409 bool getBtEnableHookAfterHashCheck() const;
410 bool getBtEnablelpd() const;
411 bool getBtForceEncryption() const;
412 bool getBtHashCheckSeed() const;
413 bool getBtLoadSavedMetadata() const;
414 bool getBtMetadataOnly() const;
415 bool getBtRequireCrypto() const;
416 bool getBtSaveMetadata() const;
417 bool getBtSeedUnverified() const;
418 bool getBtStopTimeout() const;
419 bool getCheckIntegrity() const;
420 bool getConditionalGet() const;
421 bool getCont() const;
422 bool getEnableHttpKeepAlive() const;
423 bool getEnableHttpPipelining() const;
424 bool getEnableMmap() const;
425 bool getEnablePeerExchange() const;
426 bool getFollowMetalink() const;
427 bool getFollowTorrent() const;
428 bool getFtpPasv() const;
429 bool getFtpReuseConnection() const;
430 bool getHashCheckOnly() const;
431 bool getHttpAcceptGzip() const;
432 bool getHttpAuthChallenge() const;
433 bool getHttpNoCache() const;
434 bool getMetalinkEnableUniqueProtocol() const;
435 bool getNoNetrc() const;
436 bool getParameterizedUri() const;
437 bool getPause() const;
438 bool getPauseMetadata() const;
439 bool getRealtimeChunkChecksum() const;
440 bool getRemoteTime() const;
441 bool getRemoveControlFile() const;
442 bool getReuseUri() const;
443 bool getUseHead() const;
444 float getSeedRatio() const;
445 float getSeedTime() const;
446 int getBtTrackerConnectTimeout() const;
447 int getBtTrackerInterval() const;
448 int getBtTrackerTimeout() const;
449 int getConnectTimeout() const;
450 int getLowestSpeedLimit() const;
451 int getMaxConnectionPerServer() const;
452 int getMaxResumeFailureTries() const;
453 int getMaxTries() const;
454 int getRetryWait() const;
455 int getSplit() const;
456 int getStop() const;
457 int getTimeout() const;
458 size_t getMaxMmapLimit() const;
459 size_t getMinSplitSize() const;
460 size_t getNoFileAllocationLimit() const;
461 std::string getBtExternalIp() const;
462 std::string getFtpPasswd() const;
463 std::string getFtpProxy() const;
464 std::string getFtpProxyPasswd() const;
465 std::string getFtpProxyUser() const;
466 std::string getFtpUser() const;
467 std::string getGid() const;
468 std::string getHttpPasswd() const;
469 std::string getHttpProxy() const;
470 std::string getHttpProxyPasswd() const;
471 std::string getHttpProxyUser() const;
472 std::string getHttpUser() const;
473 std::string getHttpsProxy() const;
474 std::string getHttpsProxyPasswd() const;
475 std::string getHttpsProxyUser() const;
476 std::string getMetalinkLanguage() const;
477 std::string getMetalinkLocation() const;
478 std::string getMetalinkOs() const;
479 std::string getMetalinkVersion() const;
480 std::string getOut() const;
481 std::string getUserAgent() const;
482 stringList getBtTracker() const;
483
484
485
486
487
488private:
490 boolOption dryRun;
492 boolOption forceSave;
494 boolOption rpcSaveUploadMetadata;
496 intOption btMaxPeers;
498 intOption btRequestPeerSpeedLimit;
500 intOption maxDownloadLimit;
502 intOption maxUploadLimit;
504 size_tOption pieceLength;
506 boolOption btRemoveUnselectedFile;
508 stringOption dir;
509 // all-proxy
510 //all-proxy-passwd
511 //all-proxy-user
512
514 boolOption allowOverwrite;
516 boolOption allowPieceLengthChange;
518 boolOption alwaysResume;
520 boolOption asyncDns;
522 boolOption autoFileRenaming;
524 boolOption btEnablelpd;
526 boolOption btForceEncryption;
528 boolOption btHashCheckSeed;
530 boolOption btLoadSavedMetadata;
532 boolOption btMetadataOnly;
534 boolOption btEnableHookAfterHashCheck;
536 stringOption btExternalIp;
538 CryptoLevelOption btMinCryptoLevel;
539 //bt-prioritize-piece
541 boolOption btRequireCrypto;
543 boolOption btSaveMetadata;
545 boolOption btSeedUnverified;
546
548 boolOption btStopTimeout;
549
551 stringListOption btTracker;
553 intOption btTrackerConnectTimeout;
555 intOption btTrackerInterval;
557 intOption btTrackerTimeout;
559 boolOption checkIntegrity;
561 boolOption conditionalGet;
563 intOption connectTimeout;
564
566 boolOption cont;
568 boolOption enableHttpKeepAlive;
570 boolOption enableHttpPipelining;
572 boolOption enableMmap;
574 boolOption enablePeerExchange;
575
577 FileAllocationOption fileAllocation;
578
580 boolOption followMetalink;
582 boolOption followTorrent;
583
585 stringOption ftpUser;
587 stringOption ftpPasswd;
589 stringOption ftpProxy;
591 stringOption ftpProxyPasswd;
593 stringOption ftpProxyUser;
595 boolOption ftpReuseConnection;
597 FTPTypeOption ftpType;
599 boolOption ftpPasv;
601 stringOption gid;
603 boolOption hashCheckOnly;
605 boolOption httpAcceptGzip;
607 boolOption httpAuthChallenge;
609 boolOption httpNoCache;
610 //header
612 stringOption httpUser;
614 stringOption httpPasswd;
616 stringOption httpProxy;
618 stringOption httpProxyPasswd;
620 stringOption httpProxyUser;
622 stringOption httpsProxy;
624 stringOption httpsProxyPasswd;
626 stringOption httpsProxyUser;
627 //index-out
629 intOption lowestSpeedLimit;
631 intOption maxConnectionPerServer;
633 size_tOption maxMmapLimit;
635 intOption maxResumeFailureTries;
637 intOption maxTries;
638 //metalink-base-uri
640 boolOption metalinkEnableUniqueProtocol;
642 stringOption metalinkLanguage;
644 stringOption metalinkLocation;
646 stringOption metalinkOs;
648 MetalinkProtocolOption metalinkPreferredProtocol;
650 stringOption metalinkVersion;
652 size_tOption minSplitSize;
654 size_tOption noFileAllocationLimit;
656 boolOption noNetrc;
657 //no-proxy
659 stringOption out;
661 boolOption parameterizedUri;
663 boolOption pause;
665 boolOption pauseMetadata;
667 ProxyMethodOption proxyMethod;
669 boolOption realtimeChunkChecksum;
670 //referer
672 boolOption remoteTime;
674 boolOption removeControlFile;
676 intOption retryWait;
678 boolOption reuseUri;
680 floatOption seedRatio;
682 floatOption seedTime;
683 intOption stop;
684 //select-file
686 intOption split;
687 //ssh-host-key-md
689 PieceSelectionAlgorithmOption streamPieceSelector;
691 intOption timeout;
693 URISelectorOption uriSelector;
695 boolOption useHead;
697 stringOption userAgent;
698
699
700 // Json::Value m_options;
701 Download *m_download = nullptr; // May point to an active download
702 // otherwise, if nullptr, it is inactive.
703
704};
705#endif //DOWNLOADOPTIONS_H_
Definition: downloadoptions.h:235
void setMaxUploadLimit(int value)
Definition: downloadoptions.cpp:890
void setDryRun(bool value)
Definition: downloadoptions.cpp:876
bool getForceSave() const
Definition: downloadoptions.cpp:374
void setBtMaxPeers(int value)
void setBtRemoveUnselectedFile(bool value)
Definition: downloadoptions.cpp:855
std::string getDir() const
Definition: downloadoptions.cpp:385
void setPieceLength(int value)
Definition: downloadoptions.cpp:869
int getMaxDownloadLimit() const
Definition: downloadoptions.cpp:353
int getBtMaxPeers() const
Definition: downloadoptions.cpp:364
int getBtRequestPeerSpeedLimit() const
Definition: downloadoptions.cpp:358
void setMaxDownloadLimit(int value)
Definition: downloadoptions.cpp:841
void setRpcSaveUploadMetadata(bool value)
Definition: downloadoptions.cpp:862
bool getRpcSaveUploadMetadata() const
Definition: downloadoptions.cpp:369
int getMaxUploadLimit() const
Definition: downloadoptions.cpp:348
size_t getPieceLength() const
Definition: downloadoptions.cpp:343
bool update()
Definition: downloadoptions.cpp:34
DownloadOptions()
Definition: downloadoptions.cpp:27
void setForceSave(bool value)
Definition: downloadoptions.cpp:848
bool getBtRemoveUnselectedFile() const
Definition: downloadoptions.cpp:390
void setBtRequestPeerSpeedLimit(int value)
Definition: downloadoptions.cpp:897
Json::Value asJsonArray()
Definition: downloadoptions.cpp:42
void setDir(std::string value)
Definition: downloadoptions.cpp:883
void setBtMinCryptoLevel(CryptoLevel value)
Definition: downloadoptions.cpp:904
Definition: download.h:39
Definition: downloadoptions.h:112
Definition: downloadoptions.h:165
Definition: downloadoptions.h:146
Definition: downloadoptions.h:127
Definition: downloadoptions.h:180
Definition: downloadoptions.h:98
Definition: downloadoptions.h:82
Definition: downloadoptions.h:35
Definition: downloadoptions.h:45
Definition: downloadoptions.h:54
Definition: downloadoptions.h:64
Definition: downloadoptions.h:199
Definition: downloadoptions.h:73