ENGINE-209: implemented get_identities_by_fpr, but sql processing for this and get_key_userids still buggy. In process. ENGINE-209
authorKrista Bennett <krista@pep-project.org>
Thu, 18 May 2017 11:43:01 +0200
branchENGINE-209
changeset 1798dddaa8a5d31c
parent 1797 32581fade44d
child 1799 1e46b8759248
ENGINE-209: implemented get_identities_by_fpr, but sql processing for this and get_key_userids still buggy. In process.
src/pEpEngine.c
     1.1 --- a/src/pEpEngine.c	Thu May 18 11:27:07 2017 +0200
     1.2 +++ b/src/pEpEngine.c	Thu May 18 11:43:01 2017 +0200
     1.3 @@ -1289,7 +1289,83 @@
     1.4  {
     1.5      PEP_STATUS status = PEP_STATUS_OK;
     1.6      
     1.7 +    assert(fpr);
     1.8 +    assert(id_list);
     1.9 +    
    1.10 +    if (!fpr || !id_list)
    1.11 +        return PEP_ILLEGAL_VALUE;
    1.12 +        
    1.13 +    *id_list = NULL;
    1.14 +
    1.15 +    stringlist_t* ids = NULL;
    1.16 +    
    1.17 +    sqlite3_reset(session->get_identities_by_fpr);
    1.18 +    sqlite3_bind_text(session->get_identities_by_fpr, 1, fpr, -1,
    1.19 +                      SQLITE_STATIC);
    1.20 +
    1.21 +    int result;
    1.22 +
    1.23 +    pEp_identity* ident;
    1.24 +    
    1.25 +    do {
    1.26 +        ident = NULL;
    1.27 +        
    1.28 +        result = sqlite3_step(session->get_identities_by_fpr);
    1.29 +        switch (result) {
    1.30 +        case SQLITE_ROW:            
    1.31 +            ident = new_identity(
    1.32 +                    address,
    1.33 +                    (const char *) sqlite3_column_text(session->get_identities_by_fpr, 0),
    1.34 +                    user_id,
    1.35 +                    (const char *) sqlite3_column_text(session->get_identities_by_fpr, 1)
    1.36 +                    );
    1.37 +            assert(_identity);
    1.38 +            if (ident == NULL)
    1.39 +                return PEP_OUT_OF_MEMORY;
    1.40 +
    1.41 +            ident->comm_type = (PEP_comm_type)
    1.42 +                sqlite3_column_int(session->get_identities_by_fpr, 2);
    1.43 +            const char* const _lang = (const char *)
    1.44 +                sqlite3_column_text(session->get_identities_by_fpr, 3);
    1.45 +            if (_lang && _lang[0]) {
    1.46 +                assert(_lang[0] >= 'a' && _lang[0] <= 'z');
    1.47 +                assert(_lang[1] >= 'a' && _lang[1] <= 'z');
    1.48 +                assert(_lang[2] == 0);
    1.49 +                ident->lang[0] = _lang[0];
    1.50 +                ident->lang[1] = _lang[1];
    1.51 +                ident->lang[2] = 0;
    1.52 +            }
    1.53 +            ident->flags = (unsigned int)
    1.54 +                sqlite3_column_int(session->get_identities_by_fpr, 4);
    1.55 +            
    1.56 +            if (!ids)
    1.57 +                ids = new_identity_list(ident, ids);
    1.58 +            else
    1.59 +                identity_list_add(ident, ids);
    1.60 +            
    1.61 +            break;
    1.62 +
    1.63 +        case SQLITE_DONE:
    1.64 +            break;
    1.65 +
    1.66 +        default:
    1.67 +            status = PEP_UNKNOWN_ERROR;
    1.68 +            result = SQLITE_DONE;
    1.69 +        }
    1.70 +    } while (result != SQLITE_DONE);
    1.71 +
    1.72 +    sqlite3_reset(session->get_identities_by_fpr);
    1.73 +    if (status == PEP_STATUS_OK)
    1.74 +        *id_list = ids;
    1.75 +
    1.76 +    goto the_end;
    1.77 +
    1.78 +enomem:
    1.79 +    status = PEP_OUT_OF_MEMORY;
    1.80 +
    1.81 +the_end:
    1.82      return status;
    1.83 +
    1.84  }
    1.85  
    1.86