ENGINE-304: transferred auto-consume flag to inner message on decrypt
authorKrista Bennett <krista@pep-project.org>
Mon, 30 Oct 2017 17:26:06 +0100
changeset 2220772113c6b987
parent 2218 da5d2c04cd94
child 2221 07ce59b5c058
child 2222 1ab9f8ab0a1a
child 2224 e1529b69bab3
ENGINE-304: transferred auto-consume flag to inner message on decrypt
src/message_api.c
     1.1 --- a/src/message_api.c	Fri Oct 27 17:21:25 2017 +0200
     1.2 +++ b/src/message_api.c	Mon Oct 30 17:26:06 2017 +0100
     1.3 @@ -21,6 +21,21 @@
     1.4  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
     1.5  #endif
     1.6  
     1.7 +static const stringpair_t* search_optfields(message* msg, const char* key) {
     1.8 +    stringpair_list_t* opt_fields = msg->opt_fields;
     1.9 +    
    1.10 +    const stringpair_list_t* curr;
    1.11 +    
    1.12 +    for (curr = opt_fields; curr && curr->value; curr = curr->next) {
    1.13 +        if (curr->value->key) {
    1.14 +            if (strcasecmp(curr->value->key, key) == 0)
    1.15 +                return curr->value;
    1.16 +        }
    1.17 +    } 
    1.18 +    
    1.19 +    return NULL;
    1.20 +}
    1.21 +
    1.22  static char * keylist_to_string(const stringlist_t *keylist)
    1.23  {
    1.24      if (keylist) {
    1.25 @@ -1889,6 +1904,19 @@
    1.26      return status;
    1.27  }
    1.28  
    1.29 +static PEP_STATUS transfer_autoconsume(message* src, message* msg) {
    1.30 +    const stringpair_t* autoconsume = search_optfields(src, "pEp-auto-consume");
    1.31 +    
    1.32 +    PEP_STATUS status = PEP_STATUS_OK;
    1.33 +    
    1.34 +    if (autoconsume) {
    1.35 +        stringpair_t* cpy = stringpair_dup(autoconsume);
    1.36 +        if (!cpy || !(stringpair_list_add(msg->opt_fields, cpy)))
    1.37 +            status = PEP_OUT_OF_MEMORY;
    1.38 +    }
    1.39 +    return status;
    1.40 +}
    1.41 +
    1.42  static PEP_STATUS check_for_sync_msg(PEP_SESSION session, 
    1.43                                       message* src,
    1.44                                       PEP_rating* rating, 
    1.45 @@ -2437,6 +2465,13 @@
    1.46                                      if (wrap_info) {
    1.47                                          // useless check, but just in case we screw up?
    1.48                                          if (strcmp(wrap_info, "INNER") == 0) {
    1.49 +                                            // transfer autoconsume 
    1.50 +                                            status = transfer_autoconsume(src, inner_message);
    1.51 +                                            if (status != PEP_STATUS_OK) {
    1.52 +                                                free_message(inner_message);
    1.53 +                                                GOTO(pep_error);
    1.54 +                                            }
    1.55 +                                                
    1.56                                              // THIS is our message
    1.57                                              // FIXME: free msg, but check references
    1.58                                              src = msg = inner_message;