hasl/hasl

Add version macros and exports to all functions

7 months ago, Elliott Sales de Andrade
7ed716379934
Parents 16568a4d6a41
Children ca6442534909
Add version macros and exports to all functions

This is basically copied from GPlugin.

I'm not sure if the 0.1 tag should just be made `AVAILABLE_IN_ALL`?

Testing Done:
Compiled and ran tests on Linux and Windows.

Reviewed at https://reviews.imfreedom.org/r/2675/
--- a/hasl/haslcontext.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslcontext.h Tue Oct 17 04:50:08 2023 -0500
@@ -21,6 +21,8 @@
#include <glib.h>
#include <glib-object.h>
+#include <hasl/haslversion.h>
+
G_BEGIN_DECLS
#define HASL_CONTEXT_DOMAIN (g_quark_from_static_string("hasl-context"))
@@ -96,6 +98,8 @@
* Since: 0.1.0
*/
#define HASL_TYPE_CONTEXT (hasl_context_get_type())
+
+HASL_AVAILABLE_IN_0_1
G_DECLARE_FINAL_TYPE(HaslContext, hasl_context, HASL, CONTEXT, GObject)
#include <hasl/haslmechanism.h>
@@ -109,6 +113,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
HaslContext *hasl_context_new(void);
/**
@@ -121,6 +126,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
const char *hasl_context_get_allowed_mechanisms(HaslContext *ctx);
/**
@@ -134,6 +140,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
void hasl_context_set_allowed_mechanisms(HaslContext *ctx, const char *allowed_mechanisms);
/**
@@ -147,6 +154,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
const char *hasl_context_get_authzid(HaslContext *ctx);
/**
@@ -159,6 +167,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
void hasl_context_set_authzid(HaslContext *ctx, const char *authzid);
/**
@@ -171,6 +180,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
const char *hasl_context_get_username(HaslContext *ctx);
/**
@@ -182,6 +192,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
void hasl_context_set_username(HaslContext *ctx, const char *username);
/**
@@ -194,6 +205,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
const char *hasl_context_get_password(HaslContext *ctx);
/**
@@ -205,6 +217,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
void hasl_context_set_password(HaslContext *ctx, const char *password);
/**
@@ -219,6 +232,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
gboolean hasl_context_get_tls(HaslContext *ctx);
/**
@@ -230,6 +244,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
void hasl_context_set_tls(HaslContext *ctx, gboolean tls);
/**
@@ -247,6 +262,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
gboolean hasl_context_get_allow_clear_text(HaslContext *ctx);
/**
@@ -263,6 +279,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
void hasl_context_set_allow_clear_text(HaslContext *ctx, gboolean allow_clear_text);
/**
@@ -292,6 +309,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
gboolean hasl_context_add_mechanism(HaslContext *ctx, const char *name, GType type);
/**
@@ -305,6 +323,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
char *hasl_context_get_supported_mechanisms(HaslContext *ctx);
/**
@@ -321,6 +340,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
const char *hasl_context_get_current_mechanism(HaslContext *ctx);
/**
@@ -336,6 +356,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
const char *hasl_context_next(HaslContext *ctx);
/**
@@ -361,6 +382,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
HaslMechanismResult hasl_context_step(HaslContext *ctx, const guint8 *server_in, gsize server_in_length, guint8 **client_out, gsize *client_out_length, GError **error);
G_END_DECLS
--- a/hasl/haslgs2header.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslgs2header.h Tue Oct 17 04:50:08 2023 -0500
@@ -21,6 +21,8 @@
#include <glib.h>
#include <glib-object.h>
+#include <hasl/haslversion.h>
+
G_BEGIN_DECLS
/**
@@ -62,6 +64,8 @@
* Since: 0.3.0
*/
#define HASL_TYPE_GS2_HEADER (hasl_gs2_header_get_type())
+
+HASL_AVAILABLE_IN_0_3
G_DECLARE_FINAL_TYPE(HaslGs2Header, hasl_gs2_header, HASL, GS2_HEADER, GObject)
/**
@@ -73,6 +77,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
HaslGs2Header *hasl_gs2_header_new(void);
/**
@@ -86,6 +91,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
char *hasl_gs2_header_to_string(HaslGs2Header *header, GError **error);
/**
@@ -98,6 +104,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
gboolean hasl_gs2_header_get_standard_mechanism(HaslGs2Header *header);
/**
@@ -109,6 +116,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_standard_mechanism(HaslGs2Header *header, gboolean standard);
/**
@@ -121,6 +129,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
HaslGs2HeaderChannelBinding hasl_gs2_header_get_channel_binding(HaslGs2Header *header);
/**
@@ -132,6 +141,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_channel_binding(HaslGs2Header *header, HaslGs2HeaderChannelBinding channel_binding);
/**
@@ -144,6 +154,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
const char *hasl_gs2_header_get_channel_binding_name(HaslGs2Header *header);
/**
@@ -155,6 +166,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_channel_binding_name(HaslGs2Header *header, const char *name);
/**
@@ -167,6 +179,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
const char *hasl_gs2_header_get_authzid(HaslGs2Header *header);
/**
@@ -180,6 +193,7 @@
*
* Since: 0.3.0
*/
+HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_authzid(HaslGs2Header *header, const char *authzid);
G_END_DECLS
--- a/hasl/haslmechanism.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslmechanism.h Tue Oct 17 04:50:08 2023 -0500
@@ -21,6 +21,8 @@
#include <glib.h>
#include <glib-object.h>
+#include <hasl/haslversion.h>
+
G_BEGIN_DECLS
/**
@@ -35,6 +37,8 @@
*/
#define HASL_TYPE_MECHANISM (hasl_mechanism_get_type())
+
+HASL_AVAILABLE_IN_0_1
G_DECLARE_DERIVABLE_TYPE(HaslMechanism, hasl_mechanism, HASL, MECHANISM,
GObject)
@@ -91,6 +95,7 @@
*
* Since: 0.1.0
*/
+HASL_AVAILABLE_IN_0_1
HaslMechanismResult hasl_mechanism_step(HaslMechanism *mechanism, HaslContext *ctx, const guint8 *server_in, gsize server_in_length, guint8 **client_out, gsize *client_out_length, GError **error);
/**
@@ -115,6 +120,7 @@
* Returns: %TRUE if @mechanism should be attempted otherwise %FALSE with
* @error optionally set.
*/
+HASL_AVAILABLE_IN_0_1
gboolean hasl_mechanism_possible(HaslMechanism *mechanism, HaslContext *ctx, GError **error);
G_END_DECLS
--- a/hasl/haslmechanismanonymous.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslmechanismanonymous.h Tue Oct 17 04:50:08 2023 -0500
@@ -23,6 +23,7 @@
#include <hasl/haslcontext.h>
#include <hasl/haslmechanism.h>
+#include <hasl/haslversion.h>
G_BEGIN_DECLS
@@ -43,6 +44,8 @@
*/
#define HASL_TYPE_MECHANISM_ANONYMOUS (hasl_mechanism_anonymous_get_type())
+
+HASL_AVAILABLE_IN_0_2
G_DECLARE_FINAL_TYPE(HaslMechanismAnonymous, hasl_mechanism_anonymous, HASL,
MECHANISM_ANONYMOUS, HaslMechanism)
--- a/hasl/haslmechanismexternal.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslmechanismexternal.h Tue Oct 17 04:50:08 2023 -0500
@@ -23,6 +23,7 @@
#include <hasl/haslcontext.h>
#include <hasl/haslmechanism.h>
+#include <hasl/haslversion.h>
G_BEGIN_DECLS
@@ -42,6 +43,8 @@
*/
#define HASL_TYPE_MECHANISM_EXTERNAL (hasl_mechanism_external_get_type())
+
+HASL_AVAILABLE_IN_0_1
G_DECLARE_FINAL_TYPE(HaslMechanismExternal, hasl_mechanism_external, HASL,
MECHANISM_EXTERNAL, HaslMechanism)
--- a/hasl/haslmechanismplain.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslmechanismplain.h Tue Oct 17 04:50:08 2023 -0500
@@ -23,6 +23,7 @@
#include <hasl/haslcontext.h>
#include <hasl/haslmechanism.h>
+#include <hasl/haslversion.h>
G_BEGIN_DECLS
@@ -45,6 +46,8 @@
*/
#define HASL_TYPE_MECHANISM_PLAIN (hasl_mechanism_plain_get_type())
+
+HASL_AVAILABLE_IN_0_1
G_DECLARE_FINAL_TYPE(HaslMechanismPlain, hasl_mechanism_plain, HASL,
MECHANISM_PLAIN, HaslMechanism)
--- a/hasl/haslversion.h Mon Oct 16 20:56:53 2023 -0500
+++ b/hasl/haslversion.h Tue Oct 17 04:50:08 2023 -0500
@@ -22,6 +22,132 @@
#include <hasl/haslversionconsts.h>
+/* clang-format tries to remove the space after 'if', which confuses
+ * gobject-introspection, so turn it off temporarily. */
+/* clang-format off */
+#if (defined(_WIN32) || defined(__CYGWIN__)) && \
+ !defined(HASL_STATIC_COMPILATION)
+/* clang-format on */
+#define _HASL_EXPORT __declspec(dllexport)
+#define _HASL_IMPORT __declspec(dllimport)
+#elif __GNUC__ >= 4
+#define _HASL_EXPORT __attribute__((visibility("default")))
+#define _HASL_IMPORT
+#else
+#define _HASL_EXPORT
+#define _HASL_IMPORT
+#endif
+#ifdef HASL_COMPILATION
+#define _HASL_API _HASL_EXPORT
+#else
+#define _HASL_API _HASL_IMPORT
+#endif
+
+#define _HASL_EXTERN _HASL_API extern
+
+#ifdef HASL_DISABLE_DEPRECATION_WARNINGS
+#define HASL_DEPRECATED _HASL_EXTERN
+#define HASL_DEPRECATED_FOR(f) _HASL_EXTERN
+#define HASL_UNAVAILABLE(maj, min) _HASL_EXTERN
+#define HASL_UNAVAILABLE_STATIC_INLINE(maj, min)
+#define HASL_UNAVAILABLE_TYPE(maj, min)
+#else
+#define HASL_DEPRECATED G_DEPRECATED _HASL_EXTERN
+#define HASL_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _HASL_EXTERN
+#define HASL_UNAVAILABLE(maj, min) G_UNAVAILABLE(maj, min) _HASL_EXTERN
+#define HASL_UNAVAILABLE_STATIC_INLINE(maj, min) G_UNAVAILABLE(maj, min)
+#define HASL_UNAVAILABLE_TYPE(maj, min) G_UNAVAILABLE(maj, min)
+#endif
+
+/**
+ * HASL_VERSION_CUR_STABLE:
+ *
+ * A macro that evaluates to the current stable version of hasl, in a format
+ * that can be used by the C pre-processor.
+ *
+ * Since: 0.3.0
+ */
+#define HASL_VERSION_CUR_STABLE \
+ (G_ENCODE_VERSION(HASL_MAJOR_VERSION, HASL_MINOR_VERSION))
+
+/* If the package sets HASL_VERSION_MIN_REQUIRED to some future
+ * HASL_VERSION_X_Y value that we don't know about, it will compare as 0 in
+ * preprocessor tests.
+ */
+#ifndef HASL_VERSION_MIN_REQUIRED
+#define HASL_VERSION_MIN_REQUIRED (HASL_VERSION_CUR_STABLE)
+#elif HASL_VERSION_MIN_REQUIRED == 0
+#undef HASL_VERSION_MIN_REQUIRED
+#define HASL_VERSION_MIN_REQUIRED (HASL_VERSION_CUR_STABLE + 1)
+#endif /* HASL_VERSION_MIN_REQUIRED */
+
+#if !defined(HASL_VERSION_MAX_ALLOWED) || (HASL_VERSION_MAX_ALLOWED == 0)
+#undef HASL_VERSION_MAX_ALLOWED
+#define HASL_VERSION_MAX_ALLOWED (HASL_VERSION_CUR_STABLE)
+#endif /* HASL_VERSION_MAX_ALLOWED */
+
+/* sanity checks */
+#if HASL_VERSION_MIN_REQUIRED > HASL_VERSION_CUR_STABLE
+#error "HASL_VERSION_MIN_REQUIRED must be <= HASL_VERSION_CUR_STABLE"
+#endif
+#if HASL_VERSION_MAX_ALLOWED < HASL_VERSION_MIN_REQUIRED
+#error "HASL_VERSION_MAX_ALLOWED must be >= HASL_VERSION_MIN_REQUIRED"
+#endif
+#if HASL_VERSION_MIN_REQUIRED < G_ENCODE_VERSION(0, 1)
+#error "HASL_VERSION_MIN_REQUIRED must be >= HASL_VERSION_0_1"
+#endif
+
+#define HASL_VAR _HASL_EXTERN
+#define HASL_AVAILABLE_IN_ALL _HASL_EXTERN
+
+/**
+ * HASL_VERSION_0_1:
+ *
+ * A macro that evaluates to the 0.1 version of hasl, in a format that can be
+ * used by the C pre-processor.
+ *
+ * Since: 0.3.0
+ */
+#define HASL_VERSION_0_1 (G_ENCODE_VERSION(0, 1))
+
+#if HASL_VERSION_MAX_ALLOWED < HASL_VERSION_0_1
+#define HASL_AVAILABLE_IN_0_1 HASL_UNAVAILABLE(0, 1)
+#else
+#define HASL_AVAILABLE_IN_0_1 _HASL_EXTERN
+#endif
+
+/**
+ * HASL_VERSION_0_2:
+ *
+ * A macro that evaluates to the 0.2 version of hasl, in a format that can be
+ * used by the C pre-processor.
+ *
+ * Since: 0.3.0
+ */
+#define HASL_VERSION_0_2 (G_ENCODE_VERSION(0, 2))
+
+#if HASL_VERSION_MAX_ALLOWED < HASL_VERSION_0_2
+#define HASL_AVAILABLE_IN_0_2 HASL_UNAVAILABLE(0, 2)
+#else
+#define HASL_AVAILABLE_IN_0_2 _HASL_EXTERN
+#endif
+
+/**
+ * HASL_VERSION_0_3:
+ *
+ * A macro that evaluates to the 0.3 version of hasl, in a format that can be
+ * used by the C pre-processor.
+ *
+ * Since: 0.3.0
+ */
+#define HASL_VERSION_0_3 (G_ENCODE_VERSION(0, 3))
+
+#if HASL_VERSION_MAX_ALLOWED < HASL_VERSION_0_3
+#define HASL_AVAILABLE_IN_0_3 HASL_UNAVAILABLE(0, 3)
+#else
+#define HASL_AVAILABLE_IN_0_3 _HASL_EXTERN
+#endif
+
G_BEGIN_DECLS
/**
@@ -55,6 +181,7 @@
*
* Since: 0.2.0
*/
+HASL_AVAILABLE_IN_0_2
const char *hasl_check_version(guint required_major, guint required_minor, guint required_micro);
/**
@@ -64,7 +191,7 @@
*
* Since: 0.2.0
*/
-extern const char *hasl_version;
+HASL_VAR const char *hasl_version;
/**
* hasl_major_version:
@@ -75,7 +202,7 @@
*
* Since: 0.2.0
*/
-extern const guint hasl_major_version;
+HASL_VAR const guint hasl_major_version;
/**
* hasl_minor_version:
@@ -86,7 +213,7 @@
*
* Since: 0.2.0
*/
-extern const guint hasl_minor_version;
+HASL_VAR const guint hasl_minor_version;
/**
* hasl_micro_version:
@@ -97,7 +224,7 @@
*
* Since: 0.2.0
*/
-extern const guint hasl_micro_version;
+HASL_VAR const guint hasl_micro_version;
G_END_DECLS