gs2wrap.c

Go to the documentation of this file.
00001 /* gs2parser.h --- GS2 parser.
00002  * Copyright (C) 2006  Simon Josefsson
00003  *
00004  * This file is part of GNU SASL Library.
00005  *
00006  * GNU SASL Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation; either version 2.1 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * GNU SASL Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with GNU SASL Library; if not, write to the Free
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gs2parser.h"
00024 
00025 #include <stdint.h>
00026 
00027 /*
00028  *
00029  *  1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
00030  *  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
00031  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00032  *  |  client_qops  |               client_maxbuf                   |
00033  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00034  *  |                   channel_binding_length                      |
00035  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00036  *  |[client_cbqops]|          [channel_binding_data]               /
00037  *  /                                                               /
00038  *  /                         /      [authzid]                      /
00039  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00040  *
00041  */
00042 int
00043 gs2_parse_request (const char *request, size_t reqlen,
00044                    int clientp,
00045                    int *qop, size_t * maxbuf, size_t * cblen,
00046                    int *cbqops, char **cbdata, char **authzid)
00047 {
00048   size_t l;
00049 
00050   if (reqlen < 8)
00051     return -1;
00052 
00053   if (qop)
00054     *qop = request[0];
00055 
00056   if (maxbuf)
00057     *maxbuf =
00058       (request[1] << 16) & 0xFF0000 |
00059       (request[2] << 8) & 0xFF00 | (request[3]) & 0xFF;
00060 
00061   l = (request[4] << 24) & 0xFF000000 |
00062     (request[5] << 16) & 0xFF0000 |
00063     (request[6] << 8) & 0xFF00 | (request[7]) & 0xFF;
00064 
00065   if (l > 0 && reqlen == 8)
00066     return -2;
00067 
00068   if (cblen)
00069     *cblen = l;
00070 
00071   if (l > 0)
00072     {
00073       if (cbqops)
00074         *cbqops = request[8];
00075       if (cbdata)
00076         *cbdata = &request[9];
00077       if (authzid)
00078         *authzid = &request[9] + l;
00079     }
00080   else
00081     {
00082       if (cbqops)
00083         *cbqops = 0;
00084       if (cbdata)
00085         *cbdata = NULL;
00086       if (authzid)
00087         *authzid = NULL;
00088     }
00089 
00090   return 0;
00091 }

Generated on Tue Oct 21 18:28:19 2008 for gsasl by  doxygen 1.5.6