LCOV - code coverage report
Current view: top level - lib/src - listmech.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 18 19 94.7 %
Date: 2012-05-28 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 10 90.0 %

           Branch data     Line data    Source code
       1                 :            : /* listmech.c --- List active client and server mechanisms.
       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                 :            : static int
      26                 :          6 : _gsasl_listmech (Gsasl * ctx,
      27                 :            :                  Gsasl_mechanism * mechs,
      28                 :            :                  size_t n_mechs, char **out, int clientp)
      29                 :            : {
      30                 :            :   Gsasl_session *sctx;
      31                 :            :   char *list;
      32                 :            :   size_t i;
      33                 :            :   int rc;
      34                 :            : 
      35                 :          6 :   list = calloc (n_mechs + 1, GSASL_MAX_MECHANISM_SIZE + 1);
      36         [ -  + ]:          6 :   if (!list)
      37                 :          0 :     return GSASL_MALLOC_ERROR;
      38                 :            : 
      39         [ +  + ]:         72 :   for (i = 0; i < n_mechs; i++)
      40                 :            :     {
      41         [ +  + ]:         66 :       if (clientp)
      42                 :         33 :         rc = gsasl_client_start (ctx, mechs[i].name, &sctx);
      43                 :            :       else
      44                 :         33 :         rc = gsasl_server_start (ctx, mechs[i].name, &sctx);
      45                 :            : 
      46         [ +  + ]:         66 :       if (rc == GSASL_OK)
      47                 :            :         {
      48                 :         60 :           gsasl_finish (sctx);
      49                 :            : 
      50                 :         60 :           strcat (list, mechs[i].name);
      51         [ +  + ]:         60 :           if (i < n_mechs - 1)
      52                 :         54 :             strcat (list, " ");
      53                 :            :         }
      54                 :            :     }
      55                 :            : 
      56                 :          6 :   *out = list;
      57                 :            : 
      58                 :          6 :   return GSASL_OK;
      59                 :            : }
      60                 :            : 
      61                 :            : /**
      62                 :            :  * gsasl_client_mechlist:
      63                 :            :  * @ctx: libgsasl handle.
      64                 :            :  * @out: newly allocated output character array.
      65                 :            :  *
      66                 :            :  * Return a newly allocated string containing SASL names, separated by
      67                 :            :  * space, of mechanisms supported by the libgsasl client.  @out is
      68                 :            :  * allocated by this function, and it is the responsibility of caller
      69                 :            :  * to deallocate it.
      70                 :            :  *
      71                 :            :  * Return value: Returns %GSASL_OK if successful, or error code.
      72                 :            :  **/
      73                 :            : int
      74                 :          3 : gsasl_client_mechlist (Gsasl * ctx, char **out)
      75                 :            : {
      76                 :          3 :   return _gsasl_listmech (ctx, ctx->client_mechs, ctx->n_client_mechs,
      77                 :            :                           out, 1);
      78                 :            : }
      79                 :            : 
      80                 :            : /**
      81                 :            :  * gsasl_server_mechlist:
      82                 :            :  * @ctx: libgsasl handle.
      83                 :            :  * @out: newly allocated output character array.
      84                 :            :  *
      85                 :            :  * Return a newly allocated string containing SASL names, separated by
      86                 :            :  * space, of mechanisms supported by the libgsasl server.  @out is
      87                 :            :  * allocated by this function, and it is the responsibility of caller
      88                 :            :  * to deallocate it.
      89                 :            :  *
      90                 :            :  * Return value: Returns %GSASL_OK if successful, or error code.
      91                 :            :  **/
      92                 :            : int
      93                 :          3 : gsasl_server_mechlist (Gsasl * ctx, char **out)
      94                 :            : {
      95                 :          3 :   return _gsasl_listmech (ctx, ctx->server_mechs, ctx->n_server_mechs,
      96                 :            :                           out, 0);
      97                 :            : }

Generated by: LCOV version 1.9