/[Search-Estraier]/trunk/Estraier.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 /trunk/Estraier.pm

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

revision 39 by dpavlin, Thu Jan 5 22:36:10 2006 UTC revision 40 by dpavlin, Thu Jan 5 23:00:22 2006 UTC
# Line 272  sub dump_draft { Line 272  sub dump_draft {
272    
273          $draft .= "\n";          $draft .= "\n";
274    
275          $draft .= join("\n", @{ $self->{dtexts} }) . "\n";          $draft .= join("\n", @{ $self->{dtexts} }) . "\n" if ($self->{dtexts});
276          $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n";          $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n" if ($self->{htexts});
277    
278          return $draft;          return $draft;
279  }  }
# Line 752  Specify name and password for authentica Line 752  Specify name and password for authentica
752  sub set_auth {  sub set_auth {
753          my $self = shift;          my $self = shift;
754          my ($login,$passwd) = @_;          my ($login,$passwd) = @_;
755          $self->{auth} = encode_base64( "$login:$passwd" );          my $basic_auth = encode_base64( "$login:$passwd" );
756            chomp($basic_auth);
757            $self->{auth} = $basic_auth;
758  }  }
759    
760  =head2 status  =head2 status
761    
762  Return status code of last request.  Return status code of last request.
763    
764    print $res->status;    print $node->status;
765    
766  C<-1> means connection failure.  C<-1> means connection failure.
767    
# Line 770  sub status { Line 772  sub status {
772          return $self->{status};          return $self->{status};
773  }  }
774    
775    =head2 put_doc
776    
777      $node->put_doc( $document_draft );
778    
779    =cut
780    
781    sub put_doc {
782            my $self = shift;
783            my $doc = shift || return;
784            $self->shuttle_url( $self->{url} . '/put_doc', 'text/x-estraier-draft', $doc->dump_draft, undef);
785    }
786    
787  =head2 shuttle_url  =head2 shuttle_url
788    
789  This is method which uses C<IO::Socket::INET> to communicate with Hyper Estraier node  This is method which uses C<IO::Socket::INET> to communicate with Hyper Estraier node
# Line 787  sub shuttle_url { Line 801  sub shuttle_url {
801    
802          my ($url, $content_type, $reqbody, $resbody) = @_;          my ($url, $content_type, $reqbody, $resbody) = @_;
803    
804          my $status = -1;          $self->{status} = -1;
805    
806          warn "## $url\n";          warn "## $url\n";
807    
# Line 817  sub shuttle_url { Line 831  sub shuttle_url {
831                  $headers .= "GET $query HTTP/1.0\r\n";                  $headers .= "GET $query HTTP/1.0\r\n";
832          }          }
833    
834          $headers .= "Host: $url->host:$url->port\r\n";          $headers .= "Host: " . $url->host . ":" . $url->port . "\r\n";
835          $headers .= "Connection: close\r\n";          $headers .= "Connection: close\r\n";
836          $headers .= "User-Agent: Search-Estraier/$Search::Estraier::VERSION\r\n";          $headers .= "User-Agent: Search-Estraier/$Search::Estraier::VERSION\r\n";
837          $headers .= "Content-Type $content_type\r\n";          $headers .= "Content-Type: $content_type\r\n";
838          $headers .= "Authorization: Basic $self->{auth}\r\n";          $headers .= "Authorization: Basic $self->{auth}\r\n";
839          my $len = 0;          my $len = 0;
840          {          {
# Line 842  sub shuttle_url { Line 856  sub shuttle_url {
856                  return -1;                  return -1;
857          }          }
858    
859          warn "## headers:\n$headers\n" if ($self->{debug});          warn $headers if ($self->{debug});
860    
861          print $sock $headers or          print $sock $headers or
862                  carp "can't send headers to network:\n$headers\n" and return -1;                  carp "can't send headers to network:\n$headers\n" and return -1;
863    
864          if ($reqbody) {          if ($reqbody) {
865                  warn "## request body:\n$headers\n" if ($self->{debug});                  warn $reqbody if ($self->{debug});
866                  print $sock $$reqbody or                  print $sock $reqbody or
867                          carp "can't send request body to network:\n$$reqbody\n" and return -1;                          carp "can't send request body to network:\n$$reqbody\n" and return -1;
868          }          }
869    
# Line 858  sub shuttle_url { Line 872  sub shuttle_url {
872          my ($schema, $res_status, undef) = split(/  */, $line, 3);          my ($schema, $res_status, undef) = split(/  */, $line, 3);
873          return if ($schema !~ /^HTTP/ || ! $res_status);          return if ($schema !~ /^HTTP/ || ! $res_status);
874    
875          $status = $res_status;          $self->{status} = $res_status;
876          warn "## response status: $res_status\n" if ($self->{debug});          warn "## response status: $res_status\n" if ($self->{debug});
877    
878          # skip rest of headers          # skip rest of headers
# Line 866  sub shuttle_url { Line 880  sub shuttle_url {
880          while ($line) {          while ($line) {
881                  $line = <$sock>;                  $line = <$sock>;
882                  $line =~ s/[\r\n]+$//;                  $line =~ s/[\r\n]+$//;
883                  warn "## ", $line || 'NULL', " ##\n";                  warn "## ", $line || 'NULL', " ##\n" if ($self->{debug});
884          };          };
885    
886          # read body          # read body
# Line 876  sub shuttle_url { Line 890  sub shuttle_url {
890                  $$resbody .= $buf if ($resbody);                  $$resbody .= $buf if ($resbody);
891          } while ($len);          } while ($len);
892    
893                    warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug});
         warn "## response body:\n$$resbody\n" if ($self->{debug});  
894    
895          return $status;          return $self->{status};
896  }  }
897    
898  ###  ###

Legend:
Removed from v.39  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26