test1.pl untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 39 CC 2 SCAR 12.8
CC
2
Cov
0%
pimp_neticq
6.0
disconnect
2.0
BEGIN
2.0
CRAP 3.6
1 #!/usr/bin/perl
2  
3 # Net::ICQ test script
4  
5  
6 use strict;
7 use Net::ICQ;
8  
9  
10 my ($icq);
11  
12 # Remember that Net::ICQ tries to pull a UIN and password from the
13 # environment if either value here is empty (evaluates as false).
14 $icq = Net::ICQ->new($ARGV[0], $ARGV[1]);
15  
16 if (!$icq) {
17 print <<HELP;
18  
19 Usage: test1.pl UIN PASSWORD
20  
21 You can also set the environment variable ICQ_PASS instead of passing
22 the password on the commandline. This script will go online with the
23 specified UIN, and act as an echo service. Any normal message that
24 is sent to it will be echoed back as a URL, with the message text in
25 the description field, and the URL of the Net::ICQ website in the
26 URL field.
27  
28 Press ctrl-c to exit.
29  
30 HELP
31  
32 exit;
33 }
34  
35 # add a handler for incoming messages, to call the sub pimp_neticq
36 $icq->add_handler("SRV_SYS_DELIVERED_MESS", \&pimp_neticq);
37 # register a SIGINT handler, so ctrl-c will trigger a clean shutdown
38 $SIG{INT} = \&disconnect;
39  
40 # enable debugging (this is undocumented!!!)
41 $icq->{_debug} = 1;
42  
43 # connect to the server
44 $icq->connect;
45  
46 # Run the processing loop. This well never exit. The program exits
47 # when the sub disconnect (below) is called.
48 print "\nPress ctrl-c to exit\n\n";
49 $icq->start;
50  
51  
52 sub pimp_neticq {
53 # incoming event
54 my ($icq, $event) = @_;
55 # params from incoming event, and for outgoing event
56 my ($in_params, $out_params);
57  
58 $in_params = $event->{params};
59  
60 # is this is a normal text message?
61 if ($in_params->{type} == 1){
62  
63 # create a parameter hash for a URL message
64 $out_params = {};
65 $out_params->{type} = 4;
66  
67 # set the receiver to the UIN of the person who sent the message
68 $out_params->{receiver_uin} = $in_params->{uin};
69  
70 # set the description to the message text
71 $out_params->{description} = $in_params->{text};
72  
73 # set the URL to the Net::ICQ website
74 $out_params->{url} = 'http://neticq.sourceforge.net/';
75  
76 # send the message back
77 $icq->send_event('CMD_SEND_MESSAGE', $out_params);
78 }
79 }
80  
81  
82 sub disconnect {
83 $icq->disconnect();
84 exit();
85 }