Ejemplo n.º 1
0
/* This function is meant to unify the headers passed to to mail()
 * This means, use PCRE to transform single occurrences of \n or \r in \r\n
 * As a second step we also eleminate all \r\n occurrences which are:
 * 1) At the start of the header
 * 2) At the end of the header
 * 3) Two or more occurrences in the header are removed so only one is left
 *
 * Returns NULL on error, or the new char* buffer on success.
 * You have to take care and efree() the buffer on your own.
 */
static zend_string *php_win32_mail_trim_header(char *header)
{

#if HAVE_PCRE || HAVE_BUNDLED_PCRE

	zend_string *result, *result2;
	zend_string *replace;
	zend_string *regex;

	if (!header) {
		return NULL;
	}

	replace = zend_string_init(PHP_WIN32_MAIL_UNIFY_REPLACE, strlen(PHP_WIN32_MAIL_UNIFY_REPLACE), 0);
	regex = zend_string_init(PHP_WIN32_MAIL_UNIFY_PATTERN, sizeof(PHP_WIN32_MAIL_UNIFY_PATTERN)-1, 0);

	result = php_pcre_replace(regex,
				  NULL, header, (int)strlen(header),
				  replace,
				  -1,
				  NULL);

	zend_string_release(replace);
	zend_string_release(regex);

	if (NULL == result) {
		return NULL;
	}

	replace = zend_string_init(PHP_WIN32_MAIL_RMVDBL_PATTERN, strlen(PHP_WIN32_MAIL_RMVDBL_PATTERN), 0);
	regex = zend_string_init(PHP_WIN32_MAIL_RMVDBL_PATTERN, sizeof(PHP_WIN32_MAIL_RMVDBL_PATTERN)-1, 0);

	result2 = php_pcre_replace(regex,
				   result, ZSTR_VAL(result), (int)ZSTR_LEN(result),
				   replace,
				  -1,
				  NULL);
	zend_string_release(replace);
	zend_string_release(regex);
	zend_string_release(result);

	return result2;
#else
	/* In case we don't have PCRE support (for whatever reason...) simply do nothing and return the unmodified header */
	return zend_string_init(header, strlen(header), 0);
#endif
}
Ejemplo n.º 2
0
/* This function is meant to unify the headers passed to to mail()
 * This means, use PCRE to transform single occurrences of \n or \r in \r\n
 * As a second step we also eleminate all \r\n occurrences which are:
 * 1) At the start of the header
 * 2) At the end of the header
 * 3) Two or more occurrences in the header are removed so only one is left
 *
 * Returns NULL on error, or the new char* buffer on success.
 * You have to take care and efree() the buffer on your own.
 */
static zend_string *php_win32_mail_trim_header(char *header)
{

#if HAVE_PCRE || HAVE_BUNDLED_PCRE
	
	zend_string *result, *result2;
	zval replace;
	zend_string *regex;

	if (!header) {
		return NULL;
	}

	ZVAL_STRINGL(&replace, PHP_WIN32_MAIL_UNIFY_REPLACE, strlen(PHP_WIN32_MAIL_UNIFY_REPLACE));
	regex = zend_string_init(PHP_WIN32_MAIL_UNIFY_REPLACE, sizeof(PHP_WIN32_MAIL_UNIFY_REPLACE)-1, 0);

//zend_string *php_pcre_replace(zend_string *regex, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int limit, int *replace_count);

	result = php_pcre_replace(regex,
							  header, (int)strlen(header),
							  &replace,
							  0,
							  -1,
							  NULL);

	if (NULL == result) {
		zval_ptr_dtor(&replace);
		zend_string_free(regex);
		return NULL;
	}

	ZVAL_STRING(&replace, PHP_WIN32_MAIL_RMVDBL_PATTERN);
	regex = zend_string_init(PHP_WIN32_MAIL_RMVDBL_PATTERN, sizeof(PHP_WIN32_MAIL_RMVDBL_PATTERN)-1, 0);

	result2 = php_pcre_replace(regex,
							   result->val, (int)result->len,
							   &replace,
							  0,
							  -1,
							  NULL);
	return result;
#else
	/* In case we don't have PCRE support (for whatever reason...) simply do nothing and return the unmodified header */
	return estrdup(header);
#endif
}
Ejemplo n.º 3
0
char* air_router_compile(char *key, uint key_len, int *result_len) {
	char *ret;
	zval *replace;
	MAKE_STD_ZVAL(replace);
	ZVAL_STRING(replace, "(?P<$2>$3)", 1);
	ret = php_pcre_replace(ZEND_STRL("#(<([^:]+):([^>]+)>)#"), key, key_len, replace, 0, result_len, -1, NULL TSRMLS_CC);
	zval_ptr_dtor(&replace);

	return ret;
}
Ejemplo n.º 4
0
/* This function is meant to unify the headers passed to to mail()
 * This means, use PCRE to transform single occurrences of \n or \r in \r\n
 * As a second step we also eleminate all \r\n occurrences which are:
 * 1) At the start of the header
 * 2) At the end of the header
 * 3) Two or more occurrences in the header are removed so only one is left
 *
 * Returns NULL on error, or the new char* buffer on success.
 * You have to take care and efree() the buffer on your own.
 */
