mod_echo.c revision cc910c475085f94bd30fc1b6e16363872424f780
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder#include "httpd.h"
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder#include "http_config.h"
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder#include "http_connection.h"
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian MaederAPI_VAR_EXPORT module echo_module;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maedertypedef struct
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder int bEnabled;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder } EchoConfig;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederstatic void *create_echo_server_config(pool *p,server_rec *s)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder EchoConfig *pConfig=ap_pcalloc(p,sizeof *pConfig);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder pConfig->bEnabled=0;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder return pConfig;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder
329c739bc05b8ce8d54f81071d0826ff771d1f78Christian Maederstatic const char *echo_on(cmd_parms *cmd, void *dummy, char *arg)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder EchoConfig *pConfig=ap_get_module_config(cmd->server->module_config,
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder &echo_module);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder pConfig->bEnabled=1;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder return NULL;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederstatic int process_echo_connection(conn_rec *c)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder char buf[1024];
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder EchoConfig *pConfig=ap_get_module_config(c->base_server->module_config,
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder &echo_module);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder if(!pConfig->bEnabled)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder return DECLINED;
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder for( ; ; )
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder int w;
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder int r=ap_bread(c->client,buf,sizeof buf);
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder if(r <= 0)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder break;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder w=ap_bwrite(c->client,buf,r);
a38f3d84e592184830fa308c5dab3f7c71e4464fChristian Maeder if(w != r)
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder break;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder ap_bflush(c->client);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder return OK;
329c739bc05b8ce8d54f81071d0826ff771d1f78Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederstatic const command_rec echo_cmds[] = {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder{ "ProtocolEcho", echo_on, NULL, RSRC_CONF, RAW_ARGS,
4bbd808612c2580ae6e0495a155997a6bb47ecf3Christian Maeder "Run an echo server on this host" },
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder{ NULL }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederstatic void register_hooks()
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder ap_hook_process_connection(process_echo_connection,NULL,NULL,HOOK_MIDDLE);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian MaederAPI_VAR_EXPORT module echo_module = {
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian Maeder STANDARD20_MODULE_STUFF,
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* pre_config */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* post_config */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* open_logs */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* child_init */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* create per-directory config structure */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* merge per-directory config structures */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder create_echo_server_config, /* create per-server config structure */
d9be582b00d420e2fe0737fcb07c9aa3d235a774Christian Maeder NULL, /* merge per-server config structures */
19defe35cc864caeb98dd4ea1d429b1f989ecdffChristian Maeder echo_cmds, /* command table */
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder NULL, /* handlers */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* check auth */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder NULL, /* check access */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder register_hooks /* register hooks */
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder