Skip to content

Add ext/uri skeleton along with uriparser #18658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Additional review fixes + uriparser sync with latest master
  • Loading branch information
kocsismate committed May 25, 2025
commit ac9af23581b0b560b45a4cb0259cef1469cbdc5c
11 changes: 1 addition & 10 deletions ext/uri/php_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static PHP_MINFO_FUNCTION(uri)
{
php_info_print_table_start();
php_info_print_table_row(2, "uri support", "active");
php_info_print_table_row(2, "uriparser library version", URIPARSER_VERSION);
php_info_print_table_end();
}

Expand All @@ -64,9 +65,6 @@ static PHP_MSHUTDOWN_FUNCTION(uri)

PHP_RINIT_FUNCTION(uri)
{
#if defined(COMPILE_DL_URI) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif

return SUCCESS;
}
Expand All @@ -89,10 +87,3 @@ zend_module_entry uri_module_entry = {
PHP_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_URI
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(uri)
#endif
3 changes: 0 additions & 3 deletions ext/uri/php_uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@
extern zend_module_entry uri_module_entry;
#define phpext_uri_ptr &uri_module_entry

#if defined(ZTS) && defined(COMPILE_DL_URI)
ZEND_TSRMLS_CACHE_EXTERN()
#endif

#endif
20 changes: 8 additions & 12 deletions ext/uri/uriparser/include/uriparser/Uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern "C" {
# include "UriBase.h"
#endif

extern const URI_CHAR * const URI_FUNC(SafeToPointTo);


/**
* Specifies a range of characters within a string.
Expand Down Expand Up @@ -200,11 +200,7 @@ typedef struct URI_TYPE(QueryListStruct) {
struct URI_TYPE(QueryListStruct) * next; /**< Pointer to the next key/value pair in the list, can be NULL if last already */
} URI_TYPE(QueryList); /**< @copydoc UriQueryListStructA */

URI_PUBLIC UriBool URI_FUNC(IsHostSet)(const URI_TYPE(Uri) * uri);

URI_PUBLIC UriBool URI_FUNC(PushPathSegment)(URI_TYPE(ParserState) * state,
const URI_CHAR * first, const URI_CHAR * afterLast,
UriMemoryManager * memory);

/**
* Parses a RFC 3986 %URI.
Expand Down Expand Up @@ -354,7 +350,7 @@ URI_PUBLIC int URI_FUNC(FreeUriMembersMm)(URI_TYPE(Uri) * uri,


/**
* Percent-encodes all unreserved characters from the input string and
* Percent-encodes all but unreserved characters from the input string and
* writes the encoded version to the output string.
*
* NOTE: Be sure to allocate <b>3 times</b> the space of the input buffer for
Expand Down Expand Up @@ -388,7 +384,7 @@ URI_PUBLIC URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst,


/**
* Percent-encodes all unreserved characters from the input string and
* Percent-encodes all but unreserved characters from the input string and
* writes the encoded version to the output string.
*
* NOTE: Be sure to allocate <b>3 times</b> the space of the input buffer for
Expand Down Expand Up @@ -465,7 +461,7 @@ URI_PUBLIC const URI_CHAR * URI_FUNC(UnescapeInPlace)(URI_CHAR * inout);

/**
* Performs reference resolution as described in
* <a href="http://tools.ietf.org/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.
* <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.
* Uses default libc-based memory manager.
* NOTE: On success you have to call uriFreeUriMembersA on \p absoluteDest manually later.
*
Expand All @@ -488,7 +484,7 @@ URI_PUBLIC int URI_FUNC(AddBaseUri)(URI_TYPE(Uri) * absoluteDest,

/**
* Performs reference resolution as described in
* <a href="http://tools.ietf.org/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.
* <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.
* Uses default libc-based memory manager.
* NOTE: On success you have to call uriFreeUriMembersA on \p absoluteDest manually later.
*
Expand All @@ -512,7 +508,7 @@ URI_PUBLIC int URI_FUNC(AddBaseUriEx)(URI_TYPE(Uri) * absoluteDest,

/**
* Performs reference resolution as described in
* <a href="http://tools.ietf.org/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.
* <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.
* NOTE: On success you have to call uriFreeUriMembersMmA on \p absoluteDest manually later.
*
* @param absoluteDest <b>OUT</b>: Result %URI
Expand Down Expand Up @@ -628,10 +624,10 @@ URI_PUBLIC int URI_FUNC(ToStringCharsRequired)(const URI_TYPE(Uri) * uri,

/**
* Converts a %URI structure back to text as described in
* <a href="http://tools.ietf.org/html/rfc3986#section-5.3">section 5.3 of RFC 3986</a>.
* <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5.3">section 5.3 of RFC 3986</a>.
*
* NOTE: Scheme-based normalization
* (<a href="http://tools.ietf.org/html/rfc3986#section-6.2.3">section 6.2.3 of RFC 3986</a>)
* (<a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.3">section 6.2.3 of RFC 3986</a>)
* is not applied and is considered a responsibility of the application using uriparser.
*
* @param dest <b>OUT</b>: Output destination
Expand Down
4 changes: 2 additions & 2 deletions ext/uri/uriparser/src/UriCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ unsigned char URI_FUNC(HexdigToInt)(URI_CHAR hexdig) {


URI_CHAR URI_FUNC(HexToLetter)(unsigned int value) {
/* Uppercase recommended in section 2.1. of RFC 3986 *
* http://tools.ietf.org/html/rfc3986#section-2.1 */
/* Uppercase recommended in section 2.1. of RFC 3986 *
* https://datatracker.ietf.org/doc/html/rfc3986#section-2.1 */
return URI_FUNC(HexToLetterEx)(value, URI_TRUE);
}

