merge "default" into "roker-linux" branch roker-linux
authorRoker <roker@pep-project.org>
Wed, 13 Jul 2016 23:18:30 +0200
branchroker-linux
changeset 863c4d31c928b9f
parent 859 a3e8f082fc8a
parent 862 0f0414b15c72
child 865 6820715a0928
merge "default" into "roker-linux" branch
     1.1 --- a/src/message_api.c	Wed Jul 13 09:13:39 2016 +0200
     1.2 +++ b/src/message_api.c	Wed Jul 13 23:18:30 2016 +0200
     1.3 @@ -751,13 +751,11 @@
     1.4  
     1.5  static char * without_double_ending(const char *filename)
     1.6  {
     1.7 -    char *ext;
     1.8 -
     1.9      assert(filename);
    1.10      if (filename == NULL)
    1.11          return NULL;
    1.12      
    1.13 -    ext = strrchr(filename, '.');
    1.14 +    char *ext = strrchr(filename, '.');
    1.15      if (ext == NULL)
    1.16          return NULL;
    1.17  
    1.18 @@ -1235,22 +1233,26 @@
    1.19  
    1.20  // update comm_type to pEp_ct_pEp if needed
    1.21  
    1.22 -static void _update_identity_for_incoming_message(
    1.23 +static PEP_STATUS _update_identity_for_incoming_message(
    1.24          PEP_SESSION session,
    1.25          const message *src
    1.26      )
    1.27  {
    1.28 -    if (src->from && src->from->user_id && src->from->address) {
    1.29 -        update_identity(session, src->from);
    1.30 -        if (is_a_pEpmessage(src)
    1.31 +    PEP_STATUS status;
    1.32 +    if (src->from && src->from->address) {
    1.33 +        status = update_identity(session, src->from);
    1.34 +        if (status == PEP_STATUS_OK
    1.35 +                && is_a_pEpmessage(src)
    1.36                  && src->from->comm_type >= PEP_ct_OpenPGP_unconfirmed
    1.37                  && src->from->comm_type != PEP_ct_pEp_unconfirmed
    1.38                  && src->from->comm_type != PEP_ct_pEp)
    1.39          {
    1.40              src->from->comm_type |= PEP_ct_pEp_unconfirmed;
    1.41 -            update_identity(session, src->from);
    1.42 +            status = update_identity(session, src->from);
    1.43          }
    1.44 +        return status;
    1.45      }
    1.46 +    return PEP_ILLEGAL_VALUE;
    1.47  }
    1.48  
    1.49  DYNAMIC_API PEP_STATUS _decrypt_message(
    1.50 @@ -1289,7 +1291,10 @@
    1.51  
    1.52      // Update src->from in case we just imported a key
    1.53      // we would need to check signature
    1.54 -    _update_identity_for_incoming_message(session, src);
    1.55 +    status = _update_identity_for_incoming_message(session, src);
    1.56 +    if(status != PEP_STATUS_OK)
    1.57 +        return status;
    1.58 +
    1.59      PEP_cryptotech crypto = determine_encryption_format(src);
    1.60  
    1.61      *dst = NULL;
    1.62 @@ -1359,11 +1364,8 @@
    1.63                      }
    1.64                      else if (is_encrypted_attachment(_s)) {
    1.65                          stringlist_t *_keylist = NULL;
    1.66 -                        char *attctext;
    1.67 -                        size_t attcsize;
    1.68 -
    1.69 -                        attctext = _s->value;
    1.70 -                        attcsize = _s->size;
    1.71 +                        char *attctext  = _s->value;
    1.72 +                        size_t attcsize = _s->size;
    1.73  
    1.74                          free(ptext);
    1.75                          ptext = NULL;
    1.76 @@ -1380,8 +1382,8 @@
    1.77                                      goto pep_error;
    1.78                              }
    1.79                              else {
    1.80 -                                char * mime_type = "application/octet-stream";
    1.81 -                                char * filename =
    1.82 +                                static const char * const mime_type = "application/octet-stream";
    1.83 +                                const char * const filename =
    1.84                                      without_double_ending(_s->filename);
    1.85                                  if (filename == NULL)
    1.86                                      goto enomem;
    1.87 @@ -1394,6 +1396,7 @@
    1.88  
    1.89                                  _m = bloblist_add(_m, _ptext, psize, mime_type,
    1.90                                      filename);
    1.91 +                                free(filename);
    1.92                                  if (_m == NULL)
    1.93                                      goto enomem;
    1.94  
    1.95 @@ -1493,7 +1496,9 @@
    1.96              // Update msg->from in case we just imported a key
    1.97              // we would need to check signature
    1.98  
    1.99 -            _update_identity_for_incoming_message(session, src);
   1.100 +            status = _update_identity_for_incoming_message(session, src);
   1.101 +            if(status != PEP_STATUS_OK)
   1.102 +                goto pep_error;
   1.103              
   1.104              char *re_ptext = NULL;
   1.105              size_t re_psize;
   1.106 @@ -1637,6 +1642,29 @@
   1.107  
   1.108  }
   1.109  
   1.110 +static void _max_comm_type_from_identity_list(
   1.111 +        identity_list *identities, 
   1.112 +        PEP_SESSION session,
   1.113 +        PEP_comm_type *max_comm_type,
   1.114 +        bool *comm_type_determined
   1.115 +    )
   1.116 +{
   1.117 +    identity_list * il;
   1.118 +    for (il = identities; il != NULL; il = il->next)
   1.119 +    {
   1.120 +        if (il->ident)
   1.121 +        {
   1.122 +            PEP_STATUS status = update_identity(session, il->ident);
   1.123 +            if (status == PEP_STATUS_OK)
   1.124 +            {
   1.125 +                *max_comm_type = _get_comm_type(session, *max_comm_type,
   1.126 +                        il->ident);
   1.127 +                *comm_type_determined = true;
   1.128 +            }
   1.129 +        }
   1.130 +    }
   1.131 +}
   1.132 +
   1.133  DYNAMIC_API PEP_STATUS outgoing_message_color(
   1.134          PEP_SESSION session,
   1.135          message *msg,
   1.136 @@ -1646,7 +1674,6 @@
   1.137      PEP_STATUS status = PEP_STATUS_OK;
   1.138      PEP_comm_type max_comm_type = PEP_ct_pEp;
   1.139      bool comm_type_determined = false;
   1.140 -    identity_list * il;
   1.141  
   1.142      assert(session);
   1.143      assert(msg);
   1.144 @@ -1666,38 +1693,14 @@
   1.145      if (status != PEP_STATUS_OK)
   1.146          return status;
   1.147  
   1.148 -    for (il = msg->to; il != NULL; il = il->next)
   1.149 -    {
   1.150 -        if (il->ident)
   1.151 -        {
   1.152 -            update_identity(session, il->ident);
   1.153 -            max_comm_type = _get_comm_type(session, max_comm_type,
   1.154 -                    il->ident);
   1.155 -            comm_type_determined = true;
   1.156 -        }
   1.157 -    }
   1.158 +    _max_comm_type_from_identity_list(msg->to, session,
   1.159 +                                      &max_comm_type, &comm_type_determined);
   1.160  
   1.161 -    for (il = msg->cc; il != NULL; il = il->next)
   1.162 -    {
   1.163 -        if (il->ident)
   1.164 -        {
   1.165 -            update_identity(session, il->ident);
   1.166 -            max_comm_type = _get_comm_type(session, max_comm_type,
   1.167 -                    il->ident);
   1.168 -            comm_type_determined = true;
   1.169 -        }
   1.170 -    }
   1.171 +    _max_comm_type_from_identity_list(msg->cc, session,
   1.172 +                                      &max_comm_type, &comm_type_determined);
   1.173          
   1.174 -    for (il = msg->bcc; il != NULL; il = il->next)
   1.175 -    {
   1.176 -        if (il->ident)
   1.177 -        {
   1.178 -            update_identity(session, il->ident);
   1.179 -            max_comm_type = _get_comm_type(session, max_comm_type,
   1.180 -                                           il->ident);
   1.181 -            comm_type_determined = true;
   1.182 -        }
   1.183 -    }
   1.184 +    _max_comm_type_from_identity_list(msg->bcc, session,
   1.185 +                                      &max_comm_type, &comm_type_determined);
   1.186  
   1.187      if (comm_type_determined == false)
   1.188          *color = PEP_rating_undefined;