Skip to content
Browse files

Merge pull request #2 from bit/master

Update ipc to work with Firefox 5.0
  • Loading branch information...
2 parents e92415f + 23ecb7f commit c00766de30a0d309e3e04a8dc2d4f934d8d69bc6 @darkpixel darkpixel committed Jul 7, 2011
Showing with 8,053 additions and 11 deletions.
  1. BIN components/firegpg_ipc.dll
  2. BIN components/libfiregpg_ipc.32.so
  3. BIN components/libfiregpg_ipc.64.so
  4. BIN components/libfiregpg_ipc.dylib
  5. +1 −1 content/Core/cgpg.js
  6. +2 −2 install.rdf
  7. +2 −1 ipc/build_linux32.sh
  8. +2 −1 ipc/build_linux64.sh
  9. +2 −2 ipc/build_osx.sh
  10. +1 −1 ipc/build_win32.sh
  11. +3 −3 ipc/chrome.manifest
  12. BIN ipc/firegpg-ipc/.hg/00changelog.i
  13. +1 −0 ipc/firegpg-ipc/.hg/branch
  14. +2 −0 ipc/firegpg-ipc/.hg/branchheads.cache
  15. BIN ipc/firegpg-ipc/.hg/dirstate
  16. +2 −0 ipc/firegpg-ipc/.hg/hgrc
  17. +4 −0 ipc/firegpg-ipc/.hg/requires
  18. BIN ipc/firegpg-ipc/.hg/store/00changelog.i
  19. BIN ipc/firegpg-ipc/.hg/store/00manifest.i
  20. BIN ipc/firegpg-ipc/.hg/store/data/_makefile.in.i
  21. BIN ipc/firegpg-ipc/.hg/store/data/build/_makefile.in.i
  22. BIN ipc/firegpg-ipc/.hg/store/data/build/ns_i_p_c_module.cpp.i
  23. BIN ipc/firegpg-ipc/.hg/store/data/makemake.i
  24. BIN ipc/firegpg-ipc/.hg/store/data/modules/_makefile.in.i
  25. BIN ipc/firegpg-ipc/.hg/store/data/modules/subprocess.jsm.i
  26. BIN ipc/firegpg-ipc/.hg/store/data/public/_makefile.in.i
  27. BIN ipc/firegpg-ipc/.hg/store/data/public/ns_i_i_p_c_buffer.idl.i
  28. BIN ipc/firegpg-ipc/.hg/store/data/public/ns_i_pipe_listener.idl.i
  29. BIN ipc/firegpg-ipc/.hg/store/data/public/ns_i_pipe_transport.idl.i
  30. BIN ipc/firegpg-ipc/.hg/store/data/readme.txt.i
  31. BIN ipc/firegpg-ipc/.hg/store/data/src/_i_p_c_process.cpp.i
  32. BIN ipc/firegpg-ipc/.hg/store/data/src/_i_p_c_process.h.i
  33. BIN ipc/firegpg-ipc/.hg/store/data/src/_makefile.in.i
  34. BIN ipc/firegpg-ipc/.hg/store/data/src/ipc.h.i
  35. BIN ipc/firegpg-ipc/.hg/store/data/src/ns_i_p_c_buffer.cpp.i
  36. BIN ipc/firegpg-ipc/.hg/store/data/src/ns_i_p_c_buffer.h.i
  37. BIN ipc/firegpg-ipc/.hg/store/data/src/ns_pipe_transport.cpp.i
  38. BIN ipc/firegpg-ipc/.hg/store/data/src/ns_pipe_transport.h.i
  39. BIN ipc/firegpg-ipc/.hg/store/data/tests/_ipc_cat.cpp.i
  40. BIN ipc/firegpg-ipc/.hg/store/data/tests/_makefile.in.i
  41. BIN ipc/firegpg-ipc/.hg/store/data/tests/unit/test__ipcbuffer.js.i
  42. BIN ipc/firegpg-ipc/.hg/store/data/tests/unit/test__pipetrans.js.i
  43. BIN ipc/firegpg-ipc/.hg/store/data/tests/unit/test__subprocess.js.i
  44. BIN ipc/firegpg-ipc/.hg/store/data/~2ehgtags.i
  45. +25 −0 ipc/firegpg-ipc/.hg/store/fncache
  46. BIN ipc/firegpg-ipc/.hg/store/undo
  47. +3 −0 ipc/firegpg-ipc/.hg/tags.cache
  48. +1 −0 ipc/firegpg-ipc/.hg/undo.branch
  49. +3 −0 ipc/firegpg-ipc/.hg/undo.desc
  50. 0 ipc/firegpg-ipc/.hg/undo.dirstate
  51. +1 −0 ipc/firegpg-ipc/.hgtags
  52. +53 −0 ipc/firegpg-ipc/Makefile.in
  53. +115 −0 ipc/firegpg-ipc/build/Makefile.in
  54. +69 −0 ipc/firegpg-ipc/build/nsIPCModule.cpp
  55. +193 −0 ipc/firegpg-ipc/makemake
  56. +52 −0 ipc/firegpg-ipc/modules/Makefile.in
  57. +422 −0 ipc/firegpg-ipc/modules/subprocess.jsm
  58. +53 −0 ipc/firegpg-ipc/public/Makefile.in
  59. +122 −0 ipc/firegpg-ipc/public/nsIIPCBuffer.idl
  60. +114 −0 ipc/firegpg-ipc/public/nsIPipeListener.idl
  61. +294 −0 ipc/firegpg-ipc/public/nsIPipeTransport.idl
  62. +16 −0 ipc/firegpg-ipc/readme.txt
  63. +684 −0 ipc/firegpg-ipc/src/IPCProcess.cpp
  64. +195 −0 ipc/firegpg-ipc/src/IPCProcess.h
  65. +89 −0 ipc/firegpg-ipc/src/Makefile.in
  66. +46 −0 ipc/firegpg-ipc/src/ipc.h
  67. +1,074 −0 ipc/firegpg-ipc/src/nsIPCBuffer.cpp
  68. +113 −0 ipc/firegpg-ipc/src/nsIPCBuffer.h
  69. +2,824 −0 ipc/firegpg-ipc/src/nsPipeTransport.cpp
  70. +414 −0 ipc/firegpg-ipc/src/nsPipeTransport.h
  71. +156 −0 ipc/firegpg-ipc/tests/IpcCat.cpp
  72. +62 −0 ipc/firegpg-ipc/tests/Makefile.in
  73. +245 −0 ipc/firegpg-ipc/tests/unit/test_ipcbuffer.js
  74. +342 −0 ipc/firegpg-ipc/tests/unit/test_pipetrans.js
  75. +251 −0 ipc/firegpg-ipc/tests/unit/test_subprocess.js
  76. BIN platform/Darwin_x86-gcc3/components/libipc.dylib
  77. BIN platform/Linux_x86-gcc3/components/libipc.so
  78. BIN platform/Linux_x86_64-gcc3/components/libipc.so
  79. BIN platform/WINNT_x86-msvc/components/ipc.dll
