#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
#include <pakfire/ctx.h>
#include <pakfire/dependencies.h>
#include <pakfire/jail.h>
#ifdef PAKFIRE_DEBUG_PARSER
if (*namespace)
- DEBUG(parser->pakfire, "%p: Looking up %s.%s\n", parser, namespace, name);
+ CTX_DEBUG(parser->ctx, "%p: Looking up %s.%s\n", parser, namespace, name);
else
- DEBUG(parser->pakfire, "%p: Looking up %s\n", parser, name);
+ CTX_DEBUG(parser->ctx, "%p: Looking up %s\n", parser, name);
#endif /* PAKFIRE_DEBUG_PARSER */
struct pakfire_parser_declaration* d;
// Return if namespace and name match
if ((strcmp(d->namespace, namespace) == 0) && (strcmp(d->name, name) == 0)) {
#ifdef PAKFIRE_DEBUG_PARSER
- DEBUG(parser->pakfire, "%p: Found result = %s\n", parser, d->value);
+ CTX_DEBUG(parser->ctx, "%p: Found result = %s\n", parser, d->value);
#endif /* PAKFIRE_DEBUG_PARSER */
return d;
}
#ifdef PAKFIRE_DEBUG_PARSER
- DEBUG(parser->pakfire, "%p: Nothing found\n", parser);
+ CTX_DEBUG(parser->ctx, "%p: Nothing found\n", parser);
#endif /* PAKFIRE_DEBUG_PARSER */
return NULL;
if (flags)
d->flags = flags;
- DEBUG(parser->pakfire, "%p: Updated declaration: %s.%s = %s\n",
+ CTX_DEBUG(parser->ctx, "%p: Updated declaration: %s.%s = %s\n",
parser, d->namespace, d->name, d->value);
// All done
// Import flags
d->flags = flags;
- DEBUG(parser->pakfire, "%p: New declaration (%u): %s.%s %s= %s\n",
+ CTX_DEBUG(parser->ctx, "%p: New declaration (%u): %s.%s %s= %s\n",
parser,
d->flags,
d->namespace,
static int pakfire_parser_find_template(struct pakfire_parser* parser,
char* template, const size_t length, const char* namespace) {
- DEBUG(parser->pakfire, "Looking up template in namespace '%s'\n", namespace);
+ CTX_DEBUG(parser->ctx, "Looking up template in namespace '%s'\n", namespace);
struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(
parser, namespace, "template");
// Fetch the value of the current declaration
const char* old_value = pakfire_parser_get_raw(parser, namespace, name);
- DEBUG(parser->pakfire, "%p: Old value for %s.%s = %s\n",
+ CTX_DEBUG(parser->ctx, "%p: Old value for %s.%s = %s\n",
parser, namespace, name, old_value);
// Set the new value when there is no old one
PCRE2_UCHAR* pattern = NULL;
PCRE2_SIZE pattern_length;
- DEBUG(parser->pakfire, "Searching for commands in:\n%s\n", *buffer);
+ CTX_DEBUG(parser->ctx, "Searching for commands in:\n%s\n", *buffer);
// Allocate memory for results
pcre2_match_data* match = pcre2_match_data_create_from_pattern(
// End loop when we have expanded all variables
if (r == PCRE2_ERROR_NOMATCH) {
- DEBUG(parser->pakfire, "No (more) matches found\n");
+ CTX_DEBUG(parser->ctx, "No (more) matches found\n");
r = 0;
break;
}
goto ERROR;
#ifdef PAKFIRE_DEBUG_PARSER
- DEBUG(parser->pakfire, "Expanding command: %s\n", command);
+ CTX_DEBUG(parser->ctx, "Expanding command: %s\n", command);
#endif /* PAKFIRE_DEBUG_PARSER */
// Update argv
r = pakfire_jail_run(parser->pakfire, argv, 0, &output, &length);
if (r) {
// Just log this and continue
- DEBUG(parser->pakfire, "Command '%s' failed with return code %d\n", command, r);
+ CTX_DEBUG(parser->ctx, "Command '%s' failed with return code %d\n", command, r);
}
// Strip newline from output
// End loop when we have expanded all variables
if (r == PCRE2_ERROR_NOMATCH) {
- DEBUG(parser->pakfire, "No (more) matches found in: %s\n", *buffer);
+ CTX_DEBUG(parser->ctx, "No (more) matches found in: %s\n", *buffer);
r = 0;
break;
}
goto ERROR;
#ifdef PAKFIRE_DEBUG_PARSER
- DEBUG(parser->pakfire, "Expanding variable: %s\n", variable);
+ CTX_DEBUG(parser->ctx, "Expanding variable: %s\n", variable);
#endif /* PAKFIRE_DEBUG_PARSER */
// Search for a declaration of this variable
// Is this a recursive pattern?
if (repl && pakfire_string_matches(repl, (const char*)pattern)) {
- DEBUG(parser->pakfire, "Recursion detected in %s\n", pattern);
+ CTX_DEBUG(parser->ctx, "Recursion detected in %s\n", pattern);
// Move up one step and lookup there
if (namespace && *namespace) {
#ifdef PAKFIRE_DEBUG_PARSER
// What is its value?
if (repl) {
- DEBUG(parser->pakfire, "Replacing %%{%s} with '%s'\n", variable, repl);
+ CTX_DEBUG(parser->ctx, "Replacing %%{%s} with '%s'\n", variable, repl);
} else {
- DEBUG(parser->pakfire, "Replacing %%{%s} with an empty string\n", variable);
+ CTX_DEBUG(parser->ctx, "Replacing %%{%s} with an empty string\n", variable);
}
#endif /* PAKFIRE_DEBUG_PARSER */
// Compile all regular expressions
int r = pakfire_parser_compile_regexes(parser);
if (r) {
- DEBUG(parser->pakfire, "Could not compile regular expressions: %m\n");
+ CTX_DEBUG(parser->ctx, "Could not compile regular expressions: %m\n");
goto ERROR;
}
// Expand all variables
r = pakfire_parser_expand_variables(parser, namespace, &buffer);
if (r) {
- DEBUG(parser->pakfire, "Failed to expand variables in '%s': %m\n", value);
+ CTX_DEBUG(parser->ctx, "Failed to expand variables in '%s': %m\n", value);
goto ERROR;
}
if (parser->flags & PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS) {
r = pakfire_parser_expand_commands(parser, &buffer);
if (r) {
- DEBUG(parser->pakfire, "Failed to expand commands in '%s': %m\n", value);
+ CTX_DEBUG(parser->ctx, "Failed to expand commands in '%s': %m\n", value);
goto ERROR;
}
}
// Check for any errors
else if (r > 0) {
- ERROR(parser->pakfire, "fnmatch failed: %m\n");
+ CTX_ERROR(parser->ctx, "fnmatch failed: %m\n");
if (namespaces)
free(namespaces);
char* value = NULL;
int r;
- DEBUG(parser1->pakfire, "Merging parsers %p and %p\n", parser1, parser2);
+ CTX_DEBUG(parser1->ctx, "Merging parsers %p and %p\n", parser1, parser2);
if (!parser2) {
errno = EINVAL;
int pakfire_parser_read_file(struct pakfire_parser* parser, const char* path,
struct pakfire_parser_error** error) {
- DEBUG(parser->pakfire, "Parsing %s...\n", path);
+ CTX_DEBUG(parser->ctx, "Parsing %s...\n", path);
FILE* f = fopen(path, "r");
if (!f)
else
parser->namespace = NULL;
- DEBUG(parser->pakfire, "%p: Set namespace to: %s\n", parser, parser->namespace);
+ CTX_DEBUG(parser->ctx, "%p: Set namespace to: %s\n", parser, parser->namespace);
return 0;
}
char* deps = NULL;
char* build_arches = NULL;
- DEBUG(parser->pakfire, "Building package from namespace '%s'\n", namespace);
+ CTX_DEBUG(parser->ctx, "Building package from namespace '%s'\n", namespace);
// Fetch name
name = pakfire_parser_get(parser, namespace, "name");
if (!name || !*name) {
- ERROR(parser->pakfire, "Name is empty\n");
+ CTX_ERROR(parser->ctx, "Name is empty\n");
goto CLEANUP;
}
// Fetch EVR
evr = pakfire_parser_get(parser, namespace, "evr");
if (!evr || !*evr) {
- ERROR(parser->pakfire, "EVR is empty\n");
+ CTX_ERROR(parser->ctx, "EVR is empty\n");
goto CLEANUP;
}
if (!arch)
goto CLEANUP;
} else {
- ERROR(parser->pakfire, "Arch is empty\n");
+ CTX_ERROR(parser->ctx, "Arch is empty\n");
goto CLEANUP;
}
}
// Create a new package object
r = pakfire_package_create(pkg, parser->pakfire, repo, name, evr, arch);
if (r) {
- ERROR(parser->pakfire, "Could not create package: %m\n");
+ CTX_ERROR(parser->ctx, "Could not create package: %m\n");
goto CLEANUP;
}
// Assign a new UUID to this package
char* uuid = pakfire_generate_uuid();
if (!uuid) {
- ERROR(parser->pakfire, "Generating a UUID failed: %m\n");
+ CTX_ERROR(parser->ctx, "Generating a UUID failed: %m\n");
goto CLEANUP;
}
free(value);
if (r) {
- ERROR(parser->pakfire, "Could not set %s: %m\n", a->name);
+ CTX_ERROR(parser->ctx, "Could not set %s: %m\n", a->name);
goto CLEANUP;
}
}
CLEANUP:
if (r)
- ERROR(parser->pakfire, "Could not create package: %m\n");
+ CTX_ERROR(parser->ctx, "Could not create package: %m\n");
if (name)
free(name);
}
static void pakfire_parser_error_free(struct pakfire_parser_error* error) {
- pakfire_parser_unref(error->parser);
-
+ if (error->parser)
+ pakfire_parser_unref(error->parser);
if (error->filename)
free(error->filename);
-
if (error->message)
free(error->message);
-
free(error);
}
return error;
pakfire_parser_error_free(error);
-
return NULL;
}
%parse-param
{yyscan_t* scanner}
+ {struct pakfire_ctx* ctx}
{struct pakfire* pakfire}
{struct pakfire_parser** parser}
{struct pakfire_parser* parent}
#include <stdlib.h>
#include <time.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
#include <pakfire/constants.h>
#include <pakfire/logging.h>
#include <pakfire/pakfire.h>
OP_EQUALS = 0,
};
-static void yyerror(yyscan_t* scanner, struct pakfire* pakfire, struct pakfire_parser** parser,
- struct pakfire_parser* parent, struct pakfire_parser_error** error, const char* s) {
+static void yyerror(yyscan_t* scanner, struct pakfire_ctx* ctx, struct pakfire* pakfire,
+ struct pakfire_parser** parser, struct pakfire_parser* parent,
+ struct pakfire_parser_error** error, const char* s) {
const struct pakfire_parser_state* state = yyget_extra(scanner);
- ERROR(pakfire, "Error (line %u): %s\n", state->lineno, s);
+ CTX_ERROR(ctx, "Error (line %u): %s\n", state->lineno, s);
// Create a new error object
if (error) {
int r = pakfire_parser_error_create(error, *parser, NULL, state->lineno, s);
if (r) {
- ERROR(pakfire, "Could not create error object: %s\n", strerror(errno));
+ CTX_ERROR(ctx, "Could not create error object: %s\n", strerror(errno));
}
}
}
-static struct pakfire_parser* make_if_stmt(struct pakfire* pakfire, const enum operator op,
+static struct pakfire_parser* make_if_stmt(struct pakfire_ctx* ctx, const enum operator op,
const char* val1, const char* val2, struct pakfire_parser* if_block, struct pakfire_parser* else_block);
static int pakfire_parser_new_declaration(
if_stmt : T_IF T_STRING T_EQUALS T_STRING T_EOL block else_stmt T_END T_EOL
{
- $$ = make_if_stmt(pakfire, OP_EQUALS, $2, $4, $6, $7);
+ $$ = make_if_stmt(ctx, OP_EQUALS, $2, $4, $6, $7);
if ($6)
pakfire_parser_unref($6);
.readline_indent = 0,
};
+ // Fetch context
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
#ifdef ENABLE_DEBUG
- DEBUG(pakfire, "Parsing the following data (%zu):\n%.*s\n",
- len, (int)len, data);
+ CTX_DEBUG(ctx, "Parsing the following data (%zu):\n%.*s\n", len, (int)len, data);
// Save start time
clock_t t_start = clock();
struct pakfire_parser* parser = NULL;
YY_BUFFER_STATE buffer = yy_scan_bytes(data, len, scanner);
- int r = yyparse(scanner, pakfire, &parser, parent, error);
+ int r = yyparse(scanner, ctx, pakfire, &parser, parent, error);
yy_delete_buffer(buffer, scanner);
// If everything was parsed successfully, we merge the sub-parser into
// Log what we have in the parent parser now
dump = pakfire_parser_dump(parent);
if (dump)
- DEBUG(pakfire, "Status of the parser %p:\n%s\n", parent, dump);
+ CTX_DEBUG(ctx, "Status of the parser %p:\n%s\n", parent, dump);
// Log time we needed to parse data
- DEBUG(pakfire, "Parser finished in %.4fms\n",
+ CTX_DEBUG(ctx, "Parser finished in %.4fms\n",
(double)(t_end - t_start) * 1000 / CLOCKS_PER_SEC);
#endif
// Cleanup
if (dump)
free(dump);
- pakfire_unref(pakfire);
+ if (pakfire)
+ pakfire_unref(pakfire);
+ if (ctx)
+ pakfire_ctx_unref(ctx);
yylex_destroy(scanner);
return r;
}
-static struct pakfire_parser* make_if_stmt(struct pakfire* pakfire, const enum operator op,
+static struct pakfire_parser* make_if_stmt(struct pakfire_ctx* ctx, const enum operator op,
const char* val1, const char* val2, struct pakfire_parser* if_block, struct pakfire_parser* else_block) {
switch (op) {
case OP_EQUALS:
- DEBUG(pakfire, "Evaluating if statement: %s == %s?\n", val1, val2);
+ CTX_DEBUG(ctx, "Evaluating if statement: %s == %s?\n", val1, val2);
break;
}
struct pakfire_parser* parent = pakfire_parser_get_parent(if_block);
- DEBUG(pakfire, " parent = %p, if = %p, else = %p\n", parent, if_block, else_block);
+ CTX_DEBUG(ctx, " parent = %p, if = %p, else = %p\n", parent, if_block, else_block);
// Expand values
char* v1 = pakfire_parser_expand(parent, NULL, val1);
switch (op) {
case OP_EQUALS:
- DEBUG(pakfire, " '%s' == '%s'?\n", v1, v2);
+ CTX_DEBUG(ctx, " '%s' == '%s'?\n", v1, v2);
if (strcmp(v1, v2) == 0)
result = if_block;