Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

removing blocking network code
Dear POEts,

I used to have a non-POE module that worked as an authentication server
saslauthd. A while ago I converted it to POE, but there're still traces
from the old days that I'd like to get rid of. As I'm not very much
familiar with creating non-blocking servers that process binary data,
I hope I can get some help here.

Below is the code. _start is a state handler that received the network
handle as it's argument. Ideally I'd like to see state handlers that
read SASL strings and write response back to the client. I've done that
when working with simple line-oriented protocols, but dealing with
binary data confuses me.

Thanks in advance for any advice!

<ccode>
sub _start {
my ($kernel, $heap) = @_[KERNEL, HEAP];
my $handle = $_[ARG0];

$handle->blocking(1); # XXX fix later
my $username = _sasl_string($handle);
my $password = _sasl_string($handle);
my $service = _sasl_string($handle);
my $realm = _sasl_string($handle);

my $domain = $realm || 'krot.org';
if (!$realm and $username =~ /[@%]/) {
($username, $domain) = split /[@%]/, $username, 2;
}

my $user = krot_auth("$username\@$domain", $password, $service);
return defined $user ? _sasl_allow($handle) : _sasl_deny($handle);
}

sub _sasl_string {
my $sock = shift;
my $buf;
$sock->read($buf, 2);
my $size = unpack('n', $buf);
$sock->read($buf, $size);
return unpack("A$size", $buf);
}

sub _sasl_allow {
my $sock = shift;
$sock->print(pack('nA3', 2, "OK\0"));
$sock->close();
}

sub _sasl_deny {
my $sock = shift;
$sock->print(pack('nA3', 2, "NO\0"));
$sock->close();
}
</code>

--
#!/usr/bin/perl -w
print(&{sub{eval(qq(q(@_)))}}((join(''=>map{ord=~m(1(06|12))?uc:lc}($[=>
map{chr}(97..122))[map{int}grep{length}split(/(\d\d)/,'102119200114152'.
 q(008051816051812080103110518))]))=~m(^(
Just)(.+)(Perl)(.+)(?#:-)$)),$/)


Report this thread to moderator Post Follow-up to this message
Old Post
Kirill Miazine
04-13-08 12:53 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL POE archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:48 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.