forked from freebsd/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg.h.in
1681 lines (1491 loc) · 45.7 KB
/
pkg.h.in
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
/*-
* Copyright (c) 2011-2015 Baptiste Daroussin <[email protected]>
* Copyright (c) 2011-2012 Julien Laffaye <[email protected]>
* Copyright (c) 2011 Will Andrews <[email protected]>
* Copyright (c) 2011 Philippe Pepiot <[email protected]>
* Copyright (c) 2011-2012 Marin Atanasov Nikolov <[email protected]>
* Copyright (c) 2013-2014 Matthew Seaman <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PKG_H
#define _PKG_H
#ifdef __cplusplus
extern "C" {
#define restrict
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/cdefs.h>
#include <stdarg.h>
#include <stdbool.h>
#include <sys/sbuf.h>
#include <openssl/pem.h>
#include <sysexits.h>
/* The expected name of the pkg(8) binary executable. */
#ifndef PKG_EXEC_NAME
#define PKG_EXEC_NAME "pkg"
#endif
/* The expected name of the pkg-static(8) binary */
#ifndef PKG_STATIC_NAME
#define PKG_STATIC_NAME "pkg-static"
#endif
#define PKGVERSION "@VERSION@"
/* PORTVERSION equivalent for proper pkg-static->ports-mgmt/pkg
* version comparison in pkgdb_query_newpkgversion() */
#define PKG_PORTVERSION "@VERSION@"
/* The OS major version at the time of compilation */
#ifdef __FreeBSD__
#define OSMAJOR __FreeBSD__
#endif
/* Not supported under DragonFly */
#ifdef __DragonFly__
#undef OSMAJOR
#endif
#ifdef __NetBSD_Version__
#define OSMAJOR __NetBSD_Version__
#endif
#ifndef __DECONST
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif
#ifndef NELEM
#define NELEM(array) (sizeof(array) / sizeof((array)[0]))
#endif
/* Special exit status for worker processes indicating that a restart
* is desired -- eg. after a child has updated pkg(8) itself. Don't
* clash with any of the sysexits values */
#define EX_NEEDRESTART (EX__MAX + 1)
struct pkg;
struct pkg_dep;
struct pkg_conflict;
struct pkg_file;
struct pkg_dir;
struct pkg_option;
struct pkg_license;
struct pkg_config_file;
struct pkgdb;
struct pkgdb_it;
struct pkg_jobs;
struct pkg_solve_problem;
struct pkg_repo;
struct pkg_plugin;
struct pkg_manifest_key;
struct pkg_manifest_parser;
typedef struct ucl_object_s pkg_object;
typedef void * pkg_iter;
struct pkg_kv {
char *key;
char *value;
struct pkg_kv *next;
};
/**
* The system-wide pkg(8) status: ie. is it a) installed or otherwise
* available on the sysem, b) database (local.sqlite) initialised and
* c) has at least one package installed (which should be pkg
* itself). PKG_STATUS_UNINSTALLED logically cannot be returned by
* pkg(8) itself, but it can be useful for the pkg bootstrapper
* /usr/bin/pkg or for applications that link against libpkg.so
*/
typedef enum {
PKG_STATUS_ACTIVE = 0, /* pkg in use */
PKG_STATUS_NOPACKAGES, /* local.sqlite empty */
PKG_STATUS_NODB, /* local.sqlite not found, unreadable or not initialised */
PKG_STATUS_UNINSTALLED, /* pkg not argv[0] or not on $PATH */
} pkg_status_t;
typedef enum {
/**
* The license logic is OR (dual in the ports)
*/
LICENSE_OR = '|',
/**
* The license logic is AND (multi in the ports)
*/
LICENSE_AND = '&',
/**
* The license logic un single (default in the ports)
*/
LICENSE_SINGLE = 1U
} lic_t;
typedef enum {
PKGDB_DEFAULT = 0,
PKGDB_REMOTE,
PKGDB_MAYBE_REMOTE
} pkgdb_t;
typedef enum {
PKG_INIT_FLAG_USE_IPV4 = (1U << 0),
PKG_INIT_FLAG_USE_IPV6 = (1U << 1)
} pkg_init_flags;
/**
* Specify how an argument should be used by query functions.
*/
typedef enum {
/**
* The argument does not matter, all items will be matched.
*/
MATCH_ALL,
/**
* The argument is the exact pattern. Match will be case
* sensitive or case insensitive according to
* pkgdb_case_sensitive()
*/
MATCH_EXACT,
/**
* The argument is an exact pattern except that matches will
* be made case insensitively. Match is always case sensitive
*/
MATCH_GLOB,
/**
* The argument is a regular expression ('modern' style
* according to re_format(7). Match will be case sensitive or
* case insensitive according to pkgdb_case_sensitive()
*/
MATCH_REGEX,
/**
* The argument is a WHERE clause to use as condition
*/
MATCH_CONDITION,
/**
* Match using FTS search
*/
MATCH_FTS
} match_t;
/**
* Specify on which field the pattern will be matched uppon.
*/
typedef enum {
FIELD_NONE,
FIELD_ORIGIN,
FIELD_NAME,
FIELD_NAMEVER,
FIELD_COMMENT,
FIELD_DESC
} pkgdb_field;
/**
* The type of package.
*/
typedef enum {
/**
* The pkg type can not be determined.
*/
PKG_NONE = 0,
/**
* The pkg refers to a local file archive.
*/
PKG_FILE = (1U << 0),
/**
* The pkg refers to data read from a non-regular file
* (device, pipeline, unix dmain socket etc.)
*/
PKG_STREAM = (1U << 1),
/**
* The pkg refers to a package available on the remote repository.
* @todo Document which attributes are available.
*/
PKG_REMOTE = (1U << 2),
/**
* The pkg refers to a localy installed package.
*/
PKG_INSTALLED = (1U << 3),
/**
* The pkg refers to a local file old archive.
*/
PKG_OLD_FILE = (1U << 4),
} pkg_t;
/**
* Contains keys to refer to a string attribute.
* Used by pkg_get() and pkg_set()
*/
typedef enum {
PKG_ORIGIN = 1U,
PKG_NAME,
PKG_VERSION,
PKG_COMMENT,
PKG_DESC,
PKG_MTREE,
PKG_MESSAGE,
PKG_ARCH,
PKG_ABI,
PKG_MAINTAINER,
PKG_WWW,
PKG_PREFIX,
PKG_REPOPATH,
PKG_CKSUM,
PKG_OLD_VERSION,
PKG_REPONAME,
PKG_REPOURL,
PKG_DIGEST,
PKG_REASON,
PKG_FLATSIZE,
PKG_OLD_FLATSIZE,
PKG_PKGSIZE,
PKG_LICENSE_LOGIC,
PKG_AUTOMATIC,
PKG_LOCKED,
PKG_ROWID,
PKG_TIME,
PKG_ANNOTATIONS,
PKG_UNIQUEID,
PKG_OLD_DIGEST,
PKG_DEP_FORMULA,
PKG_NUM_FIELDS, /* end of fields */
} pkg_attr;
typedef enum {
PKG_SET_FLATSIZE = 1U,
PKG_SET_AUTOMATIC,
PKG_SET_LOCKED,
PKG_SET_DEPORIGIN,
PKG_SET_ORIGIN,
PKG_SET_DEPNAME,
PKG_SET_NAME,
PKG_SET_MAX
} pkg_set_attr;
/**
* contains keys to refer to a string attribute
* Used by pkg_dep_get()
*/
typedef enum {
PKG_DEP_NAME = 0,
PKG_DEP_ORIGIN,
PKG_DEP_VERSION
} pkg_dep_attr;
typedef enum {
PKG_DEPS = 0,
PKG_RDEPS,
PKG_OPTIONS,
PKG_FILES,
PKG_DIRS,
PKG_USERS,
PKG_GROUPS,
PKG_SHLIBS_REQUIRED,
PKG_SHLIBS_PROVIDED,
PKG_CONFLICTS,
PKG_PROVIDES,
PKG_CONFIG_FILES,
PKG_REQUIRES,
PKG_CATEGORIES,
PKG_LICENSES
} pkg_list;
typedef enum {
SRV,
HTTP,
NOMIRROR,
} mirror_t;
typedef enum {
SIG_NONE = 0,
SIG_PUBKEY,
SIG_FINGERPRINT
} signature_t;
/**
* Determine the type of a pkg_script.
*/
typedef enum {
PKG_SCRIPT_PRE_INSTALL = 0,
PKG_SCRIPT_POST_INSTALL,
PKG_SCRIPT_PRE_DEINSTALL,
PKG_SCRIPT_POST_DEINSTALL,
PKG_SCRIPT_PRE_UPGRADE,
PKG_SCRIPT_POST_UPGRADE,
PKG_SCRIPT_INSTALL,
PKG_SCRIPT_DEINSTALL,
PKG_SCRIPT_UPGRADE,
PKG_SCRIPT_UNKNOWN
} pkg_script;
typedef enum _pkg_jobs_t {
PKG_JOBS_INSTALL,
PKG_JOBS_DEINSTALL,
PKG_JOBS_FETCH,
PKG_JOBS_AUTOREMOVE,
PKG_JOBS_UPGRADE,
} pkg_jobs_t;
typedef enum _pkg_flags {
PKG_FLAG_NONE = 0,
PKG_FLAG_DRY_RUN = (1U << 0),
PKG_FLAG_FORCE = (1U << 1),
PKG_FLAG_RECURSIVE = (1U << 2),
PKG_FLAG_AUTOMATIC = (1U << 3),
PKG_FLAG_WITH_DEPS = (1U << 4),
PKG_FLAG_NOSCRIPT = (1U << 5),
PKG_FLAG_PKG_VERSION_TEST = (1U << 6),
PKG_FLAG_UPGRADES_FOR_INSTALLED = (1U << 7),
PKG_FLAG_SKIP_INSTALL = (1U << 8),
PKG_FLAG_FORCE_MISSING = (1U << 9),
PKG_FLAG_FETCH_MIRROR = (1U << 10),
PKG_FLAG_USE_IPV4 = (1U << 11),
PKG_FLAG_USE_IPV6 = (1U << 12)
} pkg_flags;
typedef enum _pkg_stats_t {
PKG_STATS_LOCAL_COUNT = 0,
PKG_STATS_LOCAL_SIZE,
PKG_STATS_REMOTE_COUNT,
PKG_STATS_REMOTE_UNIQUE,
PKG_STATS_REMOTE_SIZE,
PKG_STATS_REMOTE_REPOS,
} pkg_stats_t;
typedef enum {
PKG_STRING = 0,
PKG_BOOL,
PKG_INT,
PKG_ARRAY,
PKG_OBJECT,
PKG_NULL
} pkg_object_t;
/**
* Keys for accessing pkg plugin data
*/
typedef enum _pkg_plugin_key {
PKG_PLUGIN_NAME = 0,
PKG_PLUGIN_DESC,
PKG_PLUGIN_VERSION,
PKG_PLUGIN_PLUGINFILE
} pkg_plugin_key;
/**
* Keys for hooking into the library
*/
typedef enum _pkg_plugin_hook_t {
PKG_PLUGIN_HOOK_PRE_INSTALL = 1,
PKG_PLUGIN_HOOK_POST_INSTALL,
PKG_PLUGIN_HOOK_PRE_DEINSTALL,
PKG_PLUGIN_HOOK_POST_DEINSTALL,
PKG_PLUGIN_HOOK_PRE_FETCH,
PKG_PLUGIN_HOOK_POST_FETCH,
PKG_PLUGIN_HOOK_EVENT,
PKG_PLUGIN_HOOK_PRE_UPGRADE,
PKG_PLUGIN_HOOK_POST_UPGRADE,
PKG_PLUGIN_HOOK_PRE_AUTOREMOVE,
PKG_PLUGIN_HOOK_POST_AUTOREMOVE,
PKG_PLUGIN_HOOK_PKGDB_CLOSE_RW,
} pkg_plugin_hook_t;
/**
* Error type used everywhere by libpkg.
*/
typedef enum {
EPKG_OK = 0,
/**
* No more items available (end of the loop).
*/
EPKG_END,
EPKG_WARN,
/**
* The function encountered a fatal error.
*/
EPKG_FATAL,
/**
* Can not delete the package because it is required by
* another package.
*/
EPKG_REQUIRED,
/**
* Can not install the package because it is already installed.
*/
EPKG_INSTALLED,
/**
* Can not install the package because some dependencies are
* unresolved.
*/
EPKG_DEPENDENCY,
/**
* Can not operate on package because it is locked
*/
EPKG_LOCKED,
/**
* Can not create local database or database non-existent
*/
EPKG_ENODB,
/**
* local file newer than remote
*/
EPKG_UPTODATE,
/**
* unkown keyword
*/
EPKG_UNKNOWN,
/**
* repo DB schema incompatible version
*/
EPKG_REPOSCHEMA,
/**
* Insufficient privilege for action
*/
EPKG_ENOACCESS,
/**
* Insecure permissions on any component of
* $PKGDB_DIR/local.sqlite or any of the repo database bits
*/
EPKG_INSECURE,
/**
* A conflict between packages found
*/
EPKG_CONFLICT,
/**
* Need to repeat operation
*/
EPKG_AGAIN
} pkg_error_t;
/**
* Upgrade, downgrade or reinstall?
*/
typedef enum {
PKG_DOWNGRADE = 0,
PKG_REINSTALL,
PKG_UPGRADE,
} pkg_change_t;
/**
* Locking types for database:
* `PKGDB_LOCK_READONLY`: lock for read only queries (can be nested)
* `PKGDB_LOCK_ADVISORY`: write to DB inside a transaction (allows `PKGDB_LOCK_READONLY`)
* `PKGDB_LOCK_EXCLUSIVE`: possibly destructive operations (does not allow other locks)
*/
typedef enum {
PKGDB_LOCK_READONLY,
PKGDB_LOCK_ADVISORY,
PKGDB_LOCK_EXCLUSIVE
} pkgdb_lock_t;
typedef enum {
PKG_SOLVED_INSTALL,
PKG_SOLVED_DELETE,
PKG_SOLVED_UPGRADE,
PKG_SOLVED_UPGRADE_REMOVE,
PKG_SOLVED_FETCH,
PKG_SOLVED_UPGRADE_INSTALL
} pkg_solved_t;
#define PKG_OPEN_MANIFEST_ONLY 0x1
#define PKG_OPEN_MANIFEST_COMPACT (0x1 << 1)
#define PKG_OPEN_TRY (0x1 << 2)
/**
* test if pkg is installed and activated.
* @param count If all the tests pass, and count is non-NULL,
* write the number of installed packages into *count
*/
pkg_status_t pkg_status(int *count);
/**
* Allocate a new pkg.
* Allocated pkg must be deallocated by pkg_free().
*/
int pkg_new(struct pkg **, pkg_t type);
/**
* Deallocate a pkg
*/
void pkg_free(struct pkg *);
/**
* Check if a package is valid according to its type.
*/
int pkg_is_valid(const struct pkg * restrict);
/**
* Open a package file archive and retrive informations.
* @param p A pointer to pkg allocated by pkg_new(), or if it points to a
* NULL pointer, the function allocate a new pkg using pkg_new().
* @param path The path to the local package archive.
* @param keys manifest keys that should be initialised
* @param flags open flags
*/
int pkg_open(struct pkg **p, const char *path, struct pkg_manifest_key *keys, int flags);
int pkg_open_fd(struct pkg **p, int fd, struct pkg_manifest_key *keys, int flags);
/**
* @return the type of the package.
* @warning returns PKG_NONE on error.
*/
pkg_t pkg_type(const struct pkg * restrict);
/**
* Generic getter for simple attributes.
* @return NULL-terminated string.
* @warning May return a NULL pointer.
*/
int pkg_get2(struct pkg const *const, ...);
#define pkg_get(pkg, ...) pkg_get2(pkg, __VA_ARGS__, -1)
int pkg_list_count(const struct pkg *, pkg_list);
/**
* Iterates over the dependencies of the package.
* @param dep Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_deps(const struct pkg *, struct pkg_dep **dep);
/**
* Iterates over the reverse dependencies of the package.
* That is, the packages which require this package.
* @param dep Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_rdeps(const struct pkg *, struct pkg_dep **dep);
/**
* Iterates over the files of the package.
* @param file Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_files(const struct pkg *, struct pkg_file **file);
/**
* Iterates over the directories of the package.
* @param Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_dirs(const struct pkg *pkg, struct pkg_dir **dir);
/**
* Iterates over the users of the package.
* @param Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_users(const struct pkg *pkg, char **user);
/**
* Iterates over the groups of the package.
* @param Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_groups(const struct pkg *pkg, char **group);
/**
* Iterates over the options of the package.
* @param option Must be set to NULL for the first call.
* @return An error code.
*/
int pkg_options(const struct pkg *, struct pkg_option **option);
/**
* Iterates over the shared libraries used by the package.
* @param shlib must be set to NULL for the first call.
* @return An error code
*/
int pkg_shlibs_required(const struct pkg *pkg, char **shlib);
/**
* Iterates over the shared libraries provided by the package.
* @param shlib must be set to NULL for the first call.
* @return An error code
*/
int pkg_shlibs_provided(const struct pkg *pkg, char **shlib);
/**
* Iterates over the conflicts registered in the package.
* @param conflict must be set to NULL for the first call.
* @return An error code
*/
int pkg_conflicts(const struct pkg *pkg, struct pkg_conflict **conflict);
/**
* Iterates over the provides registered in the package.
* @param provide must be set to NULL for the first call.
* @return An error code
*/
int pkg_provides(const struct pkg *pkg, char **provide);
int pkg_requires(const struct pkg *pkg, char **require);
int pkg_categories(const struct pkg *pkg, char **category);
int pkg_licenses(const struct pkg *pkg, char **licenses);
/**
* Iterates over the config files registered in the package.
* @param provide must be set to NULL for the first call.
* @return An error code
*/
int pkg_config_files(const struct pkg *pkg, struct pkg_config_file **cf);
/**
* Iterate over all of the files within the package pkg, ensuring the
* dependency list contains all applicable packages providing the
* shared objects used by pkg.
* Also add all the shared object into the shlibs.
* It respects the SHLIBS options from configuration
* @return An error code
*/
/* Don't conflict with PKG_LOAD_* q.v. */
#define PKG_CONTAINS_ELF_OBJECTS (1U << 24)
#define PKG_CONTAINS_STATIC_LIBS (1U << 25)
#define PKG_CONTAINS_H_OR_LA (1U << 26)
int pkg_analyse_files(struct pkgdb *, struct pkg *, const char *);
/**
* Suggest if a package could be marked architecture independent or
* not.
*/
int pkg_suggest_arch(struct pkg *, const char *, bool);
/**
* Generic setter for simple attributes.
*/
int pkg_set2(struct pkg *pkg, ...);
#define pkg_set(pkg, ...) pkg_set2(pkg, __VA_ARGS__, -1)
int pkgdb_set2(struct pkgdb *db, struct pkg *pkg, ...);
#define pkgdb_set(db, pkg, ...) pkgdb_set2(db, pkg, __VA_ARGS__, -1)
/**
* Read the content of a file into a buffer, then call pkg_set().
*/
int pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *file, bool trimcr);
int pkg_set_from_fileat(int fd, struct pkg *pkg, pkg_attr attr, const char *file, bool trimcr);
/**
* Set a new debug level used inside of pkg.
* @param debug_level Debug level between 0 (no debugging) and 4 (max debugging).
* @return Previous debug level.
*/
int64_t pkg_set_debug_level(int64_t debug_level);
void pkg_set_rootdir(const char *rootdir);
/**
* Allocate a new struct pkg and add it to the deps of pkg.
* @return An error code.
*/
int pkg_adddep(struct pkg *pkg, const char *name, const char *origin, const
char *version, bool locked);
int pkg_addrdep(struct pkg *pkg, const char *name, const char *origin, const
char *version, bool locked);
/**
* Helper which call pkg_addscript() with the content of the file and
* with the correct type.
*/
int pkg_addscript_file(struct pkg *pkg, const char *path);
int pkg_addscript_fileat(int fd, struct pkg *pkg, const char *path);
/**
* Parse a manifest and set the attributes of pkg accordingly.
* @param buf An NULL-terminated buffer containing the manifest data.
* @return An error code.
*/
int pkg_parse_manifest(struct pkg *pkg, char *buf, size_t len, struct pkg_manifest_key *key);
int pkg_parse_manifest_file(struct pkg *pkg, const char *, struct pkg_manifest_key *key);
int pkg_parse_manifest_fileat(int fd, struct pkg *pkg, const char *, struct pkg_manifest_key *key);
int pkg_manifest_keys_new(struct pkg_manifest_key **k);
void pkg_manifest_keys_free(struct pkg_manifest_key *k);
int pkg_manifest_parser_new(struct pkg_manifest_parser **p);
void pkg_manifest_parser_free(struct pkg_manifest_parser *p);
#define PKG_MANIFEST_EMIT_COMPACT 0x1
#define PKG_MANIFEST_EMIT_NOFILES (0x1 << 1)
#define PKG_MANIFEST_EMIT_PRETTY (0x1 << 2)
#define PKG_MANIFEST_EMIT_JSON (0x1 << 3)
#define PKG_MANIFEST_EMIT_UCL (0x1 << 4)
/**
* Emit a manifest according to the attributes of pkg.
* @param buf A pointer which will hold the allocated buffer containing the
* manifest. To be free'ed.
* @param flags Flags for manifest emitting.
* @param pdigest A pointer that will hold digest of manifest produced, ignored
* if NULL. To be free'ed if not NULL.
* @return An error code.
*/
int pkg_emit_manifest(struct pkg *pkg, char **buf, short flags, char **pdigest);
int pkg_emit_manifest_file(struct pkg*, FILE *, short, char **pdigest);
/* pkg_dep */
const char *pkg_dep_get(struct pkg_dep const * const , const pkg_dep_attr);
#define pkg_dep_name(d) pkg_dep_get(d, PKG_DEP_NAME)
#define pkg_dep_origin(d) pkg_dep_get(d, PKG_DEP_ORIGIN)
#define pkg_dep_version(d) pkg_dep_get(d, PKG_DEP_VERSION)
bool pkg_dep_is_locked(struct pkg_dep const * const);
bool pkg_has_dir(struct pkg *, const char *);
bool pkg_has_file(struct pkg *, const char *);
/* pkg_license */
const char *pkg_license_name(struct pkg_license const * const);
/* pkg_script */
const char *pkg_script_get(struct pkg const * const, pkg_script);
/**
* @param db A pointer to a struct pkgdb object
* @param origin Package origin
* @param pkg An allocated struct pkg or a pointer to a NULL pointer. In the
* last case, the function take care of the allocation.
* @param flags OR'ed PKG_LOAD_*
* @return EPKG_OK if the package is installed,
* and != EPKG_OK if the package is not installed or an error occurred
* Match will be case sensitive or insensitive depending on
* pkgdb_case_sensitive()
*/
int pkg_try_installed(struct pkgdb *db, const char *origin,
struct pkg **pkg, unsigned flags);
/**
* @param db A pointer to a struct pkgdb object
* @param origin Package origin
* @return EPKG_OK if the package is installed,
* and != EPKG_OK if the package is not installed or an error occurred
* Match will be case sensitive or insensitive depending on
* pkgdb_case_sensitive()
*/
int pkg_is_installed(struct pkgdb *db, const char *name);
/**
* Create a repository database.
* @param path The path where the repository live.
* @param output_dir The path where the package repository should be created.
* @param force If true, rebuild the repository catalogue from scratch
* @param filesite If true, create a list of all files in repo
* @param metafile Open meta from the specified file
* @param legacy Create legacy (1.2 compatible) repo
*/
int pkg_create_repo(char *path, const char *output_dir, bool filelist,
const char *metafile, bool legacy);
int pkg_finish_repo(const char *output_dir, pem_password_cb *cb, char **argv,
int argc, bool filelist);
/**
* Test if the EUID has sufficient privilege to carry out some
* operation (mode is a bitmap indicating READ, WRITE, CREATE) on the
* databases indicated in the database bitmap.
*/
#define PKGDB_MODE_READ (0x1<<0)
#define PKGDB_MODE_WRITE (0x1<<1)
#define PKGDB_MODE_CREATE (0x1<<2)
#define PKGDB_DB_LOCAL (0x1<<0)
#define PKGDB_DB_REPO (0x1<<1)
int pkgdb_access(unsigned mode, unsigned database);
/**
* Open the local package database.
* The db must be free'ed with pkgdb_close().
* @return An error code.
*/
int pkgdb_open(struct pkgdb **db, pkgdb_t type);
/**
* Open the local package database and repositories, possibly
* overriding configured repositories and replacing with the given
* reponame if not NULL
* @return An error code
*/
int pkgdb_open_all(struct pkgdb **db, pkgdb_t type, const char *reponame);
/**
* Locking functions
*/
int pkgdb_obtain_lock(struct pkgdb *db, pkgdb_lock_t type);
int pkgdb_upgrade_lock(struct pkgdb *db, pkgdb_lock_t old_type, pkgdb_lock_t new_type);
int pkgdb_downgrade_lock(struct pkgdb *db, pkgdb_lock_t old_type,
pkgdb_lock_t new_type);
int pkgdb_release_lock(struct pkgdb *db, pkgdb_lock_t type);
/**
* Transaction/savepoint handling.
* @param savepoint -- if NULL or an empty string, use BEGIN, ROLLBACK, COMMIT
* otherwise use SAVEPOINT, ROLLBACK TO, RELEASE.
* @return an error code.
*/
int pkgdb_transaction_begin(struct pkgdb *db, const char *savepoint);
int pkgdb_transaction_commit(struct pkgdb *db, const char *savepoint);
int pkgdb_transaction_rollback(struct pkgdb *db, const char *savepoint);
/**
* Close and free the struct pkgdb.
*/
void pkgdb_close(struct pkgdb *db);
/**
* Initialize the local cache of the remote database with indicies
*/
int pkgdb_remote_init(struct pkgdb *db, const char *reponame);
/**
* Dump to or load from a backup copy of the main database file
* (local.sqlite)
*/
int pkgdb_dump(struct pkgdb *db, const char *dest);
int pkgdb_load(struct pkgdb *db, const char *src);
/**
* Register a ports to the database.
* @return An error code.
*/
int pkgdb_register_ports(struct pkgdb *db, struct pkg *pkg);
/**
* Set the case sensitivity flag on or off. Defaults to
* true (case_sensitive)
*/
void pkgdb_set_case_sensitivity(bool);
/**
* Query the state of the case sensitity setting.
*/
bool pkgdb_case_sensitive(void);
/**
* Query the local package database.
* @param type Describe how pattern should be used.
* @warning Returns NULL on failure.
*/
struct pkgdb_it * pkgdb_query(struct pkgdb *db, const char *pattern,
match_t type);
struct pkgdb_it * pkgdb_repo_query(struct pkgdb *db, const char *pattern,
match_t type, const char *reponame);
struct pkgdb_it * pkgdb_repo_search(struct pkgdb *db, const char *pattern,
match_t type, pkgdb_field field, pkgdb_field sort, const char *reponame);
/**
* @todo Return directly the struct pkg?
*/
struct pkgdb_it * pkgdb_query_which(struct pkgdb *db, const char *path, bool glob);
struct pkgdb_it * pkgdb_query_shlib_require(struct pkgdb *db, const char *shlib);
struct pkgdb_it * pkgdb_query_shlib_provide(struct pkgdb *db, const char *shlib);
struct pkgdb_it * pkgdb_query_require(struct pkgdb *db, const char *req);
struct pkgdb_it * pkgdb_query_provide(struct pkgdb *db, const char *req);
struct pkgdb_it * pkgdb_rquery_provide(struct pkgdb *db,
const char *provide, const char *repo);
/**
* Add/Modify/Delete an annotation for a package
* @param tag -- tag for the annotation
* @param value -- text of the annotation
* @return An error code
*/
int pkgdb_add_annotation(struct pkgdb *db, struct pkg *pkg,
const char *tag, const char *value);
int pkgdb_modify_annotation(struct pkgdb *db, struct pkg *pkg,
const char *tag, const char *value);
int pkgdb_delete_annotation(struct pkgdb *db, struct pkg *pkg,
const char *tag);
#define PKG_LOAD_BASIC 0
#define PKG_LOAD_DEPS (1U << 0)
#define PKG_LOAD_RDEPS (1U << 1)
#define PKG_LOAD_FILES (1U << 2)
#define PKG_LOAD_SCRIPTS (1U << 3)
#define PKG_LOAD_OPTIONS (1U << 4)
#define PKG_LOAD_DIRS (1U << 5)
#define PKG_LOAD_CATEGORIES (1U << 6)
#define PKG_LOAD_LICENSES (1U << 7)
#define PKG_LOAD_USERS (1U << 8)
#define PKG_LOAD_GROUPS (1U << 9)
#define PKG_LOAD_SHLIBS_REQUIRED (1U << 10)
#define PKG_LOAD_SHLIBS_PROVIDED (1U << 11)
#define PKG_LOAD_ANNOTATIONS (1U << 12)
#define PKG_LOAD_CONFLICTS (1U << 13)
#define PKG_LOAD_PROVIDES (1U << 14)
#define PKG_LOAD_REQUIRES (1U << 15)
/* Make sure new PKG_LOAD don't conflict with PKG_CONTAINS_* */
/**
* Get the next pkg.
* @param pkg An allocated struct pkg or a pointer to a NULL pointer. In the
* last case, the function take care of the allocation.
* @param flags OR'ed PKG_LOAD_*
* @return An error code.
*/
int pkgdb_it_next(struct pkgdb_it *, struct pkg **pkg, unsigned flags);
/**
* Reset the pkgdb_it iterator, allowing for re-iterating over it
*/
void pkgdb_it_reset(struct pkgdb_it *);
/**
* Return the number of rows found.
* @return -1 on error
*/
int pkgdb_it_count(struct pkgdb_it *);
/**
* Free a struct pkgdb_it.
*/
void pkgdb_it_free(struct pkgdb_it *);
/**
* Compact the database to save space.
* Note that the function will really compact the database only if some
* internal criterias are met.
* @return An error code.
*/
int pkgdb_compact(struct pkgdb *db);
/**
* Install and register a new package.
* @param db An opened pkgdb
* @param path The path to the package archive file on the local disk
* @return An error code.
*/
int pkg_add(struct pkgdb *db, const char *path, unsigned flags,
struct pkg_manifest_key *keys, const char *location);
int pkg_add_from_remote(struct pkgdb *db, const char *path, unsigned flags,
struct pkg_manifest_key *keys, const char *location, struct pkg *rp);
#define PKG_ADD_UPGRADE (1U << 0)
#define PKG_ADD_USE_UPGRADE_SCRIPTS (1U << 1)
#define PKG_ADD_AUTOMATIC (1U << 2)