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