LCOV - code coverage report
Current view: top level - pulsecore - auth-cookie.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 0 35 0.0 %
Date: 2012-07-17 Functions: 0 4 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 34 0.0 %

           Branch data     Line data    Source code
       1                 :            : /***
       2                 :            :   This file is part of PulseAudio.
       3                 :            : 
       4                 :            :   Copyright 2008 Lennart Poettering
       5                 :            : 
       6                 :            :   PulseAudio is free software; you can redistribute it and/or modify
       7                 :            :   it under the terms of the GNU Lesser General Public License as published
       8                 :            :   by the Free Software Foundation; either version 2.1 of the License,
       9                 :            :   or (at your option) any later version.
      10                 :            : 
      11                 :            :   PulseAudio is distributed in the hope that it will be useful, but
      12                 :            :   WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      14                 :            :   General Public License for more details.
      15                 :            : 
      16                 :            :   You should have received a copy of the GNU Lesser General Public License
      17                 :            :   along with PulseAudio; if not, write to the Free Software
      18                 :            :   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
      19                 :            :   USA.
      20                 :            : ***/
      21                 :            : 
      22                 :            : #ifdef HAVE_CONFIG_H
      23                 :            : #include <config.h>
      24                 :            : #endif
      25                 :            : 
      26                 :            : #include <sys/types.h>
      27                 :            : 
      28                 :            : #include <pulse/xmalloc.h>
      29                 :            : 
      30                 :            : #include <pulsecore/refcnt.h>
      31                 :            : #include <pulsecore/macro.h>
      32                 :            : #include <pulsecore/core-util.h>
      33                 :            : #include <pulsecore/shared.h>
      34                 :            : #include <pulsecore/authkey.h>
      35                 :            : 
      36                 :            : #include "auth-cookie.h"
      37                 :            : 
      38                 :            : struct pa_auth_cookie {
      39                 :            :     PA_REFCNT_DECLARE;
      40                 :            :     pa_core *core;
      41                 :            :     char *name;
      42                 :            :     size_t size;
      43                 :            : };
      44                 :            : 
      45                 :          0 : pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, pa_bool_t create, size_t size) {
      46                 :            :     pa_auth_cookie *c;
      47                 :            :     char *t;
      48                 :            : 
      49         [ #  # ]:          0 :     pa_assert(core);
      50         [ #  # ]:          0 :     pa_assert(size > 0);
      51                 :            : 
      52 [ #  # ][ #  # ]:          0 :     t = pa_sprintf_malloc("auth-cookie%s%s", cn ? "@" : "", cn ? cn : "");
      53                 :            : 
      54         [ #  # ]:          0 :     if ((c = pa_shared_get(core, t))) {
      55                 :            : 
      56                 :          0 :         pa_xfree(t);
      57                 :            : 
      58         [ #  # ]:          0 :         if (c->size != size)
      59                 :            :             return NULL;
      60                 :            : 
      61                 :          0 :         return pa_auth_cookie_ref(c);
      62                 :            :     }
      63                 :            : 
      64                 :          0 :     c = pa_xmalloc(PA_ALIGN(sizeof(pa_auth_cookie)) + size);
      65                 :          0 :     PA_REFCNT_INIT(c);
      66                 :          0 :     c->core = core;
      67                 :          0 :     c->name = t;
      68                 :          0 :     c->size = size;
      69                 :            : 
      70         [ #  # ]:          0 :     pa_assert_se(pa_shared_set(core, t, c) >= 0);
      71                 :            : 
      72         [ #  # ]:          0 :     if (pa_authkey_load_auto(cn, create, (uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie)), size) < 0) {
      73                 :          0 :         pa_auth_cookie_unref(c);
      74                 :          0 :         return NULL;
      75                 :            :     }
      76                 :            : 
      77                 :            :     return c;
      78                 :            : }
      79                 :            : 
      80                 :          0 : pa_auth_cookie* pa_auth_cookie_ref(pa_auth_cookie *c) {
      81         [ #  # ]:          0 :     pa_assert(c);
      82         [ #  # ]:          0 :     pa_assert(PA_REFCNT_VALUE(c) >= 1);
      83                 :            : 
      84                 :          0 :     PA_REFCNT_INC(c);
      85                 :            : 
      86                 :          0 :     return c;
      87                 :            : }
      88                 :            : 
      89                 :          0 : void pa_auth_cookie_unref(pa_auth_cookie *c) {
      90         [ #  # ]:          0 :     pa_assert(c);
      91         [ #  # ]:          0 :     pa_assert(PA_REFCNT_VALUE(c) >= 1);
      92                 :            : 
      93         [ #  # ]:          0 :     if (PA_REFCNT_DEC(c) > 0)
      94                 :          0 :         return;
      95                 :            : 
      96         [ #  # ]:          0 :     pa_assert_se(pa_shared_remove(c->core, c->name) >= 0);
      97                 :            : 
      98                 :          0 :     pa_xfree(c->name);
      99                 :          0 :     pa_xfree(c);
     100                 :            : }
     101                 :            : 
     102                 :          0 : const uint8_t* pa_auth_cookie_read(pa_auth_cookie *c, size_t size) {
     103         [ #  # ]:          0 :     pa_assert(c);
     104         [ #  # ]:          0 :     pa_assert(PA_REFCNT_VALUE(c) >= 1);
     105         [ #  # ]:          0 :     pa_assert(c->size == size);
     106                 :            : 
     107                 :          0 :     return (const uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie));
     108                 :            : }

Generated by: LCOV version 1.9