Added:
trunk/gom/include/gom/gomuriutils.h
trunk/gom/src/libgom/gomuriutils.cc
Removed:
trunk/gom/Makefile.configure
trunk/gom/cppflags.py
trunk/gom/ldflags.py
trunk/gom/src/libgom/gomuri.c
Modified:
trunk/gom/ (props changed)
trunk/gom/ChangeLog
trunk/gom/Makefile.am
trunk/gom/configure.ac
trunk/gom/include/gom/Makefile.inc
trunk/gom/src/gom/Makefile.inc
trunk/gom/src/gom/gom.c
trunk/gom/src/libgom/Makefile.inc
trunk/gom/src/libgom/gomjswindow.c
trunk/gom/src/libgom/gomxhr.c
trunk/gom/tests/Makefile.inc
Log:
2008-07-27 jacob berkman <ja...@ilovegom.org>
* configure.ac: port to using xulrunner sdk rather than
spidermonkey checkout
* src/libgom/gomjswindow.c (gom_js_window_parser_end_element):
(gom_js_window_parse_file): use new gom_uri_* methods for
loading files
* src/libgom/gomxhr.c (gom_xhr_open): comment out bits that
used GomURI until this is back in action
* src/gom/gom.c (main): find a GRE and initialize XPCOM
* src/libgom/gomuriutils.cc (gom_uri_join): new nsIURI-based implementation
(gom_uri_get_contents): glib-like api for loading uris
Modified: trunk/gom/ChangeLog
==============================================================================
--- trunk/gom/ChangeLog (original)
+++ trunk/gom/ChangeLog Sun Jul 27 22:12:39 2008
@@ -1,3 +1,20 @@
+2008-07-27 jacob berkman <ja...@ilovegom.org>
+
+ * configure.ac: port to using xulrunner sdk rather than
+ spidermonkey checkout
+
+ * src/libgom/gomjswindow.c (gom_js_window_parser_end_element):
+ (gom_js_window_parse_file): use new gom_uri_* methods for
+ loading files
+
+ * src/libgom/gomxhr.c (gom_xhr_open): comment out bits that
+ used GomURI until this is back in action
+
+ * src/gom/gom.c (main): find a GRE and initialize XPCOM
+
+ * src/libgom/gomuriutils.cc (gom_uri_join): new nsIURI-based implementation
+ (gom_uri_get_contents): glib-like api for loading uris
+
2008-07-26 jacob berkman <ja...@ilovegom.org>
* src/libgom/gomdominterfaces.c:
Modified: trunk/gom/Makefile.am
==============================================================================
--- trunk/gom/Makefile.am (original)
+++ trunk/gom/Makefile.am Sun Jul 27 22:12:39 2008
@@ -24,12 +24,14 @@
# sbin_SCRIPTS :=
+noinst_LIBRARIES :=
noinst_LTLIBRARIES :=
# dist_sbin_SCRIPTS :=
dist_noinst_SCRIPTS :=
# dist_pkglibexec_SCRIPTS :=
+lib_LIBRARIES :=
lib_LTLIBRARIES :=
# apps_DATA :=
@@ -46,7 +48,7 @@
AM_CPPFLAGS :=
-dist_noinst_DATA += Makefile.am.subdir Makefile.configure gomwidgets.in
+dist_noinst_DATA += Makefile.am.subdir gomwidgets.in
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA := gom-0.pc
Modified: trunk/gom/configure.ac
==============================================================================
--- trunk/gom/configure.ac (original)
+++ trunk/gom/configure.ac Sun Jul 27 22:12:39 2008
@@ -7,6 +7,15 @@
AC_CONFIG_SRCDIR([src/gom/gom.c])
AC_CONFIG_HEADER([config.h])
+AC_ARG_WITH([xulrunner-sdk],
+ [AS_HELP_STRING([--with-xulrunner-sdk],
+ [path to XulRunner SDK directory])],
+ [xulrunnersdk=$withval])
+if test -z "$xulrunnersdk" ; then
+ AC_MSG_ERROR([You must specify the path to a XulRunner SDK with the
--with-xulrunner-sdk option.])
+fi
+AC_SUBST(DISTCHECK_CONFIGURE_FLAGS,["--with-xulrunner-sdk=$xulrunnersdk"])
+
# Honor aclocal flags
ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
@@ -30,15 +39,14 @@
# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
-AM_PROG_LIBTOOL
+AC_PROG_CXX
+AC_PROG_RANLIB
# Make libtool use --silent when --silent is passed to make
changequote(,)dnl
LIBTOOL="${LIBTOOL} \$(shell echo \"\$(MFLAGS)\" | awk '/^[^ ]*s/ {
print \"--silent\" }')"
changequote([,])dnl
-# Checks for programs.
-
# Checks for libraries.
#
# Run AM_PATH_GLIB_2_0 to make sure that GLib is installed and working
@@ -52,67 +60,43 @@
*** GLIB is always available from ftp://ftp.gtk.org/pub/gtk/.]),
gobject gmodule-no-export gthread)
-AC_ARG_WITH([mozilla-source],
- [AS_HELP_STRING([--with-mozilla-source],
- [path to checked-out and built Mozilla JavaScript source tree])],
- [mozilla_source=$withval])
-if test -z "$mozilla_source" ; then
- AC_MSG_ERROR([You must specify the path to a checked-out and built
Mozilla JavaScript source tree with the --with-mozilla-source option.])
-fi
-AC_MSG_CHECKING([for jsapi.c in $mozilla_source])
-if test -r "$mozilla_source"/jsapi.c ; then
- AC_MSG_RESULT([found])
-else
- AC_MSG_RESULT([not found])
- AC_MSG_CHECKING([for jsapi.c in $mozilla_source/src])
- if test -r "$mozilla_source"/src/jsapi.c ; then
- AC_MSG_RESULT([found])
- mozilla_source="$mozilla_source"/src
- else
- AC_MSG_RESULT([not found])
- AC_MSG_CHECKING([for jsapi.c in $mozilla_source/js/src])
- if test -r "$mozilla_source"/js/src/jsapi.c ; then
- AC_MSG_RESULT([found])
- mozilla_source="$mozilla_source"/js/src
- else
- AC_MSG_RESULT([not found])
- AC_MSG_ERROR([$mozilla_source does not look like a Mozilla
JavaScript source tree.])
- fi
- fi
-fi
-AC_MSG_CHECKING([for config.mk in $mozilla_source])
-if test -r "$mozilla_source"/config.mk ; then
- AC_MSG_RESULT([found])
-else
- AC_MSG_RESULT([not found])
- AC_MSG_ERROR([$mozilla_source does not look like a Mozilla JavaScript
source tree.])
-fi
-mozmake="make -s mozilla_source=$mozilla_source -f $srcdir/Makefile.configure"
-AC_MSG_CHECKING([for Mozilla OBJDIR])
-moz_objdir=$($mozmake objdir)
-AC_MSG_RESULT([$moz_objdir])
-AC_MSG_CHECKING([for libjs.a in $mozilla_source/$moz_objdir])
-if test -r "$mozilla_source/$moz_objdir"/libjs.a ; then
- AC_MSG_RESULT([found])
-else
- AC_MSG_RESULT([not found])
- AC_MSG_ERROR([$mozilla_source does not look like a Mozilla JavaScript
source tree.])
-fi
-moz_oscflags=$($mozmake oscflags)
-moz_oslibs=$($mozmake oslibs)
-AC_SUBST(JS_CFLAGS, ["$moz_oscflags -I$mozilla_source -I$mozilla_source/$moz_objdir"])
-AC_SUBST(JS_LIBS, ["$mozilla_source/$moz_objdir/libjs.a $moz_oslibs"])
-AC_SUBST(DISTCHECK_CONFIGURE_FLAGS,["--with-mozilla-source=$mozilla_source"])
-
-AC_SUBST(PY_LDFLAGS,[$(python ldflags.py)])
-AC_SUBST(PY_CPPFLAGS,[$(python cppflags.py)])
-AC_SUBST(CURL_CFLAGS,[$(pkg-config --cflags libcurl)])
-AC_SUBST(CURL_LIBS,[$(pkg-config --libs-only-L --libs-only-l libcurl)])
# Checks for header files.
+CPPFLAGS_save=$CPPFLAGS
+
+js_cppflags="-I$xulrunnersdk/include/js -DXP_UNIX"
+CPPFLAGS="$CPPFLAGS_save $js_cppflags"
+AC_CHECK_HEADERS([jsapi.h],[],[
+ AC_MSG_ERROR([$xulrunnersdk is missing Spidermonkey headers.])
+])
+GOM_CFLAGS="$GOM_CFLAGS $js_cppflags"
+
+xulrunner_cppflags="-I$xulrunnersdk/sdk/include -DXPCOMGLUE=1"
+CPPFLAGS="$CPPFLAGS_save $xulrunner_cppflags"
+AC_LANG_PUSH([C++])
+AC_CHECK_HEADERS([nsXPCOM.h nsIIOService.h],[],[
+ AC_MSG_ERROR([$xulrunnersdk is missing XPCOM headers.])
+])
+AC_LANG_POP([C++])
+GOM_CFLAGS="$GOM_CFLAGS $xulrunner_cppflags"
+
+CPPFLAGS=$CPPFLAGS_save
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
+LIBS_save=$LIBS
+
+xulrunner_libs="-L$xulrunnersdk/sdk/lib"
+LIBS="$LIBS_save $xulrunner_libs"
+AC_CHECK_LIB([mozjs],[JS_Init],[],[
+ AC_MSG_ERROR([$xulrunner is missing Spidermonkey libraries.])
+])
+AC_CHECK_LIB([xpcomglue],[XPCOMGlueStartup],[],[
+ AC_MSG_ERROR([$xulrunnersdk is missing XPCOM libraries.])
+])
+GOM_LIBS="$GOM_LIBS $xulrunner_libs -lxpcomglue -lmozjs"
+
+LIBS=$LIBS_save
rm -rf a.out.dSYM
Modified: trunk/gom/include/gom/Makefile.inc
==============================================================================
--- trunk/gom/include/gom/Makefile.inc (original)
+++ trunk/gom/include/gom/Makefile.inc Sun Jul 27 22:12:39 2008
@@ -40,7 +40,7 @@
include/gom/gomobject.h \
include/gom/gomtxt.h \
include/gom/gomuievt.h \
- include/gom/gomuri.h \
+ include/gom/gomuriutils.h \
include/gom/gomvalue.h \
include/gom/gomwidget.h \
include/gom/gomxhr.h
Added: trunk/gom/include/gom/gomuriutils.h
==============================================================================
--- (empty file)
+++ trunk/gom/include/gom/gomuriutils.h Sun Jul 27 22:12:39 2008
@@ -0,0 +1,45 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining
a copy
+of this software and associated documentation files (the "Software"),
to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef GOM_URI_UTILS_H
+#define GOM_URI_UTILS_H
+
+#include <glib/gerror.h>
+
+G_BEGIN_DECLS
+
+#define GOM_NSRESULT_EXCEPTION_ERROR
(gom_nsresult_exception_error_quark ())
+
+char *gom_uri_join (const char *uri, const char *base_uri, GError **error);
+
+gboolean gom_uri_get_contents (const char *uri,
+ const char *base_uri,
+ char **contents,
+ gsize *length,
+ GError **error);
+
+GQuark gom_nsresult_exception_error_quark (void);
+
+G_END_DECLS
+
+#endif /* GOM_URI_UTILS_H */
Modified: trunk/gom/src/gom/Makefile.inc
==============================================================================
--- trunk/gom/src/gom/Makefile.inc (original)
+++ trunk/gom/src/gom/Makefile.inc Sun Jul 27 22:12:39 2008
@@ -2,6 +2,11 @@
bin_PROGRAMS += gom
-gom_SOURCES := src/gom/gom.c
-gom_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
$(GOM_CFLAGS) $(JS_CFLAGS) $(PY_CPPFLAGS)
-gom_LDADD := $(PY_LDFLAGS) libgom.la $(GOM_LIBS) $(JS_LIBS) $(CURL_LIBS)
+# this makes us link as C++
+empty.cc:
+ touch $@
+
+gom_SOURCES := src/gom/gom.c empty.cc
+gom_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include $(GOM_CFLAGS)
+gom_CXXFLAGS = -fshort-wchar
+gom_LDADD := libgom.a $(GOM_LIBS)
Modified: trunk/gom/src/gom/gom.c
==============================================================================
--- trunk/gom/src/gom/gom.c (original)
+++ trunk/gom/src/gom/gom.c Sun Jul 27 22:12:39 2008
@@ -23,12 +23,51 @@
*/
#include "config.h"
+#include "xpcom-config.h"
+
#include "gom/gomgcmanager.h"
#include "gom/gomjscontext.h"
#include "gom/gomjswindow.h"
#include "gom/gomjsobject.h"
#include "gom/gomwidget.h"
+#include <nsXPCOM.h>
+
+#if 0
+#include <nsXPCOMGlue.h>
+#else
+/*
+ * nsXPCOMGlue.h could easily be included by C sources... but it
+ * isn't. Include C-compatible definitions of the things we use.
+ * They'd probably complain that it's a red herring, since the XPCOM
+ * glue needs C++ things to link, but we have C++ files places we
+ * actually use XPCOM so it works out fine for us.
+ */
+#include <nscore.h>
+
+typedef struct {
+ const char *lower;
+ PRBool lowerInclusive;
+ const char *upper;
+ PRBool upperInclusive;
+} GREVersionRange;
+
+typedef struct {
+ const char *property;
+ const char *value;
+} GREProperty;
+
+NS_COM_GLUE nsresult
+GRE_GetGREPathWithProperties(const GREVersionRange *versions,
+ PRUint32 versionsLength,
+ const GREProperty *properties,
+ PRUint32 propertiesLength,
+ char *buffer, PRUint32 buflen);
+
+NS_HIDDEN_(nsresult)
+XPCOMGlueStartup(const char* xpcomFile);
+#endif
+
#include <gtk/gtk.h>
#include <string.h>
@@ -68,7 +107,7 @@
static gboolean
parse_idle (gpointer data)
{
- MainData *d = data;
+ MainData *d = (MainData *)data;
#ifdef GOM_DEBUG_GC
JS_GC (d->cx);
#endif
@@ -90,12 +129,28 @@
MainData d = { NULL };
GObject *cxpriv;
JSRuntime *rt;
+ nsresult rv;
+ char xpcom_path[PATH_MAX];
+ GREVersionRange gre_version = { "1.9", PR_TRUE, "2", PR_TRUE };
gtk_init (&argc, &argv);
if (argc < 2) {
g_printerr ("Usage: gom <file.gom>\n");
return 1;
+ }
+
+ rv = GRE_GetGREPathWithProperties (&gre_version, 1, nsnull, 0,
+ xpcom_path, sizeof (xpcom_path));
+ if (NS_FAILED (rv)) {
+ g_printerr ("Could not find a compatible Mozilla GRE.\n");
+ return 1;
+ }
+
+ rv = XPCOMGlueStartup (xpcom_path);
+ if (NS_FAILED (rv)) {
+ g_printerr ("Could not start up xpcom glue.\n");
+ return 1;
}
d.filename = argv[1];
Modified: trunk/gom/src/libgom/Makefile.inc
==============================================================================
--- trunk/gom/src/libgom/Makefile.inc (original)
+++ trunk/gom/src/libgom/Makefile.inc Sun Jul 27 22:12:39 2008
@@ -1,8 +1,8 @@
# -*- Makefile -*-
-noinst_LTLIBRARIES += libgom.la
+noinst_LIBRARIES += libgom.a
-libgom_la_SOURCES := \
+libgom_a_SOURCES := \
include/gommacros.h \
src/libgom/gomcamel.c \
src/libgom/gomchardata.c \
@@ -41,13 +41,13 @@
src/libgom/gomobject.c \
src/libgom/gomtxt.c \
src/libgom/gomuievt.c \
- src/libgom/gomuri.c \
+ src/libgom/gomuriutils.cc \
src/libgom/gomvalue.c \
src/libgom/gomwidget.c \
src/libgom/gomxhr.c
-libgom_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
$(GOM_CFLAGS) $(JS_CFLAGS) $(PY_CPPFLAGS) $(CURL_CFLAGS)
-libgom_la_LDFLAGS = $(PY_LDFLAGS) $(GOM_LIBS) $(CURL_LIBS)
+libgom_a_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include $(GOM_CFLAGS)
+libgom_a_CXXFLAGS = -fshort-wchar
src/libgom/gomdominterfaces.c: include/gom/dom/gomdombuiltins.h
Modified: trunk/gom/src/libgom/gomjswindow.c
==============================================================================
--- trunk/gom/src/libgom/gomjswindow.c (original)
+++ trunk/gom/src/libgom/gomjswindow.c Sun Jul 27 22:12:39 2008
@@ -35,7 +35,7 @@
#include "gom/gomjsexception.h"
#include "gom/gomjsobject.h"
#include "gom/gomobject.h"
-#include "gom/gomuri.h"
+#include "gom/gomuriutils.h"
#include "gommacros.h"
@@ -548,26 +548,19 @@
*/
file = gom_element_get_attribute (data->scope->elem, "src");
if (file) {
- char *f2;
- f2 = gom_uri_join (data->filename, file);
- if (!f2) {
- g_printerr (G_STRLOC": could not resolve relative
filename %s\n", file);
+ if (!gom_uri_get_contents (file, data->filename, &script,
&script_len, &err)) {
+ g_printerr (G_STRLOC": could not load %s: %s\n",
+ filename, err->message);
+ g_error_free (err);
} else {
- GomURI *uri;
- char *scheme;
- uri = g_object_new (GOM_TYPE_URI, "uri", f2, NULL);
- g_free (f2);
- g_object_get (uri, "scheme", &scheme, "path", &f2, NULL);
- g_object_unref (uri);
- if (!strcmp (scheme, "file")) {
- g_free (file);
- file = f2;
- }
- if (!g_file_get_contents (file, &script, &script_len,
&err)) {
- g_printerr (G_STRLOC": could not load %s: %s\n",
+ char *uri = gom_uri_join (file, data->filename, &err);
+ if (!uri) {
+ g_printerr (G_STRLOC": could not build uri %s: %s\n",
file, err->message);
g_error_free (err);
}
+ g_free (file);
+ file = uri;
}
filename = file;
lineno = 0;
@@ -668,24 +661,20 @@
char *xml;
gsize xmllen;
GError *error = NULL;
+ char *base;
+ char *pwd;
- if (!g_file_get_contents (filename, &xml, &xmllen, &error)) {
+ pwd = g_get_current_dir ();
+ base = g_strdup_printf ("file://%s/", pwd);
+ if (!gom_uri_get_contents (filename, base, &xml, &xmllen, &error)) {
goto out;
}
- if (g_path_is_absolute (filename)) {
- data.filename = g_strdup_printf ("file://%s", filename);
- } else {
- char *base;
- char *pwd;
-
- pwd = g_get_current_dir ();
- base = g_strdup_printf ("file://%s/", pwd);
- g_free (pwd);
-
- data.filename = gom_uri_join (base, filename);
- g_free (base);
+ data.filename = gom_uri_join (filename, base, &error);
+ if (!data.filename) {
+ goto out;
}
+
data.cx = cx;
data.window = window;
@@ -703,6 +692,8 @@
}
out:
+ g_free (base);
+ g_free (pwd);
if (error) {
gom_js_exception_set_error (cx, &error);
}
Added: trunk/gom/src/libgom/gomuriutils.cc
==============================================================================
--- (empty file)
+++ trunk/gom/src/libgom/gomuriutils.cc Sun Jul 27 22:12:39 2008
@@ -0,0 +1,171 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining
a copy
+of this software and associated documentation files (the "Software"),
to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "config.h"
+
+#include "gom/gomuriutils.h"
+
+#include <nsCOMPtr.h>
+#include <nsIChannel.h>
+#include <nsIIOService.h>
+#include <nsIInputStream.h>
+#include <nsIURI.h>
+#include <nsServiceManagerUtils.h>
+#include <nsStringAPI.h>
+
+#include <glib/garray.h>
+#include <glib/gmessages.h>
+#include <glib/gstrfuncs.h>
+#include <glib/gtestutils.h>
+#include <glib/gthread.h>
+
+#include <stdio.h>
+
+#include "gommacros.h"
+
+G_BEGIN_DECLS
+
+GOM_DEFINE_QUARK (nsresult_exception_error);
+
+char *
+gom_uri_join (const char *uri, const char *base_uri, GError **error)
+{
+ nsCAutoString spec;
+ nsCOMPtr<nsIURI> base_nsuri;
+ nsCOMPtr<nsIIOService> io;
+ nsCOMPtr<nsIURI> nsuri;
+ nsresult rv;
+
+ io = do_GetService ("@mozilla.org/network/io-service;1", &rv);
+ if (!io) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not get IO Service");
+ return NULL;
+ }
+
+ if (base_uri) {
+ rv = io->NewURI (nsCAutoString (base_uri), "UTF-8", NULL,
getter_AddRefs (base_nsuri));
+ if (!base_nsuri) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not get base uri");
+ return NULL;
+ }
+ }
+
+ rv = io->NewURI (nsCAutoString (uri), "UTF-8", base_nsuri,
getter_AddRefs (nsuri));
+ if (!nsuri) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not get uri");
+ return NULL;
+ }
+
+ rv = nsuri->GetSpec (spec);
+ if (NS_FAILED (rv)) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not get spec");
+ return NULL;
+ }
+
+ return g_strdup (spec.get());
+}
+
+gboolean
+gom_uri_get_contents (const char *uri,
+ const char *base_uri,
+ char **contents,
+ gsize *length,
+ GError **error)
+{
+ GByteArray *buf;
+ PRUint32 bytes_read;
+ nsCOMPtr<nsIURI> base_nsuri;
+ nsCOMPtr<nsIChannel> chan;
+ nsCOMPtr<nsIIOService> io;
+ nsCOMPtr<nsIInputStream> stream;
+ nsresult rv;
+
+ io = do_GetService ("@mozilla.org/network/io-service;1", &rv);
+ if (!io) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not get IO Service");
+ return FALSE;
+ }
+
+ if (base_uri) {
+ rv = io->NewURI (nsCAutoString (base_uri), "UTF-8", NULL,
getter_AddRefs (base_nsuri));
+ if (!base_nsuri) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not get base uri");
+ return NULL;
+ }
+ }
+
+ rv = io->NewChannel (nsCAutoString(uri), "UTF-8", base_nsuri,
getter_AddRefs (chan));
+ if (!chan) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not create channel");
+ return FALSE;
+ }
+
+ rv = chan->Open (getter_AddRefs (stream));
+ if (!stream) {
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Could not open channel");
+ return FALSE;
+ }
+
+ buf = g_byte_array_sized_new (BUFSIZ);
+ while (1) {
+ rv = stream->Read ((char *)buf->data + buf->len, BUFSIZ, &bytes_read);
+ if (NS_FAILED (rv)) {
+ if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ continue;
+ }
+ stream->Close();
+ g_byte_array_free (buf, TRUE);
+ g_set_error (error, GOM_NSRESULT_EXCEPTION_ERROR, rv,
+ "Error reading stream");
+ return FALSE;
+ }
+ if (bytes_read == 0) {
+ stream->Close();
+ g_byte_array_set_size (buf, buf->len + 1);
+ buf->data[buf->len - 1] = '\0';
+ if (length) {
+ *length = buf->len - 1;
+ }
+ *contents = (char *)g_byte_array_free (buf, FALSE);
+ return TRUE;
+ }
+ /*
+ * something should really be said here but i just haven't the
+ * words
+ */
+ buf->len += bytes_read;
+ g_byte_array_set_size (buf, buf->len + BUFSIZ);
+ buf->len -= BUFSIZ;
+ }
+ g_assert_not_reached ();
+}
+
+G_END_DECLS
Modified: trunk/gom/src/libgom/gomxhr.c
==============================================================================
--- trunk/gom/src/libgom/gomxhr.c (original)
+++ trunk/gom/src/libgom/gomxhr.c Sun Jul 27 22:12:39 2008
@@ -29,12 +29,10 @@
#include "gom/dom/gomeventtarget.h"
#include "gom/dom/gomdomexception.h"
-#include "gom/gomuri.h"
#include "gommacros.h"
#include <string.h>
-#include <curl/curl.h>
enum {
PROP_DOCUMENT = 1,
@@ -52,8 +50,6 @@
GSList *reqhdr_names;
GSList *reqhdr_values;
- GomURI *uri;
-
GomXMLHttpRequestState state;
gboolean send : 1;
@@ -176,9 +172,7 @@
{
GomXhrPrivate *priv = PRIV (xml_http_request);
const char **s;
- GomURI *uri;
char *scheme;
- const curl_version_info_data *curl_data;
const char * const*protocol;
/* 1. Let stored method be the method argument. */
@@ -222,17 +216,19 @@
* 5. Drop the fragment identifier (if any) from url and let
* stored url be the result of that operation.
*/
+#if 0
uri = g_object_new (GOM_TYPE_URI,
"uri", url,
"fragment", NULL,
NULL);
-
+#endif
/*
* 6. If stored url is a relative reference resolve it using the
* current value of the baseURI attribute of the Document
* pointer. If this fails raise a SYNTAX_ERR exception and
* terminate these steps.
*/
+#if 0
if (gom_uri_is_relative (uri)) {
char *new_uri = NULL;
if (priv->doc) {
@@ -242,6 +238,7 @@
char *rel_uri;
g_object_get (uri, "uri", &rel_uri, NULL);
new_uri = gom_uri_join (base_uri, rel_uri);
+ new_uri = g_build_filename (base_uri,
g_free (rel_uri);
}
g_free (base_uri);
@@ -254,7 +251,6 @@
}
uri = g_object_new (GOM_TYPE_URI, "uri", new_uri, NULL);
}
-
/*
* 7. If stored url contains an unsupported scheme raise a
* NOT_SUPPORTED_ERR and terminate these steps.
@@ -339,7 +335,7 @@
if (password != GOM_XML_HTTP_REQUEST_OMITTED) {
g_object_set (uri, "password", password, NULL);
}
-
+#endif
/*
* 19. Abort the send() algorithm, set response entity body to
* "null" and reset the list of request headers.
@@ -362,10 +358,12 @@
*/
priv->state = GOM_OPENED;
priv->send = FALSE;
+#if 0
if (priv->uri) {
g_object_unref (priv->uri);
}
priv->uri = uri;
+#endif
}
/*
Modified: trunk/gom/tests/Makefile.inc
==============================================================================
--- trunk/gom/tests/Makefile.inc (original)
+++ trunk/gom/tests/Makefile.inc Sun Jul 27 22:12:39 2008
@@ -4,10 +4,12 @@
check_PROGRAMS += checkgom
checkgom_SOURCES := \
+ empty.cc \
tests/checkgom.c \
tests/checkgom.h \
tests/checkgomvalue.c \
tests/checkgomvalue.h
-checkgom_CFLAGS = -I$(top_srcdir)/include $(TEST_CFLAGS) $(JS_CFLAGS)
-checkgom_LDADD := libgom.la $(TEST_LIBS) $(JS_LIBS)
+checkgom_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)/include
$(TEST_CFLAGS) $(GOM_CFLAGS)
+checkgom_CXXFLAGS = -fshort-wchar
+checkgom_LDADD := libgom.a $(TEST_LIBS) $(GOM_LIBS)