#
# spec file for package perl-FCGI
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define cpan_name FCGI
Name:           perl-FCGI
Version:        0.820.0
Release:        1.13
# 0.82 -> normalize -> 0.820.0
%define cpan_version 0.82
#Upstream:  See the LICENSE file in this distribution for information on usage and redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
License:        BSD-2-Clause
Summary:        Fast CGI module
URL:            https://metacpan.org/release/%{cpan_name}
Source0:        https://cpan.metacpan.org/authors/id/E/ET/ETHER/%{cpan_name}-%{cpan_version}.tar.gz
Source1:        cpanspec.yml
BuildRequires:  perl
BuildRequires:  perl-macros
BuildRequires:  perl(FCGI::Client) >= 0.90.0
Provides:       perl(FCGI) = %{version}
Provides:       perl(FCGI::Stream)
%undefine       __perllib_provides
%{perl_requires}

%description
Functions:

* FCGI::Request

Creates a request handle. It has the following optional parameters:

  * input perl file handle (default: \*STDIN)

  * output perl file handle (default: \*STDOUT)

  * error perl file handle (default: \*STDERR)

These filehandles will be setup to act as input/output/error on successful
Accept.

  * environment hash reference (default: \%ENV)

The hash will be populated with the environment.

  * socket (default: 0)

Socket to communicate with the server. Can be the result of the OpenSocket
function. For the moment, it's the file descriptor of the socket that
should be passed. This may change in the future.

You should only use your own socket if your program is not started by a
process manager such as mod_fastcgi (except for the FastCgiExternalServer
case) or cgi-fcgi. If you use the option, you have to let your FastCGI
server know which port (and possibly server) your program is listening on.
See remote.pl for an example.

  * flags (default: FCGI::FAIL_ACCEPT_ON_INTR)

Possible values:

    * FCGI::FAIL_ACCEPT_ON_INTR

If set, Accept will fail if interrupted. It not set, it will just keep on
waiting.

Example usage: my $req = FCGI::Request;

or: my %env; my $in = new IO::Handle; my $out = new IO::Handle; my $err =
new IO::Handle; my $req = FCGI::Request($in, $out, $err, \%env);

* FCGI::OpenSocket(path, backlog)

Creates a socket suitable to use as an argument to Request.

  * path

Pathname of socket or colon followed by local tcp port. Note that some
systems take file permissions into account on Unix domain sockets, so
you'll have to make sure that the server can write to the created file, by
changing the umask before the call and/or changing permissions and/or group
of the file afterwards.

  * backlog

Maximum length of the queue of pending connections. If a connection request
arrives with the queue full the client may receive an error with an
indication of ECONNREFUSED.

* FCGI::CloseSocket(socket)

Close a socket opened with OpenSocket.

* $req->Accept()

Accepts a connection on $req, attaching the filehandles and populating the
environment hash. Returns 0 on success. If a connection has been accepted
before, the old one will be finished first.

Note that unlike with the old interface, no die and warn handlers are
installed by default. This means that if you are not running an sfio
enabled perl, any warn or die message will not end up in the server's log
by default. It is advised you set up die and warn handlers yourself.
FCGI.pm contains an example of die and warn handlers.

* $req->Finish()

Finishes accepted connection. Also detaches filehandles.

* $req->Flush()

Flushes accepted connection.

* $req->Detach()

Temporarily detaches filehandles on an accepted connection.

* $req->Attach()

Re-attaches filehandles on an accepted connection.

* $req->LastCall()

Tells the library not to accept any more requests on this handle. It should
be safe to call this method from signal handlers.

Note that this method is still experimental and everything about it,
including its name, is subject to change.

* $env = $req->GetEnvironment()

Returns the environment parameter passed to FCGI::Request.

* ($in, $out, $err) = $req->GetHandles()

Returns the file handle parameters passed to FCGI::Request.

* $isfcgi = $req->IsFastCGI()

Returns whether or not the program was run as a FastCGI.

%prep
%autosetup  -n %{cpan_name}-%{cpan_version}

find . -type f ! -path "*/t/*" ! -name "*.pl" ! -path "*/bin/*" ! -path "*/script/*" ! -path "*/scripts/*" ! -name "configure" -print0 | xargs -0 chmod 644

%build
perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE="%{optflags}"
%make_build

%check
make test

%install
%perl_make_install
%perl_process_packlist
%perl_gen_filelist

%files -f %{name}.files
%doc ChangeLog configure.readme README
%license LICENSE

