aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/gen_auth.h
blob: 6be4eb4d0b4d3301579cc87959ef060124d4883d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
  This file is part of libmicrohttpd
  Copyright (C) 2022 Evgeny Grin (Karlson2k)

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library.
  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file microhttpd/gen_auth.h
 * @brief  Declarations for HTTP authorisation general functions
 * @author Karlson2k (Evgeny Grin)
 */

#ifndef MHD_GET_AUTH_H
#define MHD_GET_AUTH_H 1

#include "mhd_options.h"
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif /* HAVE_STDBOOL_H */

struct MHD_Connection; /* Forward declaration to avoid include of the large headers */

/**
 * Type of authorisation
 */
enum MHD_AuthType
{
  MHD_AUTHTYPE_NONE = 0,/**< No authorisation */
  MHD_AUTHTYPE_BASIC,   /**< Basic Authorisation, RFC 7617  */
  MHD_AUTHTYPE_DIGEST,  /**< Digest Authorisation, RFC 7616 */
  MHD_AUTHTYPE_INVALID  /**< Wrong/Unknown/Unsupported authorisation type */
};

#ifdef BAUTH_SUPPORT
/* Forward declaration to avoid additional headers inclusion */
struct MHD_RqBAuth;
#endif /* BAUTH_SUPPORT */
#ifdef DAUTH_SUPPORT
/* Forward declaration to avoid additional headers inclusion */
struct MHD_RqDAuth;
#endif /* DAUTH_SUPPORT */

/**
 * Universal Authorisation Request parameters
 */
union MHD_AuthRqParams
{
#ifdef BAUTH_SUPPORT
  struct MHD_RqBAuth *bauth;
#endif /* BAUTH_SUPPORT */
#ifdef DAUTH_SUPPORT
  struct MHD_RqDAuth *dauth;
#endif /* DAUTH_SUPPORT */
};

/**
 * Request Authentication type and parameters
 */
struct MHD_AuthRqHeader
{
  enum MHD_AuthType auth_type;
  union MHD_AuthRqParams params;
};


/**
 * Return request's Authentication type and parameters.
 *
 * Function return result of parsing of the request's "Authorization" header or
 * returns cached parsing result if the header was already parsed for
 * the current request.
 * @param connection the connection to process
 * @return the pointer to structure with Authentication type and parameters,
 *         NULL if no memory in memory pool or if called too early (before
 *         header has been received).
 */
const struct MHD_AuthRqHeader *
MHD_get_auth_rq_params_ (struct MHD_Connection *connection);

#endif /* ! MHD_GET_AUTH_H */