From 9a1b2c283e9a74779d1d3ca149aadb7a48223dbd Mon Sep 17 00:00:00 2001
From: Guilhem Lavaux <lavaux@easynet.fr>
Date: Thu, 25 Feb 1999 20:13:10 +0000
Subject: [PATCH] * Added a small wxHTTP description * Added some
 example/description to wxFTP * Some more on wxURL

* Added missing file in wxMMedia


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1795 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/classes.tex |   1 +
 docs/latex/wx/ftp.tex     | 112 +++++++++++++++++++++++++++++++++++++-
 docs/latex/wx/url.tex     |  10 ++++
 src/common/ftp.cpp        |  15 ++++-
 src/common/http.cpp       |   6 ++
 utils/wxMMedia/sndadpcm.h |  30 ++++++++++
 utils/wxMMedia/sndfrmt.h  |   1 +
 utils/wxMMedia/sndwav.cpp |   3 +-
 8 files changed, 174 insertions(+), 4 deletions(-)
 create mode 100644 utils/wxMMedia/sndadpcm.h

diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex
index f54db8af78..7699ac12fa 100644
--- a/docs/latex/wx/classes.tex
+++ b/docs/latex/wx/classes.tex
@@ -80,6 +80,7 @@
 \input grid.tex
 \input hash.tex
 \input helpinst.tex
+\input http.tex
 \input idleevt.tex
 \input icon.tex
 \input image.tex
diff --git a/docs/latex/wx/ftp.tex b/docs/latex/wx/ftp.tex
index 2b8b6c5ec6..039bb10cd1 100644
--- a/docs/latex/wx/ftp.tex
+++ b/docs/latex/wx/ftp.tex
@@ -6,7 +6,7 @@
 
 \wxheading{Include files}
 
-<wx/ftp.h>
+<wx/protocol/ftp.h>
 
 \wxheading{See also}
 
@@ -84,6 +84,68 @@ Delete the file specified by \it{path}. Returns TRUE if successful.
 
 % ----------------------------------------------------------------------------
 
+\membersection{wxFTP::SetUser}
+\func{void}{SetUser}{\param{const wxString\&}{ user}}
+
+Sets the user name to be sent to the FTP server to be allowed to log in.
+
+\wxheading{Default value}
+
+The default value of the user name is "anonymous".
+
+\wxheading{Remark}
+
+This parameter can be included in a URL if you want to use the URL manager.
+For example, you can use: "ftp://a_user:a_password@a.host:service/a_directory/a_file"
+to specify a user and a password.
+
+\membersection{wxFTP::SetPassword}
+\func{void}{SetPassword}{\param{const wxString\&}{ passwd}}
+
+Sets the password to be sent to the FTP server to be allowed to log in.
+
+\wxheading{Default value}
+
+The default value of the user name is your email address. For example, it could
+be "username@userhost.domain". This password is built by getting the current
+user name and the host name of the local machine from the system.
+
+\wxheading{Remark}
+
+This parameter can be included in a URL if you want to use the URL manager.
+For example, you can use: "ftp://a_user:a_password@a.host:service/a_directory/a_
+file"
+to specify a user and a password.
+
+% ----------------------------------------------------------------------------
+\membersection{wxFTP::GetList}
+\func{wxList *}{GetList}{\param{const wxString\&}{ wildcard}}
+
+The GetList function is quite low-level. It returns the list of the files in
+the current directory. The list can be filtered using the \it{wildcard} string.
+If \it{wildcard} is a NULL string, it will return all files in directory.
+
+The form of the list can change from one peer system to another. For example,
+for a UNIX peer system, it will look like this:
+\begin{verbatim}
+-r--r--r--   1 guilhem  lavaux      12738 Jan 16 20:17 cmndata.cpp
+-r--r--r--   1 guilhem  lavaux      10866 Jan 24 16:41 config.cpp
+-rw-rw-rw-   1 guilhem  lavaux      29967 Dec 21 19:17 cwlex_yy.c
+-rw-rw-rw-   1 guilhem  lavaux      14342 Jan 22 19:51 cwy_tab.c
+-r--r--r--   1 guilhem  lavaux      13890 Jan 29 19:18 date.cpp
+-r--r--r--   1 guilhem  lavaux       3989 Feb  8 19:18 datstrm.cpp
+\end{verbatim}
+
+But on Windows system, it will look like this:
+\begin{verbatim}
+winamp~1 exe    520196 02-25-1999  19:28  winamp204.exe
+        1 file(s)           520 196 bytes
+\end{verbatim}
+
+The list is a string list and one node corresponds to a line sent by the peer.
+
+% ----------------------------------------------------------------------------
+
 \membersection{wxFTP::GetOutputStream}
 
 \func{wxOutputStream *}{GetOutputStream}{\param{const wxString\&}{ file}}
