24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
..
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
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
var fr = lib.file.open(befile, [lib.file.mode.read])
if fr.ok == false then
lib.bail('could not open configuration file ', befile)
end
var f = fr.val
var c: lib.mem.vec(lib.store.source) c:init(8)
var text: lib.string.acc text:init(64)
do var buf: int8[64]
while true do
var ct = f:read(buf, [buf.type.N])
if ct == 0 then break end
text:push(buf, ct)
end
end
................................................................................
s.sources = c:crush()
end
--srv.methods.conf_set = terra(self: &srv, key: rawstring, val:rawstring)
-- self.sources.ptr[0]:conf_set(key, val)
--end
srv.metamethods.__methodmissing = macro(function(meth, self, ...)
local primary, ptr, stat, simple = 0,1,2,3
local tk, rt = primary
local expr = {...}
for _,f in pairs(lib.store.backend.entries) do
local fn = f.field or f[1]
local ft = f.type or f[2]
if fn == meth then
rt = ft.type.returntype
if rt == bool then tk = simple
elseif rt.stat_basetype then tk = stat
elseif rt.ptr_basetype then tk = ptr end
break
end
end
if tk == primary then
................................................................................
return `self.sources.ptr[0]:[meth]([expr])
else local ok, empty
local r = symbol(rt)
if tk == ptr then
ok = `r.ptr ~= nil
empty = `[rt]{ptr=nil,ct=0}
elseif tk == stat then
ok = `r.ok ~= false
empty = `[rt]{ok=false,error=1}
elseif tk == simple then
ok = `r == true
empty = `false
end
return quote
var [r] = empty
for i=0,self.sources.ct do var src = self.sources.ptr + i
if src.handle ~= nil then
r = src:[meth]([expr])
if [ok] then break
................................................................................
elseif dbbind.ptr ~= nil then
bind = dbbind.ptr
else bind = '[::]:10917' end
lib.report('binding to ', bind)
lib.net.mg_mgr_init(&self.webmgr)
self.webcon = lib.net.mg_http_listen(&self.webmgr, bind, handle.http, nil)
dbbind:free()
end
srv.methods.poll = terra(self: &srv)
lib.net.mg_mgr_poll(&self.webmgr,1000)
end
srv.methods.shutdown = terra(self: &srv)
|
|
>
>
>
>
>
>
>
>
|
>
|
>
>
>
<
>
>
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
..
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
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
var fr = lib.file.open(befile, [lib.file.mode.read])
if fr.ok == false then
lib.bail('could not open configuration file ', befile)
end
var f = fr.val
var c: lib.mem.vec(lib.store.source) c:init(8)
var text: lib.str.acc text:init(64)
do var buf: int8[64]
while true do
var ct = f:read(buf, [buf.type.N])
if ct == 0 then break end
text:push(buf, ct)
end
end
................................................................................
s.sources = c:crush()
end
--srv.methods.conf_set = terra(self: &srv, key: rawstring, val:rawstring)
-- self.sources.ptr[0]:conf_set(key, val)
--end
terra srv:actor_auth_how(ip: lib.store.inet, usn: rawstring)
var cs: lib.store.credset cs:clear()
for i=0,self.sources.ct do
var set: lib.store.credset = self.sources.ptr[i]:actor_auth_how(ip, usn)
cs = cs + set
end
return cs
end
srv.metamethods.__methodmissing = macro(function(meth, self, ...)
local primary, ptr, stat, simple, oid = 0,1,2,3,4
local tk, rt = primary
local expr = {...}
for _,f in pairs(lib.store.backend.entries) do
local fn = f.field or f[1]
local ft = f.type or f[2]
if fn == meth then
rt = ft.type.returntype
if rt == bool then tk = simple
elseif rt.type == 'integer' then tk = oid
elseif rt.stat_basetype then tk = stat
elseif rt.ptr_basetype then tk = ptr end
break
end
end
if tk == primary then
................................................................................
return `self.sources.ptr[0]:[meth]([expr])
else local ok, empty
local r = symbol(rt)
if tk == ptr then
ok = `r.ptr ~= nil
empty = `[rt]{ptr=nil,ct=0}
elseif tk == stat then
ok = `r.ok == true
empty = `[rt]{ok=false,error=1}
elseif tk == simple then
ok = `r == true
empty = `false
elseif tk == oid then
ok = `r ~= 0
empty = `0
end
return quote
var [r] = empty
for i=0,self.sources.ct do var src = self.sources.ptr + i
if src.handle ~= nil then
r = src:[meth]([expr])
if [ok] then break
................................................................................
elseif dbbind.ptr ~= nil then
bind = dbbind.ptr
else bind = '[::]:10917' end
lib.report('binding to ', bind)
lib.net.mg_mgr_init(&self.webmgr)
self.webcon = lib.net.mg_http_listen(&self.webmgr, bind, handle.http, nil)
if dbbind.ptr ~= nil then dbbind:free() end
end
srv.methods.poll = terra(self: &srv)
lib.net.mg_mgr_poll(&self.webmgr,1000)
end
srv.methods.shutdown = terra(self: &srv)
|