summaryrefslogtreecommitdiff
path: root/unsorted/uContextSecret.cpp
blob: b33ca814d5ccd4796e701affa742d00a3a653340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "plugin_internal.h"

static Boolean ValidateContext(CWPluginContext context) {
    return context && (context->shellSignature == CWFOURCHAR('C','W','I','E'));
}

typedef CWResult (*cbSecretAttachHandleType)(CWPluginContext, Handle, CWMemHandle *);
typedef CWResult (*cbSecretDetachHandleType)(CWPluginContext, CWMemHandle, Handle *);
typedef CWResult (*cbSecretPeekHandleType)(CWPluginContext, CWMemHandle, Handle *);
typedef CWResult (*cbSecretGetNamedPreferencesType)(CWPluginContext, const char *, Handle *);

CW_CALLBACK CWSecretAttachHandle(CWPluginContext context, Handle handle, CWMemHandle *memHandle) {
    if (!ValidateContext(context))
        return cwErrInvalidParameter;
    return ((cbSecretAttachHandleType) context->callbacks->cbInternal[0])(context, handle, memHandle);
}

CW_CALLBACK CWSecretDetachHandle(CWPluginContext context, CWMemHandle memHandle, Handle *handle) {
    if (!ValidateContext(context))
        return cwErrInvalidParameter;
    return ((cbSecretDetachHandleType) context->callbacks->cbInternal[1])(context, memHandle, handle);
}

CW_CALLBACK CWSecretPeekHandle(CWPluginContext context, CWMemHandle memHandle, Handle *handle) {
    if (!ValidateContext(context))
        return cwErrInvalidParameter;
    return ((cbSecretPeekHandleType) context->callbacks->cbInternal[2])(context, memHandle, handle);
}

CW_CALLBACK CWSecretGetNamedPreferences(CWPluginContext context, const char *prefsname, Handle *prefsdata) {
    if (!prefsdata)
        return cwErrInvalidParameter;

    CWMemHandle memHandle;
    CWResult res = CWGetNamedPreferences(context, prefsname, &memHandle);
    if (!res)
        res = CWSecretDetachHandle(context, memHandle, prefsdata);
    return res;
}