-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_swift_api.c
82 lines (61 loc) · 2.21 KB
/
mod_swift_api.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// Copyright (C) 2017 ZeeZide GmbH, All Rights Reserved
// Created by Helge Hess on 23/01/2017.
//
#include "mod_swift.h"
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
#include <http_log.h>
#include <apr_strings.h>
#include <stdio.h>
#include <assert.h>
struct ApacheRequest ApacheRequestCreate(void *raw) {
struct ApacheRequest rq;
rq.raw = raw;
// printf("called raw %p\n", raw);
return rq;
}
#pragma mark Logging
void apz_log_rerror_(const char *file, int line, int module_index,
int level, apr_status_t status,
const request_rec *r, const char *s)
{
ap_log_rerror_(file, line, module_index, level, status, r, "%s", s);
}
void apz_log_error_(const char *file, int line, int module_index,
int level, apr_status_t status,
const server_rec *r, const char *s)
{
ap_log_error_(file, line, module_index, level, status, r, "%s", s);
}
#pragma mark Bucket Brigade Helpers
apr_status_t apz_fwrite(struct ap_filter_t *f, apr_bucket_brigade *bb,
const void *data, apr_size_t nbyte)
{
// ap_fwrite is a macro in Apache. We could get it working in pure Swift,
// but it requires a lot of casting :->
return apr_brigade_write(bb, ap_filter_flush, f, data, nbyte);
}
void apz_brigade_insert_tail(apr_bucket_brigade *bb, apr_bucket *b) {
APR_BRIGADE_INSERT_TAIL(bb, b);
}
#pragma mark Module Helpers
// LoadModule keeps an own array of loaded modules. We don't, at least not yet.
static apr_status_t apz_unload_swift_module(void *_m) {
module *module = _m;
ap_remove_loaded_module(module);
return APR_SUCCESS;
}
apr_status_t apz_register_swift_module(void *_cmd, void *_m) {
cmd_parms *cmd = _cmd;
module *module = _m;
// TODO: LoadModule also sets the 'dynamic_load_handle' in the module.
// Let Apache know about our module
const char *error = ap_add_loaded_module(module, cmd->pool, module->name);
assert(error == NULL); // "Could not add Swift module!"
apr_pool_cleanup_register(cmd->pool, module, apz_unload_swift_module,
apr_pool_cleanup_null);
ap_single_module_configure(cmd->pool, cmd->server, module);
return APR_SUCCESS;
}