src/pEp_internal.h
branchsequoia_windows
changeset 3966 67a11b194bbb
parent 3888 99d255a8dc60
parent 3963 60b100beecb3
child 4036 9ecb9fbb5f6b
     1.1 --- a/src/pEp_internal.h	Wed Aug 07 08:16:15 2019 +0200
     1.2 +++ b/src/pEp_internal.h	Thu Aug 08 08:10:32 2019 +0200
     1.3 @@ -51,7 +51,14 @@
     1.4  #define PEP_MSG_WRAP_KEY_LEN 26
     1.5  #endif
     1.6  
     1.7 +#ifndef X_PEP_MSG_WRAP_KEY
     1.8 +#define X_PEP_MSG_WRAP_KEY "X-pEp-Wrapped-Message-Info"
     1.9 +#endif
    1.10  
    1.11 +#ifndef X_PEP_SNDR_FPR_KEY
    1.12 +#define X_PEP_SNDR_FPR_KEY "X-pEp-Sender-FPR"
    1.13 +#endif
    1.14 + 
    1.15  #include "platform.h"
    1.16  
    1.17  #ifdef WIN32
    1.18 @@ -176,6 +183,7 @@
    1.19      sqlite3_stmt *exists_person;    
    1.20      sqlite3_stmt *set_as_pEp_user;
    1.21      sqlite3_stmt *is_pEp_user;
    1.22 +    sqlite3_stmt *upgrade_pEp_version_by_user_id;
    1.23      sqlite3_stmt *add_into_social_graph;
    1.24      sqlite3_stmt *get_own_address_binding_from_contact;
    1.25      sqlite3_stmt *set_revoke_contact_as_notified;
    1.26 @@ -190,6 +198,7 @@
    1.27      sqlite3_stmt *exists_identity_entry;        
    1.28      sqlite3_stmt *set_identity_flags;
    1.29      sqlite3_stmt *unset_identity_flags;
    1.30 +    sqlite3_stmt *set_pEp_version;    
    1.31      sqlite3_stmt *set_trust;
    1.32      sqlite3_stmt *update_trust;
    1.33      sqlite3_stmt *exists_trust_entry;
    1.34 @@ -280,6 +289,13 @@
    1.35          size_t psize, char **ctext, size_t *csize
    1.36  );
    1.37  
    1.38 +void decorate_message(
    1.39 +    message *msg,
    1.40 +    PEP_rating rating,
    1.41 +    stringlist_t *keylist,
    1.42 +    bool add_version,
    1.43 +    bool clobber);
    1.44 +
    1.45  #if defined(NDEBUG) || defined(NOLOG)
    1.46  #define DEBUG_LOG(TITLE, ENTITY, DESC)
    1.47  #else
    1.48 @@ -450,6 +466,68 @@
    1.49      return retval;
    1.50  }
    1.51  
    1.52 +static inline float pEp_version_numeric(const char* version_str) {
    1.53 +    float retval = 0;    
    1.54 +        
    1.55 +    if (!version_str || sscanf(version_str, "%f", &retval) != 1)
    1.56 +        return 0;
    1.57 +        
    1.58 +    return retval;    
    1.59 +}
    1.60 +
    1.61 +static inline void pEp_version_major_minor(const char* version_str, unsigned int* major, unsigned int* minor) {
    1.62 +    if (!major || !minor)
    1.63 +        return;
    1.64 +                
    1.65 +    if (!version_str || sscanf(version_str, "%u.%u", major, minor) != 2) {
    1.66 +        *major = 0;
    1.67 +        *minor = 0;
    1.68 +    }
    1.69 +        
    1.70 +    return;    
    1.71 +}
    1.72 +
    1.73 +static inline int compare_versions(unsigned int first_maj, unsigned int first_min,
    1.74 +                                   unsigned int second_maj, unsigned int second_min) {
    1.75 +    if (first_maj > second_maj)
    1.76 +        return 1;
    1.77 +    if (first_maj < second_maj)
    1.78 +        return -1;
    1.79 +    if (first_min > second_min)
    1.80 +        return 1;
    1.81 +    if (first_min < second_min)
    1.82 +        return -1;
    1.83 +    return 0;    
    1.84 +}
    1.85 +
    1.86 +static inline void set_min_version(unsigned int first_maj, unsigned int first_minor,
    1.87 +                                   unsigned int second_maj, unsigned int second_minor,
    1.88 +                                   unsigned int* result_maj, unsigned int* result_minor) {
    1.89 +    int result = compare_versions(first_maj, first_minor, second_maj, second_minor);
    1.90 +    if (result < 0) {
    1.91 +        *result_maj = first_maj;
    1.92 +        *result_minor = first_minor;
    1.93 +    }
    1.94 +    else {
    1.95 +        *result_maj = second_maj;
    1.96 +        *result_minor = second_minor;
    1.97 +    }    
    1.98 +}
    1.99 +
   1.100 +static inline void set_max_version(unsigned int first_maj, unsigned int first_minor,
   1.101 +                                   unsigned int second_maj, unsigned int second_minor,
   1.102 +                                   unsigned int* result_maj, unsigned int* result_minor) {
   1.103 +    int result = compare_versions(first_maj, first_minor, second_maj, second_minor);
   1.104 +    if (result > 0) {
   1.105 +        *result_maj = first_maj;
   1.106 +        *result_minor = first_minor;
   1.107 +    }
   1.108 +    else {
   1.109 +        *result_maj = second_maj;
   1.110 +        *result_minor = second_minor;
   1.111 +    }    
   1.112 +}
   1.113 +
   1.114  #ifndef EMPTYSTR
   1.115  #define EMPTYSTR(STR) ((STR) == NULL || (STR)[0] == '\0')
   1.116  #endif
   1.117 @@ -465,7 +543,6 @@
   1.118  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
   1.119  #endif
   1.120  
   1.121 -
   1.122  // These are globals used in generating message IDs and should only be
   1.123  // computed once, as they're either really constants or OS-dependent
   1.124  
   1.125 @@ -487,4 +564,3 @@
   1.126      } while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
   1.127      return rc;
   1.128  }
   1.129 -