This file is indexed.

/usr/share/perl5/Gedcom/WebServices.pm is in libgedcom-perl 1.19-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# Copyright 2005-2013, Paul Johnson (paul@pjcj.net)

require 5.006;

use strict;
use warnings;

our $AUTOLOAD;
our $VERSION = "1.15";

package Gedcom::WebServices;

use Gedcom 1.19;

use Apache::Constants qw( OK DECLINED );
use Apache::Request;
use Apache::URI;

sub _new
{
    my $class = shift;
    my $r     = shift;

    my $self =
    {
        r => $r ? Apache::Request->instance($r) : $r,
        @_
    };
    bless $self, $class
}

sub _set_handlers
{
    my ($handlers) = @_;

    my $handler_text;

    for my $h (@{$handlers})
    {
        # print STDERR "creating $type handler for $h\n";
        $handler_text .= _create_handler($h);
    }

    # print STDERR "handler_text is [$handler_text]\n";
    $handler_text
}

sub _create_handler
{
    my ($h) = @_;
    my $handler = "___$h";
    unless (defined &$handler)
    {
        no strict "refs";
        *$handler = sub ($$)
        {
            my ($class, $r) = @_;
            my $self;
            my $vars;
            eval
            {
                my $hn = "__$h";
                $self = $class->_new($r, handler => $hn);
                $self->$hn;
            };
            # die Template::Exception->new("Retemps.perl", $@);
            # die $@ if $@;
            $self->_error($@) if $@;
            exists $self->{_status} ? $self->{_status} : OK
        };
    }
    my $l = <<"EOE";
    \$Location{"/$h"} =
    {
        SetHandler  => "perl-script",
        PerlHandler => "Gedcom::WebServices->___$h",
    };
EOE
    $l
}

sub _parse_uri
{
    my $r      = shift;
    my $uri    = $r->parsed_uri;
    my $path   = $uri->path;
    # print STDERR "parse path $path\n";
    if ($path =~ s!^/ws/(plain|json|xml)/!!)
    {
        $r->notes(PATH => $path);
        # print STDERR "parse new path [$1]\n";
        $r->uri("/$1");
    }
    DECLINED
}

sub _error
{
    my $self = shift;
    my ($msg) = @_;
    print $msg;
}

sub _process
{
    my $self = shift;
    my ($type) = @_;

    my $path = $self->{r}->notes("path");
    # print STDERR "$type [$path]\n";

    my @params = split "/", $path;

    my $file = shift @params or die "No GEDCOM file specified\n";
    my $gedcom_file = "$Gedcom::ROOT/$file.ged";
    # print STDERR "gedcom_file $gedcom_file\n";

    my $ged = $self->{ged} = Gedcom->new(gedcom_file => $gedcom_file,
                                         read_only   => 1);
    die "Can't open gedcom file [$gedcom_file]\n" unless $ged;

    # print STDERR "params @params\n";

    my @ret;
    if (@params)
    {
        my $xref = shift @params;
        my $rec = $ged->resolve_xref($xref) || $ged->resolve_xref(uc $xref) ||
                  die "Can't get record [$xref]\n";

        if (@params)
        {
            my ($action, @parms) = @params;
            die "Invalid action [$action]\n" unless $rec->can($action);

            if ($Gedcom::Funcs{lc $action} && @parms)
            {
                # print STDERR "Calling get_value(@params)\n";
                @ret = $rec->get_value(@params);
            }
            else
            {
                # print STDERR "Calling $action(@params)\n";
                @ret = $rec->$action(@parms);
            }
        }
        else
        {
            if ($type eq "plain")
            {
                $rec->write(\*STDOUT);
            }
            elsif ($type eq "xml")
            {
                my $r = $rec->hash;
                $rec->write_xml(\*STDOUT);
            }
            elsif ($type eq "json")
            {
                my $r = $rec->hash;
                # use DDS; print STDERR Dump $r;
                print JSON->new->objToJson({ rec => $r });
            }
            else
            {
                die "unrecognised type: $type";
            }
        }
    }
    elsif (my $search = $self->{r}->param("search"))
    {
        @ret = $ged->get_individual($search);
    }
    else
    {
        die "No xref or parameters specified\n";
    }

    # print @ret . "\n";
    # use Data::Dumper; print Dumper \@ret;
    for (@ret)
    {
        if (ref)
        {
            if (defined $_->{xref})
            {
                print "/ws/$type/$file/", $_->xref, "\n";
            }
            else
            {
                if ($type eq "plain")
                {
                    $_->write(\*STDOUT, scalar @params);
                }
                elsif ($type eq "xml")
                {
                    $_->write_xml(\*STDOUT);
                }
                elsif ($type eq "json")
                {
                    my $r = $_->hash;
                    # use DDS; print STDERR Dump $r;
                    print JSON->new->objToJson($r);
                }
                else
                {
                    die "unrecognised type: $type";
                }
            }
        }
        else
        {
            my $result = @params ? $params[-1] : "result";
            if ($type eq "plain")
            {
                print "$_\n";
            }
            elsif ($type eq "xml")
            {
                $result = uc $result;
                print "<$result>$_</$result>\n";
            }
            elsif ($type eq "json")
            {
                print JSON->new->objToJson({ $result => $_ });
            }
            else
            {
                die "unrecognised type: $type";
            }
        }
    }
    print "\n" unless @ret;
}

