Removing cruft sync
authorKrista Bennett <krista@pep-project.org>
Fri, 17 Aug 2018 21:28:43 +0200
branchsync
changeset 2857dc81cb891159
parent 2856 451ac4260963
child 2864 dcbed0d35466
Removing cruft
src/sync_actions.c
src/sync_impl.c
     1.1 --- a/src/sync_actions.c	Fri Aug 17 15:23:08 2018 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,434 +0,0 @@
     1.4 -// This file is under GNU General Public License 3.0
     1.5 -// see LICENSE.txt
     1.6 -
     1.7 -#include "pEp_internal.h"
     1.8 -#include "map_asn1.h"
     1.9 -
    1.10 -#include "Sync_impl.h"
    1.11 -#include "KeySync_fsm.h"
    1.12 -
    1.13 -PEP_STATUS deviceGrouped(PEP_SESSION session, bool *result)
    1.14 -{
    1.15 -    assert(session && result);
    1.16 -    if (!(session && result))
    1.17 -        return PEP_ILLEGAL_VALUE;
    1.18 -
    1.19 -    static const char *sql = "select count(*) from identity where user_id = '"PEP_OWN_USERID"' and (flags & 4) = 4;";
    1.20 -    static const size_t len = sizeof("select count(*) from identity where user_id = '"PEP_OWN_USERID"' and (flags & 4) = 4;");
    1.21 -    sqlite3_stmt *_sql;
    1.22 -    int int_result = sqlite3_prepare_v2(session->db, sql, (int) len, &_sql, NULL);
    1.23 -    assert(int_result == SQLITE_OK);
    1.24 -    if (!(int_result == SQLITE_OK))
    1.25 -        return PEP_UNKNOWN_ERROR;
    1.26 -
    1.27 -    int _result = 0;
    1.28 -    int_result = sqlite3_step(_sql);
    1.29 -    assert(int_result == SQLITE_ROW);
    1.30 -    if (int_result == SQLITE_ROW)
    1.31 -        _result = sqlite3_column_int(_sql, 0);
    1.32 -    sqlite3_finalize(_sql);
    1.33 -    if (int_result != SQLITE_ROW)
    1.34 -        return PEP_UNKNOWN_ERROR;
    1.35 -
    1.36 -    *result = _result > 0;
    1.37 -
    1.38 -    return PEP_STATUS_OK;
    1.39 -}
    1.40 -
    1.41 -PEP_STATUS challengeAccepted(PEP_SESSION session, bool *result)
    1.42 -{
    1.43 -    assert(session && result);
    1.44 -    if (!(session && result))
    1.45 -        return PEP_ILLEGAL_VALUE;
    1.46 -
    1.47 -    TID_t *t1 = &session->sync_state.keysync.challenge;
    1.48 -    TID_t *t2 = &session->own_sync_state.challenge;
    1.49 -
    1.50 -    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.51 -
    1.52 -    return PEP_STATUS_OK;
    1.53 -}
    1.54 -
    1.55 -PEP_STATUS partnerIsGrouped(PEP_SESSION session, bool *result)
    1.56 -{
    1.57 -    assert(session && result);
    1.58 -    if (!(session && result))
    1.59 -        return PEP_ILLEGAL_VALUE;
    1.60 -
    1.61 -    *result = session->sync_state.keysync.is_group;
    1.62 -
    1.63 -    return PEP_STATUS_OK;
    1.64 -}
    1.65 -
    1.66 -PEP_STATUS keyElectionWon(PEP_SESSION session, bool *result)
    1.67 -{
    1.68 -    assert(session && result);
    1.69 -    if (!(session && result))
    1.70 -        return PEP_ILLEGAL_VALUE;
    1.71 -
    1.72 -    pEp_identity *from = session->sync_state.common.from;
    1.73 -
    1.74 -    assert(from && from->fpr && from->fpr[0] && from->address && from->address[0]);
    1.75 -    if (!(from && from->fpr && from->fpr[0] && from->address && from->address[0]))
    1.76 -        return PEP_ILLEGAL_VALUE;
    1.77 -
    1.78 -    pEp_identity *me = NULL;
    1.79 -    PEP_STATUS status = get_identity(session, from->address, PEP_OWN_USERID, &me);
    1.80 -    assert(status == PEP_STATUS_OK);
    1.81 -    if (status)
    1.82 -        return status;
    1.83 -
    1.84 -    assert(me->fpr && me->fpr[0]);
    1.85 -    if (!(me->fpr && me->fpr[0])) {
    1.86 -        free_identity(me);
    1.87 -        return PEP_ILLEGAL_VALUE;
    1.88 -    }
    1.89 -
    1.90 -    size_t len = MIN(strlen(from->fpr), strlen(me->fpr));
    1.91 -    *result = strncasecmp(from->fpr, me->fpr, len) > 0;
    1.92 -    free_identity(me);
    1.93 -
    1.94 -    return PEP_STATUS_OK;
    1.95 -}
    1.96 -
    1.97 -PEP_STATUS closeHandshakeDialog(PEP_SESSION session)
    1.98 -{
    1.99 -    assert(session);
   1.100 -    if (!session)
   1.101 -        return PEP_ILLEGAL_VALUE;
   1.102 -
   1.103 -    assert(session->notifyHandshake);
   1.104 -    if (!session->notifyHandshake)
   1.105 -        return PEP_SYNC_NO_NOTIFY_CALLBACK;
   1.106 -
   1.107 -    PEP_STATUS status = session->notifyHandshake(
   1.108 -            session->sync_management, NULL, NULL, SYNC_NOTIFY_OVERTAKEN);
   1.109 -    if (status)
   1.110 -        return status;
   1.111 -
   1.112 -    return PEP_STATUS_OK;
   1.113 -}
   1.114 -
   1.115 -PEP_STATUS clearState(PEP_SESSION session)
   1.116 -{
   1.117 -    assert(session);
   1.118 -    if (!session)
   1.119 -        return PEP_ILLEGAL_VALUE;
   1.120 -
   1.121 -    free_Sync_state(session);
   1.122 -
   1.123 -    return PEP_STATUS_OK;
   1.124 -}
   1.125 -
   1.126 -PEP_STATUS openChallenge(PEP_SESSION session)
   1.127 -{
   1.128 -    assert(session);
   1.129 -    if (!session)
   1.130 -        return PEP_ILLEGAL_VALUE;
   1.131 -
   1.132 -    pEpUUID c;
   1.133 -    uuid_generate_random(c);
   1.134 -
   1.135 -    OCTET_STRING_fromBuf(&session->own_sync_state.challenge, (char *) c, 16);
   1.136 -
   1.137 -    return PEP_STATUS_OK;
   1.138 -}
   1.139 -
   1.140 -PEP_STATUS storeChallenge(PEP_SESSION session)
   1.141 -{
   1.142 -    assert(session);
   1.143 -    if (!session)
   1.144 -        return PEP_ILLEGAL_VALUE;
   1.145 -
   1.146 -    TID_t *src = &session->sync_state.keysync.challenge;
   1.147 -    TID_t *dst = &session->own_sync_state.challenge;
   1.148 -
   1.149 -    assert(src->size == 16);
   1.150 -    if (!(src->size == 16))
   1.151 -        return PEP_UNKNOWN_ERROR;
   1.152 -
   1.153 -    OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
   1.154 -
   1.155 -    return PEP_STATUS_OK;
   1.156 -}
   1.157 -
   1.158 -PEP_STATUS openTransaction(PEP_SESSION session)
   1.159 -{
   1.160 -    assert(session);
   1.161 -    if (!session)
   1.162 -        return PEP_ILLEGAL_VALUE;
   1.163 -
   1.164 -    pEpUUID c;
   1.165 -    uuid_generate_random(c);
   1.166 -
   1.167 -    OCTET_STRING_fromBuf(&session->own_sync_state.transaction, (char *) c, 16);
   1.168 -
   1.169 -    return PEP_STATUS_OK;
   1.170 -}
   1.171 -
   1.172 -PEP_STATUS storeTransaction(PEP_SESSION session)
   1.173 -{
   1.174 -    assert(session);
   1.175 -    if (!session)
   1.176 -        return PEP_ILLEGAL_VALUE;
   1.177 -
   1.178 -    TID_t *src = &session->sync_state.keysync.transaction;
   1.179 -    TID_t *dst =  &session->own_sync_state.transaction;
   1.180 -
   1.181 -    assert(src->size == 16);
   1.182 -    if (!(src->size == 16))
   1.183 -        return PEP_UNKNOWN_ERROR;
   1.184 -
   1.185 -    OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
   1.186 -
   1.187 -    return PEP_STATUS_OK;
   1.188 -}
   1.189 -
   1.190 -PEP_STATUS showSoleHandshake(PEP_SESSION session)
   1.191 -{
   1.192 -    assert(session);
   1.193 -    if (!session)
   1.194 -        return PEP_ILLEGAL_VALUE;
   1.195 -
   1.196 -    assert(session->notifyHandshake);
   1.197 -    if (!session->notifyHandshake)
   1.198 -        return PEP_SYNC_NO_NOTIFY_CALLBACK;
   1.199 - 
   1.200 -    assert(session->sync_state.common.from);
   1.201 -    if (!session->sync_state.common.from)
   1.202 -        return PEP_ILLEGAL_VALUE;
   1.203 -
   1.204 -    pEp_identity *from = session->sync_state.common.from;
   1.205 -    pEp_identity *me = NULL;
   1.206 -    PEP_STATUS status = get_identity(session, from->address, PEP_OWN_USERID, &me);
   1.207 -    assert(status == PEP_STATUS_OK);
   1.208 -    if (status)
   1.209 -        return status;
   1.210 -
   1.211 -    assert(me->fpr && me->fpr[0]);
   1.212 -    if (!(me->fpr && me->fpr[0])) {
   1.213 -        free_identity(me);
   1.214 -        return PEP_ILLEGAL_VALUE;
   1.215 -    }
   1.216 -
   1.217 -    pEp_identity *partner = identity_dup(from);
   1.218 -    if (!partner) {
   1.219 -        free_identity(me);
   1.220 -        return PEP_OUT_OF_MEMORY;
   1.221 -    }
   1.222 -
   1.223 -    status = session->notifyHandshake(session->sync_management, me,
   1.224 -            partner, SYNC_NOTIFY_INIT_FORM_GROUP);
   1.225 -    if (status)
   1.226 -        return status;
   1.227 -
   1.228 -    return PEP_STATUS_OK;
   1.229 -}
   1.230 -
   1.231 -PEP_STATUS disable(PEP_SESSION session)
   1.232 -{
   1.233 -    assert(session);
   1.234 -    if (!session)
   1.235 -        return PEP_ILLEGAL_VALUE;
   1.236 -
   1.237 -
   1.238 -    return PEP_STATUS_OK;
   1.239 -}
   1.240 -
   1.241 -PEP_STATUS saveGroupKeys(PEP_SESSION session)
   1.242 -{
   1.243 -    assert(session);
   1.244 -    if (!session)
   1.245 -        return PEP_ILLEGAL_VALUE;
   1.246 -
   1.247 -    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.identities, NULL);
   1.248 -    if (!il)
   1.249 -        return PEP_OUT_OF_MEMORY;
   1.250 -    
   1.251 -    // BUG: this should be a transaction and been rolled back completely on error
   1.252 -    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
   1.253 -        PEP_STATUS status = set_identity(session, _il->ident);
   1.254 -        if (status) {
   1.255 -            free_identity_list(il);
   1.256 -            return status;
   1.257 -        }
   1.258 -    }
   1.259 -
   1.260 -    free_identity_list(il);
   1.261 -
   1.262 -    return PEP_STATUS_OK;
   1.263 -}
   1.264 -
   1.265 -PEP_STATUS ownKeysAreGroupKeys(PEP_SESSION session)
   1.266 -{
   1.267 -    assert(session);
   1.268 -    if (!session)
   1.269 -        return PEP_ILLEGAL_VALUE;
   1.270 -
   1.271 -    static const char *sql = "select fpr, username, comm_type, lang,"
   1.272 -        "   identity.flags | pgp_keypair.flags"
   1.273 -        "   from identity"
   1.274 -        "   join person on id = identity.user_id"
   1.275 -        "   join pgp_keypair on fpr = identity.main_key_id"
   1.276 -        "   join trust on id = trust.user_id"
   1.277 -        "       and pgp_keypair_fpr = identity.main_key_id"
   1.278 -        "   where identity.user_id = '" PEP_OWN_USERID "';";
   1.279 -    static const size_t len = sizeof("select fpr, username, comm_type, lang,"
   1.280 -        "   identity.flags | pgp_keypair.flags"
   1.281 -        "   from identity"
   1.282 -        "   join person on id = identity.user_id"
   1.283 -        "   join pgp_keypair on fpr = identity.main_key_id"
   1.284 -        "   join trust on id = trust.user_id"
   1.285 -        "       and pgp_keypair_fpr = identity.main_key_id"
   1.286 -        "   where identity.user_id = '" PEP_OWN_USERID "';");
   1.287 -    sqlite3_stmt *_sql;
   1.288 -    int int_result = sqlite3_prepare_v2(session->db, sql, (int) len, &_sql, NULL);
   1.289 -    assert(int_result == SQLITE_OK);
   1.290 -    if (!(int_result == SQLITE_OK))
   1.291 -        return PEP_UNKNOWN_ERROR;
   1.292 -
   1.293 -    identity_list *il = new_identity_list(NULL);
   1.294 -    if (!il)
   1.295 -        return PEP_OUT_OF_MEMORY;
   1.296 -
   1.297 -    pEp_identity *from = session->sync_state.common.from;
   1.298 -    identity_list *_il = il;
   1.299 -
   1.300 -    int result;
   1.301 -    do {
   1.302 -        result = sqlite3_step(_sql);
   1.303 -        pEp_identity *_identity = NULL;
   1.304 -        switch (result) {
   1.305 -        case SQLITE_ROW:
   1.306 -            _identity = new_identity(
   1.307 -                    from->address,
   1.308 -                    (const char *) sqlite3_column_text(_sql, 0),
   1.309 -                    from->user_id,
   1.310 -                    (const char *) sqlite3_column_text(_sql, 1)
   1.311 -                    );
   1.312 -            assert(_identity);
   1.313 -            if (_identity == NULL)
   1.314 -                return PEP_OUT_OF_MEMORY;
   1.315 -
   1.316 -            _identity->comm_type = (PEP_comm_type)
   1.317 -                sqlite3_column_int(_sql, 2);
   1.318 -            const char* const _lang = (const char *)
   1.319 -                sqlite3_column_text(_sql, 3);
   1.320 -            if (_lang && _lang[0]) {
   1.321 -                assert(_lang[0] >= 'a' && _lang[0] <= 'z');
   1.322 -                assert(_lang[1] >= 'a' && _lang[1] <= 'z');
   1.323 -                assert(_lang[2] == 0);
   1.324 -                _identity->lang[0] = _lang[0];
   1.325 -                _identity->lang[1] = _lang[1];
   1.326 -                _identity->lang[2] = 0;
   1.327 -            }
   1.328 -            _identity->flags = (unsigned int)
   1.329 -                sqlite3_column_int(_sql, 4);
   1.330 -
   1.331 -            _il = identity_list_add(_il, _identity);
   1.332 -            if (!_il) {
   1.333 -                free_identity_list(il);
   1.334 -                free_identity(_identity);
   1.335 -                return PEP_OUT_OF_MEMORY;
   1.336 -            }
   1.337 -            break;
   1.338 -
   1.339 -        case SQLITE_DONE:
   1.340 -            break;
   1.341 -
   1.342 -        default:
   1.343 -            free_identity_list(il);
   1.344 -            return PEP_UNKNOWN_ERROR;
   1.345 -        }
   1.346 -    } while (result != SQLITE_DONE);
   1.347 -
   1.348 -    IdentityList_t *r = IdentityList_from_identity_list(il, &session->sync_state.keysync.identities);
   1.349 -    free_identity_list(il);
   1.350 -    if (!r)
   1.351 -        return PEP_OUT_OF_MEMORY;
   1.352 -
   1.353 -    return PEP_STATUS_OK;
   1.354 -}
   1.355 -
   1.356 -PEP_STATUS showJoinGroupHandshake(PEP_SESSION session)
   1.357 -{
   1.358 -    assert(session);
   1.359 -    if (!session)
   1.360 -        return PEP_ILLEGAL_VALUE;
   1.361 -
   1.362 -    assert(session->notifyHandshake);
   1.363 -    if (!session->notifyHandshake)
   1.364 -        return PEP_SYNC_NO_NOTIFY_CALLBACK;
   1.365 - 
   1.366 -    assert(session->sync_state.common.from);
   1.367 -    if (!session->sync_state.common.from)
   1.368 -        return PEP_ILLEGAL_VALUE;
   1.369 -
   1.370 -    pEp_identity *from = session->sync_state.common.from;
   1.371 -    pEp_identity *me = NULL;
   1.372 -    PEP_STATUS status = get_identity(session, from->address, PEP_OWN_USERID, &me);
   1.373 -    assert(status == PEP_STATUS_OK);
   1.374 -    if (status)
   1.375 -        return status;
   1.376 -
   1.377 -    assert(me->fpr && me->fpr[0]);
   1.378 -    if (!(me->fpr && me->fpr[0])) {
   1.379 -        free_identity(me);
   1.380 -        return PEP_ILLEGAL_VALUE;
   1.381 -    }
   1.382 -
   1.383 -    pEp_identity *partner = identity_dup(from);
   1.384 -    if (!partner) {
   1.385 -        free_identity(me);
   1.386 -        return PEP_OUT_OF_MEMORY;
   1.387 -    }
   1.388 -
   1.389 -    status = session->notifyHandshake(session->sync_management, me,
   1.390 -            partner, SYNC_NOTIFY_INIT_ADD_OUR_DEVICE);
   1.391 -    if (status)
   1.392 -        return status;
   1.393 -
   1.394 -    return PEP_STATUS_OK;
   1.395 -}
   1.396 -
   1.397 -PEP_STATUS showGroupedHandshake(PEP_SESSION session)
   1.398 -{
   1.399 -    assert(session);
   1.400 -    if (!session)
   1.401 -        return PEP_ILLEGAL_VALUE;
   1.402 -
   1.403 -    assert(session->notifyHandshake);
   1.404 -    if (!session->notifyHandshake)
   1.405 -        return PEP_SYNC_NO_NOTIFY_CALLBACK;
   1.406 - 
   1.407 -    assert(session->sync_state.common.from);
   1.408 -    if (!session->sync_state.common.from)
   1.409 -        return PEP_ILLEGAL_VALUE;
   1.410 -
   1.411 -    pEp_identity *from = session->sync_state.common.from;
   1.412 -    pEp_identity *me = NULL;
   1.413 -    PEP_STATUS status = get_identity(session, from->address, PEP_OWN_USERID, &me);
   1.414 -    assert(status == PEP_STATUS_OK);
   1.415 -    if (status)
   1.416 -        return status;
   1.417 -
   1.418 -    assert(me->fpr && me->fpr[0]);
   1.419 -    if (!(me->fpr && me->fpr[0])) {
   1.420 -        free_identity(me);
   1.421 -        return PEP_ILLEGAL_VALUE;
   1.422 -    }
   1.423 -
   1.424 -    pEp_identity *partner = identity_dup(from);
   1.425 -    if (!partner) {
   1.426 -        free_identity(me);
   1.427 -        return PEP_OUT_OF_MEMORY;
   1.428 -    }
   1.429 -
   1.430 -    status = session->notifyHandshake(session->sync_management, me,
   1.431 -            partner, SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE);
   1.432 -    if (status)
   1.433 -        return status;
   1.434 -
   1.435 -    return PEP_STATUS_OK;
   1.436 -}
   1.437 -
     2.1 --- a/src/sync_impl.c	Fri Aug 17 15:23:08 2018 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,228 +0,0 @@
     2.4 -// This file is under GNU General Public License 3.0
     2.5 -// see LICENSE.txt
     2.6 -
     2.7 -#include "Sync_impl.h"
     2.8 -#include "pEp_internal.h"
     2.9 -#include "Sync_event.h"
    2.10 -#include "Sync_codec.h"
    2.11 -#include "baseprotocol.h"
    2.12 -#include "KeySync_fsm.h"
    2.13 -
    2.14 -PEP_STATUS Sync_driver(
    2.15 -        PEP_SESSION session,
    2.16 -        Sync_PR fsm,
    2.17 -        int event
    2.18 -    )
    2.19 -{
    2.20 -    assert(session && fsm);
    2.21 -    if (!(session && fsm))
    2.22 -        return PEP_ILLEGAL_VALUE;
    2.23 -
    2.24 -    int next_state = None;
    2.25 -    do {
    2.26 -        switch (fsm) {
    2.27 -            case Sync_PR_keysync: {
    2.28 -                int state = session->sync_state.keysync.state;
    2.29 -                next_state = fsm_KeySync(session, state, event);
    2.30 -                if (next_state > None) {
    2.31 -                    session->sync_state.keysync.state = next_state;
    2.32 -                    event = Init;
    2.33 -                }
    2.34 -                else if (next_state < None) {
    2.35 -                    return PEP_STATEMACHINE_ERROR - state;
    2.36 -                }
    2.37 -                break;
    2.38 -            }
    2.39 -            
    2.40 -            default:
    2.41 -                return PEP_ILLEGAL_VALUE;
    2.42 -        }
    2.43 -    }  while (next_state);
    2.44 -
    2.45 -    return PEP_STATUS_OK;
    2.46 -}
    2.47 -
    2.48 -PEP_STATUS inject_Sync_event(
    2.49 -        PEP_SESSION session, 
    2.50 -        Sync_PR fsm,
    2.51 -        int event
    2.52 -    )
    2.53 -{
    2.54 -    Sync_t *msg = NULL;
    2.55 -    Sync_event_t *ev = NULL;
    2.56 -
    2.57 -    assert(session && fsm > 0 && event > None);
    2.58 -    if (!(session && fsm > 0 && event > None))
    2.59 -        return PEP_ILLEGAL_VALUE;
    2.60 -
    2.61 -    PEP_STATUS status = PEP_STATUS_OK;
    2.62 -
    2.63 -    if (!session->inject_sync_event) {
    2.64 -       status = PEP_SYNC_NO_INJECT_CALLBACK;
    2.65 -       goto error;
    2.66 -    }
    2.67 -
    2.68 -    if (event < Extra) {
    2.69 -        msg = new_Sync_message(fsm, event);
    2.70 -        if (!msg) {
    2.71 -            status = PEP_OUT_OF_MEMORY;
    2.72 -            goto error;
    2.73 -        }
    2.74 -
    2.75 -        status = update_Sync_message(session, msg);
    2.76 -        if (status)
    2.77 -            goto error;
    2.78 -    }
    2.79 -
    2.80 -    ev = (Sync_event_t *) calloc(1, sizeof(Sync_event_t));
    2.81 -    assert(ev);
    2.82 -    if (!ev) {
    2.83 -        status = PEP_OUT_OF_MEMORY;
    2.84 -        goto error;
    2.85 -    }
    2.86 -    
    2.87 -    ev->fsm = fsm;
    2.88 -    ev->event = event;
    2.89 -    ev->msg = msg;
    2.90 -
    2.91 -    int result = session->inject_sync_event(ev,
    2.92 -            session->sync_management);
    2.93 -    if (result) {
    2.94 -        status = PEP_STATEMACHINE_ERROR;
    2.95 -        goto error;
    2.96 -    }
    2.97 -
    2.98 -    goto the_end;
    2.99 -
   2.100 -error:
   2.101 -    free(ev);
   2.102 -    free_Sync_message(msg);
   2.103 -
   2.104 -the_end:
   2.105 -    return status;
   2.106 -}
   2.107 -
   2.108 -PEP_STATUS Sync_notify(
   2.109 -        PEP_SESSION session, 
   2.110 -        Sync_PR fsm,
   2.111 -        int message_type
   2.112 -    )
   2.113 -{
   2.114 -    assert(session && fsm > 0 && message_type > 1 && message_type < Extra);
   2.115 -    if (!(session && fsm > 0 && message_type > 1 && message_type < Extra))
   2.116 -        return PEP_ILLEGAL_VALUE;
   2.117 -
   2.118 -    PEP_STATUS status = PEP_STATUS_OK;
   2.119 -
   2.120 -    Sync_t *msg = new_Sync_message(fsm, message_type);
   2.121 -    if (!msg) {
   2.122 -        status = PEP_OUT_OF_MEMORY;
   2.123 -        goto error;
   2.124 -    }
   2.125 -
   2.126 -    status = update_Sync_message(session, msg);
   2.127 -    if (status)
   2.128 -        goto error;
   2.129 -
   2.130 -    goto the_end;
   2.131 -
   2.132 -error:
   2.133 -    free_Sync_message(msg);
   2.134 -
   2.135 -the_end:
   2.136 -    return status;
   2.137 -}
   2.138 -
   2.139 -PEP_STATUS send_Sync_message(
   2.140 -        PEP_SESSION session, 
   2.141 -        Sync_PR fsm,
   2.142 -        int message_type
   2.143 -    )
   2.144 -{
   2.145 -    PEP_STATUS status = PEP_STATUS_OK;
   2.146 -
   2.147 -    assert(session && fsm > None && message_type > None);
   2.148 -    if (!(session && fsm > None && message_type > None))
   2.149 -        return PEP_ILLEGAL_VALUE;
   2.150 -    
   2.151 -    Sync_t *msg = new_Sync_message(fsm, message_type);
   2.152 -    if (!msg)
   2.153 -        return PEP_OUT_OF_MEMORY;
   2.154 -
   2.155 -    char *data = NULL;
   2.156 -    message *m = NULL;
   2.157 -
   2.158 -    status = update_Sync_message(session, msg);
   2.159 -    if (status)
   2.160 -        goto the_end;
   2.161 -
   2.162 -    size_t size = 0;
   2.163 -    status = encode_Sync_message(msg, &data, &size);
   2.164 -    if (status)
   2.165 -        goto the_end;
   2.166 -
   2.167 -    status = base_prepare_message(
   2.168 -            session->sync_state.common.from,
   2.169 -            session->sync_state.common.from,
   2.170 -            data,
   2.171 -            size,
   2.172 -            &m
   2.173 -        );
   2.174 -    if (status)
   2.175 -        goto the_end;
   2.176 -    
   2.177 -    status = session->messageToSend(session->sync_obj, m);
   2.178 -
   2.179 -the_end:
   2.180 -    free_message(m);
   2.181 -    free(data);
   2.182 -    free_Sync_message(msg);
   2.183 -    return status;
   2.184 -}
   2.185 -
   2.186 -PEP_STATUS recv_Sync_event(
   2.187 -        PEP_SESSION session,
   2.188 -        Sync_event_t *ev
   2.189 -    )
   2.190 -{
   2.191 -    assert(session && ev);
   2.192 -    if (!(session && ev))
   2.193 -        return PEP_ILLEGAL_VALUE;
   2.194 -
   2.195 -    PEP_STATUS status = PEP_STATUS_OK;
   2.196 -
   2.197 -    if (ev->event < Extra) {
   2.198 -        Sync_PR fsm = (int) None;
   2.199 -        int event = None;
   2.200 -
   2.201 -        status = update_Sync_state(session, ev->msg, &fsm, &event);
   2.202 -        if (status)
   2.203 -            goto error;
   2.204 -
   2.205 -        if (ev->fsm) {
   2.206 -            if (ev->fsm != fsm || ev->event != event) {
   2.207 -                status = PEP_SYNC_ILLEGAL_MESSAGE;
   2.208 -                goto error;
   2.209 -            }
   2.210 -        }
   2.211 -        else {
   2.212 -            if (ev->event) {
   2.213 -                status = PEP_SYNC_ILLEGAL_MESSAGE;
   2.214 -                goto error;
   2.215 -            }
   2.216 -            ev->fsm = fsm;
   2.217 -            ev->event = event;
   2.218 -        }
   2.219 -    }
   2.220 -
   2.221 -    free_Sync_message(ev->msg);
   2.222 -    free(ev);
   2.223 -    status = Sync_driver(session, ev->fsm, ev->event);
   2.224 -    return status;
   2.225 -
   2.226 -error:
   2.227 -    free_Sync_message(ev->msg);
   2.228 -    free(ev);
   2.229 -    return status;
   2.230 -}
   2.231 -