return d;
}
+static int pakfire_parser_command_logger(Pakfire pakfire, void* data,
+ int priority, const char* line) {
+ char** output = (char**)data;
+
+ // Append output
+ asprintf(output, "%s%s", (output && *output) ? *output : "", line);
+
+ return 0;
+}
+
static int pakfire_parser_expand_commands(PakfireParser parser, char** buffer) {
int r = 0;
PCRE2_UCHAR* command = NULL;
argv[2] = (const char*)command;
// The output of the command
- const char* output = "XXX";
+ char* output = NULL;
// Execute the command inside the Pakfire environment
- r = pakfire_execute(parser->pakfire, argv, NULL, 0, NULL, NULL);
+ r = pakfire_execute(parser->pakfire, argv, NULL, 0,
+ pakfire_parser_command_logger, &output);
if (r) {
// Just log this and continue
DEBUG(parser->pakfire, "Command '%s' failed with return code %d\n", command, r);
}
+ // Strip newline from output
+ if (output)
+ pakfire_remove_trailing_newline(output);
+
// Find the entire matched pattern
r = pcre2_substring_get_bynumber(match, 0, &pattern, &pattern_length);
- if (r)
+ if (r) {
+ if (output)
+ free(output);
+
goto ERROR;
+ }
// Replace all occurrences
char* tmp = pakfire_string_replace(*buffer, (const char*)pattern, output);
- if (!tmp)
+ if (!tmp) {
+ if (output)
+ free(output);
+
goto ERROR;
+ }
// Replace buffer
free(*buffer);
pcre2_substring_free(pattern);
pattern = NULL;
+
+ if (output)
+ free(output);
}
ERROR: