/********************************************************************** * $Id$ * * Project: MapServer * Purpose: PHP/MapScript extension for MapServer. External interface * functions * Author: Daniel Morissette, DM Solutions Group (dmorissette@dmsolutions.ca) * ********************************************************************** * Copyright (c) 2000-2005, Daniel Morissette, DM Solutions Group Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies of this Software or works derived from this Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. **********************************************************************/ #include "php_mapscript.h" #include "php_mapscript_util.h" #include "php.h" #include "php_globals.h" #include "SAPI.h" #include "ext/standard/info.h" #include "ext/standard/head.h" #include "../../maperror.h" #include #if defined(_WIN32) && !defined(__CYGWIN__) #include #else #include #endif /* All gd functions used in this extension (if they are renamed in the "main/php_compat.h" file of php source) should be added here too for compatibility reasons: when php compiles gd as a shared extention */ #if defined(HAVE_GD_BUNDLED) #undef gdImageColorExact #undef gdImageColorTransparent #undef gdImageCopy #endif #ifndef DLEXPORT #define DLEXPORT ZEND_DLEXPORT #endif //#if defined(_WIN32) && !defined(__CYGWIN__) //void ***tsrm_ls; //#endif zend_object_handlers mapscript_std_object_handlers; ZEND_BEGIN_ARG_INFO_EX(ms_newShapeObj_args, 0, 0, 1) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_shapeObjFromWkt_args, 0, 0, 1) ZEND_ARG_INFO(0, wkt) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newShapeFileObj_args, 0, 0, 2) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newMapObj_args, 0, 0, 1) ZEND_ARG_INFO(0, mapFileName) ZEND_ARG_INFO(0, newMapPath) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newMapObjFromString_args, 0, 0, 1) ZEND_ARG_INFO(0, mapFileString) ZEND_ARG_INFO(0, newMapPath) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newLayerObj_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, map, mapObj, 0) ZEND_ARG_OBJ_INFO(0, layer, layerObj, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newProjectionObj_args, 0, 0, 1) ZEND_ARG_INFO(0, projString) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newStyleObj_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, class, classObj, 0) ZEND_ARG_OBJ_INFO(0, style, styleObj, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newClassObj_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, layer, layerObj, 0) ZEND_ARG_OBJ_INFO(0, class, classObj, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newSymbolObj_args, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, map, mapObj, 0) ZEND_ARG_INFO(0, symbolName) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ms_newGridObj_args, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, layer, layerObj, 0) ZEND_END_ARG_INFO() /* {{{ proto mapObj ms_newMapObj(string mapFileName, newMapPath) Create a new mapObj instance. */ PHP_FUNCTION(ms_newMapObj) { char *filename; long filename_len = 0; char *path = NULL; long path_len = 0; mapObj *map = NULL; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &filename, &filename_len, &path, &path_len) == FAILURE) { return; PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); map = mapObj_new(filename, path); if (map == NULL) { mapscript_throw_mapserver_exception("Failed to open map file \"%s\", or map file error." TSRMLS_CC, filename); return; } mapscript_create_map(map, return_value TSRMLS_CC); } /* }}} */ /* {{{ proto mapObj ms_newMapObj(string mapFileString, newMapPath) Create a new mapObj instance. */ PHP_FUNCTION(ms_newMapObjFromString) { char *string; long string_len = 0; char *path = NULL; long path_len = 0; mapObj *map = NULL; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &string, &string_len, &path, &path_len) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); map = mapObj_newFromString(string, path); if (map == NULL) { mapscript_throw_mapserver_exception("Error while loading map file from string." TSRMLS_CC); return; } mapscript_create_map(map, return_value TSRMLS_CC); } /* }}} */ /* {{{ proto layerObj ms_newLayerObj(mapObj map [, layerObj layer]) Create a new layerObj instance. */ PHP_FUNCTION(ms_newLayerObj) { zval *zmap, *zlayer = NULL; layerObj *layer; int index; php_map_object *php_map; php_layer_object *php_layer = NULL; parent_object parent; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O", &zmap, mapscript_ce_map, &zlayer, mapscript_ce_layer) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_map = MAPSCRIPT_OBJ_P(php_map_object, zmap); if (zlayer) php_layer = MAPSCRIPT_OBJ_P(php_layer_object, zlayer); if ((layer = layerObj_new(php_map->map)) == NULL) { mapscript_throw_mapserver_exception("" TSRMLS_CC); return; } /* if a layer is passed as argument, copy the layer into the new one */ if (zlayer) { index = layer->index; msCopyLayer(layer, php_layer->layer); layer->index = index; } MAPSCRIPT_MAKE_PARENT(zmap, NULL); mapscript_create_layer(layer, parent, return_value TSRMLS_CC); } /* }}} */ /* {{{ proto projectionObj ms_newProjectionObj(string projString) Create a new projectionObj instance. */ PHP_FUNCTION(ms_newProjectionObj) { char *projString; long projString_len = 0; projectionObj *projection = NULL; parent_object parent; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &projString, &projString_len) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); if ((projection = projectionObj_new(projString)) == NULL) { mapscript_throw_mapserver_exception("Unable to construct projectionObj." TSRMLS_CC); return; } MAPSCRIPT_MAKE_PARENT(NULL, NULL); mapscript_create_projection(projection, parent, return_value TSRMLS_CC); } /* }}} */ /* {{{ proto rectObj ms_newRectObj() Create a new rectObj instance. */ PHP_FUNCTION(ms_newRectObj) { php_rect_object * php_rect; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); object_init_ex(return_value, mapscript_ce_rect); php_rect = MAPSCRIPT_OBJ_P(php_rect_object, return_value); if ((php_rect->rect = rectObj_new()) == NULL) { mapscript_throw_exception("Unable to construct rectObj." TSRMLS_CC); return; } } /* }}} */ /* {{{ proto pointObj ms_newPointObj() Create a new pointObj instance. */ PHP_FUNCTION(ms_newPointObj) { pointObj *point = NULL; parent_object parent; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); if ((point = pointObj_new()) == NULL) { mapscript_throw_mapserver_exception("Unable to construct pointObj." TSRMLS_CC); return; } point->x = 0; point->y = 0; #ifdef USE_POINT_Z_M point->z = 0; point->m = 0; #endif /* Return point object */ MAPSCRIPT_MAKE_PARENT(NULL, NULL); mapscript_create_point(point, parent, return_value TSRMLS_CC); } /* {{{ proto lineObj ms_newLineObj() Create a new lineObj instance. */ PHP_FUNCTION(ms_newLineObj) { php_line_object * php_line; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); object_init_ex(return_value, mapscript_ce_line); php_line = MAPSCRIPT_OBJ_P(php_line_object, return_value); if ((php_line->line = lineObj_new()) == NULL) { mapscript_throw_exception("Unable to construct lineObj." TSRMLS_CC); return; } } /* }}} */ /* {{{ proto styleObj __construct(classObj class [, styleObj style]) Create a new styleObj instance */ PHP_FUNCTION(ms_newStyleObj) { zval *zclass, *zstyle = NULL; styleObj *style; php_class_object *php_class; php_style_object *php_style; parent_object parent; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O", &zclass, mapscript_ce_class, &zstyle, mapscript_ce_style) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_class = MAPSCRIPT_OBJ_P(php_class_object, zclass); if (zstyle) php_style = MAPSCRIPT_OBJ_P(php_style_object, zstyle); if ((style = styleObj_new(php_class->class, (zstyle ? php_style->style : NULL))) == NULL) { mapscript_throw_mapserver_exception("" TSRMLS_CC); return; } /* Return point object */ MAPSCRIPT_MAKE_PARENT(zclass, NULL); mapscript_create_style(style, parent, return_value TSRMLS_CC); } /* {{{ proto classObj ms_newClassObj(layerObj layer [, classObj class]) Create a new class instance in the specified layer.. */ PHP_FUNCTION(ms_newClassObj) { zval *zlayer, *zclass = NULL; classObj *class; php_layer_object *php_layer; php_class_object *php_class; parent_object parent; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O", &zlayer, mapscript_ce_layer, &zclass, mapscript_ce_class) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_layer = MAPSCRIPT_OBJ_P(php_layer_object, zlayer); if (zclass) php_class = MAPSCRIPT_OBJ_P(php_class_object, zclass); if ((class = classObj_new(php_layer->layer, (zclass ? php_class->class:NULL))) == NULL) { mapscript_throw_mapserver_exception("" TSRMLS_CC); return; } MAPSCRIPT_MAKE_PARENT(zlayer, NULL); mapscript_create_class(class, parent, return_value TSRMLS_CC); } /* }}} */ /* {{{ proto int ms_newSymbolObj(mapObj map, string symbolName) Create a new symbolObj instance and return its index. */ PHP_FUNCTION(ms_newSymbolObj) { zval *zmap; char *symbolName; long symbolName_len = 0; int retval = 0; php_map_object *php_map; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &zmap, mapscript_ce_map, &symbolName, &symbolName_len) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_map = MAPSCRIPT_OBJ_P(php_map_object, zmap); retval = msAddNewSymbol(php_map->map, symbolName); RETURN_LONG(retval); } /* }}} */ /* {{{ proto shapeObj ms_newShapeObj(int type) Create a new shapeObj instance. */ PHP_FUNCTION(ms_newShapeObj) { php_shape_object * php_shape; long type; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); object_init_ex(return_value, mapscript_ce_shape); php_shape = MAPSCRIPT_OBJ_P(php_shape_object, return_value); if ((php_shape->shape = shapeObj_new(type)) == NULL) { mapscript_throw_exception("Unable to construct shapeObj." TSRMLS_CC); return; } MAKE_STD_ZVAL(php_shape->values); mapscript_array_init(php_shape->values); } /* }}} */ /* {{{ proto shapeObj shapeObjFromWkt(string type) Creates new shape object from WKT string. */ PHP_FUNCTION(ms_shapeObjFromWkt) { php_shape_object * php_shape; char *wkt; long str_len = 0; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &wkt, &str_len) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); object_init_ex(return_value, mapscript_ce_shape); php_shape = MAPSCRIPT_OBJ_P(php_shape_object, return_value); if ((php_shape->shape = msShapeFromWKT(wkt)) == NULL) { mapscript_throw_exception("Unable to construct shapeObj." TSRMLS_CC); return; } MAKE_STD_ZVAL(php_shape->values); mapscript_array_init(php_shape->values); } /* }}} */ /* {{{ proto shapefile ms_newShapeFileObj(string filename, int type) Create a new shapeFileObj instance. */ PHP_FUNCTION(ms_newShapeFileObj) { char *filename; long filename_len = 0; long type; shapefileObj *shapefile; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &filename, &filename_len, &type) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); shapefile = shapefileObj_new(filename, type); if (shapefile == NULL) { mapscript_throw_mapserver_exception("Failed to open shapefile %s" TSRMLS_CC, filename); return; } mapscript_create_shapefile(shapefile, return_value TSRMLS_CC); } /* }}} */ PHP_FUNCTION(ms_newOWSRequestObj) { cgiRequestObj *request; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); if ((request = cgirequestObj_new()) == NULL) { mapscript_throw_mapserver_exception("" TSRMLS_CC); return; } /* Return owsrequest object */ mapscript_create_owsrequest(request, return_value TSRMLS_CC); } /* {{{ proto gridObj ms_newGridObj(layerObj layer) Create a new intance of gridObj. */ PHP_FUNCTION(ms_newGridObj) { zval *zlayer; php_layer_object *php_layer; php_grid_object *php_grid; parent_object parent; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zlayer, mapscript_ce_layer) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_layer = MAPSCRIPT_OBJ_P(php_layer_object, zlayer); php_layer->layer->connectiontype = MS_GRATICULE; if (php_layer->layer->grid != NULL) { freeGrid(php_layer->layer->grid); free(php_layer->layer->grid); } php_layer->layer->grid = (graticuleObj *)malloc( sizeof( graticuleObj ) ); initGrid(php_layer->layer->grid); if (ZVAL_NOT_UNDEF(php_layer->grid) && (MAPSCRIPT_TYPE(php_layer->grid) == IS_OBJECT)) { php_grid = MAPSCRIPT_OBJ(php_grid_object, php_layer->grid); php_grid->parent.child_ptr = NULL; #if PHP_VERSION_ID < 70000 zend_objects_store_del_ref(php_layer->grid TSRMLS_CC); #else MAPSCRIPT_DELREF(php_layer->grid); #endif } MAKE_STD_ZVAL(php_layer->grid); MAPSCRIPT_MAKE_PARENT(zlayer, &php_layer->grid); #if PHP_VERSION_ID < 70000 mapscript_create_grid((graticuleObj *)(php_layer->layer->grid), parent, php_layer->grid TSRMLS_CC); zend_objects_store_add_ref(php_layer->grid TSRMLS_CC); *return_value = *(php_layer->grid); #else mapscript_create_grid((graticuleObj *)(php_layer->layer->grid), parent, &php_layer->grid TSRMLS_CC); ZVAL_COPY_VALUE(return_value, &php_layer->grid); #endif } /* }}} */ /* {{{ proto errorObj ms_GetErrorObj() Return the head of the MapServer errorObj list. */ PHP_FUNCTION(ms_GetErrorObj) { errorObj *error; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); if ((error = msGetErrorObj()) == NULL) { mapscript_throw_mapserver_exception("" TSRMLS_CC); return; } /* Return error object */ mapscript_create_error(error, return_value TSRMLS_CC); } /* }}} */ /* {{{ proto errorObj ms_ResetErrorList() Clear the MapServer errorObj list. */ PHP_FUNCTION(ms_ResetErrorList) { msResetErrorList(); } /* }} */ /*===================================================================== * PHP function wrappers *====================================================================*/ /************************************************************************/ /* ms_VetVersion() */ /* */ /* Returns a string with MapServer version and configuration */ /* params. */ /************************************************************************/ PHP_FUNCTION(ms_GetVersion) { PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); MAPSCRIPT_RETURN_STRING(msGetVersion(), 1); } /************************************************************************/ /* ms_GetVersionInt() */ /* */ /* Returns the MapServer version in int format. */ /* Given version x.y.z, returns x*0x10000+y*0x100+z */ /************************************************************************/ PHP_FUNCTION(ms_GetVersionInt) { PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); RETURN_LONG(msGetVersionInt()); } /* ==================================================================== */ /* utility functions related to msio */ /* ==================================================================== */ PHP_FUNCTION(ms_ioInstallStdoutToBuffer) { msIO_installStdoutToBuffer(); RETURN_TRUE; } PHP_FUNCTION(ms_ioResetHandlers) { msIO_resetHandlers(); RETURN_TRUE; } PHP_FUNCTION(ms_ioInstallStdinFromBuffer) { msIO_installStdinFromBuffer(); RETURN_TRUE; } PHP_FUNCTION(ms_ioGetStdoutBufferString) { char *buffer; msIOContext *ctx = msIO_getHandler( (FILE *) "stdout" ); msIOBuffer *buf; if(ctx == NULL || ctx->write_channel == MS_FALSE || strcmp(ctx->label,"buffer") != 0 ) { php_error(E_ERROR, "Can't identify msIO buffer"); RETURN_FALSE; } buf = (msIOBuffer *) ctx->cbData; /* write one zero byte and backtrack if it isn't already there */ if( buf->data_len == 0 || buf->data[buf->data_offset] != '\0' ) { msIO_bufferWrite( buf, "", 1 ); buf->data_offset--; } buffer = (char *) (buf->data); MAPSCRIPT_RETURN_STRINGL(buffer, buf->data_offset, 1); } typedef struct { unsigned char *data; int size; int owns_data; } gdBuffer; PHP_FUNCTION(ms_ioGetStdoutBufferBytes) { msIOContext *ctx = msIO_getHandler( (FILE *) "stdout" ); msIOBuffer *buf; gdBuffer gdBuf; if( ctx == NULL || ctx->write_channel == MS_FALSE || strcmp(ctx->label,"buffer") != 0 ) { php_error(E_ERROR, "Can't identify msIO buffer"); RETURN_FALSE; } buf = (msIOBuffer *) ctx->cbData; gdBuf.data = buf->data; gdBuf.size = buf->data_offset; gdBuf.owns_data = MS_FALSE; /* we are seizing ownership of the buffer contents */ buf->data_offset = 0; buf->data_len = 0; buf->data = NULL; php_write(gdBuf.data, gdBuf.size TSRMLS_CC); /* return the gdBuf.size, which is the "really used length" of the msIOBuffer */ RETURN_LONG(gdBuf.size); } PHP_FUNCTION(ms_ioStripStdoutBufferContentType) { const char *buf = NULL; buf = msIO_stripStdoutBufferContentType(); if (buf) { MAPSCRIPT_RETURN_STRING((char *)buf, 1); } else { RETURN_FALSE; } } PHP_FUNCTION(ms_ioGetAndStripStdoutBufferMimeHeaders) { hashTableObj *hashtable; char *value, *key = NULL; if((hashtable = msIO_getAndStripStdoutBufferMimeHeaders())) { array_init(return_value); while((key = hashTableObj_nextKey(hashtable, key))) { value = (char *) hashTableObj_get(hashtable, key); #if PHP_VERSION_ID < 70000 add_assoc_string(return_value, key, value, 1); #else add_assoc_string(return_value, key, value); #endif } free(hashtable); } else RETURN_FALSE; } PHP_FUNCTION(ms_ioStripStdoutBufferContentHeaders) { msIO_stripStdoutBufferContentHeaders(); } /* ==================================================================== */ /* utility functions */ /* ==================================================================== */ /************************************************************************/ /* void ms_getcwd */ /* */ /* This function is a copy of the */ /* vod php3_posix_getcwd(INTERNAL_FUNCTION_PARAMETERS) */ /* (./php/functions/posix.c). */ /* */ /* Since posix functions seems to not be standard in php, It has been*/ /* added here. */ /************************************************************************/ /* OS/2's gcc defines _POSIX_PATH_MAX but not PATH_MAX */ #if !defined(PATH_MAX) && defined(_POSIX_PATH_MAX) #define PATH_MAX _POSIX_PATH_MAX #endif #if !defined(PATH_MAX) && defined(MAX_PATH) #define PATH_MAX MAX_PATH #endif #if !defined(PATH_MAX) #define PATH_MAX 512 #endif PHP_FUNCTION(ms_getCwd) { char buffer[PATH_MAX]; char *p; p = getcwd(buffer, PATH_MAX); if (!p) { //php3_error(E_WARNING, "posix_getcwd() failed with '%s'", // strerror(errno)); RETURN_FALSE; } MAPSCRIPT_RETURN_STRING(buffer, 1); } PHP_FUNCTION(ms_getPid) { RETURN_LONG(getpid()); } /************************************************************************/ /* DLEXPORT void php3_ms_getscale(INTERNAL_FUNCTION_PARAMETERS) */ /* */ /* Utility function to get the scale based on the width/height */ /* of the pixmap, the georeference and the units of the data. */ /* */ /* Parameters are : */ /* */ /* - Georefernce extents (rectObj) */ /* - Width : width in pixel */ /* - Height : Height in pixel */ /* - Units of the data (int) */ /* */ /* */ /************************************************************************/ PHP_FUNCTION(ms_getScale) { zval *zgeoRefExt = NULL; long width, height,unit; double resolution; php_rect_object *php_geoRefExt; double dfScale = 0.0; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ollld", &zgeoRefExt, mapscript_ce_rect, &width, &height, &unit, &resolution) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_geoRefExt = MAPSCRIPT_OBJ_P(php_rect_object, zgeoRefExt); if (msCalculateScale(*(php_geoRefExt->rect), unit, width, height, resolution, &dfScale) != MS_SUCCESS) { mapscript_throw_mapserver_exception("" TSRMLS_CC); return; } RETURN_DOUBLE(dfScale); } /********************************************************************** * ms_tokenizeMap() * * Preparse mapfile and return an array containg one item for each * token in the map. **********************************************************************/ /* {{{ proto array ms_tokenizeMap(string filename) Preparse mapfile and return an array containg one item for each token in the map.*/ PHP_FUNCTION(ms_tokenizeMap) { char *filename; long filename_len = 0; char **tokens; int i, numtokens=0; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); if ((tokens = msTokenizeMap(filename, &numtokens)) == NULL) { mapscript_throw_mapserver_exception("Failed tokenizing map file %s" TSRMLS_CC, filename); return; } else { array_init(return_value); for (i=0; i