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
CFLAGS= -Wall -Wstrict-prototypes -g
# Makefile.in : Makefile structure for mini-SAP-server
# $Id: Makefile.in,v 1.1 2003/08/10 12:44:18 zorglub Exp $
FILES=program message parser broadcast
FILES_O=$(FILES:%=%.o)
GPP= g++ $(CFLAGS)
......@@ -12,8 +11,8 @@ default: sapserver
# Main target. Build .o files from every.cpp files and build the final
# executable
sapserver: $(FILES_O) sapserver.cpp sapserver.h
$(GPP) -o sapserver $(FILES_O) sapserver.cpp -DVERSION=\"$(VERSION)\"
sapserver: $(FILES_O)
$(GPP) $(LDFLAGS) -o ${EXECNAME} $(FILES_O)
# Target that builds a .o from each .cpp
$(FILES_O): %.o: %.cpp %.h
......@@ -22,13 +21,28 @@ $(FILES_O): %.o: %.cpp %.h
# Delete the .o files and the executable
clean:
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
distclean: clean
rm -f miniSAPserver-${VERSION}.tar.bz2
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.
dist:
-# Check that tmp isn't in the way
......@@ -38,13 +52,15 @@ dist:
echo "Starting dist's build."; mkdir tmp; \
fi
mkdir tmp/miniSAPserver/
# Copy the Makefile
cp Makefile tmp/miniSAPserver/
# Rebuild the configure script
autoconf
# Copy the Makefile.in & configure script
cp Makefile.in configure tmp/miniSAPserver/
# Copy the configration file
cp sap.cfg tmp/miniSAPserver/
# Copy all headers and source code files
cp *.cpp *.h tmp/miniSAPserver/
# Copy AUTHORS and CPYING
# Copy AUTHORS and COPYING
cp AUTHORS COPYING tmp/miniSAPserver/
# Build archives
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
* Bugfixes
-- 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
* 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
......
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 @@
* parser.cpp : SAP configuration file parser
****************************************************************************
* 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>
* Clment Stenac <zorglub@via.ecp.fr>
......@@ -43,12 +43,13 @@ using namespace std;
#include "message.h"
#include "parser.h"
Config::Config(string f)
{
file = f;
ttl = DEFAULT_TTL;
scope = DEFAULT_SCOPE;
type = TYPE_SAP;
reverse = false;
}
Config::~Config()
......@@ -71,6 +72,11 @@ bool Config::GetDaemonMode(void)
return daemon;
}
bool Config::GetReverse(void)
{
return reverse;
}
void Config::SetDaemonMode(bool d)
{
daemon=true;
......@@ -92,11 +98,33 @@ void Config::SetFile(char* 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()
{
return ipversion;
}
int Config::GetType()
{
return type;
}
char Config::GetScope()
{
return scope[0];
......
......@@ -2,7 +2,7 @@
* parser.h : SAP configuration file parser definition
****************************************************************************
* 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>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -34,9 +34,13 @@ class Config
void SetTTL(unsigned int);
bool GetDaemonMode(void);
void SetDaemonMode(bool);
bool GetReverse(void);
void SetReverse(bool);
void SetDotMode(bool);
bool GetDotMode(void);
void SetFile(char*);
void SetType(char*);
int GetType();
int GetIPVersion();
char GetScope();
vector<Program*> Programs;
......@@ -46,8 +50,10 @@ class Config
int ttl;
int ipversion;
char * scope;
int type;
bool daemon;
bool dot;
bool reverse;
void strgetb(char *source,char *dest,char delim);
void strgeta(char *source,char *dest,char delim);
};
......@@ -2,7 +2,7 @@
* program.cpp : SAP Program class
****************************************************************************
* 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>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......@@ -36,6 +36,8 @@ using namespace std;
Program::Program()
{
/* Set default Values */
address="";
port="";
permanent = true;
program_ipversion = 4;
program_ttl = "15";
......
......@@ -11,11 +11,11 @@ ipv6_scope=8
# IPv4 exemple
[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
machine=vlcs.via.ecp.fr # Name of the streaming machine
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
program_ttl=32 # TTL for this program (15 is the default value)
program_ipversion=4 # 4 or 6 (4 is the default value)
......@@ -30,3 +30,17 @@ program_ttl=12
program_ipversion=6
address=ff08::1
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 @@
* sapserver.cpp : SAP discovery service mini-server
****************************************************************************
* 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>
* Arnaud Schauly <gitan@via.ecp.fr>
* Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Clment Stenac <zorglub@via.ecp.fr>
* Damien Lucas <nitrox@videolan.org>
*
......@@ -38,12 +37,18 @@
using namespace std;
#include "config.h"
#include "program.h"
#include "message.h"
#include "broadcast.h"
#include "parser.h"
#include "sapserver.h"
#ifdef CONFIG_slp
#include <slp.h>
#include "slp.h"
#endif
/*************************************************
* Display the help
......@@ -54,6 +59,7 @@ void help(void)
" -d Use this to daemonize the process (run in the background)\n" \
" -f Use this to give a configuration file (default is %s)\n" \
" -c Same as -f\n" \
" -t \"slp\" or \"sap\". sap is default" \
" -h Display this help\n" \
" -s Display a dot for each packet sent\n",DEFAULT_CONF);
}
......@@ -69,13 +75,16 @@ int main(int argc, char *argv[])
Broadcast* broadcast;
Message *message;
Config *config;
#ifdef CONFIG_slp
SLP *slp;
#endif
fprintf(stdout, "%s Version %s - (c)1999-2003 VideoLAN\n\n",
PROGRAM_NAME,VERSION);
fprintf(stdout, "%s Version %s.%s.%s - (c)1999-2003 VideoLAN\n\n",
PROGRAM_NAME,VERSION_MAJOR,VERSION_MINOR,REVISION);
config=new Config(DEFAULT_CONF);
/* Parse the command line */
sprintf(getopt_string,"dhsf:c:");
sprintf(getopt_string,"dhsf:c:t:u");
while((result = getopt(argc,argv,getopt_string))>0)
{
switch(result)
......@@ -90,6 +99,12 @@ int main(int argc, char *argv[])
case 'd':
config->SetDaemonMode(true);
break;
case 't':
config->SetType(optarg);
break;
case 'u':
config->SetReverse(true);
break;
case 'h':
help();
return ( 0 );
......@@ -98,7 +113,6 @@ int main(int argc, char *argv[])
}
}
/* Get the programs */
fprintf(stdout, "+ Parsing configuration file\n");
if(config->Parse())
......@@ -108,62 +122,103 @@ int main(int argc, char *argv[])
}
/*TODO check configuration */
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(i_init_status)
if(config->GetType() == TYPE_SAP)
{
fprintf(stderr,"- Network initialization failed. Aborting\n");
return -1;
}
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();
}
/* 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)
{
for (unsigned int i=0; i<config->Programs.size(); i++)
/* Forking if necessary */
if(config->GetDaemonMode())
{
/* 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,".");
fprintf(stdout, "+ Forking ... \n");
daemon(0,0);
}
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 */
sleep(SAP_DELAY);
}
else
{
#ifndef CONFIG_slp
fprintf(stderr,"- SLP not compiled in...Aborting\n");
return -1;
#endif
#ifdef CONFIG_slp
slp = new SLP();
for(unsigned int i=0 ; i<config->Programs.size(); i++)
{
if(!config->GetReverse())
{
slp->Register(config->Programs[i]);
}
else
{
slp->UnRegister(config->Programs[i]);
}
}
if(!config->GetReverse())
{
fprintf(stdout,"+ Programs registered. To unregister them, run" \
"me with -u\n");
}
else
{
fprintf(stdout,"+ Programs unregistered\n");
}
fflush(stdout);
delete slp;
#endif
}
fprintf(stdout,"Done");
return 0;
}
......@@ -2,7 +2,7 @@
* sapserver.h : SAP discovery service classes definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: sapserver.h,v 1.6 2003/07/24 17:09:22 nitrox Exp $
* $Id: sapserver.h,v 1.7 2003/08/10 12:44:18 zorglub Exp $
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......@@ -24,8 +24,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define PROGRAM_NAME "miniSAPserver"
#define SAP_DELAY 1 /* wait DELAY seconds before each sending */
#define MSGBUFSIZE 256
......@@ -36,6 +34,9 @@
#define DEFAULT_PORT "1234"
#define TYPE_SAP 1
#define TYPE_SLP 2
#define SAP_ON 1
#define SAP_OFF 0
#define SAP_ANNOUNCE 0
......
/*****************************************************************************
* slp.cpp : SLP registration class
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: slp.cpp,v 1.1 2003/08/10 12:44:18 zorglub Exp $
*
* Authors: Clment Stenac <zorglub@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <vector>
#include "program.h"
#include "config.h"
#ifdef CONFIG_slp
#include <slp.h>
#endif
#include "slp.h"
using namespace std;
SLP::SLP()
{
if( SLPOpen( NULL, SLP_FALSE, &slp_handle ) != SLP_OK)
{
fprintf(stderr,"- Unable to initialize SLP\n");
abort();
}
}
SLP::~SLP(){return;}
void RegReport(SLPHandle slp_handle,SLPError slp_error,void* cookie)
{
}
char * BuildService(Program *p)
{
char *psz_msg;
string msg="";
string url="";