diff options
-rw-r--r-- | orkbasecxx/BatchProcessing.cpp | 77 | ||||
-rw-r--r-- | orkbasecxx/Config.cpp | 26 | ||||
-rw-r--r-- | orkbasecxx/Config.h | 10 |
3 files changed, 113 insertions, 0 deletions
diff --git a/orkbasecxx/BatchProcessing.cpp b/orkbasecxx/BatchProcessing.cpp index 1700595..5659122 100644 --- a/orkbasecxx/BatchProcessing.cpp +++ b/orkbasecxx/BatchProcessing.cpp @@ -25,6 +25,11 @@ #include "Filter.h" #include "Reporting.h" +#ifndef WIN32 +#include <pwd.h> +#include <grp.h> +#endif + TapeProcessorRef BatchProcessing::m_singleton; void BatchProcessing::Initialize() @@ -312,6 +317,78 @@ void BatchProcessing::ThreadHandler(void *args) logMsg.Format("[%s] Th%s stop: num samples: s1:%u s2:%u out:%u", trackingId, threadIdString, numSamplesS1, numSamplesS2, numSamplesOut); LOG4CXX_INFO(LOG.batchProcessingLog, logMsg); + CStdString audioFilePath = CONFIG.m_audioOutputPath + "/" + audioTapeRef->GetPath(); + CStdString audioFileName, mcfFileName; + + audioFileName = audioFilePath + "/" + audioTapeRef->GetIdentifier() + outFileRef->GetExtension(); + mcfFileName = audioFilePath + "/" + audioTapeRef->GetIdentifier() + fileRef->GetExtension(); + + //LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " audioFileName: " + audioFileName + " mcfFileName: " + mcfFileName); + +#ifndef WIN32 + if(chmod(audioFileName.c_str(), CONFIG.m_audioFilePermissions)) + { + CStdString logMsg; + + logMsg.Format("Error setting permissions of %s to %o: %s", audioFileName.c_str(), CONFIG.m_audioFilePermissions, strerror(errno)); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg); + } + + if(chmod(mcfFileName.c_str(), CONFIG.m_audioFilePermissions)) + { + CStdString logMsg; + + logMsg.Format("Error setting permissions of %s to %o: %s", mcfFileName.c_str(), CONFIG.m_audioFilePermissions, strerror(errno)); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg); + } + + struct group fileGroup, *fgP = NULL; + struct passwd fileUser, *fuP = NULL; + char infoGroupBuf[4096], infoUserBuf[4096]; + + memset(infoGroupBuf, 0, sizeof(infoGroupBuf)); + memset(infoUserBuf, 0, sizeof(infoUserBuf)); + memset(&fileGroup, 0, sizeof(fileGroup)); + memset(&fileUser, 0, sizeof(fileUser)); + + if(!getgrnam_r(CONFIG.m_audioFileGroup.c_str(), &fileGroup, infoGroupBuf, sizeof(infoGroupBuf), &fgP)) + { + if(!getpwnam_r(CONFIG.m_audioFileOwner.c_str(), &fileUser, infoUserBuf, sizeof(infoUserBuf), &fuP)) + { + + if(chown(audioFileName.c_str(), fileUser.pw_uid, fileGroup.gr_gid)) + { + CStdString logMsg; + + logMsg.Format("Error setting ownership and group of %s to %s:%s: %s", audioFileName.c_str(), CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup, strerror(errno)); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg); + } + + if(chown(mcfFileName.c_str(), fileUser.pw_uid, fileGroup.gr_gid)) + { + CStdString logMsg; + + logMsg.Format("Error setting ownership and group of %s to %s:%s: %s", mcfFileName.c_str(), CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup, strerror(errno)); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg); + } + } + else + { + CStdString logMsg; + + logMsg.Format("Failed to get user information for user %s, please check the AudioFileOwner parameter in config.xml", CONFIG.m_audioFileOwner); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg); + } + } + else + { + CStdString logMsg; + + logMsg.Format("Failed to get group information for group %s, please check the AudioFileGroup parameter in config.xml", CONFIG.m_audioFileGroup); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg); + } + +#endif if(CONFIG.m_deleteNativeFile) { fileRef->Delete(); diff --git a/orkbasecxx/Config.cpp b/orkbasecxx/Config.cpp index 75f36f7..8deb8ae 100644 --- a/orkbasecxx/Config.cpp +++ b/orkbasecxx/Config.cpp @@ -41,6 +41,9 @@ Config::Config() m_trackerTcpPort = TRACKER_TCP_PORT_DEFAULT; m_trackerServicename = TRACKER_SERVICENAME_DEFAULT; m_audioOutputPath = AUDIO_OUTPUT_PATH_DEFAULT; + m_audioFilePermissions = strtol(AUDIO_FILE_PERMISSIONS_DEFAULT, NULL, 8); + m_audioFileOwner = AUDIO_FILE_OWNER_DEFAULT; + m_audioFileGroup = AUDIO_FILE_GROUP_DEFAULT; m_immediateProcessingQueueSize = IMMEDIATE_PROCESSING_QUEUE_SIZE_DEFAULT; m_batchProcessingQueueSize = BATCH_PROCESSING_QUEUE_SIZE_DEFAULT; m_batchProcessingEnhancePriority = BATCH_PROCESSING_ENHANCE_PRIORITY_DEFAULT; @@ -103,6 +106,14 @@ void Config::Define(Serializer* s) } } + s->StringValue(AUDIO_FILE_PERMISSIONS_PARAM, m_audioFilePermissionsStr); + if(m_audioFilePermissionsStr.size()) + { + m_audioFilePermissions = strtoul(m_audioFilePermissionsStr.c_str(), NULL, 8); + } + + s->StringValue(AUDIO_FILE_OWNER_PARAM, m_audioFileOwner); + s->StringValue(AUDIO_FILE_GROUP_PARAM, m_audioFileGroup); s->IntValue(IMMEDIATE_PROCESSING_QUEUE_SIZE_PARAM, m_immediateProcessingQueueSize); s->IntValue(BATCH_PROCESSING_QUEUE_SIZE_PARAM, m_batchProcessingQueueSize); s->BoolValue(BATCH_PROCESSING_ENHANCE_PRIORITY_PARAM, m_batchProcessingEnhancePriority); @@ -148,6 +159,21 @@ void Config::Validate() { throw CStdString(CStdString("Config::Validate: please choose between audio segmentation and VAD ! Both cannot be true at the same time")); } + + if(m_audioFilePermissions == 0) + { + int perm10; + + perm10 = strtoul(m_audioFilePermissionsStr.c_str(), NULL, 10); + if(perm10 < 0 || perm10 > 511) + { + CStdString exc; + + exc.Format("Config::Validate: please set valid permissions the AudioFilePermissions paramiter in config.xml - %s is not a valid file permission", m_audioFilePermissionsStr); + + throw(CStdString(exc)); + } + } } CStdString Config::GetClassName() diff --git a/orkbasecxx/Config.h b/orkbasecxx/Config.h index 1e0ac8b..9290815 100644 --- a/orkbasecxx/Config.h +++ b/orkbasecxx/Config.h @@ -62,6 +62,12 @@ #define CLIENT_TIMEOUT_PARAM "ClientTimeout" #define AUDIO_OUTPUT_PATH_PARAM "AudioOutputPath" #define AUDIO_OUTPUT_PATH_DEFAULT "." +#define AUDIO_FILE_PERMISSIONS_PARAM "AudioFilePermissions" +#define AUDIO_FILE_PERMISSIONS_DEFAULT "0644" +#define AUDIO_FILE_OWNER_PARAM "AudioFileOwner" +#define AUDIO_FILE_OWNER_DEFAULT "root" +#define AUDIO_FILE_GROUP_PARAM "AudioFileGroup" +#define AUDIO_FILE_GROUP_DEFAULT "root" #define IMMEDIATE_PROCESSING_QUEUE_SIZE_PARAM "ImmediateProcessingQueueSize" #define IMMEDIATE_PROCESSING_QUEUE_SIZE_DEFAULT 10000 #define BATCH_PROCESSING_QUEUE_SIZE_PARAM "BatchProcessingQueueSize" @@ -125,6 +131,9 @@ public: int m_reportingRetryDelay; int m_clientTimeout; CStdString m_audioOutputPath; + int m_audioFilePermissions; + CStdString m_audioFileOwner; + CStdString m_audioFileGroup; int m_immediateProcessingQueueSize; int m_batchProcessingQueueSize; bool m_batchProcessingEnhancePriority; @@ -145,6 +154,7 @@ public: private: log4cxx::LoggerPtr m_log; + CStdString m_audioFilePermissionsStr; }; |