From 0828b70df7606b599785b3de1c15248d3e463b95 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 28 Jun 2018 10:46:29 +0200 Subject: [PATCH] fix for PHP 7.3: fields of php_url struct change from char * to zend_string * --- oauth.c | 20 ++++++++++---------- php_oauth.h | 10 ++++++++++ provider.c | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/oauth.c b/oauth.c index 198e2cb..27f158f 100644 --- a/oauth.c +++ b/oauth.c @@ -577,14 +577,14 @@ zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method php_url_free(urlparts); return NULL; } - php_strtolower(urlparts->scheme, strlen(urlparts->scheme)); - php_strtolower(urlparts->host, strlen(urlparts->host)); - smart_string_appends(&sbuf, urlparts->scheme); + php_strtolower(OAUTH_URL_STR(urlparts->scheme), OAUTH_URL_LEN(urlparts->scheme)); + php_strtolower(OAUTH_URL_STR(urlparts->host), OAUTH_URL_LEN(urlparts->host)); + smart_string_appends(&sbuf, OAUTH_URL_STR(urlparts->scheme)); smart_string_appends(&sbuf, "://"); - smart_string_appends(&sbuf, urlparts->host); + smart_string_appends(&sbuf, OAUTH_URL_STR(urlparts->host)); - if (urlparts->port && ((!strcmp("http", urlparts->scheme) && OAUTH_HTTP_PORT != urlparts->port) - || (!strcmp("https", urlparts->scheme) && OAUTH_HTTPS_PORT != urlparts->port))) { + if (urlparts->port && ((!strcmp("http", OAUTH_URL_STR(urlparts->scheme)) && OAUTH_HTTP_PORT != urlparts->port) + || (!strcmp("https", OAUTH_URL_STR(urlparts->scheme)) && OAUTH_HTTPS_PORT != urlparts->port))) { spprintf(&s_port, 0, "%d", urlparts->port); smart_string_appendc(&sbuf, ':'); smart_string_appends(&sbuf, s_port); @@ -593,7 +593,7 @@ zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method if (urlparts->path) { smart_string squery = {0}; - smart_string_appends(&sbuf, urlparts->path); + smart_string_appends(&sbuf, OAUTH_URL_STR(urlparts->path)); smart_string_0(&sbuf); array_init(¶ms); @@ -608,7 +608,7 @@ zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method } if (urlparts->query) { - query = estrdup(urlparts->query); + query = estrdup(OAUTH_URL_STR(urlparts->query)); oauth_parse_str(query, ¶ms); efree(query); } @@ -1364,11 +1364,11 @@ static void oauth_apply_url_redirect(smart_string *surl, const char *location) / /* rebuild url from scratch */ smart_string_free(surl); if (urlparts->scheme) { - smart_string_appends(surl, urlparts->scheme); + smart_string_appends(surl, OAUTH_URL_STR(urlparts->scheme)); smart_string_appends(surl, "://"); } if (urlparts->host) { - smart_string_appends(surl, urlparts->host); + smart_string_appends(surl, OAUTH_URL_STR(urlparts->host)); } if (urlparts->port) { smart_string_appendc(surl, ':'); diff --git a/php_oauth.h b/php_oauth.h index cc7da09..02d68d8 100644 --- a/php_oauth.h +++ b/php_oauth.h @@ -332,6 +332,16 @@ zend_string *soo_sign(php_so_object *soo, char *message, zval *cs, zval *ts, con oauth_sig_context *oauth_create_sig_context(const char *sigmethod); zend_string *oauth_url_encode(char *url, int url_len); + +// Compatibility macros +#if PHP_VERSION_ID < 70300 +#define OAUTH_URL_STR(a) (a) +#define OAUTH_URL_LEN(a) strlen(a) +#else +#define OAUTH_URL_STR(a) ZSTR_VAL(a) +#define OAUTH_URL_LEN(a) ZSTR_LEN(a) +#endif + #endif /** diff --git a/provider.c b/provider.c index 0170ee1..41eb3be 100644 --- a/provider.c +++ b/provider.c @@ -132,7 +132,7 @@ static int oauth_provider_token_required(zval *provider_obj, char* uri) if (reqtoken_path[0]=='/') { /* match against relative url */ php_url *urlparts = php_url_parse_ex(uri, strlen(uri)); - uri_matched = urlparts && 0==strncmp(urlparts->path, reqtoken_path, strlen(reqtoken_path)); + uri_matched = urlparts && 0==strncmp(OAUTH_URL_STR(urlparts->path), reqtoken_path, strlen(reqtoken_path)); php_url_free(urlparts); } else { /* match against full uri */