*** Protocol.pm.orig Fri Aug 22 18:39:18 2003 --- Protocol.pm Sat Oct 11 13:09:04 2003 *************** *** 15,21 **** @EXPORT_OK = qw(pad padding padded hexi make_num_hash default_error_handler); ! $VERSION = "0.51"; sub padding ($) { my($x) = @_; --- 15,21 ---- @EXPORT_OK = qw(pad padding padded hexi make_num_hash default_error_handler); ! $VERSION = "0.51.s2"; sub padding ($) { my($x) = @_; *************** *** 571,593 **** return $mask; } sub default_error_handler { ! my($self, $data) = @_; ! my($type, $seq, $info, $minor_op, $major_op) ! = unpack("xCSLSCxxxxxxxxxxxxxxxxxxxxx", $data); ! my($t); ! $t = join("", "Protocol error: bad $type (", ! $self->do_interp('Error', $type), "); ", ! "Sequence Number $seq\n", ! " Opcode ($major_op, $minor_op) = ", ! ($self->do_interp('Request', $major_op) ! or $self->{'ext_request'}{$major_op}[$minor_op][0]), "\n"); ! if ($type == 2) { ! $t .= " Bad value $info (" . hexi($info) . ")\n"; ! } elsif ($self->{'error_type'}[$type] & 1) { ! $t .= " Bad resource $info (" . hexi($info) . ")\n"; ! } ! croak($t); } sub handle_input { --- 571,598 ---- return $mask; } + sub make_error_msg { + my($self, $data) = @_; + my($type, $seq, $info, $minor_op, $major_op) + = unpack("xCSLSCxxxxxxxxxxxxxxxxxxxxx", $data); + my($t); + $t = join("", "Protocol error: bad $type (", + $self->do_interp('Error', $type), "); ", + "Sequence Number $seq\n", + " Opcode ($major_op, $minor_op) = ", + ($self->do_interp('Request', $major_op) + or $self->{'ext_request'}{$major_op}[$minor_op][0]), "\n"); + if ($type == 2) { + $t .= " Bad value $info (" . hexi($info) . ")\n"; + } elsif ($self->{'error_type'}[$type] & 1) { + $t .= " Bad resource $info (" . hexi($info) . ")\n"; + } + return $t; + } + sub default_error_handler { ! my($self, $data) = @_; ! croak($self->make_error_msg($data)); } sub handle_input { *************** *** 597,604 **** $type_b = $self->get(1); $type = unpack "C", $type_b; if ($type == 0) { ! &{$self->{'error_handler'}}($self, $type_b . $self->get(31)); ! return 0; } elsif ($type > 1) { if ($self->{'event_handler'} eq "queue") { push @{$self->{'event_queue'}}, $type_b . $self->get(31); --- 602,614 ---- $type_b = $self->get(1); $type = unpack "C", $type_b; if ($type == 0) { ! my $data = $type_b . $self->get(31); ! my ($type, $seq, $info, $minor_op, $major_op) ! = unpack("xCSLSCxxxxxxxxxxxxxxxxxxxxx", $data); ! &{$self->{'error_handler'}}($self, $data); ! # return 0 to denote an error & the sequence number to identify ! # which request it applies to. ! return (0, $seq); } elsif ($type > 1) { if ($self->{'event_handler'} eq "queue") { push @{$self->{'event_queue'}}, $type_b . $self->get(31); *************** *** 2031,2036 **** --- 2041,2047 ---- my($op, $args, $major, $minor) = (@_, 0); my($data); ($data, $minor) = (&{$op->[1]}($self, @$args), $minor); + # print($op->[0] . " req has seq: " . $self->{sequence_num} . "\n"); $minor = 0 unless defined $minor; my($len) = (length($data) / 4) + 1; croak "Request too long!\n" if $len > $self->{'maximum_request_length'}; *************** *** 2054,2061 **** $self->give($self->assemble_request($op, \@args, $major, $minor)); $seq = $self->next_sequence(); $self->add_reply($seq & 0xffff, \$data); ! $self->handle_input() until $data; $self->delete_reply($seq & 0xffff); return &{$op->[2]}($self, $data); } elsif (@$op == 4) { # Many replies my($seq, $data, @stuff, @ret); --- 2065,2077 ---- $self->give($self->assemble_request($op, \@args, $major, $minor)); $seq = $self->next_sequence(); $self->add_reply($seq & 0xffff, \$data); ! while (1) ! { ! my @ret = $self->handle_input(); ! last if ($data || ($ret[0] == 0 && $ret[1] == $seq)); ! } $self->delete_reply($seq & 0xffff); + return undef unless $data; return &{$op->[2]}($self, $data); } elsif (@$op == 4) { # Many replies my($seq, $data, @stuff, @ret); *************** *** 2063,2069 **** $seq = $self->next_sequence(); $self->add_reply($seq & 0xffff, \$data); for (;;) { ! $data = 0; $self->handle_input() until $data; @stuff = &{$op->[2]}($self, $data); last unless @stuff; if ($op->[3] eq "ARRAY") { --- 2079,2095 ---- $seq = $self->next_sequence(); $self->add_reply($seq & 0xffff, \$data); for (;;) { ! $data = 0; ! while (1) ! { ! my @ret = $self->handle_input(); ! last if ($data || ($ret[0] == 0 && $ret[1] == $seq)); ! } ! if (!$data) ! { ! $self->delete_reply($seq & 0xffff); ! return undef; ! } @stuff = &{$op->[2]}($self, $data); last unless @stuff; if ($op->[3] eq "ARRAY") { *************** *** 2392,2399 **** $self->give($self->assemble_request($op, \@_, $major, $minor)); $seq = $self->next_sequence(); $self->add_reply($seq, \$data); ! $self->handle_input() until $data; $self->delete_reply($seq); return &{$op->[2]}($self, $data); }; } else { # ListFontsWithInfo --- 2418,2430 ---- $self->give($self->assemble_request($op, \@_, $major, $minor)); $seq = $self->next_sequence(); $self->add_reply($seq, \$data); ! while (1) ! { ! my @ret = $self->handle_input(); ! last if ($data || ($ret[0] == 0 && $ret[1] == $seq)); ! } $self->delete_reply($seq); + return undef unless $data; return &{$op->[2]}($self, $data); }; } else { # ListFontsWithInfo