ENGINE-275: fixed some opt_field messes, update source identity on the inner message (since it won't have relevant information for assessing rating otherwise) for decryption ENGINE-275
authorKrista Bennett <krista@pep-project.org>
Fri, 13 Oct 2017 11:02:02 +0200
branchENGINE-275
changeset 21560df79faabcc7
parent 2155 9d16b7e422cc
child 2157 bb39881db930
ENGINE-275: fixed some opt_field messes, update source identity on the inner message (since it won't have relevant information for assessing rating otherwise) for decryption
src/message_api.c
     1.1 --- a/src/message_api.c	Thu Oct 12 17:45:48 2017 +0200
     1.2 +++ b/src/message_api.c	Fri Oct 13 11:02:02 2017 +0200
     1.3 @@ -102,6 +102,56 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +void add_opt_field(message *msg, const char *name, const char *value)
     1.8 +{
     1.9 +    assert(msg && name && value);
    1.10 +
    1.11 +    if (msg && name && value) {
    1.12 +        stringpair_t *pair = new_stringpair(name, value);
    1.13 +        if (pair == NULL)
    1.14 +            return;
    1.15 +
    1.16 +        stringpair_list_t *field = stringpair_list_add(msg->opt_fields, pair);
    1.17 +        if (field == NULL)
    1.18 +        {
    1.19 +            free_stringpair(pair);
    1.20 +            return;
    1.21 +        }
    1.22 +
    1.23 +        if (msg->opt_fields == NULL)
    1.24 +            msg->opt_fields = field;
    1.25 +    }
    1.26 +}
    1.27 +
    1.28 +void replace_opt_field(message *msg, const char *name, const char *value)
    1.29 +{
    1.30 +    assert(msg && name && value);
    1.31 +    
    1.32 +    if (msg && name && value) {
    1.33 +        stringpair_list_t* opt_fields = msg->opt_fields;
    1.34 +        stringpair_t* pair = NULL;
    1.35 +        if (opt_fields) {
    1.36 +            while (opt_fields) {
    1.37 +                pair = opt_fields->value;
    1.38 +                if (pair && (strcmp(name, pair->key) == 0))
    1.39 +                    break;
    1.40 +                    
    1.41 +                pair = NULL;
    1.42 +                opt_fields = opt_fields->next;
    1.43 +            }
    1.44 +        }
    1.45 +        
    1.46 +        if (pair) {
    1.47 +            free(pair->value);
    1.48 +            pair->value = strdup(value);
    1.49 +        }
    1.50 +        else {
    1.51 +            add_opt_field(msg, name, value);
    1.52 +        }
    1.53 +    }
    1.54 +}
    1.55 +
    1.56 +
    1.57  static void decorate_message(
    1.58      message *msg,
    1.59      PEP_rating rating,
    1.60 @@ -110,14 +160,14 @@
    1.61  {
    1.62      assert(msg);
    1.63  
    1.64 -    add_opt_field(msg, "X-pEp-Version", PEP_VERSION);
    1.65 +    replace_opt_field(msg, "X-pEp-Version", PEP_VERSION);
    1.66  
    1.67      if (rating != PEP_rating_undefined)
    1.68 -        add_opt_field(msg, "X-EncStatus", rating_to_string(rating));
    1.69 +        replace_opt_field(msg, "X-EncStatus", rating_to_string(rating));
    1.70  
    1.71      if (keylist) {
    1.72          char *_keylist = keylist_to_string(keylist);
    1.73 -        add_opt_field(msg, "X-KeyList", _keylist);
    1.74 +        replace_opt_field(msg, "X-KeyList", _keylist);
    1.75          free(_keylist);
    1.76      }
    1.77  }
    1.78 @@ -181,26 +231,6 @@
    1.79      return strcmp(bl->filename + (fn_len - fe_len), fe) == 0;
    1.80  }
    1.81  
    1.82 -void add_opt_field(message *msg, const char *name, const char *value)
    1.83 -{
    1.84 -    assert(msg && name && value);
    1.85 -
    1.86 -    if (msg && name && value) {
    1.87 -        stringpair_t *pair = new_stringpair(name, value);
    1.88 -        if (pair == NULL)
    1.89 -            return;
    1.90 -
    1.91 -        stringpair_list_t *field = stringpair_list_add(msg->opt_fields, pair);
    1.92 -        if (field == NULL)
    1.93 -        {
    1.94 -            free_stringpair(pair);
    1.95 -            return;
    1.96 -        }
    1.97 -
    1.98 -        if (msg->opt_fields == NULL)
    1.99 -            msg->opt_fields = field;
   1.100 -    }
   1.101 -}
   1.102  
   1.103  static char * encapsulate_message_wrap_info(const char *msg_wrap_info, const char *longmsg)
   1.104  {
   1.105 @@ -543,7 +573,7 @@
   1.106      
   1.107      message* _envelope = envelope;
   1.108  
   1.109 -    add_opt_field(attachment, "X-pEp-Version", PEP_VERSION);
   1.110 +    replace_opt_field(attachment, "X-pEp-Version", PEP_VERSION);
   1.111  
   1.112      if (!_envelope) {
   1.113          _envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
   1.114 @@ -2163,14 +2193,18 @@
   1.115                                      // and those are the only ones with such info.
   1.116                                      // Since we capture the information, this is ok.
   1.117                                      wrap_info = NULL;
   1.118 -                                    inner_message->enc_format = PEP_enc_PGP_MIME;
   1.119 +                                    inner_message->enc_format = src->enc_format;
   1.120                                      // FIXME
   1.121                                      status = unencapsulate_hidden_fields(inner_message, NULL, &wrap_info);
   1.122                                      if (wrap_info) {
   1.123                                          // useless check, but just in case we screw up?
   1.124                                          if (strcmp(wrap_info, "INNER") == 0) {
   1.125                                              // THIS is our message
   1.126 +                                            // FIXME: free msg, but check references
   1.127                                              src = msg = inner_message;
   1.128 +                                            
   1.129 +                                            if (src->from)
   1.130 +                                                update_identity(session, src->from);
   1.131                                              break;        
   1.132                                          }
   1.133                                          else { // should never happen