LCOV - code coverage report
Current view: top level - lib - fko_nat_access.c (source / functions) Hit Total Coverage
Test: lcov_coverage_final.info Lines: 26 26 100.0 %
Date: 2014-11-16 Functions: 2 2 100.0 %
Branches: 32 38 84.2 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  *****************************************************************************
       3                 :            :  *
       4                 :            :  * File:    fko_nat_access.c
       5                 :            :  *
       6                 :            :  * Purpose: Set/Get the spa nat access request data.
       7                 :            :  *
       8                 :            :  *  Fwknop is developed primarily by the people listed in the file 'AUTHORS'.
       9                 :            :  *  Copyright (C) 2009-2014 fwknop developers and contributors. For a full
      10                 :            :  *  list of contributors, see the file 'CREDITS'.
      11                 :            :  *
      12                 :            :  *  License (GNU General Public License):
      13                 :            :  *
      14                 :            :  *  This program is free software; you can redistribute it and/or
      15                 :            :  *  modify it under the terms of the GNU General Public License
      16                 :            :  *  as published by the Free Software Foundation; either version 2
      17                 :            :  *  of the License, or (at your option) any later version.
      18                 :            :  *
      19                 :            :  *  This program is distributed in the hope that it will be useful,
      20                 :            :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      21                 :            :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      22                 :            :  *  GNU General Public License for more details.
      23                 :            :  *
      24                 :            :  *  You should have received a copy of the GNU General Public License
      25                 :            :  *  along with this program; if not, write to the Free Software
      26                 :            :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
      27                 :            :  *  USA
      28                 :            :  *
      29                 :            :  *****************************************************************************
      30                 :            : */
      31                 :            : #include "fko_common.h"
      32                 :            : #include "fko.h"
      33                 :            : 
      34                 :            : /* Set the SPA Nat Access data
      35                 :            : */
      36                 :            : int
      37                 :       6309 : fko_set_spa_nat_access(fko_ctx_t ctx, const char * const msg)
      38                 :            : {
      39                 :       6309 :     int res = FKO_SUCCESS;
      40                 :            : 
      41                 :            : #if HAVE_LIBFIU
      42         [ +  - ]:       6309 :     fiu_return_on("fko_set_spa_nat_access_init", FKO_ERROR_CTX_NOT_INITIALIZED);
      43                 :            : #endif
      44                 :            : 
      45                 :            :     /* Context must be initialized.
      46                 :            :     */
      47 [ +  + ][ +  - ]:       6309 :     if(!CTX_INITIALIZED(ctx))
      48                 :            :         return FKO_ERROR_CTX_NOT_INITIALIZED;
      49                 :            : 
      50                 :            :     /* Gotta have a valid string.
      51                 :            :     */
      52 [ +  + ][ +  + ]:       6295 :     if(msg == NULL || strnlen(msg, MAX_SPA_NAT_ACCESS_SIZE) == 0)
      53                 :            :         return(FKO_ERROR_INVALID_DATA_NAT_EMPTY);
      54                 :            : 
      55                 :            : #if HAVE_LIBFIU
      56         [ +  - ]:       6197 :     fiu_return_on("fko_set_spa_nat_access_empty", FKO_ERROR_INVALID_DATA_NAT_EMPTY);
      57                 :            : #endif
      58                 :            : 
      59                 :            :     /* --DSS XXX: Bail out for now.  But consider just
      60                 :            :      *            truncating in the future...
      61                 :            :     */
      62         [ +  + ]:       6197 :     if(strnlen(msg, MAX_SPA_NAT_ACCESS_SIZE) == MAX_SPA_NAT_ACCESS_SIZE)
      63                 :            :         return(FKO_ERROR_DATA_TOO_LARGE);
      64                 :            : 
      65                 :            : #if HAVE_LIBFIU
      66         [ +  - ]:       5861 :     fiu_return_on("fko_set_spa_nat_access_large", FKO_ERROR_DATA_TOO_LARGE);
      67                 :            : #endif
      68                 :            : 
      69         [ +  + ]:       5861 :     if((res = validate_nat_access_msg(msg)) != FKO_SUCCESS)
      70                 :            :         return(res);
      71                 :            : 
      72                 :            :     /* Just in case this is a subsquent call to this function.  We
      73                 :            :      * do not want to be leaking memory.
      74                 :            :     */
      75         [ +  + ]:        320 :     if(ctx->nat_access != NULL)
      76                 :        171 :         free(ctx->nat_access);
      77                 :            : 
      78                 :        320 :     ctx->nat_access = strdup(msg);
      79                 :            : 
      80                 :        320 :     ctx->state |= FKO_DATA_MODIFIED;
      81                 :            : 
      82         [ +  - ]:        320 :     if(ctx->nat_access == NULL)
      83                 :            :         return(FKO_ERROR_MEMORY_ALLOCATION);
      84                 :            : 
      85                 :            :     /* If we set the nat_access message Then we force the message_type
      86                 :            :      * as well. Technically, the message type should be set already.
      87                 :            :      * This will serve a half-protective measure.
      88                 :            :      * --DSS XXX: should do this better.
      89                 :            :     */
      90         [ +  + ]:        320 :     if(ctx->client_timeout > 0)
      91                 :            :     {
      92         [ +  + ]:         84 :         if(ctx->message_type != FKO_CLIENT_TIMEOUT_LOCAL_NAT_ACCESS_MSG)
      93                 :         59 :             ctx->message_type = FKO_CLIENT_TIMEOUT_NAT_ACCESS_MSG;
      94                 :            :     }
      95                 :            :     else
      96         [ +  + ]:        236 :         if(ctx->message_type != FKO_LOCAL_NAT_ACCESS_MSG)
      97                 :        220 :             ctx->message_type = FKO_NAT_ACCESS_MSG;
      98                 :            : 
      99                 :            :     return(FKO_SUCCESS);
     100                 :            : }
     101                 :            : 
     102                 :            : /* Return the SPA message data.
     103                 :            : */
     104                 :            : int
     105                 :       4494 : fko_get_spa_nat_access(fko_ctx_t ctx, char **nat_access)
     106                 :            : {
     107                 :            : 
     108                 :            : #if HAVE_LIBFIU
     109         [ +  + ]:       4494 :     fiu_return_on("fko_get_spa_nat_access_init", FKO_ERROR_CTX_NOT_INITIALIZED);
     110                 :            : #endif
     111                 :            : 
     112                 :            :     /* Must be initialized
     113                 :            :     */
     114 [ +  + ][ +  - ]:       4492 :     if(!CTX_INITIALIZED(ctx))
     115                 :            :         return(FKO_ERROR_CTX_NOT_INITIALIZED);
     116                 :            : 
     117         [ +  + ]:       4340 :     if(nat_access == NULL)
     118                 :            :         return(FKO_ERROR_INVALID_DATA);
     119                 :            : 
     120                 :            : #if HAVE_LIBFIU
     121         [ +  + ]:       4272 :     fiu_return_on("fko_get_spa_nat_access_val", FKO_ERROR_INVALID_DATA);
     122                 :            : #endif
     123                 :            : 
     124                 :       4270 :     *nat_access = ctx->nat_access;
     125                 :            : 
     126                 :       4270 :     return(FKO_SUCCESS);
     127                 :            : }
     128                 :            : 
     129                 :            : /***EOF***/

Generated by: LCOV version 1.10