gsasl-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS gsasl/lib/src


From: gsasl-commit
Subject: CVS gsasl/lib/src
Date: Fri, 17 Sep 2004 23:27:12 +0200

Update of /home/cvs/gsasl/lib/src
In directory dopio:/tmp/cvs-serv25720/lib/src

Modified Files:
        Makefile.am init.c internal.h 
Added Files:
        register.c 
Log Message:
(gsasl_register): Add.
(gsasl_init): Use it.


--- /home/cvs/gsasl/lib/src/Makefile.am 2004/06/26 15:04:29     1.7
+++ /home/cvs/gsasl/lib/src/Makefile.am 2004/09/17 21:27:12     1.8
@@ -29,7 +29,7 @@
 libgsasl_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 libgsasl_la_LIBADD = @LTLIBINTL@ ../crypto/libgc.la
 libgsasl_la_SOURCES = gsasl.h.in internal.h \
-       init.c done.c error.c version.c common.c \
+       init.c done.c register.c error.c version.c common.c \
        callback.c callback-c.c callback-s.c \
        supportp.c suggest.c listmech.c \
        xstart.c xstep.c xfinish.c xcode.c \
--- /home/cvs/gsasl/lib/src/init.c      2004/09/17 20:57:56     1.5
+++ /home/cvs/gsasl/lib/src/init.c      2004/09/17 21:27:12     1.6
@@ -40,7 +40,8 @@
 int
 gsasl_init (Gsasl ** ctx)
 {
-  int i;
+  size_t i;
+  int rc;
 
   if (gc_init () != GC_OK)
     return GSASL_CRYPTO_ERROR;
@@ -51,55 +52,12 @@
 
   for (i = 0; _gsasl_all_mechanisms[i].name; i++)
     {
-#ifdef USE_CLIENT
-      if (_gsasl_all_mechanisms[i].client.init == NULL ||
-         _gsasl_all_mechanisms[i].client.init (*ctx) == GSASL_OK)
+      rc = gsasl_register (*ctx, &_gsasl_all_mechanisms[i]);
+      if (rc != GSASL_OK)
        {
-         if ((*ctx)->client_mechs)
-           (*ctx)->client_mechs = (_Gsasl_mechanism *)
-             realloc ((*ctx)->client_mechs,
-                      sizeof (*(*ctx)->client_mechs) *
-                      ((*ctx)->n_client_mechs + 1));
-         else
-           (*ctx)->client_mechs = (_Gsasl_mechanism *)
-             malloc (sizeof (*(*ctx)->client_mechs));
-
-         if ((*ctx)->client_mechs == NULL)
-           {
-             gsasl_done (*ctx);
-             return GSASL_MALLOC_ERROR;
-           }
-
-         (*ctx)->client_mechs[(*ctx)->n_client_mechs] =
-           _gsasl_all_mechanisms[i];
-         (*ctx)->n_client_mechs++;
-       }
-#endif
-
-#ifdef USE_SERVER
-      if (_gsasl_all_mechanisms[i].server.init == NULL ||
-         _gsasl_all_mechanisms[i].server.init (*ctx) == GSASL_OK)
-       {
-         if ((*ctx)->server_mechs)
-           (*ctx)->server_mechs = (_Gsasl_mechanism *)
-             realloc ((*ctx)->server_mechs,
-                      sizeof (*(*ctx)->server_mechs) *
-                      ((*ctx)->n_server_mechs + 1));
-         else
-           (*ctx)->server_mechs = (_Gsasl_mechanism *)
-             malloc (sizeof (*(*ctx)->server_mechs));
-
-         if ((*ctx)->server_mechs == NULL)
-           {
-             gsasl_done (*ctx);
-             return GSASL_MALLOC_ERROR;
-           }
-
-         (*ctx)->server_mechs[(*ctx)->n_server_mechs] =
-           _gsasl_all_mechanisms[i];
-         (*ctx)->n_server_mechs++;
+         gsasl_done (*ctx);
+         return rc;
        }
-#endif
     }
 
   return GSASL_OK;
--- /home/cvs/gsasl/lib/src/internal.h  2004/07/10 12:39:13     1.3
+++ /home/cvs/gsasl/lib/src/internal.h  2004/09/17 21:27:12     1.4
@@ -79,6 +79,10 @@
 };
 typedef struct _Gsasl_mechanism _Gsasl_mechanism;
 
+/* Move to gsasl.h once all mechanisms have been rewritten to use
+   allocating API.  See register.c. */
+extern int gsasl_register (Gsasl * ctx, const _Gsasl_mechanism *mech);
+
 /* Main library handle. */
 struct Gsasl
 {

--- /home/cvs/gsasl/lib/src/register.c  2004/09/17 21:27:12     NONE
+++ /home/cvs/gsasl/lib/src/register.c  2004/09/17 21:27:12     1.1
/* register.c --- Initialize and register SASL plugin in global context.
 * Copyright (C) 2002, 2003, 2004  Simon Josefsson
 *
 * This file is part of GNU SASL Library.
 *
 * GNU SASL Library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * GNU SASL Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * License along with GNU SASL Library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "internal.h"

/* This interface should be made public once the plugin API, and all
 * mechanisms, have been changed to use an allocating API.  Before
 * that, I don't want to introduce this since it would only be
 * backwards incompatible later on.  For now, only init.c calls it.
 */

/*
 * gsasl_register:
 * @ctx: pointer to libgsasl handle.
 * @mech: plugin structure with information about plugin.
 *
 * This function initialize given mechanism, and if successful, add it
 * to the list of plugins that is used by the library.
 *
 * Return value: GSASL_OK iff successful, otherwise GSASL_MALLOC_ERROR.
 **/
int
gsasl_register (Gsasl * ctx, const _Gsasl_mechanism *mech)
{
  _Gsasl_mechanism *tmp;

#ifdef USE_CLIENT
  if (mech->client.init == NULL || mech->client.init (ctx) == GSASL_OK)
    {
      tmp = realloc (ctx->client_mechs,
                     sizeof (*ctx->client_mechs) *
                     (ctx->n_client_mechs + 1));
      if (tmp == NULL)
        return GSASL_MALLOC_ERROR;

      memcpy (&tmp[ctx->n_client_mechs], mech, sizeof (*mech));

      ctx->client_mechs = tmp;
      ctx->n_client_mechs++;
    }
#endif

#ifdef USE_SERVER
  if (mech->server.init == NULL || mech->server.init (ctx) == GSASL_OK)
    {
      tmp = realloc (ctx->server_mechs,
                     sizeof (*ctx->server_mechs) *
                     (ctx->n_server_mechs + 1));
      if (tmp == NULL)
        return GSASL_MALLOC_ERROR;

      memcpy (&tmp[ctx->n_server_mechs], mech, sizeof (*mech));

      ctx->server_mechs = tmp;
      ctx->n_server_mechs++;
    }
#endif

  return GSASL_OK;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]