View
BIN components/firegpg_ipc.dll
Binary file not shown.
View
BIN components/libfiregpg_ipc.32.so
Binary file not shown.
View
BIN components/libfiregpg_ipc.64.so
Binary file not shown.
View
BIN components/libfiregpg_ipc.dylib
Binary file not shown.
View
2 content/Core/cgpg.js
@@ -176,7 +176,7 @@ FireGPG.Sortage = function(a,b) {
var i = 0;
- while(infosA[i] == infosB[i] && i < infosA.lenght)
+ while(infosA[i] == infosB[i] && i < infosA.length)
i++;
if (infosA[i]<infosB[i]) return -1;
View
4 install.rdf
@@ -5,11 +5,11 @@
<RDF:Description RDF:about="rdf:#$g5s0x"
em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
- em:minVersion="4.0"
+ em:minVersion="5.0b2"
em:maxVersion="5.0" />
<RDF:Description RDF:about="urn:mozilla:install-manifest"
em:id="firegpg@firegpg.team"
- em:version="0.8"
+ em:version="0.8.5"
em:type="2"
em:unpack="true"
em:name="FireGPG"
View
3 ipc/build_linux32.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=firegpg
-MOZBUILD=$HOME/src/mozilla-central/obj-ff-release
+MOZBUILD=$HOME/src/mozilla-beta/obj-ff-release
cd `dirname $0`
IPC=`pwd`
@@ -16,4 +16,5 @@ make
COMPONENTS=$IPC/components/
mkdir -p $COMPONENTS
cp ../../dist/bin/components/lib${name}_ipc.so $COMPONENTS/lib${name}_ipc.32.so
+strip $COMPONENTS/lib${name}_ipc.32.so
cp ../../dist/bin/components/${name}_ipc.xpt $COMPONENTS
View
3 ipc/build_linux64.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=firegpg
-MOZBUILD=$HOME/src/mozilla-central/obj-ff-release
+MOZBUILD=$HOME/src/mozilla-beta/obj-ff-release
cd `dirname $0`
IPC=`pwd`
@@ -16,4 +16,5 @@ make
COMPONENTS=$IPC/components/
mkdir -p $COMPONENTS
cp ../../dist/bin/components/lib${name}_ipc.so $COMPONENTS/lib${name}_ipc.64.so
+strip $COMPONENTS/lib${name}_ipc.64.so
cp ../../dist/bin/components/${name}_ipc.xpt $COMPONENTS
View
4 ipc/build_osx.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=firegpg
-MOZBUILD=$HOME/src/mozilla-central/obj-x86_64-apple-darwin10.6.0
+MOZBUILD=$HOME/src/mozilla-beta/obj-x86_64-apple-darwin10.6.0
cd `dirname $0`
IPC=`pwd`
@@ -27,5 +27,5 @@ lipo -create \
-arch i386 $MOZBUILD/i386/dist/bin/components/lib${name}_ipc.dylib \
-arch x86_64 $MOZBUILD/x86_64/dist/bin/components/lib${name}_ipc.dylib \
-output $COMPONENTS/lib${name}_ipc.dylib
-
+strip -S $COMPONENTS/lib${name}_ipc.dylib
cp ../../dist/bin/components/${name}_ipc.xpt $COMPONENTS
View
2 ipc/build_win32.sh
@@ -1,6 +1,6 @@
#!/bin/sh
name=firegpg
-MOZBUILD=$HOME/src/mozilla-central/ff-opt
+MOZBUILD=$HOME/src/mozilla-beta/ff-opt
cd `dirname $0`
View
6 ipc/chrome.manifest
@@ -1,10 +1,10 @@
-resource firegpg modules/
+resource firegpg modules/
interfaces components/firegpg_ipc.xpt
binary-component components/libfiregpg_ipc.dylib ABI=Darwin_x86-gcc3
binary-component components/libfiregpg_ipc.dylib ABI=Darwin_x86_64-gcc3
-binary-component components/libfiregpg_ipc.so ABI=Linux_x86_64-gcc3
-binary-component components/libfiregpg_ipc.so ABI=Linux_x86-gcc3
+binary-component components/libfiregpg_ipc.64.so ABI=Linux_x86_64-gcc3
+binary-component components/libfiregpg_ipc.32.so ABI=Linux_x86-gcc3
binary-component components/firegpg_ipc.dll ABI=WINNT_x86-msvc
contract @getfiregpg.org/ipc/ipc-buffer;1 {babce0c1-7ab1-11d4-8f02-a06008948af5}
contract @getfiregpg.org/ipc/pipe-transport;1 {babce001-7ab1-11d4-8f02-a06008948af5}
View
BIN ipc/firegpg-ipc/.hg/00changelog.i
Binary file not shown.
View
1 ipc/firegpg-ipc/.hg/branch
@@ -0,0 +1 @@
+default
View
2 ipc/firegpg-ipc/.hg/branchheads.cache
@@ -0,0 +1,2 @@
+3aa8d8e7a70a4ec2fe6fa1499b4c4cbbb7cc3e48 2
+3aa8d8e7a70a4ec2fe6fa1499b4c4cbbb7cc3e48 default
View
BIN ipc/firegpg-ipc/.hg/dirstate
Binary file not shown.
View
2 ipc/firegpg-ipc/.hg/hgrc
@@ -0,0 +1,2 @@
+[paths]
+default = http://hg.mozilla.org/ipccode
View
4 ipc/firegpg-ipc/.hg/requires
@@ -0,0 +1,4 @@
+revlogv1
+store
+fncache
+dotencode
View
BIN ipc/firegpg-ipc/.hg/store/00changelog.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/00manifest.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/_makefile.in.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/build/_makefile.in.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/build/ns_i_p_c_module.cpp.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/makemake.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/modules/_makefile.in.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/modules/subprocess.jsm.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/public/_makefile.in.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/public/ns_i_i_p_c_buffer.idl.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/public/ns_i_pipe_listener.idl.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/public/ns_i_pipe_transport.idl.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/readme.txt.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/_i_p_c_process.cpp.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/_i_p_c_process.h.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/_makefile.in.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/ipc.h.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/ns_i_p_c_buffer.cpp.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/ns_i_p_c_buffer.h.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/ns_pipe_transport.cpp.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/src/ns_pipe_transport.h.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/tests/_ipc_cat.cpp.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/tests/_makefile.in.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/tests/unit/test__ipcbuffer.js.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/tests/unit/test__pipetrans.js.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/tests/unit/test__subprocess.js.i
Binary file not shown.
View
BIN ipc/firegpg-ipc/.hg/store/data/~2ehgtags.i
Binary file not shown.
View
25 ipc/firegpg-ipc/.hg/store/fncache
@@ -0,0 +1,25 @@
+data/.hgtags.i
+data/Makefile.in.i
+data/build/Makefile.in.i
+data/build/nsIPCModule.cpp.i
+data/makemake.i
+data/modules/Makefile.in.i
+data/modules/subprocess.jsm.i
+data/public/Makefile.in.i
+data/public/nsIIPCBuffer.idl.i
+data/public/nsIPipeListener.idl.i
+data/public/nsIPipeTransport.idl.i
+data/readme.txt.i
+data/src/IPCProcess.cpp.i
+data/src/IPCProcess.h.i
+data/src/Makefile.in.i
+data/src/ipc.h.i
+data/src/nsIPCBuffer.cpp.i
+data/src/nsIPCBuffer.h.i
+data/src/nsPipeTransport.cpp.i
+data/src/nsPipeTransport.h.i
+data/tests/IpcCat.cpp.i
+data/tests/Makefile.in.i
+data/tests/unit/test_ipcbuffer.js.i
+data/tests/unit/test_pipetrans.js.i
+data/tests/unit/test_subprocess.js.i
View
BIN ipc/firegpg-ipc/.hg/store/undo
Binary file not shown.
View
3 ipc/firegpg-ipc/.hg/tags.cache
@@ -0,0 +1,3 @@
+2 3aa8d8e7a70a4ec2fe6fa1499b4c4cbbb7cc3e48 6c9c742a2408af25fc6db7a39a39ab71a35fbe79
+
+d014d4a1bac10e7131c3a1bb17859034a3839b65 gecko-192
View
1 ipc/firegpg-ipc/.hg/undo.branch
@@ -0,0 +1 @@
+default
View
3 ipc/firegpg-ipc/.hg/undo.desc
@@ -0,0 +1,3 @@
+0
+pull
+http://hg.mozilla.org/ipccode
View
0 ipc/firegpg-ipc/.hg/undo.dirstate
No changes.
View
1 ipc/firegpg-ipc/.hgtags
@@ -0,0 +1 @@
+d014d4a1bac10e7131c3a1bb17859034a3839b65 gecko-192
View
53 ipc/firegpg-ipc/Makefile.in
@@ -0,0 +1,53 @@
+# **** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "MPL"); you may not use this file
+# except in compliance with the MPL. You may obtain a copy of
+# the MPL at http://www.mozilla.org/MPL/
+#
+# Software distributed under the MPL is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the MPL for the specific language governing
+# rights and limitations under the MPL.
+#
+# The Original Code is protoZilla.
+#
+# The Initial Developer of the Original Code is Ramalingam Saravanan.
+# Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+# Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
+#
+# Contributor(s):
+# Patrick Brunschwig <patrick@mozilla-enigmail.org>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+# ***** END LICENSE BLOCK *****
+
+
+DEPTH = ../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+DIRS = public \
+ src \
+ build \
+ modules
+
+ifdef ENABLE_TESTS
+ DIRS += tests
+endif
+
+include $(topsrcdir)/config/rules.mk
View
115 ipc/firegpg-ipc/build/Makefile.in
@@ -0,0 +1,115 @@
+# **** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "MPL"); you may not use this file
+# except in compliance with the MPL. You may obtain a copy of
+# the MPL at http://www.mozilla.org/MPL/
+#
+# Software distributed under the MPL is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the MPL for the specific language governing
+# rights and limitations under the MPL.
+#
+# The Original Code is protoZilla.
+#
+# The Initial Developer of the Original Code is Ramalingam Saravanan.
+# Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+# Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
+#
+# Contributor(s):
+# Patrick Brunschwig <patrick@mozilla-enigmail.org>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+# ***** END LICENSE BLOCK *****
+
+
+DEPTH = ../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+XPI_MODULE = firegpg_ipc
+XPI_MODULE_VERS = 1.3.0
+
+MODULE = firegpg_ipc
+LIBRARY_NAME = firegpg_ipc
+SHORT_LIBNAME = firegpg_ipc
+
+IS_COMPONENT = 1
+FORCE_SHARED_LIB = 1
+EXTRA_BUILD_OPTS =
+
+ifeq ($(OS_ARCH),WINNT)
+ EXPORT_LIBRARY = 0
+ USE_STATIC_LIBS = 1
+ EXTRA_BUILD_OPTS = /NODEFAULTLIB:LIBCMT
+ FORCE_SHARED_LIB = 0
+endif
+
+MOZILLA_VERSION_PARTS = $(subst ., ,$(MOZILLA_VERSION))
+MOZILLA_MAJOR_VERSION = $(firstword $(MOZILLA_VERSION_PARTS))
+TMP_VAR = $(word 2,$(MOZILLA_VERSION_PARTS))
+MOZILLA_MINOR_VERSION = $(shell echo $(TMP_VAR)|sed 's/[a-z].*//')
+
+DEFINES += -DMOZILLA_MAJOR_VERSION=$(MOZILLA_MAJOR_VERSION)
+DEFINES += -DMOZILLA_MINOR_VERSION=$(MOZILLA_MINOR_VERSION)
+
+
+ifdef USE_XPCOM_GLUE
+# Ensure that the xpcom classes that we build
+# do not export themselves
+DEFINES += -D_IMPL_NS_COM_OFF -DXPCOM_GLUE
+endif
+
+REQUIRES = xpcom \
+ string \
+ js \
+ caps \
+ uconv \
+ necko \
+ xpconnect \
+ $(NULL)
+
+MODULE_NAME = IPCModule
+
+CPPSRCS = nsIPCModule.cpp
+
+# hack to build non standard library dependent build on unix
+ifeq ($(IPC_STATIC),1)
+BUILD_STATIC = -nodefaultlibs -Xlinker --unresolved-symbols=ignore-all
+else
+BUILD_STATIC =
+endif
+
+
+SHARED_LIBRARY_LIBS = \
+ ../src/$(LIB_PREFIX)ipc_s.$(LIB_SUFFIX) \
+ $(NULL)
+
+LOCAL_INCLUDES = \
+ -I$(srcdir)/../src \
+ $(NULL)
+
+EXTRA_DSO_LDOPTS = \
+ $(LIBS_DIR) \
+ $(XPCOM_GLUE_LDOPTS) \
+ $(XPCOM_LIBS) \
+ $(NSPR_LIBS) \
+ $(BUILD_STATIC) \
+ $(EXTRA_BUILD_OPTS) \
+ $(NULL)
+
+include $(topsrcdir)/config/rules.mk
View
69 ipc/firegpg-ipc/build/nsIPCModule.cpp
@@ -0,0 +1,69 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "MPL"); you may not use this file
+ * except in compliance with the MPL. You may obtain a copy of
+ * the MPL at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the MPL is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the MPL for the specific language governing
+ * rights and limitations under the MPL.
+ *
+ * The Original Code is protoZilla.
+ *
+ * The Initial Developer of the Original Code is Ramalingam Saravanan.
+ * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+ * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Patrick Brunschwig <patrick@mozilla-enigmail.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * ***** END LICENSE BLOCK ***** */
+
+#include "ipc.h"
+#include "nsIClassInfoImpl.h"
+
+#include "nsPipeTransport.h"
+#include "nsIPCBuffer.h"
+
+#include "mozilla/ModuleUtils.h"
+
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsPipeTransport)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsIPCBuffer)
+
+NS_DEFINE_NAMED_CID(NS_PIPETRANSPORT_CID);
+NS_DEFINE_NAMED_CID(NS_IPCBUFFER_CID);
+
+const mozilla::Module::CIDEntry kIPCModuleCIDs[] = {
+ { &kNS_PIPETRANSPORT_CID, false, NULL, nsPipeTransportConstructor },
+ { &kNS_IPCBUFFER_CID, false, NULL, nsIPCBufferConstructor },
+ { NULL }
+};
+
+const mozilla::Module::ContractIDEntry kIPCModuleContracts[] = {
+ { NS_PIPETRANSPORT_CONTRACTID, &kNS_PIPETRANSPORT_CID },
+ { NS_IPCBUFFER_CONTRACTID, &kNS_IPCBUFFER_CID },
+ { NULL }
+};
+
+static const mozilla::Module kIPCModule = {
+ mozilla::Module::kVersion,
+ kIPCModuleCIDs,
+ kIPCModuleContracts,
+ NULL
+};
+
+NSMODULE_DEFN(nsIPCModule) = &kIPCModule;
View
193 ipc/firegpg-ipc/makemake
@@ -0,0 +1,193 @@
+#!/usr/bin/perl
+
+# **** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "MPL"); you may not use this file
+# except in compliance with the MPL. You may obtain a copy of
+# the MPL at http://www.mozilla.org/MPL/
+#
+# Software distributed under the MPL is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the MPL for the specific language governing
+# rights and limitations under the MPL.
+#
+# The Original Code is ipccode.
+#
+# The Initial Developer of the Original Code is Patrick Brunschwig.
+# Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
+# Copyright (C) 2011 Patrick Brunschwig. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+# ***** END LICENSE BLOCK *****
+
+# makemake: script to generate Makefile from Makefile.in
+# -r: process recursively all subdirectories
+# -o DIR: use DIR as MOZ_OBJDIR
+# Usage: makemake [-o @TOPSRCDIR@/somedir] [-r]
+
+my $makelist="./Makefile.in";
+my $mozObjDir=".";
+my $makefile;
+
+my $cwd=`pwd`;
+chomp($cwd);
+my $topdir=$cwd;
+my $depth="";
+
+open(MAKEFILE, $makelist) || die ("Could not open '$makelist'\n");
+while (my $l = <MAKEFILE>) {
+ chomp($l);
+ if ($l =~ /^\s*DEPTH\s*=/) {
+ $l =~ s/(^\s*DEPTH\s*=\s*)(.*)$/$2/;
+ $depth = $l;
+ }
+}
+close(MAKEFILE);
+
+if ($depth eq "") {
+ while ( (length($topdir)>0) && ( basename($topdir) ne "mozilla" )) {
+ $topdir=dirname($topdir);
+ }
+}
+else {
+ chdir($depth) || die "Directory '$depth' not found\n";
+ chdir("..");
+ $topdir=`pwd`;
+ chomp($topdir);
+ chdir($cwd);
+}
+print "INFO: found toplevel source directory $topdir\n";
+
+
+if (open(MOZCONFIG, "$topdir/.mozconfig")) {
+ while (my $l = <MOZCONFIG>) {
+ chomp($l);
+ if ($l =~ /^\s*mk_add_options\s+MOZ_OBJDIR\s*=/) {
+ $l =~ s/(^\s*mk_add_options\s+MOZ_OBJDIR\s*=\s*)(.*)$/$2/;
+ $mozObjDir = $l;
+ }
+ }
+ close(MOZCONFIG);
+}
+else {
+ print "INFO: no .mozconfig file found\n";
+}
+
+
+while ( $#ARGV >= 0 ) {
+ if ($ARGV[0] eq "-o") {
+ $mozObjDir=$ARGV[1];
+ shift @ARGV;
+ }
+ if ($ARGV[0] eq "-r") {
+ $makelist=`find . -name Makefile.in -print`;
+ break;
+ }
+ shift @ARGV;
+}
+
+
+$mozObjDir =~ s/\@TOPSRCDIR\@/$topdir/;
+
+if ($mozObjDir eq ".") {
+ print "INFO: no MOZ_OBJDIR used\n";
+}
+else {
+ print "INFO: using MOZ_OBJDIR=$mozObjDir\n\n";
+}
+
+foreach $makefile (split(/[ \n\r]+/, $makelist)) {
+ $makefile =~ s/^\.\///;
+ my $dir=dirname("$cwd/$makefile");
+
+ my $wd=$dir;
+ print "Processing: $wd\n";
+ my $top_srcdir="";
+ my $newMakefile = $makefile;
+ $newMakefile =~ s/.in$//;
+
+ if ($mozObjDir eq ".") {
+ # no OBJDIR specified
+ if ($depth eq "") {
+ while ( (length($wd)>0) && (basename($wd) ne "mozilla") ) {
+ if (length($top_srcdir) == 0) {
+ $top_srcdir="..";
+ }
+ else {
+ $top_srcdir="../$top_srcdir";
+ }
+ $wd=dirname($wd);
+ }
+ }
+ else {
+ $top_srcdir=$topdir;
+ }
+ $srcdir=".";
+ }
+ else {
+ # using OBJDIR
+ if ($depth eq "") {
+ # while ( (length($wd)>0) && (basename($wd) ne "mozilla") ) {
+ while ( length($wd)>0 ) {
+ $wd=dirname($wd);
+ }
+ $top_srcdir="$wd";
+ }
+ else {
+ $top_srcdir="$topdir";
+ }
+ $srcdir=$dir;
+ my $targetDir=$srcdir;
+ $targetDir =~ s/$top_srcdir/$mozObjDir/x;
+ system("mkdir -p '$targetDir'");
+ $newMakefile=sprintf("%s/%s", $targetDir, basename($newMakefile));
+ }
+
+ # print "Creating file $newMakefile\n";
+ open(INFILE, $makefile) || die ("cannot open input file '$makefile'\n");
+ open(OUTFILE, ">$newMakefile") || die ("cannot open output file '$newMakefile'\n");
+
+ my $line;
+ while ($line = <INFILE>) {
+ $line =~ s/\@srcdir\@/$srcdir/g;
+ $line =~ s/\@top_srcdir\@/$top_srcdir\/mozilla/g;
+ print OUTFILE $line;
+ }
+ close(INFILE);
+ close(OUTFILE);
+}
+
+if ($mozObjDir eq ".") {
+ print "Done\n\n";
+}
+else {
+ my $newWd=$cwd;
+ $newWd =~ s/$topdir/$mozObjDir/x;
+ print "Done. The code can now be compiled from $newWd\n\n";
+}
+
+sub basename {
+ my $fn=$_[0];
+ $fn =~ s/^(.*)\/(.*)$/$2/;
+ return $fn;
+}
+
+sub dirname {
+ my $dn=$_[0];
+ $dn =~ s/^(.*)\/(.*)$/$1/;
+ return $dn;
+}
View
52 ipc/firegpg-ipc/modules/Makefile.in
@@ -0,0 +1,52 @@
+# **** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "MPL"); you may not use this file
+# except in compliance with the MPL. You may obtain a copy of
+# the MPL at http://www.mozilla.org/MPL/
+#
+# Software distributed under the MPL is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the MPL for the specific language governing
+# rights and limitations under the MPL.
+#
+# The Original Code is protoZilla.
+#
+# The Initial Developer of the Original Code is Ramalingam Saravanan.
+# Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+# Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
+#
+# Contributor(s):
+# Patrick Brunschwig <patrick@mozilla-enigmail.org>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+# ***** END LICENSE BLOCK *****
+
+
+# Makefile for package directory
+
+# Specify these as parameters to the make command
+
+DEPTH = ../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+EXTRA_JS_MODULES = \
+ subprocess.jsm \
+ $(NULL)
+
+include $(topsrcdir)/config/rules.mk
View
422 ipc/firegpg-ipc/modules/subprocess.jsm
@@ -0,0 +1,422 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "MPL"); you may not use this file
+ * except in compliance with the MPL. You may obtain a copy of
+ * the MPL at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the MPL is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the MPL for the specific language governing
+ * rights and limitations under the MPL.
+ *
+ * The Original Code is IPC-Pipe.
+ *
+ * The Initial Developer of this code is Patrick Brunschwig.
+ * Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org>
+ * are Copyright (C) 2010 Patrick Brunschwig.
+ * All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * ***** END LICENSE BLOCK ***** */
+
+
+/*
+ * Import into a JS component using
+ * 'Components.utils.import("resource://gre/modules/subprocess.jsm");'
+ *
+ * This object allows to start a process, and read/write data to/from it
+ * using stdin/stdout/stderr streams.
+ * Usage example:
+ *
+ * var p = subprocess.call({
+ * command: '/bin/foo',
+ * arguments: ['-v', 'foo'],
+ * environment: [ "XYZ=abc", "MYVAR=def" ],
+ * workdir: '/home/foo',
+ * stdin: subprocess.WritablePipe(function() {
+ * this.write("Writing example data\n");
+ * this.close();
+ * }),
+ * stdout: subprocess.ReadablePipe(function(data) {
+ * dump("got data on stdout:" +data+"\n");
+ * }),
+ * stderr: subprocess.ReadablePipe(function(data) {
+ * dump("got data on stderr:" +data+"\n");
+ * }),
+ * onFinished: subprocess.Terminate(function() {
+ * dump("process terminated with " +this.exitCode + "\n");
+ * }),
+ * mergeStderr: false
+ * });
+ * p.wait(); // wait for the subprocess to terminate
+ *
+ *
+ * Description of parameters:
+ * --------------------------
+ * Apart from <command>, all arguments are optional.
+ *
+ * command: either a |nsIFile| object pointing to an executable file or a
+ * String containing the platform-dependent path to an executable
+ * file.
+ *
+ * arguments: optional string array containing the arguments to the command.
+ *
+ * environment: optional string array containing environment variables to pass
+ * to the command. The array elements must have the form
+ * "VAR=data". Please note that if environment is defined, it
+ * replaces any existing environment variables for the subprocess.
+ *
+ * workdir: optional; either a |nsIFile| object pointing to a directory or a
+ * String containing the platform-dependent path to a directory to
+ * become the current working directory of the subprocess.
+ *
+ * stdin: optional input data for the process to be passed on standard
+ * input. stdin can either be a string or a function. If stdin is a
+ * string, then the string content is passed to the process. If
+ * stdin is a function defined using subprocess.WritablePipe, input
+ * data can be written synchronously to the process using
+ * this.write(string).
+ * The stream to the subprocess can be closed with this.close().
+ *
+ * stdout: an optional function that can receive output data from the
+ * process. The stdout-function is called asynchronously; it can be
+ * called mutliple times during the execution of a process. Please
+ * note that null-characters might need to be escaped with
+ * something like 'data.replace(/\0/g, "\\0");'.
+ * stdout needs to be defined using subprocess.ReadablePipe.
+ *
+ * stderr: an optional function that can receive output sent to stderr. The
+ * function is only called synchronously when the process has
+ * terminated. Again, null-characters might need to be escaped.
+ * stderr needs to be defined using subprocess.ReadablePipe.
+ *
+ * onFinished: optional function that is called when the process has terminated.
+ * The exit code from the process available via this.exitCode. If
+ * stdout is not defined, then the output from stdout is available
+ * via this.stdoutData. onFinished needs to be defined using
+ * subprocess.Terminate.
+ *
+ * mergeStderr: optional boolean value. If true, stderr is merged with stdout;
+ * no data will be provided to stderr.
+ *
+ *
+ * Description of object returned by subprocess.call(...)
+ * ------------------------------------------------------
+ * The object returned by subprocess.call offers a few methods that can be
+ * executed:
+ *
+ * wait(): waits for the subprocess to terminate. It is not required to use
+ * wait; onFinshed and stderr will be called in any case when the
+ * subprocess terminated.
+ *
+ * kill(): kill the subprocess. Any open pipes will be closed and
+ * onFinished will be called.
+ *
+ *
+ * Important notes
+ * ---------------
+ *
+ * Be careful if you create more than one subprocess in parallel. Because
+ * p.wait() is blocking the termination of other processes, you cannot wait on
+ * the same thread for more than one subprocess to terminate, unless you know
+ * the sequence in which the subprocesses finish. Therefore it is safer to
+ * create new threads if you need to execute several subprocesses at the same
+ * time.
+ *
+ */
+
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+var EXPORTED_SYMBOLS = [ "subprocess" ];
+
+const NS_PIPETRANSPORT_CONTRACTID = "@getfiregpg.org/ipc/pipe-transport;1";
+const NS_IPCBUFFER_CONTRACTID = "@getfiregpg.org/ipc/ipc-buffer;1";
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+var subprocess = {
+
+ /**
+ * Constructor method to create a subprocess.
+ *
+ * @param commandObj object defining the input parameters. See documentation
+ * above for details.
+ */
+ call: function (commandObj) {
+ var pipeObj = new PipeObj();
+ if (! pipeObj) return null;
+ pipeObj.init(commandObj);
+ return pipeObj;
+ },
+ /**
+ * Create a pipe that writes data to the subprocess
+ *
+ * @param func function definition that implements writing to the pipe
+ * using "this.write(txt)".
+ */
+ WritablePipe: function(func) {
+ var pipeWriterObj = {
+ _pipeTransport: null,
+ write: function(data) {
+ this._pipeTransport.writeSync(data, data.length);
+ },
+ close: function() {
+ this._pipeTransport.closeStdin();
+ },
+ startWriting: func
+ };
+ return pipeWriterObj;
+ },
+ /**
+ * Create a pipe that read data from the subprocess (stdout or stderr)
+ *
+ * @param func function definition that implements reading from the pipe.
+ * The 1st parameter holds the data read from the subprocess.
+ */
+ ReadablePipe: function(func) {
+ var pipeReaderObj = {
+ callbackFunction: func,
+ onDataAvailable: function(data) {
+ this.callbackFunction(data);
+ }
+ }
+ return pipeReaderObj;
+ },
+ /**
+ * Create a function that listens to the termination of the subprocess.
+ *
+ * @param func function definition that implements the listener.
+ */
+ Terminate: function(func) {
+ var onFinishedObj = {
+ stdoutData: null,
+ callbackFunction: func,
+ callback: function (exitCode) {
+ this.exitCode = exitCode;
+ this.callbackFunction();
+ }
+ };
+ return onFinishedObj;
+ },
+};
+
+
+/**
+ * Stream Listener object for handling callbacks from the subprocess' stdout
+ */
+function StdoutStreamListener(cmdObj)
+{
+ this._cmdObj = cmdObj;
+ this._reqObserver = null;
+}
+
+StdoutStreamListener.prototype = {
+ QueryInterface: XPCOMUtils.generateQI(
+ [ Ci.nsIRequestObserver, Ci.nsIStreamListener ]),
+
+ // nsIObserver
+ observe: function (aReqObserver, aContext) {
+ this._reqObserver = aReqObserver;
+ },
+
+ // nsIRequestObserver
+ onStartRequest: function(aRequest, aContext) {
+ if (this._reqObserver)
+ this._reqObserver.onStartRequest(aRequest, aContext);
+ },
+
+ // nsIRequestObserver
+ onStopRequest: function(aRequest, aContext, aStatusCode) {
+ // call to stderr and onFinished from here to avoid mandatory use of
+ // p.wait()
+ if (this._reqObserver)
+ this._reqObserver.onStopRequest(aRequest, aContext, aStatusCode);
+
+ // unset assigned variables to avoid memory leak
+ this._reqObserver=null;
+ this._cmdObj=null;
+ },
+
+ // nsIStreamListener
+ onDataAvailable: function(aRequest, aContext, aInputStream, offset, count) {
+
+ let sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
+ Ci.nsIScriptableInputStream);
+ sis.init(aInputStream);
+ if ("readBytes" in sis) {
+ // Gecko > 2.0b4, supports NULL characters
+ this._cmdObj.stdout.onDataAvailable(sis.readBytes(count));
+ }
+ else
+ // Gecko <= 2.0b4
+ this._cmdObj.stdout.onDataAvailable(sis.read(count));
+
+ // unset variable to avoid memory leak
+ sis = null;
+ }
+
+};
+
+/**
+ * Listener for handling subprocess termination
+ */
+function OnFinishedListener(pipeObj)
+{
+ this._pipeObj = pipeObj;
+}
+
+OnFinishedListener.prototype = {
+ QueryInterface: XPCOMUtils.generateQI([ Ci.nsIRequestObserver ]),
+
+ // nsIRequestObserver
+ onStartRequest: function(aRequest, aContext) {
+ // do nothing
+ },
+
+ // nsIRequestObserver
+ onStopRequest: function(aRequest, aContext, aStatusCode) {
+
+ // call to stderr and onFinished from here to avoid mandatory use of
+ // p.wait()
+
+ let cmdObj = this._pipeObj._cmdObj;
+
+ if (typeof(cmdObj.stderr) == "object" && (! cmdObj.mergeStderr)) {
+ cmdObj.stderr.onDataAvailable( this._pipeObj.stderrData.getData());
+ this._pipeObj.stderrData.shutdown();
+ }
+
+ if (typeof(cmdObj.onFinished) == "object") {
+ if (cmdObj.stdout == null) {
+ cmdObj.onFinished.stdoutData =
+ this._pipeObj.stdoutListener.getData();
+ this._pipeObj.stdoutListener.shutdown();
+ }
+
+ cmdObj.onFinished.callback(this._pipeObj._pipeTransport.exitValue);
+ }
+
+ // unset assigned variables to avoid memory leak
+ this._pipeObj = null;
+ }
+}
+
+/**
+ * Class to represent a running process. This class that is returned
+ * from subprocess.call(...)
+ */
+function PipeObj()
+{}
+
+PipeObj.prototype = {
+ stderrData: null,
+
+ /**
+ * Initializer method.
+ *
+ * @param cmdObj Object as defined for subprocess.call()
+ */
+ init: function(cmdObj) {
+ this._cmdObj = cmdObj;
+
+ // create & open pipeListener for stderr, no matter if needed or not
+ this.stderrData = Cc[NS_IPCBUFFER_CONTRACTID].createInstance(
+ Ci.nsIIPCBuffer);
+ this.stderrData.open(-1, true);
+
+
+ if (typeof (cmdObj.command) == "string") {
+ let localfile = Cc["@mozilla.org/file/local;1"].createInstance(
+ Ci.nsILocalFile);
+ localfile.initWithPath(cmdObj.command);
+ cmdObj._commandFile = localfile.QueryInterface(Ci.nsIFile);
+ }
+ else {
+ cmdObj._commandFile = cmdObj.command;
+ }
+ if (typeof (cmdObj.arguments) != "object") cmdObj.arguments = [];
+ if (typeof (cmdObj.environment) != "object") cmdObj.environment = [];
+ if (typeof (cmdObj.workdir) == "string") {
+ let localfile= Cc["@mozilla.org/file/local;1"].createInstance(
+ Ci.nsILocalFile);
+ localfile.initWithPath(cmdObj.workdir);
+ cmdObj._cwd = localfile.QueryInterface(Ci.nsIFile);
+ }
+ else if (typeof (cmdObj.workdir) == "object") {
+ cmdObj._cwd = cmdObj.workdir;
+ }
+ else {
+ cmdObj._cwd = null;
+ }
+
+ this._pipeTransport = Cc[NS_PIPETRANSPORT_CONTRACTID].createInstance(
+ Ci.nsIPipeTransport);
+ this._pipeTransport.initWithWorkDir(cmdObj._commandFile, cmdObj._cwd,
+ Ci.nsIPipeTransport.INHERIT_PROC_ATTRIBS);
+
+ this.stdoutListener = null;
+ if (typeof(cmdObj.stdout) == "object") {
+ // add listener for asynchronous processing of data
+ this.stdoutListener = new StdoutStreamListener(cmdObj);
+ }
+ else {
+ this.stdoutListener = Cc[NS_IPCBUFFER_CONTRACTID].createInstance(
+ Ci.nsIIPCBuffer);
+ this.stdoutListener.open(-1, true);
+ }
+
+ if (typeof(cmdObj.stderr) == "object" ||
+ typeof(cmdObj.onFinished) == "object")
+ this.stdoutListener.observe(new OnFinishedListener(this), null);
+
+ this._pipeTransport.openPipe(cmdObj.arguments, cmdObj.arguments.length,
+ cmdObj.environment, cmdObj.environment.length,
+ 0, "", true, cmdObj.mergeStderr ? true : false,
+ this.stderrData);
+
+ this._pipeTransport.asyncRead(this.stdoutListener, null, 0, -1, 0);
+
+ if (typeof(cmdObj.stdin) == "string") {
+ this._pipeTransport.writeSync(cmdObj.stdin, cmdObj.stdin.length);
+ this._pipeTransport.closeStdin();
+ }
+ else if (typeof(cmdObj.stdin) == "object") {
+ cmdObj.stdin._pipeTransport = this._pipeTransport;
+ cmdObj.stdin.startWriting();
+ }
+ }, // init
+
+ /**
+ * Wait for the subprocess to complete. This method is blocking.
+ */
+ wait: function () {
+ this._pipeTransport.join();
+ },
+
+ /**
+ * Kill the subprocess
+ */
+ kill: function() {
+ try {
+ this._pipeTransport.kill();
+ }
+ catch(ex) {
+ // do nothing
+ }
+ }
+}; // PipeObj
View
53 ipc/firegpg-ipc/public/Makefile.in
@@ -0,0 +1,53 @@
+# **** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "MPL"); you may not use this file
+# except in compliance with the MPL. You may obtain a copy of
+# the MPL at http://www.mozilla.org/MPL/
+#
+# Software distributed under the MPL is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the MPL for the specific language governing
+# rights and limitations under the MPL.
+#
+# The Original Code is protoZilla.
+#
+# The Initial Developer of the Original Code is Ramalingam Saravanan.
+# Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+# Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
+#
+# Contributor(s):
+# Patrick Brunschwig <patrick@mozilla-enigmail.org>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+# ***** END LICENSE BLOCK *****
+
+
+DEPTH = ../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE = firegpg_ipc
+XPIDL_MODULE = firegpg_ipc
+
+XPIDLSRCS = \
+ nsIPipeListener.idl \
+ nsIPipeTransport.idl \
+ nsIIPCBuffer.idl \
+ $(NULL)
+
+include $(topsrcdir)/config/rules.mk
View
122 ipc/firegpg-ipc/public/nsIIPCBuffer.idl
@@ -0,0 +1,122 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "MPL"); you may not use this file
+ * except in compliance with the MPL. You may obtain a copy of
+ * the MPL at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the MPL is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the MPL for the specific language governing
+ * rights and limitations under the MPL.
+ *
+ * The Original Code is protoZilla.
+ *
+ * The Initial Developer of the Original Code is Ramalingam Saravanan.
+ * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+ * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Patrick Brunschwig <patrick@mozilla-enigmail.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsIPipeListener.idl"
+
+interface nsIURI;
+interface nsIRunnable;
+interface nsIRequestObserver;
+
+%{C++
+#define NS_IPCBUFFER_CLASSNAME "IPC Buffer"
+#define NS_IPCBUFFER_CONTRACTID "@getfiregpg.org/ipc/ipc-buffer;1"
+
+#define NS_IPCBUFFER_CID \
+{ /* babce0c1-7ab1-11d4-8f02-a06008948af5 */ \
+ 0xbabce0c1, 0x7ab1, 0x11d4, \
+{0x8f, 0x02, 0xa0, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
+
+%}
+
+/* nsIIPCBuffer is an interface to a byte buffer.
+ * It is thread-safe, i.e.,it may be called from any thread. It uses a
+ * monitor to ensure data integrity.
+ */
+
+[scriptable, uuid(babce0c0-7ab1-11d4-8f02-a06008948af5)]
+interface nsIIPCBuffer : nsIPipeListener
+{
+ /**
+ * Opens byte buffer
+ *
+ * @param maxBytes maximum number of bytes to be read
+ * (maxBytes <= 0 --> unlimited buffer size)
+ * @param overflowFile determines if a temporary file should be created
+ * if the data to hold in the buffer grows larger than
+ * maxBytes. If false and the buffer reached maxBytes
+ * then reading will block until data is read from the
+ * buffer.
+ */
+
+ void open(in long maxBytes, in boolean overflowFile);
+
+ /**
+ * Loads an URI into the console buffer (use instead of the open method)
+ *
+ * @param aURI URI to be loaded
+ * @param maxBytes maximum number of bytes to be read
+ * (maxBytes <= 0 --> unlimited buffer size)
+ * @param synchronous determines whether to load synchronously
+ * (NOTE: This DOESN'T WORK if the input stream operates
+ * on the same thread -- reading and writing are
+ * both blocking operations)
+ * @param observer a request observer (same as if defined via observe())
+ * @param ctxt opaque parameter passed to listener methods
+ * @param overflowFile determines if a temporary file should be created
+ * (see open() for details)
+ */
+ void openURI(in nsIURI aURI,
+ in long maxBytes,
+ in boolean synchronous,
+ in nsIRequestObserver observer,
+ in nsISupports ctxt,
+ in boolean overflowFile);
+
+ /**
+ * Opens an input stream to access buffer data;
+ * should be called only after the OnStopRequest call to streamListener.
+ * Note: On closing the stream, the buffer will be cleared
+ */
+ nsIInputStream openInputStream();
+
+ /**
+ * Returns data from buffer
+ * (as a NUL-terminated string)
+ */
+ string getData();
+
+ /**
+ * True if onStopRequest method of StreamListener has been invoked
+ */
+ readonly attribute boolean stopped;
+
+ /**
+ * Count of total bytes in buffer (or overflow file)
+ */
+ readonly attribute unsigned long totalBytes;
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
View
114 ipc/firegpg-ipc/public/nsIPipeListener.idl
@@ -0,0 +1,114 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "MPL"); you may not use this file
+ * except in compliance with the MPL. You may obtain a copy of
+ * the MPL at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the MPL is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the MPL for the specific language governing
+ * rights and limitations under the MPL.
+ *
+ * The Original Code is protoZilla.
+ *
+ * The Initial Developer of the Original Code is Ramalingam Saravanan.
+ * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+ * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Patrick Brunschwig <patrick@mozilla-enigmail.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * ***** END LICENSE BLOCK ***** */
+
+
+#include "nsIStreamListener.idl"
+
+%{C++
+#include "IPCProcess.h"
+
+#define NS_PIPELISTENER_CLASSNAME "IPC PipeListener"
+#define NS_PIPELISTENER_CONTRACTID "@getfiregpg.org/ipc/pipe-listener;1"
+%}
+
+/* nsIPipeListener provides a StreamListener sink.
+ * Its implementations should be thread-safe.
+ */
+
+[ptr] native IPCFileDescStar(IPCFileDesc);
+
+[scriptable, uuid(babce0d0-7ab1-11d4-8f02-a06008948af5)]
+interface nsIPipeListener : nsIStreamListener
+{
+ /**
+ * Observes any asynchronous request associated with console.
+ * (E.g., when console is used to capture stdout from
+ * nsIPipeTransport.execAsync)
+ *
+ * @param observer The nsIRequestObserver object
+ * @param ctxt A user-defined context value that is passed to the
+ * observer.
+ */
+ void observe(in nsIRequestObserver observer, in nsISupports ctxt);
+
+ /**
+ * true if console pipe thread may be terminated
+ */
+ readonly attribute boolean joinable;
+
+ /**
+ * Close input pipe and blocks for console logging thread to terminate,
+ * ensuring that all data already written to the console pipe is available
+ * for reading from console buffer.
+ */
+ void join();
+
+ /**
+ * Shuts down listener (without blocking).
+ * Any data already written to the input pipe is discarded.
+ */
+ void shutdown();
+
+ /**
+ * Accesses buffer data as a string of arbitrary bytes,
+ * including NUL characters.
+ */
+ void getByteData(out unsigned long count,
+ [retval, size_is(count)] out string data);
+
+ /**
+ * True if data has been lost (i.e., getByteData does not return all data)
+ */
+ readonly attribute boolean overflowed;
+
+ /**
+ * Writes a string into the buffer
+ */
+ void write(in string str);
+
+ /**
+ * Writes data into the buffer. Data is a string of arbitrary bytes including
+ * NUL characters.
+ */
+ [noscript] void writeBuf(in string buf, in unsigned long count);
+
+ /**
+ * Returns pipe file descriptor associated with listener.
+ */
+ [noscript] IPCFileDescStar GetFileDesc();
+
+};
+
+///////////////////////////////////////////////////////////////////////////////
View
294 ipc/firegpg-ipc/public/nsIPipeTransport.idl
@@ -0,0 +1,294 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "MPL"); you may not use this file
+ * except in compliance with the MPL. You may obtain a copy of
+ * the MPL at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the MPL is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the MPL for the specific language governing
+ * rights and limitations under the MPL.
+ *
+ * The Original Code is protoZilla.
+ *
+ * The Initial Developer of the Original Code is Ramalingam Saravanan.
+ * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
+ * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Patrick Brunschwig <patrick@mozilla-enigmail.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * ***** END LICENSE BLOCK ***** */
+
+
+#include "nsIPipeListener.idl"
+#include "nsIProcess.idl"
+
+interface nsIRequest;
+interface nsIFile;
+interface nsIInputStream;
+interface nsIOutputStream;
+interface nsIStreamListener;
+interface nsIPipeTransportHeaders;
+interface nsIPipeTransportListener;
+interface nsIProcess;
+
+%{C++
+
+#include "IPCProcess.h"
+
+#define NS_PIPETRANSPORT_CLASSNAME "Pipe Transport"
+#define NS_PIPETRANSPORT_CONTRACTID "@getfiregpg.org/ipc/pipe-transport;1"
+
+#define NS_PIPETRANSPORT_CID \
+{ /* babce001-7ab1-11d4-8f02-a06008948af5 */ \
+ 0xbabce001, 0x7ab1, 0x11d4, \
+{0x8f, 0x02, 0xa0, 0x60, 0x08, 0x94, 0x8a, 0xf5} }
+
+%}
+
+/**
+ * The nsIPipeTransport interface executes a file in a new process and
+ * communicates with the process using pipes.
+ *
+ * OWNERSHIP AND THREADING MODEL for nsPipeTransport:
+ *
+ * nsPipeTransport can be created in any thread with an event queue.
+ *
+ * nsPipeTransport lives only in the thread that it was created in.
+ *
+ * nsPipeTransport creates a helper thread object, nsStdoutPoller and retains
+ * an owning reference to it. nsStdoutPoller also holds a strong reference
+ * to a proxy interface (nsIPipeTransportListener) implemented by
+ * nsPipeTransport, which is released when the polling thread terminates.
+ *
+ * The polling thread terminates when it is "interrupted" by nsPipeTransport or
+ * when EOF/error is encountered in reading data from the process STDOUT.
+ *
+ * The "terminate" method should *always* be called to release the process
+ * resources when done.
+ *
+ * For asynchronous reading, when nsStdoutPoller terminates of its own accord,
+ * any stream listener is informed by invoking OnStopRequest.
+ * Usually this listener will be the same as the owner of nsPipeTransport.
+ * (If the owner initiates the request shutdown by first calling "cancel",
+ * then the OnStopRequest method is *not* invoked, because it is assumed
+ * that the listener/owner is already aware of the shutdown.)
+ *
+ */
+[scriptable, uuid(babce000-7ab1-11d4-8f02-a06008948af5)]
+interface nsIPipeTransport : nsIProcess
+{
+
+ /**
+ * Initializes PipeTransport by executing the specified file using the
+ * supplied argument list and environment variables.
+ * It is expected that nsIPipeTransport will be embedded in a
+ * full-featured channel, which will also act as an async stream
+ * observer/listener and forward calls to the actual observer/listener.
+ *
+ * @param executable executable file
+ * @param cwd working directory for the excutable
+ * @param startupFlags flags defining how the process should be created
+ */
+
+ void initWithWorkDir(in nsIFile executable,
+ in nsIFile cwd,
+ in unsigned long startupFlags);
+
+ /**
+ * Opens a PipeTransport by executing the specified file using the
+ * supplied argument list and environment variables.
+ * It is expected that nsIPipeTransport will be embedded in a
+ * full-featured channel, which will also act as an async stream
+ * observer/listener and forward calls to the actual observer/listener.
+ *
+ * @param args arguments string array
+ * (excluding the executable path itself)
+ * @param env environment (variable=value) string array
+ * @param timeoutMS timeout (in milliseconds) after which the process
+ * at the other end of the pipe can be assumed to be
+ * dead
+ * (if == 0, a default value, usually an hour, is used)
+ * @param killString string to be transmitted to process before it is
+ * killed (specify null string, if none)
+ * @param noProxy do not use proxy for async callback
+ * (must use join to terminate process, in this case)
+ * @param mergeStderr merge STDERR with STDOUT
+ * @param stderrConsole nsIPipeListener object to capture STDERR (required
+ * if mergeStderr is false)
+ */
+ void openPipe([array, size_is(argCount)] in wstring args,
+ in unsigned long argCount,
+ [array, size_is(envCount)] in wstring env,
+ in unsigned long envCount,
+ in unsigned long timeoutMS,
+ in string killString,
+ in boolean noProxy,
+ in boolean mergeStderr,
+ in nsIPipeListener stderrConsole);
+
+ /**
+ * detach process after start
+ */
+ const long PROCESS_DETACHED = 0x01;
+ const long INHERIT_PROC_ATTRIBS = 0x02;
+
+ /**
+ * Returns stderrConsole object used to capture STDERR by default
+ */
+ readonly attribute nsIPipeListener stderrConsole;
+
+ /**
+ * Returns listener object to feed data to STDIN
+ * (call to OnStopRequest closes STDIN)
+ */
+ readonly attribute nsIStreamListener listener;
+
+ /**
+ * Specifies interface to handle MIME headers read from STDOUT
+ */
+ attribute nsIPipeTransportHeaders headerProcessor;
+
+ /**
+ * Controls console logging of STDOUT from process
+ */
+ attribute boolean loggingEnabled;
+
+ /**
+ * Open an input stream on this transport.
+ *
+ * @param offset - read starting at this offset
+ * @param count - read this many bytes (pass PRUint32(-1) if unlimited)
+ * @param flags - optional transport specific flags
+ */
+ nsIInputStream openInputStream(in unsigned long offset,
+ in unsigned long count,
+ in unsigned long flags);
+
+ /**
+ * Open an output stream on this transport.
+ *
+ * @param offset - write starting at this offset
+ * @param count - write no more than this many bytes (pass PRUint32(-1) if
+ * unlimited)
+ * @param flags - optional transport specific flags
+ */
+ nsIOutputStream openOutputStream(in unsigned long offset,
+ in unsigned long count,
+ in unsigned long flags);
+
+ /**
+ * Asynchronously read data from the transport.
+ *
+ * @param listener - notify this listener when data is available
+ * @param ctxt - opaque parameter passed to listener methods
+ * @param offset - read starting at this offset
+ * @param count - read this many bytes (pass PRUint32(-1) if unlimited)
+ * @param flags - optional transport specific flags
+ */
+ nsIRequest asyncRead(in nsIStreamListener listener,
+ in nsISupports ctxt,
+ in unsigned long offset,
+ in unsigned long count,
+ in unsigned long flags);
+
+ /**
+ * Joins STDOUT handling thread (blocking until STDOUT is closed),
+ * (Necessary and only works if noProxy is true)
+ * The process still needs to be terminated to free resources.
+ */
+ void join();
+
+ /**
+ * Terminates process, if active, by closing stdin/stdout/stderr.
+ */
+ void terminate();
+
+ /**
+ * Writes string to process STDIN (synchronously)
+ * (Note: child process may exit for valid reasons even before
+ * the first call to writeSync, causing an an exception to be
+ * thrown because STDIN has been closed by the child.)
+ */
+ void writeSync(in string inputData, in unsigned long inputLength);
+
+ /**
+ * closes process STDIN (required even if no data is being transmitted)
+ */
+ void closeStdin();
+
+ /**
+ * Writes stream data to process STDIN (asynchronously),
+ * and close inputStream and STDIN after writing, if requested
+ */
+ void writeAsync(in nsIInputStream aFromStream,
+ in unsigned long aCount,
+ in boolean closeAfterWrite);
+
+ /**
+ * Blocks for output and returns the first line from STDOUT
+ * as a string, up to maxChars (=-1 for unlimited) long.
+ * NOTE: This method is intended for short output; for longer
+ * output, reading using a stream is the better method.
+ */
+
+ string readLine(in long maxOutputLen);
+
+ attribute unsigned long bufferSegmentSize;
+ attribute unsigned long bufferMaxSize;
+ attribute unsigned long headersMaxSize;
+};
+
+
+/**
+ * nsIPipeTransportHeaders is a helper interface to parse MIME headers as
+ * specified by RFC 822.
+ */
+
+[scriptable, uuid(babce010-7ab1-11d4-8f02-006008948af5)]
+interface nsIPipeTransportHeaders : nsISupports
+{
+ /**
+ * Calls channel to parse MIME headers, returning content length
+ * or -1 for unknown content length.
+ * If invalid MIME headers or no channel set, returns error.
+ */
+ long parseMimeHeaders(in string mimeHeaders, in unsigned long count);
+};
+
+
+/**
+ * nsIPipeTransportListener is a helper interface for nsIPipeTransport.
+ * It is used to start and stop the listener stream of nsIPipeTransport.
+ */
+[scriptable, uuid(babce020-7ab1-11d4-8f02-006008948af5)]
+interface nsIPipeTransportListener : nsIPipeTransportHeaders
+{
+ /**
+ * Starts listener, and invokes OnStartRequest on listener, if any.
+ * NOTE: Should not be called if blocked for synchronous read.
+ */
+ void startRequest();
+
+ /**
+ * Stops listener
+ */
+ void stopRequest(in nsresult status);
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
View
16 ipc/firegpg-ipc/readme.txt
@@ -0,0 +1,16 @@
+Compiling ipccode
+*****************
+
+To compile ipccode, follow these steps:
+1. Compile a complete Firefox build
+2. Copy the ipcode directory into src/mozilla/extensions
+3. cd to src/mozilla/extensions/ipccode
+4. execute: ./makemake -r
+5. cd to @MOZ_OBDIR@/mozilla/extensions/ipccode and execute "make"
+
+Notes
+*****
+makemake cannot handle symbolic links, you need to cd to the real directory
+of your source code.
+makemake tries to read your .mozconfig file to determine @MOZ_OBJDIR@. You can
+alternatively provide your own MOZ_OBJDIR using makemake -o
View
684 ipc/firegpg-ipc/src/IPCProcess.cpp
@@ -0,0 +1,684 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "MPL"); you may not use this file
+ * except in compliance with the MPL. You may obtain a copy of
+ * the MPL at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the MPL is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the MPL for the specific language governing
+ * rights and limitations under the MPL.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Ramalingam Saravanan <svn@xmlterm.org>
+ * Patrick Brunschwig <patrick@mozilla-enigmail.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ * ***** END LICENSE BLOCK ***** */
+
+
+#include "ipc.h"
+#include "IPCProcess.h"
+#include "nsMemory.h"
+
+#ifdef XP_WIN
+#include <windows.h>
+#include <shellapi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <io.h>
+#include <fcntl.h>
+
+static void IPC_HideConsoleWin32();
+#endif
+
+
+PRProcess* IPC_CreateProcessRedirectedNSPR(const char *path,
+ char *const *argv,
+ char *const *envp,
+ const char *cwd,
+ PRFileDesc* std_in,
+ PRFileDesc* std_out,
+ PRFileDesc* std_err,
+ PRBool detach)
+{
+#ifdef XP_WIN
+ // Workaround for Win32
+ // Hide process console (after creating one, if need be)
+ IPC_HideConsoleWin32();
+#endif
+
+ PRProcess* process;
+ PRProcessAttr *processAttr;
+ processAttr = PR_NewProcessAttr();
+
+ /* Set current working directory */
+ if (cwd)
+ PR_ProcessAttrSetCurrentDirectory(processAttr, cwd);
+
+ /* Redirect standard I/O for process */
+ if (std_in)
+ PR_ProcessAttrSetStdioRedirect(processAttr, (PRSpecialFD) 0, std_in);
+
+ if (std_out)
+ PR_ProcessAttrSetStdioRedirect(processAttr, (PRSpecialFD) 1, std_out);
+
+ if (std_err)
+ PR_ProcessAttrSetStdioRedirect(processAttr, (PRSpecialFD) 2, std_err);
+
+
+ /* Create NSPR process */
+ process = PR_CreateProcess(path, argv, envp, processAttr);
+
+ if (detach) {
+ PR_DetachProcess(process);
+ }
+
+ return process;
+
+}
+
+PRStatus IPC_CreateInheritablePipeNSPR(PRFileDesc* *readPipe,
+ PRFileDesc* *writePipe,
+ PRBool readInherit,
+ PRBool writeInherit)
+{
+ PRStatus status;
+
+ //status = PR_NewTCPSocketPair(fd);
+ status = PR_CreatePipe(readPipe, writePipe);
+ if (status != PR_SUCCESS)
+ return status;
+
+ // Hack to handle Win32 problem: PR_SetFDInheritable returns error
+ // when we try to return off inheritability. However, inheritability is
+ // supposed to be off by default, so it shouldn't really matter.
+ status = PR_SUCCESS;
+#ifdef XP_WIN
+ if (readInherit)
+#endif
+ status = PR_SetFDInheritable(*readPipe, readInherit);
+ if (status != PR_SUCCESS)
+ return status;
+
+#ifdef XP_WIN
+ if (writeInherit)
+#endif
+ status = PR_SetFDInheritable(*writePipe, writeInherit);
+ if (status != PR_SUCCESS)
+ return status;
+
+ return PR_SUCCESS;
+}
+
+
+#ifdef XP_WIN
+static PRBool gIPCWinConsoleAllocated = PR_FALSE;
+#endif
+
+// Note: it's not necessary to free/close the console, there is (at most) 1
+// console in a parent process
+
+PRStatus IPC_GetProcessIdNSPR(IPCProcess* process, PRInt32 *pid)
+{
+ *pid = 0;
+
+ if (! process)
+ return PR_FAILURE;
+
+ struct MYProcess {
+ PRUint32 pid;
+ };
+ MYProcess* ptrProc = (MYProcess *) process;
+ *pid = ptrProc->pid;
+
+ return PR_SUCCESS;
+}
+
+
+#ifdef XP_WIN
+// Workaround for Win32
+// Try to create a console, if one hasn't already been created
+// (Otherwise each child process creates a console!)
+// and then hide the console.
+// See http://support.microsoft.com/support/kb/articles/q105/3/05.asp
+// and http://support.microsoft.com/support/kb/articles/Q124/1/03.asp
+
+void IPC_HideConsoleWin32()
+{
+
+ // AllocConsole and SetConsoleTitle et al. are Windows API functions.
+ // See Windows SDK/.../include/WinCon.h, WinBase.h, WinUser.h
+
+ if (!gIPCWinConsoleAllocated && ::AllocConsole()) {
+ // Set console title
+ const char consoleTitle[] = "IPC error console";
+ ::SetConsoleTitle(consoleTitle);
+
+ // Redirect stderr
+ int hCrt = ::_open_osfhandle( (long)::GetStdHandle( STD_ERROR_HANDLE ),
+ _O_TEXT );
+ if ( hCrt != -1 ) {
+ FILE *hf = ::_fdopen(hCrt, "w");
+ if ( hf ) {
+ *stderr = *hf;
+ }
+ }
+
+ HWND hWnd;
+ int iWait;
+
+ for (iWait = 0; iWait < 50; iWait++) {
+ // Wait for window title to be updated (up to 1 second)
+ ::Sleep(20);
+
+ // Get console window handle using title
+ // (::GetConsoleWindow() not available in win32 prior to Win2K)
+
+ hWnd = ::FindWindow(NULL, consoleTitle);
+
+ if (hWnd) {
+ ::ShowWindow(hWnd, SW_HIDE); // Hide console window
+ break;
+ }
+ }
+ }
+
+ // Console allocated
+ gIPCWinConsoleAllocated = PR_TRUE;
+
+}
+
+#endif /* XP_WIN */
+
+
+#ifdef XP_WIN_IPC
+
+/*
+ *
+ * Windows specific code adapted from mozilla/xpcom/threads/nsProcessCommon.cpp
+ * Out param `wideCmdLine` must be PR_Freed by the caller.
+ */
+
+static int assembleCmdLine(char *const *argv, PRUnichar **wideCmdLine)
+{
+ char *const *arg;
+ char *p, *q, *cmdLine;
+ int cmdLineSize;
+ int numBackslashes;
+ int i;
+ int argNeedQuotes;
+
+ UINT codePage = CP_UTF8; // the code page to use for the parameter strings
+
+ // Find out how large the command line buffer should be.
+
+ cmdLineSize = 0;
+ for (arg = argv; *arg; arg++) {
+
+ // \ and " need to be escaped by a \. In the worst case,
+ // every character is a \ or ", so the string of length
+ // may double. If we quote an argument, that needs two ".
+ // Finally, we need a space between arguments, and
+ // a null byte at the end of command line.
+
+ cmdLineSize += 2 * strlen(*arg) + // \ and " need to be escaped
+ 2+ // we quote every argument
+ 1; // space in between, or final null
+ }
+ p = cmdLine = (char *) PR_MALLOC(cmdLineSize*sizeof(char));
+ if (p == NULL) {
+ return -1;
+ }
+
+ for (arg = argv; *arg; arg++) {
+ // Add a space to separates the arguments
+ if (arg != argv) {
+ *p++ = ' ';
+ }
+ q = *arg;
+ numBackslashes = 0;
+ argNeedQuotes = 0;
+
+ // If the argument contains white space, it needs to be quoted.
+ if (strpbrk(*arg, " \f\n\r\t\v")) {
+ argNeedQuotes = 1;
+ }
+
+ if (argNeedQuotes) {
+ *p++ = '"';
+ }
+ while (*q) {
+ if (*q == '\\') {
+ numBackslashes++;
+ q++;
+ } else if (*q == '"') {
+ if (numBackslashes) {
+
+ // Double the backslashes since they are followed
+ // by a quote
+ for (i = 0; i < 2 * numBackslashes; i++) {
+ *p++ = '\\';
+ }
+ numBackslashes = 0;
+ }
+ // To escape the quote
+ *p++ = '\\';
+ *p++ = *q++;
+ } else {
+ if (numBackslashes) {
+
+ // Backslashes are not followed by a quote, so
+ // don't need to double the backslashes.
+
+ for (i = 0; i < numBackslashes; i++) {
+ *p++ = '\\';
+ }
+ numBackslashes = 0;
+ }
+ *p++ = *q++;
+ }
+ }
+
+ // Now we are at the end of this argument
+ if (numBackslashes) {
+
+ // Double the backslashes if we have a quote string
+ // delimiter at the end.
+
+ if (argNeedQuotes) {
+ numBackslashes *= 2;
+ }
+ for (i = 0; i < numBackslashes; i++) {
+ *p++ = '\\';
+ }
+ }
+ if (argNeedQuotes) {
+ *p++ = '"';
+ }
+ }
+
+ *p = '\0';
+ PRInt32 numChars = MultiByteToWideChar(codePage, 0, cmdLine, -1, NULL, 0);
+ *wideCmdLine = (PRUnichar *) PR_MALLOC(numChars*sizeof(PRUnichar));
+ MultiByteToWideChar(codePage, 0, cmdLine, -1, *wideCmdLine, numChars);
+ PR_Free(cmdLine);
+ return 0;
+}
+
+/*
+ * Assemble the environment block by concatenating the envp array
+ * (preserving the terminating null byte in each array element)
+ * and adding a null byte at the end.
+ *
+ * Returns 0 on success. The resulting environment block is returned
+ * in *envBlock. Note that if envp is NULL, a NULL pointer is returned
+ * in *envBlock. Returns -1 on failure.
+ */
+static int assembleEnvBlock(char *const *envp, PRUnichar **envBlock)
+{
+ PRUnichar *p, *q;
+ char * const *env;
+ PRInt32 envBlockSize = 0;
+
+ if (envp == NULL) {
+ *envBlock = NULL;
+ return 0;
+ }
+
+ PRInt32 len, maxLen = 0;
+ for (env = envp; *env; env++) {
+ len = MultiByteToWideChar(CP_UTF8, 0, *env, -1, NULL, 0);
+ envBlockSize += len;
+ maxLen = (len > maxLen ? len : maxLen);
+ }
+ envBlockSize++;
+
+ PRUnichar* tempStr = (PRUnichar *) PR_MALLOC(maxLen * sizeof(PRUnichar));
+ p = *envBlock = (PRUnichar *) PR_MALLOC(envBlockSize * sizeof(PRUnichar));
+
+ for (env = envp; *env; env++) {
+
+ len = MultiByteToWideChar(CP_UTF8, 0, *env, -1, NULL, 0);
+ MultiByteToWideChar(CP_UTF8, 0, *env, -1, tempStr, len);
+ q = tempStr;
+
+ while (*q) {
+ // copy data (one by one)
+ *p++ = *q++;
+ }
+
+ *p++ = '\0';
+ }
+
+ *p++ = '\0';
+ PR_Free(tempStr);
+ *p = '\0';
+
+ return 0;
+}
+
+IPCProcess* IPC_CreateProcessRedirectedWin32(const char *path,
+ char *const *argv,
+ char *const *envp,
+ const char *cwd,
+ IPCFileDesc* std_in,
+ IPCFileDesc* std_out,
+ IPCFileDesc* std_err,
+ PRBool detach)
+{
+ BOOL bRetVal;
+
+ // Determine OS Version
+ OSVERSIONINFO osvi;
+ BOOL bIsWin2KOrLater = FALSE;
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (GetVersionEx(&osvi)) {
+ bIsWin2KOrLater = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
+ (osvi.dwMajorVersion >= 5);
+ }
+
+ PRUint32 count = 0;
+ char *const *arg;
+ for (arg = argv; *arg; arg++) {
+ ++count;
+ }
+
+ // make sure that when we allocate we have 1 greater than the
+ // count since we need to null terminate the list for the argv to
+ // pass into PR_CreateProcess
+ char **my_argv = NULL;
+ my_argv = (char **)nsMemory::Alloc(sizeof(char *) * (count + 2) );
+ if (!my_argv) {
+ return IPC_NULL_HANDLE;
+ }
+
+ // copy the args
+ PRUint32 i;
+ for (i=0; i < count; i++) {
+ my_argv[i+1] = const_cast<char*>(argv[i]);
+ }
+
+ // we need to set argv[0] to the program name.
+ my_argv[0] = const_cast<char*>(path);
+ PRInt32 numChars = MultiByteToWideChar(CP_UTF8, 0, my_argv[0], -1, NULL, 0);
+ PRUnichar* wideFile = (PRUnichar *) PR_MALLOC(numChars * sizeof(PRUnichar));
+ MultiByteToWideChar(CP_UTF8, 0, my_argv[0], -1, wideFile, numChars);
+
+ // null terminate the array
+ my_argv[count+1] = NULL;
+
+ PRUnichar *cmdLine = NULL;
+ if (assembleCmdLine(argv, &cmdLine) != 0)
+ return IPC_NULL_HANDLE;
+
+ PRUnichar *envBlock = NULL;
+ if (assembleEnvBlock(envp, &envBlock) != 0) {
+ PR_Free(cmdLine);
+ return IPC_NULL_HANDLE;
+ }
+
+ PRUnichar* wideCwd = NULL;
+
+ if (cwd != NULL) {
+ numChars = MultiByteToWideChar(CP_UTF8, 0, cwd, -1, NULL, 0);
+ PRUnichar* wideCwd = (PRUnichar *) PR_MALLOC(numChars * sizeof(PRUnichar));
+ MultiByteToWideChar(CP_UTF8, 0, cwd, -1, wideCwd, numChars);
+ }
+
+ // Fill in the process's startup information
+ STARTUPINFOW sInfo;
+ memset( &sInfo, 0, sizeof(STARTUPINFOW) );
+ sInfo.cb = sizeof(STARTUPINFOW);
+ sInfo.dwFlags = STARTF_USESTDHANDLES;
+ sInfo.hStdInput = std_in ? (HANDLE)std_in : GetStdHandle(STD_INPUT_HANDLE);
+ sInfo.hStdOutput = std_out ? (HANDLE)std_out : GetStdHandle(STD_OUTPUT_HANDLE);
+ sInfo.hStdError = std_err ? (HANDLE)std_err : GetStdHandle(STD_ERROR_HANDLE);
+ DWORD dwCreationFlags = CREATE_DEFAULT_ERROR_MODE | CREATE_UNICODE_ENVIRONMENT;
+
+ char buf[128];
+ BOOL bIsConsoleAttached = (GetConsoleTitle(buf, 127) > 0);
+
+ if (bIsWin2KOrLater && !bIsConsoleAttached) {
+ // Create and hide child process console
+ // Does not work from Win2K console (and not at all on Win95!)
+ sInfo.dwFlags |= STARTF_USESHOWWINDOW;
+ sInfo.wShowWindow = SW_HIDE;
+ dwCreationFlags |= CREATE_SHARED_WOW_VDM;
+ dwCreationFlags |= CREATE_NEW_CONSOLE;
+ if (detach) {
+ dwCreationFlags |= DETACHED_PROCESS;
+ dwCreationFlags |= CREATE_NEW_PROCESS_GROUP;
+ }
+
+ } else {
+ // Hide parent process console (after creating one, if need be)
+ // Works on all win32 platforms, but creates multiple VDMs on Win2K!
+ IPC_HideConsoleWin32();
+ }
+
+ PROCESS_INFORMATION processInfo;
+
+ bRetVal = CreateProcessW(wideFile, // executable
+ cmdLine, // command line
+ NULL, // process security
+ NULL, // thread security
+ TRUE, // inherit handles
+ dwCreationFlags, // creation flags
+ envBlock, // environment
+ wideCwd, // cwd
+ &sInfo, // startup info