source: perlwrap.pm @ c82b055

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since c82b055 was 282ec9b, checked in by Erik Nygren <nygren@mit.edu>, 21 years ago
Make sure that a newline is always at the end of messages returned by perl style formatting functions. Add owl::login to legacy variables populated for format_msg.
  • Property mode set to 100644
File size: 6.2 KB
Line 
1# $Id$
2#
3# This is all linked into the binary and evaluated when perl starts up...
4#
5#####################################################################
6#####################################################################
7
8package owl;
9
10# bootstrap in C bindings and glue
11bootstrap owl 1.2;
12
13# populate global variable space for legacy owlconf files
14sub _format_msg_legacy_wrap {
15    my ($m) = @_;
16    $m->legacy_populate_global();
17    return &owl::format_msg($m);
18}
19
20# populate global variable space for legacy owlconf files
21sub _receive_msg_legacy_wrap {
22    my ($m) = @_;
23    $m->legacy_populate_global();
24    return &owl::receive_msg($m);
25}
26
27# make owl::<command>("foo") be aliases to owl::command("<command> foo");
28sub AUTOLOAD {
29    my $called = $AUTOLOAD;
30    $called =~ s/.*:://;
31    return &owl::command("$called ".join(" ",@_));
32}
33
34#####################################################################
35#####################################################################
36
37package owl::Message;
38
39sub type        { return shift->{"type"}; }
40sub direction   { return shift->{"direction"}; }
41sub time        { return shift->{"time"}; }
42sub id          { return shift->{"id"}; }
43sub body        { return shift->{"body"}; }
44sub sender      { return shift->{"sender"}; }
45sub recipient   { return shift->{"recipient"}; }
46sub login       { return shift->{"login"}; }
47
48sub is_login    { return shift->login eq "login"; }
49sub is_logout   { return shift->login eq "logout"; }
50sub is_loginout { my $m=shift; return ($m->is_login or $m->is_logout); }
51sub is_incoming { return (shift->{"direction"} eq "in"); }
52sub is_outgoing { return (shift->{"direction"} eq "out"); }
53
54sub is_deleted  { return shift->{"deleted"}; }
55
56sub is_zephyr   { return (shift->{"type"} eq "zephyr"); }
57sub is_aim      { return (shift->{"type"} eq "aim"); }
58sub is_admin    { return (shift->{"type"} eq "admin"); }
59sub is_generic  { return (shift->{"type"} eq "generic"); }
60
61# These are overridden by appropriate message types
62sub is_ping     { return 0; }
63sub is_mail     { return 0; }
64sub class       { return undef; }
65sub instance    { return undef; }
66sub realm       { return undef; }
67sub opcode      { return undef; }
68sub header      { return undef; }
69sub host        { return undef; }
70sub hostname    { return undef; }
71sub auth        { return undef; }
72sub fields      { return undef; }
73sub zsig        { return undef; }
74sub zwriteline  { return undef; }
75
76sub pretty_sender { return shift->sender; }
77
78sub delete {
79    my ($m) = @_;
80    &owl::command("delete --id ".$m->id);
81}
82
83sub undelete {
84    my ($m) = @_;
85    &owl::command("undelete --id ".$m->id);
86}
87
88# Serializes the message into something similar to the zwgc->vt format
89sub serialize {
90    my ($this) = @_;
91    my $s;
92    for my $f (keys %$this) {
93        my $val = $this->{$f};
94        if (ref($val) eq "ARRAY") {
95            for my $i (0..@$val-1) {
96                my $aval;
97                $aval = $val->[$i];
98                $aval =~ s/\n/\n$f.$i: /g;
99                $s .= "$f.$i: $aval\n";   
100            }
101        } else {
102            $val =~ s/\n/\n$f: /g;
103            $s .= "$f: $val\n";
104        }
105    }
106    return $s;
107}
108
109# Populate the annoying legacy global variables
110sub legacy_populate_global {
111    my ($m) = @_;
112    $owl::direction  = $m->direction ;
113    $owl::type       = $m->type      ;
114    $owl::id         = $m->id        ;
115    $owl::class      = $m->class     ;
116    $owl::instance   = $m->instance  ;
117    $owl::recipient  = $m->recipient ;
118    $owl::sender     = $m->sender    ;
119    $owl::realm      = $m->realm     ;
120    $owl::opcode     = $m->opcode    ;
121    $owl::zsig       = $m->zsig      ;
122    $owl::msg        = $m->body      ;
123    $owl::time       = $m->time      ;
124    $owl::host       = $m->host      ;
125    $owl::login      = $m->login     ;
126    if ($m->fields) {
127        @owl::fields = @{$m->fields};
128        @main::fields = @{$m->fields};
129    } else {
130        @owl::fields = undef;
131        @main::fields = undef;
132    }
133}
134
135#####################################################################
136#####################################################################
137
138package owl::Message::Admin;
139
140@ISA = qw( owl::Message );
141
142sub header       { return shift->{"header"}; }
143
144#####################################################################
145#####################################################################
146
147package owl::Message::Generic;
148
149@ISA = qw( owl::Message );
150
151#####################################################################
152#####################################################################
153
154package owl::Message::AIM;
155
156@ISA = qw( owl::Message );
157
158# all non-loginout AIM messages are personal for now...
159sub is_personal { 
160    return !(shift->is_loginout);
161}
162
163#####################################################################
164#####################################################################
165
166package owl::Message::Zephyr;
167
168@ISA = qw( owl::Message );
169
170sub login_tty { 
171    my ($m) = @_;
172    return undef if (!$m->is_loginout);
173    return $m->fields->[2];
174}
175
176sub login_host { 
177    my ($m) = @_;
178    return undef if (!$m->is_loginout);
179    return $m->fields->[0];
180}
181
182sub zwriteline  { return shift->{"zwriteline"}; }
183
184sub zsig        { return shift->{"zsig"}; }
185
186sub is_ping     { return (lc(shift->opcode) eq "ping"); }
187
188sub is_private {
189    my ($m) = @_;
190    return (lc($m->recipient) eq lc(owl::zephyr_getsender()));
191}
192
193sub is_personal { 
194    my ($m) = @_;
195    return ((lc($m->class) eq "message")
196            && (lc($m->instance) eq "personal")
197            && $m->is_private);
198}
199
200sub is_mail { 
201    my ($m) = @_;
202    return ((lc($m->class) eq "mail") && $m->is_private);
203}
204
205sub pretty_sender {
206    my ($m) = @_;
207    my $sender = $m->sender;
208    my $realm = owl::zephyr_getrealm();
209    $sender =~ s/\@$realm$//;
210    return $sender;
211}
212
213# These are arguably zephyr-specific
214sub class       { return shift->{"class"}; }
215sub instance    { return shift->{"instance"}; }
216sub realm       { return shift->{"realm"}; }
217sub opcode      { return shift->{"opcode"}; }
218sub host        { return shift->{"hostname"}; }
219sub hostname    { return shift->{"hostname"}; }
220sub header      { return shift->{"header"}; }
221sub auth        { return shift->{"auth"}; }
222sub fields      { return shift->{"fields"}; }
223sub zsig        { return shift->{"zsig"}; }
224
225#####################################################################
226#####################################################################
227
228# switch to package main when we're done
229package main;
230
2311;
Note: See TracBrowser for help on using the repository browser.