[xiph-commits] r6839 - in icecast/branches: . libshout-kh

j at dactyl.lonelymoon.com j
Fri Jun 25 13:45:29 PDT 2004


libshout-kh/examples libshout-kh/include
libshout-kh/include/shout libshout-kh/src
Message-ID: <20040625204529.EB94A9AAAB at dactyl.lonelymoon.com>

Author: j
Date: Fri Jun 25 13:45:29 2004
New Revision: 6839

Added:
icecast/branches/libshout-kh/
icecast/branches/libshout-kh/COPYING
icecast/branches/libshout-kh/Makefile.am
icecast/branches/libshout-kh/NEWS
icecast/branches/libshout-kh/README
icecast/branches/libshout-kh/autogen.sh
icecast/branches/libshout-kh/configure.in
icecast/branches/libshout-kh/examples/
icecast/branches/libshout-kh/examples/Makefile.am
icecast/branches/libshout-kh/examples/example.c
icecast/branches/libshout-kh/examples/example2.c
icecast/branches/libshout-kh/include/
icecast/branches/libshout-kh/include/Makefile.am
icecast/branches/libshout-kh/include/shout/
icecast/branches/libshout-kh/include/shout/Makefile.am
icecast/branches/libshout-kh/include/shout/shout.h.in
icecast/branches/libshout-kh/shout.pc.in
icecast/branches/libshout-kh/src/
icecast/branches/libshout-kh/src/Makefile.am
icecast/branches/libshout-kh/src/mp3.c
icecast/branches/libshout-kh/src/ogg.c
icecast/branches/libshout-kh/src/shout.c
icecast/branches/libshout-kh/src/shout_private.h
icecast/branches/libshout-kh/src/util.c
icecast/branches/libshout-kh/src/util.h
Log:
import of libsohut-kh

Added: icecast/branches/libshout-kh/COPYING
===================================================================
--- icecast/branches/libshout-kh/COPYING	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/COPYING	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,481 @@
+		  GNU LIBRARY GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+    		    59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL.  It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it.  You can use it for
+your libraries, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library.  If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software.  To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+  Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs.  This
+license, the GNU Library General Public License, applies to certain
+designated libraries.  This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+  The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it.  Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program.  However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+  Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries.  We
+concluded that weaker conditions might promote sharing better.
+
+  However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves.  This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them.  (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.)  The hope is that this
+will lead to faster development of free libraries.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+  Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+		  GNU LIBRARY GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License").  Each licensee is
+addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    c) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    d) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+			    NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!

Added: icecast/branches/libshout-kh/Makefile.am
===================================================================
--- icecast/branches/libshout-kh/Makefile.am	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/Makefile.am	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,25 @@
+## Process this file with automake to produce Makefile.in
+
+AUTOMAKE_OPTIONS = 1.6 foreign dist-bzip2
+ACLOCAL_AMFLAGS = -I m4
+
+SUBDIRS = include src examples
+
+EXTRA_DIST = README COPYING NEWS m4
+
+if HAVE_PKGCONFIG
+  pkgconfigdir = $(libdir)/pkgconfig
+  pkgconfig_DATA = shout.pc
+else
+  bin_SCRIPTS = shout-config
+endif
+DISTCLEANFILES = shout-config.in
+
+## SCCS stuff (for BitKeeper)
+GET = true
+
+debug:
+	$(MAKE) all CFLAGS="@DEBUG@"
+
+profile:
+	$(MAKE) all CFLAGS="@PROFILE@"

Added: icecast/branches/libshout-kh/NEWS
===================================================================
--- icecast/branches/libshout-kh/NEWS	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/NEWS	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,160 @@
+1.29
+----
+. theora wasn't optional, allow building without it
+. minor tweaks to build
+
+1.28
+----
+. fix silly build error in the examples. was actually a header issue
+
+1.27
+----
+. Add multiple ogg codec handling, time vorbis and theora logical
+  streams. Stream unhandled but paged ogg codecs.
+
+1.26
+----
+. state all dependent libs, or else static linking fails
+
+1.25
+----
+. update sock code
+. don't stall in non blocking mode waiting for reply from server
+. re-sync timing fixups in vorbis and mp3 handlers
+
+1.24
+----
+. minor memory leak on shout_new plugged
+. update the avl code, nothing significant wrt libshout, just sync-up
+
+1.23
+----
+. signal mask wokaround on openbsd
+
+1.22
+----
+. re-sync withe CVS and the icecast updates of net
+
+1.21
+----
+. added missing prototypes added in v1.0 CVS
+. fixed incorrect error return in the format specific send.
+. changed sock_connected to use sock_set_error for sock_error usage
+. remove bad use of sock_recoverable
+. some prototype cleanups
+. updated net, sock_connected API change, async blocking connect fix
+. added write check to autoconf, got lost from m4 update
+. reset header size on close, else it can cause an accumulation of
+  headers to be sent on subsequent connections to the server, even
+  causing it to fill up and bomb out with a malloc error.
+
+1.20
+----
+. Username default was not set correctly and a subsequent check
+  was missing.
+. some minor code cleanups
+
+1.19
+----
+. Add missing metadata functions
+. update the thread code, to fix potential leaks
+
+1.18
+----
+. added timeout (5s) when reading headers in blocking mode
+. added function to alter timeout setting (in ms)
+. fixed stuffed m4 macro
+
+1.17
+----
+. updated m4 macros to work done in CVS.
+. updated subtrees to include fixes sent to CVS
+. Added shout_init, shout_shutdown from CVS to bring back CVS compatability
+
+1.16
+----
+. fix serial number 0 bug left from cvs
+. use send_oggpage in send_vorbis, utilises the writev and queueing
+  facilities.
+. fixed a couple of silly bugs for shout_sync
+
+1.15
+----
+. update autoconf scripts
+. fix build problems for some platforms
+
+1.14
+----
+. Merge shout_send_ogg into shout_send using new format type
+  SHOUT_FORMAT_VORBISPAGE. This also means no shout substructure created
+  but not used. modified shout_send slightly
+. removed the last users of unhandled short write in sock_write_bytes.
+. Added shout-config, matches up with CVS now
+. check for __VAR_ARGS__
+. clean up top level Makefile.am, refers to m4 directory
+. fix leaks in shout_set_metadata
+
+1.13
+----
+. rework xaudiocast and icy logins, now they can handle short writes.
+. altered code route, so that that each protocol requires a handler for
+  creating requests and a handler for parsing responses.
+. state a limit on the amount of bytes stored in the pending queue,
+  currently 64k but a setter could be used to alter
+. misc cleanups left out from previous release.
+
+1.12
+----
+. removed static array representing pending write queue, replaced
+  with linked list with byte counts.
+. much code removal, due to old pending array removal and state
+  information migration. Pending Write queue implemented as list
+  simplified code as well.
+. Add hack for building on OBSD wrt _XOPEN_SOURCE
+
+1.11
+----
+. big cleanup release, mainly relating to connection logic.
+. Add the notion of state to a shout_t to help at connection time.
+. fix a potential thread attribute bug introduce last time.
+. Get nearer to the CVS updates.
+. Drop ICE logins as per CVS.
+. Updated ogg and vorbis autoconf macro's to mroe recent ones
+
+1.10
+----
+. minor compiler warning cleanups
+. re-sync to recent CVS code, mainly tab removal but code updates as well
+. all threads to inherit scheduling attributes, mainly for realtime
+
+1.9
+- change build setup to more like what I and brendan have put in CVS
+  . put headers in config.h
+  . use XIPH_CFLAGS
+  . check for various pthread flags
+  . build exmaples directory
+- update external shout codes to match CVS
+- deprecate the use of shout_set_bitrate, not sure if this is a good idea.
+- add shout-audio-info,  not nice at all but matches CVS.
+- update thread/avl/net/httpp to CVS.
+  . drops some of the unneeded -I flags.
+
+1.8
+- shout_close didn't free pending queue
+- only do so many non-blocking checks 60 for connection, 20 for header acceptance
+- REFUSED didn't have a pretty print message
+
+v1.7
+- fixed a couple of reuse after free cases and a pending write queue problem
+
+v1.6
+- changed mime header from x-ogg to ogg
+
+v1.5
+- make sure shout_close clear various flags.
+
+v1.4
+- Have a function for returning the version
+- writev support added.
+- non-blocking enabled on HTTP connections
+- sock uses newer posix calls for sockets, but falls back to ipv4 only

Added: icecast/branches/libshout-kh/README
===================================================================
--- icecast/branches/libshout-kh/README	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/README	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,20 @@
+libshout
+--------
+
+Libshout is a library for communicating with and sending data to an
+icecast server.  It handles the socket connection, the timing of the
+data, and prevents bad data from getting to the icecast server.
+
+With just a few lines of code, a programmer can easily turn any application
+into a streaming source for an icecast server.  Libshout also allows
+developers who want a specific feature set (database access, request taking)
+to concentrate on that feature set, instead of worrying about how server
+communication works.
+
+Please refer to the api reference and example code to start learning how to
+use libshout in your own code.
+
+Libshout is licensed under the LGPL.  Please see the COPYING file for details.
+
+If you have any questions or comments, please visit us at
+http://www.icecast.org or email us at team at icecast.org.

Added: icecast/branches/libshout-kh/autogen.sh
===================================================================
--- icecast/branches/libshout-kh/autogen.sh	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/autogen.sh	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,113 @@
+#!/bin/sh
+# Run this to set up the build system: configure, makefiles, etc.
+# (based on the version in enlightenment's cvs)
+
+package="libshout"
+
+olddir=`pwd`
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+cd "$srcdir"
+DIE=0
+
+(autoconf --version) < /dev/null > /dev/null 2>&1 || {
+        echo
+        echo "You must have autoconf installed to compile $package."
+        echo "Download the appropriate package for your distribution,"
+        echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+        DIE=1
+}
+VERSIONGREP="sed -e s/.*[^0-9\.]\([0-9]\.[0-9]\).*/\1/"
+
+# do we need automake?
+if test -r Makefile.am; then
+    echo Checking for automake version
+    options=`fgrep AUTOMAKE_OPTIONS Makefile.am`
+    AM_NEEDED=`echo "$options" | $VERSIONGREP`
+    AM_PROGS=automake
+    AC_PROGS=aclocal
+    if test -n "$AM_NEEDED" && test "x$AM_NEEDED" != "x$options"
+    then
+        AM_PROGS="automake-$AM_NEEDED automake$AM_NEEDED $AM_PROGS"
+        AC_PROGS="aclocal-$AM_NEEDED aclocal$AM_NEEDED $AC_PROGS"
+    else
+        AM_NEEDED=""
+    fi
+    AM_PROGS="$AUTOMAKE $AM_PROGS"
+    AC_PROGS="$ACLOCAL $AC_PROGS"
+    for am in $AM_PROGS; do
+      ($am --version > /dev/null 2>&1) 2>/dev/null || continue
+      ver=`$am --version | head -1 | $VERSIONGREP`
+      AWK_RES=`echo $ver $AM_NEEDED | awk '{ if ( $1 >= $2 ) print "yes"; else print "no" }'`
+      if test "$AWK_RES" = "yes"; then
+        AUTOMAKE=$am
+        echo "  found $AUTOMAKE"
+        break
+      fi
+    done
+    for ac in $AC_PROGS; do
+      ($ac --version > /dev/null 2>&1) 2>/dev/null || continue
+      ver=`$ac --version < /dev/null | head -1 | $VERSIONGREP`
+      AWK_RES=`echo $ver $AM_NEEDED | awk '{ if ( $1 >= $2 ) print "yes"; else print "no" }'`
+      if test "$AWK_RES" = "yes"; then
+        ACLOCAL=$ac
+        echo "  found $ACLOCAL"
+        break
+      fi
+    done
+    test -z $AUTOMAKE || test -z $ACLOCAL && {
+        echo
+        if test -n "$AM_NEEDED"; then
+            echo "You must have automake version $AM_NEEDED installed"
+            echo "to compile $package."
+        else
+            echo "You must have automake installed to compile $package."
+        fi
+        echo "Download the appropriate package for your distribution,"
+        echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+        DIE=1
+      }
+fi
+
+(libtoolize --version)  > /dev/null 2>&1 || {
+	echo
+	echo "You must have libtool installed to compile $package."
+	echo "Download the appropriate package for your system,"
+	echo "or get the source from one of the GNU ftp sites"
+	echo "listed in http://www.gnu.org/order/ftp.html"
+	DIE=1
+}
+
+if test "$DIE" -eq 1; then
+        exit 1
+fi
+
+echo "Generating configuration files for $package, please wait...."
+
+ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4"
+if test -n "$ACLOCAL"; then
+  echo "  $ACLOCAL $ACLOCAL_FLAGS"
+  $ACLOCAL $ACLOCAL_FLAGS
+fi
+
+echo "  autoheader"
+autoheader
+
+echo "  libtoolize --automake"
+libtoolize --automake
+
+if test -n "$AUTOMAKE"; then
+  echo "  $AUTOMAKE --add-missing"
+  $AUTOMAKE --add-missing
+fi
+
+echo "  autoconf"
+autoconf
+
+if test -z "$*"; then
+        echo "I am going to run ./configure with no arguments - if you wish "
+        echo "to pass any to it, please specify them on the $0 command line."
+fi
+cd $olddir
+$srcdir/configure "$@" && echo


