1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * Error Base
4  *
5  * Copyright 2015 Armin Novak <armin.novak@thincast.com>
6  * Copyright 2015 Thincast Technologies GmbH
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <stdio.h>
26 
27 #include <freerdp/log.h>
28 
29 #include "errinfo.h"
30 
31 #define TAG FREERDP_TAG("core")
32 
33 #define ERRBASE_DEFINE(_code)                                            \
34 	{                                                                    \
35 		ERRBASE_##_code, "ERRBASE_" #_code, ERRBASE_##_code##_STRING, "" \
36 	}
37 
38 /* Protocol-independent codes */
39 
40 /* Special codes */
41 #define ERRBASE_SUCCESS_STRING "Success."
42 #define ERRBASE_NONE_STRING ""
43 
44 static const ERRINFO ERRBASE_CODES[] = { ERRBASE_DEFINE(SUCCESS),
45 
46 	                                     ERRBASE_DEFINE(NONE) };
47 
freerdp_get_error_base_string(UINT32 code)48 const char* freerdp_get_error_base_string(UINT32 code)
49 {
50 	const ERRINFO* errInfo;
51 
52 	errInfo = &ERRBASE_CODES[0];
53 
54 	while (errInfo->code != ERRBASE_NONE)
55 	{
56 		if (code == errInfo->code)
57 		{
58 			return errInfo->info;
59 		}
60 
61 		errInfo++;
62 	}
63 
64 	return "ERRBASE_UNKNOWN";
65 }
66 
freerdp_get_error_base_category(UINT32 code)67 const char* freerdp_get_error_base_category(UINT32 code)
68 {
69 	const ERRINFO* errInfo;
70 
71 	errInfo = &ERRBASE_CODES[0];
72 
73 	while (errInfo->code != ERRBASE_NONE)
74 	{
75 		if (code == errInfo->code)
76 		{
77 			return errInfo->category;
78 		}
79 
80 		errInfo++;
81 	}
82 
83 	return "ERRBASE_UNKNOWN";
84 }
85 
freerdp_get_error_base_name(UINT32 code)86 const char* freerdp_get_error_base_name(UINT32 code)
87 {
88 	const ERRINFO* errInfo;
89 
90 	errInfo = &ERRBASE_CODES[0];
91 
92 	while (errInfo->code != ERRBASE_NONE)
93 	{
94 		if (code == errInfo->code)
95 		{
96 			return errInfo->name;
97 		}
98 
99 		errInfo++;
100 	}
101 
102 	return "ERRBASE_UNKNOWN";
103 }
104