summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/checkutils.cpp39
-rw-r--r--src/utils/checkutils.h30
-rw-r--r--src/utils/dtor.h2
-rw-r--r--src/utils/gettext.h2
-rw-r--r--src/utils/mathutils.h2
-rw-r--r--src/utils/mkdir.cpp2
-rw-r--r--src/utils/mkdir.h2
-rw-r--r--src/utils/mutex.h2
-rw-r--r--src/utils/paths.cpp4
-rw-r--r--src/utils/paths.h2
-rw-r--r--src/utils/physfsrwops.cpp186
-rw-r--r--src/utils/physfsrwops.h82
-rw-r--r--src/utils/process.cpp172
-rw-r--r--src/utils/process.h29
-rw-r--r--src/utils/sha256.cpp2
-rw-r--r--src/utils/sha256.h2
-rw-r--r--src/utils/specialfolder.cpp2
-rw-r--r--src/utils/specialfolder.h2
-rw-r--r--src/utils/stringutils.cpp25
-rw-r--r--src/utils/stringutils.h6
-rw-r--r--src/utils/xml.cpp38
-rw-r--r--src/utils/xml.h34
22 files changed, 633 insertions, 34 deletions
diff --git a/src/utils/checkutils.cpp b/src/utils/checkutils.cpp
new file mode 100644
index 000000000..64bb42d0c
--- /dev/null
+++ b/src/utils/checkutils.cpp
@@ -0,0 +1,39 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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 2 of the License, or
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "utils/checkutils.h"
+
+#include <string.h>
+
+#include "logger.h"
+
+bool reportFalseReal(bool val, const char* file, unsigned line)
+{
+ if (!val)
+ logger->log("Debug: false value at %s:%u", file, line);
+ return val;
+}
+
+bool reportTrueReal(bool val, const char* file, unsigned line)
+{
+ if (val)
+ logger->log("Debug: true value at %s:%u", file, line);
+ return val;
+}
diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h
new file mode 100644
index 000000000..6791ff7e0
--- /dev/null
+++ b/src/utils/checkutils.h
@@ -0,0 +1,30 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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 2 of the License, or
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_CHECKUTILS_H
+#define UTILS_CHECKUTILS_H
+
+#include <string>
+
+bool reportFalseReal(bool val, const char* file, unsigned line);
+
+bool reportTrueReal(bool val, const char* file, unsigned line);
+
+#endif // UTILS_CHECKUTILS_H
diff --git a/src/utils/dtor.h b/src/utils/dtor.h
index fbe903ced..54fa11549 100644
--- a/src/utils/dtor.h
+++ b/src/utils/dtor.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/gettext.h b/src/utils/gettext.h
index 696f0d4bf..8bb41a4cb 100644
--- a/src/utils/gettext.h
+++ b/src/utils/gettext.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2007-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 40a9e5d79..9f6818146 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp
index dc2ab63ef..582c9c7dc 100644
--- a/src/utils/mkdir.cpp
+++ b/src/utils/mkdir.cpp
@@ -1,7 +1,7 @@
/*
* The ManaPlus Client
* Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/mkdir.h b/src/utils/mkdir.h
index deff75475..8c5ab4ca2 100644
--- a/src/utils/mkdir.h
+++ b/src/utils/mkdir.h
@@ -1,7 +1,7 @@
/*
* The ManaPlus Client
* Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/mutex.h b/src/utils/mutex.h
index 03dac2e7a..a97a8d3f8 100644
--- a/src/utils/mutex.h
+++ b/src/utils/mutex.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2008-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index 3cc35cb55..8decb6e95 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -1,6 +1,6 @@
/*
* The ManaPlus Client
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -43,6 +43,8 @@ std::string getRealPath(const std::string &str)
#else
char *realPath = realpath(str.c_str(), nullptr);
#endif
+ if (!realPath)
+ return "";
path = realPath;
free(realPath);
return path;
diff --git a/src/utils/paths.h b/src/utils/paths.h
index 1723bf6c4..804900587 100644
--- a/src/utils/paths.h
+++ b/src/utils/paths.h
@@ -1,6 +1,6 @@
/*
* The ManaPlus Client
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
new file mode 100644
index 000000000..1960f0dee
--- /dev/null
+++ b/src/utils/physfsrwops.cpp
@@ -0,0 +1,186 @@
+/*
+ * This code provides a glue layer between PhysicsFS and Simple Directmedia
+ * Layer's (SDL) RWops i/o abstraction.
+ *
+ * License: this code is public domain. I make no warranty that it is useful,
+ * correct, harmless, or environmentally safe.
+ *
+ * This particular file may be used however you like, including copying it
+ * verbatim into a closed-source project, exploiting it commercially, and
+ * removing any trace of my name from the source (although I hope you won't
+ * do that). I welcome enhancements and corrections to this file, but I do
+ * not require you to send me patches if you make changes. This code has
+ * NO WARRANTY.
+ *
+ * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
+ * Please see LICENSE.txt in the root of the source tree.
+ *
+ * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/
+ *
+ * This file was written by Ryan C. Gordon. (icculus@icculus.org).
+ *
+ * Copyright (C) 2012 The ManaPlus Developers
+ */
+
+#include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
+#include "utils/physfsrwops.h"
+
+#include "localconsts.h"
+
+static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
+{
+ PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
+ int pos = 0;
+
+ if (whence == SEEK_SET)
+ {
+ pos = offset;
+ } /* if */
+ else if (whence == SEEK_CUR)
+ {
+ PHYSFS_sint64 current = PHYSFS_tell(handle);
+ if (current == -1)
+ {
+ SDL_SetError("Can't find position in file: %s",
+ PHYSFS_getLastError());
+ return -1;
+ } /* if */
+
+ pos = (int)current;
+ if (((PHYSFS_sint64)pos) != current)
+ {
+ SDL_SetError("Can't fit current file position in an int!");
+ return -1;
+ } /* if */
+
+ if (offset == 0) /* this is a "tell" call. We're done. */
+ return pos;
+
+ pos += offset;
+ } /* else if */
+ else if (whence == SEEK_END)
+ {
+ PHYSFS_sint64 len = PHYSFS_fileLength(handle);
+ if (len == -1)
+ {
+ SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
+ return -1;
+ } /* if */
+
+ pos = (int)len;
+ if (((PHYSFS_sint64)pos) != len)
+ {
+ SDL_SetError("Can't fit end-of-file position in an int!");
+ return -1;
+ } /* if */
+
+ pos += offset;
+ } /* else if */
+ else
+ {
+ SDL_SetError("Invalid 'whence' parameter.");
+ return -1;
+ } /* else */
+
+ if ( pos < 0 )
+ {
+ SDL_SetError("Attempt to seek past start of file.");
+ return -1;
+ } /* if */
+
+ if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
+ {
+ SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+ return -1;
+ } /* if */
+
+ return pos;
+} /* physfsrwops_seek */
+
+static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
+{
+ PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1;
+ PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
+ if (rc != maxnum)
+ {
+ if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
+ SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+ } /* if */
+
+ return (int)rc;
+} /* physfsrwops_read */
+
+static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
+{
+ PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1;
+ PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
+ if (rc != num)
+ SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+
+ return (int) rc;
+} /* physfsrwops_write */
+
+static int physfsrwops_close(SDL_RWops *rw)
+{
+ PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1;
+ if (!PHYSFS_close(handle))
+ {
+ SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+ return -1;
+ } /* if */
+
+ SDL_FreeRW(rw);
+ return 0;
+} /* physfsrwops_close */
+
+static SDL_RWops *create_rwops(PHYSFS_file *handle)
+{
+ SDL_RWops *retval = nullptr;
+
+ if (!handle)
+ {
+ SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+ }
+ else
+ {
+ retval = SDL_AllocRW();
+ if (retval)
+ {
+ retval->seek = physfsrwops_seek;
+ retval->read = physfsrwops_read;
+ retval->write = physfsrwops_write;
+ retval->close = physfsrwops_close;
+ retval->hidden.unknown.data1 = handle;
+ } /* if */
+ } /* else */
+
+ return retval;
+} /* create_rwops */
+
+SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle)
+{
+ SDL_RWops *retval = nullptr;
+ if (!handle)
+ SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
+ else
+ retval = create_rwops(handle);
+
+ return retval;
+} /* PHYSFSRWOPS_makeRWops */
+
+SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
+{
+ return create_rwops(PHYSFS_openRead(fname));
+} /* PHYSFSRWOPS_openRead */
+
+SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
+{
+ return create_rwops(PHYSFS_openWrite(fname));
+} /* PHYSFSRWOPS_openWrite */
+
+SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
+{
+ return create_rwops(PHYSFS_openAppend(fname));
+} /* PHYSFSRWOPS_openAppend */
+
+/* end of physfsrwops.c ... */
diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h
new file mode 100644
index 000000000..efa004ac6
--- /dev/null
+++ b/src/utils/physfsrwops.h
@@ -0,0 +1,82 @@
+/*
+ * This code provides a glue layer between PhysicsFS and Simple Directmedia
+ * Layer's (SDL) RWops i/o abstraction.
+ *
+ * License: this code is public domain. I make no warranty that it is useful,
+ * correct, harmless, or environmentally safe.
+ *
+ * This particular file may be used however you like, including copying it
+ * verbatim into a closed-source project, exploiting it commercially, and
+ * removing any trace of my name from the source (although I hope you won't
+ * do that). I welcome enhancements and corrections to this file, but I do
+ * not require you to send me patches if you make changes. This code has
+ * NO WARRANTY.
+ *
+ * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
+ * Please see LICENSE.txt in the root of the source tree.
+ *
+ * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/
+ *
+ * This file was written by Ryan C. Gordon. (icculus@icculus.org).
+ *
+ * Copyright (C) 2012 The ManaPlus Developers
+ */
+
+#ifndef UTILS_PHYSFSRWOPS_H
+#define UTILS_PHYSFSRWOPS_H
+
+#include <physfs.h>
+#include <SDL.h>
+
+/**
+ * Open a platform-independent filename for reading, and make it accessible
+ * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
+ * RWops is closed. PhysicsFS should be configured to your liking before
+ * opening files through this method.
+ *
+ * @param filename File to open in platform-independent notation.
+ * @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ * of the error can be gleaned from PHYSFS_getLastError().
+ */
+SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
+
+/**
+ * Open a platform-independent filename for writing, and make it accessible
+ * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
+ * RWops is closed. PhysicsFS should be configured to your liking before
+ * opening files through this method.
+ *
+ * @param filename File to open in platform-independent notation.
+ * @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ * of the error can be gleaned from PHYSFS_getLastError().
+ */
+SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
+
+/**
+ * Open a platform-independent filename for appending, and make it accessible
+ * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
+ * RWops is closed. PhysicsFS should be configured to your liking before
+ * opening files through this method.
+ *
+ * @param filename File to open in platform-independent notation.
+ * @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ * of the error can be gleaned from PHYSFS_getLastError().
+ */
+SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
+
+/**
+ * Make a SDL_RWops from an existing PhysicsFS file handle. You should
+ * dispose of any references to the handle after successful creation of
+ * the RWops. The actual PhysicsFS handle will be destroyed when the
+ * RWops is closed.
+ *
+ * @param handle a valid PhysicsFS file handle.
+ * @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ * of the error can be gleaned from PHYSFS_getLastError().
+ */
+SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle);
+
+#endif /* include-once blocker */
+
+/* end of physfsrwops.h ... */
+
diff --git a/src/utils/process.cpp b/src/utils/process.cpp
new file mode 100644
index 000000000..4a2081514
--- /dev/null
+++ b/src/utils/process.cpp
@@ -0,0 +1,172 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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 2 of the License, or
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "utils/process.h"
+
+#include <string.h>
+#include <cstdarg>
+#include <cstdio>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "localconsts.h"
+
+#include "debug.h"
+
+const int timeOut = 10;
+
+#ifdef WIN32
+
+#include <windows.h>
+
+int execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
+{
+ if (!waitTime)
+ waitTime = timeOut;
+
+ STARTUPINFO siStartupInfo;
+ PROCESS_INFORMATION piProcessInfo;
+ memset(&siStartupInfo, 0, sizeof(siStartupInfo));
+ memset(&piProcessInfo, 0, sizeof(piProcessInfo));
+ siStartupInfo.cb = sizeof(siStartupInfo);
+ DWORD ret = -1;
+ std::string args(pathName + " " + arg1);
+ if (!arg2.empty())
+ args += " " + arg2;
+
+ if (CreateProcess(pathName.c_str(), (char*)args.c_str(), 0, 0, false,
+ CREATE_DEFAULT_ERROR_MODE, 0, 0, &siStartupInfo,
+ &piProcessInfo) != false)
+ {
+ if (!WaitForSingleObject(piProcessInfo.hProcess, timeOut * 1000))
+ {
+ if (GetExitCodeProcess(piProcessInfo.hProcess, &ret))
+ {
+ CloseHandle(piProcessInfo.hProcess);
+ CloseHandle(piProcessInfo.hThread);
+ return ret;
+ }
+ }
+ TerminateProcess(piProcessInfo.hProcess, -1);
+ }
+
+ CloseHandle(piProcessInfo.hProcess);
+ CloseHandle(piProcessInfo.hThread);
+ return -1;
+}
+
+#elif defined(__APPLE__)
+
+int execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
+{
+ return -1;
+}
+
+#elif defined __linux__ || defined __linux
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
+{
+ pid_t mon_pid;
+ int status;
+
+ if (!waitTime)
+ waitTime = timeOut;
+
+ if ((mon_pid = fork()) == -1)
+ { // fork error
+ return -1;
+ }
+ else if (!mon_pid)
+ { // monitoring child
+ pid_t pid;
+ if ((pid = fork()) == -1)
+ { // fork error
+ return -1;
+ }
+ else if (!pid)
+ { // work child
+ if (arg2.empty())
+ {
+ execl(pathName.c_str(), name.c_str(),
+ arg1.c_str(), (char *)nullptr);
+ }
+ else
+ {
+ execl(pathName.c_str(), name.c_str(),
+ arg1.c_str(), arg2.c_str(), (char *)nullptr);
+ }
+ exit(-1);
+ }
+
+ // monitoring process
+ pid_t sleep_pid;
+ if ((sleep_pid = fork()) == -1)
+ { // fork error
+ return -1;
+ }
+ else if (!sleep_pid)
+ { // sleep pid
+ sleep (timeOut);
+// printf ("time out\n");
+ exit(-1);
+ }
+
+ // monitoring process
+ pid_t exited_pid = wait(&status);
+ int ret = -1;
+ if (exited_pid == pid)
+ {
+ kill(sleep_pid, SIGKILL);
+ if (WIFEXITED(status))
+ ret = WEXITSTATUS(status);
+ }
+ else
+ {
+ kill(pid, SIGKILL);
+ ret = -1;
+ }
+ wait(nullptr);
+ exit(ret);
+ }
+
+ // monitoring parent
+ waitpid(mon_pid, &status, 0);
+ if (WIFEXITED(status))
+ return WEXITSTATUS(status);
+
+ return -1;
+}
+
+#else
+
+int execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
+{
+ return -1;
+}
+
+#endif
diff --git a/src/utils/process.h b/src/utils/process.h
new file mode 100644
index 000000000..12421729f
--- /dev/null
+++ b/src/utils/process.h
@@ -0,0 +1,29 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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 2 of the License, or
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_PROCESS_H
+#define UTILS_PROCESS_H
+
+#include <string>
+
+int execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime = 0);
+
+#endif // UTILS_PROCESS_H
diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp
index 523c021a4..ac9c78b2a 100644
--- a/src/utils/sha256.cpp
+++ b/src/utils/sha256.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2008-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file has been slighly modified as part of The ManaPlus Client.
*
diff --git a/src/utils/sha256.h b/src/utils/sha256.h
index aa2468d56..54bb92f3c 100644
--- a/src/utils/sha256.h
+++ b/src/utils/sha256.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2007-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/specialfolder.cpp b/src/utils/specialfolder.cpp
index fae0fbf47..9690a9fb7 100644
--- a/src/utils/specialfolder.cpp
+++ b/src/utils/specialfolder.cpp
@@ -1,7 +1,7 @@
/*
* The ManaPlus Client
* Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/specialfolder.h b/src/utils/specialfolder.h
index 571817370..8eb00a637 100644
--- a/src/utils/specialfolder.h
+++ b/src/utils/specialfolder.h
@@ -1,7 +1,7 @@
/*
* The ManaPlus Client
* Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 39f14a646..26accbc7d 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2007-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -509,6 +509,19 @@ std::vector<std::string> getLang()
return langs;
}
+std::string getLangSimple()
+{
+ std::string lang = config.getValue("lang", "").c_str();
+ if (lang.empty())
+ {
+ char *lng = getenv("LANG");
+ if (!lng)
+ return "";
+ return lng;
+ }
+ return lang;
+}
+
std::string packList(std::list<std::string> &list)
{
std::list<std::string>::const_iterator i = list.begin();
@@ -612,3 +625,13 @@ std::string &removeProtocol(std::string &url)
url = url.substr(i + 3);
return url;
}
+
+bool checkPath(std::string path)
+{
+ if (path.empty())
+ return true;
+ return path.find("../") == std::string::npos
+ && path.find("..\\") == std::string::npos
+ && path.find("/..") == std::string::npos
+ && path.find("\\..") == std::string::npos;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 273fa0c8c..5cb726eef 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2007-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -188,6 +188,8 @@ std::string combineDye2(std::string file, std::string dye);
std::vector<std::string> getLang();
+std::string getLangSimple();
+
std::string packList(std::list<std::string> &list);
std::list<std::string> unpackList(const std::string &str);
@@ -206,4 +208,6 @@ bool findCutFirst(std::string &str1, std::string str2);
std::string &removeProtocol(std::string &url);
+bool checkPath(std::string path);
+
#endif // UTILS_STRINGUTILS_H
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 10436067f..420915d8f 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -32,6 +32,11 @@
#include "debug.h"
+static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
+{
+ // Does nothing, that's the whole point of it
+}
+
namespace XML
{
Document::Document(const std::string &filename, bool useResman):
@@ -96,12 +101,12 @@ namespace XML
xmlFreeDoc(mDoc);
}
- xmlNodePtr Document::rootNode()
+ XmlNodePtr Document::rootNode()
{
return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
}
- int getProperty(xmlNodePtr node, const char* name, int def)
+ int getProperty(XmlNodePtr node, const char* name, int def)
{
int &ret = def;
@@ -115,7 +120,7 @@ namespace XML
return ret;
}
- double getFloatProperty(xmlNodePtr node, const char* name, double def)
+ double getFloatProperty(XmlNodePtr node, const char* name, double def)
{
double &ret = def;
@@ -129,7 +134,7 @@ namespace XML
return ret;
}
- std::string getProperty(xmlNodePtr node, const char *name,
+ std::string getProperty(XmlNodePtr node, const char *name,
const std::string &def)
{
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
@@ -143,7 +148,7 @@ namespace XML
return def;
}
- bool getBoolProperty(xmlNodePtr node, const char* name, bool def)
+ bool getBoolProperty(XmlNodePtr node, const char* name, bool def)
{
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
@@ -154,15 +159,32 @@ namespace XML
return def;
}
- xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name)
+ XmlNodePtr findFirstChildByName(XmlNodePtr parent, const char *name)
{
for_each_xml_child_node(child, parent)
{
- if (xmlStrEqual(child->name, BAD_CAST name))
+ if (xmlNameEqual(child, name))
return child;
}
return nullptr;
}
+ // Initialize libxml2 and check for potential ABI mismatches between
+ // compiled version and the shared library actually used.
+ void initXML()
+ {
+ xmlInitParser();
+ LIBXML_TEST_VERSION;
+
+ // Suppress libxml2 error messages
+ xmlSetGenericErrorFunc(nullptr, xmlNullLogger);
+ }
+
+ // Shutdown libxml
+ void cleanupXML()
+ {
+ xmlCleanupParser();
+ }
+
} // namespace XML
diff --git a/src/utils/xml.h b/src/utils/xml.h
index 7bcec2c83..f623fa618 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -23,10 +23,16 @@
#ifndef XML_H
#define XML_H
+#include <libxml/encoding.h>
+#include <libxml/xmlwriter.h>
#include <libxml/tree.h>
#include <string>
+#define XmlNodePtr xmlNodePtr
+#define xmlNameEqual(node, str) xmlStrEqual((node)->name, BAD_CAST (str))
+#define XmlTextWriterPtr xmlTextWriterPtr
+
/**
* XML helper functions.
*/
@@ -63,40 +69,44 @@ namespace XML
* Returns the root node of the document (or NULL if there was a
* load error).
*/
- xmlNodePtr rootNode();
+ XmlNodePtr rootNode();
private:
xmlDocPtr mDoc;
};
/**
- * Gets an floating point property from an xmlNodePtr.
+ * Gets an floating point property from an XmlNodePtr.
*/
- double getFloatProperty(xmlNodePtr node, const char *name, double def);
+ double getFloatProperty(XmlNodePtr node, const char *name, double def);
/**
- * Gets an integer property from an xmlNodePtr.
+ * Gets an integer property from an XmlNodePtr.
*/
- int getProperty(xmlNodePtr node, const char *name, int def);
+ int getProperty(XmlNodePtr node, const char *name, int def);
/**
- * Gets a string property from an xmlNodePtr.
+ * Gets a string property from an XmlNodePtr.
*/
- std::string getProperty(xmlNodePtr node, const char *name,
+ std::string getProperty(XmlNodePtr node, const char *name,
const std::string &def);
/**
- * Gets a boolean property from an xmlNodePtr.
+ * Gets a boolean property from an XmlNodePtr.
*/
- bool getBoolProperty(xmlNodePtr node, const char *name, bool def);
+ bool getBoolProperty(XmlNodePtr node, const char *name, bool def);
/**
* Finds the first child node with the given name
*/
- xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name);
+ XmlNodePtr findFirstChildByName(XmlNodePtr parent, const char *name);
+
+ void initXML();
+
+ void cleanupXML();
}
#define for_each_xml_child_node(var, parent) \
- for (xmlNodePtr var = parent->xmlChildrenNode; var; var = var->next)
+ for (XmlNodePtr var = parent->xmlChildrenNode; var; var = var->next)
#endif // XML_H