about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-10 22:09:09 +0100
committerJames Booth <boothj5@gmail.com>2016-05-10 22:09:09 +0100
commit02bc4f217cd349c48f99520037ec31e2c9308bb9 (patch)
tree6fc288fd54b186f303534bac313b0dd8f15fc2c9 /src/xmpp
parent5cb6b174cc2e2fd629cae6b4205534577671545e (diff)
downloadprofani-tty-02bc4f217cd349c48f99520037ec31e2c9308bb9.tar.gz
Tidy connection.c
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/connection.c56
1 files changed, 35 insertions, 21 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 6ebd665e..2b508288 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -71,7 +71,9 @@ 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,
     xmpp_stream_error_t *const stream_error, void *const userdata);
+
 #ifdef HAVE_LIBMESODE
+TLSCertificate* _xmppcert_to_profcert(xmpp_tlscert_t *xmpptlscert);
 static int _connection_certfail_cb(xmpp_tlscert_t *xmpptlscert, const char *const errormsg);
 #endif
 
@@ -173,21 +175,6 @@ connection_connect(const char *const fulljid, const char *const passwd, const ch
 
 #ifdef HAVE_LIBMESODE
 TLSCertificate*
-_xmppcert_to_profcert(xmpp_tlscert_t *xmpptlscert)
-{
-    return tlscerts_new(
-        xmpp_conn_tlscert_fingerprint(xmpptlscert),
-        xmpp_conn_tlscert_version(xmpptlscert),
-        xmpp_conn_tlscert_serialnumber(xmpptlscert),
-        xmpp_conn_tlscert_subjectname(xmpptlscert),
-        xmpp_conn_tlscert_issuername(xmpptlscert),
-        xmpp_conn_tlscert_notbefore(xmpptlscert),
-        xmpp_conn_tlscert_notafter(xmpptlscert),
-        xmpp_conn_tlscert_key_algorithm(xmpptlscert),
-        xmpp_conn_tlscert_signature_algorithm(xmpptlscert));
-}
-
-TLSCertificate*
 connection_get_tls_peer_cert(void)
 {
     xmpp_tlscert_t *xmpptlscert = xmpp_conn_tls_peer_cert(conn.xmpp_conn);
@@ -425,10 +412,11 @@ 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)
 {
+    switch (status) {
+
     // login success
-    if (status == XMPP_CONN_CONNECT) {
+    case XMPP_CONN_CONNECT:
         log_debug("Connection handler: XMPP_CONN_CONNECT");
-
         conn.conn_status = JABBER_CONNECTED;
 
         Jid *my_jid = jid_create(xmpp_conn_get_jid(conn.xmpp_conn));
@@ -440,7 +428,10 @@ _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status
 
         session_login_success(connection_is_secured());
 
-    } else if (status == XMPP_CONN_DISCONNECT) {
+        break;
+
+    // disconnected
+    case XMPP_CONN_DISCONNECT:
         log_debug("Connection handler: XMPP_CONN_DISCONNECT");
 
         // lost connection for unknown reason
@@ -454,12 +445,20 @@ _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status
             session_login_failed();
         }
 
-        // close stream response from server after disconnect is handled too
+        // close stream response from server after disconnect is handled
         conn.conn_status = JABBER_DISCONNECTED;
-    } else if (status == XMPP_CONN_FAIL) {
+
+        break;
+
+    // connection failed
+    case XMPP_CONN_FAIL:
         log_debug("Connection handler: XMPP_CONN_FAIL");
-    } else {
+        break;
+
+    // unknown state
+    default:
         log_error("Connection handler: Unknown status");
+        break;
     }
 }
 
@@ -474,6 +473,21 @@ _connection_certfail_cb(xmpp_tlscert_t *xmpptlscert, const char *const errormsg)
 
     return res;
 }
+
+TLSCertificate*
+_xmppcert_to_profcert(xmpp_tlscert_t *xmpptlscert)
+{
+    return tlscerts_new(
+        xmpp_conn_tlscert_fingerprint(xmpptlscert),
+        xmpp_conn_tlscert_version(xmpptlscert),
+        xmpp_conn_tlscert_serialnumber(xmpptlscert),
+        xmpp_conn_tlscert_subjectname(xmpptlscert),
+        xmpp_conn_tlscert_issuername(xmpptlscert),
+        xmpp_conn_tlscert_notbefore(xmpptlscert),
+        xmpp_conn_tlscert_notafter(xmpptlscert),
+        xmpp_conn_tlscert_key_algorithm(xmpptlscert),
+        xmpp_conn_tlscert_signature_algorithm(xmpptlscert));
+}
 #endif
 
 static xmpp_log_t*