diff -r c4bcba8023a9 -r 8476d35b048f librazor/error.c --- a/librazor/error.c Sat Aug 23 16:28:31 2014 +0100 +++ b/librazor/error.c Thu Sep 11 18:54:16 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 J. Ali Harlow + * Copyright (C) 2011-2012, 2014 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,15 +27,33 @@ #include "razor.h" #include "razor-internal.h" -static const char *razor_error_get_path_str(struct razor_error *error) +RAZOR_EXPORT int +razor_error_get_domain(struct razor_error *error) { - if (error->path_str) - return error->path_str; + return error->domain; +} - if (error->path) { - error->path_str = razor_concat(error->path, ": ", - error->str, NULL); - return error->path_str; +RAZOR_EXPORT int +razor_error_get_code(struct razor_error *error) +{ + return error->code; +} + +RAZOR_EXPORT const char * +razor_error_get_object(struct razor_error *error) +{ + return error->object; +} + +static const char *razor_error_get_obj_str(struct razor_error *error) +{ + if (error->obj_str) + return error->obj_str; + + if (error->object) { + error->obj_str = razor_concat(error->object, ": ", + error->str, NULL); + return error->obj_str; } return error->str; @@ -46,7 +64,7 @@ * * Retrieves the basic information about an error. If a summary has been set * then this will be returned. Otherwise the error string possibly prefixed - * by the path will be returned instead. + * by the object will be returned instead. * * Returns: Primary text of error. **/ @@ -56,14 +74,14 @@ if (error->summary) return error->summary; - return razor_error_get_path_str(error); + return razor_error_get_obj_str(error); } /** * razor_error_get_secondary_text: * * Retrieves more detailed information about an error, if any. If a summary - * has been set the error string possibly prefixed by the path will be + * has been set the error string possibly prefixed by the object will be * returned. Otherwise NULL will be returned. * * Returns: Secondary text of error or NULL. @@ -74,7 +92,7 @@ if (!error->summary) return NULL; - return razor_error_get_path_str(error); + return razor_error_get_obj_str(error); } RAZOR_EXPORT const char * @@ -98,15 +116,18 @@ #ifdef MSWIN_API struct razor_error * -razor_error_new_mswin(const wchar_t *path, DWORD err) +razor_error_new_mswin(const wchar_t *object, DWORD err) { struct razor_error *error; wchar_t *buf; error = zalloc(sizeof *error); - if (path) - error->path = razor_utf16_to_utf8(path, -1); + error->domain = RAZOR_MSWIN_ERROR; + error->code = err; + + if (object) + error->object = razor_utf16_to_utf8(object, -1); FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, @@ -119,14 +140,18 @@ } struct razor_error * -razor_error_new_str2(const wchar_t *path, const char *str) +razor_error_new_str2(int domain, int code, const wchar_t *object, + const char *str) { struct razor_error *error; error = zalloc(sizeof *error); - if (path) - error->path = razor_utf16_to_utf8(path, -1); + error->domain = domain; + error->code = code; + + if (object) + error->object = razor_utf16_to_utf8(object, -1); error->str = strdup(str); @@ -135,14 +160,17 @@ #endif /* MSWIN_API */ RAZOR_EXPORT struct razor_error * -razor_error_new_str(const char *path, const char *str) +razor_error_new_str(int domain, int code, const char *object, const char *str) { struct razor_error *error; error = zalloc(sizeof *error); - if (path) - error->path = strdup(path); + error->domain = domain; + error->code = code; + + if (object) + error->object = strdup(object); error->str = strdup(str); @@ -156,13 +184,16 @@ error = zalloc(sizeof *error); + error->domain = src->domain; + error->code = src->code; + if (summary) error->summary = strdup(summary); else if (src->summary) error->summary = strdup(src->summary); - if (src->path) - error->path = strdup(src->path); + if (src->object) + error->object = strdup(src->object); if (src->str) error->str = strdup(src->str); @@ -173,9 +204,9 @@ RAZOR_EXPORT void razor_error_free(struct razor_error *error) { - free(error->path); + free(error->object); free(error->str); - free(error->path_str); + free(error->obj_str); free(error->summary); free(error->msg); free(error);