|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
Copyright (C) 2014 ABRT team
|
|
Packit Service |
779887 |
Copyright (C) 2014 RedHat Inc
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
779887 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
779887 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
779887 |
(at your option) any later version.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
779887 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
779887 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
779887 |
GNU General Public License for more details.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
You should have received a copy of the GNU General Public License along
|
|
Packit Service |
779887 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit Service |
779887 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
@brief API for formating of problem data
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
These functions can be used to convert a problem data to its string
|
|
Packit Service |
779887 |
representation.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
The output format can be parsed from a string:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
problem_formatter_t *formatter = problem_formatter_new();
|
|
Packit Service |
779887 |
problem_formatter_load_string(formatter, MY_FORMAT_STRING);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
or loaded from a file:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
problem_formatter_t *formatter = problem_formatter_new();
|
|
Packit Service |
779887 |
problem_formatter_load_file(formatter, MY_FORMAT_FILE);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
Once you have configured your formatter you can convert problem_data to
|
|
Packit Service |
779887 |
problem_report by calling:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
problem_report_t *report;
|
|
Packit Service |
779887 |
if (problem_formatter_generate_report(formatter, data, &report) != 0)
|
|
Packit Service |
779887 |
errx(EXIT_FAILURE, "Problem data cannot be converted to problem report.");
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
Now you can print the report:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
printf("Problem: %s\n", problem_report_get_summary());
|
|
Packit Service |
779887 |
printf("%s\n", problem_report_get_description());
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
puts("Problem attachments:");
|
|
Packit Service |
779887 |
for (GList *a = problem_report_get_attachments(pr); a != NULL; a = g_list_next(a))
|
|
Packit Service |
779887 |
printf(" %s\n", a->data);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
Format description:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
----
|
|
Packit Service |
779887 |
%summary:: summary format
|
|
Packit Service |
779887 |
%attach:: elemnt1[,element2]...
|
|
Packit Service |
779887 |
section:: element1[,element2]...
|
|
Packit Service |
779887 |
The literal text line to be added to report.
|
|
Packit Service |
779887 |
----
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
Summary format is a line of text, where %element% is replaced by
|
|
Packit Service |
779887 |
text element's content, and [[...%element%...]] block is used only if
|
|
Packit Service |
779887 |
%element% exists. [[...]] blocks can nest.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
Sections can be:
|
|
Packit Service |
779887 |
- %summary: bug summary format string.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- %attach: a list of elements to attach.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- text, double colon (::) and the list of comma-separated elements.
|
|
Packit Service |
779887 |
Text can be empty (":: elem1, elem2, elem3" works),
|
|
Packit Service |
779887 |
in this case "Text:" header line will be omitted.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- %description: this section is implicit and contains all text
|
|
Packit Service |
779887 |
sections unless another section was specified (%summary and %attach
|
|
Packit Service |
779887 |
are ignored when determining text section's placement)
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- every text element belongs to the last specified section (%summary
|
|
Packit Service |
779887 |
and %attach sections are ignored). If no section was specified,
|
|
Packit Service |
779887 |
the text element belogns to %description.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- If none of elements exists, the section will not be created.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- Empty lines are NOT ignored.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
Elements can be:
|
|
Packit Service |
779887 |
- problem directory element names, which get formatted as
|
|
Packit Service |
779887 |
<element_name>: <contents>
|
|
Packit Service |
779887 |
or
|
|
Packit Service |
779887 |
<element_name>:
|
|
Packit Service |
779887 |
:<contents>
|
|
Packit Service |
779887 |
:<contents>
|
|
Packit Service |
779887 |
:<contents>
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- problem directory element names prefixed by "%bare_",
|
|
Packit Service |
779887 |
which is formatted as-is, without "<element_name>:" and colons
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- %oneline, %multiline, %text wildcards, which select all corresponding
|
|
Packit Service |
779887 |
elements for output or attachment
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- %binary wildcard, valid only for %attach section, instructs to attach
|
|
Packit Service |
779887 |
binary elements
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- %short_backtrace is a reserved element that is replaced with contents
|
|
Packit Service |
779887 |
of backtrace file truncated to optimal number of frames
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- %reporter is a reserved element that is replaced by name and version
|
|
Packit Service |
779887 |
of the software that created the report
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- problem directory element names prefixed by "-",
|
|
Packit Service |
779887 |
which excludes given element from all wildcards
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
- Nonexistent elements are silently ignored.
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
You can add your own section:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
problem_formatter_t *formatter = problem_formatter_new();
|
|
Packit Service |
779887 |
problem_formatter_add_section(formatter, "additional_info", PFFF_REQUIRED);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
and then you can use the section in the formatting string:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
problem_formatter_load_string(formatter,
|
|
Packit Service |
779887 |
"::comment\n"
|
|
Packit Service |
779887 |
"%additional_info:: maps");
|
|
Packit Service |
779887 |
problem_formatter_generate_report(formatter, data, &report);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
printf("Problem: %s\n", problem_report_get_summary());
|
|
Packit Service |
779887 |
printf("%s\n", problem_report_get_description());
|
|
Packit Service |
779887 |
printf("Additional info: %s\n", problem_report_get_section(report, "additiona_info"));
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
The lines above are equivalent to the following lines:
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
printf("Problem: %s\n", problem_data_get_content_or_NULL(data, "reason"));
|
|
Packit Service |
779887 |
printf("%s\n", problem_data_get_content_or_NULL(data, "comment"));
|
|
Packit Service |
779887 |
printf("Additional info: %s\n", problem_data_get_content_or_NULL(data, "maps"));
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
#ifndef LIBREPORT_PROBLEM_REPORT_H
|
|
Packit Service |
779887 |
#define LIBREPORT_PROBLEM_REPORT_H
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#include <glib.h>
|
|
Packit Service |
779887 |
#include <stdio.h>
|
|
Packit Service |
779887 |
#include "problem_data.h"
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#ifdef __cplusplus
|
|
Packit Service |
779887 |
extern "C" {
|
|
Packit Service |
779887 |
#endif
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#define PR_SEC_SUMMARY "summary"
|
|
Packit Service |
779887 |
#define PR_SEC_DESCRIPTION "description"
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* The problem report structure represents a problem data formatted according
|
|
Packit Service |
779887 |
* to a format string.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* A problem report is composed of well-known sections:
|
|
Packit Service |
779887 |
* - summary
|
|
Packit Service |
779887 |
* - descritpion
|
|
Packit Service |
779887 |
* - attach
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* and custom sections accessed by:
|
|
Packit Service |
779887 |
* problem_report_get_section();
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
struct problem_report;
|
|
Packit Service |
779887 |
typedef struct problem_report problem_report_t;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* The problem report settings structure contains advance settings
|
|
Packit Service |
779887 |
* for report generating
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
struct problem_report_settings
|
|
Packit Service |
779887 |
{
|
|
Packit Service |
779887 |
int prs_shortbt_max_frames; ///< generate only max top frames in %short_backtrace
|
|
Packit Service |
779887 |
size_t prs_shortbt_max_text_size; ///< short bt only if it is bigger then this
|
|
Packit Service |
779887 |
};
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
typedef struct problem_report_settings problem_report_settings_t;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Helpers for easily switching between FILE and struct strbuf
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Type of buffer used by Problem report
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
typedef FILE problem_report_buffer;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Wrapper for the proble buffer's formated output function.
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
#define problem_report_buffer_printf(buf, fmt, ...)\
|
|
Packit Service |
779887 |
fprintf((buf), (fmt), ##__VA_ARGS__)
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Get a section buffer
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* Use this function if you need to amend something to a formatted section.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem report
|
|
Packit Service |
779887 |
* @param section_name Name of required section
|
|
Packit Service |
779887 |
* @return Always valid pointer to a section buffer
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
problem_report_buffer *problem_report_get_buffer(const problem_report_t *self,
|
|
Packit Service |
779887 |
const char *section_name);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Get Summary string
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* The returned pointer is valid as long as you perform no further output to
|
|
Packit Service |
779887 |
* the summary buffer.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem report
|
|
Packit Service |
779887 |
* @return Non-NULL pointer to summary data
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
const char *problem_report_get_summary(const problem_report_t *self);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Get Description string
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* The returned pointer is valid as long as you perform no further output to
|
|
Packit Service |
779887 |
* the description buffer.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem report
|
|
Packit Service |
779887 |
* @return Non-NULL pointer to description data
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
const char *problem_report_get_description(const problem_report_t *self);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Get Section's string
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* The returned pointer is valid as long as you perform no further output to
|
|
Packit Service |
779887 |
* the section's buffer.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem report
|
|
Packit Service |
779887 |
* @param section_name Name of the required section
|
|
Packit Service |
779887 |
* @return Non-NULL pointer to description data
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
const char *problem_report_get_section(const problem_report_t *self,
|
|
Packit Service |
779887 |
const char *section_name);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Get GList of the problem data items that are to be attached
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem report
|
|
Packit Service |
779887 |
* @return A pointer to GList (NULL means empty list)
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
GList *problem_report_get_attachments(const problem_report_t *self);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Releases all resources allocated by a problem report
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem report
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
void problem_report_free(problem_report_t *self);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* An enum of Extra section flags
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
enum problem_formatter_section_flags {
|
|
Packit Service |
779887 |
PFFF_REQUIRED = 1 << 0, ///< section must be present in the format spec
|
|
Packit Service |
779887 |
};
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* The problem formatter structure formats a problem data according to a format
|
|
Packit Service |
779887 |
* string and stores result a problem report.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* The problem formatter uses '%reason%' as %summary section format string, if
|
|
Packit Service |
779887 |
* %summary is not provided by a format string.
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
struct problem_formatter;
|
|
Packit Service |
779887 |
typedef struct problem_formatter problem_formatter_t;
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Constructs a new problem formatter.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @return Non-NULL pointer to the new problem formatter
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
problem_formatter_t *problem_formatter_new(void);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Releases all resources allocated by a problem formatter
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
void problem_formatter_free(problem_formatter_t *self);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Adds a new recognized section
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* The problem formatter ignores a section in the format spec if the section is
|
|
Packit Service |
779887 |
* not one of the default nor added by this function.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* How the problem formatter handles these extra sections:
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* A custom section is something like %description section. %description is the
|
|
Packit Service |
779887 |
* default section where all text (sub)sections are stored. If the formatter
|
|
Packit Service |
779887 |
* finds the custom section in format string, then starts storing text
|
|
Packit Service |
779887 |
* (sub)sections in the custom section.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* (%description) |:: comment
|
|
Packit Service |
779887 |
* (%description) |
|
|
Packit Service |
779887 |
* (%description) |Package:: package
|
|
Packit Service |
779887 |
* (%description) |
|
|
Packit Service |
779887 |
* (%additiona_info) |%additional_info::
|
|
Packit Service |
779887 |
* (%additiona_info) |%reporter%
|
|
Packit Service |
779887 |
* (%additiona_info) |User:: user_name,uid
|
|
Packit Service |
779887 |
* (%additiona_info) |
|
|
Packit Service |
779887 |
* (%additiona_info) |Directories:: root,cwd
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
* @param name Name of the added section
|
|
Packit Service |
779887 |
* @param flags Info about the added section
|
|
Packit Service |
779887 |
* @return Zero on success. -EEXIST if the name is already known by the formatter
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
int problem_formatter_add_section(problem_formatter_t *self, const char *name, int flags);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Loads a problem format from a string.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
* @param fmt Format
|
|
Packit Service |
779887 |
* @return Zero on success or number of warnings (e.g. missing section,
|
|
Packit Service |
779887 |
* unrecognized section).
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
int problem_formatter_load_string(problem_formatter_t* self, const char *fmt);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Loads a problem format from a file.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
* @param pat Path to the format file
|
|
Packit Service |
779887 |
* @return Zero on success or number of warnings (e.g. missing section,
|
|
Packit Service |
779887 |
* unrecognized section).
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
int problem_formatter_load_file(problem_formatter_t* self, const char *path);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Creates a new problem report, formats the data according to the loaded
|
|
Packit Service |
779887 |
* format string and stores output in the report.
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
* @param data Problem data to format
|
|
Packit Service |
779887 |
* @param report Pointer where the created problem report is to be stored
|
|
Packit Service |
779887 |
* @return Zero on success, otherwise non-zero value.
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
int problem_formatter_generate_report(const problem_formatter_t *self, problem_data_t *data, problem_report_t **report);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Returns problem report settings from given formatter
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
* @return problem report settings
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
problem_report_settings_t problem_formatter_get_settings(const problem_formatter_t *self);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
/*
|
|
Packit Service |
779887 |
* Sets problem report settings to given formatter
|
|
Packit Service |
779887 |
*
|
|
Packit Service |
779887 |
* @param self Problem formatter
|
|
Packit Service |
779887 |
* @param settings Problem report settings
|
|
Packit Service |
779887 |
*/
|
|
Packit Service |
779887 |
void problem_formatter_set_settings(problem_formatter_t *self, problem_report_settings_t settings);
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#ifdef __cplusplus
|
|
Packit Service |
779887 |
}
|
|
Packit Service |
779887 |
#endif
|
|
Packit Service |
779887 |
|
|
Packit Service |
779887 |
#endif // LIBREPORT_PROBLEM_REPORT_H
|