util_filter.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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_filter.h
  18. * @brief Apache filter library
  19. */
  20. #ifndef AP_FILTER_H
  21. #define AP_FILTER_H
  22. #include "apr.h"
  23. #include "apr_buckets.h"
  24. #include "httpd.h"
  25. #if APR_HAVE_STDARG_H
  26. #include <stdarg.h>
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * @brief input filtering modes
  33. */
  34. typedef enum {
  35. /** The filter should return at most readbytes data. */
  36. AP_MODE_READBYTES,
  37. /** The filter should return at most one line of CRLF data.
  38. * (If a potential line is too long or no CRLF is found, the
  39. * filter may return partial data).
  40. */
  41. AP_MODE_GETLINE,
  42. /** The filter should implicitly eat any CRLF pairs that it sees. */
  43. AP_MODE_EATCRLF,
  44. /** The filter read should be treated as speculative and any returned
  45. * data should be stored for later retrieval in another mode. */
  46. AP_MODE_SPECULATIVE,
  47. /** The filter read should be exhaustive and read until it can not
  48. * read any more.
  49. * Use this mode with extreme caution.
  50. */
  51. AP_MODE_EXHAUSTIVE,
  52. /** The filter should initialize the connection if needed,
  53. * NNTP or FTP over SSL for example.
  54. */
  55. AP_MODE_INIT
  56. } ap_input_mode_t;
  57. /**
  58. * @defgroup APACHE_CORE_FILTER Filter Chain
  59. * @ingroup APACHE_CORE
  60. *
  61. * Filters operate using a "chaining" mechanism. The filters are chained
  62. * together into a sequence. When output is generated, it is passed through
  63. * each of the filters on this chain, until it reaches the end (or "bottom")
  64. * and is placed onto the network.
  65. *
  66. * The top of the chain, the code generating the output, is typically called
  67. * a "content generator." The content generator's output is fed into the
  68. * filter chain using the standard Apache output mechanisms: ap_rputs(),
  69. * ap_rprintf(), ap_rwrite(), etc.
  70. *
  71. * Each filter is defined by a callback. This callback takes the output from
  72. * the previous filter (or the content generator if there is no previous
  73. * filter), operates on it, and passes the result to the next filter in the
  74. * chain. This pass-off is performed using the ap_fc_* functions, such as
  75. * ap_fc_puts(), ap_fc_printf(), ap_fc_write(), etc.
  76. *
  77. * When content generation is complete, the system will pass an "end of
  78. * stream" marker into the filter chain. The filters will use this to flush
  79. * out any internal state and to detect incomplete syntax (for example, an
  80. * unterminated SSI directive).
  81. *
  82. * @{
  83. */
  84. /* forward declare the filter type */
  85. typedef struct ap_filter_t ap_filter_t;
  86. /**
  87. * @name Filter callbacks
  88. *
  89. * This function type is used for filter callbacks. It will be passed a
  90. * pointer to "this" filter, and a "bucket brigade" containing the content
  91. * to be filtered.
  92. *
  93. * In filter->ctx, the callback will find its context. This context is
  94. * provided here, so that a filter may be installed multiple times, each
  95. * receiving its own per-install context pointer.
  96. *
  97. * Callbacks are associated with a filter definition, which is specified
  98. * by name. See ap_register_input_filter() and ap_register_output_filter()
  99. * for setting the association between a name for a filter and its
  100. * associated callback (and other information).
  101. *
  102. * If the initialization function argument passed to the registration
  103. * functions is non-NULL, it will be called iff the filter is in the input
  104. * or output filter chains and before any data is generated to allow the
  105. * filter to prepare for processing.
  106. *
  107. * The bucket brigade always belongs to the caller, but the filter
  108. * is free to use the buckets within it as it sees fit. Normally,
  109. * the brigade will be returned empty. Buckets *may not* be retained
  110. * between successive calls to the filter unless they have been
  111. * "set aside" with a call apr_bucket_setaside. Typically this will
  112. * be done with ap_save_brigade(). Buckets removed from the brigade
  113. * become the responsibility of the filter, which must arrange for
  114. * them to be deleted, either by doing so directly or by inserting
  115. * them in a brigade which will subsequently be destroyed.
  116. *
  117. * For the input and output filters, the return value of a filter should be
  118. * an APR status value. For the init function, the return value should
  119. * be an HTTP error code or OK if it was successful.
  120. *
  121. * @ingroup filter
  122. * @{
  123. */
  124. typedef apr_status_t (*ap_out_filter_func)(ap_filter_t *f,
  125. apr_bucket_brigade *b);
  126. typedef apr_status_t (*ap_in_filter_func)(ap_filter_t *f,
  127. apr_bucket_brigade *b,
  128. ap_input_mode_t mode,
  129. apr_read_type_e block,
  130. apr_off_t readbytes);
  131. typedef int (*ap_init_filter_func)(ap_filter_t *f);
  132. typedef union ap_filter_func {
  133. ap_out_filter_func out_func;
  134. ap_in_filter_func in_func;
  135. } ap_filter_func;
  136. /** @} */
  137. /**
  138. * Filters have different types/classifications. These are used to group
  139. * and sort the filters to properly sequence their operation.
  140. *
  141. * The types have a particular sort order, which allows us to insert them
  142. * into the filter chain in a determistic order. Within a particular grouping,
  143. * the ordering is equivalent to the order of calls to ap_add_*_filter().
  144. */
  145. typedef enum {
  146. /** These filters are used to alter the content that is passed through
  147. * them. Examples are SSI or PHP. */
  148. AP_FTYPE_RESOURCE = 10,
  149. /** These filters are used to alter the content as a whole, but after all
  150. * AP_FTYPE_RESOURCE filters are executed. These filters should not
  151. * change the content-type. An example is deflate. */
  152. AP_FTYPE_CONTENT_SET = 20,
  153. /** These filters are used to handle the protocol between server and
  154. * client. Examples are HTTP and POP. */
  155. AP_FTYPE_PROTOCOL = 30,
  156. /** These filters implement transport encodings (e.g., chunking). */
  157. AP_FTYPE_TRANSCODE = 40,
  158. /** These filters will alter the content, but in ways that are
  159. * more strongly associated with the connection. Examples are
  160. * splitting an HTTP connection into multiple requests and
  161. * buffering HTTP responses across multiple requests.
  162. *
  163. * It is important to note that these types of filters are not
  164. * allowed in a sub-request. A sub-request's output can certainly
  165. * be filtered by ::AP_FTYPE_RESOURCE filters, but all of the "final
  166. * processing" is determined by the main request. */
  167. AP_FTYPE_CONNECTION = 50,
  168. /** These filters don't alter the content. They are responsible for
  169. * sending/receiving data to/from the client. */
  170. AP_FTYPE_NETWORK = 60
  171. } ap_filter_type;
  172. /**
  173. * This is the request-time context structure for an installed filter (in
  174. * the output filter chain). It provides the callback to use for filtering,
  175. * the request this filter is associated with (which is important when
  176. * an output chain also includes sub-request filters), the context for this
  177. * installed filter, and the filter ordering/chaining fields.
  178. *
  179. * Filter callbacks are free to use ->ctx as they please, to store context
  180. * during the filter process. Generally, this is superior over associating
  181. * the state directly with the request. A callback should not change any of
  182. * the other fields.
  183. */
  184. typedef struct ap_filter_rec_t ap_filter_rec_t;
  185. typedef struct ap_filter_provider_t ap_filter_provider_t;
  186. /**
  187. * @brief This structure is used for recording information about the
  188. * registered filters. It associates a name with the filter's callback
  189. * and filter type.
  190. *
  191. * At the moment, these are simply linked in a chain, so a ->next pointer
  192. * is available.
  193. *
  194. * It is used for any filter that can be inserted in the filter chain.
  195. * This may be either a httpd-2.0 filter or a mod_filter harness.
  196. * In the latter case it contains dispatch, provider and protocol information.
  197. * In the former case, the new fields (from dispatch) are ignored.
  198. */
  199. struct ap_filter_rec_t {
  200. /** The registered name for this filter */
  201. const char *name;
  202. /** The function to call when this filter is invoked. */
  203. ap_filter_func filter_func;
  204. /** The function to call directly before the handlers are invoked
  205. * for a request. The init function is called once directly
  206. * before running the handlers for a request or subrequest. The
  207. * init function is never called for a connection filter (with
  208. * ftype >= AP_FTYPE_CONNECTION). Any use of this function for
  209. * filters for protocols other than HTTP is specified by the
  210. * module supported that protocol.
  211. */
  212. ap_init_filter_func filter_init_func;
  213. /** The next filter_rec in the list */
  214. struct ap_filter_rec_t *next;
  215. /** Providers for this filter */
  216. ap_filter_provider_t *providers;
  217. /** The type of filter, either AP_FTYPE_CONTENT or AP_FTYPE_CONNECTION.
  218. * An AP_FTYPE_CONTENT filter modifies the data based on information
  219. * found in the content. An AP_FTYPE_CONNECTION filter modifies the
  220. * data based on the type of connection.
  221. */
  222. ap_filter_type ftype;
  223. /** Trace level for this filter */
  224. int debug;
  225. /** Protocol flags for this filter */
  226. unsigned int proto_flags;
  227. };
  228. /**
  229. * @brief The representation of a filter chain.
  230. *
  231. * Each request has a list
  232. * of these structures which are called in turn to filter the data. Sub
  233. * requests get an exact copy of the main requests filter chain.
  234. */
  235. struct ap_filter_t {
  236. /** The internal representation of this filter. This includes
  237. * the filter's name, type, and the actual function pointer.
  238. */
  239. ap_filter_rec_t *frec;
  240. /** A place to store any data associated with the current filter */
  241. void *ctx;
  242. /** The next filter in the chain */
  243. ap_filter_t *next;
  244. /** The request_rec associated with the current filter. If a sub-request
  245. * adds filters, then the sub-request is the request associated with the
  246. * filter.
  247. */
  248. request_rec *r;
  249. /** The conn_rec associated with the current filter. This is analogous
  250. * to the request_rec, except that it is used for connection filters.
  251. */
  252. conn_rec *c;
  253. };
  254. /**
  255. * Get the current bucket brigade from the next filter on the filter
  256. * stack. The filter returns an apr_status_t value. If the bottom-most
  257. * filter doesn't read from the network, then ::AP_NOBODY_READ is returned.
  258. * The bucket brigade will be empty when there is nothing left to get.
  259. * @param filter The next filter in the chain
  260. * @param bucket The current bucket brigade. The original brigade passed
  261. * to ap_get_brigade() must be empty.
  262. * @param mode The way in which the data should be read
  263. * @param block How the operations should be performed
  264. * ::APR_BLOCK_READ, ::APR_NONBLOCK_READ
  265. * @param readbytes How many bytes to read from the next filter.
  266. */
  267. AP_DECLARE(apr_status_t) ap_get_brigade(ap_filter_t *filter,
  268. apr_bucket_brigade *bucket,
  269. ap_input_mode_t mode,
  270. apr_read_type_e block,
  271. apr_off_t readbytes);
  272. /**
  273. * Pass the current bucket brigade down to the next filter on the filter
  274. * stack. The filter returns an apr_status_t value. If the bottom-most
  275. * filter doesn't write to the network, then ::AP_NOBODY_WROTE is returned.
  276. * @param filter The next filter in the chain
  277. * @param bucket The current bucket brigade
  278. *
  279. * @remark Ownership of the brigade is retained by the caller. On return,
  280. * the contents of the brigade are UNDEFINED, and the caller must
  281. * either call apr_brigade_cleanup or apr_brigade_destroy on
  282. * the brigade.
  283. */
  284. AP_DECLARE(apr_status_t) ap_pass_brigade(ap_filter_t *filter,
  285. apr_bucket_brigade *bucket);
  286. /**
  287. * Pass the current bucket brigade down to the next filter on the filter
  288. * stack checking for filter errors. The filter returns an apr_status_t value.
  289. * Returns ::OK if the brigade is successfully passed
  290. * ::AP_FILTER_ERROR on a filter error
  291. * ::HTTP_INTERNAL_SERVER_ERROR on all other errors
  292. * @param r The request rec
  293. * @param bucket The current bucket brigade
  294. * @param fmt The format string. If NULL defaults to "ap_pass_brigade returned"
  295. * @param ... The arguments to use to fill out the format string
  296. * @remark Ownership of the brigade is retained by the caller. On return,
  297. * the contents of the brigade are UNDEFINED, and the caller must
  298. * either call apr_brigade_cleanup or apr_brigade_destroy on
  299. * the brigade.
  300. */
  301. AP_DECLARE(apr_status_t) ap_pass_brigade_fchk(request_rec *r,
  302. apr_bucket_brigade *bucket,
  303. const char *fmt,
  304. ...)
  305. __attribute__((format(printf,3,4)));
  306. /**
  307. * This function is used to register an input filter with the system.
  308. * After this registration is performed, then a filter may be added
  309. * into the filter chain by using ap_add_input_filter() and simply
  310. * specifying the name.
  311. *
  312. * @param name The name to attach to the filter function
  313. * @param filter_func The filter function to name
  314. * @param filter_init The function to call before the filter handlers
  315. are invoked
  316. * @param ftype The type of filter function, either ::AP_FTYPE_CONTENT_SET or
  317. * ::AP_FTYPE_CONNECTION
  318. * @see add_input_filter()
  319. */
  320. AP_DECLARE(ap_filter_rec_t *) ap_register_input_filter(const char *name,
  321. ap_in_filter_func filter_func,
  322. ap_init_filter_func filter_init,
  323. ap_filter_type ftype);
  324. /** @deprecated @see ap_register_output_filter_protocol */
  325. AP_DECLARE(ap_filter_rec_t *) ap_register_output_filter(const char *name,
  326. ap_out_filter_func filter_func,
  327. ap_init_filter_func filter_init,
  328. ap_filter_type ftype);
  329. /* For httpd-?.? I suggest replacing the above with
  330. #define ap_register_output_filter(name,ffunc,init,ftype) \
  331. ap_register_output_filter_protocol(name,ffunc,init,ftype,0)
  332. */
  333. /**
  334. * This function is used to register an output filter with the system.
  335. * After this registration is performed, then a filter may be added
  336. * directly to the filter chain by using ap_add_output_filter() and
  337. * simply specifying the name, or as a provider under mod_filter.
  338. *
  339. * @param name The name to attach to the filter function
  340. * @param filter_func The filter function to name
  341. * @param filter_init The function to call before the filter handlers
  342. * are invoked
  343. * @param ftype The type of filter function, either ::AP_FTYPE_CONTENT_SET or
  344. * ::AP_FTYPE_CONNECTION
  345. * @param proto_flags Protocol flags: logical OR of AP_FILTER_PROTO_* bits
  346. * @return the filter rec
  347. * @see ap_add_output_filter()
  348. */
  349. AP_DECLARE(ap_filter_rec_t *) ap_register_output_filter_protocol(
  350. const char *name,
  351. ap_out_filter_func filter_func,
  352. ap_init_filter_func filter_init,
  353. ap_filter_type ftype,
  354. unsigned int proto_flags);
  355. /**
  356. * Adds a named filter into the filter chain on the specified request record.
  357. * The filter will be installed with the specified context pointer.
  358. *
  359. * Filters added in this way will always be placed at the end of the filters
  360. * that have the same type (thus, the filters have the same order as the
  361. * calls to ap_add_filter). If the current filter chain contains filters
  362. * from another request, then this filter will be added before those other
  363. * filters.
  364. *
  365. * To re-iterate that last comment. This function is building a FIFO
  366. * list of filters. Take note of that when adding your filter to the chain.
  367. *
  368. * @param name The name of the filter to add
  369. * @param ctx Context data to provide to the filter
  370. * @param r The request to add this filter for (or NULL if it isn't associated with a request)
  371. * @param c The connection to add the fillter for
  372. */
  373. AP_DECLARE(ap_filter_t *) ap_add_input_filter(const char *name, void *ctx,
  374. request_rec *r, conn_rec *c);
  375. /**
  376. * Variant of ap_add_input_filter() that accepts a registered filter handle
  377. * (as returned by ap_register_input_filter()) rather than a filter name
  378. *
  379. * @param f The filter handle to add
  380. * @param ctx Context data to provide to the filter
  381. * @param r The request to add this filter for (or NULL if it isn't associated with a request)
  382. * @param c The connection to add the fillter for
  383. */
  384. AP_DECLARE(ap_filter_t *) ap_add_input_filter_handle(ap_filter_rec_t *f,
  385. void *ctx,
  386. request_rec *r,
  387. conn_rec *c);
  388. /**
  389. * Returns the filter handle for use with ap_add_input_filter_handle.
  390. *
  391. * @param name The filter name to look up
  392. */
  393. AP_DECLARE(ap_filter_rec_t *) ap_get_input_filter_handle(const char *name);
  394. /**
  395. * Add a filter to the current request. Filters are added in a FIFO manner.
  396. * The first filter added will be the first filter called.
  397. * @param name The name of the filter to add
  398. * @param ctx Context data to set in the filter
  399. * @param r The request to add this filter for (or NULL if it isn't associated with a request)
  400. * @param c The connection to add this filter for
  401. * @note If adding a connection-level output filter (i.e. where the type
  402. * is >= AP_FTYPE_CONNECTION) during processing of a request, the request
  403. * object r must be passed in to ensure the filter chains are modified
  404. * correctly. f->r will still be initialized as NULL in the new filter.
  405. */
  406. AP_DECLARE(ap_filter_t *) ap_add_output_filter(const char *name, void *ctx,
  407. request_rec *r, conn_rec *c);
  408. /**
  409. * Variant of ap_add_output_filter() that accepts a registered filter handle
  410. * (as returned by ap_register_output_filter()) rather than a filter name
  411. *
  412. * @param f The filter handle to add
  413. * @param ctx Context data to set in the filter
  414. * @param r The request to add this filter for (or NULL if it isn't associated with a request)
  415. * @param c The connection to add the filter for
  416. * @note If adding a connection-level output filter (i.e. where the type
  417. * is >= AP_FTYPE_CONNECTION) during processing of a request, the request
  418. * object r must be passed in to ensure the filter chains are modified
  419. * correctly. f->r will still be initialized as NULL in the new filter.
  420. */
  421. AP_DECLARE(ap_filter_t *) ap_add_output_filter_handle(ap_filter_rec_t *f,
  422. void *ctx,
  423. request_rec *r,
  424. conn_rec *c);
  425. /**
  426. * Returns the filter handle for use with ap_add_output_filter_handle.
  427. *
  428. * @param name The filter name to look up
  429. */
  430. AP_DECLARE(ap_filter_rec_t *) ap_get_output_filter_handle(const char *name);
  431. /**
  432. * Remove an input filter from either the request or connection stack
  433. * it is associated with.
  434. * @param f The filter to remove
  435. */
  436. AP_DECLARE(void) ap_remove_input_filter(ap_filter_t *f);
  437. /**
  438. * Remove an output filter from either the request or connection stack
  439. * it is associated with.
  440. * @param f The filter to remove
  441. */
  442. AP_DECLARE(void) ap_remove_output_filter(ap_filter_t *f);
  443. /**
  444. * Remove an input filter from either the request or connection stack
  445. * it is associated with.
  446. * @param next The filter stack to search
  447. * @param handle The filter handle (name) to remove
  448. * @return APR_SUCCESS on removal or error
  449. */
  450. AP_DECLARE(apr_status_t) ap_remove_input_filter_byhandle(ap_filter_t *next,
  451. const char *handle);
  452. /**
  453. * Remove an output filter from either the request or connection stack
  454. * it is associated with.
  455. * @param next The filter stack to search
  456. * @param handle The filter handle (name) to remove
  457. * @return APR_SUCCESS on removal or error
  458. */
  459. AP_DECLARE(apr_status_t) ap_remove_output_filter_byhandle(ap_filter_t *next,
  460. const char *handle);
  461. /* The next two filters are for abstraction purposes only. They could be
  462. * done away with, but that would require that we break modules if we ever
  463. * want to change our filter registration method. The basic idea, is that
  464. * all filters have a place to store data, the ctx pointer. These functions
  465. * fill out that pointer with a bucket brigade, and retrieve that data on
  466. * the next call. The nice thing about these functions, is that they
  467. * automatically concatenate the bucket brigades together for you. This means
  468. * that if you have already stored a brigade in the filters ctx pointer, then
  469. * when you add more it will be tacked onto the end of that brigade. When
  470. * you retrieve data, if you pass in a bucket brigade to the get function,
  471. * it will append the current brigade onto the one that you are retrieving.
  472. */
  473. /**
  474. * prepare a bucket brigade to be setaside. If a different brigade was
  475. * set-aside earlier, then the two brigades are concatenated together.
  476. * @param f The current filter
  477. * @param save_to The brigade that was previously set-aside. Regardless, the
  478. * new bucket brigade is returned in this location.
  479. * @param b The bucket brigade to save aside. This brigade is always empty
  480. * on return
  481. * @param p Ensure that all data in the brigade lives as long as this pool
  482. */
  483. AP_DECLARE(apr_status_t) ap_save_brigade(ap_filter_t *f,
  484. apr_bucket_brigade **save_to,
  485. apr_bucket_brigade **b, apr_pool_t *p);
  486. /**
  487. * Flush function for apr_brigade_* calls. This calls ap_pass_brigade
  488. * to flush the brigade if the brigade buffer overflows.
  489. * @param bb The brigade to flush
  490. * @param ctx The filter to pass the brigade to
  491. * @note this function has nothing to do with FLUSH buckets. It is simply
  492. * a way to flush content out of a brigade and down a filter stack.
  493. */
  494. AP_DECLARE_NONSTD(apr_status_t) ap_filter_flush(apr_bucket_brigade *bb,
  495. void *ctx);
  496. /**
  497. * Flush the current brigade down the filter stack.
  498. * @param f The filter we are passing to
  499. * @param bb The brigade to flush
  500. */
  501. AP_DECLARE(apr_status_t) ap_fflush(ap_filter_t *f, apr_bucket_brigade *bb);
  502. /**
  503. * Write a buffer for the current filter, buffering if possible.
  504. * @param f the filter we are writing to
  505. * @param bb The brigade to buffer into
  506. * @param data The data to write
  507. * @param nbyte The number of bytes in the data
  508. */
  509. #define ap_fwrite(f, bb, data, nbyte) \
  510. apr_brigade_write(bb, ap_filter_flush, f, data, nbyte)
  511. /**
  512. * Write a buffer for the current filter, buffering if possible.
  513. * @param f the filter we are writing to
  514. * @param bb The brigade to buffer into
  515. * @param str The string to write
  516. */
  517. #define ap_fputs(f, bb, str) \
  518. apr_brigade_write(bb, ap_filter_flush, f, str, strlen(str))
  519. /**
  520. * Write a character for the current filter, buffering if possible.
  521. * @param f the filter we are writing to
  522. * @param bb The brigade to buffer into
  523. * @param c The character to write
  524. */
  525. #define ap_fputc(f, bb, c) \
  526. apr_brigade_putc(bb, ap_filter_flush, f, c)
  527. /**
  528. * Write an unspecified number of strings to the current filter
  529. * @param f the filter we are writing to
  530. * @param bb The brigade to buffer into
  531. * @param ... The strings to write
  532. */
  533. AP_DECLARE_NONSTD(apr_status_t) ap_fputstrs(ap_filter_t *f,
  534. apr_bucket_brigade *bb,
  535. ...)
  536. AP_FN_ATTR_SENTINEL;
  537. /**
  538. * Output data to the filter in printf format
  539. * @param f the filter we are writing to
  540. * @param bb The brigade to buffer into
  541. * @param fmt The format string
  542. * @param ... The arguments to use to fill out the format string
  543. */
  544. AP_DECLARE_NONSTD(apr_status_t) ap_fprintf(ap_filter_t *f,
  545. apr_bucket_brigade *bb,
  546. const char *fmt,
  547. ...)
  548. __attribute__((format(printf,3,4)));
  549. /**
  550. * set protocol requirements for an output content filter
  551. * (only works with AP_FTYPE_RESOURCE and AP_FTYPE_CONTENT_SET)
  552. * @param f the filter in question
  553. * @param proto_flags Logical OR of AP_FILTER_PROTO_* bits
  554. */
  555. AP_DECLARE(void) ap_filter_protocol(ap_filter_t* f, unsigned int proto_flags);
  556. /** Filter changes contents (so invalidating checksums/etc) */
  557. #define AP_FILTER_PROTO_CHANGE 0x1
  558. /** Filter changes length of contents (so invalidating content-length/etc) */
  559. #define AP_FILTER_PROTO_CHANGE_LENGTH 0x2
  560. /** Filter requires complete input and can't work on byteranges */
  561. #define AP_FILTER_PROTO_NO_BYTERANGE 0x4
  562. /** Filter should not run in a proxy */
  563. #define AP_FILTER_PROTO_NO_PROXY 0x8
  564. /** Filter makes output non-cacheable */
  565. #define AP_FILTER_PROTO_NO_CACHE 0x10
  566. /** Filter is incompatible with "Cache-Control: no-transform" */
  567. #define AP_FILTER_PROTO_TRANSFORM 0x20
  568. /**
  569. * @}
  570. */
  571. #ifdef __cplusplus
  572. }
  573. #endif
  574. #endif /* !AP_FILTER_H */