1 /*
2   Copyright 2021 Northern.tech AS
3 
4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; version 3.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18 
19   To the extent this program is licensed as part of the Enterprise
20   versions of CFEngine, the applicable Commercial Open Source License
21   (COSL) may apply to this file if you as a licensee so wish it. See
22   included file COSL.txt.
23 */
24 
25 #ifndef PACKAGE_MODULE_H
26 #define PACKAGE_MODULE_H
27 
28 #include <cf3.defs.h>
29 
30 //TODO: use promise expireafter instead
31 #define PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC 4 * 3600 /* 4 hours timeout */
32 #define PACKAGE_PROMISE_TERMINATION_CHECK_SEC 1
33 
34 #define GLOBAL_PACKAGE_PROMISE_LOCK_NAME "new_packages_promise_lock"
35 
36 typedef enum
37 {
38     PACKAGE_TYPE_NONE,
39     PACKAGE_TYPE_REPO,
40     PACKAGE_TYPE_FILE
41 } PackageType;
42 
43 typedef struct
44 {
45     char *name;
46     char *version;
47     char *arch;
48     PackageType type;
49 } PackageInfo;
50 
51 typedef struct
52 {
53     char *type;
54     char *message;
55 } PackageError;
56 
57 typedef struct
58 {
59     char *name;
60     char *path;
61     char *script_path;
62     char *script_path_quoted;
63     char *script_exec_opts;
64     PackageModuleBody *package_module;
65     int supported_api_version;
66 } PackageModuleWrapper;
67 
68 typedef struct
69 {
70     CfLock g_lock;
71     EvalContext *lock_ctx;
72 } PackagePromiseGlobalLock;
73 
74 typedef enum {
75     UPDATE_TYPE_INSTALLED,
76     UPDATE_TYPE_UPDATES,
77     UPDATE_TYPE_LOCAL_UPDATES,
78 } UpdateType;
79 
80 PromiseResult HandlePresentPromiseAction(EvalContext *ctx,
81                                          const Promise *pp,
82                                          const Attributes *attr,
83                                          const PackageModuleWrapper *wrapper);
84 PromiseResult HandleAbsentPromiseAction(EvalContext *ctx,
85                                         const Promise *pp,
86                                         const Attributes *attr,
87                                         const PackageModuleWrapper *wrapper);
88 
89 void UpdatePackagesCache(EvalContext *ctx, bool force_update);
90 
91 PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module);
92 void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper);
93 
94 PackagePromiseGlobalLock AcquireGlobalPackagePromiseLock(EvalContext *ctx);
95 void YieldGlobalPackagePromiseLock(PackagePromiseGlobalLock lock);
96 
97 #endif
98