Subversion Repositories userdetect2

Rev

Rev 69 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 69 Rev 71
Line 1... Line 1...
1
#ifndef _UD2_STATUS_H_
1
#ifndef _UD2_STATUS_H_
2
#define _UD2_STATUS_H_
2
#define _UD2_STATUS_H_
3
 
3
 
4
#include <stdio.h>
4
#include <stdio.h>
5
 
5
 
6
typedef DWORD UD2_STATUS;
6
#include "ud2_api.h"
7
typedef BYTE UD2_STATUSCAT; // 0x0..0xF; only 1 nibble!
-
 
8
typedef WORD UD2_STATUSAUTH; // 0x000..0xFFF; only 3 nibbles!
-
 
9
typedef WORD UD2_STATUSMSG;
-
 
10
 
-
 
11
const UD2_STATUSCAT UD2_STATUSCAT_SUCCESS   = 0x8;
-
 
12
const UD2_STATUSCAT UD2_STATUSCAT_NOT_AVAIL = 0x9;
-
 
13
const UD2_STATUSCAT UD2_STATUSCAT_ERROR     = 0xA;
-
 
14
 
-
 
15
const UD2_STATUSAUTH UD2_STATUSAUTH_GENERIC = 0x100;
-
 
16
 
-
 
17
const UD2_STATUS UD2_STATUS_OK_UNSPECIFIED  = 0x81000000;
-
 
18
const UD2_STATUS UD2_STATUS_OK_SINGLELINE   = 0x81000001;
-
 
19
const UD2_STATUS UD2_STATUS_OK_MULTILINE    = 0x81000002;
-
 
20
const UD2_STATUS UD2_STATUS_OK_LICENSED     = 0x81000003;
-
 
21
 
-
 
22
const UD2_STATUS UD2_STATUS_NOTAVAIL_UNSPECIFIED       = 0x91000000;
-
 
23
const UD2_STATUS UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED  = 0x91000001;
-
 
24
const UD2_STATUS UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED  = 0x91000002;
-
 
25
const UD2_STATUS UD2_STATUS_NOTAVAIL_NO_ENTITIES       = 0x91000003;
-
 
26
const UD2_STATUS UD2_STATUS_NOTAVAIL_API_CALL_FAILURE  = 0x91000004;
-
 
27
 
-
 
28
const UD2_STATUS UD2_STATUS_ERROR_UNSPECIFIED          = 0xA1000000;
-
 
29
const UD2_STATUS UD2_STATUS_ERROR_BUFFER_TOO_SMALL     = 0xA1000001;
-
 
30
const UD2_STATUS UD2_STATUS_ERROR_INVALID_ARGS         = 0xA1000002;
-
 
31
const UD2_STATUS UD2_STATUS_ERROR_PLUGIN_NOT_LICENSED  = 0xA1000003;
-
 
32
 
7
 
-
 
8
typedef WORD  UD2_STATUSCAT;
33
UD2_STATUS UD2_STATUS_Construct(UD2_STATUSCAT cat, UD2_STATUSAUTH auth, UD2_STATUSMSG msg) {
9
typedef GUID  UD2_STATUSAUTH;
-
 
10
typedef DWORD UD2_STATUSMSG;
34
        return (cat << 28) + (auth << 16) + msg;
11
typedef DWORD UD2_STATUSEXTRAINFO;
35
}
-
 
36
 
12
 
-
 
13
#pragma pack(push, 1) // no alignment
-
 
14
typedef struct _UD2_STATUS {
-
 
15
    BYTE                cbSize;
-
 
16
    BYTE                bReserved;
37
UD2_STATUSCAT UD2_STATUS_GetCategory(UD2_STATUS dwStatus) {
17
    UD2_STATUSCAT       wCategory;
-
 
18
    UD2_STATUSAUTH      grAuthority;
38
        return (dwStatus & 0xF0000000) >> 28;
19
    UD2_STATUSMSG       dwMessage;
-
 
20
    UD2_STATUSEXTRAINFO dwExtraInfo;
39
}
21
} UD2_STATUS;
-
 
22
#pragma pack(pop) // restore previous pack value
40
 
23
 
41
UD2_STATUSAUTH UD2_STATUS_GetAuthority(UD2_STATUS dwStatus) {
24
const UD2_STATUSCAT UD2_STATUSCAT_SUCCESS   = 0;
-
 
25
const UD2_STATUSCAT UD2_STATUSCAT_NOT_AVAIL = 1;
42
        return (dwStatus & 0x0FFF0000) >> 16;
26
const UD2_STATUSCAT UD2_STATUSCAT_FAILED    = 2;
43
}
27
 
-
 
28
const UD2_STATUSAUTH UD2_STATUSAUTH_GENERIC = __GUID("{90F53368-1EFB-4350-A6BC-725C69938B9C}");
44
 
29
 
-
 
30
const UD2_STATUS UD2_STATUS_OK_UNSPECIFIED = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_SUCCESS, UD2_STATUSAUTH_GENERIC, 0, 0 };
-
 
31
const UD2_STATUS UD2_STATUS_OK_SINGLELINE  = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_SUCCESS, UD2_STATUSAUTH_GENERIC, 1, 0 };
45
UD2_STATUSMSG UD2_STATUS_GetMessage(UD2_STATUS dwStatus) {
32
const UD2_STATUS UD2_STATUS_OK_MULTILINE   = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_SUCCESS, UD2_STATUSAUTH_GENERIC, 2, 0 };
46
        return dwStatus & 0x0000FFFF;
