1 | =pod |
---|
2 | |
---|
3 | Net::OSCAR::Callbacks -- Process responses from OSCAR server |
---|
4 | |
---|
5 | =cut |
---|
6 | |
---|
7 | package Net::OSCAR::Callbacks; |
---|
8 | |
---|
9 | $VERSION = '1.925'; |
---|
10 | $REVISION = '$Revision: 1.134 $'; |
---|
11 | |
---|
12 | use strict; |
---|
13 | use vars qw($VERSION); |
---|
14 | use Carp; |
---|
15 | |
---|
16 | use Net::OSCAR::Common qw(:all); |
---|
17 | use Net::OSCAR::Constants; |
---|
18 | use Net::OSCAR::Utility; |
---|
19 | use Net::OSCAR::TLV; |
---|
20 | use Net::OSCAR::Buddylist; |
---|
21 | use Net::OSCAR::_BLInternal; |
---|
22 | use Net::OSCAR::XML; |
---|
23 | |
---|
24 | our %protohandlers; |
---|
25 | |
---|
26 | sub process_snac($$) { |
---|
27 | our($connection, $snac) = @_; |
---|
28 | our($conntype, $family, $subtype, $data, $reqid) = ($connection->{conntype}, $snac->{family}, $snac->{subtype}, $snac->{data}, $snac->{reqid}); |
---|
29 | |
---|
30 | our $reqdata = delete $connection->{reqdata}->[$family]->{pack("N", $reqid)}; |
---|
31 | our $session = $connection->{session}; |
---|
32 | |
---|
33 | my $protobit = snac_to_protobit(%$snac); |
---|
34 | if(!$protobit) { |
---|
35 | return $session->callback_snac_unknown($connection, $snac, $data); |
---|
36 | } |
---|
37 | |
---|
38 | our %data = protoparse($session, $protobit)->unpack($data || ""); |
---|
39 | $connection->log_printf(OSCAR_DBG_DEBUG, "Got SNAC 0x%04X/0x%04X: %s", $snac->{family}, $snac->{subtype}, $protobit); |
---|
40 | |
---|
41 | if(!exists($protohandlers{$protobit})) { |
---|
42 | $protohandlers{$protobit} = eval { |
---|
43 | require "Net/OSCAR/Callbacks/$family/$protobit.pm"; |
---|
44 | }; |
---|
45 | if($@) { |
---|
46 | my $olderr = $@; |
---|
47 | $protohandlers{$protobit} = eval { |
---|
48 | require "Net/OSCAR/Callbacks/0/$protobit.pm"; |
---|
49 | }; |
---|
50 | if($@) { |
---|
51 | $protohandlers{$protobit} = sub {}; |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | $protohandlers{$protobit}->(); |
---|
56 | |
---|
57 | return 1; |
---|
58 | } |
---|
59 | |
---|
60 | sub got_buddylist($$) { |
---|
61 | my($session, $connection) = @_; |
---|
62 | |
---|
63 | $connection->proto_send(protobit => "add_IM_parameters"); |
---|
64 | $connection->ready(); |
---|
65 | |
---|
66 | $session->set_extended_status("") if $session->{capabilities}->{extended_status}; |
---|
67 | $connection->proto_send(protobit => "set_idle", protodata => {duration => 0}); |
---|
68 | $connection->proto_send(protobit => "buddylist_done"); |
---|
69 | |
---|
70 | $session->{is_on} = 1; |
---|
71 | $session->callback_signon_done() unless $session->{sent_done}++; |
---|
72 | } |
---|
73 | |
---|
74 | sub default_snac_unknown($$$$) { |
---|
75 | my($session, $connection, $snac, $data) = @_; |
---|
76 | $session->log_printf_cond(OSCAR_DBG_WARN, sub { "Unknown SNAC %d/%d: %s", $snac->{family},$snac->{subtype}, hexdump($snac->{data}) }); |
---|
77 | } |
---|
78 | |
---|
79 | 1; |
---|
80 | |
---|