[pacman-dev] [PATCH] Add alpm_capabilities() method and enumeration

Dan McGee dan at archlinux.org
Wed Sep 21 11:32:26 EDT 2011


This allows a frontend program to query, at runtime, what the library
supports. This can be useful for sanity checking during config-
requiring a downloader or disallowing signature settings, for example.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 lib/libalpm/alpm.c |   25 +++++++++++++++++++++++--
 lib/libalpm/alpm.h |    8 ++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 585c6a8..84d9eaf 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -133,9 +133,30 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
  * @brief Various libalpm functions
  */
 
-/* Get the version of library */
-const char SYMEXPORT *alpm_version(void) {
+/** Get the version of library.
+ * @return the library version, e.g. "6.0.4"
+ * */
+const char SYMEXPORT *alpm_version(void)
+{
 	return LIB_VERSION;
 }
 
+/** Get the capabilities of the library.
+ * @return a bitmask of the capabilities
+ * */
+enum alpm_caps alpm_capabilities(void)
+{
+	return 0
+#ifdef ENABLE_NLS
+		| ALPM_CAPABILITY_NLS
+#endif
+#ifdef HAVE_LIBCURL
+		| ALPM_CAPABILITY_DOWNLOADER
+#endif
+#ifdef HAVE_GPGME
+		| ALPM_CAPABILITY_SIGNATURES
+#endif
+		| 0;
+}
+
 /* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 853cb8b..3b6b279 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1187,7 +1187,15 @@ const char *alpm_strerror(enum _alpm_errno_t err);
 alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
 		enum _alpm_errno_t *err);
 int alpm_release(alpm_handle_t *handle);
+
+enum alpm_caps {
+	ALPM_CAPABILITY_NLS = (1 << 0),
+	ALPM_CAPABILITY_DOWNLOADER = (1 << 1),
+	ALPM_CAPABILITY_SIGNATURES = (1 << 2)
+};
+
 const char *alpm_version(void);
+enum alpm_caps alpm_capabilities(void);
 
 /* End of alpm_api */
 /** @} */
-- 
1.7.6.3



More information about the pacman-dev mailing list