103 function (session, stanza) |
103 function (session, stanza) |
104 log("debug", "Client tried to bind to a resource"); |
104 log("debug", "Client tried to bind to a resource"); |
105 local resource; |
105 local resource; |
106 if stanza.attr.type == "set" then |
106 if stanza.attr.type == "set" then |
107 local bind = stanza.tags[1]; |
107 local bind = stanza.tags[1]; |
108 |
|
109 if bind and bind.attr.xmlns == xmlns_bind then |
108 if bind and bind.attr.xmlns == xmlns_bind then |
110 resource = bind:child_with_name("resource"); |
109 resource = bind:child_with_name("resource"); |
111 if resource then |
110 if resource then |
112 resource = resource[1]; |
111 resource = resource[1]; |
113 end |
112 end |
114 end |
113 end |
115 end |
114 end |
116 local success, err = sm_bind_resource(session, resource); |
115 local success, err_type, err, err_msg = sm_bind_resource(session, resource); |
117 if not success then |
116 if not success then |
118 local reply = st.reply(stanza); |
117 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
119 reply.attr.type = "error"; |
|
120 if err == "conflict" then |
|
121 reply:tag("error", { type = "modify" }) |
|
122 :tag("conflict", { xmlns = xmlns_stanzas }); |
|
123 elseif err == "constraint" then |
|
124 reply:tag("error", { type = "cancel" }) |
|
125 :tag("resource-constraint", { xmlns = xmlns_stanzas }); |
|
126 elseif err == "auth" then |
|
127 reply:tag("error", { type = "cancel" }) |
|
128 :tag("not-allowed", { xmlns = xmlns_stanzas }); |
|
129 end |
|
130 send(session, reply); |
|
131 else |
118 else |
132 local reply = st.reply(stanza); |
119 session.send(st.reply(stanza) |
133 reply:tag("bind", { xmlns = xmlns_bind}) |
120 :tag("bind", { xmlns = xmlns_bind}) |
134 :tag("jid"):text(session.full_jid); |
121 :tag("jid"):text(session.full_jid)); |
135 send(session, reply); |
|
136 end |
122 end |
137 end); |
123 end); |
138 |
124 |
139 add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", |
125 add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", |
140 function (session, stanza) |
126 function (session, stanza) |