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

* Bugfix in configuration file parsing

* Sanity check
parent 48498c85
......@@ -2,7 +2,7 @@
* parser.cpp : SAP configuration file parser
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: parser.cpp,v 1.4 2003/06/16 10:26:47 zorglub Exp $
* $Id: parser.cpp,v 1.5 2003/06/16 15:30:11 zorglub Exp $
*
* Authors: Arnaud Schauly <gitan@via.ecp.fr>
* Clment Stenac <zorglub@via.ecp.fr>
......@@ -46,9 +46,9 @@ using namespace std;
Config::Config(string f)
{
file=f;
ttl=DEFAULT_TTL;
scope=DEFAULT_SCOPE;
file = f;
ttl = DEFAULT_TTL;
scope = DEFAULT_SCOPE;
}
Config::~Config()
......@@ -99,8 +99,6 @@ int Config::GetIPVersion()
char Config::GetScope()
{
// printf("%s\n",scope);
// printf("%c\n",scope[0]);
return scope[0];
}
......@@ -158,7 +156,7 @@ int Config::Parse()
fd=fopen(file.c_str(),"r");
if(!fd)
{
fprintf(stderr, "Unable to open %s\n",file.c_str());
fprintf(stderr, "- Unable to open %s\n",file.c_str());
return(-1);
}
......@@ -166,6 +164,7 @@ int Config::Parse()
{
memset(line,'0',1024);
fgets(line,1024,fd);
if(!strlen(line))
{
break;
......@@ -173,24 +172,28 @@ int Config::Parse()
strgetb(line,line,'#'); /* Handle the comments */
if(strstr(line,"ttl="))
/* Set SAP TTL (ttl is a member of config) */
if(strstr(line,"sap_ttl="))
{
strgeta(line,tline,'=');
ttl=atoi(tline);
}
/* Set SAP IP Version (ipversion is a member of config) */
if(strstr(line,"sap_ipversion="))
{
strgeta(line,tline,'=');
ipversion=atoi(tline);
}
/* Set SAP IPv6 Scope (scope is a member of config) */
if(strstr(line,"ipv6_scope="))
{
strgeta(line,tline,'=');
scope=strdup(tline);
// scope=tline;
}
/* Beginning of programs parsing */
if(strstr(line,"[program]"))
{
if(something)
......@@ -212,12 +215,14 @@ int Config::Parse()
something=1;
pp->SetName(tline);
}
if(strstr(line,"program_ttl="))
{
strgeta(line,tline,'=');
something=1;
pp->SetTTL(tline);
}
if(strstr(line,"program_ipversion="))
{
strgeta(line,tline,'=');
......@@ -225,8 +230,6 @@ int Config::Parse()
pp->SetIPVersion(tline);
}
if(strstr(line,"user="))
{
strgeta(line,tline,'=');
......@@ -267,9 +270,8 @@ int Config::Parse()
if (!pp->GetPort().length())
{
pp->SetPort("1234");
pp->SetPort(DEFAULT_PORT);
}
Programs.push_back(pp);
}
return(0);
......
......@@ -2,7 +2,7 @@
* program.cpp : SAP Program class
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: program.cpp,v 1.4 2003/06/16 10:26:47 zorglub Exp $
* $Id: program.cpp,v 1.5 2003/06/16 15:30:12 zorglub Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
* Philippe Van Hecke <philippe.vanhecke@belnet.be>
......@@ -36,12 +36,12 @@ using namespace std;
Program::Program()
{
/* Set default Values */
permanent=true;
program_ipversion=4;
program_ttl="15";
machine="localhost";
user="VideoLAN";
site="http://www.videolan.org";
permanent = true;
program_ipversion = 4;
program_ttl = "15";
machine = "localhost";
user = "VideoLAN";
site = "http://www.videolan.org";
return;
}
Program::~Program() {return;}
......@@ -63,7 +63,9 @@ void Program::SetUser(char* u){user=u;}
void Program::SetMachine(char* m){machine=m;}
void Program::SetSite(char* s){site=s;}
void Program::SetAddress(char* a){address=a;}
void Program::SetPort(char* p){port=p;}
void Program::SetTTL(char *p){program_ttl=p;}
void Program::SetIPVersion(char *p){program_ipversion=atoi(p);}
......
......@@ -2,7 +2,7 @@
* program.h : SAP programs classes definition
****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: program.h,v 1.4 2003/06/16 10:26:47 zorglub Exp $
* $Id: program.h,v 1.5 2003/06/16 15:30:12 zorglub Exp $
*
* Authors: Damien Lucas <nitrox@videolan.org>
*
......@@ -28,6 +28,8 @@ class Program
Program(string, string, string, string, string,string);
Program();
~Program();
/* Functions to get the values */
string GetName();
string GetUser();
string GetMachine();
......@@ -36,6 +38,8 @@ class Program
string GetPort();
string GetTTL();
int GetIPVersion();
/* Functions to set the values */
void SetName(char*);
void SetUser(char*);
void SetMachine(char*);
......@@ -44,6 +48,7 @@ class Program
void SetPort(char *);
void SetTTL(char *);
void SetIPVersion(char *);
bool IsPermanent();
private:
......
# sap.cfg - Configuration file of the mini SAP server
[global]
ttl=255 # TTL (Time To Live) of the SAP announces. You should put 255
sap_ttl=255 # TTL (Time To Live) of the SAP announces. You should put 255
sap_ipversion=4 # Version of IP Protocol to use: 4 for IPv4, 6 for IPv6
ipv6_scope=A
# This is the "scope" of the IPv6 announce (if it exists)
......@@ -12,12 +12,13 @@ ipv6_scope=A
# IPv4 exemple
[program]
name=TV1 # 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
site=www.videolan.org # Site of the streaming entity
address=239.255.42.12 # Multicast IP address of the program
port=1234 # UDP Port. Default is 1234
program_ttl=24 # TTL for this program (15 is the default value)
# UDP Port
port=1234
program_ttl=32 # TTL for this program (15 is the default value)
program_ipversion=4 # 4 or 6 (4 is the default value)
# IPv6 exemple
......
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