gsasl 2.2.3
register.c
Go to the documentation of this file.
1/* register.c --- Initialize and register SASL plugin in global context.
2 * Copyright (C) 2002-2026 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, see
18 * <https://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <config.h>
23#include "internal.h"
24
37int
39{
40 Gsasl_mechanism *tmp;
41
42#ifdef USE_CLIENT
43 if (mech->client.init == NULL || mech->client.init (ctx) == GSASL_OK)
44 {
45 tmp = realloc (ctx->client_mechs,
46 sizeof (*ctx->client_mechs) * (ctx->n_client_mechs + 1));
47 if (tmp == NULL)
48 return GSASL_MALLOC_ERROR;
49
50 memcpy (&tmp[ctx->n_client_mechs], mech, sizeof (*mech));
51
52 ctx->client_mechs = tmp;
53 ctx->n_client_mechs++;
54 }
55#endif
56
57#ifdef USE_SERVER
58 if (mech->server.init == NULL || mech->server.init (ctx) == GSASL_OK)
59 {
60 tmp = realloc (ctx->server_mechs,
61 sizeof (*ctx->server_mechs) * (ctx->n_server_mechs + 1));
62 if (tmp == NULL)
63 return GSASL_MALLOC_ERROR;
64
65 memcpy (&tmp[ctx->n_server_mechs], mech, sizeof (*mech));
66
67 ctx->server_mechs = tmp;
68 ctx->n_server_mechs++;
69 }
70#endif
71
72 return GSASL_OK;
73}
@ GSASL_OK
Definition gsasl.h:128
@ GSASL_MALLOC_ERROR
Definition gsasl.h:132
int gsasl_register(Gsasl *ctx, const Gsasl_mechanism *mech)
Definition register.c:38
Gsasl_init_function init
Definition gsasl-mech.h:152
struct Gsasl_mechanism_functions server
Definition gsasl-mech.h:175
struct Gsasl_mechanism_functions client
Definition gsasl-mech.h:174
size_t n_client_mechs
Definition internal.h:37
Gsasl_mechanism * server_mechs
Definition internal.h:40
Gsasl_mechanism * client_mechs
Definition internal.h:38
size_t n_server_mechs
Definition internal.h:39