Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
More fixes to libpkg.
Vsevolod Stakhov committed 10 years ago
commit ef497f0e0a173138b89009c196a301744b57e18b
parent 0bcc13c
6 files changed +29 -19
modified libpkg/pkg.c
@@ -1735,7 +1735,7 @@ int
pkg_message_from_str(struct pkg *pkg, const char *str, size_t len)
{
	struct ucl_parser *parser;
-
	struct ucl_object *obj;
+
	ucl_object_t *obj;
	int ret = EPKG_FATAL;

	assert(str != NULL);
@@ -1761,17 +1761,13 @@ pkg_message_from_str(struct pkg *pkg, const char *str, size_t len)
	return (ret);
}

-
char*
-
pkg_message_to_str(struct pkg *pkg)
+
ucl_object_t*
+
pkg_message_to_ucl(struct pkg *pkg)
{
	ucl_object_t *obj;
-
	char *ret = NULL;
-

-
	if (pkg->message == NULL) {
-
		return (NULL);
-
	}

	obj = ucl_object_typed_new (UCL_OBJECT);
+

	ucl_object_insert_key(obj, ucl_object_fromstring(pkg->message->str),
			"message", 0, false);

@@ -1786,7 +1782,22 @@ pkg_message_to_str(struct pkg *pkg)
				"minimum_version", 0, false);
	}

+
	return (obj);
+
}
+

+
char*
+
pkg_message_to_str(struct pkg *pkg)
+
{
+
	ucl_object_t *obj;
+
	char *ret = NULL;
+

+
	if (pkg->message == NULL) {
+
		return (NULL);
+
	}
+

+
	obj = pkg_message_to_ucl(pkg);
	ret = ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
+
	ucl_object_unref(obj);

	return (ret);
}
modified libpkg/pkg_create.c
@@ -287,10 +287,9 @@ static int
pkg_load_message_from_file(int fd, struct pkg *pkg, const char *path, bool is_ucl)
{
	char *buf = NULL;
-
	char *cp;
	off_t size = 0;
	int ret;
-
	struct ucl_object *obj;
+
	ucl_object_t *obj;

	assert(pkg != NULL);
	assert(path != NULL);
modified libpkg/pkg_event.c
@@ -158,7 +158,9 @@ pipeevent(struct pkg_event *ev)
		    "}}",
		    ev->e_install_finished.pkg,
		    ev->e_install_finished.pkg,
-
		    sbuf_json_escape(buf, ev->e_install_finished.pkg->message));
+
			ev->e_install_finished.pkg->message ?
+
				sbuf_json_escape(buf, ev->e_install_finished.pkg->message->str) :
+
				"");
		break;
	case PKG_EVENT_INTEGRITYCHECK_BEGIN:
		sbuf_printf(msg, "{ \"type\": \"INFO_INTEGRITYCHECK_BEGIN\", "
modified libpkg/pkg_manifest.c
@@ -303,10 +303,8 @@ pkg_string(struct pkg *pkg, const ucl_object_t *obj, int attr)
		pkg->maintainer = strdup(str);
		break;
	case PKG_MESSAGE:
-
		urldecode(str, &buf);
-
		sbuf_finish(buf);
-
		pkg->message = strdup(sbuf_data(buf));
-
		sbuf_delete(buf);
+
		/* Should no longer be handled here */
+
		assert(0);
		break;
	case PKG_NAME:
		pkg->name = strdup(str);
@@ -1219,9 +1217,8 @@ pkg_emit_object(struct pkg *pkg, short flags)

	pkg_debug(4, "Emitting message");
	if (pkg->message != NULL) {
-
		urlencode(pkg->message, &tmpsbuf);
		ucl_object_insert_key(top,
-
		    ucl_object_fromstring_common(sbuf_data(tmpsbuf), sbuf_len(tmpsbuf), UCL_STRING_TRIM),
+
			pkg_message_to_ucl(pkg),
		    "message", 7, false);
	}

modified libpkg/pkgdb_iterator.c
@@ -776,8 +776,8 @@ pkgdb_load_requires(sqlite3 *sqlite, struct pkg *pkg)
static void
populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
	int		 icol = 0;
-
	const char	*colname;
-
	char		 legacyarch[BUFSIZ], *msg;
+
	const char	*colname, *msg;
+
	char		 legacyarch[BUFSIZ];

	assert(stmt != NULL);

modified libpkg/private/pkg.h
@@ -734,6 +734,7 @@ int pkg_arch_to_legacy(const char *arch, char *dest, size_t sz);
bool pkg_is_config_file(struct pkg *p, const char *path, const struct pkg_file **file, struct pkg_config_file **cfile);
int pkg_message_from_ucl(struct pkg *pkg, const ucl_object_t *obj);
int pkg_message_from_str(struct pkg *pkg, const char *str, size_t len);
+
ucl_object_t* pkg_message_to_ucl(struct pkg *pkg);
char* pkg_message_to_str(struct pkg *pkg);

#endif