From 7e36705ee335654194a7cd99a9ea1a908010e911 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Sun, 25 Sep 2011 18:59:42 +0200 Subject: [PATCH] use heim_error_t --- lib/hx509/error.c | 61 ++++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/lib/hx509/error.c b/lib/hx509/error.c index fc3cf90b3..f44627e90 100644 --- a/lib/hx509/error.c +++ b/lib/hx509/error.c @@ -45,17 +45,6 @@ struct hx509_error_data { char *msg; }; -static void -free_error_string(hx509_error msg) -{ - while(msg) { - hx509_error m2 = msg->next; - free(msg->msg); - free(msg); - msg = m2; - } -} - /** * Resets the error strings the hx509 context. * @@ -68,7 +57,7 @@ void hx509_clear_error_string(hx509_context context) { if (context) { - free_error_string(context->error); + heim_release(context->error); context->error = NULL; } } @@ -91,31 +80,18 @@ void hx509_set_error_stringv(hx509_context context, int flags, int code, const char *fmt, va_list ap) { - hx509_error msg; + heim_error_t msg; if (context == NULL) return; - msg = calloc(1, sizeof(*msg)); - if (msg == NULL) { - hx509_clear_error_string(context); - return; - } - - if (vasprintf(&msg->msg, fmt, ap) == -1) { - hx509_clear_error_string(context); - free(msg); - return; - } - msg->code = code; - - if (flags & HX509_ERROR_APPEND) { - msg->next = context->error; - context->error = msg; - } else { - free_error_string(context->error); - context->error = msg; + msg = heim_error_createv(code, fmt, ap); + if (msg) { + if (flags & HX509_ERROR_APPEND) + heim_error_append(msg, context->error); + heim_release(context->error); } + context->error = msg; } /** @@ -157,12 +133,12 @@ hx509_set_error_string(hx509_context context, int flags, int code, char * hx509_get_error_string(hx509_context context, int error_code) { - struct rk_strpool *p = NULL; - hx509_error msg = context->error; + heim_error_t msg = context->error; + heim_string_t s; + char *str = NULL; - if (msg == NULL || msg->code != error_code) { + if (msg == NULL || heim_error_get_code(msg) != error_code) { const char *cstr; - char *str; cstr = com_right(context->et_list, error_code); if (cstr) @@ -175,11 +151,14 @@ hx509_get_error_string(hx509_context context, int error_code) return str; } - for (msg = context->error; msg; msg = msg->next) - p = rk_strpoolprintf(p, "%s%s", msg->msg, - msg->next != NULL ? "; " : ""); - - return rk_strpoolcollect(p); + s = heim_error_copy_string(msg); + if (s) { + str = heim_string_get_utf8(s); + if (str) + str = strdup(str); + heim_release(s); + } + return str; } /** -- 2.11.4.GIT