Changes in / [a827529:16c6cca]


Ignore:
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • message.c

    r635881c r3a7cf49  
    330330  res=owl_message_get_attribute_value(m, "isprivate");
    331331  if (!res) return(0);
    332   return !strcmp(res, "true");
     332  return(1);
    333333}
    334334
  • perl/lib/BarnOwl/ModuleLoader.pm

    rb0c8011 rbe98ba5  
    99
    1010sub load_all {
    11     PAR::reload_libs();
    1211    my %modules;
    1312    my @modules;
    … …  
    3736    for my $class (keys %modules) {
    3837        if(!defined eval "use BarnOwl::Module::$class") {
    39             # BarnOwl::error("Unable to load module $class: $!") if $!;
     38            BarnOwl::error("Unable to load module $class: $!") if $!;
    4039            BarnOwl::error("Unable to load module $class: $@") if $@;
    4140        }
    … …  
    4847    BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, {
    4948                           summary => 'Reload all modules',
    50                            usage   => 'reload-modules',
     49                           usage   => 'reload',
    5150                           description => q{Reloads all modules located in ~/.owl/modules and the system modules directory}
    5251                          });
  • perl/modules/IRC/lib/BarnOwl/Message/IRC.pm

    r2fb58e4 r0e52069  
    5656sub long_sender {shift->{from} || ""};
    5757
    58 sub login_extra { shift->channel; }
    59 
    6058
    61591;
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    rb0c8011 r6286f26  
    3030
    3131sub startup {
    32     BarnOwl::new_variable_string('irc:nick', {
    33         default     => $ENV{USER},
    34         summary     => 'The default IRC nickname',
    35         description => 'By default, irc-connect will use this nick '  .
    36         'when connecting to a new server. See :help irc-connect for ' .
    37         'more information.'
    38        });
    39 
    40     BarnOwl::new_variable_string('irc:user', {
    41         default => $ENV{USER},
    42         summary => 'The IRC "username" field'
    43        });
    44         BarnOwl::new_variable_string('irc:name', {
    45         default => "",
    46         summary     => 'A short name field for IRC',
    47         description => 'A short (maybe 60 or so chars) piece of text, ' .
    48         'originally intended to display your real name, which people '  .
    49         'often use for pithy quotes and URLs.'
    50        });
    51    
    52     BarnOwl::new_variable_bool('irc:spew', {
    53         default     => 0,
    54         summary     => 'Show unhandled IRC events',
    55         description => 'If set, display all unrecognized IRC events as ' .
    56         'admin messages. Intended for debugging and development use only '
    57        });
    58    
     32    BarnOwl::new_variable_string('irc:nick', {default => $ENV{USER}});
     33    BarnOwl::new_variable_string('irc:user', {default => $ENV{USER}});
     34    BarnOwl::new_variable_string('irc:name', {default => ""});
     35    BarnOwl::new_variable_bool('irc:spew', {default => 0});
    5936    register_commands();
    6037    register_handlers();
    … …  
    8461
    8562sub register_commands {
    86     BarnOwl::new_command('irc-connect' => \&cmd_connect,
    87                        {
    88                            summary      => 'Connect to an IRC server',
    89                            usage        => 'irc-connect [-a ALIAS ] [-s] [-p PASSWORD] [-n NICK] SERVER [port]',
    90                            description  =>
    91 
    92                            "Connect to an IRC server. Supported options are\n\n" .
    93                            "-a <alias>          Define an alias for this server\n" .
    94                            "-s                  Use SSL\n" .
    95                            "-p <password>       Specify the password to use\n" .
    96                            "-n <nick>           Use a non-default nick"
    97                        });
     63    BarnOwl::new_command('irc-connect' => \&cmd_connect);
    9864    BarnOwl::new_command('irc-disconnect' => \&cmd_disconnect);
    99     BarnOwl::new_command('irc-msg'        => \&cmd_msg);
    100     BarnOwl::new_command('irc-join'       => \&cmd_join);
    101     BarnOwl::new_command('irc-part'       => \&cmd_part);
    102     BarnOwl::new_command('irc-nick'       => \&cmd_nick);
    103     BarnOwl::new_command('irc-names'      => \&cmd_names);
    104     BarnOwl::new_command('irc-whois'      => \&cmd_whois);
     65    BarnOwl::new_command('irc-msg'     => \&cmd_msg);
     66    BarnOwl::new_command('irc-join' => \&cmd_join);
     67    BarnOwl::new_command('irc-nick' => \&cmd_nick);
    10568}
    10669
    … …  
    13194            "ssl"        => \$ssl,
    13295            "password=s" => \$password,
    133             "nick=s"     => \$nick,
     96            "port=i"     => \$port,
    13497        );
    13598        $host = shift @ARGV or die("Usage: $cmd HOST\n");
    13699        if(!$alias) {
    137             if($host =~ /^(?:irc[.])?(\w+)[.]\w+$/) {
    138                 $alias = $1;
    139             } else {
    140                 $alias = $host;
    141             }
     100            $alias = $1 if $host =~ /^(?:irc[.])?(\w+)[.]\w+$/;
     101            $alias ||= $host;
    142102        }
    143         $port = shift @ARGV || 6667;
     103        $port ||= 6667;
    144104        $ssl ||= 0;
    145     }
    146 
    147     if(exists $ircnets{$alias}) {
    148         die("Already connected to a server with alias '$alias'. Either disconnect or specify an alias with -a.\n");
    149105    }
    150106
    … …  
    192148    my $msg = BarnOwl::Message->new(
    193149        type        => 'IRC',
    194         direction   => is_private($to) ? 'out' : 'in',
     150        direction   => 'out',
    195151        server      => $conn->server,
    196152        network     => $conn->alias,
    … …  
    213169}
    214170
    215 sub cmd_part {
    216     my $cmd = shift;
    217     my $conn = get_connection(\@_);
    218     my $chan = get_channel(\@_) || die("Usage: $cmd <channel>\n");
    219     $conn->part($chan);
    220 }
    221 
    222171sub cmd_nick {
    223172    my $cmd = shift;
    224173    my $conn = get_connection(\@_);
    225     my $nick = shift or die("Usage: $cmd <new nick>\n");
     174    my $nick = shift or die("Usage: $cmd <new nick>");
    226175    $conn->nick($nick);
    227 }
    228 
    229 sub cmd_names {
    230     my $cmd = shift;
    231     my $conn = get_connection(\@_);
    232     my $chan = get_channel(\@_) || die("Usage: $cmd <channel>\n");
    233     $conn->names($chan);
    234 }
    235 
    236 sub cmd_whois {
    237     my $cmd = shift;
    238     my $conn = get_connection(\@_);
    239     my $who = shift || die("Usage: $cmd <user>\n");
    240     $conn->whois($who);
    241176}
    242177
    … …  
    261196}
    262197
    263 sub get_channel {
    264     my $args = shift;
    265     if(scalar @$args) {
    266         return shift @$args;
    267     }
    268     my $m = BarnOwl::getcurmsg();
    269     if($m && $m->type eq 'IRC') {
    270         return $m->channel if !$m->is_private;
    271     }
    272     return undef;
    273 }
    274 
    275198sub get_connection_by_alias {
    276199    my $key = shift;
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r9e02bb7 r0e52069  
    1616
    1717use base qw(Net::IRC::Connection Class::Accessor Exporter);
    18 __PACKAGE__->mk_accessors(qw(alias channels motd));
     18__PACKAGE__->mk_accessors(qw(alias channels));
    1919our @EXPORT_OK = qw(&is_private);
    2020
    … …  
    2929    $self->alias($alias);
    3030    $self->channels([]);
    31     $self->motd("");
    3231    bless($self, $class);
    3332
     33    $self->add_global_handler(376 => sub { goto &on_connect });
     34    $self->add_global_handler(['msg', 'notice', 'public', 'caction'],
     35            sub { goto &on_msg });
     36    $self->add_global_handler(cping => sub { goto &on_ping });
    3437    $self->add_default_handler(sub { goto &on_event; });
    35     $self->add_handler(376 => sub { goto &on_connect });
    36     $self->add_handler(['msg', 'notice', 'public', 'caction'],
    37             sub { goto &on_msg });
    38     $self->add_handler(['welcome', 'yourhost', 'created',
    39             'luserclient', 'luserop', 'luserchannels', 'luserme'],
    40             sub { goto &on_admin_msg });
    41     $self->add_handler(['myinfo', 'map', 'n_local', 'n_global',
    42             'luserconns'],
    43             sub { });
    44     $self->add_handler(motdstart => sub { goto &on_motdstart });
    45     $self->add_handler(motd      => sub { goto &on_motd });
    46     $self->add_handler(endofmotd => sub { goto &on_endofmotd });
    47     $self->add_handler(join      => sub { goto &on_join });
    48     $self->add_handler(part      => sub { goto &on_part });
    49     $self->add_handler(disconnect => sub { goto &on_disconnect });
    50     $self->add_handler(nicknameinuse => sub { goto &on_nickinuse });
    51     $self->add_handler(cping     => sub { goto &on_ping });
    5238
    5339    return $self;
    … …  
    6349}
    6450
    65 sub new_message {
    66     my $self = shift;
    67     my $evt = shift;
    68     return BarnOwl::Message->new(
    69         type        => 'IRC',
    70         server      => $self->server,
    71         network     => $self->alias,
    72         sender      => $evt->nick,
    73         hostname    => $evt->host,
    74         from        => $evt->from,
    75         @_
    76        );
    77 }
    78 
    7951sub on_msg {
    8052    my ($self, $evt) = @_;
    8153    my ($recipient) = $evt->to;
    8254    my $body = strip_irc_formatting([$evt->args]->[0]);
    83     my $nick = $self->nick;
    84     BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;
    8555    $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
    86     my $msg = $self->new_message($evt,
     56    my $msg = BarnOwl::Message->new(
     57        type        => 'IRC',
    8758        direction   => 'in',
     59        server      => $self->server,
     60        network     => $self->alias,
    8861        recipient   => $recipient,
    89         body => $body,
     62        body        => $body,
     63        sender      => $evt->nick,
     64        hostname    => $evt->host,
     65        from        => $evt->from,
    9066        $evt->type eq 'notice' ?
    9167          (notice     => 'true') : (),
    … …  
    9470        replycmd    => 'irc-msg ' .
    9571            (is_private($recipient) ? $evt->nick : $recipient),
    96         replysendercmd => 'irc-msg ' . $evt->nick
     72        replysendercmd => 'irc-msg ' . $evt->nick,
    9773       );
    98 
    9974    BarnOwl::queue_message($msg);
    10075}
    … …  
    10580}
    10681
    107 sub on_admin_msg {
    108     my ($self, $evt) = @_;
    109     BarnOwl::admin_message("IRC",
    110             BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
    111                 . $evt->alias) . "\n"
    112             . strip_irc_formatting(join '\n', cdr $evt->args));
    113 }
    114 
    115 sub on_motdstart {
    116     my ($self, $evt) = @_;
    117     $self->motd(join "\n", cdr $evt->args);
    118 }
    119 
    120 sub on_motd {
    121     my ($self, $evt) = @_;
    122     $self->motd(join "\n", $self->motd, cdr $evt->args);
    123 }
    124 
    125 sub on_endofmotd {
    126     my ($self, $evt) = @_;
    127     $self->motd(join "\n", $self->motd, cdr $evt->args);
    128     BarnOwl::admin_message("IRC",
    129             BarnOwl::Style::boldify('MOTD for ' . $evt->alias) . "\n"
    130             . strip_irc_formatting($self->motd));
    131 }
    132 
    133 sub on_join {
    134     my ($self, $evt) = @_;
    135     my $msg = $self->new_message($evt,
    136         loginout   => 'login',
    137         channel    => $evt->to,
    138         );
    139     BarnOwl::queue_message($msg);
    140 }
    141 
    142 sub on_part {
    143     my ($self, $evt) = @_;
    144     my $msg = $self->new_message($evt,
    145         loginout   => 'logout',
    146         channel    => $evt->to,
    147         );
    148     BarnOwl::queue_message($msg);
    149 }
    150 
    151 sub on_disconnect {
    152     my $self = shift;
    153     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    154 
    155     BarnOwl::admin_message('IRC',
    156                            "[" . $self->alias . "] Disconnected from server");
    157 }
    158 
    159 sub on_nickinuse {
    160     my ($self, $evt) = @_;
    161     BarnOwl::admin_message("IRC",
    162                            "[" . $self->alias . "] " .
    163                            [$evt->args]->[1] . ": Nick already in use");
    164 }
    165 
    16682sub on_event {
    16783    my ($self, $evt) = @_;
    16884    BarnOwl::admin_message("IRC",
    169             "[" . $self->alias . "] Unhandled IRC event of type " . $evt->type . ":\n"
     85            "Unhandled IRC event of type " . $evt->type . ":\n"
    17086            . strip_irc_formatting(join("\n", $evt->args)))
    17187        if BarnOwl::getvar('irc:spew') eq 'on';
    17288}
    173 
    17489
    17590################################################################################
    … …  
    17994sub strip_irc_formatting {
    18095    my $body = shift;
    181     # Strip mIRC colors. If someone wants to write code to convert
    182     # these to zephyr colors, be my guest.
    183     $body =~ s/\cC\d+(?:,\d+)?//g;
    184     $body =~ s/\cO//g;
    185    
    186     my @pieces = split /\cB/, $body;
     96    my @pieces = split /\x02/, $body;
    18797     my $out;
    18898    while(@pieces) {
    … …  
    199109}
    200110
    201 sub cdr {
    202     shift;
    203     return @_;
    204 }
    205 
    2061111;
  • perlglue.xs

    r65fea01 rb363d83  
    1313#define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV)
    1414
    15         /*************************************************************
    16          * NOTE
    17          *************************************************************
    18          * These functions, when they are intended to be user-visible,
    19          * are document in perlwrap.pm. If you add functions to this
    20          * file, add the appropriate documentation there!
    21          *
    22          * If the function is simple enough, we simply define its
    23          * entire functionality here in XS. If, however, it needs
    24          * complex argument processing or something, we define a
    25          * simple version here that takes arguments in as flat a
    26          * manner as possible, to simplify the XS code, with a name
    27          * with a trailing `_internal', and write a perl wrapper in
    28          * perlwrap.pm that munges the arguments as appropriate and
    29          * calls the internal version.
    30          */
    31 
    32 MODULE = BarnOwl                PACKAGE = BarnOwl
     15MODULE = BarnOwl                PACKAGE = BarnOwl               
    3316
    3417char *
  • perlwrap.pm

    rb0c8011 r18fb3d4f  
    1414
    1515package BarnOwl;
    16 
    17 =head1 NAME
    18 
    19 BarnOwl
    20 
    21 =head1 DESCRIPTION
    22 
    23 The BarnOwl module contains the core of BarnOwl's perl
    24 bindings. Source in this module is also run at startup to bootstrap
    25 barnowl by defining things like the default style.
    26 
    27 =for NOTE
    28 These following functions are defined in perlglue.xs. Keep the
    29 documentation here in sync with the user-visible commands defined
    30 there!
    31 
    32 =head2 command STRING
    33 
    34 Executes a BarnOwl command in the same manner as if the user had
    35 executed it at the BarnOwl command prompt. If the command returns a
    36 value, return it as a string, otherwise return undef.
    37 
    38 =head2 getcurmsg
    39 
    40 Returns the current message as a C<BarnOwl::Message> subclass, or
    41 undef if there is no message selected
    42 
    43 =head2 getnumcols
    44 
    45 Returns the width of the display window BarnOwl is currently using
    46 
    47 =head2 getidletime
    48 
    49 Returns the length of time since the user has pressed a key, in
    50 seconds.
    51 
    52 =head2 zephyr_getrealm
    53 
    54 Returns the zephyr realm barnowl is running in
    55 
    56 =head2 zephyr_getsender
    57 
    58 Returns the fully-qualified name of the zephyr sender barnowl is
    59 running as, e.g. C<nelhage@ATHENA.MIT.EDU>
    60 
    61 =head2 zephyr_zwrite COMMAND MESSAGE
    62 
    63 Sends a zephyr programmatically. C<COMMAND> should be a C<zwrite>
    64 command line, and C<MESSAGE> is the zephyr body to send.
    65 
    66 =head2 ztext_stylestrip STRING
    67 
    68 Strips zephyr formatting from a string and returns the result
    69 
    70 =head2 queue_message MESSAGE
    71 
    72 Enqueue a message in the BarnOwl message list, logging it and
    73 processing it appropriately. C<MESSAGE> should be an instance of
    74 BarnOwl::Message or a subclass.
    75 
    76 =head2 admin_message HEADER BODY
    77 
    78 Display a BarnOwl B<Admin> message, with the given header and body.
    79 
    80 =head2 start_question PROMPT CALLBACK
    81 
    82 Displays C<PROMPT> on the screen and lets the user enter a line of
    83 text, and calls C<CALLBACK>, which must be a perl subroutine
    84 reference, with the text the user entered
    85 
    86 =head2 start_password PROMPT CALLBACK
    87 
    88 Like C<start_question>, but echoes the user's input as C<*>s when they
    89 input.
    90 
    91 =head2 start_editwin PROMPT CALLBACK
    92 
    93 Like C<start_question>, but displays C<PROMPT> on a line of its own
    94 and opens the editwin. If the user cancels the edit win, C<CALLBACK>
    95 is not invoked.
    96 
    97 =head2 get_data_dir
    98 
    99 Returns the BarnOwl system data directory, where system libraries and
    100 modules are stored
    101 
    102 =head2 get_config_dir
    103 
    104 Returns the BarnOwl user configuration directory, where user modules
    105 and configuration are stored (by default, C<$HOME/.owl>)
    106 
    107 =head2 popless_text TEXT
    108 
    109 Show a popup window containing the given C<TEXT>
    110 
    111 =head2 popless_ztext TEXT
    112 
    113 Show a popup window containing the provided zephyr-formatted C<TEXT>
    114 
    115 =head2 error STRING
    116 
    117 Reports an error and log it in `show errors'. Note that in any
    118 callback or hook called in perl code from BarnOwl, a C<die> will be
    119 caught and passed to C<error>.
    120 
    121 =head2 getnumcolors
    122 
    123 Returns the number of colors this BarnOwl is capable of displaying
    124 
    125 =cut
    126 
    12716
    12817BEGIN {
    … …  
    15746    return &BarnOwl::Hooks::_receive_msg($m);
    15847}
    159 
    160 =head2 AUTOLOAD
    161 
    162 BarnOwl.pm has a C<AUTOLOAD> method that translates unused names in
    163 the BarnOwl:: namespace to a call to BarnOwl::command() with that
    164 command. Underscores are also translated to C<->s, so you can do
    165 e.g. C<BarnOwl::start_command()> and it will be translated into
    166 C<start-command>.
    167 
    168 So, if you're looking for functionality that you can't find in the
    169 perl interface, check C<:show commands> or C<commands.c> in the
    170 BarnOwl source tree -- there's a good chance it exists as a BarnOwl
    171 command.
    172 
    173 =head3 BUGS
    174 
    175 There are horrible quoting issues here. The AUTOLOAD simple joins your
    176 commands with spaces and passes them unmodified to C<::command>
    177 
    178 =cut
    17948
    18049# make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo");
    … …  
    19463
    19564ARGS should be a hashref containing any or all of C<summary>,
    196 C<usage>, or C<description> keys:
    197 
    198 =over 4
    199 
    200 =item summary
    201 
    202 A one-line summary of the purpose of the command
    203 
    204 =item usage
    205 
    206 A one-line usage synopsis, showing available options and syntax
    207 
    208 =item description
    209 
    210 A longer description of the syntax and semantics of the command,
    211 explaining usage and options
    212 
    213 =back
     65C<usage>, or C<description> keys.
    21466
    21567=cut
    … …  
    558410package BarnOwl::Hook;
    559411
    560 =head1 BarnOwl::Hook
    561 
    562 =head1 DESCRIPTION
    563 
    564 A C<BarnOwl::Hook> represents a list of functions to be triggered on
    565 some event. C<BarnOwl> exports a default set of these (see
    566 C<BarnOwl::Hooks>), but can also be created and used by module code.
    567 
    568 =head2 new
    569 
    570 Creates a new Hook object
    571 
    572 =cut
    573 
    574412sub new {
    575413    my $class = shift;
    576414    return bless [], $class;
    577415}
    578 
    579 =head2 run [ARGS]
    580 
    581 Calls each of the functions registered with this hook with the given
    582 arguments.
    583 
    584 =cut
    585416
    586417sub run {
    … …  
    589420    return map {$_->(@args)} @$self;
    590421}
    591 
    592 =head2 add SUBREF
    593 
    594 Registers a given subroutine with this hook
    595 
    596 =cut
    597422
    598423sub add {
    … …  
    603428}
    604429
    605 =head2 clear
    606 
    607 Remove all functions registered with this hook.
    608 
    609 =cut
    610 
    611430sub clear {
    612431    my $self = shift;
    … …  
    615434
    616435package BarnOwl::Hooks;
    617 
    618 =head1 BarnOwl::Hooks
    619 
    620 =head1 DESCRIPTION
    621 
    622 C<BarnOwl::Hooks> exports a set of C<BarnOwl::Hook> objects made
    623 available by BarnOwl internally.
    624 
    625 =head2 USAGE
    626 
    627 Modules wishing to respond to events in BarnOwl should register
    628 functions with these hooks.
    629 
    630 =head2 EXPORTS
    631 
    632 None by default. Either import the hooks you need explicitly, or refer
    633 to them with fully-qualified names. Available hooks are:
    634 
    635 =over 4
    636 
    637 =item $startup
    638 
    639 Called on BarnOwl startup, and whenever modules are
    640 reloaded. Functions registered with the C<$startup> hook get a true
    641 argument if this is a reload, and false if this is a true startup
    642 
    643 =item $shutdown
    644 
    645 Called before BarnOwl shutdown
    646 
    647 =item $receiveMessage
    648 
    649 Called with a C<BarnOwl::Message> object every time BarnOwl appends a
    650 new message to its message list
    651 
    652 =item $mainLoop
    653 
    654 Called on B<every pass> through the C<BarnOwl> main loop. Any
    655 functions with this hook should be very cheap, as they are very
    656 frequently by the runtime.
    657 
    658 =item $getBuddyList
    659 
    660 Called to display buddy lists for all protocol handlers. The result
    661 from every function registered with this hook will be appended and
    662 displayed in a popup window, with zephyr formatting parsed.
    663 
    664 =back
    665 
    666 =cut
    667436
    668437use Exporter;
    … …  
    699468    }
    700469}
    701 
    702 # These are the internal hooks called by the barnowl C code, which
    703 # take care of dispatching to the appropriate perl hooks, and deal
    704 # with compatibility by calling the old, fixed-name hooks.
    705470
    706471sub _startup {
  • variable.c

    rd536e72 rad15610  
    455455
    456456int owl_variable_dict_setup(owl_vardict *vd) {
    457   owl_variable *var, *cur;
     457  owl_variable *cur;
    458458  if (owl_dict_create(vd)) return(-1);
    459   for (var = variables_to_init; var->name != NULL; var++) {
    460     cur = owl_malloc(sizeof(owl_variable));
    461     memcpy(cur, var, sizeof(owl_variable));
     459  for (cur = variables_to_init; cur->name != NULL; cur++) {
    462460    switch (cur->type) {
    463461    case OWL_VARIABLE_OTHER:
    … …  
    522520void owl_variable_dict_add_variable(owl_vardict * vardict,
    523521                                    owl_variable * var) {
    524   owl_dict_insert_element(vardict, var->name, (void*)var, (void(*)(void*))owl_variable_free);
     522  owl_dict_insert_element(vardict, var->name, (void*)var, NULL);
    525523}
    526524
    … …  
    534532}
    535533
    536 void owl_variable_update(owl_variable *var, char *summary, char *desc) {
    537   if(var->summary) owl_free(var->summary);
    538   var->summary = owl_strdup(summary);
    539   if(var->description) owl_free(var->description);
    540   var->description = owl_strdup(desc);
    541 }
    542 
    543534void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) {
    544   owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING);
    545   if(old) {
    546     owl_variable_update(old, summ, desc);
    547     if(old->pval_default) owl_free(old->pval_default);
    548     old->pval_default = owl_strdup(initval);
    549   } else {
    550     owl_variable * var = owl_variable_newvar(name, summ, desc);
    551     var->type = OWL_VARIABLE_STRING;
    552     var->pval_default = owl_strdup(initval);
    553     var->set_fn = owl_variable_string_set_default;
    554     var->set_fromstring_fn = owl_variable_string_set_fromstring_default;
    555     var->get_fn = owl_variable_get_default;
    556     var->get_tostring_fn = owl_variable_string_get_tostring_default;
    557     var->free_fn = owl_variable_free_default;
    558     var->set_fn(var, initval);
    559     owl_variable_dict_add_variable(vd, var);
    560   }
     535  owl_variable * var = owl_variable_newvar(name, summ, desc);
     536  var->type = OWL_VARIABLE_STRING;
     537  var->pval_default = owl_strdup(initval);
     538  var->set_fn = owl_variable_string_set_default;
     539  var->set_fromstring_fn = owl_variable_string_set_fromstring_default;
     540  var->get_fn = owl_variable_get_default;
     541  var->get_tostring_fn = owl_variable_string_get_tostring_default;
     542  var->free_fn = owl_variable_free_default;
     543  var->set_fn(var, initval);
     544  owl_variable_dict_add_variable(vd, var);
    561545}
    562546
    563547void owl_variable_dict_newvar_int(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
    564   owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT);
    565   if(old) {
    566     owl_variable_update(old, summ, desc);
    567     old->ival_default = initval;
    568   } else {
    569     owl_variable * var = owl_variable_newvar(name, summ, desc);
    570     var->type = OWL_VARIABLE_INT;
    571     var->ival_default = initval;
    572     var->validate_fn = owl_variable_int_validate_default;
    573     var->set_fn = owl_variable_int_set_default;
    574     var->set_fromstring_fn = owl_variable_int_set_fromstring_default;
    575     var->get_fn = owl_variable_get_default;
    576     var->get_tostring_fn = owl_variable_int_get_tostring_default;
    577     var->free_fn = owl_variable_free_default;
    578     var->val = owl_malloc(sizeof(int));
    579     var->set_fn(var, &initval);
    580     owl_variable_dict_add_variable(vd, var);
    581   }
     548  owl_variable * var = owl_variable_newvar(name, summ, desc);
     549  var->type = OWL_VARIABLE_INT;
     550  var->ival_default = initval;
     551  var->validate_fn = owl_variable_int_validate_default;
     552  var->set_fn = owl_variable_int_set_default;
     553  var->set_fromstring_fn = owl_variable_int_set_fromstring_default;
     554  var->get_fn = owl_variable_get_default;
     555  var->get_tostring_fn = owl_variable_int_get_tostring_default;
     556  var->free_fn = owl_variable_free_default;
     557  var->val = owl_malloc(sizeof(int));
     558  var->set_fn(var, &initval);
     559  owl_variable_dict_add_variable(vd, var);
    582560}
    583561
    584562void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
    585   owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL);
    586   if(old) {
    587     owl_variable_update(old, summ, desc);
    588     old->ival_default = initval;
    589   } else {
    590     owl_variable * var = owl_variable_newvar(name, summ, desc);
    591     var->type = OWL_VARIABLE_BOOL;
    592     var->ival_default = initval;
    593     var->validate_fn = owl_variable_bool_validate_default;
    594     var->set_fn = owl_variable_bool_set_default;
    595     var->set_fromstring_fn = owl_variable_bool_set_fromstring_default;
    596     var->get_fn = owl_variable_get_default;
    597     var->get_tostring_fn = owl_variable_bool_get_tostring_default;
    598     var->free_fn = owl_variable_free_default;
    599     var->val = owl_malloc(sizeof(int));
    600     var->set_fn(var, &initval);
    601     owl_variable_dict_add_variable(vd, var);
    602   }
     563  owl_variable * var = owl_variable_newvar(name, summ, desc);
     564  var->type = OWL_VARIABLE_BOOL;
     565  var->ival_default = initval;
     566  var->validate_fn = owl_variable_bool_validate_default;
     567  var->set_fn = owl_variable_bool_set_default;
     568  var->set_fromstring_fn = owl_variable_bool_set_fromstring_default;
     569  var->get_fn = owl_variable_get_default;
     570  var->get_tostring_fn = owl_variable_bool_get_tostring_default;
     571  var->free_fn = owl_variable_free_default;
     572  var->val = owl_malloc(sizeof(int));
     573  var->set_fn(var, &initval);
     574  owl_variable_dict_add_variable(vd, var);
    603575}
    604576
    … …  
    618590void owl_variable_free(owl_variable *v) {
    619591  if (v->free_fn) v->free_fn(v);
    620   owl_free(v);
    621592}
    622593
    … …  
    716687}
    717688
    718 owl_variable *owl_variable_get_var(owl_vardict *d, char *name, int require_type) {
     689/* returns a reference */
     690void *owl_variable_get(owl_vardict *d, char *name, int require_type) {
    719691  owl_variable *v;
    720692  if (!name) return(NULL);
    721693  v = owl_dict_find_element(d, name);
    722694  if (v == NULL || !v->get_fn || v->type != require_type) return(NULL);
    723   return v;
    724 }
    725 
    726 /* returns a reference */
    727 void *owl_variable_get(owl_vardict *d, char *name, int require_type) {
    728   owl_variable *v = owl_variable_get_var(d, name, require_type);
    729   if(v == NULL) return NULL;
    730695  return v->get_fn(v);
    731696}
  • zephyr.c

    r1151f0b r6201646  
    601601    }
    602602  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
    603     #define BUFFLEN 1024
    604     if (retnotice->z_recipient == NULL
    605         || *retnotice->z_recipient == NULL
    606         || *retnotice->z_recipient == '@') {
    607       char buff[BUFFLEN];
    608       owl_function_error("No one subscribed to class %s", retnotice->z_class);
    609       snprintf(buff, BUFFLEN, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class);
     603    if (strcasecmp(retnotice->z_class, "message")) {
     604      char buff[1024];
     605      owl_function_error("No one subscribed to class class %s", retnotice->z_class);
     606      sprintf(buff, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class);
    610607      owl_function_adminmsg("", buff);
    611608    } else {
    612       char buff[BUFFLEN];
     609      char buff[1024];
    613610      tmp = short_zuser(retnotice->z_recipient);
    614       owl_function_error("%s: Not logged in or subscribing.", tmp);
    615       snprintf(buff, BUFFLEN, "Could not send message to %s: not logged in or subscribing to", tmp);
    616       if(strcmp(retnotice->z_class, "message")) {
    617         snprintf(buff, BUFFLEN,
    618                  "%s class %s, instance %s.\n", buff,
    619                  retnotice->z_class,
    620                  retnotice->z_class_inst);
    621       } else {
    622         snprintf(buff, BUFFLEN,
    623                  "%s messages.\n", buff);
    624       }
     611      owl_function_error("%s: Not logged in or subscribing to messages.", tmp);
     612      sprintf(buff, "Could not send message to %s: not logged in or subscribing to messages.\n", tmp);
    625613      owl_function_adminmsg("", buff);
    626614      owl_log_outgoing_zephyr_error(tmp, buff);
Note: See TracChangeset for help on using the changeset viewer.