|
gsasl
1.8.0
|
00001 /* listmech.c --- List active client and server mechanisms. 00002 * Copyright (C) 2002-2012 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 License along with GNU SASL Library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 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 + 1, 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 }
1.7.6.1