2 //%LICENSE////////////////////////////////////////////////////////////////
4 // Licensed to The Open Group (TOG) under one or more contributor license
5 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
6 // this work for additional information regarding copyright ownership.
7 // Each contributor licenses this file to you under the OpenPegasus Open
8 // Source License; you may not use this file except in compliance with the
11 // Permission is hereby granted, free of charge, to any person obtaining a
12 // copy of this software and associated documentation files (the "Software"),
13 // to deal in the Software without restriction, including without limitation
14 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 // and/or sell copies of the Software, and to permit persons to whom the
16 // Software is furnished to do so, subject to the following conditions:
18 // The above copyright notice and this permission notice shall be included
19 // in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //////////////////////////////////////////////////////////////////////////
32 /*****************************************************************************
33 * Description: encode/decode attribute urls
35 * Originated: February 25, 2000
36 * Original Author: Mike Day md@soft-hackle.net
39 * Copyright (c) 2001 - 2003 IBM
40 * Copyright (c) 2000 - 2003 Michael Day
42 * Permission is hereby granted, free of charge, to any person obtaining a
43 * copy of this software and associated documentation files (the "Software"),
44 * to deal in the Software without restriction, including without limitation
45 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
46 * and/or sell copies of the Software, and to permit persons to whom the
47 * Software is furnished to do so, subject to the following conditions:
49 * The above copyright notice and this permission notice shall be included in
50 * all copies or substantial portions of the Software.
53 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
56 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
58 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
59 * DEALINGS IN THE SOFTWARE.
61 *****************************************************************************/
67 #define YY_NEVER_INTERACTIVE 1
69 #define YY_INPUT(b, r, m) abort()
70 #define exit(i) abort()
71 #include "slp_client.h"
75 #define urlless yyless
76 void urlerror(const char *, ...);
78 static int16 heapIndex;
81 /* special counter to exit the appletalk state */
84 static char *_lslp_strdup(const char *s);
85 void url_close_lexer(size_t handle);
86 size_t url_init_lexer(const char *s);
98 escaped ("%"{hex}{2} | "\\"{hex}{2})
100 unreserved ({alphanum}|{mark})
101 reserved [;/?:@&=+$,]
102 uric ({reserved} | {unreserved} | {escaped})
104 /* IPv6 definitions */
106 hexseq {hex4}|{hex4}(":"{hex4})*
107 hexpart {hexseq}|{hexseq}"::"({hexseq})*|"::"({hexseq})*
108 ip6prefix {hexpart}"/"{1}{digit}{2}
109 ip4addr ({digit}{1,3})"."({digit}{1,3})"."({digit}{1,3})"."({digit}{1,3})
110 ip6addr {hexpart}|{hexpart}":"{ip4addr}
118 %option noyywrap prefix="url"
121 /* the ip user @ host syntax is a special state because some reserved */
122 /* characters are valid - but user the string itself is optional so we can't */
123 /* build it into a full-time rule */
129 /* return the slash as a token */
130 <IP_SITE>"/" {urllval._i = *urltext; return(urllval._i);}
132 /* this next rule needs to kick in even if it matches a zero-length string */
133 /* i.e., it needs to be guaranteed even if there is no user @ host production */
134 <IP_SITE>[-_.!~*'()a-zA-Z0-9;+&=\%]*|"["{ip6addr}"]" {
138 if(NULL != (urllval._s = _lslp_strdup(urltext)))
145 /* appletalk syntax includes three reserved characters - give the lexer a chance */
146 /* to match an appletalk production before it starts returning reserved */
147 /* chars as tokens. */
149 "/"[aA]{1}[tT]{1}"/" {
151 if(NULL != (urllval._s = _lslp_strdup(urltext)))
157 <AT_SITE>(([-a-zA-Z0-9$_.~])|("%"([a-fA-F0-9]{2,2}))){1,31} {
159 if (atalk_state == 3)
161 if(NULL != (urllval._s = _lslp_strdup(urltext)))
167 <AT_SITE>":" {urllval._i = *urltext; return(urllval._i);}
168 <AT_SITE>"/" {BEGIN INITIAL; urlless(0);}
170 /* ipx syntax includes two reserved characters - give the lexer a chance */
171 /* to match an ipx production before it starts returning reserved chars */
174 "/"[iI]{1}[pP]{1}[xX]{1}"/"({hex}{8})":"({hex}{12})":"({hex}{4}) {
175 if(NULL != (urllval._s = _lslp_strdup(urltext)))
181 /* reserved characters - always a token in normal state unless part of */
182 /* one of the productions above */
183 ";" {BEGIN ATTRIBUTE; urllval._i = *urltext; return(urllval._i);}
184 "/" {urllval._i = *urltext; return(urllval._i);}
185 "?" {urllval._i = *urltext; return(urllval._i);}
186 ":" {urllval._i = *urltext; return(urllval._i);}
187 "@" {urllval._i = *urltext; return(urllval._i);}
188 "&" {urllval._i = *urltext; return(urllval._i);}
189 "=" {urllval._i = *urltext; return(urllval._i);}
190 "+" {urllval._i = *urltext; return(urllval._i);}
191 "$" {urllval._i = *urltext; return(urllval._i);}
192 "," {urllval._i = *urltext; return(urllval._i);}
194 /* a string consisting of only hex digits */
196 if(NULL != (urllval._s = _lslp_strdup(urltext)))
202 /* an ipv4 address */
203 ({hex}{1,3})"."({hex}{1,3})"."({hex}{1,3})"."({hex}{1,3})|"["{ip6addr}"]" {
204 if(NULL != (urllval._s = _lslp_strdup(urltext)))
210 /* resource names start with alpha and include alphanum and '+' or '-' */
211 /* but '+' is reserved and must be escaped */
213 if(NULL != (urllval._s = _lslp_strdup(urltext)))
220 /* anything else that is not reserved */
223 if(NULL != (urllval._s = _lslp_strdup(urltext)))
229 /* anything else that is not reserved */
231 if(NULL != (urllval._s = _lslp_strdup(urltext)))
237 /* anything else is an error */
241 static char *_lslp_strdup(const char *s)
243 char *p = &heap[heapIndex];
245 while ((heap[heapIndex++] = *s++))
250 void url_close_lexer(size_t handle)
252 PEGASUS_ASSERT(handle);
254 PEGASUS_ASSERT(heap);
255 url_delete_buffer((YY_BUFFER_STATE)handle);
261 size_t url_init_lexer(const char *s)
263 size_t len = strlen(s) + 2;
265 if (!(heap = (char*)malloc(len)))
269 if (!(buf = (char*)malloc(len)))
278 return ((size_t) url_scan_buffer(buf, len));
281 void urlerror(const char *s, ...)