Property changes on: icecast/branches/libshout-kh/autogen.sh
___________________________________________________________________
Name: svn:executable
+

Added: icecast/branches/libshout-kh/configure.in
===================================================================
--- icecast/branches/libshout-kh/configure.in	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/configure.in	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,190 @@
+dnl Process this file with autoconf to produce a configure script.
+
+
+m4_define(libshout_major, 2)
+m4_define(libshout_minor, 0)
+m4_define(libshout_micro, 0)
+m4_define(libshout_version,
+  m4_if(libshout_micro, 0, libshout_major.libshout_minor-kh30,
+   libshout_major.libshout_minor.libshout_micro-30))
+
+AC_INIT([libshout], libshout_version, [karl at xiph.org])
+AC_PREREQ(2.54)
+AC_CONFIG_SRCDIR([src/shout.c])
+AM_INIT_AUTOMAKE
+AM_CONFIG_HEADER([config.h])
+
+# config.h guard
+AH_TOP([#ifndef __CONFIG_H__
+#define __CONFIG_H__ 1])
+
+AC_DEFINE([LIBSHOUT_MAJOR], libshout_major, [Shout library major version])
+AC_DEFINE([LIBSHOUT_MINOR], libshout_minor, [Shout library minor version])
+AC_DEFINE([LIBSHOUT_MICRO], libshout_micro, [Shout library patch version])
+
+VERSION=libshout_version
+
+AM_MAINTAINER_MODE
+
+AC_PROG_CC
+AC_PROG_LIBTOOL
+
+dnl Set some options based on environment
+# only openbsd has shown up as being broken wrt _XOPEN_SOURCE
+case $host in
+   *bsd* | *irix*)
+   ;;
+   *) AC_DEFINE(_XOPEN_SOURCE, 600, [Define if you have POSIX and XPG])
+   ;;
+esac
+#
+case $host in
+*solaris*)
+        AC_DEFINE(__EXTENSIONS__, 1, [define to 1 for fix some headers])
+;;
+esac
+if test -n "$GCC"; then
+    XIPH_CPPFLAGS="-W"
+    dnl XIPH_CPPFLAGS="-ffast-math -fsigned-char"
+    DEBUG="-g"
+    PROFILE="-pg -g"
+fi
+
+dnl Checks for programs.
+
+dnl Checks for libraries.
+
+dnl Checks for header files.
+AC_HEADER_STDC
+AC_HEADER_TIME
+AC_CHECK_HEADERS(sys/time.h)
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+
+XIPH_FUNC_VA_COPY
+XIPH_C_ATTRIBUTE
+
+AC_TRY_COMPILE([#define f(x,...) printf(x , __VA_ARGS__)], ,
+    AC_DEFINE(HAVE_VA_ARGS,1,[Define if __VA_ARGS__ is supported]))
+
+AH_BOTTOM([
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#elif HAVE_STDINT_H
+#include <stdint.h>
+#endif
+])
+
+dnl Check for types
+AC_CHECK_TYPE([uint64_t],,AC_ERROR([could not find a uint64_t type]))
+
+dnl Checks for library functions.
+ac_save_LIBS="$LIBS"
+LIBS=""
+AC_SEARCH_LIBS([nanosleep],[rt],
+        [AC_DEFINE([HAVE_NANOSLEEP],1,[Define if you have the nanosleep function])
+        XIPH_VAR_PREPEND([XIPH_LIBS],[$LIBS])
+        ])
+LIBS="$ac_save_LIBS"
+
+dnl Module checks
+XIPH_NET
+
+AC_ARG_ENABLE([pthread],
+  [AC_HELP_STRING([--disable-thread],[do not link with thread support even if it is available])])
+SHOUT_THREADSAFE="0"
+if test "$enable_pthread" != "no"
+then
+  ACX_PTHREAD([
+    XIPH_VAR_PREPEND([XIPH_LIBS],[$PTHREAD_LIBS])
+    XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$PTHREAD_CPPFLAGS])
+    XIPH_VAR_APPEND([XIPH_CFLAGS],[$PTHREAD_CFLAGS])
+    CC="$PTHREAD_CC"
+    SHOUT_THREADSAFE="1"
+    ])
+fi
+
+AC_SUBST([SHOUT_THREADSAFE])
+AM_CONDITIONAL([HAVE_THREAD], [test "$SHOUT_THREADSAFE" = "1"])
+if test "$SHOUT_THREADSAFE" != "1"
+then
+  AC_DEFINE([NO_THREAD], 1, [Define if you don't want to use the thread library])
+fi
+
+XIPH_PATH_VORBIS
+XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$VORBIS_CFLAGS])
+XIPH_VAR_PREPEND([XIPH_LIBS],[$VORBIS_LDFLAGS $VORBISENC_LIBS $VORBIS_LIBS])
+
+XIPH_PATH_THEORA(,[AC_MSG_WARN([Theora lib not found, skipping])])
+XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$THEORA_CFLAGS])
+XIPH_VAR_PREPEND([XIPH_LIBS],[$THEORA_LDFLAGS $THEORA_LIBS])
+
+dnl pkgconfig/shout-config.
+dnl If pkgconfig is found, use it and disable shout-config, otherwise do the
+dnl opposite, unless the user overrides.
+
+AC_ARG_ENABLE([pkgconfig],
+  AC_HELP_STRING([--disable-pkgconfig],[disable pkgconfig data files (auto)]),
+  [dopkgconfig="$enableval"], [dopkgconfig="maybe"])
+if test "$dopkgconfig" = "maybe"
+then
+  AC_CHECK_PROG([PKGCONFIG], [pkg-config], [yes], [no])
+else
+  AC_MSG_CHECKING([whether pkgconfig should be used])
+  PKGCONFIG="$dopkgconfig"
+  AC_MSG_RESULT([$PKGCONFIG])
+fi
+AM_CONDITIONAL([HAVE_PKGCONFIG], [test "$PKGCONFIG" != "no"])
+
+# Build shout-config, shout.pc
+
+# I hate myself for doing this.
+save_prefix="$prefix"
+if test "$prefix" = "NONE"
+then
+  prefix="$ac_default_prefix"
+fi
+eval shout_includedir="$includedir"
+prefix="$save_prefix"
+
+
+# Build shout-config
+SHOUT_VERSION="$VERSION"
+SHOUT_LIBS="-lshout"
+SHOUT_LIBDEPS="$THEORA_LIBS $VORBIS_LIBS $PTHREAD_LIBS"
+XIPH_VAR_APPEND([SHOUT_CPPFLAGS], [-I$shout_includedir $VORBIS_CFLAGS $PTHREAD_CPPFLAGS])
+SHOUT_CFLAGS="$PTHREAD_CFLAGS"
+
+AC_CONFIG_LIBCONFIG_IN_STATIC
+AC_CONFIG_LIBCONFIG_IN([shout])
+
+AH_BOTTOM([#endif])
+
+dnl Make substitutions
+
+AC_SUBST(LIBTOOL_DEPS)
+AC_SUBST(DEBUG)
+AC_SUBST(PROFILE)
+AC_SUBST(XIPH_CFLAGS)
+AC_SUBST(XIPH_CPPFLAGS)
+AC_SUBST(XIPH_LIBS)
+AC_SUBST(SHOUT_CPPFLAGS)
+AC_SUBST(SHOUT_CFLAGS)
+AC_SUBST(SHOUT_LIBS)
+AC_SUBST(SHOUT_LIBDEPS)
+
+AC_OUTPUT([Makefile
+include/Makefile
+include/shout/Makefile
+include/shout/shout.h
+src/Makefile
+src/net/Makefile
+src/timing/Makefile
+src/thread/Makefile
+src/avl/Makefile
+src/httpp/Makefile
+examples/Makefile
+shout-config
+shout.pc
+])

Added: icecast/branches/libshout-kh/examples/Makefile.am
===================================================================
--- icecast/branches/libshout-kh/examples/Makefile.am	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/examples/Makefile.am	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,13 @@
+## Process this file with automake to create Makefile.in
+
+AUTOMAKE_OPTIONS = foreign
+
+noinst_PROGRAMS = example example2
+
+example_SOURCES = example.c
+example2_SOURCES = example2.c
+LDADD = ../src/libshout.la $(XIPH_LIBS)
+AM_CFLAGS = @XIPH_CFLAGS@
+AM_CPPFLAGS = @XIPH_CFLAGS@
+
+INCLUDES = -I$(top_builddir)/include

Added: icecast/branches/libshout-kh/examples/example.c
===================================================================
--- icecast/branches/libshout-kh/examples/example.c	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/examples/example.c	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,68 @@
+/* example.c: Demonstration of the libshout API. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <shout/shout.h>
+
+int main(int argc, char **argv)
+{
+    FILE *fptr = stdin;
+	shout_t *shout;
+	char buff[4096];
+	long read, ret, total;
+
+	if (!(shout = shout_new())) {
+		printf("Could not allocate shout_t\n");
+		return 1;
+	}
+
+	if (shout_set_host(shout, "127.0.0.1") != SHOUTERR_SUCCESS) {
+		printf("Error setting hostname: %s\n", shout_get_error(shout));
+		return 1;
+	}
+	shout_set_user(shout, "source");
+	shout_set_password(shout, "hackem");
+	shout_set_port(shout, 8002);
+	if (shout_set_password(shout, "hackme") != SHOUTERR_SUCCESS) {
+		printf("Error setting password: %s\n", shout_get_error(shout));
+		return 1;
+	}
+	if (shout_set_mount(shout, "/example.ogg") != SHOUTERR_SUCCESS) {
+		printf("Error setting mount: %s\n", shout_get_error(shout));
+		return 1;
+	}
+	shout_set_format(shout, SHOUT_FORMAT_OGG);
+
+	if (shout_open(shout) == SHOUTERR_SUCCESS) {
+		printf("Connected to server...\n");
+		total = 0;
+        if (argc > 1)
+            fptr = fopen (argv[1], "rb");
+		while (1) {
+			read = fread(buff, 1, sizeof(buff), fptr);
+			total = total + read;
+
+			if (read > 0) {
+				ret = shout_send(shout, buff, read);
+				if (ret < SHOUTERR_SUCCESS) {
+					printf("DEBUG: Send error: %s\n", shout_get_error(shout));
+					break;
+				}
+			} else {
+				break;
+			}
+
+            printf ("delay is %d ms\n", shout_delay(shout));
+			shout_sync(shout);
+		}
+	} else {
+		printf("Error connecting: %s\n", shout_get_error(shout));
+	}
+
+	shout_close(shout);
+    fclose (fptr);
+
+	return 0;
+}

Added: icecast/branches/libshout-kh/examples/example2.c
===================================================================
--- icecast/branches/libshout-kh/examples/example2.c	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/examples/example2.c	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,72 @@
+/* example.c: Demonstration of the libshout API. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <shout/shout.h>
+
+shout_t *shout;
+
+int try()
+{
+	int ret;
+
+	if (shout_set_host(shout, "localhost") != SHOUTERR_SUCCESS) {
+		printf("Error setting hostname: %s\n", shout_get_error(shout));
+		return 1;
+	}
+	shout_set_port(shout, 8000);
+	if (shout_set_password(shout, "hackme") != SHOUTERR_SUCCESS) {
+		printf("Error setting password: %s\n", shout_get_error(shout));
+		return 1;
+	}
+	if (shout_set_mount(shout, "/example.ogg") != SHOUTERR_SUCCESS) {
+		printf("Error setting mount: %s\n", shout_get_error(shout));
+		return 1;
+	}
+	/* shout_set_format(shout, SHOUT_FORMAT_MP3); */
+    shout_set_nonblocking (shout, 1);
+
+    while (1)
+    {
+        ret = shout_open(shout) == SHOUTERR_SUCCESS;
+        if (ret == SHOUTERR_SUCCESS)
+        {
+            /* printf("Connected to server...\n"); */
+            break;
+        } else if (ret == SHOUTERR_PENDING)
+            printf ("pending\n");
+        else
+        {
+            printf("Error connecting: %s\n", shout_get_error(shout));
+        }
+        usleep (300);
+    }
+
+    shout_close(shout);
+
+	return 0;
+}
+
+int main()
+{
+    int countdown = 100;
+
+	if (!(shout = shout_new()))
+    {
+		printf("Could not allocate shout_t\n");
+		return 1;
+	}
+
+    while (--countdown)
+    {
+        try ();
+        usleep(100);
+    }
+    shout_free (shout);
+
+    return 0;
+}
+

Added: icecast/branches/libshout-kh/include/Makefile.am
===================================================================
--- icecast/branches/libshout-kh/include/Makefile.am	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/include/Makefile.am	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,14 @@
+## Process this file with automake to produce Makefile.in
+
+AUTOMAKE_OPTIONS = foreign
+
+SUBDIRS = shout
+
+# SCCS stuff (for BitKeeper)
+GET = true
+
+debug:
+	$(MAKE) all CFLAGS="@DEBUG@"
+
+profile:
+	$(MAKE) all CFLAGS="@PROFILE@"

Added: icecast/branches/libshout-kh/include/shout/Makefile.am
===================================================================
--- icecast/branches/libshout-kh/include/shout/Makefile.am	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/include/shout/Makefile.am	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,15 @@
+## Process this file with automake to produce Makefile.in
+
+AUTOMAKE_OPTIONS = foreign
+
+includedir = $(prefix)/include/shout
+nodist_include_HEADERS = shout.h
+
+# SCCS stuff (for BitKeeper)
+GET = bk get -Sq
+
+debug:
+	$(MAKE) all CFLAGS="@DEBUG@"
+
+profile:
+	$(MAKE) all CFLAGS="@PROFILE@"

Added: icecast/branches/libshout-kh/include/shout/shout.h.in
===================================================================
--- icecast/branches/libshout-kh/include/shout/shout.h.in	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/include/shout/shout.h.in	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,183 @@
+/*  shout.h
+**
+**  API for libshout, the streaming library for icecast
+*/
+#ifndef __LIBSHOUT_SHOUT_H__
+#define __LIBSHOUT_SHOUT_H__
+
+#include <sys/types.h>
+
+#define SHOUTERR_SUCCESS            (0)
+#define SHOUTERR_INSANE             (-1)
+#define SHOUTERR_NOCONNECT          (-2)
+#define SHOUTERR_NOLOGIN            (-3)
+#define SHOUTERR_SOCKET             (-4)
+#define SHOUTERR_MALLOC             (-5)
+#define SHOUTERR_METADATA           (-6)
+#define SHOUTERR_CONNECTED          (-7)
+#define SHOUTERR_UNCONNECTED        (-8)
+#define SHOUTERR_UNSUPPORTED        (-9)
+#define SHOUTERR_PENDING            (-11)
+#define SHOUTERR_BUSY               (-12)
+#define SHOUTERR_PENDING_FULL       (-13)
+
+#define SHOUT_FORMAT_VORBIS         (0)
+#define SHOUT_FORMAT_MP3            (1)
+#define SHOUT_FORMAT_VORBISPAGE     (2)
+#define SHOUT_FORMAT_OGG            (3)
+
+#define SHOUT_PROTOCOL_HTTP         (0)
+#define SHOUT_PROTOCOL_XAUDIOCAST   (1)
+#define SHOUT_PROTOCOL_ICY          (2)
+
+#define SHOUT_AI_BITRATE            "bitrate"
+#define SHOUT_AI_SAMPLERATE         "samplerate"
+#define SHOUT_AI_CHANNELS           "channels"
+#define SHOUT_AI_QUALITY            "quality"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct shout shout_t;
+typedef struct _util_dict shout_metadata_t;
+
+/* initializes the shout library. Must be called before anything else */
+void shout_init(void);
+
+/* shuts down the shout library, deallocating any global storage. Don't call
+ * anything afterwards */
+void shout_shutdown(void);
+
+/* returns a static version string.  Non-null parameters will be set to the
+ * value of the library major, minor, and patch levels, respectively */
+const char *shout_version(int *major, int *minor, int *patch);
+
+/* Allocates and sets up a new shout_t.  Returns NULL if it can't get enough
+ * memory.  The returns shout_t must be disposed of with shout_free. */
+shout_t *shout_new(void);
+
+/* Free all memory allocated by a shout_t */
+void shout_free(shout_t *self);
+
+/* Returns a statically allocated string describing the last shout error
+ * to occur.  Only valid until the next libshout call on this shout_t */
+const char *shout_get_error(shout_t *self);
+
+/* Return the error code (e.g. SHOUTERR_SOCKET) for this shout instance */
+int shout_get_errno(shout_t *self);
+
+/* returns SHOUTERR_CONNECTED or SHOUTERR_UNCONNECTED */
+int shout_get_connected(shout_t *self);
+
+/* Parameter manipulation functions.  libshout makes copies of all parameters,
+ * the caller may free its copies after giving them to libshout.  May return
+ * SHOUTERR_MALLOC */
+
+int shout_set_host(shout_t *self, const char *host);
+const char *shout_get_host(shout_t *self);
+
+int shout_set_port(shout_t *self, unsigned short port);
+unsigned short shout_get_port(shout_t *self);
+
+int shout_set_password(shout_t *, const char *password);
+const char *shout_get_password(shout_t *self);
+
+int shout_set_mount(shout_t *self, const char *mount);
+const char *shout_get_mount(shout_t *self);
+
+int shout_set_name(shout_t *self, const char *name);
+const char *shout_get_name(shout_t *self);
+
+int shout_set_url(shout_t *self, const char *url);
+const char *shout_get_url(shout_t *self);
+
+int shout_set_genre(shout_t *self, const char *genre);
+const char *shout_get_genre(shout_t *self);
+
+int shout_set_user(shout_t *self, const char *username);
+const char *shout_get_user(shout_t *self);
+
+int shout_set_agent(shout_t *self, const char *username);
+const char *shout_get_agent(shout_t *self);
+
+int shout_set_description(shout_t *self, const char *description);
+const char *shout_get_description(shout_t *self);
+
+int shout_set_dumpfile(shout_t *self, const char *dumpfile);
+const char *shout_get_dumpfile(shout_t *self);
+
+int shout_set_audio_info(shout_t *self, const char *name, const char *value);
+const char *shout_get_audio_info(shout_t *self, const char *name);
+
+int shout_set_public(shout_t *self, unsigned int make_public);
+unsigned int shout_get_public(shout_t *self);
+
+/* takes a SHOUT_FORMAT_xxxx argument */
+int shout_set_format(shout_t *self, unsigned int format);
+unsigned int shout_get_format(shout_t *self);
+
+/* takes a SHOUT_PROTOCOL_xxxxx argument */
+int shout_set_protocol(shout_t *self, unsigned int protocol);
+unsigned int shout_get_protocol(shout_t *self);
+
+/* Opens a connection to the server.  All parameters must already be set */
+int shout_open(shout_t *self);
+
+/* Closes a connection to the server */
+int shout_close(shout_t *self);
+
+/* Send data to the server, parsing it for format specific timing info */
+int shout_send(shout_t *self, const void *data, size_t len);
+
+/* Send unparsed data to the server.  Do not use this unless you know
+ * what you are doing.
+ * Returns the number of bytes written, or < 0 on error.
+ */
+int shout_send_raw (shout_t *self, const void *data, size_t len);
+
+
+/* Puts caller to sleep until it is time to send more data to the server */
+void shout_sync(shout_t *self);
+
+/* Amount of time in ms caller should wait before sending again */
+int shout_delay(shout_t *self);
+
+/* Sets MP3 metadata.
+ * Returns:
+ *   SHOUTERR_SUCCESS on success
+ *   SHOUTERR_UNSUPPORTED if protocol isn't Icy or X-Audiocast
+ */
+int shout_set_metadata(shout_t *self, shout_metadata_t *metadata);
+
+/* Allocates a new metadata structure.  Must be freed by shout_metadata_free. */
+shout_metadata_t *shout_metadata_new(void);
+
+/* Free resources allocated by shout_metadata_t */
+void shout_metadata_free(shout_metadata_t *self);
+
+/* Add a parameter to the metadata structure.
+ * Returns:
+ *   SHOUTERR_SUCCESS on success
+ *   SHOUTERR_INSANE if self isn't a valid shout_metadata_t* or name is null
+ *   SHOUTERR_MALLOC if memory can't be allocated */
+int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value);
+
+/* set/unset blocking mode on the shout socket */
+void shout_set_nonblocking (shout_t *self, const int nonblock);
+
+/* flush any outstanding buffers */
+int shout_send_pending (shout_t *self);
+
+/* report is connection is ready for audio data */
+int shout_connection_ready (shout_t *self);
+
+/* --- Compiled features --- */
+
+#define SHOUT_THREADSAFE @SHOUT_THREADSAFE@
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBSHOUT_SHOUT_H__ */

