summaryrefslogtreecommitdiffstats
path: root/src/uri.cpp
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2014-02-20 17:58:24 +0000
committerJohan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl>2014-02-20 17:58:24 +0000
commitbf6ba105405a7eac70f1d36490d51962a4041ac0 (patch)
tree5f0a6ad720d952d9138afb85c1778464c2ce7d1d /src/uri.cpp
parentAdd test for URI and help with data uris. (diff)
downloadinkscape-bf6ba105405a7eac70f1d36490d51962a4041ac0.tar.gz
inkscape-bf6ba105405a7eac70f1d36490d51962a4041ac0.zip
Reverting r13045.
1. It contains a memleak realpath allocates new memory if the second argument is NULL. In the added code, this memory is never freed. 2. Breaks build on Windows (realpath(...) not found) 3. Please don't add functions that use C-strings unnecessarily. Simply rewrite parseDataUri to parseDataUri(const std::string &uri), and use C++'s string methods. ("#include <cstring.h>" is a huge red flag upon code review) 4. Please read this about "realpath" http://insanecoding.blogspot.ch/2007/11/pathmax-simply-isnt.html (bzr r13046)
Diffstat (limited to 'src/uri.cpp')
-rw-r--r--src/uri.cpp50
1 files changed, 4 insertions, 46 deletions
diff --git a/src/uri.cpp b/src/uri.cpp
index a48aa8274..89f6f33e4 100644
--- a/src/uri.cpp
+++ b/src/uri.cpp
@@ -11,8 +11,6 @@
#include <glib.h>
#include "uri.h"
#include <string>
-#include <cstring>
-#include <iostream> // XXX
#include <glibmm/ustring.h>
#include <glibmm/miscutils.h>
@@ -28,10 +26,6 @@ URI::URI(gchar const *preformed) throw(BadURIException) {
if (!preformed) {
throw MalformedURIException();
}
- if( strncmp(preformed, "data:", 5)==0 ) {
- parseDataUri( preformed + 5 );
- preformed = ""; // g_free?
- }
uri = xmlParseURI(preformed);
if (!uri) {
throw MalformedURIException();
@@ -141,38 +135,6 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException)
filename = tmp.toNativeFilename();
return filename;
}
-
-/*
- * Parse data:... uris so we can access their data transparently.
- * otherwise data: is considered a malformed protocol like http:
- * and two // as appended and the data is stored in the path of the uri.
- */
-bool URI::parseDataUri(const char *uri) {
-
- int len = (strchr(uri, ',') - uri) * sizeof(char);
-
- const char *data;
- std::string head;
- if (len > 0) {
- head = std::string(uri, len);
- data = uri + len;
- } else {
- head = "text/plain";
- data = uri;
- }
-
- //bool base64 = false;
- std::cout << "Header: " << head << "\n";
- std::cout << "Data: " << data << "\n";
- /*while(uri < data) {
- if (strncmp(uri,"base64",6) == 0)
- base64 = true;
- if (strncmp(uri,"image/",
- data = strchr(uri, ';');
- }*/
- return true;
-}
-
/*
* Returns the absolute path to an existing file referenced in this URI,
* if the uri is data, the path is empty or the file doesn't exist, then
@@ -187,16 +149,12 @@ const std::string URI::getFullPath(std::string const base) const {
if(!base.empty() && !path.empty() && path[0] != '/') {
path = Glib::build_filename(base, path);
}
- // Normalise path, this only works if all parts of the path exist
- char *output = realpath(path.c_str(), NULL);
- if(output == NULL) {
- path.clear();
- } else // Re-check the existance of the file (make damn sure)
- if(! g_file_test(output, G_FILE_TEST_EXISTS)
- || g_file_test(output, G_FILE_TEST_IS_DIR) ) {
+ // Check the existance of the file
+ if(! g_file_test(path.c_str(), G_FILE_TEST_EXISTS)
+ || g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) ) {
path.clear();
}
- return std::string( output );
+ return path;
}