1 /*****************************************************************************
2 * Description: encode/decode attribute urls
4 * Originated: March 6, 2000
5 * Original Author: Mike Day md@soft-hackle.net
8 * $Header: /cvs/MSB/pegasus/src/Unsupported/slp_client/src/cmd-utils/slp_client/Attic/url.y,v 1.2 2003/06/05 20:39:29 mday Exp $
10 * Copyright (c) 2001 - 2003 IBM
11 * Copyright (c) 2000 - 2003 Michael Day
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 * DEALINGS IN THE SOFTWARE.
32 *****************************************************************************/
38 #include "slp_client.h"
42 /* prototypes and globals go here */
43 void urlerror(int8 *, ...);
47 void url_close_lexer(uint32 handle);
48 uint32 url_init_lexer(int8 *s);
50 lslpAtomizedURL urlHead =
52 &urlHead, &urlHead, TRUE, NULL, 0
55 static lslpAtomList srvcHead = {&srvcHead, &srvcHead, TRUE, NULL, 0};
56 static lslpAtomList siteHead = {&siteHead, &siteHead, TRUE, NULL, 0};
57 static lslpAtomList pathHead = {&pathHead, &pathHead, TRUE, NULL, 0};
58 static lslpAtomList attrHead = {&attrHead, &attrHead, TRUE, NULL, 0};
62 /* definitions for ytab.h */
69 lslpAtomizedURL *_aturl;
73 %token<_s> _HEXDIG _STAG _RESNAME _NAME _ELEMENT _IPADDR _IPX
76 /* typecast the non-terminals */
79 %type <_s> ip_site ipx_site at_site hostport host service_id
81 %type <_atl> service_list service site path_list path_el attr_list attr_el
82 %type <_atl> url_part sap
85 url: service_list sap {
86 if (NULL != ($$ = (lslpAtomizedURL *)calloc(1, sizeof(lslpAtomizedURL))))
89 lslpAtomList *temp = srvcHead.next;
90 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
92 urlLen += strlen(temp->str);
96 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
98 urlLen += strlen(temp->str);
101 temp = pathHead.next;
102 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
104 urlLen += strlen(temp->str) + 1;
107 temp = attrHead.next;
108 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
110 urlLen += strlen(temp->str) + 1;
113 if (NULL != ($$->url = (int8 *)calloc(urlLen, sizeof(int8))))
115 temp = srvcHead.next;
116 if (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
118 strcpy($$->url, temp->str);
121 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
123 strcat($$->url, temp->str);
126 temp = siteHead.next;
127 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
129 strcat($$->url, temp->str);
132 temp = pathHead.next;
133 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
135 strcat($$->url, "/");
136 strcat($$->url, temp->str);
139 temp = attrHead.next;
140 while (! _LSLP_IS_HEAD(temp) && temp->str != NULL)
142 strcat($$->url, ";");
143 strcat($$->url, temp->str);
146 $$->urlHash = lslpCheckSum($$->url, (int16)strlen($$->url));
149 /* make certain the listheads are initialized */
150 $$->srvcs.next = $$->srvcs.prev = &($$->srvcs);
151 $$->srvcs.isHead = TRUE;
152 $$->site.next = $$->site.prev = &($$->site);
153 $$->site.isHead = TRUE;
154 $$->path.next = $$->path.prev = &($$->path);
155 $$->path.isHead = TRUE;
156 $$->attrs.next = $$->attrs.prev = &($$->attrs);
157 $$->attrs.isHead = TRUE;
158 if (! _LSLP_IS_EMPTY(&srvcHead ))
160 _LSLP_LINK_HEAD(&($$->srvcs), &srvcHead);
162 if (! _LSLP_IS_EMPTY(&siteHead))
164 _LSLP_LINK_HEAD(&($$->site), &siteHead);
166 if (! _LSLP_IS_EMPTY(&pathHead))
168 _LSLP_LINK_HEAD(&($$->path), &pathHead);
170 if (! _LSLP_IS_EMPTY(&attrHead))
172 _LSLP_LINK_HEAD(&($$->attrs), &attrHead);
174 _LSLP_INSERT_BEFORE($$, &urlHead);
179 service_list: service {
183 _LSLP_INSERT_BEFORE($1, $$);
187 | service_list service {
191 _LSLP_INSERT_BEFORE($2, $$);
196 service: _RESNAME ':' {
197 if (NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
199 $$->next = $$->prev = $$;
200 if (NULL != ($$->str = (int8 *)calloc(2 + strlen($1), sizeof(int8))))
203 strcat($$->str, ":");
204 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
214 | _RESNAME '.' _RESNAME ':' {
215 if (NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
217 $$->next = $$->prev = $$;
218 if (NULL != ($$->str = (int8 *)calloc(3 + strlen($1) + strlen($3), sizeof(int8))))
221 strcat($$->str, ".");
223 strcat($$->str, ":");
224 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
240 _LSLP_INSERT_BEFORE($1, $$);
247 _LSLP_INSERT_BEFORE($1, $$);
255 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
257 $$->next = $$->prev = $$;
259 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
268 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
270 $$->next = $$->prev = $$;
272 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
281 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
283 $$->next = $$->prev = $$;
285 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
296 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
298 $$->next = $$->prev = $$;
300 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
314 if(NULL != $3 && (NULL !=($$ = (int8 *)calloc(3 + strlen($3), sizeof(int8)))))
321 | '/''/' _RESNAME '@' hostport {
322 if(NULL != $5 && (NULL !=($$ = (int8 *)calloc(4 + strlen($3) + strlen($5), sizeof(int8)))))
332 service_id: _RESNAME {
342 at_site: _AT _ZONE ':' _ZONE ':' _ZONE {
343 if(NULL != ($$ = (int8 *)calloc(strlen($1) + strlen($2) + strlen($4) + strlen($6) + 3, sizeof(int8))))
361 if(NULL != ($$ = (int8 *)calloc(strlen($1) + strlen($3) + 2, sizeof(int8))))
381 url_part: path_list {
387 | path_list attr_list {
396 _LSLP_INSERT_BEFORE($1, $$);
399 | path_list path_el {
403 _LSLP_INSERT_BEFORE($2, $$);
410 /* dangling path slash - do nothing */
414 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
416 $$->prev = $$->next = $$;
417 if(NULL != ($$->str = (int8 *)calloc(1 + strlen($2), sizeof(int8))))
420 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
432 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
434 $$->prev = $$->next = $$;
435 if(NULL != ($$->str = (int8 *)calloc(1 + strlen($2), sizeof(int8))))
438 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
449 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
451 $$->prev = $$->next = $$;
452 if(NULL != ($$->str = (int8 *)calloc(1 + strlen($2), sizeof(int8))))
455 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
470 _LSLP_INSERT_BEFORE($1, $$);
473 | attr_list attr_el {
477 _LSLP_INSERT_BEFORE($2, $$);
482 attr_el: ';' _ELEMENT {
483 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
485 $$->prev = $$->next = $$;
486 if(NULL != ($$->str = (int8 *)calloc(1 + strlen($2), sizeof(int8))))
489 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
499 | ';' _ELEMENT '=' _ELEMENT {
500 if(NULL != ($$ = (lslpAtomList *)calloc(1, sizeof(lslpAtomList))))
502 $$->prev = $$->next = $$;
503 if(NULL != ($$->str = (int8 *)calloc(2 + strlen($2) + strlen($4), sizeof(int8))))
506 strcat($$->str, "=");
508 $$->hash = lslpCheckSum($$->str, (int16)strlen($$->str));
522 lslpAtomList *lslpAllocAtom(void)
524 lslpAtomList *temp = (lslpAtomList *)calloc(1, sizeof(lslpAtomList));
527 temp->next = temp->prev = temp;
532 lslpAtomList *lslpAllocAtomList(void)
534 lslpAtomList *temp =lslpAllocAtom();
540 void lslpFreeAtom(lslpAtomList *a )
549 void lslpFreeAtomList(lslpAtomList *l, int32 flag)
553 assert(_LSLP_IS_HEAD(l));
554 while (! _LSLP_IS_EMPTY(l))
557 temp->prev->next = temp->next;
558 temp->next->prev = temp->prev;
566 lslpAtomizedURL *lslpAllocAtomizedURL(void)
568 lslpAtomizedURL *temp = (lslpAtomizedURL *)calloc(1, sizeof(lslpAtomizedURL));
571 temp->prev = temp->next = temp;
576 lslpAtomizedURL *lslpAllocAtomizedURLList(void)
578 lslpAtomizedURL *temp = lslpAllocAtomizedURL();
586 void lslpFreeAtomizedURL(lslpAtomizedURL *u)
591 if (! _LSLP_IS_EMPTY(&(u->srvcs)))
592 lslpFreeAtomList(&(u->srvcs), 0);
593 if (! _LSLP_IS_EMPTY(&(u->site)))
594 lslpFreeAtomList(&(u->site), 0);
595 if (! _LSLP_IS_EMPTY(&(u->path)))
596 lslpFreeAtomList(&(u->path), 0);
597 if (! _LSLP_IS_EMPTY(&(u->attrs)))
598 lslpFreeAtomList(&(u->attrs), 0);
603 void lslpFreeAtomizedURLList(lslpAtomizedURL *l, int32 flag)
605 lslpAtomizedURL *temp;
607 assert(_LSLP_IS_HEAD(l));
608 while (! (_LSLP_IS_HEAD(l->next)))
611 temp->prev->next = temp->next;
612 temp->next->prev = temp->prev;
613 lslpFreeAtomizedURL(temp);
620 void lslpInitAtomLists(void)
622 srvcHead.next = srvcHead.prev = &srvcHead;
623 siteHead.next = siteHead.prev = &siteHead;
624 pathHead.next = pathHead.prev = &pathHead;
625 attrHead.next = attrHead.prev = &attrHead;
629 void lslpInitURLList(void)
631 urlHead.next = urlHead.prev = &urlHead;
637 void lslpCleanUpURLLists(void)
640 lslpFreeAtomList(&srvcHead, 0);
641 lslpFreeAtomList(&siteHead, 0);
642 lslpFreeAtomList(&pathHead, 0);
643 lslpFreeAtomList(&attrHead, 0);
644 lslpFreeAtomizedURLList(&urlHead, 0);
647 lslpAtomizedURL *_lslpDecodeURLs(int8 *u[], int32 count)
652 lslpAtomizedURL *temp = NULL;
653 assert(u != NULL && u[count - 1] != NULL);
657 for (i = 0; i < count; i++) {
660 if((0 != (lexer = url_init_lexer(u[i])))) {
662 lslpCleanUpURLLists();
663 url_close_lexer(lexer);
666 if (! _LSLP_IS_EMPTY(&urlHead)) {
667 if(NULL != (temp = lslpAllocAtomizedURLList())) {
668 _LSLP_LINK_HEAD(temp, &urlHead);