/src/uriparser/src/UriCompare.c
Line | Count | Source |
1 | | /* |
2 | | * uriparser - RFC 3986 URI parsing library |
3 | | * |
4 | | * Copyright (C) 2007, Weijia Song <songweijia@gmail.com> |
5 | | * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org> |
6 | | * All rights reserved. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions |
10 | | * are met: |
11 | | * |
12 | | * 1. Redistributions of source code must retain the above |
13 | | * copyright notice, this list of conditions and the following |
14 | | * disclaimer. |
15 | | * |
16 | | * 2. Redistributions in binary form must reproduce the above |
17 | | * copyright notice, this list of conditions and the following |
18 | | * disclaimer in the documentation and/or other materials |
19 | | * provided with the distribution. |
20 | | * |
21 | | * 3. Neither the name of the copyright holder nor the names of |
22 | | * its contributors may be used to endorse or promote products |
23 | | * derived from this software without specific prior written |
24 | | * permission. |
25 | | * |
26 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
27 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
28 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
29 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
30 | | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
31 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
32 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
33 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
34 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
35 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
37 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | */ |
39 | | |
40 | | /* What encodings are enabled? */ |
41 | | #include <uriparser/UriDefsConfig.h> |
42 | | #if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE)) |
43 | | /* Include SELF twice */ |
44 | | # ifdef URI_ENABLE_ANSI |
45 | | # define URI_PASS_ANSI 1 |
46 | | # include "UriCompare.c" |
47 | | # undef URI_PASS_ANSI |
48 | | # endif |
49 | | # ifdef URI_ENABLE_UNICODE |
50 | | # define URI_PASS_UNICODE 1 |
51 | | # include "UriCompare.c" |
52 | | # undef URI_PASS_UNICODE |
53 | | # endif |
54 | | #else |
55 | | # ifdef URI_PASS_ANSI |
56 | | # include <uriparser/UriDefsAnsi.h> |
57 | | # else |
58 | | # include <uriparser/UriDefsUnicode.h> |
59 | | # include <wchar.h> |
60 | | # endif |
61 | | |
62 | | # ifndef URI_DOXYGEN |
63 | | # include <uriparser/Uri.h> |
64 | | # include <uriparser/UriIp4.h> |
65 | | # include "UriCommon.h" |
66 | | # endif |
67 | | |
68 | 5.78k | UriBool URI_FUNC(EqualsUri)(const URI_TYPE(Uri) * a, const URI_TYPE(Uri) * b) { |
69 | | /* NOTE: Both NULL means equal! */ |
70 | 5.78k | if ((a == NULL) || (b == NULL)) { |
71 | 0 | return ((a == NULL) && (b == NULL)) ? URI_TRUE : URI_FALSE; |
72 | 0 | } |
73 | | |
74 | | /* scheme */ |
75 | 5.78k | if (!URI_FUNC(RangeEquals)(&(a->scheme), &(b->scheme))) { |
76 | 465 | return URI_FALSE; |
77 | 465 | } |
78 | | |
79 | | /* absolutePath -- not meaningful for URIs with a host set! */ |
80 | 5.32k | if (!URI_FUNC(HasHost)(a) && (a->absolutePath != b->absolutePath)) { |
81 | 610 | return URI_FALSE; |
82 | 610 | } |
83 | | |
84 | | /* userInfo */ |
85 | 4.71k | if (!URI_FUNC(RangeEquals)(&(a->userInfo), &(b->userInfo))) { |
86 | 648 | return URI_FALSE; |
87 | 648 | } |
88 | | |
89 | | /* Host */ |
90 | 4.06k | if (((a->hostData.ip4 == NULL) != (b->hostData.ip4 == NULL)) |
91 | 4.04k | || ((a->hostData.ip6 == NULL) != (b->hostData.ip6 == NULL)) |
92 | 4.00k | || ((a->hostData.ipFuture.first == NULL) |
93 | 4.00k | != (b->hostData.ipFuture.first == NULL))) { |
94 | 168 | return URI_FALSE; |
95 | 168 | } |
96 | | |
97 | 3.89k | if (a->hostData.ip4 != NULL) { |
98 | 14 | if (memcmp(a->hostData.ip4->data, b->hostData.ip4->data, 4)) { |
99 | 11 | return URI_FALSE; |
100 | 11 | } |
101 | 14 | } |
102 | | |
103 | 3.88k | if (a->hostData.ip6 != NULL) { |
104 | 121 | if (memcmp(a->hostData.ip6->data, b->hostData.ip6->data, 16)) { |
105 | 113 | return URI_FALSE; |
106 | 113 | } |
107 | 121 | } |
108 | | |
109 | 3.77k | if (a->hostData.ipFuture.first != NULL) { |
110 | 4 | if (!URI_FUNC(RangeEquals)(&(a->hostData.ipFuture), &(b->hostData.ipFuture))) { |
111 | 2 | return URI_FALSE; |
112 | 2 | } |
113 | 4 | } |
114 | | |
115 | 3.76k | if ((a->hostData.ip4 == NULL) && (a->hostData.ip6 == NULL) |
116 | 3.75k | && (a->hostData.ipFuture.first == NULL)) { |
117 | 3.75k | if (!URI_FUNC(RangeEquals)(&(a->hostText), &(b->hostText))) { |
118 | 757 | return URI_FALSE; |
119 | 757 | } |
120 | 3.75k | } |
121 | | |
122 | | /* portText */ |
123 | 3.01k | if (!URI_FUNC(RangeEquals)(&(a->portText), &(b->portText))) { |
124 | 4 | return URI_FALSE; |
125 | 4 | } |
126 | | |
127 | | /* Path */ |
128 | 3.00k | if ((a->pathHead == NULL) != (b->pathHead == NULL)) { |
129 | 1.76k | return URI_FALSE; |
130 | 1.76k | } |
131 | | |
132 | 1.24k | if (a->pathHead != NULL) { |
133 | 515 | URI_TYPE(PathSegment) * walkA = a->pathHead; |
134 | 515 | URI_TYPE(PathSegment) * walkB = b->pathHead; |
135 | 1.11k | do { |
136 | 1.11k | if (!URI_FUNC(RangeEquals)(&(walkA->text), &(walkB->text))) { |
137 | 219 | return URI_FALSE; |
138 | 219 | } |
139 | 894 | if ((walkA->next == NULL) != (walkB->next == NULL)) { |
140 | 14 | return URI_FALSE; |
141 | 14 | } |
142 | 880 | walkA = walkA->next; |
143 | 880 | walkB = walkB->next; |
144 | 880 | } while (walkA != NULL); |
145 | 515 | } |
146 | | |
147 | | /* query */ |
148 | 1.00k | if (!URI_FUNC(RangeEquals)(&(a->query), &(b->query))) { |
149 | 385 | return URI_FALSE; |
150 | 385 | } |
151 | | |
152 | | /* fragment */ |
153 | 622 | if (!URI_FUNC(RangeEquals)(&(a->fragment), &(b->fragment))) { |
154 | 221 | return URI_FALSE; |
155 | 221 | } |
156 | | |
157 | 401 | return URI_TRUE; /* Equal*/ |
158 | 622 | } Unexecuted instantiation: uriEqualsUriA Line | Count | Source | 68 | 5.78k | UriBool URI_FUNC(EqualsUri)(const URI_TYPE(Uri) * a, const URI_TYPE(Uri) * b) { | 69 | | /* NOTE: Both NULL means equal! */ | 70 | 5.78k | if ((a == NULL) || (b == NULL)) { | 71 | 0 | return ((a == NULL) && (b == NULL)) ? URI_TRUE : URI_FALSE; | 72 | 0 | } | 73 | | | 74 | | /* scheme */ | 75 | 5.78k | if (!URI_FUNC(RangeEquals)(&(a->scheme), &(b->scheme))) { | 76 | 465 | return URI_FALSE; | 77 | 465 | } | 78 | | | 79 | | /* absolutePath -- not meaningful for URIs with a host set! */ | 80 | 5.32k | if (!URI_FUNC(HasHost)(a) && (a->absolutePath != b->absolutePath)) { | 81 | 610 | return URI_FALSE; | 82 | 610 | } | 83 | | | 84 | | /* userInfo */ | 85 | 4.71k | if (!URI_FUNC(RangeEquals)(&(a->userInfo), &(b->userInfo))) { | 86 | 648 | return URI_FALSE; | 87 | 648 | } | 88 | | | 89 | | /* Host */ | 90 | 4.06k | if (((a->hostData.ip4 == NULL) != (b->hostData.ip4 == NULL)) | 91 | 4.04k | || ((a->hostData.ip6 == NULL) != (b->hostData.ip6 == NULL)) | 92 | 4.00k | || ((a->hostData.ipFuture.first == NULL) | 93 | 4.00k | != (b->hostData.ipFuture.first == NULL))) { | 94 | 168 | return URI_FALSE; | 95 | 168 | } | 96 | | | 97 | 3.89k | if (a->hostData.ip4 != NULL) { | 98 | 14 | if (memcmp(a->hostData.ip4->data, b->hostData.ip4->data, 4)) { | 99 | 11 | return URI_FALSE; | 100 | 11 | } | 101 | 14 | } | 102 | | | 103 | 3.88k | if (a->hostData.ip6 != NULL) { | 104 | 121 | if (memcmp(a->hostData.ip6->data, b->hostData.ip6->data, 16)) { | 105 | 113 | return URI_FALSE; | 106 | 113 | } | 107 | 121 | } | 108 | | | 109 | 3.77k | if (a->hostData.ipFuture.first != NULL) { | 110 | 4 | if (!URI_FUNC(RangeEquals)(&(a->hostData.ipFuture), &(b->hostData.ipFuture))) { | 111 | 2 | return URI_FALSE; | 112 | 2 | } | 113 | 4 | } | 114 | | | 115 | 3.76k | if ((a->hostData.ip4 == NULL) && (a->hostData.ip6 == NULL) | 116 | 3.75k | && (a->hostData.ipFuture.first == NULL)) { | 117 | 3.75k | if (!URI_FUNC(RangeEquals)(&(a->hostText), &(b->hostText))) { | 118 | 757 | return URI_FALSE; | 119 | 757 | } | 120 | 3.75k | } | 121 | | | 122 | | /* portText */ | 123 | 3.01k | if (!URI_FUNC(RangeEquals)(&(a->portText), &(b->portText))) { | 124 | 4 | return URI_FALSE; | 125 | 4 | } | 126 | | | 127 | | /* Path */ | 128 | 3.00k | if ((a->pathHead == NULL) != (b->pathHead == NULL)) { | 129 | 1.76k | return URI_FALSE; | 130 | 1.76k | } | 131 | | | 132 | 1.24k | if (a->pathHead != NULL) { | 133 | 515 | URI_TYPE(PathSegment) * walkA = a->pathHead; | 134 | 515 | URI_TYPE(PathSegment) * walkB = b->pathHead; | 135 | 1.11k | do { | 136 | 1.11k | if (!URI_FUNC(RangeEquals)(&(walkA->text), &(walkB->text))) { | 137 | 219 | return URI_FALSE; | 138 | 219 | } | 139 | 894 | if ((walkA->next == NULL) != (walkB->next == NULL)) { | 140 | 14 | return URI_FALSE; | 141 | 14 | } | 142 | 880 | walkA = walkA->next; | 143 | 880 | walkB = walkB->next; | 144 | 880 | } while (walkA != NULL); | 145 | 515 | } | 146 | | | 147 | | /* query */ | 148 | 1.00k | if (!URI_FUNC(RangeEquals)(&(a->query), &(b->query))) { | 149 | 385 | return URI_FALSE; | 150 | 385 | } | 151 | | | 152 | | /* fragment */ | 153 | 622 | if (!URI_FUNC(RangeEquals)(&(a->fragment), &(b->fragment))) { | 154 | 221 | return URI_FALSE; | 155 | 221 | } | 156 | | | 157 | 401 | return URI_TRUE; /* Equal*/ | 158 | 622 | } |
|
159 | | |
160 | | #endif |