8 |
use Carp qw/confess/; |
use Carp qw/confess/; |
9 |
use Getopt::Long; |
use Getopt::Long; |
10 |
use File::Slurp; |
use File::Slurp; |
11 |
|
use JSON; |
12 |
|
|
13 |
use IO::Socket::INET; |
use IO::Socket::INET; |
14 |
|
|
82 |
|
|
83 |
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { |
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { |
84 |
my $method = $1; |
my $method = $1; |
85 |
|
my $param; |
86 |
|
if ( $method =~ s{\?(.+)}{} ) { |
87 |
|
foreach my $p ( split(/[&;]/, $1) ) { |
88 |
|
my ($n,$v) = split(/=/, $p, 2); |
89 |
|
$param->{$n} = $v; |
90 |
|
} |
91 |
|
warn "<< param: ",dump( $param ); |
92 |
|
} |
93 |
if ( my $path = static( $client,$1 ) ) { |
if ( my $path = static( $client,$1 ) ) { |
94 |
warn ">> $path"; |
warn ">> $path"; |
95 |
} elsif ( $method =~ m{/scan} ) { |
} elsif ( $method =~ m{/scan} ) { |
|
print $client "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n"; |
|
96 |
my $tags = scan_for_tags(); |
my $tags = scan_for_tags(); |
97 |
print $client "tags: ",dump($tags); |
my $json = {}; |
98 |
my $json; |
map { |
99 |
map { $json->{$_} = decode_tag($_) } keys %$tags; |
my $d = decode_tag($_); |
100 |
print $client "decoded: ",dump( $json ); |
$d->{sid} = $_; |
101 |
|
push @{ $json->{tags} }, $d; |
102 |
|
} keys %$tags; |
103 |
|
print $client "HTTP/1.0 200 OK\r\nContent-Type: application/x-javascript\r\n\r\n", |
104 |
|
$param->{callback}, "(", to_json($json), ")\r\n"; |
105 |
} else { |
} else { |
106 |
print $client "HTTP/1.0 404 Unkown method\r\n"; |
print $client "HTTP/1.0 404 Unkown method\r\n"; |
107 |
} |
} |
154 |
'stopbits=i' => \$stopbits, |
'stopbits=i' => \$stopbits, |
155 |
'handshake=s' => \$handshake, |
'handshake=s' => \$handshake, |
156 |
'meteor=s' => \$meteor_server, |
'meteor=s' => \$meteor_server, |
157 |
|
'http-server!' => \$http_server, |
158 |
) or die $!; |
) or die $!; |
159 |
|
|
160 |
my $verbose = $debug > 0 ? $debug-- : 0; |
my $verbose = $debug > 0 ? $debug-- : 0; |