sync : added get_device_group sql stuff keysync
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 30 Sep 2016 17:25:15 +0200
branchkeysync
changeset 1235cfc9214a60a5
parent 1234 c03758736a0b
child 1236 991afc1aa2a1
sync : added get_device_group sql stuff
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Fri Sep 30 16:10:26 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Fri Sep 30 17:25:15 2016 +0200
     1.3 @@ -30,6 +30,7 @@
     1.4      static const char *sql_get_identity;
     1.5      static const char *sql_set_person;
     1.6      static const char *sql_set_device_group;
     1.7 +    static const char *sql_get_device_group;
     1.8      static const char *sql_set_pgp_keypair;
     1.9      static const char *sql_set_identity;
    1.10      static const char *sql_set_identity_flags;
    1.11 @@ -326,6 +327,9 @@
    1.12          sql_set_device_group = "update person set device_group = ?1 "
    1.13                                 "where user_id = '" PEP_OWN_USERID "';";
    1.14  
    1.15 +        sql_get_device_group = "select device_group from person "
    1.16 +                               "where user_id = '" PEP_OWN_USERID "';";
    1.17 +
    1.18          sql_set_pgp_keypair = "insert or replace into pgp_keypair (fpr) "
    1.19                                "values (upper(replace(?1,' ',''))) ;";
    1.20  
    1.21 @@ -424,6 +428,10 @@
    1.22              (int)strlen(sql_set_device_group), &_session->set_device_group, NULL);
    1.23      assert(int_result == SQLITE_OK);
    1.24  
    1.25 +    int_result = sqlite3_prepare_v2(_session->db, sql_get_device_group,
    1.26 +            (int)strlen(sql_get_device_group), &_session->get_device_group, NULL);
    1.27 +    assert(int_result == SQLITE_OK);
    1.28 +
    1.29      int_result = sqlite3_prepare_v2(_session->db, sql_set_pgp_keypair,
    1.30              (int)strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair,
    1.31              NULL);
    1.32 @@ -592,6 +600,8 @@
    1.33                  sqlite3_finalize(session->set_person);
    1.34              if (session->set_device_group)
    1.35                  sqlite3_finalize(session->set_device_group);
    1.36 +            if (session->get_device_group)
    1.37 +                sqlite3_finalize(session->get_device_group);
    1.38              if (session->set_pgp_keypair)
    1.39                  sqlite3_finalize(session->set_pgp_keypair);
    1.40              if (session->set_identity)
    1.41 @@ -1109,6 +1119,37 @@
    1.42      return PEP_STATUS_OK;
    1.43  }
    1.44  
    1.45 +DYNAMIC_API PEP_STATUS get_device_group(PEP_SESSION session, char **group_name)
    1.46 +{
    1.47 +    PEP_STATUS status = PEP_STATUS_OK;
    1.48 +    int result;
    1.49 +
    1.50 +    assert(session);
    1.51 +    assert(group_name);
    1.52 +
    1.53 +    if (!(session && group_name))
    1.54 +        return PEP_ILLEGAL_VALUE;
    1.55 +
    1.56 +    sqlite3_reset(session->get_device_group);
    1.57 +
    1.58 +    result = sqlite3_step(session->get_device_group);
    1.59 +    switch (result) {
    1.60 +    case SQLITE_ROW: {
    1.61 +        *group_name = strdup(
    1.62 +            (const char *) sqlite3_column_text(session->get_device_group, 0));
    1.63 +            if(*group_name == NULL)
    1.64 +                status = PEP_OUT_OF_MEMORY;
    1.65 +        break;
    1.66 +    }
    1.67 + 
    1.68 +    default:
    1.69 +        status = PEP_RECORD_NOT_FOUND;
    1.70 +    }
    1.71 +
    1.72 +    sqlite3_reset(session->get_device_group);
    1.73 +    return status;
    1.74 +}
    1.75 +
    1.76  DYNAMIC_API PEP_STATUS set_identity_flags(
    1.77          PEP_SESSION session,
    1.78          pEp_identity *identity,
     2.1 --- a/src/pEpEngine.h	Fri Sep 30 16:10:26 2016 +0200
     2.2 +++ b/src/pEpEngine.h	Fri Sep 30 17:25:15 2016 +0200
     2.3 @@ -537,7 +537,7 @@
     2.4  //        group_name (in)     new group name
     2.5  //
     2.6  //    return value:
     2.7 -//        PEP_STATUS_OK = 0             encryption and signing succeeded
     2.8 +//        PEP_STATUS_OK = 0             device group was updated
     2.9  //        PEP_CANNOT_SET_PERSON         update failed
    2.10  
    2.11  DYNAMIC_API PEP_STATUS set_device_group(
    2.12 @@ -545,6 +545,24 @@
    2.13          const char *group_name
    2.14      );
    2.15  
    2.16 +// get_device_group() - get own person's device group
    2.17 +//
    2.18 +//    parameters:
    2.19 +//        session (in)        session handle
    2.20 +//        group_name (in)     new group name
    2.21 +//
    2.22 +//    return value:
    2.23 +//        PEP_STATUS_OK = 0             couldn't get device group
    2.24 +//        PEP_RECORD_NOT_FOUND          update failed
    2.25 +//
    2.26 +//    caveat:
    2.27 +//        the ownerships of group_name is going to the caller
    2.28 +
    2.29 +DYNAMIC_API PEP_STATUS get_device_group(
    2.30 +        PEP_SESSION session, 
    2.31 +        char **group_name
    2.32 +    );
    2.33 +
    2.34  // set_identity_flags() - update identity flags on existing identity
    2.35  //
    2.36  //    parameters:
     3.1 --- a/src/pEp_internal.h	Fri Sep 30 16:10:26 2016 +0200
     3.2 +++ b/src/pEp_internal.h	Fri Sep 30 17:25:15 2016 +0200
     3.3 @@ -98,6 +98,7 @@
     3.4      sqlite3_stmt *get_identity;
     3.5      sqlite3_stmt *set_person;
     3.6      sqlite3_stmt *set_device_group;
     3.7 +    sqlite3_stmt *get_device_group;
     3.8      sqlite3_stmt *set_pgp_keypair;
     3.9      sqlite3_stmt *set_identity;
    3.10      sqlite3_stmt *set_identity_flags;