src/pEpEngine.c
changeset 1507 cee84fad7f33
parent 1453 5f9cc3233006
child 1508 ab010a3b7894
     1.1 --- a/src/pEpEngine.c	Tue Dec 20 22:51:41 2016 +0100
     1.2 +++ b/src/pEpEngine.c	Wed Dec 21 02:02:11 2016 +0100
     1.3 @@ -36,6 +36,7 @@
     1.4      static const char *sql_unset_identity_flags;
     1.5      static const char *sql_set_trust;
     1.6      static const char *sql_get_trust;
     1.7 +    static const char *sql_greater_trust_keys;
     1.8      static const char *sql_least_trust;
     1.9      static const char *sql_mark_as_compromized;
    1.10      static const char *sql_crashdump;
    1.11 @@ -384,6 +385,10 @@
    1.12          sql_get_trust = "select comm_type from trust where user_id = ?1 "
    1.13                          "and pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
    1.14  
    1.15 +        sql_greater_trust_keys = "select pgp_keypair_fpr from trust"
    1.16 +                                 "    where user_id = ?1"
    1.17 +                                 "      and comm_type > ?2;";
    1.18 +
    1.19          sql_least_trust = "select min(comm_type) from trust where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
    1.20  
    1.21          sql_mark_as_compromized = "update trust not indexed set comm_type = 15"
    1.22 @@ -506,6 +511,11 @@
    1.23              (int)strlen(sql_get_trust), &_session->get_trust, NULL);
    1.24      assert(int_result == SQLITE_OK);
    1.25  
    1.26 +    int_result = sqlite3_prepare_v2(_session->db, sql_greater_trust_keys,
    1.27 +            (int)strlen(sql_greater_trust_keys), &_session->greater_trust_keys,
    1.28 +            NULL);
    1.29 +    assert(int_result == SQLITE_OK);
    1.30 +    
    1.31      int_result = sqlite3_prepare_v2(_session->db, sql_least_trust,
    1.32              (int)strlen(sql_least_trust), &_session->least_trust, NULL);
    1.33      assert(int_result == SQLITE_OK);
    1.34 @@ -676,6 +686,8 @@
    1.35                  sqlite3_finalize(session->set_trust);
    1.36              if (session->get_trust)
    1.37                  sqlite3_finalize(session->get_trust);
    1.38 +            if (session->greater_trust_keys)
    1.39 +                sqlite3_finalize(session->greater_trust_keys);
    1.40              if (session->least_trust)
    1.41                  sqlite3_finalize(session->least_trust);
    1.42              if (session->mark_compromized)
    1.43 @@ -1373,6 +1385,71 @@
    1.44      return status;
    1.45  }
    1.46  
    1.47 +DYNAMIC_API PEP_STATUS greater_trust_keys(
    1.48 +        PEP_SESSION session,
    1.49 +        const char *user_id,
    1.50 +        PEP_comm_type min_comm_type,
    1.51 +        stringlist_t **keylist
    1.52 +    )
    1.53 +{
    1.54 +    PEP_STATUS status = PEP_STATUS_OK;
    1.55 +
    1.56 +    assert(session);
    1.57 +    assert(keylist);
    1.58 +
    1.59 +    if (!(session && keylist))
    1.60 +        return PEP_ILLEGAL_VALUE;
    1.61 +
    1.62 +    *keylist = NULL;
    1.63 +    stringlist_t *_keylist = new_stringlist(NULL);
    1.64 +    if (_keylist == NULL)
    1.65 +        goto enomem;
    1.66 +
    1.67 +    sqlite3_reset(session->greater_trust_keys);
    1.68 +
    1.69 +    sqlite3_bind_text(session->greater_trust_keys, 1, user_id, -1, SQLITE_STATIC);
    1.70 +    sqlite3_bind_int(session->greater_trust_keys, 2, min_comm_type);
    1.71 +    int result;
    1.72 +
    1.73 +    stringlist_t *_bl = _keylist;
    1.74 +    do {
    1.75 +        result = sqlite3_step(session->greater_trust_keys);
    1.76 +        switch (result) {
    1.77 +        case SQLITE_ROW:
    1.78 +        {
    1.79 +            const char *fpr = (const char *) sqlite3_column_text(session->greater_trust_keys, 0);
    1.80 +
    1.81 +            _bl = stringlist_add(_bl, fpr);
    1.82 +            if (_bl == NULL)
    1.83 +                goto enomem;
    1.84 +
    1.85 +            break;
    1.86 +        }
    1.87 +        case SQLITE_DONE:
    1.88 +            break;
    1.89 +
    1.90 +        default:
    1.91 +            status = PEP_UNKNOWN_ERROR;
    1.92 +            result = SQLITE_DONE;
    1.93 +        }
    1.94 +    } while (result != SQLITE_DONE);
    1.95 +
    1.96 +    sqlite3_reset(session->greater_trust_keys);
    1.97 +    if (status == PEP_STATUS_OK)
    1.98 +        *keylist = _keylist;
    1.99 +    else
   1.100 +        free_stringlist(_keylist);
   1.101 +
   1.102 +    goto the_end;
   1.103 +
   1.104 +enomem:
   1.105 +    free_stringlist(_keylist);
   1.106 +    status = PEP_OUT_OF_MEMORY;
   1.107 +
   1.108 +the_end:
   1.109 +    return status;
   1.110 +}
   1.111 +
   1.112  DYNAMIC_API PEP_STATUS least_trust(
   1.113          PEP_SESSION session,
   1.114          const char *fpr,