1.1 --- a/librazor/error.c Sat Aug 23 16:28:31 2014 +0100
1.2 +++ b/librazor/error.c Sat Oct 04 18:12:58 2014 +0100
1.3 @@ -1,5 +1,5 @@
1.4 /*
1.5 - * Copyright (C) 2011-2012 J. Ali Harlow <ali@juiblex.co.uk>
1.6 + * Copyright (C) 2011-2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
1.7 *
1.8 * This program is free software; you can redistribute it and/or modify
1.9 * it under the terms of the GNU General Public License as published by
1.10 @@ -27,15 +27,33 @@
1.11 #include "razor.h"
1.12 #include "razor-internal.h"
1.13
1.14 -static const char *razor_error_get_path_str(struct razor_error *error)
1.15 +RAZOR_EXPORT int
1.16 +razor_error_get_domain(struct razor_error *error)
1.17 {
1.18 - if (error->path_str)
1.19 - return error->path_str;
1.20 + return error->domain;
1.21 +}
1.22
1.23 - if (error->path) {
1.24 - error->path_str = razor_concat(error->path, ": ",
1.25 - error->str, NULL);
1.26 - return error->path_str;
1.27 +RAZOR_EXPORT int
1.28 +razor_error_get_code(struct razor_error *error)
1.29 +{
1.30 + return error->code;
1.31 +}
1.32 +
1.33 +RAZOR_EXPORT const char *
1.34 +razor_error_get_object(struct razor_error *error)
1.35 +{
1.36 + return error->object;
1.37 +}
1.38 +
1.39 +static const char *razor_error_get_obj_str(struct razor_error *error)
1.40 +{
1.41 + if (error->obj_str)
1.42 + return error->obj_str;
1.43 +
1.44 + if (error->object) {
1.45 + error->obj_str = razor_concat(error->object, ": ",
1.46 + error->str, NULL);
1.47 + return error->obj_str;
1.48 }
1.49
1.50 return error->str;
1.51 @@ -46,7 +64,7 @@
1.52 *
1.53 * Retrieves the basic information about an error. If a summary has been set
1.54 * then this will be returned. Otherwise the error string possibly prefixed
1.55 - * by the path will be returned instead.
1.56 + * by the object will be returned instead.
1.57 *
1.58 * Returns: Primary text of error.
1.59 **/
1.60 @@ -56,14 +74,14 @@
1.61 if (error->summary)
1.62 return error->summary;
1.63
1.64 - return razor_error_get_path_str(error);
1.65 + return razor_error_get_obj_str(error);
1.66 }
1.67
1.68 /**
1.69 * razor_error_get_secondary_text:
1.70 *
1.71 * Retrieves more detailed information about an error, if any. If a summary
1.72 - * has been set the error string possibly prefixed by the path will be
1.73 + * has been set the error string possibly prefixed by the object will be
1.74 * returned. Otherwise NULL will be returned.
1.75 *
1.76 * Returns: Secondary text of error or NULL.
1.77 @@ -74,7 +92,7 @@
1.78 if (!error->summary)
1.79 return NULL;
1.80
1.81 - return razor_error_get_path_str(error);
1.82 + return razor_error_get_obj_str(error);
1.83 }
1.84
1.85 RAZOR_EXPORT const char *
1.86 @@ -98,15 +116,18 @@
1.87
1.88 #ifdef MSWIN_API
1.89 struct razor_error *
1.90 -razor_error_new_mswin(const wchar_t *path, DWORD err)
1.91 +razor_error_new_mswin(const wchar_t *object, DWORD err)
1.92 {
1.93 struct razor_error *error;
1.94 wchar_t *buf;
1.95
1.96 error = zalloc(sizeof *error);
1.97
1.98 - if (path)
1.99 - error->path = razor_utf16_to_utf8(path, -1);
1.100 + error->domain = RAZOR_MSWIN_ERROR;
1.101 + error->code = err;
1.102 +
1.103 + if (object)
1.104 + error->object = razor_utf16_to_utf8(object, -1);
1.105
1.106 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|
1.107 FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1.108 @@ -119,14 +140,18 @@
1.109 }
1.110
1.111 struct razor_error *
1.112 -razor_error_new_str2(const wchar_t *path, const char *str)
1.113 +razor_error_new_str2(int domain, int code, const wchar_t *object,
1.114 + const char *str)
1.115 {
1.116 struct razor_error *error;
1.117
1.118 error = zalloc(sizeof *error);
1.119
1.120 - if (path)
1.121 - error->path = razor_utf16_to_utf8(path, -1);
1.122 + error->domain = domain;
1.123 + error->code = code;
1.124 +
1.125 + if (object)
1.126 + error->object = razor_utf16_to_utf8(object, -1);
1.127
1.128 error->str = strdup(str);
1.129
1.130 @@ -135,14 +160,17 @@
1.131 #endif /* MSWIN_API */
1.132
1.133 RAZOR_EXPORT struct razor_error *
1.134 -razor_error_new_str(const char *path, const char *str)
1.135 +razor_error_new_str(int domain, int code, const char *object, const char *str)
1.136 {
1.137 struct razor_error *error;
1.138
1.139 error = zalloc(sizeof *error);
1.140
1.141 - if (path)
1.142 - error->path = strdup(path);
1.143 + error->domain = domain;
1.144 + error->code = code;
1.145 +
1.146 + if (object)
1.147 + error->object = strdup(object);
1.148
1.149 error->str = strdup(str);
1.150
1.151 @@ -156,13 +184,16 @@
1.152
1.153 error = zalloc(sizeof *error);
1.154
1.155 + error->domain = src->domain;
1.156 + error->code = src->code;
1.157 +
1.158 if (summary)
1.159 error->summary = strdup(summary);
1.160 else if (src->summary)
1.161 error->summary = strdup(src->summary);
1.162
1.163 - if (src->path)
1.164 - error->path = strdup(src->path);
1.165 + if (src->object)
1.166 + error->object = strdup(src->object);
1.167
1.168 if (src->str)
1.169 error->str = strdup(src->str);
1.170 @@ -173,9 +204,9 @@
1.171 RAZOR_EXPORT void
1.172 razor_error_free(struct razor_error *error)
1.173 {
1.174 - free(error->path);
1.175 + free(error->object);
1.176 free(error->str);
1.177 - free(error->path_str);
1.178 + free(error->obj_str);
1.179 free(error->summary);
1.180 free(error->msg);
1.181 free(error);