/* THE REALAUDIO FIREWALL PROXY KIT 2.0 BETA 2 */
/* This file: $Date: 1996/04/17 18:25:20 $ $Revision: 1.9 $ */

/*
 * Copyright (c) 1996 Progressive Networks, Inc.
 * 
 * By clicking on the "Accept" button or opening the package, you are
 * consenting to be bound by this Agreement.  If you do not agree to all of
 * the terms of this agreement, click the "Do Not Accept" button and, if
 * you received the Software by package, return the product to the place of
 * purchase for a full refund.
 * 
 * 1. GRANT OF LICENSE.
 * 
 *  
 * Progressive Networks, Inc. (PN) grants to Recipient a limited,
 * non-exclusive, royalty-free license to use, modify, or redistribute the
 * Software without a fee, subject to the conditions stated below.
 * 
 * All other rights are reserved to PN. 
 * 
 * 
 * 2.  CONDITIONS
 * The above grant of license is subject to the following conditions:
 * 
 *        A) The copyright notice ("Copyright (c) 1996 Progressive
 *           Networks, Inc. ")  and this license appear on all copies of the
 *           Software and/or any derivatives of the Software.
 * 
 *        B) Recipient uses the Software or any derivatives only to build a
 *           firewall proxy for use with RealAudio products from PN.
 * 
 *        C) Recipient acknowledges and agrees that PN is and shall be the
 *           exclusive owner of all right, title and interest, including
 *           copyright, in the Software.
 * 
 * 3. SOFTWARE  MAINTENANCE. 
 * 
 * PN is not obligated to provide maintenance or updates to Recipient for
 * the Software. However, any maintenance or updates provided by PN shall
 * be covered by this Agreement.
 * 
 * 4. DISCLAIMER OF WARRANTY.
 * 
 * Software is deemed accepted by Recipient.  Because PN is providing
 * Recipient the Software for free, the Software is provided to Recipient
 * AS IS, WITHOUT WARRANTY OF ANY KIND. TO THE MAXIMUM EXTENT PERMITTED
 * BYAPPLICABLE LAW, PROGRESSIVE NETWORKS FURTHER DISCLAIMS ALL
 * WARRANTIES,INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 * NONINFRINGEMENT. THE ENTIRE RISK ARISING OUT OF THE USE OR PERFORMANCE
 * OF THE SOFTWARE REMAINS WITH RECIPIENT. TO THE MAXIMUM EXTENT PERMITTED
 * BY APPLICABLE LAW, IN NO EVENT SHALL PROGRESSIVE NETWORKS OR ITS
 * SUPPLIERS BE LIABLE FOR ANY CONSEQUENTIAL, INCIDENTAL, DIRECT, INDIRECT,
 * SPECIAL, PUNITIVE, OR OTHER DAMAGES WHATSOEVER (INCLUDING, WITHOUT
 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING OUT OF
 * THIS AGREEMENT OR THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF
 * PROGRESSIVE NETWORKS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGES. BECAUSE SOME STATES/JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR
 * LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE
 * ABOVE LIMITATION MAY NOT APPLY TO RECIPIENT.
 * 
 * 5. INDEMNIFICATION. 
 * 
 * Recipient hereby agrees to defend, indemnify, and hold PN, its
 * directors, officers, employees and agents, harmless from any and all
 * claims, damages, and expenses (including attorneys fees and costs) of
 * any nature arising out of the use, modification, or redistribution the
 * Software or any derivatives.
 * 
 * 6. U.S. GOVERNMENT RESTRICTED RIGHTS AND EXPORT RESTRICTIONS. 
 * 
 * The Software is provided with RESTRICTED RIGHTS. Use, duplication, or
 * disclosure by the Government is subject to restrictions as set forth in
 * subparagraph (c)(1)(ii) of The Rights in Technical Data and Computer
 * Software clause of DFARS 252.227-7013 or subparagraphs (c)(i) and (2) of
 * the Commercial Computer Software-Restricted Rights at 48 CFR 52.227-19,
 * as applicable. Manufacturer is Progressive Networks, 616 First Avenue,
 * Suite 701, Seattle, Washington 98104-2258. Recipient acknowledges that
 * none of the Software or underlying information or technology may be
 * downloaded or otherwise exported or re-exported (i) into (or to a
 * national or resident of) Cuba, Iraq, Libya, Yugoslavia, North Korea,
 * Iran, Syria or any other country to which the U.S. has embargoed goods;
 * or (ii) to anyone on the U.S. Treasury Department's list of Specially
 * Designated Nationals or the U.S. Commerce Department's Table of Denial
 * Orders.  By using the Software, you are agreeing to the foregoing and
 * you are representing and warranting that you are not located in, under
 * the control of, or a national or resident or resident of any such
 * country or on any such list.
 * 
 * 7. GOVERNING LAW; ATTORNEYS FEES. 
 * 
 * This agreement shall be governed by the laws of the State of Washington
 * and Recipient further consents to jurisdiction by the state and federal
 * courts sitting in the State of Washington. If either PN or Recipient
 * employs attorneys to enforce any rights arising out of or relating to
 * this Agreement, the prevailing party shall be entitled to recover
 * reasonable attorneys' fees.
 * 
 * 8. ENTIRE AGREEMENT. 
 * 
 * This agreement constitutes the complete and exclusive agreement between
 * PN and Recipient with respect to the subject matter hereof, and
 * supersedes all prior oral or written understandings, communications or
 * agreements not specifically incorporated herein.  This agreement may not
 * be modified except in a writing duly signed by an authorized
 * representative of PN and Recipient.
 *
 */