Added: icecast/branches/libshout-kh/shout.pc.in
===================================================================
--- icecast/branches/libshout-kh/shout.pc.in	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/shout.pc.in	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,14 @@
+# libshout pkg-config source file
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+cppflags=@SHOUT_CPPFLAGS@
+cflags_only=@SHOUT_CFLAGS@
+
+Name: Shout
+Description: Audio streaming library for icecast encoders
+Version: @VERSION@
+Libs: -L${libdir} -lshout @SHOUT_LIBDEPS@
+Cflags: @SHOUT_CPPFLAGS@ @SHOUT_CFLAGS@

Added: icecast/branches/libshout-kh/src/Makefile.am
===================================================================
--- icecast/branches/libshout-kh/src/Makefile.am	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/Makefile.am	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,25 @@
+## Process this with automake to create Makefile.in
+
+AUTOMAKE_OPTIONS = foreign
+
+SUBDIRS = avl net timing httpp thread
+
+lib_LTLIBRARIES = libshout.la
+libshout_la_LDFLAGS = -version-info 3:0:0
+AM_CFLAGS = @XIPH_CFLAGS@
+AM_CPPFLAGS = @XIPH_CPPFLAGS@
+
+noinst_HEADERS = shout_private.h util.h
+libshout_la_SOURCES = shout.c util.c ogg.c mp3.c
+
+libshout_la_LIBADD = net/libicenet.la timing/libicetiming.la avl/libiceavl.la\
+		httpp/libicehttpp.la thread/libicethread.la
+
+INCLUDES = -I$(top_builddir)/include
+
+debug:
+	$(MAKE) all CFLAGS="@DEBUG@"
+
+profile:
+	$(MAKE) all CFLAGS="@PROFILE@"
+

