Changeset 8203afd


Ignore:
Timestamp:
Jan 9, 2007, 11:33:44 PM (18 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
d609dd6
Parents:
ffe70f9
git-author:
Nelson Elhage <nelhage@mit.edu> (01/09/07 18:50:40)
git-committer:
Nelson Elhage <nelhage@mit.edu> (01/09/07 23:33:44)
Message:
* Renaming package owl to BarnOwl::
* Moving hooks into the BarnOwl::Hooks package, and restoring support
  for .owlconf files that use sub startup {} and so on.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r25729b2 r8203afd  
    10301030
    10311031  /* execute the commands in shutdown */
    1032   ret = owl_perlconfig_execute("owl::shutdown();");
     1032  ret = owl_perlconfig_execute("BarnOwl::Hooks::shutdown();");
    10331033  if (ret) owl_free(ret);
    10341034
     
    33163316
    33173317  if(aim && zephyr) {
    3318       if(owl_perlconfig_is_function("owl::get_blist")) {
    3319           char * perlblist = owl_perlconfig_execute("owl::get_blist()");
     3318      if(owl_perlconfig_is_function("BarnOwl::Hooks::get_blist")) {
     3319          char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::get_blist()");
    33203320          if(perlblist) {
    33213321              owl_fmtext_append_ztext(&fm, perlblist);
  • owl.c

    r00f9a7d r8203afd  
    319319    owl_function_debugmsg("Found perl formatting");
    320320    s=owl_malloc(sizeof(owl_style));
    321     owl_style_create_perl(s, "perl", "owl::_format_msg_legacy_wrap",
    322                           "User-defined perl style that calls owl::format_msg"
     321    owl_style_create_perl(s, "perl", "BarnOwl::_format_msg_legacy_wrap",
     322                          "User-defined perl style that calls BarnOwl::format_msg"
    323323                          "with legacy global variable support");
    324324    owl_global_add_style(&g, s);
     
    328328  /* execute the startup function in the configfile */
    329329  owl_function_debugmsg("startup: executing perl startup, if applicable");
    330   perlout = owl_perlconfig_execute("owl::startup();");
     330  perlout = owl_perlconfig_execute("BarnOwl::Hooks::startup();");
    331331  if (perlout) owl_free(perlout);
    332332 
     
    439439    }
    440440
    441     /* Hook perl into the loop */
    442     if (owl_perlconfig_is_function("owl::mainloop_hook")) {
    443          owl_perlconfig_mainloop();
    444     }
     441    owl_perlconfig_mainloop();
    445442
    446443    /* little hack */
  • perlconfig.c

    r9364a36 r8203afd  
    1212extern char *owl_perlwrap_codebuff;
    1313
    14 extern XS(boot_owl);
     14extern XS(boot_BarnOwl);
    1515extern XS(boot_DynaLoader);
    1616// extern XS(boot_DBI);
     
    2121  dXSUB_SYS;
    2222  {
    23     newXS("owl::bootstrap", boot_owl, file);
     23    newXS("BarnOwl::bootstrap", boot_BarnOwl, file);
    2424    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
    2525  }
     
    8686  hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
    8787
    88   if (owl_message_is_type_zephyr(m))       blessas = "owl::Message::Zephyr";
    89   else if (owl_message_is_type_aim(m))     blessas = "owl::Message::AIM";
    90   else if (owl_message_is_type_jabber(m))  blessas = "owl::Message::Jabber";
    91   else if (owl_message_is_type_admin(m))   blessas = "owl::Message::Admin";
    92   else if (owl_message_is_type_generic(m)) blessas = "owl::Message::Generic";
    93   else                                     blessas = "owl::Message";
     88  if (owl_message_is_type_zephyr(m))       blessas = "BarnOwl::Message::Zephyr";
     89  else if (owl_message_is_type_aim(m))     blessas = "BarnOwl::Message::AIM";
     90  else if (owl_message_is_type_jabber(m))  blessas = "BarnOwl::Message::Jabber";
     91  else if (owl_message_is_type_admin(m))   blessas = "BarnOwl::Message::Admin";
     92  else if (owl_message_is_type_generic(m)) blessas = "BarnOwl::Message::Generic";
     93  else                                     blessas = "BarnOwl::Message";
    9494
    9595  hr = sv_2mortal(newRV_noinc((SV*)h));
     
    255255
    256256  /* create legacy variables */
    257   perl_get_sv("owl::id", TRUE);
    258   perl_get_sv("owl::class", TRUE);
    259   perl_get_sv("owl::instance", TRUE);
    260   perl_get_sv("owl::recipient", TRUE);
    261   perl_get_sv("owl::sender", TRUE);
    262   perl_get_sv("owl::realm", TRUE);
    263   perl_get_sv("owl::opcode", TRUE);
    264   perl_get_sv("owl::zsig", TRUE);
    265   perl_get_sv("owl::msg", TRUE);
    266   perl_get_sv("owl::time", TRUE);
    267   perl_get_sv("owl::host", TRUE);
    268   perl_get_av("owl::fields", TRUE);
     257  perl_get_sv("BarnOwl::id", TRUE);
     258  perl_get_sv("BarnOwl::class", TRUE);
     259  perl_get_sv("BarnOwl::instance", TRUE);
     260  perl_get_sv("BarnOwl::recipient", TRUE);
     261  perl_get_sv("BarnOwl::sender", TRUE);
     262  perl_get_sv("BarnOwl::realm", TRUE);
     263  perl_get_sv("BarnOwl::opcode", TRUE);
     264  perl_get_sv("BarnOwl::zsig", TRUE);
     265  perl_get_sv("BarnOwl::msg", TRUE);
     266  perl_get_sv("BarnOwl::time", TRUE);
     267  perl_get_sv("BarnOwl::host", TRUE);
     268  perl_get_av("BarnOwl::fields", TRUE);
    269269
    270270  if(file) {
    271     SV * cfg = get_sv("owl::configfile", TRUE);
     271    SV * cfg = get_sv("BarnOwl::configfile", TRUE);
    272272    sv_setpv(cfg, file);
    273273  }
     
    283283
    284284  /* check if we have the formatting function */
    285   if (owl_perlconfig_is_function("owl::format_msg")) {
     285  if (owl_perlconfig_is_function("BarnOwl::format_msg")) {
    286286    owl_global_set_config_format(&g, 1);
    287287  }
     
    361361    char *ret = NULL;
    362362    ret = owl_perlconfig_call_with_message(subname?subname
    363                                            :"owl::_format_msg_legacy_wrap", m);
     363                                           :"BarnOwl::_format_msg_legacy_wrap", m);
    364364    if (!ret) {
    365365      ret = owl_sprintf("@b([Perl Message Formatting Failed!])\n");
     
    368368  } else {
    369369    char *ptr = NULL;
    370     if (owl_perlconfig_is_function("owl::receive_msg")) {
     370    if (owl_perlconfig_is_function("BarnOwl::Hooks::receive_msg")) {
    371371      ptr = owl_perlconfig_call_with_message(subname?subname
    372                                        :"owl::_receive_msg_legacy_wrap", m);
     372                                       :"BarnOwl::_receive_msg_legacy_wrap", m);
    373373    }
    374374    if (ptr) owl_free(ptr);
     
    452452void owl_perlconfig_mainloop()
    453453{
     454  if (!owl_perlconfig_is_function("BarnOwl::Hooks::mainloop_hook"))
     455    return;
    454456  dSP ;
    455457  PUSHMARK(SP) ;
    456   call_pv("owl::mainloop_hook", G_DISCARD|G_EVAL);
     458  call_pv("BarnOwl::Hooks::mainloop_hook", G_DISCARD|G_EVAL);
    457459  if(SvTRUE(ERRSV)) {
    458460    STRLEN n_a;
  • perlglue.xs

    r17eed9c r8203afd  
    1313#define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV)
    1414
    15 MODULE = owl            PACKAGE = owl           
     15MODULE = BarnOwl                PACKAGE = BarnOwl               
    1616
    1717char *
  • perlwrap.pm

    r3354cea5 r8203afd  
    99use warnings;
    1010
    11 package owl;
     11package BarnOwl;
    1212
    1313
    1414BEGIN {
    1515# bootstrap in C bindings and glue
    16     bootstrap owl 1.2;
     16    *owl:: = \*BarnOwl::;
     17    bootstrap BarnOwl 1.2;
    1718};
    1819
     
    2829    my ($m) = @_;
    2930    $m->legacy_populate_global();
    30     return &owl::format_msg($m);
     31    return &BarnOwl::format_msg($m);
    3132}
    3233
     
    3536    my ($m) = @_;
    3637    $m->legacy_populate_global();
    37     return &owl::receive_msg($m);
    38 }
    39 
    40 # make owl::<command>("foo") be aliases to owl::command("<command> foo");
     38    return &BarnOwl::Hooks::receive_msg($m);
     39}
     40
     41# make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo");
    4142sub AUTOLOAD {
    4243    our $AUTOLOAD;
     
    4445    $called =~ s/.*:://;
    4546    $called =~ s/_/-/g;
    46     return &owl::command("$called ".join(" ",@_));
     47    return &BarnOwl::command("$called ".join(" ",@_));
    4748}
    4849
     
    7071
    7172    no warnings 'uninitialized';
    72     owl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});
    73 }
    74 
    75 #####################################################################
    76 #####################################################################
    77 
    78 package owl::Message;
     73    BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});
     74}
     75
     76#####################################################################
     77#####################################################################
     78
     79package BarnOwl::Message;
    7980
    8081sub new {
     
    8283    my %args = (@_);
    8384    if($class eq __PACKAGE__ && $args{type}) {
    84         $class = "owl::Message::" . ucfirst $args{type};
     85        $class = "BarnOwl::Message::" . ucfirst $args{type};
    8586    }
    8687    return bless {%args}, $class;
     
    137138sub delete {
    138139    my ($m) = @_;
    139     &owl::command("delete --id ".$m->id);
     140    &BarnOwl::command("delete --id ".$m->id);
    140141}
    141142
    142143sub undelete {
    143144    my ($m) = @_;
    144     &owl::command("undelete --id ".$m->id);
     145    &BarnOwl::command("undelete --id ".$m->id);
    145146}
    146147
     
    169170sub legacy_populate_global {
    170171    my ($m) = @_;
    171     $owl::direction  = $m->direction ;
    172     $owl::type       = $m->type      ;
    173     $owl::id         = $m->id        ;
    174     $owl::class      = $m->class     ;
    175     $owl::instance   = $m->instance  ;
    176     $owl::recipient  = $m->recipient ;
    177     $owl::sender     = $m->sender    ;
    178     $owl::realm      = $m->realm     ;
    179     $owl::opcode     = $m->opcode    ;
    180     $owl::zsig       = $m->zsig      ;
    181     $owl::msg        = $m->body      ;
    182     $owl::time       = $m->time      ;
    183     $owl::host       = $m->host      ;
    184     $owl::login      = $m->login     ;
    185     $owl::auth       = $m->auth      ;
     172    $BarnOwl::direction  = $m->direction ;
     173    $BarnOwl::type       = $m->type      ;
     174    $BarnOwl::id         = $m->id        ;
     175    $BarnOwl::class      = $m->class     ;
     176    $BarnOwl::instance   = $m->instance  ;
     177    $BarnOwl::recipient  = $m->recipient ;
     178    $BarnOwl::sender     = $m->sender    ;
     179    $BarnOwl::realm      = $m->realm     ;
     180    $BarnOwl::opcode     = $m->opcode    ;
     181    $BarnOwl::zsig       = $m->zsig      ;
     182    $BarnOwl::msg        = $m->body      ;
     183    $BarnOwl::time       = $m->time      ;
     184    $BarnOwl::host       = $m->host      ;
     185    $BarnOwl::login      = $m->login     ;
     186    $BarnOwl::auth       = $m->auth      ;
    186187    if ($m->fields) {
    187         @owl::fields = @{$m->fields};
     188        @BarnOwl::fields = @{$m->fields};
    188189        @main::fields = @{$m->fields};
    189190    } else {
    190         @owl::fields = undef;
     191        @BarnOwl::fields = undef;
    191192        @main::fields = undef;
    192193    }
     
    200201#####################################################################
    201202
    202 package owl::Message::Admin;
    203 
    204 use base qw( owl::Message );
     203package BarnOwl::Message::Admin;
     204
     205use base qw( BarnOwl::Message );
    205206
    206207sub header       { return shift->{"header"}; }
     
    209210#####################################################################
    210211
    211 package owl::Message::Generic;
    212 
    213 use base qw( owl::Message );
    214 
    215 #####################################################################
    216 #####################################################################
    217 
    218 package owl::Message::AIM;
    219 
    220 use base qw( owl::Message );
     212package BarnOwl::Message::Generic;
     213
     214use base qw( BarnOwl::Message );
     215
     216#####################################################################
     217#####################################################################
     218
     219package BarnOwl::Message::AIM;
     220
     221use base qw( BarnOwl::Message );
    221222
    222223# all non-loginout AIM messages are personal for now...
     
    228229#####################################################################
    229230
    230 package owl::Message::Zephyr;
    231 
    232 use base qw( owl::Message );
     231package BarnOwl::Message::Zephyr;
     232
     233use base qw( BarnOwl::Message );
    233234
    234235sub login_tty {
     
    263264    my ($m) = @_;
    264265    my $sender = $m->sender;
    265     my $realm = owl::zephyr_getrealm();
     266    my $realm = BarnOwl::zephyr_getrealm();
    266267    $sender =~ s/\@$realm$//;
    267268    return $sender;
     
    285286package owl;
    286287
     288################################################################################
     289# Mainloop hook
     290################################################################################
     291
     292our $shutdown;
     293$shutdown = 0;
     294our $reload;
     295$reload = 0;
     296
     297#Run this on start and reload. Adds modules
     298sub onStart
     299{
     300    reload_init();
     301    loadModules();
     302}
     303################################################################################
     304# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
     305################################################################################
     306sub reload_hook (@)
     307{
     308    BarnOwl::Hooks::startup();
     309    return 1;
     310}
     311
     312sub reload
     313{
     314    # Use $reload to tell modules that we're performing a reload.
     315  {
     316      local $reload = 1;
     317      BarnOwl::mainloop_hook();
     318  }
     319   
     320  @BarnOwl::Hooks::onMainLoop = ();
     321  @BarnOwl::Hooks::onStartSubs = ();
     322
     323  # Do reload
     324  package main;
     325  if (do "$ENV{HOME}/.owlconf" && BarnOwl::reload_hook(@_))
     326  {
     327      return "owlconf reloaded";
     328  }
     329  else
     330  {
     331      return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
     332  }
     333  package owl;
     334}
     335
     336sub reload_init ()
     337{
     338    BarnOwl::command('alias reload perl BarnOwl::reload()');
     339    BarnOwl::command('bindkey global "C-x C-r" command reload');
     340}
     341
     342################################################################################
     343# Loads modules from ~/.owl/modules and owl's data directory
     344################################################################################
     345
     346sub loadModules () {
     347    my @modules;
     348    my $rv;
     349    foreach my $dir ( BarnOwl::get_data_dir() . "/modules",
     350                      $ENV{HOME} . "/.owl/modules" )
     351    {
     352        opendir( MODULES, $dir );
     353
     354        # source ./modules/*.pl
     355        @modules = grep( /\.pl$/, readdir(MODULES) );
     356
     357        foreach my $mod (@modules) {
     358            owl::error("Loading $dir/$mod...");
     359            unless ($rv = do "$dir/$mod") {
     360                BarnOwl::error("Couldn't load $dir/$mod:\n $@") if $@;
     361                BarnOwl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv;
     362            }
     363        }
     364        closedir(MODULES);
     365    }
     366}
     367
     368package BarnOwl::Hooks;
     369
    287370# Arrays of subrefs to be called at specific times.
    288371our @onStartSubs = ();
     
    291374our @onGetBuddyList = ();
    292375
    293 ################################################################################
    294 # Mainloop hook
    295 ################################################################################
    296 
    297 our $shutdown;
    298 $shutdown = 0;
    299 our $reload;
    300 $reload = 0;
    301 
    302376# Functions to call hook lists
    303377sub runHook($@)
     
    315389}
    316390
    317 sub mainloop_hook
    318 {
    319     runHook(\@onMainLoop);
    320 }
    321 
    322391################################################################################
    323392# Startup and Shutdown code
     
    325394sub startup
    326395{
    327 # Modern versions of owl provides a great place to have startup stuff.
    328 # Put things in ~/.owl/startup
    329     onStart();
    330 }
    331 
    332 sub shutdown
    333 {
    334 # Modern versions of owl provides a great place to have shutdown stuff.
    335 # Put things in ~/.owl/shutdown
    336 
    337     # use $shutdown to tell modules that that's what we're doing.
    338     $shutdown = 1;
    339     mainloop_hook();
    340 }
    341 
    342 #Run this on start and reload. Adds modules and runs their startup functions.
    343 sub onStart
    344 {
    345     reload_init();
     396    # Modern versions of owl provides a great place to have startup stuff.
     397    # Put things in ~/.owl/startup
     398
    346399    #So that the user's .owlconf can have startsubs, we don't clear
    347400    #onStartSubs; reload does however
     
    350403    @onGetBuddyList = ();
    351404
    352     loadModules();
     405    BarnOwl::onStart();
     406
    353407    runHook(\@onStartSubs);
    354 }
    355 ################################################################################
    356 # Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
    357 ################################################################################
    358 sub reload_hook (@)
    359 {
    360     onStart();
    361     return 1;
    362 }
    363 
    364 sub reload
    365 {
    366     # Use $reload to tell modules that we're performing a reload.
    367     $reload = 1;
    368     owl::mainloop_hook();
    369     $reload = 0;
    370     @onMainLoop = ();
    371     @onStartSubs = ();
    372 
    373     # Do reload
    374     package main;
    375     if (do "$ENV{HOME}/.owlconf" && owl::reload_hook(@_))
    376     {
    377         return "owlconf reloaded";
    378     }
    379     else
    380     {
    381         return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
    382     }
    383     package owl;
    384 }
    385 
    386 sub reload_init ()
    387 {
    388     owl::command('alias reload perl owl::reload()');
    389     owl::command('bindkey global "C-x C-r" command reload');
    390 }
    391 
    392 ################################################################################
    393 # Loads modules from ~/.owl/modules and owl's data directory
    394 ################################################################################
    395 
    396 sub loadModules () {
    397     my @modules;
    398     my $rv;
    399     foreach my $dir ( owl::get_data_dir() . "/modules",
    400                       $ENV{HOME} . "/.owl/modules" )
    401     {
    402         opendir( MODULES, $dir );
    403 
    404         # source ./modules/*.pl
    405         @modules = grep( /\.pl$/, readdir(MODULES) );
    406 
    407         foreach my $mod (@modules) {
    408             unless ($rv = do "$dir/$mod") {
    409                 owl::error("Couldn't load $dir/$mod:\n $@") if $@;
    410                 owl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv;
    411             }
    412         }
    413         closedir(MODULES);
    414     }
    415 }
    416 
    417 
     408
     409    BarnOwl::startup() if *BarnOwl::startup{CODE};
     410}
     411
     412sub shutdown
     413{
     414# Modern versions of owl provides a great place to have shutdown stuff.
     415# Put things in ~/.owl/shutdown
     416
     417    # use $shutdown to tell modules that that's what we're doing.
     418    $BarnOwl::shutdown = 1;
     419    BarnOwl::mainloop_hook();
     420
     421    BarnOwl::shutdown() if *BarnOwl::shutdown{CODE};
     422}
     423
     424sub mainloop_hook
     425{
     426    runHook(\@onMainLoop);
     427    BarnOwl::mainlook_hook() if *BarnOwl::mainloop_hook{CODE};
     428}
    418429
    419430################################################################################
     
    425436    my $m = shift;
    426437    runHook(\@onReceiveMsg, $m);
     438    BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE};
    427439}
    428440
     
    433445sub get_blist
    434446{
    435     my $m = shift;
    436     return runHook_accumulate(\@onGetBuddyList, $m);
     447    return runHook_accumulate(\@onGetBuddyList);
    437448}
    438449
     
    446457                          onMainLoop
    447458                          onGetBuddyList ) {
    448         *{"main::".$hook} = \*{"owl::".$hook};
     459        *{"main::".$hook} = \*{"BarnOwl::Hooks::".$hook};
     460        *{"owl::".$hook} = \*{"BarnOwl::Hooks::".$hook};
    449461    }
    450462}
    451463
    452464# load the config  file
    453 if (-r $owl::configfile) {
     465if (-r $BarnOwl::configfile) {
    454466    undef $@;
    455     do $owl::configfile;
     467    do $BarnOwl::configfile;
    456468    die $@ if $@;
    457469}
Note: See TracChangeset for help on using the changeset viewer.