1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

use new libstrophe API

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2021-10-27 18:29:15 +02:00
parent 687714d7d6
commit 7f646e3668
2 changed files with 23 additions and 45 deletions

View File

@ -88,10 +88,8 @@ static void _xmpp_file_logger(void* const userdata, const xmpp_log_level_t level
static void _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status, const int error, static void _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status, const int error,
xmpp_stream_error_t* const stream_error, void* const userdata); xmpp_stream_error_t* const stream_error, void* const userdata);
#ifdef HAVE_LIBMESODE TLSCertificate* _xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert);
TLSCertificate* _xmppcert_to_profcert(xmpp_tlscert_t* xmpptlscert); static int _connection_certfail_cb(const xmpp_tlscert_t* xmpptlscert, const char* errormsg);
static int _connection_certfail_cb(xmpp_tlscert_t* xmpptlscert, const char* const errormsg);
#endif
static void _random_bytes_init(void); static void _random_bytes_init(void);
static void _random_bytes_close(void); static void _random_bytes_close(void);
@ -214,28 +212,20 @@ connection_connect(const char* const jid, const char* const passwd, const char*
#undef LOG_FLAG_IF_SET #undef LOG_FLAG_IF_SET
} }
#ifdef HAVE_LIBMESODE
char* cert_path = prefs_get_tls_certpath(); char* cert_path = prefs_get_tls_certpath();
if (cert_path) { if (cert_path) {
xmpp_conn_tlscert_path(conn.xmpp_conn, cert_path); xmpp_conn_set_capath(conn.xmpp_conn, cert_path);
free(cert_path); free(cert_path);
} }
xmpp_conn_set_certfail_handler(conn.xmpp_conn, _connection_certfail_cb);
int connect_status = xmpp_connect_client( int connect_status = xmpp_connect_client(
conn.xmpp_conn, conn.xmpp_conn,
altdomain, altdomain,
port, port,
_connection_certfail_cb,
_connection_handler, _connection_handler,
conn.xmpp_ctx); conn.xmpp_ctx);
#else
int connect_status = xmpp_connect_client(
conn.xmpp_conn,
altdomain,
port,
_connection_handler,
conn.xmpp_ctx);
#endif
if (connect_status == 0) { if (connect_status == 0) {
conn.conn_status = JABBER_CONNECTING; conn.conn_status = JABBER_CONNECTING;
@ -549,28 +539,20 @@ connection_register(const char* const altdomain, int port, const char* const tls
reg->username = strdup(username); reg->username = strdup(username);
reg->password = strdup(password); reg->password = strdup(password);
#ifdef HAVE_LIBMESODE
char* cert_path = prefs_get_tls_certpath(); char* cert_path = prefs_get_tls_certpath();
if (cert_path) { if (cert_path) {
xmpp_conn_tlscert_path(conn.xmpp_conn, cert_path); xmpp_conn_set_capath(conn.xmpp_conn, cert_path);
free(cert_path); free(cert_path);
} }
xmpp_conn_set_certfail_handler(conn.xmpp_conn, _connection_certfail_cb);
int connect_status = xmpp_connect_raw( int connect_status = xmpp_connect_raw(
conn.xmpp_conn, conn.xmpp_conn,
altdomain, altdomain,
port, port,
_connection_certfail_cb,
_register_handler, _register_handler,
reg); reg);
#else
int connect_status = xmpp_connect_raw(
conn.xmpp_conn,
altdomain,
port,
_register_handler,
reg);
#endif
if (connect_status == 0) { if (connect_status == 0) {
conn.conn_status = JABBER_RAW_CONNECTING; conn.conn_status = JABBER_RAW_CONNECTING;
@ -639,17 +621,15 @@ connection_clear_data(void)
} }
} }
#ifdef HAVE_LIBMESODE
TLSCertificate* TLSCertificate*
connection_get_tls_peer_cert(void) connection_get_tls_peer_cert(void)
{ {
xmpp_tlscert_t* xmpptlscert = xmpp_conn_tls_peer_cert(conn.xmpp_conn); xmpp_tlscert_t* xmpptlscert = xmpp_conn_get_peer_cert(conn.xmpp_conn);
TLSCertificate* cert = _xmppcert_to_profcert(xmpptlscert); TLSCertificate* cert = _xmppcert_to_profcert(xmpptlscert);
xmpp_conn_free_tlscert(conn.xmpp_ctx, xmpptlscert); xmpp_tlscert_free(xmpptlscert);
return cert; return cert;
} }
#endif
gboolean gboolean
connection_is_secured(void) connection_is_secured(void)
@ -965,9 +945,8 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
} }
} }
#ifdef HAVE_LIBMESODE
static int static int
_connection_certfail_cb(xmpp_tlscert_t* xmpptlscert, const char* const errormsg) _connection_certfail_cb(const xmpp_tlscert_t* xmpptlscert, const char* errormsg)
{ {
TLSCertificate* cert = _xmppcert_to_profcert(xmpptlscert); TLSCertificate* cert = _xmppcert_to_profcert(xmpptlscert);
@ -978,20 +957,21 @@ _connection_certfail_cb(xmpp_tlscert_t* xmpptlscert, const char* const errormsg)
} }
TLSCertificate* TLSCertificate*
_xmppcert_to_profcert(xmpp_tlscert_t* xmpptlscert) _xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert)
{ {
int version = (int)strtol(
xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_VERSION), NULL, 10);
return tlscerts_new( return tlscerts_new(
xmpp_conn_tlscert_fingerprint(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_FINGERPRINT_SHA1),
xmpp_conn_tlscert_version(xmpptlscert), version,
xmpp_conn_tlscert_serialnumber(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_SERIALNUMBER),
xmpp_conn_tlscert_subjectname(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_SUBJECT),
xmpp_conn_tlscert_issuername(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_ISSUER),
xmpp_conn_tlscert_notbefore(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_NOTBEFORE),
xmpp_conn_tlscert_notafter(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_NOTAFTER),
xmpp_conn_tlscert_key_algorithm(xmpptlscert), xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_KEYALG),
xmpp_conn_tlscert_signature_algorithm(xmpptlscert)); xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_SIGALG));
} }
#endif
static xmpp_log_t* static xmpp_log_t*
_xmpp_get_file_logger(void) _xmpp_get_file_logger(void)

View File

@ -193,9 +193,7 @@ char* connection_get_barejid(void);
char* connection_get_user(void); char* connection_get_user(void);
char* connection_create_uuid(void); char* connection_create_uuid(void);
void connection_free_uuid(char* uuid); void connection_free_uuid(char* uuid);
#ifdef HAVE_LIBMESODE
TLSCertificate* connection_get_tls_peer_cert(void); TLSCertificate* connection_get_tls_peer_cert(void);
#endif
gboolean connection_is_secured(void); gboolean connection_is_secured(void);
gboolean connection_send_stanza(const char* const stanza); gboolean connection_send_stanza(const char* const stanza);
GList* connection_get_available_resources(void); GList* connection_get_available_resources(void);