?

Log in

No account? Create an account
DJabberd config file - brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

DJabberd config file [May. 6th, 2006|09:28 pm]
Brad Fitzpatrick
[Tags|, ]

Ahhh yeah, Artur and I just added Apache-style conf to DJabberd so you don't have to write a Perl file with a bunch of server/vhost/plugin constructors by hand. Now it looks like:

$ cat djabberd.conf
OldSSL  enable

# defaults:
ClientPort 5222
ServerPort 5269

#PerlModule DJabberd::SixApart

<VHost jabber.bradfitz.com>
  S2S enable
  RequireSSL no

  <Plugin DJabberd::Authen::AllowedUsers>
     Policy accept
     AllowedUsers brad crucially test
  </Plugin>

  <Plugin DJabberd::Authen::StaticPassword>
      Password password
  </Plugin>

  <Plugin DJabberd::PresenceChecker::Local />
  <Plugin DJabberd::Delivery::Local />
  <Plugin DJabberd::Delivery::S2S   />

  <Plugin DJabberd::RosterStorage::SQLite>
     Database roster.sqlite
  </Plugin>

</VHost>

$ ./djabberd --conf=djabberd.conf
Next step is removing the need for the must-have plugins and making them automatic. That means adding plugin-declared before/after dependencies so DJabberd can do the hook ordering. Should be easy. Then DJabberd should be getting ready for usability by the masses. :-)

Update: the as_bool function was fun:
sub as_bool {
    my $val = shift;
    return 1 if $val =~ /^1|yes|true|t|on|enabled?$/;
    return 0 if $val =~ /^0|no|false|f|off|disabled?$/;
    die "Can't determine booleanness of '$val'\n";
}
LinkReply

Comments:
[User Picture]From: gaal
2006-05-07 04:37 am (UTC)
You're missing a /i modifier in these regexps. But maybe use YAML instead of doing your own parsing? That Apache conf format always looked a little weird to me.
(Reply) (Thread)
[User Picture]From: brad
2006-05-07 04:54 am (UTC)
YAML's for YAML nerds only. It used to be cool but now it's overbloated and overcomplex and even regular programers hate it, not to mention users/sysadmins.

Also, sysadmins know the Apache format. Therefore, it wins.

Q.E.D.
(Reply) (Parent) (Thread)
[User Picture]From: gaal
2006-05-07 05:13 am (UTC)
Hey, whatever works.

When was it not bloated, in your opinion?
(Reply) (Parent) (Thread)
[User Picture]From: brad
2006-05-07 05:38 am (UTC)
When I first learned YAML (pre-Python/Ruby committee standardization as I'm told?) it was dictionaries and lists, and you could fit the entire syntax (and parser) in your head. Now look at it:

http://yaml.org/spec/current.html

Look how tiny your vertical scroll handle gets! Read some of those examples! OMFGZ.

I'd rather use JSON, but no sysadmins know that either.
(Reply) (Parent) (Thread)
From: evan
2006-05-07 06:29 am (UTC)
I actually was about to write the same comment to Brad ("why not YAML?") and then I saw his response and realized that is my response as well.
I guess it could be hidden by a library, but yeah: every time I've wanted to use YAML I've sat down, tried to start reading about how it works, and decided it was way too complicated for what I needed.

FWIW, I think the Apache format is kinda lame too: why use angle brackets if you're not gonna be XML? Same thing (nesting) could be accomplished with curlies and it's less typing.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2006-05-07 12:21 pm (UTC)
Familiarity to sysadmins.

How much do /I/ hate it when I go to configure some program and the config file is in Python (say, Xen, or GNU Mailman) and I know language $Foo better. Apache-style is common ground that everybody has warm fuzzies about.
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: brad
2006-05-07 04:55 am (UTC)
Committed revision 201.
(Reply) (Parent) (Thread)
[User Picture]From: ckd
2006-05-07 05:05 am (UTC)
Yeah. Also, I'd probably rewrite those regexps a bit:

/^1|y(es)?|t(rue)?|on|enabled?$/i;
/^0|n(o)?|f(alse)?|off|disabled?$/i;

(Yes, I realize that "n(o)?" doesn't need the paren grouping. Take it out if it offends you. Readability beats efficiency for something that isn't getting run in a tight loop.)
(Reply) (Parent) (Thread)
[User Picture]From: brad
2006-05-07 05:08 am (UTC)
Readability is subjective. :-)
(Reply) (Parent) (Thread)
[User Picture]From: ckd
2006-05-07 05:37 am (UTC)
Says the guy who's writing this in Perl. (It could be worse; it could be APL. Or sendmail.cf.)
(Reply) (Parent) (Thread)
[User Picture]From: brad
2006-05-07 05:40 am (UTC)
I've sure you've heard it, but: "You can write clean and ugly code in any language." I'm not going to say my Perl is the most beautiful it could be, but it's pretty sexy.... a lot more than what people think of when they hear Perl, which is often sysadmin-Perl. (although I'd argue that syadmins prefer sysadmin perl to my Perl....)

This thread goes nowhere productive. :-)
(Reply) (Parent) (Thread)
[User Picture]From: grumpy_sysadmin
2006-05-07 05:44 am (UTC)
Um, and it was for readability that you dumped a lot of punctuation in there instead of having separate slots for each item?
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: grumpy_sysadmin
2006-05-07 05:55 am (UTC)
Yeah, well. You're still right.

I guess I'm kinda surprised there isn't a "parse Apache config files" Perl module on CPAN already.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2006-05-07 06:02 am (UTC)
There are several.

We looked into it but it didn't pay off for the extremely limited subset we needed. If we need more later, we could go that route. But as is, it's almost no code, and 7/8ths of it is integration with DJabberd, not parsing.
(Reply) (Parent) (Thread)
[User Picture]From: grumpy_sysadmin
2006-05-07 05:43 am (UTC)
I think I'd say "booleanity" before I said "booleanness"...
(Reply) (Thread)
[User Picture]From: gaal
2006-05-07 03:28 pm (UTC)
ObPerl6 :via

That function was fun because it was in declarative, guardy style. In Haskell, where pattern matching means something else than it does in Perl, you have that in sweet, sweet syntax. In Perl 6, the syntax is less sweet in the general case (more punctuation), but here because of the regular expression it's quite nice:

multi sub as_bool (Str $val where rx:i/^ 1 | yes | etc/) { 1 }
multi sub as_bool (Str $val where rx:i/^0 | no | etc/) { 0 }
multi sub as_bool (Str $val) { !!! }

The last variant is actually optional: you'll get an error anywhere when multidispatch fails, and it should contain the argument.
(Reply) (Thread)
[User Picture]From: brad
2006-05-07 11:49 pm (UTC)
So cool.
(Reply) (Parent) (Thread)