dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / triglib.h
CommitLineData
1479465f
GJ
1/*
2 * libdpkg - Debian packaging suite library routines
3 * triglib.h - declarations for trigger handling
4 *
5 * Copyright © 2007 Canonical, Ltd.
6 * written by Ian Jackson <ijackson@chiark.greenend.org.uk>
7 * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
8 *
9 * This 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 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This 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 <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef LIBDPKG_TRIGLIB_H
24#define LIBDPKG_TRIGLIB_H
25
26#include <dpkg/macros.h>
27#include <dpkg/dpkg-db.h>
28
29DPKG_BEGIN_DECLS
30
31/**
32 * @defgroup triglib Trigger handling
33 * @ingroup dpkg-internal
34 * @{
35 */
36
37/*
38 * Hooks for more sophisticated processing in dpkg proper.
39 *
40 * We do things like this so we can get most of the trigger tracking
41 * in dpkg-query, dselect, and so on, but avoid the transitional
42 * processing and deferred trigproc queue management other than when
43 * we're actually doing real package management work.
44 */
45
46const char *trig_name_is_illegal(const char *p);
47
48enum trig_options {
49 TRIG_AWAIT,
50 TRIG_NOAWAIT,
51};
52
53struct trigfileint {
54 struct pkginfo *pkg;
55 struct pkgbin *pkgbin;
56 struct filenamenode *fnn;
57 enum trig_options options;
58 struct trigfileint *samefile_next;
59 struct {
60 struct trigfileint *next, *prev;
61 } inoverall;
62};
63
64/**
65 * The first two hooks are normally NULL.
66 * If non-NULL, we're dpkg proper and we might need to invent trigger
67 * activations as the first run of a triggers-supporting dpkg.
68 */
69struct trig_hooks {
70 void (*enqueue_deferred)(struct pkginfo *pend);
71 void (*transitional_activate)(enum modstatdb_rw cstatus);
72
73 struct filenamenode *(*namenode_find)(const char *filename, bool nonew);
74 struct trigfileint **(*namenode_interested)(struct filenamenode *fnn);
75
76 /** Returns a pointer from nfmalloc. */
77 const char *(*namenode_name)(struct filenamenode *fnn);
78};
79
80#define TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS \
81 static struct trigfileint **th_nn_interested(struct filenamenode *fnn) \
82 { return &fnn->trig_interested; } \
83 static const char *th_nn_name(struct filenamenode *fnn) \
84 { return fnn->name; }
85
86void trig_override_hooks(const struct trig_hooks *hooks);
87
88void trig_file_activate_byname(const char *trig, struct pkginfo *aw);
89void trig_file_activate(struct filenamenode *trig, struct pkginfo *aw);
90void trig_path_activate(struct filenamenode *trig, struct pkginfo *aw);
91
92bool trig_note_pend_core(struct pkginfo *pend, const char *trig /*not copied!*/);
93bool trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/);
94bool trig_note_aw(struct pkginfo *pend, struct pkginfo *aw);
95void trig_clear_awaiters(struct pkginfo *notpend);
96
97typedef void trig_awaited_pend_foreach_func(struct pkginfo *pkg);
98
99void trig_awaited_pend_enqueue(struct pkginfo *pend);
100void trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func);
101void trig_awaited_pend_free(void);
102
103void trig_fixup_awaiters(enum modstatdb_rw cstatus);
104
105void trig_file_interests_ensure(void);
106void trig_file_interests_save(void);
107
108typedef void trig_parse_cicb(const char *trig, struct pkginfo *pkg,
109 struct pkgbin *pkgbin, enum trig_options to);
110void trig_cicb_interest_delete(const char *trig, struct pkginfo *pkg,
111 struct pkgbin *pkgbin, enum trig_options to);
112void trig_cicb_interest_add(const char *trig, struct pkginfo *pkg,
113 struct pkgbin *pkgbin, enum trig_options to);
114void trig_cicb_statuschange_activate(const char *trig, struct pkginfo *pkg,
115 struct pkgbin *pkgbin, enum trig_options to);
116void trig_parse_ci(const char *file, trig_parse_cicb *interest,
117 trig_parse_cicb *activate, struct pkginfo *pkg,
118 struct pkgbin *pkgbin);
119
120void trig_incorporate(enum modstatdb_rw cstatus);
121
122/** @} */
123
124DPKG_END_DECLS
125
126#endif /* LIBDPKG_TRIGLIB_H */