Commit 5df8b25a 5df8b25aa71abb5a6dd087132ee417911c2d6f0a by Sam Roberts

url_is_ticket() - new function, determines whether a url_t contains

ticket information for another url
1 parent 2ee171e8
...@@ -58,6 +58,8 @@ extern int url_is_same_port __P ((url_t, url_t)); ...@@ -58,6 +58,8 @@ extern int url_is_same_port __P ((url_t, url_t));
58 58
59 extern char* url_decode __P ((const char *s)); 59 extern char* url_decode __P ((const char *s));
60 60
61 extern int url_is_ticket __P ((url_t ticket, url_t url));
62
61 #ifdef __cplusplus 63 #ifdef __cplusplus
62 } 64 }
63 #endif 65 #endif
......
...@@ -97,47 +97,6 @@ url_destroy (url_t *purl) ...@@ -97,47 +97,6 @@ url_destroy (url_t *purl)
97 } 97 }
98 } 98 }
99 99
100 /* From RFC 1738, section 2.2 */
101 char *
102 url_decode (const char *s)
103 {
104 char *d = strdup (s);
105 const char *eos = s + strlen (s);
106 int i;
107
108 if (!d)
109 return NULL;
110
111 for (i = 0; s < eos; i++)
112 {
113 if (*s != '%')
114 {
115 d[i] = *s;
116 s++;
117 }
118 else
119 {
120 unsigned long ul = 0;
121
122 s++;
123
124 /* don't check return value, it's correctly coded, or it's not,
125 in which case we just skip the garbage, this is a decoder,
126 not an AI project */
127
128 mu_hexstr2ul (&ul, s, 2);
129
130 s += 2;
131
132 d[i] = (char) ul;
133 }
134 }
135
136 d[i] = 0;
137
138 return d;
139 }
140
141 int 100 int
142 url_parse (url_t url) 101 url_parse (url_t url)
143 { 102 {
...@@ -512,7 +471,7 @@ url_is_same_user (url_t url1, url_t url2) ...@@ -512,7 +471,7 @@ url_is_same_user (url_t url1, url_t url2)
512 if (s2) 471 if (s2)
513 { 472 {
514 url_get_user (url2, s2, j + 1, NULL); 473 url_get_user (url2, s2, j + 1, NULL);
515 ret = !strcasecmp (s1, s2); 474 ret = !strcmp (s1, s2);
516 free (s2); 475 free (s2);
517 } 476 }
518 free (s1); 477 free (s1);
...@@ -537,7 +496,7 @@ url_is_same_path (url_t url1, url_t url2) ...@@ -537,7 +496,7 @@ url_is_same_path (url_t url1, url_t url2)
537 if (s2) 496 if (s2)
538 { 497 {
539 url_get_path (url2, s2, j + 1, NULL); 498 url_get_path (url2, s2, j + 1, NULL);
540 ret = !strcasecmp (s1, s2); 499 ret = !strcmp (s1, s2);
541 free (s2); 500 free (s2);
542 } 501 }
543 free (s1); 502 free (s1);
...@@ -579,3 +538,86 @@ url_is_same_port (url_t url1, url_t url2) ...@@ -579,3 +538,86 @@ url_is_same_port (url_t url1, url_t url2)
579 url_get_port (url2, &p2); 538 url_get_port (url2, &p2);
580 return (p1 == p2); 539 return (p1 == p2);
581 } 540 }
541
542 /* From RFC 1738, section 2.2 */
543 char *
544 url_decode (const char *s)
545 {
546 char *d = strdup (s);
547 const char *eos = s + strlen (s);
548 int i;
549
550 if (!d)
551 return NULL;
552
553 for (i = 0; s < eos; i++)
554 {
555 if (*s != '%')
556 {
557 d[i] = *s;
558 s++;
559 }
560 else
561 {
562 unsigned long ul = 0;
563
564 s++;
565
566 /* don't check return value, it's correctly coded, or it's not,
567 in which case we just skip the garbage, this is a decoder,
568 not an AI project */
569
570 mu_hexstr2ul (&ul, s, 2);
571
572 s += 2;
573
574 d[i] = (char) ul;
575 }
576 }
577
578 d[i] = 0;
579
580 return d;
581 }
582
583 static int defined(const char* s)
584 {
585 if(s && strcmp("*", s) != 0)
586 return 1;
587 return 0;
588 }
589
590 int
591 url_is_ticket (url_t ticket, url_t url)
592 {
593 if(!ticket || !url)
594 return 0;
595
596 /* If ticket has a scheme, host, port, or path, then the queries
597 equivalent must be defined and match. */
598 if(defined(ticket->scheme))
599 {
600 if(!url->scheme || strcasecmp(ticket->scheme, url->scheme) != 0)
601 return 0;
602 }
603 if(defined(ticket->host))
604 {
605 if(!url->host || strcasecmp(ticket->host, url->host) != 0)
606 return 0;
607 }
608 if(ticket->port && ticket->port != url->port)
609 return 0;
610 /* If ticket has a user or pass, but url doesn't thats OK, were
611 urling for this info. But if url does have a user/pass, it
612 must match the ticket. */
613 if(url->user)
614 {
615 if(defined(ticket->user) && strcmp(ticket->user, url->user) != 0)
616 return 0;
617 }
618
619 /* Guess it matches. */
620 return 1;
621 }
622
623
......