/* {{{ HELPER FUNCTIONS */
static void php_filter_encode_html(zval *value, const unsigned char *chars)
{
	smart_str str = {0};
	int len = Z_STRLEN_P(value);
	unsigned char *s = (unsigned char *)Z_STRVAL_P(value);
	unsigned char *e = s + len;

	if (Z_STRLEN_P(value) == 0) {
		return;
	}

	while (s < e) {
		if (chars[*s]) {
			smart_str_appendl(&str, "&#", 2);
			smart_str_append_unsigned(&str, (unsigned long)*s);
			smart_str_appendc(&str, ';');
		} else {
			/* XXX: this needs to be optimized to work with blocks of 'safe' chars */
			smart_str_appendc(&str, *s);
		}
		s++;
	}

	smart_str_0(&str);
	str_efree(Z_STRVAL_P(value));
	Z_STRVAL_P(value) = str.c;
	Z_STRLEN_P(value) = str.len;
}
Пример #2
0
/* {{{ proto bool SessionHandler::read(string id)
   Wraps the old read handler */
PHP_METHOD(SessionHandler, read)
{
    char *key, *val;
    int key_len, val_len;

    PS_SANITY_CHECK_IS_OPEN;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) {
        return;
    }

    if (PS(default_mod)->s_read(&PS(mod_data), key, &val, &val_len TSRMLS_CC) == FAILURE) {
        RETVAL_FALSE;
        return;
    }

    RETVAL_STRINGL(val, val_len, 1);
    str_efree(val);
    return;
}
Пример #3
0
ZEND_API void zend_indent()
{
	zval token;
	int token_type;
	int in_string=0;
	int nest_level=0;
	int emit_whitespace[256];
	int i;
	TSRMLS_FETCH();

	memset(emit_whitespace, 0, sizeof(int)*256);

	/* highlight stuff coming back from zendlex() */
	token.type = 0;
	while ((token_type=lex_scan(&token TSRMLS_CC))) {
		switch (token_type) {
			case T_INLINE_HTML:
				zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
				break;
			case T_WHITESPACE: {
					token.type = 0;
					/* eat whitespace, emit newlines */
					for (i=0; i<LANG_SCNG(yy_leng); i++) {
						emit_whitespace[(unsigned char) LANG_SCNG(yy_text)[i]]++;
					}
					continue;
				}
				break;
			case '"':
				in_string = !in_string;
				/* break missing intentionally */
			default:
				if (token.type==0) {
					/* keyword */
					switch (token_type) {
						case ',':
							ZEND_PUTS(", ");
							goto dflt_printout;
							break;
						case '{':
							nest_level++;
							if (emit_whitespace['\n']>0) {
								ZEND_PUTS(" {\n");
								memset(emit_whitespace, 0, sizeof(int)*256);
							} else {
								ZEND_PUTS("{");
							}
							break;
						case '}':
							nest_level--;
							if (emit_whitespace['\n']==0) {
								ZEND_PUTS("\n");
							}
							for (i=0; i<nest_level; i++) {
								ZEND_PUTS("    ");
							}
							goto dflt_printout;
							break;
dflt_printout:
						default:
							if (emit_whitespace['\n']>0) {
								for (i=0; i<emit_whitespace['\n']; i++) {
									ZEND_PUTS("\n");
								}
								memset(emit_whitespace, 0, sizeof(int)*256);
								for (i=0; i<nest_level; i++) {
									ZEND_PUTS("    ");
								}
							} else {
								handle_whitespace(emit_whitespace);
							}
							zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
							break;
					}
				} else {
					handle_whitespace(emit_whitespace);
					if (in_string) {
						zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
						/* a part of a string */
					} else {
						zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
					}
				}
				break;
		}
		if (token.type == IS_STRING) {
			switch (token_type) {
			case T_OPEN_TAG:
			case T_CLOSE_TAG:
			case T_WHITESPACE:
				break;
			default:
				str_efree(token.value.str.val);
				break;
			}
		}
		token.type = 0;
	}
}