src/pEpEngine.c
changeset 8 26cc9f0228f4
parent 0 16f27efbef98
child 9 41e66a54f03e
     1.1 --- a/src/pEpEngine.c	Fri Jul 11 12:07:26 2014 +0200
     1.2 +++ b/src/pEpEngine.c	Fri Jul 11 17:43:11 2014 +0200
     1.3 @@ -130,6 +130,7 @@
     1.4  	sqlite3_stmt *set_pgp_keypair;
     1.5  	sqlite3_stmt *set_identity;
     1.6  	sqlite3_stmt *set_trust;
     1.7 +    sqlite3_stmt *get_trust;
     1.8  
     1.9  	gpgme_check_version_t gpgme_check;
    1.10  	gpgme_set_locale_t gpgme_set_locale;
    1.11 @@ -214,6 +215,8 @@
    1.12  	const char *sql_set_pgp_keypair;
    1.13  	const char *sql_set_identity;
    1.14  	const char *sql_set_trust;
    1.15 +    const char *sql_get_trust;
    1.16 +
    1.17      bool bResult;
    1.18  
    1.19  	assert(sqlite3_threadsafe());
    1.20 @@ -571,6 +574,8 @@
    1.21      sql_set_trust = "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type)"
    1.22                          "values (?1, ?2, ?3) ;";
    1.23  	
    1.24 +    sql_get_trust = "select user_id, comm_type from trust where user_id = ?1 and pgp_keypair_fpr = ?2 ;";
    1.25 +
    1.26      int_result = sqlite3_prepare_v2(_session->db, sql_set_person,
    1.27              strlen(sql_set_person), &_session->set_person, NULL);
    1.28      assert(int_result == SQLITE_OK);
    1.29 @@ -583,6 +588,9 @@
    1.30      int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
    1.31              strlen(sql_set_trust), &_session->set_trust, NULL);
    1.32  	assert(int_result == SQLITE_OK);
    1.33 +    int_result = sqlite3_prepare_v2(_session->db, sql_get_trust,
    1.34 +            strlen(sql_get_trust), &_session->get_trust, NULL);
    1.35 +    assert(int_result == SQLITE_OK);
    1.36  
    1.37  	sqlite3_reset(_session->log);
    1.38      sqlite3_bind_text(_session->log, 1, "init", -1, SQLITE_STATIC);
    1.39 @@ -1354,6 +1362,7 @@
    1.40  
    1.41  	assert(session);
    1.42  	assert(address);
    1.43 +    assert(address[0]);
    1.44  
    1.45      sqlite3_reset(_session->get_identity);
    1.46      sqlite3_bind_text(_session->get_identity, 1, address, -1, SQLITE_STATIC);
    1.47 @@ -1853,6 +1862,9 @@
    1.48  	pEpSession *_session = (pEpSession *) session;
    1.49  	gpgme_error_t gpgme_error;
    1.50  
    1.51 +    assert(session);
    1.52 +    assert(pattern);
    1.53 +
    1.54      gpgme_error = _session->gpgme_op_export(_session->ctx, pattern,
    1.55              GPGME_EXPORT_MODE_EXTERN, NULL);
    1.56      assert(gpgme_error != GPG_ERR_INV_VALUE);
    1.57 @@ -1867,3 +1879,46 @@
    1.58      free(p);
    1.59  }
    1.60  
    1.61 +DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity)
    1.62 +{
    1.63 +    pEpSession *_session = (pEpSession *) session;
    1.64 +    PEP_STATUS status = PEP_STATUS_OK;
    1.65 +    int result;
    1.66 +
    1.67 +    assert(session);
    1.68 +    assert(identity);
    1.69 +    assert(identity->user_id);
    1.70 +    assert(identity->user_id[0]);
    1.71 +    assert(identity->fpr);
    1.72 +    assert(identity->fpr[0]);
    1.73 +
    1.74 +    identity->comm_type = PEP_ct_unknown;
    1.75 +
    1.76 +    sqlite3_reset(_session->get_trust);
    1.77 +    sqlite3_bind_text(_session->get_trust, 1, identity->user_id, -1, SQLITE_STATIC);
    1.78 +    sqlite3_bind_text(_session->get_trust, 2, identity->fpr, -1, SQLITE_STATIC);
    1.79 +
    1.80 +    result = sqlite3_step(_session->get_trust);
    1.81 +    switch (result) {
    1.82 +    case SQLITE_ROW: {
    1.83 +        const char * user_id = (const char *) sqlite3_column_text(_session->get_trust, 1);
    1.84 +        int comm_type = (PEP_comm_type) sqlite3_column_int(_session->get_trust, 2);
    1.85 +
    1.86 +        if (strcmp(user_id, identity->user_id) != 0) {
    1.87 +            free(identity->user_id);
    1.88 +            identity->user_id = strdup(user_id);
    1.89 +            assert(identity->user_id);
    1.90 +            if (identity->user_id == NULL)
    1.91 +                return PEP_OUT_OF_MEMORY;
    1.92 +        }
    1.93 +        identity->comm_type = comm_type;
    1.94 +        break;
    1.95 +    }
    1.96 + 
    1.97 +    default:
    1.98 +        status = PEP_CANNOT_FIND_IDENTITY;
    1.99 +    }
   1.100 +
   1.101 +    sqlite3_reset(_session->get_trust);
   1.102 +    return status;
   1.103 +}
   1.104 \ No newline at end of file