#!/usr/bin/perl # Copyright 2005 Jerzy Wachowiak use strict; use warnings; use Text::CSV_XS; use File::Copy; use xdSRA; my $filepath = shift; defined( $filepath ) or usage(); my $result = xdSRA::create_sra_from( $filepath ); my @sender = @{ $result->{sender} }; my @receiver = @{ $result->{receiver} }; my @archivist = @{ $result->{archivist} }; print "\n---Start creating straw command files---\n"; for my $si (0..$#sender) { my $jclientpath = "$sender[$si]{username}\@$sender[$si]{hostname}_$sender[$si]{resource}"; create_straw_dir( $jclientpath ); my $senderFQJID = "$sender[$si]{username}\@$sender[$si]{hostname}/$sender[$si]{resource}"; my $archivistJID = "$archivist[0]{username}\@$archivist[0]{hostname}"; print "Files created for $jclientpath in the directory straw: "; create_connection( "$jclientpath/straw/c", $sender[$si]{hostname} ); print 'c, '; create_authentication( "$jclientpath/straw/a", $sender[$si]{username}, $sender[$si]{password}, $sender[$si]{resource} ); print 'a, '; create_presence( "$jclientpath/straw/p" ); print 'p, '; create_selftest( "$jclientpath/straw/s", $senderFQJID, 'Jabber sever should send as repley an error message.' ); print 's, '; create_normal( "$jclientpath/straw/n", $senderFQJID, $archivistJID, 'Archivist should discard this message.' ); print 'n, '; create_good( "$jclientpath/straw/g", $senderFQJID, $archivistJID, 'Archivist has to send back confirmation with the same id.', $sender[$si]{id} ); print 'g, '; create_bad( "$jclientpath/straw/b", $senderFQJID, $archivistJID, 'Sender has dedected some processing error.', $sender[$si]{id} ); print 'b, '; create_error( "$jclientpath/straw/e", $senderFQJID, $archivistJID, 'Some internal processing error has happend.' ); print "e\n"; create_readme( "$jclientpath/straw/README.txt"); print "README.txt.\n"; copy_straw( $jclientpath ) }; for my $ri (0..$#receiver) { my $jclientpath = "$receiver[$ri]{username}\@$receiver[$ri]{hostname}_$receiver[$ri]{resource}"; create_straw_dir( $jclientpath ); my $receiverFQJID = "$receiver[$ri]{username}\@$receiver[$ri]{hostname}" ."/$receiver[$ri]{resource}"; my $archivistJID = "$archivist[0]{username}\@$archivist[0]{hostname}"; print "Files created for $jclientpath in the directory straw: "; create_connection( "$jclientpath/straw/c", $receiver[$ri]{hostname} ); print 'c, '; create_authentication( "$jclientpath/straw/a", $receiver[$ri]{username}, $receiver[$ri]{password}, $receiver[$ri]{resource} ); print 'a, '; create_presence( "$jclientpath/straw/p" ); print 'p, '; create_selftest( "$jclientpath/straw/s", $receiverFQJID, 'Jabber sever should send as repley an error message.' ); print 's, '; create_normal( "$jclientpath/straw/n", $receiverFQJID, $archivistJID, 'Archivist should discard this message.' ); print 'n, '; create_good( "$jclientpath/straw/g", $receiverFQJID, $archivistJID, 'Receiver sends result of a job, which has succeeded.' ); print 'g, '; create_bad( "$jclientpath/straw/b", $receiverFQJID, $archivistJID, 'Receiver sends result of a job, which failed' ); print 'b, '; create_error( "$jclientpath/straw/e", $receiverFQJID, $archivistJID, 'Some internal processing error has happend.' ); print "e\n"; create_readme( "$jclientpath/straw/README.txt"); print "README.txt.\n"; copy_straw( $jclientpath ) }; for my $ai (0..0) { my $jclientpath = "$archivist[$ai]{username}\@$archivist[$ai]{hostname}_$archivist[$ai]{resource}"; create_straw_dir( $jclientpath ); my $archivistFQJID = "$archivist[$ai]{username}\@$archivist[$ai]{hostname}/$archivist[$ai]{resource}"; print "Files created for $jclientpath in the directory straw: "; create_connection( "$jclientpath/straw/c", $archivist[$ai]{hostname} ); print 'c, '; create_authentication( "$jclientpath/straw/a", $archivist[$ai]{username}, $archivist[$ai]{password}, $archivist[$ai]{resource} ); print 'a, '; create_presence( "$jclientpath/straw/p" ); print 'p, '; create_selftest( "$jclientpath/straw/s", $archivistFQJID, 'Jabber sever should send as repley an error message.' ); print 's, '; for my $si (0..$#sender) { my $senderJID = "$sender[$si]{username}\@$sender[$si]{hostname}"; create_good( "$jclientpath/straw/g$sender[$si]{id}", $archivistFQJID, $senderJID, 'Job confirmation sent back to the sender.', $sender[$si]{id} ); print "g$sender[$si]{id}, "; create_bad( "$jclientpath/straw/b$sender[$si]{id}", $archivistFQJID, $senderJID, 'Archivist has dedected some processing error.', $sender[$si]{id} ); print "b$sender[$si]{id}, "; create_error( "$jclientpath/straw/e$sender[$si]{id}", $archivistFQJID, $senderJID, 'Some internal processing error has happend.' ); print "e$sender[$si]{id}\n"; create_readme( "$jclientpath/straw/README.txt"); print "README.txt.\n"; } copy_straw( $jclientpath ) }; print "---End creating straw command files---\n"; exit; sub create_connection { my $file = shift; my $host = shift; my $xml = < $username $password $resource EOM xml2file( $file, $xml ) } sub create_presence { my $file = shift; my $xml = < EOM xml2file( $file, $xml ) } sub create_selftest { my $file = shift; my $FQJID = shift; my $body = shift; my $id_string; if ( defined( my $id = shift ) ){ $id_string = " id='$id'" } else { $id_string = '' }; my $xml = < a message to myself $body EOM xml2file( $file, $xml ) } sub create_normal { my $file = shift; my $fromFQJID = shift; my $toJID = shift; my $body = shift; my $id_string; if ( defined( my $id = shift ) ){ $id_string = " id='$id'" } else { $id_string = '' }; my $xml = < test a message of type normal $body EOM xml2file( $file, $xml ) } sub create_good { my $file = shift; my $fromFQJID = shift; my $toJID = shift; my $body = shift; my $id_string; if ( defined( my $id = shift ) ){ $id_string = " id='$id'" } else { $id_string = '' }; my $xml = < test a good message $body EOM xml2file( $file, $xml ) } sub create_bad { my $file = shift; my $fromFQJID = shift; my $toJID = shift; my $body = shift; my $id_string; if ( defined( my $id = shift ) ){ $id_string = " id='$id'" } else { $id_string = '' }; my $xml = < test a bad processing message $body xDash agent error EOM xml2file( $file, $xml ) } sub create_error { my $file = shift; my $fromFQJID = shift; my $toJID = shift; my $body = shift; my $id_string; if ( defined( my $id = shift ) ){ $id_string = " id='$id'" } else { $id_string = '' }; my $xml = < test an internal error message $body unknown internal error EOM xml2file( $file, $xml ) } sub xml2file { my $file = shift; my $xml = shift; open( FILE, "> $file" ); print FILE $xml; close( FILE ) } sub trim { my @out=@_; for (@out) { s/^\s+//; s/\s+$//; } return wantarray ? @out : $out[0]; } sub copy_straw { my $jclientpath = shift; if ( -e 'straw' ){ copy('straw', "$jclientpath/straw/straw" ) or die 'Failed to copy script straw to the directory' ." ./$jclientpath/straw ($!). Bye, bye...\n" } else { print "Missing script straw," ." cannot copy to the directory ./$jclientpath/straw\n" } } sub create_straw_dir { my $jclientpath = shift; unless ( -d $jclientpath ){ mkdir( $jclientpath ) or die "Failed to create the directory $jclientpath ($!). Bye, bye...\n"; } unless ( -d "$jclientpath/straw" ){ mkdir("$jclientpath/straw") or die "Failed to create directory straw in $jclientpath ($!)." ." Bye, bye...\n"; } } sub usage { print < waiting for jabber server response [3] a -> waiting for jabber server response [4] p -> waiting for jabber server response [5] s -> waiting for jabber server response [6] n -> waiting for jabber server response [7] g -> waiting for response of another agent [8] b -> waiting for response of another agent [9] e -> waiting for jabber server response [10] CRT+C @ Sea also [1] Book "Programming Jabber" by DJ Adams, ISBN: 0-596-00202-5; [2] Jabber protocol description on www.jabber.org. EOT xml2file( $file, $text ) }