Exemplo n.º 1
0
ZEND_API size_t zend_extensions_op_array_persist(zend_op_array *op_array, void *mem)
{
	if (zend_extension_flags & ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST) {
		zend_extension_persist_data data;

		data.op_array = op_array;
		data.size = 0;
		data.mem  = mem;
		zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_persist_handler, &data);
		return data.size;
	}
	return 0;
}
Exemplo n.º 2
0
SAPI_API int sapi_send_headers(void)
{
	int retval;
	int ret = FAILURE;

	if (SG(headers_sent) || SG(request_info).no_headers) {
		return SUCCESS;
	}

	/* Success-oriented.  We set headers_sent to 1 here to avoid an infinite loop
	 * in case of an error situation.
	 */
	if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) {
	    uint32_t len = 0;
		char *default_mimetype = get_default_content_type(0, &len);

		if (default_mimetype && len) {
			sapi_header_struct default_header;

			SG(sapi_headers).mimetype = default_mimetype;

			default_header.header_len = sizeof("Content-type: ") - 1 + len;
			default_header.header = emalloc(default_header.header_len + 1);

			memcpy(default_header.header, "Content-type: ", sizeof("Content-type: ") - 1);
			memcpy(default_header.header + sizeof("Content-type: ") - 1, SG(sapi_headers).mimetype, len + 1);
			
			sapi_header_add_op(SAPI_HEADER_ADD, &default_header);
		} else {
			efree(default_mimetype);
		}
		SG(sapi_headers).send_default_content_type = 0;
	}

	if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
		zval cb;
		ZVAL_COPY_VALUE(&cb, &SG(callback_func));
		ZVAL_UNDEF(&SG(callback_func));
		sapi_run_header_callback(&cb);
		zval_ptr_dtor(&cb);
	}

	SG(headers_sent) = 1;

	if (sapi_module.send_headers) {
		retval = sapi_module.send_headers(&SG(sapi_headers));
	} else {
		retval = SAPI_HEADER_DO_SEND;
	}

	switch (retval) {
		case SAPI_HEADER_SENT_SUCCESSFULLY:
			ret = SUCCESS;
			break;
		case SAPI_HEADER_DO_SEND: {
				sapi_header_struct http_status_line;
				char buf[255];

				if (SG(sapi_headers).http_status_line) {
					http_status_line.header = SG(sapi_headers).http_status_line;
					http_status_line.header_len = (uint32_t)strlen(SG(sapi_headers).http_status_line);
				} else {
					http_status_line.header = buf;
					http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
				}
				sapi_module.send_header(&http_status_line, SG(server_context));
			}
			zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context));
			if(SG(sapi_headers).send_default_content_type) {
				sapi_header_struct default_header;

				sapi_get_default_content_type_header(&default_header);
				sapi_module.send_header(&default_header, SG(server_context));
				sapi_free_header(&default_header);
			}
			sapi_module.send_header(NULL, SG(server_context));
			ret = SUCCESS;
			break;
		case SAPI_HEADER_SEND_FAILED:
			SG(headers_sent) = 0;
			ret = FAILURE;
			break;
	}

	sapi_send_headers_free();

	return ret;
}
Exemplo n.º 3
0
void php_run_ticks(int count)
{
	zend_llist_apply_with_argument(&PG(tick_functions), (llist_apply_with_arg_func_t) php_tick_iterator, &count);
}