Verified Commit 256287a7 authored by Karel Koci's avatar Karel Koci 🤘
Browse files

WIP

parent 60cb320d
Pipeline #59775 failed with stages
in 2 minutes and 39 seconds
#include "repository.h"
/*
* Copyright 2020, CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This file is part of the Turris Updater.
*
* Updater is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Updater is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Updater. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UPDATER_REPOSITORY_H
#define UPDATER_REPOSITORY_H
#include <stdbool.h>
#include <lua.h>
#include "uri.h"
struct repository;
struct repository_data;
struct package {
char *package; // Name of package (Package field in index)
char *versions; // Version of package (Version field in index)
char *architecture; // CPU architecture of package (Architecture field in index)
unsigned size; // Size of package in archive form (Size field in index)
unsigned installed_size; // Amount of space we need to install package (Installed-Size field)
char **depends; // NULL terminated array of dependencies (Dependencies field in index)
char **conflicts; // NULL terminated array of conflicts (Conflicts field in index)
char *md5sum; // MD5 sum of package (MD5Sum filed in index)
char *sha256sum; // SHA256 sum of package (SHA256sum filed in index)
char *filename; // Name of file we look for in repository (Filename field in index)
struct repository *repository;
};
struct repository {
bool valid; // if repository was successfully parsed
char *parse_error; // Field used to store parse error when index is invalid
Uri uri_obj; // URI object of repository
struct repository_data *data;
};
// Load new repository from given URI
// name is alias for repository reported to user in messages
// uri argument has to be downloaded but not finished URI
// Returns repository instance
struct repository *new_repository(const char *name, Uri uri);
// Package getter for repository
// name is canonical name of package to be returned
// version_limit is version limitation for package.
// Returns package from repository with highest version or NULL if there is no
// such package.
struct package *repository_get_package(const char *name, const char *version_limit);
// Create repository module and inject it into the lua state
void repository_mod_init(lua_State *L) __attribute__((nonnull));
#endif
/*
* Copyright 2020, CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This file is part of the Turris Updater.
*
* Updater is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Updater is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Updater. If not, see <http://www.gnu.org/licenses/>.
*/
#include "transaction.h"
#include <lauxlib.h>
#include <lualib.h>
#include "logging.h"
#include "inject.h"
static int lua_install(lua_State *L) {
return 0;
}
static const struct inject_func funcs[] = {
{ lua_install, "install" },
};
void transaction_mod_init(lua_State *L) {
TRACE("Transaction module init");
lua_newtable(L);
inject_func_n(L, "transaction", funcs, sizeof funcs / sizeof *funcs);
lua_pushvalue(L, -1);
lua_setmetatable(L, -2);
inject_module(L, "transaction");
}
/*
* Copyright 2020, CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This file is part of the Turris Updater.
*
* Updater is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Updater is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Updater. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UPDATER_TRANSACTION_H
#define UPDATER_TRANSACTION_H
#include <lua.h>
#include <stdbool.h>
// Transaction handle
struct transaction;
// Initialize new transaction instance
struct transaction *transaction_init();
void transaction_install(
// Create transaction module and inject it into the lua state
void transaction_mod_init(lua_State *L) __attribute__((nonnull));
#endif
......@@ -22,15 +22,10 @@
#include <stdint.h>
#include <stdbool.h>
#include "download.h"
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#define THREAD_LOCAL thread_local
#else
#warning Your LIBC does not provide threads.h. Updater should work but you should update nonetheless
#define THREAD_LOCAL
#endif
#include "util.h"
struct uri;
typedef struct uri* Uri;
enum uri_error {
URI_E_INVALID_URI, // Parsed URI was deemed as invalid
......@@ -113,7 +108,7 @@ struct uri {
// output_path: path to file where content will be stored in
// Returns URI object or NULL on error.
// Possible errors: URI_E_INVALID_URI, URI_E_UNKNOWN_SCHEME
struct uri *uri_to_file(const char *uri, const char *output_path,
Uri uri_to_file(const char *uri, const char *output_path,
const struct uri *parent) __attribute__((nonnull(1, 2)));
// Create new URI object which content will be stored in temporally file
// uri: URI string
......@@ -121,7 +116,7 @@ struct uri *uri_to_file(const char *uri, const char *output_path,
// output_template: path to file where content will be stored in
// Returns URI object or NULL on error.
// Possible errors: URI_E_INVALID_URI, URI_E_UNKNOWN_SCHEME
struct uri *uri_to_temp_file(const char *uri, char *output_template,
Uri uri_to_temp_file(const char *uri, char *output_template,
const struct uri *parent) __attribute__((nonnull(1, 2)));
// Create new URI object which content will be stored in buffer in program
// uri: URI string
......@@ -129,25 +124,25 @@ struct uri *uri_to_temp_file(const char *uri, char *output_template,
// for no inheritence.
// Returns URI object or NULL on error.
// Possible errors: URI_E_INVALID_URI, URI_E_UNKNOWN_SCHEME
struct uri *uri_to_buffer(const char *uri, const struct uri *parent) __attribute__((nonnull(1)));
Uri uri_to_buffer(const char *uri, const struct uri *parent) __attribute__((nonnull(1)));
// Free URI object
void uri_free(struct uri *uri) __attribute__((nonnull));
void uri_free(Uri) __attribute__((nonnull));
// Check if given URI is local or remote (if downloader is needed or not)
bool uri_is_local(const struct uri *uri) __attribute__((nonnull));
bool uri_is_local(const Uri uri) __attribute__((nonnull));
// Returns Unix path from URI. This can be used only on URI of URI_S_FILE type.
// Returned pointer points to malloc allocated memory and should be freed by
// caller.
char *uri_path(const struct uri *uri) __attribute__((nonnull));
char *uri_path(const Uri uri) __attribute__((nonnull));
// Register given URI to downloader to be downloaded
// uri: URI object downloader is registered to
// downloader: Downloader object
// Returns true on success or false on error.
// Possible errors: URI_E_SIG_FAIL, URI_E_OUTPUT_OPEN_FAIL
bool uri_downloader_register(struct uri *uri, struct downloader *downloader) __attribute__((nonnull(1, 2)));
bool uri_downloader_register(Uri uri, struct downloader *downloader) __attribute__((nonnull(1, 2)));
// Ensure that URI is received and stored to appropriate place (file or buffer)
// For remote ones call this after downloder_register and downloader_run.
......@@ -156,7 +151,7 @@ bool uri_downloader_register(struct uri *uri, struct downloader *downloader) __
// Possible errors: URI_E_UNFINISHED_DOWNLOAD, URI_E_DOWNLOAD_FAILED,
// URI_E_OUTPUT_OPEN_FAIL, URI_E_FILE_INPUT_ERROR, URI_E_OUTPUT_WRITE_FAIL,
// URI_E_VERIFY_FAIL, URI_E_SIG_FAIL
bool uri_finish(struct uri *uri) __attribute__((nonnull));
bool uri_finish(Uri uri) __attribute__((nonnull));
// Get buffer/content of URI
// Note that this can be called only once. Provided buffer has to be freed by
......@@ -165,7 +160,7 @@ bool uri_finish(struct uri *uri) __attribute__((nonnull));
// uri: URI object
// buffer: Pointer to pointer where address to first byte of buffer is set to
// len: Pointer to variable where size of buffer wiil be set to
void uri_take_buffer(struct uri *uri, uint8_t **buffer, size_t *len) __attribute__((nonnull(1, 2, 3)));
void uri_take_buffer(Uri uri, uint8_t **buffer, size_t *len) __attribute__((nonnull(1, 2, 3)));
// Build error message of URI retrieval failure.
// Returns string with error message.
......@@ -174,7 +169,7 @@ const char *uri_error_msg(enum uri_error);
// Returns pointer to error string for URI that reported URI_E_DOWNLOAD_FAILED
// when uri_finish was called.
// Returned string is valid until uri object is freed.
const char *uri_download_error(struct uri *uri) __attribute((nonnull));
const char *uri_download_error(Uri uri) __attribute((nonnull));
// Returns name of scheme
const char *uri_scheme_string(enum uri_scheme);
......@@ -185,7 +180,7 @@ const char *uri_scheme_string(enum uri_scheme);
// verify: boolean value setting if verification should or should not be done
// In default this is enabled.
// This setting is inherited.
void uri_set_ssl_verify(struct uri *uri, bool verify) __attribute__((nonnull(1)));
void uri_set_ssl_verify(Uri uri, bool verify) __attribute__((nonnull(1)));
// Set certification authority to be used
// uri: URI object CA to be set to
// ca_uri: URI to local CA to be added to list of CAs for SSL verification. You
......@@ -194,7 +189,7 @@ void uri_set_ssl_verify(struct uri *uri, bool verify) __attribute__((nonnull(1))
// In default system CAs are used.
// This setting is inherited.
// Possible errors: URI_E_NONLOCAL and all errors by uri_to_buffer
bool uri_add_ca(struct uri *uri, const char *ca_uri) __attribute__((nonnull(1)));
bool uri_add_ca(Uri uri, const char *ca_uri) __attribute__((nonnull(1)));
// Set URI to CRL that is used if CA verification is used
// uri: URI object CRLs to be set to
// crl_uri: URI to local CRL to be added to list of CRLs for SSL verification. You
......@@ -203,13 +198,13 @@ bool uri_add_ca(struct uri *uri, const char *ca_uri) __attribute__((nonnull(1)))
// In default CRL verification is disabled.
// This setting is inherited.
// Possible errors: URI_E_NONLOCAL and all errors by uri_to_buffer
bool uri_add_crl(struct uri *uri, const char *crl_uri) __attribute__((nonnull(1)));
bool uri_add_crl(Uri uri, const char *crl_uri) __attribute__((nonnull(1)));
// Set URI OCSP verification
// uri: URI object OCSP to be set to
// enabled: If OCSP should be used
// In default OCSP is enabled.
// This setting is inherited.
void uri_set_ocsp(struct uri *uri, bool enabled) __attribute__((nonnull(1)));
void uri_set_ocsp(Uri uri, bool enabled) __attribute__((nonnull(1)));
// HTTP/HTTPS configuration //
// Set public key verification
// uri: URI object public keys are set to
......@@ -217,7 +212,7 @@ void uri_set_ocsp(struct uri *uri, bool enabled) __attribute__((nonnull(1)));
// to drop all added URIs and that way to disable signature verification.
//This setting is inherited.
// Possible errors: URI_E_NONLOCAL and all errors by uri_to_temp_file
bool uri_add_pubkey(struct uri *uri, const char *pubkey_uri) __attribute__((nonnull(1)));
bool uri_add_pubkey(Uri uri, const char *pubkey_uri) __attribute__((nonnull(1)));
// Set URI to signature to be used.
// uri: URI object signature URI to be set to
// sig_uri: string URI to signature. This signature is received with same
......@@ -231,6 +226,6 @@ bool uri_add_pubkey(struct uri *uri, const char *pubkey_uri) __attribute__((nonn
// last command of all.
// This option is not inherited!
// Possible errors: all errors by uri_to_temp_file
bool uri_set_sig(struct uri *uri, const char *sig_uri) __attribute__((nonnull(1)));
bool uri_set_sig(Uri uri, const char *sig_uri) __attribute__((nonnull(1)));
#endif
......@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <alloca.h>
#include <unistd.h>
#include <threads.h>
// Writes given text to file. Be aware that no information about failure is given.
bool dump2file (const char *file, const char *text) __attribute__((nonnull,nonnull));
......@@ -88,4 +89,14 @@ char *printf_into(char *dst, const char *msg, ...) __attribute__((format(printf,
#define FALLTROUGH
#endif
// threads.h was introduced in C11 but we are not running on threads so it is not
// hard dependency for us. On the other hands we should warn about this.
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#define THREAD_LOCAL thread_local
#else
#warning Your LIBC does not provide threads.h. Updater should work but you should update nonetheless
#define THREAD_LOCAL
#endif
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment