[7a1c90d] | 1 | =pod |
---|
| 2 | |
---|
| 3 | Net::OSCAR::ServerCallbacks -- Process responses from OSCAR client |
---|
| 4 | |
---|
| 5 | =cut |
---|
| 6 | |
---|
| 7 | package Net::OSCAR::ServerCallbacks; |
---|
| 8 | |
---|
| 9 | $VERSION = '1.925'; |
---|
| 10 | $REVISION = '$Revision: 1.8 $'; |
---|
| 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 | use Digest::MD5 qw(md5); |
---|
| 25 | use POSIX qw(ctime); |
---|
| 26 | |
---|
| 27 | our %protohandlers; |
---|
| 28 | our $SESSIONS = bltie(); |
---|
| 29 | our $SCREENNAMES = bltie(); |
---|
| 30 | our %COOKIES; |
---|
| 31 | $SCREENNAMES->{somedude} = {sn => "Some Dude", pw => "somepass", email => 'some@dude.com', blist => [qw(SomeDude OtherDude)]}; |
---|
| 32 | $SCREENNAMES->{otherdude} = {sn => "Other Dude", pw => "otherpass", email => 'other@dude.com', blist => [qw(SomeDude OtherDude)]}; |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | sub srv_send_error($$$) { |
---|
| 36 | my($connection, $family, $errno) = @_; |
---|
| 37 | |
---|
| 38 | $connection->proto_send(family => $family, protobit => "error", protodata => {errno => $errno}); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | sub process_snac($$) { |
---|
| 42 | our($connection, $snac) = @_; |
---|
| 43 | our($conntype, $family, $subtype, $data, $reqid) = ($connection->{conntype}, $snac->{family}, $snac->{subtype}, $snac->{data}, $snac->{reqid}); |
---|
| 44 | our $screenname = $connection->{screenname}; |
---|
| 45 | |
---|
| 46 | our $reqdata = delete $connection->{reqdata}->[$family]->{pack("N", $reqid)}; |
---|
| 47 | our $session = $connection->{session}; |
---|
| 48 | |
---|
| 49 | our $protobit = snac_to_protobit(%$snac); |
---|
| 50 | if(!$protobit) { |
---|
| 51 | return $session->callback_snac_unknown($connection, $snac, $data); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | our %data = protoparse($session, $protobit)->unpack($data); |
---|
| 55 | $connection->log_printf(OSCAR_DBG_DEBUG, "Got SNAC 0x%04X/0x%04X: %s", $snac->{family}, $snac->{subtype}, $protobit); |
---|
| 56 | |
---|
| 57 | if(!exists($protohandlers{$protobit})) { |
---|
| 58 | $protohandlers{$protobit} = eval { |
---|
| 59 | require "Net/OSCAR/ServerCallbacks/$family/$protobit.pm"; |
---|
| 60 | }; |
---|
| 61 | if($@) { |
---|
| 62 | my $olderr = $@; |
---|
| 63 | $protohandlers{$protobit} = eval { |
---|
| 64 | require "Net/OSCAR/ServerCallbacks/0/$protobit.pm"; |
---|
| 65 | }; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | if($protohandlers{$protobit}) { |
---|
| 70 | $protohandlers{$protobit}->(); |
---|
| 71 | } else { |
---|
| 72 | #srv_send_error($connection, $family, 1); |
---|
| 73 | print "Unhandled protobit: $protobit\n"; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | 1; |
---|
| 78 | |
---|