dtcm: Resolve CID 87822
[oweals/cde.git] / cde / programs / dtcm / server / cmsmatch.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: cmsmatch.c /main/4 1995/11/09 12:42:30 rswiston $ */
24 /*
25  *  (c) Copyright 1993, 1994 Hewlett-Packard Company
26  *  (c) Copyright 1993, 1994 International Business Machines Corp.
27  *  (c) Copyright 1993, 1994 Novell, Inc.
28  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
29  */
30
31 #include <EUSCompat.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include "cmsmatch.h"
36 #include "iso8601.h"
37 #include "misc.h"
38 #include "match.h"
39
40 /******************************************************************************
41  * forward declaration of static functions used within the file
42  ******************************************************************************/
43
44 static boolean_t _MatchOneAttribute(cms_attribute eattr, cms_attribute mattr,
45                         int op);
46
47 /*****************************************************************************
48  * extern functions
49  *****************************************************************************/
50
51 extern boolean_t
52 _DtCmsMatchAttributes(
53         cms_entry *entry,
54         uint num_attrs,
55         cms_attribute *attrs,
56         CSA_enum *ops)
57 {
58         int             i;
59
60         for (i = 0; i < num_attrs; i++) {
61                 if (attrs[i].name.num > entry->num_attrs)
62                         return (B_FALSE);
63
64                 if (_MatchOneAttribute(entry->attrs[attrs[i].name.num],
65                     attrs[i], (ops ? ops[i] : CSA_MATCH_EQUAL_TO)) == B_FALSE)
66                         return (B_FALSE);
67         }
68         return (B_TRUE);
69 }
70
71 /*****************************************************************************
72  * static functions used within the file
73  *****************************************************************************/
74
75 static boolean_t
76 _MatchOneAttribute(cms_attribute eattr, cms_attribute mattr, int op)
77 {
78         if (eattr.value == NULL) {
79                 if (op == CSA_MATCH_EQUAL_TO && mattr.value == NULL)
80                         return (B_TRUE);
81                 else
82                         return (B_FALSE);
83         }
84
85         switch (eattr.value->type) {
86         case CSA_VALUE_ENUMERATED:
87         case CSA_VALUE_SINT32:
88                 return (_DtCm_match_sint32_attribute(eattr.value, mattr.value,
89                         op));
90
91         case CSA_VALUE_BOOLEAN:
92         case CSA_VALUE_FLAGS:
93         case CSA_VALUE_UINT32:
94                 return (_DtCm_match_uint32_attribute(eattr.value, mattr.value,
95                         op));
96
97         case CSA_VALUE_STRING:
98         case CSA_VALUE_CALENDAR_USER:
99         case CSA_VALUE_DATE_TIME_RANGE:
100                 return (_DtCm_match_string_attribute(eattr.value, mattr.value,
101                         op));
102
103         case CSA_VALUE_DATE_TIME:
104                 return (_DtCm_match_time_attribute(eattr.value, mattr.value,
105                         op));
106
107         case CSA_VALUE_TIME_DURATION:
108                 return (_DtCm_match_time_duration_attribute(eattr.value,
109                         mattr.value, op));
110
111         case CSA_VALUE_REMINDER:
112                 return (_DtCm_match_reminder_attribute(eattr.value, mattr.value,
113                         op));
114         default:
115                 return (B_FALSE);
116         }
117 }
118