1 | /* qop.c --- DIGEST-MD5 QOP handling. |
2 | * Copyright (C) 2002-2012 Simon Josefsson |
3 | * |
4 | * This file is part of GNU SASL Library. |
5 | * |
6 | * GNU SASL Library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public License |
8 | * as published by the Free Software Foundation; either version 2.1 of |
9 | * the License, or (at your option) any later version. |
10 | * |
11 | * GNU SASL Library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with GNU SASL Library; if not, write to the Free |
18 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #ifdef HAVE_CONFIG_H |
24 | #include "config.h" |
25 | #endif |
26 | |
27 | /* Get prototypes. */ |
28 | #include "qop.h" |
29 | |
30 | #include "tokens.h" |
31 | #include "parser.h" |
32 | |
33 | #include <string.h> |
34 | #include <stdlib.h> |
35 | |
36 | int |
37 | digest_md5_qopstr2qops (const char *qopstr) |
38 | { |
39 | int qops = 0; |
40 | enum |
41 | { |
42 | /* the order must match the following struct */ |
43 | QOP_AUTH = 0, |
44 | QOP_AUTH_INT, |
45 | QOP_AUTH_CONF |
46 | }; |
47 | const char *const qop_opts[] = { |
48 | /* the order must match the previous enum */ |
49 | "qop-auth" , |
50 | "qop-int" , |
51 | "qop-conf" , |
52 | NULL |
53 | }; |
54 | char *subsubopts; |
55 | char *val; |
56 | char *qopdup; |
57 | |
58 | if (!qopstr) |
59 | return 0; |
60 | |
61 | qopdup = strdup (qopstr); |
62 | if (!qopdup) |
63 | return -1; |
64 | |
65 | subsubopts = qopdup; |
66 | while (*subsubopts != '\0') |
67 | switch (digest_md5_getsubopt (&subsubopts, qop_opts, &val)) |
68 | { |
69 | case QOP_AUTH: |
70 | qops |= DIGEST_MD5_QOP_AUTH; |
71 | break; |
72 | |
73 | case QOP_AUTH_INT: |
74 | qops |= DIGEST_MD5_QOP_AUTH_INT; |
75 | break; |
76 | |
77 | case QOP_AUTH_CONF: |
78 | qops |= DIGEST_MD5_QOP_AUTH_CONF; |
79 | break; |
80 | |
81 | default: |
82 | /* ignore unrecognized options */ |
83 | break; |
84 | } |
85 | |
86 | free (qopdup); |
87 | |
88 | return qops; |
89 | } |
90 | |
91 | const char * |
92 | digest_md5_qops2qopstr (int qops) |
93 | { |
94 | const char *qopstr[] = { |
95 | /* 0 */ "qop-auth" , |
96 | /* 1 */ "qop-auth" , |
97 | /* 2 */ "qop-int" , |
98 | /* 3 */ "qop-auth, qop-int" , |
99 | /* 4 */ "qop-conf" , |
100 | /* 5 */ "qop-auth, qop-conf" , |
101 | /* 6 */ "qop-int, qop-conf" , |
102 | /* 7 */ "qop-auth, qop-int, qop-conf" |
103 | }; |
104 | |
105 | return qopstr[qops & 0x07]; |
106 | } |
107 | |