From 5f40de7083fb16ffdb811bff04522d905718a196 Mon Sep 17 00:00:00 2001
From: Chris Tallon <chris@vomp.tv>
Date: Wed, 2 Apr 2008 17:24:00 +0000
Subject: [PATCH] Fix for moving recordings

---
 log.c       | 18 ++++++++++--------
 mvpclient.c | 14 ++++++++------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/log.c b/log.c
index c1f7445..12be43e 100755
--- a/log.c
+++ b/log.c
@@ -100,14 +100,16 @@ int Log::log(const char *fromModule, int level, const char* message, ...)
 
   if (level > logLevel) return 1;
 
-  char buffer[151];
-  int spaceLeft = 150;
+  int lineLength = 250;
+
+  char buffer[lineLength + 1];
+  int spaceLeft = lineLength;
 
   struct timeval tv;
   gettimeofday(&tv, NULL);
   struct tm* tm = localtime(&tv.tv_sec);
   spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", tm);
-  spaceLeft -= snprintf(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec);
+  spaceLeft -= snprintf(&buffer[lineLength-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec);
 
 
   char levelString[10];
@@ -121,23 +123,23 @@ int Log::log(const char *fromModule, int level, const char* message, ...)
   if (level == INFO)    strcpy(levelString, "[info]  ");
   if (level == DEBUG)   strcpy(levelString, "[debug] ");
 
-  spaceLeft -= snprintf(&buffer[150-spaceLeft], spaceLeft, "%s %s - ", levelString, fromModule);
+  spaceLeft -= snprintf(&buffer[lineLength-spaceLeft], spaceLeft, "%s %s - ", levelString, fromModule);
 
   va_list ap;
   va_start(ap, message);
-  spaceLeft = vsnprintf(&buffer[150-spaceLeft], spaceLeft, message, ap);
+  spaceLeft = vsnprintf(&buffer[lineLength-spaceLeft], spaceLeft, message, ap);
   va_end(ap);
 
   int messageLength = strlen(buffer);
-  if (messageLength < 150)
+  if (messageLength < lineLength)
   {
     buffer[messageLength] = '\n';
     buffer[messageLength+1] = '\0';
   }
   else
   {
-    buffer[149] = '\n';
-    buffer[150] = '\0';
+    buffer[lineLength-1] = '\n';
+    buffer[lineLength] = '\0';
   }
 
   int success = fputs(buffer, logfile);
diff --git a/mvpclient.c b/mvpclient.c
index 40449f4..cad8345 100644
--- a/mvpclient.c
+++ b/mvpclient.c
@@ -566,18 +566,20 @@ int MVPClient::processMoveRecording(UCHAR* data, int length, ResponsePacket* rp)
 
       log->log("Client", Log::DEBUG, "datedirname: %s", dateDirName);
       log->log("Client", Log::DEBUG, "titledirname: %s", titleDirName);
-
       log->log("Client", Log::DEBUG, "viddir: %s", VideoDirectory);
 
-      char* newContainer = new char[strlen(VideoDirectory) + strlen(newPath) + strlen(titleDirName) + 1];
-      log->log("Client", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPath) + strlen(titleDirName) + 1);
-      sprintf(newContainer, "%s%s%s", VideoDirectory, newPath, titleDirName);
+      char* newPathConv = new char[strlen(newPath)+1];
+      strcpy(newPathConv, newPath);
+      ExchangeChars(newPathConv, true);
+      log->log("Client", Log::DEBUG, "EC: %s", newPathConv);
 
-      // FIXME Check whether this already exists before mkdiring it
+      char* newContainer = new char[strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1];
+      log->log("Client", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1);
+      sprintf(newContainer, "%s%s%s", VideoDirectory, newPathConv, titleDirName);
+      delete[] newPathConv;
 
       log->log("Client", Log::DEBUG, "%s", newContainer);
 
-
       struct stat dstat;
       int statret = stat(newContainer, &dstat);
       if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
-- 
2.39.5