示例#1
0
文件: zlib.c 项目: KomaBeyond/php-src
/* {{{ php_zlib_output_conflict_check() */
static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len TSRMLS_DC)
{
	if (php_output_get_level(TSRMLS_C) > 0) {
		if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME) TSRMLS_CC)
		||	php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_gzhandler") TSRMLS_CC)
		||  php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)
		||	php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("URL-Rewriter") TSRMLS_CC)) {
			return FAILURE;
		}
	}
	return SUCCESS;
}
示例#2
0
文件: output.c 项目: Myleft/cphalcon7
int phalcon_ob_get_level()
{
	return php_output_get_level();
}
示例#3
0
/* {{{ php_exec
 * If type==0, only last line of output is returned (exec)
 * If type==1, all lines will be printed and last lined returned (system)
 * If type==2, all lines will be saved to given array (exec with &$array)
 * If type==3, output will be printed binary, no lines will be saved or returned (passthru)
 *
 */
PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value)
{
	FILE *fp;
	char *buf;
	size_t l = 0;
	int pclose_return;
	char *b, *d=NULL;
	php_stream *stream;
	size_t buflen, bufl = 0;
#if PHP_SIGCHILD
	void (*sig_handler)() = NULL;
#endif

#if PHP_SIGCHILD
	sig_handler = signal (SIGCHLD, SIG_DFL);
#endif

#ifdef PHP_WIN32
	fp = VCWD_POPEN(cmd, "rb");
#else
	fp = VCWD_POPEN(cmd, "r");
#endif
	if (!fp) {
		php_error_docref(NULL, E_WARNING, "Unable to fork [%s]", cmd);
		goto err;
	}

	stream = php_stream_fopen_from_pipe(fp, "rb");

	buf = (char *) emalloc(EXEC_INPUT_BUF);
	buflen = EXEC_INPUT_BUF;

	if (type != 3) {
		b = buf;

		while (php_stream_get_line(stream, b, EXEC_INPUT_BUF, &bufl)) {
			/* no new line found, let's read some more */
			if (b[bufl - 1] != '\n' && !php_stream_eof(stream)) {
				if (buflen < (bufl + (b - buf) + EXEC_INPUT_BUF)) {
					bufl += b - buf;
					buflen = bufl + EXEC_INPUT_BUF;
					buf = erealloc(buf, buflen);
					b = buf + bufl;
				} else {
					b += bufl;
				}
				continue;
			} else if (b != buf) {
				bufl += b - buf;
			}

			if (type == 1) {
				PHPWRITE(buf, bufl);
				if (php_output_get_level() < 1) {
					sapi_flush();
				}
			} else if (type == 2) {
				/* strip trailing whitespaces */
				l = bufl;
				while (l >= 1 && l-- && isspace(((unsigned char *)buf)[l]));
				if (l != (bufl - 1)) {
					bufl = l + 1;
					buf[bufl] = '\0';
				}
				add_next_index_stringl(array, buf, bufl);
			}
			b = buf;
		}
		if (bufl) {
			/* strip trailing whitespaces if we have not done so already */
			if ((type == 2 && buf != b) || type != 2) {
				l = bufl;
				while (l >= 1 && l-- && isspace(((unsigned char *)buf)[l]));
				if (l != (bufl - 1)) {
					bufl = l + 1;
					buf[bufl] = '\0';
				}
				if (type == 2) {
					add_next_index_stringl(array, buf, bufl);
				}
			}

			/* Return last line from the shell command */
			RETVAL_STRINGL(buf, bufl);
		} else { /* should return NULL, but for BC we return "" */
			RETVAL_EMPTY_STRING();
		}
	} else {
		while((bufl = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) {
			PHPWRITE(buf, bufl);
		}
	}

	pclose_return = php_stream_close(stream);
	efree(buf);

done:
#if PHP_SIGCHILD
	if (sig_handler) {
		signal(SIGCHLD, sig_handler);
	}
#endif
	if (d) {
		efree(d);
	}
	return pclose_return;
err:
	pclose_return = -1;
	goto done;
}
示例#4
0
PHP_METHOD(imageObj, saveImage)
{
    zval *zobj = getThis();
    zval *zmap = NULL;
    char *filename = NULL;
    long filename_len = 0;
    php_image_object *php_image;
    php_map_object *php_map;
    int status = MS_SUCCESS;
    /* stdout specific vars */
    int size=0;
    void *iptr=NULL;

    PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO",
                              &filename, &filename_len,
                              &zmap, mapscript_ce_map) == FAILURE) {
        PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
        return;
    }
    PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);

    php_image = (php_image_object *) zend_object_store_get_object(zobj TSRMLS_CC);
    if (zmap)
        php_map = (php_map_object *) zend_object_store_get_object(zmap TSRMLS_CC);

    if(filename_len > 0)
    {
        if ((status = msSaveImage((zmap ? php_map->map:NULL), php_image->image, filename) != MS_SUCCESS))
        {
            mapscript_throw_mapserver_exception("Failed writing image to %s" TSRMLS_CC, filename);
            return;
        }

        RETURN_LONG(status);
    }

    /* no filename - read stdout */

    /* if there is no output buffer active, set the header */
    //handle changes in PHP 5.4.x
    #if PHP_VERSION_ID < 50399
      if (OG(ob_nesting_level)<=0)
      {
          php_header(TSRMLS_C);
      }
    #else
      if (php_output_get_level(TSRMLS_C)<=0)
      {
          php_header(TSRMLS_C);
      }
    #endif

    if (MS_RENDERER_PLUGIN(php_image->image->format))
    {
        iptr = (void *)msSaveImageBuffer(php_image->image, &size, php_image->image->format);
    }
    else if (php_image->image->format->name && (strcasecmp(php_image->image->format->name, "imagemap")==0))
    {
        iptr = php_image->image->img.imagemap;
        size = strlen(php_image->image->img.imagemap);
    }

    if (size == 0) {
        mapscript_throw_mapserver_exception("Failed writing image to stdout" TSRMLS_CC);
        return;
    }
    else
    {
        php_write(iptr, size TSRMLS_CC);
        status = MS_SUCCESS;
        /* status = size;  why should we return the size ?? */
        msFree(iptr);
    }

    RETURN_LONG(status);
}