PHP 7 support; just for fun master
authorMichael Wallner <root@iworks.at>
Thu, 24 Sep 2020 12:40:52 +0000 (14:40 +0200)
committerMichael Wallner <root@iworks.at>
Thu, 24 Sep 2020 12:40:52 +0000 (14:40 +0200)
courierauth.c
php_courierauth.h

index 6b99366b073222163573190fec9c49b124ccc280..cacb3c3f2acd0699f020583a19d1860714d8055c 100644 (file)
 
 #include <courierauth.h>
 
 
 #include <courierauth.h>
 
-/* {{{ courierauth_functions[] */
-zend_function_entry courierauth_functions[] = {
-       PHP_FE(courierauth_login, NULL)
-       PHP_FE(courierauth_enumerate, NULL)
-       PHP_FE(courierauth_getuserinfo, NULL)
-       PHP_FE(courierauth_passwd, NULL)
-       PHP_FE(courierauth_getoption, NULL)
-       {NULL, NULL, NULL}
-};
-/* }}} */
-
-/* {{{ courierauth_module_entry
- */
-zend_module_entry courierauth_module_entry = {
-#if ZEND_MODULE_API_NO >= 20010901
-       STANDARD_MODULE_HEADER,
-#endif
-       "courierauth",
-       courierauth_functions,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       PHP_MINFO(courierauth),
-#if ZEND_MODULE_API_NO >= 20010901
-       PHP_COURIERAUTH_VERSION,
-#endif
-       STANDARD_MODULE_PROPERTIES
-};
-/* }}} */
-
-#ifdef COMPILE_DL_COURIERAUTH
-ZEND_GET_MODULE(courierauth)
-#endif
-
-/* {{{ PHP_MINFO_FUNCTION */
-PHP_MINFO_FUNCTION(courierauth)
-{
-       php_info_print_table_start();
-       php_info_print_table_header(2, "courierauth support", "enabled");
-       php_info_print_table_row(2, "extension version", PHP_COURIERAUTH_VERSION);
-       php_info_print_table_row(2, "courierauth version", courierauth_h_rcsid);
-       php_info_print_table_end();
-}
-/* }}} */
-
 typedef struct {
        zval *rv;
 typedef struct {
        zval *rv;
-#ifdef ZTS
-       void ***tsrm_ls;
-#endif
-       uint success:1;
-       uint _res:31;
+       unsigned success:1;
+       unsigned _res:31;
 } php_courierauth_data;
 
 } php_courierauth_data;
 
-#ifdef ZTS
-#define php_courierauth_data_init {return_value, tsrm_ls, 0, 0}
-#else
-#define TSRMLS_SET_CTX(c)
-#define TSRMLS_FETCH_FROM_CTX(c)
 #define php_courierauth_data_init {return_value, 0, 0}
 #define php_courierauth_data_init {return_value, 0, 0}
