00001 /* register.c --- Initialize and register SASL plugin in global context. 00002 * Copyright (C) 2002, 2003, 2004, 2005 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 00037 int 00038 gsasl_register (Gsasl * ctx, const Gsasl_mechanism * mech) 00039 { 00040 Gsasl_mechanism *tmp; 00041 00042 #ifdef USE_CLIENT 00043 if (mech->client.init == NULL || mech->client.init (ctx) == GSASL_OK) 00044 { 00045 tmp = realloc (ctx->client_mechs, 00046 sizeof (*ctx->client_mechs) * (ctx->n_client_mechs + 1)); 00047 if (tmp == NULL) 00048 return GSASL_MALLOC_ERROR; 00049 00050 memcpy (&tmp[ctx->n_client_mechs], mech, sizeof (*mech)); 00051 00052 ctx->client_mechs = tmp; 00053 ctx->n_client_mechs++; 00054 } 00055 #endif 00056 00057 #ifdef USE_SERVER 00058 if (mech->server.init == NULL || mech->server.init (ctx) == GSASL_OK) 00059 { 00060 tmp = realloc (ctx->server_mechs, 00061 sizeof (*ctx->server_mechs) * (ctx->n_server_mechs + 1)); 00062 if (tmp == NULL) 00063 return GSASL_MALLOC_ERROR; 00064 00065 memcpy (&tmp[ctx->n_server_mechs], mech, sizeof (*mech)); 00066 00067 ctx->server_mechs = tmp; 00068 ctx->n_server_mechs++; 00069 } 00070 #endif 00071 00072 return GSASL_OK; 00073 }