Expand Down
3 changes: 3 additions & 0 deletions ext/uri/uriparser/src/UriCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

/* Used to point to from empty path segments.
* X.first and X.afterLast must be the same non-NULL value then. */
extern const URI_CHAR * const URI_FUNC(SafeToPointTo);
extern const URI_CHAR * const URI_FUNC(ConstPwd);
extern const URI_CHAR * const URI_FUNC(ConstParent);

Expand All @@ -90,6 +91,8 @@ unsigned char URI_FUNC(HexdigToInt)(URI_CHAR hexdig);
URI_CHAR URI_FUNC(HexToLetter)(unsigned int value);
URI_CHAR URI_FUNC(HexToLetterEx)(unsigned int value, UriBool uppercase);

UriBool URI_FUNC(IsHostSet)(const URI_TYPE(Uri) * uri);

UriBool URI_FUNC(CopyPath)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * source,
UriMemoryManager * memory);
UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest,
Expand Down
51 changes: 0 additions & 51 deletions ext/uri/uriparser/src/UriConfig.h

This file was deleted.

11 changes: 7 additions & 4 deletions ext/uri/uriparser/src/UriNormalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static UriBool URI_FUNC(ContainsUglyPercentEncoding)(const URI_CHAR * first,

static void URI_FUNC(LowercaseInplace)(const URI_CHAR * first,
const URI_CHAR * afterLast);
static void URI_FUNC(LowercaseInplaceAfterPercentEncoding)(const URI_CHAR * first,
static void URI_FUNC(LowercaseInplaceExceptPercentEncoding)(const URI_CHAR * first,
const URI_CHAR * afterLast);
static UriBool URI_FUNC(LowercaseMalloc)(const URI_CHAR ** first,
const URI_CHAR ** afterLast, UriMemoryManager * memory);
Expand Down Expand Up @@ -247,7 +247,7 @@ static URI_INLINE void URI_FUNC(LowercaseInplace)(const URI_CHAR * first,



static URI_INLINE void URI_FUNC(LowercaseInplaceAfterPercentEncoding)(const URI_CHAR * first,
static URI_INLINE void URI_FUNC(LowercaseInplaceExceptPercentEncoding)(const URI_CHAR * first,
const URI_CHAR * afterLast) {
if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
URI_CHAR * i = (URI_CHAR *)first;
Expand All @@ -256,6 +256,9 @@ static URI_INLINE void URI_FUNC(LowercaseInplaceAfterPercentEncoding)(const URI_
if ((*i >= _UT('A')) && (*i <=_UT('Z'))) {
*i = (URI_CHAR)(*i + lowerUpperDiff);
} else if (*i == _UT('%')) {
if (i + 3 >= afterLast) {
return;
}
i += 2;
}
}
Expand Down Expand Up @@ -634,7 +637,7 @@ static URI_INLINE int URI_FUNC(NormalizeSyntaxEngine)(URI_TYPE(Uri) * uri,
uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
} else if ((uri->hostText.first != NULL)
&& (uri->hostData.ip4 == NULL)) {
/* Regname and IPv6 */
/* Regname or IPv6 */
if (uri->owner) {
URI_FUNC(FixPercentEncodingInplace)(uri->hostText.first,
&(uri->hostText.afterLast));
Expand All @@ -649,7 +652,7 @@ static URI_INLINE int URI_FUNC(NormalizeSyntaxEngine)(URI_TYPE(Uri) * uri,
doneMask |= URI_NORMALIZE_HOST;
}

URI_FUNC(LowercaseInplaceAfterPercentEncoding)(uri->hostText.first,
URI_FUNC(LowercaseInplaceExceptPercentEncoding)(uri->hostText.first,
uri->hostText.afterLast);
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/uri/uriparser/src/UriParse.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static void URI_FUNC(OnExitPartHelperTwo)(URI_TYPE(ParserState) * state);

static void URI_FUNC(ResetParserStateExceptUri)(URI_TYPE(ParserState) * state);

UriBool URI_FUNC(PushPathSegment)(URI_TYPE(ParserState) * state,
static UriBool URI_FUNC(PushPathSegment)(URI_TYPE(ParserState) * state,
const URI_CHAR * first, const URI_CHAR * afterLast,
UriMemoryManager * memory);

Expand Down Expand Up @@ -2119,7 +2119,7 @@ static URI_INLINE void URI_FUNC(ResetParserStateExceptUri)(URI_TYPE(ParserState)



UriBool URI_FUNC(PushPathSegment)(
static URI_INLINE UriBool URI_FUNC(PushPathSegment)(
URI_TYPE(ParserState) * state, const URI_CHAR * first,
const URI_CHAR * afterLast, UriMemoryManager * memory) {
URI_TYPE(PathSegment) * segment = memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment)));
Expand Down
Loading