[freenos] r230 commited - Added the FileURI class, but it just checks whether the given URI has ...

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Sun, 26 Jul 2009 15:49:25 +0000

Revision: 230
Author: coenbijlsma
Date: Sun Jul 26 08:48:41 2009
Log: Added the FileURI class, but it just checks whether the given URI has the file: scheme. If not, the program is aborted. Also, parse now uses commandline
arguments and checks the scheme of the given argument, though file: is only
supported now.

http://code.google.com/p/freenos/source/detail?r=230

Added:
 /trunk/lib/libparse/FileURI.cpp
 /trunk/lib/libparse/FileURI.h
Modified:
 /trunk/bin/parse/Main.cpp
 /trunk/lib/libparse/SConscript
 /trunk/lib/libparse/URI.cpp
 /trunk/lib/libparse/URI.h

=======================================
--- /dev/null
+++ /trunk/lib/libparse/FileURI.cpp     Sun Jul 26 08:48:41 2009
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 Coen Bijlsma
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "FileURI.h"
+
+FileURI::FileURI(char* uri) : URI(uri)
+{
+    if( _scheme == 0 )
+    {
+        // Temporary until exception support is added to FreeNOS
+        printf("Illegal FileURI.\n");
+        exit(1);
+    } else {
+        if( strcasecmp(_scheme, "file") != 0 )
+        {
+            printf("Not a FileURI: %s.\n", _uri);
+            // Temporary until exception support is added to FreeNOS
+            exit(1);
+        }
+    }
+
+}
+
+FileURI::~FileURI()
+{
+}
=======================================
--- /dev/null
+++ /trunk/lib/libparse/FileURI.h       Sun Jul 26 08:48:41 2009
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2009 Coen Bijlsma
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIBPARSE_FILEURI_H
+#define __LIBPARSE_FILEURI_H
+
+#include "URI.h"
+
+/**
+ * Represents a FileURI according to RFC 1630 and 1738
+ *
+ * Foo.
+ *
+ * @see http://tools.ietf.org/html/rfc1630
+ * @see http://tools.ietf.org/html/rfc1738
+ */
+class FileURI : public URI
+{
+    public:
+
+        /**
+         * Constructor
+         */
+        FileURI(char* uri);
+
+        /**
+         * Destructor
+         */
+        virtual ~FileURI();
+
+};
+
+#endif /* __LIBPARSE_FILEURI */
=======================================
--- /trunk/bin/parse/Main.cpp   Sat Jun 27 04:52:57 2009
+++ /trunk/bin/parse/Main.cpp   Sun Jul 26 08:48:41 2009
@@ -16,27 +16,39 @@
  */

 #include <String.h>
+#include <string.h>
 #include <URI.h>
+#include <FileURI.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>

+void usage(char*);
+
 int main(int argc, char **argv)
 {
-    String u1("http://coen@xxxxxxx\%2enl/file.php?query#fragment";);
-    String u2("http://my.site.nl";);
-
-    URI uri1(*u1);
-    URI uri2(*u2);
-
-    printf("URI1 == %s\n", uri1.getRawURI());
-    printf("URI2 == %s\n", uri2.getRawURI());
-    printf("URI1 has scheme %s\n", uri1.getScheme() );
-    printf("URI1 has hierarchical: %s\n", uri1.getHierarchical() );
-    printf("URI1 has query: %s\n", uri1.getQuery() );
-    printf("URI1 has fragment: %s\n", uri1.getFragment() );
- printf("URI1 equals URI2: %s\n", (uri1.equals(uri2) ? "true" : "false") );
-    printf("URI1 normalized == %s\n", uri1.normalize() );
-
+
+    if( argc == 1 )
+    {
+        usage(argv[0]);
+    }
+
+    String u1(argv[1]);
+    URI uri1(*u1);
+
+    if( strcasecmp("file", uri1.getScheme() ) == 0 )
+    {
+        FileURI fu(*u1);
+        printf("%s\n", fu.getRawURI() );
+    }else {
+        printf("Unknown scheme: %s\n", uri1.getRawURI() );
+    }
+
     return EXIT_SUCCESS;
 }
+
+void usage(char* prog)
+{
+    printf("usage: %s [--uri <uri> | <value>]\n", prog);
+    exit(0);
+}
=======================================
--- /trunk/lib/libparse/SConscript      Sat Jun 27 04:52:57 2009
+++ /trunk/lib/libparse/SConscript      Sun Jul 26 08:48:41 2009
@@ -22,11 +22,11 @@
 #
 env = Prepare(target, [ 'libc', 'libposix' ])
env.Library('libparse', [ 'Parser.cpp', 'StringTokenizer.cpp', 'Delimeter.cpp',
-    'CommandLine.cpp', 'URI.cpp' ])
+    'CommandLine.cpp', 'URI.cpp', 'FileURI.cpp' ])

 #
 # Host build
 #
 env = Prepare(host)
env.Library('host/libparse', [ 'host/Parser.cpp', 'host/StringTokenizer.cpp', 'host/Delimeter.cpp',
-    'host/CommandLine.cpp', 'host/URI.cpp' ])
+    'host/CommandLine.cpp', 'host/URI.cpp', 'host/FileURI.cpp' ])
=======================================
--- /trunk/lib/libparse/URI.cpp Sat Jun 27 04:52:57 2009
+++ /trunk/lib/libparse/URI.cpp Sun Jul 26 08:48:41 2009
@@ -24,6 +24,13 @@

 URI::URI(char* uri) : _uri(uri)
 {
+    if( _uri == (char*)0 )
+    {
+        // TODO: Throw exception if support is added to FreeNOS.
+        printf("ERROR: Illegal URI.\n");
+        exit(1);
+    }
+
     _scheme = 0;
     _hierarchical = 0;
     _query = 0;
=======================================
--- /trunk/lib/libparse/URI.h   Sun Jun 28 12:18:18 2009
+++ /trunk/lib/libparse/URI.h   Sun Jul 26 08:48:41 2009
@@ -136,6 +136,9 @@
         /** The fragment part of the URI. */
         char* _fragment;

+        /** The scheme of the URI. */
+        char* _scheme;
+
         /**
          * Decodes the given encoded char* (hex)
          * and returns the decoded char.
@@ -143,11 +146,6 @@
          * @return char The decoded char.
          */
         char _decode(char* encoded);
-
-    private:
-
-        /** The scheme of the URI. */
-        char* _scheme;

 };


Other related posts:

  • » [freenos] r230 commited - Added the FileURI class, but it just checks whether the given URI has ... - codesite-noreply