You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
5.0 KiB

  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP version 4.0 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license/2_02.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Kristian Koehntopp <kris@koehntopp.de> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. /* {{{ includes & prototypes */
  20. #include "php.h"
  21. #include "php_recode.h"
  22. #if HAVE_LIBRECODE
  23. #include "ext/standard/info.h"
  24. #include "ext/standard/file.h"
  25. #include "ext/standard/php_string.h"
  26. #include "zend_list.h"
  27. #ifdef HAVE_BROKEN_RECODE
  28. extern char *program_name;
  29. char *program_name = "php";
  30. #endif
  31. /* }}} */
  32. #define SAFE_STRING(s) ((s)?(s):"")
  33. php_recode_globals recode_globals;
  34. extern int le_fp,le_pp;
  35. /* {{{ module stuff */
  36. static zend_function_entry php_recode_functions[] = {
  37. PHP_FE(recode_string, NULL)
  38. PHP_FE(recode_file, NULL)
  39. PHP_FALIAS(recode, recode_string, NULL)
  40. {NULL, NULL, NULL}
  41. };
  42. zend_module_entry recode_module_entry = {
  43. "Recode",
  44. php_recode_functions,
  45. PHP_MINIT(recode),
  46. PHP_MSHUTDOWN(recode),
  47. NULL,
  48. NULL,
  49. PHP_MINFO(recode),
  50. STANDARD_MODULE_PROPERTIES
  51. };
  52. #if APACHE
  53. extern void timeout(int sig);
  54. #endif
  55. #ifdef COMPILE_DL_RECODE
  56. ZEND_GET_MODULE(recode)
  57. #endif
  58. PHP_MINIT_FUNCTION(recode)
  59. {
  60. ReSLS_FETCH();
  61. ReSG(outer) = recode_new_outer(true);
  62. if (ReSG(outer) == NULL)
  63. return FAILURE;
  64. return SUCCESS;
  65. }
  66. PHP_MSHUTDOWN_FUNCTION(recode)
  67. {
  68. ReSLS_FETCH();
  69. if (ReSG(outer))
  70. recode_delete_outer(ReSG(outer));
  71. return SUCCESS;
  72. }
  73. PHP_MINFO_FUNCTION(recode)
  74. {
  75. ReSLS_FETCH();
  76. php_info_print_table_start();
  77. php_info_print_table_row(2, "Recode Support", "enabled");
  78. php_info_print_table_row(2, "Revision", "$Revision$");
  79. php_info_print_table_end();
  80. }
  81. /* {{{ proto string recode_string(string request, string str)
  82. Recode string str according to request string */
  83. PHP_FUNCTION(recode_string)
  84. {
  85. RECODE_REQUEST request = NULL;
  86. char *r = NULL;
  87. pval **str;
  88. pval **req;
  89. bool success;
  90. ReSLS_FETCH();
  91. if (ZEND_NUM_ARGS() != 2
  92. || zend_get_parameters_ex(2, &req, &str) == FAILURE) {
  93. WRONG_PARAM_COUNT;
  94. }
  95. convert_to_string_ex(str);
  96. convert_to_string_ex(req);
  97. request = recode_new_request(ReSG(outer));
  98. if (request == NULL) {
  99. php_error(E_WARNING, "Cannot allocate request structure");
  100. RETURN_FALSE;
  101. }
  102. success = recode_scan_request(request, (*req)->value.str.val);
  103. if (!success) {
  104. php_error(E_WARNING, "Illegal recode request '%s'", (*req)->value.str.val);
  105. goto error_exit;
  106. }
  107. r = recode_string(request, (*str)->value.str.val);
  108. if (!r) {
  109. php_error(E_WARNING, "Recoding failed.");
  110. goto error_exit;
  111. }
  112. RETVAL_STRING(r, 1);
  113. free(r);
  114. /* FALLTHROUGH */
  115. error_exit:
  116. if (request)
  117. recode_delete_request(request);
  118. if (!r)
  119. RETURN_FALSE;
  120. return;
  121. }
  122. /* }}} */
  123. /* {{{ proto bool recode_file(string request, resource input, resource output)
  124. Recode file input into file output according to request */
  125. PHP_FUNCTION(recode_file)
  126. {
  127. RECODE_REQUEST request = NULL;
  128. int success;
  129. pval **req;
  130. pval **input, **output;
  131. FILE *in_fp, *out_fp;
  132. int in_type, out_type;
  133. ReSLS_FETCH();
  134. if (ZEND_NUM_ARGS() != 3
  135. || zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) {
  136. WRONG_PARAM_COUNT;
  137. }
  138. in_fp = zend_fetch_resource(input,-1, "File-Handle", &in_type,
  139. 2, php_file_le_fopen(), php_file_le_popen());
  140. if (!in_fp) {
  141. php_error(E_WARNING,"Unable to find input file identifier");
  142. RETURN_FALSE;
  143. }
  144. out_fp = zend_fetch_resource(output,-1, "File-Handle", &out_type,
  145. 2, php_file_le_fopen(), php_file_le_popen());
  146. if (!out_fp) {
  147. php_error(E_WARNING,"Unable to find output file identifier");
  148. RETURN_FALSE;
  149. }
  150. convert_to_string_ex(req);
  151. request = recode_new_request(ReSG(outer));
  152. if (request == NULL) {
  153. php_error(E_WARNING, "Cannot allocate request structure");
  154. RETURN_FALSE;
  155. }
  156. success = recode_scan_request(request, (*req)->value.str.val);
  157. if (!success) {
  158. php_error(E_WARNING, "Illegal recode request '%s'", (*req)->value.str.val);
  159. goto error_exit;
  160. }
  161. success = recode_file_to_file(request, in_fp, out_fp);
  162. if (!success) {
  163. php_error(E_WARNING, "Recoding failed.");
  164. goto error_exit;
  165. }
  166. if (request)
  167. recode_delete_request(request);
  168. RETURN_TRUE;
  169. error_exit:
  170. if (request)
  171. recode_delete_request(request);
  172. RETURN_FALSE;
  173. }
  174. /* }}} */
  175. #endif
  176. /*
  177. * Local variables:
  178. * tab-width: 4
  179. * c-basic-offset: 4
  180. * End:
  181. */