%changelog
* Sun Aug  1 2021 Tina Müller <timueller+perl@suse.de>
- updated to 0.82
  see /usr/share/doc/packages/perl-FCGI/ChangeLog
  Version 0.82 --  2021-07-31
  - fix failing skip tests on MSWin32
  Version 0.81 --  2021-07-31
  - Add dependency to FCGI::Client 0.09 so as to not depend on Any::Moose,
    which is deprecated. (Michal Josef Špaček, PR #7)
  - fix test failures on MSWin32 ((Michal Josef Špaček, PR #8)
  Version 0.80 --  2021-07-24
  - Add test for FCGI over unix domain socket (Michal Josef Špaček, PR #6)
* Sun Dec 15 2019 <timueller+perl@suse.de>
- updated to 0.79
  see /usr/share/doc/packages/perl-FCGI/ChangeLog
  Version 0.79 --  2019-12-14
  - Check socket path length in OS_CreateLocalIpcFd() and OS_FcgiConnect()
    to avoid buffer overrun (Petr Písař, pull request #5)
  - Fix a memory leak in ProcessManagementRecord() (Petr Písař, pull request #4)
* Fri Mar 11 2016 coolo@suse.com
- updated to 0.78
  see /usr/share/doc/packages/perl-FCGI/ChangeLog
  Version 0.78 --  2015-03-07
    o make copyright and license information more visible (RT#112535)
* Fri Apr 17 2015 coolo@suse.com
- updated to 0.77
  see /usr/share/doc/packages/perl-FCGI/ChangeLog
  Release history for FCGI
  Version 0.77 --  2014-08-05
    o re-release to remove build artifacts that should not have been shipped
  Version 0.76 --  2014-08-05
    o On Android, set TMPDIR before calling configure (RT#97680, Brian Fraser)
  Version 0.75 --  2014-07-17
    o deprecated APIs removed (chansen)
    o broken PP implementation removed (chansen)
    o retooled distribution so FCGI.pm and FCGI.xs exist as-is, rather than
    being generated by FCGI.PL and FCGI.XL (chansen)
* Thu May 24 2012 coolo@suse.com
- updated to 0.74
  o Stop leaking information across requests when using the deprecated
    and undocumented old FCGI interface. This is CVE-2011-2766.
  o Only discard input stream if FCGI_KEEP_CONN is set in
    FCGI_BeginRequestBody flags.
* Wed Jun  8 2011 coolo@novell.com
- updated to 0.73
  o Stop claiming we ship a file called -e in the MANIFEST.
  o Clean up Makefile.PL and restore compatibility with recent
    ExtUtils::MakeMaker versions.
  o Remove support for sfio which is an optional (and not enabled by default)
    compile option to perl that is never used.
  o Fix FCGI::Stream::READ() to warn() instead of croak() incase of
    wide characters which cannot be gracefully downgraded.
  o Fix warnings due to wide characters being mangled to note that accepting
    them is deprecated and will stop working at some point.
  o Various fixes to FCGI::Stream::READ() to improve handling of error and
    edge cases.
  - croak if called with invalid number of arguments
  - croak if length is negative
  - croak if offset is outside string
  - pad scalar if offset is greater than length
  o Fix in FCGX_Finish_r to discard any remaining data in input stream
    which otherwise ends up in next request. This fixes multiple requests
    being broken if something goes wrong whilst reading the initial request.
    This discarding is done silently, as RFC 3875 says a script is not
    obliged to read any of the data.
  o Fixed indent style and braces to be consistent, swapped tabs for spaces
    in indenting.
  o Change the Request function to pass FAIL_ON_INTR into the XS
    RequestX function. This prevents the fcgi C client code from
    looping around their accept() call. This change means that
    when using CGI::Fast, and the process recieves SIGTERM or
    SIGHUP, the error statusis correctly passed back up, allowing process
    managers (such as FCGI::ProcManager) to correctly handle cleanly exiting.
  o Restore old behavior when un-downgradeable uft8 is sent to FCGI.
    The first time this happens, a warning will be issued, but subsequently
    the bytes will be sent through raw (causing double encoding etc).
    If the character string can be downgraded safely, then it will still be.
    use warnings FATAL => 'utf8'; can be used to make undowngradeable strings
    throw an exception.
  o Fix PRINT retval (Closes: RT#57697).
* Wed Dec  1 2010 coolo@novell.com
- switch to perl_requires macro
* Tue Sep 14 2010 chris@computersalat.de
- update to 0.71
    o Fix some more defined(%%hash) warnings on perl 5.12.
  - Version 0.70 --     22 Mar 2010  <bobtfish@bobtfish.net> Tomas Doran
    o Fix use of defined %%hash which becomes deprecated in perl 5.12
  - Version 0.69 --     15 Feb 2010  <mst@shadowcat.co.uk> Matt S Trout
    o No changes since the previous development release.
  - Version 0.68_02 --   13 Jan 2010  <mst@shadowcat.co.uk> Matt S Trout
    o Make the PRINT method return a boolean value rather than the
  number of bytes written, previous patch was incorrect.
  - Version 0.68_01 --   10 Jan 2010  <mst@shadowcat.co.uk> Matt S Trout
    o Force signal handler installation so that we correctly install handlers
    for SIGPIPE. Fixes RT#5100 <bobtfish@bobtfish.net>
    o Make the PRINT method return the number of bytes written rather than
    undef to be consistent with the IO:: interface. Fixes RT#24347
    <David Dick>
    o Fix UTF-8 double encoding when FCGI is passed octets by downgrading
    them into bytes correctly. Fixes RT#52400 <chansen@cpan.org>
  - Version 0.68 --     31 Dec 2009  <mst@shadowcat.co.uk> Matt S Trout
    o No changes since the previous development release.
  - Version 0.67_01 --   20 Dec 2009  <mst@shadowcat.co.uk> Matt S Trout
    o Add FILENO method which returns a defined but invalid value to
    placate things such as IPC::Run which call fileno to check if a
    filehandle is open.
    Closes bugs:
    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=544540
    http://rt.cpan.org/Public/Bug/Display.html?id=50972
    Removes need for upstream patch in OpenBSD <bobtfish@bobtfish.net>
    o Call the fcgi lib's attach/detach <robs@fastcgi.com>
- recreated by cpanspec 1.78
* Wed Dec  9 2009 bitshuffler #suse@irc.freenode.org
- Initial RPM