PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/mapscript/php/error.c

https://github.com/smcmurray/mapserver
C | 198 lines | 126 code | 33 blank | 39 comment | 17 complexity | 5c35dd4352b4f78f29bb15ffad7544ad MD5 | raw file
  1. /**********************************************************************
  2. * $Id: php_mapscript.c 9765 2010-01-28 15:32:10Z aboudreault $
  3. *
  4. * Project: MapServer
  5. * Purpose: PHP/MapScript extension for MapServer. External interface
  6. * functions
  7. * Author: Daniel Morissette, DM Solutions Group (dmorissette@dmsolutions.ca)
  8. * Alan Boudreault, Mapgears
  9. *
  10. **********************************************************************
  11. * Copyright (c) 2000-2010, Daniel Morissette, DM Solutions Group Inc.
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in
  21. * all copies of this Software or works derived from this Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. * DEALINGS IN THE SOFTWARE.
  30. **********************************************************************/
  31. #include "php_mapscript.h"
  32. zend_class_entry *mapscript_ce_error;
  33. ZEND_BEGIN_ARG_INFO_EX(error___get_args, 0, 0, 1)
  34. ZEND_ARG_INFO(0, property)
  35. ZEND_END_ARG_INFO()
  36. ZEND_BEGIN_ARG_INFO_EX(error___set_args, 0, 0, 2)
  37. ZEND_ARG_INFO(0, property)
  38. ZEND_ARG_INFO(0, value)
  39. ZEND_END_ARG_INFO()
  40. /* {{{ proto error __construct()
  41. errorObj CANNOT be instanciated, this will throw an exception on use */
  42. PHP_METHOD(errorObj, __construct)
  43. {
  44. mapscript_throw_exception("errorObj cannot be constructed" TSRMLS_CC);
  45. }
  46. /* }}} */
  47. PHP_METHOD(errorObj, __get)
  48. {
  49. char *property;
  50. long property_len = 0;
  51. zval *zobj = getThis();
  52. php_error_object *php_error;
  53. PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
  54. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
  55. &property, &property_len) == FAILURE) {
  56. PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
  57. return;
  58. }
  59. PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
  60. php_error = (php_error_object *) zend_object_store_get_object(zobj TSRMLS_CC);
  61. IF_GET_LONG("code", php_error->error->code)
  62. else IF_GET_STRING("routine", php_error->error->routine)
  63. else IF_GET_STRING("message", php_error->error->message)
  64. else IF_GET_LONG("isreported", php_error->error->isreported)
  65. else {
  66. mapscript_throw_exception("Property '%s' does not exist in this object." TSRMLS_CC, property);
  67. }
  68. }
  69. PHP_METHOD(errorObj, __set)
  70. {
  71. char *property;
  72. long property_len = 0;
  73. zval *value;
  74. zval *zobj = getThis();
  75. php_error_object *php_error;
  76. PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
  77. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
  78. &property, &property_len, &value) == FAILURE) {
  79. PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
  80. return;
  81. }
  82. PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
  83. php_error = (php_error_object *) zend_object_store_get_object(zobj TSRMLS_CC);
  84. if ( (STRING_EQUAL("code", property)) ||
  85. (STRING_EQUAL("routine", property)) ||
  86. (STRING_EQUAL("isreported", property)) ||
  87. (STRING_EQUAL("message", property))) {
  88. mapscript_throw_exception("Property '%s' is read-only and cannot be set." TSRMLS_CC, property);
  89. } else {
  90. mapscript_throw_exception("Property '%s' does not exist in this object." TSRMLS_CC, property);
  91. }
  92. }
  93. /* {{{ proto int error.next()
  94. Returns a ref to the next errorObj in the list, or NULL if we reached the last one */
  95. PHP_METHOD(errorObj, next)
  96. {
  97. zval *zobj = getThis();
  98. php_error_object *php_error;
  99. errorObj *error = NULL;
  100. PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
  101. if (zend_parse_parameters_none() == FAILURE) {
  102. PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
  103. return;
  104. }
  105. PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
  106. php_error = (php_error_object *) zend_object_store_get_object(zobj TSRMLS_CC);
  107. if (php_error->error->next == NULL)
  108. RETURN_NULL();
  109. /* Make sure 'self' is still valid. It may have been deleted by
  110. * msResetErrorList() */
  111. error = msGetErrorObj();
  112. while(error != php_error->error) {
  113. if (error->next == NULL) {
  114. mapscript_throw_exception("Trying to access an errorObj that has expired." TSRMLS_CC);
  115. return;
  116. }
  117. error = error->next;
  118. }
  119. php_error->error = php_error->error->next;
  120. *return_value = *zobj;
  121. zval_copy_ctor(return_value);
  122. INIT_PZVAL(return_value);
  123. }
  124. /* }}} */
  125. zend_function_entry error_functions[] = {
  126. PHP_ME(errorObj, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
  127. PHP_ME(errorObj, __get, error___get_args, ZEND_ACC_PUBLIC)
  128. PHP_ME(errorObj, __set, error___set_args, ZEND_ACC_PUBLIC)
  129. PHP_ME(errorObj, next, NULL, ZEND_ACC_PUBLIC) {
  130. NULL, NULL, NULL
  131. }
  132. };
  133. void mapscript_create_error(errorObj *error, zval *return_value TSRMLS_DC)
  134. {
  135. php_error_object * php_error;
  136. object_init_ex(return_value, mapscript_ce_error);
  137. php_error = (php_error_object *)zend_object_store_get_object(return_value TSRMLS_CC);
  138. php_error->error = error;
  139. }
  140. static void mapscript_error_object_destroy(void *object TSRMLS_DC)
  141. {
  142. php_error_object *php_error = (php_error_object *)object;
  143. MAPSCRIPT_FREE_OBJECT(php_error);
  144. /* We don't need to free the errorObj */
  145. efree(object);
  146. }
  147. static zend_object_value mapscript_error_object_new(zend_class_entry *ce TSRMLS_DC)
  148. {
  149. zend_object_value retval;
  150. php_error_object *php_error;
  151. MAPSCRIPT_ALLOC_OBJECT(php_error, php_error_object);
  152. retval = mapscript_object_new(&php_error->std, ce,
  153. &mapscript_error_object_destroy TSRMLS_CC);
  154. return retval;
  155. }
  156. PHP_MINIT_FUNCTION(error)
  157. {
  158. zend_class_entry ce;
  159. MAPSCRIPT_REGISTER_CLASS("errorObj",
  160. error_functions,
  161. mapscript_ce_error,
  162. mapscript_error_object_new);
  163. mapscript_ce_error->ce_flags |= ZEND_ACC_FINAL_CLASS;
  164. return SUCCESS;
  165. }