From cbc9299df8cd5fb1639f9e7db9db59ce9ce3fbf6 Mon Sep 17 00:00:00 2001 From: martii Date: Tue, 11 Jun 2013 13:32:19 +0200 Subject: [PATCH] convert most char[...] configuration values to std::string Signed-off-by: Jacek Jendrzej --- lib/libnet/Makefile.am | 2 +- lib/libnet/{libnet.c => libnet.cpp} | 97 +++++++++-------- lib/libnet/libnet.h | 34 +++--- src/daemonc/remotecontrol.cpp | 2 +- src/driver/neutrinofonts.cpp | 6 +- src/driver/record.cpp | 6 +- src/driver/record.h | 4 +- src/gui/audioplayer.cpp | 14 +-- src/gui/audioplayer_setup.cpp | 4 +- src/gui/dboxinfo.cpp | 20 ++-- src/gui/epgview.cpp | 17 ++- src/gui/eventlist.cpp | 10 +- src/gui/infoviewer_bb.cpp | 4 +- src/gui/moviebrowser.cpp | 40 ++++--- src/gui/movieplayer.cpp | 12 +-- src/gui/network_setup.cpp | 72 ++++++------- src/gui/network_setup.h | 2 +- src/gui/nfs.cpp | 155 ++++++++++++++-------------- src/gui/nfs.h | 6 +- src/gui/osd_setup.cpp | 4 +- src/gui/osdlang_setup.cpp | 15 ++- src/gui/pictureviewer.cpp | 8 +- src/gui/pictureviewer_setup.cpp | 4 +- src/gui/record_setup.cpp | 32 +++--- src/gui/timerlist.cpp | 4 +- src/gui/update.cpp | 17 +-- src/gui/update_ext.cpp | 3 +- src/gui/update_settings.cpp | 4 +- src/gui/widget/menue.cpp | 54 ++++++++-- src/gui/widget/menue.h | 2 + src/gui/widget/mountchooser.cpp | 23 ++--- src/gui/widget/mountchooser.h | 2 +- src/gui/widget/stringinput_ext.cpp | 14 ++- src/gui/widget/stringinput_ext.h | 5 +- src/neutrino.cpp | 125 +++++++++++----------- src/system/configure_network.cpp | 23 ++--- src/system/fsmounter.cpp | 48 ++++----- src/system/fsmounter.h | 8 +- src/system/setting_helpers.cpp | 2 +- src/system/settings.h | 49 ++++----- 40 files changed, 483 insertions(+), 470 deletions(-) rename lib/libnet/{libnet.c => libnet.cpp} (70%) diff --git a/lib/libnet/Makefile.am b/lib/libnet/Makefile.am index ac17412c3..5818bc9b4 100644 --- a/lib/libnet/Makefile.am +++ b/lib/libnet/Makefile.am @@ -2,5 +2,5 @@ noinst_LIBRARIES = libtuxbox-net.a AM_CXXFLAGS = -fno-rtti -fno-exceptions -libtuxbox_net_a_SOURCES = libnet.c network_interfaces.cpp +libtuxbox_net_a_SOURCES = libnet.cpp network_interfaces.cpp diff --git a/lib/libnet/libnet.c b/lib/libnet/libnet.cpp similarity index 70% rename from lib/libnet/libnet.c rename to lib/libnet/libnet.cpp index 87a0ef294..fff4b2d8d 100644 --- a/lib/libnet/libnet.c +++ b/lib/libnet/libnet.cpp @@ -9,7 +9,9 @@ #include #include -#if 0 +#include "libnet.h" + +#if 0 //never used static void scanip( char *str, unsigned char *to ) { @@ -83,16 +85,16 @@ abbruch: return rc; } #endif -void netGetIP( char *dev, char *ip, char *mask, char *brdcast ) +void netGetIP(std::string &dev, std::string &ip, std::string &mask, std::string &brdcast) { int fd; struct ifreq req; struct sockaddr_in *saddr; unsigned char *addr; - *ip=0; - *mask=0; - *brdcast=0; + ip = ""; + mask = ""; + brdcast = ""; fd=socket(AF_INET,SOCK_DGRAM,0); if ( !fd ) @@ -100,23 +102,28 @@ void netGetIP( char *dev, char *ip, char *mask, char *brdcast ) memset(&req,0,sizeof(req)); - strcpy(req.ifr_name,dev); + strncpy(req.ifr_name, dev.c_str(), sizeof(req.ifr_name)); saddr = (struct sockaddr_in *) &req.ifr_addr; addr= (unsigned char*) &saddr->sin_addr.s_addr; + char tmp[80]; + if( ioctl(fd,SIOCGIFADDR,&req) == 0 ) - sprintf(ip,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]); + snprintf(tmp, sizeof(tmp),"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]); + ip = std::string(tmp); if( ioctl(fd,SIOCGIFNETMASK,&req) == 0 ) - sprintf(mask,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]); + snprintf(tmp, sizeof(tmp),"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]); + mask = std::string(tmp); if( ioctl(fd,SIOCGIFBRDADDR,&req) == 0 ) - sprintf(brdcast,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]); + snprintf(tmp, sizeof(tmp),"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]); + brdcast = std::string(tmp); close(fd); return; } -#if 0 +#if 0 //never used void netSetDefaultRoute( char *gw ) { @@ -153,34 +160,37 @@ void netSetDefaultRoute( char *gw ) return; } #endif -void netGetDefaultRoute( char *ip ) +void netGetDefaultRoute( std::string &ip ) { FILE *fp; char interface[9]; - unsigned char destination[4]; - unsigned char gateway[4]; + uint32_t destination; + uint32_t gw; + uint8_t gateway[4]; char zeile[256]; - *ip = 0 ; + ip = ""; fp = fopen("/proc/net/route","r"); if (fp == NULL) return; - fgets(zeile,sizeof(zeile),fp); + fgets(zeile,sizeof(zeile),fp); /* skip header */ while(fgets(zeile,sizeof(zeile),fp)) { - sscanf(zeile,"%8s %x %x",interface,(unsigned *) destination,(unsigned *) gateway); - if (*(unsigned *)destination == 0) - { - sprintf(ip,"%d.%d.%d.%d",gateway[0],gateway[1],gateway[2],gateway[3]); - break; - } + destination = 1; /* in case sscanf fails */ + sscanf(zeile,"%8s %x %x", interface, &destination, &gw); + if (destination) + continue; + /* big/little endian kernels have reversed entries, so this is correct */ + memcpy(gateway, &gw, 4); + char tmp[80]; + snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d", gateway[0], gateway[1], gateway[2], gateway[3]); + ip = std::string(tmp); + break; } fclose(fp); } -static char hostbuf[256]; -static char hostis=0; -#if 0 +#if 0 static char dombuf[256]; static char domis=0; //never used @@ -199,29 +209,27 @@ void netSetDomainname( char *dom ) setdomainname(dombuf,strlen(dombuf)+1); } #endif -char *netGetHostname( void ) +void netGetHostname( std::string &host ) { - if (!hostis) - gethostname( hostbuf, 256 ); - hostis=1; - return hostbuf; + host = ""; + char hostbuf[256]; + if (!gethostname(hostbuf, sizeof(hostbuf))) + host = std::string(hostbuf); } -void netSetHostname( char *host ) +void netSetHostname( std::string &host ) { FILE * fp; - strcpy(hostbuf,host); - hostis=1; - sethostname(hostbuf,strlen(hostbuf)+1); + sethostname(host.c_str(), host.length()); fp = fopen("/etc/hostname", "w"); if(fp != NULL) { - fprintf(fp, "%s\n", hostbuf); + fprintf(fp, "%s\n", host.c_str()); fclose(fp); } } -void netSetNameserver(const char * const ip) +void netSetNameserver(std::string &ip) { FILE *fp; @@ -236,19 +244,19 @@ void netSetNameserver(const char * const ip) fprintf(fp,"search %s\n",dom); #endif fprintf(fp, "# generated by neutrino\n"); - if ((ip != NULL) && (strlen(ip) > 0)) - fprintf(fp,"nameserver %s\n",ip); + if (!ip.empty()) + fprintf(fp,"nameserver %s\n",ip.c_str()); fclose(fp); } -void netGetNameserver( char *ip ) +void netGetNameserver( std::string &ip ) { FILE *fp; char zeile[256]; char *indexLocal; unsigned zaehler; - *ip = 0; + ip = ""; fp = fopen("/etc/resolv.conf","r"); if (!fp) return; @@ -257,32 +265,33 @@ void netGetNameserver( char *ip ) { if (!strncasecmp(zeile,"nameserver",10)) { + char tmp[20]; indexLocal = zeile + 10; while ( (*indexLocal == ' ') || (*indexLocal == '\t') ) indexLocal++; zaehler = 0; while ( (zaehler < 15) && ( ((*indexLocal >= '0') && (*indexLocal <= '9')) || (*indexLocal == '.'))) - ip[zaehler++] = *(indexLocal++); - ip[zaehler] = 0; + tmp[zaehler++] = *(indexLocal++); + tmp[zaehler] = 0; + ip = std::string(tmp); break; } } fclose(fp); } -void netGetMacAddr(char * ifname, unsigned char * mac) +void netGetMacAddr(std::string &ifname, unsigned char *mac) { int fd; struct ifreq ifr; - memset(mac, 0, 6); fd = socket(AF_INET, SOCK_DGRAM, 0); if(fd < 0) return; ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1); + strncpy(ifr.ifr_name, ifname.c_str(), sizeof(ifr.ifr_name)); if(ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) return; diff --git a/lib/libnet/libnet.h b/lib/libnet/libnet.h index 2f1d7fe97..37b179442 100644 --- a/lib/libnet/libnet.h +++ b/lib/libnet/libnet.h @@ -1,28 +1,18 @@ #ifndef __libnet__ #define __libnet__ -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - - -extern int netSetIP( char *dev, char *ip, char *mask, char *brdcast ); -extern void netGetIP( char *dev, char *ip, char *mask, char *brdcast ); -extern void netSetDefaultRoute( char *gw ); -extern void netGetDefaultRoute( char *ip ); -extern char *netGetDomainname( void ); -extern void netSetDomainname( char *dom ); -extern char *netGetHostname( void ); -extern void netSetHostname( char *host ); -extern void netSetNameserver(const char *ip); -extern void netGetNameserver( char *ip ); -extern void netGetMacAddr(char * ifname, unsigned char * mac); - - -#ifdef __cplusplus -} -#endif +#include +int netSetIP(std::string &dev, std::string &ip, std::string &mask, std::string &brdcast ); +void netGetIP(std::string &dev, std::string &ip, std::string &mask, std::string &brdcast ); +void netSetDefaultRoute( std::string &gw ); +void netGetDefaultRoute( std::string &ip ); +void netGetDomainname( std::string &dom ); +void netSetDomainname( std::string &dom ); +void netGetHostname( std::string &host ); +void netSetHostname( std::string &host ); +void netSetNameserver(std::string &ip); +void netGetNameserver( std::string &ip ); +void netGetMacAddr(std::string & ifname, unsigned char *); #endif diff --git a/src/daemonc/remotecontrol.cpp b/src/daemonc/remotecontrol.cpp index 8b27129bb..90273c2f3 100644 --- a/src/daemonc/remotecontrol.cpp +++ b/src/daemonc/remotecontrol.cpp @@ -469,7 +469,7 @@ void CRemoteControl::processAPIDnames() /* processAPIDnames called 2 times, TODO find better way to detect second call */ if(strlen( desc ) != 3) continue; - if(strlen(g_settings.pref_lang[i]) == 0) + if(g_settings.pref_lang[i].empty()) continue; std::string temp(g_settings.pref_lang[i]); diff --git a/src/driver/neutrinofonts.cpp b/src/driver/neutrinofonts.cpp index 1e42bd049..908c2ec1d 100644 --- a/src/driver/neutrinofonts.cpp +++ b/src/driver/neutrinofonts.cpp @@ -134,11 +134,11 @@ void CNeutrinoFonts::SetupNeutrinoFonts(bool initRenderClass/*=true*/) old_fontDescr.size_offset = fontDescr.size_offset; old_fontDescr.filename = fontDescr.filename; fontDescr.filename = ""; - printf("[neutrino] settings font file %s\n", g_settings.font_file); - if (access(g_settings.font_file, F_OK)) { + printf("[neutrino] settings font file %s\n", g_settings.font_file.c_str()); + if (access(g_settings.font_file.c_str(), F_OK)) { if (!access(FONTDIR"/neutrino.ttf", F_OK)) { fontDescr.filename = FONTDIR"/neutrino.ttf"; - strcpy(g_settings.font_file, fontDescr.filename.c_str()); + g_settings.font_file = fontDescr.filename; } else { fprintf( stderr,"[neutrino] font file [%s] not found\n neutrino exit\n",FONTDIR"/neutrino.ttf"); diff --git a/src/driver/record.cpp b/src/driver/record.cpp index c10d2e924..97bd2e251 100644 --- a/src/driver/record.cpp +++ b/src/driver/record.cpp @@ -614,12 +614,12 @@ record_error_msg_t CRecordInstance::MakeFileName(CZapitChannel * channel) if(check_dir(Directory.c_str())) { /* check if Directory and network_nfs_recordingdir the same */ - if(strcmp(g_settings.network_nfs_recordingdir, Directory.c_str())) { + if(g_settings.network_nfs_recordingdir != Directory) { /* not the same, check network_nfs_recordingdir and return error if not ok */ - if(check_dir(g_settings.network_nfs_recordingdir)) + if(check_dir(g_settings.network_nfs_recordingdir.c_str())) return RECORD_INVALID_DIRECTORY; /* fallback to g_settings.network_nfs_recordingdir */ - Directory = std::string(g_settings.network_nfs_recordingdir); + Directory = g_settings.network_nfs_recordingdir; }else{ return RECORD_INVALID_DIRECTORY; } diff --git a/src/driver/record.h b/src/driver/record.h index d427ccc0c..a018c66a2 100644 --- a/src/driver/record.h +++ b/src/driver/record.h @@ -211,8 +211,8 @@ class CRecordManager : public CMenuTarget /*, public CChangeObserver*/ StreamSubtitlePids = stream_subtitle_pids; StreamPmtPid = stream_pmt_pid; }; - void SetDirectory(const char * const directory) { Directory = directory; }; - void SetTimeshiftDirectory(const char * const directory) { TimeshiftDirectory = directory; }; + void SetDirectory(std::string directory) { Directory = directory; }; + void SetTimeshiftDirectory(std::string directory) { TimeshiftDirectory = directory; }; bool RecordingStatus(const t_channel_id channel_id = 0); bool TimeshiftOnly(); bool Timeshift() { return (autoshift || shift_timer); }; diff --git a/src/gui/audioplayer.cpp b/src/gui/audioplayer.cpp index 4a8a2107c..9ebb8f4c4 100644 --- a/src/gui/audioplayer.cpp +++ b/src/gui/audioplayer.cpp @@ -178,8 +178,8 @@ void CAudioPlayerGui::Init(void) m_select_title_by_name = g_settings.audioplayer_select_title_by_name==1; - if (strlen(g_settings.network_nfs_audioplayerdir)!=0) - m_Path = g_settings.network_nfs_audioplayerdir; + if (!g_settings.network_nfs_audioplayerdir.empty()) + m_Path = g_settings.network_nfs_audioplayerdir.c_str(); else m_Path = "/"; @@ -1218,7 +1218,7 @@ bool CAudioPlayerGui::openFilebrowser(void) { bool result = false; CFileBrowser filebrowser((g_settings.filebrowser_denydirectoryleave) - ? g_settings.network_nfs_audioplayerdir : ""); + ? g_settings.network_nfs_audioplayerdir.c_str() : ""); filebrowser.Multi_Select = true; filebrowser.Dirs_Selectable = true; @@ -1389,8 +1389,8 @@ bool CAudioPlayerGui::openFilebrowser(void) printTimevalDiff(start,end); #endif //store last dir - if( (sizeof(g_settings.network_nfs_audioplayerdir)) > m_Path.size() && (strcmp(g_settings.network_nfs_audioplayerdir,m_Path.c_str()) != 0)) - strcpy(g_settings.network_nfs_audioplayerdir,m_Path.c_str()); + if( (g_settings.network_nfs_audioplayerdir.size()) > m_Path.size() && g_settings.network_nfs_audioplayerdir != m_Path.c_str() ) + g_settings.network_nfs_audioplayerdir = m_Path; result = true; } @@ -2584,8 +2584,8 @@ void CAudioPlayerGui::savePlaylist() dirFilter.addFilter("m3u"); browser.Filter = &dirFilter; // select preferred directory if exists - if (strlen(g_settings.network_nfs_audioplayerdir) != 0) - path = g_settings.network_nfs_audioplayerdir; + if (!g_settings.network_nfs_audioplayerdir.empty()) + path = g_settings.network_nfs_audioplayerdir.c_str(); else path = "/"; diff --git a/src/gui/audioplayer_setup.cpp b/src/gui/audioplayer_setup.cpp index d7b4a4cc7..74dbcc725 100644 --- a/src/gui/audioplayer_setup.cpp +++ b/src/gui/audioplayer_setup.cpp @@ -75,8 +75,8 @@ int CAudioPlayerSetup::exec(CMenuTarget* parent, const std::string &actionKey) { CFileBrowser b; b.Dir_Mode=true; - if (b.exec(g_settings.network_nfs_audioplayerdir)) - strncpy(g_settings.network_nfs_audioplayerdir, b.getSelectedFile()->Name.c_str(), sizeof(g_settings.network_nfs_audioplayerdir)-1); + if (b.exec(g_settings.network_nfs_audioplayerdir.c_str())) + g_settings.network_nfs_audioplayerdir = b.getSelectedFile()->Name; return res; } diff --git a/src/gui/dboxinfo.cpp b/src/gui/dboxinfo.cpp index 03ed078d3..c904b89e9 100644 --- a/src/gui/dboxinfo.cpp +++ b/src/gui/dboxinfo.cpp @@ -398,19 +398,17 @@ void CDBoxInfoWidget::paint() case 0: { if (s.f_type != 0x72b6) { - char *p1=NULL, *p2=NULL; - p1=strchr(g_settings.network_nfs_recordingdir+1,'/') ; - p2=strchr(mnt->mnt_dir+1,'/') ; - if (p2) { - if (strstr(p1,p2)) { - + std::string mntDir = mnt->mnt_dir; + std::size_t found1 = g_settings.network_nfs_recordingdir.find_first_of("/",1); + std::size_t found2 = mntDir.find_first_of("/",1); + if (found2 !=std::string::npos){ + std::size_t found3 = g_settings.network_nfs_recordingdir.find_first_of(mntDir.substr(found2),found1); + if (found3 !=std::string::npos) rec_mp = true; - } - } - else { - if (strstr(g_settings.network_nfs_recordingdir,mnt->mnt_dir)) { + }else{ + std::size_t found = mntDir.find_first_of(g_settings.network_nfs_recordingdir); + if (found !=std::string::npos) rec_mp = true; - } } } mpOffset = 10; diff --git a/src/gui/epgview.cpp b/src/gui/epgview.cpp index 747633e61..e9b117146 100644 --- a/src/gui/epgview.cpp +++ b/src/gui/epgview.cpp @@ -779,19 +779,18 @@ int CEpgData::show(const t_channel_id channel_id, uint64_t a_id, time_t* a_start case CRCInput::RC_red: if (!g_settings.minimode && (g_settings.recording_type != CNeutrinoApp::RECORDING_OFF)) { - char recDir[255]; + std::string recDir; //CTimerdClient timerdclient; if (g_Timerd->isTimerdAvailable()) { bool doRecord = true; - //char *recDir = g_settings.network_nfs_recordingdir; - strcpy(recDir, g_settings.network_nfs_recordingdir); + recDir = g_settings.network_nfs_recordingdir; if (g_settings.recording_choose_direct_rec_dir == 2) { CFileBrowser b; b.Dir_Mode=true; hide(); - if (b.exec(g_settings.network_nfs_recordingdir)) { - strcpy(recDir, b.getSelectedFile()->Name.c_str()); + if (b.exec(g_settings.network_nfs_recordingdir.c_str())) { + recDir = b.getSelectedFile()->Name; } else doRecord = false; if (!bigFonts && g_settings.bigFonts) { @@ -805,7 +804,7 @@ int CEpgData::show(const t_channel_id channel_id, uint64_t a_id, time_t* a_start else if (g_settings.recording_choose_direct_rec_dir == 1) { int lid = -1; - CMountChooser recDirs(LOCALE_TIMERLIST_RECORDING_DIR,NEUTRINO_ICON_SETTINGS,&lid,NULL,g_settings.network_nfs_recordingdir); + CMountChooser recDirs(LOCALE_TIMERLIST_RECORDING_DIR,NEUTRINO_ICON_SETTINGS,&lid,NULL,g_settings.network_nfs_recordingdir.c_str()); if (recDirs.hasItem()) { hide(); @@ -823,12 +822,8 @@ int CEpgData::show(const t_channel_id channel_id, uint64_t a_id, time_t* a_start printf("no network devices available\n"); } if (lid != -1) - strcpy(recDir, g_settings.network_nfs_local_dir[lid]); - //recDir = g_settings.network_nfs_local_dir[id]; - //else - //recDir = NULL; + recDir = g_settings.network_nfs[lid].local_dir; } - //if (recDir != NULL) if (doRecord) { if (g_Timerd->addRecordTimerEvent(channel_id, diff --git a/src/gui/eventlist.cpp b/src/gui/eventlist.cpp index a3fe5307f..e73b74165 100644 --- a/src/gui/eventlist.cpp +++ b/src/gui/eventlist.cpp @@ -450,11 +450,11 @@ int CNeutrinoEventList::exec(const t_channel_id channel_id, const std::string& c showFunctionBar(true, evtlist[selected].channelID); continue; } - char *recDir = g_settings.network_nfs_recordingdir; + std::string recDir = g_settings.network_nfs_recordingdir; if (g_settings.recording_choose_direct_rec_dir) { int id = -1; - CMountChooser recDirs(LOCALE_TIMERLIST_RECORDING_DIR,NEUTRINO_ICON_SETTINGS,&id,NULL,g_settings.network_nfs_recordingdir); + CMountChooser recDirs(LOCALE_TIMERLIST_RECORDING_DIR,NEUTRINO_ICON_SETTINGS,&id,NULL,g_settings.network_nfs_recordingdir.c_str()); if (recDirs.hasItem()) { hide(); @@ -468,11 +468,11 @@ int CNeutrinoEventList::exec(const t_channel_id channel_id, const std::string& c } if (id != -1) - recDir = g_settings.network_nfs_local_dir[id]; + recDir = g_settings.network_nfs[id].local_dir; else - recDir = NULL; + recDir = ""; } - if (recDir != NULL) //add/remove recording timer events and check/warn for conflicts + if (!recDir.empty()) //add/remove recording timer events and check/warn for conflicts { if (g_Timerd->addRecordTimerEvent(evtlist[selected].channelID , evtlist[selected].startTime, diff --git a/src/gui/infoviewer_bb.cpp b/src/gui/infoviewer_bb.cpp index ce419374d..fbb15043c 100644 --- a/src/gui/infoviewer_bb.cpp +++ b/src/gui/infoviewer_bb.cpp @@ -635,7 +635,7 @@ void CInfoViewerBB::showSysfsHdd() percent = (int)((u * 100ULL) / t); showBarSys(percent); - if (check_dir(g_settings.network_nfs_recordingdir) == 0) + if (check_dir(g_settings.network_nfs_recordingdir.c_str()) == 0) showBarHdd(hddpercent); else showBarHdd(-1); @@ -646,7 +646,7 @@ void* CInfoViewerBB::hddperThread(void *arg) { CInfoViewerBB *infoViewerBB = (CInfoViewerBB*) arg; uint64_t t, u; - if (get_fs_usage(g_settings.network_nfs_recordingdir, t, u)) + if (get_fs_usage(g_settings.network_nfs_recordingdir.c_str(), t, u)) infoViewerBB->hddpercent = (int)((u * 100ULL) / t); else infoViewerBB->hddpercent = 0; diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index 1b3019af9..dd088a25d 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -1002,8 +1002,8 @@ int CMovieBrowser::exec(const char* path) //umount automount dirs for(int i = 0; i < NETWORK_NFS_NR_OF_ENTRIES; i++) { - if(g_settings.network_nfs_automount[i]) - umount2(g_settings.network_nfs_local_dir[i],MNT_FORCE); + if(g_settings.network_nfs[i].automount) + umount2(g_settings.network_nfs[i].local_dir.c_str(), MNT_FORCE); } CFSMounter::automount(); } @@ -2509,10 +2509,9 @@ void CMovieBrowser::updateDir(void) } #endif // check if there is a record dir and if we should use it - if(g_settings.network_nfs_recordingdir[0] != 0 ) + if(!g_settings.network_nfs_recordingdir.empty()) { - std::string name = g_settings.network_nfs_recordingdir; - addDir(name,&m_settings.storageDirRecUsed); + addDir(g_settings.network_nfs_recordingdir, &m_settings.storageDirRecUsed); } for(int i = 0; i < MB_MAX_DIRS; i++) @@ -3990,11 +3989,10 @@ CDirMenu::CDirMenu(std::vector* dir_list) { for(int nfs = 0; nfs < NETWORK_NFS_NR_OF_ENTRIES; nfs++) { - std::string tmp = g_settings.network_nfs_local_dir[nfs]; int result = -1; - if(!tmp.empty()) - result = (*dirList)[i].name.compare( 0,tmp.size(),tmp) ; -printf("[CDirMenu] (nfs%d) %s == (mb%d) %s (%d)\n",nfs,g_settings.network_nfs_local_dir[nfs],i,(*dirList)[i].name.c_str(),result); + if(!g_settings.network_nfs[nfs].local_dir.empty()) + result = (*dirList)[i].name.compare( 0,g_settings.network_nfs[nfs].local_dir.size(),g_settings.network_nfs[nfs].local_dir) ; +printf("[CDirMenu] (nfs%d) %s == (mb%d) %s (%d)\n",nfs,g_settings.network_nfs[nfs].local_dir.c_str(),i,(*dirList)[i].name.c_str(),result); if(result == 0) { @@ -4025,8 +4023,8 @@ int CDirMenu::exec(CMenuTarget* parent, const std::string & actionKey) { if(dirState[number] == DIR_STATE_SERVER_DOWN) { - printf("try to start server: %s %s\n","ether-wake", g_settings.network_nfs_mac[dirNfsMountNr[number]]); - if (my_system(2, "ether-wake", g_settings.network_nfs_mac[dirNfsMountNr[number]]) != 0) + printf("try to start server: %s %s\n","ether-wake", g_settings.network_nfs[dirNfsMountNr[number]].mac.c_str()); + if (my_system(2, "ether-wake", g_settings.network_nfs[dirNfsMountNr[number]].mac.c_str()) != 0) perror("ether-wake failed"); dirOptionText[number]="STARTE SERVER"; @@ -4035,14 +4033,14 @@ int CDirMenu::exec(CMenuTarget* parent, const std::string & actionKey) { printf("[CDirMenu] try to mount %d,%d\n",number,dirNfsMountNr[number]); CFSMounter::MountRes res; - res = CFSMounter::mount( g_settings.network_nfs_ip[dirNfsMountNr[number]].c_str(), - g_settings.network_nfs_dir[dirNfsMountNr[number]] , - g_settings.network_nfs_local_dir[dirNfsMountNr[number]] , - (CFSMounter::FSType)g_settings.network_nfs_type[dirNfsMountNr[number]] , - g_settings.network_nfs_username[dirNfsMountNr[number]] , - g_settings.network_nfs_password[dirNfsMountNr[number]] , - g_settings.network_nfs_mount_options1[dirNfsMountNr[number]] , - g_settings.network_nfs_mount_options2[dirNfsMountNr[number]] ); + res = CFSMounter::mount( g_settings.network_nfs[dirNfsMountNr[number]].ip, + g_settings.network_nfs[dirNfsMountNr[number]].dir, + g_settings.network_nfs[dirNfsMountNr[number]].local_dir, + (CFSMounter::FSType)g_settings.network_nfs[dirNfsMountNr[number]].type , + g_settings.network_nfs[dirNfsMountNr[number]].username, + g_settings.network_nfs[dirNfsMountNr[number]].password, + g_settings.network_nfs[dirNfsMountNr[number]].mount_options1, + g_settings.network_nfs[dirNfsMountNr[number]].mount_options2); if(res == CFSMounter::MRES_OK) // if mount is successful we set the state to active in any case { *(*dirList)[number].used = true; @@ -4083,7 +4081,7 @@ void CDirMenu::updateDirState(void) printf("updateDirState: %d: state %d nfs %d\n", i, dirState[i], dirNfsMountNr[i]); if(dirNfsMountNr[i] != -1) { - int retvalue = pinghost(g_settings.network_nfs_ip[dirNfsMountNr[i]].c_str()); + int retvalue = pinghost(g_settings.network_nfs[dirNfsMountNr[i]].ip.c_str()); if (retvalue == 0)//LOCALE_PING_UNREACHABLE { dirOptionText[i]="Server, offline"; @@ -4091,7 +4089,7 @@ printf("updateDirState: %d: state %d nfs %d\n", i, dirState[i], dirNfsMountNr[i] } else if (retvalue == 1)//LOCALE_PING_OK { - if(CFSMounter::isMounted (g_settings.network_nfs_local_dir[dirNfsMountNr[i]]) == 0) + if(!CFSMounter::isMounted (g_settings.network_nfs[dirNfsMountNr[i]].local_dir)) { dirOptionText[i]="Not mounted"; dirState[i]=DIR_STATE_NOT_MOUNTED; diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index 34db1ac03..01e975edf 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -124,10 +124,10 @@ void CMoviePlayerGui::Init(void) tsfilefilter.addFilter("m3u"); tsfilefilter.addFilter("pls"); - if (strlen(g_settings.network_nfs_moviedir) != 0) - Path_local = g_settings.network_nfs_moviedir; - else + if (g_settings.network_nfs_moviedir.empty()) Path_local = "/"; + else + Path_local = g_settings.network_nfs_moviedir; if (g_settings.filebrowser_denydirectoryleave) filebrowser = new CFileBrowser(Path_local.c_str()); @@ -357,7 +357,7 @@ bool CMoviePlayerGui::SelectFile() printf("CMoviePlayerGui::SelectFile: isBookmark %d timeshift %d isMovieBrowser %d\n", isBookmark, timeshift, isMovieBrowser); if (has_hdd) - wakeup_hdd(g_settings.network_nfs_recordingdir); + wakeup_hdd(g_settings.network_nfs_recordingdir.c_str()); if (timeshift) { t_channel_id live_channel_id = CZapit::getInstance()->GetCurrentChannelID(); @@ -465,9 +465,7 @@ bool CMoviePlayerGui::SelectFile() printf("CMoviePlayerGui::SelectFile: full_name [%s] file_name [%s]\n", full_name.c_str(), file_name.c_str()); } //store last multiformat play dir - if( (sizeof(g_settings.network_nfs_moviedir)) > Path_local.size() && (strcmp(g_settings.network_nfs_moviedir,Path_local.c_str()) != 0)){ - strcpy(g_settings.network_nfs_moviedir,Path_local.c_str()); - } + g_settings.network_nfs_moviedir = Path_local; return ret; } diff --git a/src/gui/network_setup.cpp b/src/gui/network_setup.cpp index b860de305..a74ac4106 100644 --- a/src/gui/network_setup.cpp +++ b/src/gui/network_setup.cpp @@ -202,14 +202,14 @@ int CNetworkSetup::showNetworkSetup() int ifcount = scandir("/sys/class/net", &namelist, my_filter, alphasort); - CMenuOptionStringChooser * ifSelect = new CMenuOptionStringChooser(LOCALE_NETWORKMENU_SELECT_IF, g_settings.ifname, ifcount > 1, this, CRCInput::RC_nokey, "", true); + CMenuOptionStringChooser * ifSelect = new CMenuOptionStringChooser(LOCALE_NETWORKMENU_SELECT_IF, &g_settings.ifname, ifcount > 1, this, CRCInput::RC_nokey, "", true); ifSelect->setHint("", LOCALE_MENU_HINT_NET_IF); bool found = false; for(int i = 0; i < ifcount; i++) { ifSelect->addOption(namelist[i]->d_name); - if(strcmp(g_settings.ifname, namelist[i]->d_name) == 0) + if(strcmp(g_settings.ifname.c_str(), namelist[i]->d_name) == 0) found = true; free(namelist[i]); } @@ -218,7 +218,7 @@ int CNetworkSetup::showNetworkSetup() free(namelist); if(!found) - strcpy(g_settings.ifname, "eth0"); + g_settings.ifname = "eth0"; networkConfig->readConfig(g_settings.ifname); readNetworkSettings(); @@ -602,7 +602,7 @@ int CNetworkSetup::saveChangesDialog() //restores settings void CNetworkSetup::restoreNetworkSettings() { - snprintf(g_settings.ifname, sizeof(g_settings.ifname), "%s", old_ifname.c_str()); + g_settings.ifname = old_ifname; networkConfig->readConfig(g_settings.ifname);//FIXME ? mac_addr = networkConfig->mac_addr; @@ -649,7 +649,7 @@ bool CNetworkSetup::changeNotify(const neutrino_locale_t locale, void * Data) } else if(locale == LOCALE_NETWORKMENU_SELECT_IF) { networkConfig->readConfig(g_settings.ifname); readNetworkSettings(); - printf("CNetworkSetup::changeNotify: using %s, static %d\n", g_settings.ifname, CNetworkConfig::getInstance()->inet_static); + printf("CNetworkSetup::changeNotify: using %s, static %d\n", g_settings.ifname.c_str(), CNetworkConfig::getInstance()->inet_static); changeNotify(LOCALE_NETWORKMENU_DHCP, &CNetworkConfig::getInstance()->inet_static); @@ -675,13 +675,7 @@ void CNetworkSetup::setWizardMode(bool mode) void CNetworkSetup::showCurrentNetworkSettings() { - char ip[16] = {0}; - char mask[16] = {0}; - char broadcast[16] = {0}; - char router[16] = {0}; - char nameserver[16] = {0}; - std::string text; - + std::string ip, mask, broadcast, router, nameserver, text; netGetIP(g_settings.ifname, ip, mask, broadcast); if (ip[0] == 0) { text = g_Locale->getText(LOCALE_NETWORKMENU_INACTIVE_NETWORK); @@ -705,9 +699,9 @@ void CNetworkSetup::showCurrentNetworkSettings() ShowMsgUTF(LOCALE_NETWORKMENU_SHOW, text, CMessageBox::mbrBack, CMessageBox::mbBack); // UTF-8 } -const char * CNetworkSetup::mypinghost(const char * const host) +const char * CNetworkSetup::mypinghost(std::string &host) { - int retvalue = pinghost(host); + int retvalue = pinghost(host.c_str()); switch (retvalue) { case 1: return (g_Locale->getText(LOCALE_PING_OK)); @@ -720,11 +714,7 @@ const char * CNetworkSetup::mypinghost(const char * const host) void CNetworkSetup::testNetworkSettings() { - char our_ip[16]; - char our_mask[16]; - char our_broadcast[16]; - char our_gateway[16]; - char our_nameserver[16]; + std::string our_ip, our_mask, our_broadcast, our_gateway, our_nameserver; std::string text, testsite, offset = " "; @@ -747,29 +737,29 @@ void CNetworkSetup::testNetworkSettings() if (networkConfig->inet_static) { - strcpy(our_ip, networkConfig->address.c_str()); - strcpy(our_mask, networkConfig->netmask.c_str()); - strcpy(our_broadcast, networkConfig->broadcast.c_str()); - strcpy(our_gateway, networkConfig->gateway.c_str()); - strcpy(our_nameserver, networkConfig->nameserver.c_str()); + our_ip = networkConfig->address; + our_mask = networkConfig->netmask; + our_broadcast = networkConfig->broadcast; + our_gateway = networkConfig->gateway; + our_nameserver = networkConfig->nameserver; } else { // FIXME test with current, not changed ifname ? - netGetIP((char *) old_ifname.c_str(), our_ip, our_mask, our_broadcast); + netGetIP(old_ifname, our_ip, our_mask, our_broadcast); netGetDefaultRoute(our_gateway); netGetNameserver(our_nameserver); } - printf("testNw IP: %s\n", our_ip); + printf("testNw IP: %s\n", our_ip.c_str()); printf("testNw MAC-address: %s\n", old_mac_addr.c_str()); - printf("testNw Netmask: %s\n", our_mask); - printf("testNw Broadcast: %s\n", our_broadcast); - printf("testNw Gateway: %s\n", our_gateway); - printf("testNw Nameserver: %s\n", our_nameserver); + printf("testNw Netmask: %s\n", our_mask.c_str()); + printf("testNw Broadcast: %s\n", our_broadcast.c_str()); + printf("testNw Gateway: %s\n", our_gateway.c_str()); + printf("testNw Nameserver: %s\n", our_nameserver.c_str()); printf("testNw Testsite: %s\n", testsite.c_str()); - if (our_ip[0] == 0) + if (our_ip.empty()) { text = g_Locale->getText(LOCALE_NETWORKMENU_INACTIVE_NETWORK); } @@ -777,28 +767,28 @@ void CNetworkSetup::testNetworkSettings() { //Box text = "Box (" + old_mac_addr + "):\n"; - text += offset + (std::string)our_ip + " " + (std::string)mypinghost(our_ip) + "\n"; + text += offset + our_ip + " " + mypinghost(our_ip) + "\n"; //Gateway text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_GATEWAY) + " (Router):\n"; - text += offset + (std::string)our_gateway + " " + (std::string)mypinghost(our_gateway) + "\n"; + text += offset + our_gateway + " " + mypinghost(our_gateway) + "\n"; //Nameserver text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n"; - text += offset + (std::string)our_nameserver + " " + (std::string)mypinghost(our_nameserver) + "\n"; + text += offset + our_nameserver + " " + mypinghost(our_nameserver) + "\n"; //NTPserver - if ( (pinghost(our_nameserver) == 1) && g_settings.network_ntpenable && (g_settings.network_ntpserver != "") ) + if ( (pinghost(our_nameserver.c_str()) == 1) && g_settings.network_ntpenable && (g_settings.network_ntpserver != "") ) { - text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_NTPSERVER) + ":\n"; - text += offset + g_settings.network_ntpserver + " " + (std::string)mypinghost(g_settings.network_ntpserver.c_str()) + "\n"; + text += std::string(g_Locale->getText(LOCALE_NETWORKMENU_NTPSERVER)) + ":\n"; + text += offset + g_settings.network_ntpserver + " " + mypinghost(g_settings.network_ntpserver) + "\n"; } //Wiki text += wiki_URL + ":\n"; - text += offset + "via IP (" + wiki_IP + "): " + (std::string)mypinghost(wiki_IP.c_str()) + "\n"; - if (pinghost(our_nameserver) == 1) + text += offset + "via IP (" + wiki_IP + "): " + mypinghost(wiki_IP) + "\n"; + if (pinghost(our_nameserver.c_str()) == 1) { - text += offset + "via DNS: " + (std::string)mypinghost(wiki_URL.c_str()) + "\n"; + text += offset + "via DNS: " + mypinghost(wiki_URL) + "\n"; //testsite (or defaultsite) text += testsite + ":\n"; - text += offset + "via DNS: " + (std::string)mypinghost(testsite.c_str()) + "\n"; + text += offset + "via DNS: " + mypinghost(testsite) + "\n"; } } diff --git a/src/gui/network_setup.h b/src/gui/network_setup.h index f2c015c24..993c7c86e 100644 --- a/src/gui/network_setup.h +++ b/src/gui/network_setup.h @@ -95,7 +95,7 @@ class CNetworkSetup : public CMenuTarget, CChangeObserver bool checkStringSettings(); bool checkForIP(); bool settingsChanged(); - const char * mypinghost(const char * const host); + const char * mypinghost(std::string &host); public: enum NETWORK_DHCP_MODE diff --git a/src/gui/nfs.cpp b/src/gui/nfs.cpp index 71d14b114..21cf95aa7 100644 --- a/src/gui/nfs.cpp +++ b/src/gui/nfs.cpp @@ -72,6 +72,21 @@ const char * nfs_entry_printf_string[3] = "FTPFS %s/%s -> %s auto: %4s" }; +std::string CNFSMountGui::getEntryString(int i) +{ + std::string res; + switch(g_settings.network_nfs[i].type) { + case CFSMounter::NFS: res = "NFS " + g_settings.network_nfs[i].ip + ":"; break; + case CFSMounter::CIFS: res = "CIFS //" + g_settings.network_nfs[i].ip + "/"; break; + case CFSMounter::LUFS: res = "FTPS " + g_settings.network_nfs[i].ip + "/"; break; + } + return res + + FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs[i].local_dir) + + " -> " + + FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs[i].local_dir) + + " auto: " + + g_Locale->getText(g_settings.network_nfs[i].automount ? LOCALE_MESSAGEBOX_YES : LOCALE_MESSAGEBOX_NO); +} int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey ) { @@ -94,12 +109,7 @@ int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey ) parent->hide(); for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES; i++) { - sprintf(m_entry[i], - nfs_entry_printf_string[(g_settings.network_nfs_type[i] == (int) CFSMounter::NFS) ? 0 : ((g_settings.network_nfs_type[i] == (int) CFSMounter::CIFS) ? 1 : 2)], - g_settings.network_nfs_ip[i].c_str(), - FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs_dir[i]), - FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs_local_dir[i]), - g_Locale->getText(g_settings.network_nfs_automount[i] ? LOCALE_MESSAGEBOX_YES : LOCALE_MESSAGEBOX_NO)); + m_entry[i] = getEntryString(i); } returnval = menu(); } @@ -107,24 +117,18 @@ int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey ) { int i = mountMenuWPtr->getSelected() - menu_offset; if (i > -1 && i < NETWORK_NFS_NR_OF_ENTRIES) { - g_settings.network_nfs_ip[i] = ""; - g_settings.network_nfs_dir[i][0] = 0; - g_settings.network_nfs_local_dir[i][0] = 0; - g_settings.network_nfs_automount[i] = 0; - g_settings.network_nfs_type[i] = 0; - g_settings.network_nfs_username[i][0] = 0; - g_settings.network_nfs_password[i][0] = 0; - strcpy(g_settings.network_nfs_mount_options1[i], "ro,soft,udp"); - strcpy(g_settings.network_nfs_mount_options2[i], "nolock,rsize=8192,wsize=8192"); - strcpy(g_settings.network_nfs_mac[i], "11:22:33:44:55:66"); - sprintf(m_entry[i], - nfs_entry_printf_string[(g_settings.network_nfs_type[i] == (int) CFSMounter::NFS) ? 0 : ((g_settings.network_nfs_type[i] == (int) CFSMounter::CIFS) ? 1 : 2)], - g_settings.network_nfs_ip[i].c_str(), - FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs_dir[i]), - FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs_local_dir[i]), - g_Locale->getText(g_settings.network_nfs_automount[i] ? LOCALE_MESSAGEBOX_YES : LOCALE_MESSAGEBOX_NO)); - sprintf(ISO_8859_1_entry[i],ZapitTools::UTF8_to_Latin1(m_entry[i]).c_str()); - mountMenuEntry[i]->setOption(ISO_8859_1_entry[i]); + g_settings.network_nfs[i].ip = ""; + g_settings.network_nfs[i].dir = ""; + g_settings.network_nfs[i].local_dir = ""; + g_settings.network_nfs[i].automount = 0; + g_settings.network_nfs[i].type = 0; + g_settings.network_nfs[i].username = ""; + g_settings.network_nfs[i].password = ""; + g_settings.network_nfs[i].mount_options1 = "ro,soft,udp"; + g_settings.network_nfs[i].mount_options2 = "nolock,rsize=8192,wsize=8192"; + g_settings.network_nfs[i].mac = "11:22:33:44:55:66"; + m_entry[i] = getEntryString(i); + ISO_8859_1_entry[i] = ZapitTools::UTF8_to_Latin1(m_entry[i].c_str()); } } else if(actionKey.substr(0,10)=="mountentry") @@ -133,23 +137,18 @@ int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey ) returnval = menuEntry(actionKey[10]-'0'); for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES; i++) { - sprintf(m_entry[i], - nfs_entry_printf_string[(g_settings.network_nfs_type[i] == (int) CFSMounter::NFS) ? 0 : ((g_settings.network_nfs_type[i] == (int) CFSMounter::CIFS) ? 1 : 2)], - g_settings.network_nfs_ip[i].c_str(), - FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs_dir[i]), - FILESYSTEM_ENCODING_TO_UTF8(g_settings.network_nfs_local_dir[i]), - g_Locale->getText(g_settings.network_nfs_automount[i] ? LOCALE_MESSAGEBOX_YES : LOCALE_MESSAGEBOX_NO)); - sprintf(ISO_8859_1_entry[i],ZapitTools::UTF8_to_Latin1(m_entry[i]).c_str()); + m_entry[i] = getEntryString(i); + ISO_8859_1_entry[i] = ZapitTools::UTF8_to_Latin1(m_entry[i].c_str()); } } else if(actionKey.substr(0,7)=="domount") { int nr=atoi(actionKey.substr(7,1).c_str()); CFSMounter::MountRes mres = CFSMounter::mount( - g_settings.network_nfs_ip[nr].c_str(), g_settings.network_nfs_dir[nr], - g_settings.network_nfs_local_dir[nr], (CFSMounter::FSType) g_settings.network_nfs_type[nr], - g_settings.network_nfs_username[nr], g_settings.network_nfs_password[nr], - g_settings.network_nfs_mount_options1[nr], g_settings.network_nfs_mount_options2[nr]); + g_settings.network_nfs[nr].ip, g_settings.network_nfs[nr].dir, + g_settings.network_nfs[nr].local_dir, (CFSMounter::FSType) g_settings.network_nfs[nr].type, + g_settings.network_nfs[nr].username, g_settings.network_nfs[nr].password, + g_settings.network_nfs[nr].mount_options1, g_settings.network_nfs[nr].mount_options2); if (mres == CFSMounter::MRES_OK || mres == CFSMounter::MRES_FS_ALREADY_MOUNTED) mountMenuEntry[nr]->iconName = NEUTRINO_ICON_MOUNTED; @@ -163,7 +162,7 @@ int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey ) { parent->hide(); int nr=atoi(actionKey.substr(3,1).c_str()); - chooserDir(g_settings.network_nfs_local_dir[nr], false, NULL, sizeof(g_settings.network_nfs_local_dir[nr])-1); + chooserDir(g_settings.network_nfs[nr].local_dir, false, NULL); returnval = menu_return::RETURN_REPAINT; } return returnval; @@ -180,12 +179,12 @@ int CNFSMountGui::menu() for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES ; i++) { sprintf(s2,"mountentry%d",i); - sprintf(ISO_8859_1_entry[i],ZapitTools::UTF8_to_Latin1(m_entry[i]).c_str()); + ISO_8859_1_entry[i] = ZapitTools::UTF8_to_Latin1(m_entry[i].c_str()); mountMenuEntry[i] = new CMenuForwarderNonLocalized("", true, ISO_8859_1_entry[i], this, s2); if (!i) menu_offset = mountMenuW.getItemsCount(); - if (CFSMounter::isMounted(g_settings.network_nfs_local_dir[i])) + if (CFSMounter::isMounted(g_settings.network_nfs[i].local_dir)) { mountMenuEntry[i]->iconName = NEUTRINO_ICON_MOUNTED; } else @@ -216,64 +215,62 @@ const CMenuOptionChooser::keyval NFS_TYPE_OPTIONS[NFS_TYPE_OPTION_COUNT] = int CNFSMountGui::menuEntry(int nr) { - char *dir,*local_dir, *username, *password, *options1, *options2/*, *mac*/; - int* automount; - int* type; + int type, automount; + char cmd[9]; char cmd2[9]; - dir = g_settings.network_nfs_dir[nr]; - local_dir = g_settings.network_nfs_local_dir[nr]; - username = g_settings.network_nfs_username[nr]; - password = g_settings.network_nfs_password[nr]; - automount = &g_settings.network_nfs_automount[nr]; - type = &g_settings.network_nfs_type[nr]; - options1 = g_settings.network_nfs_mount_options1[nr]; - options2 = g_settings.network_nfs_mount_options2[nr]; -// mac = g_settings.network_nfs_mac[nr]; - - sprintf(cmd,"domount%d",nr); - sprintf(cmd2,"dir%d",nr); + snprintf(cmd, sizeof(cmd), "domount%d",nr); + snprintf(cmd2, sizeof(cmd2), "dir%d",nr); /* rewrite fstype in new entries */ - if(strlen(local_dir)==0) + if(g_settings.network_nfs[nr].local_dir.empty()) { if(m_cifs_sup != CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_lufs_sup == CFSMounter::FS_UNSUPPORTED) - *type = (int) CFSMounter::CIFS; + type = (int) CFSMounter::CIFS; else if(m_lufs_sup != CFSMounter::FS_UNSUPPORTED && m_cifs_sup == CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED) - *type = (int) CFSMounter::LUFS; + type = (int) CFSMounter::LUFS; } bool typeEnabled = (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && m_nfs_sup != CFSMounter::FS_UNSUPPORTED && m_lufs_sup != CFSMounter::FS_UNSUPPORTED) || - (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::CIFS) || - (m_nfs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::NFS) || - (m_lufs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::LUFS); + (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && type != (int)CFSMounter::CIFS) || + (m_nfs_sup != CFSMounter::FS_UNSUPPORTED && type != (int)CFSMounter::NFS) || + (m_lufs_sup != CFSMounter::FS_UNSUPPORTED && type != (int)CFSMounter::LUFS); CMenuWidget mountMenuEntryW(LOCALE_NFS_MOUNT, NEUTRINO_ICON_NETWORK, width); mountMenuEntryW.addIntroItems(); - CIPInput ipInput(LOCALE_NFS_IP, g_settings.network_nfs_ip[nr], LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); - CStringInputSMS dirInput(LOCALE_NFS_DIR, dir, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE,"abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); - CMenuOptionChooser *automountInput= new CMenuOptionChooser(LOCALE_NFS_AUTOMOUNT, automount, MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); - CStringInputSMS options1Input(LOCALE_NFS_MOUNT_OPTIONS, options1, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_=.,:|!?/ "); - CMenuForwarder *options1_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, options1, &options1Input); - CStringInputSMS options2Input(LOCALE_NFS_MOUNT_OPTIONS, options2, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_=.,:|!?/ "); - CMenuForwarder *options2_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, options2, &options2Input); - CStringInputSMS userInput(LOCALE_NFS_USERNAME, username, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); - CMenuForwarder *username_fwd = new CMenuForwarder(LOCALE_NFS_USERNAME, (*type != (int)CFSMounter::NFS), username, &userInput); - CStringInputSMS passInput(LOCALE_NFS_PASSWORD, password, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); - CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (*type != (int)CFSMounter::NFS), NULL, &passInput); - CMACInput macInput(LOCALE_RECORDINGMENU_SERVER_MAC, g_settings.network_nfs_mac[nr], LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); - CMenuForwarder * macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs_mac[nr], &macInput); - CMenuForwarder *mountnow_fwd = new CMenuForwarder(LOCALE_NFS_MOUNTNOW, !(CFSMounter::isMounted(g_settings.network_nfs_local_dir[nr])), NULL, this, cmd); + + CIPInput ipInput(LOCALE_NFS_IP, g_settings.network_nfs[nr].ip, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); + CStringInputSMS dirInput(LOCALE_NFS_DIR, &g_settings.network_nfs[nr].dir, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE,"abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); + + CMenuOptionChooser *automountInput= new CMenuOptionChooser(LOCALE_NFS_AUTOMOUNT, &automount, MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); + + CStringInputSMS options1Input(LOCALE_NFS_MOUNT_OPTIONS, &g_settings.network_nfs[nr].mount_options1, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_=.,:|!?/ "); + CMenuForwarder *options1_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, g_settings.network_nfs[nr].mount_options1, &options1Input); + + CStringInputSMS options2Input(LOCALE_NFS_MOUNT_OPTIONS, &g_settings.network_nfs[nr].mount_options2, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_=.,:|!?/ "); + CMenuForwarder *options2_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, g_settings.network_nfs[nr].mount_options2, &options2Input); + + CStringInputSMS userInput(LOCALE_NFS_USERNAME, &g_settings.network_nfs[nr].username, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); + CMenuForwarder *username_fwd = new CMenuForwarder(LOCALE_NFS_USERNAME, (type != (int)CFSMounter::NFS), g_settings.network_nfs[nr].username, &userInput); + + CStringInputSMS passInput(LOCALE_NFS_PASSWORD, &g_settings.network_nfs[nr].password, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); + CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (type != (int)CFSMounter::NFS), NULL, &passInput); + + CMACInput macInput(LOCALE_RECORDINGMENU_SERVER_MAC, g_settings.network_nfs[nr].mac, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); + CMenuForwarder * macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs[nr].mac, &macInput); + + CMenuForwarder *mountnow_fwd = new CMenuForwarder(LOCALE_NFS_MOUNTNOW, !(CFSMounter::isMounted(g_settings.network_nfs[nr].local_dir)), NULL, this, cmd); + mountnow_fwd->setItemButton(NEUTRINO_ICON_BUTTON_OKAY, true); COnOffNotifier notifier(CFSMounter::NFS); notifier.addItem(username_fwd); notifier.addItem(password_fwd); - mountMenuEntryW.addItem(new CMenuOptionChooser(LOCALE_NFS_TYPE, type, NFS_TYPE_OPTIONS, NFS_TYPE_OPTION_COUNT, typeEnabled, ¬ifier)); - mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_IP , true, g_settings.network_nfs_ip[nr], &ipInput )); - mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_DIR , true, dir , &dirInput )); - mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_LOCALDIR, true, local_dir , this , cmd2)); + mountMenuEntryW.addItem(new CMenuOptionChooser(LOCALE_NFS_TYPE, &type, NFS_TYPE_OPTIONS, NFS_TYPE_OPTION_COUNT, typeEnabled, ¬ifier)); + mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_IP , true, g_settings.network_nfs[nr].ip, &ipInput )); + mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_DIR , true, g_settings.network_nfs[nr].dir, &dirInput )); + mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_LOCALDIR, true, g_settings.network_nfs[nr].local_dir, this , cmd2)); mountMenuEntryW.addItem(automountInput); mountMenuEntryW.addItem(options1_fwd); mountMenuEntryW.addItem(options2_fwd); @@ -357,8 +354,8 @@ int CNFSSmallMenu::exec( CMenuTarget* parent, const std::string & actionKey ) //umount automount dirs for(int i = 0; i < NETWORK_NFS_NR_OF_ENTRIES; i++) { - if(g_settings.network_nfs_automount[i]) - umount2(g_settings.network_nfs_local_dir[i],MNT_FORCE); + if(g_settings.network_nfs[i].automount) + umount2(g_settings.network_nfs[i].local_dir.c_str(),MNT_FORCE); } CFSMounter::automount(); return menu_return::RETURN_REPAINT; diff --git a/src/gui/nfs.h b/src/gui/nfs.h index 3caabdcdb..17f33e08b 100644 --- a/src/gui/nfs.h +++ b/src/gui/nfs.h @@ -45,8 +45,10 @@ class CNFSMountGui : public CMenuTarget int menu(); int menuEntry(int nr); - char m_entry[NETWORK_NFS_NR_OF_ENTRIES][200]; - char ISO_8859_1_entry[NETWORK_NFS_NR_OF_ENTRIES][200]; + std::string m_entry[NETWORK_NFS_NR_OF_ENTRIES]; + std::string ISO_8859_1_entry[NETWORK_NFS_NR_OF_ENTRIES]; + + std::string getEntryString(int i); CMenuWidget *mountMenuWPtr; int menu_offset; diff --git a/src/gui/osd_setup.cpp b/src/gui/osd_setup.cpp index 5f07fc011..d0382a1b8 100644 --- a/src/gui/osd_setup.cpp +++ b/src/gui/osd_setup.cpp @@ -201,7 +201,7 @@ int COsdSetup::exec(CMenuTarget* parent, const std::string &actionKey) fileBrowser.Filter = &fileFilter; if (fileBrowser.exec(FONTDIR) == true) { - strcpy(g_settings.font_file, fileBrowser.getSelectedFile()->Name.c_str()); + g_settings.font_file = fileBrowser.getSelectedFile()->Name; printf("[neutrino] new font file %s\n", fileBrowser.getSelectedFile()->Name.c_str()); CNeutrinoApp::getInstance()->SetupFonts(CNeutrinoFonts::FONTSETUP_ALL); osdFontFile = "(" + getBaseName(fileBrowser.getSelectedFile()->Name) + ")"; @@ -217,7 +217,7 @@ int COsdSetup::exec(CMenuTarget* parent, const std::string &actionKey) fileBrowser.Filter = &fileFilter; if (fileBrowser.exec(FONTDIR) == true) { - strcpy(g_settings.ttx_font_file, fileBrowser.getSelectedFile()->Name.c_str()); + g_settings.ttx_font_file = fileBrowser.getSelectedFile()->Name; ttx_font_file = fileBrowser.getSelectedFile()->Name; printf("[neutrino] ttx font file %s\n", fileBrowser.getSelectedFile()->Name.c_str()); CNeutrinoApp::getInstance()->SetupFonts(CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT | CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT_INST); diff --git a/src/gui/osdlang_setup.cpp b/src/gui/osdlang_setup.cpp index d53802637..efea73397 100644 --- a/src/gui/osdlang_setup.cpp +++ b/src/gui/osdlang_setup.cpp @@ -129,7 +129,7 @@ CMenuOptionStringChooser* COsdLangSetup::getTzItems() CMenuOptionStringChooser* tzSelect = NULL; if (parser != NULL) { - tzSelect = new CMenuOptionStringChooser(LOCALE_MAINSETTINGS_TIMEZONE, g_settings.timezone, true, tzNotifier, CRCInput::RC_green, NEUTRINO_ICON_BUTTON_GREEN, true); + tzSelect = new CMenuOptionStringChooser(LOCALE_MAINSETTINGS_TIMEZONE, &g_settings.timezone, true, tzNotifier, CRCInput::RC_green, NEUTRINO_ICON_BUTTON_GREEN, true); tzSelect->setHint("", LOCALE_MENU_HINT_TIMEZONE); xmlNodePtr search = xmlDocGetRootElement(parser)->xmlChildrenNode; bool found = false; @@ -209,7 +209,7 @@ void COsdLangSetup::showPrefMenu(CMenuWidget *prefMenu, CLangSelectNotifier *lan for(int i = 0; i < 3; i++) { - CMenuOptionStringChooser * langSelect = new CMenuOptionStringChooser(LOCALE_AUDIOMENU_PREF_LANG, g_settings.pref_lang[i], true, langNotifier, CRCInput::convertDigitToKey(i+1), "", true); + CMenuOptionStringChooser * langSelect = new CMenuOptionStringChooser(LOCALE_AUDIOMENU_PREF_LANG, &g_settings.pref_lang[i], true, langNotifier, CRCInput::convertDigitToKey(i+1), "", true); langSelect->setHint("", LOCALE_MENU_HINT_PREF_LANG); langSelect->addOption("none"); std::map::const_iterator it; @@ -225,7 +225,7 @@ void COsdLangSetup::showPrefMenu(CMenuWidget *prefMenu, CLangSelectNotifier *lan prefMenu->addItem(mc); for(int i = 0; i < 3; i++) { - CMenuOptionStringChooser * langSelect = new CMenuOptionStringChooser(LOCALE_AUDIOMENU_PREF_SUBS, g_settings.pref_subs[i], true, NULL, CRCInput::convertDigitToKey(i+4), "", true); + CMenuOptionStringChooser * langSelect = new CMenuOptionStringChooser(LOCALE_AUDIOMENU_PREF_SUBS, &g_settings.pref_subs[i], true, NULL, CRCInput::convertDigitToKey(i+4), "", true); langSelect->setHint("", LOCALE_MENU_HINT_PREF_SUBS); std::map::const_iterator it; langSelect->addOption("none"); @@ -239,7 +239,7 @@ void COsdLangSetup::showPrefMenu(CMenuWidget *prefMenu, CLangSelectNotifier *lan bool COsdLangSetup::changeNotify(const neutrino_locale_t, void *) { //apply osd language - g_Locale->loadLocale(g_settings.language); + g_Locale->loadLocale(g_settings.language.c_str()); return true; } @@ -253,14 +253,13 @@ bool CLangSelectNotifier::changeNotify(const neutrino_locale_t, void *) //prefered audio languages for(int i = 0; i < 3; i++) { - if(strlen(g_settings.pref_lang[i]) && strcmp(g_settings.pref_lang[i], "none")) + if(!g_settings.pref_lang[i].empty() && g_settings.pref_lang[i] != "none") { - printf("setLanguages: %d: %s\n", i, g_settings.pref_lang[i]); + printf("setLanguages: %d: %s\n", i, g_settings.pref_lang[i].c_str()); - std::string temp(g_settings.pref_lang[i]); for(it = iso639.begin(); it != iso639.end(); ++it) { - if(temp == it->second) + if(g_settings.pref_lang[i] == it->second) { v_languages.push_back(it->first); printf("setLanguages: adding %s\n", it->first.c_str()); diff --git a/src/gui/pictureviewer.cpp b/src/gui/pictureviewer.cpp index eb6fbec6a..f491d67a3 100644 --- a/src/gui/pictureviewer.cpp +++ b/src/gui/pictureviewer.cpp @@ -97,10 +97,10 @@ CPictureViewerGui::CPictureViewerGui() selected = 0; m_sort = FILENAME; m_viewer = new CPictureViewer(); - if (strlen(g_settings.network_nfs_picturedir)!=0) - Path = g_settings.network_nfs_picturedir; - else + if (g_settings.network_nfs_picturedir.empty()) Path = "/"; + else + Path = g_settings.network_nfs_picturedir; picture_filter.addFilter("png"); picture_filter.addFilter("bmp"); @@ -426,7 +426,7 @@ int CPictureViewerGui::show() { if (m_state == MENU) { - CFileBrowser filebrowser((g_settings.filebrowser_denydirectoryleave) ? g_settings.network_nfs_picturedir : ""); + CFileBrowser filebrowser((g_settings.filebrowser_denydirectoryleave) ? g_settings.network_nfs_picturedir.c_str() : ""); filebrowser.Multi_Select = true; filebrowser.Dirs_Selectable = true; diff --git a/src/gui/pictureviewer_setup.cpp b/src/gui/pictureviewer_setup.cpp index cf135f5eb..7d3eb96f8 100644 --- a/src/gui/pictureviewer_setup.cpp +++ b/src/gui/pictureviewer_setup.cpp @@ -75,8 +75,8 @@ int CPictureViewerSetup::exec(CMenuTarget* parent, const std::string &actionKey) parent->hide(); CFileBrowser b; b.Dir_Mode=true; - if (b.exec(g_settings.network_nfs_picturedir)) - strncpy(g_settings.network_nfs_picturedir, b.getSelectedFile()->Name.c_str(), sizeof(g_settings.network_nfs_picturedir)-1); + if (b.exec(g_settings.network_nfs_picturedir.c_str())) + g_settings.network_nfs_picturedir = b.getSelectedFile()->Name; return res; } diff --git a/src/gui/record_setup.cpp b/src/gui/record_setup.cpp index 055b16c72..02b8aebfc 100644 --- a/src/gui/record_setup.cpp +++ b/src/gui/record_setup.cpp @@ -67,7 +67,7 @@ int CRecordSetup::exec(CMenuTarget* parent, const std::string &actionKey) { dprintf(DEBUG_DEBUG, "init record setup\n"); int res = menu_return::RETURN_REPAINT; - char timeshiftDir[255]; + std::string timeshiftDir; if (parent) { @@ -88,13 +88,13 @@ int CRecordSetup::exec(CMenuTarget* parent, const std::string &actionKey) { //parent->hide(); const char *action_str = "recordingdir"; - if(chooserDir(g_settings.network_nfs_recordingdir, true, action_str, sizeof(g_settings.network_nfs_recordingdir)-1)){ - printf("New recordingdir: %s (timeshift %s)\n", g_settings.network_nfs_recordingdir, g_settings.timeshiftdir); - if(strlen(g_settings.timeshiftdir) == 0) + if(chooserDir(g_settings.network_nfs_recordingdir, true, action_str)){ + printf("New recordingdir: %s (timeshift %s)\n", g_settings.network_nfs_recordingdir.c_str(), g_settings.timeshiftdir.c_str()); + if(g_settings.timeshiftdir.empty()) { - sprintf(timeshiftDir, "%s/.timeshift", g_settings.network_nfs_recordingdir); - safe_mkdir(timeshiftDir); - printf("New timeshift dir: %s\n", timeshiftDir); + timeshiftDir = g_settings.network_nfs_recordingdir + "/.timeshift"; + safe_mkdir(timeshiftDir.c_str()); + printf("New timeshift dir: %s\n", timeshiftDir.c_str()); } CRecordManager::getInstance()->SetTimeshiftDirectory(timeshiftDir); } @@ -105,7 +105,7 @@ int CRecordSetup::exec(CMenuTarget* parent, const std::string &actionKey) //parent->hide(); CFileBrowser b; b.Dir_Mode=true; - if (b.exec(g_settings.timeshiftdir)) + if (b.exec(g_settings.timeshiftdir.c_str())) { const char * newdir = b.getSelectedFile()->Name.c_str(); printf("New timeshift: selected %s\n", newdir); @@ -113,21 +113,21 @@ int CRecordSetup::exec(CMenuTarget* parent, const std::string &actionKey) printf("Wrong/unsupported recording dir %s\n", newdir); else { - printf("New timeshift dir: old %s (record %s)\n", g_settings.timeshiftdir, g_settings.network_nfs_recordingdir); - if(strcmp(newdir, g_settings.network_nfs_recordingdir)) + printf("New timeshift dir: old %s (record %s)\n", g_settings.timeshiftdir.c_str(), g_settings.network_nfs_recordingdir.c_str()); + if(newdir != g_settings.network_nfs_recordingdir) { printf("New timeshift != rec dir\n"); - strncpy(g_settings.timeshiftdir, b.getSelectedFile()->Name.c_str(), sizeof(g_settings.timeshiftdir)-1); - strcpy(timeshiftDir, g_settings.timeshiftdir); + g_settings.timeshiftdir = b.getSelectedFile()->Name; + timeshiftDir = g_settings.timeshiftdir; } else { - sprintf(timeshiftDir, "%s/.timeshift", g_settings.network_nfs_recordingdir); - strcpy(g_settings.timeshiftdir, newdir); - safe_mkdir(timeshiftDir); + timeshiftDir = g_settings.network_nfs_recordingdir + "/.timeshift"; + g_settings.timeshiftdir = newdir; + safe_mkdir(timeshiftDir.c_str()); printf("New timeshift == rec dir\n"); } - printf("New timeshift dir: %s\n", timeshiftDir); + printf("New timeshift dir: %s\n", timeshiftDir.c_str()); CRecordManager::getInstance()->SetTimeshiftDirectory(timeshiftDir); } } diff --git a/src/gui/timerlist.cpp b/src/gui/timerlist.cpp index 0aeeaed11..484f3954d 100644 --- a/src/gui/timerlist.cpp +++ b/src/gui/timerlist.cpp @@ -1090,7 +1090,7 @@ int CTimerList::modifyTimer() //printf("TIMER: rec dir %s len %s\n", timer->recordingDir, strlen(timer->recordingDir)); if (!strlen(timer->recordingDir)) - strncpy(timer->recordingDir,g_settings.network_nfs_recordingdir,sizeof(timer->recordingDir)-1); + strncpy(timer->recordingDir,g_settings.network_nfs_recordingdir.c_str(),sizeof(timer->recordingDir)-1); bool recDirEnabled = (timer->eventType == CTimerd::TIMER_RECORD) && (g_settings.recording_type == RECORDING_FILE); CMenuForwarder* m6 = new CMenuForwarder(LOCALE_TIMERLIST_RECORDING_DIR, recDirEnabled, timer->recordingDir, this, "rec_dir1", CRCInput::RC_green, NEUTRINO_ICON_BUTTON_GREEN); @@ -1143,7 +1143,7 @@ int CTimerList::newTimer() timerNew.channel_id = 0; strcpy(timerNew.message, ""); timerNew_standby_on =false; - strncpy(timerNew.recordingDir,g_settings.network_nfs_recordingdir,sizeof(timerNew.recordingDir)-1); + strncpy(timerNew.recordingDir,g_settings.network_nfs_recordingdir.c_str(),sizeof(timerNew.recordingDir)-1); CMenuWidget timerSettings(LOCALE_TIMERLIST_MENUNEW, NEUTRINO_ICON_SETTINGS); diff --git a/src/gui/update.cpp b/src/gui/update.cpp index 7e496b283..f705165fb 100644 --- a/src/gui/update.cpp +++ b/src/gui/update.cpp @@ -290,7 +290,7 @@ bool CFlashUpdate::getUpdateImage(const std::string & version) if(fname != NULL) fname++; else return false; - sprintf(dest_name, "%s/%s", g_settings.update_dir, fname); + sprintf(dest_name, "%s/%s", g_settings.update_dir.c_str(), fname); showStatusMessageUTF(std::string(g_Locale->getText(LOCALE_FLASHUPDATE_GETUPDATEFILE)) + ' ' + version); // UTF-8 printf("get update (url): %s - %s\n", filename.c_str(), dest_name); @@ -360,7 +360,7 @@ printf("[update] mode is %d\n", softupdate_mode); UpdatesBrowser.Filter = &UpdatesFilter; CFile * CFileSelected = NULL; - if (!(UpdatesBrowser.exec(g_settings.update_dir))) { + if (!(UpdatesBrowser.exec(g_settings.update_dir.c_str()))) { menu_ret = UpdatesBrowser.getMenuRet(); return false; } @@ -443,7 +443,7 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey) ShowHintUTF(LOCALE_MESSAGEBOX_ERROR, g_Locale->getText(LOCALE_FLASHUPDATE_GETUPDATEFILEERROR)); // UTF-8 return menu_return::RETURN_REPAINT; } - sprintf(fullname, "%s/%s", g_settings.update_dir, fname); + sprintf(fullname, "%s/%s", g_settings.update_dir.c_str(), fname); filename = std::string(fullname); } @@ -522,10 +522,10 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey) { const char install_sh[] = "/bin/install.sh"; #ifdef DEBUG1 - printf("[update] calling %s %s %s\n",install_sh, g_settings.update_dir, filename.c_str() ); + printf("[update] calling %s %s %s\n",install_sh, g_settings.update_dir.c_str(), filename.c_str() ); #else - printf("[update] calling %s %s %s\n",install_sh, g_settings.update_dir, filename.c_str() ); - my_system(3, install_sh, g_settings.update_dir, filename.c_str()); + printf("[update] calling %s %s %s\n",install_sh, g_settings.update_dir.c_str(), filename.c_str() ); + my_system(3, install_sh, g_settings.update_dir.c_str(), filename.c_str()); #endif showGlobalStatus(100); ShowHintUTF(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FLASHUPDATE_READY)); // UTF-8 @@ -682,7 +682,8 @@ void CFlashExpert::readmtd(int preadmtd) { std::string filename; CMTDInfo* mtdInfo = CMTDInfo::getInstance(); - std::string hostName = netGetHostname(); + std::string hostName =""; + netGetHostname(hostName); std::string timeStr = getNowTimeStr("_%Y%m%d_%H%M"); std::string tankStr = ""; #ifdef BOXMODEL_APOLLO @@ -840,7 +841,7 @@ int CFlashExpert::showFileSelector(const std::string & actionkey) fileselector->addIntroItems(LOCALE_FLASHUPDATE_FILESELECTOR, NONEXISTANT_LOCALE, CMenuWidget::BTN_TYPE_CANCEL); struct dirent **namelist; - int n = scandir(g_settings.update_dir, &namelist, 0, alphasort); + int n = scandir(g_settings.update_dir.c_str(), &namelist, 0, alphasort); if (n < 0) { perror("no flashimages available"); diff --git a/src/gui/update_ext.cpp b/src/gui/update_ext.cpp index dad3e296f..f8cc39f7c 100644 --- a/src/gui/update_ext.cpp +++ b/src/gui/update_ext.cpp @@ -151,7 +151,8 @@ bool CExtUpdate::applySettings(std::string & filename, int mode) DBG_TIMER_START() std::string oldFilename = imgFilename; - std::string hostName = netGetHostname(); + std::string hostName =""; + netGetHostname(hostName); std::string orgPath = getPathName(imgFilename); std::string orgName = getBaseName(imgFilename); orgName = getFileName(orgName); diff --git a/src/gui/update_settings.cpp b/src/gui/update_settings.cpp index d53cc7af7..a261feac6 100644 --- a/src/gui/update_settings.cpp +++ b/src/gui/update_settings.cpp @@ -93,8 +93,8 @@ int CUpdateSettings::exec(CMenuTarget* parent, const std::string &actionKey) if(actionKey == "update_dir") { const char *action_str = "update"; - if(chooserDir(g_settings.update_dir, true, action_str, sizeof(g_settings.update_dir)-1,true)) - printf("[neutrino] new %s dir %s\n", action_str, g_settings.update_dir); + if(chooserDir(g_settings.update_dir, true, action_str, true)) + printf("[neutrino] new %s dir %s\n", action_str, g_settings.update_dir.c_str()); return res; } diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index 57c305f68..81946fcb0 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -1505,6 +1505,23 @@ CMenuOptionStringChooser::CMenuOptionStringChooser(const char* OptionName, char* active = Active; optionValue = OptionValue; observ = Observ; + optionValueString = NULL; + + directKey = DirectKey; + iconName = IconName; + pulldown = Pulldown; +} + +CMenuOptionStringChooser::CMenuOptionStringChooser(const neutrino_locale_t OptionName, std::string* OptionValue, bool Active, CChangeObserver* Observ, const neutrino_msg_t DirectKey, const std::string & IconName, bool Pulldown) +{ + height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); + optionNameString = g_Locale->getText(OptionName); + optionName = OptionName; + active = Active; + optionValue = (char *) OptionValue->c_str(); + optionValueString = OptionValue; + observ = Observ; + optionValueString = NULL; directKey = DirectKey; iconName = IconName; @@ -1555,8 +1572,13 @@ int CMenuOptionStringChooser::exec(CMenuTarget* parent) } menu->exec(NULL, ""); ret = menu_return::RETURN_REPAINT; - if(select >= 0) - strcpy(optionValue, options[select].c_str()); + if(select >= 0) { + if (optionValueString) { + *optionValueString = options[select]; + optionValue = (char *)optionValueString->c_str(); + } else + strcpy(optionValue, options[select].c_str()); + } delete menu; delete selector; } else { @@ -1564,12 +1586,26 @@ int CMenuOptionStringChooser::exec(CMenuTarget* parent) for(unsigned int count = 0; count < options.size(); count++) { if (strcmp(options[count].c_str(), optionValue) == 0) { if(msg == CRCInput::RC_left) { - if(count > 0) - strcpy(optionValue, options[(count - 1) % options.size()].c_str()); - else - strcpy(optionValue, options[options.size() - 1].c_str()); - } else - strcpy(optionValue, options[(count + 1) % options.size()].c_str()); + if(count > 0) { + if (optionValueString) { + *optionValueString = options[(count - 1) % options.size()]; + optionValue = (char *)optionValueString->c_str(); + } else + strcpy(optionValue, options[(count - 1) % options.size()].c_str()); + } else { + if (optionValueString) { + *optionValueString = options[options.size() - 1]; + optionValue = (char *)optionValueString->c_str(); + } else + strcpy(optionValue, options[options.size() - 1].c_str()); + } + } else { + if (optionValueString) { + *optionValueString = options[(count + 1) % options.size()]; + optionValue = (char *)optionValueString->c_str(); + } else + strcpy(optionValue, options[(count + 1) % options.size()].c_str()); + } //wantsRepaint = true; break; } @@ -1621,7 +1657,7 @@ CMenuOptionLanguageChooser::~CMenuOptionLanguageChooser() int CMenuOptionLanguageChooser::exec(CMenuTarget*) { - strncpy(g_settings.language, optionValue.c_str(), sizeof(g_settings.language)-1); + g_settings.language = optionValue; if(observ) observ->changeNotify(LOCALE_LANGUAGESETUP_SELECT, (void *) optionValue.c_str()); return menu_return::RETURN_EXIT; diff --git a/src/gui/widget/menue.h b/src/gui/widget/menue.h index cea625567..886f501bd 100644 --- a/src/gui/widget/menue.h +++ b/src/gui/widget/menue.h @@ -371,12 +371,14 @@ class CMenuOptionStringChooser : public CMenuItem std::string optionNameString; int height; char * optionValue; + std::string * optionValueString; std::vector options; CChangeObserver * observ; bool pulldown; public: CMenuOptionStringChooser(const neutrino_locale_t OptionName, char* OptionValue, bool Active = false, CChangeObserver* Observ = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "", bool Pulldown = false); + CMenuOptionStringChooser(const neutrino_locale_t OptionName, std::string* OptionValue, bool Active = false, CChangeObserver* Observ = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "", bool Pulldown = false); CMenuOptionStringChooser(const char* OptionName, char* OptionValue, bool Active = false, CChangeObserver* Observ = NULL, const neutrino_msg_t DirectKey = CRCInput::RC_nokey, const std::string & IconName= "", bool Pulldown = false); ~CMenuOptionStringChooser(); diff --git a/src/gui/widget/mountchooser.cpp b/src/gui/widget/mountchooser.cpp index b205b99d7..ff3f25ebe 100644 --- a/src/gui/widget/mountchooser.cpp +++ b/src/gui/widget/mountchooser.cpp @@ -47,20 +47,14 @@ CMountChooser::CMountChooser(const neutrino_locale_t Name, const std::string & I char indexStr[2]; for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES ; i++) { - if (g_settings.network_nfs_local_dir[i] != NULL && - strcmp(g_settings.network_nfs_local_dir[i],"") != 0 && - (strstr(g_settings.network_nfs_mount_options1[i],"rw") != NULL || - strstr(g_settings.network_nfs_mount_options2[i],"rw") != NULL)) + if (!g_settings.network_nfs[i].local_dir.empty() && + (g_settings.network_nfs[i].mount_options1.find("rw") != string::npos || + g_settings.network_nfs[i].mount_options2.find("rw") != string::npos)) { - std::string s(g_settings.network_nfs_local_dir[i]); - s += " ("; - s += g_settings.network_nfs_ip[i]; - s += ":"; - s += g_settings.network_nfs_dir[i]; - s +=")"; - snprintf(indexStr,2,"%d",i); + std::string s = g_settings.network_nfs[i].local_dir + " (" + g_settings.network_nfs[i].ip + ":" + g_settings.network_nfs[i].dir + ")"; + snprintf(indexStr,sizeof(indexStr),"%d",i); addItem(new CMenuForwarderNonLocalized(s.c_str(),true,NULL,this,(std::string("MID:") + std::string(indexStr)).c_str()), - (strcmp(selectedLocalDir,g_settings.network_nfs_local_dir[i]) == 0)); + selectedLocalDir == g_settings.network_nfs[i].local_dir); } } } @@ -78,8 +72,9 @@ int CMountChooser::exec(CMenuTarget* parent, const std::string & actionKey) { if (index) *index = mount_id; - if (localDir) - strcpy(localDir,g_settings.network_nfs_local_dir[mount_id]); + + if (localDir.empty()) // ??? + localDir = g_settings.network_nfs[mount_id].local_dir; } hide(); return menu_return::RETURN_EXIT; diff --git a/src/gui/widget/mountchooser.h b/src/gui/widget/mountchooser.h index d8a558b0a..98966eb4b 100644 --- a/src/gui/widget/mountchooser.h +++ b/src/gui/widget/mountchooser.h @@ -52,7 +52,7 @@ class CMountChooser : public CMenuWidget { private: int * index; - char * localDir; + std::string localDir; public: diff --git a/src/gui/widget/stringinput_ext.cpp b/src/gui/widget/stringinput_ext.cpp index af6c9b410..0766b235f 100644 --- a/src/gui/widget/stringinput_ext.cpp +++ b/src/gui/widget/stringinput_ext.cpp @@ -566,9 +566,11 @@ void CDateInput::onAfterExec() } //-----------------------------#################################------------------------------------------------------- -CMACInput::CMACInput(const neutrino_locale_t Name, char* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ) - : CExtendedInput(Name, Value, Hint_1, Hint_2, Observ) +CMACInput::CMACInput(const neutrino_locale_t Name, std::string & +Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ) + : CExtendedInput(Name, MAC, Hint_1, Hint_2, Observ) { + mac = &Value; frameBuffer = CFrameBuffer::getInstance(); addInputField( new CExtendedInput_Item_Char("0123456789ABCDEF") ); addInputField( new CExtendedInput_Item_Char("0123456789ABCDEF") ); @@ -600,7 +602,7 @@ void CMACInput::onBeforeExec() return; } int _mac[6]; - sscanf( value, "%x:%x:%x:%x:%x:%x", &_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[4], &_mac[5] ); + sscanf( mac->c_str(), "%x:%x:%x:%x:%x:%x", &_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[4], &_mac[5] ); sprintf( value, "%02x:%02x:%02x:%02x:%02x:%02x", _mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _mac[5]); } @@ -610,7 +612,11 @@ void CMACInput::onAfterExec() sscanf( value, "%x:%x:%x:%x:%x:%x", &_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[4], &_mac[5] ); sprintf( value, "%02x:%02x:%02x:%02x:%02x:%02x", _mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _mac[5]); if(strcmp(value,"00:00:00:00:00:00")==0) - value[0] = 0; /* strcpy(value, ""); */ + { + (*mac) = ""; + } + else + (*mac) = value; } //-----------------------------#################################------------------------------------------------------- diff --git a/src/gui/widget/stringinput_ext.h b/src/gui/widget/stringinput_ext.h index 2fe9d7fea..26e1c0d6f 100644 --- a/src/gui/widget/stringinput_ext.h +++ b/src/gui/widget/stringinput_ext.h @@ -187,12 +187,15 @@ class CDateInput : public CExtendedInput class CMACInput : public CExtendedInput { + char MAC[32]; + std::string * mac; + protected: virtual void onBeforeExec(); virtual void onAfterExec(); public: - CMACInput(const neutrino_locale_t Name, char* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL); + CMACInput(const neutrino_locale_t Name, std::string & Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL); }; //---------------------------------------------------------------------------------------------------- diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 3426328d5..6b9b7cc0d 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -425,9 +425,9 @@ int CNeutrinoApp::loadSetup(const char * fname) for(int i = 0; i < 3; i++) { sprintf(cfg_key, "pref_lang_%d", i); - strncpy(g_settings.pref_lang[i], configfile.getString(cfg_key, "none").c_str(), 30); + g_settings.pref_lang[i] = configfile.getString(cfg_key, "none"); sprintf(cfg_key, "pref_subs_%d", i); - strncpy(g_settings.pref_subs[i], configfile.getString(cfg_key, "none").c_str(), 30); + g_settings.pref_subs[i] = configfile.getString(cfg_key, "none"); } g_settings.zap_cycle = configfile.getInt32( "zap_cycle", 0 ); @@ -435,8 +435,8 @@ int CNeutrinoApp::loadSetup(const char * fname) g_settings.vcr_AutoSwitch = configfile.getBool("vcr_AutoSwitch" , true ); //language - strcpy(g_settings.language, configfile.getString("language", "").c_str()); - strcpy(g_settings.timezone, configfile.getString("timezone", "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna").c_str()); + g_settings.language = configfile.getString("language", ""); + g_settings.timezone = configfile.getString("timezone", "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna"); //epg dir g_settings.epg_cache = configfile.getString("epg_cache_time", "14"); g_settings.epg_extendedcache = configfile.getString("epg_extendedcache_time", "360"); @@ -448,7 +448,7 @@ int CNeutrinoApp::loadSetup(const char * fname) g_settings.network_ntprefresh = configfile.getString("network_ntprefresh", "30" ); g_settings.network_ntpenable = configfile.getBool("network_ntpenable", false); - snprintf(g_settings.ifname, sizeof(g_settings.ifname), "%s", configfile.getString("ifname", "eth0").c_str());; + g_settings.ifname = configfile.getString("ifname", "eth0"); g_settings.epg_save = configfile.getBool("epg_save", false); g_settings.epg_save_standby = configfile.getBool("epg_save_standby", true); @@ -523,53 +523,46 @@ int CNeutrinoApp::loadSetup(const char * fname) //network for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES ; i++) { - sprintf(cfg_key, "network_nfs_ip_%d", i); - g_settings.network_nfs_ip[i] = configfile.getString(cfg_key, ""); - sprintf(cfg_key, "network_nfs_dir_%d", i); - strcpy( g_settings.network_nfs_dir[i], configfile.getString( cfg_key, "" ).c_str() ); - sprintf(cfg_key, "network_nfs_local_dir_%d", i); - strcpy( g_settings.network_nfs_local_dir[i], configfile.getString( cfg_key, "" ).c_str() ); - sprintf(cfg_key, "network_nfs_automount_%d", i); - g_settings.network_nfs_automount[i] = configfile.getInt32( cfg_key, 0); - sprintf(cfg_key, "network_nfs_type_%d", i); - g_settings.network_nfs_type[i] = configfile.getInt32( cfg_key, 0); - sprintf(cfg_key,"network_nfs_username_%d", i); - strcpy( g_settings.network_nfs_username[i], configfile.getString( cfg_key, "" ).c_str() ); - sprintf(cfg_key, "network_nfs_password_%d", i); - strcpy( g_settings.network_nfs_password[i], configfile.getString( cfg_key, "" ).c_str() ); - sprintf(cfg_key, "network_nfs_mount_options1_%d", i); - strcpy( g_settings.network_nfs_mount_options1[i], configfile.getString( cfg_key, "ro,soft,udp" ).c_str() ); - sprintf(cfg_key, "network_nfs_mount_options2_%d", i); - strcpy( g_settings.network_nfs_mount_options2[i], configfile.getString( cfg_key, "nolock,rsize=8192,wsize=8192" ).c_str() ); - sprintf(cfg_key, "network_nfs_mac_%d", i); - strcpy( g_settings.network_nfs_mac[i], configfile.getString( cfg_key, "11:22:33:44:55:66").c_str() ); + std::string i_str(to_string(i)); + g_settings.network_nfs[i].ip = configfile.getString("network_nfs_ip_" + i_str, ""); + g_settings.network_nfs[i].dir = configfile.getString("network_nfs_dir_" + i_str, ""); + g_settings.network_nfs[i].local_dir = configfile.getString("network_nfs_local_dir_" + i_str, ""); + if (g_settings.network_nfs[i].local_dir.empty()) + g_settings.network_nfs[i].local_dir = "/mnt/mnt" + i_str; + g_settings.network_nfs[i].automount = configfile.getInt32("network_nfs_automount_" + i_str, 0); + g_settings.network_nfs[i].type = configfile.getInt32("network_nfs_type_" + i_str, 0); + g_settings.network_nfs[i].username = configfile.getString("network_nfs_username_" + i_str, "" ); + g_settings.network_nfs[i].password = configfile.getString("network_nfs_password_" + i_str, "" ); + g_settings.network_nfs[i].mount_options1 = configfile.getString("network_nfs_mount_options1_" + i_str, "ro,soft,udp" ); + g_settings.network_nfs[i].mount_options2 = configfile.getString("network_nfs_mount_options2_" + i_str, "nolock,rsize=8192,wsize=8192" ); + g_settings.network_nfs[i].mac = configfile.getString("network_nfs_mac_" + i_str, "11:22:33:44:55:66"); } - strcpy( g_settings.network_nfs_audioplayerdir, configfile.getString( "network_nfs_audioplayerdir", "/media/sda1/music" ).c_str() ); - strcpy( g_settings.network_nfs_picturedir, configfile.getString( "network_nfs_picturedir", "/media/sda1/pictures" ).c_str() ); - strcpy( g_settings.network_nfs_moviedir, configfile.getString( "network_nfs_moviedir", "/media/sda1/movies" ).c_str() ); - strcpy( g_settings.network_nfs_recordingdir, configfile.getString( "network_nfs_recordingdir", "/media/sda1/movies" ).c_str() ); - strcpy( g_settings.timeshiftdir, configfile.getString( "timeshiftdir", "" ).c_str() ); + g_settings.network_nfs_audioplayerdir = configfile.getString( "network_nfs_audioplayerdir", "/media/sda1/music" ); + g_settings.network_nfs_picturedir = configfile.getString( "network_nfs_picturedir", "/media/sda1/pictures" ); + g_settings.network_nfs_moviedir = configfile.getString( "network_nfs_moviedir", "/media/sda1/movies" ); + g_settings.network_nfs_recordingdir = configfile.getString( "network_nfs_recordingdir", "/media/sda1/movies" ); + g_settings.timeshiftdir = configfile.getString( "timeshiftdir", "" ); g_settings.temp_timeshift = configfile.getInt32( "temp_timeshift", 0 ); g_settings.auto_timeshift = configfile.getInt32( "auto_timeshift", 0 ); g_settings.auto_delete = configfile.getInt32( "auto_delete", 1 ); - char timeshiftDir[255]; - if(strlen(g_settings.timeshiftdir) == 0) { - sprintf(timeshiftDir, "%s/.timeshift", g_settings.network_nfs_recordingdir); - safe_mkdir(timeshiftDir); + std::string timeshiftDir; + if(g_settings.timeshiftdir.empty()) { + timeshiftDir = g_settings.network_nfs_recordingdir + "/.timeshift"; + safe_mkdir(timeshiftDir.c_str()); } else { - if(strcmp(g_settings.timeshiftdir, g_settings.network_nfs_recordingdir)) - strncpy(timeshiftDir, g_settings.timeshiftdir, sizeof(timeshiftDir)); + if(g_settings.timeshiftdir != g_settings.network_nfs_recordingdir) + timeshiftDir = g_settings.timeshiftdir; else - sprintf(timeshiftDir, "%s/.timeshift", g_settings.network_nfs_recordingdir); + timeshiftDir = g_settings.network_nfs_recordingdir + "/.timeshift"; } - printf("***************************** rec dir %s timeshift dir %s\n", g_settings.network_nfs_recordingdir, timeshiftDir); - CRecordManager::getInstance()->SetTimeshiftDirectory(timeshiftDir); + printf("***************************** rec dir %s timeshift dir %s\n", g_settings.network_nfs_recordingdir.c_str(), timeshiftDir.c_str()); + CRecordManager::getInstance()->SetTimeshiftDirectory(timeshiftDir.c_str()); if(g_settings.auto_delete) { - if(strcmp(g_settings.timeshiftdir, g_settings.network_nfs_recordingdir)) { - DIR *d = opendir(timeshiftDir); + if(g_settings.timeshiftdir == g_settings.network_nfs_recordingdir) { + DIR *d = opendir(timeshiftDir.c_str()); if(d){ while (struct dirent *e = readdir(d)) { @@ -684,10 +677,10 @@ int CNeutrinoApp::loadSetup(const char * fname) strcpy(g_settings.softupdate_proxyusername, configfile.getString("softupdate_proxyusername", "" ).c_str()); strcpy(g_settings.softupdate_proxypassword, configfile.getString("softupdate_proxypassword", "" ).c_str()); // - strcpy( g_settings.font_file, configfile.getString( "font_file", FONTDIR"/neutrino.ttf" ).c_str() ); - strcpy( g_settings.ttx_font_file, configfile.getString( "ttx_font_file", FONTDIR"/DejaVuLGCSansMono-Bold.ttf" ).c_str() ); - ttx_font_file = g_settings.ttx_font_file; - strcpy( g_settings.update_dir, configfile.getString( "update_dir", "/tmp" ).c_str() ); + g_settings.font_file = configfile.getString("font_file", FONTDIR"/neutrino.ttf"); + g_settings.ttx_font_file = configfile.getString( "ttx_font_file", FONTDIR"/DejaVuLGCSansMono-Bold.ttf"); + ttx_font_file = g_settings.ttx_font_file.c_str(); + g_settings.update_dir = configfile.getString("update_dir", "/tmp"); // parentallock if (!parentallocked) { @@ -1031,25 +1024,25 @@ void CNeutrinoApp::saveSetup(const char * fname) //network for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES ; i++) { sprintf(cfg_key, "network_nfs_ip_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_ip[i] ); + configfile.setString(cfg_key, g_settings.network_nfs[i].ip); sprintf(cfg_key, "network_nfs_dir_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_dir[i] ); + configfile.setString(cfg_key, g_settings.network_nfs[i].dir); sprintf(cfg_key, "network_nfs_local_dir_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_local_dir[i] ); + configfile.setString(cfg_key, g_settings.network_nfs[i].local_dir); sprintf(cfg_key, "network_nfs_automount_%d", i); - configfile.setInt32( cfg_key, g_settings.network_nfs_automount[i]); + configfile.setInt32(cfg_key, g_settings.network_nfs[i].automount); sprintf(cfg_key, "network_nfs_type_%d", i); - configfile.setInt32( cfg_key, g_settings.network_nfs_type[i]); - sprintf(cfg_key,"network_nfs_username_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_username[i] ); + configfile.setInt32(cfg_key, g_settings.network_nfs[i].type); + sprintf(cfg_key, "network_nfs_username_%d", i); + configfile.setString(cfg_key, g_settings.network_nfs[i].username); sprintf(cfg_key, "network_nfs_password_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_password[i] ); + configfile.setString(cfg_key, g_settings.network_nfs[i].password); sprintf(cfg_key, "network_nfs_mount_options1_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_mount_options1[i]); + configfile.setString(cfg_key, g_settings.network_nfs[i].mount_options1); sprintf(cfg_key, "network_nfs_mount_options2_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_mount_options2[i]); + configfile.setString(cfg_key, g_settings.network_nfs[i].mount_options2); sprintf(cfg_key, "network_nfs_mac_%d", i); - configfile.setString( cfg_key, g_settings.network_nfs_mac[i]); + configfile.setString(cfg_key, g_settings.network_nfs[i].mac); } configfile.setString( "network_nfs_audioplayerdir", g_settings.network_nfs_audioplayerdir); configfile.setString( "network_nfs_picturedir", g_settings.network_nfs_picturedir); @@ -1791,11 +1784,11 @@ TIMER_START(); initialize_iso639_map(); bool show_startwizard = false; - CLocaleManager::loadLocale_ret_t loadLocale_ret = g_Locale->loadLocale(g_settings.language); + CLocaleManager::loadLocale_ret_t loadLocale_ret = g_Locale->loadLocale(g_settings.language.c_str()); if (loadLocale_ret == CLocaleManager::NO_SUCH_LOCALE) { - strcpy(g_settings.language, "english"); - loadLocale_ret = g_Locale->loadLocale(g_settings.language); + g_settings.language = "english"; + loadLocale_ret = g_Locale->loadLocale(g_settings.language.c_str()); show_startwizard = true; } /* setup GUI */ @@ -2808,15 +2801,15 @@ int CNeutrinoApp::handleMsg(const neutrino_msg_t _msg, neutrino_msg_data_t data) if (g_settings.recording_type == RECORDING_FILE) { char * recordingDir = eventinfo->recordingDir; for(int i=0 ; i < NETWORK_NFS_NR_OF_ENTRIES ; i++) { - if (strcmp(g_settings.network_nfs_local_dir[i],recordingDir) == 0) { - printf("[neutrino] waking up %s (%s)\n",g_settings.network_nfs_ip[i].c_str(),recordingDir); - if (my_system(2, "ether-wake", g_settings.network_nfs_mac[i]) != 0) + if (g_settings.network_nfs[i].local_dir == recordingDir) { + printf("[neutrino] waking up %s (%s)\n", g_settings.network_nfs[i].ip.c_str(), recordingDir); + if (my_system(2, "ether-wake", g_settings.network_nfs[i].mac.c_str()) != 0) perror("ether-wake failed"); break; } } if(has_hdd) { - wakeup_hdd(g_settings.network_nfs_recordingdir); + wakeup_hdd(g_settings.network_nfs_recordingdir.c_str()); } } @@ -3589,7 +3582,7 @@ int CNeutrinoApp::exec(CMenuTarget* parent, const std::string & actionKey) else if(actionKey == "moviedir") { parent->hide(); - chooserDir(g_settings.network_nfs_moviedir, false, NULL, sizeof(g_settings.network_nfs_moviedir)-1); + chooserDir(g_settings.network_nfs_moviedir, false, NULL); return menu_return::RETURN_REPAINT; } @@ -3647,7 +3640,7 @@ bool CNeutrinoApp::changeNotify(const neutrino_locale_t OptionName, void * /*dat { if (ARE_LOCALES_EQUAL(OptionName, LOCALE_LANGUAGESETUP_SELECT)) { - g_Locale->loadLocale(g_settings.language); + g_Locale->loadLocale(g_settings.language.c_str()); return true; } return false; @@ -3958,7 +3951,7 @@ void CNeutrinoApp::SelectSubtitles() return; for(int i = 0; i < 3; i++) { - if(strlen(g_settings.pref_subs[i]) == 0 || !strcmp(g_settings.pref_subs[i], "none")) + if(g_settings.pref_subs[i].empty() || g_settings.pref_subs[i] == "none") continue; std::string temp(g_settings.pref_subs[i]); diff --git a/src/system/configure_network.cpp b/src/system/configure_network.cpp index bcb086917..c439adade 100644 --- a/src/system/configure_network.cpp +++ b/src/system/configure_network.cpp @@ -35,10 +35,7 @@ CNetworkConfig::CNetworkConfig() { - char our_nameserver[16]; - - netGetNameserver(our_nameserver); - nameserver = our_nameserver; + netGetNameserver(nameserver); ifname = "eth0"; orig_automatic_start = false; orig_inet_static = false; @@ -74,13 +71,13 @@ void CNetworkConfig::readConfig(std::string iname) void CNetworkConfig::init_vars(void) { - char mask[16]; - char _broadcast[16]; - char router[16]; - char ip[16]; + std::string mask; + std::string _broadcast; + std::string router; + std::string ip; unsigned char addr[6]; - hostname = netGetHostname(); + netGetHostname(hostname); netGetDefaultRoute(router); gateway = router; @@ -88,13 +85,13 @@ void CNetworkConfig::init_vars(void) /* FIXME its enough to read IP for dhcp only ? * static config should not be different from settings in etc/network/interfaces */ if(!inet_static) { - netGetIP((char *) ifname.c_str(), ip, mask, _broadcast); + netGetIP(ifname, ip, mask, _broadcast); netmask = mask; broadcast = _broadcast; address = ip; } - netGetMacAddr((char *) ifname.c_str(), addr); + netGetMacAddr(ifname, addr); std::stringstream mac_tmp; for(int i=0;i<6;++i) @@ -191,7 +188,7 @@ void CNetworkConfig::commitConfig(void) printf("CNetworkConfig::commitConfig: modified, saving (wireless %d, ssid %s key %s)...\n", wireless, ssid.c_str(), key.c_str()); #endif if(orig_hostname != hostname) - netSetHostname((char *) hostname.c_str()); + netSetHostname(hostname); if (inet_static) { @@ -212,7 +209,7 @@ void CNetworkConfig::commitConfig(void) if (nameserver != orig_nameserver) { orig_nameserver = nameserver; - netSetNameserver(nameserver.c_str()); + netSetNameserver(nameserver); } } diff --git a/src/system/fsmounter.cpp b/src/system/fsmounter.cpp index a6bfb93b3..a10ef4f10 100644 --- a/src/system/fsmounter.cpp +++ b/src/system/fsmounter.cpp @@ -154,10 +154,10 @@ CFSMounter::FS_Support CFSMounter::fsSupported(const CFSMounter::FSType fstype, return CFSMounter::FS_UNSUPPORTED; } -bool CFSMounter::isMounted(const char * const local_dir) +bool CFSMounter::isMounted(const std::string &local_dir) { std::ifstream in; - if (local_dir == NULL) + if (local_dir.empty()) return false; #ifdef PATH_MAX @@ -165,8 +165,8 @@ bool CFSMounter::isMounted(const char * const local_dir) #else char mount_point[4096]; #endif - if (realpath(local_dir, mount_point) == NULL) { - printf("[CFSMounter] could not resolve dir: %s: %s\n",local_dir, strerror(errno)); + if (realpath(local_dir.c_str(), mount_point) == NULL) { + printf("[CFSMounter] could not resolve dir: %s: %s\n",local_dir.c_str(), strerror(errno)); return false; } in.open("/proc/mounts", std::ifstream::in); @@ -183,9 +183,9 @@ bool CFSMounter::isMounted(const char * const local_dir) return false; } -CFSMounter::MountRes CFSMounter::mount(const char * const ip, const char * const dir, const char * const local_dir, - const FSType fstype, const char * const username, const char * const password, - char * options1, char * options2) +CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string &dir, const std::string &local_dir, + const FSType fstype, const std::string &username, const std::string &password, + std::string options1, std::string options2) { std::string cmd; pthread_mutex_init(&g_mut, NULL); @@ -200,36 +200,36 @@ CFSMounter::MountRes CFSMounter::mount(const char * const ip, const char * const return MRES_FS_NOT_SUPPORTED; } - printf("[CFSMounter] Mount(%d) %s:%s -> %s\n", (int) fstype, ip, dir, local_dir); + printf("[CFSMounter] Mount(%d) %s:%s -> %s\n", (int) fstype, ip.c_str(), dir.c_str(), local_dir.c_str()); if (isMounted(local_dir)) { - printf("[CFSMounter] FS mount error %s already mounted\n", local_dir); + printf("[CFSMounter] FS mount error %s already mounted\n", local_dir.c_str()); return MRES_FS_ALREADY_MOUNTED; } - if(options1[0] == '\0') + if(options1.empty()) { - strcpy(options1,options2); - options2[0] = '\0'; + options1 = options2; + options2 = ""; } - if((options1[0] == '\0') && (options2[0] == '\0')) + if(options1.empty() && options2.empty()) { if(fstype == NFS) { - strcpy(options1,"ro,soft,udp"); - strcpy(options2,"nolock,rsize=8192,wsize=8192"); + options1 = "ro,soft,udp"; + options2 = "nolock,rsize=8192,wsize=8192"; } else if(fstype == CIFS) { - strcpy(options1,"ro"); - strcpy(options2,""); + options1 = "ro"; + options2 = ""; } else if(fstype == LUFS) { - strcpy(options1,""); - strcpy(options2,""); + options1 = ""; + options2 = ""; } } @@ -314,12 +314,12 @@ bool CFSMounter::automount() bool res = true; for(int i = 0; i < NETWORK_NFS_NR_OF_ENTRIES; i++) { - if(g_settings.network_nfs_automount[i]) + if(g_settings.network_nfs[i].automount) { - res = (MRES_OK == mount(g_settings.network_nfs_ip[i].c_str(), g_settings.network_nfs_dir[i], g_settings.network_nfs_local_dir[i], - (FSType) g_settings.network_nfs_type[i], g_settings.network_nfs_username[i], - g_settings.network_nfs_password[i], g_settings.network_nfs_mount_options1[i], - g_settings.network_nfs_mount_options2[i])) && res; + res = (MRES_OK == mount(g_settings.network_nfs[i].ip, g_settings.network_nfs[i].dir, g_settings.network_nfs[i].local_dir, + (FSType) g_settings.network_nfs[i].type, g_settings.network_nfs[i].username, + g_settings.network_nfs[i].password, g_settings.network_nfs[i].mount_options1, + g_settings.network_nfs[i].mount_options2)) && res; } } return res; diff --git a/src/system/fsmounter.h b/src/system/fsmounter.h index 35d133636..6cd6a2a9d 100644 --- a/src/system/fsmounter.h +++ b/src/system/fsmounter.h @@ -91,10 +91,10 @@ class CFSMounter */ public: CFSMounter(); - static bool isMounted(const char * const local_dir); - static CFSMounter::MountRes mount(const char * const ip, const char * const dir, const char * const local_dir, - const FSType fstype, const char * const username, const char * const password, - char * options1, char * options2); + static bool isMounted(const std::string &local_dir); + static CFSMounter::MountRes mount(const std::string &ip, const std::string &dir, const std::string &local_dir, + const FSType fstype, const std::string &username, const std::string &password, + std::string options1, std::string options2); static bool automount(); static CFSMounter::UMountRes umount(const char * const dir = NULL); static void getMountedFS(MountInfos& fs); diff --git a/src/system/setting_helpers.cpp b/src/system/setting_helpers.cpp index 7f7f58d34..e029f6361 100644 --- a/src/system/setting_helpers.cpp +++ b/src/system/setting_helpers.cpp @@ -483,7 +483,7 @@ bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void * Data) while (search) { if (!strcmp(xmlGetName(search), "zone")) { name = xmlGetAttribute(search, "name"); - if(!strcmp(g_settings.timezone, name.c_str())) { + if(g_settings.timezone == name) { zone = xmlGetAttribute(search, "zone"); found = true; break; diff --git a/src/system/settings.h b/src/system/settings.h index 3ec475ed1..a1afa39b5 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -132,11 +132,11 @@ struct SNeutrinoSettings int vcr_AutoSwitch; //language - char language[25]; - char timezone[150]; + std::string language; + std::string timezone; - char pref_lang[3][30]; - char pref_subs[3][30]; + std::string pref_lang[3]; + std::string pref_subs[3]; // EPG int epg_save; @@ -156,7 +156,7 @@ struct SNeutrinoSettings std::string network_ntpserver; std::string network_ntprefresh; int network_ntpenable; - char ifname[10]; + std::string ifname; //personalize enum PERSONALIZE_SETTINGS //settings.h @@ -322,21 +322,24 @@ struct SNeutrinoSettings //network #define NETWORK_NFS_NR_OF_ENTRIES 8 - std::string network_nfs_ip[NETWORK_NFS_NR_OF_ENTRIES]; - char network_nfs_mac[NETWORK_NFS_NR_OF_ENTRIES][31]; - char network_nfs_local_dir[NETWORK_NFS_NR_OF_ENTRIES][100]; - char network_nfs_dir[NETWORK_NFS_NR_OF_ENTRIES][100]; - int network_nfs_automount[NETWORK_NFS_NR_OF_ENTRIES]; - char network_nfs_mount_options1[NETWORK_NFS_NR_OF_ENTRIES][31]; - char network_nfs_mount_options2[NETWORK_NFS_NR_OF_ENTRIES][31]; - int network_nfs_type[NETWORK_NFS_NR_OF_ENTRIES]; - char network_nfs_username[NETWORK_NFS_NR_OF_ENTRIES][31]; - char network_nfs_password[NETWORK_NFS_NR_OF_ENTRIES][31]; - char network_nfs_audioplayerdir[100]; - char network_nfs_picturedir[100]; - char network_nfs_moviedir[100]; - char network_nfs_recordingdir[100]; - char timeshiftdir[100]; + struct { + std::string ip; + std::string mac; + std::string local_dir; + std::string dir; + int automount; + std::string mount_options1; + std::string mount_options2; + int type; + std::string username; + std::string password; + } network_nfs[NETWORK_NFS_NR_OF_ENTRIES]; + std::string network_nfs_audioplayerdir; + std::string network_nfs_picturedir; + std::string network_nfs_moviedir; + std::string network_nfs_recordingdir; + std::string timeshiftdir; + std::string downloadcache_dir; //recording int recording_type; @@ -609,9 +612,9 @@ struct SNeutrinoSettings int hdd_fs; int zap_cycle; int sms_channel; - char font_file[100]; - char ttx_font_file[100]; - char update_dir[100]; + std::string font_file; + std::string ttx_font_file; + std::string update_dir; // USERMENU typedef enum {