-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathhydra.h
More file actions
2668 lines (2549 loc) · 80 KB
/
Copy pathhydra.h
File metadata and controls
2668 lines (2549 loc) · 80 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* libhydra - a stable C ABI over the hydra download engine.
*
* Copyright (C) 2026 Javad Rajabzadeh
* SPDX-License-Identifier: MIT OR Apache-2.0
*
* GENERATED FILE - do not edit. Regenerate with `make header`.
* The source of truth is crates/hydra-ffi/src/{abi,exports}.rs.
*
* ---------------------------------------------------------------------------
* THE SPECIFICATION IS docs/ffi/ABI.md
* ---------------------------------------------------------------------------
*
* This header is the machine-readable half of the ABI: the declarations your
* compiler reads, each carrying its own threading, blocking and allocation
* behaviour. docs/ffi/ABI.md is the other half - the design principles, the
* stability policy, the event queue's ordering and drop guarantees, and the
* rules for credentials, rate limits, persistence and destinations. Read it
* once before writing a binding.
*
* https://github.com/ja7ad/hydra/blob/main/docs/ffi/ABI.md
*
* What follows is the short form, for the reader who is already here.
*
* ABI VERSION
* Compare HYDRA_FFI_ABI_VERSION against hydra_ffi_abi_version() at startup
* and refuse to continue on a mismatch. Nothing below means anything if the
* two disagree. The ABI version is independent of the library version.
*
* Within one ABI version: existing fields never move and never change width
* or meaning, enumerator values are never reassigned or reused, exported
* symbols never disappear, ownership rules never change, and new fields are
* appended only to the two size-prefixed configuration structs. Anything
* else becomes ABI 2. See ABI.md section 3; the frozen layout lives in
* crates/hydra-ffi/abi/abi-1.manifest and is enforced in CI.
*
* OWNERSHIP
* Memory allocated by hydra is freed by hydra, through the matching *_free
* function and NEVER through free(). A statically linked libhydra may not
* share an allocator with your program, and on Windows it may not share a
* CRT; a cross-allocator free corrupts the heap intermittently and far from
* the call that caused it.
* Strings you pass IN are borrowed for the duration of that call only. hydra
* copies whatever it needs before returning, so you never have to keep a
* buffer alive on hydra's behalf.
* user_data handed to a callback is never owned and never freed by hydra; it
* must outlive the registration.
*
* ENCODING
* Every string crossing this boundary is UTF-8. Invalid UTF-8 supplied by a
* caller is HYDRA_ERR_INVALID_ARGUMENT, never a lossy conversion.
*
* LANGUAGE BASELINE
* C11 or later, or C++11 or later. Fixed-width integer types and static
* assertions throughout; every language this ABI targets can meet that.
*
* ENUM REPRESENTATION
* Every ABI-visible enum VALUE is a uint32_t. That is a statement about
* values rather than about enumeration types: under C++ and C23 the typedef
* names a real enum with uint32_t as its fixed underlying type, while under
* C11 the typedef IS uint32_t and the enumerators are ordinary constants.
* The assertions at the foot of this header check it in whichever mode you
* compile.
*
* Hence the asymmetry in struct fields: a field hydra WRITES (an event's
* kind, a snapshot's state, an error's code) is declared as the enum, because
* hydra constructs it. A field hydra READS from you is a uint32_t and is
* validated, because you can put any bit pattern in a struct field.
*
* ERRORS
* Every fallible call returns hydra_error_code_t. The detail behind it -
* message, errno, HTTP status - is in a THREAD-LOCAL slot readable with
* hydra_last_error(), cleared at the start of every call. Branch on the
* code; never parse the message.
*
* HYDRA_ERR_AGAIN is not a failure. It means "nothing to report right now",
* and the non-blocking event calls return it constantly. Use HYDRA_IS_ERROR()
* rather than a bare != HYDRA_OK when you mean "something went wrong".
*
* PANICS
* No Rust panic crosses this boundary. An internal failure becomes
* HYDRA_ERR_INTERNAL with the detail preserved.
*
* THREADS
* hydra_engine_t* thread-safe
* job operations thread-safe
* event consumption thread-safe, but intended for ONE consumer
* hydra_engine_destroy synchronisation-sensitive: must not race with any
* other call on the same engine
*
* RUNTIME
* The engine owns its own threads. Your program needs no async runtime, no
* event loop and no particular thread. No Rust future appears in this ABI.
*
* EVENTS
* The bounded queue is the fundamental mechanism; callbacks are an optional
* convenience and are EXPERIMENTAL. Progress events coalesce, terminal
* events (COMPLETED, FAILED, CANCELLED, ENGINE_SHUTDOWN) are never dropped,
* life-cycle events drop oldest-first and every drop is counted in
* hydra_event_t.dropped_events. Ordering is guaranteed WITHIN one job only,
* and every event is delivered exactly once - drain in one place and
* dispatch from there. The full order is in ABI.md section 5.
*
* BYTES
* File data never crosses this ABI. hydra writes the object directly to its
* destination by positioned writes; this interface carries control, state,
* progress and errors only. That is what keeps resident memory independent
* of file size.
*
* CREDENTIALS
* Passwords, proxy passwords and the Authorization, Proxy-Authorization and
* Cookie headers never appear in a snapshot, an event, an error message, the
* log sink, the metrics, or the persisted state file. Userinfo in a URL is
* stripped at hydra_job_create(). A restored job comes back without its
* credentials by design - re-arm it with hydra_job_set_credentials().
*
* MACROS
* The helpers below are thin wrappers over static inline functions, so an
* argument with side effects is evaluated exactly once. HYDRA_IS_ERROR(f())
* calls f() one time, which a naive macro would not.
*
* CRATE NAMES
* The engine crates are named hya-core and hya-net (in directories
* crates/hydra-core and crates/hydra-net). That prefix is deliberate and is
* not a typo where it appears below.
*
* STABILITY
* Everything here is STABLE except hydra_job_get_sources,
* hydra_source_info_t and hydra_source_array_t, which are EXPERIMENTAL and
* may change within ABI 1.
*/
#ifndef HYDRA_H
#define HYDRA_H
#include <stdint.h>
#include <stddef.h>
/* --------------------------------------------------------------------------
* These macros are defined here, before the declarations they wrap, because
* this is the hook that lands INSIDE the include guard. A macro is expanded at
* its use site, so it does not need the function to be declared yet - and
* being inside the guard is what makes a second #include of this header
* harmless.
* -------------------------------------------------------------------------- */
/* Initialise a configuration struct.
*
* These pass sizeof(*(c)) as the caller's header declares it, which is what
* makes initialisation safe when your header is OLDER than the library you
* link against: the library writes at most the number of bytes your struct
* actually has, and everything past that keeps its documented default. Always
* prefer these to calling the underlying function with a hand-written size.
*
* `c` appears twice but is evaluated once: sizeof does not evaluate its
* operand. */
#define HYDRA_ENGINE_CONFIG_INIT(c) \
hydra_engine_config_init((c), (uint32_t)sizeof(*(c)))
#define HYDRA_JOB_CONFIG_INIT(c) \
hydra_job_config_init((c), (uint32_t)sizeof(*(c)))
/* Static assertions, spelled for whichever language is compiling this. */
#if defined(__cplusplus)
#define HYDRA_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define HYDRA_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
#else
/* Pre-C11, which is what MSVC compiles a .c file as unless it is given
* /std:c11 or later. Declaring an array with a negative length fails just as
* loudly, and the layout checks below are the point rather than the spelling
* of the assertion. The message survives as the typedef's neighbour in the
* error, which is as much as this construct can carry. */
#define HYDRA_STATIC_ASSERT_JOIN_(a, b) a##b
#define HYDRA_STATIC_ASSERT_NAME_(a, b) HYDRA_STATIC_ASSERT_JOIN_(a, b)
#define HYDRA_STATIC_ASSERT(cond, msg) typedef char HYDRA_STATIC_ASSERT_NAME_(hydra_static_assert_, __LINE__)[(cond) ? 1 : -1]
#endif
/* The code classifiers (hydra_succeeded / hydra_failed / hydra_is_error and
* their uppercase aliases) are at the FOOT of this header, not here: they are
* inline functions rather than bare macros, so their bodies need HYDRA_OK to
* be declared first. */
/* Import/export decoration. A static build needs none; a shared build on
* Windows needs both halves, and which half depends on who is compiling. */
#if defined(_WIN32)
#if defined(HYDRA_BUILD_SHARED)
#define HYDRA_API __declspec(dllexport)
#elif defined(HYDRA_USE_SHARED)
#define HYDRA_API __declspec(dllimport)
#else
#define HYDRA_API
#endif
#else
#define HYDRA_API
#endif
/**
* The ABI version implemented by this library.
*/
#define HYDRA_FFI_ABI_VERSION 1
/**
* The version field value stamped by `hydra_engine_config_init`.
*/
#define HYDRA_ENGINE_CONFIG_VERSION 1
/**
* The version field value stamped by `hydra_job_config_init`.
*/
#define HYDRA_JOB_CONFIG_VERSION 1
/**
* Value indicating an indefinite wait for `hydra_event_wait`.
*/
#define HYDRA_WAIT_FOREVER UINT32_MAX
/**
* Major version component of `HYDRA_FFI_VERSION`.
*/
#define HYDRA_FFI_VERSION_MAJOR 0
/**
* Minor version component of `HYDRA_FFI_VERSION`.
*/
#define HYDRA_FFI_VERSION_MINOR 3
/**
* Patch version component of `HYDRA_FFI_VERSION`.
*/
#define HYDRA_FFI_VERSION_PATCH 0
/**
* The library version this header was generated from.
*
* The LIBRARY version, not the ABI version: it moves on every release,
* including ones that change nothing a binding can observe. Compare
* HYDRA_FFI_ABI_VERSION to decide whether a header and a library are
* compatible; use this to report what you linked against.
*
* hydra_ffi_version_string() returns the value compiled into the library.
* If the two disagree, this header is not the one that library was built
* from.
*/
#define HYDRA_FFI_VERSION "0.3.0"
/**
* Numeric version encoded as `major * 1_000_000 + minor * 1_000 + patch` for preprocessor checks.
*/
#define HYDRA_FFI_VERSION_NUMBER (((HYDRA_FFI_VERSION_MAJOR * 1000000) + (HYDRA_FFI_VERSION_MINOR * 1000)) + HYDRA_FFI_VERSION_PATCH)
/**
* Status and error codes returned by ABI functions.
*/
enum hydra_error_code_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Operation completed successfully.
*/
HYDRA_OK = 0,
/**
* Invalid argument, NULL pointer, or malformed parameter.
*/
HYDRA_ERR_INVALID_ARGUMENT = 1,
/**
* URL parsing failed or unsupported scheme.
*/
HYDRA_ERR_INVALID_URL = 2,
/**
* Operation is invalid for the job's current state.
*/
HYDRA_ERR_INVALID_STATE = 3,
/**
* Requested feature or scheme is unsupported.
*/
HYDRA_ERR_UNSUPPORTED = 4,
/**
* Non-blocking call has no data available right now.
*/
HYDRA_ERR_AGAIN = 5,
/**
* General network or transport failure.
*/
HYDRA_ERR_NETWORK = 6,
/**
* Connection establishment failed or connection reset.
*/
HYDRA_ERR_CONNECTION = 7,
/**
* Network or operation timeout expired.
*/
HYDRA_ERR_TIMEOUT = 8,
/**
* Protocol error encountered.
*/
HYDRA_ERR_PROTOCOL = 9,
/**
* Filesystem or I/O error.
*/
HYDRA_ERR_IO = 10,
/**
* Filesystem permission denied.
*/
HYDRA_ERR_PERMISSION = 11,
/**
* Target disk or partition has insufficient space.
*/
HYDRA_ERR_NO_SPACE = 12,
/**
* Computed checksum does not match expected digest.
*/
HYDRA_ERR_CHECKSUM = 13,
/**
* Integrity verification failed to read or verify target file.
*/
HYDRA_ERR_VERIFICATION = 14,
/**
* Operation was cancelled by caller.
*/
HYDRA_ERR_CANCELLED = 15,
/**
* Specified job, source, or file not found.
*/
HYDRA_ERR_NOT_FOUND = 16,
/**
* Entity or job ID already exists.
*/
HYDRA_ERR_ALREADY_EXISTS = 17,
/**
* System or configured resource limit reached.
*/
HYDRA_ERR_RESOURCE_LIMIT = 18,
/**
* Engine is shutting down or shut down.
*/
HYDRA_ERR_SHUTDOWN = 19,
/**
* Internal engine error or caught panic.
*/
HYDRA_ERR_INTERNAL = 20,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_error_code_t hydra_error_code_t;
#else
typedef uint32_t hydra_error_code_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Download job lifecycle states.
*/
enum hydra_job_state_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Created and pending initial start.
*/
HYDRA_JOB_CREATED = 0,
/**
* Queued and waiting for an execution slot.
*/
HYDRA_JOB_QUEUED = 1,
/**
* Probing source capabilities and metadata.
*/
HYDRA_JOB_RESOLVING = 2,
/**
* Actively transferring data.
*/
HYDRA_JOB_DOWNLOADING = 3,
/**
* Paused; partial downloads and range maps preserved.
*/
HYDRA_JOB_PAUSED = 4,
/**
* Transfer complete; verifying checksum.
*/
HYDRA_JOB_VERIFYING = 5,
/**
* Download successfully completed and verified.
*/
HYDRA_JOB_COMPLETED = 6,
/**
* Job encountered an error and stopped.
*/
HYDRA_JOB_FAILED = 7,
/**
* Job was cancelled by request.
*/
HYDRA_JOB_CANCELLED = 8,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_job_state_t hydra_job_state_t;
#else
typedef uint32_t hydra_job_state_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Event types emitted on state transitions and progress ticks.
*/
enum hydra_event_type_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Job was created.
*/
HYDRA_EVENT_JOB_CREATED = 0,
/**
* Job was admitted to the wait queue.
*/
HYDRA_EVENT_JOB_QUEUED = 1,
/**
* Job started execution.
*/
HYDRA_EVENT_JOB_STARTED = 2,
/**
* Sources resolved (size and capabilities determined).
*/
HYDRA_EVENT_RESOLVED = 3,
/**
* Periodic download progress sample.
*/
HYDRA_EVENT_PROGRESS = 4,
/**
* Job was paused.
*/
HYDRA_EVENT_PAUSED = 5,
/**
* Job was resumed from paused state.
*/
HYDRA_EVENT_RESUMED = 6,
/**
* Transfer failed and is retrying.
*/
HYDRA_EVENT_RETRYING = 7,
/**
* Source list or active mirrors changed.
*/
HYDRA_EVENT_SOURCE_CHANGED = 8,
/**
* Transfer stalled due to lack of progress.
*/
HYDRA_EVENT_STALLED = 9,
/**
* Checksum verification started.
*/
HYDRA_EVENT_VERIFYING = 10,
/**
* Job finished successfully.
*/
HYDRA_EVENT_COMPLETED = 11,
/**
* Job failed.
*/
HYDRA_EVENT_FAILED = 12,
/**
* Job was cancelled.
*/
HYDRA_EVENT_CANCELLED = 13,
/**
* Engine is shutting down.
*/
HYDRA_EVENT_ENGINE_SHUTDOWN = 14,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_event_type_t hydra_event_type_t;
#else
typedef uint32_t hydra_event_type_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Which dialect a document was written in.
*/
enum hydra_metalink_version_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* The document has no recognisable Metalink namespace.
*/
HYDRA_METALINK_UNKNOWN = 0,
/**
* Metalink 3.0, `http://www.metalinker.org/`. Preference is 0-100, higher
* is better — the reader converts it, so nothing downstream sees the
* inverted scale.
*/
HYDRA_METALINK_V3 = 3,
/**
* Metalink 4 / RFC 5854, `urn:ietf:params:xml:ns:metalink`. Priority is
* 1-999999, lower is better.
*/
HYDRA_METALINK_V4 = 4,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_metalink_version_t hydra_metalink_version_t;
#else
typedef uint32_t hydra_metalink_version_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Disposition of partial download files upon cancellation.
*/
enum hydra_cancel_mode_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Keep partial files on disk.
*/
HYDRA_CANCEL_KEEP_PARTIAL = 0,
/**
* Remove partial files from disk.
*/
HYDRA_CANCEL_REMOVE_PARTIAL = 1,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_cancel_mode_t hydra_cancel_mode_t;
#else
typedef uint32_t hydra_cancel_mode_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Job queue priority level.
*/
enum hydra_priority_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Low priority.
*/
HYDRA_PRIORITY_LOW = 0,
/**
* Normal priority (default).
*/
HYDRA_PRIORITY_NORMAL = 1,
/**
* High priority.
*/
HYDRA_PRIORITY_HIGH = 2,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_priority_t hydra_priority_t;
#else
typedef uint32_t hydra_priority_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Network interface usage policy.
*/
enum hydra_network_policy_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Allow transfers over any available network.
*/
HYDRA_NETWORK_ANY = 0,
/**
* Allow transfers over unmetered connections only.
*/
HYDRA_NETWORK_UNMETERED = 1,
/**
* Allow transfers over Wi-Fi connections only.
*/
HYDRA_NETWORK_WIFI_ONLY = 2,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_network_policy_t hydra_network_policy_t;
#else
typedef uint32_t hydra_network_policy_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Power consumption profile for the engine.
*/
enum hydra_power_mode_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Full performance mode.
*/
HYDRA_POWER_NORMAL = 0,
/**
* Reduced concurrency and lower event frequency.
*/
HYDRA_POWER_BATTERY_SAVER = 1,
/**
* Single-connection minimal power mode.
*/
HYDRA_POWER_RESTRICTED = 2,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_power_mode_t hydra_power_mode_t;
#else
typedef uint32_t hydra_power_mode_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Forward proxy protocol type.
*/
enum hydra_proxy_type_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Direct connection without proxy.
*/
HYDRA_PROXY_NONE = 0,
/**
* HTTP/HTTPS forward proxy.
*/
HYDRA_PROXY_HTTP = 1,
/**
* SOCKS4 proxy.
*/
HYDRA_PROXY_SOCKS4 = 2,
/**
* SOCKS4a proxy with remote DNS resolution.
*/
HYDRA_PROXY_SOCKS4A = 3,
/**
* SOCKS5 proxy.
*/
HYDRA_PROXY_SOCKS5 = 4,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_proxy_type_t hydra_proxy_type_t;
#else
typedef uint32_t hydra_proxy_type_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Checksum digest algorithm.
*/
enum hydra_checksum_algorithm_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* No checksum verification.
*/
HYDRA_CHECKSUM_NONE = 0,
/**
* MD5 digest (16 bytes).
*/
HYDRA_CHECKSUM_MD5 = 1,
/**
* SHA-1 digest (20 bytes).
*/
HYDRA_CHECKSUM_SHA1 = 2,
/**
* SHA-256 digest (32 bytes).
*/
HYDRA_CHECKSUM_SHA256 = 3,
/**
* SHA-512 digest (64 bytes).
*/
HYDRA_CHECKSUM_SHA512 = 4,
/**
* BLAKE3 digest (32 bytes).
*/
HYDRA_CHECKSUM_BLAKE3 = 5,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_checksum_algorithm_t hydra_checksum_algorithm_t;
#else
typedef uint32_t hydra_checksum_algorithm_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Logging verbosity levels.
*/
enum hydra_log_level_t
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311L
: uint32_t
#endif // defined(__cplusplus) || __STDC_VERSION__ >= 202311L
{
/**
* Error messages.
*/
HYDRA_LOG_ERROR = 0,
/**
* Warning messages.
*/
HYDRA_LOG_WARN = 1,
/**
* Informational messages.
*/
HYDRA_LOG_INFO = 2,
/**
* Debug messages.
*/
HYDRA_LOG_DEBUG = 3,
/**
* Trace-level messages.
*/
HYDRA_LOG_TRACE = 4,
};
#ifndef __cplusplus
#if __STDC_VERSION__ >= 202311L
typedef enum hydra_log_level_t hydra_log_level_t;
#else
typedef uint32_t hydra_log_level_t;
#endif // __STDC_VERSION__ >= 202311L
#endif // __cplusplus
/**
* Opaque engine instance handle type.
*/
typedef struct hydra_engine_t hydra_engine_t;
/**
* An opaque, parsed Metalink document.
*
* Created by `hydra_metalink_parse`, `hydra_metalink_open` or
* `hydra_metalink_fetch`, and released with `hydra_metalink_free`. Immutable
* once created, so it may be read from several threads at once.
*/
typedef struct hydra_metalink_t hydra_metalink_t;
/**
* Owned, NUL-terminated UTF-8 string allocated by hydra.
*
* Must be freed with `hydra_string_free` and never with `free()`.
*/
typedef struct {
/**
* UTF-8 bytes, NUL-terminated. NULL when absent.
*/
char *data;
/**
* Length in bytes, excluding the NUL terminator.
*/
size_t len;
} hydra_string_t;
/**
* Detailed error container with OS and HTTP status metadata.
*
* Owned strings must be released with `hydra_error_free`.
*/
typedef struct {
/**
* Primary error classification.
*/
hydra_error_code_t code;
/**
* Platform error code (errno / GetLastError), or 0.
*/
int32_t os_error;
/**
* HTTP response status code, or 0.
*/
int32_t http_status;
/**
* Human-readable error message.
*/
hydra_string_t message;
} hydra_error_t;
/**
* Global engine configuration.
*
* Initialise with `hydra_engine_config_init` before setting fields.
*/
typedef struct {
/**
* Struct size in bytes for version compatibility.
*/
uint32_t size;
/**
* Struct version (`HYDRA_ENGINE_CONFIG_VERSION`).
*/
uint32_t version;
/**
* Maximum number of concurrent active jobs (default 4).
*/
uint32_t max_jobs;
/**
* Maximum connections per job ceiling (default 8).
*/
uint32_t max_connections;
/**
* Default retry attempts for failed transfers (default 3).
*/
uint32_t max_retries;
/**
* Minimum interval in milliseconds between progress events (default 250).
*/
uint32_t progress_interval_ms;
/**
* Event queue capacity (default 1024).
*/
uint32_t event_queue_capacity;
/**
* Internal runtime worker threads (0 for auto).
*/
uint32_t worker_threads;
/**
* Engine-wide download rate limit in bytes/sec (0 = unlimited).
*/
uint64_t max_bytes_per_second;
/**
* Nonzero to enable dynamic connection scaling (default 1).
*/
uint8_t adaptive_concurrency;
/**
* Nonzero to enable range work stealing (default 1).
*/
uint8_t range_stealing;
/**
* Nonzero to disable TLS certificate verification (testing only).
*/
uint8_t allow_insecure_tls;
/**
* Reserved; must be zero.
*/
uint8_t reserved0;
/**
* Initial network policy (`hydra_network_policy_t`).
*/
uint32_t network_policy;
/**
* Initial power mode (`hydra_power_mode_t`).
*/
uint32_t power_mode;
/**
* File path for durable state storage, or NULL.
*/
const char *state_path;
/**
* Custom HTTP User-Agent string, or NULL for default.
*/
const char *user_agent;
/**
* Reserved for future fields; must be zero.
*/
uint8_t reserved[32];
} hydra_engine_config_t;
/**
* HTTP request header key-value pair.
*/
typedef struct {
/**
* Header name (excluding trailing colon).
*/
const char *name;
/**
* Header value.
*/
const char *value;
} hydra_header_t;
/**
* Proxy server configuration.
*/
typedef struct {
/**
* Proxy protocol (`hydra_proxy_type_t`).
*/
uint32_t kind;
/**
* Proxy port.
*/
uint16_t port;
/**
* Reserved; must be zero.
*/
uint8_t reserved[2];
/**
* Proxy hostname or IP address.
*/
const char *host;
/**
* Optional username, or NULL.
*/
const char *username;
/**
* Optional password, or NULL.
*/
const char *password;
} hydra_proxy_config_t;
/**
* Checksum verification specification.
*/
typedef struct {
/**
* Digest algorithm (`hydra_checksum_algorithm_t`).
*/
uint32_t algorithm;
/**
* Reserved; must be zero.
*/
uint32_t reserved;
/**
* Pointer to raw expected digest bytes, or NULL.
*/
const uint8_t *digest;
/**
* Expected digest byte length.
*/
size_t digest_len;
} hydra_checksum_t;
/**
* Download job configuration.
*
* Initialise with `hydra_job_config_init` before setting fields.
*/
typedef struct {
/**
* Struct size in bytes for version compatibility.
*/
uint32_t size;
/**
* Struct version (`HYDRA_JOB_CONFIG_VERSION`).
*/
uint32_t version;
/**
* Array of source URLs (mirrors).
*/
const char *const *urls;
/**
* Number of URLs in `urls` (minimum 1).
*/
size_t url_count;
/**
* Destination file path.
*/
const char *output_path;
/**
* Array of custom HTTP headers, or NULL.
*/
const hydra_header_t *headers;
/**
* Number of headers in `headers`.
*/
size_t header_count;
/**
* Optional HTTP Basic / FTP username, or NULL.
*/
const char *username;
/**
* Optional HTTP Basic / FTP password, or NULL.
*/
const char *password;
/**
* Proxy configuration for this job, or NULL.
*/
const hydra_proxy_config_t *proxy;
/**
* Checksum verification specification.
*/
hydra_checksum_t checksum;
/**
* Max connections for this job (0 inherits engine default).
*/
uint32_t max_connections;
/**
* Max retries for this job (0 inherits engine default).
*/
uint32_t max_retries;