Esempio n. 1
0
void
xmpp_stream_destroy(XmppStream *stream)
{
    IqTransaction *trans;

    if (stream) {

        g_free(stream->jid);
        g_free(stream->stream_id);
        
        xmpp_account_destroy(stream->account);
        
        while (stream->pending_trans) {
            trans = (IqTransaction*)stream->pending_trans->data;
            iq_transaction_remove(stream, trans);
        }

        hybrid_connection_destroy(stream->conn);
        hybrid_ssl_connection_destory(stream->ssl);

        xmlnode_free(stream->node);
        stream->node = NULL;
        
        g_free(stream);
        stream = NULL;
    }
}
Esempio n. 2
0
HybridSslConnection*
hybrid_ssl_connect(const gchar *hostname, gint port, ssl_callback func,
                   gpointer user_data)
{
    BIO                 *buf_io;
    BIO                 *ssl_bio;
    HybridSslConnection *conn;

    g_return_val_if_fail(hostname != NULL, NULL);
    g_return_val_if_fail(port != 0, NULL);
    g_return_val_if_fail(func != NULL, NULL);

    SSLeay_add_all_algorithms();
    SSL_load_error_strings();
    SSL_library_init();

    conn = g_new0(HybridSslConnection, 1);

    if (!(conn->ssl_ctx = SSL_CTX_new(SSLv23_client_method()))) {
        hybrid_debug_error("ssl", "initialize SSL CTX: %s",
                           ERR_reason_error_string(ERR_get_error()));
        hybrid_ssl_connection_destory(conn);
        return NULL;
    }

    if (!(conn->ssl = ssl_new_with_certs(conn->ssl_ctx))) {
        hybrid_ssl_connection_destory(conn);
        return NULL;
    }

    SSL_set_mode(conn->ssl, SSL_MODE_AUTO_RETRY);

    buf_io  = BIO_new(BIO_f_buffer());
    ssl_bio = BIO_new(BIO_f_ssl());

    BIO_set_ssl(ssl_bio, conn->ssl, BIO_NOCLOSE);
    BIO_push(buf_io, ssl_bio);

    conn->conn_cb   = func;
    conn->conn_data = user_data;
    conn->rbio      = buf_io;

    conn->conn = hybrid_proxy_connect(hostname, port, ssl_connect_cb, conn);

    return conn;
}
Esempio n. 3
0
File: imap.c Progetto: GCrean/hybrid
void
hybrid_imap_destroy(hybrid_imap *imap)
{
    if (imap) {
        hybrid_ssl_connection_destory(imap->ssl);

        g_free(imap->username);
        g_free(imap->password);

        g_free(imap);
    }
}
Esempio n. 4
0
/**
 * Callback function to handle the ssi read event. We get the response
 * string from the ssi server here.
 */
static gboolean
ssi_auth_cb(HybridSslConnection *ssl, gpointer user_data)
{
    gchar           buf[BUF_LENGTH];
    gchar          *pos;
    gchar          *pos1;
    gint            ret;
    gint            code;
    fetion_account *ac = (fetion_account*)user_data;

    ret = hybrid_ssl_read(ssl, buf, sizeof(buf));

    if (ret == -1 || ret == 0) {
        hybrid_debug_error("ssi", "ssi server response error");
        return FALSE;
    }

    buf[ret] = '\0';

    hybrid_ssl_connection_destory(ssl);

    hybrid_debug_info("fetion", "recv:\n%s", buf);

    code = hybrid_get_http_code(buf);

    if (421 == code || 420 == code) {            /* confirm code needed. */
        if (HYBRID_ERROR == parse_ssi_fail_resp(ac, buf)) {
            goto ssi_auth_err;
        }

        verify_data.ssl     = ssl;
        verify_data.type = VERIFY_TYPE_SSI;

        hybrid_proxy_connect(NAV_SERVER, 80, pic_download_cb, ac);

        return FALSE;
    }

    if (200 != code) {
        goto ssi_auth_err;
    }

    if (!(pos = strstr(buf, "ssic="))) {
        goto ssi_auth_err;
    }

    pos += 5;

    for (pos1 = pos; *pos1 && *pos1 != ';'; pos1 ++);

    ac->ssic = g_strndup(pos, pos1 - pos);

    if (!(pos = g_strrstr(buf, "\r\n\r\n"))) {
        goto ssi_auth_err;
    }

    pos += 4;

    if (strlen(pos) != hybrid_get_http_length(buf)) {
        goto ssi_auth_err;
    }

    if (parse_ssi_response(ac, pos) != HYBRID_OK) {
        goto ssi_auth_err;
    }

    /*
     * First of all, we load the account's version information from the disk,
     * so that we can use it for authenticating, if the server find the versions
     * are up-to-date, it would return a brief response message in stead of the
     * full version, so that we can use the information store locally. This method
     * makes account logining more faster.
     */
    fetion_config_load_account(ac);

    /* now we will download the configuration */
    hybrid_proxy_connect(NAV_SERVER, 80, cfg_connect_cb, ac);

    return FALSE;

ssi_auth_err:

    hybrid_account_error_reason(ac->account, _("ssi authentication failed"));

    return FALSE;
}