remove size fields of pEp_identity
authorVolker Birk <vb@pep-project.org>
Tue, 10 May 2016 18:24:49 +0200
changeset 591a3dbbf610d32
parent 590 d28f8852ac45
child 592 cbd8592f70fe
remove size fields of pEp_identity
src/keymanagement.c
src/pEpEngine.c
src/pEpEngine.h
     1.1 --- a/src/keymanagement.c	Tue May 10 17:32:54 2016 +0200
     1.2 +++ b/src/keymanagement.c	Tue May 10 18:24:49 2016 +0200
     1.3 @@ -76,18 +76,13 @@
     1.4      {
     1.5          free(identity->user_id);
     1.6  
     1.7 -        identity->user_id = calloc(1, identity->address_size + 6);
     1.8 +        identity->user_id = calloc(1, strlen(identity->address) + 6);
     1.9          if (!identity->user_id)
    1.10          {
    1.11              return PEP_OUT_OF_MEMORY;
    1.12          }
    1.13 -        snprintf(identity->user_id, identity->address_size + 5,
    1.14 +        snprintf(identity->user_id, strlen(identity->address) + 5,
    1.15                   "TOFU_%s", identity->address);
    1.16 -
    1.17 -        if(identity->user_id)
    1.18 -        {
    1.19 -            identity->user_id_size = strlen(identity->user_id);
    1.20 -        }
    1.21      }
    1.22      
    1.23      status = get_identity(session,
    1.24 @@ -108,19 +103,17 @@
    1.25  
    1.26          if (EMPTYSTR(identity->username)) {
    1.27              free(identity->username);
    1.28 -            identity->username = strndup(stored_identity->username, stored_identity->username_size);
    1.29 +            identity->username = strdup(stored_identity->username);
    1.30              assert(identity->username);
    1.31              if (identity->username == NULL)
    1.32                  return PEP_OUT_OF_MEMORY;
    1.33 -            identity->username_size = stored_identity->username_size;
    1.34          }
    1.35  
    1.36          if (EMPTYSTR(identity->fpr)) {
    1.37 -            identity->fpr = strndup(stored_identity->fpr, stored_identity->fpr_size);
    1.38 +            identity->fpr = strdup(stored_identity->fpr);
    1.39              assert(identity->fpr);
    1.40              if (identity->fpr == NULL)
    1.41                  return PEP_OUT_OF_MEMORY;
    1.42 -            identity->fpr_size = stored_identity->fpr_size;
    1.43              if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
    1.44                  identity->comm_type = _comm_type_key;
    1.45              }
    1.46 @@ -130,9 +123,9 @@
    1.47          }
    1.48          else /* !EMPTYSTR(identity->fpr) */ {
    1.49              if (_same_fpr(identity->fpr,
    1.50 -                          identity->fpr_size,
    1.51 +                          strlen(identity->fpr),
    1.52                            stored_identity->fpr,
    1.53 -                          stored_identity->fpr_size)) {
    1.54 +                          strlen(stored_identity->fpr))) {
    1.55                  if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
    1.56                      identity->comm_type = _comm_type_key;
    1.57                  }else{
    1.58 @@ -210,7 +203,6 @@
    1.59                      free_stringlist(keylist);
    1.60                      return PEP_OUT_OF_MEMORY;
    1.61                  }
    1.62 -                identity->fpr_size = strlen(identity->fpr);
    1.63              }
    1.64              free_stringlist(keylist);
    1.65          }
    1.66 @@ -226,7 +218,6 @@
    1.67              identity->username = strdup("anonymous");
    1.68              if (identity->username == NULL)
    1.69                  return PEP_OUT_OF_MEMORY;
    1.70 -            identity->username_size = 9;
    1.71          }
    1.72  
    1.73          // Identity doesn't get stored if is was just about checking existing
    1.74 @@ -282,13 +273,12 @@
    1.75      if (stored_identity)
    1.76      {
    1.77          if (EMPTYSTR(identity->fpr)) {
    1.78 -            identity->fpr = strndup(stored_identity->fpr, stored_identity->fpr_size);
    1.79 +            identity->fpr = strdup(stored_identity->fpr);
    1.80              assert(identity->fpr);
    1.81              if (identity->fpr == NULL)
    1.82              {
    1.83                  return PEP_OUT_OF_MEMORY;
    1.84              }
    1.85 -            identity->fpr_size = stored_identity->fpr_size;
    1.86          }
    1.87  
    1.88          // Backward compatibility, not check that stored key is indeed own key
    1.89 @@ -312,7 +302,6 @@
    1.90          stringlist_t *keylist = NULL;
    1.91  
    1.92          free(identity->fpr);
    1.93 -        identity->fpr_size = 0;
    1.94          
    1.95          status = find_keys(session, identity->address, &keylist);
    1.96          assert(status != PEP_OUT_OF_MEMORY);
    1.97 @@ -370,7 +359,6 @@
    1.98                      free_stringlist(keylist);
    1.99                      return PEP_OUT_OF_MEMORY;
   1.100                  }
   1.101 -                identity->fpr_size = strlen(identity->fpr);
   1.102              }
   1.103              free_stringlist(keylist);
   1.104          }
     2.1 --- a/src/pEpEngine.c	Tue May 10 17:32:54 2016 +0200
     2.2 +++ b/src/pEpEngine.c	Tue May 10 18:24:49 2016 +0200
     2.3 @@ -643,7 +643,6 @@
     2.4                  free(result);
     2.5                  return NULL;
     2.6              }
     2.7 -            result->address_size = strlen(address);
     2.8          }
     2.9          if (fpr) {
    2.10              result->fpr = strdup(fpr);
    2.11 @@ -652,7 +651,6 @@
    2.12                  free_identity(result);
    2.13                  return NULL;
    2.14              }
    2.15 -            result->fpr_size = strlen(fpr);
    2.16          }
    2.17          if (user_id) {
    2.18              result->user_id = strdup(user_id);
    2.19 @@ -661,7 +659,6 @@
    2.20                  free_identity(result);
    2.21                  return NULL;
    2.22              }
    2.23 -            result->user_id_size = strlen(user_id);
    2.24          }
    2.25          if (username) {
    2.26              result->username = strdup(username);
    2.27 @@ -670,9 +667,7 @@
    2.28                  free_identity(result);
    2.29                  return NULL;
    2.30              }
    2.31 -            result->username_size = strlen(username);
    2.32          }
    2.33 -        result->struct_size = sizeof(pEp_identity);
    2.34      }
    2.35      return result;
    2.36  }
     3.1 --- a/src/pEpEngine.h	Tue May 10 17:32:54 2016 +0200
     3.2 +++ b/src/pEpEngine.h	Tue May 10 18:24:49 2016 +0200
     3.3 @@ -363,15 +363,10 @@
     3.4  } PEP_comm_type;
     3.5  
     3.6  typedef struct _pEp_identity {
     3.7 -    size_t struct_size;         // size of whole struct
     3.8      char *address;              // C string with address UTF-8 encoded
     3.9 -    size_t address_size;        // size of address
    3.10      char *fpr;                  // C string with fingerprint UTF-8 encoded
    3.11 -    size_t fpr_size;            // size of fingerprint
    3.12      char *user_id;              // C string with user ID UTF-8 encoded
    3.13 -    size_t user_id_size;        // size of user ID
    3.14      char *username;             // C string with user name UTF-8 encoded
    3.15 -    size_t username_size;       // size of user name
    3.16      PEP_comm_type comm_type;    // type of communication with this ID
    3.17      char lang[3];               // language of conversation
    3.18                                  // ISO 639-1 ALPHA-2, last byte is 0