00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "internal.h"
00024
00025 static int
00026 _gsasl_listmech (Gsasl * ctx,
00027 Gsasl_mechanism * mechs,
00028 size_t n_mechs, char **out, int clientp)
00029 {
00030 Gsasl_session *sctx;
00031 char *list;
00032 size_t i;
00033 int rc;
00034
00035 list = calloc (n_mechs, GSASL_MAX_MECHANISM_SIZE + 1);
00036 if (!list)
00037 return GSASL_MALLOC_ERROR;
00038
00039 for (i = 0; i < n_mechs; i++)
00040 {
00041 if (clientp)
00042 rc = gsasl_client_start (ctx, mechs[i].name, &sctx);
00043 else
00044 rc = gsasl_server_start (ctx, mechs[i].name, &sctx);
00045
00046 if (rc == GSASL_OK)
00047 {
00048 gsasl_finish (sctx);
00049
00050 strcat (list, mechs[i].name);
00051 if (i < n_mechs - 1)
00052 strcat (list, " ");
00053 }
00054 }
00055
00056 *out = list;
00057
00058 return GSASL_OK;
00059 }
00060
00073 int
00074 gsasl_client_mechlist (Gsasl * ctx, char **out)
00075 {
00076 return _gsasl_listmech (ctx, ctx->client_mechs, ctx->n_client_mechs,
00077 out, 1);
00078 }
00079
00092 int
00093 gsasl_server_mechlist (Gsasl * ctx, char **out)
00094 {
00095 return _gsasl_listmech (ctx, ctx->server_mechs, ctx->n_server_mechs,
00096 out, 0);
00097 }