Commit efbcc944 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
9780596000950
\ No newline at end of file
#!/bin/env perl
#!d:\perl\bin\perl.exe
# -- Copyright (C) 2001 Paul Kulchenko --
use strict;
use SOAP::Lite;
use File::Path;
print "\n\nWelcome to CodeShare! The Open source code sharing network!";
print "\nCopyright(c) 2001, James Snell, Paul Kulchenko, Doug Tidwell\n\n";
@ARGV or die "Usage: $0 CodeShareServer [commands...] [-dump [filename]] \n";
my $proxy = shift;
my $uri = 'http://namespaces.soaplite.com/CodeShare/Owner';
my $soap = SOAP::Lite->proxy($proxy)->uri($uri)->on_fault(sub{});
my($dump, $file) = @ARGV > 0 && @ARGV[-1] eq '-dump' ? splice(@ARGV, -1, 1) :
@ARGV > 1 && @ARGV[-2] eq '-dump' ? splice(@ARGV, -2, 2) :
(undef, undef);
if ($dump) {
print STDERR "Wiredumps are logged in '$file'\n" if $file;
$file ||= '&STDOUT'; # STDOUT by default
open(F, ">>$file") or die "$file: $!\n"; # open in append mode
select((select(F), $|=1)[0]); # select non-buffered output
$soap->on_debug(sub{print F @_}); # debug goes there
eval "END { close F }"; # close handle when we are done
}
print STDERR "Usage: { search | info | get | list | quit | help } [parameters...]\n> ";
while (defined($_ = shift || <>)) {
next unless /\w/;
my($method, $modifier, $parameters) = m!^\s*(\w+)(?:\s*/(\w*)\s)?\s*(.*)!;
last if $method =~ /^q(?:uit)?$/i;
help(), next if $method =~ /^h(?:elp)?$/i;
my $res = eval "\$soap->$method('$parameters', '$modifier')";
# check for errors
$@ and print(STDERR join "\n", $@, ''), next;
defined($res) && $res->fault and print(STDERR join "\n", $res->faultstring, ''), next;
!$soap->transport->is_success and print(STDERR join "\n", $soap->transport->status, ''), next;
# check for result
my @result = @{$res->result} or print(STDERR "No matches\n"), next;
foreach (@result) {
print(STDERR "$_->{type}: @{[join ', ', $_->{Title} || (), $_->{path} || ()]}\n");
if ($method eq 'get') {
if ($_->{type} eq 'directory') { File::Path::mkpath($_->{path}) }
if ($_->{type} eq 'file') {
open(F, '>'. $_->{path}) or warn "$_->{path}: $!\n";
print F $_->{file};
close(F) or warn "$_->{path}: $!\n";
}
} elsif ($method eq 'info') {
foreach my $key (grep {$_ !~ /^(?:type|path)/} keys %$_) {
print " $key: $_->{$key}\n";
}
}
}
} continue {
print STDERR "\n> ";
}
sub help {
print "Short help about search, info, get and list commands is here\n";
}
@echo off
cls
title Codeshare Command Line Client
perl cs_client.pl %1
# ======================================================================
# Copyright (C) 2001 Paul Kulchenko (paulclinger@yahoo.com)
# ======================================================================
package CodeShare::Owner;
use strict;
my $index; # parsed index file
my $DC_NS = "http://purl.org/dc/elements/1.1/"; # Dublin Code namespace
my @ELEMENTS = qw(Title Creator Date Subject Description);
sub init {
my($class, $root) = @_;
open(F, $root) or die "$root: $!\n";
$index = SOAP::Custom::XML::Deserializer->deserialize(join '', <F>)->root;
close(F) or die "$root: $!\n";
}
sub traverse {
my($self, %params) = @_;
my $start = $params{start};
my $type = $start->SOAP::Data::name; # file|project|directory
my $location = ref $start->location ? $start->location->value : '';
# path to current structure. Empty for projects
my $path = $type eq 'directory' ||
$type eq 'file' ? join('/', $params{path} || (), $location) : '';
my $prefix = $type eq 'project' ? $location : $params{prefix} || '';
my $fullpath = join '/', $prefix, $path; # full path. Used to GET files
my $where = $params{where};
my $matched =
$params{get} && $params{matched} ||
$params{what} &&
# check only subelements in Dublin Core namespace
$start->$where() =~ /$params{what}/ && $start->$where()->uri eq $DC_NS;
return
# current element
($matched
? +{ type => $type,
path => $path,
($params{get} ? (fullpath => $fullpath) : ()),
map { ref $start->$_() ? ($_ => $start->$_()->value) : ()
} @ELEMENTS
}
: ()
),
# and everything below
map { $self->traverse(start => $_, where => $where, what => $params{what},
path => $path, prefix => $prefix,
get => ($params{get} || 0), matched => $matched) }
$start->project, $start->directory, ($type eq 'file' ? () : $start->file)
;
}
sub list {
print("\nHandling a list request...");
my($self, $what) = @_;
[ map { my $e = $_; +{ map {$_ => $e->{$_}} qw(type path Title file fullpath) } }
$self->traverse(start => $index, where => 'Title', what => $what, get => 1)
];
}
sub get {
print("\nHandling a get request...");
my $results = shift->list(@_);
[ map { $_->{type} eq 'file' && open(F, delete $_->{fullpath})
? ($_->{file} = join('', <F>), close F) : (); $_ }
@$results
];
}
sub search { # same as info(), but returns only 'type', 'path' and 'Title'
print("\nHandling a search request...");
my $results = shift->info(@_);
[ map { my $e = $_; +{ map {$_ => $e->{$_}} qw(type path Title) } }
@$results
];
}
sub info {
print("\nHandling an info request...");
my($self, $what, $where) = @_;
[ $self->traverse(start => $index,
where => $where || 'Title', what => $what || '.')
];
}
1;
#!/usr/bin/env perl
# -- Copyright (C) 2001 Paul Kulchenko --
use strict;
use SOAP::Transport::HTTP;
use CodeShare::Owner;
CodeShare::Owner->init('../Projects/index.xml');
my $daemon = SOAP::Transport::HTTP::CGI
-> dispatch_to('CodeShare::Owner::(?:get|search|info|list)')
-> handle;
;
\ No newline at end of file
#!perl -w
#!d:\perl\bin\perl.exe
# -- Copyright (C) 2001 Paul Kulchenko --
use SOAP::Transport::HTTP;
use CodeShare::Owner;
print "\n\nWelcome to CodeShare! The Open source code sharing network!";
print "\nCopyright(c) 2001, James Snell, Paul Kulchenko, Doug Tidwell\n\n";
CodeShare::Owner->init(shift or die "Usage: $0 <path/to/index.xml>\n");
my $daemon = SOAP::Transport::HTTP::Daemon
-> new (LocalPort => 8080)
-> dispatch_to('CodeShare::Owner::(?:get|search|info|list)')
;
print "CodeShare Owner Server started at ", $daemon->url, "\n";
print "Waiting for a request...\n";
$daemon->handle;
To run the CodeShare Owner server as a standalone HTTP daemon, use the startServer.bat
To run the CodeShare Owner server as a CGI script, use cs_server.cgi
@echo off
start "CodeShare Owner Server" perl cs_server.pl ..\Projects\index.xml
<codeShare xmlns:dc="http://purl.org/dc/elements/1.1/">
<project location="source">
<dc:Title>CodeShare Project</dc:Title>
<dc:Creator>Paul Kulchenko, et al</dc:Creator>
<dc:Date>2001-07-20</dc:Date>
<dc:Subject>Open Source Code Share Distributed</dc:Subject>
<dc:Description>Code Share project that allows share the source code</dc:Description>
<file location="cs_server.pl">
<dc:Title>Server module</dc:Title>
</file>
<file location="cs_client.pl">
<dc:Title>Client module</dc:Title>
</file>
<directory location="CodeShare">
<dc:Title>Modules</dc:Title>
<file location="Owner.pm">
<dc:Title>Main module</dc:Title>
</file>
</directory>
</project>
</codeShare>
Microsoft Visual Studio Solution File, Format Version 1.00
Project("{66355F20-A65B-11D0-BFB5-00A0C91EBFA0}") = "Console Application", "Console Application.vjp", "{4006B352-3388-4E85-A9BD-E53ADE9CF883}"
EndProject
Global
GlobalSection(LocalDeployment) = postSolution
StartupProject = {4006B352-3388-4E85-A9BD-E53ADE9CF883}
EndGlobalSection
GlobalSection(BuildOrder) = postSolution
0 = {4006B352-3388-4E85-A9BD-E53ADE9CF883}
EndGlobalSection
GlobalSection(DeploymentRoot) = postSolution
EndGlobalSection
EndGlobal
import codeshare.index.*;
import java.util.List;
import java.util.Iterator;
import codeshare.service.IndexService;
/**
* @author James Snell (jasnell@us.ibm.com)
*/
public class Test {
public static void main(String[] args) throws Exception {
IndexService is = new IndexService();
Index index = is.getIndex();
/*
ProjectItem project = new ProjectItem();
project.setLocation("/Test");
project.setDublinCoreValue("Title", "CodeShare Project");
project.setDublinCoreValue("Subject", "This is the CodeShare Open Source Project");
DirectoryItem directory = new DirectoryItem();
directory.setLocation("src");
directory.setDublinCoreValue("Title", "src");
FileItem file = new FileItem();
file.setLocation("cs_client.pl");
file.setDublinCoreValue("Title", "cs_client.pl");
file.setDublinCoreValue("Subject", "CodeShare Client Perl Script");
index.addItem(project);
project.addItem(directory);
directory.addItem(file);
is.save();
*/
List list = index.search("Title", "cs_client.pl");
if (list != null) {
for (Iterator i = list.iterator(); i.hasNext();) {
ProjectItem p = (ProjectItem)i.next();
System.out.println(p);
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<codeShare xmlns:dc="http://purl.org/dc/elements/1.1/"/>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment