LCOV - code coverage report
Current view: top level - src/utils - ext_password_test.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 32 36 88.9 %
Date: 2014-03-02 Functions: 3 3 100.0 %
Branches: 14 22 63.6 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * External password backend
       3                 :            :  * Copyright (c) 2012, Jouni Malinen <j@w1.fi>
       4                 :            :  *
       5                 :            :  * This software may be distributed under the terms of the BSD license.
       6                 :            :  * See README for more details.
       7                 :            :  */
       8                 :            : 
       9                 :            : #include "includes.h"
      10                 :            : 
      11                 :            : #include "common.h"
      12                 :            : #include "ext_password_i.h"
      13                 :            : 
      14                 :            : 
      15                 :            : struct ext_password_test_data {
      16                 :            :         char *params;
      17                 :            : };
      18                 :            : 
      19                 :            : 
      20                 :          3 : static void * ext_password_test_init(const char *params)
      21                 :            : {
      22                 :            :         struct ext_password_test_data *data;
      23                 :            : 
      24                 :          3 :         data = os_zalloc(sizeof(*data));
      25         [ -  + ]:          3 :         if (data == NULL)
      26                 :          0 :                 return NULL;
      27                 :            : 
      28         [ +  - ]:          3 :         if (params)
      29                 :          3 :                 data->params = os_strdup(params);
      30                 :            : 
      31                 :          3 :         return data;
      32                 :            : }
      33                 :            : 
      34                 :            : 
      35                 :          3 : static void ext_password_test_deinit(void *ctx)
      36                 :            : {
      37                 :          3 :         struct ext_password_test_data *data = ctx;
      38                 :            : 
      39                 :          3 :         os_free(data->params);
      40                 :          3 :         os_free(data);
      41                 :          3 : }
      42                 :            : 
      43                 :            : 
      44                 :          7 : static struct wpabuf * ext_password_test_get(void *ctx, const char *name)
      45                 :            : {
      46                 :          7 :         struct ext_password_test_data *data = ctx;
      47                 :            :         char *pos, *pos2;
      48                 :            :         size_t nlen;
      49                 :            : 
      50                 :          7 :         wpa_printf(MSG_DEBUG, "EXT PW TEST: get(%s)", name);
      51                 :            : 
      52                 :          7 :         pos = data->params;
      53         [ -  + ]:          7 :         if (pos == NULL)
      54                 :          0 :                 return NULL;
      55                 :          7 :         nlen = os_strlen(name);
      56                 :            : 
      57 [ +  - ][ +  - ]:         11 :         while (pos && *pos) {
      58 [ +  + ][ +  - ]:         11 :                 if (os_strncmp(pos, name, nlen) == 0 && pos[nlen] == '=') {
      59                 :            :                         struct wpabuf *buf;
      60                 :          7 :                         pos += nlen + 1;
      61                 :          7 :                         pos2 = pos;
      62 [ +  + ][ +  + ]:         63 :                         while (*pos2 != '|' && *pos2 != '\0')
      63                 :         56 :                                 pos2++;
      64                 :          7 :                         buf = ext_password_alloc(pos2 - pos);
      65         [ -  + ]:          7 :                         if (buf == NULL)
      66                 :          0 :                                 return NULL;
      67                 :          7 :                         wpabuf_put_data(buf, pos, pos2 - pos);
      68                 :          7 :                         wpa_hexdump_ascii_key(MSG_DEBUG, "EXT PW TEST: value",
      69                 :            :                                               wpabuf_head(buf),
      70                 :            :                                               wpabuf_len(buf));
      71                 :          7 :                         return buf;
      72                 :            :                 }
      73                 :            : 
      74                 :          4 :                 pos = os_strchr(pos + 1, '|');
      75         [ +  - ]:          4 :                 if (pos)
      76                 :          4 :                         pos++;
      77                 :            :         }
      78                 :            : 
      79                 :          0 :         wpa_printf(MSG_DEBUG, "EXT PW TEST: get(%s) - not found", name);
      80                 :            : 
      81                 :          7 :         return NULL;
      82                 :            : }
      83                 :            : 
      84                 :            : 
      85                 :            : const struct ext_password_backend ext_password_test = {
      86                 :            :         .name = "test",
      87                 :            :         .init = ext_password_test_init,
      88                 :            :         .deinit = ext_password_test_deinit,
      89                 :            :         .get = ext_password_test_get,
      90                 :            : };

Generated by: LCOV version 1.9