root / libcacard / vcard_emul_type.c @ 92f562ec
History | View | Annotate | Download (1.6 kB)
1 | 111a38b0 | Robert Relyea | /*
|
---|---|---|---|
2 | 111a38b0 | Robert Relyea | * This file contains utility functions which abstract the different card
|
3 | 111a38b0 | Robert Relyea | * types. The goal is that new card types can easily be added by simply
|
4 | 111a38b0 | Robert Relyea | * changing this file and vcard_emul_type.h. It is currently not a requirement
|
5 | 111a38b0 | Robert Relyea | * to dynamically add new card types.
|
6 | 111a38b0 | Robert Relyea | *
|
7 | 111a38b0 | Robert Relyea | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
8 | 111a38b0 | Robert Relyea | * See the COPYING.LIB file in the top-level directory.
|
9 | 111a38b0 | Robert Relyea | */
|
10 | 111a38b0 | Robert Relyea | |
11 | 111a38b0 | Robert Relyea | #include <strings.h> |
12 | 111a38b0 | Robert Relyea | #include "vcardt.h" |
13 | 111a38b0 | Robert Relyea | #include "vcard_emul_type.h" |
14 | 111a38b0 | Robert Relyea | #include "cac.h" |
15 | 111a38b0 | Robert Relyea | |
16 | 111a38b0 | Robert Relyea | VCardStatus vcard_init(VReader *vreader, VCard *vcard, |
17 | 111a38b0 | Robert Relyea | VCardEmulType type, const char *params, |
18 | 111a38b0 | Robert Relyea | unsigned char *const *cert, int cert_len[], |
19 | 111a38b0 | Robert Relyea | VCardKey *key[], int cert_count)
|
20 | 111a38b0 | Robert Relyea | { |
21 | 111a38b0 | Robert Relyea | switch (type) {
|
22 | 111a38b0 | Robert Relyea | case VCARD_EMUL_NONE:
|
23 | 111a38b0 | Robert Relyea | break;
|
24 | 111a38b0 | Robert Relyea | case VCARD_EMUL_CAC:
|
25 | 111a38b0 | Robert Relyea | return cac_card_init(vreader, vcard, params,
|
26 | 111a38b0 | Robert Relyea | cert, cert_len, key, cert_count); |
27 | 111a38b0 | Robert Relyea | /* add new ones here */
|
28 | 111a38b0 | Robert Relyea | default:
|
29 | 111a38b0 | Robert Relyea | break;
|
30 | 111a38b0 | Robert Relyea | } |
31 | 111a38b0 | Robert Relyea | return VCARD_FAIL;
|
32 | 111a38b0 | Robert Relyea | } |
33 | 111a38b0 | Robert Relyea | |
34 | 111a38b0 | Robert Relyea | VCardEmulType vcard_emul_type_select(VReader *vreader) |
35 | 111a38b0 | Robert Relyea | { |
36 | 111a38b0 | Robert Relyea | #ifdef notdef
|
37 | 111a38b0 | Robert Relyea | /* since there is only one emulator no need to call this function */
|
38 | 111a38b0 | Robert Relyea | if (cac_is_cac_card(vreader) == VCARD_DONE) {
|
39 | 111a38b0 | Robert Relyea | return VCARD_EMUL_CAC;
|
40 | 111a38b0 | Robert Relyea | } |
41 | 111a38b0 | Robert Relyea | #endif
|
42 | 111a38b0 | Robert Relyea | /* return the default */
|
43 | 111a38b0 | Robert Relyea | return VCARD_EMUL_CAC;
|
44 | 111a38b0 | Robert Relyea | } |
45 | 111a38b0 | Robert Relyea | |
46 | 111a38b0 | Robert Relyea | VCardEmulType vcard_emul_type_from_string(const char *type_string) |
47 | 111a38b0 | Robert Relyea | { |
48 | 111a38b0 | Robert Relyea | if (strcasecmp(type_string, "CAC") == 0) { |
49 | 111a38b0 | Robert Relyea | return VCARD_EMUL_CAC;
|
50 | 111a38b0 | Robert Relyea | } |
51 | 111a38b0 | Robert Relyea | #ifdef USE_PASSTHRU
|
52 | 111a38b0 | Robert Relyea | if (strcasecmp(type_string, "PASSTHRU") == 0) { |
53 | 111a38b0 | Robert Relyea | return VCARD_EMUL_PASSTHRU;
|
54 | 111a38b0 | Robert Relyea | } |
55 | 111a38b0 | Robert Relyea | #endif
|
56 | 111a38b0 | Robert Relyea | return VCARD_EMUL_NONE;
|
57 | 111a38b0 | Robert Relyea | } |