-#endif
 
 static int php_courierauth_callback(struct authinfo *ai, void *arg)
 {
        php_courierauth_data *pa = (php_courierauth_data *) arg;
 
 static int php_courierauth_callback(struct authinfo *ai, void *arg)
 {
        php_courierauth_data *pa = (php_courierauth_data *) arg;
-       TSRMLS_FETCH_FROM_CTX(pa->tsrm_ls);
        
        convert_to_object(pa->rv);
        
        if (ai->sysusername) {
        
        convert_to_object(pa->rv);
        
        if (ai->sysusername) {
-               add_property_string(pa->rv, "sysusername", (char *) ai->sysusername, 1);
+               add_property_string(pa->rv, "sysusername", ai->sysusername);
                add_property_null(pa->rv, "sysuserid");
                add_property_null(pa->rv, "sysgroupid");
        } else if (ai->sysuserid) {
                add_property_null(pa->rv, "sysuserid");
                add_property_null(pa->rv, "sysgroupid");
        } else if (ai->sysuserid) {
@@ -107,7 +51,7 @@ static int php_courierauth_callback(struct authinfo *ai, void *arg)
        }
 #define ADD_STRING(s) \
        if (ai->s) { \
        }
 #define ADD_STRING(s) \
        if (ai->s) { \
-               add_property_string(pa->rv, #s, (char *) ai->s, 1); \
+               add_property_string(pa->rv, #s, ai->s); \
        } else { \
                add_property_null(pa->rv, #s); \
        }
        } else { \
                add_property_null(pa->rv, #s); \
        }
@@ -129,20 +73,18 @@ static int php_courierauth_callback(struct authinfo *ai, void *arg)
 
 static void php_courierauth_enumeration_callback(const char *sysusername, uid_t sysuserid, gid_t sysgroupid, const char *homedir, const char *maildir, const char *options, void *arg)
 {
 
 static void php_courierauth_enumeration_callback(const char *sysusername, uid_t sysuserid, gid_t sysgroupid, const char *homedir, const char *maildir, const char *options, void *arg)
 {
-       zval *entry, *array;
        struct authinfo ai = {NULL};
        php_courierauth_data *pa = (php_courierauth_data *) arg;
        struct authinfo ai = {NULL};
        php_courierauth_data *pa = (php_courierauth_data *) arg;
-       TSRMLS_FETCH_FROM_CTX(pa->tsrm_ls);
        
        if (!sysusername && !sysuserid && !homedir && !maildir && !options) {
                pa->success = 1;
        } else {
        
        if (!sysusername && !sysuserid && !homedir && !maildir && !options) {
                pa->success = 1;
        } else {
+               zval *array, tmp;
+
                array = pa->rv;
                array = pa->rv;
-               convert_to_array(array);
-               MAKE_STD_ZVAL(entry);
-               ZVAL_NULL(entry);
-               pa->rv = entry;
-               
+               pa->rv = &tmp;
+               ZVAL_NULL(&tmp);
+
                ai.sysusername = sysusername;
                ai.sysuserid = &sysuserid;
                ai.homedir = homedir;
                ai.sysusername = sysusername;
                ai.sysuserid = &sysuserid;
                ai.homedir = homedir;
@@ -151,20 +93,20 @@ static void php_courierauth_enumeration_callback(const char *sysusername, uid_t
                
                php_courierauth_callback(&ai, (void *) pa);
                
                
                php_courierauth_callback(&ai, (void *) pa);
                
-               add_next_index_zval(array, entry);
+               add_next_index_zval(array, pa->rv);
                pa->rv = array;
        }
 }
 
 /* {{{ proto object courierauth_login(string service, string user, string pass)
    Login and return account info on success */
                pa->rv = array;
        }
 }
 
 /* {{{ proto object courierauth_login(string service, string user, string pass)
    Login and return account info on success */
-PHP_FUNCTION(courierauth_login)
+static PHP_FUNCTION(courierauth_login)
 {
        char *svc_str, *user_str, *pass_str;
 {
        char *svc_str, *user_str, *pass_str;
-       int svc_len, user_len, pass_len;
+       size_t svc_len, user_len, pass_len;
        php_courierauth_data ca = php_courierauth_data_init;
        
        php_courierauth_data ca = php_courierauth_data_init;
        
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &svc_str, &svc_len, &user_str, &user_len, &pass_str, &pass_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sss", &svc_str, &svc_len, &user_str, &user_len, &pass_str, &pass_len)) {
                RETURN_FALSE;
        }
        
                RETURN_FALSE;
        }
        
@@ -176,13 +118,13 @@ PHP_FUNCTION(courierauth_login)
 
 /* {{{ proto object courierauth_getuserinfo(string service, string user)
        Get account info for a user */
 
 /* {{{ proto object courierauth_getuserinfo(string service, string user)
        Get account info for a user */
-PHP_FUNCTION(courierauth_getuserinfo)
+static PHP_FUNCTION(courierauth_getuserinfo)
 {
        char *svc_str, *user_str;
 {
        char *svc_str, *user_str;
-       int svc_len, user_len;
+       size_t svc_len, user_len;
        php_courierauth_data ca = php_courierauth_data_init;
        
        php_courierauth_data ca = php_courierauth_data_init;
        
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &svc_str, &svc_len, &user_str, &user_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &svc_str, &svc_len, &user_str, &user_len)) {
                RETURN_FALSE;
        }
        
                RETURN_FALSE;
        }
        
@@ -194,27 +136,28 @@ PHP_FUNCTION(courierauth_getuserinfo)
 
 /* {{{ proto array courierauth_enumerate(void)
        List all users */
 
 /* {{{ proto array courierauth_enumerate(void)
        List all users */
-PHP_FUNCTION(courierauth_enumerate)
+static PHP_FUNCTION(courierauth_enumerate)
 {
        php_courierauth_data ca = php_courierauth_data_init;
        
 {
        php_courierauth_data ca = php_courierauth_data_init;
        
-       zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "");
-       
+       zend_parse_parameters_none();
+
+       array_init(return_value);
        auth_enumerate(php_courierauth_enumeration_callback, &ca);
        if (!ca.success) {
        auth_enumerate(php_courierauth_enumeration_callback, &ca);
        if (!ca.success) {
-               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "auth_enumerate() aborted or unavailable");
+               php_error_docref(NULL, E_NOTICE, "auth_enumerate() aborted or unavailable");
        }
 }
 /* }}} */
 
 /* {{{ proto bool courierauth_passwd(string service, string user, string old_pass, string new_pass)
        Change the password of a user */
        }
 }
 /* }}} */
 
 /* {{{ proto bool courierauth_passwd(string service, string user, string old_pass, string new_pass)
        Change the password of a user */
-PHP_FUNCTION(courierauth_passwd)
+static PHP_FUNCTION(courierauth_passwd)
 {
        char *svc_str, *user_str, *oldpw_str, *newpw_str;
 {
        char *svc_str, *user_str, *oldpw_str, *newpw_str;
-       int svc_len, user_len, oldpw_len, newpw_len;
+       size_t svc_len, user_len, oldpw_len, newpw_len;
        
        
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &svc_str, &svc_len, &user_str, &user_len, &oldpw_str, &oldpw_len, &newpw_str, &newpw_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "ssss", &svc_str, &svc_len, &user_str, &user_len, &oldpw_str, &oldpw_len, &newpw_str, &newpw_len)) {
                RETURN_FALSE;
        }
        
                RETURN_FALSE;
        }
        
@@ -223,17 +166,17 @@ PHP_FUNCTION(courierauth_passwd)
 
 /* {{{ proto string courierauth_getoption(string options, string key)
        Get the value of a key from options string */
 
 /* {{{ proto string courierauth_getoption(string options, string key)
        Get the value of a key from options string */
-PHP_FUNCTION(courierauth_getoption)
+static PHP_FUNCTION(courierauth_getoption)
 {
        char *opt_str, *key_str, *val_str;
 {
        char *opt_str, *key_str, *val_str;
-       int opt_len, key_len;
+       size_t opt_len, key_len;
        
        
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &opt_str, &opt_len, &key_str, &key_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &opt_str, &opt_len, &key_str, &key_len)) {
                RETURN_FALSE;
        }
        
        if ((val_str = auth_getoption(opt_str, key_str))) {
                RETURN_FALSE;
        }
        
        if ((val_str = auth_getoption(opt_str, key_str))) {
-               RETVAL_STRING(val_str, 1);
+               RETVAL_STRING(val_str);
                free(val_str);
        } else {
                RETURN_FALSE;
                free(val_str);
        } else {
                RETURN_FALSE;
@@ -241,6 +184,48 @@ PHP_FUNCTION(courierauth_getoption)
 }
 /* }}} */
 
 }
 /* }}} */
 
+/* {{{ courierauth_functions[] */
+static zend_function_entry courierauth_functions[] = {
+       PHP_FE(courierauth_login, NULL)
+       PHP_FE(courierauth_enumerate, NULL)
+       PHP_FE(courierauth_getuserinfo, NULL)
+       PHP_FE(courierauth_passwd, NULL)
+       PHP_FE(courierauth_getoption, NULL)
+       {0}
+};
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION */
+static PHP_MINFO_FUNCTION(courierauth)
+{
+       php_info_print_table_start();
+       php_info_print_table_header(2, "courierauth support", "enabled");
+       php_info_print_table_row(2, "extension version", PHP_COURIERAUTH_VERSION);
+       php_info_print_table_row(2, "courierauth version", "unknown");
+       php_info_print_table_end();
+}
+/* }}} */
+
+/* {{{ courierauth_module_entry
+ */
+zend_module_entry courierauth_module_entry = {
+       STANDARD_MODULE_HEADER,
+       "courierauth",
+       courierauth_functions,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       PHP_MINFO(courierauth),
+       PHP_COURIERAUTH_VERSION,
+       STANDARD_MODULE_PROPERTIES
+};
+/* }}} */
+
+#ifdef COMPILE_DL_COURIERAUTH
+ZEND_GET_MODULE(courierauth)
+#endif
+
 /*
  * Local variables:
  * tab-width: 4
 /*
  * Local variables:
  * tab-width: 4
index ff3ae3c63b68bb66f3bc62755c349568d300c503..8b900e33e29ace7e4774f9cc5d381ae0443bd3f7 100644 (file)
 extern zend_module_entry courierauth_module_entry;
 #define phpext_courierauth_ptr &courierauth_module_entry
 
 extern zend_module_entry courierauth_module_entry;
 #define phpext_courierauth_ptr &courierauth_module_entry
 
-#ifdef ZTS
-#include "TSRM.h"
-#endif
-
-PHP_MINFO_FUNCTION(courierauth);
-
-PHP_FUNCTION(courierauth_login);
-PHP_FUNCTION(courierauth_getuserinfo);
-PHP_FUNCTION(courierauth_enumerate);
-PHP_FUNCTION(courierauth_passwd);
-PHP_FUNCTION(courierauth_getoption);
-
 #endif /* PHP_COURIERAUTH_H */
 
 
 #endif /* PHP_COURIERAUTH_H */