gsasl  2.2.1
qop.c
Go to the documentation of this file.
1 /* qop.c --- DIGEST-MD5 QOP handling.
2  * Copyright (C) 2002-2024 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 #include <config.h>
24 
25 /* Get prototypes. */
26 #include "qop.h"
27 
28 #include "tokens.h"
29 #include "parser.h"
30 
31 #include <string.h>
32 #include <stdlib.h>
33 
34 int
35 digest_md5_qopstr2qops (const char *qopstr)
36 {
37  int qops = 0;
38  enum
39  {
40  /* the order must match the following struct */
41  QOP_AUTH = 0,
44  };
45  const char *const qop_opts[] = {
46  /* the order must match the previous enum */
47  "qop-auth",
48  "qop-int",
49  "qop-conf",
50  NULL
51  };
52  char *subsubopts;
53  char *val;
54  char *qopdup;
55 
56  if (!qopstr)
57  return 0;
58 
59  qopdup = strdup (qopstr);
60  if (!qopdup)
61  return -1;
62 
63  subsubopts = qopdup;
64  while (*subsubopts != '\0')
65  switch (digest_md5_getsubopt (&subsubopts, qop_opts, &val))
66  {
67  case QOP_AUTH:
68  qops |= DIGEST_MD5_QOP_AUTH;
69  break;
70 
71  case QOP_AUTH_INT:
73  break;
74 
75  case QOP_AUTH_CONF:
77  break;
78 
79  default:
80  /* ignore unrecognized options */
81  break;
82  }
83 
84  free (qopdup);
85 
86  return qops;
87 }
88 
89 const char *
91 {
92  const char *qopstr[] = {
93  /* 0 */ "qop-auth",
94  /* 1 */ "qop-auth",
95  /* 2 */ "qop-int",
96  /* 3 */ "qop-auth, qop-int",
97  /* 4 */ "qop-conf",
98  /* 5 */ "qop-auth, qop-conf",
99  /* 6 */ "qop-int, qop-conf",
100  /* 7 */ "qop-auth, qop-int, qop-conf"
101  };
102 
103  return qopstr[qops & 0x07];
104 }
@ QOP_AUTH_CONF
@ QOP_AUTH_INT
@ QOP_AUTH
@ DIGEST_MD5_QOP_AUTH_INT
@ DIGEST_MD5_QOP_AUTH_CONF
@ DIGEST_MD5_QOP_AUTH
int digest_md5_getsubopt(char **optionp, const char *const *tokens, char **valuep)
Definition: getsubopt.c:44
const char * digest_md5_qops2qopstr(int qops)
Definition: qop.c:90
int digest_md5_qopstr2qops(const char *qopstr)
Definition: qop.c:35