sync : added set_device_group sql stuff keysync
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 30 Sep 2016 16:10:26 +0200
branchkeysync
changeset 1234c03758736a0b
parent 1233 9d4ae88baa53
child 1235 cfc9214a60a5
sync : added set_device_group sql stuff
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Fri Sep 30 16:07:57 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Fri Sep 30 16:10:26 2016 +0200
     1.3 @@ -29,6 +29,7 @@
     1.4      static const char *sql_trustword;
     1.5      static const char *sql_get_identity;
     1.6      static const char *sql_set_person;
     1.7 +    static const char *sql_set_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 @@ -322,6 +323,9 @@
    1.12                           "    (select coalesce((select main_key_id from person "
    1.13                           "      where id = ?1), upper(replace(?4,' ',''))))) ;";
    1.14  
    1.15 +        sql_set_device_group = "update person set device_group = ?1 "
    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 @@ -416,6 +420,10 @@
    1.22              (int)strlen(sql_set_person), &_session->set_person, NULL);
    1.23      assert(int_result == SQLITE_OK);
    1.24  
    1.25 +    int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
    1.26 +            (int)strlen(sql_set_device_group), &_session->set_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 @@ -582,6 +590,8 @@
    1.33                  sqlite3_finalize(session->get_identity);
    1.34              if (session->set_person)
    1.35                  sqlite3_finalize(session->set_person);
    1.36 +            if (session->set_device_group)
    1.37 +                sqlite3_finalize(session->set_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 @@ -1075,6 +1085,30 @@
    1.42          return PEP_COMMIT_FAILED;
    1.43  }
    1.44  
    1.45 +DYNAMIC_API PEP_STATUS set_device_group(
    1.46 +        PEP_SESSION session,
    1.47 +        const char *group_name
    1.48 +    )
    1.49 +{
    1.50 +    int result;
    1.51 +
    1.52 +    assert(session);
    1.53 +    assert(group_name);
    1.54 +
    1.55 +    if (!(session && group_name))
    1.56 +        return PEP_ILLEGAL_VALUE;
    1.57 +
    1.58 +    sqlite3_reset(session->set_device_group);
    1.59 +    sqlite3_bind_text(session->set_device_group, 1, group_name, -1,
    1.60 +            SQLITE_STATIC);
    1.61 +    result = sqlite3_step(session->set_device_group);
    1.62 +    sqlite3_reset(session->set_device_group);
    1.63 +    if (result != SQLITE_DONE)
    1.64 +        return PEP_CANNOT_SET_PERSON;
    1.65 +
    1.66 +    return PEP_STATUS_OK;
    1.67 +}
    1.68 +
    1.69  DYNAMIC_API PEP_STATUS set_identity_flags(
    1.70          PEP_SESSION session,
    1.71          pEp_identity *identity,
     2.1 --- a/src/pEpEngine.h	Fri Sep 30 16:07:57 2016 +0200
     2.2 +++ b/src/pEpEngine.h	Fri Sep 30 16:10:26 2016 +0200
     2.3 @@ -530,6 +530,20 @@
     2.4          PEP_SESSION session, const pEp_identity *identity
     2.5      );
     2.6  
     2.7 +// set_device_group() - update own person's device group
     2.8 +//
     2.9 +//    parameters:
    2.10 +//        session (in)        session handle
    2.11 +//        group_name (in)     new group name
    2.12 +//
    2.13 +//    return value:
    2.14 +//        PEP_STATUS_OK = 0             encryption and signing succeeded
    2.15 +//        PEP_CANNOT_SET_PERSON         update failed
    2.16 +
    2.17 +DYNAMIC_API PEP_STATUS set_device_group(
    2.18 +        PEP_SESSION session,
    2.19 +        const char *group_name
    2.20 +    );
    2.21  
    2.22  // set_identity_flags() - update identity flags on existing identity
    2.23  //
     3.1 --- a/src/pEp_internal.h	Fri Sep 30 16:07:57 2016 +0200
     3.2 +++ b/src/pEp_internal.h	Fri Sep 30 16:10:26 2016 +0200
     3.3 @@ -97,6 +97,7 @@
     3.4      sqlite3_stmt *trustword;
     3.5      sqlite3_stmt *get_identity;
     3.6      sqlite3_stmt *set_person;
     3.7 +    sqlite3_stmt *set_device_group;
     3.8      sqlite3_stmt *set_pgp_keypair;
     3.9      sqlite3_stmt *set_identity;
    3.10      sqlite3_stmt *set_identity_flags;