gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10556: Improve portability and make


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10556: Improve portability and make useful code more widely available.
Date: Tue, 27 Jan 2009 15:48:53 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10556
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2009-01-27 15:48:53 +0100
message:
  Improve portability and make useful code more widely available.
added:
  libbase/GnashFileUtilities.cpp
  libbase/GnashFileUtilities.h
modified:
  libbase/GnashSystemIOHeaders.h
  libbase/Makefile.am
  libcore/StreamProvider.cpp
  libcore/asobj/SharedObject_as.cpp
    ------------------------------------------------------------
    revno: 10554.1.9
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-01-27 13:23:12 +0100
    message:
      Move system headers and useful utilities for file handling to 
      libbase/GnashFileUtilities.{cpp,h} (compatibility header).
    added:
      libbase/GnashFileUtilities.cpp
      libbase/GnashFileUtilities.h
    modified:
      libbase/Makefile.am
      libcore/StreamProvider.cpp
      libcore/asobj/SharedObject_as.cpp
    ------------------------------------------------------------
    revno: 10554.1.10
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-01-27 13:31:10 +0100
    message:
      Copyright boilerplate and header descriptions.
    modified:
      libbase/GnashFileUtilities.cpp
      libbase/GnashFileUtilities.h
      libbase/GnashSystemIOHeaders.h
=== added file 'libbase/GnashFileUtilities.cpp'
--- a/libbase/GnashFileUtilities.cpp    1970-01-01 00:00:00 +0000
+++ b/libbase/GnashFileUtilities.cpp    2009-01-27 12:31:10 +0000
@@ -0,0 +1,69 @@
+// GnashFileUtilities.cpp     File handling for Gnash
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifndef GNASH_FILE_HEADERS_H
+#define GNASH_FILE_HEADERS_H
+
+#include "gnashconfig.h"
+#include "GnashFileUtilities.h"
+
+#include <string>
+#include <boost/tokenizer.hpp>
+#include <cerrno>
+
+namespace gnash {
+
+/// Create a directory for a given filename.
+//
+/// Everything after the last '/' is assumed to be the filename.
+bool
+mkdirRecursive(const std::string& filename)
+{
+    // Not a directory, nothing to do.
+    std::string::size_type pos = filename.rfind("/");
+    if (pos == std::string::npos) {
+        return true;
+    }
+    const std::string& target = filename.substr(0, pos);
+    
+    typedef boost::tokenizer<boost::char_separator<char> > Tok;
+    boost::char_separator<char> sep("/");
+    Tok t(target, sep);
+    std::string newdir = "/";
+
+    for (Tok::iterator tit = t.begin(); tit != t.end(); ++tit) {
+
+        newdir += *tit;
+
+        if (newdir.find("..") != std::string::npos) {
+            return false;
+        }
+
+        int ret = mkdirUserPermissions(newdir);
+        
+        if ((errno != EEXIST) && (ret != 0)) {
+            return false;
+        }
+        newdir.push_back('/');
+    }
+    return true;
+}
+
+} // namespace gnash
+
+#endif

=== added file 'libbase/GnashFileUtilities.h'
--- a/libbase/GnashFileUtilities.h      1970-01-01 00:00:00 +0000
+++ b/libbase/GnashFileUtilities.h      2009-01-27 12:31:10 +0000
@@ -0,0 +1,62 @@
+// GnashFileUtilities.h     File handling for Gnash
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+/// This file should also be included for the following system functions:
+//
+/// stat()
+/// fstat()
+/// lstat()
+/// dup()
+#ifndef GNASH_FILE_UTILITIES_H
+#define GNASH_FILE_UTILITIES_H
+
+#include "gnashconfig.h"
+#if !defined(_MSC_VER)
+# include <unistd.h>
+# include <sys/stat.h>
+# include <sys/types.h>
+#else
+#include <io.h>
+#define dup _dup
+#endif
+
+#include <string>
+
+namespace gnash {
+
+    /// Create a directory, granting owner rwx permissions.
+    //
+    /// On non-POSIX systems, just create the directory.
+    inline int mkdirUserPermissions(const std::string& dirname)
+    {
+#if !defined(_WIN32) && !defined(_MSC_VER)
+        return mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
+#else
+        return mkdir(dirname.c_str());
+#endif
+    }
+
+    /// Create a directory for a given filename.
+    //
+    /// Everything after the last '/' is assumed to be the filename.
+    bool mkdirRecursive(const std::string& filename);
+
+} // namespace gnash
+
+#endif

=== modified file 'libbase/GnashSystemIOHeaders.h'
--- a/libbase/GnashSystemIOHeaders.h    2008-11-21 15:15:25 +0000
+++ b/libbase/GnashSystemIOHeaders.h    2009-01-27 12:31:10 +0000
@@ -1,6 +1,27 @@
-// Compatibility system headers for Gnash
-//
-// Include this file for read() and write()
+// GnashImageSystemIOHeaders.h: Compatibility IO header for Gnash.
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+//
+
+/// This file should be included for:
+//
+/// read()
+/// write()
 
 #ifndef GNASH_IO_HEADERS_H
 #define GNASH_IO_HEADERS_H

