/[cwmp]/google/trunk/lib/CWMP/Session.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/trunk/lib/CWMP/Session.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 48 by dpavlin, Tue Jun 19 20:02:36 2007 UTC revision 49 by dpavlin, Tue Jun 19 20:46:51 2007 UTC
# Line 9  __PACKAGE__->mk_accessors( qw/ Line 9  __PACKAGE__->mk_accessors( qw/
9  debug  debug
10  port  port
11  sock  sock
12    state
13  / );  / );
14    
15  use IO::Socket::INET;  use IO::Socket::INET;
# Line 85  sub process_request { Line 86  sub process_request {
86          $sock->blocking( 1 );          $sock->blocking( 1 );
87    
88          ### read the first line of response          ### read the first line of response
89          my $line = $sock->getline || return $self->error(400, "No Data");          my $line = $sock->getline;
90            return $self->error(400, "No Data") unless ( defined $line );
91    
92          $line =~ s/[\r\n]+$//;          $line =~ s/[\r\n]+$//;
93          if ($line !~ /^ (\w+) \ + (\S+) \ + (HTTP\/1.\d) $ /x) {          if ($line !~ /^ (\w+) \ + (\S+) \ + (HTTP\/1.\d) $ /x) {
94                    warn "ERROR: $line\n";
95                  return $self->error(400, "Bad request");                  return $self->error(400, "Bad request");
96          }          }
97          my ($method, $req, $protocol) = ($1, $2, $3);          my ($method, $req, $protocol) = ($1, $2, $3);
98          warn "<<<< ",join(" ", time, $method, $req)."\n";          warn "<<<< ", $sock->peerhost, " - - [" . localtime() . "] \"$method $req $protocol\"\n";
99    
100          ### read in other headers          ### read in other headers
101          $self->read_headers || return $self->error(400, "Strange headers");          $self->read_headers || return $self->error(400, "Strange headers");
# Line 131  sub process_request { Line 134  sub process_request {
134                          warn "--- $len bytes: --=>||$buff||<=--\n";                          warn "--- $len bytes: --=>||$buff||<=--\n";
135    
136                  } while ( $len > 0 );                  } while ( $len > 0 );
137                    my $sep = $sock->getline;
138                    die "expected separator, not ", dump( $sep ) if ( $sep !~ m/^[\n\r]+$/ );
139    
140          } else {          } else {
141                  die "right now, we support only Transfer-Encoding: chunked";                  die "right now, we support only Transfer-Encoding: chunked";
142          }          }
143    
144          warn "handler got ", length($chunk), " bytes\n" if $self->debug;          my $size = length( $chunk );
145    
146          warn "<<< " . localtime() . " " . $sock->peerhost . "\n";          warn "<<< " . $sock->peerhost . " [" . localtime() . "] request $size bytes\n";
   
         die "not SOAP request" unless defined ( $self->header('SOAPAction') );  
147    
148          my $state;          my $state;
149    
150          if ( $chunk ) {          if ( $size > 0 ) {
151                  warn "## request chunk: ",length($chunk)," bytes\n$chunk\n" if $self->debug;  
152                    die "no SOAPAction header in ",dump($chunk) unless defined ( $self->header('SOAPAction') );
153    
154    
155                    if ( $chunk ) {
156                            warn "## request chunk: ",length($chunk)," bytes\n$chunk\n" if $self->debug;
157    
158                            $state = CWMP::Request->parse( $chunk );
159    
160                  $state = CWMP::Request->parse( $chunk );                          warn "acquired state = ", dump( $state ), "\n";
161    
162                            $self->state( $state );
163    
164                    } else {
165                            warn "empty request\n";
166                    }
167    
                 warn "acquired state = ", dump( $state ), "\n";  
           
168          } else {          } else {
169                  warn "empty request\n";                  $state = $self->state;
170                    warn "last request state = ", dump( $state ), "\n";
171          }          }
172    
   
173          my $response = CWMP::Response->new({ debug => $self->debug });          my $response = CWMP::Response->new({ debug => $self->debug });
174    
175          $sock->send(join("\r\n",          $sock->send(join("\r\n",
176                  'HTTP/1.1 200 OK',                  'HTTP/1.1 200 OK',
177                  'Content-Type: text/xml; charset="utf-8"',                  'Content-Type: text/xml; charset="utf-8"',
178                  'Server: AcmeCWMP/42',                  'Server: AcmeCWMP/42',
179                  'SOAPServer: AcmeCWMP/42',                  'SOAPServer: AcmeCWMP/42'
180          ));          ));
181    
182          $sock->send( "Set-Cookie: ID=" . $state->{ID} . "; path=/\r\n" ) if ( $state->{ID} );          $sock->send( "Set-Cookie: ID=" . $state->{ID} . "; path=/\r\n" ) if ( $state->{ID} );

Legend:
Removed from v.48  
changed lines
  Added in v.49

  ViewVC Help
Powered by ViewVC 1.1.26