static zend_string *php_win32_mail_trim_header(char *header)
{
	zend_string *result, *result2;
	zend_string *replace;
	zend_string *regex;

	if (!header) {
		return NULL;
	}

	replace = zend_string_init(PHP_WIN32_MAIL_UNIFY_REPLACE, strlen(PHP_WIN32_MAIL_UNIFY_REPLACE), 0);
	regex = zend_string_init(PHP_WIN32_MAIL_UNIFY_PATTERN, sizeof(PHP_WIN32_MAIL_UNIFY_PATTERN)-1, 0);

	result = php_pcre_replace(regex,
				  NULL, header, strlen(header),
				  replace,
				  -1,
				  NULL);

	zend_string_release_ex(replace, 0);
	zend_string_release_ex(regex, 0);

	if (NULL == result) {
		return NULL;
	}

	replace = zend_string_init(PHP_WIN32_MAIL_RMVDBL_PATTERN, strlen(PHP_WIN32_MAIL_RMVDBL_PATTERN), 0);
	regex = zend_string_init(PHP_WIN32_MAIL_RMVDBL_PATTERN, sizeof(PHP_WIN32_MAIL_RMVDBL_PATTERN)-1, 0);

	result2 = php_pcre_replace(regex,
				   result, ZSTR_VAL(result), ZSTR_LEN(result),
				   replace,
				  -1,
				  NULL);
	zend_string_release_ex(replace, 0);
	zend_string_release_ex(regex, 0);
	zend_string_release_ex(result, 0);

	return result2;
}
Ejemplo n.º 5
0
// need efree
char * kr_regex_replace (char * regex_o, char * replace_o, char * str_o) // {{{
{
	zend_string * buf;
	zend_string * regex;
	zend_string * subject;
#if PHP_VERSION_ID < 70200
	zval          replaces;
#else
	zend_string * replaces;
#endif
#if PHP_VERSION_ID < 70300
	int           repc = 0;
#else
	size_t        repc = 0;
#endif

	char        * sval;

	regex = ze_string_init (regex_o, STRLEN (regex_o), 0);
	subject = ze_string_init (str_o, STRLEN (str_o), 0);
#if PHP_VERSION_ID < 70200
	ZVAL_STRINGL (&replaces, replace_o, STRLEN (replace_o));
#else
	replaces = ze_string_init (replace_o, STRLEN (replace_o), 0);
#endif

	buf = php_pcre_replace (
#if PHP_VERSION_ID < 70200
			regex, subject, ZSTR_VAL (subject), (int) ZSTR_LEN (subject), &replaces, 0, -1, &repc
#else
			regex, subject, ZSTR_VAL (subject), ZSTR_LEN (subject), replaces, -1, &repc
#endif
	);

#if PHP_VERSION_ID < 70200
	zval_ptr_dtor (&replaces);
#else
	zend_string_release (replaces);
#endif
	zend_string_release (regex);
	zend_string_release (subject);

	sval = estrdup (ZSTR_VAL (buf));
	zend_string_release (buf);

	return sval;
} // }}}
Ejemplo n.º 6
0
// need efree
char * kr_regex_replace_arr (char * regex_o[], char * replace_o[], char * str_o, int regex_no) // {{{
{
	zend_string * buf = NULL;
	zend_string * regex;
	zend_string * subject;

	int           i;
#if PHP_VERSION_ID < 70200
	zval          rep;
#else
	zend_string * rep;
#endif
#if PHP_VERSION_ID < 70300
	int           repc = 0;
#else
	size_t        repc = 0;
#endif

	char        * sval;

	subject = ze_string_init (str_o, STRLEN (str_o), 0);

	for ( i=0; i<regex_no ; i++ ) {
		regex = ze_string_init (regex_o[i], STRLEN (regex_o[i]), 0);
#if PHP_VERSION_ID < 70200
		ZVAL_STRINGL (&rep, replace_o[i], STRLEN (replace_o[i]));
#else
		rep = ze_string_init (replace_o[i], STRLEN (replace_o[i]), 0);
#endif

		if ( i != 0 ) {
			subject = zend_string_dup (buf, 0);
			zend_string_release(buf);
			buf = NULL;
		}

		/*
		php_printf ("regex ########### %s\n", ZSTR_VAL (regex));
		php_printf ("subject ######### %s\n", ZSTR_VAL (subject));
		php_printf ("subjlen ######### %d\n", ZSTR_LEN (subject));
		php_printf ("replace ######### %s\n", ZSTR_VAL (rep.value.str));
		php_printf ("replace ######### %s\n", Z_STRVAL (rep.value.str));
		*/

		buf = php_pcre_replace (
				regex,
		  		subject,
				ZSTR_VAL (subject),
				ZSTR_LEN (subject),
#if PHP_VERSION_ID < 70200
				&rep, 0,
#else
				rep,
#endif
				-1, &repc
		);

#if PHP_VERSION_ID < 70200
		zval_ptr_dtor (&rep);
#else
		zend_string_release (rep);
#endif
		zend_string_release (regex);
		zend_string_release (subject);
	}


	sval = estrdup (ZSTR_VAL (buf));
	zend_string_release (buf);

	return sval;
} // }}}
Ejemplo n.º 7
0
#include "ext/standard/php_string.h"
#include "ext/standard/php_smart_str.h"

