summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2021-09-19 23:47:30 +0300
committerdefanor <defanor@uberspace.net>2021-09-19 23:47:30 +0300
commit917211b67cc27f07b3743611ee9389ff966ffba5 (patch)
tree9ef0f966201e820568489d3390467a2ee4e013e0 /src
parent003a44b641ab5630b23f335483aef9a21350769f (diff)
Make GPGME optional
Diffstat (limited to 'src')
-rw-r--r--src/rexmpp.c12
-rw-r--r--src/rexmpp.h7
-rw-r--r--src/rexmpp_openpgp.c72
3 files changed, 91 insertions, 0 deletions
diff --git a/src/rexmpp.c b/src/rexmpp.c
index bfaca29..5c41625 100644
--- a/src/rexmpp.c
+++ b/src/rexmpp.c
@@ -15,11 +15,15 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include "config.h"
+
#include <libxml/tree.h>
#include <libxml/xmlsave.h>
#include <gsasl.h>
#include <unbound.h>
+#ifdef HAVE_GPGME
#include <gpgme.h>
+#endif
#include <nettle/sha1.h>
#include "rexmpp.h"
@@ -387,7 +391,11 @@ rexmpp_err_t rexmpp_init (rexmpp_t *s,
s->track_roster_presence = 1;
s->track_roster_events = 1;
s->nick_notifications = 1;
+#ifdef HAVE_GPGME
s->retrieve_openpgp_keys = 1;
+#else
+ s->retrieve_openpgp_keys = 0;
+#endif
s->autojoin_bookmarked_mucs = 1;
s->require_tls = 1;
s->send_buffer = NULL;
@@ -489,6 +497,7 @@ rexmpp_err_t rexmpp_init (rexmpp_t *s,
gsasl_callback_hook_set(s->sasl_ctx, s);
gsasl_callback_set(s->sasl_ctx, rexmpp_sasl_cb);
+#ifdef HAVE_GPGME
gpgme_check_version(NULL);
err = gpgme_new(&(s->pgp_ctx));
if (gpg_err_code(err) != GPG_ERR_NO_ERROR) {
@@ -499,6 +508,7 @@ rexmpp_err_t rexmpp_init (rexmpp_t *s,
xmlFreeParserCtxt(s->xml_parser);
return REXMPP_E_PGP;
}
+#endif
return REXMPP_SUCCESS;
}
@@ -565,7 +575,9 @@ void rexmpp_cleanup (rexmpp_t *s) {
/* Frees the things that persist through reconnects. */
void rexmpp_done (rexmpp_t *s) {
rexmpp_cleanup(s);
+#ifdef HAVE_GPGME
gpgme_release(s->pgp_ctx);
+#endif
gsasl_done(s->sasl_ctx);
rexmpp_tls_deinit(s);
if (s->resolver_ctx != NULL) {
diff --git a/src/rexmpp.h b/src/rexmpp.h
index b47703f..bfcde96 100644
--- a/src/rexmpp.h
+++ b/src/rexmpp.h
@@ -10,10 +10,15 @@
#define REXMPP_H
#include <stdint.h>
+
+#include "config.h"
+
#include <unbound.h>
#include <gsasl.h>
#include <libxml/tree.h>
+#ifdef HAVE_GPGME
#include <gpgme.h>
+#endif
typedef struct rexmpp rexmpp_t;
@@ -347,7 +352,9 @@ struct rexmpp
Gsasl_session *sasl_session;
/* OpenPGP structures */
+#ifdef HAVE_GPGME
gpgme_ctx_t pgp_ctx;
+#endif
};
/**
diff --git a/src/rexmpp_openpgp.c b/src/rexmpp_openpgp.c
index 2ec975d..fd22cf4 100644
--- a/src/rexmpp_openpgp.c
+++ b/src/rexmpp_openpgp.c
@@ -42,7 +42,11 @@ Possible future improvements:
#include <string.h>
#include <time.h>
+#include "config.h"
+
+#ifdef HAVE_GPGME
#include <gpgme.h>
+#endif
#include <libxml/tree.h>
#include <gsasl.h>
@@ -52,6 +56,8 @@ Possible future improvements:
#include "rexmpp_pubsub.h"
+#ifdef HAVE_GPGME
+
void rexmpp_pgp_fp_reply (rexmpp_t *s,
xmlNodePtr req,
xmlNodePtr response,
@@ -817,3 +823,69 @@ rexmpp_err_t rexmpp_openpgp_set_home_dir (rexmpp_t *s, const char *home_dir) {
}
return REXMPP_SUCCESS;
}
+
+#else
+
+/* Dummy functions for when it's built without GPGME. */
+
+rexmpp_err_t gpgme_not_supported(rexmpp_t *s) {
+ rexmpp_log(s, LOG_ERR, "rexmpp is compiled without GPGME support");
+ return REXMPP_E_PGP;
+}
+
+rexmpp_err_t
+rexmpp_openpgp_check_keys (rexmpp_t *s,
+ const char *jid,
+ xmlNodePtr items) {
+ (void)jid;
+ (void)items;
+ return gpgme_not_supported(s);
+}
+
+rexmpp_err_t rexmpp_openpgp_publish_key (rexmpp_t *s, const char *fp) {
+ (void)fp;
+ return gpgme_not_supported(s);
+}
+
+void rexmpp_openpgp_retract_key (rexmpp_t *s, const char *fp) {
+ (void)fp;
+ gpgme_not_supported(s);
+}
+
+xmlNodePtr
+rexmpp_openpgp_decrypt_verify (rexmpp_t *s,
+ const char *cipher_base64) {
+ (void)cipher_base64;
+ gpgme_not_supported(s);
+ return NULL;
+}
+
+xmlNodePtr
+rexmpp_openpgp_decrypt_verify_message (rexmpp_t *s,
+ xmlNodePtr message,
+ int *valid) {
+ (void)message;
+ (void)valid;
+ gpgme_not_supported(s);
+ return NULL;
+}
+
+char *rexmpp_openpgp_payload (rexmpp_t *s,
+ xmlNodePtr payload,
+ const char **recipients,
+ const char **signers,
+ enum rexmpp_ox_mode mode) {
+ (void)recipients;
+ (void)signers;
+ (void)mode;
+ xmlFreeNode(payload);
+ gpgme_not_supported(s);
+ return NULL;
+}
+
+rexmpp_err_t rexmpp_openpgp_set_home_dir (rexmpp_t *s, const char *home_dir) {
+ (void)home_dir;
+ return gpgme_not_supported(s);
+}
+
+#endif