Commit b9b21650 authored by Clément Stenac's avatar Clément Stenac

* configure.ac , Makefile.in: light use of autoconf to manage options

* Makefile.in:  added install and allclean targets

* slp.cpp / slp.h : SLP protocol support based on libslp
 (use "-t slp" to register programs, and "-t slp -u" to unregister them)

* sapserver.1: manpage
parent 58eb5702
VERSION=0.2.2 # Makefile.in : Makefile structure for mini-SAP-server
CFLAGS= -Wall -Wstrict-prototypes -g # $Id: Makefile.in,v 1.1 2003/08/10 12:44:18 zorglub Exp $
FILES=program message parser broadcast
FILES_O=$(FILES:%=%.o) FILES_O=$(FILES:%=%.o)
GPP= g++ $(CFLAGS) GPP= g++ $(CFLAGS)
...@@ -12,8 +11,8 @@ default: sapserver ...@@ -12,8 +11,8 @@ default: sapserver
# Main target. Build .o files from every.cpp files and build the final # Main target. Build .o files from every.cpp files and build the final
# executable # executable
sapserver: $(FILES_O) sapserver.cpp sapserver.h sapserver: $(FILES_O)
$(GPP) -o sapserver $(FILES_O) sapserver.cpp -DVERSION=\"$(VERSION)\" $(GPP) $(LDFLAGS) -o ${EXECNAME} $(FILES_O)
# Target that builds a .o from each .cpp # Target that builds a .o from each .cpp
$(FILES_O): %.o: %.cpp %.h $(FILES_O): %.o: %.cpp %.h
...@@ -22,13 +21,28 @@ $(FILES_O): %.o: %.cpp %.h ...@@ -22,13 +21,28 @@ $(FILES_O): %.o: %.cpp %.h
# Delete the .o files and the executable # Delete the .o files and the executable
clean: clean:
rm -f $(FILES_O) rm -f $(FILES_O)
rm -f sapserver rm -f ${EXECNAME}
# Also delete the Makefile (configure needed)
allclean: clean
rm -f Makefile
# Cleans and remove the dists # Cleans and remove the dists
distclean: clean distclean: clean
rm -f miniSAPserver-${VERSION}.tar.bz2 rm -f miniSAPserver-${VERSION}.tar.bz2
rm -f miniSAPserver-${VERSION}.tar.gz rm -f miniSAPserver-${VERSION}.tar.gz
# Install in the prefix
install:
install -d ${EXECDIR}
install -d ${MANDIR}
install -d ${CONFDIR}
install -m 755 ${EXECNAME} ${EXECDIR}
install -m 644 ${MANPAGE} ${MANDIR}
install -m 644 ${CONFFILE} ${CONFDIR}
# Makes the dists. # Makes the dists.
dist: dist:
-# Check that tmp isn't in the way -# Check that tmp isn't in the way
...@@ -38,13 +52,15 @@ dist: ...@@ -38,13 +52,15 @@ dist:
echo "Starting dist's build."; mkdir tmp; \ echo "Starting dist's build."; mkdir tmp; \
fi fi
mkdir tmp/miniSAPserver/ mkdir tmp/miniSAPserver/
# Copy the Makefile # Rebuild the configure script
cp Makefile tmp/miniSAPserver/ autoconf
# Copy the Makefile.in & configure script
cp Makefile.in configure tmp/miniSAPserver/
# Copy the configration file # Copy the configration file
cp sap.cfg tmp/miniSAPserver/ cp sap.cfg tmp/miniSAPserver/
# Copy all headers and source code files # Copy all headers and source code files
cp *.cpp *.h tmp/miniSAPserver/ cp *.cpp *.h tmp/miniSAPserver/
# Copy AUTHORS and CPYING # Copy AUTHORS and COPYING
cp AUTHORS COPYING tmp/miniSAPserver/ cp AUTHORS COPYING tmp/miniSAPserver/
# Build archives # Build archives
F=miniSAPserver-${VERSION}; \ F=miniSAPserver-${VERSION}; \
......
-- Changes from version 0.2.2 to version 0.2.3
* Support for the SLP announcing protocol
* Bugfixes
* Improved build system
-- Changes from version 0.2.1 to version 0.2.2 -- Changes from version 0.2.1 to version 0.2.2
* Bugfixes * Bugfixes
-- Changes from version 0.2.0 to version 0.2.1 -- Changes from version 0.2.0 to version 0.2.1
* IPv6 support -both for announces and announced streams * IPv6 support -both for announces and announced streams-
-- Changes from version 0.1.2 to version 0.2.0 -- Changes from version 0.1.2 to version 0.2.0
* Major structural improvements * Major structural improvements
* The miniSAPserver now sends packets that complie with the RFC * The miniSAPserver now sends packets that comply with the RFC
-- Changes from version 0.1.1 to version 0.1.2 -- Changes from version 0.1.1 to version 0.1.2
......
dnl Autoconf settings for mini-SAP-server
dnl $Id: configure.ac,v 1.1 2003/08/10 12:44:18 zorglub Exp $
AC_INIT("mini-SAP-server",0.2.3-cvs)
dnl ****************************
dnl Program information
dnl ****************************
PROGRAM_NAME="mini-SAP-server"
VERSION_MAJOR=0
VERSION_MINOR=2
REVISION=3-cvs
dnl ****************************
dnl Default settings
dnl ****************************
CONFIG="config.h"
DEFAULT_PREFIX="/usr/local/${PROGRAM_NAME}"
EXECNAME="sapserver"
CONFFILE="sap.cfg"
MANPAGE="sapserver.1"
ACTIVE=""
CFLAGS="-Wall -Wstrict-prototypes"
BUILTIN="program message parser broadcast sapserver"
dnl ****************************
dnl General checks
dnl ****************************
AC_PROG_CC
AC_PROG_CPP dnl C++
AC_PROG_MAKE_SET dnl make result
dnl ****************************
dnl Features
dnl ****************************
dnl Enable/Disable slp
AC_ARG_ENABLE(slp,
[ --enable-slp enable SLP announcing (default disabled)],
[if test ${enable_slp} = "yes"
then
AC_CHECK_HEADERS(slp.h, ,
echo "Unable to find SLP headers";exit 1)
ACTIVE="${ACTIVE} slp"
LDFLAGS="${LDFLAGS} -lslp"
fi
])
dnl Debug Mode
AC_ARG_ENABLE(debug,
[ --enable-debug enable debug mode (default enabled)])
if test "${enable_debug}" != "no"
then
CFLAGS="${CFLAGS} -g"
fi
dnl ****************************
dnl Output Files
dnl ****************************
dnl Generate config.h
echo ""
echo -n "Generating ${CONFIG}:"
rm -f ${CONFIG}
touch ${CONFIG}
echo -n "."
echo "#define PROGRAM_NAME \"${PROGRAM_NAME}\" " >> ${CONFIG}
echo "#define VERSION_MAJOR \"${VERSION_MAJOR}\" " >> ${CONFIG}
echo "#define VERSION_MINOR \"${VERSION_MINOR}\" " >> ${CONFIG}
echo "#define REVISION \"${REVISION}\"" >> ${CONFIG}
echo -n "."
for active in `echo ${ACTIVE}`
do
echo -n "."
echo "#define CONFIG_"$active >> ${CONFIG}
done
echo "Done"
dnl Generate Makefile
echo -n "Generating Makefile:"
rm -f Makefile
touch Makefile
echo -n "."
echo "VERSION= ${VERSION_MAJOR}-${VERSION_MINOR}-${REVISION}" >> Makefile
echo "FILES= ${BUILTIN} ${ACTIVE}" >> Makefile
echo "" >> Makefile
echo "#Compilation Flags" >> Makefile
if test ${includedir} != "\${prefix}/include"
then
CFLAGS="${CFLAGS} -I${includedir}"
fi
echo "CFLAGS = ${CFLAGS}" >> Makefile
echo "LDFLAGS = ${LDFLAGS} " >> Makefile
echo -n "."
echo "" >> Makefile
echo "# Build files" >> Makefile
echo "EXECNAME = ${EXECNAME}" >> Makefile
echo "CONFFILE = ${CONFFILE}" >> Makefile
echo "MANPAGE = ${MANPAGE}" >> Makefile
echo -n "."
echo "" >> Makefile
echo "# Build directories" >> Makefile
if test "${prefix}" != "NONE"
then
echo "prefix = ${prefix}" >> Makefile
else
echo "prefix = ${DEFAULT_PREFIX}" >> Makefile
fi
if test "${exec_prefix}" != "NONE"
then
echo "exec_prefix = ${exec_prefix}" >> Makefile
else
if test "${prefix}" != "NONE"
then
echo "exec_prefix = ${prefix}" >> Makefile
else
echo "exec_prefix = ${DEFAULT_PREFIX}" >> Makefile
fi
fi
echo "EXECDIR = ${bindir}" >> Makefile
echo "CONFDIR = ${sysconfdir}" >> Makefile
echo "MANDIR = ${mandir}" >> Makefile
echo -n "."
echo "" >> Makefile
cat Makefile.in >> Makefile
echo ".Done"
echo -n "Run 'make' to build ${PROGRAM_NAME} "
echo "${VERSION_MAJOR}.${VERSION_MINOR}.${REVISION}"
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* parser.cpp : SAP configuration file parser * parser.cpp : SAP configuration file parser
**************************************************************************** ****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: parser.cpp,v 1.6 2003/07/24 16:35:08 nitrox Exp $ * $Id: parser.cpp,v 1.7 2003/08/10 12:44:18 zorglub Exp $
* *
* Authors: Arnaud Schauly <gitan@via.ecp.fr> * Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Clment Stenac <zorglub@via.ecp.fr> * Clment Stenac <zorglub@via.ecp.fr>
...@@ -43,12 +43,13 @@ using namespace std; ...@@ -43,12 +43,13 @@ using namespace std;
#include "message.h" #include "message.h"
#include "parser.h" #include "parser.h"
Config::Config(string f) Config::Config(string f)
{ {
file = f; file = f;
ttl = DEFAULT_TTL; ttl = DEFAULT_TTL;
scope = DEFAULT_SCOPE; scope = DEFAULT_SCOPE;
type = TYPE_SAP;
reverse = false;
} }
Config::~Config() Config::~Config()
...@@ -71,6 +72,11 @@ bool Config::GetDaemonMode(void) ...@@ -71,6 +72,11 @@ bool Config::GetDaemonMode(void)
return daemon; return daemon;
} }
bool Config::GetReverse(void)
{
return reverse;
}
void Config::SetDaemonMode(bool d) void Config::SetDaemonMode(bool d)
{ {
daemon=true; daemon=true;
...@@ -92,11 +98,33 @@ void Config::SetFile(char* s) ...@@ -92,11 +98,33 @@ void Config::SetFile(char* s)
file=s; file=s;
} }
void Config::SetReverse(bool d)
{
reverse= true;
}
void Config::SetType(char *s)
{
if(!strcasecmp(s,"slp"))
{
type=TYPE_SLP;
}
else
{
type=TYPE_SAP;
}
}
int Config::GetIPVersion() int Config::GetIPVersion()
{ {
return ipversion; return ipversion;
} }
int Config::GetType()
{
return type;
}
char Config::GetScope() char Config::GetScope()
{ {
return scope[0]; return scope[0];
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* parser.h : SAP configuration file parser definition * parser.h : SAP configuration file parser definition
**************************************************************************** ****************************************************************************
* Copyright (C) 1998-2003 VideoLAN * Copyright (C) 1998-2003 VideoLAN
* $Id: parser.h,v 1.4 2003/07/24 17:09:22 nitrox Exp $ * $Id: parser.h,v 1.5 2003/08/10 12:44:18 zorglub Exp $
* *
* Authors: Fabrice Ollivier <cif@via.ecp.fr> * Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr> * Arnaud Schauly <gitan@via.ecp.fr>
...@@ -34,9 +34,13 @@ class Config ...@@ -34,9 +34,13 @@ class Config
void SetTTL(unsigned int); void SetTTL(unsigned int);
bool GetDaemonMode(void); bool GetDaemonMode(void);
void SetDaemonMode(bool); void SetDaemonMode(bool);
bool GetReverse(void);
void SetReverse(bool);
void SetDotMode(bool); void SetDotMode(bool);
bool GetDotMode(void); bool GetDotMode(void);
void SetFile(char*); void SetFile(char*);
void SetType(char*);
int GetType();
int GetIPVersion(); int GetIPVersion();
char GetScope(); char GetScope();
vector<Program*> Programs; vector<Program*> Programs;
...@@ -46,8 +50,10 @@ class Config ...@@ -46,8 +50,10 @@ class Config
int ttl; int ttl;
int ipversion; int ipversion;
char * scope; char * scope;
int type;
bool daemon; bool daemon;
bool dot; bool dot;
bool reverse;
void strgetb(char *source,char *dest,char delim); void strgetb(char *source,char *dest,char delim);
void strgeta(char *source,char *dest,char delim); void strgeta(char *source,char *dest,char delim);
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* program.cpp : SAP Program class * program.cpp : SAP Program class
**************************************************************************** ****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: program.cpp,v 1.7 2003/07/24 17:09:22 nitrox Exp $ * $Id: program.cpp,v 1.8 2003/08/10 12:44:18 zorglub Exp $
* *
* Authors: Damien Lucas <nitrox@videolan.org> * Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be> * Philippe Van Hecke <philippe.vanhecke@belnet.be>
...@@ -36,6 +36,8 @@ using namespace std; ...@@ -36,6 +36,8 @@ using namespace std;
Program::Program() Program::Program()
{ {
/* Set default Values */ /* Set default Values */
address="";
port="";
permanent = true; permanent = true;
program_ipversion = 4; program_ipversion = 4;
program_ttl = "15"; program_ttl = "15";
......
...@@ -11,11 +11,11 @@ ipv6_scope=8 ...@@ -11,11 +11,11 @@ ipv6_scope=8
# IPv4 exemple # IPv4 exemple
[program] [program]
name=TV1 # Name of the program (as will show up in the VLC playlist) name=Tele V1 # Name of the program (as will show up in the VLC playlist)
user=videolan # Name of the streaming entity user=videolan # Name of the streaming entity
machine=vlcs.via.ecp.fr # Name of the streaming machine machine=vlcs.via.ecp.fr # Name of the streaming machine
site=www.videolan.org # Site of the streaming entity site=www.videolan.org # Site of the streaming entity
address=239.255.42.12 # Multicast IP address of the program address=239.255.12.42 # Multicast IP address of the program
port=1234 # UDP Port port=1234 # UDP Port
program_ttl=32 # TTL for this program (15 is the default value) program_ttl=32 # TTL for this program (15 is the default value)
program_ipversion=4 # 4 or 6 (4 is the default value) program_ipversion=4 # 4 or 6 (4 is the default value)
...@@ -30,3 +30,17 @@ program_ttl=12 ...@@ -30,3 +30,17 @@ program_ttl=12
program_ipversion=6 program_ipversion=6
address=ff08::1 address=ff08::1
port=1234 port=1234
# HTTP exemple (not yet implemented)
[program]
name=TV3
user=videolan
machine=vlcs.via.ecp.fr
site=www.videolan.org
program_ttl=12
program_ipversion=4
type=http
address=myserver.com
port=80
path=/myfolder/mystream.mpg
.TH SAPSERVER 1 "August 9, 2003" "Clément Stenac" "VideoLAN"
.SH NAME
sapserver - SAP and SLP announcment for the VLC Media Player
.SH SYNOPSIS
.B sapserver
.BR [OPTIONS]
.PP
.SH DESCRIPTION
.B sapserver
announces,using the SAP/SDP or the SLP protocols, streams to be played with the VLC Media Player
.SH OPTIONS
.TP
.B -f file
Use the \fIfile\fP as configuration file
.TP
.B -c file
Same as -f
.TP
.B -d
Daemonize the process (run it in the background)
.TP
.B -h
Displays the help
.TP
.B -t
Specifies the protocol to use ("slp" or "sap". Default is sap)
.TP
.B -u
When using SLP, unregister the programs
.TP
.B -s
When using SAP, display a dot for each packet sent
.SH "SEE ALSO"
.IR vlc(1)
.TP
The "VideoLAN Howto", found on http://www.videolan.org
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
* sapserver.cpp : SAP discovery service mini-server * sapserver.cpp : SAP discovery service mini-server
**************************************************************************** ****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: sapserver.cpp,v 1.13 2003/07/24 17:09:22 nitrox Exp $ * $Id: sapserver.cpp,v 1.14 2003/08/10 12:44:18 zorglub Exp $
* *
* Authors: Fabrice Ollivier <cif@via.ecp.fr> * Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
* Clment Stenac <zorglub@via.ecp.fr> * Clment Stenac <zorglub@via.ecp.fr>
* Damien Lucas <nitrox@videolan.org> * Damien Lucas <nitrox@videolan.org>
* *
...@@ -38,12 +37,18 @@ ...@@ -38,12 +37,18 @@
using namespace std; using namespace std;
#include "config.h"
#include "program.h" #include "program.h"
#include "message.h" #include "message.h"
#include "broadcast.h" #include "broadcast.h"
#include "parser.h" #include "parser.h"
#include "sapserver.h" #include "sapserver.h"
#ifdef CONFIG_slp
#include <slp.h>
#include "slp.h"
#endif
/************************************************* /*************************************************
* Display the help * Display the help
...@@ -54,6 +59,7 @@ void help(void) ...@@ -54,6 +59,7 @@ void help(void)
" -d Use this to daemonize the process (run in the background)\n" \ " -d Use this to daemonize the process (run in the background)\n" \
" -f Use this to give a configuration file (default is %s)\n" \ " -f Use this to give a configuration file (default is %s)\n" \
" -c Same as -f\n" \ " -c Same as -f\n" \
" -t \"slp\" or \"sap\". sap is default" \
" -h Display this help\n" \ " -h Display this help\n" \
" -s Display a dot for each packet sent\n",DEFAULT_CONF); " -s Display a dot for each packet sent\n",DEFAULT_CONF);
} }
...@@ -69,13 +75,16 @@ int main(int argc, char *argv[]) ...@@ -69,13 +75,16 @@ int main(int argc, char *argv[])
Broadcast* broadcast; Broadcast* broadcast;
Message *message; Message *message;
Config *config; Config *config;
#ifdef CONFIG_slp
SLP *slp;
#endif
fprintf(stdout, "%s Version %s - (c)1999-2003 VideoLAN\n\n", fprintf(stdout, "%s Version %s.%s.%s - (c)1999-2003 VideoLAN\n\n",
PROGRAM_NAME,VERSION); PROGRAM_NAME,VERSION_MAJOR,VERSION_MINOR,REVISION);
config=new Config(DEFAULT_CONF); config=new Config(DEFAULT_CONF);
/* Parse the command line */ /* Parse the command line */
sprintf(getopt_string,"dhsf:c:"); sprintf(getopt_string,"dhsf:c:t:u");
while((result = getopt(argc,argv,getopt_string))>0) while((result = getopt(argc,argv,getopt_string))>0)
{ {
switch(result) switch(result)
...@@ -90,6 +99,12 @@ int main(int argc, char *argv[]) ...@@ -90,6 +99,12 @@ int main(int argc, char *argv[])
case 'd': case 'd':
config->SetDaemonMode(true); config->SetDaemonMode(true);
break; break;
case 't':
config->SetType(optarg);
break;
case 'u':
config->SetReverse(true);
break;
case 'h': case 'h':
help(); help();
return ( 0 ); return ( 0 );
...@@ -98,7 +113,6 @@ int main(int argc, char *argv[]) ...@@ -98,7 +113,6 @@ int main(int argc, char *argv[])
} }
} }
/* Get the programs */ /* Get the programs */
fprintf(stdout, "+ Parsing configuration file\n"); fprintf(stdout, "+ Parsing configuration file\n");
if(config->Parse()) if(config->Parse())
...@@ -108,62 +122,103 @@ int main(int argc, char *argv[]) ...@@ -108,62 +122,103 @@ int main(int argc, char *argv[])
} }
/*TODO check configuration */ /*TODO check configuration */
fprintf(stdout, "+ %d programs loaded\n",(int)config->Programs.size()); fprintf(stdout, "+ %d programs loaded\n",(int)config->Programs.size());
fprintf(stdout, "+ Packet TTL set to %i\n",config->GetTTL());
if(config->GetDaemonMode()) fprintf(stdout, "+ Running as daemon.\n");
else fprintf(stdout, "+ Running as program.\n");
/* Create the broadcast object */
/* IPv4 is the default behavior */
broadcast = new Broadcast(config->GetTTL());
if(config->GetIPVersion() == 6)
{
fprintf(stdout,"+ Using IPv6\n");
i_init_status=broadcast->Initv6(config->GetScope());
}
else
{
fprintf(stdout,"+ Using IPv4\n");
i_init_status=broadcast->Initv4();
}
if(config->GetType() == TYPE_SAP)
if(i_init_status)
{ {
fprintf(stderr,"- Network initialization failed. Aborting\n"); fprintf(stdout, "+ Packet TTL set to %i\n",config->GetTTL());
return -1; if(config->GetDaemonMode()) fprintf(stdout, "+ Running as daemon.\n");
} else fprintf(stdout, "+ Running as program.\n");
/* Create the broadcast object */
/* IPv4 is the default behavior */
broadcast = new Broadcast(config->GetTTL());
if(config->GetIPVersion() == 6)
{
fprintf(stdout,"+ Using IPv6\n");
i_init_status=broadcast->Initv6(config->GetScope());
}
else
{
fprintf(stdout,"+ Using IPv4\n");
i_init_status=broadcast->Initv4();
}
/* Forking if necessary */
if(config->GetDaemonMode())
{
fprintf(stdout, "+ Forking ... \n");
daemon(0,0);
}
if(i_init_status)
{
fprintf(stderr,"- Network initialization failed. Aborting\n");
return -1;
}
while(1) /* Forking if necessary */
{ if(config->GetDaemonMode())
for (unsigned int i=0; i<config->Programs.size(); i++)
{ {
/* Create a new message */ fprintf(stdout, "+ Forking ... \n");
message=new Message(SAP_ANNOUNCE, 0x4212, "1.2.3.4"); daemon(0,0);
/* Build the message header */ }
message->BuildHeader("application/sdp");
/* Add the program */
message->AddProgram(config->Programs[i]);
/* Send the message */
if(broadcast->Send( message , config->GetIPVersion() ))
fprintf(stderr,"- Message send failed\n");
/* Delete the message */
delete message;
if(config->GetDotMode())
fprintf(stdout,".");
while(1)
{
for (unsigned int i=0; i<config->Programs.size(); i++)
{
/* Create a new message */
message=new Message(SAP_ANNOUNCE, 0x4212, "1.2.3.4");
/* Build the message header */
message->BuildHeader("application/sdp");
/* Add the program */
message->AddProgram(config->Programs[i]);
/* Send the message */
if(broadcast->Send( message , config->GetIPVersion() ))
fprintf(stderr,"- Message send failed\n");
/* Delete the message */
delete message;
if(config->GetDotMode())
fprintf(stdout,".");
}
fflush(stdout);
/* Wait for next sending */
sleep(SAP_DELAY);
} }
fflush(stdout);
/* Wait for next sending */