#include "php_air.h"

#include "src/air_exception.h"
#include "src/air_router.h"

zend_class_entry *air_router_ce;

char* air_router_compile(char *key, uint key_len, int *result_len TSRMLS_DC) {
	char *ret;
	zval *replace;
	MAKE_STD_ZVAL(replace);
	ZVAL_STRING(replace, "(?P<$2>$3)", 1);
	ret = php_pcre_replace(ZEND_STRL("#(<([^:]+):([^>]+)>)#"), key, key_len, replace, 0, result_len, -1, NULL TSRMLS_CC);
	zval_ptr_dtor(&replace);

	return ret;
}

ZEND_RESULT_CODE air_router_route_apply_subpats(zval *r, zval *subpats, char *key, int key_len, char *ro, int ro_len) {
	zval *tmp_val = air_arr_find(r, key, key_len);
	if(tmp_val){
		char *tmp = Z_STRVAL_P(tmp_val);
		if(tmp[0] == '$'){
			tmp_val = air_arr_find(subpats, tmp+1, strlen(tmp));
			if(tmp_val){
				add_assoc_stringl_ex(subpats, key, key_len, Z_STRVAL_P(tmp_val), Z_STRLEN_P(tmp_val), 1);
			}else{
				php_error(E_NOTICE, "ref name '%s' not found in route rule '%s', and 'index' will be set instead,", tmp,  ro);