view liboctave/util/url-transfer.h @ 27918:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents 4d6d21839dfd
children 1891570abac8
line wrap: on
line source

/*

Copyright (C) 2006-2019 The Octave Project Developers

See the file COPYRIGHT.md in the top-level directory of this distribution
or <https://octave.org/COPYRIGHT.html/>.


This file is part of Octave.

Octave is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Octave is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING.  If not, see
<https://www.gnu.org/licenses/>.

*/

// Author: Alexander Barth <abarth@marine.usf.edu>

#if ! defined (octave_url_transfer_h)
#define octave_url_transfer_h 1

#include "octave-config.h"

#include <istream>
#include <memory>
#include <ostream>
#include <string>

#include "str-vec.h"

template <typename T> class Array;

namespace octave
{
  struct weboptions
  {
    std::string UserAgent;
    long Timeout;
    std::string Username;
    std::string Password;
    Array<std::string> HeaderFields;
    std::string ContentReader;
    std::string RequestMethod;
    std::string ArrayFormat;
    std::string CertificateFilename;
  };

  class
  OCTAVE_API
  base_url_transfer
  {
  private:

    static void delete_file (const std::string& file);

    static void reset_path (base_url_transfer *curl_xfer)
    {
      curl_xfer->cwd ("..");
    }

  public:

    friend class url_transfer;

    base_url_transfer (void);

    base_url_transfer (const std::string& host,
                       const std::string& /* user_arg */,
                       const std::string& /* passwd */,
                       std::ostream& os);

    base_url_transfer (const std::string& url, std::ostream& os);

    // No copying!

    base_url_transfer (const base_url_transfer&) = delete;

    base_url_transfer& operator = (const base_url_transfer&) = delete;

    virtual ~base_url_transfer (void) = default;

    bool is_valid (void) const { return m_valid; }

    bool good (void) const { return m_valid && m_ok; }

    virtual void perform (void) { }

    virtual std::string lasterror (void) const { return m_errmsg; }

    virtual std::ostream& set_ostream (std::ostream& /* os */)
    {
      return *m_curr_ostream;
    }

    virtual std::istream& set_istream (std::istream& /* is */)
    {
      return *m_curr_istream;
    }

    virtual void ascii (void) { }

    virtual void binary (void) { }

    bool is_ascii (void) const { return m_ascii_mode; }

    bool is_binary (void) const { return ! m_ascii_mode; }

    virtual void cwd (const std::string& /* path */) { }

    virtual void del (const std::string& /* file */) { }

    virtual void rmdir (const std::string& /* path */) { }

    virtual void mkdir (const std::string& /* path */) { }

    virtual void rename (const std::string& /* oldname */,
                         const std::string& /* newname */) { }

    virtual void put (const std::string& /* file */,
                      std::istream& /* is */) { }

    virtual void get (const std::string& /* file */,
                      std::ostream& /* os */) { }

    void mget_directory (const std::string& directory,
                         const std::string& target);

    string_vector mput_directory (const std::string& base,
                                  const std::string& directory);

    virtual void dir (void) { }

    virtual string_vector list (void) { return string_vector (); }

    virtual void get_fileinfo (const std::string& /* filename */,
                               double& /* filesize */,
                               time_t& /* filetime */,
                               bool& /* fileisdir */) { }

    virtual std::string pwd (void) { return ""; }

    virtual void http_get (const Array<std::string>& /* param */) { }

    virtual void http_post (const Array<std::string>& /* param */) { }

    virtual void http_action (const Array<std::string>& /* param */,
                              const std::string& /* action */) { }

    virtual void cookie_jar (const std::string& /* filename */) { }

    virtual void set_header_fields (const Array<std::string>& /* param */) { }

    virtual void form_data_post (const Array<std::string>& /* param */) { }

    virtual void set_weboptions (const struct weboptions& /* param */) { }

  protected:

    // Host for ftp transfers or full URL for http requests.
    std::string m_host_or_url;
    bool m_valid;
    bool m_ftp;
    bool m_ascii_mode;
    bool m_ok;
    std::string m_errmsg;
    std::istream *m_curr_istream;
    std::ostream *m_curr_ostream;
  };

  class
  OCTAVE_API
  url_transfer
  {
  public:

    url_transfer (void);

    url_transfer (const std::string& host, const std::string& user,
                  const std::string& passwd, std::ostream& os);

    url_transfer (const std::string& url, std::ostream& os);

    url_transfer (const url_transfer&) = default;

    url_transfer& operator = (const url_transfer&) = default;

    ~url_transfer (void) = default;

    bool is_valid (void) const { return m_rep->is_valid (); }

    bool good (void) const { return m_rep->good (); }

    std::string lasterror (void) const { return m_rep->lasterror (); }

    std::ostream& set_ostream (std::ostream& os)
    {
      return m_rep->set_ostream (os);
    }

    std::istream& set_istream (std::istream& is)
    {
      return m_rep->set_istream (is);
    }

    void ascii (void) { m_rep->ascii (); }

    void binary (void) { m_rep->binary (); }

    bool is_ascii (void) const { return m_rep->is_ascii (); }

    bool is_binary (void) const { return m_rep->is_binary (); }

    void cwd (const std::string& path) { m_rep->cwd (path); }

    void del (const std::string& file) { m_rep->del (file); }

    void rmdir (const std::string& path) { m_rep->rmdir (path); }

    void mkdir (const std::string& path) { m_rep->mkdir (path); }

    void rename (const std::string& oldname, const std::string& newname)
    {
      m_rep->rename (oldname, newname);
    }

    void put (const std::string& file, std::istream& is)
    {
      m_rep->put (file, is);
    }

    void get (const std::string& file, std::ostream& os)
    {
      m_rep->get (file, os);
    }

    void mget_directory (const std::string& directory,
                         const std::string& target)
    {
      m_rep->mget_directory (directory, target);
    }

    string_vector mput_directory (const std::string& base,
                                  const std::string& directory)
    {
      return m_rep->mput_directory (base, directory);
    }

    void dir (void) { m_rep->dir (); }

    string_vector list (void) { return m_rep->list (); }

    void get_fileinfo (const std::string& filename, double& filesize,
                       time_t& filetime, bool& fileisdir)
    {
      m_rep->get_fileinfo (filename, filesize, filetime, fileisdir);
    }

    std::string pwd (void) { return m_rep->pwd (); }

    void http_get (const Array<std::string>& param)
    {
      m_rep->http_get (param);
    }

    void http_post (const Array<std::string>& param)
    {
      m_rep->http_post (param);
    }

    void http_action (const Array<std::string>& param,
                      const std::string& action)
    {
      m_rep->http_action (param, action);
    }

    void cookie_jar (const std::string& filename)
    {
      m_rep->cookie_jar (filename);
    }

    void set_header_fields (const Array<std::string>& param)
    {
      m_rep->set_header_fields (param);
    }

    void form_data_post (const Array<std::string>& param)
    {
      m_rep->form_data_post (param);
    }

    void set_weboptions (const struct weboptions& param)
    {
      m_rep->set_weboptions (param);
    }

  private:

    std::shared_ptr<base_url_transfer> m_rep;
  };
}

#endif