Commit 12b1665d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- Clean up

- Basic signal handling
parent 83612ed1
......@@ -17,7 +17,7 @@ C: gitan
D: Core
S: France
N: Clment Stenac
N: Clément Stenac
E: zorglub@via.ecp.fr
C: zorglub
D: Core
......@@ -30,3 +30,8 @@ D: Delay option
D: Standards compliance fixes
S: Netherlands
N: Rémi Denis-Courmont
E: rem at videolan dot org
C: courmisch
D: Unicode support, various fixes
S: France
#! /bin/sh
## Minimalistic boostrap file for the mini-SAP-server
## $Id: bootstrap,v 1.1 2003/08/12 15:59:19 zorglub Exp $
## $Id$
set +x
......
......@@ -2,7 +2,7 @@
* broadcast.cpp : SAP Broadcast class
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: broadcast.cpp,v 1.7 2003/10/29 00:43:39 nitrox Exp $
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......
......@@ -2,7 +2,7 @@
* broacast.h : SAP Broadcast Class definition
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: broadcast.h,v 1.3 2003/06/16 10:26:47 zorglub Exp $
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......
dnl Autoconf settings for mini-SAP-server
dnl $Id: configure.ac,v 1.3 2003/10/29 00:43:39 nitrox Exp $
dnl $Id$
AC_INIT(miniSAPserver,0.2.5-svn,streaming@videolan.org)
AM_INIT_AUTOMAKE(miniSAPserver,0.2.5-svn)
......
......@@ -2,7 +2,7 @@
* slp.h : SLP Class definition
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: lslp.h,v 1.1 2003/08/12 15:59:19 zorglub Exp $
* $Id$
*
* Authors: Clément Stenac <zorglub@via.ecp.fr>
*
......
......@@ -2,7 +2,7 @@
* message.cpp : SAP Message class
****************************************************************************
* Copyright (C) 1998-2004 VideoLAN
* $Id: message.cpp,v 1.8 2003/09/23 16:47:15 nitrox Exp $
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......
......@@ -2,7 +2,7 @@
* message.h : SAP Message Class definition
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: message.h,v 1.2 2003/05/25 16:36:00 nitrox Exp $
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......
......@@ -2,7 +2,7 @@
* parser.cpp : SAP configuration file parser
****************************************************************************
* Copyright (C) 1998-2005 VideoLAN
* $Id: parser.cpp,v 1.8 2003/09/11 15:33:53 zorglub Exp $
* $Id$
*
* Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Clément Stenac <zorglub@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* parser.h : SAP configuration file parser definition
****************************************************************************
* Copyright (C) 1998-2004 VideoLAN
* $Id: parser.h,v 1.5 2003/08/10 12:44:18 zorglub Exp $
* $Id$
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* program.cpp : SAP Program class
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: program.cpp,v 1.9 2003/09/11 15:33:53 zorglub Exp $
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......
......@@ -2,7 +2,7 @@
* program.h : SAP programs classes definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: program.h,v 1.7 2003/09/11 15:33:53 zorglub Exp $
* $Id$
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......
......@@ -2,7 +2,7 @@
* sapserver.cpp : SAP discovery service mini-server
****************************************************************************
* Copyright (C) 1998-2004 VideoLAN
* $Id: sapserver.cpp,v 1.16 2003/09/23 16:47:15 nitrox Exp $
* $Id$
*
* Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Clément Stenac <zorglub@via.ecp.fr>
......@@ -31,6 +31,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <locale.h>
#include <string>
......@@ -49,6 +50,19 @@ using namespace std;
#include "lslp.h"
#endif
/*************************************************
* Signal handler
*************************************************/
static int should_exit = 0;
static void
exit_handler (int signum)
{
signal (signum, exit_handler);
should_exit = 1;
}
/*************************************************
* Display the help
*************************************************/
......@@ -70,17 +84,15 @@ int main(int argc, char *argv[])
{
int result=0;
int i_init_status=0;
Broadcast* broadcast;
Message *message;
Config *config;
#ifdef CONFIG_SLP
SLP *slp;
#endif
setlocale(LC_ALL, "");
fprintf(stdout, "%s Version %s - (c)1999-2004 VideoLAN\n\n",
fprintf(stdout, "%s Version %s - (c)1999-2005 VideoLAN\n\n",
PACKAGE,VERSION);
config=new Config(DEFAULT_CONF);
Config config(DEFAULT_CONF);
/* Parse the command line */
while((result = getopt(argc,argv,"dhsf:c:t:u"))>0)
......@@ -89,20 +101,20 @@ int main(int argc, char *argv[])
{
case 'c':
case 'f':
config->SetFile(optarg);
config.SetFile(optarg);
break;
case 's':
config->SetDotMode(true);
config.SetDotMode(true);
break;
case 'd':
config->SetDaemonMode(true);
config.SetDaemonMode(true);
break;
case 't':
config.SetType(optarg);
break;
case 'u':
config.SetReverse(true);
break;
case 't':
config->SetType(optarg);
break;
case 'u':
config->SetReverse(true);
break;
case 'h':
help();
return ( 0 );
......@@ -113,32 +125,32 @@ int main(int argc, char *argv[])
/* Get the programs */
fprintf(stdout, "+ Parsing configuration file\n");
if(config->Parse())
if(config.Parse())
{
fprintf(stderr, "+ Parsing failed\n");
return(-1);
}
/*TODO check configuration */
fprintf(stdout, "+ %d programs loaded\n",(int)config->Programs.size());
fprintf(stdout, "+ %d programs loaded\n",(int)config.Programs.size());
if(config->GetType() == TYPE_SAP)
if(config.GetType() == TYPE_SAP)
{
printf("+ Packet TTL set to %i\n",config->GetTTL());
printf("+ Packet TTL set to %i\n",config.GetTTL());
printf("+ Running as %s.\n",
config->GetDaemonMode() ? "daemon" : "program");
config.GetDaemonMode() ? "daemon" : "program");
/* Create the broadcast object */
/* IPv4 is the default behavior */
broadcast = new Broadcast(config->GetInterface(),config->GetTTL());
if(config->GetIPVersion() == 6)
Broadcast broadcast(config.GetInterface(),config.GetTTL());
if(config.GetIPVersion() == 6)
{
fprintf(stdout,"+ Using IPv6\n");
i_init_status=broadcast->Initv6(config->GetScope());
i_init_status=broadcast.Initv6(config.GetScope());
}
else
{
fprintf(stdout,"+ Using IPv4\n");
i_init_status=broadcast->Initv4();
i_init_status=broadcast.Initv4();
}
......@@ -149,7 +161,7 @@ int main(int argc, char *argv[])
}
/* Forking if necessary */
if(config->GetDaemonMode())
if(config.GetDaemonMode())
{
fprintf(stdout, "+ Forking ... \n");
daemon(0,0);
......@@ -157,28 +169,50 @@ int main(int argc, char *argv[])
vector<Message *> messages;
for (unsigned int i=0; i<config->Programs.size(); i++)
for (unsigned int i=0; i<config.Programs.size(); i++)
{
/* Create a new message */
message=new Message(SAP_ANNOUNCE, 0x4212+i, "1.2.3.4");
/* Build the message header */
message->BuildHeader("application/sdp");
/* Add the program */
message->AddProgram(config->Programs[i]);
message->AddProgram(config.Programs[i]);
messages.push_back( message );
}
while(1)
struct timespec delay;
if (config.Programs.size() == 1)
{
delay.tv_sec = 1;
delay.tv_nsec = 0;
}
else
{
delay.tv_sec = 0;
delay.tv_nsec = 1000000000 * config.GetDelay()
/ config.Programs.size();
}
signal (SIGINT, exit_handler);
signal (SIGTERM, exit_handler);
signal (SIGHUP, exit_handler);
signal (SIGQUIT, exit_handler);
while(!should_exit)
{
for( unsigned int i = 0; i< messages.size() ; i ++ )
{
Message *message = messages[i];
/* Send the message */
if(broadcast->Send( message , config->GetIPVersion() ))
if(broadcast.Send( message , config.GetIPVersion() ))
fprintf(stderr,"- Message send failed\n");
if(config->GetDotMode())
if(config.GetDotMode())
fprintf(stdout,".");
/* Wait for next sending */
usleep( 1+ (config->GetDelay() * 1000000 / config->Programs.size() ) );
if(should_exit)
break;
nanosleep( &delay, NULL );
}
fflush(stdout);
}
......@@ -191,31 +225,30 @@ int main(int argc, char *argv[])
#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
{
SLP 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
}
......
......@@ -2,7 +2,7 @@
* sapserver.h : SAP discovery service classes definition
****************************************************************************
* Copyright (C) 1998-2004 VideoLAN
* $Id: sapserver.h,v 1.7 2003/08/10 12:44:18 zorglub Exp $
* $Id$
*
* Authors: Fabrice Ollivier <cif@via.ecp.fr>
* Arnaud Schauly <gitan@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* slp.cpp : SLP registration class
****************************************************************************
* Copyright (C) 1998-2003 VideoLAN
* $Id: slp.cpp,v 1.3 2003/09/14 16:40:47 zorglub Exp $
* $Id$
*
* Authors: Clment Stenac <zorglub@via.ecp.fr>
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment