use ERROR() and GOTO() to fill the error stack. ENGINE-199
authorRoker <roker@pep-project.org>
Thu, 20 Apr 2017 14:57:42 +0200
branchENGINE-199
changeset 17291dd554ac85d1
parent 1728 3c032ad43e6e
child 1730 f8f1a806a051
use ERROR() and GOTO() to fill the error stack.
src/message_api.c
src/pEp_internal.h
     1.1 --- a/src/message_api.c	Thu Apr 20 10:37:10 2017 +0200
     1.2 +++ b/src/message_api.c	Thu Apr 20 14:57:42 2017 +0200
     1.3 @@ -1606,7 +1606,7 @@
     1.4      assert(flags);
     1.5  
     1.6      if (!(session && src && dst && keylist && rating && flags))
     1.7 -        return PEP_ILLEGAL_VALUE;
     1.8 +        return ERROR(PEP_ILLEGAL_VALUE);
     1.9  
    1.10      *flags = 0;
    1.11  
    1.12 @@ -1617,7 +1617,7 @@
    1.13      // we would need to check signature
    1.14      status = _update_identity_for_incoming_message(session, src);
    1.15      if(status != PEP_STATUS_OK)
    1.16 -        return status;
    1.17 +        return ERROR(status);
    1.18  
    1.19      // Get detached signature, if any
    1.20      bloblist_t* detached_sig = NULL;
    1.21 @@ -1651,7 +1651,7 @@
    1.22                                  PEP_decrypt_flag_consume;
    1.23                  }
    1.24                  else if (status != PEP_STATUS_OK) {
    1.25 -                    return status;
    1.26 +                    return ERROR(status);
    1.27                  }
    1.28              }
    1.29              
    1.30 @@ -1683,7 +1683,7 @@
    1.31                  }
    1.32              }
    1.33              
    1.34 -            return PEP_UNENCRYPTED;
    1.35 +            return ERROR(PEP_UNENCRYPTED);
    1.36  
    1.37          case PEP_enc_PGP_MIME:
    1.38              ctext = src->attachments->next->value;
    1.39 @@ -1707,7 +1707,7 @@
    1.40                                                     csize, dsig_text, dsig_size,
    1.41                                                     &ptext, &psize, &_keylist);
    1.42      if (status > PEP_CANNOT_DECRYPT_UNKNOWN){
    1.43 -        goto pep_error;
    1.44 +        GOTO(pep_error);
    1.45      }
    1.46  
    1.47      decrypt_status = status;
    1.48 @@ -1883,7 +1883,9 @@
    1.49              case PEP_enc_PGP_MIME_Outlook1:
    1.50                  status = copy_fields(msg, src);
    1.51                  if (status != PEP_STATUS_OK)
    1.52 -                    goto pep_error;
    1.53 +                {
    1.54 +                    GOTO(pep_error);
    1.55 +                }
    1.56  
    1.57                  if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
    1.58                  {
    1.59 @@ -1941,7 +1943,9 @@
    1.60  
    1.61              status = _update_identity_for_incoming_message(session, src);
    1.62              if(status != PEP_STATUS_OK)
    1.63 -                goto pep_error;
    1.64 +            {
    1.65 +                GOTO(pep_error);
    1.66 +            }
    1.67  
    1.68              char *re_ptext = NULL;
    1.69              size_t re_psize;
    1.70 @@ -1955,7 +1959,9 @@
    1.71              free(re_ptext);
    1.72  
    1.73              if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
    1.74 -                goto pep_error;
    1.75 +            {
    1.76 +                GOTO(pep_error);
    1.77 +            }
    1.78  
    1.79              decrypt_status = status;
    1.80          }
    1.81 @@ -1995,7 +2001,9 @@
    1.82                      if (status == PEP_CANNOT_FIND_IDENTITY)
    1.83                         status = PEP_STATUS_OK;
    1.84                      if (status != PEP_STATUS_OK)
    1.85 -                        goto pep_error;
    1.86 +                    {
    1.87 +                        GOTO(pep_error);
    1.88 +                    }
    1.89                  }
    1.90              }
    1.91          }
    1.92 @@ -2053,7 +2061,7 @@
    1.93      *dst = msg;
    1.94      *keylist = _keylist;
    1.95  
    1.96 -    return status;
    1.97 +    return ERROR(status);
    1.98  
    1.99  enomem:
   1.100      status = PEP_OUT_OF_MEMORY;
   1.101 @@ -2063,7 +2071,7 @@
   1.102      free_message(msg);
   1.103      free_stringlist(_keylist);
   1.104  
   1.105 -    return status;
   1.106 +    return ERROR(status);
   1.107  }
   1.108  
   1.109  DYNAMIC_API PEP_STATUS decrypt_message(
   1.110 @@ -2112,8 +2120,7 @@
   1.111  
   1.112      free_identity_list(private_il);
   1.113  
   1.114 -    return status;
   1.115 -
   1.116 +    return ERROR(status);
   1.117  }
   1.118  
   1.119  static void _max_comm_type_from_identity_list(
   1.120 @@ -2154,10 +2161,10 @@
   1.121      assert(rating);
   1.122  
   1.123      if (!(session && msg && rating))
   1.124 -        return PEP_ILLEGAL_VALUE;
   1.125 +        return ERROR(PEP_ILLEGAL_VALUE);
   1.126  
   1.127      if (msg->dir != PEP_dir_outgoing)
   1.128 -        return PEP_ILLEGAL_VALUE;
   1.129 +        return ERROR(PEP_ILLEGAL_VALUE);
   1.130  
   1.131      *rating = PEP_rating_undefined;
   1.132  
   1.133 @@ -2241,7 +2248,7 @@
   1.134  
   1.135      // this should never happen
   1.136      assert(false);
   1.137 -	return PEP_color_no_color;
   1.138 +    return PEP_color_no_color;
   1.139  }
   1.140  
   1.141  static bool _is_valid_hex(const char* hexstr) {
   1.142 @@ -2386,7 +2393,7 @@
   1.143                  goto error_release;
   1.144              break;
   1.145          default:
   1.146 -            return PEP_UNKNOWN_ERROR; // shouldn't be possible
   1.147 +            return ERROR(PEP_UNKNOWN_ERROR); // shouldn't be possible
   1.148      }
   1.149  
   1.150      size_t _wsize = first_wsize + second_wsize;
   1.151 @@ -2428,7 +2435,7 @@
   1.152      the_end:
   1.153      free(first_set);
   1.154      free(second_set);
   1.155 -    return status;
   1.156 +    return ERROR(status);
   1.157  }
   1.158  
   1.159  DYNAMIC_API PEP_STATUS get_message_trustwords(
   1.160 @@ -2514,7 +2521,7 @@
   1.161  
   1.162      if (status != PEP_STATUS_OK) {
   1.163          free_identity(partner);
   1.164 -        return status;
   1.165 +        return ERROR(status);
   1.166      }
   1.167     
   1.168      // Find own identity corresponding to given account address.
   1.169 @@ -2527,7 +2534,7 @@
   1.170  
   1.171      if (status != PEP_STATUS_OK) {
   1.172          free_identity(stored_identity);
   1.173 -        return status;
   1.174 +        return ERROR(status);
   1.175      }
   1.176  
   1.177      // get the trustwords
   1.178 @@ -2536,7 +2543,7 @@
   1.179                              partner, received_by, 
   1.180                              lang, words, &wsize, full);
   1.181  
   1.182 -    return status;
   1.183 +    return ERROR(status);
   1.184  }
   1.185  
   1.186  DYNAMIC_API PEP_STATUS MIME_decrypt_message(
   1.187 @@ -2574,14 +2581,14 @@
   1.188      if (status == PEP_STATUS_OK)
   1.189      {
   1.190          free(tmp_msg);
   1.191 -        return decrypt_status;
   1.192 +        return ERROR(decrypt_status);
   1.193      }
   1.194      
   1.195  pep_error:
   1.196      free_message(tmp_msg);
   1.197      free_message(dec_msg);
   1.198  
   1.199 -    return status;
   1.200 +    return ERROR(status);
   1.201  }
   1.202  
   1.203  
   1.204 @@ -2620,7 +2627,7 @@
   1.205      free_message(tmp_msg);
   1.206      free_message(enc_msg);
   1.207  
   1.208 -    return status;
   1.209 +    return ERROR(status);
   1.210  
   1.211  }
   1.212  
   1.213 @@ -2659,5 +2666,5 @@
   1.214      free_message(tmp_msg);
   1.215      free_message(enc_msg);
   1.216  
   1.217 -    return status;
   1.218 +    return ERROR(status);
   1.219  }
     2.1 --- a/src/pEp_internal.h	Thu Apr 20 10:37:10 2017 +0200
     2.2 +++ b/src/pEp_internal.h	Thu Apr 20 14:57:42 2017 +0200
     2.3 @@ -238,6 +238,8 @@
     2.4  #ifdef DEBUG_ERRORSTACK
     2.5      PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status);
     2.6      #define ERROR(status)   session_add_error(session, __FILE__, __LINE__, (status))
     2.7 +    #define GOTO(label)     do{ (void)session_add_error(session, __FILE__, __LINE__, status); goto label; }while(0)
     2.8  #else
     2.9      #define ERROR(status)   (status)
    2.10 +    #define GOTO(label)     goto label
    2.11  #endif