LCOV - code coverage report
Current view: top level - lib/src - register.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 16 18 88.9 %
Date: 2012-05-28 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 12 33.3 %

           Branch data     Line data    Source code
       1                 :            : /* register.c --- Initialize and register SASL plugin in global context.
       2                 :            :  * Copyright (C) 2002-2012 Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of GNU SASL Library.
       5                 :            :  *
       6                 :            :  * GNU SASL Library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public License
       8                 :            :  * as published by the Free Software Foundation; either version 2.1 of
       9                 :            :  * the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * GNU SASL Library 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.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General Public
      17                 :            :  * License License along with GNU SASL Library; if not, write to the
      18                 :            :  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      19                 :            :  * Boston, MA 02110-1301, USA.
      20                 :            :  *
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "internal.h"
      24                 :            : 
      25                 :            : /**
      26                 :            :  * gsasl_register:
      27                 :            :  * @ctx: pointer to libgsasl handle.
      28                 :            :  * @mech: plugin structure with information about plugin.
      29                 :            :  *
      30                 :            :  * This function initialize given mechanism, and if successful, add it
      31                 :            :  * to the list of plugins that is used by the library.
      32                 :            :  *
      33                 :            :  * Return value: %GSASL_OK iff successful, otherwise %GSASL_MALLOC_ERROR.
      34                 :            :  *
      35                 :            :  * Since: 0.2.0
      36                 :            :  **/
      37                 :            : int
      38                 :        198 : gsasl_register (Gsasl * ctx, const Gsasl_mechanism * mech)
      39                 :            : {
      40                 :            :   Gsasl_mechanism *tmp;
      41                 :            : 
      42                 :            : #ifdef USE_CLIENT
      43 [ -  + ][ #  # ]:        198 :   if (mech->client.init == NULL || mech->client.init (ctx) == GSASL_OK)
      44                 :            :     {
      45                 :        198 :       tmp = realloc (ctx->client_mechs,
      46                 :        198 :                      sizeof (*ctx->client_mechs) * (ctx->n_client_mechs + 1));
      47         [ -  + ]:        198 :       if (tmp == NULL)
      48                 :          0 :         return GSASL_MALLOC_ERROR;
      49                 :            : 
      50                 :        198 :       memcpy (&tmp[ctx->n_client_mechs], mech, sizeof (*mech));
      51                 :            : 
      52                 :        198 :       ctx->client_mechs = tmp;
      53                 :        198 :       ctx->n_client_mechs++;
      54                 :            :     }
      55                 :            : #endif
      56                 :            : 
      57                 :            : #ifdef USE_SERVER
      58 [ -  + ][ #  # ]:        198 :   if (mech->server.init == NULL || mech->server.init (ctx) == GSASL_OK)
      59                 :            :     {
      60                 :        198 :       tmp = realloc (ctx->server_mechs,
      61                 :        198 :                      sizeof (*ctx->server_mechs) * (ctx->n_server_mechs + 1));
      62         [ -  + ]:        198 :       if (tmp == NULL)
      63                 :          0 :         return GSASL_MALLOC_ERROR;
      64                 :            : 
      65                 :        198 :       memcpy (&tmp[ctx->n_server_mechs], mech, sizeof (*mech));
      66                 :            : 
      67                 :        198 :       ctx->server_mechs = tmp;
      68                 :        198 :       ctx->n_server_mechs++;
      69                 :            :     }
      70                 :            : #endif
      71                 :            : 
      72                 :        198 :   return GSASL_OK;
      73                 :            : }

Generated by: LCOV version 1.9