Apache HTTPD
mod_dialup.c
Go to the documentation of this file.
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
18
19#include "httpd.h"
20#include "http_core.h"
21
22#include "util_filter.h"
23#include "http_log.h"
24#include "http_config.h"
25#include "http_request.h"
26#include "http_protocol.h"
27
28
29
30#include "ap_mpm.h"
31
32module AP_MODULE_DECLARE_DATA dialup_module;
33
37
45
46static int
48{
49 int status;
50 apr_off_t len = 0;
51 apr_size_t bytes_sent = 0;
52
53 while (!APR_BRIGADE_EMPTY(db->bb) && bytes_sent < db->bytes_per_second) {
55
56 if (db->r->connection->aborted) {
58 }
59
61
63 /* XXXXXX: Log me. */
65 }
66
67 if (e != APR_BRIGADE_SENTINEL(db->bb)) {
70 f = APR_RING_FIRST(&db->bb->list);
71 APR_RING_UNSPLICE(f, b, link);
73 }
74 else {
75 APR_BRIGADE_CONCAT(db->tmpbb, db->bb);
76 }
77
79
81
83 bytes_sent += len;
85
87
88 if (status != APR_SUCCESS) {
90 "dialup: pulse: ap_pass_brigade failed:");
91 return AP_FILTER_ERROR;
92 }
93 }
94
95 if (APR_BRIGADE_EMPTY(db->bb)) {
96 return DONE;
97 }
98 else {
99 return SUSPENDED;
100 }
101}
102
103static void
105{
106 int status;
108
110
112
113 if (status == SUSPENDED) {
115 }
116 else if (status == DONE) {
120 return;
121 }
122 else {
124 "dialup: pulse returned: %d", status);
125 db->r->status = HTTP_OK;
126 ap_die(status, db->r);
127 }
128
130}
131
132static int
134{
135 int status;
136 apr_status_t rv;
139 apr_file_t *fd;
140 dialup_baton_t *db;
141 apr_bucket *e;
142
143
144 /* See core.c, default handler for all of the cases we just decline. */
145 if (r->method_number != M_GET ||
147 r->finfo.filetype == APR_DIR) {
148 return DECLINED;
149 }
150
152 &dialup_module);
153
154 if (dcfg->bytes_per_second == 0) {
155 return DECLINED;
156 }
157
159
160
163 | AP_SENDFILE_ENABLED(ccfg->enable_sendfile)
164#endif
165 , 0, r->pool);
166
167 if (rv) {
168 return DECLINED;
169 }
170
171 /* copied from default handler: */
177
179 if (status != OK) {
181 "dialup: declined, meets conditions, good luck core handler");
182 return DECLINED;
183 }
184
185 db = apr_palloc(r->pool, sizeof(dialup_baton_t));
186
189
190 e = apr_brigade_insert_file(db->bb, fd, 0, r->finfo.size, r->pool);
191
192#if APR_HAS_MMAP
193 if (ccfg->enable_mmap == ENABLE_MMAP_OFF) {
195 }
196#endif
197
198
199 db->bytes_per_second = dcfg->bytes_per_second;
200 db->r = r;
201 db->fd = fd;
202
204
206
208 if (status != SUSPENDED && status != DONE) {
210 "dialup: failed, send pulse");
211 return status;
212 }
213
215
216 return SUSPENDED;
217}
218
219
220
221#ifndef APR_HOOK_ALMOST_LAST
222#define APR_HOOK_ALMOST_LAST (APR_HOOK_REALLY_LAST - 1)
223#endif
224
225static void
230
235
236#ifndef BITRATE_TO_BYTES
237#define BITRATE_TO_BYTES(x) ((1000 * x)/8)
238#endif
239
241{
242 {"V.21", BITRATE_TO_BYTES(0.1)},
243 {"V.26bis", BITRATE_TO_BYTES(2.4)},
244 {"V.32", BITRATE_TO_BYTES(9.6)},
245 {"V.34", BITRATE_TO_BYTES(28.8)},
246 {"V.92", BITRATE_TO_BYTES(56.0)},
247 {"i-was-rich-and-got-a-leased-line", BITRATE_TO_BYTES(1500)},
248 {NULL, 0}
249};
250
251static const char *
253 void *dconf,
254 const char *input)
255{
256 const modem_speed_t *standard;
257 int i = 0;
259
261
262 while (modem_bitrates[i].name != NULL) {
264 if (strcasecmp(standard->name, input) == 0) {
265 dcfg->bytes_per_second = standard->bytes_per_second;
266 break;
267 }
268 i++;
269 }
270
271 if (dcfg->bytes_per_second == 0) {
272 return "mod_dialup: Unknown Modem Standard specified.";
273 }
274
275 return NULL;
276}
277
278static void *
280{
281 dialup_dcfg_t *cfg = apr_palloc(p, sizeof(dialup_dcfg_t));
282
283 cfg->bytes_per_second = 0;
284
285 return cfg;
286}
287
288
289static const command_rec dialup_cmds[] =
290{
292 "Modem Standard to.. simulate. "
293 "Must be one of: 'V.21', 'V.26bis', 'V.32', 'V.34', or 'V.92'"),
294 {NULL}
295};
296
298{
301 NULL,
302 NULL,
303 NULL,
306};
Apache Multi-Processing Module library.
const char apr_size_t len
Definition ap_regex.h:187
#define AP_INIT_TAKE1(directive, func, mconfig, where, help)
#define ap_get_module_config(v, m)
#define AP_DECLARE_MODULE(foo)
void ap_hook_handler(ap_HOOK_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:170
request_rec * r
#define AP_FILTER_ERROR
Definition httpd.h:473
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
#define DONE
Definition httpd.h:458
#define SUSPENDED
Definition httpd.h:461
apr_status_t ap_pass_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket)
#define AP_SENDFILE_ENABLED(x)
Definition http_core.h:689
#define ap_get_core_module_config(v)
Definition http_core.h:383
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_MARK
Definition http_log.h:283
apr_status_t ap_mpm_register_timed_callback(apr_time_t t, ap_mpm_callback_fn_t *cbfn, void *baton)
Definition mpm_common.c:543
void ap_set_accept_ranges(request_rec *r)
int ap_meets_conditions(request_rec *r)
void ap_set_etag_fd(request_rec *r, apr_file_t *fd)
Definition http_etag.c:391
void ap_finalize_request_protocol(request_rec *r)
Definition protocol.c:1723
void ap_set_content_length(request_rec *r, apr_off_t length)
Definition protocol.c:160
void ap_set_last_modified(request_rec *r)
Definition protocol.c:2280
void ap_process_request_after_handler(request_rec *r)
void ap_die(int type, request_rec *r)
void ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
Definition request.c:2557
ap_vhost_iterate_conn_cb void * baton
Definition http_vhost.h:87
void * dummy
Definition http_vhost.h:62
#define APR_INCOMPLETE
Definition apr_errno.h:452
apr_file_t * f
#define APR_BRIGADE_INSERT_TAIL(b, e)
apr_bucket * e
#define APR_BRIGADE_CONCAT(a, b)
#define APR_BRIGADE_EMPTY(b)
#define APR_BRIGADE_SENTINEL(b)
apr_file_t * fd
#define APR_BUCKET_PREV(e)
#define ACCESS_CONF
#define HTTP_OK
Definition httpd.h:490
#define HTTP_INTERNAL_SERVER_ERROR
Definition httpd.h:535
#define M_GET
Definition httpd.h:592
#define STANDARD20_MODULE_STUFF
apr_size_t size
const char * input
Definition apr_cstr.h:93
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
@ APR_DIR
@ APR_NOFILE
#define APR_READ
Definition apr_file_io.h:93
#define APR_BINARY
Definition apr_file_io.h:98
int strcasecmp(const char *a, const char *b)
apr_pool_t * b
Definition apr_pools.h:529
#define APR_RING_UNSPLICE(ep1, epN, link)
Definition apr_ring.h:368
#define APR_RING_SPLICE_HEAD(hp, ep1, epN, elem, link)
Definition apr_ring.h:286
#define APR_RING_FIRST(hp)
Definition apr_ring.h:166
apr_cmdtype_e cmd
int int status
#define apr_time_from_sec(sec)
Definition apr_time.h:78
Apache Configuration.
CORE HTTP Daemon.
#define ENABLE_MMAP_OFF
Definition http_core.h:618
Apache Logging library.
HTTP protocol handling.
Apache Request library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
#define APR_HOOK_ALMOST_LAST
Definition mod_dialup.c:222
static const command_rec dialup_cmds[]
Definition mod_dialup.c:289
static void dialup_callback(void *baton)
Definition mod_dialup.c:104
static void * dialup_dcfg_create(apr_pool_t *p, char *dummy)
Definition mod_dialup.c:279
static const modem_speed_t modem_bitrates[]
Definition mod_dialup.c:240
static const char * cmd_modem_standard(cmd_parms *cmd, void *dconf, const char *input)
Definition mod_dialup.c:252
static int dialup_send_pulse(dialup_baton_t *db)
Definition mod_dialup.c:47
#define BITRATE_TO_BYTES(x)
Definition mod_dialup.c:237
static void dialup_register_hooks(apr_pool_t *p)
Definition mod_dialup.c:226
static int dialup_handler(request_rec *r)
Definition mod_dialup.c:133
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
char * name
struct apr_bucket_brigade::apr_bucket_list list
apr_filetype_e filetype
apr_off_t size
apr_time_t mtime
struct apr_bucket_alloc_t * bucket_alloc
Definition httpd.h:1201
unsigned aborted
Definition httpd.h:1219
Per-directory configuration.
Definition http_core.h:527
apr_file_t * fd
Definition mod_dialup.c:41
apr_size_t bytes_per_second
Definition mod_dialup.c:39
request_rec * r
Definition mod_dialup.c:40
apr_bucket_brigade * bb
Definition mod_dialup.c:42
apr_bucket_brigade * tmpbb
Definition mod_dialup.c:43
apr_size_t bytes_per_second
Definition mod_dialup.c:35
const char * name
Definition mod_dialup.c:232
apr_size_t bytes_per_second
Definition mod_dialup.c:233
A structure that represents the current request.
Definition httpd.h:845
int status
Definition httpd.h:891
struct ap_filter_t * output_filters
Definition httpd.h:1070
int method_number
Definition httpd.h:898
apr_pool_t * pool
Definition httpd.h:847
char * filename
Definition httpd.h:1018
conn_rec * connection
Definition httpd.h:849
apr_finfo_t finfo
Definition httpd.h:1094
struct ap_conf_vector_t * per_dir_config
Definition httpd.h:1047
apr_thread_mutex_t * invoke_mtx
Definition httpd.h:1089
Apache filter library.