Changes in / [16c6cca:a827529]


Ignore:
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • message.c

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

    rbe98ba5 rb0c8011  
    99
    1010sub load_all {
     11    PAR::reload_libs();
    1112    my %modules;
    1213    my @modules;
     
    3637    for my $class (keys %modules) {
    3738        if(!defined eval "use BarnOwl::Module::$class") {
    38             BarnOwl::error("Unable to load module $class: $!") if $!;
     39            # BarnOwl::error("Unable to load module $class: $!") if $!;
    3940            BarnOwl::error("Unable to load module $class: $@") if $@;
    4041        }
     
    4748    BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, {
    4849                           summary => 'Reload all modules',
    49                            usage   => 'reload',
     50                           usage   => 'reload-modules',
    5051                           description => q{Reloads all modules located in ~/.owl/modules and the system modules directory}
    5152                          });
  • perl/modules/IRC/lib/BarnOwl/Message/IRC.pm

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

    r6286f26 rb0c8011  
    3030
    3131sub startup {
    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});
     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   
    3659    register_commands();
    3760    register_handlers();
     
    6184
    6285sub register_commands {
    63     BarnOwl::new_command('irc-connect' => \&cmd_connect);
     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                       });
    6498    BarnOwl::new_command('irc-disconnect' => \&cmd_disconnect);
    65     BarnOwl::new_command('irc-msg'     => \&cmd_msg);
    66     BarnOwl::new_command('irc-join' => \&cmd_join);
    67     BarnOwl::new_command('irc-nick' => \&cmd_nick);
     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);
    68105}
    69106
     
    94131            "ssl"        => \$ssl,
    95132            "password=s" => \$password,
    96             "port=i"     => \$port,
     133            "nick=s"     => \$nick,
    97134        );
    98135        $host = shift @ARGV or die("Usage: $cmd HOST\n");
    99136        if(!$alias) {
    100             $alias = $1 if $host =~ /^(?:irc[.])?(\w+)[.]\w+$/;
    101             $alias ||= $host;
     137            if($host =~ /^(?:irc[.])?(\w+)[.]\w+$/) {
     138                $alias = $1;
     139            } else {
     140                $alias = $host;
     141            }
    102142        }
    103         $port ||= 6667;
     143        $port = shift @ARGV || 6667;
    104144        $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");
    105149    }
    106150
     
    148192    my $msg = BarnOwl::Message->new(
    149193        type        => 'IRC',
    150         direction   => 'out',
     194        direction   => is_private($to) ? 'out' : 'in',
    151195        server      => $conn->server,
    152196        network     => $conn->alias,
     
    169213}
    170214
     215sub 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
    171222sub cmd_nick {
    172223    my $cmd = shift;
    173224    my $conn = get_connection(\@_);
    174     my $nick = shift or die("Usage: $cmd <new nick>");
     225    my $nick = shift or die("Usage: $cmd <new nick>\n");
    175226    $conn->nick($nick);
     227}
     228
     229sub 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
     236sub cmd_whois {
     237    my $cmd = shift;
     238    my $conn = get_connection(\@_);
     239    my $who = shift || die("Usage: $cmd <user>\n");
     240    $conn->whois($who);
    176241}
    177242
     
    196261}
    197262
     263sub 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
    198275sub get_connection_by_alias {
    199276    my $key = shift;
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r0e52069 r9e02bb7  
    1616
    1717use base qw(Net::IRC::Connection Class::Accessor Exporter);
    18 __PACKAGE__->mk_accessors(qw(alias channels));
     18__PACKAGE__->mk_accessors(qw(alias channels motd));
    1919our @EXPORT_OK = qw(&is_private);
    2020
     
    2929    $self->alias($alias);
    3030    $self->channels([]);
     31    $self->motd("");
    3132    bless($self, $class);
    3233
    33     $self->add_global_handler(376 => sub { goto &on_connect });
    34     $self->add_global_handler(['msg', 'notice', 'public', 'caction'],
     34    $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'],
    3537            sub { goto &on_msg });
    36     $self->add_global_handler(cping => sub { goto &on_ping });
    37     $self->add_default_handler(sub { goto &on_event; });
     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 });
    3852
    3953    return $self;
     
    4963}
    5064
    51 sub on_msg {
    52     my ($self, $evt) = @_;
    53     my ($recipient) = $evt->to;
    54     my $body = strip_irc_formatting([$evt->args]->[0]);
    55     $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
    56     my $msg = BarnOwl::Message->new(
     65sub new_message {
     66    my $self = shift;
     67    my $evt = shift;
     68    return BarnOwl::Message->new(
    5769        type        => 'IRC',
    58         direction   => 'in',
    5970        server      => $self->server,
    6071        network     => $self->alias,
    61         recipient   => $recipient,
    62         body        => $body,
    6372        sender      => $evt->nick,
    6473        hostname    => $evt->host,
    6574        from        => $evt->from,
     75        @_
     76       );
     77}
     78
     79sub on_msg {
     80    my ($self, $evt) = @_;
     81    my ($recipient) = $evt->to;
     82    my $body = strip_irc_formatting([$evt->args]->[0]);
     83    my $nick = $self->nick;
     84    BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;
     85    $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
     86    my $msg = $self->new_message($evt,
     87        direction   => 'in',
     88        recipient   => $recipient,
     89        body => $body,
    6690        $evt->type eq 'notice' ?
    6791          (notice     => 'true') : (),
     
    7094        replycmd    => 'irc-msg ' .
    7195            (is_private($recipient) ? $evt->nick : $recipient),
    72         replysendercmd => 'irc-msg ' . $evt->nick,
     96        replysendercmd => 'irc-msg ' . $evt->nick
    7397       );
     98
    7499    BarnOwl::queue_message($msg);
    75100}
     
    80105}
    81106
     107sub 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
     115sub on_motdstart {
     116    my ($self, $evt) = @_;
     117    $self->motd(join "\n", cdr $evt->args);
     118}
     119
     120sub on_motd {
     121    my ($self, $evt) = @_;
     122    $self->motd(join "\n", $self->motd, cdr $evt->args);
     123}
     124
     125sub 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
     133sub 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
     142sub 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
     151sub 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
     159sub on_nickinuse {
     160    my ($self, $evt) = @_;
     161    BarnOwl::admin_message("IRC",
     162                           "[" . $self->alias . "] " .
     163                           [$evt->args]->[1] . ": Nick already in use");
     164}
     165
    82166sub on_event {
    83167    my ($self, $evt) = @_;
    84168    BarnOwl::admin_message("IRC",
    85             "Unhandled IRC event of type " . $evt->type . ":\n"
     169            "[" . $self->alias . "] Unhandled IRC event of type " . $evt->type . ":\n"
    86170            . strip_irc_formatting(join("\n", $evt->args)))
    87171        if BarnOwl::getvar('irc:spew') eq 'on';
    88172}
    89173
     174
    90175################################################################################
    91176########################### Utilities/Helpers ##################################
     
    94179sub strip_irc_formatting {
    95180    my $body = shift;
    96     my @pieces = split /\x02/, $body;
     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;
    97187     my $out;
    98188    while(@pieces) {
     
    109199}
    110200
     201sub cdr {
     202    shift;
     203    return @_;
     204}
     205
    1112061;
  • perlglue.xs

    rb363d83 r65fea01  
    1313#define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV)
    1414
    15 MODULE = BarnOwl                PACKAGE = BarnOwl               
     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
     32MODULE = BarnOwl                PACKAGE = BarnOwl
    1633
    1734char *
  • perlwrap.pm

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

    rad15610 rd536e72  
    455455
    456456int owl_variable_dict_setup(owl_vardict *vd) {
    457   owl_variable *cur;
     457  owl_variable *var, *cur;
    458458  if (owl_dict_create(vd)) return(-1);
    459   for (cur = variables_to_init; cur->name != NULL; cur++) {
     459  for (var = variables_to_init; var->name != NULL; var++) {
     460    cur = owl_malloc(sizeof(owl_variable));
     461    memcpy(cur, var, sizeof(owl_variable));
    460462    switch (cur->type) {
    461463    case OWL_VARIABLE_OTHER:
     
    520522void owl_variable_dict_add_variable(owl_vardict * vardict,
    521523                                    owl_variable * var) {
    522   owl_dict_insert_element(vardict, var->name, (void*)var, NULL);
     524  owl_dict_insert_element(vardict, var->name, (void*)var, (void(*)(void*))owl_variable_free);
    523525}
    524526
     
    532534}
    533535
     536void 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
    534543void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) {
    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);
     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  }
    545561}
    546562
    547563void owl_variable_dict_newvar_int(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
    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);
     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  }
    560582}
    561583
    562584void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
    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);
     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  }
    575603}
    576604
     
    590618void owl_variable_free(owl_variable *v) {
    591619  if (v->free_fn) v->free_fn(v);
     620  owl_free(v);
    592621}
    593622
     
    687716}
    688717
    689 /* returns a reference */
    690 void *owl_variable_get(owl_vardict *d, char *name, int require_type) {
     718owl_variable *owl_variable_get_var(owl_vardict *d, char *name, int require_type) {
    691719  owl_variable *v;
    692720  if (!name) return(NULL);
    693721  v = owl_dict_find_element(d, name);
    694722  if (v == NULL || !v->get_fn || v->type != require_type) return(NULL);
     723  return v;
     724}
     725
     726/* returns a reference */
     727void *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;
    695730  return v->get_fn(v);
    696731}
  • zephyr.c

    r6201646 r1151f0b  
    601601    }
    602602  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
    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);
     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);
    607610      owl_function_adminmsg("", buff);
    608611    } else {
    609       char buff[1024];
     612      char buff[BUFFLEN];
    610613      tmp = short_zuser(retnotice->z_recipient);
    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);
     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      }
    613625      owl_function_adminmsg("", buff);
    614626      owl_log_outgoing_zephyr_error(tmp, buff);
Note: See TracChangeset for help on using the changeset viewer.