IDZEBRA  2.1.2
attrfind.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <assert.h>
24 
25 #include <attrfind.h>
26 
27 void attr_init_APT(AttrType *src, Z_AttributesPlusTerm *zapt, int type)
28 {
29  src->attributeList = zapt->attributes->attributes;
30  src->num_attributes = zapt->attributes->num_attributes;
31  src->type = type;
32  src->major = 0;
33  src->minor = 0;
34 }
35 
36 void attr_init_AttrList(AttrType *src, Z_AttributeList *list, int type)
37 {
38  src->attributeList = list->attributes;
39  src->num_attributes = list->num_attributes;
40  src->type = type;
41  src->major = 0;
42  src->minor = 0;
43 }
44 
45 int attr_find_ex(AttrType *src, const Odr_oid **attribute_set_oid,
46  const char **string_value)
47 {
48  int num_attributes;
49 
50  num_attributes = src->num_attributes;
51  while (src->major < num_attributes)
52  {
53  Z_AttributeElement *element;
54 
55  element = src->attributeList[src->major];
56  if (src->type == *element->attributeType)
57  {
58  switch (element->which)
59  {
60  case Z_AttributeValue_numeric:
61  ++(src->major);
62  if (element->attributeSet && attribute_set_oid)
63  *attribute_set_oid = element->attributeSet;
64  return *element->value.numeric;
65  break;
66  case Z_AttributeValue_complex:
67  if (src->minor >= element->value.complex->num_list)
68  break;
69  if (element->attributeSet && attribute_set_oid)
70  *attribute_set_oid = element->attributeSet;
71  if (element->value.complex->list[src->minor]->which ==
72  Z_StringOrNumeric_numeric)
73  {
74  ++(src->minor);
75  return
76  *element->value.complex->list[src->minor-1]->u.numeric;
77  }
78  else if (element->value.complex->list[src->minor]->which ==
79  Z_StringOrNumeric_string)
80  {
81  if (!string_value)
82  break;
83  ++(src->minor);
84  *string_value =
85  element->value.complex->list[src->minor-1]->u.string;
86  return -2;
87  }
88  else
89  break;
90  default:
91  assert(0);
92  }
93  }
94  ++(src->major);
95  }
96  return -1;
97 }
98 
99 int attr_find(AttrType *src, const Odr_oid **attribute_set_id)
100 {
101  return attr_find_ex(src, attribute_set_id, 0);
102 }
103 
104 
105 /*
106  * Local variables:
107  * c-basic-offset: 4
108  * c-file-style: "Stroustrup"
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113 
int minor
Definition: attrfind.h:31
int major
Definition: attrfind.h:30
int num_attributes
Definition: attrfind.h:33
void attr_init_APT(AttrType *src, Z_AttributesPlusTerm *zapt, int type)
Definition: attrfind.c:27
Z_AttributeElement ** attributeList
Definition: attrfind.h:32
int attr_find_ex(AttrType *src, const Odr_oid **attribute_set_oid, const char **string_value)
Definition: attrfind.c:45
void attr_init_AttrList(AttrType *src, Z_AttributeList *list, int type)
Definition: attrfind.c:36
int type
Definition: attrfind.h:29
int attr_find(AttrType *src, const Odr_oid **attribute_set_id)
Definition: attrfind.c:99