Skip to content

Commit

Permalink
plugins/php: drop PHP < 7 code
Browse files Browse the repository at this point in the history
Not supported upstream since years.
  • Loading branch information
xrmx committed Jun 20, 2021
1 parent 5b93863 commit c875857
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 49 deletions.
5 changes: 0 additions & 5 deletions plugins/php/common.h
Expand Up @@ -3,11 +3,6 @@
#include "php_main.h"
#include "php_variables.h"

#if (PHP_MAJOR_VERSION < 7)
#include "ext/standard/php_smart_str.h"
#else
#define UWSGI_PHP7
#endif
#include "ext/standard/info.h"

#include "ext/session/php_session.h"
Expand Down
28 changes: 5 additions & 23 deletions plugins/php/php_plugin.c
Expand Up @@ -4,6 +4,11 @@ extern struct uwsgi_server uwsgi;

static sapi_module_struct uwsgi_sapi_module;

static int uwsgi_php_init(void);

typedef size_t php_strlen_size;
typedef zend_long php_long_size;

struct uwsgi_php {
struct uwsgi_string_list *allowed_docroot;
struct uwsgi_string_list *allowed_ext;
Expand Down Expand Up @@ -73,11 +78,7 @@ struct uwsgi_option uwsgi_php_options[] = {
};


#ifdef UWSGI_PHP7
static size_t sapi_uwsgi_ub_write(const char *str, size_t str_length TSRMLS_DC)
#else
static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
#endif
{
struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);

Expand Down Expand Up @@ -123,11 +124,7 @@ static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
return SAPI_HEADER_SENT_SUCCESSFULLY;
}

#ifdef UWSGI_PHP7
static size_t sapi_uwsgi_read_post(char *buffer, size_t count_bytes TSRMLS_DC)
#else
static int sapi_uwsgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
#endif
{
uint read_bytes = 0;

Expand Down Expand Up @@ -253,9 +250,6 @@ PHP_MINIT_FUNCTION(uwsgi_php_minit) {
char *name = usl->value;
char *strval = equal + 1;
equal = NULL;
#ifndef UWSGI_PHP7
name_len = name_len + 1;
#endif
zend_register_string_constant(name, name_len, strval, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
}
usl = usl->next;
Expand All @@ -264,11 +258,7 @@ PHP_MINIT_FUNCTION(uwsgi_php_minit) {
}

PHP_FUNCTION(uwsgi_version) {
#ifdef UWSGI_PHP7
RETURN_STRING(UWSGI_VERSION);
#else
RETURN_STRING(UWSGI_VERSION, 1);
#endif
}

PHP_FUNCTION(uwsgi_worker_id) {
Expand Down Expand Up @@ -354,11 +344,7 @@ PHP_FUNCTION(uwsgi_cache_get) {
if (value) {
char *ret = estrndup(value, valsize);
free(value);
#ifdef UWSGI_PHP7
RETURN_STRING(ret);
#else
RETURN_STRING(ret, 0);
#endif
}
RETURN_NULL();
}
Expand Down Expand Up @@ -462,11 +448,7 @@ PHP_FUNCTION(uwsgi_rpc) {
// here we do not free varargs for performance reasons
char *ret = estrndup(response, size);
free(response);
#ifdef UWSGI_PHP7
RETURN_STRING(ret);
#else
RETURN_STRING(ret, 0);
#endif
}

clear:
Expand Down
21 changes: 0 additions & 21 deletions plugins/php/session.c
Expand Up @@ -12,52 +12,31 @@ PS_CLOSE_FUNC(uwsgi) {
PS_READ_FUNC(uwsgi) {
char *cache = PS_GET_MOD_DATA();
uint64_t valsize = 0;
#ifdef UWSGI_PHP7
char *value = uwsgi_cache_magic_get(key->val, key->len , &valsize, NULL, cache);
#else
char *value = uwsgi_cache_magic_get((char *)key, strlen((char *)key), &valsize, NULL, cache);
#endif
if (!value) {
*val = STR_EMPTY_ALLOC();
return SUCCESS;
}
#ifdef UWSGI_PHP7
*val = zend_string_init(value, valsize, 0);
#else
char *new_val = emalloc(valsize);
memcpy(new_val, value, valsize);
free(value);
*val = new_val;
*vallen = valsize;
#endif
return SUCCESS;

}

PS_WRITE_FUNC(uwsgi) {
char *cache = PS_GET_MOD_DATA();
#ifdef UWSGI_PHP7
if (val->len == 0) return SUCCESS;
if (!uwsgi_cache_magic_set(key->val, key->len, val->val, val->len, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) {
#else
if (vallen == 0) return SUCCESS;
if (!uwsgi_cache_magic_set((char *)key, strlen(key), (char *)val, vallen, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) {
#endif
return SUCCESS;
}
return FAILURE;
}

PS_DESTROY_FUNC(uwsgi) {
char *cache = PS_GET_MOD_DATA();
#ifdef UWSGI_PHP7
if (!uwsgi_cache_magic_exists(key->val, key->len, cache))
return SUCCESS;

if (!uwsgi_cache_magic_del(key->val, key->len, cache)) {
#else
if (!uwsgi_cache_magic_del((char *)key, strlen(key), cache)) {
#endif
return SUCCESS;
}
return FAILURE;
Expand Down

0 comments on commit c875857

Please sign in to comment.