36 local function new_plain(realm, credentials_handler) |
36 local function new_plain(realm, credentials_handler) |
37 local object = { mechanism = "PLAIN", realm = realm, credentials_handler = credentials_handler} |
37 local object = { mechanism = "PLAIN", realm = realm, credentials_handler = credentials_handler} |
38 function object.feed(self, message) |
38 function object.feed(self, message) |
39 if message == "" or message == nil then return "failure", "malformed-request" end |
39 if message == "" or message == nil then return "failure", "malformed-request" end |
40 local response = message |
40 local response = message |
41 local authorization = s_match(response, "([^&%z]+)") |
41 local authorization = s_match(response, "([^%z]+)") |
42 local authentication = s_match(response, "%z([^&%z]+)%z") |
42 local authentication = s_match(response, "%z([^%z]+)%z") |
43 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") |
43 local password = s_match(response, "%z[^%z]+%z([^%z]+)") |
44 |
44 |
45 if authentication == nil or password == nil then return "failure", "malformed-request" end |
45 if authentication == nil or password == nil then return "failure", "malformed-request" end |
46 self.username = authentication |
46 self.username = authentication |
47 local auth_success = self.credentials_handler("PLAIN", self.username, self.realm, password) |
47 local auth_success = self.credentials_handler("PLAIN", self.username, self.realm, password) |
48 |
48 |