Apache HTTPD
lua_apr.c
Go to the documentation of this file.
1
18#include "mod_lua.h"
19#include "lua_apr.h"
21
23{
25 luaL_checkudata(L, index, "Apr.Table");
26 t = lua_unboxpointer(L, index);
27 return t;
28}
29
30
32{
33 lua_boxpointer(L, t);
34 luaL_getmetatable(L, "Apr.Table");
35 lua_setmetatable(L, -2);
36}
37
39{
41 const char *key = luaL_checkstring(L, 2);
42 const char *val = luaL_optlstring(L, 3, NULL, NULL);
43
44 if (!val) {
46 return 0;
47 }
48
49 /* Unless it's the 'notes' table, check for newline chars */
50 /* t->r will be NULL in case of the connection notes, but since
51 we aren't going to check anything called 'notes', we can safely
52 disregard checking whether t->r is defined.
53 */
54 if (strcmp(t->n, "notes") && ap_strchr_c(val, '\n')) {
55 char *badchar;
56 char *replacement = apr_pstrdup(t->r->pool, val);
57 badchar = replacement;
58 while ( (badchar = ap_strchr(badchar, '\n')) ) {
59 *badchar = ' ';
60 }
62 "mod_lua: Value for '%s' in table '%s' contains newline!",
63 key, t->n);
64 apr_table_set(t->t, key, replacement);
65 }
66 else {
67 apr_table_set(t->t, key, val);
68 }
69 return 0;
70}
71
73{
75 const char *key = luaL_checkstring(L, 2);
76 const char *val = apr_table_get(t->t, key);
78 return 1;
79}
80
81static const luaL_Reg lua_table_methods[] = {
82 {"set", lua_table_set},
83 {"get", lua_table_get},
84 {0, 0}
85};
86
87
89{
90 luaL_newmetatable(L, "Apr.Table");
91#if LUA_VERSION_NUM < 502
92 luaL_register(L, "apr_table", lua_table_methods);
93#else
95#endif
96 lua_pushstring(L, "__index");
97 lua_pushstring(L, "get");
98 lua_gettable(L, 2);
99 lua_settable(L, 1);
100
101 lua_pushstring(L, "__newindex");
102 lua_pushstring(L, "set");
103 lua_gettable(L, 2);
104 lua_settable(L, 1);
105
106 return 0;
107}
108
109
110
#define APLOG_USE_MODULE(foo)
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_WARNING
Definition http_log.h:68
#define ap_strchr(s, c)
Definition httpd.h:2351
#define ap_strchr_c(s, c)
Definition httpd.h:2353
apr_size_t size
apr_uint32_t val
Definition apr_atomic.h:66
const char * key
apr_interval_time_t t
int ap_lua_init(lua_State *L, apr_pool_t *p)
Definition lua_apr.c:88
static int lua_table_set(lua_State *L)
Definition lua_apr.c:38
req_table_t * ap_lua_check_apr_table(lua_State *L, int index)
Definition lua_apr.c:22
static const luaL_Reg lua_table_methods[]
Definition lua_apr.c:81
void ap_lua_push_apr_table(lua_State *L, req_table_t *t)
Definition lua_apr.c:31
static int lua_table_get(lua_State *L)
Definition lua_apr.c:72
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359