updatable management.db
authorVolker Birk <vb@pep-project.org>
Wed, 27 Jul 2016 12:35:51 +0200
changeset 928c87f1fdaff36
parent 926 95247f30b919
child 929 b094dd6bb553
updatable management.db
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Tue Jul 26 11:03:29 2016 +0200
     1.2 +++ b/src/pEpEngine.c	Wed Jul 27 12:35:51 2016 +0200
     1.3 @@ -6,6 +6,19 @@
     1.4  
     1.5  static int init_count = -1;
     1.6  
     1.7 +static int user_version(void *_version, int count, char **text, char **name)
     1.8 +{
     1.9 +    assert(_version);
    1.10 +    assert(count == 1);
    1.11 +    assert(text && text[0]);
    1.12 +    if (!(_version && count == 1 && text && text[0]))
    1.13 +        return -1;
    1.14 +
    1.15 +    int *version = (int *) _version;
    1.16 +    *version = atoi(text[0]);
    1.17 +    return 0;
    1.18 +}
    1.19 +
    1.20  DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
    1.21  {
    1.22      PEP_STATUS status = PEP_STATUS_OK;
    1.23 @@ -112,15 +125,37 @@
    1.24  
    1.25      sqlite3_busy_timeout(_session->system_db, 1000);
    1.26  
    1.27 +// increment this when patching DDL
    1.28 +#define _DDL_USER_VERSION "1"
    1.29 +
    1.30      if (in_first) {
    1.31          int_result = sqlite3_exec(
    1.32              _session->db,
    1.33 -                "create table if not exists version_info (\n"
    1.34 +                "create table version_info (\n"
    1.35                  "   id integer primary key,\n"
    1.36                  "   timestamp integer default (datetime('now')) ,\n"
    1.37                  "   version text,\n"
    1.38                  "   comment text\n"
    1.39 -                ");\n"
    1.40 +                ");\n",
    1.41 +                NULL,
    1.42 +                NULL,
    1.43 +                NULL
    1.44 +        );
    1.45 +        if (int_result == SQLITE_OK) {
    1.46 +            int_result = sqlite3_exec(
    1.47 +                _session->db,
    1.48 +                "pragma user_version = "_DDL_USER_VERSION";\n"
    1.49 +                "insert or replace into version_info (id, version)"
    1.50 +                    "values (1, '" PEP_ENGINE_VERSION "');",
    1.51 +                NULL,
    1.52 +                NULL,
    1.53 +                NULL
    1.54 +            );
    1.55 +            assert(int_result == SQLITE_OK);
    1.56 +        }
    1.57 +
    1.58 +        int_result = sqlite3_exec(
    1.59 +            _session->db,
    1.60                  "create table if not exists log (\n"
    1.61                  "   timestamp integer default (datetime('now')) ,\n"
    1.62                  "   title text not null,\n"
    1.63 @@ -160,6 +195,7 @@
    1.64                  "       references pgp_keypair (fpr)\n"
    1.65                  "       on delete set null,\n"
    1.66                  "   comment text,\n"
    1.67 +                "   flags integer default (0),"
    1.68                  "   primary key (address, user_id)\n"
    1.69                  ");\n"
    1.70                  "create table if not exists trust (\n"
    1.71 @@ -196,15 +232,41 @@
    1.72          );
    1.73          assert(int_result == SQLITE_OK);
    1.74  
    1.75 +        int version;
    1.76          int_result = sqlite3_exec(
    1.77              _session->db,
    1.78 -            "insert or replace into version_info (id, version) values (1, '1.1');",
    1.79 -            NULL,
    1.80 -            NULL,
    1.81 +            "pragma user_version;",
    1.82 +            user_version,
    1.83 +            &version,
    1.84              NULL
    1.85          );
    1.86          assert(int_result == SQLITE_OK);
    1.87  
    1.88 +        if (version < 1) {
    1.89 +            int_result = sqlite3_exec(
    1.90 +                _session->db,
    1.91 +                "alter table identity\n"
    1.92 +                "   add column flags integer default (0);",
    1.93 +                NULL,
    1.94 +                NULL,
    1.95 +                NULL
    1.96 +            );
    1.97 +            assert(int_result == SQLITE_OK);
    1.98 +        }
    1.99 +
   1.100 +        if (version < atoi(_DDL_USER_VERSION)) {
   1.101 +            int_result = sqlite3_exec(
   1.102 +                _session->db,
   1.103 +                "pragma user_version = "_DDL_USER_VERSION";\n"
   1.104 +                "insert or replace into version_info (id, version)"
   1.105 +                    "values (1, '" PEP_ENGINE_VERSION "');",
   1.106 +                NULL,
   1.107 +                NULL,
   1.108 +                NULL
   1.109 +            );
   1.110 +            assert(int_result == SQLITE_OK);
   1.111 +        }
   1.112 +
   1.113          sql_log = "insert into log (title, entity, description, comment)"
   1.114                    "values (?1, ?2, ?3, ?4);";
   1.115  
     2.1 --- a/src/pEpEngine.h	Tue Jul 26 11:03:29 2016 +0200
     2.2 +++ b/src/pEpEngine.h	Wed Jul 27 12:35:51 2016 +0200
     2.3 @@ -379,6 +379,11 @@
     2.4      PEP_ct_pEp = 0xff
     2.5  } PEP_comm_type;
     2.6  
     2.7 +typedef enum _identity_flags {
     2.8 +    PEP_idf_NOT_FOR_SYNC = 1,   // don't use this identity for sync
     2.9 +    PEP_idf_GROUP = 2           // identity of group of persons
    2.10 +} identity_flags;
    2.11 +
    2.12  typedef struct _pEp_identity {
    2.13      char *address;              // C string with address UTF-8 encoded
    2.14      char *fpr;                  // C string with fingerprint UTF-8 encoded
    2.15 @@ -388,6 +393,7 @@
    2.16      char lang[3];               // language of conversation
    2.17                                  // ISO 639-1 ALPHA-2, last byte is 0
    2.18      bool me;                    // if this is the local user herself/himself
    2.19 +    unsigned int flags;         // identity_flag1 | identity_flag2 | ...
    2.20  } pEp_identity;
    2.21  
    2.22  typedef struct _identity_list {
     3.1 --- a/src/pEp_internal.h	Tue Jul 26 11:03:29 2016 +0200
     3.2 +++ b/src/pEp_internal.h	Wed Jul 27 12:35:51 2016 +0200
     3.3 @@ -1,4 +1,4 @@
     3.4 -#define PEP_ENGINE_VERSION "0.7.0"
     3.5 +#define PEP_ENGINE_VERSION "0.8.0"
     3.6  
     3.7  // maximum attachment size to import as key 1MB, maximum of 20 attachments
     3.8