@@ -100,3 +162,51 @@ An initialized write-only stream.
 
 \helpref{wxOutputStream}{wxoutputstream}
 
+% ----------------------------------------------------------------------------
+
+\membersection{wxFTP::GetInputStream}\label{wxftpgetinput}
+
+\func{wxInputStream *}{GetInputStream}{\param{const wxString\&}{ path}}
+
+Creates a new input stream on the the specified path. You can use all but seek
+functionnality of wxStream. Seek isn't available on all stream. For example,
+http or ftp streams doesn't deal with it. Other functions like Tell
+aren't available for the moment for this sort of stream.
+You will be notified when the EOF is reached by an error.
+
+\wxheading{Return value}
+
+Returns NULL if an error occured (it could be a network failure or the fact
+that the file doesn't exist).
+
+Returns the initialized stream. You will have to delete it yourself once you
+don't use it anymore. The destructor close the DATA stream connection but
+will leave the COMMAND stream connection opened. It means that you still
+can send new commands without reconnecting.
+
+\wxheading{Example of a standalone connection (without wxURL)}
+
+\begin{verbatim}
+  wxFTP ftp;
+  wxInputStream *in\_stream;
+  char *data;
+
+  ftp.Connect("a.host.domain");
+  ftp.ChDir("a\_directory");
+  in\_stream = ftp.GetInputStream("a\_file\_to\_get");
+
+  data = new char[in\_stream->StreamSize()];
+
+  in\_stream->Read(data, in\_stream->StreamSize());
+  if (in\_stream->LastError() != wxStream\_NOERROR) {
+    // Do something.
+  }
+
+  delete in\_stream; /* Close the DATA connection */
+
+  ftp.Close(); /* Close the COMMAND connection */
+\end{verbatim}
+
+\wxheading{See also}
+
+\helpref{wxInputStream}{wxinputstream}
diff --git a/docs/latex/wx/url.tex b/docs/latex/wx/url.tex
index 56a55a318c..4d40753f83 100644
--- a/docs/latex/wx/url.tex
+++ b/docs/latex/wx/url.tex
@@ -12,6 +12,16 @@
 
 \helpref{wxSocketBase}{wxsocketbase}, \helpref{wxProtocol}{wxprotocol}
 
+\wxheading{Example}
+
+\begin{verbatim}
+  wxURL url("http://a.host/a.dir/a.file");
+  wxInputStream *in\_stream;
+
+  in\_stream = url.GetInputStream();
+  /* Then, you can use all IO calls of in\_stream (See wxStream) */
+\end{verbatim}
+
 % ----------------------------------------------------------------------------
 % Members
 % ----------------------------------------------------------------------------
diff --git a/src/common/ftp.cpp b/src/common/ftp.cpp
index 28aad19f7f..d0b2a80211 100644
--- a/src/common/ftp.cpp
+++ b/src/common/ftp.cpp
@@ -249,9 +249,11 @@ bool wxFTP::RmFile(const wxString& path)
 class wxInputFTPStream : public wxSocketInputStream {
 public:
   wxFTP *m_ftp;
+  size_t m_ftpsize;
 
   wxInputFTPStream(wxFTP *ftp_clt, wxSocketBase *sock)
     : wxSocketInputStream(*sock), m_ftp(ftp_clt) {}
+  size_t StreamSize() { return m_ftpsize; }
   virtual ~wxInputFTPStream(void)
   { 
      if (LastError() != wxStream_NOERROR)
@@ -328,6 +330,8 @@ bool wxFTP::Abort(void)
 wxInputStream *wxFTP::GetInputStream(const wxString& path)
 {
   wxString tmp_str;
+  int pos_size;
+  wxInputFTPStream *in_stream;
 
   if (!SendCommand("TYPE I", '2'))
     return NULL;
@@ -343,7 +347,16 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path)
   if (!SendCommand(tmp_str, '1'))
     return NULL;
 
-  return new wxInputFTPStream(this, sock);
+  in_stream = new wxInputFTPStream(this, sock);
+
+  pos_size = m_lastResult.Index('(');
+  if (pos_size != wxNOT_FOUND) {
+    wxString str_size = m_lastResult(pos_size, m_lastResult.Index(')'));
+
+    in_stream->m_ftpsize = atoi(WXSTRINGCAST str_size);
+  }
+
+  return in_stream;
 }
 
 wxOutputStream *wxFTP::GetOutputStream(const wxString& path)
diff --git a/src/common/http.cpp b/src/common/http.cpp
index 80c8bf09e8..d92ac8436b 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -231,7 +231,10 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
 class wxHTTPStream : public wxSocketInputStream {
 public:
   wxHTTP *m_http;
+  size_t m_httpsize;
+
   wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
+  size_t StreamSize() { return m_httpsize; }
   virtual ~wxHTTPStream(void) { m_http->Abort(); }
 };
 
@@ -255,5 +258,8 @@ wxInputStream *wxHTTP::GetInputStream(const wxString& path)
   if (!BuildRequest(path, wxHTTP_GET))
     return NULL;
 
+  if (GetHeader("Content-Length").IsEmpty())
+    inp_stream->m_httpsize = atoi(WXSTRINGCAST GetHeader("Content-Length"));
+
   return inp_stream;
 }
diff --git a/utils/wxMMedia/sndadpcm.h b/utils/wxMMedia/sndadpcm.h
new file mode 100644
index 0000000000..465958c887
--- /dev/null
+++ b/utils/wxMMedia/sndadpcm.h
@@ -0,0 +1,30 @@
+#ifndef __MEDIA_SNDADPCM_H__
+#define __MEDIA_SNDADPCM_H__
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "sndfrmt.h"
+
+class wxSoundAdpcmCodec : public wxSoundCodec {
+  DECLARE_DYNAMIC_CLASS(wxSoundAdpcmCodec)
+ public:
+  wxSoundAdpcmCodec();
+  ~wxSoundAdpcmCodec();
+
+  size_t GetByteRate() const;
+  wxSoundDataFormat GetPreferredFormat(int codec = 0) const;
+  int GetBits(int bits);
+
+  void Decode();
+  void Encode();
+
+  void InitWith(const wxSoundDataFormat& format);
+ protected:
+  struct g72x_state *m_codec_state;
+  int m_bits_waiting, m_current_byte;
+  int m_srate;
+};
+
+#endif
diff --git a/utils/wxMMedia/sndfrmt.h b/utils/wxMMedia/sndfrmt.h
index ee686f1753..6a67db7de2 100644
--- a/utils/wxMMedia/sndfrmt.h
+++ b/utils/wxMMedia/sndfrmt.h
@@ -36,6 +36,7 @@ class wxSoundDataFormat {
   void SetChannels(int channels);
   void SetStereo(bool on);
   void SetCodecNo(int no);
+  int GetCodecNo() { return m_codno; }
   void SetCodecCreate(bool create) { m_codcreate = create; }
 
   int GetSampleRate() const { return m_srate; }
diff --git a/utils/wxMMedia/sndwav.cpp b/utils/wxMMedia/sndwav.cpp
index 05d8019cc6..23857f15c1 100644
--- a/utils/wxMMedia/sndwav.cpp
+++ b/utils/wxMMedia/sndwav.cpp
@@ -140,13 +140,12 @@ bool wxSndWavCodec::PrepareToRecord(wxUint32 m_fsize)
   if (!riff_codec.CreateChunk("fmt ", sizeof(wav_hdr)))
     return FALSE;
 
-  wav_hdr.format = 1; // PCM_WAV_FORMAT
+  wav_hdr.format = m_sndformat.GetCodecNo(); // PCM_WAV_FORMAT
   wav_hdr.channels = m_sndformat.GetChannels();
   wav_hdr.sample_fq = m_sndformat.GetSampleRate();
   wav_hdr.byte_p_spl = (m_sndformat.GetBps() / 8) * wav_hdr.channels;
   wav_hdr.byte_p_sec = m_sndformat.GetCodec()->GetByteRate();
   wav_hdr.bits_p_spl = m_sndformat.GetBps();
-  ChangeCodec(WXSOUND_PCM);
 
   if (wav_hdr.format == WXSOUND_PCM) {
     m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
-- 
2.50.0

