Changes in / [16c6cca:a827529]
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
message.c
r3a7cf49 r635881c 330 330 res=owl_message_get_attribute_value(m, "isprivate"); 331 331 if (!res) return(0); 332 return (1);332 return !strcmp(res, "true"); 333 333 } 334 334 -
perl/lib/BarnOwl/ModuleLoader.pm
rbe98ba5 rb0c8011 9 9 10 10 sub load_all { 11 PAR::reload_libs(); 11 12 my %modules; 12 13 my @modules; … … 36 37 for my $class (keys %modules) { 37 38 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 $!; 39 40 BarnOwl::error("Unable to load module $class: $@") if $@; 40 41 } … … 47 48 BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, { 48 49 summary => 'Reload all modules', 49 usage => 'reload ',50 usage => 'reload-modules', 50 51 description => q{Reloads all modules located in ~/.owl/modules and the system modules directory} 51 52 }); -
perl/modules/IRC/lib/BarnOwl/Message/IRC.pm
r0e52069 r2fb58e4 56 56 sub long_sender {shift->{from} || ""}; 57 57 58 sub login_extra { shift->channel; } 59 58 60 59 61 1; -
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r6286f26 rb0c8011 30 30 31 31 sub 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 36 59 register_commands(); 37 60 register_handlers(); … … 61 84 62 85 sub 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 }); 64 98 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); 68 105 } 69 106 … … 94 131 "ssl" => \$ssl, 95 132 "password=s" => \$password, 96 " port=i" => \$port,133 "nick=s" => \$nick, 97 134 ); 98 135 $host = shift @ARGV or die("Usage: $cmd HOST\n"); 99 136 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 } 102 142 } 103 $port ||=6667;143 $port = shift @ARGV || 6667; 104 144 $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"); 105 149 } 106 150 … … 148 192 my $msg = BarnOwl::Message->new( 149 193 type => 'IRC', 150 direction => 'out',194 direction => is_private($to) ? 'out' : 'in', 151 195 server => $conn->server, 152 196 network => $conn->alias, … … 169 213 } 170 214 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 171 222 sub cmd_nick { 172 223 my $cmd = shift; 173 224 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"); 175 226 $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); 176 241 } 177 242 … … 196 261 } 197 262 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 198 275 sub get_connection_by_alias { 199 276 my $key = shift; -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r0e52069 r9e02bb7 16 16 17 17 use base qw(Net::IRC::Connection Class::Accessor Exporter); 18 __PACKAGE__->mk_accessors(qw(alias channels ));18 __PACKAGE__->mk_accessors(qw(alias channels motd)); 19 19 our @EXPORT_OK = qw(&is_private); 20 20 … … 29 29 $self->alias($alias); 30 30 $self->channels([]); 31 $self->motd(""); 31 32 bless($self, $class); 32 33 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'], 35 37 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 }); 38 52 39 53 return $self; … … 49 63 } 50 64 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( 65 sub new_message { 66 my $self = shift; 67 my $evt = shift; 68 return BarnOwl::Message->new( 57 69 type => 'IRC', 58 direction => 'in',59 70 server => $self->server, 60 71 network => $self->alias, 61 recipient => $recipient,62 body => $body,63 72 sender => $evt->nick, 64 73 hostname => $evt->host, 65 74 from => $evt->from, 75 @_ 76 ); 77 } 78 79 sub 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, 66 90 $evt->type eq 'notice' ? 67 91 (notice => 'true') : (), … … 70 94 replycmd => 'irc-msg ' . 71 95 (is_private($recipient) ? $evt->nick : $recipient), 72 replysendercmd => 'irc-msg ' . $evt->nick ,96 replysendercmd => 'irc-msg ' . $evt->nick 73 97 ); 98 74 99 BarnOwl::queue_message($msg); 75 100 } … … 80 105 } 81 106 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 82 166 sub on_event { 83 167 my ($self, $evt) = @_; 84 168 BarnOwl::admin_message("IRC", 85 " Unhandled IRC event of type " . $evt->type . ":\n"169 "[" . $self->alias . "] Unhandled IRC event of type " . $evt->type . ":\n" 86 170 . strip_irc_formatting(join("\n", $evt->args))) 87 171 if BarnOwl::getvar('irc:spew') eq 'on'; 88 172 } 89 173 174 90 175 ################################################################################ 91 176 ########################### Utilities/Helpers ################################## … … 94 179 sub strip_irc_formatting { 95 180 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; 97 187 my $out; 98 188 while(@pieces) { … … 109 199 } 110 200 201 sub cdr { 202 shift; 203 return @_; 204 } 205 111 206 1; -
perlglue.xs
rb363d83 r65fea01 13 13 #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) 14 14 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 32 MODULE = BarnOwl PACKAGE = BarnOwl 16 33 17 34 char * -
perlwrap.pm
r18fb3d4f rb0c8011 14 14 15 15 package 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 16 127 17 128 BEGIN { … … 46 157 return &BarnOwl::Hooks::_receive_msg($m); 47 158 } 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 48 179 49 180 # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo"); … … 63 194 64 195 ARGS should be a hashref containing any or all of C<summary>, 65 C<usage>, or C<description> keys. 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 66 214 67 215 =cut … … 410 558 package BarnOwl::Hook; 411 559 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 412 574 sub new { 413 575 my $class = shift; 414 576 return bless [], $class; 415 577 } 578 579 =head2 run [ARGS] 580 581 Calls each of the functions registered with this hook with the given 582 arguments. 583 584 =cut 416 585 417 586 sub run { … … 420 589 return map {$_->(@args)} @$self; 421 590 } 591 592 =head2 add SUBREF 593 594 Registers a given subroutine with this hook 595 596 =cut 422 597 423 598 sub add { … … 428 603 } 429 604 605 =head2 clear 606 607 Remove all functions registered with this hook. 608 609 =cut 610 430 611 sub clear { 431 612 my $self = shift; … … 434 615 435 616 package 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 436 667 437 668 use Exporter; … … 468 699 } 469 700 } 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. 470 705 471 706 sub _startup { -
variable.c
rad15610 rd536e72 455 455 456 456 int owl_variable_dict_setup(owl_vardict *vd) { 457 owl_variable * cur;457 owl_variable *var, *cur; 458 458 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)); 460 462 switch (cur->type) { 461 463 case OWL_VARIABLE_OTHER: … … 520 522 void owl_variable_dict_add_variable(owl_vardict * vardict, 521 523 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); 523 525 } 524 526 … … 532 534 } 533 535 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 534 543 void 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 } 545 561 } 546 562 547 563 void 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 } 560 582 } 561 583 562 584 void 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 } 575 603 } 576 604 … … 590 618 void owl_variable_free(owl_variable *v) { 591 619 if (v->free_fn) v->free_fn(v); 620 owl_free(v); 592 621 } 593 622 … … 687 716 } 688 717 689 /* returns a reference */ 690 void *owl_variable_get(owl_vardict *d, char *name, int require_type) { 718 owl_variable *owl_variable_get_var(owl_vardict *d, char *name, int require_type) { 691 719 owl_variable *v; 692 720 if (!name) return(NULL); 693 721 v = owl_dict_find_element(d, name); 694 722 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; 695 730 return v->get_fn(v); 696 731 } -
zephyr.c
r6201646 r1151f0b 601 601 } 602 602 } 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); 607 610 owl_function_adminmsg("", buff); 608 611 } else { 609 char buff[ 1024];612 char buff[BUFFLEN]; 610 613 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 } 613 625 owl_function_adminmsg("", buff); 614 626 owl_log_outgoing_zephyr_error(tmp, buff);
Note: See TracChangeset
for help on using the changeset viewer.