pass back an heim_error from hx509_cert_init

This commit is contained in:
Love Hornquist Astrand
2012-10-07 06:33:13 -07:00
parent 216bfa564d
commit 029de6cfa4
16 changed files with 135 additions and 92 deletions

View File

@@ -68,7 +68,7 @@
#define HEIM_ENOMEM(ep) \
(((ep) && !*(ep)) ? \
heim_error_get_code((*(ep) = heim_error_enomem())) : ENOMEM)
heim_error_get_code((*(ep) = heim_error_create_enomem())) : ENOMEM)
#define HEIM_ERROR_HELPER(ep, ec, args) \
(((ep) && !*(ep)) ? \
@@ -326,7 +326,7 @@ heim_db_create(const char *dbtype, const char *dbname,
options = heim_dict_create(11);
if (options == NULL) {
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}
} else {
@@ -413,7 +413,7 @@ heim_db_create(const char *dbtype, const char *dbname,
if (!db->dbtype || ! db->dbname) {
heim_release(db);
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}
}
@@ -456,7 +456,7 @@ heim_db_clone(heim_db_t db, heim_error_t *error)
result = _heim_alloc_object(&db_object, sizeof(*result));
if (result == NULL) {
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}
@@ -763,7 +763,7 @@ heim_db_copy_value(heim_db_t db, heim_string_t table, heim_data_t key,
key64 = to_base64(key, error);
if (key64 == NULL) {
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}
@@ -1126,7 +1126,7 @@ heim_string_t to_base64(heim_data_t data, heim_error_t *error)
enomem:
free(b64);
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}
@@ -1150,7 +1150,7 @@ heim_data_t from_base64(heim_string_t s, heim_error_t *error)
enomem:
free(buf);
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}

View File

@@ -77,12 +77,24 @@ struct heim_type_data _heim_error_object = {
};
heim_error_t
heim_error_enomem(void)
heim_error_create_enomem(void)
{
/* This is an immediate object; see heim_number_create() */
return (heim_error_t)heim_number_create(ENOMEM);
}
void
heim_error_create_opt(heim_error_t *error, int error_code, const char *fmt, ...)
{
if (error) {
va_list ap;
va_start(ap, fmt);
*error = heim_error_createv(error_code, fmt, ap);
va_end(ap);
}
}
heim_error_t
heim_error_create(int error_code, const char *fmt, ...)
{
@@ -107,7 +119,7 @@ heim_error_createv(int error_code, const char *fmt, va_list ap)
str = malloc(1024);
errno = save_errno;
if (str == NULL)
return heim_error_enomem();
return heim_error_create_enomem();
len = vsnprintf(str, 1024, fmt, ap);
errno = save_errno;
if (len < 0) {
@@ -141,6 +153,8 @@ heim_error_copy_string(heim_error_t error)
int
heim_error_get_code(heim_error_t error)
{
if (error == NULL)
return -1;
if (heim_get_tid(error) != HEIM_TID_ERROR) {
if (heim_get_tid(error) == heim_number_get_type_id())
return heim_number_get_int((heim_number_t)error);

View File

@@ -894,7 +894,7 @@ heim_path_vcreate(heim_object_t ptr, size_t size, heim_object_t leaf,
err:
if (error && !*error) {
if (ret == ENOMEM)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
else
*error = heim_error_create(ret, "Could not set "
"dict value");

View File

@@ -189,11 +189,15 @@ heim_string_t __heim_string_constant(const char *);
*/
typedef struct heim_error * heim_error_t;
heim_error_t heim_error_enomem(void);
heim_error_t heim_error_create_enomem(void);
heim_error_t heim_error_create(int, const char *, ...)
HEIMDAL_PRINTF_ATTRIBUTE((printf, 2, 3));
void heim_error_create_opt(heim_error_t *error, int error_code, const char *fmt, ...)
HEIMDAL_PRINTF_ATTRIBUTE((printf, 3, 4));
heim_error_t heim_error_createv(int, const char *, va_list)
HEIMDAL_PRINTF_ATTRIBUTE((printf, 2, 0));

View File

@@ -390,7 +390,7 @@ parse_string(struct parse_ctx *ctx)
} else {
o = heim_string_create_with_bytes(start, ctx->p - start);
if (o == NULL) {
ctx->error = heim_error_enomem();
ctx->error = heim_error_create_enomem();
return NULL;
}
@@ -407,7 +407,7 @@ parse_string(struct parse_ctx *ctx)
buf = malloc(len);
if (buf == NULL) {
heim_release(o);
ctx->error = heim_error_enomem();
ctx->error = heim_error_create_enomem();
return NULL;
}
len = base64_decode(s, buf);
@@ -511,7 +511,7 @@ parse_dict(struct parse_ctx *ctx)
dict = heim_dict_create(11);
if (dict == NULL) {
ctx->error = heim_error_enomem();
ctx->error = heim_error_create_enomem();
return NULL;
}
@@ -538,7 +538,7 @@ parse_dict(struct parse_ctx *ctx)
if (buf == NULL) {
heim_release(dict);
heim_release(v);
ctx->error = heim_error_enomem();
ctx->error = heim_error_create_enomem();
return NULL;
}
len = base64_decode(heim_string_get_utf8(v), buf);
@@ -777,7 +777,7 @@ heim_serialize(heim_object_t obj, heim_json_flags_t flags, heim_error_t *error)
strbuf.str = malloc(STRBUF_INIT_SZ);
if (strbuf.str == NULL) {
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
return NULL;
}
strbuf.len = 0;
@@ -789,7 +789,7 @@ heim_serialize(heim_object_t obj, heim_json_flags_t flags, heim_error_t *error)
if (ret || strbuf.enomem) {
if (error) {
if (strbuf.enomem || ret == ENOMEM)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
else
*error = heim_error_create(1, "Impossible to JSON-encode "
"object");
@@ -804,7 +804,7 @@ heim_serialize(heim_object_t obj, heim_json_flags_t flags, heim_error_t *error)
str = heim_string_ref_create(strbuf.str, free);
if (str == NULL) {
if (error)
*error = heim_error_enomem();
*error = heim_error_create_enomem();
free(strbuf.str);
}
return str;

View File

@@ -55,9 +55,10 @@ HEIMDAL_BASE_1.0 {
heim_dict_set_value;
heim_error_append;
heim_error_copy_string;
heim_error_create_opt;
heim_error_create;
heim_error_createv;
heim_error_enomem;
heim_error_create_enomem;
heim_error_get_code;
heim_get_hash;
heim_get_tid;