Changes in / [a827529:16c6cca]
- Files:
-
- 9 edited
-
message.c (modified) (1 diff)
-
perl/lib/BarnOwl/ModuleLoader.pm (modified) (3 diffs)
-
perl/modules/IRC/lib/BarnOwl/Message/IRC.pm (modified) (1 diff)
-
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm (modified) (6 diffs)
-
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm (modified) (7 diffs)
-
perlglue.xs (modified) (1 diff)
-
perlwrap.pm (modified) (8 diffs)
-
variable.c (modified) (5 diffs)
-
zephyr.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
message.c
r635881c r3a7cf49 330 330 res=owl_message_get_attribute_value(m, "isprivate"); 331 331 if (!res) return(0); 332 return !strcmp(res, "true");332 return(1); 333 333 } 334 334 -
perl/lib/BarnOwl/ModuleLoader.pm
rb0c8011 rbe98ba5 9 9 10 10 sub load_all { 11 PAR::reload_libs();12 11 my %modules; 13 12 my @modules; … … 37 36 for my $class (keys %modules) { 38 37 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 $!; 40 39 BarnOwl::error("Unable to load module $class: $@") if $@; 41 40 } … … 48 47 BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, { 49 48 summary => 'Reload all modules', 50 usage => 'reload -modules',49 usage => 'reload', 51 50 description => q{Reloads all modules located in ~/.owl/modules and the system modules directory} 52 51 }); -
perl/modules/IRC/lib/BarnOwl/Message/IRC.pm
r2fb58e4 r0e52069 56 56 sub long_sender {shift->{from} || ""}; 57 57 58 sub login_extra { shift->channel; }59 60 58 61 59 1; -
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
rb0c8011 r6286f26 30 30 31 31 sub 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}); 59 36 register_commands(); 60 37 register_handlers(); … … 84 61 85 62 sub 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); 98 64 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); 105 68 } 106 69 … … 131 94 "ssl" => \$ssl, 132 95 "password=s" => \$password, 133 " nick=s" => \$nick,96 "port=i" => \$port, 134 97 ); 135 98 $host = shift @ARGV or die("Usage: $cmd HOST\n"); 136 99 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; 142 102 } 143 $port = shift @ARGV ||6667;103 $port ||= 6667; 144 104 $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");149 105 } 150 106 … … 192 148 my $msg = BarnOwl::Message->new( 193 149 type => 'IRC', 194 direction => is_private($to) ? 'out' : 'in',150 direction => 'out', 195 151 server => $conn->server, 196 152 network => $conn->alias, … … 213 169 } 214 170 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 222 171 sub cmd_nick { 223 172 my $cmd = shift; 224 173 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>"); 226 175 $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);241 176 } 242 177 … … 261 196 } 262 197 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 275 198 sub get_connection_by_alias { 276 199 my $key = shift; -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r9e02bb7 r0e52069 16 16 17 17 use base qw(Net::IRC::Connection Class::Accessor Exporter); 18 __PACKAGE__->mk_accessors(qw(alias channels motd));18 __PACKAGE__->mk_accessors(qw(alias channels)); 19 19 our @EXPORT_OK = qw(&is_private); 20 20 … … 29 29 $self->alias($alias); 30 30 $self->channels([]); 31 $self->motd("");32 31 bless($self, $class); 33 32 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 }); 34 37 $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 });52 38 53 39 return $self; … … 63 49 } 64 50 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 79 51 sub on_msg { 80 52 my ($self, $evt) = @_; 81 53 my ($recipient) = $evt->to; 82 54 my $body = strip_irc_formatting([$evt->args]->[0]); 83 my $nick = $self->nick;84 BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;85 55 $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', 87 58 direction => 'in', 59 server => $self->server, 60 network => $self->alias, 88 61 recipient => $recipient, 89 body => $body, 62 body => $body, 63 sender => $evt->nick, 64 hostname => $evt->host, 65 from => $evt->from, 90 66 $evt->type eq 'notice' ? 91 67 (notice => 'true') : (), … … 94 70 replycmd => 'irc-msg ' . 95 71 (is_private($recipient) ? $evt->nick : $recipient), 96 replysendercmd => 'irc-msg ' . $evt->nick 72 replysendercmd => 'irc-msg ' . $evt->nick, 97 73 ); 98 99 74 BarnOwl::queue_message($msg); 100 75 } … … 105 80 } 106 81 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 166 82 sub on_event { 167 83 my ($self, $evt) = @_; 168 84 BarnOwl::admin_message("IRC", 169 " [" . $self->alias . "]Unhandled IRC event of type " . $evt->type . ":\n"85 "Unhandled IRC event of type " . $evt->type . ":\n" 170 86 . strip_irc_formatting(join("\n", $evt->args))) 171 87 if BarnOwl::getvar('irc:spew') eq 'on'; 172 88 } 173 174 89 175 90 ################################################################################ … … 179 94 sub strip_irc_formatting { 180 95 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; 187 97 my $out; 188 98 while(@pieces) { … … 199 109 } 200 110 201 sub cdr {202 shift;203 return @_;204 }205 206 111 1; -
perlglue.xs
r65fea01 rb363d83 13 13 #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) 14 14 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 15 MODULE = BarnOwl PACKAGE = BarnOwl 33 16 34 17 char * -
perlwrap.pm
rb0c8011 r18fb3d4f 14 14 15 15 package BarnOwl; 16 17 =head1 NAME18 19 BarnOwl20 21 =head1 DESCRIPTION22 23 The BarnOwl module contains the core of BarnOwl's perl24 bindings. Source in this module is also run at startup to bootstrap25 barnowl by defining things like the default style.26 27 =for NOTE28 These following functions are defined in perlglue.xs. Keep the29 documentation here in sync with the user-visible commands defined30 there!31 32 =head2 command STRING33 34 Executes a BarnOwl command in the same manner as if the user had35 executed it at the BarnOwl command prompt. If the command returns a36 value, return it as a string, otherwise return undef.37 38 =head2 getcurmsg39 40 Returns the current message as a C<BarnOwl::Message> subclass, or41 undef if there is no message selected42 43 =head2 getnumcols44 45 Returns the width of the display window BarnOwl is currently using46 47 =head2 getidletime48 49 Returns the length of time since the user has pressed a key, in50 seconds.51 52 =head2 zephyr_getrealm53 54 Returns the zephyr realm barnowl is running in55 56 =head2 zephyr_getsender57 58 Returns the fully-qualified name of the zephyr sender barnowl is59 running as, e.g. C<nelhage@ATHENA.MIT.EDU>60 61 =head2 zephyr_zwrite COMMAND MESSAGE62 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 STRING67 68 Strips zephyr formatting from a string and returns the result69 70 =head2 queue_message MESSAGE71 72 Enqueue a message in the BarnOwl message list, logging it and73 processing it appropriately. C<MESSAGE> should be an instance of74 BarnOwl::Message or a subclass.75 76 =head2 admin_message HEADER BODY77 78 Display a BarnOwl B<Admin> message, with the given header and body.79 80 =head2 start_question PROMPT CALLBACK81 82 Displays C<PROMPT> on the screen and lets the user enter a line of83 text, and calls C<CALLBACK>, which must be a perl subroutine84 reference, with the text the user entered85 86 =head2 start_password PROMPT CALLBACK87 88 Like C<start_question>, but echoes the user's input as C<*>s when they89 input.90 91 =head2 start_editwin PROMPT CALLBACK92 93 Like C<start_question>, but displays C<PROMPT> on a line of its own94 and opens the editwin. If the user cancels the edit win, C<CALLBACK>95 is not invoked.96 97 =head2 get_data_dir98 99 Returns the BarnOwl system data directory, where system libraries and100 modules are stored101 102 =head2 get_config_dir103 104 Returns the BarnOwl user configuration directory, where user modules105 and configuration are stored (by default, C<$HOME/.owl>)106 107 =head2 popless_text TEXT108 109 Show a popup window containing the given C<TEXT>110 111 =head2 popless_ztext TEXT112 113 Show a popup window containing the provided zephyr-formatted C<TEXT>114 115 =head2 error STRING116 117 Reports an error and log it in `show errors'. Note that in any118 callback or hook called in perl code from BarnOwl, a C<die> will be119 caught and passed to C<error>.120 121 =head2 getnumcolors122 123 Returns the number of colors this BarnOwl is capable of displaying124 125 =cut126 127 16 128 17 BEGIN { … … 157 46 return &BarnOwl::Hooks::_receive_msg($m); 158 47 } 159 160 =head2 AUTOLOAD161 162 BarnOwl.pm has a C<AUTOLOAD> method that translates unused names in163 the BarnOwl:: namespace to a call to BarnOwl::command() with that164 command. Underscores are also translated to C<->s, so you can do165 e.g. C<BarnOwl::start_command()> and it will be translated into166 C<start-command>.167 168 So, if you're looking for functionality that you can't find in the169 perl interface, check C<:show commands> or C<commands.c> in the170 BarnOwl source tree -- there's a good chance it exists as a BarnOwl171 command.172 173 =head3 BUGS174 175 There are horrible quoting issues here. The AUTOLOAD simple joins your176 commands with spaces and passes them unmodified to C<::command>177 178 =cut179 48 180 49 # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo"); … … 194 63 195 64 ARGS 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 65 C<usage>, or C<description> keys. 214 66 215 67 =cut … … 558 410 package BarnOwl::Hook; 559 411 560 =head1 BarnOwl::Hook561 562 =head1 DESCRIPTION563 564 A C<BarnOwl::Hook> represents a list of functions to be triggered on565 some event. C<BarnOwl> exports a default set of these (see566 C<BarnOwl::Hooks>), but can also be created and used by module code.567 568 =head2 new569 570 Creates a new Hook object571 572 =cut573 574 412 sub new { 575 413 my $class = shift; 576 414 return bless [], $class; 577 415 } 578 579 =head2 run [ARGS]580 581 Calls each of the functions registered with this hook with the given582 arguments.583 584 =cut585 416 586 417 sub run { … … 589 420 return map {$_->(@args)} @$self; 590 421 } 591 592 =head2 add SUBREF593 594 Registers a given subroutine with this hook595 596 =cut597 422 598 423 sub add { … … 603 428 } 604 429 605 =head2 clear606 607 Remove all functions registered with this hook.608 609 =cut610 611 430 sub clear { 612 431 my $self = shift; … … 615 434 616 435 package BarnOwl::Hooks; 617 618 =head1 BarnOwl::Hooks619 620 =head1 DESCRIPTION621 622 C<BarnOwl::Hooks> exports a set of C<BarnOwl::Hook> objects made623 available by BarnOwl internally.624 625 =head2 USAGE626 627 Modules wishing to respond to events in BarnOwl should register628 functions with these hooks.629 630 =head2 EXPORTS631 632 None by default. Either import the hooks you need explicitly, or refer633 to them with fully-qualified names. Available hooks are:634 635 =over 4636 637 =item $startup638 639 Called on BarnOwl startup, and whenever modules are640 reloaded. Functions registered with the C<$startup> hook get a true641 argument if this is a reload, and false if this is a true startup642 643 =item $shutdown644 645 Called before BarnOwl shutdown646 647 =item $receiveMessage648 649 Called with a C<BarnOwl::Message> object every time BarnOwl appends a650 new message to its message list651 652 =item $mainLoop653 654 Called on B<every pass> through the C<BarnOwl> main loop. Any655 functions with this hook should be very cheap, as they are very656 frequently by the runtime.657 658 =item $getBuddyList659 660 Called to display buddy lists for all protocol handlers. The result661 from every function registered with this hook will be appended and662 displayed in a popup window, with zephyr formatting parsed.663 664 =back665 666 =cut667 436 668 437 use Exporter; … … 699 468 } 700 469 } 701 702 # These are the internal hooks called by the barnowl C code, which703 # take care of dispatching to the appropriate perl hooks, and deal704 # with compatibility by calling the old, fixed-name hooks.705 470 706 471 sub _startup { -
variable.c
rd536e72 rad15610 455 455 456 456 int owl_variable_dict_setup(owl_vardict *vd) { 457 owl_variable * var, *cur;457 owl_variable *cur; 458 458 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++) { 462 460 switch (cur->type) { 463 461 case OWL_VARIABLE_OTHER: … … 522 520 void owl_variable_dict_add_variable(owl_vardict * vardict, 523 521 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); 525 523 } 526 524 … … 534 532 } 535 533 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 543 534 void 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); 561 545 } 562 546 563 547 void 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); 582 560 } 583 561 584 562 void 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); 603 575 } 604 576 … … 618 590 void owl_variable_free(owl_variable *v) { 619 591 if (v->free_fn) v->free_fn(v); 620 owl_free(v);621 592 } 622 593 … … 716 687 } 717 688 718 owl_variable *owl_variable_get_var(owl_vardict *d, char *name, int require_type) { 689 /* returns a reference */ 690 void *owl_variable_get(owl_vardict *d, char *name, int require_type) { 719 691 owl_variable *v; 720 692 if (!name) return(NULL); 721 693 v = owl_dict_find_element(d, name); 722 694 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;730 695 return v->get_fn(v); 731 696 } -
zephyr.c
r1151f0b r6201646 601 601 } 602 602 } 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); 610 607 owl_function_adminmsg("", buff); 611 608 } else { 612 char buff[ BUFFLEN];609 char buff[1024]; 613 610 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); 625 613 owl_function_adminmsg("", buff); 626 614 owl_log_outgoing_zephyr_error(tmp, buff);
Note: See TracChangeset
for help on using the changeset viewer.
