1 /*****************************************************************************
2  * program.cpp : SAP Program class
3  ****************************************************************************
4  * Copyright (C) 1998-2002 VideoLAN
5  * $Id: program.cpp 358 2009-04-25 20:45:09Z courmisch $
6  *
7  * Authors: Damien Lucas <nitrox@videolan.org>
8  *          Philippe Van Hecke <philippe.vanhecke@belnet.be>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24 
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string>
35 #include <vector>
36 using namespace std;
37 
38 #include "program.h"
39 
Program()40 Program::Program() : b_rtp(false), b_has_pl_group(false)
41 {
42     /* Set default Values */
43     address="";
44     port=0;
45     permanent = true;
46     program_ttl = "255";
47     machine = "localhost";
48     user = "VideoLAN";
49     site = "http://www.videolan.org";
50 	custom_sdp = "";
51 }
~Program()52 Program::~Program() {return;}
53 
GetName(void)54 string Program::GetName(void) {return name;}
GetUser(void)55 string Program::GetUser(void) {return user;}
GetMachine(void)56 string Program::GetMachine(void) {return machine;}
GetSite(void)57 string Program::GetSite(void) {return site;}
GetAddress(void)58 string Program::GetAddress(void){return address;}
GetPort(void)59 uint16_t Program::GetPort(void){return port;}
GetTTL(void)60 string Program::GetTTL(void){return program_ttl;}
GetPlGroup(void)61 string Program::GetPlGroup(void){return pl_group;}
GetCustomSDP(void)62 string Program::GetCustomSDP(void){return custom_sdp;}
IsPermanent(void)63 bool   Program::IsPermanent(void){return permanent;}
IsRTP(void)64 bool   Program::IsRTP(void){return b_rtp;}
HasPlGroup(void)65 bool   Program::HasPlGroup(void){return b_has_pl_group;}
HasCustomSDP(void)66 bool   Program::HasCustomSDP(void){return custom_sdp.size() ? true : false;}
SetName(const char * n)67 void Program::SetName(const char* n){name=n;}
SetUser(const char * u)68 void Program::SetUser(const char* u){user=u;}
SetMachine(const char * m)69 void Program::SetMachine(const char* m){machine=m;}
SetSite(const char * s)70 void Program::SetSite(const char* s){site=s;}
SetAddress(const char * a)71 void Program::SetAddress(const char* a){address=a;}
SetPlGroup(const char * h)72 void Program::SetPlGroup(const char *h){pl_group=h;}
SetRTP(bool b)73 void Program::SetRTP(bool b){b_rtp = b;}
SetHasPlGroup(bool b)74 void Program::SetHasPlGroup(bool b){b_has_pl_group = b ;}
SetPort(uint16_t p)75 void Program::SetPort(uint16_t p) { port = p; }
SetTTL(const char * p)76 void Program::SetTTL(const char *p){program_ttl=p;}
77 
Program(string n,string u,string m,string s,string a,uint16_t p)78 Program::Program(string n, string u, string m, string s, string a,uint16_t p)
79     : b_has_pl_group (false)
80 {
81     name=n;
82     user=u;
83     machine=m;
84     site=s;
85     address=a;
86     port=p;
87     permanent=true;
88 }
89 
SetCustomSDP(const char * fname)90 void Program::SetCustomSDP(const char *fname)
91 {
92     /* Although it's a (relatively small) fixed-sized buffer, we can't serve
93      * SDP any larger than this in any case - see the condition in
94      * Message::AddProgram():
95      *   if(msg_len + sdp.length () > 1024) - RFC 2974 Chap 6.
96      */
97     char buf[1024];
98     FILE *f;
99     ssize_t l;
100 
101     if(NULL == (f = fopen(fname, "rb")))
102     {
103         perror(fname);
104         exit(1);
105     }
106     l = fread(buf, 1, sizeof(buf) - 1, f);
107     fclose(f);
108     buf[l] = '\0';
109     custom_sdp = buf;
110 }
111