LCOV - code coverage report
Current view: top level - zxid - zxida7n.c (source / functions) Hit Total Coverage
Test: ZXID Code Coverage Lines: 16 21 76.2 %
Date: 2010-12-19 Functions: 1 1 100.0 %
Branches: 15 54 27.8 %

           Branch data     Line data    Source code
       1                 :            : /* zxida7n.c  -  Handwritten functions for Assertion handling
       2                 :            :  * Copyright (c) 2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.
       3                 :            :  * Copyright (c) 2007-2008 Symlabs (symlabs@symlabs.com), All Rights Reserved.
       4                 :            :  * Author: Sampo Kellomaki (sampo@iki.fi)
       5                 :            :  * This is confidential unpublished proprietary source code of the author.
       6                 :            :  * NO WARRANTY, not even implied warranties. Contains trade secrets.
       7                 :            :  * Distribution prohibited unless authorized in writing.
       8                 :            :  * Licensed under Apache License 2.0, see file COPYING.
       9                 :            :  * $Id: zxida7n.c,v 1.3 2008-10-08 03:56:55 sampo Exp $
      10                 :            :  *
      11                 :            :  * 3.2.2007, created --Sampo
      12                 :            :  * 7.10.2008, added documentation --Sampo
      13                 :            :  *
      14                 :            :  * See also: zxidsimp.c (attributes to LDIF), and zxidepr.c
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <string.h>
      18                 :            : 
      19                 :            : #include "errmac.h"
      20                 :            : #include "zxid.h"
      21                 :            : #include "zxidconf.h"
      22                 :            : #include "saml2.h"
      23                 :            : #include "c/zx-ns.h"
      24                 :            : #include "c/zx-sa-data.h"
      25                 :            : 
      26                 :            : /*() Look into attribute statement(s) of an assertion and scan
      27                 :            :  * for nth occurance of named attribute. Ordering of attributes
      28                 :            :  * is accoring to their occurance in attribute statement, or
      29                 :            :  * more broadly according to ordering of the attribute statements
      30                 :            :  * themselves.
      31                 :            :  *
      32                 :            :  * - NULL or zero length nfmt (name format) will match any
      33                 :            :  * - NULL or zero length name will match any
      34                 :            :  * - NULL or zero length friendly (name) will match any
      35                 :            :  * - minus one (-1) as either length field will cause strlen() to be done
      36                 :            :  * - the index n is one based
      37                 :            :  *
      38                 :            :  * *Arguments*
      39                 :            :  *
      40                 :            :  * a7n:: Assertion data structure, obtained from XML parsing
      41                 :            :  * nfmt_len:: Length of the name format, or 0 if no matching by name format is desired
      42                 :            :  * nfmt:: name format to match (or 0)
      43                 :            :  * name_len:: Length of the attribute name, or 0 if no matching by attribute name is desired
      44                 :            :  * name:: attribute name to match (or 0)
      45                 :            :  * friendly_len:: Length of the friendly name, or 0 if no matching by friendly name is desired
      46                 :            :  * friendly:: friendly name to match (or 0)
      47                 :            :  * n:: Howmanieth instance of the matching attribute is desired. 1 means first.
      48                 :            :  * return:: Data structure representing the matching attribute.
      49                 :            :  */
      50                 :            : 
      51                 :            : struct zx_sa_Attribute_s* zxid_find_attribute(zxid_a7n* a7n, int nfmt_len, char* nfmt, int name_len, char* name, int friendly_len, char* friendly, int n)
      52                 :          1 : {
      53                 :            :   struct zx_sa_Attribute_s* at;
      54                 :            :   struct zx_sa_AttributeStatement_s* as;
      55         [ +  - ]:          1 :   if (!nfmt) { nfmt_len = 0; nfmt = ""; }
      56   [ -  +  #  # ]:          1 :   if (nfmt_len == -1 && nfmt) nfmt_len = strlen(nfmt);
      57         [ +  - ]:          1 :   if (!name) { name_len = 0; name = ""; }
      58   [ -  +  #  # ]:          1 :   if (name_len == -1 && name) name_len = strlen(name);
      59         [ +  - ]:          1 :   if (!friendly) { friendly_len = 0; friendly = ""; }
      60   [ -  +  #  # ]:          1 :   if (friendly_len == -1 && friendly) friendly_len = strlen(friendly);
      61         [ -  + ]:          1 :   if (!a7n) {
      62                 :          0 :     ERR("No assertion supplied (null assertion pointer) when looking for attribute nfmt(%.*s) name(%.*s) friendly(%.*s) n=%d", nfmt_len, nfmt, name_len, name, friendly_len, friendly, n);
      63                 :          0 :     return 0;
      64                 :            :   }
      65                 :          1 :   for (as = a7n->AttributeStatement;
      66   [ +  -  +  - ]:          2 :        as && as->gg.g.tok == zx_sa_AttributeStatement_ELEM;
      67                 :          0 :        as = (struct zx_sa_AttributeStatement_s*)as->gg.g.n)
      68                 :          1 :     for (at = as->Attribute;
      69   [ +  -  +  - ]:          2 :          at && at->gg.g.tok == zx_sa_Attribute_ELEM;
      70                 :          0 :          at = (struct zx_sa_Attribute_s*)at->gg.g.n)
      71   [ -  +  #  #  :          1 :       if ((nfmt_len ? (at->NameFormat
          #  #  #  #  -  
          +  #  #  #  #  
          #  #  -  +  #  
             #  #  #  #  
                      # ]
      72                 :            :                        && at->NameFormat->g.len == nfmt_len
      73                 :            :                        && !memcmp(at->NameFormat->g.s, nfmt, nfmt_len)) : 1)
      74                 :            :           && (name_len ? (at->Name
      75                 :            :                           && at->Name->g.len == name_len
      76                 :            :                           && !memcmp(at->Name->g.s, name, name_len)) : 1)
      77                 :            :           && (friendly_len ? (at->FriendlyName
      78                 :            :                               && at->FriendlyName->g.len == friendly_len
      79                 :            :                               && !memcmp(at->FriendlyName->g.s, friendly, friendly_len)) : 1)) {
      80                 :          1 :         --n;
      81         [ +  - ]:          1 :         if (!n)
      82                 :          1 :           return at;
      83                 :            :       }
      84                 :          0 :   return 0;
      85                 :            : }
      86                 :            : 
      87                 :            : /* EOF  --  zxida7n.c */

Generated by: LCOV version 1.9