removed parameter assert checks ENGINE-781
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 05 Aug 2020 14:23:44 +0200
branchENGINE-781
changeset 4925843b9f8ee201
parent 4922 32a5d2ca9691
child 4926 19b16c61fdd8
removed parameter assert checks
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
test/src/Engine.cc
test/src/SyncTest.cc
     1.1 --- a/src/pEpEngine.c	Fri Jul 31 21:10:17 2020 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Aug 05 14:23:44 2020 +0200
     1.3 @@ -538,9 +538,6 @@
     1.4          
     1.5  static int user_version(void *_version, int count, char **text, char **name)
     1.6  {
     1.7 -    assert(_version);
     1.8 -    assert(count == 1);
     1.9 -    assert(text && text[0]);
    1.10      if (!(_version && count == 1 && text && text[0]))
    1.11          return -1;
    1.12  
    1.13 @@ -984,7 +981,6 @@
    1.14      // client session, or by using synchronization primitive to protect
    1.15      // creation/deletion of first/last session from the app.
    1.16  
    1.17 -    assert(session);
    1.18      if (session == NULL)
    1.19          return PEP_ILLEGAL_VALUE;
    1.20  
    1.21 @@ -1000,10 +996,6 @@
    1.22      _session->inject_sync_event = inject_sync_event;
    1.23      _session->ensure_passphrase = ensure_passphrase;
    1.24      
    1.25 -#ifdef DEBUG_ERRORSTACK
    1.26 -    _session->errorstack = new_stringlist("init()");
    1.27 -#endif
    1.28 -
    1.29      assert(LOCAL_DB);
    1.30      if (LOCAL_DB == NULL) {
    1.31          status = PEP_INIT_CANNOT_OPEN_DB;
    1.32 @@ -2130,10 +2122,7 @@
    1.33      bool out_last = false;
    1.34      int _count = --init_count;
    1.35      
    1.36 -    assert(_count >= -1);
    1.37 -    assert(session);
    1.38 -
    1.39 -    if (!((_count >= -1) && session))
    1.40 +    if ((_count < -1) || !session)
    1.41          return;
    1.42  
    1.43      // a small race condition but still a race condition
    1.44 @@ -2310,9 +2299,6 @@
    1.45          release_transport_system(session, out_last);
    1.46          release_cryptotech(session, out_last);
    1.47  
    1.48 -#ifdef DEBUG_ERRORSTACK
    1.49 -        free_stringlist(session->errorstack);
    1.50 -#endif
    1.51          free(session);
    1.52      }
    1.53  }
    1.54 @@ -2404,11 +2390,7 @@
    1.55      session->service_log = true;
    1.56  
    1.57      int result;
    1.58 -    
    1.59 -    assert(session);
    1.60 -    assert(title);
    1.61 -    assert(entity);
    1.62 -    
    1.63 +        
    1.64      if (!(session && title && entity))
    1.65          return PEP_ILLEGAL_VALUE;
    1.66      
    1.67 @@ -2438,7 +2420,6 @@
    1.68          const char *comment
    1.69      )
    1.70  {
    1.71 -    assert(session);
    1.72      if (!session)
    1.73          return PEP_ILLEGAL_VALUE;
    1.74  
    1.75 @@ -2455,10 +2436,6 @@
    1.76  {
    1.77      PEP_STATUS status = PEP_STATUS_OK;
    1.78  
    1.79 -    assert(session);
    1.80 -    assert(word);
    1.81 -    assert(wsize);
    1.82 -
    1.83      if (!(session && word && wsize))
    1.84          return PEP_ILLEGAL_VALUE;
    1.85  
    1.86 @@ -2468,6 +2445,7 @@
    1.87      if (lang == NULL)
    1.88          lang = "en";
    1.89  
    1.90 +    // FIXME: should this not be an actual check???
    1.91      assert((lang[0] >= 'A' && lang[0] <= 'Z')
    1.92              || (lang[0] >= 'a' && lang[0] <= 'z'));
    1.93      assert((lang[1] >= 'A' && lang[1] <= 'Z')
    1.94 @@ -2500,12 +2478,6 @@
    1.95  {
    1.96      const char *source = fingerprint;
    1.97  
    1.98 -    assert(session);
    1.99 -    assert(fingerprint);
   1.100 -    assert(words);
   1.101 -    assert(wsize);
   1.102 -    assert(max_words >= 0);
   1.103 -
   1.104      if (!(session && fingerprint && words && wsize && max_words >= 0))
   1.105          return PEP_ILLEGAL_VALUE;
   1.106  
   1.107 @@ -2523,6 +2495,7 @@
   1.108      if (!lang || !lang[0])
   1.109          lang = "en";
   1.110  
   1.111 +    // FIXME: Should this not be an actual check?
   1.112      assert((lang[0] >= 'A' && lang[0] <= 'Z')
   1.113              || (lang[0] >= 'a' && lang[0] <= 'z'));
   1.114      assert((lang[1] >= 'A' && lang[1] <= 'Z')
   1.115 @@ -2588,7 +2561,6 @@
   1.116      )
   1.117  {
   1.118      pEp_identity *result = calloc(1, sizeof(pEp_identity));
   1.119 -    assert(result);
   1.120      if (result) {
   1.121          if (address) {
   1.122              result->address = strdup(address);
   1.123 @@ -2628,23 +2600,23 @@
   1.124  
   1.125  pEp_identity *identity_dup(const pEp_identity *src)
   1.126  {
   1.127 -    assert(src);
   1.128 -
   1.129 -    pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id,
   1.130 -            src->username);
   1.131 -    assert(dup);
   1.132 -    if (dup == NULL)
   1.133 -        return NULL;
   1.134 -    
   1.135 -    dup->comm_type = src->comm_type;
   1.136 -    dup->lang[0] = src->lang[0];
   1.137 -    dup->lang[1] = src->lang[1];
   1.138 -    dup->lang[2] = 0;
   1.139 -    dup->flags = src->flags;
   1.140 -    dup->me = src->me;
   1.141 -    dup->major_ver = src->major_ver;
   1.142 -    dup->minor_ver = src->minor_ver;
   1.143 -    
   1.144 +    pEp_identity* dup = NULL;
   1.145 +    if (src) {
   1.146 +        dup = new_identity(src->address, src->fpr, src->user_id,
   1.147 +                src->username);
   1.148 +        assert(dup);
   1.149 +        if (dup == NULL)
   1.150 +            return NULL;
   1.151 +        
   1.152 +        dup->comm_type = src->comm_type;
   1.153 +        dup->lang[0] = src->lang[0];
   1.154 +        dup->lang[1] = src->lang[1];
   1.155 +        dup->lang[2] = 0;
   1.156 +        dup->flags = src->flags;
   1.157 +        dup->me = src->me;
   1.158 +        dup->major_ver = src->major_ver;
   1.159 +        dup->minor_ver = src->minor_ver;
   1.160 +    }    
   1.161      return dup;
   1.162  }
   1.163  
   1.164 @@ -2664,8 +2636,6 @@
   1.165          char** userid
   1.166      )
   1.167  {
   1.168 -    assert(session);
   1.169 -    assert(userid);
   1.170      
   1.171      if (!session || !userid)
   1.172          return PEP_ILLEGAL_VALUE;
   1.173 @@ -2708,11 +2678,6 @@
   1.174          const char* alias_id,
   1.175          char** default_id) {
   1.176              
   1.177 -    assert(session);
   1.178 -    assert(alias_id);
   1.179 -    assert(alias_id[0]);
   1.180 -    assert(default_id);
   1.181 -
   1.182      if (!(session && alias_id && alias_id[0] && default_id))
   1.183          return PEP_ILLEGAL_VALUE;
   1.184  
   1.185 @@ -2753,10 +2718,6 @@
   1.186              
   1.187      int result;
   1.188  
   1.189 -    assert(session);
   1.190 -    assert(default_id);
   1.191 -    assert(alias_id);
   1.192 -
   1.193      if (!(session && default_id && alias_id && 
   1.194            default_id[0] != '\0' && alias_id[0] != '\0'))
   1.195          return PEP_ILLEGAL_VALUE;
   1.196 @@ -2792,11 +2753,6 @@
   1.197      PEP_STATUS status = PEP_STATUS_OK;
   1.198      pEp_identity *_identity = NULL;
   1.199  
   1.200 -    assert(session);
   1.201 -    assert(address);
   1.202 -    assert(address[0]);
   1.203 -    assert(identity);
   1.204 -
   1.205      if (!(session && address && address[0] && identity))
   1.206          return PEP_ILLEGAL_VALUE;
   1.207  
   1.208 @@ -3021,11 +2977,6 @@
   1.209      PEP_STATUS status = PEP_STATUS_OK;
   1.210      pEp_identity *_identity = NULL;
   1.211  
   1.212 -    assert(session);
   1.213 -    assert(address);
   1.214 -    assert(address[0]);
   1.215 -    assert(identity);
   1.216 -
   1.217      if (!(session && address && address[0] && identity))
   1.218          return PEP_ILLEGAL_VALUE;
   1.219  
   1.220 @@ -3090,10 +3041,6 @@
   1.221          identity_list** id_list
   1.222      )
   1.223  {
   1.224 -    assert(session);
   1.225 -    assert(address);
   1.226 -    assert(address[0]);
   1.227 -    assert(id_list);
   1.228  
   1.229      if (!(session && address && address[0] && id_list))
   1.230          return PEP_ILLEGAL_VALUE;
   1.231 @@ -3161,11 +3108,7 @@
   1.232  
   1.233  PEP_STATUS exists_identity_entry(PEP_SESSION session, pEp_identity* identity,
   1.234                                   bool* exists) {
   1.235 -    assert(session);
   1.236 -    assert(identity);
   1.237 -    assert(!EMPTYSTR(identity->user_id));        
   1.238 -    assert(!EMPTYSTR(identity->address));
   1.239 -    if (!session || !exists || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->address))
   1.240 +    if (!session || !exists || !identity || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->address))
   1.241          return PEP_ILLEGAL_VALUE;
   1.242      
   1.243      *exists = false;
   1.244 @@ -3196,11 +3139,7 @@
   1.245  
   1.246  PEP_STATUS exists_trust_entry(PEP_SESSION session, pEp_identity* identity,
   1.247                                bool* exists) {
   1.248 -    assert(session);
   1.249 -    assert(identity);
   1.250 -    assert(!EMPTYSTR(identity->user_id));        
   1.251 -    assert(!EMPTYSTR(identity->fpr));
   1.252 -    if (!session || !exists || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
   1.253 +    if (!session || !exists || !identity || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
   1.254          return PEP_ILLEGAL_VALUE;
   1.255      
   1.256      *exists = false;
   1.257 @@ -3271,11 +3210,6 @@
   1.258  static PEP_STATUS _set_or_update_trust(PEP_SESSION session,
   1.259                                         pEp_identity* identity,
   1.260                                         sqlite3_stmt* set_or_update) {
   1.261 -
   1.262 -    assert(session);
   1.263 -    assert(identity);
   1.264 -    assert(identity->user_id);
   1.265 -    assert(identity->fpr);
   1.266      
   1.267      if (!session || !identity || EMPTYSTR(identity->user_id) || EMPTYSTR(identity->fpr))
   1.268          return PEP_ILLEGAL_VALUE;
   1.269 @@ -3304,9 +3238,6 @@
   1.270  static PEP_STATUS _set_or_update_identity_entry(PEP_SESSION session,
   1.271                                                  pEp_identity* identity,
   1.272                                                  sqlite3_stmt* set_or_update) {
   1.273 -    assert(session);
   1.274 -    assert(identity);
   1.275 -    assert(set_or_update);
   1.276                        
   1.277      if (!session || !identity || !identity->user_id || !identity->address)
   1.278          return PEP_ILLEGAL_VALUE;
   1.279 @@ -3334,9 +3265,6 @@
   1.280  static PEP_STATUS _set_or_update_person(PEP_SESSION session, 
   1.281                                          pEp_identity* identity,
   1.282                                          sqlite3_stmt* set_or_update) {
   1.283 -    assert(session);
   1.284 -    assert(identity);
   1.285 -    assert(set_or_update);
   1.286                          
   1.287      if (!session || !identity || !identity->user_id || !identity->username)
   1.288          return PEP_ILLEGAL_VALUE;
   1.289 @@ -3443,12 +3371,6 @@
   1.290  {
   1.291      int result;
   1.292  
   1.293 -    assert(session);
   1.294 -    assert(identity);
   1.295 -    assert(identity->address);
   1.296 -    assert(identity->user_id);
   1.297 -    assert(identity->username);
   1.298 -
   1.299      if (!(session && identity && identity->address &&
   1.300                  identity->user_id && identity->username))
   1.301          return PEP_ILLEGAL_VALUE;
   1.302 @@ -3541,10 +3463,6 @@
   1.303  
   1.304  // This ONLY sets the user flag. Must be called outside of a transaction.
   1.305  DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user) {
   1.306 -
   1.307 -    assert(session);
   1.308 -    assert(user);
   1.309 -    assert(!EMPTYSTR(user->user_id));
   1.310          
   1.311      if (!session || !user || EMPTYSTR(user->user_id))
   1.312          return PEP_ILLEGAL_VALUE;
   1.313 @@ -3578,10 +3496,10 @@
   1.314  
   1.315  // This ONLY sets the version flag. Must be called outside of a transaction.
   1.316  PEP_STATUS set_pEp_version(PEP_SESSION session, pEp_identity* ident, unsigned int new_ver_major, unsigned int new_ver_minor) {
   1.317 -    assert(session);
   1.318 -    assert(!EMPTYSTR(ident->user_id));
   1.319 -    assert(!EMPTYSTR(ident->address));
   1.320 -    
   1.321 +
   1.322 +    if (!session || !ident || EMPTYSTR(ident->user_id) || EMPTYSTR(ident->address))
   1.323 +        return PEP_ILLEGAL_VALUE;
   1.324 +
   1.325      sqlite3_reset(session->set_pEp_version);
   1.326      sqlite3_bind_double(session->set_pEp_version, 1, new_ver_major);
   1.327      sqlite3_bind_double(session->set_pEp_version, 2, new_ver_minor);    
   1.328 @@ -3606,8 +3524,9 @@
   1.329          unsigned int new_ver_minor
   1.330      ) 
   1.331  {
   1.332 -    assert(session);
   1.333 -    assert(!EMPTYSTR(ident->user_id));
   1.334 +
   1.335 +    if (!session || !ident || EMPTYSTR(ident->user_id))
   1.336 +        return PEP_ILLEGAL_VALUE;
   1.337      
   1.338      sqlite3_reset(session->upgrade_pEp_version_by_user_id);
   1.339      sqlite3_bind_int(session->upgrade_pEp_version_by_user_id, 1, new_ver_major);
   1.340 @@ -3626,14 +3545,7 @@
   1.341  
   1.342  PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
   1.343                           bool* exists) {            
   1.344 -    
   1.345 -    // const char* user_id,
   1.346 -    //                      char** default_id, bool* exists) {
   1.347 -    assert(session);
   1.348 -    assert(exists);
   1.349 -    assert(identity);
   1.350 -    assert(!EMPTYSTR(identity->user_id));
   1.351 -        
   1.352 +            
   1.353      if (!session || !exists || !identity || EMPTYSTR(identity->user_id))
   1.354          return PEP_ILLEGAL_VALUE;
   1.355      
   1.356 @@ -3675,8 +3587,7 @@
   1.357  }
   1.358  
   1.359  PEP_STATUS delete_person(PEP_SESSION session, const char* user_id) {
   1.360 -    assert(session);
   1.361 -    assert(!EMPTYSTR(user_id));        
   1.362 +
   1.363      if (!session || EMPTYSTR(user_id))
   1.364          return PEP_ILLEGAL_VALUE;
   1.365          
   1.366 @@ -3697,10 +3608,6 @@
   1.367  
   1.368  DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session, pEp_identity *identity, bool* is_pEp)
   1.369  {
   1.370 -    assert(session);
   1.371 -    assert(is_pEp);
   1.372 -    assert(identity);
   1.373 -    assert(!EMPTYSTR(identity->user_id));
   1.374  
   1.375      if (!session || !is_pEp || !identity || EMPTYSTR(identity->user_id))
   1.376          return PEP_ILLEGAL_VALUE;
   1.377 @@ -3742,9 +3649,6 @@
   1.378  
   1.379  PEP_STATUS is_own_address(PEP_SESSION session, const char* address, bool* is_own_addr)
   1.380  {
   1.381 -    assert(session);
   1.382 -    assert(is_own_addr);
   1.383 -    assert(!EMPTYSTR(address));
   1.384  
   1.385      if (!session || !is_own_addr || EMPTYSTR(address))
   1.386          return PEP_ILLEGAL_VALUE;
   1.387 @@ -3802,12 +3706,7 @@
   1.388  // since this could be either way
   1.389  PEP_STATUS has_partner_contacted_address(PEP_SESSION session, const char* partner_id,
   1.390                                           const char* own_address, bool* was_contacted) {            
   1.391 -    
   1.392 -    assert(session);
   1.393 -    assert(!EMPTYSTR(partner_id));
   1.394 -    assert(!EMPTYSTR(own_address));    
   1.395 -    assert(was_contacted);
   1.396 -    
   1.397 +        
   1.398      if (!session || !was_contacted || EMPTYSTR(partner_id) || EMPTYSTR(own_address))
   1.399          return PEP_ILLEGAL_VALUE;
   1.400      
   1.401 @@ -3885,7 +3784,6 @@
   1.402  PEP_STATUS remove_fpr_as_default(PEP_SESSION session, 
   1.403                                   const char* fpr) 
   1.404  {
   1.405 -    assert(fpr);
   1.406      
   1.407      if (!session || !fpr)
   1.408          return PEP_ILLEGAL_VALUE;
   1.409 @@ -3918,8 +3816,6 @@
   1.410                                   const char* old_fpr, 
   1.411                                   const char* new_fpr) 
   1.412  {
   1.413 -    assert(old_fpr);
   1.414 -    assert(new_fpr);
   1.415      
   1.416      if (!old_fpr || !new_fpr)
   1.417          return PEP_ILLEGAL_VALUE;
   1.418 @@ -3967,11 +3863,6 @@
   1.419  {
   1.420      int result;
   1.421  
   1.422 -    assert(session);
   1.423 -    assert(identity);
   1.424 -    assert(identity->address);
   1.425 -    assert(identity->user_id);
   1.426 -
   1.427      if (!(session && identity && identity->address && identity->user_id))
   1.428          return PEP_ILLEGAL_VALUE;
   1.429  
   1.430 @@ -4000,11 +3891,6 @@
   1.431  {
   1.432      int result;
   1.433  
   1.434 -    assert(session);
   1.435 -    assert(identity);
   1.436 -    assert(identity->address);
   1.437 -    assert(identity->user_id);
   1.438 -
   1.439      if (!(session && identity && identity->address && identity->user_id))
   1.440          return PEP_ILLEGAL_VALUE;
   1.441  
   1.442 @@ -4032,11 +3918,6 @@
   1.443  {
   1.444      int result;
   1.445  
   1.446 -    assert(session);
   1.447 -    assert(identity);
   1.448 -    assert(identity->address);
   1.449 -    assert(identity->user_id);
   1.450 -
   1.451      if (!(session && identity && identity->address && identity->user_id))
   1.452          return PEP_ILLEGAL_VALUE;
   1.453  
   1.454 @@ -4377,9 +4258,6 @@
   1.455  
   1.456  PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
   1.457                            const char* new_uid) {
   1.458 -    assert(session);
   1.459 -    assert(old_uid);
   1.460 -    assert(new_uid);
   1.461      
   1.462      if (!session || !old_uid || !new_uid)
   1.463          return PEP_ILLEGAL_VALUE;
   1.464 @@ -4416,8 +4294,6 @@
   1.465  }
   1.466  
   1.467  PEP_STATUS remove_key(PEP_SESSION session, const char* fpr) {
   1.468 -    assert(session);
   1.469 -    assert(fpr);
   1.470      
   1.471      if (!session || EMPTYSTR(fpr))
   1.472          return PEP_ILLEGAL_VALUE;
   1.473 @@ -4437,8 +4313,6 @@
   1.474  
   1.475  
   1.476  PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id) {
   1.477 -    assert(session);
   1.478 -    assert(user_id);
   1.479      
   1.480      if (!session || !user_id)
   1.481          return PEP_ILLEGAL_VALUE;
   1.482 @@ -4458,9 +4332,6 @@
   1.483  
   1.484  PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
   1.485                                   const char* new_fpr) {
   1.486 -    assert(session);
   1.487 -    assert(user_id);
   1.488 -    assert(new_fpr);
   1.489      
   1.490      if (!session || !user_id || !new_fpr)
   1.491          return PEP_ILLEGAL_VALUE;
   1.492 @@ -4482,9 +4353,6 @@
   1.493  
   1.494  PEP_STATUS replace_main_user_fpr_if_equal(PEP_SESSION session, const char* user_id,
   1.495                                            const char* new_fpr, const char* compare_fpr) {
   1.496 -    assert(session);
   1.497 -    assert(user_id);
   1.498 -    assert(compare_fpr);
   1.499      
   1.500      if (!session || !user_id || !compare_fpr)
   1.501          return PEP_ILLEGAL_VALUE;
   1.502 @@ -4515,11 +4383,7 @@
   1.503  {
   1.504      PEP_STATUS status = PEP_STATUS_OK;
   1.505      int result;
   1.506 -    
   1.507 -    assert(session);
   1.508 -    assert(user_id);
   1.509 -    assert(main_fpr);
   1.510 -    
   1.511 +        
   1.512      if (!(session && user_id && user_id[0] && main_fpr))
   1.513          return PEP_ILLEGAL_VALUE;
   1.514          
   1.515 @@ -4567,9 +4431,6 @@
   1.516  {
   1.517      int result;
   1.518  
   1.519 -    assert(session);
   1.520 -    assert(fpr && fpr[0]);
   1.521 -
   1.522      if (!(session && fpr && fpr[0]))
   1.523          return PEP_ILLEGAL_VALUE;
   1.524  
   1.525 @@ -4600,15 +4461,6 @@
   1.526      PEP_STATUS status = PEP_STATUS_OK;
   1.527      int result;
   1.528  
   1.529 -    // We need to be able to test that we break correctly without shutting
   1.530 -    // asserts off everywhere.
   1.531 -    // assert(session);
   1.532 -    // assert(identity);
   1.533 -    // assert(identity->user_id);
   1.534 -    // assert(identity->user_id[0]);
   1.535 -    // assert(identity->fpr);
   1.536 -    // assert(identity->fpr[0]);
   1.537 -
   1.538      if (!(session && identity && identity->user_id && identity->user_id[0] &&
   1.539                  identity->fpr && identity->fpr[0]))
   1.540          return PEP_ILLEGAL_VALUE;
   1.541 @@ -4647,10 +4499,6 @@
   1.542      PEP_STATUS status = PEP_STATUS_OK;
   1.543      int result;
   1.544  
   1.545 -    assert(session);
   1.546 -    assert(fpr);
   1.547 -    assert(comm_type);
   1.548 -
   1.549      if (!(session && fpr && comm_type))
   1.550          return PEP_ILLEGAL_VALUE;
   1.551  
   1.552 @@ -4702,12 +4550,6 @@
   1.553      char** filename_ptr
   1.554      )
   1.555  {
   1.556 -    assert(session);
   1.557 -    assert(ctext);
   1.558 -    assert(csize);
   1.559 -    assert(ptext);
   1.560 -    assert(psize);
   1.561 -    assert(keylist);
   1.562  
   1.563      if (!(session && ctext && csize && ptext && psize && keylist))
   1.564          return PEP_ILLEGAL_VALUE;
   1.565 @@ -4730,12 +4572,6 @@
   1.566      size_t psize, char **ctext, size_t *csize
   1.567      )
   1.568  {
   1.569 -    assert(session);
   1.570 -    assert(keylist);
   1.571 -    assert(ptext);
   1.572 -    assert(psize);
   1.573 -    assert(ctext);
   1.574 -    assert(csize);
   1.575  
   1.576      if (!(session && keylist && ptext && psize && ctext && csize))
   1.577          return PEP_ILLEGAL_VALUE;
   1.578 @@ -4749,12 +4585,6 @@
   1.579      size_t psize, char **ctext, size_t *csize
   1.580      )
   1.581  {
   1.582 -    assert(session);
   1.583 -    assert(keylist);
   1.584 -    assert(ptext);
   1.585 -    assert(psize);
   1.586 -    assert(ctext);
   1.587 -    assert(csize);
   1.588  
   1.589      if (!(session && keylist && ptext && psize && ctext && csize))
   1.590          return PEP_ILLEGAL_VALUE;
   1.591 @@ -4769,12 +4599,6 @@
   1.592                       const char *fpr, 
   1.593                       char **sign, 
   1.594                       size_t *sign_size) {
   1.595 -    assert(session);
   1.596 -    assert(fpr);
   1.597 -    assert(data);
   1.598 -    assert(data_size);
   1.599 -    assert(sign);
   1.600 -    assert(sign_size);
   1.601  
   1.602      if (!(session && fpr && data && data_size && sign && sign_size))
   1.603          return PEP_ILLEGAL_VALUE;
   1.604 @@ -4791,12 +4615,6 @@
   1.605      const char *signature, size_t sig_size, stringlist_t **keylist
   1.606      )
   1.607  {
   1.608 -    assert(session);
   1.609 -    assert(text);
   1.610 -    assert(size);
   1.611 -    assert(signature);
   1.612 -    assert(sig_size);
   1.613 -    assert(keylist);
   1.614  
   1.615      if (!(session && text && size && signature && sig_size && keylist))
   1.616          return PEP_ILLEGAL_VALUE;
   1.617 @@ -4807,8 +4625,6 @@
   1.618  
   1.619  DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
   1.620  {
   1.621 -    assert(session);
   1.622 -    assert(fpr);
   1.623  
   1.624      if (!(session && fpr))
   1.625          return PEP_ILLEGAL_VALUE;
   1.626 @@ -4820,10 +4636,6 @@
   1.627          PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   1.628      )
   1.629  {
   1.630 -    assert(session);
   1.631 -    assert(fpr);
   1.632 -    assert(key_data);
   1.633 -    assert(size);
   1.634  
   1.635      if (!(session && fpr && key_data && size))
   1.636          return PEP_ILLEGAL_VALUE;
   1.637 @@ -4836,11 +4648,6 @@
   1.638          PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   1.639      )
   1.640  {
   1.641 -    assert(session);
   1.642 -    assert(fpr);
   1.643 -    assert(key_data);
   1.644 -    assert(size);
   1.645 -
   1.646      if (!(session && fpr && key_data && size))
   1.647          return PEP_ILLEGAL_VALUE;
   1.648  
   1.649 @@ -4864,10 +4671,6 @@
   1.650          PEP_SESSION session, const char *pattern, stringlist_t **keylist
   1.651      )
   1.652  {
   1.653 -    assert(session);
   1.654 -    assert(pattern);
   1.655 -    assert(keylist);
   1.656 -
   1.657      if (!(session && pattern && keylist))
   1.658          return PEP_ILLEGAL_VALUE;
   1.659  
   1.660 @@ -4888,11 +4691,6 @@
   1.661                               bool suppress_event
   1.662      )
   1.663  {
   1.664 -    assert(session);
   1.665 -    assert(identity);
   1.666 -    assert(identity->address);
   1.667 -    assert(identity->fpr == NULL || identity->fpr[0] == 0);
   1.668 -//    assert(identity->username);
   1.669      // N.B. We now allow empty usernames, so the underlying layer for 
   1.670      // non-sequoia crypto implementations will have to deal with this.
   1.671  
   1.672 @@ -4951,10 +4749,6 @@
   1.673          PEP_comm_type *comm_type
   1.674      )
   1.675  {
   1.676 -    assert(session);
   1.677 -    assert(fpr);
   1.678 -    assert(comm_type);
   1.679 -
   1.680      if (!(session && fpr && comm_type))
   1.681          return PEP_ILLEGAL_VALUE;
   1.682  
   1.683 @@ -4980,9 +4774,6 @@
   1.684          uint64_t* changed_public_keys        
   1.685      )
   1.686  {
   1.687 -    assert(session);
   1.688 -    assert(key_data);
   1.689 -
   1.690      if (!(session && key_data))
   1.691          return PEP_ILLEGAL_VALUE;
   1.692          
   1.693 @@ -4994,10 +4785,7 @@
   1.694  }
   1.695  
   1.696  DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
   1.697 -{
   1.698 -    assert(session);
   1.699 -    assert(pattern);
   1.700 -
   1.701 +{   
   1.702      if (!(session && pattern))
   1.703          return PEP_ILLEGAL_VALUE;
   1.704  
   1.705 @@ -5006,9 +4794,6 @@
   1.706  
   1.707  DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern)
   1.708  {
   1.709 -    assert(session);
   1.710 -    assert(pattern);
   1.711 -
   1.712      if (!(session && pattern))
   1.713          return PEP_ILLEGAL_VALUE;
   1.714  
   1.715 @@ -5021,9 +4806,6 @@
   1.716          const timestamp *ts
   1.717      )
   1.718  {
   1.719 -    assert(session);
   1.720 -    assert(fpr);
   1.721 -
   1.722      if (!(session && fpr))
   1.723          return PEP_ILLEGAL_VALUE;
   1.724  
   1.725 @@ -5036,9 +4818,6 @@
   1.726          const char *reason
   1.727      )
   1.728  {
   1.729 -    assert(session);
   1.730 -    assert(fpr);
   1.731 -
   1.732      if (!(session && fpr))
   1.733          return PEP_ILLEGAL_VALUE;
   1.734  
   1.735 @@ -5062,10 +4841,6 @@
   1.736          bool *expired
   1.737      )
   1.738  {
   1.739 -    assert(session);
   1.740 -    assert(fpr);
   1.741 -    assert(expired);
   1.742 -
   1.743      if (!(session && fpr && expired))
   1.744          return PEP_ILLEGAL_VALUE;
   1.745  
   1.746 @@ -5078,11 +4853,7 @@
   1.747         const char *fpr,
   1.748         bool *revoked
   1.749     )
   1.750 -{
   1.751 -    assert(session);
   1.752 -    assert(fpr);
   1.753 -    assert(revoked);
   1.754 -    
   1.755 +{    
   1.756      if (!(session && fpr && revoked))
   1.757          return PEP_ILLEGAL_VALUE;
   1.758      
   1.759 @@ -5093,7 +4864,6 @@
   1.760  DYNAMIC_API PEP_STATUS config_cipher_suite(PEP_SESSION session,
   1.761          PEP_CIPHER_SUITE suite)
   1.762  {
   1.763 -    assert(session);
   1.764      if (!session)
   1.765          return PEP_ILLEGAL_VALUE;
   1.766  
   1.767 @@ -5143,10 +4913,6 @@
   1.768      PEP_STATUS status = PEP_STATUS_OK;
   1.769      char *_logdata= NULL;
   1.770  
   1.771 -    assert(session);
   1.772 -    assert(maxlines >= 0 && maxlines <= CRASHDUMP_MAX_LINES);
   1.773 -    assert(logdata);
   1.774 -
   1.775      if (!(session && logdata && maxlines >= 0 && maxlines <=
   1.776              CRASHDUMP_MAX_LINES))
   1.777          return PEP_ILLEGAL_VALUE;
   1.778 @@ -5241,9 +5007,6 @@
   1.779      PEP_STATUS status = PEP_STATUS_OK;
   1.780      char *_languages= NULL;
   1.781  
   1.782 -    assert(session);
   1.783 -    assert(languages);
   1.784 -
   1.785      if (!(session && languages))
   1.786          return PEP_ILLEGAL_VALUE;
   1.787  
   1.788 @@ -5313,7 +5076,6 @@
   1.789  {
   1.790      PEP_STATUS status = PEP_STATUS_OK;
   1.791  
   1.792 -    assert(session && lang && lang[0] && lang[1] && lang[2] == 0 && phrase);
   1.793      if (!(session && lang && lang[0] && lang[1] && lang[2] == 0 && phrase))
   1.794          return PEP_ILLEGAL_VALUE;
   1.795  
   1.796 @@ -5359,7 +5121,6 @@
   1.797  static PEP_STATUS _get_sequence_value(PEP_SESSION session, const char *name,
   1.798          int32_t *value)
   1.799  {
   1.800 -    assert(session && name && value);
   1.801      if (!(session && name && value))
   1.802          return PEP_ILLEGAL_VALUE;
   1.803  
   1.804 @@ -5390,7 +5151,6 @@
   1.805  static PEP_STATUS _increment_sequence_value(PEP_SESSION session,
   1.806          const char *name)
   1.807  {
   1.808 -    assert(session && name);
   1.809      if (!(session && name))
   1.810          return PEP_ILLEGAL_VALUE;
   1.811  
   1.812 @@ -5413,9 +5173,6 @@
   1.813  {
   1.814      PEP_STATUS status = PEP_STATUS_OK;
   1.815  
   1.816 -    assert(session);
   1.817 -    assert(name && value);
   1.818 -
   1.819      if (!(session && name && name[0] && value))
   1.820          return PEP_ILLEGAL_VALUE;
   1.821  
   1.822 @@ -5478,12 +5235,7 @@
   1.823      )
   1.824  {
   1.825      PEP_STATUS status = PEP_STATUS_OK;
   1.826 -    
   1.827 -    assert(session &&
   1.828 -           revoked_fpr && revoked_fpr[0] &&
   1.829 -           replacement_fpr && replacement_fpr[0]
   1.830 -          );
   1.831 -    
   1.832 +        
   1.833      if (!(session &&
   1.834            revoked_fpr && revoked_fpr[0] &&
   1.835            replacement_fpr && replacement_fpr[0]
   1.836 @@ -5520,16 +5272,8 @@
   1.837      )
   1.838  {
   1.839      PEP_STATUS status = PEP_STATUS_OK;
   1.840 -
   1.841 -    assert(session &&
   1.842 -           revoked_fpr &&
   1.843 -           fpr && fpr[0]
   1.844 -          );
   1.845 -    
   1.846 -    if (!(session &&
   1.847 -           revoked_fpr &&
   1.848 -           fpr && fpr[0]
   1.849 -          ))
   1.850 +   
   1.851 +    if (!(session && revoked_fpr && fpr && fpr[0]))
   1.852          return PEP_ILLEGAL_VALUE;
   1.853  
   1.854      *revoked_fpr = NULL;
   1.855 @@ -5570,8 +5314,6 @@
   1.856      )
   1.857  {
   1.858      PEP_STATUS status = PEP_STATUS_OK;
   1.859 -
   1.860 -    assert(session && revoked_fpr && !EMPTYSTR(fpr) && revocation_date);
   1.861      
   1.862      if (!session || !revoked_fpr || EMPTYSTR(fpr) || !revocation_date)
   1.863          return PEP_ILLEGAL_VALUE;
   1.864 @@ -5611,9 +5353,6 @@
   1.865          identity_list** id_list
   1.866      )
   1.867  {
   1.868 -    assert(session);
   1.869 -    assert(id_list);
   1.870 -
   1.871      if (!(session && id_list))
   1.872          return PEP_ILLEGAL_VALUE;
   1.873  
   1.874 @@ -5659,7 +5398,6 @@
   1.875          time_t *created
   1.876      )
   1.877  {
   1.878 -    assert(session && fpr && created);
   1.879      if (!(session && fpr && created))
   1.880          return PEP_ILLEGAL_VALUE;
   1.881  
   1.882 @@ -5669,7 +5407,6 @@
   1.883  
   1.884  PEP_STATUS find_private_keys(PEP_SESSION session, const char* pattern,
   1.885                               stringlist_t **keylist) {
   1.886 -    assert(session && keylist);
   1.887      if (!(session && keylist))
   1.888          return PEP_ILLEGAL_VALUE;
   1.889      
   1.890 @@ -5688,7 +5425,6 @@
   1.891  
   1.892  DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session)
   1.893  {
   1.894 -    assert(session);
   1.895  
   1.896      if (!session)
   1.897          return PEP_ILLEGAL_VALUE;
   1.898 @@ -5708,55 +5444,6 @@
   1.899      return PEP_STATUS_OK;
   1.900  }
   1.901  
   1.902 -#ifdef DEBUG_ERRORSTACK
   1.903 -PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status)
   1.904 -{
   1.905 -    char logline[48];
   1.906 -    if(status>0)
   1.907 -    {
   1.908 -        snprintf(logline,47, "%.24s:%u status=%u (0x%x)", file, line, status, status);
   1.909 -    }else{
   1.910 -        snprintf(logline,47, "%.24s:%u status=%i.", file, line, status);
   1.911 -    }
   1.912 -    stringlist_add(session->errorstack, logline); // logline is copied! :-)
   1.913 -    return status;
   1.914 -}
   1.915 -
   1.916 -DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session)
   1.917 -{
   1.918 -    return session->errorstack;
   1.919 -}
   1.920 -
   1.921 -DYNAMIC_API void clear_errorstack(PEP_SESSION session)
   1.922 -{
   1.923 -    const int old_len = stringlist_length(session->errorstack);
   1.924 -    char buf[48];
   1.925 -    free_stringlist(session->errorstack);
   1.926 -    snprintf(buf, 47, "(%i elements cleared)", old_len);
   1.927 -    session->errorstack = new_stringlist(buf);
   1.928 -}
   1.929 -
   1.930 -#else
   1.931 -
   1.932 -static stringlist_t* dummy_errorstack = NULL;
   1.933 -
   1.934 -DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session)
   1.935 -{
   1.936 -    if(dummy_errorstack == NULL)
   1.937 -    {
   1.938 -        dummy_errorstack = new_stringlist("( Please recompile pEpEngine with -DDEBUG_ERRORSTACK )");
   1.939 -    }
   1.940 -
   1.941 -    return dummy_errorstack;
   1.942 -}
   1.943 -
   1.944 -DYNAMIC_API void clear_errorstack(PEP_SESSION session)
   1.945 -{
   1.946 -    // nothing to do here
   1.947 -}
   1.948 -
   1.949 -#endif
   1.950 -
   1.951  DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
   1.952          PEP_STATUS status, const char *where)
   1.953  {
     2.1 --- a/src/pEpEngine.h	Fri Jul 31 21:10:17 2020 +0200
     2.2 +++ b/src/pEpEngine.h	Wed Aug 05 14:23:44 2020 +0200
     2.3 @@ -285,26 +285,6 @@
     2.4  
     2.5  DYNAMIC_API void release(PEP_SESSION session);
     2.6  
     2.7 -
     2.8 -// const stringlist_t* get_errorstack(PEP_SESSION) - get the error stack for that session, if any
     2.9 -//
    2.10 -//  parameters:
    2.11 -//        session (in)    session handle
    2.12 -//
    2.13 -//    caveat:
    2.14 -//        To get a useful error stack you have to compile with -DDEBUG_ERRORSTACK
    2.15 -//        The error stack belongs to the session. Do no not change it!
    2.16 -DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session);
    2.17 -
    2.18 -
    2.19 -// void clear_errorstack(PEP_SESSION) - clear the error stack for that session, if any
    2.20 -//
    2.21 -//  parameters:
    2.22 -//        session (in)    session handle
    2.23 -//
    2.24 -DYNAMIC_API void clear_errorstack(PEP_SESSION session);
    2.25 -
    2.26 -
    2.27  // config_passive_mode() - enable passive mode
    2.28  //
    2.29  //  parameters:
     3.1 --- a/src/pEp_internal.h	Fri Jul 31 21:10:17 2020 +0200
     3.2 +++ b/src/pEp_internal.h	Wed Aug 05 14:23:44 2020 +0200
     3.3 @@ -269,9 +269,6 @@
     3.4      bool service_log;
     3.5      
     3.6  #ifndef NDEBUG
     3.7 -#   ifdef DEBUG_ERRORSTACK
     3.8 -    stringlist_t* errorstack;
     3.9 -#   endif
    3.10      int debug_color;
    3.11  #endif
    3.12  };
     4.1 --- a/test/src/Engine.cc	Fri Jul 31 21:10:17 2020 +0200
     4.2 +++ b/test/src/Engine.cc	Wed Aug 05 14:23:44 2020 +0200
     4.3 @@ -95,13 +95,6 @@
     4.4      PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event, cached_ensure_passphrase);
     4.5      assert(status == PEP_STATUS_OK);
     4.6      assert(session);
     4.7 -
     4.8 -#ifdef USE_GPG
     4.9 -    success = system("gpgconf --create-socketdir");
    4.10 -    if (success != 0)
    4.11 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
    4.12 -    system("gpg-connect-agent /bye 2>/dev/null");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
    4.13 -#endif
    4.14  }
    4.15  
    4.16  void Engine::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {
     5.1 --- a/test/src/SyncTest.cc	Fri Jul 31 21:10:17 2020 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,342 +0,0 @@
     5.4 -// This file is under GNU General Public License 3.0
     5.5 -// see LICENSE.txt
     5.6 -
     5.7 -#include <stdlib.h>
     5.8 -#include <string>
     5.9 -#include <assert.h>
    5.10 -#include <thread>
    5.11 -
    5.12 -#include "locked_queue.hh"
    5.13 -#include "sync_api.h"
    5.14 -#include "Sync_impl.h"
    5.15 -
    5.16 -#include "test_util.h"
    5.17 -
    5.18 -#include "pEpEngine.h"
    5.19 -
    5.20 -#include "pEp_internal.h"
    5.21 -#include "KeySync_fsm.h"
    5.22 -#include "sync_codec.h"
    5.23 -
    5.24 -#include "Engine.h"
    5.25 -
    5.26 -#include <gtest/gtest.h>
    5.27 -
    5.28 -class Sync_Adapter;
    5.29 -
    5.30 -// wrappers for static callbacks. Don't ask me about this mess.
    5.31 -PEP_STATUS ST_message_send_callback(message* msg);
    5.32 -int ST_inject_sync_event_callback(SYNC_EVENT ev, void *management);
    5.33 -Sync_event_t* ST_retrieve_next_sync_event_callback(void *management, unsigned threshold);
    5.34 -void ST_sync_thread_callback(PEP_SESSION session, Sync_Adapter *adapter);
    5.35 -PEP_STATUS ST_notifyHandshake_callback(pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal);
    5.36 -
    5.37 -static void* ST_fake_this;
    5.38 -
    5.39 -class Sync_Adapter {
    5.40 -public:
    5.41 -    utility::locked_queue< Sync_event_t * > q;
    5.42 -
    5.43 -    void processing();
    5.44 -
    5.45 -    static PEP_STATUS notifyHandshake(
    5.46 -            pEp_identity *me,
    5.47 -            pEp_identity *partner,
    5.48 -            sync_handshake_signal signal
    5.49 -        );
    5.50 -    static int inject_sync_event(SYNC_EVENT ev, void *management);
    5.51 -    static Sync_event_t *retrieve_next_sync_event(void *management, unsigned threshold);
    5.52 -    static PEP_STATUS messageToSend(struct _message *msg);
    5.53 -
    5.54 -    static void sync_thread(PEP_SESSION session, Sync_Adapter *adapter);
    5.55 -};
    5.56 -
    5.57 -
    5.58 -void Sync_Adapter::processing()
    5.59 -{
    5.60 -    output_stream << "waiting for processing\n";
    5.61 -    const struct timespec arr[] = {{0, 100000000L}};
    5.62 -    while (!q.empty()) {
    5.63 -        nanosleep(arr, NULL);
    5.64 -    }
    5.65 -}
    5.66 -
    5.67 -PEP_STATUS Sync_Adapter::notifyHandshake(
    5.68 -        pEp_identity *me,
    5.69 -        pEp_identity *partner,
    5.70 -        sync_handshake_signal signal
    5.71 -    )
    5.72 -{
    5.73 -    return PEP_STATUS_OK;
    5.74 -}
    5.75 -
    5.76 -PEP_STATUS ST_notifyHandshake_callback(
    5.77 -        pEp_identity*me,
    5.78 -        pEp_identity *partner,
    5.79 -        sync_handshake_signal signal
    5.80 -    ) {
    5.81 -    return ((Sync_Adapter*)ST_fake_this)->notifyHandshake(me, partner, signal);    
    5.82 -}
    5.83 -    
    5.84 -int Sync_Adapter::inject_sync_event(SYNC_EVENT ev, void *management)
    5.85 -{
    5.86 -    Sync_event_t *_ev = ev;
    5.87 -    switch (_ev->fsm) {
    5.88 -        case Sync_PR_keysync:
    5.89 -            output_stream << "injecting event " << KeySync_event_name(_ev->event) << "\n";
    5.90 -            break;
    5.91 -        default:
    5.92 -            output_stream << "unknown state machine: " << _ev->fsm << "\n";
    5.93 -            assert(0);
    5.94 -    }
    5.95 -    auto adapter = static_cast< Sync_Adapter *>(management);
    5.96 -    adapter->q.push_front(ev);
    5.97 -    return 0;
    5.98 -}
    5.99 -
   5.100 -int ST_inject_sync_event_callback(SYNC_EVENT ev, void *management) {
   5.101 -    return ((Sync_Adapter*)ST_fake_this)->inject_sync_event(ev, management);    
   5.102 -}
   5.103 -    
   5.104 -Sync_event_t *Sync_Adapter::retrieve_next_sync_event(void *management, unsigned threshold)
   5.105 -{
   5.106 -    // N.B. I think it's too late by the time you get here.
   5.107 -    auto adapter = static_cast< Sync_Adapter *>(management);
   5.108 -    time_t started = time(nullptr);
   5.109 -    bool timeout = false;
   5.110 -
   5.111 -    while (adapter->q.empty()) {
   5.112 -        int i = 0;
   5.113 -        ++i;
   5.114 -        if (i > 10) {
   5.115 -            if (time(nullptr) > started + threshold) {
   5.116 -                timeout = true;
   5.117 -                break;
   5.118 -            }
   5.119 -            i = 0;
   5.120 -        }
   5.121 -        const struct timespec arr[] = {{0, 100000000L}};        
   5.122 -        nanosleep(arr, NULL);
   5.123 -    }
   5.124 -
   5.125 -    if (timeout)
   5.126 -        return SYNC_TIMEOUT_EVENT;
   5.127 -
   5.128 -    Sync_event_t *ev = adapter->q.pop_front();
   5.129 -    if (ev) {
   5.130 -        switch (ev->fsm) {
   5.131 -            case Sync_PR_keysync:
   5.132 -                output_stream << "sync thread: retrieving event " << KeySync_event_name(ev->event) << "\n";
   5.133 -                break;
   5.134 -            default:
   5.135 -                output_stream << "sync thread: unknown state machine: " << ev->fsm << "\n";
   5.136 -                assert(0);
   5.137 -        }
   5.138 -    }
   5.139 -    else {
   5.140 -        output_stream << "sync thread: retrieving shutdown\n";
   5.141 -    }
   5.142 -
   5.143 -    return ev;
   5.144 -}
   5.145 -
   5.146 -Sync_event_t* ST_retrieve_next_sync_event_callback(void *management, 
   5.147 -                                                   unsigned threshold) {
   5.148 -                                                       
   5.149 -    return ((Sync_Adapter*)ST_fake_this)->retrieve_next_sync_event(management, threshold);
   5.150 -}
   5.151 -
   5.152 -PEP_STATUS Sync_Adapter::messageToSend(struct _message *msg)
   5.153 -{
   5.154 -    assert(msg && msg->attachments);
   5.155 -
   5.156 -    output_stream << "sending message:\n";
   5.157 -
   5.158 -    for (bloblist_t *b = msg->attachments; b && b->value; b = b->next) {
   5.159 -        if (b->mime_type && strcasecmp(b->mime_type, "application/pEp.sync") == 0) {
   5.160 -            assert(msg->from && msg->from->address && msg->from->username);
   5.161 -            output_stream << "<!-- " << msg->from->username << " <" << msg->from->address << "> -->\n";
   5.162 -            char *text = NULL;
   5.163 -            PEP_STATUS status = PER_to_XER_Sync_msg(msg->attachments->value, msg->attachments->size, &text);
   5.164 -            assert(status == PEP_STATUS_OK);
   5.165 -            output_stream << text << "\n";
   5.166 -            free(text);
   5.167 -        }
   5.168 -    }
   5.169 -
   5.170 -    free_message(msg);
   5.171 -    return PEP_STATUS_OK;
   5.172 -}
   5.173 -
   5.174 -PEP_STATUS ST_message_send_callback(message* msg) {
   5.175 -    return ((Sync_Adapter*)ST_fake_this)->messageToSend(msg);
   5.176 -}
   5.177 -
   5.178 -
   5.179 -void Sync_Adapter::sync_thread(PEP_SESSION session, Sync_Adapter *adapter)
   5.180 -{
   5.181 -    output_stream << "sync_thread: startup\n";
   5.182 -    do_sync_protocol(session, adapter);
   5.183 -    output_stream << "sync_thread: shutdown\n";
   5.184 -}
   5.185 -
   5.186 -void ST_sync_thread_callback(PEP_SESSION session, Sync_Adapter *adapter) {
   5.187 -    ((Sync_Adapter*)ST_fake_this)->sync_thread(session, adapter);
   5.188 -}
   5.189 -
   5.190 -namespace {
   5.191 -
   5.192 -	//The fixture for SyncTest
   5.193 -    class SyncTest : public ::testing::Test {
   5.194 -        public:
   5.195 -            Engine* engine;
   5.196 -            PEP_SESSION session;
   5.197 -
   5.198 -            Sync_Adapter adapter;
   5.199 -            PEP_SESSION sync = NULL;
   5.200 -            thread *sync_thread;
   5.201 -            
   5.202 -
   5.203 -        protected:
   5.204 -            // You can remove any or all of the following functions if its body
   5.205 -            // is empty.
   5.206 -            SyncTest() {
   5.207 -                // You can do set-up work for each test here.
   5.208 -                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
   5.209 -                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
   5.210 -                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
   5.211 -            }
   5.212 -
   5.213 -            ~SyncTest() override {
   5.214 -                // You can do clean-up work that doesn't throw exceptions here.
   5.215 -            }
   5.216 -
   5.217 -            // If the constructor and destructor are not enough for setting up
   5.218 -            // and cleaning up each test, you can define the following methods:
   5.219 -
   5.220 -            void SetUp() override {
   5.221 -                // Code here will be called immediately after the constructor (right
   5.222 -                // before each test).
   5.223 -
   5.224 -                // Leave this empty if there are no files to copy to the home directory path
   5.225 -                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
   5.226 -
   5.227 -                // Get a new test Engine.
   5.228 -                engine = new Engine(test_path);
   5.229 -                ASSERT_NE(engine, nullptr);
   5.230 -
   5.231 -                // Ok, let's initialize test directories etc.
   5.232 -                engine->prep(NULL, NULL, NULL, init_files);
   5.233 -
   5.234 -                // Ok, try to start this bugger. Is this totally irrelevant for this case??
   5.235 -                engine->start();
   5.236 -                ASSERT_NE(engine->session, nullptr);
   5.237 -                session = engine->session;
   5.238 -
   5.239 -                // Engine is up. Keep on truckin'
   5.240 -
   5.241 -                pEp_identity *self = new_identity("alice@synctests.pEp", nullptr, "23", "Alice Miller");
   5.242 -                assert(self);
   5.243 -                output_stream << "setting own identity for " << self->address << "\n";
   5.244 -                PEP_STATUS status = myself(session, self);
   5.245 -                assert(self->me);
   5.246 -                assert(self->fpr);
   5.247 -                output_stream << "fpr: " << self->fpr << "\n";
   5.248 -                free_identity(self);
   5.249 -                
   5.250 -                ST_fake_this = (void*)(&adapter);
   5.251 -
   5.252 -                status = init(&sync, ST_message_send_callback, ST_inject_sync_event_callback, NULL);
   5.253 -                if (status != PEP_STATUS_OK)
   5.254 -                    throw std::runtime_error((string("init returned ") + tl_status_string(status)).c_str());
   5.255 -
   5.256 -                output_stream << "initialize sync and start first state machine\n";
   5.257 -                status = register_sync_callbacks(
   5.258 -                    sync,
   5.259 -                    (void *) &adapter.q,
   5.260 -                    ST_notifyHandshake_callback,
   5.261 -                    ST_retrieve_next_sync_event_callback
   5.262 -                );
   5.263 -                if (status != PEP_STATUS_OK)
   5.264 -                    throw std::runtime_error((string("register sync status returned ") + tl_status_string(status)).c_str());
   5.265 -                if (sync->sync_state.keysync.state != Sole)
   5.266 -                    throw std::runtime_error((string("keysync.state was supposed to be ") + to_string((int)Sole) + " but was " + to_string((int)(sync->sync_state.keysync.state))).c_str());
   5.267 -
   5.268 -                output_stream << "creating thread for sync\n";
   5.269 -                sync_thread = new thread(ST_sync_thread_callback, sync, &adapter);
   5.270 -
   5.271 -            }
   5.272 -
   5.273 -            void TearDown() override {
   5.274 -                // Code here will be called immediately after each test (right
   5.275 -                // before the destructor).
   5.276 -                
   5.277 -                adapter.processing();
   5.278 -
   5.279 -                output_stream << "sending shutdown to sync thread\n";
   5.280 -                adapter.q.push_front(nullptr);
   5.281 -                sync_thread->join();
   5.282 -
   5.283 -                unregister_sync_callbacks(sync);
   5.284 -                release(sync);
   5.285 -                
   5.286 -                engine->shut_down();
   5.287 -                delete engine;
   5.288 -                engine = NULL;
   5.289 -                session = NULL;
   5.290 -            }
   5.291 -
   5.292 -        private:
   5.293 -            const char* test_suite_name;
   5.294 -            const char* test_name;
   5.295 -            string test_path;
   5.296 -            // Objects declared here can be used by all tests in the SyncTest suite.
   5.297 -
   5.298 -    };
   5.299 -
   5.300 -}  // namespace
   5.301 -
   5.302 -TEST_F(SyncTest, check_sync)
   5.303 -{
   5.304 -    output_stream << "check_sync(): trigger KeyGen event\n";
   5.305 -    signal_Sync_event(sync, Sync_PR_keysync, KeyGen, NULL);
   5.306 -    adapter.processing();
   5.307 -
   5.308 -    output_stream << "check_sync(): cry for unknown key\n";
   5.309 -    signal_Sync_event(sync, Sync_PR_keysync, CannotDecrypt, NULL);
   5.310 -}
   5.311 -
   5.312 -/*
   5.313 - * This wont work because of threading stuff. Don't put it back in.
   5.314 - 
   5.315 -TEST_F(SyncTest, check_sync_enable)
   5.316 -{
   5.317 -    pEp_identity* julio = new_identity("julio.iglesias@truhan.senor.es", NULL, PEP_OWN_USERID, "Julio Iglesias");
   5.318 -    PEP_STATUS status = myself(sync, julio);
   5.319 -    ASSERT_OK;
   5.320 -    enable_identity_for_sync(sync, julio);
   5.321 -    adapter.processing();
   5.322 -    myself(sync, julio);
   5.323 -    ASSERT_EQ(julio->flags, PEP_idf_devicegroup);
   5.324 -    string current_fpr = julio->fpr;
   5.325 -
   5.326 -    // Passes if you step through and ignore the send_key_to_recents part of key reset, because the attempt to pass the static class vars above doesn't work.
   5.327 -    // FIXME: KB, reimplement according to now-standard method used in key reset tests
   5.328 -    disable_identity_for_sync(sync, julio);
   5.329 -    adapter.processing();
   5.330 -    status = myself(sync, julio);
   5.331 -    ASSERT_OK;   
   5.332 -    ASSERT_EQ(julio->flags, PEP_idf_not_for_sync);
   5.333 -    ASSERT_STRNE(current_fpr.c_str(), julio->fpr);
   5.334 -   
   5.335 -    pEp_identity* juan = new_identity("juan.valdez@columbian.coffee.co", NULL, PEP_OWN_USERID, "Juan Valdez");
   5.336 -    status = myself(sync, juan);
   5.337 -    ASSERT_OK;   
   5.338 -    disable_identity_for_sync(sync, juan);
   5.339 -    adapter.processing();
   5.340 -    status = myself(sync, juan);
   5.341 -    ASSERT_OK;   
   5.342 -    ASSERT_EQ(juan->flags, PEP_idf_not_for_sync);
   5.343 -    ASSERT_FALSE(EMPTYSTR(juan->fpr));
   5.344 -}
   5.345 -*/