[f1e629d] | 1 | # $Id$ |
---|
| 2 | # |
---|
| 3 | # This is all linked into the binary and evaluated when perl starts up... |
---|
| 4 | # |
---|
| 5 | ##################################################################### |
---|
| 6 | ##################################################################### |
---|
[b6c067a] | 7 | # XXX NOTE: This file is sourced before almost any barnowl |
---|
| 8 | # architecture is loaded. This means, for example, that it cannot |
---|
[0337203] | 9 | # execute any owl commands. Any code that needs to do so should live |
---|
| 10 | # in BarnOwl::Hooks::_startup |
---|
[f1e629d] | 11 | |
---|
[c681337] | 12 | use strict; |
---|
| 13 | use warnings; |
---|
| 14 | |
---|
[8203afd] | 15 | package BarnOwl; |
---|
[f1e629d] | 16 | |
---|
[8862725] | 17 | BEGIN { |
---|
[f1e629d] | 18 | # bootstrap in C bindings and glue |
---|
[8203afd] | 19 | *owl:: = \*BarnOwl::; |
---|
| 20 | bootstrap BarnOwl 1.2; |
---|
[8862725] | 21 | }; |
---|
| 22 | |
---|
[3354cea5] | 23 | use lib(get_data_dir()."/lib"); |
---|
[2e3b9c2] | 24 | use lib($ENV{HOME}."/.owl/lib"); |
---|
[8862725] | 25 | |
---|
[00f9a7d] | 26 | our $configfile; |
---|
| 27 | |
---|
[2e3b9c2] | 28 | if(!$configfile && -f $ENV{HOME} . "/.barnowlconf") { |
---|
| 29 | $configfile = $ENV{HOME} . "/.barnowlconf"; |
---|
| 30 | } |
---|
| 31 | $configfile ||= $ENV{HOME}."/.owlconf"; |
---|
[d03091c] | 32 | |
---|
[186cdc4] | 33 | # populate global variable space for legacy owlconf files |
---|
[f1e629d] | 34 | sub _format_msg_legacy_wrap { |
---|
| 35 | my ($m) = @_; |
---|
| 36 | $m->legacy_populate_global(); |
---|
[8203afd] | 37 | return &BarnOwl::format_msg($m); |
---|
[f1e629d] | 38 | } |
---|
| 39 | |
---|
[186cdc4] | 40 | # populate global variable space for legacy owlconf files |
---|
[f1e629d] | 41 | sub _receive_msg_legacy_wrap { |
---|
| 42 | my ($m) = @_; |
---|
| 43 | $m->legacy_populate_global(); |
---|
[0337203] | 44 | return &BarnOwl::Hooks::_receive_msg($m); |
---|
[f1e629d] | 45 | } |
---|
| 46 | |
---|
[8203afd] | 47 | # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo"); |
---|
[f1e629d] | 48 | sub AUTOLOAD { |
---|
[c681337] | 49 | our $AUTOLOAD; |
---|
[f1e629d] | 50 | my $called = $AUTOLOAD; |
---|
| 51 | $called =~ s/.*:://; |
---|
[e7ac2b6] | 52 | $called =~ s/_/-/g; |
---|
[8203afd] | 53 | return &BarnOwl::command("$called ".join(" ",@_)); |
---|
[f1e629d] | 54 | } |
---|
| 55 | |
---|
[6922edd] | 56 | =head2 new_command NAME FUNC [{ARGS}] |
---|
| 57 | |
---|
| 58 | Add a new owl command. When owl executes the command NAME, FUNC will |
---|
| 59 | be called with the arguments passed to the command, with NAME as the |
---|
| 60 | first argument. |
---|
| 61 | |
---|
| 62 | ARGS should be a hashref containing any or all of C<summary>, |
---|
| 63 | C<usage>, or C<description> keys. |
---|
| 64 | |
---|
| 65 | =cut |
---|
| 66 | |
---|
| 67 | sub new_command { |
---|
| 68 | my $name = shift; |
---|
| 69 | my $func = shift; |
---|
| 70 | my $args = shift || {}; |
---|
| 71 | my %args = ( |
---|
| 72 | summary => undef, |
---|
| 73 | usage => undef, |
---|
| 74 | description => undef, |
---|
| 75 | %{$args} |
---|
| 76 | ); |
---|
| 77 | |
---|
[c681337] | 78 | no warnings 'uninitialized'; |
---|
[8203afd] | 79 | BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description}); |
---|
[6922edd] | 80 | } |
---|
| 81 | |
---|
[cd57601] | 82 | =head2 new_variable_int NAME [{ARGS}] |
---|
| 83 | |
---|
| 84 | =head2 new_variable_bool NAME [{ARGS}] |
---|
| 85 | |
---|
| 86 | =head2 new_variable_string NAME [{ARGS}] |
---|
| 87 | |
---|
| 88 | Add a new owl variable, either an int, a bool, or a string, with the |
---|
| 89 | specified name. |
---|
| 90 | |
---|
| 91 | ARGS can optionally contain the following keys: |
---|
| 92 | |
---|
| 93 | =over 4 |
---|
| 94 | |
---|
| 95 | =item default |
---|
| 96 | |
---|
| 97 | The default and initial value for the variable |
---|
| 98 | |
---|
| 99 | =item summary |
---|
| 100 | |
---|
| 101 | A one-line summary of the variable's purpose |
---|
| 102 | |
---|
| 103 | =item description |
---|
| 104 | |
---|
| 105 | A longer description of the function of the variable |
---|
| 106 | |
---|
| 107 | =back |
---|
| 108 | |
---|
| 109 | =cut |
---|
| 110 | |
---|
[a695a68] | 111 | sub new_variable_int { |
---|
| 112 | unshift @_, \&BarnOwl::new_variable_int_internal, 0; |
---|
| 113 | goto \&_new_variable; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | sub new_variable_bool { |
---|
| 117 | unshift @_, \&BarnOwl::new_variable_bool_internal, 0; |
---|
| 118 | goto \&_new_variable; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | sub new_variable_string { |
---|
| 122 | unshift @_, \&BarnOwl::new_variable_string_internal, ""; |
---|
| 123 | goto \&_new_variable; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | sub _new_variable { |
---|
| 127 | my $func = shift; |
---|
| 128 | my $default_default = shift; |
---|
| 129 | my $name = shift; |
---|
| 130 | my $args = shift || {}; |
---|
| 131 | my %args = ( |
---|
| 132 | summary => "", |
---|
| 133 | description => "", |
---|
| 134 | default => $default_default, |
---|
| 135 | %{$args}); |
---|
| 136 | $func->($name, $args{default}, $args{summary}, $args{description}); |
---|
| 137 | } |
---|
| 138 | |
---|
[f1e629d] | 139 | ##################################################################### |
---|
| 140 | ##################################################################### |
---|
| 141 | |
---|
[8203afd] | 142 | package BarnOwl::Message; |
---|
[f1e629d] | 143 | |
---|
[dd16bdd] | 144 | sub new { |
---|
| 145 | my $class = shift; |
---|
| 146 | my %args = (@_); |
---|
| 147 | if($class eq __PACKAGE__ && $args{type}) { |
---|
[8203afd] | 148 | $class = "BarnOwl::Message::" . ucfirst $args{type}; |
---|
[dd16bdd] | 149 | } |
---|
| 150 | return bless {%args}, $class; |
---|
| 151 | } |
---|
| 152 | |
---|
[f1e629d] | 153 | sub type { return shift->{"type"}; } |
---|
| 154 | sub direction { return shift->{"direction"}; } |
---|
| 155 | sub time { return shift->{"time"}; } |
---|
| 156 | sub id { return shift->{"id"}; } |
---|
| 157 | sub body { return shift->{"body"}; } |
---|
| 158 | sub sender { return shift->{"sender"}; } |
---|
| 159 | sub recipient { return shift->{"recipient"}; } |
---|
| 160 | sub login { return shift->{"login"}; } |
---|
[216c734] | 161 | sub is_private { return shift->{"private"}; } |
---|
[f1e629d] | 162 | |
---|
| 163 | sub is_login { return shift->login eq "login"; } |
---|
| 164 | sub is_logout { return shift->login eq "logout"; } |
---|
| 165 | sub is_loginout { my $m=shift; return ($m->is_login or $m->is_logout); } |
---|
| 166 | sub is_incoming { return (shift->{"direction"} eq "in"); } |
---|
| 167 | sub is_outgoing { return (shift->{"direction"} eq "out"); } |
---|
| 168 | |
---|
| 169 | sub is_deleted { return shift->{"deleted"}; } |
---|
| 170 | |
---|
| 171 | sub is_admin { return (shift->{"type"} eq "admin"); } |
---|
| 172 | sub is_generic { return (shift->{"type"} eq "generic"); } |
---|
[421c8ef7] | 173 | sub is_zephyr { return (shift->{"type"} eq "zephyr"); } |
---|
[467aa16] | 174 | sub is_aim { return (shift->{"type"} eq "AIM"); } |
---|
[dd16bdd] | 175 | sub is_jabber { return (shift->{"type"} eq "jabber"); } |
---|
[421c8ef7] | 176 | sub is_icq { return (shift->{"type"} eq "icq"); } |
---|
| 177 | sub is_yahoo { return (shift->{"type"} eq "yahoo"); } |
---|
| 178 | sub is_msn { return (shift->{"type"} eq "msn"); } |
---|
| 179 | sub is_loopback { return (shift->{"type"} eq "loopback"); } |
---|
[f1e629d] | 180 | |
---|
| 181 | # These are overridden by appropriate message types |
---|
| 182 | sub is_ping { return 0; } |
---|
| 183 | sub is_mail { return 0; } |
---|
[3c9012b] | 184 | sub is_personal { return shift->is_private; } |
---|
[f1e629d] | 185 | sub class { return undef; } |
---|
| 186 | sub instance { return undef; } |
---|
| 187 | sub realm { return undef; } |
---|
| 188 | sub opcode { return undef; } |
---|
| 189 | sub header { return undef; } |
---|
| 190 | sub host { return undef; } |
---|
| 191 | sub hostname { return undef; } |
---|
| 192 | sub auth { return undef; } |
---|
| 193 | sub fields { return undef; } |
---|
| 194 | sub zsig { return undef; } |
---|
| 195 | sub zwriteline { return undef; } |
---|
[87c6ef1] | 196 | sub login_host { return undef; } |
---|
| 197 | sub login_tty { return undef; } |
---|
[f1e629d] | 198 | |
---|
[ae47efb] | 199 | sub pretty_sender { return shift->sender; } |
---|
| 200 | sub pretty_recipient { return shift->recipient; } |
---|
[f1e629d] | 201 | |
---|
| 202 | sub delete { |
---|
| 203 | my ($m) = @_; |
---|
[8203afd] | 204 | &BarnOwl::command("delete --id ".$m->id); |
---|
[f1e629d] | 205 | } |
---|
| 206 | |
---|
| 207 | sub undelete { |
---|
| 208 | my ($m) = @_; |
---|
[8203afd] | 209 | &BarnOwl::command("undelete --id ".$m->id); |
---|
[f1e629d] | 210 | } |
---|
| 211 | |
---|
| 212 | # Serializes the message into something similar to the zwgc->vt format |
---|
| 213 | sub serialize { |
---|
| 214 | my ($this) = @_; |
---|
| 215 | my $s; |
---|
| 216 | for my $f (keys %$this) { |
---|
| 217 | my $val = $this->{$f}; |
---|
| 218 | if (ref($val) eq "ARRAY") { |
---|
| 219 | for my $i (0..@$val-1) { |
---|
| 220 | my $aval; |
---|
| 221 | $aval = $val->[$i]; |
---|
| 222 | $aval =~ s/\n/\n$f.$i: /g; |
---|
[186cdc4] | 223 | $s .= "$f.$i: $aval\n"; |
---|
[f1e629d] | 224 | } |
---|
| 225 | } else { |
---|
| 226 | $val =~ s/\n/\n$f: /g; |
---|
| 227 | $s .= "$f: $val\n"; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | return $s; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | # Populate the annoying legacy global variables |
---|
| 234 | sub legacy_populate_global { |
---|
| 235 | my ($m) = @_; |
---|
[8203afd] | 236 | $BarnOwl::direction = $m->direction ; |
---|
| 237 | $BarnOwl::type = $m->type ; |
---|
| 238 | $BarnOwl::id = $m->id ; |
---|
| 239 | $BarnOwl::class = $m->class ; |
---|
| 240 | $BarnOwl::instance = $m->instance ; |
---|
| 241 | $BarnOwl::recipient = $m->recipient ; |
---|
| 242 | $BarnOwl::sender = $m->sender ; |
---|
| 243 | $BarnOwl::realm = $m->realm ; |
---|
| 244 | $BarnOwl::opcode = $m->opcode ; |
---|
| 245 | $BarnOwl::zsig = $m->zsig ; |
---|
| 246 | $BarnOwl::msg = $m->body ; |
---|
| 247 | $BarnOwl::time = $m->time ; |
---|
| 248 | $BarnOwl::host = $m->host ; |
---|
| 249 | $BarnOwl::login = $m->login ; |
---|
| 250 | $BarnOwl::auth = $m->auth ; |
---|
[f1e629d] | 251 | if ($m->fields) { |
---|
[8203afd] | 252 | @BarnOwl::fields = @{$m->fields}; |
---|
[f1e629d] | 253 | @main::fields = @{$m->fields}; |
---|
| 254 | } else { |
---|
[8203afd] | 255 | @BarnOwl::fields = undef; |
---|
[f1e629d] | 256 | @main::fields = undef; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | |
---|
[25729b2] | 260 | sub smartfilter { |
---|
[0337203] | 261 | die("smartfilter not supported for this message\n"); |
---|
[25729b2] | 262 | } |
---|
| 263 | |
---|
[6e6ded7] | 264 | # Display fields -- overridden by subclasses when needed |
---|
| 265 | sub login_type {""} |
---|
| 266 | sub login_extra {""} |
---|
| 267 | sub long_sender {""} |
---|
| 268 | |
---|
| 269 | # The context in which a non-personal message was sent, e.g. a chat or |
---|
| 270 | # class |
---|
| 271 | sub context {""} |
---|
| 272 | |
---|
| 273 | # Some indicator of context *within* $self->context. e.g. the zephyr |
---|
| 274 | # instance |
---|
| 275 | sub subcontext {""} |
---|
| 276 | |
---|
[f1e629d] | 277 | ##################################################################### |
---|
| 278 | ##################################################################### |
---|
| 279 | |
---|
[8203afd] | 280 | package BarnOwl::Message::Admin; |
---|
[f1e629d] | 281 | |
---|
[8203afd] | 282 | use base qw( BarnOwl::Message ); |
---|
[f1e629d] | 283 | |
---|
| 284 | sub header { return shift->{"header"}; } |
---|
| 285 | |
---|
| 286 | ##################################################################### |
---|
| 287 | ##################################################################### |
---|
| 288 | |
---|
[8203afd] | 289 | package BarnOwl::Message::Generic; |
---|
[f1e629d] | 290 | |
---|
[8203afd] | 291 | use base qw( BarnOwl::Message ); |
---|
[f1e629d] | 292 | |
---|
| 293 | ##################################################################### |
---|
| 294 | ##################################################################### |
---|
| 295 | |
---|
[186cdc4] | 296 | package BarnOwl::Message::Loopback; |
---|
| 297 | |
---|
| 298 | use base qw( BarnOwl::Message ); |
---|
| 299 | |
---|
[cb06a43] | 300 | # all loopback messages are private |
---|
| 301 | sub is_private { |
---|
[186cdc4] | 302 | return 1; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | ##################################################################### |
---|
| 306 | ##################################################################### |
---|
| 307 | |
---|
[8203afd] | 308 | package BarnOwl::Message::AIM; |
---|
[f1e629d] | 309 | |
---|
[8203afd] | 310 | use base qw( BarnOwl::Message ); |
---|
[f1e629d] | 311 | |
---|
[cb06a43] | 312 | # all non-loginout AIM messages are private for now... |
---|
| 313 | sub is_private { |
---|
[f1e629d] | 314 | return !(shift->is_loginout); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | ##################################################################### |
---|
| 318 | ##################################################################### |
---|
| 319 | |
---|
[8203afd] | 320 | package BarnOwl::Message::Zephyr; |
---|
[f1e629d] | 321 | |
---|
[8203afd] | 322 | use base qw( BarnOwl::Message ); |
---|
[f1e629d] | 323 | |
---|
[6e6ded7] | 324 | sub login_type { |
---|
| 325 | return (shift->zsig eq "") ? "(PSEUDO)" : ""; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | sub login_extra { |
---|
| 329 | my $m = shift; |
---|
| 330 | return undef if (!$m->is_loginout); |
---|
| 331 | my $s = lc($m->host); |
---|
| 332 | $s .= " " . $m->login_tty if defined $m->login_tty; |
---|
| 333 | return $s; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | sub long_sender { |
---|
| 337 | my $m = shift; |
---|
| 338 | return $m->zsig; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | sub context { |
---|
| 342 | return shift->class; |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | sub subcontext { |
---|
| 346 | return shift->instance; |
---|
| 347 | } |
---|
| 348 | |
---|
[186cdc4] | 349 | sub login_tty { |
---|
[f1e629d] | 350 | my ($m) = @_; |
---|
| 351 | return undef if (!$m->is_loginout); |
---|
| 352 | return $m->fields->[2]; |
---|
| 353 | } |
---|
| 354 | |
---|
[186cdc4] | 355 | sub login_host { |
---|
[f1e629d] | 356 | my ($m) = @_; |
---|
| 357 | return undef if (!$m->is_loginout); |
---|
| 358 | return $m->fields->[0]; |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | sub zwriteline { return shift->{"zwriteline"}; } |
---|
| 362 | |
---|
| 363 | sub is_ping { return (lc(shift->opcode) eq "ping"); } |
---|
| 364 | |
---|
[186cdc4] | 365 | sub is_personal { |
---|
[f1e629d] | 366 | my ($m) = @_; |
---|
| 367 | return ((lc($m->class) eq "message") |
---|
| 368 | && (lc($m->instance) eq "personal") |
---|
| 369 | && $m->is_private); |
---|
| 370 | } |
---|
| 371 | |
---|
[186cdc4] | 372 | sub is_mail { |
---|
[f1e629d] | 373 | my ($m) = @_; |
---|
| 374 | return ((lc($m->class) eq "mail") && $m->is_private); |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | sub pretty_sender { |
---|
| 378 | my ($m) = @_; |
---|
| 379 | my $sender = $m->sender; |
---|
[8203afd] | 380 | my $realm = BarnOwl::zephyr_getrealm(); |
---|
[f1e629d] | 381 | $sender =~ s/\@$realm$//; |
---|
| 382 | return $sender; |
---|
| 383 | } |
---|
| 384 | |
---|
[ae47efb] | 385 | sub pretty_recipient { |
---|
| 386 | my ($m) = @_; |
---|
| 387 | my $recip = $m->recipient; |
---|
| 388 | my $realm = BarnOwl::zephyr_getrealm(); |
---|
| 389 | $recip =~ s/\@$realm$//; |
---|
| 390 | return $recip; |
---|
| 391 | } |
---|
| 392 | |
---|
[f1e629d] | 393 | # These are arguably zephyr-specific |
---|
| 394 | sub class { return shift->{"class"}; } |
---|
| 395 | sub instance { return shift->{"instance"}; } |
---|
| 396 | sub realm { return shift->{"realm"}; } |
---|
| 397 | sub opcode { return shift->{"opcode"}; } |
---|
| 398 | sub host { return shift->{"hostname"}; } |
---|
| 399 | sub hostname { return shift->{"hostname"}; } |
---|
| 400 | sub header { return shift->{"header"}; } |
---|
| 401 | sub auth { return shift->{"auth"}; } |
---|
| 402 | sub fields { return shift->{"fields"}; } |
---|
| 403 | sub zsig { return shift->{"zsig"}; } |
---|
| 404 | |
---|
| 405 | ##################################################################### |
---|
| 406 | ##################################################################### |
---|
[7e470da] | 407 | ################################################################################ |
---|
| 408 | |
---|
[0337203] | 409 | package BarnOwl::Hook; |
---|
[7e470da] | 410 | |
---|
[0337203] | 411 | sub new { |
---|
| 412 | my $class = shift; |
---|
| 413 | return bless [], $class; |
---|
| 414 | } |
---|
[7e470da] | 415 | |
---|
[0337203] | 416 | sub run { |
---|
| 417 | my $self = shift; |
---|
| 418 | my @args = @_; |
---|
| 419 | return map {$_->(@args)} @$self; |
---|
[7e470da] | 420 | } |
---|
[0337203] | 421 | |
---|
| 422 | sub add { |
---|
| 423 | my $self = shift; |
---|
| 424 | my $func = shift; |
---|
| 425 | die("Not a coderef!") unless ref($func) eq 'CODE'; |
---|
| 426 | push @$self, $func; |
---|
[7e470da] | 427 | } |
---|
| 428 | |
---|
[0337203] | 429 | sub clear { |
---|
| 430 | my $self = shift; |
---|
| 431 | @$self = (); |
---|
[7e470da] | 432 | } |
---|
| 433 | |
---|
[0337203] | 434 | package BarnOwl::Hooks; |
---|
[7e470da] | 435 | |
---|
[0337203] | 436 | use Exporter; |
---|
| 437 | |
---|
| 438 | our @EXPORT_OK = qw($startup $shutdown |
---|
| 439 | $receiveMessage $mainLoop |
---|
| 440 | $getBuddyList); |
---|
| 441 | |
---|
| 442 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
---|
| 443 | |
---|
| 444 | our $startup = BarnOwl::Hook->new; |
---|
| 445 | our $shutdown = BarnOwl::Hook->new; |
---|
| 446 | our $receiveMessage = BarnOwl::Hook->new; |
---|
| 447 | our $mainLoop = BarnOwl::Hook->new; |
---|
| 448 | our $getBuddyList = BarnOwl::Hook->new; |
---|
| 449 | |
---|
| 450 | # Internal startup/shutdown routines called by the C code |
---|
[7e470da] | 451 | |
---|
[b6c067a] | 452 | sub _load_owlconf { |
---|
| 453 | # load the config file |
---|
| 454 | if ( -r $BarnOwl::configfile ) { |
---|
| 455 | undef $@; |
---|
[e8bc8ac] | 456 | package main; |
---|
[b6c067a] | 457 | do $BarnOwl::configfile; |
---|
| 458 | die $@ if $@; |
---|
[e8bc8ac] | 459 | package BarnOwl; |
---|
[39dc159] | 460 | if(*BarnOwl::format_msg{CODE}) { |
---|
| 461 | # if the config defines a legacy formatting function, add 'perl' as a style |
---|
| 462 | BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap", |
---|
| 463 | "User-defined perl style that calls BarnOwl::format_msg" |
---|
| 464 | . " with legacy global variable support"); |
---|
| 465 | BarnOwl::set("-q default_style perl"); |
---|
| 466 | } |
---|
[b6c067a] | 467 | } |
---|
| 468 | } |
---|
| 469 | |
---|
[0337203] | 470 | sub _startup { |
---|
| 471 | _load_owlconf(); |
---|
[8203afd] | 472 | |
---|
[0337203] | 473 | if(eval {require BarnOwl::ModuleLoader}) { |
---|
| 474 | eval { |
---|
| 475 | BarnOwl::ModuleLoader->load_all; |
---|
| 476 | }; |
---|
[f6b319c] | 477 | BarnOwl::error("$@") if $@; |
---|
| 478 | |
---|
[0337203] | 479 | } else { |
---|
| 480 | BarnOwl::error("Can't load BarnOwl::ModuleLoader, loadable module support disabled:\n$@"); |
---|
| 481 | } |
---|
| 482 | |
---|
[836e6263] | 483 | $startup->run(0); |
---|
[8203afd] | 484 | BarnOwl::startup() if *BarnOwl::startup{CODE}; |
---|
| 485 | } |
---|
| 486 | |
---|
[0337203] | 487 | sub _shutdown { |
---|
| 488 | $shutdown->run; |
---|
| 489 | |
---|
[8203afd] | 490 | BarnOwl::shutdown() if *BarnOwl::shutdown{CODE}; |
---|
| 491 | } |
---|
| 492 | |
---|
[0337203] | 493 | sub _receive_msg { |
---|
[7e470da] | 494 | my $m = shift; |
---|
[0337203] | 495 | |
---|
| 496 | $receiveMessage->run($m); |
---|
| 497 | |
---|
[8203afd] | 498 | BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE}; |
---|
[7e470da] | 499 | } |
---|
| 500 | |
---|
[0337203] | 501 | sub _mainloop_hook { |
---|
| 502 | $mainLoop->run; |
---|
| 503 | BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; |
---|
| 504 | } |
---|
[7e470da] | 505 | |
---|
[0337203] | 506 | sub _get_blist { |
---|
| 507 | return join("\n", $getBuddyList->run); |
---|
[7e470da] | 508 | } |
---|
[dd16bdd] | 509 | |
---|
[b6c067a] | 510 | ################################################################################ |
---|
| 511 | # Built-in perl styles |
---|
| 512 | ################################################################################ |
---|
| 513 | package BarnOwl::Style::Default; |
---|
| 514 | ################################################################################ |
---|
| 515 | # Branching point for various formatting functions in this style. |
---|
| 516 | ################################################################################ |
---|
| 517 | sub format_message($) |
---|
| 518 | { |
---|
| 519 | my $m = shift; |
---|
| 520 | |
---|
[6e6ded7] | 521 | if ( $m->is_loginout) { |
---|
| 522 | return format_login($m); |
---|
| 523 | } elsif($m->is_ping) { |
---|
| 524 | return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" ); |
---|
| 525 | } elsif($m->is_admin) { |
---|
[b6c067a] | 526 | return "\@bold(OWL ADMIN)\n" . indentBody($m); |
---|
[6e6ded7] | 527 | } else { |
---|
| 528 | return format_chat($m); |
---|
[b6c067a] | 529 | } |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style"); |
---|
| 533 | |
---|
| 534 | ################################################################################ |
---|
| 535 | |
---|
[6e6ded7] | 536 | sub time_hhmm { |
---|
| 537 | my $m = shift; |
---|
[b6c067a] | 538 | my ($time) = $m->time =~ /(\d\d:\d\d)/; |
---|
[6e6ded7] | 539 | return $time; |
---|
[b6c067a] | 540 | } |
---|
| 541 | |
---|
[6e6ded7] | 542 | sub format_login($) { |
---|
[b6c067a] | 543 | my $m = shift; |
---|
[6e6ded7] | 544 | return sprintf( |
---|
| 545 | '@b<%s%s> for @b(%s) (%s) %s', |
---|
| 546 | uc( $m->login ), |
---|
| 547 | $m->login_type, |
---|
| 548 | $m->pretty_sender, |
---|
| 549 | $m->login_extra, |
---|
| 550 | time_hhmm($m) |
---|
| 551 | ); |
---|
[b6c067a] | 552 | } |
---|
| 553 | |
---|
[6e6ded7] | 554 | sub format_chat($) { |
---|
[b6c067a] | 555 | my $m = shift; |
---|
[6e6ded7] | 556 | my $header; |
---|
| 557 | if ( $m->is_personal ) { |
---|
| 558 | if ( $m->direction eq "out" ) { |
---|
| 559 | $header = ucfirst $m->type . " sent to " . $m->pretty_recipient; |
---|
| 560 | } else { |
---|
| 561 | $header = ucfirst $m->type . " from " . $m->pretty_sender; |
---|
| 562 | } |
---|
| 563 | } else { |
---|
| 564 | $header = $m->context; |
---|
[37dd88c] | 565 | if(defined $m->subcontext) { |
---|
[c39999f] | 566 | $header .= ' / ' . $m->subcontext; |
---|
[6e6ded7] | 567 | } |
---|
[c39999f] | 568 | $header .= ' / @b{' . $m->pretty_sender . '}'; |
---|
[6e6ded7] | 569 | } |
---|
[b6c067a] | 570 | |
---|
[6e6ded7] | 571 | $header .= " " . time_hhmm($m); |
---|
[0449730] | 572 | my $sender = $m->long_sender; |
---|
| 573 | $sender =~ s/\n.*$//s; |
---|
[cc5b906] | 574 | $header .= " " x (4 - ((length $header) % 4)); |
---|
| 575 | $header .= "(" . $sender . ")"; |
---|
[6e6ded7] | 576 | my $message = $header . "\n". indentBody($m); |
---|
[cb06a43] | 577 | if($m->is_personal && $m->direction eq "in") { |
---|
[6e6ded7] | 578 | $message = BarnOwl::Style::boldify($message); |
---|
| 579 | } |
---|
| 580 | return $message; |
---|
[b6c067a] | 581 | } |
---|
| 582 | |
---|
| 583 | sub indentBody($) |
---|
| 584 | { |
---|
| 585 | my $m = shift; |
---|
[186cdc4] | 586 | |
---|
[b6c067a] | 587 | my $body = $m->body; |
---|
[f6b319c] | 588 | if ($m->{should_wordwrap}) { |
---|
| 589 | $body = BarnOwl::wordwrap($body, BarnOwl::getnumcols()-8); |
---|
| 590 | } |
---|
[186cdc4] | 591 | # replace newline followed by anything with |
---|
[b6c067a] | 592 | # newline plus four spaces and that thing. |
---|
| 593 | $body =~ s/\n(.)/\n $1/g; |
---|
| 594 | |
---|
| 595 | return " ".$body; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | |
---|
| 599 | package BarnOwl::Style; |
---|
| 600 | |
---|
| 601 | # This takes a zephyr to be displayed and modifies it to be displayed |
---|
| 602 | # entirely in bold. |
---|
| 603 | sub boldify($) |
---|
| 604 | { |
---|
| 605 | local $_ = shift; |
---|
| 606 | if ( !(/\)/) ) { |
---|
| 607 | return '@b(' . $_ . ')'; |
---|
| 608 | } elsif ( !(/\>/) ) { |
---|
| 609 | return '@b<' . $_ . '>'; |
---|
| 610 | } elsif ( !(/\}/) ) { |
---|
| 611 | return '@b{' . $_ . '}'; |
---|
| 612 | } elsif ( !(/\]/) ) { |
---|
| 613 | return '@b[' . $_ . ']'; |
---|
| 614 | } else { |
---|
| 615 | my $txt = "\@b($_"; |
---|
| 616 | $txt =~ s/\)/\)\@b\[\)\]\@b\(/g; |
---|
| 617 | return $txt . ')'; |
---|
| 618 | } |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | |
---|
[f1e629d] | 622 | # switch to package main when we're done |
---|
| 623 | package main; |
---|
[0337203] | 624 | |
---|
| 625 | # Shove a bunch of fake entries into @INC so modules can use or |
---|
| 626 | # require them without choking |
---|
| 627 | $::INC{$_} = 1 for (qw(BarnOwl.pm BarnOwl/Hooks.pm |
---|
| 628 | BarnOwl/Message.pm BarnOwl/Style.pm)); |
---|
[f1e629d] | 629 | |
---|
| 630 | 1; |
---|
[0337203] | 631 | |
---|