use heim_error_t

This commit is contained in:
Love Hornquist Astrand
2011-09-25 18:59:42 +02:00
parent 9f46874cfb
commit 7e36705ee3

View File

@@ -45,17 +45,6 @@ struct hx509_error_data {
char *msg; 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. * Resets the error strings the hx509 context.
* *
@@ -68,7 +57,7 @@ void
hx509_clear_error_string(hx509_context context) hx509_clear_error_string(hx509_context context)
{ {
if (context) { if (context) {
free_error_string(context->error); heim_release(context->error);
context->error = NULL; context->error = NULL;
} }
} }
@@ -91,31 +80,18 @@ void
hx509_set_error_stringv(hx509_context context, int flags, int code, hx509_set_error_stringv(hx509_context context, int flags, int code,
const char *fmt, va_list ap) const char *fmt, va_list ap)
{ {
hx509_error msg; heim_error_t msg;
if (context == NULL) if (context == NULL)
return; return;
msg = calloc(1, sizeof(*msg)); msg = heim_error_createv(code, fmt, ap);
if (msg == NULL) { if (msg) {
hx509_clear_error_string(context); if (flags & HX509_ERROR_APPEND)
return; heim_error_append(msg, context->error);
} heim_release(context->error);
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;
} }
context->error = msg;
} }
/** /**
@@ -157,12 +133,12 @@ hx509_set_error_string(hx509_context context, int flags, int code,
char * char *
hx509_get_error_string(hx509_context context, int error_code) hx509_get_error_string(hx509_context context, int error_code)
{ {
struct rk_strpool *p = NULL; heim_error_t msg = context->error;
hx509_error 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; const char *cstr;
char *str;
cstr = com_right(context->et_list, error_code); cstr = com_right(context->et_list, error_code);
if (cstr) if (cstr)
@@ -175,11 +151,14 @@ hx509_get_error_string(hx509_context context, int error_code)
return str; return str;
} }
for (msg = context->error; msg; msg = msg->next) s = heim_error_copy_string(msg);
p = rk_strpoolprintf(p, "%s%s", msg->msg, if (s) {
msg->next != NULL ? "; " : ""); str = heim_string_get_utf8(s);
if (str)
return rk_strpoolcollect(p); str = strdup(str);
heim_release(s);
}
return str;
} }
/** /**