From 12822292e87f2287961bde5bf3f9a5a90b5e4283 Mon Sep 17 00:00:00 2001 From: djfiander Date: Sun, 16 Apr 2006 15:44:56 +0000 Subject: [PATCH] Move add_count() to Sip.pm from Sip::MsgType.pm --- Sip.pm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Sip.pm b/Sip.pm index da92680..a143460 100644 --- a/Sip.pm +++ b/Sip.pm @@ -17,14 +17,14 @@ use Sip::Checksum qw(checksum); our @ISA = qw(Exporter); -our @EXPORT_OK = qw(y_or_n timestamp add_field maybe_add denied sipbool - boolspace write_msg +our @EXPORT_OK = qw(y_or_n timestamp add_field maybe_add add_count + denied sipbool boolspace write_msg $error_detection $protocol_version $field_delimiter $last_response); our %EXPORT_TAGS = ( all => [qw(y_or_n timestamp add_field maybe_add - denied sipbool boolspace write_msg + add_count denied sipbool boolspace write_msg $error_detection $protocol_version $field_delimiter $last_response)]); @@ -71,6 +71,29 @@ sub maybe_add { return (defined($value) && $value) ? add_field($fid, $value) : ''; } +# +# add_count() produce fixed four-character count field, +# or a string of four spaces if the count is invalid for some +# reason +# +sub add_count { + my ($label, $count) = @_; + + # If the field is unsupported, it will be undef, return blanks + # as per the spec. + if (!defined($count)) { + return ' ' x 4; + } + + $count = sprintf("%04d", $count); + if (length($count) != 4) { + syslog("WARNING", "handle_patron_info: %s wrong size: '%s'", + $label, $count); + $count = ' ' x 4; + } + return $count; +} + # # denied($bool) # if $bool is false, return true. This is because SIP statuses -- 2.11.0