Add smtp_status_code_clear function Deprecated the smtp_status_code_set function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
diff --git a/Makefile b/Makefile
index 158f639..d1f1216 100644
--- a/Makefile
+++ b/Makefile
@@ -78,6 +78,7 @@ CWARN.gcc += -Wvector-operation-performance
CWARN.clang += -Weverything
CWARN.clang += -Wno-format-nonliteral
+CWARN.clang += -Wno-documentation-deprecated-sync
CWARN.clang += -fcomment-block-commands=retval
CFLAGS += $(CWARN)
diff --git a/README.md b/README.md
index ccb3c1e..905fbbe 100644
--- a/README.md
+++ b/README.md
@@ -118,9 +118,7 @@ example, the program checks for an error at the end of the mail session after
calling smtp_close. We can do this because if an error occurs in any of the
prior functions, the error will continue to propagate through any future
function calls until either closing the SMTP context using smtp_close or by
-resetting the error condition using smtp_status_code_set. However, make sure to
-review the smtp_status_code_set function prior to using that option for
-clearing the error message to avoid any undefined behavior.
+resetting the error condition using smtp_status_code_clear.
## Technical Documentation
See the [Technical Documentation](https://www.somnisoft.com/smtp-client/technical-documentation/index.html) generated from Doxygen.
diff --git a/src/smtp.c b/src/smtp.c
index b89d464..8298110 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -3186,6 +3186,15 @@ smtp_status_code_get(const struct smtp *const smtp){
}
enum smtp_status_code
+smtp_status_code_clear(struct smtp *const smtp){
+ enum smtp_status_code old_status;
+
+ old_status = smtp_status_code_get(smtp);
+ smtp_status_code_set(smtp, SMTP_STATUS_OK);
+ return old_status;
+}
+
+enum smtp_status_code
smtp_status_code_set(struct smtp *const smtp,
enum smtp_status_code status_code){
if((unsigned)status_code >= SMTP_STATUS__LAST){
diff --git a/src/smtp.h b/src/smtp.h
index 239fd7b..8d606f1 100644
--- a/src/smtp.h
+++ b/src/smtp.h
@@ -298,6 +298,15 @@ enum smtp_status_code
smtp_status_code_get(const struct smtp *const smtp);
/**
+ * Clear the current error code set in the SMTP client context.
+ *
+ * @param[in,out] smtp SMTP client context.
+ * @return Previous error code before clearing.
+ */
+enum smtp_status_code
+smtp_status_code_clear(struct smtp *const smtp);
+
+/**
* Set the error status of the SMTP client context and return the same code.
*
* This allows the caller to clear an error status to SMTP_STATUS_OK
@@ -305,8 +314,10 @@ smtp_status_code_get(const struct smtp *const smtp);
* work correctly for clearing the SMTP_STATUS_PARAM and SMTP_STATUS_FILE
* errors. Do not use this to clear any other error codes.
*
- * @param[in] smtp SMTP client context.
- * @param[in] status_code See @ref smtp_status_code.
+ * @deprecated Use @ref smtp_status_code_clear instead.
+ *
+ * @param[in] smtp SMTP client context.
+ * @param[in] new_status_code See @ref smtp_status_code.
* @return See @ref smtp_status_code.
*/
enum smtp_status_code
diff --git a/test/test.c b/test/test.c
index f0bd51f..2f88beb 100644
--- a/test/test.c
+++ b/test/test.c
@@ -2220,7 +2220,7 @@ smtp_func_test_all_status_code_get(struct smtp_test_config *const config){
smtp_status_code_set(config->smtp, SMTP_STATUS_NOMEM);
rc = smtp_status_code_get(config->smtp);
assert(rc == SMTP_STATUS_NOMEM);
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
rc = smtp_close(config->smtp);
assert(rc == SMTP_STATUS_OK);
@@ -2840,7 +2840,7 @@ smtp_func_test_all_address(struct smtp_test_config *const config){
rc = smtp_mail(config->smtp,
"This email should not have a FROM address in the header.");
assert(rc == SMTP_STATUS_PARAM);
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
/* FROM address contains UTF-8 characters. */
smtp_header_clear_all(config->smtp);
@@ -3685,7 +3685,7 @@ test_failure_address_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_NOMEM);
/* Invalid email address. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
rc = smtp_address_add(config->smtp,
SMTP_ADDRESS_FROM,
"<invalid>",
@@ -3693,7 +3693,7 @@ test_failure_address_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_PARAM);
/* Invalid email name. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
rc = smtp_address_add(config->smtp,
SMTP_ADDRESS_FROM,
config->email_from,
@@ -3701,7 +3701,7 @@ test_failure_address_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_PARAM);
/* Wrap when trying to increase size of address list. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_si_add_size_t_ctr = 0;
rc = smtp_address_add(config->smtp,
SMTP_ADDRESS_FROM,
@@ -3711,7 +3711,7 @@ test_failure_address_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_NOMEM);
/* Memory allocation failed while trying to increase size of address list. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_realloc_ctr = 0;
rc = smtp_address_add(config->smtp,
SMTP_ADDRESS_FROM,
@@ -3721,7 +3721,7 @@ test_failure_address_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_NOMEM);
/* Failed to duplicate email string. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_malloc_ctr = 0;
rc = smtp_address_add(config->smtp,
SMTP_ADDRESS_FROM,
@@ -3731,7 +3731,7 @@ test_failure_address_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_NOMEM);
/* Failed to duplicate name string. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_malloc_ctr = 1;
rc = smtp_address_add(config->smtp,
SMTP_ADDRESS_FROM,
@@ -3766,7 +3766,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
/* Invalid SMTP status code. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_PARAM);
+ smtp_status_code_clear(config->smtp);
rc = smtp_attachment_add_mem(config->smtp,
"valid",
"test",
@@ -3775,7 +3775,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
/* Invalid filename parameter. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
rc = smtp_attachment_add_mem(config->smtp,
"\"invalid\"",
"test",
@@ -3783,7 +3783,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_PARAM);
/* Wrap when increasing the attachment list size. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_si_add_size_t_ctr = 0;
rc = smtp_attachment_add_mem(config->smtp,
"valid",
@@ -3793,7 +3793,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
g_smtp_test_err_si_add_size_t_ctr = -1;
/* Memory allocation failure while increasing the attachment list size. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_realloc_ctr = 0;
rc = smtp_attachment_add_mem(config->smtp,
"valid",
@@ -3803,7 +3803,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
g_smtp_test_err_realloc_ctr = -1;
/* Memory allocation failure while using smtp_strdup on file name. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_malloc_ctr = 0;
rc = smtp_attachment_add_mem(config->smtp,
"valid",
@@ -3814,7 +3814,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
/* Memory allocation failure while using smtp_base64_encode. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_calloc_ctr = 0;
rc = smtp_attachment_add_mem(config->smtp,
"valid",
@@ -3824,7 +3824,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
g_smtp_test_err_calloc_ctr = -1;
/* Memory allocation failure when splitting base64 lines into chunks. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_calloc_ctr = 1;
rc = smtp_attachment_add_mem(config->smtp,
"valid",
@@ -3834,19 +3834,19 @@ test_failure_attachment_add(struct smtp_test_config *const config){
g_smtp_test_err_calloc_ctr = -1;
/* Invalid SMTP status code. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_PARAM);
+ smtp_status_code_clear(config->smtp);
rc = smtp_attachment_add_fp(config->smtp, "test", stdin);
assert(rc == SMTP_STATUS_PARAM);
/* @ref smtp_ffile_get_contents memory allocation failure. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_realloc_ctr = 0;
rc = smtp_attachment_add_fp(config->smtp, "test", stdin);
g_smtp_test_err_realloc_ctr = -1;
assert(rc == SMTP_STATUS_NOMEM);
/* @ref smtp_ffile_get_contents fread error. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
fp = fopen("COPYING", "r");
assert(fp);
g_smtp_test_err_ferror_ctr = 0;
@@ -3857,7 +3857,7 @@ test_failure_attachment_add(struct smtp_test_config *const config){
assert(fp_rc == 0);
/* @ref smtp_file_get_contents memory allocation failure. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_realloc_ctr = 0;
rc = smtp_attachment_add_path(config->smtp, "test", "COPYING");
g_smtp_test_err_realloc_ctr = -1;
@@ -3898,35 +3898,35 @@ test_failure_header_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_NOMEM);
/* Invalid header key. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
rc = smtp_header_add(config->smtp,
"invalid:",
"value");
assert(rc == SMTP_STATUS_PARAM);
/* Invalid header value. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
rc = smtp_header_add(config->smtp,
"key",
"invalid\n");
assert(rc == SMTP_STATUS_PARAM);
/* Wrap when increasing the header list size. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_si_add_size_t_ctr = 0;
rc = smtp_header_add(config->smtp, "key", "value");
g_smtp_test_err_si_add_size_t_ctr = -1;
assert(rc == SMTP_STATUS_NOMEM);
/* Memory allocation failure while trying to increase header list size. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_realloc_ctr = 0;
rc = smtp_header_add(config->smtp, "key", "value");
g_smtp_test_err_realloc_ctr = -1;
assert(rc == SMTP_STATUS_NOMEM);
/* Failed to strdup header key. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_malloc_ctr = 0;
rc = smtp_header_add(config->smtp,
"key",
@@ -3935,7 +3935,7 @@ test_failure_header_add(struct smtp_test_config *const config){
assert(rc == SMTP_STATUS_NOMEM);
/* Failed to strdup header value. */
- smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ smtp_status_code_clear(config->smtp);
g_smtp_test_err_malloc_ctr = 1;
rc = smtp_header_add(config->smtp,
"key",
@@ -3970,7 +3970,7 @@ test_failure_status_code_set(struct smtp_test_config *const config){
rc = smtp_status_code_set(config->smtp, SMTP_STATUS__LAST);
assert(rc == SMTP_STATUS_PARAM);
- rc = smtp_status_code_set(config->smtp, SMTP_STATUS_OK);
+ rc = smtp_status_code_clear(config->smtp);
assert(rc == SMTP_STATUS_OK);
rc = smtp_close(config->smtp);