Add.
[gsasl.git] / lib / gs2 / gs2wrap.c
blob16678c10258bddac85549c6a9369531723b8c913
1 /* gs2parser.h --- GS2 parser.
2 * Copyright (C) 2006 Simon Josefsson
4 * This file is part of GNU SASL Library.
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.
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.
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.
23 #include "gs2parser.h"
25 #include <stdint.h>
29 * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
30 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | client_qops | client_maxbuf |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | channel_binding_length |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * |[client_cbqops]| [channel_binding_data] /
37 * / /
38 * / / [authzid] /
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 int
43 gs2_parse_request (const char *request, size_t reqlen,
44 int clientp,
45 int *qop, size_t *maxbuf, size_t *cblen,
46 int *cbqops, char **cbdata, char **authzid)
48 size_t l;
50 if (reqlen < 8)
51 return -1;
53 if (qop)
54 *qop = request[0];
56 if (maxbuf)
57 *maxbuf =
58 (request[1] << 16) & 0xFF0000 |
59 (request[2] << 8) & 0xFF00 |
60 (request[3]) & 0xFF;
62 l = (request[4] << 24) & 0xFF000000 |
63 (request[5] << 16) & 0xFF0000 |
64 (request[6] << 8) & 0xFF00 |
65 (request[7]) & 0xFF;
67 if (l > 0 && reqlen == 8)
68 return -2;
70 if (cblen)
71 *cblen = l;
73 if (l > 0)
75 if (cbqops)
76 *cbqops = request[8];
77 if (cbdata)
78 *cbdata = &request[9];
79 if (authzid)
80 *authzid = &request[9] + l;
82 else
84 if (cbqops)
85 *cbqops = 0;
86 if (cbdata)
87 *cbdata = NULL;
88 if (authzid)
89 *authzid = NULL;
92 return 0;