Initial release, version 0.0.0.
[gsasl.git] / lib / listmech.c
blob03006b4cfdb8d2069013128ae98cb8092f0bb510
1 /* listmech.c list active client and server mechanisms
2 * Copyright (C) 2002 Simon Josefsson
4 * This file is part of libgsasl.
6 * Libgsasl is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libgsasl 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 libgsasl; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 static int
25 _gsasl_listmech (Gsasl_ctx *ctx,
26 _Gsasl_mechanism *mechs,
27 size_t n_mechs,
28 char *out,
29 size_t *outlen,
30 int clientp)
32 Gsasl_session_ctx *xctx;
33 void *mech_data;
34 int i = 0;
36 if (out == NULL)
38 *outlen = n_mechs * GSASL_MAX_MECHANISM_SIZE;
39 return GSASL_OK;
42 if (outlen == NULL || *outlen == 0)
43 return GSASL_TOO_SMALL_BUFFER;
45 *out = '\0';
46 for (i = 0; i < n_mechs; i++)
48 if ((clientp &&
49 gsasl_client_start (ctx, mechs[i].name, &xctx) == GSASL_OK) ||
50 (!clientp &&
51 gsasl_server_start (ctx, mechs[i].name, &xctx) == GSASL_OK))
53 if (clientp)
54 gsasl_client_finish (xctx);
55 else
56 gsasl_server_finish (xctx);
58 if (strlen(out) + strlen(mechs[i].name) + strlen(" ") >= *outlen)
59 return GSASL_TOO_SMALL_BUFFER;
61 strcat(out, mechs[i].name);
62 strcat(out, " ");
66 return GSASL_OK;
69 /**
70 * gsasl_client_listmech:
71 * @ctx: libgsasl handle.
72 * @out: output character array.
73 * @outlen: input maximum size of output character array, on output
74 * contains actual length of output array.
76 * Write SASL names, separated by space, of mechanisms supported by
77 * the libgsasl client to the output array. To find out how large the
78 * output array must be, call this function with out=NULL.
80 * Return value: Returns GSASL_OK if successful, or error code.
81 **/
82 int
83 gsasl_client_listmech (Gsasl_ctx *ctx, char *out, size_t *outlen)
85 return _gsasl_listmech (ctx, ctx->client_mechs, ctx->n_client_mechs,
86 out, outlen, 1);
89 /**
90 * gsasl_server_listmech:
91 * @ctx: libgsasl handle.
92 * @out: output character array.
93 * @outlen: input maximum size of output character array, on output
94 * contains actual length of output array.
96 * Write SASL names, separated by space, of mechanisms supported by
97 * the libgsasl server to the output array. To find out how large the
98 * output array must be, call this function with out=NULL.
100 * Return value: Returns GSASL_OK if successful, or error code.
103 gsasl_server_listmech (Gsasl_ctx *ctx, char *out, size_t *outlen)
105 return _gsasl_listmech (ctx, ctx->server_mechs, ctx->n_server_mechs,
106 out, outlen, 0);