Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add new pkg_plugin_{errno,error,info} to emit information from the plugins thought the event interface
Baptiste Daroussin committed 13 years ago
commit fa5dd5de40340ffa2aebeae0643e9aabf56e211d
parent c5799f6
3 files changed +77 -1
modified libpkg/pkg.h
@@ -944,7 +944,9 @@ int pkg_plugin_conf_integer(struct pkg_plugin *p, int key, int64_t *value);
int pkg_plugin_confs(struct pkg_plugin *p, struct pkg_config **conf);

int pkg_plugin_parse(struct pkg_plugin *p);
-

+
void pkg_plugin_errno(struct pkg_plugin *p, const char *func, const char *arg);
+
void pkg_plugin_error(struct pkg_plugin *p, const char *fmt, ...);
+
void pkg_plugin_info(struct pkg_plugin *p, const char *fmt, ...);
/**
 * This is where plugin hook into the library using pkg_plugin_hook()
 * @todo: Document
@@ -1016,6 +1018,9 @@ typedef enum {
	PKG_EVENT_NOLOCALDB,
	PKG_EVENT_FILE_MISMATCH,
	PKG_EVENT_DEVELOPER_MODE,
+
	PKG_EVENT_PLUGIN_ERRNO,
+
	PKG_EVENT_PLUGIN_ERROR,
+
	PKG_EVENT_PLUGIN_INFO,
} pkg_event_t;

struct pkg_event {
@@ -1074,6 +1079,19 @@ struct pkg_event {
			struct pkg_file *file;
			const char *newsum;
		} e_file_mismatch;
+
		struct {
+
			struct pkg_plugin *plugin;
+
			char *msg;
+
		} e_plugin_info;
+
		struct {
+
			struct pkg_plugin *plugin;
+
			const char *func;
+
			const char *arg;
+
		} e_plugin_errno;
+
		struct {
+
			struct pkg_plugin *plugin;
+
			char *msg;
+
		} e_plugin_error;
	};
};

modified libpkg/pkg_event.c
@@ -309,3 +309,50 @@ pkg_emit_file_mismatch(struct pkg *pkg, struct pkg_file *f, const char *newsum)

	pkg_emit_event(&ev);
}
+

+
void
+
pkg_plugin_errno(struct pkg_plugin *p, const char *func, const char *arg)
+
{
+
	struct pkg_event ev;
+

+
	ev.type = PKG_EVENT_PLUGIN_ERRNO;
+
	ev.e_plugin_errno.plugin = p;
+
	ev.e_plugin_errno.func = func;
+
	ev.e_plugin_errno.arg = arg;
+

+
	pkg_emit_event(&ev);
+
}
+

+
void
+
pkg_plugin_error(struct pkg_plugin *p, const char *fmt, ...)
+
{
+
	struct pkg_event ev;
+
	va_list ap;
+

+
	ev.type = PKG_EVENT_PLUGIN_ERROR;
+
	ev.e_plugin_error.plugin = p;
+

+
	va_start(ap, fmt);
+
	vasprintf(&ev.e_plugin_error.msg, fmt, ap);
+
	va_end(ap);
+

+
	pkg_emit_event(&ev);
+
	free(ev.e_plugin_error.msg);
+
}
+

+
void
+
pkg_plugin_info(struct pkg_plugin *p, const char *fmt, ...)
+
{
+
	struct pkg_event ev;
+
	va_list ap;
+

+
	ev.type = PKG_EVENT_PLUGIN_INFO;
+
	ev.e_plugin_info.plugin = p;
+

+
	va_start(ap, fmt);
+
	vasprintf(&ev.e_plugin_info.msg, fmt, ap);
+
	va_end(ap);
+

+
	pkg_emit_event(&ev);
+
	free(ev.e_plugin_info.msg);
+
}
modified pkg/event.c
@@ -223,6 +223,17 @@ event_callback(void *data, struct pkg_event *ev)
		    PKG_VERSION, &version);
		fprintf(stderr, "%s-%s: checksum mismatch for %s\n", name,
		    version, pkg_file_path(ev->e_file_mismatch.file));
+
	case PKG_EVENT_PLUGIN_ERRNO:
+
		warn("%s: %s(%s)", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME),ev->e_plugin_errno.func, ev->e_plugin_errno.arg);
+
		break;
+
	case PKG_EVENT_PLUGIN_ERROR:
+
		warnx("%s: %s", pkg_plugin_get(ev->e_plugin_error.plugin, PKG_PLUGIN_NAME), ev->e_plugin_error.msg);
+
		break;
+
	case PKG_EVENT_PLUGIN_INFO:
+
		if (quiet)
+
			break;
+
		printf("%s: %s\n", pkg_plugin_get(ev->e_plugin_info.plugin, PKG_PLUGIN_NAME), ev->e_plugin_info.msg);
+
		break;
	default:
		break;
	}