33
const UD2_STATUS UD2_STATUS_OK_LICENSED    = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_SUCCESS, UD2_STATUSAUTH_GENERIC, 3, 0 };
47
}
34
 
-
 
35
const UD2_STATUS UD2_STATUS_NOTAVAIL_UNSPECIFIED         = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_NOT_AVAIL, UD2_STATUSAUTH_GENERIC, 0, 0 };
-
 
36
const UD2_STATUS UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED    = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_NOT_AVAIL, UD2_STATUSAUTH_GENERIC, 1, 0 };
-
 
37
const UD2_STATUS UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED    = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_NOT_AVAIL, UD2_STATUSAUTH_GENERIC, 2, 0 };
-
 
38
const UD2_STATUS UD2_STATUS_NOTAVAIL_NO_ENTITIES         = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_NOT_AVAIL, UD2_STATUSAUTH_GENERIC, 3, 0 };
-
 
39
const UD2_STATUS UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_NOT_AVAIL, UD2_STATUSAUTH_GENERIC, 4, 0 };
48
 
40
 
-
 
41
const UD2_STATUS UD2_STATUS_FAILURE_UNSPECIFIED         = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_FAILED, UD2_STATUSAUTH_GENERIC, 0, 0 };
-
 
42
const UD2_STATUS UD2_STATUS_FAILURE_BUFFER_TOO_SMALL    = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_FAILED, UD2_STATUSAUTH_GENERIC, 1, 0 };
49
BOOL UD2_STATUS_Successful(UD2_STATUS dwStatus) {
43
const UD2_STATUS UD2_STATUS_FAILURE_INVALID_ARGS        = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_FAILED, UD2_STATUSAUTH_GENERIC, 2, 0 };
50
        return UD2_STATUS_GetCategory(dwStatus) == UD2_STATUSCAT_SUCCESS;
44
const UD2_STATUS UD2_STATUS_FAILURE_PLUGIN_NOT_LICENSED = { sizeof(UD2_STATUS), 0, UD2_STATUSCAT_FAILED, UD2_STATUSAUTH_GENERIC, 3, 0 };
51
}
-
 
52
 
45
 
53
BOOL UD2_STATUS_NotAvail(UD2_STATUS dwStatus) {
46
int UD2_STATUS_FormatStatusCode(char* szStr, size_t cchLen, UD2_STATUS grStatus) {
-
 
47
        // 00 0000 {44332211-1234-ABCD-EFEF-001122334455} 00000000 00000000
-
 
48
        if (cchLen < 73) szStr = NULL; // incl. null-terminator
-
 
49
        return sprintf(szStr, "%02x %04x {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX} %08x %08x",
-
 
50
                grStatus.bReserved,
-
 
51
                grStatus.wCategory,
-
 
52
                grStatus.grAuthority,
54
        return UD2_STATUS_GetCategory(dwStatus) == UD2_STATUSCAT_NOT_AVAIL;
53
                grStatus.grAuthority.Data1, grStatus.grAuthority.Data2, grStatus.grAuthority.Data3,
-
 
54
                        grStatus.grAuthority.Data4[0], grStatus.grAuthority.Data4[1], grStatus.grAuthority.Data4[2], grStatus.grAuthority.Data4[3],
-
 
55
                        grStatus.grAuthority.Data4[4], grStatus.grAuthority.Data4[5], grStatus.grAuthority.Data4[6], grStatus.grAuthority.Data4[7],
-
 
56
                grStatus.dwMessage,
-
 
57
                grStatus.dwExtraInfo); 
55
}
58
}
56
 
59
 
57
BOOL UD2_STATUS_Failed(UD2_STATUS dwStatus) {
60
bool UD2_STATUS_Equal(UD2_STATUS grStatus1, UD2_STATUS grStatus2, bool compareExtraInfo) {
58
        return UD2_STATUS_GetCategory(dwStatus) == UD2_STATUSCAT_ERROR;
61
        return (grStatus1.bReserved == grStatus2.bReserved) &&
-
 
62
                (grStatus1.wCategory == grStatus2.wCategory) &&
-
 
63
                IsEqualGUID(grStatus1.grAuthority, grStatus2.grAuthority) &&
-
 
64
                (grStatus1.dwMessage == grStatus2.dwMessage);
-
 
65
               
-
 
66
        if (compareExtraInfo && (grStatus1.dwExtraInfo != grStatus2.dwExtraInfo)) return false;
59
}
67
}
60
 
68
 
61
int UD2_STATUS_FormatStatusCode(char* szStr, size_t cchLen, UD2_STATUS dwStatus) {
-
 
62
        if (cchLen < 11) szStr = NULL;
69
#ifdef __cplusplus
63
        return sprintf(szStr, "%01x %03x %04x", UD2_STATUS_GetCategory(dwStatus),
-
 
64
                                                UD2_STATUS_GetAuthority(dwStatus),
70
bool operator==(const UD2_STATUS& lhs, const UD2_STATUS& rhs) {
65
                                                UD2_STATUS_GetMessage(dwStatus));
71
        return UD2_STATUS_Equal(lhs, rhs, true);
66
}
72
}
-
 
73
#endif
67
 
74
 
68
BOOL UD2_STATUS_IsSpecific(UD2_STATUS dwStatus) {
75
UD2_STATUS UD2_STATUS_OSError(DWORD dwOSError) {
-
 
76
        UD2_STATUS ret = UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE;
69
        return (dwStatus & 0x0000FFFF) != 0;
77
        ret.dwExtraInfo = dwOSError;   
-
 
78
        return ret;
70
}
79
}
71
 
80
 
72
#endif
81
#endif