#!/usr/bin/env swipl
/* xmpp_print_features.pl
Author: Gimenez, Christian.
Copyright (C) 2026 Gimenez, Christian
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
2026-05-03
*/
:- module(xmpp_print_features, []).
/** xmpp_print_features: A client that prints all server features.
@author Christian Gimenez
@license GPLv3
*/
:- use_module(library(ansi_term)).
:- use_module(library(xmpp/xmpp)).
:- use_module(library(xmpp/xmpp_core)).
:- use_module(library(xmpp/xmpp_auth)).
:- initialization(main, main).
:- dynamic all_done/0.
opt_type(d, debug, boolean).
opt_help(debug, 'Enable debug mode').
print_feat(element(Feat, Attr, Contents)) :-
ansi_format([bold], '* Feature: ~s\n', [Feat]),
format('~q\n~q\n\n', [Attr, Contents]), !.
print_feat(X) :- writeq(X), nl.
receive_hook(Lst) :-
member(data([element('stream:features', _, Content)]), Lst),
% writeq(Content), nl, flush,
maplist(print_feat, Content).
connected_hook(_) :-
asserta(all_done),
write('- Connected -'), nl, flush.
wait_until_end :-
repeat,
sleep(1),
all_done, !.
enable_debug(Options) :-
option(debug(true), Options, false),
debug(xmpp), % debug(xmpp_auth), debug(xmpp_ping),
debug(xmppbot).
get_envdata(JID, Password) :-
getenv('BOTJID', JID),
getenv('BOTPASS', Password).
get_envdata(_, _) :-
throw(error(no_envvar_set,
context(get_envdata/2, 'Please, set BOTJID and BOTPASS environment variables'))).
main(ArgV) :-
argv_options(ArgV, [], Options),
ignore(enable_debug(Options)),
get_envdata(JID, Password),
%% format('~s password?', [JID]), nl,
%% read_line_to_string(current_input, PasswordS),
%% atom_string(Password, PasswordS),
add_hook(received_xml, xmpp_print_features:receive_hook),
add_hook(after_connect, xmpp_print_features:connected_hook),
connect(JID, Password),
wait_until_end,
write('- Done -'), nl, flush.