|
@@ -0,0 +1,55 @@
|
|
1
|
+socket = require "socket"
|
|
2
|
+
|
|
3
|
+function shortname()
|
|
4
|
+ local long = socket.dns.gethostname()
|
|
5
|
+ return string.gmatch(long, '[^.]+')()
|
|
6
|
+end
|
|
7
|
+
|
|
8
|
+function get_queue(mbox)
|
|
9
|
+ --TODO: try to get tail
|
|
10
|
+ return mbox.FILTER_QUEUE:is_newer(84)
|
|
11
|
+end
|
|
12
|
+
|
|
13
|
+function _partinf_compare(a, b)
|
|
14
|
+ if not type(a) == type(b) then
|
|
15
|
+ return false
|
|
16
|
+ end
|
|
17
|
+ if type(a) == 'number' then
|
|
18
|
+ return a == b
|
|
19
|
+ elseif type(a) == 'string' then
|
|
20
|
+ return a:lower() == b:lower()
|
|
21
|
+ end
|
|
22
|
+end
|
|
23
|
+
|
|
24
|
+function has_part_like(query, structure)
|
|
25
|
+ if structure == nil then
|
|
26
|
+ return false
|
|
27
|
+ end
|
|
28
|
+ for partid, partinf in pairs(structure) do
|
|
29
|
+ local part_answer = true
|
|
30
|
+ -- check all query parts
|
|
31
|
+ for qkey, qvalue in pairs(query) do
|
|
32
|
+ value = partinf[qkey]
|
|
33
|
+ if not _partinf_compare(value, qvalue) then
|
|
34
|
+ part_answer = false
|
|
35
|
+ break
|
|
36
|
+ end
|
|
37
|
+ end
|
|
38
|
+ if part_answer then
|
|
39
|
+ return true
|
|
40
|
+ end
|
|
41
|
+ end
|
|
42
|
+ return false
|
|
43
|
+end
|
|
44
|
+
|
|
45
|
+function filter_part_like(query, seq)
|
|
46
|
+ result = Set {}
|
|
47
|
+ for _, mesg in ipairs(seq) do
|
|
48
|
+ mbox, uid = table.unpack(mesg)
|
|
49
|
+ structure = mbox[uid]:fetch_structure()
|
|
50
|
+ if has_part_like(query, structure) then
|
|
51
|
+ table.insert(result, mesg)
|
|
52
|
+ end
|
|
53
|
+ end
|
|
54
|
+ return result
|
|
55
|
+end
|