Vrátit zpět IRC-chat.txt
[pidgin-purple-perl-plugins.git] / open-chats-from-xmpp-bookmarks.pl
blobc5782d6de8b77bc75e559eb8729a3a85332629f8
1 use Purple;
3 my $pluginName = "$pluginName";
4 my $login = "mcepl";
5 my $password = "kyrios";
6 my $loggedAccount = "mcepl\@porky.stuttgart.redhat.com";
8 #+#define XMLNS_BOOKMARK "storage:bookmarks" /* XEP-0048 */
9 #+#define XMLNS_PRIVATE "jabber:iq:private" /* XEP-0049 */
11 $botname = "USERSERV";
12 %PLUGIN_INFO = (
13 perl_api_version => 2,
14 name => "Perl: Open Chats from XMPP Bookmarks",
15 version => "0.1",
16 summary => "Opens all chats on XMPP server according to bookmarks stored there.",
17 description => "Opens all chats on XMPP server according to bookmarks stored there.",
18 author => "Matěj Cepl <mcepl\@redhat.com>",
19 url => "http://matej.ceplovi.cz",
20 load => "plugin_load",
21 unload => "plugin_unload",
24 #(00:25:06) charding: Can anyone tell me what's the difference
25 #between the 'signing-on' and 'account-connecting' signals? Is
26 #signing-on for when pidgin is starting up? and account-connecting
27 #is when pidgin is already running and you enable and that
28 #particular acct is connecting?
29 #(00:29:18) elb: charding: as best I can tell, the only difference is that
30 #signing-on is called for both registration and regular
31 #connection, and account-connecting is called only for the later
32 #(00:29:22) elb: latter
33 #(00:29:28) elb: they're emitted one right after another in
34 #purple_connection_new
37 sub plugin_load {
38 Purple::Debug::info("$pluginName", "start paramterers=@_\n");
39 $plugin = shift;
41 $conn = Purple::Connections::get_handle();
42 Purple::Signal::connect($conn, "signed-on", $plugin,
43 \&signed_on, 0);
44 Purple::Debug::info("$pluginName", "Login to $botname plugin loaded\n");
47 sub plugin_unload {
48 Purple::Debug::info("$pluginName", "Login to $botname plugin unloaded\n");
51 sub signed_on {
52 my $conn = shift;
53 my $account = $conn->get_account();
54 my $username = $account->get_username();
55 Purple::Debug::misc("$pluginName", "signed-on (" . $username . ")\n");
57 # login to USERSERV
58 if ($username eq $loggedAccount) {
59 my $ret = Purple::Prpl::send_raw($conn,
60 ":$login PRIVMSG $botname :login $login $password\n");
61 Purple::Debug::misc("$pluginName", "ret=$ret\n");
64 # Purple::timeout_add();
65 sleep(10);
67 my @allChats = Purple::get_ims();
68 my @allTitles = map($_->get_title(),@allChats);
69 Purple::Debug::misc("$pluginName", "\@allTitles=@allTitles\n");
70 Purple::Debug::misc("$pluginName", "Purple::get_ims() = " . Purple::get_ims());
71 my @userservChats = grep ((
72 $_->get_title() =~ /^\W*$botname\W*$/
73 ), Purple::get_ims());
74 $userservChats[1]->destroy();
77 #+static xt_status jabber_parse_bookmark( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )
78 #+{
79 #+ struct xt_node *query, *c, *c2;
80 #+
81 #+ if( !( query = xt_find_node( node->children, "query" ) ) )
82 #+ {
83 #+ imcb_log( ic, "WARNING: Received NULL roster packet" );
84 #+ return XT_HANDLED;
85 #+ }
86 #+
87 #+ imcb_log( ic, "Bookmark fetched" );
88 #+ c = query->children;
89 #+ if( !( c = xt_find_node( c, "storage" )))
90 #+ return XT_HANDLED;
92 #+ c = c->children;
94 #+ while( ( c = xt_find_node( c, "conference" ) ) )
95 #+ {
96 #+ char *autojoin = xt_find_attr( c, "autojoin" );
97 #+ char *name = xt_find_attr( c, "name" );
98 #+ char *jid = xt_find_attr( c, "jid" );
99 #+ char *nick, *password;
100 #+ nick = NULL;
101 #+ password = NULL;
102 #+ if( (c2 = xt_find_node( c->children, "nick" )))
103 #+ nick = c2->text;
104 #+ if( (c2 = xt_find_node( c->children, "password" )))
105 #+ password = c2->text;
107 #+ if( jid && autojoin &&
108 #+ ( g_strcasecmp( autojoin, "true" ) == 0 ||
109 #+ g_strcasecmp( autojoin, "1" ) == 0 ))
110 #+ {
111 #+ imcb_log( ic, "Autojoin on %s as %s", jid, nick );
112 #+ jabber_chat_join(ic, jid, nick, password);
113 #+ }
115 #+ c = c->next;
116 #+ }
118 # return XT_HANDLED;
121 sub parse_bookmark {
125 #+int jabber_get_bookmark( struct im_connection *ic )
127 #+ struct xt_node *node;
128 #+ int st;
130 #+ imcb_log( ic, "Fetching bookmark list" );
132 #+ node = xt_new_node( "storage", NULL, NULL );
133 #+ xt_add_attr( node, "xmlns", XMLNS_BOOKMARK );
135 #+ node = xt_new_node( "query", NULL, node );
136 #+ xt_add_attr( node, "xmlns", XMLNS_PRIVATE );
137 #+ node = jabber_make_packet( "iq", "get", NULL, node );
139 #+ jabber_cache_add( ic, node, jabber_parse_bookmark );
140 #+ st = jabber_write_packet( ic, node );
141 #+ return st;
145 # Probably better get_bookmarkS (instead of get_bookmark), because
146 # it gets all bookmarks stored on the server.
147 # @param im_connection pointer Connection
148 # @return ???
150 sub get_bookmarks {
151 my $im_connection = shift;
152 my $st = 0;
153 my $xt_node = null;
155 Purple::Debug::info("$pluginName", "Fetching bookmark list\n");
158 # ##################
159 # whenever we get connected
160 # * is this Jabber server?
161 # * if yes, does it support Private Storage?
162 # * if yes, get bookmarks
163 # * for bookmark in bookmarks:
164 # connectMUC(bookmark)# if isAutostart(bookmark) and notOpen(bookmark):