util_script.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file util_script.h
  18. * @brief Apache script tools
  19. *
  20. * @defgroup APACHE_CORE_SCRIPT Script Tools
  21. * @ingroup APACHE_CORE
  22. * @{
  23. */
  24. #ifndef APACHE_UTIL_SCRIPT_H
  25. #define APACHE_UTIL_SCRIPT_H
  26. #include "apr_buckets.h"
  27. #include "ap_config.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #ifndef APACHE_ARG_MAX
  32. #ifdef _POSIX_ARG_MAX
  33. #define APACHE_ARG_MAX _POSIX_ARG_MAX
  34. #else
  35. #define APACHE_ARG_MAX 512
  36. #endif
  37. #endif
  38. /**
  39. * Create an environment variable out of an Apache table of key-value pairs
  40. * @param p pool to allocate out of
  41. * @param t Apache table of key-value pairs
  42. * @return An array containing the same key-value pairs suitable for
  43. * use with an exec call.
  44. * @fn char **ap_create_environment(apr_pool_t *p, apr_table_t *t)
  45. */
  46. AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t);
  47. /**
  48. * This "cute" little function comes about because the path info on
  49. * filenames and URLs aren't always the same. So we take the two,
  50. * and find as much of the two that match as possible.
  51. * @param uri The uri we are currently parsing
  52. * @param path_info The current path info
  53. * @return The length of the path info
  54. * @fn int ap_find_path_info(const char *uri, const char *path_info)
  55. */
  56. AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info);
  57. /**
  58. * Add CGI environment variables required by HTTP/1.1 to the request's
  59. * environment table
  60. * @param r the current request
  61. * @fn void ap_add_cgi_vars(request_rec *r)
  62. */
  63. AP_DECLARE(void) ap_add_cgi_vars(request_rec *r);
  64. /**
  65. * Add common CGI environment variables to the requests environment table
  66. * @param r The current request
  67. * @fn void ap_add_common_vars(request_rec *r)
  68. */
  69. AP_DECLARE(void) ap_add_common_vars(request_rec *r);
  70. /**
  71. * Read headers output from a script, ensuring that the output is valid. If
  72. * the output is valid, then the headers are added to the headers out of the
  73. * current request
  74. * @param r The current request
  75. * @param f The file to read from
  76. * @param buffer Empty when calling the function. On output, if there was an
  77. * error, the string that cause the error is stored here.
  78. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  79. * @fn int ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer)
  80. */
  81. AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer);
  82. /**
  83. * Read headers output from a script, ensuring that the output is valid. If
  84. * the output is valid, then the headers are added to the headers out of the
  85. * current request
  86. * @param r The current request
  87. * @param f The file to read from
  88. * @param buffer Empty when calling the function. On output, if there was an
  89. * error, the string that cause the error is stored here.
  90. * @param module_index The module index to be used for logging
  91. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  92. */
  93. AP_DECLARE(int) ap_scan_script_header_err_ex(request_rec *r, apr_file_t *f,
  94. char *buffer, int module_index);
  95. /**
  96. * Read headers output from a script, ensuring that the output is valid. If
  97. * the output is valid, then the headers are added to the headers out of the
  98. * current request
  99. * @param r The current request
  100. * @param bb The brigade from which to read
  101. * @param buffer Empty when calling the function. On output, if there was an
  102. * error, the string that cause the error is stored here.
  103. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  104. * @fn int ap_scan_script_header_err_brigade(request_rec *r, apr_bucket_brigade *bb, char *buffer)
  105. */
  106. AP_DECLARE(int) ap_scan_script_header_err_brigade(request_rec *r,
  107. apr_bucket_brigade *bb,
  108. char *buffer);
  109. /**
  110. * Read headers output from a script, ensuring that the output is valid. If
  111. * the output is valid, then the headers are added to the headers out of the
  112. * current request
  113. * @param r The current request
  114. * @param bb The brigade from which to read
  115. * @param buffer Empty when calling the function. On output, if there was an
  116. * error, the string that cause the error is stored here.
  117. * @param module_index The module index to be used for logging
  118. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  119. */
  120. AP_DECLARE(int) ap_scan_script_header_err_brigade_ex(request_rec *r,
  121. apr_bucket_brigade *bb,
  122. char *buffer,
  123. int module_index);
  124. /**
  125. * Read headers strings from a script, ensuring that the output is valid. If
  126. * the output is valid, then the headers are added to the headers out of the
  127. * current request
  128. * @param r The current request
  129. * @param buffer Empty when calling the function. On output, if there was an
  130. * error, the string that cause the error is stored here.
  131. * @param termch Pointer to the last character parsed.
  132. * @param termarg Pointer to an int to capture the last argument parsed.
  133. *
  134. * The varargs are string arguments to parse consecutively for headers,
  135. * with a NULL argument to terminate the list.
  136. *
  137. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  138. */
  139. AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r,
  140. char *buffer,
  141. const char **termch,
  142. int *termarg, ...)
  143. AP_FN_ATTR_SENTINEL;
  144. /**
  145. * Read headers strings from a script, ensuring that the output is valid. If
  146. * the output is valid, then the headers are added to the headers out of the
  147. * current request
  148. * @param r The current request
  149. * @param buffer Empty when calling the function. On output, if there was an
  150. * error, the string that cause the error is stored here.
  151. * @param module_index The module index to be used for logging
  152. * @param termch Pointer to the last character parsed.
  153. * @param termarg Pointer to an int to capture the last argument parsed.
  154. *
  155. * The varargs are string arguments to parse consecutively for headers,
  156. * with a NULL argument to terminate the list.
  157. *
  158. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  159. */
  160. AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs_ex(request_rec *r,
  161. char *buffer,
  162. int module_index,
  163. const char **termch,
  164. int *termarg, ...)
  165. AP_FN_ATTR_SENTINEL;
  166. /**
  167. * Read headers output from a script, ensuring that the output is valid. If
  168. * the output is valid, then the headers are added to the headers out of the
  169. * current request
  170. * @param r The current request
  171. * @param buffer Empty when calling the function. On output, if there was an
  172. * error, the string that cause the error is stored here.
  173. * @param getsfunc Function to read the headers from. This function should
  174. act like gets()
  175. * @param getsfunc_data The place to read from
  176. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  177. */
  178. AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
  179. int (*getsfunc) (char *, int, void *),
  180. void *getsfunc_data);
  181. /**
  182. * Read headers output from a script, ensuring that the output is valid. If
  183. * the output is valid, then the headers are added to the headers out of the
  184. * current request
  185. * @param r The current request
  186. * @param buffer Empty when calling the function. On output, if there was an
  187. * error, the string that cause the error is stored here.
  188. * @param getsfunc Function to read the headers from. This function should
  189. act like gets()
  190. * @param getsfunc_data The place to read from
  191. * @param module_index The module index to be used for logging
  192. * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise
  193. */
  194. AP_DECLARE(int) ap_scan_script_header_err_core_ex(request_rec *r, char *buffer,
  195. int (*getsfunc) (char *, int, void *),
  196. void *getsfunc_data, int module_index);
  197. /**
  198. * Parse query args for the request and store in a new table allocated
  199. * from the request pool.
  200. * For args with no value, "1" will be used instead.
  201. * If no query args were specified, the table will be empty.
  202. * @param r The current request
  203. * @param table A new table on output.
  204. */
  205. AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif /* !APACHE_UTIL_SCRIPT_H */
  210. /** @} */