Added: icecast/branches/libshout-kh/src/mp3.c
===================================================================
--- icecast/branches/libshout-kh/src/mp3.c	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/mp3.c	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,325 @@
+/* mp3.c: libshout MP3 format handler
+ *
+ *  Copyright (C) 2002-2003 the Icecast team <team at icecast.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <shout/shout.h>
+#include "shout_private.h"
+
+/*
+ * MP3 frame handling courtesy of Scott Manley - may he always be Manley.
+ */
+
+#define MPEG_MODE_MONO 3
+
+/* -- local datatypes -- */
+typedef struct {
+	unsigned int frames;
+	/* the number of samples for the current frame */
+	int frame_samples;
+	/* the samplerate of the current frame */
+	int frame_samplerate;
+	/* how many bytes for the rest of this frame */
+	unsigned int frame_left;
+	/* is the header bridged?? */
+	int header_bridges;
+	/* put part of header here if it spans a boundary */
+	unsigned char header_bridge[3];
+} mp3_data_t;
+
+typedef struct {
+	int syncword;
+	int layer;
+	int version;
+	int error_protection;
+	int bitrate_index;
+	int samplerate_index;
+	int padding;
+	int extension;
+	int mode;
+	int mode_ext;
+	int copyright;
+	int original;
+	int emphasis;
+	int stereo;
+	int bitrate;
+	unsigned int samplerate;
+	unsigned int samples;
+	unsigned int framesize;
+} mp3_header_t;
+
+/* -- const data -- */
+static const unsigned int bitrate[3][3][16] =
+{
+	{
+		{ 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 },
+		{ 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 },
+		{ 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0 }
+	}, {
+		{ 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0 },
+		{ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 },
+		{ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 }
+	}, {
+		{ 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0 },
+		{ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 },
+		{ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 }
+	}
+};
+
+static const unsigned int samplerate[3][4] =
+{
+	{ 44100, 48000, 32000, 0 },
+	{ 22050, 24000, 16000, 0 },
+	{ 11025, 8000, 8000, 0 }
+};
+
+/* -- static prototypes -- */
+static int send_mp3(shout_t *self, const void *data, unsigned len);
+static void close_mp3(shout_t *self);
+
+static void parse_header(mp3_header_t *mh, uint32_t header);
+static int mp3_header(uint32_t head, mp3_header_t *mh);
+
+int shout_open_mp3(shout_t *self)
+{
+	mp3_data_t *mp3_data;
+
+    self->error = SHOUTERR_MALLOC;
+	if ((mp3_data = (mp3_data_t *)calloc(1, sizeof(mp3_data_t))) == NULL)
+		return -1;
+	self->format_data = mp3_data;
+
+	self->send = send_mp3;
+	self->close = close_mp3;
+    self->mime_type = "audio/mpeg";
+
+    self->error = SHOUTERR_SUCCESS;
+	return 0;
+}
+
+static int send_mp3(shout_t* self, const void *in_buff, unsigned len)
+{
+    const unsigned char *buff = in_buff;
+	mp3_data_t* mp3_data = (mp3_data_t*) self->format_data;
+	unsigned long pos;
+	uint32_t head;
+	int ret, count;
+	int start, end, error, i;
+	unsigned char *bridge_buff;
+	mp3_header_t mh;
+
+	bridge_buff = NULL;
+	pos = 0;
+	start = 0;
+	error = 0;
+	end = len - 1;
+	memset(&mh, 0, sizeof(mh));
+
+	/* finish the previous frame */
+	if (mp3_data->frame_left > 0) {
+		/* is the rest of the frame here? */
+		if (mp3_data->frame_left <= len) {
+			self->senttime += (int64_t)((double)mp3_data->frame_samples / (double)mp3_data->frame_samplerate * 1000000);
+			mp3_data->frames++;
+			pos += mp3_data->frame_left;
+			mp3_data->frame_left = 0;
+		} else {
+			mp3_data->frame_left -= len;
+			pos = len;
+		}
+	}
+
+	/* header was over the boundary, so build a new build a new buffer */
+	if (mp3_data->header_bridges) {
+		bridge_buff = (unsigned char *)malloc(len + mp3_data->header_bridges);
+		if (bridge_buff == NULL) {
+			return self->error = SHOUTERR_MALLOC;
+		}
+
+		bridge_buff[0] = mp3_data->header_bridge[0];
+		bridge_buff[1] = mp3_data->header_bridge[1];
+		bridge_buff[2] = mp3_data->header_bridge[2];
+
+		memcpy(&bridge_buff[mp3_data->header_bridges], buff, len);
+
+		buff = bridge_buff;
+		len += mp3_data->header_bridges;
+		end = len - 1;
+
+		mp3_data->header_bridges = 0;
+	}
+
+	/** this is the main loop
+	*** we handle everything but the last 4 bytes...
+	**/
+	while ((pos + 4) <= len) {
+		/* find mp3 header */
+		head = (buff[pos] << 24) |
+			(buff[pos + 1] << 16) |
+			(buff[pos + 2] << 8) |
+			(buff[pos + 3]);
+
+		/* is this a valid header? */
+		if (mp3_header(head, &mh)) {
+			if (error) {
+				start = pos;
+				end = len - 1;
+				error = 0;
+			}
+
+			mp3_data->frame_samples = mh.samples;
+			mp3_data->frame_samplerate = mh.samplerate;
+
+			/* do we have a complete frame in this buffer? */
+			if (len - pos >= mh.framesize) {
+				self->senttime += (int64_t)((double)mp3_data->frame_samples / (double)mp3_data->frame_samplerate * 1000000);
+				mp3_data->frames++;
+				pos += mh.framesize;
+			} else {
+				mp3_data->frame_left = mh.framesize - (len - pos);
+				pos = len;
+			}
+		} else {
+			/* there was an error
+			** so we send all the valid data up to this point
+			*/
+			if (!error) {
+				error = 1;
+				end = pos - 1;
+				count = end - start + 1;
+				if (count > 0)
+					ret = shout_send_raw (self, (char *)&buff[start], count);
+				else
+					ret = 0;
+
+				if (ret != count) {
+					if (bridge_buff != NULL)
+						free(bridge_buff);
+					return self->error = SHOUTERR_SOCKET;
+				}
+			}
+			pos++;
+		}
+	}
+
+	/* catch the tail if there is one */
+	if ((pos > (len - 4)) && (pos < len)) {
+		end = pos - 1;
+
+		i = 0;
+		while (pos < len) {
+			mp3_data->header_bridge[i] = buff[pos];
+			pos++;
+			i++;
+		}
+		mp3_data->header_bridges = i;
+	}
+
+	if (!error) {
+		/* if there's no errors, lets send the frames */
+		count = end - start + 1;
+		if (count > 0)
+            ret = shout_send_raw (self, (char *)&buff[start], count);
+		else
+			ret = 0;
+
+		if (bridge_buff != NULL)
+			free(bridge_buff);
+
+		if (ret == count) {
+			return self->error = SHOUTERR_SUCCESS;
+		} else {
+			return self->error = SHOUTERR_SOCKET;
+		}
+	}
+
+	if (bridge_buff != NULL)
+		free(bridge_buff);
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+static void parse_header(mp3_header_t *mh, uint32_t header)
+{
+	mh->syncword = (header >> 20) & 0x0fff;
+	mh->version = ((header >> 19) & 0x01) ? 0 : 1;
+	if ((mh->syncword & 0x01) == 0)
+		mh->version = 2;
+	mh->layer = 3 - ((header >> 17) & 0x03);
+	mh->error_protection = ((header >> 16) & 0x01) ? 0 : 1;
+	mh->bitrate_index = (header >> 12) & 0x0F;
+	mh->samplerate_index = (header >> 10) & 0x03;
+	mh->padding = (header >> 9) & 0x01;
+	mh->extension = (header >> 8) & 0x01;
+	mh->mode = (header >> 6) & 0x03;
+	mh->mode_ext = (header >> 4) & 0x03;
+	mh->copyright = (header >> 3) & 0x01;
+	mh->original = (header >> 2) & 0x01;
+	mh->emphasis = header & 0x03;
+
+	mh->stereo = (mh->mode == MPEG_MODE_MONO) ? 1 : 2;
+	mh->bitrate = bitrate[mh->version][mh->layer][mh->bitrate_index];
+	mh->samplerate = samplerate[mh->version][mh->samplerate_index];
+
+	if (mh->version == 0)
+		mh->samples = 1152;
+	else
+		mh->samples = 576;
+
+	if(mh->samplerate)
+		mh->framesize = (mh->samples * mh->bitrate * 1000 / mh->samplerate) / 8 + mh->padding;
+}
+
+/* mp3 frame parsing stuff */
+static int mp3_header(uint32_t head, mp3_header_t *mh)
+{
+	/* fill out the header struct */
+	parse_header(mh, head);
+
+	/* check for syncword */
+	if ((mh->syncword & 0x0ffe) != 0x0ffe)
+		return 0;
+
+	/* check for the right layer */
+	if (mh->layer != 2)
+		return 0;
+
+	/* make sure bitrate is sane */
+	if (mh->bitrate == 0)
+		return 0;
+
+	/* make sure samplerate is sane */
+	if (mh->samplerate == 0)
+		return 0;
+
+	return 1;
+}
+
+static void close_mp3(shout_t *self)
+{
+	mp3_data_t *mp3_data = (mp3_data_t *)self->format_data;
+
+	free(mp3_data);
+}

Added: icecast/branches/libshout-kh/src/ogg.c
===================================================================
--- icecast/branches/libshout-kh/src/ogg.c	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/ogg.c	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,596 @@
+/* vorbis.c: Ogg Vorbis data handlers for libshout
+ *
+ * Copyright(c) 2003 Karl Heyes <karl at xiph.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; See the file COPYING;
+ * if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <ogg/ogg.h>
+#include <vorbis/codec.h>
+#ifdef HAVE_THEORA
+#include <theora/theora.h>
+#endif
+
+#include <shout/shout.h>
+#include "shout_private.h"
+
+
+typedef struct _ogg_codec_tag
+{
+    char *name;
+    ogg_stream_state os;
+    unsigned headers;
+    uint64_t senttime;
+    void *specific;
+    struct _ogg_codec_tag *next;
+    int (*process_page)(shout_t *shout, struct _ogg_codec_tag *codec, ogg_page *page);
+    void (*codec_free)(struct _ogg_codec_tag *codec);
+} ogg_codec_t;
+
+
+typedef struct _ogg_info_tag
+{
+    ogg_sync_state oy;
+
+    ogg_codec_t *codecs;
+    int headers_completed;
+    int not_in_bos;
+} ogg_info_t;
+
+
+typedef struct _vorbis_codec_tag
+{
+    vorbis_info vi;
+    vorbis_comment vc;
+    int prevW;
+} vorbis_codec_t;
+
+
+
+/* -- static prototypes -- */
+static int send_oggpage (shout_t *self, const void *ptr,  unsigned len);
+static int send_ogg (shout_t *self, const void *ptr, unsigned len);
+static void close_ogg (shout_t *self);
+
+
+static void free_ogg_codecs (ogg_info_t *ogg_info)
+{
+    ogg_codec_t *codec;
+
+    if (ogg_info == NULL)
+       return;
+    // printf ("codec handlers are being cleared\n");
+    codec = ogg_info->codecs;
+    while (codec)
+    {
+        ogg_codec_t *next = codec->next;
+        codec->codec_free (codec);
+        codec = next;
+    }
+    ogg_info->codecs = NULL;
+    ogg_info->headers_completed = 0;
+}
+
+
+static void vorbis_codec_free (ogg_codec_t *codec)
+{
+    vorbis_codec_t *vorbis = codec->specific;
+
+    vorbis_info_clear (&vorbis->vi);
+    vorbis_comment_clear (&vorbis->vc);
+    ogg_stream_clear (&codec->os);
+    free (vorbis);
+    free (codec);
+}
+
+
+int shout_open_vorbis(shout_t *self)
+{
+    if (self->format == SHOUT_FORMAT_VORBISPAGE)
+        self->send = send_oggpage;
+    else
+    {
+        ogg_info_t *ogg_info;
+
+        self->error = SHOUTERR_MALLOC;
+        ogg_info = (ogg_info_t *)calloc (1, sizeof (ogg_info_t));
+        if (ogg_info == NULL)
+            return -1;
+        self->format_data = ogg_info;
+
+        ogg_sync_init (&ogg_info->oy);
+
+        self->send = send_ogg;
+    }
+	self->close = close_ogg;
+    self->mime_type = "application/ogg";
+
+    self->error = SHOUTERR_SUCCESS;
+	return 0;
+}
+
+
+static int blocksize (vorbis_codec_t *vd, ogg_packet *p)
+{
+    int this = vorbis_packet_blocksize(&vd->vi, p);
+    int ret = (this + vd->prevW)/4;
+
+    if(!vd->prevW) {
+        vd->prevW = this;
+        return 0;
+    }
+
+    vd->prevW = this;
+    return ret;
+}
+
+static int process_vorbis_page (shout_t *shout, ogg_codec_t *codec, ogg_page *page)
+{
+    ogg_packet packet;
+    vorbis_codec_t *vorbis = codec->specific;
+    int ret;
+
+    ogg_stream_pagein (&codec->os, page);
+    if (codec->headers < 3)
+    {
+
+        while (ogg_stream_packetout (&codec->os, &packet) > 0)
+        {
+           if (vorbis_synthesis_headerin (&vorbis->vi, &vorbis->vc, &packet) < 0)
+           {
+               /* set some error code */
+               return 0;
+           }
+           codec->headers++;
+        }
+    }
+    else
+    {
+        /* work out the number of samples in each page */
+        unsigned samples = 0;
+
+        while (ogg_stream_packetout (&codec->os, &packet) == 1)
+        {
+            unsigned size = blocksize (vorbis, &packet);
+            samples += size;
+        }
+        codec->senttime += (((uint64_t)samples * 1000000) / vorbis->vi.rate);
+        if (shout->senttime < codec->senttime)
+            shout->senttime = codec->senttime;
+#if 0
+        else
+            if (shout->senttime - codec->senttime > 300000)
+                printf ("vorbis lag of %lld\n", shout->senttime - codec->senttime);
+        printf ("vorbis sentime %lld\n", codec->senttime);
+#endif
+    }
+    ret = shout_send_raw (shout, page->header, page->header_len);
+    if (ret < page->header_len)
+        return -1;
+    ret = shout_send_raw (shout, page->body, page->body_len);
+    if (ret < page->body_len)
+        return -1;
+
+    return page->header_len + page->body_len;
+}
+
+
+static ogg_codec_t *initial_vorbis_page (shout_t *shout, ogg_page *page)
+{
+    ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
+    ogg_packet packet;
+
+    vorbis_codec_t *vorbis_codec = calloc (1, sizeof (vorbis_codec_t));
+
+    ogg_stream_init (&codec->os, ogg_page_serialno (page));
+    ogg_stream_pagein (&codec->os, page);
+
+    vorbis_info_init (&vorbis_codec->vi);
+    vorbis_comment_init (&vorbis_codec->vc);
+
+    ogg_stream_packetout (&codec->os, &packet);
+
+    codec->name = "Vorbis";
+    do
+    {
+        int ret;
+
+        if (vorbis_synthesis_headerin (&vorbis_codec->vi, &vorbis_codec->vc, &packet) < 0)
+        {
+            break;
+        }
+        codec->specific = vorbis_codec;
+        codec->process_page = process_vorbis_page;
+        codec->codec_free = vorbis_codec_free;
+        codec->headers = 1;
+        codec->senttime = shout->senttime;
+
+        ret = shout_send_raw (shout, page->header, page->header_len);
+        if (ret < 0)
+            break;
+        ret = shout_send_raw (shout, page->body, page->body_len);
+        if (ret < 0)
+            break;
+
+        return codec;
+    } while (0);
+
+    ogg_stream_clear (&codec->os);
+    vorbis_info_clear (&vorbis_codec->vi);
+    vorbis_comment_clear (&vorbis_codec->vc);
+    free (vorbis_codec);
+    free (codec);
+    return NULL;
+}
+
+#ifdef HAVE_THEORA
+typedef struct _theora_codec_tag
+{
+    theora_info ti;
+    theora_comment tc;
+    uint32_t granule_shift;
+    double prev_time;
+} theora_codec_t;
+
+
+static void theora_codec_free (ogg_codec_t *codec)
+{
+    theora_codec_t *theora = codec->specific;
+
+    theora_info_clear (&theora->ti);
+    theora_comment_clear (&theora->tc);
+    ogg_stream_clear (&codec->os);
+    free (theora);
+    free (codec);
+}
+
+
+static int _ilog (unsigned int v)
+{
+    int ret=0;
+    while(v){
+        ret++;
+        v>>=1;
+    }
+    return ret;
+}
+
+
+static int process_theora_page (shout_t *shout, ogg_codec_t *codec, ogg_page *page)
+{
+    theora_codec_t *theora = codec->specific;
+    ogg_packet packet;
+    int ret;
+
+    ogg_stream_pagein (&codec->os, page);
+    if (ogg_page_granulepos (page) == 0)
+    {
+        while (ogg_stream_packetout (&codec->os, &packet) > 0)
+        {
+           if (theora_decode_header (&theora->ti, &theora->tc, &packet) < 0)
+           {
+               /* set some error code */
+               // fprintf (stderr, "error from theora decode header\n");
+               return -1;
+           }
+           codec->headers++;
+        }
+        if (codec->headers == 3)
+        {
+            theora->prev_time = 0.0;
+            theora->granule_shift = _ilog (theora->ti.keyframe_frequency_force - 1);
+            // printf ("fps values %ld, %ld\n", theora->ti.fps_denominator , theora->ti.fps_numerator);
+        }
+    }
+    else
+    {
+        // double fps = theora->ti.fps_numerator / theora->ti.fps_denominator;
+        double per_frame = (double)theora->ti.fps_denominator / theora->ti.fps_numerator * 1000000;
+        double duration;
+#if 0
+        double from_start;
+        from_start = theora_granule_time (&theora->ti, ogg_page_granulepos (page));
+        duration = (from_start - theora->prev_time) * 1000000;
+#endif
+#if 0
+        int packets = ogg_page_packets(page);
+
+        duration = (packets / fps) * 1000000.0;
+        printf ("packets %d, fps is %.2f, duration %.3f\n", packets, fps, duration);
+        codec->senttime += (uint64_t)(duration + 0.5);
+#endif
+        ogg_int64_t granulepos = ogg_page_granulepos (page);
+        if (granulepos > 0)
+        {
+            ogg_int64_t iframe = granulepos >> theora->granule_shift;
+            ogg_int64_t pframe = granulepos - (iframe << theora->granule_shift);
+
+            uint64_t frames = iframe + pframe;
+            double new_time = (frames  * per_frame);
+            duration = new_time - theora->prev_time;
+            // printf ("frames %lld (%.2f), new %.2f, prev %.2f\n", frames, per_frame, new_time, theora->prev_time);
+            theora->prev_time = new_time;
+
+            codec->senttime += (uint64_t)(duration + 0.5);
+            if (shout->senttime < codec->senttime)
+                shout->senttime = codec->senttime;
+#if 0
+            else
+                if (shout->senttime - codec->senttime > 300000)
+                    printf ("theora lag of %lld\n", shout->senttime - codec->senttime);
+#endif
+        }
+        // printf ("theora sentime %lld\n", codec->senttime);
+    }
+    // printf ("page no is %ld\n", ogg_page_pageno (page));
+    ret = shout_send_raw (shout, page->header, page->header_len);
+    if (ret < page->header_len)
+        return -1;
+    ret = shout_send_raw (shout, page->body, page->body_len);
+    if (ret < page->body_len)
+        return -1;
+
+    return page->header_len + page->body_len;
+}
+
+
+static ogg_codec_t *initial_theora_page (shout_t *shout, ogg_page *page)
+{
+    ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
+    ogg_packet packet;
+
+    theora_codec_t *theora_codec = calloc (1, sizeof (theora_codec_t));
+
+    ogg_stream_init (&codec->os, ogg_page_serialno (page));
+    ogg_stream_pagein (&codec->os, page);
+
+    theora_info_init (&theora_codec->ti);
+    theora_comment_init (&theora_codec->tc);
+
+    ogg_stream_packetout (&codec->os, &packet);
+
+    do
+    {
+        int ret;
+
+        if (theora_decode_header (&theora_codec->ti, &theora_codec->tc, &packet) < 0)
+        {
+            break;
+        }
+        codec->specific = theora_codec;
+        codec->process_page = process_theora_page;
+        codec->codec_free = theora_codec_free;
+        codec->headers = 1;
+        codec->senttime = shout->senttime;
+
+        ret = shout_send_raw (shout, page->header, page->header_len);
+        if (ret < page->header_len)
+            break;
+        ret = shout_send_raw (shout, page->body, page->body_len);
+        if (ret < page->body_len)
+            break;
+
+        codec->name = "Theora";
+
+        return codec;
+    } while (0);
+
+    ogg_stream_clear (&codec->os);
+    theora_info_clear (&theora_codec->ti);
+    theora_comment_clear (&theora_codec->tc);
+    free (theora_codec);
+    free (codec);
+    return NULL;
+}
+#endif
+
+/* catch all for unknown codecs */
+
+static void unhandled_codec_free (ogg_codec_t *codec)
+{
+    ogg_stream_clear (&codec->os);
+    free (codec);
+}
+
+
+static int process_unhandled_page (shout_t *shout, ogg_codec_t *codec, ogg_page *page)
+{
+    int ret;
+
+    ret = shout_send_raw (shout, page->header, page->header_len);
+    if (ret < 0)
+        return SHOUTERR_SOCKET;
+    ret = shout_send_raw (shout, page->body, page->body_len);
+
+    return ret;
+}
+
+
+static ogg_codec_t *initial_unhandled_page (shout_t *shout, ogg_page *page)
+{
+    ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
+    codec->process_page = process_unhandled_page;
+    codec->codec_free = unhandled_codec_free;
+    codec->name = "not timed";
+    ogg_stream_init (&codec->os, ogg_page_serialno (page));
+
+    do
+    {
+        int ret = shout_send_raw (shout, page->header, page->header_len);
+        if (ret < 0)
+            break;
+        ret = shout_send_raw (shout, page->body, page->body_len);
+        if (ret < 0)
+            break;
+        return codec;
+    } while (0);
+
+    ogg_stream_clear (&codec->os);
+    free (codec);
+    return NULL;
+}
+
+
+static int process_initial_page (shout_t *shout, ogg_page *page)
+{
+	ogg_info_t *ogg_info = (ogg_info_t *)shout->format_data;
+    ogg_codec_t *codec;
+    int ret = SHOUTERR_SUCCESS;
+
+    if (ogg_info->not_in_bos)
+    {
+        free_ogg_codecs (ogg_info);
+    }
+    ogg_info->not_in_bos = 0;
+    do
+    {
+        codec = initial_vorbis_page (shout, page);
+        if (codec)
+            break;
+#ifdef HAVE_THEORA
+        codec = initial_theora_page (shout, page);
+        if (codec)
+            break;
+#endif
+        /* any others */
+        codec = initial_unhandled_page (shout, page);
+        if (codec)
+            break;
+        shout->error = SHOUTERR_INSANE;
+        ret = -1;
+
+    } while (0);
+
+    if (codec)
+    {
+        /* add codec to list */
+        /* printf ("Adding codec handler (%s) to list\n", codec->name); */
+        codec->next = ogg_info->codecs;
+        ogg_info->codecs = codec;
+    }
+    return ret;
+}
+
+
+static int send_ogg (shout_t *self, const void *ptr, unsigned len)
+{
+	ogg_info_t *ogg_info = (ogg_info_t *)self->format_data;
+	ogg_page page;
+    void *buffer;
+
+    /* lets chop up the data into pages */
+	buffer = ogg_sync_buffer (&ogg_info->oy, len);
+	memcpy (buffer, ptr, len);
+	ogg_sync_wrote (&ogg_info->oy, len);
+
+	while (ogg_sync_pageout (&ogg_info->oy, &page) == 1)
+    {
+        ogg_codec_t *codec;
+
+        if (ogg_page_bos (&page))
+        {
+            /* printf ("serial of bos page is %d\n", ogg_page_serialno (&page)); */
+            process_initial_page (self, &page);
+            return self->error;
+        }
+        ogg_info->not_in_bos = 1;
+
+        codec = ogg_info->codecs;
+        while (codec)
+        {
+            if (ogg_page_serialno (&page) == codec->os.serialno)
+            {
+                // printf ("page handler is %s, %lld", codec->name, codec->senttime);
+                codec->process_page (self, codec, &page);
+                // printf ("\n");
+                return self->error;
+            }
+
+            codec = codec->next;
+        }
+    }
+    return 0;
+}
+
+
+static void close_ogg(shout_t *self)
+{
+   free_ogg_codecs (self->format_data);
+}
+
+
+static int send_oggpage (shout_t *self, const void *ptr, unsigned unused)
+{
+    const ogg_page *page = ptr;
+    unsigned len = page->header_len + page->body_len;
+
+    if (self->pending_queue == NULL)
+    {
+        struct iovec vecs [2];
+        int ret;
+
+        vecs[0] . iov_base = page->header;
+        vecs[0] . iov_len  = page->header_len;
+        vecs[1] . iov_base = page->body;
+        vecs[1] . iov_len  = page->body_len;
+
+        ret = sock_writev (self->socket, vecs, 2);
+        if (ret == (int)len)
+            return self->error = SHOUTERR_SUCCESS;
+        if (ret < 0)
+        {
+            if (sock_recoverable (sock_error()))
+                ret = 0;
+            else
+            {
+                self->state = SHOUT_NOCONNECT;
+                return self->error = SHOUTERR_SOCKET;
+            }
+        }
+        if (ret < page->header_len)
+        {
+            if (shout_queue_raw (self, page->header+ret, page->header_len-ret) < 0)
+                return self->error;
+            ret = 0;
+        }
+        else
+            ret -= page->header_len;
+        if (shout_queue_raw (self, page->body+ret, page->body_len-ret) < 0)
+            return self->error;
+
+        return self->error = SHOUTERR_SUCCESS;
+    }
+    if (shout_queue_raw (self, page->header, page->header_len) < 0)
+        return self->error;
+    if (shout_queue_raw (self, page->body, page->body_len) < 0)
+        return self->error;
+
+    if (shout_send_pending (self) < 0)
+        return self->error;
+
+    return self->error = SHOUTERR_SUCCESS;
+}
+

Added: icecast/branches/libshout-kh/src/shout.c
===================================================================
--- icecast/branches/libshout-kh/src/shout.c	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/shout.c	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,1315 @@
+/* shout.c  Implementation of public libshout interface shout.h
+ *
+ * Copyright(c) 2003-4 Karl Heyes <karl at xiph.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; see the file COPYING; if not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <shout/shout.h>
+#include <net/sock.h>
+#include <timing/timing.h>
+#include <httpp/httpp.h>
+#include <thread/thread.h>
+
+#include "shout_private.h"
+#include "util.h"
+
+/* -- local prototypes -- */
+static char *http_basic_authorization(shout_t *self);
+
+/* -- static data -- */
+static int _initialized = 0;
+
+
+static void shout_free_pending (shout_t *self)
+{
+    struct shout_pending_node *node = self->pending_queue, *next;
+
+    while (node)
+    {
+        next = node->next;
+
+        if (node->data)
+            free (node->data);
+        free (node);
+
+        node = next;
+    }
+    self->pending_total = 0;
+    self->pending_queue = NULL;
+    self->pending_queue_tail = &self->pending_queue;
+}
+
+
+static int shout_try_write (shout_t *self, const void *data, unsigned len)
+{
+    int ret = sock_write_bytes (self->socket, data, len);
+
+    if (ret < 0)
+    {
+        if (sock_recoverable (sock_error()))
+        {
+            self->error = SHOUTERR_BUSY;
+            return 0;
+        }
+        self->error = SHOUTERR_SOCKET;
+    }
+    return ret;
+}
+
+
+/* -- static function definitions -- */
+static char *http_basic_authorization(shout_t *self)
+{
+    char *out, *in;
+    int len;
+
+    if (!self || !self->user || !self->password)
+        return NULL;
+
+    len = strlen(self->user) + strlen(self->password) + 2;
+    if (!(in = malloc(len)))
+        return NULL;
+    sprintf(in, "%s:%s", self->user, self->password);
+    out = util_base64_encode(in);
+    free(in);
+
+    len = strlen(out) + 24;
+    if (!(in = malloc(len))) {
+        free(out);
+        return NULL;
+    }
+    sprintf(in, "Authorization: Basic %s\r\n", out);
+    free(out);
+
+    return in;
+}
+
+
+static int shout_connect (shout_t *self)
+{
+    if (self->pending_connection)
+    {
+        int ret;
+
+        self->error = SHOUTERR_PENDING;
+        switch (sock_connected (self->socket, 0))
+        {
+            case 1:
+                self->error = SHOUTERR_SUCCESS;
+                self->state = SHOUT_CONNECTED;
+                self->pending_connection = 0;
+                return 0;
+            case SOCK_ERROR:
+                self->error = SHOUTERR_NOCONNECT;
+                self->pending_connection = 0;
+                /* fall thru */
+            case SOCK_TIMEOUT:
+            default:
+                return -1;
+        }
+    }
+
+    if (self->nonblocking)
+    {
+        self->error = SHOUTERR_PENDING;
+        self->socket = sock_connect_non_blocking (self->host, self->port);
+        if (self->socket < 0)
+            self->error = SHOUTERR_NOCONNECT;
+        else
+            self->pending_connection = 1;
+        return -1;
+    }
+    else
+    {
+        self->error = SHOUTERR_NOCONNECT;
+        self->socket = sock_connect(self->host, self->port);
+        if (self->socket < 0)
+            return -1;
+        self->error = SHOUTERR_SUCCESS;
+        self->state = SHOUT_CONNECTED;
+        return 0;
+    }
+}
+
+
+int shout_send_pending (shout_t *self)
+{
+    if (self->pending_queue == NULL)
+        return 0;
+    else
+    {
+        struct shout_pending_node *node = self->pending_queue;
+        int written;
+
+        while (node)
+        {
+            written = shout_try_write (self, node->start, node->len);
+            if (written == (int)node->len)
+            {
+                self->pending_queue = node->next;
+                if (self->pending_queue == NULL)
+                    self->pending_queue_tail = &self->pending_queue;
+                free (node->data);
+                free (node);
+                node = self->pending_queue;
+                self->pending_total -= written;
+            }
+            else
+            {
+                if (written < 0)
+                    return -1;
+
+                node->start = (char*)node->start+written;
+                node->len -= written;
+                self->pending_total -= written;
+                self->error = SHOUTERR_SUCCESS;
+                break;
+            }
+        }
+    }
+    self->error = SHOUTERR_SUCCESS;
+
+    return 0;
+}
+
+
+static int create_http_request (shout_t *self)
+{
+    int ret = -1;
+    char *auth = NULL, *data = NULL;
+    self->error = SHOUTERR_MALLOC;
+
+    while (1)
+    {
+        if (add_send_header (self, "SOURCE %s HTTP/1.0\r\n", self->mount))
+            break;
+
+        if (add_send_header (self, "ice-name: %s\r\n", self->name != NULL ? self->name : "no name"))
+            break;
+        if (self->url)
+            if (add_send_header (self, "ice-url: %s\r\n", self->url))
+                break;
+        if (self->genre)
+            if (add_send_header (self, "ice-genre: %s\r\n", self->genre))
+                break;
+        if ((data = util_dict_urlencode(self->audio_info, ';')))
+            if (add_send_header (self, "ice-audio-info: %s\r\n", data))
+                break;
+        if (add_send_header (self, "ice-public: %d\r\n", self->public))
+            break;
+        if (self->description)
+            if (add_send_header (self, "ice-description: %s\r\n", self->description))
+                break;
+        if (self->useragent)
+            if (add_send_header (self, "User-Agent: %s\r\n", self->useragent))
+                break;
+        if (add_send_header (self, "Content-Type: %s\r\n", self->mime_type))
+            break;
+        auth = http_basic_authorization (self);
+        if (auth == NULL)
+        {
+            self->error = SHOUTERR_INSANE;
+            break; /* need username and password */
+        }
+        else
+        {
+            if (add_send_header (self, "%s", auth))
+                break;
+        }
+        if (add_send_header (self, "\r\n"))
+            break;
+        ret = 0;
+        self->error = SHOUTERR_SUCCESS;
+        break;
+    }
+    if (data)  free (data);
+
+    return ret;
+}
+
+
+static int send_request(shout_t *self)
+{
+    switch (self->state)
+    {
+        case SHOUT_REQ_SENT:
+            self->error = SHOUTERR_CONNECTED;
+            return 0;
+
+        case SHOUT_CONNECTED:
+            if (self->create_request)
+            {
+                if (self->create_request (self) < 0)
+                    return -1;
+                self->state = SHOUT_REQ_MADE;
+                /* ok, we've made the header */
+            }
+            else
+                break;
+
+        case SHOUT_REQ_MADE:
+            if (shout_send_raw (self, self->send_header + self->send_header_offset,
+                    self->send_header_size - self->send_header_offset) < 0)
+                 return -1;
+            break;
+        default:
+            self->error = SHOUTERR_INSANE;
+            return -1;
+    }
+    self->state = SHOUT_REQ_SENT;
+    self->response_senttime = time(NULL);
+    return 0;
+}
+
+
+
+static int shout_read_response (shout_t *self)
+{
+    char *ptr;
+
+    shout_send_pending (self);
+    if (self->state == SHOUT_REQ_SENT)
+    {
+        self->error = SHOUTERR_SOCKET;
+        while (1)
+        {
+            int bytes;
+            char  *start;
+
+            if (self->nonblocking == 0)
+            {
+                switch (sock_read_pending (self->socket, self->read_timeout*1000))
+                {
+                    case SOCK_ERROR:
+                        self->error = SHOUTERR_SOCKET;
+                        return -1;
+                    case SOCK_TIMEOUT:
+                        self->error = SHOUTERR_NOCONNECT;
+                        return -1;
+                    default:
+                        break;
+                }
+            }
+            else
+            {
+                time_t now = time (NULL);
+                if ((time_t)(self->response_senttime + self->read_timeout) < now)
+                {
+                    self->error = SHOUTERR_NOCONNECT;
+                    return -1;
+                }
+                self->error = SHOUTERR_PENDING;
+                switch (sock_read_pending (self->socket, 0))
+                {
+                    case SOCK_ERROR:
+                        self->error = SHOUTERR_SOCKET;
+                    case SOCK_TIMEOUT:
+                    case 0:
+                        return -1;
+                    default:
+                        break;
+                }
+            }
+            bytes = sock_read_bytes (self->socket, self->response + self->response_len,
+                    MAX_HTTP_RESPONSE - self->response_len - 1);
+            if (bytes == 0)
+            {
+                self->error = SHOUTERR_SOCKET;
+                return -1;
+            }
+            if (bytes < 0)
+            {
+                if (sock_stalled (sock_error()))
+                    self->error = SHOUTERR_PENDING;
+                return -1;
+            }
+
+            /* lets get rid of any '\r' in '\r\n' sequences */
+            start = ptr = (char *)(self->response + self->response_len);
+            ptr [bytes] = '\0';
+            while (1)
+            {
+                char * tmp_ptr;
+                tmp_ptr = strstr (ptr, "\r\n");
+                if (tmp_ptr)
+                {
+                    memmove (tmp_ptr, tmp_ptr+1, bytes-(tmp_ptr-ptr));
+                    bytes--;  /* removed \r */
+                    ptr = tmp_ptr+1;
+                }
+                else
+                    break;
+            }
+            self->response_len += bytes;
+
+            if (strstr (start, "\n\n"))
+                break;
+        }
+
+        self->error = SHOUTERR_SUCCESS;
+        return self->response_len;
+    }
+    self->error = SHOUTERR_INSANE;
+    return -1;
+}
+
+
+static int shout_login (shout_t *self)
+{
+    if (self->state == SHOUT_NOCONNECT && shout_connect (self) < 0)
+        return -1;
+
+    if (send_request (self) < 0)
+        return -1;
+
+    if (self->get_response (self) < 0)
+        return -1;
+    self->state = SHOUT_READY;
+    return 0;
+}
+
+
+static int login_http(shout_t *self)
+{
+    http_parser_t *parser;
+    int code;
+    char *retcode;
+
+    if (shout_read_response (self) < 0)
+        return -1;
+
+    self->error = SHOUTERR_NOLOGIN;
+    parser = httpp_create_parser();
+    httpp_initialize (parser, NULL);
+    if (httpp_parse_response (parser, (char*)self->response, self->response_len, self->mount))
+    {
+        retcode = httpp_getvar (parser, HTTPP_VAR_ERROR_CODE);
+        code = atoi(retcode);
+        if (code >= 200 && code < 300)
+        {
+            httpp_destroy (parser);
+            self->error = SHOUTERR_SUCCESS;
+            return 0;
+        }
+    }
+
+    httpp_destroy (parser);
+    return -1;
+}
+
+
+static int create_xaudiocast_request (shout_t *self)
+{
+    int ret = -1;
+
+    while (1)
+    {
+        self->error = SHOUTERR_SOCKET;
+        if (add_send_header (self, "SOURCE %s %s\r\n", self->password, self->mount))
+            break;
+
+        if (add_send_header (self, "x-audiocast-name: %s\n", self->name != NULL ? self->name : "unnamed"))
+            break;
+        if (add_send_header (self, "x-audiocast-url: %s\n", self->url != NULL ? self->url : "http://www.icecast.org/"))
+            break;
+        if (add_send_header (self, "x-audiocast-genre: %s\n", self->genre != NULL ? self->genre : "icecast"))
+            break;
+        if (add_send_header (self, "x-audiocast-bitrate: %i\n", self->bitrate))
+            break;
+        if (add_send_header (self, "x-audiocast-public: %i\n", self->public))
+            break;
+        if (add_send_header (self, "x-audiocast-description: %s\n", self->description != NULL ? self->description : "Broadcasting with the icecast streaming media server!"))
+            break;
+
+        if (add_send_header (self, "\n"))
+            break;
+
+        self->error = SHOUTERR_SUCCESS;
+        ret = 0;
+        break;
+    }
+
+	return ret;
+}
+
+
+static int login_ok(shout_t *self)
+{
+    if (shout_read_response (self) < 0)
+        return -1;
+    self->error = SHOUTERR_NOLOGIN;
+    if (!strstr(self->response, "OK"))
+        return -1;
+    self->error = SHOUTERR_SUCCESS;
+    return 0;
+}
+
+
+static int create_icy_request (shout_t *self)
+{
+    int ret = -1;
+
+    while (1)
+    {
+        self->error = SHOUTERR_SOCKET;
+        /* no decent return code check */
+        if (add_send_header (self, "%s\n", self->password))
+            break;
+        if (add_send_header (self, "icy-name:%s\n", self->name != NULL ? self->name : "unnamed"))
+            break;
+        if (add_send_header (self, "icy-url:%s\n", self->url != NULL ? self->url : "http://www.icecast.org/"))
+            break;
+        /* Fields we don't use */
+        if (add_send_header (self, "icy-irc:\nicy-aim:\nicy-icq:\n"))
+            break;
+        if (add_send_header (self, "icy-pub:%i\n", self->public))
+            break;
+        if (add_send_header (self, "icy-genre:%s\n", self->genre != NULL ? self->genre : "icecast"))
+            break;
+        if (add_send_header (self, "icy-br:%i\n", self->bitrate))
+            break;
+        if (add_send_header (self, "\n"))
+            break;
+
+        ret = 0;
+        self->error = SHOUTERR_SUCCESS;
+        break;
+    }
+
+	return ret;
+}
+
+
+/* -- public functions -- */
+
+void shout_init(void)
+{
+    if (_initialized)
+        return;
+
+    sock_initialize();
+    _initialized = 1;
+}
+
+void shout_shutdown(void)
+{
+    if (!_initialized)
+        return;
+
+    sock_shutdown();
+    _initialized = 0;
+}
+
+
+int shout_queue_raw (shout_t *self, const void *data, size_t len)
+{
+    struct shout_pending_node *node = NULL;
+
+    self->error = SHOUTERR_SOCKET;
+    do
+    {
+        void *ptr;
+
+        if (self->pending_total + len > self->pending_limit)
+            break;
+        node = calloc (1, sizeof (*node));
+        self->error = SHOUTERR_MALLOC;
+        if (node == NULL)
+            break;
+        ptr = malloc (len);
+        if (ptr == NULL)
+            break;
+        node->data = node->start = ptr;
+        memcpy (ptr, data, len);
+        node->len = len;
+        *self->pending_queue_tail = node;
+        self->pending_queue_tail = &node->next;
+        self->pending_total += len;
+        self->error = SHOUTERR_SUCCESS;
+        return 0;
+    } while (0);
+    if (node)
+        free (node);
+    return -1;
+}
+
+
+
+int shout_open(shout_t *self)
+{
+	/* sanity check */
+	if (!self)
+		return SHOUTERR_INSANE;
+
+    do
+    {
+		self->error = SHOUTERR_INSANE;
+        if (!self->host || !self->password || !self->port)
+            break;
+
+        self->error = SHOUTERR_CONNECTED;
+        if (self->state == SHOUT_CONNECTED)
+            break;
+
+        if (self->state == SHOUT_NOCONNECT && self->format_open (self) < 0)
+            break;
+
+        if (shout_login (self) < 0)
+            break;
+
+        self->starttime = timing_get_time();
+
+        self->error = SHOUTERR_SUCCESS;
+    } while (0);
+
+	return self->error;
+}
+
+
+const char *shout_version(int *major, int *minor, int *patch)
+{
+    if (major)
+        *major = LIBSHOUT_MAJOR;
+    if (minor)
+        *minor = LIBSHOUT_MINOR;
+    if (patch)
+        *patch = LIBSHOUT_MICRO;
+    return VERSION;
+}
+
+int shout_get_errno(shout_t *self)
+{
+    return self->error;
+}
+
+
+const char *shout_get_error(shout_t *self)
+{
+	if (!self)
+		return "Invalid shout_t";
+
+	switch (self->error)
+    {
+        case SHOUTERR_SUCCESS:
+            return "No error";
+        case SHOUTERR_INSANE:
+            return "Nonsensical arguments";
+        case SHOUTERR_NOCONNECT:
+            return "Couldn't connect";
+        case SHOUTERR_NOLOGIN:
+            return "Login failed";
+        case SHOUTERR_SOCKET:
+            return "Socket error";
+        case SHOUTERR_MALLOC:
+            return "Out of memory";
+        case SHOUTERR_CONNECTED:
+            return "Still connected";
+        case SHOUTERR_UNCONNECTED:
+            return "Not connected";
+        case SHOUTERR_UNSUPPORTED:
+            return "This libshout doesn't support the requested option";
+        case SHOUTERR_PENDING:
+            return "Operation pending completion";
+        case SHOUTERR_PENDING_FULL:
+            return "Too much data waiting to be sent";
+        case SHOUTERR_BUSY:
+            return "Cannot perform task at the moment";
+        default:
+            return "Unknown error";
+	}
+}
+
+
+int shout_get_connected(shout_t *self)
+{
+    if (self->state != SHOUT_NOCONNECT)
+        return SHOUTERR_CONNECTED;
+    else
+        return SHOUTERR_UNCONNECTED;
+}
+
+
+int shout_set_host(shout_t *self, const char *host)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->host)
+		free(self->host);
+
+	self->host = util_strdup(host);
+	if (self->host == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_host(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->host;
+}
+
+int shout_set_port(shout_t *self, unsigned short port)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	self->port = port;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+unsigned short shout_get_port(shout_t *self)
+{
+	if (!self)
+		return 0;
+
+	return self->port;
+}
+
+int shout_set_password(shout_t *self, const char *password)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->password)
+		free (self->password);
+
+	self->password = util_strdup (password);
+	if (self->password == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char* shout_get_password(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->password;
+}
+
+int shout_set_mount(shout_t *self, const char *mount)
+{
+    size_t len;
+
+	if (!self || !mount)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->mount)
+		free(self->mount);
+
+    len = strlen (mount) + 1;
+    if (mount[0] != '/')
+        len++;
+
+    self->mount = malloc (len);
+    if (self->mount == NULL)
+        return self->error = SHOUTERR_MALLOC;
+
+    sprintf (self->mount, "%s%s", mount[0] == '/' ? "" : "/", mount);
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_mount(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->mount;
+}
+
+int shout_set_name(shout_t *self, const char *name)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->name)
+		free(self->name);
+
+	self->name = util_strdup (name);
+	if (self->name == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_name(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->name;
+}
+
+int shout_set_url(shout_t *self, const char *url)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->url)
+		free(self->url);
+
+	self->url = util_strdup(url);
+	if (self->url == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_url(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->url;
+}
+
+int shout_set_genre(shout_t *self, const char *genre)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->genre)
+		free(self->genre);
+
+	self->genre = util_strdup (genre);
+	if (self->genre == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_genre(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->genre;
+}
+
+int shout_set_agent(shout_t *self, const char *agent)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->useragent)
+		free(self->useragent);
+
+	self->useragent = util_strdup (agent);
+	if (self->useragent == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_agent(shout_t *self)
+{
+    if (!self)
+        return NULL;
+
+    return self->useragent;
+}
+
+
+int shout_set_user(shout_t *self, const char *username)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->user)
+		free(self->user);
+
+	self->user = util_strdup (username);
+	if (self->user == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_user(shout_t *self)
+{
+    if (!self)
+        return NULL;
+
+    return self->user;
+}
+
+int shout_set_description(shout_t *self, const char *description)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	if (self->description)
+		free(self->description);
+
+	self->description = util_strdup (description);
+	if (self->description == NULL)
+		return self->error = SHOUTERR_MALLOC;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_description(shout_t *self)
+{
+	if (!self)
+		return NULL;
+
+	return self->description;
+}
+
+int shout_set_dumpfile(shout_t *self, const char *dumpfile)
+{
+    if (!self)
+        return SHOUTERR_INSANE;
+
+    if (self->state != SHOUT_NOCONNECT)
+        return SHOUTERR_CONNECTED;
+
+    if (self->dumpfile)
+        free(self->dumpfile);
+
+    self->dumpfile = util_strdup (dumpfile);
+    if (self->dumpfile == NULL)
+        return self->error = SHOUTERR_MALLOC;
+
+    return self->error = SHOUTERR_SUCCESS;
+}
+
+const char *shout_get_dumpfile(shout_t *self)
+{
+    if (!self)
+        return NULL;
+
+    return self->dumpfile;
+}
+
+
+
+/* this really needs looking at, embedding info into one headers can be limiting */
+int shout_set_audio_info(shout_t *self, const char *name, const char *value)
+{
+    return self->error = util_dict_set(self->audio_info, name, value);
+}
+
+const char *shout_get_audio_info(shout_t *self, const char *name)
+{
+    return util_dict_get(self->audio_info, name);
+}
+
+
+int shout_set_public(shout_t *self, unsigned int public)
+{
+	if (!self || (public != 0 && public != 1))
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+	self->public = public;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+unsigned int shout_get_public(shout_t *self)
+{
+	if (!self)
+		return 0;
+
+	return self->public;
+}
+
+int shout_set_format(shout_t *self, unsigned int format)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+    switch (format)
+    {
+        case SHOUT_FORMAT_VORBISPAGE:
+        case SHOUT_FORMAT_VORBIS:
+            self->format_open = shout_open_vorbis;
+            break;
+        case SHOUT_FORMAT_MP3:
+            self->format_open = shout_open_mp3;
+            break;
+        default:
+            return self->error = SHOUTERR_UNSUPPORTED;
+    }
+
+	self->format = format;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+unsigned int shout_get_format(shout_t* self)
+{
+	if (!self)
+		return 0;
+
+	return self->format;
+}
+
+int shout_set_protocol(shout_t *self, unsigned int protocol)
+{
+	if (!self)
+		return SHOUTERR_INSANE;
+
+	if (self->state != SHOUT_NOCONNECT)
+		return self->error = SHOUTERR_CONNECTED;
+
+    switch (protocol)
+    {
+        case SHOUT_PROTOCOL_HTTP:
+            self->get_response = login_http;
+            self->create_request = create_http_request;
+            break;
+        case SHOUT_PROTOCOL_XAUDIOCAST:
+            self->get_response = login_ok;
+            self->create_request = create_xaudiocast_request;
+            break;
+        case SHOUT_PROTOCOL_ICY:
+            self->get_response = login_ok;
+            self->create_request = create_icy_request;
+            break;
+        default:
+            return self->error = SHOUTERR_UNSUPPORTED;
+    }
+
+	self->protocol = protocol;
+
+	return self->error = SHOUTERR_SUCCESS;
+}
+
+unsigned int shout_get_protocol(shout_t *self)
+{
+	if (!self)
+		return 0;
+
+	return self->protocol;
+}
+
+int shout_connection_ready (shout_t *self)
+{
+    if (self)
+        return self->state == SHOUT_READY;
+    return 0;
+}
+
+
+shout_metadata_t *shout_metadata_new(void)
+{
+    return util_dict_new();
+}
+
+void shout_metadata_free(shout_metadata_t *self)
+{
+    if (!self)
+        return;
+
+    util_dict_free(self);
+}
+
+int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value)
+{
+    if (!self || !name)
+        return SHOUTERR_INSANE;
+    return util_dict_set(self, name, value);
+}
+
+
+
+int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
+{
+    sock_t socket;
+    int ret;
+    char *encvalue;
+
+    if (!self)
+        return SHOUTERR_INSANE;
+
+    if (metadata == NULL)
+        return self->error = SHOUTERR_INSANE;
+
+    if (self->state != SHOUT_READY)
+        return self->error = SHOUTERR_UNCONNECTED;
+
+    encvalue = util_dict_urlencode(metadata, '&');
+    if (encvalue == NULL)
+        return self->error = SHOUTERR_MALLOC;
+
+    ret = SHOUTERR_NOCONNECT;
+    if ((socket = sock_connect(self->host, self->port)) >= 0)
+    {
+        int rv = 1;
+        if (self->protocol == SHOUT_PROTOCOL_ICY)
+            rv = sock_write(socket, "GET /admin.cgi?mode=updinfo&pass=%s&%s HTTP/1.0\r\nUser-Agent: %s (Mozilla compatible)\r\n\r\n",
+                    self->password, encvalue, shout_get_agent(self));
+        else if (self->protocol == SHOUT_PROTOCOL_HTTP)
+        {
+            char *auth = http_basic_authorization(self);
+
+            rv = sock_write(socket, "GET /admin/metadata?mode=updinfo&mount=%s&%s HTTP/1.0\r\nUser-Agent: %s\r\n%s\r\n",
+                    self->mount, encvalue, shout_get_agent(self), auth ? auth : "");
+        }
+        if (rv)
+            ret = SHOUTERR_SUCCESS;
+        else
+            ret = SHOUTERR_SOCKET;
+        sock_close(socket);
+    }
+
+    free (encvalue);
+
+    return self->error = ret;
+}
+
+
+int shout_send_raw (shout_t *self, const void *data, size_t len)
+{
+    int written = 0;
+    const char *ptr = data;
+
+    if (self->pending_queue)
+        shout_send_pending (self);
+
+    if (self->pending_queue == NULL)
+    {
+        written = shout_try_write (self, data, len);
+        if (written == (int)len || written < 0)
+            return written;
+    }
+    if (shout_queue_raw (self, ptr+written, len-written) < 0)
+        return -1;
+    return (int)len;
+}
+
+
+
+void shout_sync(shout_t *self)
+{
+    int64_t sleep;
+
+    if (!self)
+        return;
+
+    if (self->senttime == 0)
+        return;
+
+    sleep = self->senttime/1000 - (timing_get_time() - self->starttime);
+
+    // printf ("senttime is %lld, sleep is %lld\n", self->senttime, sleep);
+    if (sleep > 0)
+        timing_sleep((uint64_t)sleep);
+}
+
+int shout_delay(shout_t *self)
+{
+    if (!self)
+        return 0;
+
+    if (self->senttime == 0)
+        return 0;
+
+    return self->senttime / 1000 - (timing_get_time() - self->starttime);
+}
+
+
+int shout_send(shout_t *self, const void *data, size_t len)
+{
+    if (self)
+    {
+        if (self->state != SHOUT_READY)
+            return self->error = SHOUTERR_UNCONNECTED;
+
+        if (self->send)
+            return self->send(self, data, len);
+
+        self->error = SHOUTERR_INSANE;
+    }
+    return SHOUTERR_INSANE;
+}
+
+
+shout_t *shout_new(void)
+{
+	shout_t *self;
+
+    shout_init();  /* initialise lib is not already */
+
+	self = (shout_t *)calloc(1, sizeof(shout_t));
+	while (self)
+    {
+
+        if (shout_set_host (self, LIBSHOUT_DEFAULT_HOST))
+            break;
+
+        self->port = LIBSHOUT_DEFAULT_PORT;
+        shout_set_format (self,  LIBSHOUT_DEFAULT_FORMAT);
+        shout_set_protocol (self, LIBSHOUT_DEFAULT_PROTOCOL);
+
+        if (shout_set_user (self, LIBSHOUT_DEFAULT_USER) < SHOUTERR_SUCCESS)
+            break;
+        if (shout_set_agent (self, LIBSHOUT_DEFAULT_USERAGENT) < SHOUTERR_SUCCESS)
+            break;
+
+        if ((self->audio_info = util_dict_new()) == NULL)
+            break;
+
+        self->send_header = malloc (MAX_HTTP_SENT);
+        if (self->send_header == NULL)
+            break;
+        self->send_header_offset = 0;
+
+        self->response = malloc (MAX_HTTP_RESPONSE);
+        if (self->response == NULL)
+            break;
+        self->read_timeout = 10;   /* default 10 seconds */
+        self->pending_total = 0;
+        self->pending_limit = 65535;  /* don't queue more than this */
+        self->pending_queue_tail = &self->pending_queue;
+        self->response_len = 0;
+
+        return self;
+    }
+    shout_free(self);
+
+	return NULL;
+}
+
+
+void shout_set_read_timeout (shout_t *self, unsigned timeout)
+{
+    if (self)
+        self->read_timeout = timeout;
+}
+
+
+void shout_set_nonblocking (shout_t *self, int nonblock)
+{
+     self->nonblocking = nonblock;
+     if (sock_valid_socket(self->socket))
+         sock_set_blocking (self->socket, nonblock?SOCK_NONBLOCK:SOCK_BLOCK);
+}
+
+
+int shout_close(shout_t *self)
+{
+    if (!self)
+        return SHOUTERR_INSANE;
+
+    self->starttime = 0;
+    if (self->send_header)
+    {
+        self->send_header_offset = 0;
+        self->send_header_size = 0;
+    }
+    if (self->response)
+    {
+        self->response_len = 0;
+    }
+
+    /* send what we can if any pending */
+    shout_send_pending (self);
+    /* do memory cleanup */
+    shout_free_pending (self);
+
+    if (self->close)
+        self->close(self);
+
+    if (self->socket > -1)
+        sock_close(self->socket);
+    self->socket = -1;
+    self->pending_connection = 0;
+
+    if (self->state == SHOUT_NOCONNECT)
+        self->error = SHOUTERR_UNCONNECTED;
+    else
+        self->error = SHOUTERR_SUCCESS;
+
+    self->state = SHOUT_NOCONNECT;
+	return self->error;
+}
+
+
+void shout_free(shout_t *self)
+{
+	if (!self) return;
+
+	if (self->host) free(self->host);
+	if (self->password) free(self->password);
+	if (self->mount) free(self->mount);
+	if (self->name) free(self->name);
+	if (self->url) free(self->url);
+	if (self->genre) free(self->genre);
+	if (self->description) free(self->description);
+	if (self->user) free(self->user);
+    if (self->useragent) free(self->useragent);
+    if (self->audio_info) util_dict_free (self->audio_info);
+    if (self->response) free (self->response);
+    if (self->send_header) free (self->send_header);
+
+    shout_free_pending (self);
+	free(self);
+}
+

Added: icecast/branches/libshout-kh/src/shout_private.h
===================================================================
--- icecast/branches/libshout-kh/src/shout_private.h	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/shout_private.h	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,197 @@
+/* shout.h: Private libshout data structures and declarations
+ *
+ * Copyright(c) 2003 Karl Heyes <karl at pts.tele2.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; See the file COPYING
+ *
+ * if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef __LIBSHOUT_SHOUT_PRIVATE_H__
+#define __LIBSHOUT_SHOUT_PRIVATE_H__
+
+#include <shout/shout.h>
+#include <net/sock.h>
+#include <timing/timing.h>
+#include "util.h"
+
+#include <sys/types.h>
+#ifdef HAVE_STDINT_H
+#  include <stdint.h>
+#elif defined (HAVE_INTTYPES_H)
+#  include <inttypes.h>
+#endif
+
+
+/* anymore than this is silly */
+#define MAX_HTTP_SENT       4096
+#define MAX_HTTP_RESPONSE   1024
+
+
+#define LIBSHOUT_DEFAULT_HOST "localhost"
+#define LIBSHOUT_DEFAULT_PORT 8000
+#define LIBSHOUT_DEFAULT_FORMAT SHOUT_FORMAT_VORBIS
+#define LIBSHOUT_DEFAULT_PROTOCOL SHOUT_PROTOCOL_HTTP
+#define LIBSHOUT_DEFAULT_USER "source"
+#define LIBSHOUT_DEFAULT_USERAGENT "libshout/" VERSION
+
+typedef enum
+{
+    SHOUT_NOCONNECT,
+    SHOUT_CONNECTED,
+    SHOUT_REQ_MADE,
+    SHOUT_REQ_SENT,
+    SHOUT_READY
+} shout_state_t;
+
+struct shout {
+    /* hostname or IP of icecast server */
+    char *host;
+    /* port of the icecast server */
+    int port;
+    /* login password for the server */
+    char *password;
+    /* server protocol to use */
+    unsigned int protocol;
+    /* type of data being sent */
+    unsigned int format;
+    /* audio encoding parameters */
+    util_dict *audio_info;
+
+    /* user-agent to use when doing HTTP login */
+    char *useragent;
+    /* mountpoint for this stream */
+    char *mount;
+    /* name of the stream */
+    char *name;
+    /* homepage of the stream */
+    char *url;
+    /* genre of the stream */
+    char *genre;
+    /* description of the stream */
+    char *description;
+    /* icecast 1.x dumpfile */
+    char *dumpfile;
+    /* username to use for HTTP auth. */
+    char *user;
+    /* bitrate of this stream */
+    int bitrate;
+    /* is this stream private? */
+    int public;
+
+    /* socket the connection is on */
+    sock_t socket;
+
+    /* timeout for reading sockets in blocking mode */
+    unsigned read_timeout;
+
+    void *format_data;
+    int (*send)(shout_t* self, const void * buff, unsigned len);
+    void (*close)(shout_t* self);
+    int (*get_response)(shout_t *self);
+    int (*format_open)(shout_t *self);
+    int (*create_request)(shout_t *self);
+
+    const char *mime_type;
+
+    /* start of this period's timeclock */
+    uint64_t starttime;
+    /* amount of data we've sent (in milliseconds) */
+    uint64_t senttime;
+
+    int error;
+
+    /* general state information */
+    shout_state_t  state;
+    int nonblocking;
+    int pending_connection;
+
+    signed char *send_header;
+    int send_header_size;
+    int send_header_offset;
+
+    unsigned char *response;
+    unsigned response_len;
+    time_t response_senttime;
+
+    unsigned pending_total;
+    unsigned pending_limit;
+    struct shout_pending_node *pending_queue, **pending_queue_tail;
+};
+
+
+struct shout_metadata {
+	char *name;
+	char *value;
+	shout_metadata_t *next;
+};
+
+struct shout_pending_node
+{
+    void *data;   /* actual data start */
+    void *start;  /* somewhere in data */
+    unsigned len;
+    struct shout_pending_node *next;
+};
+
+static __inline__ int send_header_write (shout_t *self, int count)
+{
+    if (count < 0)
+        return 1;
+
+    self->send_header_size += count;
+    if (self->send_header_size >= MAX_HTTP_SENT)
+        return 1;
+    return 0;
+}
+
+static __inline__ signed char *send_header_end (shout_t *self)
+{
+    return self->send_header + self->send_header_size;
+}
+
+static __inline__ int send_header_remaining (shout_t *self)
+{
+    return MAX_HTTP_SENT - self->send_header_size;
+}
+
+#ifdef HAVE_VA_ARGS
+#define add_send_header(x, ...)  send_header_write((x),snprintf(send_header_end(x) , send_header_remaining(x) , __VA_ARGS__))
+#else
+static __inline__ int add_send_header (shout_t *self, const char *fmt, ...)
+{
+    char *start = send_header_end (self);
+    unsigned len = send_header_remaining (self);
+    int ret;
+    va_list ap;
+    va_start (ap, fmt);
+    ret = send_header_write (self, vsnprintf (start, len, fmt, ap));
+    va_end (ap);
+    return ret;
+}
+#endif
+
+
+
+
+int shout_open_vorbis(shout_t *self);
+int shout_open_mp3(shout_t *self);
+int shout_queue_raw (shout_t *self, const void *data, size_t len);
+int shout_write_direct (shout_t *self, const struct iovec *vecs, size_t count);
+int shout_store_vec (shout_t *self, const struct iovec *vecs, size_t count, size_t written);
+
+
+#endif /* __LIBSHOUT_SHOUT_PRIVATE_H__ */

Added: icecast/branches/libshout-kh/src/util.c
===================================================================
--- icecast/branches/libshout-kh/src/util.c	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/util.c	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,237 @@
+/* util.c: libshout utility/portability functions */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <errno.h>
+
+#include <shout/shout.h>
+
+#include "util.h"
+
+char *util_strdup(const char *s)
+{
+	if (!s) return NULL;
+	return strdup(s);
+}
+
+
+static char base64table[64] = {
+    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+    'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+    'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+    'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
+};
+
+/* This isn't efficient, but it doesn't need to be */
+char *util_base64_encode(char *data)
+{
+    int len = strlen(data);
+    char *out = malloc(len*4/3 + 4);
+    char *result = out;
+    int chunk;
+
+    while(len > 0) {
+        chunk = (len >3)?3:len;
+        *out++ = base64table[(*data & 0xFC)>>2];
+        *out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
+        switch(chunk) {
+            case 3:
+                *out++ = base64table[((*(data+1) & 0x0F)<<2) | ((*(data+2) & 0xC0)>>6)];
+                *out++ = base64table[(*(data+2)) & 0x3F];
+                break;
+            case 2:
+                *out++ = base64table[((*(data+1) & 0x0F)<<2)];
+                *out++ = '=';
+                break;
+            case 1:
+                *out++ = '=';
+                *out++ = '=';
+                break;
+        }
+        data += chunk;
+        len -= chunk;
+    }
+    *out = 0;
+
+    return result;
+}
+
+
+static char urltable[16] = {
+            '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
+};
+
+/* modified from libshout1, which credits Rick Franchuk <rickf at transpect.net>.
+ * Caller must free result. */
+char *util_url_encode(const char *data) {
+    const char *p;
+    char *q, *dest;
+    int digit;
+    size_t n;
+
+    for (p = data, n = 0; *p; p++) {
+        n++;
+        if (!isalnum((int)*p))
+            n += 2;
+    }
+    if (!(dest = malloc(n+1)))
+        return NULL;
+
+    for (p = data, q = dest; *p; p++, q++) {
+        if (isalnum((int)*p)) {
+            *q = *p;
+        } else {
+            *q++ = '%';
+            digit = (*p >> 4) & 0xF;
+            *q++ = urltable[digit];
+            digit = *p & 0xf;
+            *q = urltable[digit];
+            n += 2;
+        }
+    }
+    *q = '\0';
+
+    return dest;
+}
+
+util_dict *util_dict_new(void)
+{
+    return (util_dict *)calloc(1, sizeof(util_dict));
+}
+
+void util_dict_free(util_dict *dict)
+{
+    util_dict *next;
+
+    while (dict) {
+        next = dict->next;
+
+        if (dict->key)
+            free (dict->key);
+        if (dict->val)
+            free (dict->val);
+        free (dict);
+
+        dict = next;
+    }
+}
+
+const char *util_dict_get(util_dict *dict, const char *key)
+{
+    while (dict) {
+        if (dict->key && !strcmp(key, dict->key))
+            return dict->val;
+        dict = dict->next;
+    }
+
+    return NULL;
+}
+
+int util_dict_set(util_dict *dict, const char *key, const char *val)
+{
+    util_dict *prev;
+
+    if (!dict || !key)
+        return SHOUTERR_INSANE;
+
+    prev = NULL;
+    while (dict) {
+        if (!dict->key || !strcmp(dict->key, key))
+            break;
+        prev = dict;
+        dict = dict->next;
+    }
+
+    if (!dict) {
+        dict = util_dict_new();
+        if (!dict)
+            return SHOUTERR_MALLOC;
+        if (prev)
+            prev->next = dict;
+    }
+    if (dict->key)
+        free (dict->val);
+    else if (!(dict->key = strdup(key))) {
+        if (prev)
+            prev->next = NULL;
+        util_dict_free (dict);
+
+        return SHOUTERR_MALLOC;
+    }
+
+    dict->val = strdup(val);
+    if (!dict->val) {
+        return SHOUTERR_MALLOC;
+    }
+
+    return SHOUTERR_SUCCESS;
+}
+
+/* given a dictionary, URL-encode each key and val and stringify them in order as
+ *   key=val&key=val... if val is set, or just key&key if val is NULL.
+ *     TODO: Memory management needs overhaul. */
+char *util_dict_urlencode(util_dict *dict, char delim)
+{
+    char *res, *tmp;
+    char *enc;
+    int start = 1;
+
+    for (res = NULL; dict; dict = dict->next) {
+        /* encode key */
+        if (!dict->key)
+            continue;
+        if (!(enc = util_url_encode(dict->key))) {
+            if (res)
+                free(res);
+            return NULL;
+        }
+        if (start) {
+            if (!(res = malloc(strlen(enc) + 1))) {
+                free(enc);
+                return NULL;
+            }
+            sprintf(res, "%s", enc);
+            free(enc);
+            start = 0;
+        } else {
+            if (!(tmp = realloc(res, strlen(res) + strlen(enc) + 2))) {
+                free(enc);
+                free(res);
+                return NULL;
+            } else
+                res = tmp;
+            sprintf(res + strlen(res), "%c%s", delim, enc);
+            free(enc);
+        }
+
+        /* encode value */
+        if (!dict->val)
+            continue;
+        if (!(enc = util_url_encode(dict->val))) {
+            free(res);
+            return NULL;
+        }
+
+        if (!(tmp = realloc(res, strlen(res) + strlen(enc) + 2))) {
+            free(enc);
+            free(res);
+            return NULL;
+        } else
+            res = tmp;
+        sprintf(res + strlen(res), "=%s", enc);
+        free(enc);
+    }
+
+    return res;
+}
+
+

Added: icecast/branches/libshout-kh/src/util.h
===================================================================
--- icecast/branches/libshout-kh/src/util.h	2004-06-22 21:47:20 UTC (rev 6838)
+++ icecast/branches/libshout-kh/src/util.h	2004-06-24 18:19:16 UTC (rev 6839)
@@ -0,0 +1,28 @@
+/* util.h: libshout utility/portability functions */
+
+#ifndef __LIBSHOUT_UTIL_H__
+#define __LIBSHOUT_UTIL_H__
+
+/* String dictionary type, without support for NULL keys, or multiple
+ *  * instances of the same key */
+typedef struct _util_dict {
+    char *key;
+    char *val;
+    struct _util_dict *next;
+} util_dict;
+
+char *util_strdup(const char *s);
+
+util_dict *util_dict_new(void);
+void util_dict_free(util_dict *dict);
+/* dict, key must not be NULL. */
+int util_dict_set(util_dict *dict, const char *key, const char *val);
+const char *util_dict_get(util_dict *dict, const char *key);
+char *util_dict_urlencode(util_dict *dict, char delim);
+
+char *util_strdup(const char *s);
+char *util_base64_encode(char *data);
+int util_read_header(int sock, char *buff, unsigned long len);
+
+
+#endif /* __LIBSHOUT_UTIL_H__ */



More information about the commits mailing list