Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision cf9143f945a67f3d540e2704fdbdf1bdc985233d authored by Richard Levitte on 28 May 2019, 12:56:29 UTC, committed by Richard Levitte on 28 May 2019, 12:56:29 UTC
Prepare for 1.0.2s release
Reviewed-by: Matt Caswell <matt@openssl.org>
1 parent 66c236c
  • Files
  • Changes
  • 745ed18
  • /
  • demos
  • /
  • tunala
  • /
  • sm.c
Raw File
Cook and download a directory from the Software Heritage Vault

You have requested the cooking of the directory with identifier None into a standard tar.gz archive.

Are you sure you want to continue ?

Download a directory from the Software Heritage Vault

You have requested the download of the directory with identifier None as a standard tar.gz archive.

Are you sure you want to continue ?

Cook and download a revision from the Software Heritage Vault

You have requested the cooking of the history heading to revision with identifier swh:1:rev:cf9143f945a67f3d540e2704fdbdf1bdc985233d into a bare git archive.

Are you sure you want to continue ?

Download a revision from the Software Heritage Vault

You have requested the download of the history heading to revision with identifier swh:1:rev:cf9143f945a67f3d540e2704fdbdf1bdc985233d as a bare git archive.

Are you sure you want to continue ?

Invalid Email !

The provided email is not well-formed.

Download link has expired

The requested archive is no longer available for download from the Software Heritage Vault.

Do you want to cook it again ?

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • content
revision badge
swh:1:rev:cf9143f945a67f3d540e2704fdbdf1bdc985233d
content badge Iframe embedding
swh:1:cnt:5658dfff2d8d8a4a9c766f16b53a5bd85b4fecaf
sm.c
#include "tunala.h"

#ifndef NO_TUNALA

void state_machine_init(state_machine_t * machine)
{
    machine->ssl = NULL;
    machine->bio_intossl = machine->bio_fromssl = NULL;
    buffer_init(&machine->clean_in);
    buffer_init(&machine->clean_out);
    buffer_init(&machine->dirty_in);
    buffer_init(&machine->dirty_out);
}

void state_machine_close(state_machine_t * machine)
{
    if (machine->ssl)
        SSL_free(machine->ssl);
    /*
     * SSL_free seems to decrement the reference counts already so doing this
     * goes kaboom.
     */
# if 0
    if (machine->bio_intossl)
        BIO_free(machine->bio_intossl);
    if (machine->bio_fromssl)
        BIO_free(machine->bio_fromssl);
# endif
    buffer_close(&machine->clean_in);
    buffer_close(&machine->clean_out);
    buffer_close(&machine->dirty_in);
    buffer_close(&machine->dirty_out);
    state_machine_init(machine);
}

buffer_t *state_machine_get_buffer(state_machine_t * machine,
                                   sm_buffer_t type)
{
    switch (type) {
    case SM_CLEAN_IN:
        return &machine->clean_in;
    case SM_CLEAN_OUT:
        return &machine->clean_out;
    case SM_DIRTY_IN:
        return &machine->dirty_in;
    case SM_DIRTY_OUT:
        return &machine->dirty_out;
    default:
        break;
    }
    /* Should never get here */
    abort();
    return NULL;
}

SSL *state_machine_get_SSL(state_machine_t * machine)
{
    return machine->ssl;
}

int state_machine_set_SSL(state_machine_t * machine, SSL *ssl, int is_server)
{
    if (machine->ssl)
        /* Shouldn't ever be set twice */
        abort();
    machine->ssl = ssl;
    /* Create the BIOs to handle the dirty side of the SSL */
    if ((machine->bio_intossl = BIO_new(BIO_s_mem())) == NULL)
        abort();
    if ((machine->bio_fromssl = BIO_new(BIO_s_mem())) == NULL)
        abort();
    /* Hook up the BIOs on the dirty side of the SSL */
    SSL_set_bio(machine->ssl, machine->bio_intossl, machine->bio_fromssl);
    if (is_server)
        SSL_set_accept_state(machine->ssl);
    else
        SSL_set_connect_state(machine->ssl);
    /*
     * If we're the first one to generate traffic - do it now otherwise we go
     * into the next select empty-handed and our peer will not send data but
     * will similarly wait for us.
     */
    return state_machine_churn(machine);
}

/* Performs the data-IO loop and returns zero if the machine should close */
int state_machine_churn(state_machine_t * machine)
{
    unsigned int loop;
    if (machine->ssl == NULL) {
        if (buffer_empty(&machine->clean_out))
            /* Time to close this state-machine altogether */
            return 0;
        else
            /* Still buffered data on the clean side to go out */
            return 1;
    }
    /*
     * Do this loop twice to cover any dependencies about which precise order
     * of reads and writes is required.
     */
    for (loop = 0; loop < 2; loop++) {
        buffer_to_SSL(&machine->clean_in, machine->ssl);
        buffer_to_BIO(&machine->dirty_in, machine->bio_intossl);
        buffer_from_SSL(&machine->clean_out, machine->ssl);
        buffer_from_BIO(&machine->dirty_out, machine->bio_fromssl);
    }
    /*
     * We close on the SSL side if the info callback noticed some problems or
     * an SSL shutdown was underway and shutdown traffic had all been sent.
     */
    if (SSL_get_app_data(machine->ssl) || (SSL_get_shutdown(machine->ssl) &&
                                           buffer_empty(&machine->dirty_out)))
    {
        /* Great, we can seal off the dirty side completely */
        if (!state_machine_close_dirty(machine))
            return 0;
    }
    /*
     * Either the SSL is alive and well, or the closing process still has
     * outgoing data waiting to be sent
     */
    return 1;
}

/* Called when the clean side of the SSL has lost its connection */
int state_machine_close_clean(state_machine_t * machine)
{
    /*
     * Well, first thing to do is null out the clean-side buffers - they're
     * no use any more.
     */
    buffer_close(&machine->clean_in);
    buffer_close(&machine->clean_out);
    /* And start an SSL shutdown */
    if (machine->ssl)
        SSL_shutdown(machine->ssl);
    /* This is an "event", so flush the SSL of any generated traffic */
    state_machine_churn(machine);
    if (buffer_empty(&machine->dirty_in) && buffer_empty(&machine->dirty_out))
        return 0;
    return 1;
}

/*
 * Called when the dirty side of the SSL has lost its connection. This is
 * pretty terminal as all that can be left to do is send any buffered output
 * on the clean side - after that, we're done.
 */
int state_machine_close_dirty(state_machine_t * machine)
{
    buffer_close(&machine->dirty_in);
    buffer_close(&machine->dirty_out);
    buffer_close(&machine->clean_in);
    if (machine->ssl)
        SSL_free(machine->ssl);
    machine->ssl = NULL;
    machine->bio_intossl = machine->bio_fromssl = NULL;
    if (buffer_empty(&machine->clean_out))
        return 0;
    return 1;
}

#endif                          /* !defined(NO_TUNALA) */
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top