Mercurial > prosody-modules
annotate mod_json_streams/mod_json_streams.lua @ 349:ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 02 Apr 2011 00:04:26 +0500 |
parents | |
children | 98569ec25ac2 |
rev | line source |
---|---|
349
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- XEP-0295: JSON Encodings for XMPP |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 module.host = "*" |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local filters = require "util.filters" |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local json = require "util.json" |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local json_escapes = { |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f", |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"}; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local s_char = string.char; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 for i=0,31 do |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local ch = s_char(i); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 if not json_escapes[ch] then json_escapes[ch] = ("\\u%.4X"):format(i); end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local state_out = 0; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 local state_key_before = 1; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 local state_key_in = 2; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local state_key_escape = 3; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 local state_key_after = 4; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local state_val_before = 5; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 local state_val_in = 6; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local state_val_escape = 7; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local state_val_after = 8; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 local whitespace = { [" "] = true, ["\n"] = true, ["\r"] = true, ["\t"] = true }; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 function json_decoder() |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 local state = state_out; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 local quote; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 local output = ""; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 local buffer = ""; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 return function(input) |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 for ch in input:gmatch(".") do |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 module:log("debug", "%s | %d", ch, state) |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 local final = false; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 if state == state_out then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 if whitespace[ch] then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 elseif ch ~= "{" then return nil, "{ expected"; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 else state = state_key_before end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 elseif state == state_key_before then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 if whitespace[ch] then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 elseif ch ~= "'" and ch ~= "\"" then return nil, "\" expected"; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 else quote = ch; state = state_key_in; end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 elseif state == state_key_in then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 if ch == quote then state = state_key_after; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 elseif ch ~= "s" then return nil, "invalid key, 's' expected"; -- only s as key allowed |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 else end -- ignore key |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 elseif state == state_key_after then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 if whitespace[ch] then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 elseif ch ~= ":" then return nil, ": expected"; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 else state = state_val_before; end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 elseif state == state_val_before then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 if whitespace[ch] then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 elseif ch ~= "'" and ch ~= "\"" then return nil, "\" expected"; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 else quote = ch; state = state_val_in; end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 elseif state == state_val_in then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 if ch == quote then state = state_val_after; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 elseif ch == "\\" then state = state_val_escape; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 else end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 elseif state == state_val_after then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 if whitespace[ch] then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 elseif ch ~= "}" then return nil, "} expected"; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 else state = state_out; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 final = true; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 elseif state == state_val_escape then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 state = state_val_in; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 else |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 module:log("error", "Unhandled state: "..state); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 return nil, "Unhandled state in parser" |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 buffer = buffer..ch; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 if final then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 module:log("debug", "%s", buffer) |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 local tmp; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 pcall(function() tmp = json.decode(buffer); end); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 if not tmp then return nil, "Invalid JSON"; end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 output, buffer = output..tmp.s, ""; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 local _ = output; output = ""; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 return _; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 end; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 function filter_hook(session) |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 local determined = false; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 local is_json = false; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 local function in_filter(t) |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 if not determined then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 is_json = (t:sub(1,1) == "{") and json_decoder(); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 determined = true; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 if is_json then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 local s, err = is_json(t); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 if not err then return s; end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 session:close("not-well-formed"); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 return; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 return t; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 local function out_filter(t) |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 if is_json then |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 return '{"s":"' .. t:gsub(".", json_escapes) .. '"}'; -- encode |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 return t; |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 filters.add_filter(session, "bytes/in", in_filter, 100); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 filters.add_filter(session, "bytes/out", out_filter, 100); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 function module.load() |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 filters.add_filter_hook(filter_hook); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 function module.unload() |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 filters.remove_filter_hook(filter_hook); |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 end |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 |
ee99eafdd168
mod_json_streams: An implementation of XEP-0295: JSON Encodings for XMPP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 |