/[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 133 by dpavlin, Mon May 8 21:33:37 2006 UTC revision 134 by dpavlin, Tue May 9 12:21:26 2006 UTC
# Line 1700  sub links { Line 1700  sub links {
1700          return $self->{inform}->{links};          return $self->{inform}->{links};
1701  }  }
1702    
1703    =head2 master
1704    
1705    Set actions on Hyper Estraier node master (C<estmaster> process)
1706    
1707      $node->master(
1708            action => 'sync'
1709      );
1710    
1711    All available actions are documented in
1712    L<http://hyperestraier.sourceforge.net/nguide-en.html#protocol>
1713    
1714    =cut
1715    
1716    my $estmaster_rest = {
1717            shutdown => {
1718                    status => 202,
1719            },
1720            sync => {
1721                    status => 202,
1722            },
1723            backup => {
1724                    status => 202,
1725            },
1726            userlist => {
1727                    status => 200,
1728                    returns => qw/name passwd flags fname misc/,
1729            },
1730            useradd => {
1731                    required => qw/name passwd flags/,
1732                    optional => qw/fname misc/,
1733                    status => 200,
1734            },
1735            userdel => {
1736                    required => qw/name/,
1737                    status => 200,
1738            },
1739            nodelist => {
1740                    status => 200,
1741                    returns => qw/name label doc_num word_num size/,
1742            },
1743            nodeadd => {
1744                    required => qw/name/,
1745                    optional => qw/label/,
1746                    status => 200,
1747            },
1748            nodedel => {
1749                    required => qw/name/,
1750                    status => 200,
1751            },
1752            nodeclr => {
1753                    required => qw/name/,
1754                    status => 200,
1755            },
1756            nodertt => {
1757                    status => 200,  
1758            },
1759    };
1760    
1761    sub master {
1762            my $self = shift;
1763    
1764            my $args = {@_};
1765    
1766            # have action?
1767            my $action = $args->{action} || croak "need action, available: ",
1768                    join(", ",keys %{ $estmaster_rest });
1769    
1770            # check if action is valid
1771            my $rest = $estmaster_rest->{$action};
1772            croak "action '$action' is not supported, available actions: ",
1773                    join(", ",keys %{ $estmaster_rest }) unless ($rest);
1774    
1775            croak "BUG: action '$action' needs return status" unless ($rest->{status});
1776    
1777            my @args;
1778    
1779            if ($rest->{required} || $rest->{optional}) {
1780    
1781                    map {
1782                            croak "need parametar '$_' for action '$action'" unless ($args->{$_});
1783                            push @args, $_ . '=' . uri_escape( $args->{$_} );
1784                    } ( keys %{ $rest->{required} } );
1785    
1786                    map {
1787                            push @args, $_ . '=' . uri_escape( $args->{$_} ) if ($args->{$_});
1788                    } ( keys %{ $rest->{optional} } );
1789    
1790            }
1791    
1792            my $uri = new URI( $self->{url} );
1793    
1794            my $resbody;
1795    
1796            if ($self->shuttle_url(
1797                    'http://' . $uri->host_port . '/master?action=' . $action ,
1798                    'application/x-www-form-urlencoded',
1799                    join('&', @args),
1800                    \$resbody,
1801                    1,
1802            ) == $rest->{status}) {
1803                    return 0E0 unless ($rest->{returns});
1804    
1805                    if (wantarray) {
1806    
1807                            my @results;
1808    
1809                            foreach my $line ( split(/[\r\n]/,$resbody) ) {
1810                                    my @e = split(/\t/, $line);
1811                                    my $row;
1812                                    map { $row->{$_} = shift @e; } @{ $rest->{returns} };
1813                                    push @results, $row;
1814                            }
1815    
1816                            return @results;
1817                    } else {
1818    
1819                            carp "calling master action '$action', but not expecting array back, returning whole body";
1820                            return $resbody;
1821                    }
1822            }
1823    }
1824    
1825  =head1 PRIVATE METHODS  =head1 PRIVATE METHODS
1826    

Legend:
Removed from v.133  
changed lines
  Added in v.134

  ViewVC Help
Powered by ViewVC 1.1.26