=== modified file 'libbase/Makefile.am'
--- a/libbase/Makefile.am       2009-01-22 20:10:39 +0000
+++ b/libbase/Makefile.am       2009-01-27 12:23:12 +0000
@@ -102,6 +102,7 @@
        $(MALLOC) \
        GnashImage.cpp \
        GnashImageJpeg.cpp \
+       GnashFileUtilities.cpp \
        log.cpp \
        memory.cpp \
        rc.cpp \
@@ -155,6 +156,7 @@
        IOChannel.h \
        tu_opengl_includes.h \
        GnashSystemIOHeaders.h \
+       GnashFileUtilities.h \
        ClockTime.h \
        WallClockTimer.h \
        utf8.h \

=== modified file 'libcore/StreamProvider.cpp'
--- a/libcore/StreamProvider.cpp        2009-01-26 07:57:10 +0000
+++ b/libcore/StreamProvider.cpp        2009-01-27 12:23:12 +0000
@@ -22,6 +22,7 @@
 #endif
 
 
+#include "GnashFileUtilities.h"
 #include "StreamProvider.h"
 #include "URL.h"
 #include "tu_file.h"
@@ -35,14 +36,6 @@
 #include <string>
 #include <vector>
 
-
-#if defined(_WIN32) || defined(WIN32)
-#      include <io.h>
-#      define dup _dup
-#else
-#include <unistd.h> // dup
-#endif
-
 namespace gnash
 {
 

=== modified file 'libcore/asobj/SharedObject_as.cpp'
--- a/libcore/asobj/SharedObject_as.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/asobj/SharedObject_as.cpp 2009-01-27 12:23:12 +0000
@@ -21,8 +21,6 @@
 #include "gnashconfig.h" // USE_SOL_READ_ONLY
 #endif
 
-#include <sys/stat.h>
-#include <sys/types.h>
 #include <boost/tokenizer.hpp>
 #include <boost/scoped_array.hpp>
 #include <boost/shared_ptr.hpp>
@@ -34,6 +32,7 @@
 # include <io.h>
 #endif
 
+#include "GnashFileUtilities.h" // stat
 #include "SimpleBuffer.h"
 #include "as_value.h"
 #include "amf.h"
@@ -88,7 +87,6 @@
 
     as_object* getSharedObjectInterface();
     void attachSharedObjectStaticInterface(as_object& o);
-    bool createDirForFile(const std::string& filespec);
     void flushSOL(SharedObjectLibrary::SoLib::value_type& sol);
     bool validateName(const std::string& solName);
 }
@@ -322,7 +320,7 @@
 
     const std::string& filespec = _sol.getFilespec();
 
-    if ( ! createDirForFile(filespec) )
+    if (!mkdirRecursive(filespec))
     {
         log_error("Couldn't create dir for flushing SharedObject %s", 
filespec);
         return false;
@@ -1112,46 +1110,5 @@
     sol.second->flush();
 }
 
-
-bool
-createDirForFile(const std::string& filename)
-{
-    if (filename.find("/", 0) != std::string::npos)
-    {
-        typedef boost::tokenizer<boost::char_separator<char> > Tok;
-        boost::char_separator<char> sep("/");
-        Tok t(filename, sep);
-        Tok::iterator tit;
-        std::string newdir = "/";
-        for(tit=t.begin(); tit!=t.end();++tit){
-            //cout << *tit << "\n";
-            newdir += *tit;
-            if (newdir.find("..", 0) != std::string::npos) {
-               log_error("Invalid SharedObject path (contains '..'): %s", 
filename);
-                return false;
-            }
-            // Don't try to create a directory of the .sol file name!
-            // TODO: don't fail if the movie url has a component 
-            // ending with .sol (eh...)
-            //
-            if (newdir.rfind(".sol") != (newdir.size()-4)) {
-#ifndef _WIN32
-                int ret = mkdir(newdir.c_str(), S_IRUSR|S_IWUSR|S_IXUSR);
-#else
-                int ret = mkdir(newdir.c_str());
-#endif
-                if ((errno != EEXIST) && (ret != 0)) {
-                    log_error(_("Couldn't create SOL files directory %s: %s"),
-                              newdir, std::strerror(errno));
-                    return false;
-                }
-            } // else log_debug("newdir %s ends with .sol", newdir);
-            newdir += "/";
-        }
-    }
-    else log_debug("no slash in filespec %s", filename);
-    return true;
-}
-
 } // anonymous namespace
 } // end of gnash namespace


reply via email to

[Prev in Thread] Current Thread [Next in Thread]