src/pEpEngine.c
branchkeysync
changeset 1235 cfc9214a60a5
parent 1234 c03758736a0b
child 1236 991afc1aa2a1
     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,