Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
log-to-scs: remove stream management nonzas by default
Browse files Browse the repository at this point in the history
  • Loading branch information
horazont committed Sep 16, 2019
1 parent d0997d3 commit dfa3768
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion utils/log-to-scs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
)


SM_TAGS = [
"{urn:xmpp:sm:3}a",
"{urn:xmpp:sm:3}r",
"{urn:xmpp:sm:3}enable",
"{urn:xmpp:sm:3}enabled"
]


def _parse_stream_bytes(b):
FOOTER = b"</stream:stream>"
b = ast.literal_eval(b)
Expand Down Expand Up @@ -124,6 +132,19 @@ def xmllines(tree):
return [line for line in lines if line.strip()]


def filter_sm(actions):
for action in actions:
xml = action.get("sent", action.get("recv"))
if xml is None:
yield action
continue

if xml["xml"].tag in SM_TAGS:
continue

yield action


def filter_sessions(actions):
ids_to_drop = set()
for action in actions:
Expand Down Expand Up @@ -274,6 +295,13 @@ def bind_client(client_id, jid):
default=[],
const=filter_serverdisco,
)
parser.add_argument(
"--no-strip-stream-management",
action="append_const",
dest="remove_filters",
default=[],
const=filter_sm,
)
parser.add_argument(
"--no-strip-sessions",
action="append_const",
Expand Down Expand Up @@ -304,7 +332,7 @@ def bind_client(client_id, jid):

args = parser.parse_args()

filters = [filter_sessions]
filters = [filter_sm, filter_sessions]
for to_add in args.add_filters:
filters.append(to_add)
for to_remove in args.remove_filters:
Expand Down

0 comments on commit dfa3768

Please sign in to comment.