Net-Chat-Daemon

 view release on metacpan or  search on metacpan

scripts/jabber  view on Meta::CPAN

  my $tree = $msg->{TREE};
  my $attachments = $tree->add_child("attachments");
  foreach my $attachment (@file_attachments) {
    open(DATA, $attachment) or die "open $attachment: $!";
    my $data = do { local $/; <DATA>; };
    close DATA;

    my $attach = $attachments->add_child("attachment");
    $attach->add_child("type", 'file');
    $attach->add_child("filename", $attachment);
    $attach->add_child("data", xml_escape($data));
  }
  foreach my $attachment (@attachments) {
    my $attach = $attachments->add_child("attachment");
    $attach->add_child("type", 'data');
    $attach->add_child("data", xml_escape($attachment));
  }
  $Con->Send($msg);
  terminate();
  exit 0;
}

if ($action eq 'add') {
  my ($jid) = @args;
  $Con->Subscription(type => "subscribe", to => $jid);
  terminate();
  exit 0;
}

if ($action eq 'dump') {
  my ($jid) = @args;
  use Data::Dumper;
  print Dumper($Con->RosterGet());
  terminate();
  exit 0;
}

while (1) {
  print "receiving...\n";
  defined($Con->Process()) or terminate();
}

terminate();

sub terminate {
  $Con->Disconnect();
  exit 0;
}

sub handleMessage {
  my $sid = shift;
  my $msg = shift;
  my $src = $msg->GetFrom("jid")->GetUserID();
  my $msgtxt = $msg->GetBody();
  print "GOT MESSAGE: $msgtxt\n";
  my $attachments = $msg->{TREE}->XPath("attachments");
  if ($attachments) {
    foreach my $node ($attachments->children()) {
      my %attachment;
      foreach ($node->children()) {
        $attachment{$_->get_tag()} = $_->get_cdata();
      }

      print "Attachment type: $attachment{type}\n";
      local $_ = $attachment{data};
      s/^/= /g;
      print;
      print "\n";
    }
  }
  $Con->MessageSend(to=>$msg->GetFrom(), subject=>"Build of $msgtxt",
                    thread=>"$msg->GetThread()",type=>$msg->GetType(),
                    body=>"response");
}

sub handlePresence {
  my $sid = shift;
  my $presence = shift;
  my $from = $presence->GetFrom();
  my $type = $presence->GetType();
  my $show = $presence->GetShow();
  my $status = $presence->GetStatus();
  print "$from is now $show/$status\n";
}



( run in 0.775 second using v1.01-cache-2.11-cpan-39bf76dae61 )