Pino Toscano
2017-Feb-23 17:55 UTC
[Libguestfs] [PATCH 1/3] inspect: add source and summary to internal add_application
This way source and summary can be specified for any package read from the guest. --- lib/inspect-apps.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c index 1216c52..eabe565 100644 --- a/lib/inspect-apps.c +++ b/lib/inspect-apps.c @@ -51,7 +51,7 @@ static struct guestfs_application2_list *list_applications_deb (guestfs_h *g, st static struct guestfs_application2_list *list_applications_pacman (guestfs_h *g, struct inspect_fs *fs); static struct guestfs_application2_list *list_applications_apk (guestfs_h *g, struct inspect_fs *fs); static struct guestfs_application2_list *list_applications_windows (guestfs_h *g, struct inspect_fs *fs); -static void add_application (guestfs_h *g, struct guestfs_application2_list *, const char *name, const char *display_name, int32_t epoch, const char *version, const char *release, const char *arch, const char *install_path, const char *publisher, const char *url, const char *description); +static void add_application (guestfs_h *g, struct guestfs_application2_list *, const char *name, const char *display_name, int32_t epoch, const char *version, const char *release, const char *arch, const char *install_path, const char *publisher, const char *url, const char *source, const char *summary, const char *description); static void sort_applications (struct guestfs_application2_list *); /* The deprecated guestfs_inspect_list_applications call, which is now @@ -369,7 +369,7 @@ read_package (guestfs_h *g, /* Add the application and what we know. */ if (version && release) add_application (g, data->apps, entry->name, "", epoch, version, release, - arch ? arch : "", "", "", "", ""); + arch ? arch : "", "", "", "", "", "", ""); return 0; } @@ -504,7 +504,7 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs) else if (STREQ (line, "")) { if (installed_flag && name && version && (epoch >= 0)) add_application (g, apps, name, "", epoch, version, release ? : "", - arch ? : "", "", "", "", ""); + arch ? : "", "", "", "", "", "", ""); free (name); free (version); free (release); @@ -634,7 +634,7 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs) if ((epoch >= 0) && (ver[0] != '\0') && (rel[0] != '\0')) add_application (g, apps, name, "", epoch, ver, rel, arch, "", "", - url ? : "", desc ? : ""); + url ? : "", "", "", desc ? : ""); after_add_application: key = NULL; @@ -708,7 +708,8 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs) case '\0': if (name && version && (epoch >= 0)) add_application (g, apps, name, "", epoch, version, release ? : "", - arch ? : "", "", "", url ? : "", description ? : ""); + arch ? : "", "", "", url ? : "", "", "", + description ? : ""); free (name); free (version); free (release); @@ -880,6 +881,7 @@ list_applications_windows_from_path (guestfs_h *g, install_path ? : "", publisher ? : "", url ? : "", + "", "", comments ? : ""); } } @@ -892,6 +894,7 @@ add_application (guestfs_h *g, struct guestfs_application2_list *apps, const char *version, const char *release, const char *arch, const char *install_path, const char *publisher, const char *url, + const char *source, const char *summary, const char *description) { apps->len++; @@ -911,8 +914,8 @@ add_application (guestfs_h *g, struct guestfs_application2_list *apps, /* XXX The next two are not yet implemented for any package * format, but we could easily support them for rpm and deb. */ - apps->val[apps->len-1].app2_source_package = safe_strdup (g, ""); - apps->val[apps->len-1].app2_summary = safe_strdup (g, ""); + apps->val[apps->len-1].app2_source_package = safe_strdup (g, source); + apps->val[apps->len-1].app2_summary = safe_strdup (g, summary); apps->val[apps->len-1].app2_description = safe_strdup (g, description); /* XXX Reserved for future use. */ apps->val[apps->len-1].app2_spare1 = safe_strdup (g, ""); -- 2.9.3
Pino Toscano
2017-Feb-23 17:55 UTC
[Libguestfs] [PATCH 2/3] inspect: read more fields for Debian packages
In particular, read the URL, the source name, and both the summary and the description. For the long description, add a small system to read continuation lines. --- lib/inspect-apps.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c index eabe565..b7adaa2 100644 --- a/lib/inspect-apps.c +++ b/lib/inspect-apps.c @@ -437,7 +437,11 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs) size_t len; int32_t epoch = 0; CLEANUP_FREE char *name = NULL, *version = NULL, *release = NULL, *arch = NULL; + CLEANUP_FREE char *url = NULL, *source = NULL, *summary = NULL; + CLEANUP_FREE char *description = NULL; int installed_flag = 0; + char **continuation_field = NULL; + size_t continuation_field_len = 0; status = guestfs_int_download_to_tmp (g, fs, "/var/lib/dpkg/status", "status", MAX_PKG_DB_SIZE); @@ -457,10 +461,6 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs) /* Read the temporary file. Each package entry is separated by * a blank line. - * XXX Strictly speaking this is in mailbox header format, so it - * would be possible for fields to spread across multiple lines, - * although for the short fields that we are concerned about this is - * unlikely and not seen in practice. */ while (fgets (line, sizeof line, fp) != NULL) { len = strlen (line); @@ -469,6 +469,35 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs) len--; } + /* Handling of continuation lines, which must be done before + * checking for other headers. + */ + if (line[0] == ' ' && continuation_field) { + /* This is a continuation line, and this is the first line of + * the field. + */ + if (*continuation_field == NULL) { + *continuation_field = safe_strdup (g, &line[1]); + continuation_field_len = len - 1; + } + else { + /* Not the first line, so append to the existing buffer + * (with a new line before). + */ + size_t new_len = continuation_field_len + 1 + (len - 1); + *continuation_field = safe_realloc (g, *continuation_field, + new_len + 1); + (*continuation_field)[continuation_field_len] = '\n'; + strcpy (*continuation_field + continuation_field_len + 1, &line[1]); + continuation_field_len = new_len; + } + } + else { + /* Not a continuation line, or not interested in it -- reset. */ + continuation_field = NULL; + continuation_field = 0; + } + if (STRPREFIX (line, "Package: ")) { free (name); name = safe_strdup (g, &line[9]); @@ -501,15 +530,39 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs) free (arch); arch = safe_strdup (g, &line[14]); } + else if (STRPREFIX (line, "Homepage: ")) { + free (url); + url = safe_strdup (g, &line[10]); + } + else if (STRPREFIX (line, "Source: ")) { + /* A 'Source' entry may be both 'foo' and 'foo (1.0)', so make sure + * to read only the name in the latter case. + */ + char *space_pos = strchr (&line[8], ' '); + if (space_pos) + *space_pos = '\0'; + free (source); + source = safe_strdup (g, &line[8]); + } + else if (STRPREFIX (line, "Description: ")) { + free (summary); + summary = safe_strdup (g, &line[13]); + continuation_field = &description; + } else if (STREQ (line, "")) { if (installed_flag && name && version && (epoch >= 0)) add_application (g, apps, name, "", epoch, version, release ? : "", - arch ? : "", "", "", "", "", "", ""); + arch ? : "", "", "", url ? : "", source ? : "", + summary ? : "", description ? : ""); free (name); free (version); free (release); free (arch); - name = version = release = arch = NULL; + free (url); + free (source); + free (summary); + free (description); + name = version = release = arch = url = source = summary = description = NULL; installed_flag = 0; } } -- 2.9.3
Pino Toscano
2017-Feb-23 17:55 UTC
[Libguestfs] [PATCH 3/3] inspect: read more fields for RPM packages
In particular, read the URL, and both the summary and the description. --- lib/inspect-apps.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c index b7adaa2..c324f3b 100644 --- a/lib/inspect-apps.c +++ b/lib/inspect-apps.c @@ -257,6 +257,9 @@ read_rpm_name (guestfs_h *g, #define RPMTAG_RELEASE 1002 #define RPMTAG_EPOCH 1003 #define RPMTAG_ARCH 1022 +#define RPMTAG_URL 1020 +#define RPMTAG_SUMMARY 1004 +#define RPMTAG_DESCRIPTION 1005 static char * get_rpm_header_tag (guestfs_h *g, const unsigned char *header_start, @@ -329,7 +332,8 @@ read_package (guestfs_h *g, struct read_package_data *data = datav; struct rpm_name nkey, *entry; CLEANUP_FREE char *version = NULL, *release = NULL, - *epoch_str = NULL, *arch = NULL; + *epoch_str = NULL, *arch = NULL, *url = NULL, *summary = NULL, + *description = NULL; int32_t epoch; /* This function reads one (key, value) pair from the Packages @@ -359,6 +363,9 @@ read_package (guestfs_h *g, release = get_rpm_header_tag (g, value, valuelen, RPMTAG_RELEASE, 's'); epoch_str = get_rpm_header_tag (g, value, valuelen, RPMTAG_EPOCH, 'i'); arch = get_rpm_header_tag (g, value, valuelen, RPMTAG_ARCH, 's'); + url = get_rpm_header_tag (g, value, valuelen, RPMTAG_URL, 's'); + summary = get_rpm_header_tag (g, value, valuelen, RPMTAG_SUMMARY, 's'); + description = get_rpm_header_tag (g, value, valuelen, RPMTAG_DESCRIPTION, 's'); /* The epoch is stored as big-endian integer. */ if (epoch_str) @@ -369,7 +376,8 @@ read_package (guestfs_h *g, /* Add the application and what we know. */ if (version && release) add_application (g, data->apps, entry->name, "", epoch, version, release, - arch ? arch : "", "", "", "", "", "", ""); + arch ? arch : "", "", "", url ? : "", "", + summary ? : "", description ? : ""); return 0; } -- 2.9.3
Seemingly Similar Threads
- [PATCH v2 1/3] inspect: add source and summary to internal add_application
- [PATCH v2 0/2] inspect: basic UTF-8 encoding for rpm
- [PATCH v3 0/2] inspect: basic UTF-8 encoding for rpm
- [PATCH for discussion] lib: update inspect_list_applications to return app_arch
- [PATCH 0/2] New inspect_list_applications2 API