1 marek 1.1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 marek 1.1 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Config.h>
33 #include "SubscriptionKey.h"
34
35 PEGASUS_USING_PEGASUS;
36
37 PEGASUS_NAMESPACE_BEGIN
38
39
40 SubscriptionKey::SubscriptionKey(
41 const CIMObjectPath & subscription)
42 {
43 marek 1.1 //
44 // Get filter and handler object paths from subscription Filter and Handler
45 // reference property values
46 //
47 Array<CIMKeyBinding> subscriptionKB = subscription.getKeyBindings ();
48
49 subscriptionNamespace=subscription.getNameSpace().getString();
50 subscriptionClassName=subscription.getClassName().getString();
51
52 SubscriptionKey::_parseObjectName(
53 subscriptionKB[0].getValue(),
54 filterName,
55 filterNamespace,
56 filterClassName);
57
58 SubscriptionKey::_parseObjectName(
59 subscriptionKB[1].getValue(),
60 handlerName,
61 handlerNamespace,
62 handlerClassName);
63
64 marek 1.1 if (String::equalNoCase(filterNamespace,subscriptionNamespace))
65 {
66 filterNamespace.clear();
67 }
68 if (String::equalNoCase(handlerNamespace,subscriptionNamespace))
69 {
70 handlerNamespace.clear();
71 }
72 }
73
74 String SubscriptionKey::toString() const
75 {
76 String str;
77 str.reserveCapacity(200);
78 str.append(subscriptionNamespace);
79 str.append(":");
80 str.append(subscriptionClassName);
81
82 str.append(";Filter=");
83 str.append(filterNamespace);
84 str.append(":");
85 marek 1.1 str.append(filterClassName);
86 str.append(".Name=\"");
87 str.append(filterName);
88 str.append("\"");
89
90 str.append(";Handler=");
91 str.append(handlerNamespace);
92 str.append(":");
93 str.append(handlerClassName);
94 str.append(".Name=\"");
95 str.append(handlerName);
96 str.append("\"");
97
98 return str;
99 };
100
101 void SubscriptionKey::_parseObjectName(
102 const String & objectName,
103 String & name,
104 String & ns,
105 String & className)
106 marek 1.1 {
107 static const Char16 slash = 0x002F;
108 static const Char16 dot = 0x002E;
109 static const Char16 quote = 0x0022;
110 static const Char16 colon = 0x003A;
111 static const Char16 equal = 0x003D;
112
113 String x=objectName;
114 Uint32 nsStart=0;
115 Uint32 cnStart=0;
116
117 // check for hostname, don't need it
118 if (x[0] == slash && x[1] == slash)
119 {
120 // namespace starts after next slash
121 nsStart = x.find(2, slash);
122 }
123 // namespace ends at a colon
124 Uint32 nsEnd = x.find(nsStart,colon);
125 if (PEG_NOT_FOUND != nsEnd)
126 {
127 marek 1.1 // ignore slash in front of namespace if existing
128 if (x[nsStart] == slash)
129 {
130 nsStart++;
131 }
132 // the colon needs be before the dot starting the keybindings,
133 // else there is no namespace
134 if (nsEnd < x.find(nsStart,dot))
135 {
136 ns=objectName.subString(nsStart,nsEnd-nsStart);
137 cnStart=nsEnd+1;
138 }
139 }
140
141 // Next is class name which is ending at a dot
142 Uint32 classNameEnd = x.find(cnStart, dot);
143 className = x.subString(cnStart,classNameEnd-cnStart);
144
145 Uint32 keyNameStart=classNameEnd+1;
146 // Name keybinding always is second in list because order is:
147 // CreationClassName=,Name=,SystemCreationClassName=,SystemName=
148 marek 1.1 Uint32 keyNameEnd=x.find(keyNameStart,equal);
149 keyNameEnd=x.find(keyNameEnd+1,equal);
150
151 Uint32 valueStart=keyNameEnd+2; // one step forward + jump over quote
152 Uint32 valueEnd=x.find(valueStart,quote);
153
154 name = x.subString(valueStart,valueEnd-valueStart);
155 }
156
157 Boolean SubscriptionKeyEqualFunc::equal(
158 const SubscriptionKey& x,
159 const SubscriptionKey& y)
160 {
161 if (x.filterName != y.filterName)
162 {
163 return false;
164 }
165 if (x.handlerName != y.handlerName)
166 {
167 return false;
168 }
169 marek 1.1 if (!String::equalNoCase(x.subscriptionNamespace,y.subscriptionNamespace))
170 {
171 return false;
172 }
173 if (!String::equalNoCase(x.filterNamespace,y.filterNamespace))
174 {
175 return false;
176 }
177 if (!String::equalNoCase(x.handlerNamespace,y.handlerNamespace))
178 {
179 return false;
180 }
181 if (!String::equalNoCase(x.subscriptionClassName,y.subscriptionClassName))
182 {
183 return false;
184 }
185 if (!String::equalNoCase(x.filterClassName,y.filterClassName))
186 {
187 return false;
188 }
189 if (!String::equalNoCase(x.handlerClassName,y.handlerClassName))
190 marek 1.1 {
191 return false;
192 }
193 return true;
194 };
195
196 inline Uint32 generateHash(const String& str)
197 {
198 Uint32 h = 0;
199 const Uint16* p = reinterpret_cast<const Uint16*> (str.getChar16Data());
200 Uint32 n = str.size();
201
202 while (n--)
203 {
204 h = 5 * h + *p++;
205 }
206 return h;
207 }
208
209 Uint32 SubscriptionKeyHashFunc::hash(const SubscriptionKey& x)
210 {
211 marek 1.1 return generateHash(x.handlerName)+generateHash(x.filterName);
212 };
213
|