ENGINE-171 merged into default
authorKrista Bennett <krista@pep-project.org>
Wed, 28 Jun 2017 10:59:26 +0200
changeset 188849612a614567
parent 1877 e2f357447046
parent 1887 3feebd18c35f
child 1890 2f85b57d9964
child 1891 b6a9ff28108c
child 1895 fcafaecea8b6
ENGINE-171 merged into default
     1.1 --- a/src/pEpEngine.c	Tue Jun 20 23:57:08 2017 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Jun 28 10:59:26 2017 +0200
     1.3 @@ -10,6 +10,32 @@
     1.4  
     1.5  static int init_count = -1;
     1.6  
     1.7 +// sql overloaded functions - modified from sqlite3.c
     1.8 +static void _sql_lower(sqlite3_context* ctx, int argc, sqlite3_value** argv) {
     1.9 +    char *z1;
    1.10 +    const char *z2;
    1.11 +    int i, n;
    1.12 +    z2 = (char*)sqlite3_value_text(argv[0]);
    1.13 +    n = sqlite3_value_bytes(argv[0]);
    1.14 +    /* Verify that the call to _bytes() does not invalidate the _text() pointer */
    1.15 +    assert( z2==(char*)sqlite3_value_text(argv[0]) );
    1.16 +    if( z2 ){
    1.17 +        z1 = (char*)sqlite3_malloc(n+1);
    1.18 +        if( z1 ){
    1.19 +            for(i=0; i<n; i++){
    1.20 +                char c = z2[i];
    1.21 +                char c_mod = c | 0x20;
    1.22 +                if (c_mod < 0x61 || c_mod > 0x7a)
    1.23 +                    c_mod = c;
    1.24 +                z1[i] = c_mod;
    1.25 +            }
    1.26 +            z1[n] = '\0';
    1.27 +            sqlite3_result_text(ctx, z1, n, sqlite3_free);
    1.28 +        }
    1.29 +    }
    1.30 +}
    1.31 +
    1.32 +
    1.33  // sql manipulation statements
    1.34  static const char *sql_log = 
    1.35      "insert into log (title, entity, description, comment)"
    1.36 @@ -19,6 +45,7 @@
    1.37      "select id, word from wordlist where lang = lower(?1) "
    1.38      "and id = ?2 ;";
    1.39  
    1.40 +
    1.41  static const char *sql_get_identity =  
    1.42      "select fpr, username, comm_type, lang,"
    1.43      "   identity.flags | pgp_keypair.flags"
    1.44 @@ -26,8 +53,13 @@
    1.45      "   join person on id = identity.user_id"
    1.46      "   join pgp_keypair on fpr = identity.main_key_id"
    1.47      "   join trust on id = trust.user_id"
    1.48 -    "       and pgp_keypair_fpr = identity.main_key_id"
    1.49 -    "   where address = ?1 and identity.user_id = ?2;";
    1.50 +    "       and pgp_keypair_fpr = identity.main_key_id"    
    1.51 +    "   where (case when (address = ?1) then (1)"
    1.52 +    "               when (lower(address) = lower(?1)) then (1)"
    1.53 +    "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1)"
    1.54 +    "               else 0"
    1.55 +    "          end) = 1"
    1.56 +    "   and identity.user_id = ?2;";
    1.57  
    1.58  static const char *sql_replace_identities_fpr =  
    1.59      "update identity"
    1.60 @@ -414,6 +446,21 @@
    1.61              &version,
    1.62              NULL
    1.63          );
    1.64 +
    1.65 +        assert(int_result == SQLITE_OK);
    1.66 +        
    1.67 +        void (*xFunc_lower)(sqlite3_context*,int,sqlite3_value**) = &_sql_lower;
    1.68 +        
    1.69 +        int_result = sqlite3_create_function_v2(
    1.70 +            _session->db,
    1.71 +            "lower",
    1.72 +            1,
    1.73 +            SQLITE_UTF8 | SQLITE_DETERMINISTIC,
    1.74 +            NULL,
    1.75 +            xFunc_lower,
    1.76 +            NULL,
    1.77 +            NULL,
    1.78 +            NULL);
    1.79          assert(int_result == SQLITE_OK);
    1.80  
    1.81          if(version != 0) { 
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/case_and_dot_address_test.cc	Wed Jun 28 10:59:26 2017 +0200
     2.3 @@ -0,0 +1,80 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#include <stdlib.h>
     2.8 +#include <string.h>
     2.9 +#include <time.h>
    2.10 +#include "platform.h"
    2.11 +#include <iostream>
    2.12 +#include <fstream>
    2.13 +#include <assert.h>
    2.14 +#include "mime.h"
    2.15 +#include "message_api.h"
    2.16 +#include "test_util.h"
    2.17 +
    2.18 +using namespace std;
    2.19 +
    2.20 +int main() {
    2.21 +    cout << "\n*** case_and_dot_address_test.cc ***\n\n";
    2.22 +
    2.23 +    PEP_SESSION session;
    2.24 +    
    2.25 +    cout << "calling init()\n";
    2.26 +    PEP_STATUS status = init(&session);   
    2.27 +    assert(status == PEP_STATUS_OK);
    2.28 +    assert(session);
    2.29 +    cout << "init() completed.\n";
    2.30 +    
    2.31 +    
    2.32 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.33 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    2.34 +
    2.35 +    const char* alice_email_case = "pEp.teST.AlICe@pEP-pRoJeCt.ORG";
    2.36 +    const char* alice_email_dot = "pe.p.te.st.a.l.i.ce@pep-project.org";
    2.37 +    const char* alice_email_dotless = "peptestalice@pep-project.org";
    2.38 +    const char* alice_email_case_and_dot = "PE.p.teS.t.ALICE@pep-project.OrG";
    2.39 +
    2.40 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    2.41 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
    2.42 +    assert(statuspub == PEP_STATUS_OK);
    2.43 +    assert(statuspriv == PEP_STATUS_OK);
    2.44 +
    2.45 +    pEp_identity * alice_id = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
    2.46 +    status = update_identity(session, alice_id);
    2.47 +    assert(alice_id->fpr);
    2.48 +    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    2.49 +    free_identity(alice_id);
    2.50 +    alice_id = NULL;
    2.51 +
    2.52 +    alice_id = new_identity(alice_email_case, NULL, PEP_OWN_USERID, "Alice Test");
    2.53 +    status = update_identity(session, alice_id);
    2.54 +    assert(alice_id->fpr);
    2.55 +    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    2.56 +    free_identity(alice_id);
    2.57 +    alice_id = NULL;
    2.58 +
    2.59 +    alice_id = new_identity(alice_email_dot, NULL, PEP_OWN_USERID, "Alice Test");
    2.60 +    status = update_identity(session, alice_id);
    2.61 +    assert(alice_id->fpr);
    2.62 +    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    2.63 +    free_identity(alice_id);
    2.64 +    alice_id = NULL;
    2.65 +
    2.66 +    alice_id = new_identity(alice_email_dotless, NULL, PEP_OWN_USERID, "Alice Test");
    2.67 +    status = update_identity(session, alice_id);
    2.68 +    assert(alice_id->fpr);
    2.69 +    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    2.70 +    free_identity(alice_id);
    2.71 +    alice_id = NULL;
    2.72 +
    2.73 +    alice_id = new_identity(alice_email_case_and_dot, NULL, PEP_OWN_USERID, "Alice Test");
    2.74 +    status = update_identity(session, alice_id);
    2.75 +    assert(alice_id->fpr);
    2.76 +    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    2.77 +    free_identity(alice_id);
    2.78 +    alice_id = NULL;
    2.79 +    
    2.80 +    release(session);
    2.81 +
    2.82 +    return 0;
    2.83 +}