/* RealAudio proxy protocol version */
#define RA_PROXYVERSION	1

#define RA_TIMEOUT	120	/* max seconds for proxy dialog */

/* proxy protocol control codes */
#define RA_END			0
#define RA_VERSION		1
#define RA_HOSTNAME		2
#define RA_SERVERPORT		3
#define RA_BACKPORTOFFSET	4
#define RA_CONNECTTYPE		5
#define RA_STATUS		6

/* 
 * proxy protocol opcode message sizes.
 * number of bytes of data to read after opcode
 */ 
int opcodebytes[] = {
		0,	/* RA_END */
		1,	/* RA_VERSION */
		-1,	/* RA_HOSTNAME (-1 means string) */
		2,	/* RA_SERVERPORT */
		2,	/* RA_BACKPORTOFFSET */
		1,	/* RA_CONNECTTYPE */
		-1,	/* RA_STATUS */
};
		
		
/* status messages that can be returned to player */
#define	RA_SUCCESS	0	/* proxy dialog succesful */
#define	RA_NOCONNECT	1	/* couldn't connect to server  */
#define	RA_BADINFO	2	/* bad info passed in proxy dialog. */
#define	RA_BADVERSION	3	/* proxy version mismatch */
#define	RA_BADCODE	4	/* bad proxy opcode */
#define	RA_NOUDP	5	/* UDP audio connections not allowed */
#define	RA_LIMIT	6	/* Exceeded Maximum # Audio streams  */
#define	RA_LIMITPROB	7	/* Problem with limit lock file */

char *statusmsgs[] = {	0,
			"Couldn't connect to server: ",
			"Didn't receive all proxy info.",
		 	"Wrong Proxy Version.",
			"Unexpected Proxy Opcode.",
			"UDP audio connections not allowed.  Please change network preferences in your player to receive audio via TCP.",
			"Maximum audio streams running.  Try again later.",
			"Problem accessing RA lockfile.  Contact Administrator."
};

#ifdef LOAD_LIMIT
#ifndef MAXAUDIOSTREAMS
#define MAXAUDIOSTREAMS 2
#endif
/* these should be made configurable options */
int	maxaudiostreams = MAXAUDIOSTREAMS;
/* lockfile to limit audio streams */
char	ralockfile[] = "/etc/raproxy.lock";
int	ranumbytes = sizeof maxaudiostreams;
#endif /* LOAD_LIMIT */
