ENGINE-289: Ok, really. Someone tell me what's wrong with 'update person set id = ?1 where id = ?2 ;', because honestly... anyway, some of the sql is fixed. I should give it up. ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Tue, 19 Dec 2017 00:00:35 +0100
branchENGINE-289
changeset 2329b9b75cd73c2b
parent 2328 33103198fcdc
child 2365 597b1dc40520
ENGINE-289: Ok, really. Someone tell me what's wrong with 'update person set id = ?1 where id = ?2 ;', because honestly... anyway, some of the sql is fixed. I should give it up.
src/pEpEngine.c
     1.1 --- a/src/pEpEngine.c	Mon Dec 18 23:17:20 2017 +0100
     1.2 +++ b/src/pEpEngine.c	Tue Dec 19 00:00:35 2017 +0100
     1.3 @@ -64,7 +64,7 @@
     1.4      "   and identity.user_id = ?2;";
     1.5  
     1.6  static const char *sql_get_identity_without_trust_check =  
     1.7 -    "select main_key_id, username, comm_type, lang,"
     1.8 +    "select identity.main_key_id, username, lang,"
     1.9      "   identity.flags, is_own"
    1.10      "   from identity"
    1.11      "   join person on id = identity.user_id"
    1.12 @@ -76,9 +76,10 @@
    1.13      "   and identity.user_id = ?2;";
    1.14  
    1.15  static const char *sql_get_identities_by_address =  
    1.16 -    "select user_id, main_key_id, username, comm_type, lang,"
    1.17 +    "select user_id, identity.main_key_id, username, lang,"
    1.18      "   identity.flags, is_own"
    1.19      "   from identity"
    1.20 +    "   join person on id = identity.user_id"
    1.21      "   where (case when (address = ?1) then (1)"
    1.22      "               when (lower(address) = lower(?1)) then (1)"
    1.23      "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1)"
    1.24 @@ -183,9 +184,7 @@
    1.25  
    1.26  // This will cascade to identity and trust
    1.27  static const char* sql_replace_userid =
    1.28 -    "update id from person"
    1.29 -    "   set id = ?1"
    1.30 -    "   where id = ?2;";
    1.31 +    "update person set id = ?1 where id = ?2 ;";
    1.32  
    1.33  // blacklist
    1.34  static const char *sql_blacklist_add = 
    1.35 @@ -1464,12 +1463,11 @@
    1.36      return status;
    1.37  }
    1.38  
    1.39 -static PEP_STATUS _get_identity_internal(
    1.40 +DYNAMIC_API PEP_STATUS get_identity(
    1.41          PEP_SESSION session,
    1.42          const char *address,
    1.43          const char *user_id,
    1.44 -        pEp_identity **identity,
    1.45 -        sqlite3_stmt* get_id_stmt
    1.46 +        pEp_identity **identity
    1.47      )
    1.48  {
    1.49      PEP_STATUS status = PEP_STATUS_OK;
    1.50 @@ -1485,27 +1483,27 @@
    1.51  
    1.52      *identity = NULL;
    1.53  
    1.54 -    sqlite3_reset(get_id_stmt);
    1.55 -    sqlite3_bind_text(get_id_stmt, 1, address, -1, SQLITE_STATIC);
    1.56 -    sqlite3_bind_text(get_id_stmt, 2, user_id, -1, SQLITE_STATIC);
    1.57 -
    1.58 -    const int result = sqlite3_step(get_id_stmt);
    1.59 +    sqlite3_reset(session->get_identity);
    1.60 +    sqlite3_bind_text(session->get_identity, 1, address, -1, SQLITE_STATIC);
    1.61 +    sqlite3_bind_text(session->get_identity, 2, user_id, -1, SQLITE_STATIC);
    1.62 +
    1.63 +    const int result = sqlite3_step(session->get_identity);
    1.64      switch (result) {
    1.65      case SQLITE_ROW:
    1.66          _identity = new_identity(
    1.67                  address,
    1.68 -                (const char *) sqlite3_column_text(get_id_stmt, 0),
    1.69 +                (const char *) sqlite3_column_text(session->get_identity, 0),
    1.70                  user_id,
    1.71 -                (const char *) sqlite3_column_text(get_id_stmt, 1)
    1.72 +                (const char *) sqlite3_column_text(session->get_identity, 1)
    1.73                  );
    1.74          assert(_identity);
    1.75          if (_identity == NULL)
    1.76              return PEP_OUT_OF_MEMORY;
    1.77  
    1.78          _identity->comm_type = (PEP_comm_type)
    1.79 -            sqlite3_column_int(get_id_stmt, 2);
    1.80 +            sqlite3_column_int(session->get_identity, 2);
    1.81          const char* const _lang = (const char *)
    1.82 -            sqlite3_column_text(get_id_stmt, 3);
    1.83 +            sqlite3_column_text(session->get_identity, 3);
    1.84          if (_lang && _lang[0]) {
    1.85              assert(_lang[0] >= 'a' && _lang[0] <= 'z');
    1.86              assert(_lang[1] >= 'a' && _lang[1] <= 'z');
    1.87 @@ -1515,9 +1513,9 @@
    1.88              _identity->lang[2] = 0;
    1.89          }
    1.90          _identity->flags = (unsigned int)
    1.91 -            sqlite3_column_int(get_id_stmt, 4);
    1.92 +            sqlite3_column_int(session->get_identity, 4);
    1.93          _identity->me = (unsigned int)
    1.94 -            sqlite3_column_int(get_id_stmt, 5);
    1.95 +            sqlite3_column_int(session->get_identity, 5);
    1.96      
    1.97          *identity = _identity;
    1.98          break;
    1.99 @@ -1526,21 +1524,10 @@
   1.100          *identity = NULL;
   1.101      }
   1.102  
   1.103 -    sqlite3_reset(get_id_stmt);
   1.104 +    sqlite3_reset(session->get_identity);
   1.105      return status;
   1.106  }
   1.107  
   1.108 -DYNAMIC_API PEP_STATUS get_identity(
   1.109 -        PEP_SESSION session,
   1.110 -        const char *address,
   1.111 -        const char *user_id,
   1.112 -        pEp_identity **identity
   1.113 -    )
   1.114 -{
   1.115 -    return _get_identity_internal(session, address, user_id, identity,
   1.116 -                                  session->get_identity);
   1.117 -}
   1.118 -
   1.119  PEP_STATUS get_identity_without_trust_check(
   1.120          PEP_SESSION session,
   1.121          const char *address,
   1.122 @@ -1548,8 +1535,61 @@
   1.123          pEp_identity **identity
   1.124      )
   1.125  {
   1.126 -    return _get_identity_internal(session, address, user_id, identity,
   1.127 -                                  session->get_identity_without_trust_check);
   1.128 +    PEP_STATUS status = PEP_STATUS_OK;
   1.129 +    static pEp_identity *_identity;
   1.130 +
   1.131 +    assert(session);
   1.132 +    assert(address);
   1.133 +    assert(address[0]);
   1.134 +    assert(identity);
   1.135 +
   1.136 +    if (!(session && address && address[0] && identity))
   1.137 +        return PEP_ILLEGAL_VALUE;
   1.138 +
   1.139 +    *identity = NULL;
   1.140 +
   1.141 +    sqlite3_reset(session->get_identity_without_trust_check);
   1.142 +    sqlite3_bind_text(session->get_identity_without_trust_check, 1, address, -1, SQLITE_STATIC);
   1.143 +    sqlite3_bind_text(session->get_identity_without_trust_check, 2, user_id, -1, SQLITE_STATIC);
   1.144 +
   1.145 +    const int result = sqlite3_step(session->get_identity_without_trust_check);
   1.146 +    switch (result) {
   1.147 +    case SQLITE_ROW:
   1.148 +        _identity = new_identity(
   1.149 +                address,
   1.150 +                (const char *) sqlite3_column_text(session->get_identity_without_trust_check, 0),
   1.151 +                user_id,
   1.152 +                (const char *) sqlite3_column_text(session->get_identity_without_trust_check, 1)
   1.153 +                );
   1.154 +        assert(_identity);
   1.155 +        if (_identity == NULL)
   1.156 +            return PEP_OUT_OF_MEMORY;
   1.157 +
   1.158 +        _identity->comm_type = PEP_ct_unknown;
   1.159 +        const char* const _lang = (const char *)
   1.160 +            sqlite3_column_text(session->get_identity_without_trust_check, 2);
   1.161 +        if (_lang && _lang[0]) {
   1.162 +            assert(_lang[0] >= 'a' && _lang[0] <= 'z');
   1.163 +            assert(_lang[1] >= 'a' && _lang[1] <= 'z');
   1.164 +            assert(_lang[2] == 0);
   1.165 +            _identity->lang[0] = _lang[0];
   1.166 +            _identity->lang[1] = _lang[1];
   1.167 +            _identity->lang[2] = 0;
   1.168 +        }
   1.169 +        _identity->flags = (unsigned int)
   1.170 +            sqlite3_column_int(session->get_identity_without_trust_check, 3);
   1.171 +        _identity->me = (unsigned int)
   1.172 +            sqlite3_column_int(session->get_identity_without_trust_check, 4);
   1.173 +    
   1.174 +        *identity = _identity;
   1.175 +        break;
   1.176 +    default:
   1.177 +        status = PEP_CANNOT_FIND_IDENTITY;
   1.178 +        *identity = NULL;
   1.179 +    }
   1.180 +
   1.181 +    sqlite3_reset(session->get_identity_without_trust_check);
   1.182 +    return status;
   1.183  }
   1.184  
   1.185  PEP_STATUS get_identities_by_address(
   1.186 @@ -1588,10 +1628,10 @@
   1.187          if (ident == NULL)
   1.188              return PEP_OUT_OF_MEMORY;
   1.189  
   1.190 -        ident->comm_type = (PEP_comm_type)
   1.191 -            sqlite3_column_int(session->get_identities_by_address, 3);
   1.192 +        ident->comm_type = PEP_ct_unknown;
   1.193 +        
   1.194          const char* const _lang = (const char *)
   1.195 -            sqlite3_column_text(session->get_identities_by_address, 4);
   1.196 +            sqlite3_column_text(session->get_identities_by_address, 3);
   1.197          if (_lang && _lang[0]) {
   1.198              assert(_lang[0] >= 'a' && _lang[0] <= 'z');
   1.199              assert(_lang[1] >= 'a' && _lang[1] <= 'z');
   1.200 @@ -1601,9 +1641,9 @@
   1.201              ident->lang[2] = 0;
   1.202          }
   1.203          ident->flags = (unsigned int)
   1.204 +            sqlite3_column_int(session->get_identities_by_address, 4);
   1.205 +        ident->me = (unsigned int)
   1.206              sqlite3_column_int(session->get_identities_by_address, 5);
   1.207 -        ident->me = (unsigned int)
   1.208 -            sqlite3_column_int(session->get_identities_by_address, 6);
   1.209      
   1.210          if (ident_list)
   1.211              identity_list_add(ident_list, ident);
   1.212 @@ -1978,7 +2018,6 @@
   1.213      return PEP_STATUS_OK;
   1.214  }
   1.215  
   1.216 -
   1.217  DYNAMIC_API PEP_STATUS mark_as_compromized(
   1.218          PEP_SESSION session,
   1.219          const char *fpr