[f1e629d] | 1 | # $Id$ |
---|
| 2 | # |
---|
| 3 | # This is all linked into the binary and evaluated when perl starts up... |
---|
| 4 | # |
---|
| 5 | ##################################################################### |
---|
| 6 | ##################################################################### |
---|
| 7 | |
---|
| 8 | package owl; |
---|
| 9 | |
---|
| 10 | # bootstrap in C bindings and glue |
---|
| 11 | bootstrap owl 1.2; |
---|
| 12 | |
---|
| 13 | # populate global variable space for legacy owlconf files |
---|
| 14 | sub _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 |
---|
| 21 | sub _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"); |
---|
| 28 | sub AUTOLOAD { |
---|
| 29 | my $called = $AUTOLOAD; |
---|
| 30 | $called =~ s/.*:://; |
---|
| 31 | return &owl::command("$called ".join(" ",@_)); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | ##################################################################### |
---|
| 35 | ##################################################################### |
---|
| 36 | |
---|
| 37 | package owl::Message; |
---|
| 38 | |
---|
| 39 | sub type { return shift->{"type"}; } |
---|
| 40 | sub direction { return shift->{"direction"}; } |
---|
| 41 | sub time { return shift->{"time"}; } |
---|
| 42 | sub id { return shift->{"id"}; } |
---|
| 43 | sub body { return shift->{"body"}; } |
---|
| 44 | sub sender { return shift->{"sender"}; } |
---|
| 45 | sub recipient { return shift->{"recipient"}; } |
---|
| 46 | sub login { return shift->{"login"}; } |
---|
[216c734] | 47 | sub is_private { return shift->{"private"}; } |
---|
[f1e629d] | 48 | |
---|
| 49 | sub is_login { return shift->login eq "login"; } |
---|
| 50 | sub is_logout { return shift->login eq "logout"; } |
---|
| 51 | sub is_loginout { my $m=shift; return ($m->is_login or $m->is_logout); } |
---|
| 52 | sub is_incoming { return (shift->{"direction"} eq "in"); } |
---|
| 53 | sub is_outgoing { return (shift->{"direction"} eq "out"); } |
---|
| 54 | |
---|
| 55 | sub is_deleted { return shift->{"deleted"}; } |
---|
| 56 | |
---|
| 57 | sub is_zephyr { return (shift->{"type"} eq "zephyr"); } |
---|
| 58 | sub is_aim { return (shift->{"type"} eq "aim"); } |
---|
| 59 | sub is_admin { return (shift->{"type"} eq "admin"); } |
---|
| 60 | sub is_generic { return (shift->{"type"} eq "generic"); } |
---|
| 61 | |
---|
| 62 | # These are overridden by appropriate message types |
---|
| 63 | sub is_ping { return 0; } |
---|
| 64 | sub is_mail { return 0; } |
---|
[87c6ef1] | 65 | sub is_personal { return undef; } |
---|
[f1e629d] | 66 | sub class { return undef; } |
---|
| 67 | sub instance { return undef; } |
---|
| 68 | sub realm { return undef; } |
---|
| 69 | sub opcode { return undef; } |
---|
| 70 | sub header { return undef; } |
---|
| 71 | sub host { return undef; } |
---|
| 72 | sub hostname { return undef; } |
---|
| 73 | sub auth { return undef; } |
---|
| 74 | sub fields { return undef; } |
---|
| 75 | sub zsig { return undef; } |
---|
| 76 | sub zwriteline { return undef; } |
---|
[87c6ef1] | 77 | sub login_host { return undef; } |
---|
| 78 | sub login_tty { return undef; } |
---|
[f1e629d] | 79 | |
---|
| 80 | sub pretty_sender { return shift->sender; } |
---|
| 81 | |
---|
| 82 | sub delete { |
---|
| 83 | my ($m) = @_; |
---|
| 84 | &owl::command("delete --id ".$m->id); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | sub undelete { |
---|
| 88 | my ($m) = @_; |
---|
| 89 | &owl::command("undelete --id ".$m->id); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | # Serializes the message into something similar to the zwgc->vt format |
---|
| 93 | sub serialize { |
---|
| 94 | my ($this) = @_; |
---|
| 95 | my $s; |
---|
| 96 | for my $f (keys %$this) { |
---|
| 97 | my $val = $this->{$f}; |
---|
| 98 | if (ref($val) eq "ARRAY") { |
---|
| 99 | for my $i (0..@$val-1) { |
---|
| 100 | my $aval; |
---|
| 101 | $aval = $val->[$i]; |
---|
| 102 | $aval =~ s/\n/\n$f.$i: /g; |
---|
| 103 | $s .= "$f.$i: $aval\n"; |
---|
| 104 | } |
---|
| 105 | } else { |
---|
| 106 | $val =~ s/\n/\n$f: /g; |
---|
| 107 | $s .= "$f: $val\n"; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | return $s; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | # Populate the annoying legacy global variables |
---|
| 114 | sub legacy_populate_global { |
---|
| 115 | my ($m) = @_; |
---|
| 116 | $owl::direction = $m->direction ; |
---|
| 117 | $owl::type = $m->type ; |
---|
| 118 | $owl::id = $m->id ; |
---|
| 119 | $owl::class = $m->class ; |
---|
| 120 | $owl::instance = $m->instance ; |
---|
| 121 | $owl::recipient = $m->recipient ; |
---|
| 122 | $owl::sender = $m->sender ; |
---|
| 123 | $owl::realm = $m->realm ; |
---|
| 124 | $owl::opcode = $m->opcode ; |
---|
| 125 | $owl::zsig = $m->zsig ; |
---|
| 126 | $owl::msg = $m->body ; |
---|
| 127 | $owl::time = $m->time ; |
---|
| 128 | $owl::host = $m->host ; |
---|
[282ec9b] | 129 | $owl::login = $m->login ; |
---|
[87c6ef1] | 130 | $owl::auth = $m->auth ; |
---|
[f1e629d] | 131 | if ($m->fields) { |
---|
| 132 | @owl::fields = @{$m->fields}; |
---|
| 133 | @main::fields = @{$m->fields}; |
---|
| 134 | } else { |
---|
| 135 | @owl::fields = undef; |
---|
| 136 | @main::fields = undef; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | ##################################################################### |
---|
| 141 | ##################################################################### |
---|
| 142 | |
---|
| 143 | package owl::Message::Admin; |
---|
| 144 | |
---|
| 145 | @ISA = qw( owl::Message ); |
---|
| 146 | |
---|
| 147 | sub header { return shift->{"header"}; } |
---|
| 148 | |
---|
| 149 | ##################################################################### |
---|
| 150 | ##################################################################### |
---|
| 151 | |
---|
| 152 | package owl::Message::Generic; |
---|
| 153 | |
---|
| 154 | @ISA = qw( owl::Message ); |
---|
| 155 | |
---|
| 156 | ##################################################################### |
---|
| 157 | ##################################################################### |
---|
| 158 | |
---|
| 159 | package owl::Message::AIM; |
---|
| 160 | |
---|
| 161 | @ISA = qw( owl::Message ); |
---|
| 162 | |
---|
| 163 | # all non-loginout AIM messages are personal for now... |
---|
| 164 | sub is_personal { |
---|
| 165 | return !(shift->is_loginout); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | ##################################################################### |
---|
| 169 | ##################################################################### |
---|
| 170 | |
---|
| 171 | package owl::Message::Zephyr; |
---|
| 172 | |
---|
| 173 | @ISA = qw( owl::Message ); |
---|
| 174 | |
---|
| 175 | sub login_tty { |
---|
| 176 | my ($m) = @_; |
---|
| 177 | return undef if (!$m->is_loginout); |
---|
| 178 | return $m->fields->[2]; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | sub login_host { |
---|
| 182 | my ($m) = @_; |
---|
| 183 | return undef if (!$m->is_loginout); |
---|
| 184 | return $m->fields->[0]; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | sub zwriteline { return shift->{"zwriteline"}; } |
---|
| 188 | |
---|
| 189 | sub zsig { return shift->{"zsig"}; } |
---|
| 190 | |
---|
| 191 | sub is_ping { return (lc(shift->opcode) eq "ping"); } |
---|
| 192 | |
---|
| 193 | sub is_personal { |
---|
| 194 | my ($m) = @_; |
---|
| 195 | return ((lc($m->class) eq "message") |
---|
| 196 | && (lc($m->instance) eq "personal") |
---|
| 197 | && $m->is_private); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | sub is_mail { |
---|
| 201 | my ($m) = @_; |
---|
| 202 | return ((lc($m->class) eq "mail") && $m->is_private); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | sub 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 |
---|
| 214 | sub class { return shift->{"class"}; } |
---|
| 215 | sub instance { return shift->{"instance"}; } |
---|
| 216 | sub realm { return shift->{"realm"}; } |
---|
| 217 | sub opcode { return shift->{"opcode"}; } |
---|
| 218 | sub host { return shift->{"hostname"}; } |
---|
| 219 | sub hostname { return shift->{"hostname"}; } |
---|
| 220 | sub header { return shift->{"header"}; } |
---|
| 221 | sub auth { return shift->{"auth"}; } |
---|
| 222 | sub fields { return shift->{"fields"}; } |
---|
| 223 | sub zsig { return shift->{"zsig"}; } |
---|
| 224 | |
---|
| 225 | ##################################################################### |
---|
| 226 | ##################################################################### |
---|
| 227 | |
---|
| 228 | # switch to package main when we're done |
---|
| 229 | package main; |
---|
| 230 | |
---|
| 231 | 1; |
---|