ENGINE-289: added getter and setter methods for user id aliases, plus error codes for failure (PEP_CANNOT_SET/FIND_ALIAS) ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Wed, 17 Jan 2018 01:01:10 +0100
branchENGINE-289
changeset 23982365cdba8783
parent 2397 ee6f72ef704b
child 2399 09faff2e1f54
ENGINE-289: added getter and setter methods for user id aliases, plus error codes for failure (PEP_CANNOT_SET/FIND_ALIAS)
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Wed Jan 17 00:25:36 2018 +0100
     1.2 +++ b/src/pEpEngine.c	Wed Jan 17 01:01:10 2018 +0100
     1.3 @@ -1496,6 +1496,79 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 +DYNAMIC_API PEP_STATUS get_userid_alias_default(
     1.8 +        PEP_SESSION session, 
     1.9 +        char* alias_id,
    1.10 +        char** default_id) {
    1.11 +            
    1.12 +    assert(session);
    1.13 +    assert(alias_id);
    1.14 +    assert(alias_id[0]);
    1.15 +    assert(default_id);
    1.16 +
    1.17 +    if (!(session && alias_id && alias_id[0] && default_id))
    1.18 +        return PEP_ILLEGAL_VALUE;
    1.19 +
    1.20 +    PEP_STATUS status = PEP_STATUS_OK;
    1.21 +    char* retval = NULL;
    1.22 +
    1.23 +    sqlite3_reset(session->get_userid_alias_default);
    1.24 +    sqlite3_bind_text(session->get_userid_alias_default, 1, alias_id, -1, SQLITE_STATIC);
    1.25 +
    1.26 +    const char* tempid;
    1.27 +    
    1.28 +    const int result = sqlite3_step(session->get_userid_alias_default);
    1.29 +    switch (result) {
    1.30 +    case SQLITE_ROW:
    1.31 +        tempid = (const char *) sqlite3_column_text(session->get_userid_alias_default, 0);
    1.32 +        if (tempid) {
    1.33 +            retval = strdup(tempid);
    1.34 +            assert(retval);
    1.35 +            if (retval == NULL)
    1.36 +                return PEP_OUT_OF_MEMORY;
    1.37 +        }
    1.38 +    
    1.39 +        *default_id = retval;
    1.40 +        break;
    1.41 +    default:
    1.42 +        status = PEP_CANNOT_FIND_ALIAS;
    1.43 +        *default_id = NULL;
    1.44 +    }
    1.45 +
    1.46 +    sqlite3_reset(session->get_userid_alias_default);
    1.47 +    return status;            
    1.48 +}
    1.49 +
    1.50 +DYNAMIC_API PEP_STATUS set_userid_alias (
    1.51 +        PEP_SESSION session, 
    1.52 +        char* default_id,
    1.53 +        char* alias_id) {
    1.54 +            
    1.55 +    int result;
    1.56 +
    1.57 +    assert(session);
    1.58 +    assert(default_id);
    1.59 +    assert(alias_id);
    1.60 +
    1.61 +    if (!(session && default_id && alias_id && 
    1.62 +          default_id[0] != '\0' && alias_id[0] != '\0'))
    1.63 +        return PEP_ILLEGAL_VALUE;
    1.64 +
    1.65 +    sqlite3_reset(session->add_userid_alias);
    1.66 +    sqlite3_bind_text(session->add_userid_alias, 1, default_id, -1,
    1.67 +            SQLITE_STATIC);
    1.68 +    sqlite3_bind_text(session->add_userid_alias, 2, alias_id, -1,
    1.69 +            SQLITE_STATIC);
    1.70 +        
    1.71 +    result = sqlite3_step(session->add_userid_alias);
    1.72 +
    1.73 +    sqlite3_reset(session->add_userid_alias);
    1.74 +    if (result != SQLITE_DONE)
    1.75 +        return PEP_CANNOT_SET_ALIAS;
    1.76 +    
    1.77 +    return PEP_STATUS_OK;
    1.78 +}
    1.79 +
    1.80  DYNAMIC_API PEP_STATUS get_identity(
    1.81          PEP_SESSION session,
    1.82          const char *address,
     2.1 --- a/src/pEpEngine.h	Wed Jan 17 00:25:36 2018 +0100
     2.2 +++ b/src/pEpEngine.h	Wed Jan 17 01:01:10 2018 +0100
     2.3 @@ -56,6 +56,9 @@
     2.4      PEP_CANNOT_SET_TRUST                            = 0x0384,
     2.5      PEP_KEY_BLACKLISTED                             = 0x0385,
     2.6      
     2.7 +    PEP_CANNOT_FIND_ALIAS                           = 0x0391,
     2.8 +    PEP_CANNOT_SET_ALIAS                            = 0x0392,
     2.9 +    
    2.10      PEP_UNENCRYPTED                                 = 0x0400,
    2.11      PEP_VERIFIED                                    = 0x0401,
    2.12      PEP_DECRYPTED                                   = 0x0402,
    2.13 @@ -622,6 +625,45 @@
    2.14          char** userid
    2.15      );
    2.16  
    2.17 +// get_userid_alias_default() - get the default user_id which corresponds
    2.18 +//                              to an alias
    2.19 +//    parameters:
    2.20 +//        session (in)        session handle
    2.21 +//        alias_id (in)       the user_id which may be an alias for a default id
    2.22 +//        default_id (out)    the default id for this alias, if the alias
    2.23 +//                            is in the DB as an alias, else NULL
    2.24 +//    return value:
    2.25 +//        PEP_STATUS_OK = 0             userid was found
    2.26 +//        PEP_CANNOT_FIND_ALIAS         this userid is not listed as an 
    2.27 +//                                      alias in the DB
    2.28 +//        PEP_UNKNOWN_ERROR             results were returned, but no ID
    2.29 +//                                      found (no reason this should ever occur)
    2.30 +//    caveat:
    2.31 +//        default_id will be NULL if not found; otherwise, returned string
    2.32 +//        belongs to the caller.
    2.33 +//        also, current implementation does NOT check to see if this userid
    2.34 +//        IS a default.
    2.35 +
    2.36 +DYNAMIC_API PEP_STATUS get_userid_alias_default(
    2.37 +        PEP_SESSION session, 
    2.38 +        char* alias_id,
    2.39 +        char** default_id);
    2.40 +
    2.41 +// set_userid_alias() - set an alias to correspond to a default id
    2.42 +//    parameters:
    2.43 +//        session (in)        session handle
    2.44 +//        default_id (in)     the default id for this alias. This must
    2.45 +//                            correspond to the default user_id for an
    2.46 +//                            entry in the person (user) table.
    2.47 +//        alias_id (in)       the alias to be set for this default id
    2.48 +//    return value:
    2.49 +//        PEP_STATUS_OK = 0             userid was found
    2.50 +//        PEP_CANNOT_SET_ALIAS          there was an error setting this
    2.51 +
    2.52 +DYNAMIC_API PEP_STATUS set_userid_alias (
    2.53 +        PEP_SESSION session, 
    2.54 +        char* default_id,
    2.55 +        char* alias_id);
    2.56  
    2.57  // set_device_group() - update own person's device group
    2.58  //
     3.1 --- a/src/pEp_internal.h	Wed Jan 17 00:25:36 2018 +0100
     3.2 +++ b/src/pEp_internal.h	Wed Jan 17 01:01:10 2018 +0100
     3.3 @@ -174,7 +174,6 @@
     3.4      sqlite3_stmt *get_userid_alias_default;
     3.5      sqlite3_stmt *add_userid_alias;
     3.6  
     3.7 -
     3.8      // callbacks
     3.9      examine_identity_t examine_identity;
    3.10      void *examine_management;