-
Notifications
You must be signed in to change notification settings - Fork 9
/
mod_small_light.h
188 lines (171 loc) · 4.89 KB
/
mod_small_light.h
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h"
#include "ap_config.h"
#include "ap_mpm.h"
#include "apr_file_io.h"
#include "apr_file_info.h"
#include "apr_mmap.h"
#include "apr_hash.h"
#include "apr_strings.h"
#include <stdio.h>
#include <regex.h>
#include <sys/mman.h>
#define SMALL_LIGHT_PARAM_STR_MAX 512
#define SMALL_LIGHT_PATTERN_MAX_LENGTH 64
#define SMALL_LIGHT_ENGINE_MAX_LENGTH 20
#define SMALL_LIGHT_ENGINE_DUMMY "dummy"
#define SMALL_LIGHT_ENGINE_IMLIB2 "imlib2"
#define SMALL_LIGHT_ENGINE_IMAGEMAGICK "imagemagick"
#define SMALL_LIGHT_DEFAULT_ENGINE SMALL_LIGHT_ENGINE_IMLIB2
#define SMALL_LIGHT_INT_INVALID_VALUE (INT_MAX)
#define SMALL_LIGHT_INT_MIN_VALUE (INT_MIN + 1)
#define SMALL_LIGHT_INT_MAX_VALUE (INT_MAX)
#define SMALL_LIGHT_COORD_INVALID_VALUE (1.e+38)
// function defines.
typedef apr_status_t (*SMALL_LIGHT_FILTER_INIT) (
ap_filter_t *,
apr_bucket_brigade *,
void *);
typedef apr_status_t (*SMALL_LIGHT_FILTER_RECEIVE_DATA) (
ap_filter_t *,
apr_bucket_brigade *,
void *,
apr_bucket *,
const char *,
apr_size_t);
typedef apr_status_t (*SMALL_LIGHT_FILTER_OUTPUT_DATA) (
ap_filter_t *,
apr_bucket_brigade *,
void *,
apr_bucket *);
// typedefs.
typedef struct {
const char *name;
char *param_str;
} small_light_pattern_t;
typedef enum {
SMALL_LIGHT_COORD_UNIT_NONE,
SMALL_LIGHT_COORD_UNIT_PIXEL,
SMALL_LIGHT_COORD_UNIT_PERCENT
} small_light_coord_unit_t;
typedef struct {
double v;
small_light_coord_unit_t u;
} small_light_coord_t;
typedef struct {
short r;
short g;
short b;
short a;
} small_light_color_t;
typedef struct {
double sx;
double sy;
double sw;
double sh;
double dx;
double dy;
double dw;
double dh;
double cw;
double ch;
small_light_color_t cc;
double bw;
double bh;
small_light_color_t bc;
double aspect;
int pt_flg;
int scale_flg;
int inhexif_flg;
int jpeghint_flg;
} small_light_image_size_t;
typedef struct {
apr_pool_t *p;
apr_hash_t *h;
} small_light_server_conf_t;
typedef struct {
apr_bucket_brigade *bb;
SMALL_LIGHT_FILTER_INIT init_func;
SMALL_LIGHT_FILTER_RECEIVE_DATA receive_data_func;
SMALL_LIGHT_FILTER_OUTPUT_DATA output_data_func;
struct timeval t;
apr_table_t *prm;
void *lctx;
} small_light_module_ctx_t;
// external functions.
int small_light_parse_flag(request_rec *r, const char *str);
int small_light_parse_int(request_rec *r, const char *str);
double small_light_parse_double(request_rec *r, const char *str);
int small_light_parse_coord(request_rec *r, small_light_coord_t *crd, const char *str);
double small_light_calc_coord(small_light_coord_t *crd, double v);
int small_light_parse_color(request_rec *r, small_light_color_t *color, const char *str);
void *small_light_alloc(apr_pool_t *pool, apr_size_t size);
void *small_light_realloc(apr_pool_t *pool, void *ptr, apr_size_t size, apr_size_t old_size);
void small_light_free(apr_pool_t *pool, void *ptr);
long small_light_timeval_diff(struct timeval *st, struct timeval *et);
void small_light_calc_image_size(
small_light_image_size_t *sz,
request_rec *r,
small_light_module_ctx_t *ctx,
double iw, double ih);
void small_light_init_param(apr_table_t *prm);
int small_light_parse_param(
request_rec *r,
apr_table_t *prm,
const char *param_str);
int small_light_parse_uri_param(request_rec *r, char *param_str, const char *uri_str);
apr_status_t small_light_receive_data(
unsigned char **image,
size_t *image_len,
const ap_filter_t *f,
const apr_bucket_brigade *bb,
const char *data,
const apr_size_t data_len);
#define small_light_filter_prototype(name)\
apr_status_t small_light_filter_##name##_init(\
ap_filter_t *f,\
apr_bucket_brigade *bb,\
void *v_ctx);\
apr_status_t small_light_filter_##name##_receive_data(\
ap_filter_t *f,\
apr_bucket_brigade *bb,\
void *v_ctx,\
apr_bucket *e,\
const char *data,\
apr_size_t len);\
apr_status_t small_light_filter_##name##_output_data(\
ap_filter_t *f,\
apr_bucket_brigade *bb,\
void *v_ctx,\
apr_bucket *e);
#define small_light_filter_dummy_template(name)\
small_light_filter_prototype(dummy)\
apr_status_t small_light_filter_##name##_init(\
ap_filter_t *f,\
apr_bucket_brigade *bb,\
void *v_ctx)\
{\
return small_light_filter_dummy_init(f, bb, v_ctx);\
}\
\
apr_status_t small_light_filter_##name##_receive_data(\
ap_filter_t *f,\
apr_bucket_brigade *bb,\
void *v_ctx,\
apr_bucket *e,\
const char *data,\
apr_size_t len)\
{\
return small_light_filter_dummy_receive_data(f, bb, v_ctx, e, data, len);\
}\
\
apr_status_t small_light_filter_##name##_output_data(\
ap_filter_t *f,\
apr_bucket_brigade *bb,\
void *v_ctx,\
apr_bucket *e)\
{\
return small_light_filter_dummy_output_data(f, bb, v_ctx, e);\
}