LCOV - code coverage report
Current view: top level - lib - fko_nat_access.c (source / functions) Hit Total Coverage
Test: id:002084,src:002034,op:havoc,rep:2.lcov_info_final Lines: 5 21 23.8 %
Date: 2015-05-30 Functions: 1 2 50.0 %
Branches: 3 28 10.7 %

           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                 :          0 : fko_set_spa_nat_access(fko_ctx_t ctx, const char * const msg)
      38                 :            : {
      39                 :          0 :     int res = FKO_SUCCESS;
      40                 :            : 
      41                 :            : #if HAVE_LIBFIU
      42                 :            :     fiu_return_on("fko_set_spa_nat_access_init", FKO_ERROR_CTX_NOT_INITIALIZED);
      43                 :            : #endif
      44                 :            : 
      45                 :            :     /* Context must be initialized.
      46                 :            :     */
      47 [ #  # ][ #  # ]:          0 :     if(!CTX_INITIALIZED(ctx))
      48                 :            :         return FKO_ERROR_CTX_NOT_INITIALIZED;
      49                 :            : 
      50                 :            :     /* Gotta have a valid string.
      51                 :            :     */
      52 [ #  # ][ #  # ]:          0 :     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                 :            :     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         [ #  # ]:          0 :     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                 :            :     fiu_return_on("fko_set_spa_nat_access_large", FKO_ERROR_DATA_TOO_LARGE);
      67                 :            : #endif
      68                 :            : 
      69         [ #  # ]:          0 :     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         [ #  # ]:          0 :     if(ctx->nat_access != NULL)
      76                 :          0 :         free(ctx->nat_access);
      77                 :            : 
      78                 :          0 :     ctx->nat_access = strdup(msg);
      79                 :            : 
      80                 :          0 :     ctx->state |= FKO_DATA_MODIFIED;
      81                 :            : 
      82         [ #  # ]:          0 :     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         [ #  # ]:          0 :     if(ctx->client_timeout > 0)
      91                 :            :     {
      92         [ #  # ]:          0 :         if(ctx->message_type != FKO_CLIENT_TIMEOUT_LOCAL_NAT_ACCESS_MSG)
      93                 :          0 :             ctx->message_type = FKO_CLIENT_TIMEOUT_NAT_ACCESS_MSG;
      94                 :            :     }
      95                 :            :     else
      96         [ #  # ]:          0 :         if(ctx->message_type != FKO_LOCAL_NAT_ACCESS_MSG)
      97                 :          0 :             ctx->message_type = FKO_NAT_ACCESS_MSG;
      98                 :            : 
      99                 :            :     return(FKO_SUCCESS);
     100                 :            : }
     101                 :            : 
     102                 :            : /* Return the SPA message data.
     103                 :            : */
     104                 :            : int
     105                 :        449 : fko_get_spa_nat_access(fko_ctx_t ctx, char **nat_access)
     106                 :            : {
     107                 :            : 
     108                 :            : #if HAVE_LIBFIU
     109                 :            :     fiu_return_on("fko_get_spa_nat_access_init", FKO_ERROR_CTX_NOT_INITIALIZED);
     110                 :            : #endif
     111                 :            : 
     112                 :            :     /* Must be initialized
     113                 :            :     */
     114 [ +  - ][ +  - ]:        449 :     if(!CTX_INITIALIZED(ctx))
     115                 :            :         return(FKO_ERROR_CTX_NOT_INITIALIZED);
     116                 :            : 
     117         [ +  - ]:        449 :     if(nat_access == NULL)
     118                 :            :         return(FKO_ERROR_INVALID_DATA);
     119                 :            : 
     120                 :            : #if HAVE_LIBFIU
     121                 :            :     fiu_return_on("fko_get_spa_nat_access_val", FKO_ERROR_INVALID_DATA);
     122                 :            : #endif
     123                 :            : 
     124                 :        449 :     *nat_access = ctx->nat_access;
     125                 :            : 
     126                 :        449 :     return(FKO_SUCCESS);
     127                 :            : }
     128                 :            : 
     129                 :            : /***EOF***/

Generated by: LCOV version 1.10