Coverage Report

Created: 2025-08-28 06:22

/src/uriparser/src/UriCompare.c
Line
Count
Source (jump to first uncovered line)
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
63
64
#ifndef URI_DOXYGEN
65
# include <uriparser/Uri.h>
66
# include <uriparser/UriIp4.h>
67
# include "UriCommon.h"
68
#endif
69
70
71
72
UriBool URI_FUNC(EqualsUri)(const URI_TYPE(Uri) * a,
73
6.86k
    const URI_TYPE(Uri) * b) {
74
  /* NOTE: Both NULL means equal! */
75
6.86k
  if ((a == NULL) || (b == NULL)) {
76
0
    return ((a == NULL) && (b == NULL)) ? URI_TRUE : URI_FALSE;
77
0
  }
78
79
  /* scheme */
80
6.86k
  if (URI_FUNC(CompareRange)(&(a->scheme), &(b->scheme))) {
81
463
    return URI_FALSE;
82
463
  }
83
84
  /* absolutePath */
85
6.39k
  if ((a->scheme.first == NULL)&& (a->absolutePath != b->absolutePath)) {
86
699
    return URI_FALSE;
87
699
  }
88
89
  /* userInfo */
90
5.69k
  if (URI_FUNC(CompareRange)(&(a->userInfo), &(b->userInfo))) {
91
748
    return URI_FALSE;
92
748
  }
93
94
  /* Host */
95
4.95k
  if (((a->hostData.ip4 == NULL) != (b->hostData.ip4 == NULL))
96
4.95k
      || ((a->hostData.ip6 == NULL) != (b->hostData.ip6 == NULL))
97
4.95k
      || ((a->hostData.ipFuture.first == NULL)
98
4.88k
        != (b->hostData.ipFuture.first == NULL))) {
99
175
    return URI_FALSE;
100
175
  }
101
102
4.77k
  if (a->hostData.ip4 != NULL) {
103
5
    if (memcmp(a->hostData.ip4->data, b->hostData.ip4->data, 4)) {
104
4
      return URI_FALSE;
105
4
    }
106
5
  }
107
108
4.77k
  if (a->hostData.ip6 != NULL) {
109
134
    if (memcmp(a->hostData.ip6->data, b->hostData.ip6->data, 16)) {
110
128
      return URI_FALSE;
111
128
    }
112
134
  }
113
114
4.64k
  if (a->hostData.ipFuture.first != NULL) {
115
4
    if (URI_FUNC(CompareRange)(&(a->hostData.ipFuture), &(b->hostData.ipFuture))) {
116
2
      return URI_FALSE;
117
2
    }
118
4
  }
119
120
4.64k
  if ((a->hostData.ip4 == NULL)
121
4.64k
      && (a->hostData.ip6 == NULL)
122
4.64k
      && (a->hostData.ipFuture.first == NULL)) {
123
4.63k
    if (URI_FUNC(CompareRange)(&(a->hostText), &(b->hostText))) {
124
1.22k
      return URI_FALSE;
125
1.22k
    }
126
4.63k
  }
127
128
  /* portText */
129
3.42k
  if (URI_FUNC(CompareRange)(&(a->portText), &(b->portText))) {
130
3
    return URI_FALSE;
131
3
  }
132
133
  /* Path */
134
3.41k
  if ((a->pathHead == NULL) != (b->pathHead == NULL)) {
135
2.02k
    return URI_FALSE;
136
2.02k
  }
137
138
1.38k
  if (a->pathHead != NULL) {
139
526
    URI_TYPE(PathSegment) * walkA = a->pathHead;
140
526
    URI_TYPE(PathSegment) * walkB = b->pathHead;
141
944
    do {
142
944
      if (URI_FUNC(CompareRange)(&(walkA->text), &(walkB->text))) {
143
218
        return URI_FALSE;
144
218
      }
145
726
      if ((walkA->next == NULL) != (walkB->next == NULL)) {
146
13
        return URI_FALSE;
147
13
      }
148
713
      walkA = walkA->next;
149
713
      walkB = walkB->next;
150
713
    } while (walkA != NULL);
151
526
  }
152
153
  /* query */
154
1.15k
  if (URI_FUNC(CompareRange)(&(a->query), &(b->query))) {
155
482
    return URI_FALSE;
156
482
  }
157
158
  /* fragment */
159
676
  if (URI_FUNC(CompareRange)(&(a->fragment), &(b->fragment))) {
160
254
    return URI_FALSE;
161
254
  }
162
163
422
  return URI_TRUE; /* Equal*/
164
676
}
Unexecuted instantiation: uriEqualsUriA
uriEqualsUriW
Line
Count
Source
73
6.86k
    const URI_TYPE(Uri) * b) {
74
  /* NOTE: Both NULL means equal! */
75
6.86k
  if ((a == NULL) || (b == NULL)) {
76
0
    return ((a == NULL) && (b == NULL)) ? URI_TRUE : URI_FALSE;
77
0
  }
78
79
  /* scheme */
80
6.86k
  if (URI_FUNC(CompareRange)(&(a->scheme), &(b->scheme))) {
81
463
    return URI_FALSE;
82
463
  }
83
84
  /* absolutePath */
85
6.39k
  if ((a->scheme.first == NULL)&& (a->absolutePath != b->absolutePath)) {
86
699
    return URI_FALSE;
87
699
  }
88
89
  /* userInfo */
90
5.69k
  if (URI_FUNC(CompareRange)(&(a->userInfo), &(b->userInfo))) {
91
748
    return URI_FALSE;
92
748
  }
93
94
  /* Host */
95
4.95k
  if (((a->hostData.ip4 == NULL) != (b->hostData.ip4 == NULL))
96
4.95k
      || ((a->hostData.ip6 == NULL) != (b->hostData.ip6 == NULL))
97
4.95k
      || ((a->hostData.ipFuture.first == NULL)
98
4.88k
        != (b->hostData.ipFuture.first == NULL))) {
99
175
    return URI_FALSE;
100
175
  }
101
102
4.77k
  if (a->hostData.ip4 != NULL) {
103
5
    if (memcmp(a->hostData.ip4->data, b->hostData.ip4->data, 4)) {
104
4
      return URI_FALSE;
105
4
    }
106
5
  }
107
108
4.77k
  if (a->hostData.ip6 != NULL) {
109
134
    if (memcmp(a->hostData.ip6->data, b->hostData.ip6->data, 16)) {
110
128
      return URI_FALSE;
111
128
    }
112
134
  }
113
114
4.64k
  if (a->hostData.ipFuture.first != NULL) {
115
4
    if (URI_FUNC(CompareRange)(&(a->hostData.ipFuture), &(b->hostData.ipFuture))) {
116
2
      return URI_FALSE;
117
2
    }
118
4
  }
119
120
4.64k
  if ((a->hostData.ip4 == NULL)
121
4.64k
      && (a->hostData.ip6 == NULL)
122
4.64k
      && (a->hostData.ipFuture.first == NULL)) {
123
4.63k
    if (URI_FUNC(CompareRange)(&(a->hostText), &(b->hostText))) {
124
1.22k
      return URI_FALSE;
125
1.22k
    }
126
4.63k
  }
127
128
  /* portText */
129
3.42k
  if (URI_FUNC(CompareRange)(&(a->portText), &(b->portText))) {
130
3
    return URI_FALSE;
131
3
  }
132
133
  /* Path */
134
3.41k
  if ((a->pathHead == NULL) != (b->pathHead == NULL)) {
135
2.02k
    return URI_FALSE;
136
2.02k
  }
137
138
1.38k
  if (a->pathHead != NULL) {
139
526
    URI_TYPE(PathSegment) * walkA = a->pathHead;
140
526
    URI_TYPE(PathSegment) * walkB = b->pathHead;
141
944
    do {
142
944
      if (URI_FUNC(CompareRange)(&(walkA->text), &(walkB->text))) {
143
218
        return URI_FALSE;
144
218
      }
145
726
      if ((walkA->next == NULL) != (walkB->next == NULL)) {
146
13
        return URI_FALSE;
147
13
      }
148
713
      walkA = walkA->next;
149
713
      walkB = walkB->next;
150
713
    } while (walkA != NULL);
151
526
  }
152
153
  /* query */
154
1.15k
  if (URI_FUNC(CompareRange)(&(a->query), &(b->query))) {
155
482
    return URI_FALSE;
156
482
  }
157
158
  /* fragment */
159
676
  if (URI_FUNC(CompareRange)(&(a->fragment), &(b->fragment))) {
160
254
    return URI_FALSE;
161
254
  }
162
163
422
  return URI_TRUE; /* Equal*/
164
676
}
165
166
167
168
#endif