+sub waitfor
+{
+ my $conn = shift;
+ my $msg = shift;
+ $msg =~ s/\cM//g;
+
+ my $buf = $conn->{msg};
+ $buf =~ s/\r/\\r/g;
+ $buf =~ s/\n/\\n/g;
+ dbg "state $conn->{state} '$msg' '$buf'";
+
+ if ($conn->{state} eq 'waitfor') {
+ if ($msg =~ /utc$/ ) {
+ $conn->send_later("$conn->{target_call}\n");
+ $conn->{state} = 'working';
+ }
+ } elsif ($conn->{state} eq 'working') {
+ if ($conn->{msg} =~ /^\rquery->\s*$/) {
+ $conn->send_later("QUIT\n");
+ $conn->{state} = 'ending';
+ }
+ return if $msg =~ /^query->/;
+ $conn->handle_raw($msg);
+ } else {
+ return if $msg =~ /^query->/ || $msg =~ /bye/;
+ $conn->handle_raw($msg);
+ }
+}
+