1
/*********************************************************
2
* Copyright (C) 2005 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
24
#include <sys/types.h>
25
#include <netinet/in.h>
32
#include "SLPv2Private.h"
36
*-----------------------------------------------------------------------------
38
* SLPv2MsgParserMatchStringInList -
40
* Returns TRUE if attribute is contained in list, where list
41
* is a comma separated list of attributes.
44
* Returns TRUE upon match.
49
*-----------------------------------------------------------------------------
53
SLPv2MsgParserMatchStringInList(char *list, // IN
54
char *attribute) // IN
61
* If there is no attribute to match against, it's a match.
63
if (NULL == list || NULL == attribute || 0 == strlen(attribute)) {
68
* Look at every attribute in the list that is followed by a comma.
71
end = Str_Strchr(start, ',');
72
length = (NULL != end) ? (end - start) : strlen(start);
75
if (0 == Str_Strncasecmp(start, attribute, length)) {
80
end = Str_Strchr(start, ',');
81
length = (NULL != end) ? (end - start) : strlen(start);
85
* At this point we're at the last item in list.
87
if (0 == Str_Strncasecmp(start, attribute, length)) {
96
*-----------------------------------------------------------------------------
98
* SLPv2MsgParser_ServiceRequestMatch -
100
* Returns TRUE if the packet matches the SLPv2 request parameters
101
* passed to this function.
104
* Returns TRUE upon match.
109
*-----------------------------------------------------------------------------
113
SLPv2MsgParser_ServiceRequestMatch(struct SLPv2_Parse *parse, // IN
114
char *myIpsList, // UN
115
char *myServiceType, // IN
117
char *myPredicate, // IN
120
ASSERT(NULL != parse);
122
if (SLPV2_SERVICEREQUEST != parse->header->functionId) {
127
* TODO: ip address matching.
130
if (! SLPv2MsgParserMatchStringInList(parse->serviceRequest.serviceType,
135
if (! SLPv2MsgParserMatchStringInList(parse->serviceRequest.scope,
140
// TODO: implement LDAPv3 predicate match
143
*xid = Portable_ntohs(parse->header->xid);
151
*-----------------------------------------------------------------------------
153
* SLPv2MsgParser_ServiceReplyMatch -
155
* Returns TRUE if the packet matches the SLPv2 parameters
156
* passed to this function.
159
* Returns TRUE upon match.
164
*-----------------------------------------------------------------------------
168
SLPv2MsgParser_ServiceReplyMatch(struct SLPv2_Parse *parse, // IN
169
int *urlCount, // OUT
170
char ***urlArray, // OUT
173
ASSERT(NULL != parse);
175
if (SLPV2_SERVICEREPLY != parse->header->functionId) {
179
if (NULL != urlCount) {
180
*urlCount = parse->serviceReply.urlCount;
183
if (NULL != urlArray) {
185
*urlArray = Util_SafeMalloc(sizeof(char *)*parse->serviceReply.urlCount);
187
for (i = 0; i < parse->serviceReply.urlCount; i++) {
188
*urlArray[i] = Util_SafeStrdup(parse->serviceReply.url[i]);
193
*xid = Portable_ntohs(parse->header->xid);
201
*-----------------------------------------------------------------------------
203
* SLPv2MsgParser_AttributeRequestMatch -
205
* Returns TRUE if the packet matches the SLPv2 request parameters
206
* passed to this function.
209
* Returns TRUE upon match.
214
*-----------------------------------------------------------------------------
218
SLPv2MsgParser_AttributeRequestMatch(struct SLPv2_Parse *parse, // IN
219
char *myIpsList, // UN
225
ASSERT(NULL != parse);
227
if (SLPV2_ATTRIBUTEREQUEST != parse->header->functionId) {
232
* TODO: ip address matching.
235
if ((url != NULL) && (0 != strcmp(url, parse->attributeRequest.url))) {
239
if (! SLPv2MsgParserMatchStringInList(parse->serviceRequest.scope,
245
* TODO: tag list and LDAPv3 predicate matching.
249
*xid = Portable_ntohs(parse->header->xid);
258
*-----------------------------------------------------------------------------
260
* SLPv2MsgParser_AttributeReplyMatch -
262
* Returns TRUE if the packet matches the SLPv2 parameters
263
* passed to this function.
266
* Returns TRUE upon match.
271
*-----------------------------------------------------------------------------
275
SLPv2MsgParser_AttributeReplyMatch(struct SLPv2_Parse *parse, // IN
276
char **attributeList, // OUT
279
ASSERT(NULL != parse);
281
if (SLPV2_ATTRIBUTEREPLY != parse->header->functionId) {
285
if (attributeList != NULL) {
286
*attributeList = Util_SafeStrdup(parse->attributeReply.attributeList);
290
*xid = Portable_ntohs(parse->header->xid);