Skip to content

Commit 6637638

Browse files
committed
Update uriparser to commit 5f7c6d88c50f548d0c7f499c22d36f51d34775b3
While there, fix Windows build by adding UriResolve.c to the sources.
1 parent 59dd0f8 commit 6637638

File tree

12 files changed

+574
-26
lines changed

12 files changed

+574
-26
lines changed

ext/uri/config.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ AC_DEFINE([URI_ENABLE_ANSI], [1], [Define to 1 for enabling ANSI support of urip
1111
AC_DEFINE([URI_NO_UNICODE], [1], [Define to 1 for disabling unicode support of uriparser.])
1212

1313
URIPARSER_DIR="uriparser"
14-
URIPARSER_SOURCES="$URIPARSER_DIR/src/UriCommon.c $URIPARSER_DIR/src/UriCompare.c $URIPARSER_DIR/src/UriEscape.c \
15-
$URIPARSER_DIR/src/UriFile.c $URIPARSER_DIR/src/UriIp4.c $URIPARSER_DIR/src/UriIp4Base.c \
14+
URIPARSER_SOURCES="$URIPARSER_DIR/src/UriCommon.c $URIPARSER_DIR/src/UriCompare.c $URIPARSER_DIR/src/UriCopy.c \
15+
$URIPARSER_DIR/src/UriEscape.c $URIPARSER_DIR/src/UriFile.c $URIPARSER_DIR/src/UriIp4.c $URIPARSER_DIR/src/UriIp4Base.c \
1616
$URIPARSER_DIR/src/UriMemory.c $URIPARSER_DIR/src/UriNormalize.c $URIPARSER_DIR/src/UriNormalizeBase.c \
1717
$URIPARSER_DIR/src/UriParse.c $URIPARSER_DIR/src/UriParseBase.c $URIPARSER_DIR/src/UriQuery.c \
1818
$URIPARSER_DIR/src/UriRecompose.c $URIPARSER_DIR/src/UriResolve.c $URIPARSER_DIR/src/UriShorten.c"

ext/uri/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ AC_DEFINE("URI_NO_UNICODE", 1, "Define to 1 for disabling unicode support of uri
55
ADD_FLAG("CFLAGS_URI", "/D URI_STATIC_BUILD");
66

77
ADD_EXTENSION_DEP('uri', 'lexbor');
8-
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriShorten.c", "uri");
8+
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriCopy.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriResolve.c UriShorten.c", "uri");
99
PHP_INSTALL_HEADERS("ext/uri", "php_lexbor.h php_uri.h php_uri_common.h uriparser/src uriparser/include");

ext/uri/uriparser/include/uriparser/Uri.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ typedef struct URI_TYPE(QueryListStruct) {
201201
} URI_TYPE(QueryList); /**< @copydoc UriQueryListStructA */
202202

203203

204+
/**
205+
* Checks if a URI has the host component set.
206+
*
207+
* @param uri <b>IN</b>: %URI to check
208+
* @return <c>URI_TRUE</c> when host is set, <c>URI_FALSE</c> otherwise
209+
*
210+
* @since 0.9.9
211+
*/
212+
URI_PUBLIC UriBool URI_FUNC(HasHost)(const URI_TYPE(Uri) * uri);
213+
214+
204215

205216
/**
206217
* Parses a RFC 3986 %URI.
@@ -644,6 +655,36 @@ URI_PUBLIC int URI_FUNC(ToString)(URI_CHAR * dest, const URI_TYPE(Uri) * uri,
644655

645656

646657

658+
/**
659+
* Copies a %URI structure.
660+
*
661+
* @param destUri <b>OUT</b>: Output destination
662+
* @param sourceUri <b>IN</b>: %URI to copy
663+
* @param memory <b>IN</b>: Memory manager to use, NULL for default libc
664+
* @return Error code or 0 on success
665+
*
666+
* @see uriCopyUriA
667+
* @since 0.9.9
668+
*/
669+
URI_PUBLIC int URI_FUNC(CopyUriMm)(URI_TYPE(Uri) * destUri,
670+
const URI_TYPE(Uri) * sourceUri, UriMemoryManager * memory);
671+
672+
673+
674+
/**
675+
* Copies a %URI structure.
676+
*
677+
* @param destUri <b>OUT</b>: Output destination
678+
* @param sourceUri <b>IN</b>: %URI to copy
679+
* @return Error code or 0 on success
680+
*
681+
* @see uriCopyUriMmA
682+
* @since 0.9.9
683+
*/
684+
URI_PUBLIC int URI_FUNC(CopyUri)(URI_TYPE(Uri) * destUri, const URI_TYPE(Uri) * sourceUri);
685+
686+
687+
647688
/**
648689
* Determines the components of a %URI that are not normalized.
649690
*

ext/uri/uriparser/include/uriparser/UriBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ typedef enum UriNormalizationMaskEnum {
258258
URI_NORMALIZE_HOST = 1 << 2, /**< Normalize host (fix uppercase letters) */
259259
URI_NORMALIZE_PATH = 1 << 3, /**< Normalize path (fix uppercase percent-encodings and redundant dot segments) */
260260
URI_NORMALIZE_QUERY = 1 << 4, /**< Normalize query (fix uppercase percent-encodings) */
261-
URI_NORMALIZE_FRAGMENT = 1 << 5 /**< Normalize fragment (fix uppercase percent-encodings) */
261+
URI_NORMALIZE_FRAGMENT = 1 << 5, /**< Normalize fragment (fix uppercase percent-encodings) */
262+
URI_NORMALIZE_PORT = 1 << 6 /**< Normalize port (drop leading zeros) @since 0.9.9 */
262263
} UriNormalizationMask; /**< @copydoc UriNormalizationMaskEnum */
263264

264265

ext/uri/uriparser/src/UriCommon.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,40 @@ int URI_FUNC(CompareRange)(
119119

120120

121121

122+
UriBool URI_FUNC(CopyRange)(URI_TYPE(TextRange) * destRange,
123+
const URI_TYPE(TextRange) * sourceRange, UriMemoryManager * memory) {
124+
const int lenInChars = (int)(sourceRange->afterLast - sourceRange->first);
125+
const int lenInBytes = lenInChars * sizeof(URI_CHAR);
126+
URI_CHAR * dup = memory->malloc(memory, lenInBytes);
127+
if (dup == NULL) {
128+
return URI_FALSE;
129+
}
130+
memcpy(dup, sourceRange->first, lenInBytes);
131+
destRange->first = dup;
132+
destRange->afterLast = dup + lenInChars;
133+
134+
return URI_TRUE;
135+
}
136+
137+
138+
139+
UriBool URI_FUNC(CopyRangeAsNeeded)(URI_TYPE(TextRange) * destRange,
140+
const URI_TYPE(TextRange) * sourceRange, UriBool useSafe, UriMemoryManager * memory) {
141+
if (sourceRange->first == NULL) {
142+
destRange->first = NULL;
143+
destRange->afterLast = NULL;
144+
} else if (sourceRange->first == sourceRange->afterLast && useSafe) {
145+
destRange->first = URI_FUNC(SafeToPointTo);
146+
destRange->afterLast = URI_FUNC(SafeToPointTo);
147+
} else {
148+
return URI_FUNC(CopyRange)(destRange, sourceRange, memory);
149+
}
150+
151+
return URI_TRUE;
152+
}
153+
154+
155+
122156
UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri,
123157
UriBool relative, UriBool pathOwned, UriMemoryManager * memory) {
124158
URI_TYPE(PathSegment) * walker;
@@ -189,7 +223,7 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri,
189223

190224
if (prev == NULL) {
191225
/* Last and first */
192-
if (URI_FUNC(IsHostSet)(uri)) {
226+
if (URI_FUNC(HasHost)(uri)) {
193227
/* Replace "." with empty segment to represent trailing slash */
194228
walker->text.first = URI_FUNC(SafeToPointTo);
195229
walker->text.afterLast = URI_FUNC(SafeToPointTo);
@@ -463,7 +497,7 @@ URI_CHAR URI_FUNC(HexToLetterEx)(unsigned int value, UriBool uppercase) {
463497

464498

465499
/* Checks if a URI has the host component set. */
466-
UriBool URI_FUNC(IsHostSet)(const URI_TYPE(Uri) * uri) {
500+
UriBool URI_FUNC(HasHost)(const URI_TYPE(Uri) * uri) {
467501
return (uri != NULL)
468502
&& ((uri->hostText.first != NULL)
469503
|| (uri->hostData.ip4 != NULL)
@@ -601,7 +635,7 @@ void URI_FUNC(FixEmptyTrailSegment)(URI_TYPE(Uri) * uri,
601635
UriMemoryManager * memory) {
602636
/* Fix path if only one empty segment */
603637
if (!uri->absolutePath
604-
&& !URI_FUNC(IsHostSet)(uri)
638+
&& !URI_FUNC(HasHost)(uri)
605639
&& (uri->pathHead != NULL)
606640
&& (uri->pathHead->next == NULL)
607641
&& (uri->pathHead->text.first == uri->pathHead->text.afterLast)) {

ext/uri/uriparser/src/UriCommon.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ int URI_FUNC(CompareRange)(
8282
const URI_TYPE(TextRange) * a,
8383
const URI_TYPE(TextRange) * b);
8484

85+
UriBool URI_FUNC(CopyRange)(URI_TYPE(TextRange) * destRange,
86+
const URI_TYPE(TextRange) * sourceRange, UriMemoryManager * memory);
87+
UriBool URI_FUNC(CopyRangeAsNeeded)(URI_TYPE(TextRange) * destRange,
88+
const URI_TYPE(TextRange) * sourceRange, UriBool useSafe, UriMemoryManager * memory);
89+
8590
UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri,
8691
UriMemoryManager * memory);
8792
UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri,
@@ -91,8 +96,6 @@ unsigned char URI_FUNC(HexdigToInt)(URI_CHAR hexdig);
9196
URI_CHAR URI_FUNC(HexToLetter)(unsigned int value);
9297
URI_CHAR URI_FUNC(HexToLetterEx)(unsigned int value, UriBool uppercase);
9398

94-
UriBool URI_FUNC(IsHostSet)(const URI_TYPE(Uri) * uri);
95-
9699
UriBool URI_FUNC(CopyPath)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * source,
97100
UriMemoryManager * memory);
98101
UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest,

0 commit comments

Comments
 (0)