merged
authorVolker Birk <vb@pep.foundation>
Sat, 24 Feb 2018 16:51:55 +0100
changeset 2536ee7e89ef6a18
parent 2535 76edc488ccdd
parent 2534 9d17c132c770
child 2537 e5dfe9a29d1c
child 2539 58c77e002d60
merged
     1.1 --- a/src/message_api.c	Sat Feb 24 16:51:38 2018 +0100
     1.2 +++ b/src/message_api.c	Sat Feb 24 16:51:55 2018 +0100
     1.3 @@ -940,8 +940,16 @@
     1.4      for (id_list_ptr = list; id_list_ptr; id_list_ptr = id_list_ptr->next) {
     1.5          pEp_identity* curr_identity = id_list_ptr->ident;
     1.6          if (curr_identity) {
     1.7 -            if (!is_me(session, curr_identity))
     1.8 +            if (!is_me(session, curr_identity)) {
     1.9 +                char* name_bak = curr_identity->username;
    1.10 +                curr_identity->username = NULL;
    1.11                  status = update_identity(session, curr_identity);
    1.12 +                if (name_bak && 
    1.13 +                    (EMPTYSTR(curr_identity->username) || strcmp(name_bak, curr_identity->username) != 0)) {
    1.14 +                    free(curr_identity->username);
    1.15 +                    curr_identity->username = name_bak;
    1.16 +                }                        
    1.17 +            }
    1.18              else
    1.19                  status = myself(session, curr_identity);
    1.20          if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY)
     2.1 --- a/test/test_util.cc	Sat Feb 24 16:51:38 2018 +0100
     2.2 +++ b/test/test_util.cc	Sat Feb 24 16:51:55 2018 +0100
     2.3 @@ -6,6 +6,43 @@
     2.4  #include <sstream>
     2.5  #include <stdexcept>
     2.6  
     2.7 +char* str_to_lower(const char* str) {
     2.8 +    if (!str)
     2.9 +        return NULL;
    2.10 +    int str_len = strlen(str);
    2.11 +    if (str_len == 0)
    2.12 +        return strdup("");
    2.13 +    int i;
    2.14 +    
    2.15 +    char* retval = (char*) calloc(1, str_len + 1);
    2.16 +    for (i = 0; i < str_len; i++) {
    2.17 +        retval[i] = tolower(str[i]);
    2.18 +    }    
    2.19 +    return retval;
    2.20 +}
    2.21 +
    2.22 +// Because annoyed
    2.23 +bool _streq(const char* str1, const char* str2) {
    2.24 +    if (!str1) {
    2.25 +        if (str2)
    2.26 +            return false;
    2.27 +        return true;
    2.28 +    }
    2.29 +    if (!str2)
    2.30 +        return false;
    2.31 +        
    2.32 +    return (strcmp(str1, str2) == 0);
    2.33 +}
    2.34 +
    2.35 +bool _strceq(const char* str1, const char* str2) {
    2.36 +    char* str1_dup = str_to_lower(str1);
    2.37 +    char* str2_dup = str_to_lower(str2);
    2.38 +
    2.39 +    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
    2.40 +    free(str1_dup);
    2.41 +    free(str2_dup);
    2.42 +    return retval;
    2.43 +}
    2.44  
    2.45  void test_init() {
    2.46      unlink ("../test_home/.pEp_management.db");
     3.1 --- a/test/test_util.h	Sat Feb 24 16:51:38 2018 +0100
     3.2 +++ b/test/test_util.h	Sat Feb 24 16:51:55 2018 +0100
     3.3 @@ -4,6 +4,10 @@
     3.4  
     3.5  void test_init();
     3.6  
     3.7 +// string equality (case and non-case sensitive)
     3.8 +bool _streq(const char* str1, const char* str2);
     3.9 +bool _strceq(const char* str1, const char* str2);
    3.10 +
    3.11  // reads a whole file and returns it as std::string
    3.12  // throws std::runtime_error() if the file cannot be read. Empty file is not an error.
    3.13  std::string slurp(const std::string& filename);