Software /
code /
prosody
Annotate
util/helpers.lua @ 1585:edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
Not all authentication mechanisms have the same requirements; it makes sense
to provide them only with the information they require (and for them to
depend on that) so that as many auth mechanisms as possible can be supported
with a variety of credentials-storing schemes. This commit patches that together
author | nick@lupine.me.uk |
---|---|
date | Fri, 24 Jul 2009 01:34:25 +0100 |
parent | 1531:21051377f11b |
child | 1795:0e933d6f2c31 |
rev | line source |
---|---|
1531
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 module("helpers", package.seeall); |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- Helper functions for debugging |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local log = require "util.logger".init("util.debug"); |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 function log_events(events, name, logger) |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local f = events.fire_event; |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 if not f then |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 error("Object does not appear to be a util.events object"); |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 end |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 logger = logger or log; |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 name = name or tostring(events); |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 function events.fire_event(event, ...) |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 logger("debug", "%s firing event: %s", name, event); |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 events[events.fire_event] = f; |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 return events; |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 function revert_log_events(events) |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 events.fire_event, events[events.fire_event] = events[events.fire_event], nil; -- :) |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
21051377f11b
util.helpers: New util library to aid with debugging, etc.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 return _M; |