|
| 1 | +/**************************************************************************** |
| 2 | + * apps/system/nxpkg/pkg.h |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 7 | + * contributor license agreements. See the NOTICE file distributed with |
| 8 | + * this work for additional information regarding copyright ownership. The |
| 9 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + * "License"); you may not use this file except in compliance with the |
| 11 | + * License. You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | + * License for the specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + * |
| 21 | + ****************************************************************************/ |
| 22 | + |
| 23 | +#ifndef __APPS_SYSTEM_NXPKG_PKG_H |
| 24 | +#define __APPS_SYSTEM_NXPKG_PKG_H |
| 25 | + |
| 26 | +/**************************************************************************** |
| 27 | + * Included Files |
| 28 | + ****************************************************************************/ |
| 29 | + |
| 30 | +#include <limits.h> |
| 31 | +#include <stdbool.h> |
| 32 | +#include <stddef.h> |
| 33 | +#include <stdio.h> |
| 34 | + |
| 35 | +/**************************************************************************** |
| 36 | + * Pre-processor Definitions |
| 37 | + ****************************************************************************/ |
| 38 | + |
| 39 | +#define PKG_REPO_DIR "/etc/nxpkg" |
| 40 | +#define PKG_REPO_INDEX "/etc/nxpkg/index.json" |
| 41 | +#define PKG_REPO_INSTALLED "/var/lib/nxpkg/installed.json" |
| 42 | +#define PKG_STORE_DIR "/var/lib/nxpkg/pkgs" |
| 43 | +#define PKG_TMP_DIR "/var/cache/nxpkg" |
| 44 | +#define PKG_TMP_PKG_DIR "/var/cache/nxpkg/pkg" |
| 45 | + |
| 46 | +#define PKG_NAME_MAX 63 |
| 47 | +#define PKG_VERSION_MAX 31 |
| 48 | +#define PKG_ARCH_MAX 31 |
| 49 | +#define PKG_COMPAT_MAX 63 |
| 50 | +#define PKG_HASH_HEX_LEN 64 |
| 51 | +#define PKG_INDEX_MAX 32 |
| 52 | +#define PKG_INSTALLED_MAX 16 |
| 53 | +#define PKG_INSTALLED_VERSIONS_MAX 8 |
| 54 | + |
| 55 | +/**************************************************************************** |
| 56 | + * Public Types |
| 57 | + ****************************************************************************/ |
| 58 | + |
| 59 | +enum pkg_payload_type_e |
| 60 | +{ |
| 61 | + PKG_PAYLOAD_ELF = 0, |
| 62 | + PKG_PAYLOAD_SHARED_LIB |
| 63 | +}; |
| 64 | + |
| 65 | +enum pkg_txn_state_e |
| 66 | +{ |
| 67 | + PKG_TXN_IDLE = 0, |
| 68 | + PKG_TXN_FETCHING, |
| 69 | + PKG_TXN_VERIFIED, |
| 70 | + PKG_TXN_STAGED, |
| 71 | + PKG_TXN_COMPAT_OK, |
| 72 | + PKG_TXN_ACTIVATED, |
| 73 | + PKG_TXN_CLEANUP, |
| 74 | + PKG_TXN_FAILED, |
| 75 | + PKG_TXN_RESTORE |
| 76 | +}; |
| 77 | + |
| 78 | +struct pkg_manifest_s |
| 79 | +{ |
| 80 | + char name[PKG_NAME_MAX + 1]; |
| 81 | + char version[PKG_VERSION_MAX + 1]; |
| 82 | + char arch[PKG_ARCH_MAX + 1]; |
| 83 | + char compat[PKG_COMPAT_MAX + 1]; |
| 84 | + char artifact[PATH_MAX]; |
| 85 | + char sha256[PKG_HASH_HEX_LEN + 1]; |
| 86 | + enum pkg_payload_type_e type; |
| 87 | +}; |
| 88 | + |
| 89 | +struct pkg_index_s |
| 90 | +{ |
| 91 | + struct pkg_manifest_s manifests[PKG_INDEX_MAX]; |
| 92 | + size_t count; |
| 93 | +}; |
| 94 | + |
| 95 | +struct pkg_installed_entry_s |
| 96 | +{ |
| 97 | + char name[PKG_NAME_MAX + 1]; |
| 98 | + char current[PKG_VERSION_MAX + 1]; |
| 99 | + char previous[PKG_VERSION_MAX + 1]; |
| 100 | + char arch[PKG_ARCH_MAX + 1]; |
| 101 | + char compat[PKG_COMPAT_MAX + 1]; |
| 102 | + char versions[PKG_INSTALLED_VERSIONS_MAX][PKG_VERSION_MAX + 1]; |
| 103 | + enum pkg_payload_type_e type; |
| 104 | + size_t version_count; |
| 105 | +}; |
| 106 | + |
| 107 | +struct pkg_installed_db_s |
| 108 | +{ |
| 109 | + struct pkg_installed_entry_s entries[PKG_INSTALLED_MAX]; |
| 110 | + size_t count; |
| 111 | +}; |
| 112 | + |
| 113 | +/**************************************************************************** |
| 114 | + * Public Function Prototypes |
| 115 | + ****************************************************************************/ |
| 116 | + |
| 117 | +const char *pkg_manifest_type_str(enum pkg_payload_type_e type); |
| 118 | +int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest); |
| 119 | +int pkg_manifest_parse_type(FAR const char *value, |
| 120 | + FAR enum pkg_payload_type_e *type); |
| 121 | + |
| 122 | +int pkg_store_prepare_layout(void); |
| 123 | +int pkg_store_ensure_package_root(FAR const char *name); |
| 124 | +int pkg_store_ensure_version_dir(FAR const char *name, |
| 125 | + FAR const char *version); |
| 126 | +int pkg_store_format_index_path(FAR char *buffer, size_t size); |
| 127 | +int pkg_store_format_installed_path(FAR char *buffer, size_t size); |
| 128 | +int pkg_store_format_package_root(FAR char *buffer, size_t size, |
| 129 | + FAR const char *name); |
| 130 | +int pkg_store_format_version_path(FAR char *buffer, size_t size, |
| 131 | + FAR const char *name, |
| 132 | + FAR const char *version); |
| 133 | +int pkg_store_format_current_path(FAR char *buffer, size_t size, |
| 134 | + FAR const char *name); |
| 135 | +int pkg_store_format_previous_path(FAR char *buffer, size_t size, |
| 136 | + FAR const char *name); |
| 137 | +int pkg_store_format_txn_path(FAR char *buffer, size_t size, |
| 138 | + FAR const char *name); |
| 139 | +int pkg_store_format_lock_path(FAR char *buffer, size_t size, |
| 140 | + FAR const char *name); |
| 141 | +int pkg_store_format_download_path(FAR char *buffer, size_t size, |
| 142 | + FAR const char *name, |
| 143 | + FAR const char *version); |
| 144 | +int pkg_store_format_payload_path(FAR char *buffer, size_t size, |
| 145 | + FAR const char *name, |
| 146 | + FAR const char *version, |
| 147 | + FAR const char *artifact); |
| 148 | +int pkg_store_format_manifest_path(FAR char *buffer, size_t size, |
| 149 | + FAR const char *name, |
| 150 | + FAR const char *version); |
| 151 | +int pkg_store_read_text(FAR const char *path, FAR char **buffer); |
| 152 | +int pkg_store_write_text_atomic(FAR const char *path, FAR const char *text); |
| 153 | +int pkg_store_copy_file(FAR const char *src, FAR const char *dest); |
| 154 | +int pkg_store_remove_file(FAR const char *path); |
| 155 | + |
| 156 | +const char *pkg_runtime_arch(void); |
| 157 | +const char *pkg_runtime_compat(void); |
| 158 | +int pkg_compat_check(FAR const struct pkg_manifest_s *manifest); |
| 159 | + |
| 160 | +int pkg_hash_file_sha256(FAR const char *path, |
| 161 | + FAR char digest[PKG_HASH_HEX_LEN + 1]); |
| 162 | + |
| 163 | +int pkg_metadata_load_index(FAR struct pkg_index_s *index); |
| 164 | +FAR const struct pkg_manifest_s * |
| 165 | +pkg_metadata_find_latest(FAR const struct pkg_index_s *index, |
| 166 | + FAR const char *name); |
| 167 | +int pkg_metadata_load_installed(FAR struct pkg_installed_db_s *db); |
| 168 | +int pkg_metadata_save_installed(FAR const struct pkg_installed_db_s *db); |
| 169 | +FAR struct pkg_installed_entry_s * |
| 170 | +pkg_metadata_find_installed(FAR struct pkg_installed_db_s *db, |
| 171 | + FAR const char *name); |
| 172 | +int pkg_metadata_write_manifest(FAR const char *path, |
| 173 | + FAR const struct pkg_manifest_s *manifest); |
| 174 | +int pkg_metadata_print_installed(FAR FILE *stream, |
| 175 | + FAR const struct pkg_installed_db_s *db); |
| 176 | + |
| 177 | +const char *pkg_txn_state_str(enum pkg_txn_state_e state); |
| 178 | +int pkg_txn_write_state(FAR const char *name, enum pkg_txn_state_e state); |
| 179 | +int pkg_txn_clear_state(FAR const char *name); |
| 180 | + |
| 181 | +int pkg_install(FAR const char *name); |
| 182 | +int pkg_list(FAR FILE *stream); |
| 183 | + |
| 184 | +void pkg_error(FAR const char *fmt, ...); |
| 185 | +void pkg_info(FAR const char *fmt, ...); |
| 186 | + |
| 187 | +#endif /* __APPS_SYSTEM_NXPKG_PKG_H */ |
0 commit comments