sub __plain
{
    my $self = shift;
    $self->_process("plain");
}

sub __xml
{
    my $self = shift;
    $self->_process("xml");
}

sub __json
{
    my $self = shift;
    require JSON;
    $self->_process("json");
}

1;

__END__

=head1 NAME

Gedcom::WebServices - Basic web service routines for Gedcom.pm

Version 1.19 - 18th August 2013

=head1 SYNOPSIS

 wget -qO - http://www.example.com/ws/plain/my_family/i9/name

=head1 DESCRIPTION

This module provides web service access to a GEDCOM file in conjunction with
mod_perl.  Using it, A request for information can be made in the form of a URL
specifying the GEDCOM file to be used, which information is required and the
format in which the information is to be delivered.  This information is then
returned in the specified format.

There are currently three supported formats:

=over

=item *

plain - no markup

=item *

XML

=item *

JSON

=back

=head2 URLs

The format of the URLs used to access the web services are:

 $BASEURL/$FORMAT/$GEDCOM/$XREF/requested/information
 $BASEURL/$FORMAT/$GEDCOM?search=search_criteria

=over

=item BASEURL

The base URL to access the web services.

=item FORMAT

The format in which to return the results.

=item GEDCOM

The name of the GEDCOM file to use (the extension .ged is assumed).

=item XREF

The xref of the record about which information is required.  XREFs can be
obtained initially from a search, and subsequently from certain queries.


=item requested/information

The information requested.  This is in the same format as that taken by the
get_value method.

=item search_criteria

An individual to search for.  This is in the same format as that taken by the
get_individual method.

=back

=head1 EXAMPLES

 $ wget -qO - 'http://pjcj.sytes.net:8585/ws/plain/royal92?search=elizabeth_ii'
 /ws/plain/royal92/I52

 $ wget -qO - http://pjcj.sytes.net:8585/ws/plain/royal92/I52
 0 @I52@ INDI
 1   NAME Elizabeth_II Alexandra Mary/Windsor/
 1   TITL Queen of England
 1   SEX F
 1   BIRT
 2     DATE 21 APR 1926
 2     PLAC 17 Bruton St.,London,W1,England
 1   FAMS @F14@
 1   FAMC @F12@

 $ wget -qO - http://pjcj.sytes.net:8585/ws/plain/royal92/I52/name
 Elizabeth_II Alexandra Mary /Windsor/

 $ wget -qO - http://pjcj.sytes.net:8585/ws/plain/royal92/I52/birth/date
 21 APR 1926

 $ wget -qO - http://pjcj.sytes.net:8585/ws/plain/royal92/I52/children
 /ws/plain/royal92/I58
 /ws/plain/royal92/I59
 /ws/plain/royal92/I60
 /ws/plain/royal92/I61

 $ wget -qO - http://pjcj.sytes.net:8585/ws/json/royal92/I52/name
 {"name":"Elizabeth_II Alexandra Mary /Windsor/"}

 $ wget -qO - http://pjcj.sytes.net:8585/ws/xml/royal92/I52/name
 <NAME>Elizabeth_II Alexandra Mary /Windsor/</NAME>

 $ wget -qO - http://pjcj.sytes.net:8585/ws/xml/royal92/I52
 <INDI ID="I52">
   <NAME>Elizabeth_II Alexandra Mary/Windsor/</NAME>
   <TITL>Queen of England</TITL>
   <SEX>F</SEX>
   <BIRT>
     <DATE>21 APR 1926</DATE>
     <PLAC>17 Bruton St.,London,W1,England</PLAC>
   </BIRT>
   <FAMS REF="F14"/>
   <FAMC REF="F12"/>
 </INDI>

=head1 CONFIGURATION

Add a section similar to the following to your mod_perl config:

 PerlWarn On
 PerlTaintCheck On

 PerlPassEnv GEDCOM_TEST

 <IfDefine GEDCOM_TEST>
     <Perl>
         $Gedcom::TEST = 1;
     </Perl>
 </IfDefine>

 <Perl>
     use Apache::Status;

     $ENV{PATH} = "/bin:/usr/bin";
     delete @ENV{"IFS", "CDPATH", "ENV", "BASH_ENV"};

     $Gedcom::DATA = $Gedcom::ROOT;  # location of data stored on server

     use lib "$Gedcom::ROOT/blib/lib";
     use Gedcom::WebServices;

     my $handlers =
     [ qw
       (
           plain
           xml
           json
       )
     ];

     eval Gedcom::WebServices::_set_handlers($handlers);
     # use Apache::PerlSections; print STDERR Apache::PerlSections->dump;
 </Perl>

 PerlTransHandler Gedcom::WebServices::_parse_uri

=head1 BUGS

Very probably.

See the BUGS file.  And the TODO file.

=head1 VERSION

Version 1.19 - 18th August 2013

=head1 LICENCE

Copyright 2005-2013, Paul Johnson (paul@pjcj.net)

This software is free.  It is licensed under the same terms as Perl itself.

The latest version of this software should be available from my homepage:
http://www.pjcj.net

=cut