JBoss Native SVN: r1386 - in trunk/httpd/httpd-2.2: srclib/zlib and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2008-02-22 03:35:30 -0500 (Fri, 22 Feb 2008)
New Revision: 1386
Modified:
trunk/httpd/httpd-2.2/NMAKElibhttpd
trunk/httpd/httpd-2.2/srclib/zlib/NMAKEmakefile
Log:
Fix target extensions for libraries
Modified: trunk/httpd/httpd-2.2/NMAKElibhttpd
===================================================================
--- trunk/httpd/httpd-2.2/NMAKElibhttpd 2008-02-22 07:51:35 UTC (rev 1385)
+++ trunk/httpd/httpd-2.2/NMAKElibhttpd 2008-02-22 08:35:30 UTC (rev 1386)
@@ -102,11 +102,11 @@
RCFLAGS = $(RCFLAGS) /d BIN_NAME="$(PROJECT).dll" /d LONG_NAME="Apache HTTP Server Core"
-BUILDAPR = $(BUILDOUT)\$(LIBAPR).dll
-BUILDAPI = $(BUILDOUT)\$(LIBAPI).dll
-BUILDAPU = $(BUILDOUT)\$(LIBAPU).dll
-BUILDZLIB = $(BUILDLIB)\$(ZLIB).lib
-BUILDPCRE = $(BUILDLIB)\$(PCRE).lib
+BUILDAPR = $(BUILDOUT)\$(LIBAPR)
+BUILDAPI = $(BUILDOUT)\$(LIBAPI)
+BUILDAPU = $(BUILDOUT)\$(LIBAPU)
+BUILDZLIB = $(BUILDLIB)\$(ZLIB)
+BUILDPCRE = $(BUILDLIB)\$(PCRE)
BUILDTCHR = $(SRCDIR)\server\gen_test_char.exe
all: $(BUILDINS) $(WORKDIR) $(HEADERS) $(BUILDAPR) $(BUILDAPI) $(BUILDAPU) $(BUILDPCRE) $(BUILDZLIB) $(BUILDBIN)
Modified: trunk/httpd/httpd-2.2/srclib/zlib/NMAKEmakefile
===================================================================
--- trunk/httpd/httpd-2.2/srclib/zlib/NMAKEmakefile 2008-02-22 07:51:35 UTC (rev 1385)
+++ trunk/httpd/httpd-2.2/srclib/zlib/NMAKEmakefile 2008-02-22 08:35:30 UTC (rev 1386)
@@ -40,14 +40,14 @@
!include <..\..\NMAKEhttpd.inc>
!IF "$(TARGET)" == "DLL"
-PROJECT = $(ZLIB)
+PROJECT = libzlib-1
CFLAGS = -DZLIB_DLL $(CFLAGS)
BUILDBIN = $(WORKDIR)\$(PROJECT).dll
BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
BUILDRES = $(WORKDIR)\$(PROJECT).res
BUILDMFT = $(BUILDBIN).manifest
!ELSE
-PROJECT = $(LIBZLIB)
+PROJECT = zlib-1
CFLAGS = -DZLIB_WINAPI $(CFLAGS)
BUILDBIN = $(WORKDIR)\$(PROJECT).lib
!ENDIF
@@ -93,15 +93,6 @@
ASM_OBJECTS =
!ENDIF
-!IF "$(TARGET)" == "DLL"
-BUILDBIN = $(WORKDIR)\$(PROJECT).dll
-BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
-BUILDRES = $(WORKDIR)\$(PROJECT).res
-BUILDMFT = $(BUILDBIN).manifest
-!ELSE
-BUILDBIN = $(WORKDIR)\$(PROJECT).lib
-!ENDIF
-
all : $(BUILDINC) $(BUILDLIB) $(BUILDOUT) $(WORKDIR) $(BUILDBIN)
$(WORKDIR) :
16 years, 10 months
JBoss Native SVN: r1385 - trunk/httpd/httpd-2.2.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2008-02-22 02:51:35 -0500 (Fri, 22 Feb 2008)
New Revision: 1385
Added:
trunk/httpd/httpd-2.2/installer/
Removed:
trunk/httpd/httpd-2.2/install/
Log:
Rename install to installer. It breaks on case insensitive file systems because of INSTALL file
Copied: trunk/httpd/httpd-2.2/installer (from rev 1384, trunk/httpd/httpd-2.2/install)
16 years, 10 months
JBoss Native SVN: r1384 - in trunk/utils/windows/native/service: procrun and 6 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2008-02-19 15:18:46 -0500 (Tue, 19 Feb 2008)
New Revision: 1384
Added:
trunk/utils/windows/native/service/procrun/
trunk/utils/windows/native/service/procrun/NMAKEcommon.inc
trunk/utils/windows/native/service/procrun/NMAKEmgr
trunk/utils/windows/native/service/procrun/NMAKEsvc
trunk/utils/windows/native/service/procrun/apps/
trunk/utils/windows/native/service/procrun/apps/prunmgr/
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.manifest
trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc
trunk/utils/windows/native/service/procrun/apps/prunsrv/
trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c
trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h
trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc
trunk/utils/windows/native/service/procrun/include/
trunk/utils/windows/native/service/procrun/include/apxwin.h
trunk/utils/windows/native/service/procrun/include/cmdline.h
trunk/utils/windows/native/service/procrun/include/console.h
trunk/utils/windows/native/service/procrun/include/gui.h
trunk/utils/windows/native/service/procrun/include/handles.h
trunk/utils/windows/native/service/procrun/include/javajni.h
trunk/utils/windows/native/service/procrun/include/log.h
trunk/utils/windows/native/service/procrun/include/registry.h
trunk/utils/windows/native/service/procrun/include/rprocess.h
trunk/utils/windows/native/service/procrun/include/service.h
trunk/utils/windows/native/service/procrun/resources/
trunk/utils/windows/native/service/procrun/resources/jboss.ico
trunk/utils/windows/native/service/procrun/resources/jbosslogo.bmp
trunk/utils/windows/native/service/procrun/resources/license.rtf
trunk/utils/windows/native/service/procrun/resources/procrunr.ico
trunk/utils/windows/native/service/procrun/resources/procruns.ico
trunk/utils/windows/native/service/procrun/src/
trunk/utils/windows/native/service/procrun/src/cmdline.c
trunk/utils/windows/native/service/procrun/src/console.c
trunk/utils/windows/native/service/procrun/src/gui.c
trunk/utils/windows/native/service/procrun/src/handles.c
trunk/utils/windows/native/service/procrun/src/javajni.c
trunk/utils/windows/native/service/procrun/src/log.c
trunk/utils/windows/native/service/procrun/src/mclib.c
trunk/utils/windows/native/service/procrun/src/mclib.h
trunk/utils/windows/native/service/procrun/src/private.h
trunk/utils/windows/native/service/procrun/src/registry.c
trunk/utils/windows/native/service/procrun/src/rprocess.c
trunk/utils/windows/native/service/procrun/src/service.c
trunk/utils/windows/native/service/procrun/src/utils.c
Log:
For now use the full source copy. Later we might create just a patch
Added: trunk/utils/windows/native/service/procrun/NMAKEcommon.inc
===================================================================
--- trunk/utils/windows/native/service/procrun/NMAKEcommon.inc (rev 0)
+++ trunk/utils/windows/native/service/procrun/NMAKEcommon.inc 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,309 @@
+# Copyright 2001-2006 The Apache Software Foundation or its licensors, as
+# applicable.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ====================================================================
+#
+# NMAKEcommon.inc Master makefile definitions.
+# This file defines CPU architecture and basic compiler
+# and linker parameters.
+# Common params:
+# CPU Compile for specified CPU. Supported CPU's are:
+# i386
+# AMD64
+# IA64
+# If not specified it will default to the
+# PROCESSOR_ARCHITECTURE environment variable
+# or to the i386 if not specified.
+# WINVER Compile for specified Windows version
+# WINNT for Windows 2000 and up(default)
+# WINXP for Windows XP and up
+# WIN2003 for Windows 2003 and up
+# VSITA for Windows Vista and up
+# Deprecated targets (may not even compile):
+# NT4 for Windows NT4 and up
+# WIN9X for Windows 95, 98 and Me
+# BUILD Build version
+# RETAIL or RELEASE (default)
+# DEBUG
+# TARGET Build application target
+# EXE Console executable (default)
+# GUI Windows GUI executable
+# DLL Dynamic Link Library
+# LIB Static library
+# Environment variables used:
+# CFLAGS Added to the common CFLAGS
+# CPPFLAGS Added to the common CPPFLAGS
+# LIBS Added to the common LIBS
+# INCLUDES Added to the common INCLUDES
+# LFLAGS Added to the common LFLAGS
+# RCFLAGS Added to the common RCFLAGS
+#
+# Originally contributed by Mladen Turk <mturk jboss.com>
+#
+# ====================================================================
+#
+
+!IF !DEFINED(CC) || "$(CC)" == ""
+CC = cl.exe
+!ENDIF
+
+!IF !DEFINED(LINK) || "$(LINK)" == ""
+LINK = link.exe
+!ENDIF
+
+!IF !DEFINED(RC) || "$(RC)" == ""
+RC = rc.exe
+!ENDIF
+
+# Read the PROCESSOR_ARCHITECTURE environment value for a CPU type
+
+!IF "$(BUILDCPU)" == "i386" || "$(BUILDCPU)" == "x86" || "$(BUILDCPU)" == "i686"
+CPU=I386
+!ENDIF
+!IF "$(BUILDCPU)" == "amd64" || "$(BUILDCPU)" == "x86_64"
+CPU=AMD64
+!ENDIF
+!IF "$(BUILDCPU)" == "ia64"
+CPU=IA64
+!ENDIF
+
+!IF !DEFINED(CPU) || "$(CPU)" == ""
+!IF "$(PROCESSOR_ARCHITECTURE)" == ""
+CPU=I386
+!ELSE
+CPU=$(PROCESSOR_ARCHITECTURE)
+!ENDIF
+!ENDIF
+
+!IF "$(CPU)" != "I386"
+!IF "$(CPU)" != "AMD64"
+!IF "$(CPU)" != "IA64"
+!ERROR Must specify CPU environment variable (I386, AMD64, IA64) $(CPU)
+!ENDIF
+!ENDIF
+!ENDIF
+
+!IF !DEFINED(TARGET) || "$(TARGET)" == ""
+TARGET=EXE
+!ENDIF
+
+!IF "$(TARGET)" != "EXE"
+!IF "$(TARGET)" != "GUI"
+!IF "$(TARGET)" != "DLL"
+!IF "$(TARGET)" != "LIB"
+!ERROR Must specify TARGET environment variable (EXE, GUI, DLL, LIB)
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+
+!IF !DEFINED(WINVER) || "$(WINVER)" == ""
+WINVER=WINXP
+!ENDIF
+
+
+!IF "$(WINVER)" != "WINNT"
+!IF "$(WINVER)" != "WINXP"
+!IF "$(WINVER)" != "WIN2003"
+!IF "$(WINVER)" != "NT4"
+!IF "$(WINVER)" != "WIN9X"
+!IF "$(WINVER)" != "WVSITA"
+!ERROR Must specify WINVER environment variable (WINNT, WINXP, WIN2003, VSITA, NT4, WIN9X)
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+
+!IF "$(WINVER)" == "WINNT"
+NMAKE_WINVER = 0x0500
+_WIN32_IE = 0x0500
+!ELSEIF "$(WINVER)" == "WINXP"
+NMAKE_WINVER = 0x0501
+_WIN32_IE = 0x0600
+!ELSEIF "$(WINVER)" == "WIN2003"
+NMAKE_WINVER = 0x0502
+_WIN32_IE = 0x0600
+!ELSEIF "$(WINVER)" == "VSITA"
+NMAKE_WINVER = 0x0600
+_WIN32_IE = 0x0700
+!ELSEIF "$(WINVER)" == "NT4"
+NMAKE_WINVER = 0x0400
+_WIN32_IE = 0x0400
+!ELSE
+!ERROR Must specify WINVER environment variable (WINNT, WINXP, WIN2003, VSITA, NT4, WIN9X)
+!ENDIF
+
+!IF !DEFINED(NMAKE_WINVER) || "$(NMAKE_WINVER)" == ""
+NMAKE_WINVER = 0x0400
+_WIN32_IE = 0x0400
+NMAKE_WINNT = -D_WIN95 -D_WIN32_WINDOWS=$(NMAKE_WINVER) -DWINVER=$(NMAKE_WINVER) -D_WIN32_IE=$(_WIN32_IE)
+!ELSE
+NMAKE_WINNT = -D_WINNT -D_WIN32_WINNT=$(NMAKE_WINVER) -DWINVER=$(NMAKE_WINVER) -D_WIN32_IE=$(_WIN32_IE)
+!ENDIF
+
+!IF !DEFINED(BUILD) || "$(BUILD)" == ""
+BUILD=RELEASE
+!ENDIF
+
+!IFDEF RELEASE
+BUILD=RELEASE
+!ENDIF
+
+!IFDEF DEBUG
+BUILD=DEBUG
+!ENDIF
+
+!IFDEF NODEBUG
+BUILD=RELEASE
+!ENDIF
+
+!IF "$(BUILD)" != "RELEASE"
+!IF "$(BUILD)" != "DEBUG"
+!ERROR Must specify BUILD environment variable (RELEASE, DEBUG)
+!ENDIF
+!ENDIF
+
+# Common flags for all platforms
+CMN_CFLAGS = -c -nologo -DWIN32 -D_WIN32 -D_WINDOWS $(NMAKE_WINNT) -W3
+
+!IF "$(CPU)" == "I386"
+CPU_CFLAGS = -D_X86_=1
+!ELSEIF "$(CPU)" == "AMD64"
+CPU_CFLAGS = -D_AMD64_=1 -DWIN64 -D_WIN64 -Wp64
+!ELSEIF "$(CPU)" == "IA64"
+CPU_CFLAGS = -D_IA64_=1 -DWIN64 -D_WIN64 -Wp64
+!ENDIF
+
+!IF "$(INCLUDE_PRE64PRA)" == "1"
+!IF "$(CPU)" != "I386"
+CPU_CFLAGS = $(CPU_CFLAGS) /FIPRE64PRA.H
+!ENDIF
+!ENDIF
+
+!IF "$(BUILD)" == "RELEASE"
+!IF "$(CPU)" == "I386"
+OPT_CFLAGS = -O2 -Ob2 -Oy- -Zi -DNDEBUG
+!ELSE
+OPT_CFLAGS = -O2 -Ob2 -Zi -DNDEBUG
+!ENDIF
+!ELSE
+OPT_CFLAGS = -Od -Zi -DDEBUG -D_DEBUG
+!ENDIF
+
+!IF DEFINED(STATIC_CRT)
+CRT_CFLAGS = -D_MT -MT
+!ELSE
+CRT_CFLAGS = -D_MT -MD
+!ENDIF
+
+!IF "$(BUILD)" == "DEBUG"
+CRT_CFLAGS = $(CRT_CFLAGS)d
+!ENDIF
+
+CFLAGS = $(CMN_CFLAGS) $(CPU_CFLAGS) $(OPT_CFLAGS) $(CRT_CFLAGS) $(CFLAGS)
+
+!IF DEFINED(EXTRA_CFLAGS)
+CFLAGS = $(CFLAGS) $(EXTRA_CFLAGS)
+!ENDIF
+
+
+# Linker section
+LIBS = kernel32.lib advapi32.lib ws2_32.lib mswsock.lib ole32.lib shell32.lib rpcrt4.lib $(LIBS)
+!IF "$(INCLUDE_BUFFEROVERFLOWU)" == "1"
+!IF "$(CPU)" != "I386"
+LIBS = $(LIBS) bufferoverflowu.lib
+!ENDIF
+!ENDIF
+
+!IF DEFINED(EXTRA_LIBS)
+LIBS = $(LIBS) $(EXTRA_LIBS)
+!ENDIF
+
+COMMON_LFLAGS = /NOLOGO
+
+# Always add debugging to the linker
+OPT_LFLAGS = /INCREMENTAL:NO /DEBUG
+!IF "$(BUILD)" == "RELEASE"
+OPT_LFLAGS = /OPT:REF
+!ENDIF
+
+!IF "$(TARGET)" == "EXE"
+LFLAGS = $(COMMON_LFLAGS) /SUBSYSTEM:CONSOLE /MACHINE:$(CPU)
+!ELSEIF "$(TARGET)" == "GUI"
+LFLAGS = $(COMMON_LFLAGS) /SUBSYSTEM:WINDOWS /MACHINE:$(CPU)
+!ELSEIF "$(TARGET)" == "DLL"
+LFLAGS = $(COMMON_LFLAGS) /DLL /SUBSYSTEM:WINDOWS /MACHINE:$(CPU)
+!ELSEIF "$(TARGET)" == "LIB"
+LFLAGS = -lib $(COMMON_LFLAGS)
+!ENDIF
+
+!IF DEFINED(EXTRA_LFLAGS)
+LFLAGS = $(LFLAGS) $(EXTRA_LFLAGS)
+!ENDIF
+
+!IF "$(TARGET)" != "LIB"
+LFLAGS = $(LFLAGS) $(OPT_LFLAGS)
+!ENDIF
+
+# Resource compiler flags
+
+BASE_RCFLAGS=/l 0x409
+!IF "$(BUILD)" == "RELEASE"
+BASE_RCFLAGS = $(BASE_RCFLAGS) /d "NDEBUG"
+!ELSE
+BASE_RCFLAGS = $(BASE_RCFLAGS) /d "_DEBUG" /d "DEBUG"
+!ENDIF
+RCFLAGS = $(BASE_RCFLAGS) $(RCFLAGS)
+
+# Build Target dir e.g. WINNT_I386_RELEASE_DLL
+!IF !DEFINED(WORKDIR) || "$(WORKDIR)" == ""
+!IF !DEFINED(WORKDIR_EXT) || "$(WORKDIR_EXT)" == ""
+WORKDIR = $(WINVER)_$(CPU)_$(TARGET)_$(BUILD)
+!ELSE
+WORKDIR = $(WINVER)_$(CPU)_$(BUILDIR_EXT)_$(BUILD)
+!ENDIF
+!ENDIF
+
+!IF "$(OS)" == "Windows_NT"
+CLEANTARGET=if exist "$(WORKDIR)\$(NULL)" rd /s /q $(WORKDIR)
+!ELSE
+CLEANTARGET=deltree /y $(BUILDIR)
+!ENDIF
+
+MAKEWORKDIR=if not exist "$(WORKDIR)\$(NULL)" mkdir $(WORKDIR)
+MAKEINSTALL=if not exist "$(INSTALLLOC)" mkdir $(INSTALLLOC)
+
+!IF DEFINED(JAVA_HOME) && "$(JAVA_HOME)" != ""
+JAVA_INCLUDES=-I "$(JAVA_HOME)\include"
+!IF "$(CPU)" != "I386"
+JAVA_INCLUDES=$(JAVA_INCLUDES) -I "$(JAVA_HOME)\include\win64"
+!ENDIF
+JAVA_INCLUDES=$(JAVA_INCLUDES) -I "$(JAVA_HOME)\include\win32"
+!ENDIF
+
+!IF !DEFINED(ML) || "$(ML)" == ""
+!IF "$(CPU)" == "I386"
+ML = ml.exe
+AFLAGS = /coff /Zi /c
+!ELSEIF "$(CPU)" == "AMD64"
+ML = ml64.exe
+AFLAGS = /Zi /c
+!ELSEIF "$(CPU)" == "IA64"
+ML = ml64.exe
+AFLAGS = /coff /Zi /c
+!ENDIF
+!ENDIF
Added: trunk/utils/windows/native/service/procrun/NMAKEmgr
===================================================================
--- trunk/utils/windows/native/service/procrun/NMAKEmgr (rev 0)
+++ trunk/utils/windows/native/service/procrun/NMAKEmgr 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,86 @@
+# Copyright(c) 2006 Red Hat Middleware, LLC,
+# and individual contributors as indicated by the @authors tag.
+# See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library in the file COPYING.LIB;
+# if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+#
+# @author Mladen Turk
+#
+
+TARGET = GUI
+PROJECT = jbosswebw
+!include <NMAKEcommon.inc>
+
+!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
+SRCDIR = .
+!ENDIF
+
+LFLAGS = $(LFLAGS) user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib shlwapi.lib netapi32.lib
+INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\src -I$(SRCDIR)\apps\prunmgr -I$(JAVA_HOME)\include -I$(JAVA_HOME)\include\win32
+
+!IF "$(CPU)" == "I386"
+RCFLAGS = $(RCFLAGS) /d "USE_MANIFEST"
+!ENDIF
+
+PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
+OBJECTS = \
+ $(WORKDIR)\cmdline.obj \
+ $(WORKDIR)\console.obj \
+ $(WORKDIR)\gui.obj \
+ $(WORKDIR)\handles.obj \
+ $(WORKDIR)\javajni.obj \
+ $(WORKDIR)\log.obj \
+ $(WORKDIR)\mclib.obj \
+ $(WORKDIR)\registry.obj \
+ $(WORKDIR)\rprocess.obj \
+ $(WORKDIR)\service.obj \
+ $(WORKDIR)\utils.obj \
+ $(WORKDIR)\prunmgr.obj
+
+BUILDLOC = $(PREFIX)\bin
+BUILDEXE = $(WORKDIR)\$(PROJECT).exe
+BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
+BUILDRES = $(WORKDIR)\$(PROJECT).res
+BUILDMAN = $(BUILDEXE).manifest
+
+all : $(WORKDIR) $(BUILDEXE)
+
+$(BUILDLOC) :
+ @if not exist "$(BUILDLOC)\$(NULL)" mkdir "$(BUILDLOC)"
+
+$(WORKDIR) :
+ @$(MAKEWORKDIR)
+
+{$(SRCDIR)\src}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\apps\prunmgr}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+$(BUILDRES): $(SRCDIR)/apps/prunmgr/prunmgr.rc
+ $(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /fo $(BUILDRES) $(SRCDIR)/apps/prunmgr/prunmgr.rc
+
+$(BUILDEXE): $(WORKDIR) $(OBJECTS) $(BUILDRES)
+ $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDEXE)
+ IF EXIST $(BUILDMAN) \
+ mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDEXE);1
+
+clean:
+ @$(CLEANTARGET)
+
+install: $(BUILDLOC) $(WORKDIR) $(BUILDEXE)
+ @xcopy "$(WORKDIR)\*.exe" "$(BUILDLOC)" /Y /Q
Added: trunk/utils/windows/native/service/procrun/NMAKEsvc
===================================================================
--- trunk/utils/windows/native/service/procrun/NMAKEsvc (rev 0)
+++ trunk/utils/windows/native/service/procrun/NMAKEsvc 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,82 @@
+# Copyright(c) 2006 Red Hat Middleware, LLC,
+# and individual contributors as indicated by the @authors tag.
+# See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library in the file COPYING.LIB;
+# if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+#
+# @author Mladen Turk
+#
+
+TARGET = EXE
+PROJECT = jbossweb
+!include <NMAKEcommon.inc>
+
+!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
+SRCDIR = .
+!ENDIF
+
+LFLAGS = $(LFLAGS) user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib shlwapi.lib netapi32.lib
+INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\src -I$(SRCDIR)\apps\prunsrv -I$(JAVA_HOME)\include -I$(JAVA_HOME)\include\win32
+
+PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
+OBJECTS = \
+ $(WORKDIR)\cmdline.obj \
+ $(WORKDIR)\console.obj \
+ $(WORKDIR)\gui.obj \
+ $(WORKDIR)\handles.obj \
+ $(WORKDIR)\javajni.obj \
+ $(WORKDIR)\log.obj \
+ $(WORKDIR)\mclib.obj \
+ $(WORKDIR)\registry.obj \
+ $(WORKDIR)\rprocess.obj \
+ $(WORKDIR)\service.obj \
+ $(WORKDIR)\utils.obj \
+ $(WORKDIR)\prunsrv.obj
+
+BUILDLOC = $(PREFIX)\bin
+BUILDEXE = $(WORKDIR)\$(PROJECT).exe
+BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
+BUILDRES = $(WORKDIR)\$(PROJECT).res
+BUILDMAN = $(BUILDEXE).manifest
+
+all : $(WORKDIR) $(BUILDEXE)
+
+$(BUILDLOC) :
+ @if not exist "$(BUILDLOC)\$(NULL)" mkdir "$(BUILDLOC)"
+
+$(WORKDIR) :
+ @$(MAKEWORKDIR)
+
+{$(SRCDIR)\src}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\apps\prunsrv}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+$(BUILDRES): $(SRCDIR)/apps/prunsrv/prunsrv.rc
+ $(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /fo $(BUILDRES) $(SRCDIR)/apps/prunsrv/prunsrv.rc
+
+$(BUILDEXE): $(WORKDIR) $(OBJECTS) $(BUILDRES)
+ $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDEXE)
+ IF EXIST $(BUILDMAN) \
+ mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDEXE);1
+
+clean:
+ @$(CLEANTARGET)
+
+install: $(BUILDLOC) $(WORKDIR) $(BUILDEXE)
+ @xcopy "$(WORKDIR)\*.exe" "$(BUILDLOC)" /Y /Q
Added: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,1731 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ * prunsrv -- Service Runner.
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI 1
+#include "apxwin.h"
+#include "prunmgr.h"
+
+LPAPXGUISTORE _gui_store = NULL;
+#define PRUNMGR_CLASS TEXT("PRUNMGR")
+#define TMNU_CONF TEXT("Configure...")
+#define TMNU_START TEXT("Start service")
+#define TMNU_STOP TEXT("Stop service")
+#define TMNU_EXIT TEXT("Exit")
+#define TMNU_ABOUT TEXT("About")
+#define TMNU_DUMP TEXT("Thread Dump")
+
+/* Display only Started/Paused status */
+#define STAT_STARTED TEXT("Started")
+#define STAT_PAUSED TEXT("Paused")
+#define STAT_STOPPED TEXT("Stopped")
+#define STAT_DISABLED TEXT("Disabled")
+#define STAT_NONE TEXT("")
+#define STAT_SYSTEM L"LocalSystem"
+
+#define LOGL_ERROR L"Error"
+#define LOGL_DEBUG L"Debug"
+#define LOGL_INFO L"Info"
+#define LOGL_WARN L"Warning"
+
+
+#define START_AUTO L"Automatic"
+#define START_MANUAL L"Manual"
+#define START_DISABLED L"Disabled"
+#define START_BOOT L"Boot"
+#define START_SYSTEM L"SystemInit"
+#define EMPTY_PASSWORD L" "
+
+/* Main application pool */
+APXHANDLE hPool = NULL;
+APXHANDLE hService = NULL;
+APXHANDLE hRegistry = NULL;
+APXHANDLE hRegserv = NULL;
+HICON hIcoRun = NULL;
+HICON hIcoStop = NULL;
+
+LPAPXSERVENTRY _currentEntry = NULL;
+
+BOOL bEnableTry = FALSE;
+DWORD startPage = 0;
+
+static LPCWSTR _s_log = L"Log";
+static LPCWSTR _s_java = L"Java";
+static LPCWSTR _s_start = L"Start";
+static LPCWSTR _s_stop = L"Stop";
+
+/* Allowed procrun commands */
+static LPCWSTR _commands[] = {
+ L"ES", /* 1 Manage Service (default)*/
+ L"MS", /* 2 Monitor Service */
+ L"MR", /* 3 Monitor Service and start if not runing */
+ L"MQ", /* 4 Quit all running Monitor applications */
+ NULL
+};
+
+/* Allowed procrun parameters */
+static APXCMDLINEOPT _options[] = {
+/* 0 */ { L"AllowMultiInstances", NULL, NULL, APXCMDOPT_INT, NULL, 0},
+ /* NULL terminate the array */
+ { NULL }
+};
+
+/* Create RBUTTON try menu
+ * Configure... (default, or lbutton dblclick)
+ * Start <service name>
+ * Stop <service name>
+ * Exit
+ * Logo
+ */
+static void createRbuttonTryMenu(HWND hWnd)
+{
+ HMENU hMnu;
+ POINT pt;
+ BOOL canStop = FALSE;
+ BOOL canStart = FALSE;
+ hMnu = CreatePopupMenu();
+
+ if (_currentEntry) {
+ if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING) {
+ if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP)
+ canStop = TRUE;
+ }
+ else if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_STOPPED) {
+ if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED)
+ canStart = TRUE;
+ }
+ }
+ apxAppendMenuItem(hMnu, IDM_TM_CONFIG, TMNU_CONF, TRUE, TRUE);
+ apxAppendMenuItem(hMnu, IDM_TM_START, TMNU_START, FALSE, canStart);
+ apxAppendMenuItem(hMnu, IDM_TM_STOP, TMNU_STOP, FALSE, canStop);
+ apxAppendMenuItem(hMnu, IDM_TM_DUMP, TMNU_DUMP, FALSE, canStop);
+ apxAppendMenuItem(hMnu, IDM_TM_EXIT, TMNU_EXIT, FALSE, TRUE);
+ apxAppendMenuItem(hMnu, -1, NULL, FALSE, FALSE);
+ apxAppendMenuItem(hMnu, IDM_TM_ABOUT, TMNU_ABOUT, FALSE, TRUE);
+
+ /* Ensure we have a focus */
+ if (!SetForegroundWindow(hWnd))
+ SetForegroundWindow(NULL);
+ GetCursorPos(&pt);
+ /* Display the try menu */
+ TrackPopupMenu(hMnu, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
+ pt.x, pt.y, 0, hWnd, NULL);
+ DestroyMenu(hMnu);
+}
+
+/* wParam progress dialog handle
+ */
+static BOOL __startServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService)) {
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return FALSE;
+ }
+ if (apxServiceControl(hService, SERVICE_CONTROL_CONTINUE, WM_USER+2,
+ __startServiceCallback, hDlg)) {
+ _currentEntry->stServiceStatus.dwCurrentState = SERVICE_RUNNING;
+ _currentEntry->stStatusProcess.dwCurrentState = SERVICE_RUNNING;
+
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(500);
+ break;
+ }
+ return TRUE;
+}
+
+static BOOL __stopServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ if (apxServiceControl(hService, SERVICE_CONTROL_STOP, WM_USER+2,
+ __stopServiceCallback, hDlg)) {
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ if (wParam == 4)
+ AplCopyMemory(&_currentEntry->stServiceStatus,
+ (LPVOID)lParam, sizeof(SERVICE_STATUS));
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(100);
+ break;
+ }
+ return TRUE;
+}
+
+static BOOL __restartServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ /* TODO: use 128 as controll code */
+ if (apxServiceControl(hService, 128, WM_USER+2,
+ __restartServiceCallback, hDlg)) {
+
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ if (wParam == 4)
+ AplCopyMemory(&_currentEntry->stServiceStatus,
+ (LPVOID)lParam, sizeof(SERVICE_STATUS));
+
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(100);
+ break;
+ }
+ return TRUE;
+}
+
+static BOOL __pauseServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ HWND hDlg = (HWND)hObject;
+ switch (uMsg) {
+ case WM_USER+1:
+ hDlg = (HWND)lParam;
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ if (apxServiceControl(hService, SERVICE_CONTROL_PAUSE, WM_USER+2,
+ __pauseServiceCallback, hDlg)) {
+ }
+ EndDialog(hDlg, IDOK);
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+ MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ break;
+ case WM_USER+2:
+ if (wParam == 4)
+ AplCopyMemory(&_currentEntry->stServiceStatus,
+ (LPVOID)lParam, sizeof(SERVICE_STATUS));
+ SendMessage(hDlg, WM_USER+1, 0, 0);
+ Sleep(100);
+ break;
+ }
+ return TRUE;
+}
+
+static DWORD _propertyChanged;
+static BOOL _propertyOpened = FALSE;
+static HWND _propertyHwnd = NULL;
+/* Service property pages */
+int CALLBACK __propertyCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
+{
+ switch(uMsg) {
+ case PSCB_PRECREATE:
+ {
+ LPDLGTEMPLATE lpTemplate = (LPDLGTEMPLATE)lParam;
+ if (!(lpTemplate->style & WS_SYSMENU))
+ lpTemplate->style |= WS_SYSMENU;
+ _propertyHwnd = hwndPropSheet;
+
+ _propertyChanged = 0;
+ _propertyOpened = TRUE;
+ return TRUE;
+ }
+ break;
+ case PSCB_INITIALIZED:
+ break;
+ }
+ return TRUE;
+}
+
+BOOL __generalPropertySave(HWND hDlg)
+{
+ WCHAR szN[256];
+ WCHAR szD[256];
+ DWORD dwStartType = SERVICE_NO_CHANGE;
+ int i;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 1);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, 255);
+ GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, 1023);
+ i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
+ if (i == 0)
+ dwStartType = SERVICE_AUTO_START;
+ else if (i == 1)
+ dwStartType = SERVICE_DEMAND_START;
+ else if (i == 2)
+ dwStartType = SERVICE_DISABLED;
+ apxServiceSetNames(hService, NULL, szN, szD, NULL, NULL);
+ apxServiceSetOptions(hService, SERVICE_NO_CHANGE, dwStartType, SERVICE_NO_CHANGE);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+
+ return TRUE;
+}
+
+BOOL __generalLogonSave(HWND hDlg)
+{
+ WCHAR szU[64];
+ WCHAR szP[64];
+ WCHAR szC[64];
+ DWORD dwStartType = SERVICE_NO_CHANGE;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 2);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ GetDlgItemTextW(hDlg, IDC_PPSLUSER, szU, 63);
+ GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
+ GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+
+ if (lstrlenW(szU) && lstrcmpiW(szU, STAT_SYSTEM)) {
+ if (szP[0] != L' ' && szC[0] != L' ' && !lstrcmpW(szP, szC))
+ apxServiceSetNames(hService, NULL, NULL, NULL, szU, szP);
+ else {
+ MessageBoxW(hDlg, apxLoadResourceW(IDS_VALIDPASS, 0),
+ apxLoadResourceW(IDS_APPLICATION, 1),
+ MB_OK | MB_ICONSTOP);
+ return FALSE;
+ }
+ }
+ else {
+ apxServiceSetNames(hService, NULL, NULL, NULL, STAT_SYSTEM, L"");
+ if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED)
+ apxServiceSetOptions(hService,
+ _currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
+ SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+ else
+ apxServiceSetOptions(hService,
+ _currentEntry->stServiceStatus.dwServiceType & ~SERVICE_INTERACTIVE_PROCESS,
+ SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+ }
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalLoggingSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_DESLEN];
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 3)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 3);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+
+ GetDlgItemTextW(hDlg, IDC_PPLGLEVEL, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Level", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGPATH, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Path", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGPREFIX, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Prefix", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdOutput", szB);
+ GetDlgItemTextW(hDlg, IDC_PPLGSTDERR, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdError", szB);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalJvmSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_DESLEN];
+ LPWSTR p, s;
+ DWORD l;
+ if (!(TST_BIT_FLAG(_propertyChanged, 4)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 4);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+ if (!IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
+ GetDlgItemTextW(hDlg, IDC_PPJJVM, szB, SIZ_DESMAX);
+ }
+ else
+ lstrcpyW(szB, L"auto");
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Jvm", szB);
+ GetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Classpath", szB);
+
+ l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPJOPTIONS));
+ p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+ GetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p, l + 1);
+ s = apxCRLFToMszW(hPool, p, &l);
+ apxFree(p);
+ apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Options", s, l);
+ if (!GetDlgItemTextW(hDlg, IDC_PPJMS, szB, SIZ_DESMAX))
+ szB[0] = L'\0';
+
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMs",
+ apxAtoulW(szB));
+ if (!GetDlgItemTextW(hDlg, IDC_PPJMX, szB, SIZ_DESMAX))
+ szB[0] = L'\0';
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMx",
+ apxAtoulW(szB));
+ if (!GetDlgItemTextW(hDlg, IDC_PPJSS, szB, SIZ_DESMAX))
+ szB[0] = L'\0';
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmSs",
+ apxAtoulW(szB));
+ apxFree(s);
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalStartSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_DESLEN];
+ LPWSTR p, s;
+ DWORD l;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 5)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 5);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+
+ GetDlgItemTextW(hDlg, IDC_PPRCLASS, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Class", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRIMAGE, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Image", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRWPATH, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"WorkingPath", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRMETHOD, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Method", szB);
+ GetDlgItemTextW(hDlg, IDC_PPRMODE, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Mode", szB);
+
+ l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPRARGS));
+ p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+ GetDlgItemTextW(hDlg, IDC_PPRARGS, p, l + 1);
+ s = apxCRLFToMszW(hPool, p, &l);
+ apxFree(p);
+ apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Params", s, l);
+ apxFree(s);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+BOOL __generalStopSave(HWND hDlg)
+{
+ WCHAR szB[SIZ_DESLEN];
+ LPWSTR p, s;
+ DWORD l;
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 6)))
+ return TRUE;
+ CLR_BIT_FLAG(_propertyChanged, 6);
+
+ if (IS_INVALID_HANDLE(hService))
+ return FALSE;
+
+ GetDlgItemTextW(hDlg, IDC_PPSCLASS, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Class", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSIMAGE, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Image", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSWPATH, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"WorkingPath", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSMETHOD, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Method", szB);
+ GetDlgItemTextW(hDlg, IDC_PPSTIMEOUT, szB, SIZ_DESMAX);
+ apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Timeout", apxAtoulW(szB));
+ GetDlgItemTextW(hDlg, IDC_PPSMODE, szB, SIZ_DESMAX);
+ apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Mode", szB);
+
+ l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPSARGS));
+ p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+ GetDlgItemTextW(hDlg, IDC_PPSARGS, p, l + 1);
+ s = apxCRLFToMszW(hPool, p, &l);
+ apxFree(p);
+ apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Params", s, l);
+ apxFree(s);
+
+ if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+ return TRUE;
+}
+
+void __generalPropertyRefresh(HWND hDlg)
+{
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), FALSE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), FALSE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), FALSE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), FALSE);
+ switch (_currentEntry->stServiceStatus.dwCurrentState) {
+ case SERVICE_RUNNING:
+ if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP ||
+ _currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), TRUE);
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STARTED);
+ }
+ else
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+ if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) {
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), TRUE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+ }
+ break;
+ case SERVICE_PAUSED:
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_PAUSED);
+ break;
+ case SERVICE_STOPPED:
+ if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+ Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STOPPED);
+ }
+ else
+ SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+ break;
+ default:
+ break;
+ }
+}
+
+static BOOL bpropCentered = FALSE;
+LRESULT CALLBACK __generalProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ WCHAR szBuf[1024];
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ if (!bEnableTry)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ else if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+ startPage = 0;
+ if (!bEnableTry)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, 255, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, 1023, 0);
+
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_AUTO);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_MANUAL);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_DISABLED);
+ if (_currentEntry->lpConfig->dwStartType == SERVICE_AUTO_START)
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 0);
+ else if (_currentEntry->lpConfig->dwStartType == SERVICE_DEMAND_START)
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 1);
+ else if (_currentEntry->lpConfig->dwStartType == SERVICE_DISABLED)
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 2);
+
+ SetDlgItemTextW(hDlg, IDC_PPSGNAME, _currentEntry->szServiceName);
+ SetDlgItemTextW(hDlg, IDC_PPSGDISP, _currentEntry->lpConfig->lpDisplayName);
+ SetDlgItemTextW(hDlg, IDC_PPSGDESC, _currentEntry->szServiceDescription);
+ SetDlgItemTextW(hDlg, IDC_PPSGDEXE, _currentEntry->lpConfig->lpBinaryPathName);
+ __generalPropertyRefresh(hDlg);
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPSGCMBST:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 1);
+ }
+ break;
+ case IDC_PPSGDISP:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, 255);
+ if (!lstrcmpW(szBuf, _currentEntry->lpConfig->lpDisplayName)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 1);
+ }
+ else {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 1);
+ }
+ }
+ break;
+ case IDC_PPSGDESC:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, 1023);
+ if (!lstrcmpW(szBuf, _currentEntry->szServiceDescription)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 1);
+ }
+ else {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 1);
+ }
+ }
+ break;
+ case IDC_PPSGSTART:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSSTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __startServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ case IDC_PPSGSTOP:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSSTOP, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __stopServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ case IDC_PPSGPAUSE:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSPAUSE, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __pauseServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ case IDC_PPSGRESTART:
+ apxProgressBox(hDlg, apxLoadResource(IDS_HSRESTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __restartServiceCallback, NULL);
+ __generalPropertyRefresh(hDlg);
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalPropertySave(hDlg)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ }
+ else {
+ SET_BIT_FLAG(_propertyChanged, 1);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+LRESULT CALLBACK __logonProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ WCHAR szBuf[1024];
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ BOOL bAccount = FALSE;
+ startPage = 1;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+
+ SendMessage(GetDlgItem(hDlg, IDC_PPSLUSER), EM_LIMITTEXT, 63, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSLPASS), EM_LIMITTEXT, 63, 0);
+ SendMessage(GetDlgItem(hDlg, IDC_PPSLCPASS), EM_LIMITTEXT, 63, 0);
+ /* Check if we use LocalSystem or user defined account */
+ if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+ bAccount = TRUE;
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLUA);
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+ SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+ SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+ }
+ else {
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLLS);
+ if (_currentEntry->lpConfig->dwServiceType &
+ SERVICE_INTERACTIVE_PROCESS)
+ CheckDlgButton(hDlg, IDC_PPSLID, BST_CHECKED);
+ }
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), !bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), bAccount);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), bAccount);
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPSLLS:
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, L"");
+ SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
+ SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), FALSE);
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);
+ if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ else {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ break;
+ case IDC_PPSLUA:
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+ SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+ SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), TRUE);
+ CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);
+ if (lstrcmpW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ else {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ break;
+ case IDC_PPSLID:
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ break;
+ case IDC_PPSLUSER:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, 63);
+ if (!lstrcmpiW(szBuf, _currentEntry->szObjectName)) {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ else {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ }
+ break;
+ case IDC_PPSLPASS:
+ case IDC_PPSLCPASS:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ WCHAR szP[64];
+ WCHAR szC[64];
+ GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
+ GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+ /* check for valid password match */
+ if (szP[0] == L' ' && szC[0] == L' ') {
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ CLR_BIT_FLAG(_propertyChanged, 2);
+ }
+ else if (!lstrcmpW(szP, szC)) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 2);
+ }
+ }
+ break;
+ case IDC_PPSLBROWSE:
+ {
+ WCHAR szUser[SIZ_RESLEN];
+ if (apxDlgSelectUser(hDlg, szUser))
+ SetDlgItemTextW(hDlg, IDC_PPSLUSER, szUser);
+ }
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalLogonSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 2);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __loggingProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf;
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ LPWSTR b;
+ startPage = 2;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_ERROR);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_INFO);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_WARN);
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_DEBUG);
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"Level")) != NULL) {
+ if (!lstrcmpiW(b, LOGL_ERROR))
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
+ else if (!lstrcmpiW(b, LOGL_INFO))
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 1);
+ else if (!lstrcmpiW(b, LOGL_WARN))
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 2);
+ else
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 3);
+ apxFree(b);
+ }
+ else
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"Path")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPATH, b);
+ apxFree(b);
+ }
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"StdOutput")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);
+ apxFree(b);
+ }
+ if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_log, L"StdError")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, b);
+ apxFree(b);
+ }
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPLGLEVEL:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGPATH:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGPREFIX:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGSTDERR:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGSTDOUT:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGBPATH:
+ lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_LGPATHTITLE, 0),
+ NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPLGPATH, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGBSTDOUT:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDOUT, 0),
+ apxLoadResourceW(IDS_ALLFILES, 1), NULL,
+ NULL, FALSE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ case IDC_PPLGBSTDERR:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDERR, 0),
+ apxLoadResourceW(IDS_ALLFILES, 1), NULL,
+ NULL, FALSE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 3);
+ }
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalLoggingSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 3);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __jvmProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf, b;
+ DWORD v;
+ CHAR bn[32];
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ startPage = 3;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Jvm")) != NULL) {
+ if (!lstrcmpiW(lpBuf, L"auto")) {
+ CheckDlgButton(hDlg, IDC_PPJAUTO, BST_CHECKED);
+ apxFree(lpBuf);
+ lpBuf = apxGetJavaSoftRuntimeLib(hPool);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
+ }
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+ apxFree(lpBuf);
+ }
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Classpath")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"Options", NULL, NULL)) != NULL) {
+ LPWSTR p = apxMszToCRLFW(hPool, lpBuf);
+ SetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p);
+ apxFree(lpBuf);
+ apxFree(p);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"JvmMs");
+ if (v && v != 0xFFFFFFFF) {
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPJMS, bn);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"JvmMx");
+ if (v && v != 0xFFFFFFFF) {
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPJMX, bn);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_java, L"JvmSs");
+ if (v && v != 0xFFFFFFFF) {
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPJSS, bn);
+ }
+
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPJBJVM:
+ b = apxGetJavaSoftHome(hPool, TRUE);
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPJBJVM, 0),
+ apxLoadResourceW(IDS_DLLFILES, 1), NULL,
+ b,
+ TRUE, NULL);
+ apxFree(b);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 4);
+ }
+ break;
+ case IDC_PPJAUTO:
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 4);
+ if (IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
+ lpBuf = apxGetJavaSoftRuntimeLib(hPool);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+ apxFree(lpBuf);
+ }
+ }
+ else {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), TRUE);
+ }
+ break;
+ case IDC_PPJJVM:
+ case IDC_PPJCLASSPATH:
+ case IDC_PPJOPTIONS:
+ case IDC_PPJMX:
+ case IDC_PPJMS:
+ case IDC_PPJSS:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 4);
+ }
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalJvmSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 4);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __startProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf, b;
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ startPage = 4;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"jvm");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), _s_java);
+
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Class")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRCLASS, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Image")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"WorkingPath")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Method")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPRMETHOD, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Params", NULL, NULL)) != NULL) {
+ b = apxMszToCRLFW(hPool, lpBuf);
+ SetDlgItemTextW(hDlg, IDC_PPRARGS, b);
+ apxFree(lpBuf);
+ apxFree(b);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_start, L"Mode")) != NULL) {
+ if (!lstrcmpiW(lpBuf, L"jvm")) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 1);
+
+ }
+ else if (!lstrcmpiW(lpBuf, _s_java)) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 2);
+ }
+ else {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 0);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
+ }
+ apxFree(lpBuf);
+ }
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPRBWPATH:
+ lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
+ NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ }
+ break;
+ case IDC_PPRBIMAGE:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
+ apxLoadResourceW(IDS_EXEFILES, 1), NULL,
+ NULL, TRUE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ }
+ break;
+ case IDC_PPRCLASS:
+ case IDC_PPRMETHOD:
+ case IDC_PPRARGS:
+ case IDC_PPRIMAGE:
+ case IDC_PPRWPATH:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ }
+ break;
+ case IDC_PPRMODE:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 5);
+ if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPRMODE))) {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), FALSE);
+ }
+ else {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
+ }
+ }
+ break;
+
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalStartSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 5);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+LRESULT CALLBACK __stopProperty(HWND hDlg,
+ UINT uMessage,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ LPPSHNOTIFY lpShn;
+ LPWSTR lpBuf, b;
+ DWORD v;
+
+ switch (uMessage) {
+ case WM_INITDIALOG:
+ {
+ startPage = 5;
+ if (!bpropCentered)
+ apxCenterWindow(GetParent(hDlg), NULL);
+ bpropCentered = TRUE;
+
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"jvm");
+ ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), _s_java);
+
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Class")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSCLASS, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Image")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"WorkingPath")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Method")) != NULL) {
+ SetDlgItemTextW(hDlg, IDC_PPSMETHOD, lpBuf);
+ apxFree(lpBuf);
+ }
+ if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Params", NULL, NULL)) != NULL) {
+ b = apxMszToCRLFW(hPool, lpBuf);
+ SetDlgItemTextW(hDlg, IDC_PPSARGS, b);
+ apxFree(lpBuf);
+ apxFree(b);
+ }
+ v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Timeout");
+ {
+ CHAR bn[32];
+ wsprintfA(bn, "%d", v);
+ SetDlgItemTextA(hDlg, IDC_PPSTIMEOUT, bn);
+ }
+ if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+ _s_stop, L"Mode")) != NULL) {
+ if (!lstrcmpiW(lpBuf, L"jvm")) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 1);
+
+ }
+ else if (!lstrcmpiW(lpBuf, _s_java)) {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 2);
+ }
+ else {
+ ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 0);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
+ }
+ apxFree(lpBuf);
+ }
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_PPSBWPATH:
+ lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
+ NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ }
+ break;
+ case IDC_PPSBIMAGE:
+ lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
+ apxLoadResourceW(IDS_EXEFILES, 1), NULL,
+ NULL, TRUE, NULL);
+ if (lpBuf) {
+ SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
+ apxFree(lpBuf);
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ }
+ break;
+ case IDC_PPSCLASS:
+ case IDC_PPSMETHOD:
+ case IDC_PPSTIMEOUT:
+ case IDC_PPSARGS:
+ case IDC_PPSIMAGE:
+ case IDC_PPSWPATH:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ }
+ break;
+ case IDC_PPSMODE:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ PropSheet_Changed(GetParent(hDlg), hDlg);
+ SET_BIT_FLAG(_propertyChanged, 6);
+ if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSMODE))) {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), FALSE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), FALSE);
+ }
+ else {
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
+ EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
+ }
+ }
+ break;
+
+ }
+ break;
+ case WM_NOTIFY:
+ lpShn = (LPPSHNOTIFY )lParam;
+ switch (lpShn->hdr.code) {
+ case PSN_APPLY: /* sent when OK or Apply button pressed */
+ if (__generalStopSave(hDlg))
+ PropSheet_UnChanged(GetParent(hDlg), hDlg);
+ else {
+ SET_BIT_FLAG(_propertyChanged, 6);
+ SetWindowLong(hDlg, DWLP_MSGRESULT,
+ PSNRET_INVALID_NOCHANGEPAGE);
+ return TRUE;
+ }
+
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+void __initPpage(PROPSHEETPAGEW *lpPage, INT iDlg, INT iTitle, DLGPROC pfnDlgProc)
+{
+ lpPage->dwSize = sizeof(PROPSHEETPAGE);
+ lpPage->dwFlags = PSP_USETITLE;
+ lpPage->hInstance = _gui_store->hInstance;
+ lpPage->pszTemplate = MAKEINTRESOURCEW(iDlg);
+ lpPage->pszIcon = NULL;
+ lpPage->pfnDlgProc = pfnDlgProc;
+ lpPage->pszTitle = MAKEINTRESOURCEW(iTitle);
+ lpPage->lParam = 0;
+}
+
+void ShowServiceProperties(HWND hWnd)
+{
+ PROPSHEETPAGEW psP[6];
+ PROPSHEETHEADERW psH;
+ WCHAR szT[1024] = {0};
+
+ if (_propertyOpened) {
+ SetForegroundWindow(_gui_store->hMainWnd);
+ return;
+ }
+ __initPpage(&psP[0], IDD_PROPPAGE_SGENERAL, IDS_PPGENERAL,
+ __generalProperty);
+ __initPpage(&psP[1], IDD_PROPPAGE_LOGON, IDS_PPLOGON,
+ __logonProperty);
+ __initPpage(&psP[2], IDD_PROPPAGE_LOGGING, IDS_PPLOGGING,
+ __loggingProperty);
+ __initPpage(&psP[3], IDD_PROPPAGE_JVM, IDS_PPJAVAVM,
+ __jvmProperty);
+ __initPpage(&psP[4], IDD_PROPPAGE_START, IDS_PPSTART,
+ __startProperty);
+ __initPpage(&psP[5], IDD_PROPPAGE_STOP, IDS_PPSTOP,
+ __stopProperty);
+
+ if (_currentEntry && _currentEntry->lpConfig)
+ lstrcpyW(szT, _currentEntry->lpConfig->lpDisplayName);
+ else
+ return;
+ lstrcatW(szT, L" Properties");
+
+ psH.dwSize = sizeof(PROPSHEETHEADER);
+ psH.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
+ psH.hwndParent = bEnableTry ? hWnd : NULL;
+ psH.hInstance = _gui_store->hInstance;
+ psH.pszIcon = MAKEINTRESOURCEW(IDI_MAINICON);
+ psH.pszCaption = szT;
+ psH.nPages = 6;
+ psH.ppsp = (LPCPROPSHEETPAGEW) &psP;
+ psH.pfnCallback = (PFNPROPSHEETCALLBACK)__propertyCallback;
+ psH.nStartPage = startPage;
+
+ PropertySheetW(&psH);
+ _propertyOpened = FALSE;
+ if (!bEnableTry)
+ PostQuitMessage(0);
+ bpropCentered = FALSE;
+
+}
+
+static void signalService(LPCWSTR szServiceName)
+{
+ HANDLE event;
+ WCHAR en[SIZ_DESLEN];
+ int i;
+ lstrcpyW(en, szServiceName);
+ lstrcatW(en, L"SIGNAL");
+ for (i = 0; i < lstrlenW(en); i++) {
+ if (en[i] >= L'a' && en[i] <= L'z')
+ en[i] = en[i] - 32;
+ }
+
+
+ event = OpenEventW(EVENT_MODIFY_STATE, FALSE, en);
+ if (event) {
+ SetEvent(event);
+ CloseHandle(event);
+ }
+ else
+ apxDisplayError(TRUE, NULL, 0, "Unable to open the Event Mutex");
+
+}
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
+ case WM_CREATE:
+ if (bEnableTry) {
+ if (_currentEntry && _currentEntry->lpConfig) {
+ BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
+ apxManageTryIconW(hWnd, NIM_ADD, NULL,
+ _currentEntry->lpConfig->lpDisplayName,
+ isRunning ? hIcoRun : hIcoStop);
+ }
+ else {
+ apxManageTryIconA(hWnd, NIM_ADD, NULL,
+ apxLoadResourceA(IDS_APPLICATION, 0),
+ NULL);
+ }
+ }
+ else
+ ShowServiceProperties(hWnd);
+
+ break;
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDM_TM_CONFIG:
+ ShowServiceProperties(hWnd);
+ break;
+ case IDM_TM_ABOUT:
+ apxAboutBox(hWnd);
+ break;
+ case IDM_TM_EXIT:
+ SendMessage(hWnd, WM_CLOSE, 0, 0);
+ break;
+ case IDM_TM_START:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSSTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __startServiceCallback, NULL);
+ break;
+ case IDM_TM_STOP:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSSTOP, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __stopServiceCallback, NULL);
+ break;
+ case IDM_TM_PAUSE:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSPAUSE, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __pauseServiceCallback, NULL);
+ break;
+ case IDM_TM_RESTART:
+ if (!_propertyOpened)
+ apxProgressBox(hWnd, apxLoadResource(IDS_HSRESTART, 0),
+ _currentEntry->lpConfig->lpDisplayName,
+ __restartServiceCallback, NULL);
+ break;
+ case IDM_TM_DUMP:
+ signalService(_currentEntry->szServiceName);
+ break;
+ case IDMS_REFRESH:
+ if (bEnableTry &&
+ (_currentEntry = apxServiceEntry(hService, TRUE)) != NULL) {
+ BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
+ apxManageTryIconW(hWnd, NIM_MODIFY, NULL,
+ _currentEntry->lpConfig->lpDisplayName,
+ isRunning ? hIcoRun : hIcoStop);
+ }
+ break;
+
+ }
+ break;
+ case WM_TRAYMESSAGE:
+ switch(lParam) {
+ case WM_LBUTTONDBLCLK:
+ ShowServiceProperties(hWnd);
+ break;
+ case WM_RBUTTONUP:
+ _currentEntry = apxServiceEntry(hService, TRUE);
+ createRbuttonTryMenu(hWnd);
+ break;
+ }
+ break;
+ case WM_QUIT:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ break;
+ case WM_DESTROY:
+ if (bEnableTry)
+ apxManageTryIconA(hWnd, NIM_DELETE, NULL, NULL, NULL);
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ break;
+ }
+
+ return FALSE;
+}
+
+static BOOL loadConfiguration()
+{
+ return TRUE;
+}
+
+static BOOL saveConfiguration()
+{
+ return TRUE;
+}
+
+/* Main program entry
+ * Since we are inependant from CRT
+ * the arguments are not used
+ */
+#ifdef _NO_CRTLIBRARY
+int xMain(void)
+#else
+int WINAPI WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
+#endif
+{
+ MSG msg;
+ LPAPXCMDLINE lpCmdline;
+ HANDLE mutex = NULL;
+ BOOL quiet = FALSE;
+
+ apxHandleManagerInitialize();
+ hPool = apxPoolCreate(NULL, 0);
+
+ /* Parse the command line */
+ if ((lpCmdline = apxCmdlineParse(hPool, _options, _commands)) == NULL) {
+ /* TODO: dispalay error message */
+ apxDisplayError(TRUE, NULL, 0, "Error parsing command line");
+ goto cleanup;
+ }
+
+ if (!lpCmdline->dwCmdIndex) {
+ /* Skip sytem error message */
+ SetLastError(ERROR_SUCCESS);
+ apxDisplayError(TRUE, NULL, 0,
+ apxLoadResourceA(IDS_ERRORCMD, 0),
+ lpCmdLine);
+ goto cleanup;
+ }
+ else if (lpCmdline->dwCmdIndex == 4)
+ quiet = TRUE;
+ else if (lpCmdline->dwCmdIndex >= 2)
+ bEnableTry = TRUE;
+ hService = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to open the Service Manager");
+ goto cleanup;
+ }
+ /* Open the main service handle */
+ if (!apxServiceOpen(hService, lpCmdline->szApplication,
+ SERVICE_ALL_ACCESS)) {
+ LPWSTR w = lpCmdline->szApplication + lstrlenW(lpCmdline->szApplication) - 1;
+ if (*w == L'w')
+ *w = L'\0';
+ if (!apxServiceOpen(hService, lpCmdline->szApplication,
+ SERVICE_ALL_ACCESS)) {
+ if (!apxServiceOpen(hService, lpCmdline->szApplication,
+ GENERIC_READ | GENERIC_EXECUTE)) {
+
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to open the service '%S'",
+ lpCmdline->szApplication);
+ goto cleanup;
+ }
+ }
+ }
+ /* Obtain service parameters and status */
+ if (!(_currentEntry = apxServiceEntry(hService, TRUE))) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to query the service '%S' status",
+ lpCmdline->szApplication);
+ goto cleanup;
+ }
+#ifdef _UNICODE
+ _gui_store = apxGuiInitialize(MainWndProc, lpCmdline->szApplication);
+#else
+ {
+ CHAR szApp[MAX_PATH];
+ _gui_store = apxGuiInitialize(MainWndProc,
+ WideToAscii(lpCmdline->szApplication, szApp));
+ }
+#endif
+ if (!_gui_store) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, "Unable to initialize GUI manager");
+ goto cleanup;
+ }
+ hIcoRun = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONRUN),
+ IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ hIcoStop = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONSTOP),
+ IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+
+ /* Handle //MQ// option */
+ if (lpCmdline->dwCmdIndex == 4) {
+ HANDLE hOther = FindWindow(_gui_store->szWndClass, NULL);
+ if (hOther)
+ SendMessage(hOther, WM_CLOSE, 0, 0);
+ goto cleanup;
+ }
+
+ if (!_options[0].dwValue) {
+ mutex = CreateMutex(NULL, FALSE, _gui_store->szWndMutex);
+ if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
+ /* Skip sytem error message */
+ SetLastError(ERROR_SUCCESS);
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ALREAY_RUNING, 0),
+ lpCmdline->szApplication);
+ goto cleanup;
+ }
+ }
+ hRegistry = apxCreateRegistry(hPool, KEY_ALL_ACCESS, NULL,
+ apxLoadResource(IDS_APPLICATION, 0),
+ APXREG_USER);
+ loadConfiguration();
+ hRegserv = apxCreateRegistryW(hPool, KEY_READ | KEY_WRITE, PRG_REGROOT,
+ lpCmdline->szApplication,
+ APXREG_SOFTWARE | APXREG_SERVICE);
+
+ if (IS_INVALID_HANDLE(hRegserv)) {
+ if (!quiet)
+ apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ERRSREG, 0));
+ return FALSE;
+ }
+ /* Create main invisible window */
+ _gui_store->hMainWnd = CreateWindow(_gui_store->szWndClass,
+ apxLoadResource(IDS_APPLICATION, 0),
+ 0, 0, 0, 0, 0,
+ NULL, NULL,
+ _gui_store->hInstance,
+ NULL);
+
+ if (!_gui_store->hMainWnd) {
+ goto cleanup;
+ }
+ if (lpCmdline->dwCmdIndex == 3)
+ PostMessage(_gui_store->hMainWnd, WM_COMMAND, IDM_TM_START, 0);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ if(!TranslateAccelerator(_gui_store->hMainWnd,
+ _gui_store->hAccel, &msg)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ saveConfiguration();
+
+cleanup:
+ if (hIcoStop)
+ DestroyIcon(hIcoStop);
+ if (hIcoRun)
+ DestroyIcon(hIcoRun);
+ if (mutex)
+ CloseHandle(mutex);
+ if (lpCmdline)
+ apxCmdlineFree(lpCmdline);
+ apxCloseHandle(hService);
+ apxHandleManagerDestroy();
+ ExitProcess(0);
+ return 0;
+}
+
Property changes on: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,140 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ *
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+#ifndef _PRUNMGR_H
+#define _PRUNMGR_H
+
+#undef PRG_VERSION
+#define PRG_VERSION "2.0.3.0"
+#define PRG_REGROOT L"JBoss\\JBoss Web 2"
+
+#define IDM_TM_EXIT 2000
+#define IDM_TM_START 2001
+#define IDM_TM_STOP 2002
+#define IDM_TM_PAUSE 2003
+#define IDM_TM_RESTART 2004
+#define IDM_TM_CONFIG 2005
+#define IDM_TM_ABOUT 2006
+#define IDM_TM_DUMP 2007
+
+#define IDMS_REFRESH 2020
+
+#define IDI_ICONSTOP 2030
+#define IDI_ICONRUN 2031
+
+
+
+/* Property pages */
+
+#define IDD_PROPPAGE_SGENERAL 2600
+#define IDC_PPSGNAME 2601
+#define IDC_PPSGDISP 2602
+#define IDC_PPSGDESC 2603
+#define IDC_PPSGDEXE 2604
+#define IDC_PPSGCMBST 2605
+#define IDC_PPSGSTATUS 2606
+#define IDC_PPSGSTART 2607
+#define IDC_PPSGSTOP 2608
+#define IDC_PPSGPAUSE 2609
+#define IDC_PPSGRESTART 2610
+
+#define IDD_PROPPAGE_LOGON 2620
+#define IDC_PPSLLS 2621
+#define IDC_PPSLID 2622
+#define IDC_PPSLUA 2623
+#define IDC_PPSLUSER 2624
+#define IDC_PPSLBROWSE 2625
+#define IDC_PPSLPASS 2626
+#define IDC_PPSLCPASS 2627
+#define IDL_PPSLPASS 2628
+#define IDL_PPSLCPASS 2629
+
+#define IDD_PROPPAGE_LOGGING 2640
+#define IDC_PPLGLEVEL 2641
+#define IDC_PPLGPATH 2642
+#define IDC_PPLGBPATH 2643
+#define IDC_PPLGPREFIX 2644
+#define IDC_PPLGSTDOUT 2645
+#define IDC_PPLGBSTDOUT 2646
+#define IDC_PPLGSTDERR 2647
+#define IDC_PPLGBSTDERR 2648
+
+#define IDD_PROPPAGE_JVM 2660
+#define IDC_PPJAUTO 2661
+#define IDC_PPJJVM 2662
+#define IDC_PPJBJVM 2663
+#define IDC_PPJCLASSPATH 2664
+#define IDC_PPJOPTIONS 2665
+#define IDC_PPJMS 2666
+#define IDC_PPJMX 2667
+#define IDC_PPJSS 2668
+
+#define IDD_PROPPAGE_START 2680
+#define IDC_PPRCLASS 2681
+#define IDC_PPRIMAGE 2682
+#define IDC_PPRBIMAGE 2683
+#define IDC_PPRWPATH 2684
+#define IDC_PPRBWPATH 2685
+#define IDC_PPRMETHOD 2686
+#define IDC_PPRARGS 2687
+#define IDC_PPRTIMEOUT 2688
+#define IDC_PPRMODE 2689
+
+#define IDD_PROPPAGE_STOP 2700
+#define IDC_PPSCLASS 2701
+#define IDC_PPSIMAGE 2702
+#define IDC_PPSBIMAGE 2703
+#define IDC_PPSWPATH 2704
+#define IDC_PPSBWPATH 2705
+#define IDC_PPSMETHOD 2706
+#define IDC_PPSARGS 2707
+#define IDC_PPSTIMEOUT 2708
+#define IDC_PPSMODE 2709
+
+#define IDS_ALREAY_RUNING 3100
+#define IDS_ERRORCMD 3101
+#define IDS_HSSTART 3102
+#define IDS_HSSTOP 3103
+#define IDS_HSPAUSE 3104
+#define IDS_HSRESTART 3105
+#define IDS_VALIDPASS 3106
+#define IDS_PPGENERAL 3107
+#define IDS_PPLOGON 3108
+#define IDS_PPLOGGING 3109
+#define IDS_PPJAVAVM 3110
+#define IDS_PPSTART 3111
+#define IDS_PPSTOP 3112
+#define IDS_LGPATHTITLE 3113
+#define IDS_ALLFILES 3114
+#define IDS_DLLFILES 3115
+#define IDS_EXEFILES 3116
+#define IDS_LGSTDERR 3117
+#define IDS_LGSTDOUT 3118
+#define IDS_PPJBJVM 3119
+#define IDS_PPWPATH 3120
+#define IDS_PPIMAGE 3121
+#define IDS_ERRSREG 3122
+
+#define IDS_NOTIMPLEMENTED 3199
+
+#endif /* _PRUNMGR_H */
Property changes on: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.manifest
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.manifest (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.manifest 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+<assemblyIdentity version="2.0.1.0" processorArchitecture="X86" name="JBoss.Web.Service" type="win32" />
+<description>JBoss Web Service Manager</description>
+<dependency>
+<dependentAssembly>
+<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" />
+</dependentAssembly>
+</dependency>
+</assembly>
Property changes on: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.manifest
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunmgr/prunmgr.rc 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,297 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "prunmgr.h"
+
+#define RSTR_SCMATS "Service Manager is attempting to "
+
+#define STR_COPYRIGHT "Copyright � 2008 Red Hat Middleware, LLC. " \
+ "or its licensors, as applicable."
+
+#define STR_LICENSE "Distributable under LGPL license. " \
+ "See terms of license at gnu.org."
+
+#define STR_COMPANY "Red Hat�, Inc."
+#define STR_TRADEMARK "� Red Hat Inc."
+#define STR_PRODUCT "JBoss Web Service manager"
+
+IDI_MAINICON ICON "../../resources/jboss.ico"
+IDI_ICONSTOP ICON "../../resources/procruns.ico"
+IDI_ICONRUN ICON "../../resources/procrunr.ico"
+IDR_LICENSE RTF "../../resources/license.rtf"
+BMP_JBOSSLOGO BITMAP "../../resources/jbosslogo.bmp"
+
+#ifdef USE_MANIFEST
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "prunmgr.manifest"
+#endif
+
+IDD_ABOUTBOX DIALOGEX 0, 0, 337, 187
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "JBoss Web Service Manager"
+FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+ DEFPUSHBUTTON "&OK",IDOK,285,150,50,14
+ CONTROL "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE |
+ ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
+ CONTROL "BMP_JBOSSLOGO",IDC_STATIC,"Static",SS_BITMAP|0x00000040L,0,0,337,30
+ LTEXT " ",IDC_ABOUTAPP,2,150,270,12
+ LTEXT "Copyright � 2008 Red Hat Middleware, LLC.",IDC_STATIC,2,160,270,12
+ LTEXT "http://www.jboss.org",IDC_STATIC,2,170,270,12
+ PUSHBUTTON "&System Info",IAB_SYSINF,285,170,50,14
+END
+
+IDD_PROGRESS DIALOGEX 0, 0, 322, 92
+STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP |
+ WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_TOPMOST
+CAPTION "JBoss Web Service Manager"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "Cl&ose",IDOK,261,73,50,14
+ PUSHBUTTON "&Cancel",IDCANCEL,202,73,50,14
+ LTEXT " ",
+ IDDP_HEAD,40,4,250,8
+ LTEXT " ",IDDP_TEXT,40,15,250,44
+ CONTROL "",IDDP_PROGRESS,"msctls_progress32",WS_BORDER,10,50,302,
+ 14
+ ICON IDI_MAINICON,IDC_STATIC,10,4,20,20,0,WS_EX_TRANSPARENT
+END
+
+IDD_SELUSER DIALOGEX 0, 0, 410, 201
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
+ WS_THICKFRAME
+EXSTYLE WS_EX_CONTEXTHELP
+CAPTION "Select User"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "Name:",IDSU_SELNAME,10,183,22,8
+ EDITTEXT IDSU_SELECTED,48,200,213,14,ES_AUTOHSCROLL
+ DEFPUSHBUTTON "OK",IDOK,292,180,50,14,WS_DISABLED
+ PUSHBUTTON "Cancel",IDCANCEL,348,180,50,14
+ LTEXT "Look In:",IDC_STATIC,10,9,27,8
+ CONTROL "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL |
+ LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER |
+ WS_TABSTOP,0,26,410,149,WS_EX_CLIENTEDGE
+ CONTROL "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST |
+ WS_VSCROLL | WS_TABSTOP,47,6,260,80
+END
+
+IDD_PROPPAGE_SGENERAL DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "Service Name: ",IDC_STATIC,10,8,52,8
+ LTEXT " ",IDC_PPSGNAME,70,8,240,8
+ LTEXT "Display &name: ",IDC_STATIC,10,23,50,8
+ EDITTEXT IDC_PPSGDISP,70,22,180,12,ES_AUTOHSCROLL
+ LTEXT "&Description: ",IDC_STATIC,10,41,43,8
+ EDITTEXT IDC_PPSGDESC,70,40,180,12,ES_AUTOHSCROLL
+ LTEXT "Pat&h to executable:",IDC_STATIC,10,63,66,8
+ EDITTEXT IDC_PPSGDEXE,10,75,240,12,ES_AUTOHSCROLL | WS_DISABLED
+ LTEXT "Startup typ&e:",IDC_STATIC,10,94,46,8
+ COMBOBOX IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+ CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1
+ LTEXT "Service Status:",IDC_STATIC,10,138,52,8
+ LTEXT " ",IDC_PPSGSTATUS,70,138,240,8
+ PUSHBUTTON "&Start",IDC_PPSGSTART,10,160,55,14,WS_DISABLED
+ PUSHBUTTON "S&top",IDC_PPSGSTOP,71,160,55,14,WS_DISABLED
+ PUSHBUTTON "&Pause",IDC_PPSGPAUSE,132,160,55,14,WS_DISABLED
+ PUSHBUTTON "&Restart",IDC_PPSGRESTART,193,160,55,14,WS_DISABLED
+END
+
+IDD_PROPPAGE_LOGON DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "Log on as:",IDC_STATIC,10,8,51,8
+ CONTROL "&Local System account",IDC_PPSLLS,"Button",
+ BS_AUTORADIOBUTTON,10,23,85,10
+ CONTROL "Allo&w service to interact with desktop",IDC_PPSLID,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,37,135,10
+ CONTROL "&This account:",IDC_PPSLUA,"Button",BS_AUTORADIOBUTTON,
+ 10,59,61,10
+ EDITTEXT IDC_PPSLUSER,86,58,114,12,ES_AUTOHSCROLL
+ PUSHBUTTON "&Browse...",IDC_PPSLBROWSE,205,57,50,14
+ LTEXT "&Password:",IDL_PPSLPASS,21,76,36,8
+ EDITTEXT IDC_PPSLPASS,86,75,114,12,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "&Confirm Password:",IDL_PPSLCPASS,20,93,63,8
+ EDITTEXT IDC_PPSLCPASS,86,92,114,12,ES_PASSWORD | ES_AUTOHSCROLL
+END
+
+IDD_PROPPAGE_LOGGING DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "&Level:",IDC_STATIC,10,18,46,8
+ COMBOBOX IDC_PPLGLEVEL,70,17,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+ LTEXT "Log &path: ",IDC_STATIC,10,33,50,8
+ EDITTEXT IDC_PPLGPATH,10,45,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBPATH,232,44,18,14
+ LTEXT "Log prefix: ",IDC_STATIC,10,63,50,8
+ EDITTEXT IDC_PPLGPREFIX,70,62,158,12,ES_AUTOHSCROLL
+
+ LTEXT "Redirect Stdout: ",IDC_STATIC,10,85,80,8
+ EDITTEXT IDC_PPLGSTDOUT,10,97,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBSTDOUT,232,96,18,14
+ LTEXT "Redirect Stderror: ",IDC_STATIC,10,115,80,8
+ EDITTEXT IDC_PPLGSTDERR,10,127,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPLGBSTDERR,232,126,18,14
+END
+
+IDD_PROPPAGE_JVM DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ CONTROL " Use default",IDC_PPJAUTO,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,10,8,72,12
+ LTEXT "Java Virtual Machine: ",IDC_STATIC,10,23,80,8
+ EDITTEXT IDC_PPJJVM,10,35,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPJBJVM,232,34,18,14
+ LTEXT "Java Classpath:",IDC_STATIC,10,53,66,8
+ EDITTEXT IDC_PPJCLASSPATH,10,65,240,12,ES_AUTOHSCROLL
+ LTEXT "Java Options:",IDC_STATIC,10,83,66,8
+ EDITTEXT IDC_PPJOPTIONS,10,95,240,40,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_WANTRETURN | WS_VSCROLL
+ LTEXT "Initial memory pool:",IDC_STATIC,10,140,80,8
+ EDITTEXT IDC_PPJMS,90,139,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "MB",IDC_STATIC,195,140,25,8
+ LTEXT "Maximum memory pool:",IDC_STATIC,10,156,80,8
+ EDITTEXT IDC_PPJMX,90,155,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "MB",IDC_STATIC,195,156,25,8
+ LTEXT "Thread stack size:",IDC_STATIC,10,172,80,8
+ EDITTEXT IDC_PPJSS,90,171,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "KB",IDC_STATIC,195,172,25,8
+END
+
+IDD_PROPPAGE_START DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "&Class: ",IDC_STATIC,10,8,50,8
+ EDITTEXT IDC_PPRCLASS,10,20,240,12,ES_AUTOHSCROLL
+ LTEXT "Image: ",IDC_STATIC,10,38,80,8
+ EDITTEXT IDC_PPRIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
+ PUSHBUTTON "...",IDC_PPRBIMAGE,232,49,18,14,WS_DISABLED
+ LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
+ EDITTEXT IDC_PPRWPATH,10,80,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPRBWPATH,232,79,18,14
+ LTEXT "&Method: ",IDC_STATIC,10,98,50,8
+ EDITTEXT IDC_PPRMETHOD,70,97,180,12,ES_AUTOHSCROLL
+ LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
+ EDITTEXT IDC_PPRARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_WANTRETURN | WS_VSCROLL
+ LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
+ EDITTEXT IDC_PPRTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | WS_DISABLED
+ LTEXT "sec.",IDC_STATIC,175,150,25,8
+ LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
+ COMBOBOX IDC_PPRMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+END
+
+IDD_PROPPAGE_STOP DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "&Class: ",IDC_STATIC,10,8,50,8
+ EDITTEXT IDC_PPSCLASS,10,20,240,12,ES_AUTOHSCROLL
+ LTEXT "Image: ",IDC_STATIC,10,38,80,8
+ EDITTEXT IDC_PPSIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
+ PUSHBUTTON "...",IDC_PPSBIMAGE,232,49,18,14,WS_DISABLED
+ LTEXT "Working Path: ",IDC_STATIC,10,68,80,8
+ EDITTEXT IDC_PPSWPATH,10,80,218,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_PPSBWPATH,232,79,18,14
+ LTEXT "&Method: ",IDC_STATIC,10,98,50,8
+ EDITTEXT IDC_PPSMETHOD,70,97,180,12,ES_AUTOHSCROLL
+ LTEXT "&Arguments: ",IDC_STATIC,10,115,50,8
+ EDITTEXT IDC_PPSARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_WANTRETURN | WS_VSCROLL
+ LTEXT "&Timeout: ",IDC_STATIC,10,150,50,8
+ EDITTEXT IDC_PPSTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "sec.",IDC_STATIC,175,150,25,8
+ LTEXT "&Mode: ",IDC_STATIC,10,168,50,8
+ COMBOBOX IDC_PPSMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL |
+ WS_TABSTOP
+END
+
+STRINGTABLE
+BEGIN
+ IDS_APPLICATION STR_PRODUCT
+ IDS_APPVERSION "Version 2.0.3"
+ IDS_APPFULLNAME STR_PRODUCT " Version " PRG_VERSION
+ IDS_APPCOPYRIGHT "Copyright � 2008 Red Hat Middleware, LLC."
+ IDS_APPDESCRIPTION "JBoss Web Service Management Tool"
+ IDS_ALREAY_RUNING "An instance of '%S' application is already running"
+ IDS_ERRORCMD "Unknown command line option '%s'\nSee the manual for command line usage."
+ IDS_HSSTART RSTR_SCMATS "start the following service ..."
+ IDS_HSSTOP RSTR_SCMATS "stop the following service ..."
+ IDS_HSRESTART RSTR_SCMATS "to restart the following service ..."
+ IDS_HSPAUSE RSTR_SCMATS "to pause the following service ..."
+ IDS_VALIDPASS "Please enter a valid password"
+ IDS_PPGENERAL "General"
+ IDS_PPLOGON "Log On"
+ IDS_PPLOGGING "Logging"
+ IDS_PPJAVAVM "Java"
+ IDS_PPSTART "Startup"
+ IDS_PPSTOP "Shutdown"
+ IDS_NOTIMPLEMENTED "Sorry, but this feature is not implemented yet"
+ IDS_LGPATHTITLE "Select Log root folder"
+ IDS_ALLFILES "All Files (*.*)\0*.*\0"
+ IDS_DLLFILES "Dynamic Link Libraries (*.dll)\0*.dll\0"
+ IDS_EXEFILES "Executables (*.exe)\0*.exe\0"
+ IDS_LGSTDOUT "Select Stdoutput filename"
+ IDS_LGSTDERR "Select Stderror filename"
+ IDS_PPJBJVM "Select Java Virtual Machine DLL"
+ IDS_PPWPATH "Select Working path"
+ IDS_PPIMAGE "Select Executable Image"
+ IDS_ERRSREG "Unable to open the service registry key"
+END
+
+1 VERSIONINFO
+ FILEVERSION 2,0,3,0
+ PRODUCTVERSION 2,0,3,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", STR_COPYRIGHT "\0"
+ VALUE "CompanyName", STR_COMPANY "\0"
+ VALUE "FileDescription", STR_PRODUCT "\0"
+ VALUE "FileVersion", PRG_VERSION
+ VALUE "InternalName", STR_PRODUCT "\0"
+ VALUE "LegalCopyright", STR_COPYRIGHT "\0"
+ VALUE "OriginalFilename", "jbosswebw.exe\0"
+ VALUE "ProductName", STR_PRODUCT "\0"
+ VALUE "ProductVersion", PRG_VERSION
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
Added: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,1390 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ * prunsrv -- Service Runner.
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI 1
+#include "apxwin.h"
+#include "prunsrv.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <io.h> /* _open_osfhandle */
+
+#ifndef MIN
+#define MIN(a,b) (((a)<(b)) ? (a) : (b))
+#endif
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+typedef struct APX_STDWRAP {
+ LPCWSTR szLogPath;
+ LPCWSTR szStdOutFilename;
+ LPCWSTR szStdErrFilename;
+ HANDLE hStdOutFile;
+ HANDLE hStdErrFile;
+ FILE *fpStdOutFile;
+ FILE *fpStdErrFile;
+ FILE fpStdOutSave;
+ FILE fpStdErrSave;
+} APX_STDWRAP;
+
+/* Use static variables instead of #defines */
+static LPCWSTR PRSRV_AUTO = L"auto";
+static LPCWSTR PRSRV_JAVA = L"java";
+static LPCWSTR PRSRV_JVM = L"jvm";
+static LPCWSTR PRSRV_MANUAL = L"manual";
+static LPCWSTR PRSRV_JBIN = L"\\bin\\java.exe";
+static LPCWSTR PRSRV_SIGNAL = L"SIGNAL";
+
+static LPCWSTR STYPE_INTERACTIVE = L"interactive";
+
+static LPWSTR _service_name = NULL;
+/* Allowed procrun commands */
+static LPCWSTR _commands[] = {
+ L"TS", /* 1 Run Service as console application (default)*/
+ L"RS", /* 2 Run Service */
+ L"SS", /* 3 Stop Service */
+ L"US", /* 4 Update Service parameters */
+ L"IS", /* 5 Install Service */
+ L"DS", /* 6 Delete Service */
+ NULL
+};
+
+/* Allowed procrun parameters */
+static APXCMDLINEOPT _options[] = {
+
+/* 0 */ { L"Description", L"Description", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 1 */ { L"DisplayName", L"DisplayName", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 2 */ { L"Install", L"ImagePath", NULL, APXCMDOPT_STE | APXCMDOPT_SRV, NULL, 0},
+/* 3 */ { L"ServiceUser", L"ServiceUser", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 4 */ { L"ServicePassword", L"ServicePassword", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 5 */ { L"Startup", L"Startup", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 6 */ { L"Type", L"Type", NULL, APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+
+/* 7 */ { L"DependsOn", L"DependsOn", NULL, APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 8 */ { L"Environment", L"Environment", NULL, APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 9 */ { L"User", L"User", NULL, APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 10 */ { L"Password", L"Password", NULL, APXCMDOPT_BIN | APXCMDOPT_REG, NULL, 0},
+
+/* 11 */ { L"JavaHome", L"JavaHome", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 12 */ { L"Jvm", L"Jvm", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 13 */ { L"JvmOptions", L"Options", L"Java", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 14 */ { L"Classpath", L"Classpath", L"Java", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 15 */ { L"JvmMs", L"JvmMs", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+/* 16 */ { L"JvmMx", L"JvmMx", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+/* 17 */ { L"JvmSs", L"JvmSs", L"Java", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+
+/* 18 */ { L"StopImage", L"Image", L"Stop", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 19 */ { L"StopPath", L"WorkingPath", L"Stop", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 20 */ { L"StopClass", L"Class", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 21 */ { L"StopParams", L"Params", L"Stop", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 22 */ { L"StopMethod", L"Method", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 23 */ { L"StopMode", L"Mode", L"Stop", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 24 */ { L"StopTimeout", L"Timeout", L"Stop", APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+
+/* 25 */ { L"StartImage", L"Image", L"Start", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 26 */ { L"StartPath", L"WorkingPath", L"Start", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 27 */ { L"StartClass", L"Class", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 28 */ { L"StartParams", L"Params", L"Start", APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 29 */ { L"StartMethod", L"Method", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 30 */ { L"StartMode", L"Mode", L"Start", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+
+/* 31 */ { L"LogPath", L"Path", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 32 */ { L"LogPrefix", L"Prefix", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 33 */ { L"LogLevel", L"Level", L"Log", APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 34 */ { L"StdError", L"StdError", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 35 */ { L"StdOutput", L"StdOutput", L"Log", APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+ /* NULL terminate the array */
+ { NULL }
+};
+
+#define GET_OPT_V(x) _options[x].szValue
+#define GET_OPT_I(x) _options[x].dwValue
+#define GET_OPT_T(x) _options[x].dwType
+
+#define ST_DESCRIPTION GET_OPT_T(0)
+#define ST_DISPLAYNAME GET_OPT_T(1)
+#define ST_INSTALL GET_OPT_T(2)
+#define ST_SUSER GET_OPT_T(3)
+#define ST_SPASSWORD GET_OPT_T(4)
+#define ST_STARTUP GET_OPT_T(5)
+#define ST_TYPE GET_OPT_T(6)
+
+#define SO_DESCRIPTION GET_OPT_V(0)
+#define SO_DISPLAYNAME GET_OPT_V(1)
+#define SO_INSTALL GET_OPT_V(2)
+#define SO_SUSER GET_OPT_V(3)
+#define SO_SPASSWORD GET_OPT_V(4)
+#define SO_STARTUP GET_OPT_V(5)
+#define SO_TYPE GET_OPT_V(6)
+
+#define SO_DEPENDSON GET_OPT_V(7)
+#define SO_ENVIRONMENT GET_OPT_V(8)
+
+#define SO_USER GET_OPT_V(9)
+#define SO_PASSWORD GET_OPT_V(10)
+
+#define SO_JAVAHOME GET_OPT_V(11)
+#define SO_JVM GET_OPT_V(12)
+#define SO_JVMOPTIONS GET_OPT_V(13)
+#define SO_CLASSPATH GET_OPT_V(14)
+#define SO_JVMMS GET_OPT_I(15)
+#define SO_JVMMX GET_OPT_I(16)
+#define SO_JVMSS GET_OPT_I(17)
+
+#define SO_STOPIMAGE GET_OPT_V(18)
+#define SO_STOPPATH GET_OPT_V(19)
+#define SO_STOPCLASS GET_OPT_V(20)
+#define SO_STOPPARAMS GET_OPT_V(21)
+#define SO_STOPMETHOD GET_OPT_V(22)
+#define SO_STOPMODE GET_OPT_V(23)
+#define SO_STOPTIMEOUT GET_OPT_I(24)
+
+#define SO_STARTIMAGE GET_OPT_V(25)
+#define SO_STARTPATH GET_OPT_V(26)
+#define SO_STARTCLASS GET_OPT_V(27)
+#define SO_STARTPARAMS GET_OPT_V(28)
+#define SO_STARTMETHOD GET_OPT_V(29)
+#define SO_STARTMODE GET_OPT_V(30)
+
+#define SO_LOGPATH GET_OPT_V(31)
+#define SO_LOGPREFIX GET_OPT_V(32)
+#define SO_LOGLEVEL GET_OPT_V(33)
+
+#define SO_STDERROR GET_OPT_V(34)
+#define SO_STDOUTPUT GET_OPT_V(35)
+
+/* Main servic table entry
+ * filled at run-time
+ */
+static SERVICE_TABLE_ENTRYW _service_table[] = {
+ {NULL, NULL},
+ {NULL, NULL}
+};
+
+static SERVICE_STATUS _service_status;
+static SERVICE_STATUS_HANDLE _service_status_handle = NULL;
+/* Set if launched by SCM */
+static BOOL _service_mode = FALSE;
+/* JVM used as worker */
+static BOOL _jni_startup = FALSE;
+/* JVM used for shutdown */
+static BOOL _jni_shutdown = FALSE;
+/* Global variables and objects */
+static APXHANDLE gPool;
+static APXHANDLE gWorker;
+static APX_STDWRAP gStdwrap; /* stdio/stderr redirection */
+
+static LPWSTR _jni_jvmpath = NULL; /* Path to jvm dll */
+static LPSTR _jni_jvmoptions = NULL; /* Path to jvm options */
+
+static LPSTR _jni_classpath = NULL;
+static LPCWSTR _jni_rparam = NULL; /* Startup arguments */
+static LPCWSTR _jni_sparam = NULL; /* Shutdown arguments */
+static LPSTR _jni_rmethod = NULL; /* Startup arguments */
+static LPSTR _jni_smethod = NULL; /* Shutdown arguments */
+static CHAR _jni_rclass[SIZ_RESLEN] = {'\0'}; /* Startup class */
+static CHAR _jni_sclass[SIZ_RESLEN] = {'\0'}; /* Shutdown class */
+
+static HANDLE gShutdownEvent = NULL;
+static HANDLE gSignalEvent = NULL;
+static HANDLE gSignalThread = NULL;
+static BOOL gSignalValid = TRUE;
+
+DWORD WINAPI eventThread(LPVOID lpParam)
+{
+ for (;;) {
+ DWORD dw = WaitForSingleObject(gSignalEvent, INFINITE);
+ if (dw == WAIT_OBJECT_0 && gSignalValid) {
+ if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0))
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ ResetEvent(gSignalEvent);
+ }
+ else
+ break;
+ }
+ ExitThread(0);
+ return 0;
+}
+
+/* redirect console stdout/stderr to files
+ * so that java messages can get logged
+ * If stderrfile is not specified it will
+ * go to stdoutfile.
+ */
+static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper)
+{
+ BOOL aErr = FALSE;
+ BOOL aOut = FALSE;
+
+ /* Clear up the handles */
+ lpWrapper->fpStdErrFile = NULL;
+ lpWrapper->fpStdOutFile = NULL;
+
+ /* Save the original streams */
+ lpWrapper->fpStdOutSave = *stdout;
+ lpWrapper->fpStdErrSave = *stderr;
+
+ /* redirect to file or console */
+ if (lpWrapper->szStdOutFilename) {
+ if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
+ aOut = TRUE;
+ lpWrapper->szStdOutFilename = apxLogFile(gPool,
+ lpWrapper->szLogPath,
+ NULL,
+ L"stdout_");
+ }
+ /* Delete the file if not in append mode
+ * XXX: See if we can use the params instead of that.
+ */
+ if (!aOut)
+ DeleteFileW(lpWrapper->szStdOutFilename);
+ lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
+ GENERIC_WRITE | GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
+ return FALSE;
+ /* Allways move to the end of file */
+ SetFilePointer(lpWrapper->hStdOutFile, 0, NULL, FILE_END);
+ }
+ else {
+ lpWrapper->hStdOutFile = CreateFileW(L"CONOUT$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
+ if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
+ return FALSE;
+ }
+ if (lpWrapper->szStdErrFilename) {
+ if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
+ aErr = TRUE;
+ lpWrapper->szStdErrFilename = apxLogFile(gPool,
+ lpWrapper->szLogPath,
+ NULL,
+ L"stderr_");
+ }
+ if (!aErr)
+ DeleteFileW(lpWrapper->szStdErrFilename);
+ lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
+ GENERIC_WRITE | GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (IS_INVALID_HANDLE(lpWrapper->hStdErrFile))
+ return FALSE;
+ SetFilePointer(lpWrapper->hStdErrFile, 0, NULL, FILE_END);
+ }
+ else if (lpWrapper->szStdOutFilename) {
+ /* Use the same file handle for stderr as for stdout */
+ lpWrapper->szStdErrFilename = lpWrapper->szStdOutFilename;
+ lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
+ }
+ else {
+ lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
+ }
+ /* Open the stream buffers
+ * This will redirect all printf to go to the redirected files.
+ * It is used for JNI vprintf functionality.
+ */
+ lpWrapper->fpStdOutFile = _fdopen(_open_osfhandle(
+ (intptr_t)lpWrapper->hStdOutFile,
+ _O_TEXT), "w");
+ lpWrapper->fpStdErrFile = _fdopen(_open_osfhandle(
+ (intptr_t)lpWrapper->hStdErrFile,
+ _O_TEXT), "w");
+ if (lpWrapper->fpStdOutFile) {
+ *stdout = *lpWrapper->fpStdOutFile;
+ setvbuf(stdout, NULL, _IONBF, 0);
+ }
+ if (lpWrapper->fpStdErrFile) {
+ *stderr = *lpWrapper->fpStdErrFile;
+ setvbuf(stderr, NULL, _IONBF, 0);
+ }
+ return TRUE;
+}
+
+static void cleanupStdStreams(APX_STDWRAP *lpWrapper)
+{
+ /* Close the redirectied streams */
+ if (lpWrapper->fpStdOutFile) {
+ fclose(lpWrapper->fpStdOutFile);
+ *stdout = lpWrapper->fpStdOutSave;
+ }
+ if (lpWrapper->fpStdErrFile) {
+ fclose(lpWrapper->fpStdErrFile);
+ *stderr = lpWrapper->fpStdErrSave;
+ }
+}
+
+/* Debugging functions */
+static void printUsage(LPAPXCMDLINE lpCmdline)
+{
+#ifdef _DEBUG
+ int i = 0;
+ fwprintf(stderr, L"Usage: %s //CMD//Servce [--options]\n",
+ lpCmdline->szExecutable);
+ fwprintf(stderr, L" Commands:\n");
+ fwprintf(stderr, L" //IS//ServiceName Install Service\n");
+ fwprintf(stderr, L" //US//ServiceName Update Service parameters\n");
+ fwprintf(stderr, L" //DS//ServiceName Delete Service\n");
+ fwprintf(stderr, L" //RS//ServiceName Run Service\n");
+ fwprintf(stderr, L" //SS//ServiceName Stop Service\n");
+ fwprintf(stderr,
+ L" //TS//ServiceName Run Service as console application\n");
+ fwprintf(stderr, L" Options:\n");
+ while (_options[i].szName) {
+ fwprintf(stderr, L" --%s\n", _options[i].szName);
+ ++i;
+ }
+#endif
+}
+/* Display configuration parameters */
+static void dumpCmdline()
+{
+ int i = 0;
+ while (_options[i].szName) {
+ if (_options[i].dwType & APXCMDOPT_INT)
+ fwprintf(stderr, L"--%-16s %d\n", _options[i].szName,
+ _options[i].dwValue);
+ else if (_options[i].szValue)
+ fwprintf(stderr, L"--%-16s %s\n", _options[i].szName,
+ _options[i].szValue);
+ else
+ fwprintf(stderr, L"--%-16s <NULL>\n", _options[i].szName);
+ ++i;
+ }
+}
+
+static void setInprocEnvironment()
+{
+ LPWSTR p, e;
+
+ if (!SO_ENVIRONMENT)
+ return; /* Nothing to do */
+
+ for (p = SO_ENVIRONMENT; *p; p++) {
+ e = apxExpandStrW(gPool, p);
+ _wputenv(e);
+ apxFree(e);
+ while (*p)
+ p++;
+ }
+}
+
+/* Load the configuration from Registry
+ * loads only nonspecified items
+ */
+static BOOL loadConfiguration(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hRegistry;
+ int i = 0;
+
+ SetLastError(ERROR_SUCCESS);
+ hRegistry = apxCreateRegistryW(gPool, KEY_READ, PRG_REGROOT,
+ lpCmdline->szApplication,
+ APXREG_SOFTWARE | APXREG_SERVICE);
+ if (IS_INVALID_HANDLE(hRegistry)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ /* browse through options */
+ while (_options[i].szName) {
+ DWORD dwFrom;
+
+ dwFrom = (_options[i].dwType & APXCMDOPT_REG) ? APXREG_PARAMSOFTWARE : APXREG_SERVICE;
+ if (!(_options[i].dwType & APXCMDOPT_FOUND)) {
+ if (_options[i].dwType & APXCMDOPT_STR) {
+ _options[i].szValue = apxRegistryGetStringW(hRegistry,
+ dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry);
+ /* Expand environment variables */
+ if (_options[i].szValue && (_options[i].dwType & APXCMDOPT_STE)) {
+ LPWSTR exp = apxExpandStrW(gPool, _options[i].szValue);
+ if (exp != _options[i].szValue)
+ apxFree(_options[i].szValue);
+ _options[i].szValue = exp;
+ }
+ }
+ else if (_options[i].dwType & APXCMDOPT_INT) {
+ _options[i].dwValue = apxRegistryGetNumberW(hRegistry,
+ dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry);
+ }
+ else if (_options[i].dwType & APXCMDOPT_MSZ) {
+ _options[i].szValue = apxRegistryGetMzStrW(hRegistry,
+ dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ NULL,
+ &(_options[i].dwValue));
+ }
+ }
+ /* Merge the command line options with registry */
+ else if (_options[i].dwType & APXCMDOPT_ADD) {
+ LPWSTR cv = _options[i].szValue;
+ LPWSTR ov = NULL;
+ if (_options[i].dwType & APXCMDOPT_MSZ) {
+ ov = apxRegistryGetMzStrW(hRegistry, dwFrom,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ NULL,
+ &(_options[i].dwValue));
+ _options[i].szValue = apxMultiSzCombine(gPool, ov, cv,
+ &(_options[i].dwValue));
+ if (ov)
+ apxFree(ov);
+ }
+ }
+ ++i;
+ }
+ apxCloseHandle(hRegistry);
+#ifdef _DEBUG
+ dumpCmdline();
+#endif
+ return TRUE;
+}
+
+/* Save changed configuration to registry
+ */
+static BOOL saveConfiguration(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hRegistry;
+ int i = 0;
+ hRegistry = apxCreateRegistryW(gPool, KEY_WRITE, PRG_REGROOT,
+ lpCmdline->szApplication,
+ APXREG_SOFTWARE | APXREG_SERVICE);
+ if (IS_INVALID_HANDLE(hRegistry))
+ return FALSE;
+ /* TODO: Use array size */
+ while (_options[i].szName) {
+ /* Skip the service params */
+ if ((_options[i].dwType & APXCMDOPT_SRV) ||
+ !(_options[i].dwType & APXCMDOPT_FOUND)) {
+ /* Skip non-modified version */
+ }
+ /* Update only modified params */
+ else if (_options[i].dwType & APXCMDOPT_STR)
+ apxRegistrySetStrW(hRegistry, APXREG_PARAMSOFTWARE,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ _options[i].szValue);
+ else if (_options[i].dwType & APXCMDOPT_INT)
+ apxRegistrySetNumW(hRegistry, APXREG_PARAMSOFTWARE,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ _options[i].dwValue);
+ else if (_options[i].dwType & APXCMDOPT_MSZ)
+ apxRegistrySetMzStrW(hRegistry, APXREG_PARAMSOFTWARE,
+ _options[i].szSubkey,
+ _options[i].szRegistry,
+ _options[i].szValue,
+ _options[i].dwValue);
+ ++i;
+ }
+ apxCloseHandle(hRegistry);
+ return TRUE;
+}
+
+/* Operations */
+static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv;
+ DWORD dwStart = SERVICE_DEMAND_START;
+ DWORD dwType = SERVICE_WIN32_OWN_PROCESS;
+ WCHAR szImage[SIZ_HUGLEN];
+
+ apxLogWrite(APXLOG_MARK_DEBUG "Installing service...");
+ hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+ /* Check the startup mode */
+ if ((ST_STARTUP & APXCMDOPT_FOUND) &&
+ lstrcmpiW(SO_STARTUP, PRSRV_AUTO) == 0)
+ dwStart = SERVICE_AUTO_START;
+ /* Check the service type */
+ if ((ST_TYPE & APXCMDOPT_FOUND) &&
+ lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE) == 0)
+ dwType |= SERVICE_INTERACTIVE_PROCESS;
+
+ /* Check if --Install is provided */
+ if (!SO_INSTALL) {
+ lstrcpyW(szImage, lpCmdline->szExePath);
+ lstrcatW(szImage, L"\\");
+ lstrcatW(szImage, lpCmdline->szExecutable);
+ lstrcatW(szImage, L".exe");
+ }
+ else
+ lstrcpyW(szImage, SO_INSTALL);
+ /* Replace not needed qoutes */
+ apxStrQuoteInplaceW(szImage);
+ /* Add run-service command line option */
+ lstrcatW(szImage, L" //RS//");
+ lstrcatW(szImage, lpCmdline->szApplication);
+ SO_INSTALL = apxPoolStrdupW(gPool, szImage);
+ /* Ensure that option gets saved in the registry */
+ ST_INSTALL |= APXCMDOPT_FOUND;
+#ifdef _DEBUG
+ /* Display configured options */
+ dumpCmdline();
+#endif
+ apxLogWrite(APXLOG_MARK_INFO "Service %S name %S", lpCmdline->szApplication,
+ SO_DISPLAYNAME);
+ rv = apxServiceInstall(hService,
+ lpCmdline->szApplication,
+ SO_DISPLAYNAME, /* --DisplayName */
+ SO_INSTALL,
+ SO_DEPENDSON, /* --DependendsOn */
+ dwType,
+ dwStart);
+ /* Set the --Description */
+ if (rv) {
+ LPCWSTR sd = NULL;
+ LPCWSTR su = NULL;
+ LPCWSTR sp = NULL;
+ if (ST_DESCRIPTION & APXCMDOPT_FOUND) {
+ sd = SO_DESCRIPTION;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service description %S",
+ SO_DESCRIPTION);
+ }
+ if (ST_SUSER & APXCMDOPT_FOUND) {
+ su = SO_SUSER;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service user %S",
+ SO_SUSER);
+ }
+ if (ST_SPASSWORD & APXCMDOPT_FOUND) {
+ sp = SO_SPASSWORD;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
+ SO_SPASSWORD);
+ }
+ apxServiceSetNames(hService, NULL, NULL, sd, su, sp);
+ }
+ apxCloseHandle(hService);
+ if (rv) {
+ saveConfiguration(lpCmdline);
+ apxLogWrite(APXLOG_MARK_INFO "Service %S installed",
+ lpCmdline->szApplication);
+ }
+ else
+ apxLogWrite(APXLOG_MARK_ERROR "Failed installing %S service",
+ lpCmdline->szApplication);
+
+ return rv;
+}
+
+static BOOL docmdDeleteService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv = FALSE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Deleting service...");
+ hService = apxCreateService(gPool, SC_MANAGER_CONNECT, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+ /* Delete service will stop the service if running */
+ if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ WCHAR szWndManagerClass[SIZ_RESLEN];
+ HANDLE hWndManager = NULL;
+ lstrcpyW(szWndManagerClass, lpCmdline->szApplication);
+ lstrcatW(szWndManagerClass, L"_CLASS");
+ /* Close the monitor application if running */
+ if ((hWndManager = FindWindowW(szWndManagerClass, NULL)) != NULL) {
+ SendMessage(hWndManager, WM_CLOSE, 0, 0);
+ }
+ rv = apxServiceDelete(hService);
+ }
+ if (rv) {
+ /* Delete all service registry settings */
+ apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, TRUE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Service %S deleted",
+ lpCmdline->szApplication);
+ }
+ else {
+ apxDisplayError(TRUE, NULL, 0, "Unable to delete %S service",
+ lpCmdline->szApplication);
+ }
+ apxCloseHandle(hService);
+ apxLogWrite(APXLOG_MARK_INFO "Delete service finished.");
+ return rv;
+}
+
+static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv = FALSE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+ hService = apxCreateService(gPool, GENERIC_ALL, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+
+ SetLastError(ERROR_SUCCESS);
+ /* Open the service */
+ if (apxServiceOpen(hService, lpCmdline->szApplication,
+ GENERIC_READ | GENERIC_EXECUTE)) {
+ rv = apxServiceControl(hService,
+ SERVICE_CONTROL_STOP,
+ 0,
+ NULL,
+ NULL);
+ if (rv)
+ apxLogWrite(APXLOG_MARK_INFO "Service %S stopped",
+ lpCmdline->szApplication);
+ else
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to stop %S service",
+ lpCmdline->szApplication);
+
+ }
+ else
+ apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
+ lpCmdline->szApplication);
+ apxCloseHandle(hService);
+ apxLogWrite(APXLOG_MARK_INFO "Stop service finished.");
+ return rv;
+}
+
+static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
+{
+ APXHANDLE hService;
+ BOOL rv = FALSE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Updating service...");
+
+ hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+ return FALSE;
+ }
+ SetLastError(0);
+ /* Open the service */
+ if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ DWORD dwStart = SERVICE_NO_CHANGE;
+ DWORD dwType = SERVICE_NO_CHANGE;
+ LPCWSTR su = NULL;
+ LPCWSTR sp = NULL;
+ if (ST_SUSER & APXCMDOPT_FOUND) {
+ su = SO_SUSER;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service user %S",
+ SO_SUSER);
+ }
+ if (ST_SPASSWORD & APXCMDOPT_FOUND) {
+ sp = SO_SPASSWORD;
+ apxLogWrite(APXLOG_MARK_DEBUG "Setting service password %S",
+ SO_SPASSWORD);
+ }
+ apxServiceSetNames(hService,
+ NULL, /* Never update the ImagePath */
+ SO_DISPLAYNAME,
+ SO_DESCRIPTION,
+ su,
+ sp);
+ /* Update the --Startup mode */
+ if (ST_STARTUP & APXCMDOPT_FOUND) {
+ if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
+ dwStart = SERVICE_AUTO_START;
+ else if (!lstrcmpiW(SO_STARTUP, PRSRV_MANUAL))
+ dwStart = SERVICE_DEMAND_START;
+ }
+ if (ST_TYPE & APXCMDOPT_FOUND) {
+ if (!lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE))
+ dwType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
+ }
+ apxServiceSetOptions(hService,
+ dwType,
+ dwStart,
+ SERVICE_NO_CHANGE);
+
+ apxLogWrite(APXLOG_MARK_INFO "Service %S updated",
+ lpCmdline->szApplication);
+
+ saveConfiguration(lpCmdline);
+ }
+ else
+ apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
+ lpCmdline->szApplication);
+ apxCloseHandle(hService);
+ apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
+ return rv;
+}
+
+
+/* Report the service status to the SCM
+ */
+int reportServiceStatus(DWORD dwCurrentState,
+ DWORD dwWin32ExitCode,
+ DWORD dwWaitHint)
+{
+ static DWORD dwCheckPoint = 1;
+ BOOL fResult = TRUE;
+
+ if (_service_mode && _service_status_handle) {
+ if (dwCurrentState == SERVICE_START_PENDING)
+ _service_status.dwControlsAccepted = 0;
+ else
+ _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+
+ _service_status.dwCurrentState = dwCurrentState;
+ _service_status.dwWin32ExitCode = dwWin32ExitCode;
+ _service_status.dwWaitHint = dwWaitHint;
+
+ if ((dwCurrentState == SERVICE_RUNNING) ||
+ (dwCurrentState == SERVICE_STOPPED))
+ _service_status.dwCheckPoint = 0;
+ else
+ _service_status.dwCheckPoint = dwCheckPoint++;
+ fResult = SetServiceStatus(_service_status_handle, &_service_status);
+ if (!fResult) {
+ /* TODO: Deal with error */
+ }
+ }
+ return fResult;
+}
+
+
+BOOL child_callback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ /* TODO: Make stdout and stderr buffers
+ * to prevent streams intermixing when there
+ * is no separate file for each stream
+ */
+ if (uMsg == WM_CHAR) {
+ int ch = LOWORD(wParam);
+ if (lParam)
+ fputc(ch, stderr);
+ else
+ fputc(ch, stdout);
+ }
+ return TRUE;
+}
+
+/* Executed when the service receives stop event */
+static DWORD WINAPI serviceStop(LPVOID lpParameter)
+{
+ APXHANDLE hWorker = NULL;
+ DWORD rv = 0;
+ BOOL wait_to_die = FALSE;
+ DWORD timeout = SO_STOPTIMEOUT * 1000;
+ DWORD dwCtrlType = (DWORD)((BYTE *)lpParameter - (BYTE *)0);
+
+ apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+
+ if (IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
+ return TRUE; /* Nothing to do */
+ }
+ if (_jni_shutdown) {
+ if (!SO_STARTPATH && SO_STOPPATH) {
+ /* If the Working path is specified change the current directory
+ * but only if the start path wasn't specified already.
+ */
+ SetCurrentDirectoryW(SO_STARTPATH);
+ }
+ hWorker = apxCreateJava(gPool, _jni_jvmpath);
+ if (IS_INVALID_HANDLE(hWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
+ return 1;
+ }
+ if (!apxJavaInitialize(hWorker, _jni_classpath, _jni_jvmoptions,
+ SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
+ rv = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
+ goto cleanup;
+ }
+ if (!apxJavaLoadMainClass(hWorker, _jni_sclass, _jni_smethod, _jni_sparam)) {
+ rv = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s",
+ _jni_rclass, _jni_classpath);
+ goto cleanup;
+ }
+ /* Create sutdown event */
+ gShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (!apxJavaStart(hWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed starting java");
+ rv = 3;
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for java jni stop worker to finish...");
+ apxJavaWait(hWorker, INFINITE, FALSE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Java jni stop worker finished.");
+ }
+ wait_to_die = TRUE;
+ }
+ else if (SO_STOPMODE) { /* Only in case we have a stop mode */
+ DWORD nArgs;
+ LPWSTR *pArgs;
+ /* Redirect process */
+ hWorker = apxCreateProcessW(gPool,
+ 0,
+ child_callback,
+ SO_USER,
+ SO_PASSWORD,
+ FALSE);
+ if (IS_INVALID_HANDLE(hWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
+ return 1;
+ }
+ if (!apxProcessSetExecutableW(hWorker, SO_STOPIMAGE)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
+ SO_STARTIMAGE);
+ rv = 2;
+ goto cleanup;
+ }
+ /* Assemble the command line */
+ nArgs = apxMultiSzToArrayW(gPool, SO_STOPPARAMS, &pArgs);
+ /* Pass the argv to child process */
+ if (!apxProcessSetCommandArgsW(hWorker, SO_STOPIMAGE,
+ nArgs, pArgs)) {
+ rv = 3;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
+ nArgs);
+ goto cleanup;
+ }
+ /* Set the working path */
+ if (!apxProcessSetWorkingPathW(hWorker, SO_STOPPATH)) {
+ rv = 4;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
+ SO_STOPPATH);
+ goto cleanup;
+ }
+ /* Finally execute the child process
+ */
+ if (!apxProcessExecute(hWorker)) {
+ rv = 5;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
+ goto cleanup;
+ } else {
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting stop worker to finish...");
+ apxHandleWait(hWorker, INFINITE, FALSE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Stop worker finished.");
+ }
+ wait_to_die = TRUE;
+ }
+cleanup:
+ /* Close Java JNI handle or stop worker
+ * If this is the single JVM instance it will unload
+ * the JVM dll too.
+ * The worker will be closed on service exit.
+ */
+ if (!IS_INVALID_HANDLE(hWorker))
+ apxCloseHandle(hWorker);
+ if (gSignalEvent) {
+ gSignalValid = FALSE;
+ SetEvent(gSignalEvent);
+ WaitForSingleObject(gSignalThread, 1000);
+ CloseHandle(gSignalEvent);
+ CloseHandle(gSignalThread);
+ gSignalEvent = NULL;
+ }
+ SetEvent(gShutdownEvent);
+ if (timeout > 0x7FFFFFFF)
+ timeout = INFINITE; /* If the timeout was '-1' wait forewer */
+ if (wait_to_die && !timeout)
+ timeout = 300 * 1000; /* Use the 5 minute default shutdown */
+
+ if (dwCtrlType == SERVICE_CONTROL_SHUTDOWN)
+ timeout = MIN(timeout, apxGetMaxServiceTimeout(gPool));
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, timeout);
+
+ if (timeout) {
+ FILETIME fts, fte;
+ ULARGE_INTEGER s, e;
+ DWORD nms;
+ /* Wait to give it a chance to die naturally, then kill it. */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for worker to die naturally...");
+ GetSystemTimeAsFileTime(&fts);
+ rv = apxHandleWait(gWorker, timeout, TRUE);
+ GetSystemTimeAsFileTime(&fte);
+ s.LowPart = fts.dwLowDateTime;
+ s.HighPart = fts.dwHighDateTime;
+ e.LowPart = fte.dwLowDateTime;
+ e.HighPart = fte.dwHighDateTime;
+ nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
+ if (rv == WAIT_OBJECT_0) {
+ rv = 0;
+ apxLogWrite(APXLOG_MARK_DEBUG "Worker finished gracefully in %d ms.", nms);
+ }
+ else
+ apxLogWrite(APXLOG_MARK_DEBUG "Worker was killed in %d ms.", nms);
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_DEBUG "Sending WM_CLOSE to worker");
+ apxHandleSendMessage(gWorker, WM_CLOSE, 0, 0);
+ }
+
+ apxLogWrite(APXLOG_MARK_INFO "Service stopped.");
+ reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+ return rv;
+}
+
+/* Executed when the service receives start event */
+static DWORD serviceStart()
+{
+ DWORD rv = 0;
+ DWORD nArgs;
+ LPWSTR *pArgs;
+ FILETIME fts;
+
+ apxLogWrite(APXLOG_MARK_INFO "Starting service...");
+
+ if (!IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
+ return TRUE; /* Nothing to do */
+ }
+ GetSystemTimeAsFileTime(&fts);
+ if (_jni_startup) {
+ if (SO_STARTPATH) {
+ /* If the Working path is specified change the current directory */
+ SetCurrentDirectoryW(SO_STARTPATH);
+ }
+ /* Set the environment using putenv, so JVM can use it */
+ setInprocEnvironment();
+ /* Create the JVM glbal worker */
+ gWorker = apxCreateJava(gPool, _jni_jvmpath);
+ if (IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
+ return 1;
+ }
+ if (!apxJavaInitialize(gWorker, _jni_classpath, _jni_jvmoptions,
+ SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
+ rv = 2;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
+ goto cleanup;
+ }
+ if (!apxJavaLoadMainClass(gWorker, _jni_rclass, _jni_rmethod, _jni_rparam)) {
+ rv = 3;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s", _jni_rclass, _jni_classpath);
+ goto cleanup;
+ }
+ apxJavaSetOut(gWorker, TRUE, gStdwrap.szStdErrFilename);
+ apxJavaSetOut(gWorker, FALSE, gStdwrap.szStdOutFilename);
+ if (!apxJavaStart(gWorker)) {
+ rv = 4;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed starting Java");
+ goto cleanup;
+ }
+ apxLogWrite(APXLOG_MARK_DEBUG "Java started %s", _jni_rclass);
+ }
+ else {
+ /* Redirect process */
+ gWorker = apxCreateProcessW(gPool,
+ 0,
+ child_callback,
+ SO_USER,
+ SO_PASSWORD,
+ FALSE);
+ if (IS_INVALID_HANDLE(gWorker)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
+ return 1;
+ }
+ if (!apxProcessSetExecutableW(gWorker, SO_STARTIMAGE)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
+ SO_STARTIMAGE);
+ rv = 2;
+ goto cleanup;
+ }
+ /* Assemble the command line */
+ nArgs = apxMultiSzToArrayW(gPool, SO_STARTPARAMS, &pArgs);
+ /* Pass the argv to child process */
+ if (!apxProcessSetCommandArgsW(gWorker, SO_STARTIMAGE,
+ nArgs, pArgs)) {
+ rv = 3;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
+ nArgs);
+ goto cleanup;
+ }
+ /* Set the working path */
+ if (!apxProcessSetWorkingPathW(gWorker, SO_STARTPATH)) {
+ rv = 4;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
+ SO_STARTPATH);
+ goto cleanup;
+ }
+ /* Finally execute the child process
+ */
+ if (!apxProcessExecute(gWorker)) {
+ rv = 5;
+ apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
+ goto cleanup;
+ }
+ }
+ if (rv == 0) {
+ FILETIME fte;
+ ULARGE_INTEGER s, e;
+ DWORD nms;
+ GetSystemTimeAsFileTime(&fte);
+ s.LowPart = fts.dwLowDateTime;
+ s.HighPart = fts.dwHighDateTime;
+ e.LowPart = fte.dwLowDateTime;
+ e.HighPart = fte.dwHighDateTime;
+ nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
+ apxLogWrite(APXLOG_MARK_INFO "Service started in %d ms.", nms);
+ }
+ return rv;
+cleanup:
+ if (!IS_INVALID_HANDLE(gWorker))
+ apxCloseHandle(gWorker); /* Close the worker handle */
+ gWorker = NULL;
+ return rv;
+}
+
+/* Service control handler
+ */
+void WINAPI service_ctrl_handler(DWORD dwCtrlCode)
+{
+ DWORD threadId;
+ HANDLE stopThread;
+
+ switch (dwCtrlCode) {
+ case SERVICE_CONTROL_STOP:
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
+ /* Stop the service asynchronously */
+ stopThread = CreateThread(NULL, 0,
+ serviceStop,
+ (LPVOID)SERVICE_CONTROL_STOP,
+ 0, &threadId);
+ WaitForSingleObject(stopThread, INFINITE);
+ CloseHandle(stopThread);
+
+ return;
+ case SERVICE_CONTROL_SHUTDOWN:
+ apxLogWrite(APXLOG_MARK_INFO "Service SHUTDOWN signaled");
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 3000);
+ /* Stop the service asynchronously */
+ stopThread = CreateThread(NULL, 0,
+ serviceStop,
+ (LPVOID)SERVICE_CONTROL_SHUTDOWN,
+ 0, &threadId);
+ WaitForSingleObject(stopThread, INFINITE);
+ CloseHandle(stopThread);
+ return;
+ case SERVICE_CONTROL_INTERROGATE:
+ reportServiceStatus(_service_status.dwCurrentState,
+ _service_status.dwWin32ExitCode,
+ _service_status.dwWaitHint);
+ return;
+ default:
+ break;
+ }
+}
+
+/* Console control handler
+ *
+ */
+BOOL WINAPI console_handler(DWORD dwCtrlType)
+{
+ switch (dwCtrlType) {
+ case CTRL_BREAK_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console CTRL+BREAK event signaled");
+ return FALSE;
+ case CTRL_C_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console CTRL+C event signaled");
+ serviceStop((LPVOID)SERVICE_CONTROL_STOP);
+ return TRUE;
+ case CTRL_CLOSE_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console CTRL+CLOSE event signaled");
+ serviceStop((LPVOID)SERVICE_CONTROL_STOP);
+ return TRUE;
+ case CTRL_SHUTDOWN_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console SHUTDOWN event signaled");
+ serviceStop((LPVOID)SERVICE_CONTROL_SHUTDOWN);
+ return TRUE;
+ case CTRL_LOGOFF_EVENT:
+ apxLogWrite(APXLOG_MARK_INFO "Console LOGOFF event signaled");
+ if (!_service_mode) {
+ serviceStop((LPVOID)SERVICE_CONTROL_STOP);
+ }
+ return TRUE;
+ break;
+
+ }
+ return FALSE;
+}
+
+/* Main service execution loop */
+void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
+{
+ DWORD rc;
+ _service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ _service_status.dwCurrentState = SERVICE_START_PENDING;
+ _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
+ SERVICE_ACCEPT_PAUSE_CONTINUE;
+ _service_status.dwWin32ExitCode = 0;
+ _service_status.dwCheckPoint = 0;
+ _service_status.dwWaitHint = 0;
+ _service_status.dwServiceSpecificExitCode = 0;
+
+ apxLogWrite(APXLOG_MARK_DEBUG "Inside ServiceMain...");
+
+ if (_service_name) {
+ WCHAR en[SIZ_DESLEN];
+ int i;
+ PSECURITY_ATTRIBUTES sa = GetNullACL();
+ lstrcpyW(en, _service_name);
+ lstrcatW(en, PRSRV_SIGNAL);
+ for (i = 0; i < lstrlenW(en); i++) {
+ if (en[i] >= L'a' && en[i] <= L'z')
+ en[i] = en[i] - 32;
+ }
+ gSignalEvent = CreateEventW(sa, TRUE, FALSE, en);
+ CleanNullACL((void *)sa);
+
+ if (gSignalEvent) {
+ DWORD tid;
+ gSignalThread = CreateThread(NULL, 0, eventThread, NULL, 0, &tid);
+ }
+ }
+ /* Check the StartMode */
+ if (SO_STARTMODE) {
+ if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
+ _jni_startup = TRUE;
+ WideToAscii(SO_STARTCLASS, _jni_rclass);
+ /* Exchange all dots with slashes */
+ apxStrCharReplaceA(_jni_rclass, '.', '/');
+ _jni_rparam = SO_STARTPARAMS;
+ }
+ else if (!lstrcmpiW(SO_STARTMODE, PRSRV_JAVA)) {
+ LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
+ if (szJH) {
+ jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
+ lstrcpyW(jx, szJH);
+ lstrcatW(jx, PRSRV_JBIN);
+ SO_STARTPATH = szJH;
+ }
+ /* StartImage now contains the full path to the java.exe */
+ SO_STARTIMAGE = jx;
+ }
+ }
+ /* Check the StopMode */
+ if (SO_STOPMODE) {
+ if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
+ _jni_shutdown = TRUE;
+ WideToAscii(SO_STOPCLASS, _jni_sclass);
+ apxStrCharReplaceA(_jni_sclass, '.', '/');
+ _jni_sparam = SO_STOPPARAMS;
+ }
+ else if (!lstrcmpiW(SO_STOPMODE, PRSRV_JAVA)) {
+ LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
+ if (szJH) {
+ jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
+ lstrcpyW(jx, szJH);
+ lstrcatW(jx, PRSRV_JBIN);
+ SO_STOPPATH = szJH;
+ }
+ /* StopImage now contains the full path to the java.exe */
+ SO_STOPIMAGE = jx;
+ }
+ }
+ /* Find the classpath */
+ if (_jni_shutdown || _jni_startup) {
+ if (SO_JVM) {
+ if (lstrcmpW(SO_JVM, PRSRV_AUTO))
+ _jni_jvmpath = SO_JVM;
+ }
+ if (SO_CLASSPATH)
+ _jni_classpath = WideToUTF8(SO_CLASSPATH);
+ if (SO_STARTMETHOD)
+ _jni_rmethod = WideToAscii(SO_STARTMETHOD, (LPSTR)SO_STARTMETHOD);
+ if (SO_STOPMETHOD)
+ _jni_smethod = WideToAscii(SO_STOPMETHOD, (LPSTR)SO_STOPMETHOD);
+ _jni_jvmoptions = MzWideToUTF8(SO_JVMOPTIONS);
+ }
+ if (_service_mode) {
+ /* Register Service Control handler */
+ _service_status_handle = RegisterServiceCtrlHandlerW(_service_name,
+ service_ctrl_handler);
+ if (IS_INVALID_HANDLE(_service_status_handle)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to register Service Control for %S",
+ _service_name);
+ goto cleanup;
+ }
+ /* Allocate console so that events gets processed */
+ AllocConsole();
+ }
+ reportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+ if ((rc = serviceStart()) == 0) {
+ /* Service is started */
+ DWORD rv;
+ reportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting worker to finish...");
+ /* Set console handler to capture CTRL events */
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
+
+ rv = apxHandleWait(gWorker, INFINITE, FALSE);
+ apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
+ reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ fflush(stdout);
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
+ goto cleanup;
+ }
+ if (gShutdownEvent) {
+ /* Ensure that shutdown thread exits before us */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
+ WaitForSingleObject(gShutdownEvent, 60 * 1000);
+ apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
+ CloseHandle(gShutdownEvent);
+ }
+ reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+
+ return;
+cleanup:
+ /* Cleanup */
+ reportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, 0);
+ return;
+}
+
+
+/* Run the service in the debug mode */
+BOOL docmdDebugService(LPAPXCMDLINE lpCmdline)
+{
+ BOOL rv = FALSE;
+
+ _service_mode = FALSE;
+ _service_name = lpCmdline->szApplication;
+ apxLogWrite(APXLOG_MARK_INFO "Debugging Service...");
+ serviceMain(0, NULL);
+ apxLogWrite(APXLOG_MARK_INFO "Debug service finished.");
+
+ return rv;
+}
+
+BOOL docmdRunService(LPAPXCMDLINE lpCmdline)
+{
+ BOOL rv = FALSE;
+ _service_mode = TRUE;
+
+ apxLogWrite(APXLOG_MARK_INFO "Running Service...");
+ _service_name = lpCmdline->szApplication;
+ _service_table[0].lpServiceName = lpCmdline->szApplication;
+ _service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONW)serviceMain;
+ rv = (StartServiceCtrlDispatcherW(_service_table) == FALSE);
+ apxLogWrite(APXLOG_MARK_INFO "Run service finished.");
+ return rv;
+}
+
+void __cdecl main(int argc, char **argv)
+{
+ UINT rv = 0;
+
+ LPAPXCMDLINE lpCmdline;
+
+ apxHandleManagerInitialize();
+ /* Create the main Pool */
+ gPool = apxPoolCreate(NULL, 0);
+
+ /* Parse the command line */
+ if ((lpCmdline = apxCmdlineParse(gPool, _options, _commands)) == NULL) {
+ apxLogWrite(APXLOG_MARK_ERROR "Invalid command line arguments");
+ rv = 1;
+ goto cleanup;
+ }
+ apxCmdlineLoadEnvVars(lpCmdline);
+ if (lpCmdline->dwCmdIndex < 5 &&
+ !loadConfiguration(lpCmdline)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
+ rv = 2;
+ goto cleanup;
+ }
+
+ apxLogOpen(gPool, SO_LOGPATH, SO_LOGPREFIX);
+ apxLogLevelSetW(NULL, SO_LOGLEVEL);
+ apxLogWrite(APXLOG_MARK_DEBUG "Procrun log initialized");
+ apxLogWrite(APXLOG_MARK_INFO "Procrun (%s) started", PRG_VERSION);
+
+ AplZeroMemory(&gStdwrap, sizeof(APX_STDWRAP));
+
+ gStdwrap.szLogPath = SO_LOGPATH;
+ /* In debug mode allways use console */
+ if (lpCmdline->dwCmdIndex != 1) {
+ gStdwrap.szStdOutFilename = SO_STDOUTPUT;
+ gStdwrap.szStdErrFilename = SO_STDERROR;
+ }
+ redirectStdStreams(&gStdwrap);
+ switch (lpCmdline->dwCmdIndex) {
+ case 1: /* Run Service as console application */
+ if (!docmdDebugService(lpCmdline))
+ rv = 3;
+ break;
+ case 2: /* Run Service */
+ if (!docmdRunService(lpCmdline))
+ rv = 4;
+ break;
+ case 3: /* Stop Service */
+ if (!docmdStopService(lpCmdline))
+ rv = 5;
+ break;
+ case 4: /* Update Service parameters */
+ if (!docmdUpdateService(lpCmdline))
+ rv = 6;
+ break;
+ case 5: /* Install Service */
+ if (!docmdInstallService(lpCmdline))
+ rv = 7;
+ break;
+ case 6: /* Delete Service */
+ if (!docmdDeleteService(lpCmdline))
+ rv = 8;
+ break;
+ default:
+ /* Unknown command option */
+ apxLogWrite(APXLOG_MARK_ERROR "Unknown command line option");
+ printUsage(lpCmdline);
+ rv = 99;
+ break;
+ }
+
+cleanup:
+ apxLogWrite(APXLOG_MARK_INFO "Procrun finished.");
+ if (lpCmdline)
+ apxCmdlineFree(lpCmdline);
+ if (_service_status_handle)
+ CloseHandle(_service_status_handle);
+ _service_status_handle = NULL;
+ apxLogClose(NULL);
+ apxHandleManagerDestroy();
+ cleanupStdStreams(&gStdwrap);
+ ExitProcess(rv);
+}
Property changes on: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,32 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* ====================================================================
+ * jar2exe -- convert .jar file to WIN32 executable.
+ * Contributed by Mladen Turk <mturk(a)apache.org>
+ * 05 Aug 2003
+ * ====================================================================
+ */
+
+#ifndef _PRUNSRV_H
+#define _PRUNSRV_H
+
+#undef PRG_VERSION
+#define PRG_VERSION "2.0.3.0"
+#define PRG_REGROOT L"JBoss\\JBoss Web 2"
+
+#endif /* _PRUNSRV_H */
+
Property changes on: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc
===================================================================
--- trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc (rev 0)
+++ trunk/utils/windows/native/service/procrun/apps/prunsrv/prunsrv.rc 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,64 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "prunsrv.h"
+
+#define STR_COPYRIGHT "Copyright � 2007 Red Hat Middleware, LLC. " \
+ "or its licensors, as applicable."
+
+#define STR_LICENSE "Distributable under LGPL license. " \
+ "See terms of license at gnu.org."
+
+#define STR_COMPANY "Red Hat�, Inc."
+#define STR_TRADEMARK "� Red Hat Inc."
+#define STR_PRODUCT "JBoss Web Service wrapper"
+
+IDI_MAINICON ICON "../../resources/jboss.ico"
+
+1 VERSIONINFO
+ FILEVERSION 2,0,3,0
+ PRODUCTVERSION 2,0,3,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", STR_COPYRIGHT "\0"
+ VALUE "CompanyName", STR_COMPANY "\0"
+ VALUE "FileDescription", STR_PRODUCT "\0"
+ VALUE "FileVersion", PRG_VERSION
+ VALUE "InternalName", STR_PRODUCT "\0"
+ VALUE "LegalCopyright", STR_COPYRIGHT "\0"
+ VALUE "OriginalFilename", "jbossweb.exe\0"
+ VALUE "ProductName", STR_PRODUCT "\0"
+ VALUE "ProductVersion", PRG_VERSION
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
Added: trunk/utils/windows/native/service/procrun/include/apxwin.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/apxwin.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/apxwin.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,210 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _APXWIN_H_INCLUDED_
+#define _APXWIN_H_INCLUDED_
+
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0400
+#endif
+
+#include <windows.h>
+#include <windowsx.h>
+#include <commdlg.h>
+#include <commctrl.h>
+#include <objbase.h>
+#include <shlobj.h>
+#include <shlwapi.h>
+#include <shellapi.h>
+#include <zmouse.h>
+#include <richedit.h>
+
+#include <lm.h>
+
+#ifndef _INTPTR_T_DEFINED
+#ifdef _WIN64
+typedef __int64 intptr_t;
+#else
+typedef _W64 int intptr_t;
+#endif
+#define _INTPTR_T_DEFINED
+#endif
+
+#define APXMACRO_BEGIN do {
+#define APXMACRO_END } while(0)
+
+#ifdef __cplusplus
+#define __APXBEGIN_DECLS extern "C" {
+#define __APXEND_DECLS }
+#else
+#define __APXBEGIN_DECLS
+#define __APXEND_DECLS
+#endif
+
+#define SET_BIT_FLAG(x, b) ((x) |= (1 << b))
+#define CLR_BIT_FLAG(x, b) ((x) &= ~(1 << b))
+#define TST_BIT_FLAG(x, b) ((x) & (1 << b))
+
+#define IS_INVALID_HANDLE(h) (((h) == NULL || (h) == INVALID_HANDLE_VALUE))
+
+#define DYNOLAD_TYPE_DECLARE(fnName, callconv, retType) \
+ typedef retType (callconv *PFN_##fnName) \
+
+#define DYNLOAD_FPTR_DECLARE(fnName) \
+ PFN_##fnName FP_##fnName
+
+#define DYNLOAD_FPTR(fnName) FP_##fnName
+
+#define DYNLOAD_FPTR_ADDRESS(fnName, dllName) \
+ FP_##fnName = (PFN_##fnName)GetProcAddress( \
+ GetModuleHandle(TEXT(#dllName)), \
+ #fnName)
+
+#define DYNLOAD_FPTR_LOAD(fnName, dllHandle) \
+ FP_##fnName = (PFN_##fnName)GetProcAddress( \
+ dllHandle, \
+ #fnName)
+
+#define DYNLOAD_CALL(fnName) (*FP_##fnName)
+
+#ifndef ABS
+#define ABS(x) (((x) > 0) ? (x) : (x) * (-1))
+#endif
+
+#define SIZ_RESLEN 256
+#define SIZ_RESMAX (SIZ_RESLEN -1)
+#define SIZ_BUFLEN 512
+#define SIZ_BUFMAX (SIZ_BUFLEN -1)
+#define SIZ_DESLEN 1024
+#define SIZ_DESMAX (SIZ_DESLEN -1)
+#define SIZ_HUGLEN 8192
+#define SIZ_HUGMAX (SIZ_HUGLEN -1)
+
+#include "handles.h"
+#include "log.h"
+#include "cmdline.h"
+#include "console.h"
+#include "rprocess.h"
+#include "registry.h"
+#include "service.h"
+#include "javajni.h"
+#include "gui.h"
+
+__APXBEGIN_DECLS
+
+typedef enum {
+ APX_WINVER_UNK = 0,
+ APX_WINVER_UNSUP = 1,
+ APX_WINVER_95 = 10,
+ APX_WINVER_95_B = 11,
+ APX_WINVER_95_OSR2 = 12,
+ APX_WINVER_98 = 14,
+ APX_WINVER_98_SE = 16,
+ APX_WINVER_ME = 18,
+
+ APX_WINVER_UNICODE = 20, /* Prior versions support only narrow chars */
+
+ APX_WINVER_CE_3 = 23, /* CE is an odd beast, not supporting */
+ /* some pre-NT features, such as the */
+ APX_WINVER_NT = 30, /* narrow charset APIs (fooA fns), while */
+ APX_WINVER_NT_3_5 = 35, /* not supporting some NT-family features. */
+ APX_WINVER_NT_3_51 = 36,
+
+ APX_WINVER_NT_4 = 40,
+ APX_WINVER_NT_4_SP2 = 42,
+ APX_WINVER_NT_4_SP3 = 43,
+ APX_WINVER_NT_4_SP4 = 44,
+ APX_WINVER_NT_4_SP5 = 45,
+ APX_WINVER_NT_4_SP6 = 46,
+
+ APX_WINVER_2000 = 50,
+ APX_WINVER_2000_SP1 = 51,
+ APX_WINVER_2000_SP2 = 52,
+ APX_WINVER_XP = 60
+} APX_OSLEVEL;
+
+APX_OSLEVEL apxGetOsLevel();
+LPWSTR AsciiToWide(LPCSTR s, LPWSTR ws);
+LPSTR WideToAscii(LPCWSTR ws, LPSTR s);
+LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s);
+LPSTR WideToUTF8(LPCWSTR ws);
+LPSTR MzWideToUTF8(LPCWSTR ws);
+
+typedef struct APXMULTISZ APXMULTISZ;
+typedef APXMULTISZ* LPAPXMULTISZ;
+
+DWORD apxMultiSzToArrayA(APXHANDLE hPool, LPCSTR lpString, LPSTR **lppArray);
+DWORD apxMultiSzToArrayW(APXHANDLE hPool, LPCWSTR lpString, LPWSTR **lppArray);
+LPWSTR apxMultiSzCombine(APXHANDLE hPool, LPCWSTR lpStrA, LPCWSTR lpStrB,
+ LPDWORD lpdwLength);
+
+LPAPXMULTISZ apxMultiSzStrdup(LPCTSTR szSrc);
+LPTSTR apxMultiSzStrcat(LPAPXMULTISZ lpmSz, LPCTSTR szSrc);
+LPCTSTR apxMultiSzGet(LPAPXMULTISZ lpmSz);
+/** Remove the specified character from the string
+ * Replacement is done in-place.
+ */
+LPTSTR apxStrCharRemove(LPTSTR szString, TCHAR chSkip);
+DWORD apxStrUnQuoteInplaceA(LPSTR szString);
+DWORD apxStrUnQuoteInplaceW(LPWSTR szString);
+
+BOOL apxUltohex(ULONG n, LPTSTR lpBuff, DWORD dwBuffLength);
+BOOL apxUptohex(ULONG_PTR n, LPTSTR lpBuff, DWORD dwBuffLength);
+ULONG apxStrToul(LPCTSTR szNum);
+ULONG apxStrToulW(LPCWSTR szNum);
+ULONG apxAtoulW(LPCWSTR szNum);
+
+BOOL apxMakeResourceName(LPCTSTR szPrefix, LPTSTR lpBuff,
+ DWORD dwBuffLength);
+
+INT apxStrMatchA(LPCSTR szString, LPCSTR szPattern, BOOL bIgnoreCase);
+INT apxStrMatchW(LPCWSTR szString, LPCWSTR szPattern, BOOL bIgnoreCase);
+INT apxMultiStrMatchW(LPCWSTR szString, LPCWSTR szPattern,
+ WCHAR chSeparator, BOOL bIgnoreCase);
+LPSTR apxArrayToMultiSzA(APXHANDLE hPool, DWORD nArgs, LPCSTR *lpArgs);
+void apxStrQuoteInplaceW(LPWSTR szString);
+LPWSTR apxMszToCRLFW(APXHANDLE hPool, LPCWSTR szStr);
+LPWSTR apxCRLFToMszW(APXHANDLE hPool, LPCWSTR szStr, LPDWORD lpdwBytes);
+LPSTR apxExpandStrA(APXHANDLE hPool, LPCSTR szString);
+LPWSTR apxExpandStrW(APXHANDLE hPool, LPCWSTR szString);
+void apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith);
+void apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith);
+
+
+LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill);
+void AplZeroMemory(PVOID Destination, SIZE_T Length);
+LPVOID AplCopyMemory(PVOID Destination, const VOID* Source, SIZE_T Length);
+/*
+ * Find the first occurrence of lpFind in lpMem.
+ * dwLen: The length of lpFind
+ * dwSize: The length of lpMem
+ */
+LPBYTE ApcMemSearch(LPCVOID lpMem, LPCVOID lpFind, SIZE_T dwLen, SIZE_T dwSize);
+LPSTR AplRindexA(LPCSTR lpStr, int ch);
+
+#define AplMoveMemory AplCopyMemory
+
+PSECURITY_ATTRIBUTES GetNullACL();
+void CleanNullACL(void *sa);
+
+__APXEND_DECLS
+
+#endif /* _APXWIN_H_INCLUDED_ */
+
Property changes on: trunk/utils/windows/native/service/procrun/include/apxwin.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/cmdline.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/cmdline.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/cmdline.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,77 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CMDLINE_H_INCLUDED_
+#define _CMDLINE_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define APXCMDOPT_NIL 0x00000000 /* Argopt value not needed */
+#define APXCMDOPT_INT 0x00000001 /* Argopt value is unsigned integer */
+#define APXCMDOPT_STR 0x00000002 /* Argopt value is string */
+#define APXCMDOPT_STE 0x00000006 /* Argopt value is expandable string */
+#define APXCMDOPT_MSZ 0x00000010 /* Multiline string '#' separated */
+#define APXCMDOPT_BIN 0x00000020 /* Encrypted binary */
+
+#define APXCMDOPT_REG 0x00000100 /* Save to registry */
+#define APXCMDOPT_SRV 0x00000200 /* Save to service registry */
+#define APXCMDOPT_USR 0x00000400 /* Save to user registry */
+
+#define APXCMDOPT_FOUND 0x00001000 /* The option is present in cmdline */
+#define APXCMDOPT_ADD 0x00002000 /* The option is present in cmdline as ++*/
+
+
+typedef struct APXCMDLINEOPT APXCMDLINEOPT;
+
+struct APXCMDLINEOPT {
+ LPWSTR szName; /* Long Argument Name */
+ LPWSTR szRegistry; /* Registry Association */
+ LPWSTR szSubkey; /* Registry Association */
+ DWORD dwType; /* Argument type (string, number, multistring */
+ LPWSTR szValue; /* Return string value */
+ DWORD dwValue; /* Return numeric value or present if NIL */
+};
+
+typedef struct APXCMDLINE {
+ APXCMDLINEOPT *lpOptions;
+ LPWSTR szExecutable; /* Parsed argv0 */
+ LPWSTR szExePath; /* Parsed argv0 */
+ LPWSTR szApplication; /* Fist string after //CMD// */
+ DWORD dwCmdIndex; /* Command index */
+ LPWSTR *lpArgvw;
+ DWORD dwArgc;
+ APXHANDLE hPool;
+
+} APXCMDLINE, *LPAPXCMDLINE;
+
+LPAPXCMDLINE apxCmdlineParse(
+ APXHANDLE hPool,
+ APXCMDLINEOPT *lpOptions,
+ LPCWSTR *lpszCommands
+);
+
+void apxCmdlineLoadEnvVars(
+ LPAPXCMDLINE lpCmdline
+);
+
+void apxCmdlineFree(
+ LPAPXCMDLINE lpCmdline
+);
+
+
+__APXEND_DECLS
+
+#endif /* _CMDLINE_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/cmdline.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/console.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/console.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/console.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,26 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONSOLE_H_INCLUDED_
+#define _CONSOLE_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+
+
+__APXEND_DECLS
+
+#endif /* _CONSOLE_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/console.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/gui.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/gui.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/gui.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,186 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _GUI_H_INCLUDED_
+#define _GUI_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+
+#define IDC_STATIC -1
+#define IDC_APPLICATION 100
+#define IDI_MAINICON 101
+#define IDC_STATBAR 102
+#define IDB_SUSERS 103
+
+#define IDS_APPLICATION 150
+#define IDS_APPDESCRIPTION 151
+#define IDS_APPVERSION 152
+#define IDS_APPCOPYRIGHT 153
+#define IDS_APPFULLNAME 154
+
+#define IDD_ABOUTBOX 250
+#define IDC_LICENSE 251
+#define IDR_LICENSE 252
+#define IAB_SYSINF 253
+#define IDC_ABOUTAPP 254
+
+#define IDD_PROGRESS 260
+#define IDDP_HEAD 261
+#define IDDP_TEXT 262
+#define IDDP_PROGRESS 263
+
+#define IDD_SELUSER 270
+#define IDSU_SELNAME 271
+#define IDSU_SELECTED 272
+#define IDSU_LIST 273
+#define IDSU_COMBO 274
+
+
+#define WM_TRAYMESSAGE (WM_APP+1)
+
+#define SNDMSGW SendMessageW
+#define SNDMSGA SendMessageA
+#define ComboBox_AddStringW(hwndCtl, lpsz) ((int)(DWORD)SNDMSGW((hwndCtl), CB_ADDSTRING, 0L, (LPARAM)(LPCWSTR)(lpsz)))
+
+#define ListView_SetItemTextW(hwndLV, i, iSubItem_, pszText_) \
+{ LV_ITEMW _ms_lvi;\
+ _ms_lvi.iSubItem = iSubItem_;\
+ _ms_lvi.pszText = pszText_;\
+ SNDMSG((hwndLV), LVM_SETITEMTEXTW, (WPARAM)(i), (LPARAM)(LV_ITEMW *)&_ms_lvi);\
+} ((void)0)
+
+#define ListView_GetItemTextA(hwndLV, i, iSubItem_, pszText_, cchTextMax_) \
+{ LV_ITEMA _ms_lvi;\
+ _ms_lvi.iSubItem = iSubItem_;\
+ _ms_lvi.cchTextMax = cchTextMax_;\
+ _ms_lvi.pszText = pszText_;\
+ SNDMSGA((hwndLV), LVM_GETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&_ms_lvi);\
+} ((void)0)
+
+#define ListView_GetItemTextW(hwndLV, i, iSubItem_, pszText_, cchTextMax_) \
+{ LV_ITEMW _ms_lvi;\
+ _ms_lvi.iSubItem = iSubItem_;\
+ _ms_lvi.cchTextMax = cchTextMax_;\
+ _ms_lvi.pszText = pszText_;\
+ SNDMSG((hwndLV), LVM_GETITEMTEXTW, (WPARAM)(i), (LPARAM)(LV_ITEMW *)&_ms_lvi);\
+} ((void)0)
+
+#define ListView_InsertItemW(hwnd, pitem) \
+ (int)SNDMSGW((hwnd), LVM_INSERTITEMW, 0, (LPARAM)(const LV_ITEMW *)(pitem))
+
+typedef struct APXLVITEM {
+ INT iPosition;
+ BOOL bSortable;
+ INT iWidth;
+ INT iDefault;
+ INT iFmt;
+ LPTSTR szLabel;
+} APXLVITEM, *LPAPXLVITEM;
+
+typedef struct APXGUISTATE {
+ DWORD dwShow;
+ RECT rcPosition;
+ COLORREF bgColor;
+ COLORREF fgColor;
+ COLORREF txColor;
+ INT nColumnWidth[32];
+ INT nUser[8];
+} APXGUISTATE, *LPAPXGUISTATE;
+
+typedef struct APXGUISTORE {
+ HANDLE hInstance;
+ HICON hIcon;
+ HICON hIconSm;
+ HICON hIconHg;
+ HWND hMainWnd;
+ HACCEL hAccel;
+ TCHAR szWndClass[256];
+ TCHAR szWndMutex[256];
+ APXGUISTATE stState;
+ STARTUPINFO stStartupInfo;
+ UINT nWhellScroll;
+
+} APXGUISTORE, *LPAPXGUISTORE;
+
+LPAPXGUISTORE apxGuiInitialize(WNDPROC lpfnWndProc, LPCTSTR szAppName);
+
+BOOL apxCenterWindow(HWND hwndChild, HWND hwndParent);
+
+LPSTR apxLoadResourceA(UINT wID, UINT nBuf);
+LPWSTR apxLoadResourceW(UINT wID, UINT nBuf);
+
+
+void apxAppendMenuItem(HMENU hMenu, UINT idMenu, LPCTSTR szName,
+ BOOL bDefault, BOOL bEnabled);
+void apxAppendMenuItemBmp(HMENU hMenu, UINT idMenu, LPCTSTR szName);
+
+void apxManageTryIconA(HWND hWnd, DWORD dwMessage, LPCSTR szInfoTitle,
+ LPCSTR szInfo, HICON hIcon);
+void apxManageTryIconW(HWND hWnd, DWORD dwMessage, LPCWSTR szInfoTitle,
+ LPCWSTR szInfo, HICON hIcon);
+#ifdef _UNICODE
+#define apxLoadResource apxLoadResourceW
+#else
+#define apxLoadResource apxLoadResourceA
+#endif
+
+void apxAboutBox(HWND hWnd);
+int apxProgressBox(HWND hWnd, LPCTSTR szHeader,
+ LPCWSTR szText,
+ LPAPXFNCALLBACK fnProgressCallback,
+ LPVOID cbData);
+BOOL apxYesNoMessage(LPCTSTR szTitle, LPCTSTR szMessage, BOOL bStop);
+
+BOOL apxCalcStringEllipsis(HDC hDC, LPTSTR szString,
+ int cchMax, UINT uColWidth);
+LPWSTR apxGetDlgTextW(APXHANDLE hPool, HWND hDlg, int nIDDlgItem);
+LPSTR apxGetDlgTextA(APXHANDLE hPool, HWND hDlg, int nIDDlgItem);
+
+#ifdef _UNICODE
+#define apxGetDlgText apxGetDlgTextW
+#else
+#define apxGetDlgText apxGetDlgTextA
+#endif
+
+LPSTR apxBrowseForFolderA(HWND hWnd, LPCSTR szTitle, LPCSTR szName);
+LPWSTR apxBrowseForFolderW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szName);
+
+#ifdef _UNICODE
+#define apxBrowseForFolder apxBrowseForFolderW
+#else
+#define apxBrowseForFolder apxBrowseForFolderA
+#endif
+
+LPSTR apxGetFileNameA(HWND hWnd, LPCSTR szTitle, LPCSTR szFilter,
+ LPCSTR szDefExt, LPCSTR szDefPath, BOOL bOpenOrSave,
+ LPDWORD lpdwFindex);
+
+LPWSTR apxGetFileNameW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szFilter,
+ LPCWSTR szDefExt, LPCWSTR szDefPath, BOOL bOpenOrSave,
+ LPDWORD lpdwFindex);
+
+#ifdef _UNICODE
+#define apxGetFileName apxGetFileNameW
+#else
+#define apxGetFileName apxGetFileNameA
+#endif
+
+LPCWSTR apxDlgSelectUser(HWND hWnd, LPWSTR szUser);
+
+__APXEND_DECLS
+
+#endif /* _GUI_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/gui.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/handles.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/handles.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/handles.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,192 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _HANDLES_H_INCLUDED_
+#define _HANDLES_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define SAFE_CLOSE_HANDLE(h) \
+ if ((h) != NULL && (h) != INVALID_HANDLE_VALUE) { \
+ CloseHandle((h)); \
+ (h) = NULL; \
+ }
+
+typedef struct stAPXHANDLE stAPXHANDLE;
+typedef stAPXHANDLE* APXHANDLE;
+
+/**
+ * Alignment macros
+ */
+
+/* APR_ALIGN() is only to be used to align on a power of 2 boundary */
+#define APX_ALIGN(size, boundary) \
+ (((size) + ((boundary) - 1)) & ~((boundary) - 1))
+
+/** Default alignment */
+#define APX_ALIGN_DEFAULT(size) APX_ALIGN(size, 16)
+
+
+/** Handle callback function prototype */
+typedef BOOL (*LPAPXFNCALLBACK)(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam);
+
+#if _MSC_VER >= 1300
+#define APXHANDLE_INVALID ((void *)0xdeadbeefLL)
+#else
+#define APXHANDLE_INVALID ((void *)0xdeadbeefL)
+#endif
+
+#define APXHANDLE_HOOK_FIRST 0
+#define APXHANDLE_HOOK_LAST 1
+
+/** Flags */
+/** handle has its own heap */
+#define APXHANDLE_HAS_HEAP 0x00000001
+/** handle has CriticalSection */
+#define APXHANDLE_HAS_LOCK 0x00000002
+/** handle owns the CriticalSection */
+#define APXHANDLE_OWNS_LOCK 0x00000006
+/** handle has EventThread */
+#define APXHANDLE_HAS_EVENT 0x00000010
+/** handle has UserData */
+#define APXHANDLE_HAS_USERDATA 0x00000020
+
+/** Types */
+#define APXHANDLE_TYPE_INVALID 0xdeadbeef
+#define APXHANDLE_TYPE_POOL 0x01000000
+#define APXHANDLE_TYPE_WINHANDLE 0x02000000
+#define APXHANDLE_TYPE_SERVICE 0x03000000
+#define APXHANDLE_TYPE_LPTR 0x04000000
+#define APXHANDLE_TYPE_CONSOLE 0x05000000
+#define APXHANDLE_TYPE_PROCESS 0x06000000
+#define APXHANDLE_TYPE_JVM 0x07000000
+#define APXHANDLE_TYPE_REGISTRY 0x08000000
+
+/** Initialize the Handle manager
+ * reference counted
+ */
+BOOL apxHandleManagerInitialize();
+/** Destroys the Handle manager
+ * reference counted
+ */
+BOOL apxHandleManagerDestroy();
+/** Create the memory pool
+ * param: hParent parent pool or NULL to use the system pool
+ * dwOptions OR'd flags: APXHANDLE_HAS_HEAP,
+ * APXHANDLE_HAS_LOCK
+ * APXHANDLE_OWNS_LOCK
+ */
+APXHANDLE apxPoolCreate(APXHANDLE hParent, DWORD dwOptions);
+/** Create the memory pool
+ * param: hPpool pool to allocate from or NULL for system pool
+ * dwOptions OR'd flags: see APXHANDLE_TYPE_ and APXHANDLE_HAS_
+ * values
+ * lpData user supplied Data
+ * dwDataSize extra pool user data size, combined with options
+ * the lpData is copied to the internal storage;
+ * fnCallback Optional handle callback function
+ */
+APXHANDLE apxHandleCreate(APXHANDLE hPool, DWORD dwOptions,
+ LPVOID lpData, DWORD dwDataSize,
+ LPAPXFNCALLBACK fnCallback);
+/** Close the handle
+ * Calls the callback function and frees the memory
+ */
+BOOL apxCloseHandle(APXHANDLE hObject);
+/** Get The internal user data
+ */
+LPVOID apxHandleGetUserData(APXHANDLE hObject);
+/** Set The internal user data
+ * params:
+ * lpData user supplied Data
+ * dwDataSize user data size, combined with create options
+ * the lpData is either copied to the internal storage
+ * or assigned.
+ */
+LPVOID apxHandleSetUserData(APXHANDLE hObject, LPVOID lpData,
+ DWORD dwDataSize);
+/** Send the message to the handle
+ * Callback function is executed with WM_COMMAND uMsg
+ */
+BOOL apxHandleSendMessage(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam);
+
+/** Post the message to the handle
+ * function returns imediately.
+ */
+BOOL apxHandlePostMessage(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam);
+/** Lock or unlock the handle
+ * If bLock is true lock the handle, otherwise unlock.
+ */
+BOOL apxHandleLock(APXHANDLE hObject, BOOL bLock);
+
+/** Add the callback to the handles hook chain
+ *
+ */
+BOOL apxHandleAddHook(APXHANDLE hObject, DWORD dwWhere,
+ LPAPXFNCALLBACK fnCallback);
+
+DWORD apxHandleWait(APXHANDLE hHandle, DWORD dwMilliseconds,
+ BOOL bKill);
+
+/** General pool memory allocation functions
+ */
+LPVOID apxPoolAlloc(APXHANDLE hPool, DWORD dwSize);
+LPVOID apxPoolCalloc(APXHANDLE hPool, DWORD dwSize);
+LPVOID apxPoolRealloc(APXHANDLE hPool, LPVOID lpMem, DWORD dwNewSize);
+LPTSTR apxPoolStrdup(APXHANDLE hPool, LPCTSTR szSource);
+
+/** General system pool memory allocation functions
+ */
+
+LPVOID apxAlloc(DWORD dwSize);
+LPVOID apxCalloc(DWORD dwSize);
+LPVOID apxRealloc(LPVOID lpMem, DWORD dwNewSize);
+
+LPSTR apxStrdupA(LPCSTR szSource);
+LPWSTR apxStrdupW(LPCWSTR szSource);
+LPSTR apxPoolStrdupA(APXHANDLE hPool, LPCSTR szSource);
+LPWSTR apxPoolStrdupW(APXHANDLE hPool, LPCWSTR szSource);
+
+LPWSTR apxPoolWStrdupA(APXHANDLE hPool, LPCSTR szSource);
+
+#define apxPoolWStrdupW apxPoolStrdupW
+
+#ifdef _UNICODE
+#define apxStrdup apxStrdupW
+#define apxPoolStrdup apxPoolStrdupW
+#else
+#define apxStrdup apxStrdupA
+#define apxPoolStrdup apxPoolStrdupW
+#endif
+
+#ifndef _UNICODE
+#define apxPoolWStrdup apxPoolWStrdupA
+#define apxWStrdup apxWStrdupA
+#else
+#define apxPoolWStrdup apxPoolStrdupW
+#define apxWStrdup apxStrdupW
+#endif
+/** Free the allocated memory
+ * It will call te correct pool if the address is valid
+ */
+VOID apxFree(LPVOID lpMem);
+
+__APXEND_DECLS
+
+#endif /* _HANDLES_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/handles.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/javajni.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/javajni.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/javajni.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _JAVAJNI_H_INCLUDED_
+#define _JAVAJNI_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+APXHANDLE apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath);
+
+BOOL apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
+ LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
+ DWORD dwSs);
+
+BOOL apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szMethodName,
+ LPCVOID lpArguments);
+
+BOOL apxJavaStart(APXHANDLE hJava);
+
+DWORD apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill);
+
+BOOL apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut,
+ LPCWSTR szFilename);
+
+
+__APXEND_DECLS
+
+#endif /* _JAVAJNI_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/javajni.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/log.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/log.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/log.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,102 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Logfile handling
+ * Use Systemdir/Logfiles/Apache as a default path
+ */
+
+#ifndef _LOG_H_INCLUDED_
+#define _LOG_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define APX_LOGLOCK(file) \
+ APXMACRO_BEGIN \
+ DWORD _lmax = 0; \
+ while(!LockFile(file, 0, 0, 512, 0)) { \
+ Sleep(10); \
+ if (_lmax++ > 1000) break; \
+ } \
+ SetFilePointer(file, 0, NULL, FILE_END); \
+ APXMACRO_END
+
+#define APX_LOGUNLOCK(file) \
+ APXMACRO_BEGIN \
+ UnlockFile(file, 0, 0, 512, 0); \
+ APXMACRO_END
+
+#define APXLOG_LEVEL_DEBUG 0
+#define APXLOG_LEVEL_INFO 1
+#define APXLOG_LEVEL_WARN 2
+#define APXLOG_LEVEL_ERROR 3
+
+#define APXLOG_MARK_INFO NULL, APXLOG_LEVEL_INFO, TRUE, NULL, 0, ""
+#define APXLOG_MARK_WARN NULL, APXLOG_LEVEL_WARN, TRUE, NULL, 0, ""
+#define APXLOG_MARK_ERROR NULL, APXLOG_LEVEL_ERROR, TRUE, __FILE__, __LINE__, ""
+#define APXLOG_MARK_DEBUG NULL, APXLOG_LEVEL_DEBUG, TRUE, __FILE__, __LINE__, ""
+#define APXLOG_MARK_RAW NULL, APXLOG_LEVEL_INFO, FALSE, NULL, 0,
+#define APXLOG_MARK_SYSERR NULL, APXLOG_LEVEL_ERROR, TRUE, __FILE__, __LINE__, NULL
+
+LPWSTR apxLogFile(
+ APXHANDLE hPool,
+ LPCWSTR szPath,
+ LPCWSTR szPrefix,
+ LPCWSTR szName
+);
+
+HANDLE apxLogOpen(
+ APXHANDLE hPool,
+ LPCWSTR szPath,
+ LPCWSTR szPrefix
+);
+
+void apxLogClose(
+ HANDLE hFile
+);
+
+void apxLogLevelSet(
+ HANDLE hFile,
+ DWORD dwLevel
+);
+
+void apxLogLevelSetW(
+ HANDLE hFile,
+ LPCWSTR szLevel
+);
+
+int
+apxLogWrite(
+ HANDLE hFile,
+ DWORD dwLevel,
+ BOOL bTimeStamp,
+ LPCSTR szFile,
+ DWORD dwLine,
+ LPCSTR szFormat,
+ ...
+);
+
+int
+apxDisplayError(
+ BOOL bDisplay,
+ LPCSTR szFile,
+ DWORD dwLine,
+ LPCSTR szFormat,
+ ...
+);
+
+__APXEND_DECLS
+
+#endif /* _LOG_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/log.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/registry.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/registry.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/registry.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,145 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _REGISTRY_H_INCLUDED_
+#define _REGISTRY_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define APXREG_SOFTWARE 0x0001
+#define APXREG_SERVICE 0x0002
+#define APXREG_USER 0x0004
+
+#define APXREG_PARAMSOFTWARE 0x0010
+#define APXREG_PARAMSERVICE 0x0020
+#define APXREG_PARAMUSER 0x0040
+
+/** Create or open the process registry keys
+ */
+APXHANDLE apxCreateRegistryA(APXHANDLE hPool, REGSAM samDesired,
+ LPCSTR szRoot, LPCSTR szKeyName,
+ DWORD dwOptions);
+APXHANDLE apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired,
+ LPCWSTR szRoot, LPCWSTR szKeyName,
+ DWORD dwOptions);
+
+#ifdef _UNICODE
+#define apxCreateRegistry apxCreateRegistryW
+#else
+#define apxCreateRegistry apxCreateRegistryA
+#endif
+
+/** Delete the process registry keys
+ */
+BOOL apxDeleteRegistryA(LPCSTR szRoot, LPCSTR szKeyName,
+ BOOL bDeleteEmpty);
+
+BOOL apxDeleteRegistryW(LPCWSTR szRoot, LPCWSTR szKeyName,
+ BOOL bDeleteEmpty);
+
+#ifdef _UNICODE
+#define apxDeleteRegistry apxDeleteRegistryW
+#else
+#define apxDeleteRegistry apxDeleteRegistryA
+#endif
+
+/** Get the JavaHome path from registry
+ * and set the JAVA_HOME environment variable if not found
+ * If bPreferJre is set use the JRE's path as JAVA_HOME
+ */
+LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre);
+
+/** Get the Java RuntimeLib from registry (jvm.dll)
+ */
+LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool);
+
+LPSTR apxRegistryGetStringA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName);
+
+LPWSTR apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName);
+
+#ifdef _UNICODE
+#define apxRegistryGetString apxRegistryGetStringW
+#else
+#define apxRegistryGetString apxRegistryGetStringA
+#endif
+
+LPBYTE apxRegistryGetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ LPBYTE lpData, LPDWORD lpdwLength);
+
+LPBYTE apxRegistryGetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPBYTE lpData, LPDWORD lpdwLength);
+
+#ifdef _UNICODE
+#define apxRegistryGetBinary apxRegistryGetBinaryW
+#else
+#define apxRegistryGetBinary apxRegistryGetBinaryA
+#endif
+
+BOOL apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ const LPBYTE lpData, DWORD dwLength);
+
+BOOL apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ const LPBYTE lpData, DWORD dwLength);
+
+LPWSTR apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPWSTR lpData, LPDWORD lpdwLength);
+
+BOOL apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPCWSTR lpData, DWORD dwLength);
+
+BOOL apxRegistrySetStrA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ LPCSTR szValue);
+
+BOOL apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPCWSTR szValue);
+
+
+#ifdef _UNICODE
+#define apxRegistrySetStr apxRegistrySetStrW
+#else
+#define apxRegistrySetStr apxRegistrySetStrA
+#endif
+
+BOOL apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ DWORD dwValue);
+
+DWORD apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName);
+
+
+BOOL apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName);
+
+#ifdef _UNICODE
+#define apxRegistryDelete apxRegistryDeleteW
+#else
+#define apxRegistryDelete apxRegistryDeleteA
+#endif
+
+__APXEND_DECLS
+
+#endif /* _REGISTRY_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/registry.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/rprocess.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/rprocess.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/rprocess.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,76 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _RPROCESS_H_INCLUDED_
+#define _RPROCESS_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+BOOL apxProcessExecute(APXHANDLE hProcess);
+
+APXHANDLE apxCreateProcessA(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCSTR szUsername, LPCSTR szPassword,
+ BOOL bLogonAsService);
+APXHANDLE apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCWSTR szUsername, LPCWSTR szPassword,
+ BOOL bLogonAsService);
+
+#ifdef _UNICODE
+#define apxCreateProcess apxCreateProcessW
+#else
+#define apxCreateProcess apxCreateProcessA
+#endif
+
+BOOL apxProcessSetExecutableA(APXHANDLE hProcess, LPCSTR szName);
+BOOL apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName);
+
+BOOL apxProcessSetCommandLineA(APXHANDLE hProcess, LPCSTR szCmdline);
+BOOL apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline);
+BOOL apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle,
+ DWORD dwArgc, LPCWSTR *lpArgs);
+
+BOOL apxProcessSetWorkingPathA(APXHANDLE hProcess, LPCSTR szPath);
+BOOL apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath);
+
+DWORD apxProcessPutcA(APXHANDLE hProcess, INT ch);
+DWORD apxProcessPutcW(APXHANDLE hProcess, INT ch);
+DWORD apxProcessPutsA(APXHANDLE hProcess, LPCSTR szString);
+DWORD apxProcessPutsW(APXHANDLE hProcess, LPCWSTR szString);
+
+#ifndef _UNICODE
+#define apxProcessPutc apxProcessPutcA
+#define apxProcessPuts apxProcessPutsA
+#else
+#define apxProcessPutc apxProcessPutcW
+#define apxProcessPuts apxProcessPutsW
+#endif
+
+DWORD apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen);
+
+VOID apxProcessCloseInputStream(APXHANDLE hProcess);
+BOOL apxProcessFlushStdin(APXHANDLE hProcess);
+
+DWORD apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds,
+ BOOL bKill);
+
+BOOL apxProcessRunning(APXHANDLE hProcess);
+
+
+__APXEND_DECLS
+
+#endif /* _RPROCESS_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/rprocess.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/include/service.h
===================================================================
--- trunk/utils/windows/native/service/procrun/include/service.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/include/service.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,75 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _SERVICE_H_INCLUDED_
+#define _SERVICE_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+typedef struct APXSERVENTRY {
+ WCHAR szServiceName[SIZ_RESLEN];
+ WCHAR szObjectName[SIZ_RESLEN];
+ WCHAR szServiceDescription[SIZ_DESLEN];
+ DWORD dwStart;
+ LPQUERY_SERVICE_CONFIGW lpConfig;
+ SERVICE_STATUS stServiceStatus;
+ SERVICE_STATUS_PROCESS stStatusProcess;
+
+} APXSERVENTRY, *LPAPXSERVENTRY;
+
+
+APXHANDLE apxCreateService(APXHANDLE hPool, DWORD dwOptions,
+ BOOL bManagerMode);
+
+BOOL apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions);
+
+
+BOOL apxServiceSetNames(APXHANDLE hService, LPCWSTR szImagePath,
+ LPCWSTR szDisplayName, LPCWSTR szDescription,
+ LPCWSTR szUsername, LPCWSTR szPassword);
+
+BOOL apxServiceSetOptions(APXHANDLE hService, DWORD dwServiceType,
+ DWORD dwStartType, DWORD dwErrorControl);
+
+BOOL apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
+ LPAPXFNCALLBACK fnControlCallback,
+ LPVOID lpCbData);
+BOOL apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
+ LPCWSTR szDisplayName, LPCWSTR szImagePath,
+ LPCWSTR lpDependencies, DWORD dwServiceType,
+ DWORD dwStartType);
+
+LPAPXSERVENTRY apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus);
+
+/** Delete te service
+ * Stops the service if running
+ */
+BOOL apxServiceDelete(APXHANDLE hService);
+
+DWORD apxServiceBrowse(APXHANDLE hService,
+ LPCWSTR szIncludeNamePattern,
+ LPCWSTR szIncludeImagePattern,
+ LPCWSTR szExcludeNamePattern,
+ LPCWSTR szExcludeImagePattern,
+ UINT uMsg,
+ LPAPXFNCALLBACK fnDisplayCallback,
+ LPVOID lpCbData);
+
+DWORD apxGetMaxServiceTimeout(APXHANDLE hPool);
+
+__APXEND_DECLS
+
+#endif /* _SERVICE_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/include/service.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/resources/jboss.ico
===================================================================
(Binary files differ)
Property changes on: trunk/utils/windows/native/service/procrun/resources/jboss.ico
___________________________________________________________________
Name: svn:mime-type
+ image/x-icon
Added: trunk/utils/windows/native/service/procrun/resources/jbosslogo.bmp
===================================================================
(Binary files differ)
Property changes on: trunk/utils/windows/native/service/procrun/resources/jbosslogo.bmp
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/utils/windows/native/service/procrun/resources/license.rtf
===================================================================
--- trunk/utils/windows/native/service/procrun/resources/license.rtf (rev 0)
+++ trunk/utils/windows/native/service/procrun/resources/license.rtf 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,523 @@
+{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fswiss\fcharset238\fprq2{\*\panose 020b0604020202020204}Arial;}{\f39\froman\fcharset0\fprq2 Times New Roman;}
+{\f38\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f40\froman\fcharset161\fprq2 Times New Roman Greek;}{\f41\froman\fcharset162\fprq2 Times New Roman Tur;}{\f42\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}
+{\f43\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f44\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f45\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f49\fswiss\fcharset0\fprq2 Arial;}
+{\f48\fswiss\fcharset204\fprq2 Arial Cyr;}{\f50\fswiss\fcharset161\fprq2 Arial Greek;}{\f51\fswiss\fcharset162\fprq2 Arial Tur;}{\f52\fbidi \fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f53\fbidi \fswiss\fcharset178\fprq2 Arial (Arabic);}
+{\f54\fswiss\fcharset186\fprq2 Arial Baltic;}{\f55\fswiss\fcharset163\fprq2 Arial (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;
+\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{
+\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden
+Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tblind0\tblindtype3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv
+\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs20 \ltrch\fcs0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}
+{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\rsidtbl \rsid16733255}{\*\generator Microsoft Word 11.0.0000;}{\info{\operator Mladen Turk}{\creatim\yr2008\mo2\dy19\hr17\min13}{\revtim\yr2008\mo2\dy19\hr17\min13}{\version2}{\edmins0}{\nofpages16}
+{\nofwords3944}{\nofchars22486}{\nofcharsws26378}{\vern24611}{\*\password 00000000}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}{\xmlns2 urn:schemas-microsoft-com:office:smarttags}}
+\paperw12240\paperh15840\margl1417\margr1417\margt1417\margb1417\gutter0\ltrsect
+\widowctrl\ftnbj\aenddoc\donotembedsysfont0\donotembedlingdata1\grfdocevents0\validatexml0\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3
+\jcompress\viewkind4\viewscale100\rsidroot16733255 \fet0{\*\wgrffmtfilter 013f}\ilfomacatclnup0\ltrpar \sectd \ltrsect\linex0\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2
+\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6
+\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang
+{\pntxtb (}{\pntxta )}}\pard\plain \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af1 \ltrch\fcs0 \f1\insrsid16733255
+\tab \tab }{\rtlch\fcs1 \af1 \ltrch\fcs0 \b\f1\insrsid16733255\charrsid16733255 GNU LESSER GENERAL PUBLIC LICENSE
+\par }{\rtlch\fcs1 \af1 \ltrch\fcs0 \f1\insrsid16733255 \tab \tab Version 2.1, February 1999
+\par
+\par Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+\par {\*\xmlopen\xmlns2{\factoidname country-region}}{\*\xmlopen\xmlns2{\factoidname Street}}59 Temple Place, Suite 330{\*\xmlclose}, {\*\xmlopen\xmlns2{\factoidname country-region}}Boston{\*\xmlclose}, {\*\xmlopen\xmlns2{\factoidname country-region}}MA
+{\*\xmlclose} {\*\xmlopen\xmlns2{\factoidname country-region}}02111-1307{\*\xmlclose} {\*\xmlopen\xmlns2{\factoidname country-region}}USA{\*\xmlclose}{\*\xmlclose}
+\par Everyone is permitted to copy and distribute verbatim copies
+\par of this license document, but changing it is not allowed.
+\par
+\par [This is the first released version of the Lesser GPL. It also counts
+\par as the successor of the GNU Library Public License, version 2, hence
+\par the version number 2.1.]
+\par
+\par \tab \tab \tab Preamble
+\par
+\par The licenses for most software are designed to take away your
+\par freedom to share and change it. By contrast, the GNU General Public
+\par Licenses are intended to guarantee your freedom to share and change
+\par free software--to make sure the software is free for all its users.
+\par
+\par This license, the Lesser General Public License, applies to some
+\par specially designated software packages--typically libraries--of the
+\par Free Software Foundation and other authors who decide to use it. You
+\par can use it too, but we suggest you first think carefully about whether
+\par this license or the ordinary General Public License is the better
+\par strategy to use in any particular case, based on the explanations below.
+\par
+\par When we speak of free software, we are referring to freedom of use,
+\par not price. Our General Public Licenses are designed to make sure that
+\par you have the freedom to distribute copies of free software (and charge
+\par for this service if you wish); that you receive source code or can get
+\par it if you want it; that you can change the software and use pieces of
+\par it in new free programs; and that you are informed that you can do
+\par these things.
+\par
+\par To protect your rights, we need to make restrictions that forbid
+\par distributors to deny you these rights or to ask you to surrender these
+\par rights. These restrictions translate to certain responsibilities for
+\par you if you distribute copies of the library or if you modify it.
+\par
+\par For example, if you distribute copies of the library, whether gratis
+\par or for a fee, you must give the recipients all the rights that we gave
+\par you. You must make sure that they, too, receive or can get the source
+\par code. If you link other code with the library, you must provide
+\par complete object files to the recipients, so that they can relink them
+\par with the library after making changes to the library and recompiling
+\par it. And you must show them these terms so they know their rights.
+\par
+\par We protect your rights with a two-step method: (1) we copyright the
+\par library, and (2) we offer you this license, which gives you legal
+\par permission to copy, distribute and/or modify the library.
+\par
+\par To protect each distributor, we want to make it very clear that
+\par there is no warranty for the free library. Also, if the library is
+\par modified by someone else and passed on, the recipients should know
+\par that what they have is not the original version, so that the original
+\par author's reputation will not be affected by problems that might be
+\par introduced by others.
+\par \page
+\par Finally, software patents pose a constant threat to the existence of
+\par any free program. We wish to make sure that a company cannot
+\par effectively restrict the users of a free program by obtaining a
+\par restrictive license from a patent holder. Therefore, we insist that
+\par any patent license obtained for a version of the library must be
+\par consistent with the full freedom of use specified in this license.
+\par
+\par Most GNU software, including some libraries, is covered by the
+\par ordinary GNU General Public License. This license, the GNU Lesser
+\par General Public License, applies to certain designated libraries, and
+\par is quite different from the ordinary General Public License. We use
+\par this license for certain libraries in order to permit linking those
+\par libraries into non-free programs.
+\par
+\par When a program is linked with a library, whether statically or using
+\par a shared library, the combination of the two is legally speaking a
+\par combined work, a derivative of the original library. The ordinary
+\par General Public License therefore permits such linking only if the
+\par entire combination fits its criteria of freedom. The Lesser General
+\par Public License permits more lax criteria for linking other code with
+\par the library.
+\par
+\par We call this license the "Lesser" General Public License because it
+\par does Less to protect the user's freedom than the ordinary General
+\par Public License. It also provides other free software developers Less
+\par of an advantage over competing non-free programs. These disadvantages
+\par are the reason we use the ordinary General Public License for many
+\par libraries. However, the Lesser license provides advantages in certain
+\par special circumstances.
+\par
+\par For example, on rare occasions, there may be a special need to
+\par encourage the widest possible use of a certain library, so that it becomes
+\par a de-facto standard. To achieve this, non-free programs must be
+\par allowed to use the library. A more frequent case is that a free
+\par library does the same job as widely used non-free libraries. In this
+\par case, there is little to gain by limiting the free library to free
+\par software only, so we use the Lesser General Public License.
+\par
+\par In other cases, permission to use a particular library in non-free
+\par programs enables a greater number of people to use a large body of
+\par free software. For example, permission to use the GNU C Library in
+\par non-free programs enables many more people to use the whole GNU
+\par operating system, as well as its variant, the GNU/Linux operating
+\par system.
+\par
+\par Although the Lesser General Public License is Less protective of the
+\par users' freedom, it does ensure that the user of a program that is
+\par linked with the Library has the freedom and the wherewithal to run
+\par that program using a modified version of the Library.
+\par
+\par The precise terms and conditions for copying, distribution and
+\par modification follow. Pay close attention to the difference between a
+\par "work based on the library" and a "work that uses the library". The
+\par former contains code derived from the library, whereas the latter must
+\par be combined with the library in order to run.
+\par \page
+\par \tab \tab GNU LESSER GENERAL PUBLIC LICENSE
+\par TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+\par
+\par 0. This License Agreement applies to any software library or other
+\par program which contains a notice placed by the copyright holder or
+\par other authorized party saying it may be distributed under the terms of
+\par this Lesser General Public License (also called "this License").
+\par Each licensee is addressed as "you".
+\par
+\par A "library" means a collection of software functions and/or data
+\par prepared so as to be conveniently linked with application programs
+\par (which use some of those functions and data) to form executables.
+\par
+\par The "Library", below, refers to any such software library or work
+\par which has been distributed under these terms. A "work based on the
+\par Library" means either the Library or any derivative work under
+\par copyright law: that is to say, a work containing the Library or a
+\par portion of it, either verbatim or with modifications and/or translated
+\par straightforwardly into another language. (Hereinafter, translation is
+\par included without limitation in the term "modification".)
+\par
+\par "Source code" for a work means the preferred form of the work for
+\par making modifications to it. For a library, complete source code means
+\par all the source code for all modules it contains, plus any associated
+\par interface definition files, plus the scripts used to control compilation
+\par and installation of the library.
+\par
+\par Activities other than copying, distribution and modification are not
+\par covered by this License; they are outside its scope. The act of
+\par running a program using the Library is not restricted, and output from
+\par such a program is covered only if its contents constitute a work based
+\par on the Library (independent of the use of the Library in a tool for
+\par writing it). Whether that is true depends on what the Library does
+\par and what the program that uses the Library does.
+\par
+\par 1. You may copy and distribute verbatim copies of the Library's
+\par complete source code as you receive it, in any medium, provided that
+\par you conspicuously and appropriately publish on each copy an
+\par appropriate copyright notice and disclaimer of warranty; keep intact
+\par all the notices that refer to this License and to the absence of any
+\par warranty; and distribute a copy of this License along with the
+\par Library.
+\par
+\par You may charge a fee for the physical act of transferring a copy,
+\par and you may at your option offer warranty protection in exchange for a
+\par fee.
+\par \page
+\par 2. You may modify your copy or copies of the Library or any portion
+\par of it, thus forming a work based on the Library, and copy and
+\par distribute such modifications or work under the terms of Section 1
+\par above, provided that you also meet all of these conditions:
+\par
+\par a) The modified work must itself be a software library.
+\par
+\par b) You must cause the files modified to carry prominent notices
+\par stating that you changed the files and the date of any change.
+\par
+\par c) You must cause the whole of the work to be licensed at no
+\par charge to all third parties under the terms of this License.
+\par
+\par d) If a facility in the modified Library refers to a function or a
+\par table of data to be supplied by an application program that uses
+\par the facility, other than as an argument passed when the facility
+\par is invoked, then you must make a good faith effort to ensure that,
+\par in the event an application does not supply such function or
+\par table, the facility still operates, and performs whatever part of
+\par its purpose remains meaningful.
+\par
+\par (For example, a function in a library to compute square roots has
+\par a purpose that is entirely well-defined independent of the
+\par application. Therefore, Subsection 2d requires that any
+\par application-supplied function or table used by this function must
+\par be optional: if the application does not supply it, the square
+\par root function must still compute square roots.)
+\par
+\par These requirements apply to the modified work as a whole. If
+\par identifiable sections of that work are not derived from the Library,
+\par and can be reasonably considered independent and separate works in
+\par themselves, then this License, and its terms, do not apply to those
+\par sections when you distribute them as separate works. But when you
+\par distribute the same sections as part of a whole which is a work based
+\par on the Library, the distribution of the whole must be on the terms of
+\par this License, whose permissions for other licensees extend to the
+\par entire whole, and thus to each and every part regardless of who wrote
+\par it.
+\par
+\par Thus, it is not the intent of this section to claim rights or contest
+\par your rights to work written entirely by you; rather, the intent is to
+\par exercise the right to control the distribution of derivative or
+\par collective works based on the Library.
+\par
+\par In addition, mere aggregation of another work not based on the Library
+\par with the Library (or with a work based on the Library) on a volume of
+\par a storage or distribution medium does not bring the other work under
+\par the scope of this License.
+\par
+\par 3. You may opt to apply the terms of the ordinary GNU General Public
+\par License instead of this License to a given copy of the Library. To do
+\par this, you must alter all the notices that refer to this License, so
+\par that they refer to the ordinary GNU General Public License, version 2,
+\par instead of to this License. (If a newer version than version 2 of the
+\par ordinary GNU General Public License has appeared, then you can specify
+\par that version instead if you wish.) Do not make any other change in
+\par these notices.
+\par \page
+\par Once this change is made in a given copy, it is irreversible for
+\par that copy, so the ordinary GNU General Public License applies to all
+\par subsequent copies and derivative works made from that copy.
+\par
+\par This option is useful when you wish to copy part of the code of
+\par the Library into a program that is not a library.
+\par
+\par 4. You may copy and distribute the Library (or a portion or
+\par derivative of it, under Section 2) in object code or executable form
+\par under the terms of Sections 1 and 2 above provided that you accompany
+\par it with the complete corresponding machine-readable source code, which
+\par must be distributed under the terms of Sections 1 and 2 above on a
+\par medium customarily used for software interchange.
+\par
+\par If distribution of object code is made by offering access to copy
+\par from a designated place, then offering equivalent access to copy the
+\par source code from the same place satisfies the requirement to
+\par distribute the source code, even though third parties are not
+\par compelled to copy the source along with the object code.
+\par
+\par 5. A program that contains no derivative of any portion of the
+\par Library, but is designed to work with the Library by being compiled or
+\par linked with it, is called a "work that uses the Library". Such a
+\par work, in isolation, is not a derivative work of the Library, and
+\par therefore falls outside the scope of this License.
+\par
+\par However, linking a "work that uses the Library" with the Library
+\par creates an executable that is a derivative of the Library (because it
+\par contains portions of the Library), rather than a "work that uses the
+\par library". The executable is therefore covered by this License.
+\par Section 6 states terms for distribution of such executables.
+\par
+\par When a "work that uses the Library" uses material from a header file
+\par that is part of the Library, the object code for the work may be a
+\par derivative work of the Library even though the source code is not.
+\par Whether this is true is especially significant if the work can be
+\par linked without the Library, or if the work is itself a library. The
+\par threshold for this to be true is not precisely defined by law.
+\par
+\par If such an object file uses only numerical parameters, data
+\par structure layouts and accessors, and small macros and small inline
+\par functions (ten lines or less in length), then the use of the object
+\par file is unrestricted, regardless of whether it is legally a derivative
+\par work. (Executables containing this object code plus portions of the
+\par Library will still fall under Section 6.)
+\par
+\par Otherwise, if the work is a derivative of the Library, you may
+\par distribute the object code for the work under the terms of Section 6.
+\par Any executables containing that work also fall under Section 6,
+\par whether or not they are linked directly with the Library itself.
+\par \page
+\par 6. As an exception to the Sections above, you may also combine or
+\par link a "work that uses the Library" with the Library to produce a
+\par work containing portions of the Library, and distribute that work
+\par under terms of your choice, provided that the terms permit
+\par modification of the work for the customer's own use and reverse
+\par engineering for debugging such modifications.
+\par
+\par You must give prominent notice with each copy of the work that the
+\par Library is used in it and that the Library and its use are covered by
+\par this License. You must supply a copy of this License. If the work
+\par during execution displays copyright notices, you must include the
+\par copyright notice for the Library among them, as well as a reference
+\par directing the user to the copy of this License. Also, you must do one
+\par of these things:
+\par
+\par a) Accompany the work with the complete corresponding
+\par machine-readable source code for the Library including whatever
+\par changes were used in the work (which must be distributed under
+\par Sections 1 and 2 above); and, if the work is an executable linked
+\par with the Library, with the complete machine-readable "work that
+\par uses the Library", as object code and/or source code, so that the
+\par user can modify the Library and then relink to produce a modified
+\par executable containing the modified Library. (It is understood
+\par that the user who changes the contents of definitions files in the
+\par Library will not necessarily be able to recompile the application
+\par to use the modified definitions.)
+\par
+\par b) Use a suitable shared library mechanism for linking with the
+\par Library. A suitable mechanism is one that (1) uses at run time a
+\par copy of the library already present on the user's computer system,
+\par rather than copying library functions into the executable, and (2)
+\par will operate properly with a modified version of the library, if
+\par the user installs one, as long as the modified version is
+\par interface-compatible with the version that the work was made with.
+\par
+\par c) Accompany the work with a written offer, valid for at
+\par least three years, to give the same user the materials
+\par specified in Subsection 6a, above, for a charge no more
+\par than the cost of performing this distribution.
+\par
+\par d) If distribution of the work is made by offering access to copy
+\par from a designated place, offer equivalent access to copy the above
+\par specified materials from the same place.
+\par
+\par e) Verify that the user has already received a copy of these
+\par materials or that you have already sent this user a copy.
+\par
+\par For an executable, the required form of the "work that uses the
+\par Library" must include any data and utility programs needed for
+\par reproducing the executable from it. However, as a special exception,
+\par the materials to be distributed need not include anything that is
+\par normally distributed (in either source or binary form) with the major
+\par components (compiler, kernel, and so on) of the operating system on
+\par which the executable runs, unless that component itself accompanies
+\par the executable.
+\par
+\par It may happen that this requirement contradicts the license
+\par restrictions of other proprietary libraries that do not normally
+\par accompany the operating system. Such a contradiction means you cannot
+\par use both them and the Library together in an executable that you
+\par distribute.
+\par \page
+\par 7. You may place library facilities that are a work based on the
+\par Library side-by-side in a single library together with other library
+\par facilities not covered by this License, and distribute such a combined
+\par library, provided that the separate distribution of the work based on
+\par the Library and of the other library facilities is otherwise
+\par permitted, and provided that you do these two things:
+\par
+\par a) Accompany the combined library with a copy of the same work
+\par based on the Library, uncombined with any other library
+\par facilities. This must be distributed under the terms of the
+\par Sections above.
+\par
+\par b) Give prominent notice with the combined library of the fact
+\par that part of it is a work based on the Library, and explaining
+\par where to find the accompanying uncombined form of the same work.
+\par
+\par 8. You may not copy, modify, sublicense, link with, or distribute
+\par the Library except as expressly provided under this License. Any
+\par attempt otherwise to copy, modify, sublicense, link with, or
+\par distribute the Library is void, and will automatically terminate your
+\par rights under this License. However, parties who have received copies,
+\par or rights, from you under this License will not have their licenses
+\par terminated so long as such parties remain in full compliance.
+\par
+\par 9. You are not required to accept this License, since you have not
+\par signed it. However, nothing else grants you permission to modify or
+\par distribute the Library or its derivative works. These actions are
+\par prohibited by law if you do not accept this License. Therefore, by
+\par modifying or distributing the Library (or any work based on the
+\par Library), you indicate your acceptance of this License to do so, and
+\par all its terms and conditions for copying, distributing or modifying
+\par the Library or works based on it.
+\par
+\par 10. Each time you redistribute the Library (or any work based on the
+\par Library), the recipient automatically receives a license from the
+\par original licensor to copy, distribute, link with or modify the Library
+\par subject to these terms and conditions. You may not impose any further
+\par restrictions on the recipients' exercise of the rights granted herein.
+\par You are not responsible for enforcing compliance by third parties with
+\par this License.
+\par \page
+\par 11. If, as a consequence of a court judgment or allegation of patent
+\par infringement or for any other reason (not limited to patent issues),
+\par conditions are imposed on you (whether by court order, agreement or
+\par otherwise) that contradict the conditions of this License, they do not
+\par excuse you from the conditions of this License. If you cannot
+\par distribute so as to satisfy simultaneously your obligations under this
+\par License and any other pertinent obligations, then as a consequence you
+\par may not distribute the Library at all. For example, if a patent
+\par license would not permit royalty-free redistribution of the Library by
+\par all those who receive copies directly or indirectly through you, then
+\par the only way you could satisfy both it and this License would be to
+\par refrain entirely from distribution of the Library.
+\par
+\par If any portion of this section is held invalid or unenforceable under any
+\par particular circumstance, the balance of the section is intended to apply,
+\par and the section as a whole is intended to apply in other circumstances.
+\par
+\par It is not the purpose of this section to induce you to infringe any
+\par patents or other property right claims or to contest validity of any
+\par such claims; this section has the sole purpose of protecting the
+\par integrity of the free software distribution system which is
+\par implemented by public license practices. Many people have made
+\par generous contributions to the wide range of software distributed
+\par through that system in reliance on consistent application of that
+\par system; it is up to the author/donor to decide if he or she is willing
+\par to distribute software through any other system and a licensee cannot
+\par impose that choice.
+\par
+\par This section is intended to make thoroughly clear what is believed to
+\par be a consequence of the rest of this License.
+\par
+\par 12. If the distribution and/or use of the Library is restricted in
+\par certain countries either by patents or by copyrighted interfaces, the
+\par original copyright holder who places the Library under this License may add
+\par an explicit geographical distribution limitation excluding those countries,
+\par so that distribution is permitted only in or among countries not thus
+\par excluded. In such case, this License incorporates the limitation as if
+\par written in the body of this License.
+\par
+\par 13. The Free Software Foundation may publish revised and/or new
+\par versions of the Lesser General Public License from time to time.
+\par Such new versions will be similar in spirit to the present version,
+\par but may differ in detail to address new problems or concerns.
+\par
+\par Each version is given a distinguishing version number. If the Library
+\par specifies a version number of this License which applies to it and
+\par "any later version", you have the option of following the terms and
+\par conditions either of that version or of any later version published by
+\par the Free Software Foundation. If the Library does not specify a
+\par license version number, you may choose any version ever published by
+\par the Free Software Foundation.
+\par \page
+\par 14. If you wish to incorporate parts of the Library into other free
+\par programs whose distribution conditions are incompatible with these,
+\par write to the author to ask for permission. For software which is
+\par copyrighted by the Free Software Foundation, write to the Free
+\par Software Foundation; we sometimes make exceptions for this. Our
+\par decision will be guided by the two goals of preserving the free status
+\par of all derivatives of our free software and of promoting the sharing
+\par and reuse of software generally.
+\par
+\par \tab \tab \tab NO WARRANTY
+\par
+\par 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+\par WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+\par EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+\par OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+\par KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+\par IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+\par PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+\par LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+\par THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+\par
+\par 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+\par WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+\par AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+\par FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+\par CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+\par LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+\par RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+\par FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+\par SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+\par DAMAGES.
+\par
+\par \tab \tab END OF TERMS AND CONDITIONS
+\par \page
+\par How to Apply These Terms to Your New Libraries
+\par
+\par If you develop a new library, and you want it to be of the greatest
+\par possible use to the public, we recommend making it free software that
+\par everyone can redistribute and change. You can do so by permitting
+\par redistribution under these terms (or, alternatively, under the terms of the
+\par ordinary General Public License).
+\par
+\par To apply these terms, attach the following notices to the library. It is
+\par safest to attach them to the start of each source file to most effectively
+\par convey the exclusion of warranty; and each file should have at least the
+\par "copyright" line and a pointer to where the full notice is found.
+\par
+\par <one line to give the library's name and a brief idea of what it does.>
+\par Copyright (C) <year> <name of author>
+\par
+\par This library is free software; you can redistribute it and/or
+\par modify it under the terms of the GNU Lesser General Public
+\par License as published by the Free Software Foundation; either
+\par version 2.1 of the License, or (at your option) any later version.
+\par
+\par This library is distributed in the hope that it will be useful,
+\par but WITHOUT ANY WARRANTY; without even the implied warranty of
+\par MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+\par Lesser General Public License for more details.
+\par
+\par You should have received a copy of the GNU Lesser General Public
+\par License along with this library; if not, write to the Free Software
+\par Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+\par
+\par Also add information on how to contact you by electronic and paper mail.
+\par
+\par You should also get your employer (if you work as a programmer) or your
+\par school, if any, to sign a "copyright disclaimer" for the library, if
+\par necessary. Here is a sample; alter the names:
+\par
+\par Yoyodyne, Inc., hereby disclaims all copyright interest in the
+\par library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+\par
+\par <signature of Ty Coon>, 1 April 1990
+\par Ty Coon, President of Vice
+\par
+\par That's all there is to it!
+\par
+\par
+\par }}
\ No newline at end of file
Added: trunk/utils/windows/native/service/procrun/resources/procrunr.ico
===================================================================
(Binary files differ)
Property changes on: trunk/utils/windows/native/service/procrun/resources/procrunr.ico
___________________________________________________________________
Name: svn:mime-type
+ image/x-icon
Added: trunk/utils/windows/native/service/procrun/resources/procruns.ico
===================================================================
(Binary files differ)
Property changes on: trunk/utils/windows/native/service/procrun/resources/procruns.ico
___________________________________________________________________
Name: svn:mime-type
+ image/x-icon
Added: trunk/utils/windows/native/service/procrun/src/cmdline.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/cmdline.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/cmdline.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,277 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define EXE_SUFFIX L".EXE"
+#define EXE_SUFFIXLEN (sizeof(EXE_SUFFIX) / sizeof(WCHAR) - 1)
+
+/* Those two are declared in handles.c */
+extern LPWSTR *_st_sys_argvw;
+extern int _st_sys_argc;
+
+static WCHAR _st_sys_appexe[MAX_PATH];
+/*
+ * argv parsing.
+ * Parse the argv[0] and split to ExePath and
+ * Executable name. Strip the extension ('.exe').
+ * Check for command in argv[1] //CMD//Application
+ * Parse the options --option value or --option==value
+ * break on first argument that doesn't start with '--'
+ */
+LPAPXCMDLINE apxCmdlineParse(
+ APXHANDLE hPool,
+ APXCMDLINEOPT *lpOptions,
+ LPCWSTR *lpszCommands)
+{
+
+ LPAPXCMDLINE lpCmdline = NULL;
+ DWORD l, i = 0, s = 1;
+ LPWSTR p;
+ WCHAR cmd[4];
+ DWORD match;
+ BOOL add;
+ if (_st_sys_argc < 1)
+ return NULL;
+
+ l = lstrlenW(_st_sys_argvw[0]);
+ if (l < EXE_SUFFIXLEN)
+ return NULL;
+ if (!(lpCmdline = (LPAPXCMDLINE)apxPoolCalloc(hPool, sizeof(APXCMDLINE))))
+ return NULL;
+ lpCmdline->hPool = hPool;
+ lpCmdline->lpOptions = lpOptions;
+ lpCmdline->szExePath = _st_sys_argvw[0];
+ p = lpCmdline->szExePath + l;
+
+ while (p > lpCmdline->szExePath) {
+ if (*p == L'\\') {
+ *p++ = L'\0';
+ break;
+ }
+ p--;
+ }
+ /* Find the path if it wasn't specified in the argv[0] */
+ if (p == lpCmdline->szExePath) {
+ WCHAR mh[4096];
+ LPWSTR m;
+ if (GetModuleFileNameW(GetModuleHandle(NULL), mh, 4096)) {
+ lpCmdline->szExePath = apxPoolStrdupW(hPool, mh);
+ m = lpCmdline->szExePath + lstrlenW(lpCmdline->szExePath);
+ while (m > lpCmdline->szExePath) {
+ if (*(m--) == L'\\') {
+ *(++m) = L'\0';
+ break;
+ }
+ }
+ }
+ }
+ lpCmdline->szExecutable = p;
+ p = _st_sys_argvw[0] + l - EXE_SUFFIXLEN;
+ if (lstrcmpiW(p, EXE_SUFFIX) == 0)
+ *p = L'\0';
+ if (lpszCommands && _st_sys_argc > 1 && lstrlenW(_st_sys_argvw[1]) > 5) {
+ if (_st_sys_argvw[1][0] == L'/' &&
+ _st_sys_argvw[1][1] == L'/' &&
+ _st_sys_argvw[1][5] == L'/') { /* allow max tree char command */
+ l = 2;
+ while (_st_sys_argvw[1][l] != L'/') {
+ cmd[l - 2] = _st_sys_argvw[1][l];
+ if (l++ > 3)
+ break;
+ }
+ cmd[l - 2] = L'\0';
+ while (lpszCommands[i]) {
+ if (lstrcmpW(lpszCommands[i++], cmd) == 0) {
+ lpCmdline->dwCmdIndex = i;
+ s = 2;
+ break;
+ }
+ }
+ if (lpCmdline->dwCmdIndex) {
+ _st_sys_argvw[1][l+1] = L'\0';
+ lpCmdline->szApplication = &(_st_sys_argvw[1][l+2]);
+ if (!lstrlenW(lpCmdline->szApplication))
+ lpCmdline->szApplication = _st_sys_argvw[0];
+ }
+ else {
+ apxLogWrite(APXLOG_MARK_ERROR "Unrecognized cmd option %s", cmd);
+ s = 2;
+ }
+ }
+ }
+ else {
+ lpCmdline->szApplication = lpCmdline->szExecutable;
+ lpCmdline->dwCmdIndex = 1;
+ return lpCmdline;
+ }
+ for (i = s; i < (DWORD)_st_sys_argc; i++) {
+ LPWSTR e = NULL;
+ if (_st_sys_argvw[i][0] != L'-' ||
+ _st_sys_argvw[i][1] != L'-') {
+ if (_st_sys_argvw[i][0] != L'+' ||
+ _st_sys_argvw[i][1] != L'+')
+ break;
+ else
+ add = TRUE;
+ }
+ else
+ add = FALSE;
+ p = &(_st_sys_argvw[i][2]);
+ /* Find if the option has '=' char
+ * for --option==value or --option value cases.
+ */
+ while (*p) {
+ if (*p == L'=') {
+ *p = L'\0';
+ e = p + 1;
+ break;
+ }
+ else
+ p++;
+ }
+ match = 0;
+ for (l = 0; lpOptions[l].szName; l++) {
+ if (lstrcmpW(lpOptions[l].szName, &(_st_sys_argvw[i][2])) == 0) {
+ LPWSTR val;
+ /* check if arg is needed */
+ if (e)
+ val = e;
+ else if ((i + 1) < (DWORD)_st_sys_argc)
+ val = _st_sys_argvw[++i];
+ else {
+ lpOptions[l].dwValue = 0;
+ lpOptions[l].szValue = NULL;
+ lpOptions[l].dwType |= APXCMDOPT_FOUND;
+ break;
+ }
+ if (lpOptions[l].dwType & APXCMDOPT_STR)
+ lpOptions[l].szValue = val;
+ else if (lpOptions[l].dwType & APXCMDOPT_INT)
+ lpOptions[l].dwValue = (DWORD)apxAtoulW(val);
+ else if (lpOptions[l].dwType & APXCMDOPT_MSZ) {
+ LPWSTR pp;
+ BOOL insquote = FALSE, indquote=FALSE;
+ DWORD sp = 0;
+ LPWSTR ov = lpOptions[l].szValue;
+ if (lpOptions[l].dwValue > 2) {
+ sp = (lpOptions[l].dwValue - sizeof(WCHAR)) / sizeof(WCHAR);
+ }
+ lpOptions[l].dwValue = (sp + lstrlenW(val) + 2) * sizeof(WCHAR);
+ lpOptions[l].szValue = (LPWSTR)apxPoolCalloc(hPool,
+ lpOptions[l].dwValue);
+ if (sp) {
+ AplMoveMemory(lpOptions[l].szValue, ov, sp * sizeof(WCHAR));
+ apxFree(ov);
+ }
+ pp = val;
+ while(*pp) {
+ if (*pp == L'\'')
+ insquote = !insquote;
+ else if (*pp == L'"') {
+ indquote = !indquote;
+ lpOptions[l].szValue[sp++] = L'"';
+ }
+ else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
+ lpOptions[l].szValue[sp++] = L'\0';
+ else
+ lpOptions[l].szValue[sp++] = *pp;
+ pp++;
+ }
+ }
+ lpOptions[l].dwType |= APXCMDOPT_FOUND;
+ if (add)
+ lpOptions[l].dwType |= APXCMDOPT_ADD;
+ match = l + 1;
+ break;
+ }
+ }
+ }
+ if (i < (DWORD)_st_sys_argc) {
+ lpCmdline->dwArgc = _st_sys_argc - i;
+ lpCmdline->lpArgvw = &_st_sys_argvw[i];
+ }
+ return lpCmdline;
+}
+
+/* Used for future expansion */
+void apxCmdlineFree(
+ LPAPXCMDLINE lpCmdline)
+{
+
+ apxFree(lpCmdline);
+}
+
+/*
+ * Environment variables parsing
+ * Each variable is prfixed with PR_
+ * for example 'set PR_JVM=auto' has a same meaning as providing '--Jvm auto'
+ * on the command line.
+ * Multistring varisables are added to the present conf.
+ */
+void apxCmdlineLoadEnvVars(
+ LPAPXCMDLINE lpCmdline)
+{
+ WCHAR szEnv[64];
+ int i = 0;
+ if (!lpCmdline || !lpCmdline->lpOptions)
+ return;
+
+ while (lpCmdline->lpOptions[i].szName) {
+ DWORD l;
+ WCHAR szVar[SIZ_HUGLEN];
+ lstrcpyW(szEnv, L"PR_");
+ lstrcatW(szEnv, lpCmdline->lpOptions[i].szName);
+ l = GetEnvironmentVariableW(szEnv, szVar, SIZ_HUGMAX);
+ if (l == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
+ apxLogWrite(APXLOG_MARK_ERROR "Error geting environment variable %S",
+ szEnv);
+ ++i;
+ continue;
+ }
+ if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_STR)) {
+ lpCmdline->lpOptions[i].szValue = apxPoolStrdupW(lpCmdline->hPool, szVar);
+ lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
+ }
+ else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_MSZ)) {
+ LPWSTR pp;
+ BOOL insquote = FALSE, indquote = FALSE;
+ DWORD sp = 0;
+ lpCmdline->lpOptions[i].szValue = apxPoolCalloc(lpCmdline->hPool,
+ (lstrlenW(szVar) + 2) *
+ sizeof(WCHAR));
+ lstrcpyW(lpCmdline->lpOptions[i].szValue, szVar);
+ pp = szVar;
+ while(*pp) {
+ if (*pp == L'\'')
+ insquote = !insquote;
+ else if (*pp == L'"') {
+ indquote = !indquote;
+ lpCmdline->lpOptions[i].szValue[sp++] = L'"';
+ }
+ else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
+ lpCmdline->lpOptions[i].szValue[sp++] = L'\0';
+ else
+ lpCmdline->lpOptions[i].szValue[sp++] = *pp;
+ pp++;
+ }
+ lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND | APXCMDOPT_ADD;
+ }
+ ++i;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/utils/windows/native/service/procrun/src/cmdline.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/console.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/console.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/console.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,150 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+/** Console layout saved in the registry as binary */
+typedef struct stAPXCONSOLE_LAYOUT {
+ /** Main window size */
+ POINT ptSize;
+ /** Main window size and position */
+ RECT rcPos;
+ /** Client window size */
+ POINT ptClientSize;
+ /** Client size and position */
+ RECT rcClientPos;
+ /** Scroll position */
+ POINT ptScrollPos;
+ /** Maximum Scroll position */
+ POINT ptScrollMax;
+ /** Caret position */
+ POINT ptCaretPos;
+ /** Background color */
+ COLORREF clrBackground;
+ /** Text color */
+ COLORREF clrText;
+ /** Selected text background color */
+ COLORREF clrSelectBackground;
+ /** Selected rext color */
+ COLORREF clrSelectText;
+ /** Character size */
+ POINT ptCharSize;
+ /** Current Screen size */
+ POINT ptScreenSize;
+ /** Font size */
+ INT nFontSize;
+ /** Caret size */
+ POINT ptCaretSize;
+ /** Caret Bilnk time in ms */
+ UINT nCaretBlinkTime;
+ /** Typeface name of the font (32 char max including the null terminator) */
+ TCHAR szFontName[32];
+
+} stAPXCONSOLE_LAYOUT, *APXCONSOLE_LAYOUT;
+
+typedef struct stAPXCONSOLE {
+ /** Application instance handle */
+ HINSTANCE hInstance;
+ /** Console Screen Buffer */
+ TCHAR lpScreenBuffer;
+ /** The size of the Console Screen Buffer */
+ DWORD dwScreenBufferSize;
+ /** Main window Handle */
+ HWND hWnd;
+ /** Console window Handle */
+ HWND hConsole;
+ /** Console Window Layout */
+ stAPXCONSOLE_LAYOUT stLayout;
+ /** Console Keyboard Buffer */
+ TCHAR lpKeyboardBuffer;
+ /** The size of the Keyboard Buffer */
+ DWORD dwKeyboardBufferSize;
+ /** Console Handler routine */
+ PHANDLER_ROUTINE fnHandlerRoutine;
+ /** Console Reference Count */
+ DWORD dwReferenceCount;
+} stAPXCONSOLE, *APXCONSOLE;
+
+APXHANDLE __st_sys_console = NULL;
+
+static BOOL __apxConsoleCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ APXCONSOLE lpConsole = APXHANDLE_DATA(hObject);
+
+ if (hObject->dwType != APXHANDLE_TYPE_CONSOLE)
+ return FALSE;
+ switch (uMsg) {
+ case WM_CLOSE:
+
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+APXHANDLE
+apxAllocConsoleHandle(APXHANDLE hPool)
+{
+ APXHANDLE hConsole;
+
+ hConsole = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT |
+ APXHANDLE_OWNS_LOCK, NULL,
+ sizeof(stAPXCONSOLE),
+ __apxConsoleCallback);
+
+ return hConsole;
+}
+
+BOOL
+apxFreeConsoleHandle(APXHANDLE hConsole)
+{
+ APXCONSOLE lpConsole = APXHANDLE_DATA(hConsole);
+ if (hConsole->dwType != APXHANDLE_TYPE_CONSOLE)
+ return FALSE;
+
+ return apxCloseHandle(hConsole);
+}
+
+
+
+
+
+/** Standard Console Functions */
+BOOL
+apxAllocConsole()
+{
+
+ if (!__st_sys_console) {
+ __st_sys_console = apxAllocConsoleHandle(NULL);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+BOOL
+apxFreeConsole()
+{
+ if (apxFreeConsoleHandle(__st_sys_console)) {
+ __st_sys_console = NULL;
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/console.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/gui.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/gui.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/gui.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,1025 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define BALLON_TIMEOUT 1000
+/* Offset for listview dots */
+#define DOTOFFSET 0
+
+static HMODULE _st_sys_riched;
+static APXGUISTORE _st_sys_gui;
+static HIMAGELIST _st_sel_users_il = NULL;
+static WNDPROC _st_sel_users_lvm;
+
+typedef struct PROGRESS_DLGPARAM {
+ LPCTSTR szHead;
+ LPCWSTR szText;
+ LPVOID cbData;
+ LPAPXFNCALLBACK fnCb;
+ HANDLE hThread;
+ HWND hDialog;
+} PROGRESS_DLGPARAM, *LPPROGRESS_DLGPARAM;
+
+APXLVITEM lvUsers[] = {
+ { 0, FALSE, 180, 180, LVCFMT_LEFT, TEXT("User") },
+ { 0, TRUE, 180, 180, LVCFMT_LEFT, TEXT("Full Name") },
+ { 0, TRUE, 235, 235, LVCFMT_LEFT, TEXT("Comment") }
+};
+
+
+#define NUMLVUSERS (sizeof(lvUsers) / sizeof(lvUsers[0]))
+
+static UINT __getWhellScrollLines()
+{
+ HWND hdlMsWheel;
+ UINT ucNumLines = 3; /* 3 is the default */
+ UINT uiMsh_MsgScrollLines;
+
+ APX_OSLEVEL os = apxGetOsLevel();
+ /* In Windows 9x & Windows NT 3.51, query MSWheel for the
+ * number of scroll lines. In Windows NT 4.0 and later,
+ * use SystemParametersInfo.
+ */
+ if (os < APX_WINVER_NT_4) {
+ hdlMsWheel = FindWindow(MSH_WHEELMODULE_CLASS,
+ MSH_WHEELMODULE_TITLE);
+ if (hdlMsWheel) {
+ uiMsh_MsgScrollLines = RegisterWindowMessage(MSH_SCROLL_LINES);
+ if (uiMsh_MsgScrollLines)
+ ucNumLines = (int)SendMessage(hdlMsWheel,
+ uiMsh_MsgScrollLines,
+ 0, 0);
+ }
+ }
+ else {
+ SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
+ &ucNumLines, 0);
+ }
+ return ucNumLines;
+}
+
+/* Initialize the Gui
+ */
+LPAPXGUISTORE apxGuiInitialize(WNDPROC lpfnWndProc, LPCTSTR szAppName)
+{
+ INITCOMMONCONTROLSEX stCmn;
+ WNDCLASSEX wcex;
+
+ _st_sys_gui.hInstance = GetModuleHandleA(NULL);
+ GetStartupInfo(&_st_sys_gui.stStartupInfo);
+
+ lstrcpy(_st_sys_gui.szWndClass, szAppName);
+ lstrcat(_st_sys_gui.szWndClass, TEXT("_CLASS"));
+
+ /* Single instance or general application mutex */
+ lstrcpy(_st_sys_gui.szWndMutex, szAppName);
+ lstrcat(_st_sys_gui.szWndMutex, TEXT("_MUTEX"));
+
+
+ stCmn.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ stCmn.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES | ICC_COOL_CLASSES |
+ ICC_INTERNET_CLASSES | ICC_PAGESCROLLER_CLASS | ICC_BAR_CLASSES;
+
+ InitCommonControlsEx(&stCmn);
+
+ _st_sys_riched = LoadLibraryA("RICHED32.DLL");
+ _st_sys_gui.hIconSm = LoadImage(_st_sys_gui.hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+ IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ _st_sys_gui.hIcon = LoadImage(_st_sys_gui.hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+ IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
+ _st_sys_gui.hIconHg = LoadImage(_st_sys_gui.hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+ IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR);
+ _st_sys_gui.hAccel = LoadAccelerators(_st_sys_gui.hInstance,
+ MAKEINTRESOURCE(IDC_APPLICATION));
+ _st_sys_gui.stState.rcPosition.left = CW_USEDEFAULT;
+ _st_sys_gui.stState.rcPosition.top = CW_USEDEFAULT;
+ _st_sys_gui.stState.rcPosition.right = CW_USEDEFAULT;
+ _st_sys_gui.stState.rcPosition.bottom = CW_USEDEFAULT;
+
+ _st_sys_gui.nWhellScroll = __getWhellScrollLines();
+
+ wcex.cbSize = sizeof(WNDCLASSEX);
+
+ wcex.style = 0;
+ wcex.lpfnWndProc = lpfnWndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = _st_sys_gui.hInstance;
+ wcex.hIcon = _st_sys_gui.hIcon;
+ wcex.hIconSm = _st_sys_gui.hIconSm;
+ wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wcex.hbrBackground = (HBRUSH)(COLOR_INACTIVEBORDER+1);
+ wcex.lpszMenuName = MAKEINTRESOURCE(IDC_APPLICATION);
+ wcex.lpszClassName = _st_sys_gui.szWndClass;
+
+ if (RegisterClassEx(&wcex)) {
+ return &_st_sys_gui;
+ }
+ else
+ return NULL;
+}
+
+
+BOOL apxCenterWindow(HWND hwndChild, HWND hwndParent)
+{
+ RECT rChild, rParent, rWorkArea;
+ int wChild, hChild, wParent, hParent;
+ int xNew, yNew;
+ BOOL bResult;
+
+ /* Get the Height and Width of the child window */
+ GetWindowRect(hwndChild, &rChild);
+ wChild = rChild.right - rChild.left;
+ hChild = rChild.bottom - rChild.top;
+
+ /* Get the Height and Width of the parent window */
+ GetWindowRect(hwndParent, &rParent);
+ wParent = rParent.right - rParent.left;
+ hParent = rParent.bottom - rParent.top;
+
+ if (wParent < wChild && hParent < hChild) {
+ GetWindowRect(GetDesktopWindow(), &rParent);
+ wParent = rParent.right - rParent.left;
+ hParent = rParent.bottom - rParent.top;
+ }
+ /* Get the limits of the 'workarea' */
+ bResult = SystemParametersInfo(SPI_GETWORKAREA, sizeof(RECT),
+ &rWorkArea, 0);
+ if (!bResult) {
+ rWorkArea.left = rWorkArea.top = 0;
+ rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
+ rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
+ }
+
+ /* Calculate new X position, then adjust for workarea */
+ xNew = rParent.left + ((wParent - wChild) /2);
+ if (xNew < rWorkArea.left)
+ xNew = rWorkArea.left;
+ else if ((xNew+wChild) > rWorkArea.right)
+ xNew = rWorkArea.right - wChild;
+
+ /* Calculate new Y position, then adjust for workarea */
+ yNew = rParent.top + ((hParent - hChild) /2);
+ if (yNew < rWorkArea.top)
+ yNew = rWorkArea.top;
+ else if ((yNew+hChild) > rWorkArea.bottom)
+ yNew = rWorkArea.bottom - hChild;
+
+ /* Set it, and return */
+ return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
+}
+
+/***************************************************************************
+ * Function: LoadRcString
+ *
+ * Purpose: Loads a resource string from string table and returns a pointer
+ * to the string.
+ *
+ * Parameters: wID - resource string id
+ *
+ */
+
+/** Load the resource string with the ID given, and return a
+ * pointer to it. Notice that the buffer is common memory so
+ * the string must be used before this call is made a second time.
+ */
+
+LPSTR apxLoadResourceA(UINT wID, UINT nBuf)
+
+{
+ static CHAR szBuf[4][SIZ_BUFLEN];
+ if (nBuf > 4)
+ return "";
+ if (LoadStringA(_st_sys_gui.hInstance,wID ,szBuf[nBuf], SIZ_BUFMAX) > 0)
+ return szBuf[nBuf];
+ else
+ return "";
+}
+
+LPWSTR apxLoadResourceW(UINT wID, UINT nBuf)
+
+{
+ static WCHAR szBuf[4][SIZ_BUFLEN];
+ if (nBuf > 4)
+ return L"";
+ if (LoadStringW(_st_sys_gui.hInstance,wID ,szBuf[nBuf], SIZ_BUFMAX) > 0)
+ return szBuf[nBuf];
+ else
+ return L"";
+}
+
+/* Add the item to the Try popup menu
+ */
+void apxAppendMenuItem(HMENU hMenu, UINT idMenu, LPCTSTR szName,
+ BOOL bDefault, BOOL bEnabled)
+{
+ MENUITEMINFO miI;
+
+ AplZeroMemory(&miI, sizeof(MENUITEMINFO));
+ miI.cbSize = sizeof(MENUITEMINFO);
+ miI.fMask = MIIM_TYPE | MIIM_STATE;
+ if (szName && lstrlen(szName)) {
+ miI.fMask |= MIIM_ID;
+ miI.fType = MFT_STRING;
+ miI.wID = idMenu;
+ if (bDefault)
+ miI.fState = MFS_DEFAULT;
+ if (!bEnabled)
+ miI.fState |= MFS_DISABLED;
+ miI.dwTypeData = (LPTSTR)szName;
+ }
+ else {
+ miI.fType = MFT_SEPARATOR;
+ }
+ InsertMenuItem(hMenu, idMenu, FALSE, &miI);
+}
+
+/* Add the item to the Try popup menu
+ */
+void apxAppendMenuItemBmp(HMENU hMenu, UINT idMenu, LPCTSTR szName)
+{
+ MENUITEMINFO miI;
+ HBITMAP hBmp;
+
+ hBmp = LoadImage(_st_sys_gui.hInstance, szName,
+ IMAGE_BITMAP, 0, 0,
+ LR_CREATEDIBSECTION | LR_SHARED);
+
+ AplZeroMemory(&miI, sizeof(MENUITEMINFO));
+ miI.cbSize = sizeof(MENUITEMINFO);
+ miI.fMask = MIIM_BITMAP | MFT_MENUBARBREAK;
+
+ miI.hbmpItem = hBmp;
+ InsertMenuItem(hMenu, idMenu, FALSE, &miI);
+}
+
+/* Try icon helper
+ * Add/Change/Delete icon from the windows try.
+ */
+void apxManageTryIconA(HWND hWnd, DWORD dwMessage, LPCSTR szInfoTitle,
+ LPCSTR szInfo, HICON hIcon)
+{
+ static BOOL inTry = FALSE;
+ NOTIFYICONDATAA nId;
+ AplZeroMemory(&nId, sizeof(NOTIFYICONDATAA));
+
+ nId.cbSize = sizeof(NOTIFYICONDATAA);
+ nId.hWnd = hWnd;
+ nId.uID = 0xFF;
+ nId.uCallbackMessage = WM_TRAYMESSAGE;
+ nId.uFlags = NIF_MESSAGE;
+
+ if (dwMessage == NIM_ADD && inTry)
+ return;
+ if (dwMessage != NIM_DELETE) {
+ nId.uFlags |= NIF_ICON;
+ if (! szInfoTitle) {
+ nId.uFlags |= NIF_TIP;
+ lstrcpynA(nId.szTip, szInfo, 63);
+ }
+ else if (szInfo) {
+ nId.uFlags |= NIF_INFO;
+ lstrcpynA(nId.szInfo, szInfo, 255);
+ lstrcpynA(nId.szInfoTitle, szInfoTitle, 63);
+ nId.dwInfoFlags = NIIF_INFO;
+ nId.uTimeout = BALLON_TIMEOUT;
+ }
+
+ nId.hIcon = hIcon ? hIcon : _st_sys_gui.hIconSm;
+ inTry = TRUE;
+ }
+ else
+ inTry = FALSE;
+
+ Shell_NotifyIconA(dwMessage, &nId);
+}
+
+void apxManageTryIconW(HWND hWnd, DWORD dwMessage, LPCWSTR szInfoTitle,
+ LPCWSTR szInfo, HICON hIcon)
+{
+
+ NOTIFYICONDATAW nId;
+ AplZeroMemory(&nId, sizeof(NOTIFYICONDATAW));
+
+ nId.cbSize = sizeof(NOTIFYICONDATAW);
+ nId.hWnd = hWnd;
+ nId.uID = 0xFF;
+ nId.uCallbackMessage = WM_TRAYMESSAGE;
+ nId.uFlags = NIF_MESSAGE;
+
+ if (dwMessage != NIM_DELETE) {
+ nId.uFlags |= NIF_ICON;
+ if (! szInfoTitle) {
+ nId.uFlags |= NIF_TIP;
+ lstrcpynW(nId.szTip, szInfo, 63);
+ }
+ else if (szInfo) {
+ nId.uFlags |= NIF_INFO;
+ lstrcpynW(nId.szInfo, szInfo, 255);
+ lstrcpynW(nId.szInfoTitle, szInfoTitle, 63);
+ nId.dwInfoFlags = NIIF_INFO;
+ nId.uTimeout = BALLON_TIMEOUT;
+ }
+ nId.hIcon = hIcon ? hIcon : _st_sys_gui.hIconSm;
+ }
+
+ Shell_NotifyIconW(dwMessage, &nId);
+}
+
+static void __apxShellAbout(HWND hWnd)
+{
+ TCHAR szApplication[512];
+
+ wsprintf(szApplication , TEXT("About - %s#Windows"),
+ apxLoadResource(IDS_APPLICATION, 0));
+
+ ShellAbout(hWnd, szApplication,
+ apxLoadResource(IDS_APPDESCRIPTION, 1),
+ _st_sys_gui.hIconHg);
+}
+
+
+static LRESULT CALLBACK __apxAboutDlgProc(HWND hDlg, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ static HWND hRich = NULL;
+ static POINT ptScroll;
+ HRSRC hRsrc;
+ HGLOBAL hGlob;
+ LPSTR szTxt;
+
+ switch (uMsg) {
+ case WM_INITDIALOG:
+ apxCenterWindow(hDlg, _st_sys_gui.hMainWnd);
+ hRich = GetDlgItem(hDlg, IDC_LICENSE);
+ hRsrc = FindResource(GetModuleHandleA(NULL), MAKEINTRESOURCE(IDR_LICENSE),
+ TEXT("RTF"));
+ hGlob = LoadResource(GetModuleHandleA(NULL), hRsrc);
+ szTxt = (LPSTR)LockResource(hGlob);
+
+ SendMessageA(hRich, WM_SETTEXT, 0, (LPARAM)szTxt);
+ SetDlgItemText(hDlg, IDC_ABOUTAPP, apxLoadResource(IDS_APPFULLNAME, 0));
+ ptScroll.x = 0;
+ ptScroll.y = 0;
+ return TRUE;
+ break;
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+ }
+ else if (LOWORD(wParam) == IAB_SYSINF)
+ __apxShellAbout(hDlg);
+ break;
+ case WM_MOUSEWHEEL:
+ {
+ int nScroll, nLines;
+ if ((SHORT)HIWORD(wParam) < 0)
+ nScroll = _st_sys_gui.nWhellScroll;
+ else
+ nScroll = _st_sys_gui.nWhellScroll * (-1);
+ ptScroll.y += (nScroll * 11);
+ if (ptScroll.y < 0)
+ ptScroll.y = 0;
+ nLines = (int)SendMessage(hRich, EM_GETLINECOUNT, 0, 0) + 1;
+ if (ptScroll.y / 11 > nLines)
+ ptScroll.y = nLines * 11;
+ SendMessage(hRich, EM_SETSCROLLPOS, 0, (LPARAM)&ptScroll);
+ }
+ break;
+
+ }
+ return FALSE;
+}
+
+void apxAboutBox(HWND hWnd)
+{
+ DialogBox(_st_sys_gui.hInstance,
+ MAKEINTRESOURCE(IDD_ABOUTBOX),
+ hWnd,
+ (DLGPROC)__apxAboutDlgProc);
+}
+
+static DWORD WINAPI __apxProgressWorkerThread(LPVOID lpParameter)
+{
+ LPPROGRESS_DLGPARAM lpDlgParam = (LPPROGRESS_DLGPARAM)lpParameter;
+
+ (*lpDlgParam->fnCb)(NULL, WM_USER+1, 0, (LPARAM)lpDlgParam->hDialog);
+ CloseHandle(lpDlgParam->hThread);
+ ExitThread(0);
+ return 0;
+}
+
+static LRESULT CALLBACK __apxProgressDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ LPPROGRESS_DLGPARAM lpDlgParam;
+ DWORD dwId;
+ switch (uMsg) {
+ case WM_INITDIALOG:
+ lpDlgParam = (LPPROGRESS_DLGPARAM)lParam;
+ apxCenterWindow(hDlg, _st_sys_gui.hMainWnd);
+ if (lpDlgParam && lpDlgParam->szHead && lpDlgParam->szText) {
+ SetDlgItemText(hDlg, IDDP_HEAD, lpDlgParam->szHead);
+ SetDlgItemTextW(hDlg, IDDP_TEXT, lpDlgParam->szText);
+ }
+ lpDlgParam->hDialog = hDlg;
+ lpDlgParam->hThread = CreateThread(NULL, 0, __apxProgressWorkerThread,
+ lpDlgParam, 0, &dwId);
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+ break;
+ }
+ break;
+ case WM_USER+1:
+ SendMessage(GetDlgItem(hDlg, IDDP_PROGRESS), PBM_STEPIT, 0, 0);
+ break;
+ }
+ return FALSE;
+}
+
+int apxProgressBox(HWND hWnd, LPCTSTR szHeader,
+ LPCWSTR szText,
+ LPAPXFNCALLBACK fnProgressCallback,
+ LPVOID cbData)
+{
+ PROGRESS_DLGPARAM dlgParam;
+ int rv;
+
+ dlgParam.szHead = szHeader;
+ dlgParam.szText = szText;
+ dlgParam.cbData = cbData;
+ dlgParam.fnCb = fnProgressCallback;
+ dlgParam.hThread = NULL;
+ rv = (int)DialogBoxParam(_st_sys_gui.hInstance,
+ MAKEINTRESOURCE(IDD_PROGRESS),
+ hWnd,
+ (DLGPROC)__apxProgressDlgProc,
+ (LPARAM)&dlgParam);
+ return rv;
+}
+
+BOOL apxYesNoMessage(LPCTSTR szTitle, LPCTSTR szMessage, BOOL bStop)
+{
+ UINT uType = MB_YESNO;
+ int rv;
+
+ if (bStop)
+ uType |= MB_DEFBUTTON2 | MB_ICONEXCLAMATION;
+ else
+ uType |= MB_DEFBUTTON1 | MB_ICONQUESTION;
+
+ rv = MessageBox(_st_sys_gui.hMainWnd, szMessage, szTitle, uType);
+
+ return (rv == IDYES);
+}
+
+LPWSTR apxGetDlgTextW(APXHANDLE hPool, HWND hDlg, int nIDDlgItem)
+{
+ DWORD l, n;
+ LPWSTR szT = NULL;
+
+ l = (DWORD)SendMessageW(GetDlgItem(hDlg, nIDDlgItem), WM_GETTEXTLENGTH, 0, 0);
+ if (l > 0) {
+ szT = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+ n = GetDlgItemTextW(hDlg, nIDDlgItem, szT, l + 1);
+ if (n == 0) {
+ apxFree(szT);
+ szT = NULL;
+ }
+ }
+ return szT;
+}
+
+LPSTR apxGetDlgTextA(APXHANDLE hPool, HWND hDlg, int nIDDlgItem)
+{
+ DWORD l, n;
+ LPSTR szT = NULL;
+
+ l = (DWORD)SendMessageA(GetDlgItem(hDlg, nIDDlgItem), WM_GETTEXTLENGTH, 0, 0);
+ if (l > 0) {
+ szT = apxPoolAlloc(hPool, (l + 1));
+ n = GetDlgItemTextA(hDlg, nIDDlgItem, szT, l + 1);
+ if (n == 0) {
+ apxFree(szT);
+ szT = NULL;
+ }
+ }
+ return szT;
+}
+
+/* Browse for folder dialog.
+ */
+LPSTR apxBrowseForFolderA(HWND hWnd, LPCSTR szTitle, LPCSTR szName)
+{
+ BROWSEINFOA bi;
+ LPITEMIDLIST il, ir;
+ LPMALLOC pMalloc;
+ CHAR szPath[MAX_PATH+1];
+ LPSTR rv = NULL;
+
+ AplZeroMemory(&bi, sizeof(BROWSEINFOW));
+ SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &il);
+ bi.lpszTitle = szTitle;
+ bi.pszDisplayName = szPath;
+ bi.hwndOwner = hWnd;
+ bi.ulFlags = BIF_EDITBOX;
+ bi.lpfn = NULL;
+ bi.lParam = 0;
+ bi.iImage = 0;
+ bi.pidlRoot = il;
+
+ if ((ir = SHBrowseForFolderA(&bi)) != NULL) {
+ if (SHGetPathFromIDListA(ir, szPath))
+ rv = apxStrdupA(szPath);
+ }
+ if (SHGetMalloc(&pMalloc)) {
+ pMalloc->lpVtbl->Free(pMalloc, il);
+ pMalloc->lpVtbl->Release(pMalloc);
+ }
+
+ return rv;
+}
+
+LPWSTR apxBrowseForFolderW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szName)
+{
+ BROWSEINFOW bi;
+ LPITEMIDLIST il, ir;
+ LPMALLOC pMalloc;
+ WCHAR szPath[MAX_PATH+1];
+ LPWSTR rv = NULL;
+
+ AplZeroMemory(&bi, sizeof(BROWSEINFOW));
+ SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &il);
+ bi.lpszTitle = szTitle;
+ bi.pszDisplayName = szPath;
+ bi.hwndOwner = hWnd;
+ bi.ulFlags = BIF_EDITBOX;
+ bi.lpfn = NULL;
+ bi.lParam = 0;
+ bi.iImage = 0;
+ bi.pidlRoot = il;
+
+ if ((ir = SHBrowseForFolderW(&bi)) != NULL) {
+ if (SHGetPathFromIDListW(ir, szPath))
+ rv = apxStrdupW(szPath);
+ }
+ if (SHGetMalloc(&pMalloc)) {
+ pMalloc->lpVtbl->Free(pMalloc, il);
+ pMalloc->lpVtbl->Release(pMalloc);
+ }
+
+ return rv;
+}
+
+LPSTR apxGetFileNameA(HWND hWnd, LPCSTR szTitle, LPCSTR szFilter,
+ LPCSTR szDefExt, LPCSTR szDefPath, BOOL bOpenOrSave,
+ LPDWORD lpdwFindex)
+{
+ OPENFILENAMEA lpOf;
+ CHAR szFile[SIZ_BUFLEN];
+ BOOL rv;
+
+ AplZeroMemory(&lpOf, sizeof(OPENFILENAMEA));
+ szFile[0] = '\0';
+ lpOf.lStructSize = sizeof(OPENFILENAMEA);
+ lpOf.hwndOwner = hWnd;
+ lpOf.hInstance = _st_sys_gui.hInstance;
+ lpOf.lpstrTitle = szTitle;
+ lpOf.lpstrFilter = szFilter;
+ lpOf.lpstrDefExt = szDefExt;
+ lpOf.lpstrInitialDir = szDefPath;
+ lpOf.lpstrFile = szFile;
+ lpOf.nMaxFile = SIZ_BUFMAX;
+ lpOf.Flags = OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
+
+ if (bOpenOrSave)
+ rv = GetOpenFileNameA(&lpOf);
+ else
+ rv = GetSaveFileNameA(&lpOf);
+
+ if (rv) {
+ if (lpdwFindex)
+ *lpdwFindex = lpOf.nFilterIndex;
+ return apxStrdupA(szFile);
+ }
+ else
+ return NULL;
+}
+
+LPWSTR apxGetFileNameW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szFilter,
+ LPCWSTR szDefExt, LPCWSTR szDefPath, BOOL bOpenOrSave,
+ LPDWORD lpdwFindex)
+{
+ OPENFILENAMEW lpOf;
+ WCHAR szFile[SIZ_BUFLEN];
+ BOOL rv;
+
+ AplZeroMemory(&lpOf, sizeof(OPENFILENAMEW));
+ szFile[0] = L'\0';
+ lpOf.lStructSize = sizeof(OPENFILENAMEW);
+ lpOf.hwndOwner = hWnd;
+ lpOf.hInstance = _st_sys_gui.hInstance;
+ lpOf.lpstrTitle = szTitle;
+ lpOf.lpstrFilter = szFilter;
+ lpOf.lpstrDefExt = szDefExt;
+ lpOf.lpstrInitialDir = szDefPath;
+ lpOf.lpstrFile = szFile;
+ lpOf.nMaxFile = SIZ_BUFMAX;
+ lpOf.Flags = OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
+
+ if (bOpenOrSave)
+ rv = GetOpenFileNameW(&lpOf);
+ else
+ rv = GetSaveFileNameW(&lpOf);
+
+ if (rv) {
+ if (lpdwFindex)
+ *lpdwFindex = lpOf.nFilterIndex;
+ return apxStrdupW(szFile);
+ }
+ else
+ return NULL;
+}
+
+static __apxSelectUserDlgResize(HWND hDlg, INT nWidth, INT nHeight)
+{
+ /* Combo box */
+ MoveWindow(GetDlgItem(hDlg, IDSU_COMBO),
+ 70, 10,
+ nWidth - 70,
+ 120,
+ TRUE);
+ /* List Window */
+ MoveWindow(GetDlgItem(hDlg, IDSU_LIST),
+ 0, 36,
+ nWidth,
+ nHeight - 74,
+ TRUE);
+
+ /* Name label */
+ MoveWindow(GetDlgItem(hDlg, IDSU_SELNAME),
+ 16,
+ nHeight - 30,
+ 50,
+ 24,
+ TRUE);
+
+ /* Edit Box */
+ MoveWindow(GetDlgItem(hDlg, IDSU_SELECTED),
+ 70,
+ nHeight - 32,
+ nWidth - 300,
+ 24,
+ TRUE);
+
+ /* OK Button */
+ MoveWindow(GetDlgItem(hDlg, IDOK),
+ nWidth - 200,
+ nHeight - 32,
+ 80,
+ 24,
+ TRUE);
+
+ /* Cancel Button */
+ MoveWindow(GetDlgItem(hDlg, IDCANCEL),
+ nWidth - 110,
+ nHeight - 32,
+ 80,
+ 24,
+ TRUE);
+
+
+}
+
+static LRESULT CALLBACK
+__apxSelectUserCreateLvSubclass(HWND hWnd, UINT uMsg, WPARAM wParam,
+ LPARAM lParam)
+{
+ static POINTS mouseClick;
+ int iS;
+ LVHITTESTINFO iHit;
+ switch (uMsg) {
+ case WM_LBUTTONDBLCLK:
+ /* Call the original window proc */
+ CallWindowProc(_st_sel_users_lvm, hWnd, uMsg, wParam, lParam);
+ mouseClick = MAKEPOINTS(lParam);
+ iHit.pt.x = mouseClick.x;
+ iHit.pt.y = mouseClick.y;
+ iS = ListView_HitTest(hWnd, &iHit);
+ if (iS >= 0) {
+ DWORD i;
+ WCHAR szUser[SIZ_RESLEN] = L"";
+ LPWSTR szP;
+ HWND hCombo;
+ HWND hDlg = GetParent(hWnd);
+ hCombo = GetDlgItem(hDlg, IDSU_COMBO);
+ if ((i = ComboBox_GetCurSel(hCombo)) == 0) {
+ lstrcpyW(szUser, L".\\");
+ }
+ else {
+ COMBOBOXEXITEMW cbEi;
+ cbEi.mask = CBEIF_TEXT;
+ cbEi.iItem = i;
+ cbEi.cchTextMax = SIZ_RESMAX;
+ cbEi.pszText = szUser;
+ SendMessage(hCombo, CBEM_GETITEM, 0, (LPARAM)&cbEi);
+ lstrcatW(szUser, L"\\");
+ }
+ szP = &szUser[lstrlenW(szUser)];
+ ListView_GetItemTextW(hWnd, iS, 0, szP, SIZ_RESMAX);
+ if (*szP) {
+ SetDlgItemTextW(hDlg, IDSU_SELECTED, szUser);
+ }
+ }
+ return TRUE;
+ break;
+ }
+ return CallWindowProc(_st_sel_users_lvm, hWnd, uMsg, wParam, lParam);
+}
+
+#define SUMIN_WIDTH 600
+#define SUMIN_HEIGHT 200
+
+static void __apxSelectUserCreateLv(HWND hDlg)
+{
+ DWORD i;
+ LV_COLUMN lvC;
+ HBITMAP hBmp;
+
+ HWND hList = GetDlgItem(hDlg, IDSU_LIST);
+
+ lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+ for (i = 0; i < NUMLVUSERS; i++) {
+ lvC.iSubItem = i;
+ lvC.cx = lvUsers[i].iWidth;
+ lvC.pszText = lvUsers[i].szLabel;
+ lvC.fmt = lvUsers[i].iFmt;
+ ListView_InsertColumn(hList, i, &lvC );
+ }
+#ifdef LVS_EX_FULLROWSELECT
+ ListView_SetExtendedListViewStyleEx(hList, 0,
+ LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
+#endif
+ _st_sel_users_il = ImageList_Create(16, 16, ILC_COLOR4, 0, 16);
+ hBmp = LoadImage(GetModuleHandleA(NULL), MAKEINTRESOURCE(IDB_SUSERS),
+ IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
+
+ ImageList_Add(_st_sel_users_il, hBmp, NULL);
+ DeleteObject(hBmp);
+
+ ListView_SetImageList(hList, _st_sel_users_il, LVSIL_SMALL);
+ _st_sel_users_lvm = (WNDPROC)((SIZE_T)SetWindowLong(hList, GWLP_WNDPROC,
+ (LONG)((SIZE_T)__apxSelectUserCreateLvSubclass)));
+
+}
+
+static void __apxSelectUserPopulate(HWND hDlg, LPCWSTR szComputer)
+{
+ PNET_DISPLAY_USER pBuff, p;
+ INT row = 0x7FFFFFFF;
+ DWORD res, dwRec, i = 0;
+
+ HWND hList = GetDlgItem(hDlg, IDSU_LIST);
+
+ ListView_DeleteAllItems(hList);
+
+ do {
+ res = NetQueryDisplayInformation(szComputer, 1, i, 1000, MAX_PREFERRED_LENGTH,
+ &dwRec, &pBuff);
+ if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+ p = pBuff;
+ for (;dwRec > 0; dwRec--) {
+ LV_ITEMW lvI;
+ AplZeroMemory(&lvI, sizeof(LV_ITEMW));
+ lvI.mask = LVIF_IMAGE | LVIF_TEXT;
+ lvI.iItem = 0x7FFFFFFF;
+ lvI.pszText = p->usri1_name;
+ if (p->usri1_flags & UF_ACCOUNTDISABLE)
+ lvI.iImage = 5;
+ else
+ lvI.iImage = 4;
+ row = ListView_InsertItemW(hList, &lvI);
+ if (row != -1) {
+ if (p->usri1_full_name) {
+ ListView_SetItemTextW(hList, row, 1,
+ p->usri1_full_name);
+ }
+ if (p->usri1_comment) {
+ ListView_SetItemTextW(hList, row, 2,
+ p->usri1_comment);
+ }
+ }
+ i = p->usri1_next_index;
+ p++;
+ }
+ NetApiBufferFree(pBuff);
+ }
+ } while (res == ERROR_MORE_DATA);
+
+}
+
+static void __apxSelectUserCreateCbex(HWND hDlg)
+{
+ COMBOBOXEXITEMW cbEi;
+ LPBYTE lpNetBuf;
+ LPWKSTA_INFO_100 lpWksta;
+ DWORD res;
+ HWND hCombo = GetDlgItem(hDlg, IDSU_COMBO);
+
+#ifndef _UNICODE
+ SendMessageW(hCombo, CBEM_SETUNICODEFORMAT, TRUE, 0);
+#endif
+
+ cbEi.mask = CBEIF_TEXT | CBEIF_INDENT |
+ CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
+
+ res = NetWkstaGetInfo(NULL, 101, (LPBYTE *)&lpWksta);
+ if (res != ERROR_SUCCESS) {
+ EnableWindow(hCombo, FALSE);
+ return;
+ }
+ /* add localhost computer */
+ cbEi.iItem = 0;
+ cbEi.pszText = (LPWSTR)lpWksta->wki100_computername;
+ cbEi.iIndent = 0;
+ cbEi.iImage = 1;
+ cbEi.iSelectedImage = 1;
+ SendMessageW(hCombo, CBEM_INSERTITEMW, 0, (LPARAM)&cbEi);
+ NetApiBufferFree(lpWksta);
+
+ ComboBox_SetCurSel(hCombo, 0);
+ res = NetGetDCName(NULL, NULL, &lpNetBuf);
+ if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+
+ cbEi.iItem = 1;
+ cbEi.pszText = ((LPWSTR)lpNetBuf) + 2;
+ cbEi.iIndent = 0;
+ cbEi.iImage = 0;
+ cbEi.iSelectedImage = 0;
+ SendMessageW(hCombo, CBEM_INSERTITEMW, 0, (LPARAM)&cbEi);
+ EnableWindow(hCombo, TRUE);
+ NetApiBufferFree(lpNetBuf);
+ }
+ else
+ EnableWindow(hCombo, FALSE);
+
+ SendMessageW(hCombo, CBEM_SETIMAGELIST, 0, (LPARAM)_st_sel_users_il);
+}
+
+static LRESULT CALLBACK __apxSelectUserDlgProc(HWND hDlg, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ static HWND hList;
+ static LPWSTR lpUser;
+ RECT r, *l;
+
+ switch (uMsg) {
+ case WM_INITDIALOG:
+ /* Set the application icon */
+ SetClassLong(hDlg, GCLP_HICON,
+ (LONG)(SIZE_T)LoadIcon(_st_sys_gui.hInstance,
+ MAKEINTRESOURCE(IDI_MAINICON)));
+ apxCenterWindow(hDlg, _st_sys_gui.hMainWnd);
+ hList = GetDlgItem(hDlg, IDSU_LIST);
+ __apxSelectUserCreateLv(hDlg);
+ __apxSelectUserCreateCbex(hDlg);
+ GetClientRect(hDlg, &r);
+ /* Resize the controls */
+ __apxSelectUserDlgResize(hDlg, r.right - r.left,
+ r.bottom - r.top);
+ lpUser = (LPWSTR)lParam;
+ __apxSelectUserPopulate(hDlg, NULL);
+ return TRUE;
+ break;
+ case WM_SIZING:
+ l = (LPRECT)lParam;
+ /* limit the window size */
+ switch (wParam) {
+ case WMSZ_BOTTOM:
+ case WMSZ_BOTTOMRIGHT:
+ if ((l->bottom - l->top) < SUMIN_HEIGHT)
+ l->bottom = l->top + SUMIN_HEIGHT;
+ if ((l->right - l->left) < SUMIN_WIDTH)
+ l->right = l->left + SUMIN_WIDTH;
+ break;
+ case WMSZ_TOPLEFT:
+ if ((l->bottom - l->top) < SUMIN_HEIGHT)
+ l->top = l->bottom - SUMIN_HEIGHT;
+ if ((l->right - l->left) < SUMIN_WIDTH)
+ l->left = l->right - SUMIN_WIDTH;
+ break;
+ case WMSZ_TOP:
+ case WMSZ_RIGHT:
+ case WMSZ_TOPRIGHT:
+ if ((l->bottom - l->top) < SUMIN_HEIGHT)
+ l->top = l->bottom - SUMIN_HEIGHT;
+ if ((l->right - l->left) < SUMIN_WIDTH)
+ l->right = l->left + SUMIN_WIDTH;
+ break;
+ case WMSZ_BOTTOMLEFT:
+ case WMSZ_LEFT:
+ if ((l->bottom - l->top) < SUMIN_HEIGHT)
+ l->bottom = l->top + SUMIN_HEIGHT;
+ if ((l->right - l->left) < SUMIN_WIDTH)
+ l->left = l->right - SUMIN_WIDTH;
+ break;
+ }
+ break;
+ case WM_SIZE:
+ __apxSelectUserDlgResize(hDlg, LOWORD(lParam),
+ HIWORD(lParam));
+ GetClientRect(hDlg, &r);
+ InvalidateRect(hDlg, &r, FALSE);
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+ case IDCANCEL:
+ /* Clear the user name buffer */
+ *lpUser = L'\0';
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+ break;
+ case IDSU_SELECTED:
+ if (HIWORD(wParam) == EN_CHANGE) {
+ /* enable OK button if there is a user */
+ GetDlgItemTextW(hDlg, IDSU_SELECTED, lpUser, SIZ_RESMAX);
+ if (lstrlenW(lpUser))
+ Button_Enable(GetDlgItem(hDlg, IDOK), TRUE);
+ else
+ Button_Enable(GetDlgItem(hDlg, IDOK), FALSE);
+ }
+ break;
+ case IDSU_COMBO:
+ if (HIWORD(wParam) == CBN_SELCHANGE) {
+ COMBOBOXEXITEMW cbEi;
+ DWORD i;
+ WCHAR szServer[SIZ_RESLEN] = L"\\\\";
+ HWND hCombo = GetDlgItem(hDlg, IDSU_COMBO);
+ if ((i = ComboBox_GetCurSel(hCombo)) >= 0) {
+ cbEi.mask = CBEIF_TEXT;
+ cbEi.iItem = i;
+ cbEi.cchTextMax = SIZ_RESMAX;
+ cbEi.pszText = &szServer[2];
+ SendMessageW(hCombo, CBEM_GETITEM, 0, (LPARAM)&cbEi);
+ }
+ if (szServer[2])
+ __apxSelectUserPopulate(hDlg, szServer);
+ }
+ break;
+
+ }
+ break;
+ case WM_MOUSEWHEEL:
+ {
+ int nScroll;
+ if ((SHORT)HIWORD(wParam) < 0)
+ nScroll = _st_sys_gui.nWhellScroll;
+ else
+ nScroll = _st_sys_gui.nWhellScroll * (-1);
+ }
+ break;
+
+ }
+ return FALSE;
+}
+
+
+LPCWSTR apxDlgSelectUser(HWND hWnd, LPWSTR szUser)
+{
+ szUser[0] = L'\0';
+
+ DialogBoxParam(_st_sys_gui.hInstance,
+ MAKEINTRESOURCE(IDD_SELUSER),
+ hWnd,
+ (DLGPROC)__apxSelectUserDlgProc,
+ (LPARAM)szUser);
+ if (_st_sel_users_il)
+ ImageList_Destroy(_st_sel_users_il);
+ _st_sel_users_il = NULL;
+ if (szUser[0] != '\0')
+ return szUser;
+ else
+ return NULL;
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/gui.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/handles.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/handles.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/handles.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,686 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define ALLOCBLOCK_INVALID 0xdeadbeef
+
+typedef struct APXPOOL APXPOOL;
+typedef APXPOOL* LPAPXPOOL;
+
+typedef struct ALLOCBLOCK {
+ DWORD dwSize;
+ APXHANDLE lpPool;
+ APXMEMWORD lpAlign;
+} ALLOCBLOCK, *LPALLOCBLOCK;
+
+struct APXPOOL {
+ TAILQ_HEAD(_lHandles, stAPXHANDLE) lHandles;
+ TAILQ_HEAD(_lPools, stAPXHANDLE) lPools;
+};
+
+static SYSTEM_INFO _st_sys_info;
+static APXHANDLE _st_sys_pool = NULL;
+static int _st_sys_init = 0;
+static LPVOID _st_sys_page = NULL;
+LPWSTR *_st_sys_argvw = NULL;
+int _st_sys_argc = 0;
+
+#ifdef _DEBUG
+static INT _heap_count = 0;
+static INT _heap_alloc_count = 0;
+static INT _heap_realloc_count = 0;
+
+HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
+{
+ _heap_count++;
+ return HeapCreate(flOptions, dwInitialSize, dwMaximumSize);
+}
+
+BOOL HeapDESTROY(HANDLE hHeap)
+{
+ _heap_count--;
+ return HeapDestroy(hHeap);
+}
+
+
+LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize)
+{
+ _heap_alloc_count++;
+ return HeapAlloc(hHeap, dwFlags, nSize);
+}
+
+BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
+{
+ _heap_alloc_count--;
+ return HeapFree(hHeap, dwFlags, lpMem);
+}
+
+LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
+{
+
+ _heap_realloc_count++;
+ return HeapReAlloc(hHeap, dwFlags, lpMem, dwBytes);
+}
+#endif
+
+static LPVOID __apxPoolAllocCore(APXHANDLE hPool,
+ DWORD dwSize, DWORD dwOptions)
+{
+ DWORD dwPhysicalSize;
+ LPALLOCBLOCK lpBlock;
+
+ if (!hPool)
+ hPool = _st_sys_pool;
+ dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
+ lpBlock = HeapALLOC(hPool->hHeap, dwOptions, dwPhysicalSize);
+ lpBlock->dwSize = dwPhysicalSize;
+ lpBlock->lpPool = hPool;
+
+ return ((char *)lpBlock + sizeof(ALLOCBLOCK));
+}
+
+static LPVOID __apxPoolReallocCore(APXHANDLE hPool, LPVOID lpMem,
+ DWORD dwSize, DWORD dwOptions)
+{
+ DWORD dwPhysicalSize;
+ LPALLOCBLOCK lpBlock;
+ LPALLOCBLOCK lpOrg;
+
+ if (!lpMem)
+ return __apxPoolAllocCore(hPool, dwSize, dwOptions);
+ lpOrg = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
+ if (!hPool)
+ hPool = _st_sys_pool;
+ /* Trying to realloc something that isn't valid */
+ if (lpOrg->lpPool == APXHANDLE_INVALID ||
+ lpOrg->lpPool != hPool)
+ return NULL;
+ dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
+ lpBlock = HeapREALLOC(hPool->hHeap, dwOptions, lpOrg, dwPhysicalSize);
+ lpBlock->dwSize = dwPhysicalSize;
+ lpBlock->lpPool = hPool;
+
+ return ((char *)lpBlock + sizeof(ALLOCBLOCK));
+}
+
+static void __apxPoolFreeCore(LPVOID lpMem)
+{
+ APXHANDLE hPool;
+ LPALLOCBLOCK lpBlock = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
+
+ if (lpBlock->lpPool != APXHANDLE_INVALID) {
+ hPool = lpBlock->lpPool;
+ lpBlock->lpPool = APXHANDLE_INVALID;
+ }
+ else
+ return;
+ HeapFREE(hPool->hHeap, 0, lpBlock);
+}
+/*
+ *
+ */
+static DWORD WINAPI __apxHandleEventThread(LPVOID lpParameter)
+{
+ APXHANDLE hHandle = (APXHANDLE)lpParameter;
+ DWORD rv = 0;
+ while (hHandle->dwType != APXHANDLE_TYPE_INVALID) {
+ DWORD dwState;
+ dwState = WaitForSingleObject(hHandle->hEventHandle, INFINITE);
+ /* the flags can be changed to invalid meaning we are killing
+ * this event.
+ */
+ if (dwState == WAIT_OBJECT_0 &&
+ hHandle->dwType != APXHANDLE_TYPE_INVALID) {
+ if (hHandle->uMsg && (hHandle->wParam || hHandle->lParam)) {
+ APXCALLHOOK *lpCall;
+ rv = (*hHandle->fnCallback)(hHandle, hHandle->uMsg,
+ hHandle->wParam, hHandle->lParam);
+ TAILQ_FOREACH(lpCall, &hHandle->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hHandle, hHandle->uMsg,
+ hHandle->wParam, hHandle->lParam);
+ }
+ hHandle->uMsg = 0;
+ if (!rv)
+ break;
+ }
+ ResetEvent(hHandle->hEventHandle);
+ SwitchToThread();
+ }
+ else
+ break;
+ }
+ ResetEvent(hHandle->hEventHandle);
+ /* This will rise the Thread waiting function */
+ return 0;
+}
+
+static BOOL __apxPoolCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXPOOL lpPool;
+ APXHANDLE hCur;
+ if (hObject->dwType != APXHANDLE_TYPE_POOL)
+ return FALSE;
+ lpPool = APXHANDLE_DATA(hObject);
+
+ /* recurse the subpools */
+ TAILQ_FOREACH(hCur, &lpPool->lPools, queue) {
+ __apxPoolCallback(hCur, uMsg, 0, 0);
+ }
+ /* call the handles callback */
+ for(hCur = TAILQ_FIRST(&lpPool->lHandles) ;
+ hCur != NULL ;
+ hCur = TAILQ_FIRST(&lpPool->lHandles)) {
+ apxCloseHandle(hCur);
+ }
+ /* if we are closing this pool destroy the private Heap */
+ if (uMsg == WM_CLOSE) {
+ if (hObject->dwFlags & APXHANDLE_HAS_HEAP)
+ HeapDESTROY(hObject->hHeap);
+ hObject->dwSize = 0;
+ }
+ else if (uMsg == WM_CLEAR)
+ hObject->dwSize = 0;
+
+ return TRUE;
+}
+
+static BOOL __apxHandleCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ BOOL rv = FALSE;
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ /* Default handler handles only close event */
+ if (uMsg != WM_CLOSE)
+ return FALSE;
+ if (hObject->dwType == APXHANDLE_TYPE_WINHANDLE &&
+ !(IS_INVALID_HANDLE(hObject->uData.hWinHandle))) {
+ rv = CloseHandle(hObject->uData.hWinHandle);
+ hObject->uData.hWinHandle = NULL;
+ }
+ /* Invalidate the handle */
+ hObject->dwType = APXHANDLE_TYPE_INVALID;
+
+ if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+ DWORD dwState;
+ /* Signal the EventThread to exit */
+ SetEvent(hObject->hEventHandle);
+ /* Wait for EventThread to Exit */
+ dwState = WaitForSingleObject(hObject->hEventThread, 1000);
+ SAFE_CLOSE_HANDLE(hObject->hEventHandle);
+ if (dwState == WAIT_TIMEOUT)
+ TerminateThread(hObject->hEventThread, 0);
+ SAFE_CLOSE_HANDLE(hObject->hEventThread);
+ /* Reset the evant flag */
+ hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
+ }
+ return rv;
+}
+
+static BOOL __apxCreateSystemPool()
+{
+ LPAPXPOOL lpPool;
+ HANDLE hHeap;
+
+ GetSystemInfo(&_st_sys_info);
+ apxGetOsLevel();
+ /* First create the shared data segment */
+ _st_sys_page = VirtualAlloc(NULL, _st_sys_info.dwAllocationGranularity,
+ MEM_RESERVE, PAGE_NOACCESS);
+ if (!_st_sys_page)
+ return FALSE;
+ _st_sys_page = VirtualAlloc(_st_sys_page, _st_sys_info.dwAllocationGranularity,
+ MEM_COMMIT, PAGE_READWRITE);
+
+ /* Create the main Heap */
+ hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
+ _st_sys_pool = HeapALLOC(hHeap, HEAP_ZERO_MEMORY,
+ APX_ALIGN_DEFAULT(APXHANDLE_SZ + sizeof(APXPOOL)));
+ _st_sys_pool->hHeap = hHeap;
+ _st_sys_pool->dwType = APXHANDLE_TYPE_INVALID;
+ if (IS_INVALID_HANDLE(_st_sys_pool->hHeap))
+ return FALSE;
+ _st_sys_pool->fnCallback = __apxPoolCallback;
+ lpPool = APXHANDLE_DATA(_st_sys_pool);
+ /* Initialize the pool and object lists */
+ TAILQ_INIT(&lpPool->lHandles);
+ TAILQ_INIT(&lpPool->lPools);
+ _st_sys_pool->dwType = APXHANDLE_TYPE_POOL;
+
+ /** TODO: For each unsupported function make a surrogate */
+ _st_sys_argvw = CommandLineToArgvW(GetCommandLineW(), &_st_sys_argc);
+
+ return TRUE;
+}
+
+BOOL
+apxHandleManagerInitialize()
+{
+ BOOL rv;
+ if (_st_sys_init++)
+ return TRUE;
+ rv = __apxCreateSystemPool();
+
+ return rv;
+}
+
+BOOL
+apxHandleManagerDestroy()
+{
+ HANDLE hHeap;
+
+ if (--_st_sys_init == 0) {
+ hHeap = _st_sys_pool->hHeap;
+ apxCloseHandle(_st_sys_pool);
+ /* Destroy the main Heap */
+ HeapDESTROY(hHeap);
+ _st_sys_pool = NULL;
+ VirtualFree(_st_sys_page, 0, MEM_RELEASE);
+ GlobalFree(_st_sys_argvw);
+ _st_sys_argvw = NULL;
+ _st_sys_argc = 0;
+#ifdef _DEBUG
+ apxLogWrite(APXLOG_MARK_DEBUG "Alloc Count %d", _heap_alloc_count);
+ apxLogWrite(APXLOG_MARK_DEBUG "Realloc Count %d", _heap_realloc_count);
+ apxLogWrite(APXLOG_MARK_DEBUG "Heap Count %d", _heap_count);
+#endif
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+APXHANDLE
+apxPoolCreate(APXHANDLE hParent, DWORD dwOptions)
+{
+ APXHANDLE hHandle;
+ LPAPXPOOL lpPool;
+ HANDLE hHeap;
+
+ if (IS_INVALID_HANDLE(hParent))
+ hParent = _st_sys_pool;
+ if (hParent->dwType != APXHANDLE_TYPE_POOL) {
+ apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
+ hParent->dwType);
+ return INVALID_HANDLE_VALUE;
+ }
+ /* Allocate the handle from the parent */
+ hHandle = __apxPoolAllocCore(hParent, APXHANDLE_SZ + sizeof(APXPOOL),
+ HEAP_ZERO_MEMORY);
+
+ if (dwOptions & APXHANDLE_HAS_HEAP) {
+ /* Create the private Heap */
+ hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
+ hHandle->dwFlags |= APXHANDLE_HAS_HEAP;
+ }
+ else
+ hHeap = hParent->hHeap;
+ hHandle->hHeap = hHeap;
+ hHandle->dwType = APXHANDLE_TYPE_POOL;
+ hHandle->hPool = hParent;
+ hHandle->fnCallback = __apxPoolCallback;
+ lpPool = APXHANDLE_DATA(hHandle);
+ TAILQ_INIT(&lpPool->lHandles);
+ TAILQ_INIT(&lpPool->lPools);
+
+ /* Insert the pool to the head of parent pool */
+ lpPool = APXHANDLE_DATA(hParent);
+ APXHANDLE_SPINLOCK(hParent);
+ TAILQ_INSERT_HEAD(&lpPool->lPools, hHandle, queue);
+ ++hParent->dwSize;
+ APXHANDLE_SPINUNLOCK(hParent);
+
+ return hHandle;
+}
+
+LPVOID
+apxPoolAlloc(APXHANDLE hPool, DWORD dwSize)
+{
+ if (IS_INVALID_HANDLE(hPool) ||
+ (hPool->dwType != APXHANDLE_TYPE_POOL))
+ hPool = _st_sys_pool;
+ return __apxPoolAllocCore(hPool, dwSize, 0);
+}
+
+LPVOID
+apxPoolCalloc(APXHANDLE hPool, DWORD dwSize)
+{
+ if (IS_INVALID_HANDLE(hPool) ||
+ (hPool->dwType != APXHANDLE_TYPE_POOL))
+ hPool = _st_sys_pool;
+ return __apxPoolAllocCore(hPool, dwSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxPoolRealloc(APXHANDLE hPool, LPVOID lpMem, DWORD dwNewSize)
+{
+ if (IS_INVALID_HANDLE(hPool) ||
+ (hPool->dwType != APXHANDLE_TYPE_POOL))
+ hPool = _st_sys_pool;
+ return __apxPoolReallocCore(hPool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxAlloc(DWORD dwSize)
+{
+ return __apxPoolAllocCore(_st_sys_pool, dwSize, 0);
+}
+
+LPVOID
+apxCalloc(DWORD dwSize)
+{
+ return __apxPoolAllocCore(_st_sys_pool, dwSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxRealloc(LPVOID lpMem, DWORD dwNewSize)
+{
+ return __apxPoolReallocCore(_st_sys_pool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
+}
+
+VOID
+apxFree(LPVOID lpMem)
+{
+ if (lpMem)
+ __apxPoolFreeCore(lpMem);
+
+}
+
+LPWSTR
+apxPoolWStrdupA(APXHANDLE hPool, LPCSTR szSource)
+{
+ if (szSource) {
+ LPWSTR szDest;
+ DWORD l = lstrlenA(szSource);
+ szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+ AsciiToWide(szSource, szDest);
+ return szDest;
+ }
+ else
+ return NULL;
+}
+
+LPWSTR apxWStrdupA(LPCTSTR szSource)
+{
+ return apxPoolWStrdup(_st_sys_pool, szSource);
+}
+
+LPSTR
+apxPoolStrdupA(APXHANDLE hPool, LPCSTR szSource)
+{
+ if (szSource) {
+ LPSTR szDest;
+ DWORD l = lstrlenA(szSource);
+ szDest = apxPoolAlloc(hPool, l + 1);
+ lstrcpyA(szDest, szSource);
+ return szDest;
+ }
+ else
+ return NULL;
+}
+
+LPWSTR
+apxPoolStrdupW(APXHANDLE hPool, LPCWSTR szSource)
+{
+ if (szSource) {
+ LPWSTR szDest;
+ DWORD l = lstrlenW(szSource);
+ szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+ lstrcpyW(szDest, szSource);
+ return szDest;
+ }
+ else
+ return NULL;
+}
+
+LPSTR
+apxStrdupA(LPCSTR szSource)
+{
+ return apxPoolStrdupA(_st_sys_pool, szSource);
+}
+
+LPWSTR
+apxStrdupW(LPCWSTR szSource)
+{
+ return apxPoolStrdupW(_st_sys_pool, szSource);
+}
+
+APXHANDLE
+apxHandleCreate(APXHANDLE hPool, DWORD dwFlags,
+ LPVOID lpData, DWORD dwDataSize,
+ LPAPXFNCALLBACK fnCallback)
+{
+ APXHANDLE hHandle;
+ LPAPXPOOL lpPool;
+
+ if (IS_INVALID_HANDLE(hPool))
+ hPool = _st_sys_pool;
+ if (hPool->dwType != APXHANDLE_TYPE_POOL) {
+ apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
+ hPool->dwType);
+ return INVALID_HANDLE_VALUE;
+ }
+ hHandle = __apxPoolAllocCore(hPool, APXHANDLE_SZ + dwDataSize,
+ HEAP_ZERO_MEMORY);
+
+ hHandle->hPool = hPool;
+ if (fnCallback)
+ hHandle->fnCallback = fnCallback;
+ else
+ hHandle->fnCallback = __apxHandleCallback;
+
+ if (dwFlags & APXHANDLE_TYPE_WINHANDLE) {
+ hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+ hHandle->dwFlags |= APXHANDLE_TYPE_WINHANDLE;
+ hHandle->uData.hWinHandle = lpData;
+ }
+ else if (dwFlags & APXHANDLE_TYPE_LPTR) {
+ hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+ hHandle->dwFlags |= APXHANDLE_TYPE_LPTR;
+ hHandle->uData.lpPtr = lpData;
+ }
+ else if (dwDataSize && lpData) {
+ hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+ AplCopyMemory(APXHANDLE_DATA(hHandle), lpData, dwDataSize);
+ hHandle->dwSize = dwDataSize;
+ }
+
+ if (dwFlags & APXHANDLE_HAS_EVENT) {
+ /* Create the message event and message wathcing thread */
+ hHandle->hEventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
+ hHandle->hEventThread = CreateThread(NULL, 0, __apxHandleEventThread,
+ hHandle, 0,
+ &(hHandle->hEventThreadId));
+ if (IS_INVALID_HANDLE(hHandle->hEventThread)) {
+ SAFE_CLOSE_HANDLE(hHandle->hEventHandle);
+ }
+ else
+ hHandle->dwFlags |= APXHANDLE_HAS_EVENT;
+ }
+ TAILQ_INIT(&hHandle->lCallbacks);
+ /* Add the handle to the pool's object list */
+ lpPool = APXHANDLE_DATA(hPool);
+ APXHANDLE_SPINLOCK(hPool);
+ TAILQ_INSERT_HEAD(&lpPool->lHandles, hHandle, queue);
+ ++hPool->dwSize;
+ APXHANDLE_SPINUNLOCK(hPool);
+
+ return hHandle;
+}
+
+BOOL
+apxCloseHandle(APXHANDLE hObject)
+{
+ LPAPXPOOL lpPool;
+ APXCALLHOOK *lpCall;
+
+ if (IS_INVALID_HANDLE(hObject) || hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ /* Call the user callback first */
+ (*hObject->fnCallback)(hObject, WM_CLOSE, 0, 0);
+ /* Now go through the callback chain */
+ TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hObject, WM_CLOSE, 0, 0);
+ TAILQ_REMOVE(&hObject->lCallbacks, lpCall, queue);
+ __apxPoolFreeCore(lpCall);
+ }
+
+ hObject->dwType = APXHANDLE_TYPE_INVALID;
+ if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+ DWORD dwState;
+
+ SetEvent(hObject->hEventHandle);
+ dwState = WaitForSingleObject(hObject->hEventThread, 1000);
+ SAFE_CLOSE_HANDLE(hObject->hEventHandle);
+ if (dwState == WAIT_TIMEOUT)
+ TerminateThread(hObject->hEventThread, 0);
+ SAFE_CLOSE_HANDLE(hObject->hEventThread);
+
+ hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
+ }
+
+ /* finaly remove the object from the pool's object list */
+ if (!IS_INVALID_HANDLE(hObject->hPool)) {
+ lpPool = APXHANDLE_DATA(hObject->hPool);
+ APXHANDLE_SPINLOCK(hObject->hPool);
+ TAILQ_REMOVE(&lpPool->lHandles, hObject, queue);
+ hObject->hPool->dwSize--;
+ APXHANDLE_SPINUNLOCK(hObject->hPool);
+ __apxPoolFreeCore(hObject);
+ }
+ return TRUE;
+}
+
+LPVOID
+apxHandleGetUserData(APXHANDLE hObject)
+{
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return NULL;
+ if (hObject->dwFlags & APXHANDLE_HAS_USERDATA)
+ return APXHANDLE_DATA(hObject);
+ else
+ return hObject->uData.lpPtr;
+}
+
+LPVOID
+apxHandleSetUserData(APXHANDLE hObject, LPVOID lpData, DWORD dwDataSize)
+{
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return NULL;
+ if (hObject->dwFlags & APXHANDLE_HAS_USERDATA && hObject->dwSize > 0) {
+ AplCopyMemory(APXHANDLE_DATA(hObject), lpData,
+ MIN(hObject->dwSize, dwDataSize));
+ return APXHANDLE_DATA(hObject);
+ }
+ else {
+ LPVOID lpOrg = hObject->uData.lpPtr;
+ hObject->uData.lpPtr = lpData;
+ return lpOrg;
+ }
+}
+
+BOOL apxHandleSendMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ BOOL rv = TRUE;
+ APXCALLHOOK *lpCall;
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ /* Serialize requests to the callback */
+ APXHANDLE_SPINLOCK(hObject);
+ if (hObject->fnCallback)
+ rv = (*hObject->fnCallback)(hObject, uMsg, wParam, lParam);
+ TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hObject, uMsg, wParam, lParam);
+ }
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return rv;
+}
+
+BOOL apxHandlePostMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+ return FALSE;
+ if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+ /* TODO: Create a thread message queue
+ * Right now wait while the event gets nonsignaled
+ */
+ while (WaitForSingleObject(hObject->hEventHandle, 0) == WAIT_OBJECT_0)
+ SwitchToThread();
+ APXHANDLE_SPINLOCK(hObject);
+ SuspendThread(hObject->hEventThread);
+ hObject->uMsg = uMsg;
+ hObject->wParam = wParam;
+ hObject->lParam = lParam;
+ /* Signal the event thread to call the user callback */
+ SetEvent(hObject->hEventHandle);
+ ResumeThread(hObject->hEventThread);
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+BOOL apxHandleLock(APXHANDLE hObject, BOOL bLock)
+{
+ if (bLock)
+ APXHANDLE_SPINLOCK(hObject);
+ else
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return TRUE;
+}
+
+BOOL apxHandleAddHook(APXHANDLE hObject, DWORD dwWhere,
+ LPAPXFNCALLBACK fnCallback)
+{
+ APXCALLHOOK *lpCall;
+
+ if (hObject->dwType == APXHANDLE_TYPE_INVALID || !fnCallback)
+ return FALSE;
+ lpCall = (APXCALLHOOK *)__apxPoolAllocCore(hObject->hPool,
+ sizeof(APXCALLHOOK), 0);
+ if (!lpCall)
+ return FALSE;
+ lpCall->fnCallback = fnCallback;
+ APXHANDLE_SPINLOCK(hObject);
+ if (dwWhere == APXHANDLE_HOOK_FIRST) {
+ TAILQ_INSERT_HEAD(&hObject->lCallbacks, lpCall, queue);
+ }
+ else {
+ TAILQ_INSERT_TAIL(&hObject->lCallbacks, lpCall, queue);
+ }
+ APXHANDLE_SPINUNLOCK(hObject);
+
+ return TRUE;
+}
+
+DWORD apxHandleWait(APXHANDLE hHandle, DWORD dwMilliseconds, BOOL bKill)
+{
+ if (IS_INVALID_HANDLE(hHandle))
+ return WAIT_ABANDONED;
+ if (hHandle->dwType == APXHANDLE_TYPE_JVM)
+ return apxJavaWait(hHandle, dwMilliseconds, bKill);
+ else if (hHandle->dwType == APXHANDLE_TYPE_PROCESS)
+ return apxProcessWait(hHandle, dwMilliseconds, bKill);
+ else
+ return WAIT_ABANDONED;
+}
+
Property changes on: trunk/utils/windows/native/service/procrun/src/handles.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/javajni.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/javajni.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/javajni.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,784 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#include <jni.h>
+
+#ifndef JNI_VERSION_1_2
+#error -------------------------------------------------------
+#error JAVA 1.1 IS NO LONGER SUPPORTED
+#error -------------------------------------------------------
+#endif
+
+#ifdef JNI_VERSION_1_4
+#define JNI_VERSION_DEFAULT JNI_VERSION_1_4
+#else
+#define JNI_VERSION_DEFAULT JNI_VERSION_1_2
+#endif
+
+/* Standard jvm.dll prototypes
+ * since only single jvm can exist per process
+ * make those global
+ */
+
+DYNOLAD_TYPE_DECLARE(JNI_GetDefaultJavaVMInitArgs, JNICALL, jint)(void *);
+static DYNLOAD_FPTR_DECLARE(JNI_GetDefaultJavaVMInitArgs) = NULL;
+
+DYNOLAD_TYPE_DECLARE(JNI_CreateJavaVM, JNICALL, jint)(JavaVM **, void **, void *);
+static DYNLOAD_FPTR_DECLARE(JNI_CreateJavaVM) = NULL;
+
+DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, jsize *);
+static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
+
+static HANDLE _st_sys_jvmDllHandle = NULL;
+
+#define JVM_DELETE_CLAZZ(jvm, cl) \
+ APXMACRO_BEGIN \
+ if ((jvm)->lpEnv && (jvm)->##cl.jClazz) { \
+ (*((jvm)->lpEnv))->DeleteGlobalRef((jvm)->lpEnv, (jvm)->##cl.jClazz); \
+ (jvm)->##cl.jClazz = NULL; \
+ } APXMACRO_END
+
+#define JVM_EXCEPTION_CHECK(jvm) \
+ ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv) != JNI_OK)
+
+#ifdef _DEBUG
+#define JVM_EXCEPTION_CLEAR(jvm) \
+ APXMACRO_BEGIN \
+ if ((jvm)->lpEnv) { \
+ if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) { \
+ (*((jvm)->lpEnv))->ExceptionDescribe((jvm)->lpEnv); \
+ (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv); \
+ } \
+ } APXMACRO_END
+#else
+#define JVM_EXCEPTION_CLEAR(jvm) \
+ APXMACRO_BEGIN \
+ if ((jvm)->lpEnv) { \
+ if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) { \
+ (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv); \
+ } \
+ } APXMACRO_END
+#endif
+
+#define JNI_LOCAL_UNREF(obj) \
+ (*(lpJava->lpEnv))->DeleteLocalRef(lpJava->lpEnv, obj)
+
+#define JNICALL_0(fName) \
+ ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv))
+
+#define JNICALL_1(fName, a1) \
+ ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1)))
+
+#define JNICALL_2(fName, a1, a2) \
+ ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2)))
+
+#define JNICALL_3(fName, a1, a2, a3) \
+ ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3)))
+
+#define JNICALL_4(fName, a1, a2, a3, a4) \
+ ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
+
+typedef struct APXJAVASTDCLAZZ {
+ jclass jClazz;
+ jmethodID jMethod;
+ jobject jObject;
+ jarray jArgs;
+} APXJAVASTDCLAZZ, *LPAPXJAVASTDCLAZZ;
+
+typedef struct APXJAVAVM {
+ DWORD dwOptions;
+ APXJAVASTDCLAZZ clString;
+ APXJAVASTDCLAZZ clWorker;
+ jint iVersion;
+ jsize iVmCount;
+ JNIEnv *lpEnv;
+ JavaVM *lpJvm;
+ /* JVM worker thread info */
+ HANDLE hWorkerThread;
+ DWORD iWorkerThread;
+ DWORD dwWorkerStatus;
+
+} APXJAVAVM, *LPAPXJAVAVM;
+
+#define JAVA_CLASSPATH "-Djava.class.path="
+#define JAVA_CLASSSTRING "java/lang/String"
+
+static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
+{
+ jint _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
+ (void **)&(lpJava->lpEnv),
+ lpJava->iVersion);
+ if (_iStatus != JNI_OK) {
+ if (_iStatus == JNI_EDETACHED)
+ _iStatus = (*(lpJava->lpJvm))->AttachCurrentThread(lpJava->lpJvm,
+ (void **)&(lpJava->lpEnv), NULL);
+ }
+ if (_iStatus != JNI_OK) {
+ lpJava->lpEnv = NULL;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
+{
+ jint _iStatus = (*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm);
+ if (_iStatus != JNI_OK) {
+ lpJava->lpEnv = NULL;
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+static BOOL __apxLoadJvmDll(LPCWSTR szJvmDllPath)
+{
+ UINT errMode;
+ LPWSTR dllJvmPath = (LPWSTR)szJvmDllPath;
+
+ if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+ return TRUE; /* jvm.dll is already loaded */
+
+ if (!dllJvmPath || *dllJvmPath == L'\0')
+ dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
+ if (!dllJvmPath)
+ return FALSE;
+ /* Suppress the not found system popup message */
+ errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
+ /* This shuldn't happen, but try to search in %PATH% */
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+ _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
+ LOAD_WITH_ALTERED_SEARCH_PATH);
+ /* Restore the error mode signalization */
+ SetErrorMode(errMode);
+ if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ DYNLOAD_FPTR_LOAD(JNI_GetDefaultJavaVMInitArgs, _st_sys_jvmDllHandle);
+ DYNLOAD_FPTR_LOAD(JNI_CreateJavaVM, _st_sys_jvmDllHandle);
+ DYNLOAD_FPTR_LOAD(JNI_GetCreatedJavaVMs, _st_sys_jvmDllHandle);
+
+ if (!DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs) ||
+ !DYNLOAD_FPTR(JNI_CreateJavaVM) ||
+ !DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ FreeLibrary(_st_sys_jvmDllHandle);
+ _st_sys_jvmDllHandle = NULL;
+ return FALSE;
+ }
+
+ /* Real voodo ... */
+ return TRUE;
+}
+
+static BOOL __apxJavaJniCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXJAVAVM lpJava;
+ DWORD dwJvmRet = 0;
+
+ lpJava = APXHANDLE_DATA(hObject);
+ switch (uMsg) {
+ case WM_CLOSE:
+ if (lpJava->lpJvm) {
+ if (!IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
+ if (GetExitCodeThread(lpJava->hWorkerThread, &dwJvmRet) &&
+ dwJvmRet == STILL_ACTIVE) {
+ TerminateThread(lpJava->hWorkerThread, 5);
+ }
+ }
+ SAFE_CLOSE_HANDLE(lpJava->hWorkerThread);
+ __apxJvmAttach(lpJava);
+ JVM_DELETE_CLAZZ(lpJava, clWorker);
+ JVM_DELETE_CLAZZ(lpJava, clString);
+ __apxJvmDetach(lpJava);
+ /* Check if this is the jvm loader */
+ if (!lpJava->iVmCount && _st_sys_jvmDllHandle) {
+#if 0
+ /* Do not destroy if we terminated the worker thread */
+ if (dwJvmRet != STILL_ACTIVE)
+ (*(lpJava->lpJvm))->DestroyJavaVM(lpJava->lpJvm);
+#endif
+ /* Unload JVM dll */
+ FreeLibrary(_st_sys_jvmDllHandle);
+ _st_sys_jvmDllHandle = NULL;
+ }
+ lpJava->lpJvm = NULL;
+ }
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+APXHANDLE
+apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath)
+{
+
+ APXHANDLE hJava;
+ LPAPXJAVAVM lpJava;
+ jsize iVmCount;
+ JavaVM *lpJvm = NULL;
+
+ if (!__apxLoadJvmDll(szJvmDllPath))
+ return NULL;
+ /*
+ */
+ if (DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)(&lpJvm, 1, &iVmCount) != JNI_OK) {
+ return NULL;
+ }
+ if (iVmCount && !lpJvm)
+ return NULL;
+
+ hJava = apxHandleCreate(hPool, 0,
+ NULL, sizeof(APXJAVAVM),
+ __apxJavaJniCallback);
+ if (IS_INVALID_HANDLE(hJava))
+ return NULL;
+ hJava->dwType = APXHANDLE_TYPE_JVM;
+ lpJava = APXHANDLE_DATA(hJava);
+ lpJava->lpJvm = lpJvm;
+ lpJava->iVmCount = iVmCount;
+ return hJava;
+}
+
+static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
+ LPCSTR lpString,
+ JavaVMOption **lppArray,
+ DWORD nExtra)
+{
+ DWORD i, n = 0, l = 0;
+ char *buff;
+ LPSTR p;
+
+ if (lpString) {
+ l = __apxGetMultiSzLengthA(lpString, &n);
+ }
+ n += nExtra;
+ if (IS_INVALID_HANDLE(hPool))
+ buff = apxPoolAlloc(hPool, (n + 1) * sizeof(JavaVMOption) + (l + 1));
+ else
+ buff = apxAlloc((n + 1) * sizeof(JavaVMOption) + (l + 1));
+
+ *lppArray = (JavaVMOption *)buff;
+ p = (LPSTR)(buff + (n + 1) * sizeof(JavaVMOption));
+ if (lpString)
+ AplCopyMemory(p, lpString, l + 1);
+ for (i = 0; i < (n - nExtra); i++) {
+ DWORD qr = apxStrUnQuoteInplaceA(p);
+ (*lppArray)[i].optionString = p;
+ while (*p)
+ p++;
+ p++;
+ p += qr;
+ }
+
+ return n;
+}
+
+/* a hook for a function that redirects all VM messages. */
+static jint JNICALL __apxJniVfprintf(FILE *fp, const char *format, va_list args)
+{
+ jint rv;
+ CHAR sBuf[1024+16];
+ rv = wvsprintfA(sBuf, format, args);
+ if (apxLogWrite(APXLOG_MARK_INFO "%s", sBuf) == 0)
+ fputs(sBuf, stdout);
+ return rv;
+}
+
+
+/* ANSI version only */
+BOOL
+apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
+ LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
+ DWORD dwSs)
+{
+ LPAPXJAVAVM lpJava;
+ JavaVMInitArgs vmArgs;
+ JavaVMOption *lpJvmOptions;
+ DWORD i, nOptions, sOptions = 2;
+ BOOL rv = FALSE;
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+
+ lpJava = APXHANDLE_DATA(hJava);
+
+ if (lpJava->iVmCount) {
+ if (!lpJava->lpEnv && !__apxJvmAttach(lpJava)) {
+ if (lpJava->iVersion == JNI_VERSION_1_2) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
+ return FALSE;
+ }
+ else
+ lpJava->iVersion = JNI_VERSION_1_2;
+ if (!__apxJvmAttach(lpJava)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
+ return FALSE;
+ }
+ }
+ lpJava->iVersion = JNICALL_0(GetVersion);
+ if (lpJava->iVersion < JNI_VERSION_1_2) {
+ apxLogWrite(APXLOG_MARK_ERROR "Unsupported JNI version %#08x", lpJava->iVersion);
+ return FALSE;
+ }
+ rv = TRUE;
+ }
+ else {
+ CHAR iB[3][64];
+ LPSTR szCp;
+ lpJava->iVersion = JNI_VERSION_DEFAULT;
+ if (dwMs)
+ ++sOptions;
+ if (dwMx)
+ ++sOptions;
+ if (dwSs)
+ ++sOptions;
+ nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
+ &lpJvmOptions, sOptions);
+ szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
+ lstrcpyA(szCp, JAVA_CLASSPATH);
+ lstrcatA(szCp, szClassPath);
+ lpJvmOptions[nOptions - sOptions].optionString = szCp;
+ --sOptions;
+ /* default JNI error printer */
+ lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
+ lpJvmOptions[nOptions - sOptions].extraInfo = __apxJniVfprintf;
+ --sOptions;
+ if (dwMs) {
+ wsprintfA(iB[0], "-Xms%dm", dwMs);
+ lpJvmOptions[nOptions - sOptions].optionString = iB[0];
+ --sOptions;
+ }
+ if (dwMx) {
+ wsprintfA(iB[1], "-Xmx%dm", dwMx);
+ lpJvmOptions[nOptions - sOptions].optionString = iB[1];
+ --sOptions;
+ }
+ if (dwSs) {
+ wsprintfA(iB[2], "-Xss%dk", dwSs);
+ lpJvmOptions[nOptions - sOptions].optionString = iB[2];
+ --sOptions;
+ }
+ for (i = 0; i < nOptions; i++) {
+ apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", i,
+ lpJvmOptions[i].optionString);
+ }
+ vmArgs.options = lpJvmOptions;
+ vmArgs.nOptions = nOptions;
+ vmArgs.version = lpJava->iVersion;
+ vmArgs.ignoreUnrecognized = JNI_FALSE;
+ if (DYNLOAD_FPTR(JNI_CreateJavaVM)(&(lpJava->lpJvm),
+ (void **)&(lpJava->lpEnv),
+ &vmArgs) != JNI_OK) {
+ apxLogWrite(APXLOG_MARK_ERROR "CreateJavaVM Failed");
+ rv = FALSE;
+ }
+ else
+ rv = TRUE;
+ apxFree(szCp);
+ apxFree(lpJvmOptions);
+ }
+ /* Load standard classes */
+ if (rv) {
+ jclass jClazz = JNICALL_1(FindClass, JAVA_CLASSSTRING);
+ if (!jClazz) {
+ apxLogWrite(APXLOG_MARK_ERROR "FindClass " JAVA_CLASSSTRING " failed");
+ goto cleanup;
+ }
+ lpJava->clString.jClazz = JNICALL_1(NewGlobalRef, jClazz);
+ JNI_LOCAL_UNREF(jClazz);
+
+ return TRUE;
+ }
+ else
+ return FALSE;
+
+cleanup:
+ JVM_EXCEPTION_CLEAR(lpJava);
+ return FALSE;
+}
+
+BOOL
+apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szMethodName,
+ LPCVOID lpArguments)
+{
+ LPWSTR *lpArgs = NULL;
+ DWORD nArgs;
+ LPAPXJAVAVM lpJava;
+ jclass jClazz;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+ if (!__apxJvmAttach(lpJava))
+ return FALSE;
+
+ /* Find the class */
+ jClazz = JNICALL_1(FindClass, szClassName);
+ if (!jClazz) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "FindClass %s failed", szClassName);
+ return FALSE;
+ }
+ /* Make the class global so that worker thread can attach */
+ lpJava->clWorker.jClazz = JNICALL_1(NewGlobalRef, jClazz);
+ JNI_LOCAL_UNREF(jClazz);
+
+ if (szMethodName)
+ lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+ lpJava->clWorker.jClazz,
+ szMethodName, "([Ljava/lang/String;)V");
+ else
+ lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+ lpJava->clWorker.jClazz,
+ "main", "([Ljava/lang/String;)V");
+ if (!lpJava->clWorker.jMethod) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Static method 'void main(String[])' in Class %s not found", szClassName);
+ return FALSE;
+ }
+ nArgs = apxMultiSzToArrayW(hJava->hPool, lpArguments, &lpArgs);
+ if (nArgs) {
+ DWORD i;
+ lpJava->clWorker.jArgs = JNICALL_3(NewObjectArray, nArgs,
+ lpJava->clString.jClazz, NULL);
+ for (i = 0; i < nArgs; i++) {
+ jstring arg = JNICALL_2(NewString, lpArgs[i], lstrlenW(lpArgs[i]));
+ JNICALL_3(SetObjectArrayElement, lpJava->clWorker.jArgs, i, arg);
+ apxLogWrite(APXLOG_MARK_DEBUG "argv[%d] = %S", i, lpArgs[i]);
+ }
+ }
+ apxFree(lpArgs);
+ return TRUE;
+}
+
+
+/* Main java application worker thread
+ * It will launch Java main and wait until
+ * it finishes.
+ */
+static DWORD WINAPI __apxJavaWorkerThread(LPVOID lpParameter)
+{
+#define WORKER_EXIT(x) { rv = x; goto finished; }
+ DWORD rv = 0;
+ LPAPXJAVAVM lpJava;
+ APXHANDLE hJava = (APXHANDLE)lpParameter;
+ /* This shouldn't happen */
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ WORKER_EXIT(0);
+ lpJava = APXHANDLE_DATA(hJava);
+ /* Check if we have a class and a method */
+ if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod)
+ WORKER_EXIT(2);
+ if (!__apxJvmAttach(lpJava))
+ WORKER_EXIT(3);
+ lpJava->dwWorkerStatus = 1;
+ JNICALL_3(CallStaticVoidMethod,
+ lpJava->clWorker.jClazz,
+ lpJava->clWorker.jMethod,
+ lpJava->clWorker.jArgs);
+
+ JVM_EXCEPTION_CLEAR(lpJava);
+ __apxJvmDetach(lpJava);
+finished:
+ lpJava->dwWorkerStatus = 0;
+ apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished");
+ ExitThread(rv);
+ /* never gets here but keep the compiler happy */
+ return 0;
+}
+
+
+BOOL
+apxJavaStart(APXHANDLE hJava)
+{
+
+ LPAPXJAVAVM lpJava;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ lpJava->hWorkerThread = CreateThread(NULL, 0, __apxJavaWorkerThread,
+ hJava, CREATE_SUSPENDED,
+ &lpJava->iWorkerThread);
+ if (IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ ResumeThread(lpJava->hWorkerThread);
+ /* Give some time to initialize the thread */
+ Sleep(1000);
+ return TRUE;
+}
+
+DWORD
+apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
+{
+ DWORD rv;
+ LPAPXJAVAVM lpJava;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ if (!lpJava->dwWorkerStatus && lpJava->hWorkerThread)
+ return WAIT_OBJECT_0;
+ rv = WaitForSingleObject(lpJava->hWorkerThread, dwMilliseconds);
+ if (rv == WAIT_TIMEOUT && bKill) {
+ __apxJavaJniCallback(hJava, WM_CLOSE, 0, 0);
+ }
+
+ return rv;
+}
+
+LPVOID
+apxJavaCreateClassV(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szSignature, va_list lpArgs)
+{
+ LPAPXJAVAVM lpJava;
+ jclass clazz;
+ jmethodID ccont;
+ jobject cinst;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return NULL;
+ lpJava = APXHANDLE_DATA(hJava);
+ if (!__apxJvmAttach(lpJava))
+ return NULL;
+
+ clazz = JNICALL_1(FindClass, szClassName);
+ if (clazz == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass %s", szClassName);
+ return NULL;
+ }
+
+ ccont = JNICALL_3(GetMethodID, clazz, "<init>", szSignature);
+ if (ccont == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not find Constructor %s for %s",
+ szSignature, szClassName);
+ return NULL;
+ }
+
+ cinst = JNICALL_3(NewObjectV, clazz, ccont, lpArgs);
+ if (cinst == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not create instance of %s",
+ szClassName);
+ return NULL;
+ }
+
+ return cinst;
+}
+
+LPVOID
+apxJavaCreateClass(APXHANDLE hJava, LPCSTR szClassName,
+ LPCSTR szSignature, ...)
+{
+ LPVOID rv;
+ va_list args;
+
+ va_start(args, szSignature);
+ rv = apxJavaCreateClassV(hJava, szClassName, szSignature, args);
+ va_end(args);
+
+ return rv;
+}
+
+LPVOID
+apxJavaCreateStringA(APXHANDLE hJava, LPCSTR szString)
+{
+ LPAPXJAVAVM lpJava;
+ jstring str;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return NULL;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ str = JNICALL_1(NewStringUTF, szString);
+ if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %s",
+ szString);
+ return NULL;
+ }
+
+ return str;
+}
+
+LPVOID
+apxJavaCreateStringW(APXHANDLE hJava, LPCWSTR szString)
+{
+ LPAPXJAVAVM lpJava;
+ jstring str;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return NULL;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ str = JNICALL_2(NewString, szString, lstrlenW(szString));
+ if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %S",
+ szString);
+ return NULL;
+ }
+
+ return str;
+}
+
+jvalue
+apxJavaCallStaticMethodV(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
+ LPCSTR szSignature, va_list lpArgs)
+{
+ LPAPXJAVAVM lpJava;
+ jmethodID method;
+ jvalue rv;
+ LPCSTR s = szSignature;
+ rv.l = 0;
+ if (hJava->dwType != APXHANDLE_TYPE_JVM)
+ return rv;
+ lpJava = APXHANDLE_DATA(hJava);
+
+ while (*s && *s != ')')
+ ++s;
+ if (*s != ')') {
+ return rv;
+ }
+ else
+ ++s;
+ method = JNICALL_3(GetStaticMethodID, lpClass, szMethodName, szSignature);
+ if (method == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not find method %s with signature %s",
+ szMethodName, szSignature);
+ return rv;
+ }
+ switch (*s) {
+ case 'V':
+ JNICALL_3(CallStaticVoidMethodV, lpClass, method, lpArgs);
+ break;
+ case 'L':
+ case '[':
+ rv.l = JNICALL_3(CallStaticObjectMethodV, lpClass, method, lpArgs);
+ break;
+ case 'Z':
+ rv.z = JNICALL_3(CallStaticBooleanMethodV, lpClass, method, lpArgs);
+ break;
+ case 'B':
+ rv.b = JNICALL_3(CallStaticByteMethodV, lpClass, method, lpArgs);
+ break;
+ case 'C':
+ rv.c = JNICALL_3(CallStaticCharMethodV, lpClass, method, lpArgs);
+ break;
+ case 'S':
+ rv.i = JNICALL_3(CallStaticShortMethodV, lpClass, method, lpArgs);
+ break;
+ case 'I':
+ rv.i = JNICALL_3(CallStaticIntMethodV, lpClass, method, lpArgs);
+ break;
+ case 'J':
+ rv.j = JNICALL_3(CallStaticLongMethodV, lpClass, method, lpArgs);
+ break;
+ case 'F':
+ rv.f = JNICALL_3(CallStaticFloatMethodV, lpClass, method, lpArgs);
+ break;
+ case 'D':
+ rv.d = JNICALL_3(CallStaticDoubleMethodV, lpClass, method, lpArgs);
+ break;
+ default:
+ apxLogWrite(APXLOG_MARK_ERROR "Invalid signature %s for method %s",
+ szSignature, szMethodName);
+ return rv;
+ break;
+ }
+
+ return rv;
+}
+
+jvalue
+apxJavaCallStaticMethod(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
+ LPCSTR szSignature, ...)
+{
+ jvalue rv;
+ va_list args;
+
+ va_start(args, szSignature);
+ rv = apxJavaCallStaticMethodV(hJava, lpClass, szMethodName, szSignature, args);
+ va_end(args);
+
+ return rv;
+}
+
+/* Call the Java:
+ * System.setOut(new PrintStream(new FileOutputStream(filename)));
+ */
+BOOL
+apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut, LPCWSTR szFilename)
+{
+ LPAPXJAVAVM lpJava;
+ jobject fs;
+ jobject ps;
+ jstring fn;
+ jclass sys;
+
+ if (hJava->dwType != APXHANDLE_TYPE_JVM || !szFilename)
+ return FALSE;
+ lpJava = APXHANDLE_DATA(hJava);
+ if (!__apxJvmAttach(lpJava))
+ return FALSE;
+
+ if ((fn = apxJavaCreateStringW(hJava, szFilename)) == NULL)
+ return FALSE;
+ if ((fs = apxJavaCreateClass(hJava, "java/io/FileOutputStream",
+ "(Ljava/lang/String;Z)V", fn, JNI_TRUE)) == NULL)
+ return FALSE;
+ if ((ps = apxJavaCreateClass(hJava, "java/io/PrintStream",
+ "(Ljava/io/OutputStream;)V", fs)) == NULL)
+ return FALSE;
+ sys = JNICALL_1(FindClass, "java/lang/System");
+ if (sys == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass java/lang/System");
+ return FALSE;
+ }
+
+ if (setErrorOrOut)
+ apxJavaCallStaticMethod(hJava, sys, "setErr", "(Ljava/io/PrintStream;)V", ps);
+ else
+ apxJavaCallStaticMethod(hJava, sys, "setOut", "(Ljava/io/PrintStream;)V", ps);
+
+ if (JVM_EXCEPTION_CHECK(lpJava)) {
+ JVM_EXCEPTION_CLEAR(lpJava);
+ apxLogWrite(APXLOG_MARK_ERROR "Error calling set method for java/lang/System");
+ return FALSE;
+ }
+ else
+ return TRUE;
+
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/javajni.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/log.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/log.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/log.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,410 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define LINE_SEP "\n"
+
+static LPCSTR _log_level[] = {
+ "[debug] ",
+ "[info] ",
+ "[warn] ",
+ "[error] ",
+ NULL
+};
+
+typedef struct apx_logfile_st {
+ HANDLE hFile;
+ DWORD dwLogLevel;
+ BOOL bRotate;
+ SYSTEMTIME sysTime;
+ WCHAR szPath[MAX_PATH + 1];
+ WCHAR szPrefix[MAX_PATH];
+} apx_logfile_st;
+
+/* Per-application master log file */
+static apx_logfile_st *_st_sys_loghandle = NULL;
+
+static apx_logfile_st _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
+
+
+LPWSTR apxLogFile(
+ APXHANDLE hPool,
+ LPCWSTR szPath,
+ LPCWSTR szPrefix,
+ LPCWSTR szName)
+{
+ LPWSTR sRet;
+ WCHAR sPath[MAX_PATH+1];
+ WCHAR sName[MAX_PATH+1];
+ SYSTEMTIME sysTime;
+
+ GetLocalTime(&sysTime);
+ if (!szPath) {
+ if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
+ return INVALID_HANDLE_VALUE;
+ lstrcatW(sPath, L"\\LogFiles\\");
+ if (!szPrefix)
+ lstrcatW(sPath, L"Apache");
+ else
+ lstrcatW(sPath, szPrefix);
+ wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+ szName,
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
+ }
+ else {
+ lstrcpyW(sPath, szPath);
+ if (szPrefix)
+ wsprintfW(sName, L"\\%s", szPrefix);
+ else
+ wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+ szName,
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
+ }
+ sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
+ /* Set default level to info */
+ CreateDirectoryW(sPath, NULL);
+
+ lstrcpyW(sRet, sPath);
+ lstrcatW(sRet, sName);
+
+ return sRet;
+}
+
+/* Open the log file
+ * TODO: format like standard apache error.log
+ * Add the EventLogger
+ */
+HANDLE apxLogOpen(
+ APXHANDLE hPool,
+ LPCWSTR szPath,
+ LPCWSTR szPrefix)
+{
+
+ WCHAR sPath[MAX_PATH+1];
+ WCHAR sName[MAX_PATH+1];
+ SYSTEMTIME sysTime;
+ apx_logfile_st *h;
+
+ GetLocalTime(&sysTime);
+ if (!szPath) {
+ if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
+ return INVALID_HANDLE_VALUE;
+ lstrcatW(sPath, L"\\LogFiles\\");
+ if (!szPrefix)
+ lstrcatW(sPath, L"Apache");
+ else
+ lstrcatW(sPath, szPrefix);
+ wsprintfW(sName, L"\\%04d%02d%02d.log",
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
+ }
+ else {
+ lstrcpyW(sPath, szPath);
+ if (szPrefix)
+ wsprintfW(sName, L"\\%s", szPrefix);
+ else
+ wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log",
+ sysTime.wYear,
+ sysTime.wMonth,
+ sysTime.wDay);
+ }
+ if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
+ return NULL;
+ /* Set default level to info */
+ h->dwLogLevel = APXLOG_LEVEL_INFO;
+ CreateDirectoryW(sPath, NULL);
+
+ h->sysTime = sysTime;
+ lstrcpyW(h->szPath, sPath);
+ lstrcatW(sPath, sName);
+ if (szPrefix)
+ lstrcpyW(h->szPrefix, szPrefix);
+
+ h->hFile = CreateFileW(sPath,
+ GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+ NULL);
+ /* Set this file as system log file */
+ if (!_st_sys_loghandle)
+ _st_sys_loghandle = h;
+
+ return (HANDLE)h;
+}
+
+void apxLogLevelSet(HANDLE hFile, DWORD dwLevel)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+ if (dwLevel < 4)
+ lf->dwLogLevel = dwLevel;
+}
+
+void apxLogRotateSet(HANDLE hFile, BOOL doRotate)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+ lf->bRotate = doRotate;
+}
+
+void apxLogLevelSetW(HANDLE hFile,
+ LPCWSTR szLevel)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+ if (szLevel) {
+ if (!lstrcmpiW(szLevel, L"error"))
+ lf->dwLogLevel = APXLOG_LEVEL_ERROR;
+ else if (!lstrcmpiW(szLevel, L"warn"))
+ lf->dwLogLevel = APXLOG_LEVEL_WARN;
+ else if (!lstrcmpiW(szLevel, L"info"))
+ lf->dwLogLevel = APXLOG_LEVEL_INFO;
+ else if (!lstrcmpiW(szLevel, L"debug"))
+ lf->dwLogLevel = APXLOG_LEVEL_DEBUG;
+ }
+}
+
+static BOOL apx_log_rotate(apx_logfile_st *l,
+ LPSYSTEMTIME lpCtime)
+{
+ WCHAR sPath[MAX_PATH+1];
+
+ /* rotate on daily basis */
+ if (l->sysTime.wDay == lpCtime->wDay)
+ return TRUE;
+ FlushFileBuffers(l->hFile);
+ CloseHandle(l->hFile);
+ l->sysTime = *lpCtime;
+
+ wsprintfW(sPath, L"%s\\%s%04d%02d%02d.log",
+ l->szPath,
+ l->szPrefix,
+ l->sysTime.wYear,
+ l->sysTime.wMonth,
+ l->sysTime.wDay);
+ l->hFile = CreateFileW(sPath,
+ GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+ NULL);
+ if (IS_INVALID_HANDLE(l->hFile))
+ return FALSE;
+ else
+ return TRUE;
+}
+
+int
+apxLogWrite(
+ HANDLE hFile,
+ DWORD dwLevel,
+ BOOL bTimeStamp,
+ LPCSTR szFile,
+ DWORD dwLine,
+ LPCSTR szFormat,
+ ...)
+{
+ va_list args;
+ CHAR buffer[1024+32];
+ LPSTR szBp;
+ int len = 0;
+ LPCSTR f = szFile;
+ CHAR sb[MAX_PATH+1];
+ DWORD wr;
+ DWORD err;
+ BOOL dolock = TRUE;
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf)) {
+ lf = &_st_sys_errhandle;
+ lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
+ dolock = FALSE;
+ }
+ if (dwLevel < lf->dwLogLevel)
+ return 0;
+ err = GetLastError(); /* save the last Error code */
+ if (f) {
+ f = (szFile + lstrlenA(szFile) - 1);
+ while(f != szFile && '\\' != *f && '/' != *f)
+ f--;
+ if(f != szFile)
+ f++;
+ }
+ lstrcpyA(buffer, _log_level[dwLevel]);
+ if (!dolock)
+ lstrcatA(buffer, "\n");
+ szBp = &buffer[lstrlenA(buffer)];
+ if (!szFormat) {
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ szBp,
+ 1000,
+ NULL);
+ }
+ else {
+ va_start(args, szFormat);
+ wvsprintfA(szBp, szFormat, args);
+ va_end(args);
+ }
+ len = lstrlenA(buffer);
+ if (len > 0) {
+ /* Remove trailing line separator */
+ if (buffer[len - 1] == '\n') {
+ buffer[len - 1] = '\0';
+ --len;
+ }
+ if (!IS_INVALID_HANDLE(lf->hFile)) {
+ SYSTEMTIME t;
+ GetLocalTime(&t);
+ if (lf->bRotate) {
+ if (!apx_log_rotate(lf, &t))
+ return 0;
+ }
+ if (dolock) {
+ APX_LOGLOCK(lf->hFile);
+ }
+ if (bTimeStamp) {
+ wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
+ t.wYear, t.wMonth, t.wDay,
+ t.wHour, t.wMinute, t.wSecond);
+ WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+ }
+ if (f) {
+ wsprintfA(sb, "[%-4d %s] ", dwLine, f);
+ WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+ }
+
+ WriteFile(lf->hFile, buffer, len, &wr, NULL);
+ /* Terminate the line */
+ WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
+#ifdef _DEBUG_FULL
+ FlushFileBuffers(lf->hFile);
+#endif
+ if (dolock) {
+ APX_LOGUNLOCK(lf->hFile);
+ }
+ }
+#ifdef _DEBUG_FULL
+ {
+ char tid[1024 + 16];
+ wsprintfA(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
+ OutputDebugStringA(tid);
+ }
+#endif
+ }
+ /* Restore the last Error code */
+ SetLastError(err);
+ return len;
+}
+
+void apxLogClose(
+ HANDLE hFile)
+{
+ apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+ if (IS_INVALID_HANDLE(lf))
+ lf = _st_sys_loghandle;
+ if (IS_INVALID_HANDLE(lf))
+ return;
+
+ FlushFileBuffers(lf->hFile);
+ CloseHandle(lf->hFile);
+ if (lf == _st_sys_loghandle)
+ _st_sys_loghandle = NULL;
+ apxFree(lf);
+}
+
+int
+apxDisplayError(
+ BOOL bDisplay,
+ LPCSTR szFile,
+ DWORD dwLine,
+ LPCSTR szFormat,
+ ...)
+{
+ va_list args;
+ CHAR buffer[1024+16];
+ CHAR sysbuf[2048];
+ int len = 0, nRet;
+ LPCSTR f = szFile;
+ DWORD err = GetLastError(); /* save the last Error code */
+ if (f) {
+ f = (szFile + lstrlenA(szFile) - 1);
+ while(f != szFile && '\\' != *f && '/' != *f)
+ f--;
+ if(f != szFile)
+ f++;
+ }
+ sysbuf[0] = '\0';
+ if (err != ERROR_SUCCESS) {
+ len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ sysbuf,
+ 1000,
+ NULL);
+ sysbuf[len] = 0;
+ }
+ if (szFormat) {
+ va_start(args, szFormat);
+ wvsprintfA(buffer, szFormat, args);
+ va_end(args);
+ if (f) {
+ CHAR sb[MAX_PATH+1];
+ wsprintfA(sb, "\n%s (%d)", f, dwLine);
+ lstrcatA(sysbuf, sb);
+ }
+ lstrcatA(sysbuf, "\n");
+ lstrcatA(sysbuf, buffer);
+ }
+ len = lstrlenA(sysbuf);
+#ifdef _DEBUG_FULL
+ OutputDebugStringA(sysbuf);
+#endif
+ if (len > 0 && bDisplay) {
+ nRet = MessageBoxA(NULL, sysbuf,
+ "Application System Error",
+ MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+ }
+ /* Restore the last Error code */
+ SetLastError(err);
+ return len;
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/log.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/mclib.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/mclib.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/mclib.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,294 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copyright (c) 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Andrew Hume of AT&T Bell Laboratories.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+typedef UINT word; /* "word" used for optimal copy speed */
+#define wsize sizeof(UINT)
+#define wmask (wsize - 1)
+
+LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill)
+{
+
+ SIZE_T t;
+#ifdef WIN64
+ UINT64 c;
+#else
+ UINT c;
+#endif
+ LPBYTE dst;
+
+ dst = Destination;
+ /*
+ * If not enough words, just fill bytes. A length >= 2 words
+ * guarantees that at least one of them is `complete' after
+ * any necessary alignment. For instance:
+ *
+ * |-----------|-----------|-----------|
+ * |00|01|02|03|04|05|06|07|08|09|0A|00|
+ * ^---------------------^
+ * dst dst+length-1
+ *
+ * but we use a minimum of 3 here since the overhead of the code
+ * to do word writes is substantial.
+ */
+ if (Length < 3 * wsize) {
+ while (Length != 0) {
+ *dst++ = Fill;
+ --Length;
+ }
+ return (Destination);
+ }
+
+ if ((c = Fill) != 0) { /* Fill the word. */
+ c = (c << 8) | c; /* u_int is 16 bits. */
+ c = (c << 16) | c; /* u_int is 32 bits. */
+#ifdef WIN64
+ c = (c << 32) | c; /* u_int is 64 bits. */
+#endif
+ }
+ /* Align destination by filling in bytes. */
+ if ((t = (SIZE_T)dst & wmask) != 0) {
+ t = wsize - t;
+ Length -= t;
+ do {
+ *dst++ = Fill;
+ } while (--t != 0);
+ }
+
+ /* Fill words. Length was >= 2*words so we know t >= 1 here. */
+ t = Length / wsize;
+ do {
+#ifdef WIN64
+ *(UINT64 *)dst = c;
+#else
+ *(UINT *)dst = c;
+#endif
+ dst += wsize;
+ } while (--t != 0);
+
+ /* Mop up trailing bytes, if any. */
+ t = Length & wmask;
+ if (t != 0)
+ do {
+ *dst++ = Fill;
+ } while (--t != 0);
+ return (Destination);
+}
+
+void AplZeroMemory(PVOID Destination, SIZE_T Length)
+{
+
+ SIZE_T t;
+ LPBYTE dst;
+
+ dst = Destination;
+ /*
+ * If not enough words, just fill bytes. A length >= 2 words
+ * guarantees that at least one of them is `complete' after
+ * any necessary alignment. For instance:
+ *
+ * |-----------|-----------|-----------|
+ * |00|01|02|03|04|05|06|07|08|09|0A|00|
+ * ^---------------------^
+ * dst dst+length-1
+ *
+ * but we use a minimum of 3 here since the overhead of the code
+ * to do word writes is substantial.
+ */
+ if (Length < 3 * wsize) {
+ while (Length != 0) {
+ *dst++ = 0;
+ --Length;
+ }
+ return;
+ }
+
+ /* Align destination by filling in bytes. */
+ if ((t = (SIZE_T)dst & wmask) != 0) {
+ t = wsize - t;
+ Length -= t;
+ do {
+ *dst++ = 0;
+ } while (--t != 0);
+ }
+
+ /* Fill words. Length was >= 2*words so we know t >= 1 here. */
+ t = Length / wsize;
+ do {
+ *(UINT *)dst = 0;
+ dst += wsize;
+ } while (--t != 0);
+
+ /* Mop up trailing bytes, if any. */
+ t = Length & wmask;
+ if (t != 0)
+ do {
+ *dst++ = 0;
+ } while (--t != 0);
+}
+
+LPVOID AplCopyMemory(PVOID Destination, const VOID* Source, SIZE_T Length)
+{
+ char *dst = Destination;
+ const char *src = Source;
+ SIZE_T t;
+
+ if (Length == 0 || dst == src) /* nothing to do */
+ goto done;
+
+ /*
+ * Macros: loop-t-times; and loop-t-times, t>0
+ */
+#define TLOOP(s) if (t) TLOOP1(s)
+#define TLOOP1(s) do { s; } while (--t)
+
+ if ((SIZE_T)dst < (SIZE_T)src) {
+ /*
+ * Copy forward.
+ */
+ t = (int)(SIZE_T)src; /* only need low bits */
+ if ((t | (int)(SIZE_T)dst) & wmask) {
+ /*
+ * Try to align operands. This cannot be done
+ * unless the low bits match.
+ */
+ if ((t ^ (int)(SIZE_T)dst) & wmask || Length < wsize)
+ t = Length;
+ else
+ t = wsize - (t & wmask);
+ Length -= t;
+ TLOOP1(*dst++ = *src++);
+ }
+ /*
+ * Copy whole words, then mop up any trailing bytes.
+ */
+ t = Length / wsize;
+ TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
+ t = Length & wmask;
+ TLOOP(*dst++ = *src++);
+ } else {
+ /*
+ * Copy backwards. Otherwise essentially the same.
+ * Alignment works as before, except that it takes
+ * (t&wmask) bytes to align, not wsize-(t&wmask).
+ */
+ src += Length;
+ dst += Length;
+ t = (int)(SIZE_T)src;
+ if ((t | (int)(SIZE_T)dst) & wmask) {
+ if ((t ^ (int)(SIZE_T)dst) & wmask || Length <= wsize)
+ t = Length;
+ else
+ t &= wmask;
+ Length -= t;
+ TLOOP1(*--dst = *--src);
+ }
+ t = Length / wsize;
+ TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
+ t = Length & wmask;
+ TLOOP(*--dst = *--src);
+ }
+done:
+ return (Destination);
+}
+
+
+INT
+AplMemCmp(LPCVOID lpA, LPCVOID lpB, SIZE_T nBytes)
+{
+ if (nBytes != 0) {
+ const BYTE *p1 = lpA, *p2 = lpB;
+
+ do {
+ if (*p1++ != *p2++)
+ return (*--p1 - *--p2);
+ } while (--nBytes != 0);
+ }
+ return 0;
+}
+
+/*
+ * Find the first occurrence of lpFind in lpMem.
+ * dwLen: The length of lpFind
+ * dwSize: The length of lpMem
+ */
+LPBYTE
+ApcMemSearch(LPCVOID lpMem, LPCVOID lpFind, SIZE_T dwLen, SIZE_T dwSize)
+{
+ BYTE c, sc;
+ SIZE_T cnt = 0;
+ const BYTE *s = lpMem, *find = lpFind;
+
+ if ((c = *find++) != 0) {
+ do {
+ do {
+ sc = *s++;
+ if (cnt++ > dwSize)
+ return NULL;
+ } while (sc != c);
+ } while (AplMemCmp(s, find, dwLen - 1) != 0);
+ s--;
+ }
+ return (LPBYTE)s;
+}
+
+LPSTR
+AplRindexA(LPCSTR lpStr, int ch)
+{
+ LPSTR save;
+
+ for (save = NULL;; ++lpStr) {
+ if (*lpStr == ch)
+ save = (LPSTR)lpStr;
+ if (!*lpStr)
+ return save;
+ }
+ /* NOTREACHED */
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/mclib.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/mclib.h
===================================================================
--- trunk/utils/windows/native/service/procrun/src/mclib.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/mclib.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,27 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _MCLIB_H_INCLUDED_
+#define _MCLIB_H_INCLUDED_
+
+#ifndef MIN
+#define MIN(a,b) (((a)<(b)) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a,b) (((a)>(b)) ? (a) : (b))
+#endif
+
+#endif /* _MCLIB_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/src/mclib.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/private.h
===================================================================
--- trunk/utils/windows/native/service/procrun/src/private.h (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/private.h 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,274 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVATE_H_INCLUDED_
+#define _PRIVATE_H_INCLUDED_
+
+#include "mclib.h"
+
+#ifdef _DEBUG
+
+HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
+BOOL HeapDESTROY(HANDLE hHeap);
+
+LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize);
+BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
+LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
+
+#else
+
+#define HeapCREATE HeapCreate
+#define HeapDESTROY HeapDestroy
+#define HeapALLOC HeapAlloc
+#define HeapFREE HeapFree
+#define HeapREALLOC HeapReAlloc
+
+#endif
+
+/*
+ * Tail queue declarations.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_CONCAT(head1, head2, field) do { \
+ if (!TAILQ_EMPTY(head2)) { \
+ *(head1)->tqh_last = (head2)->tqh_first; \
+ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
+ (head1)->tqh_last = (head2)->tqh_last; \
+ TAILQ_INIT((head2)); \
+ } \
+} while (0)
+
+#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
+
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+
+#define TAILQ_FOREACH(var, head, field) \
+ for ((var) = TAILQ_FIRST((head)); \
+ (var); \
+ (var) = TAILQ_NEXT((var), field))
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for ((var) = TAILQ_LAST((head), headname); \
+ (var); \
+ (var) = TAILQ_PREV((var), headname, field))
+
+#define TAILQ_INIT(head) do { \
+ TAILQ_FIRST((head)) = NULL; \
+ (head)->tqh_last = &TAILQ_FIRST((head)); \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
+ TAILQ_NEXT((elm), field)->field.tqe_prev = \
+ &TAILQ_NEXT((elm), field); \
+ else { \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ } \
+ TAILQ_NEXT((listelm), field) = (elm); \
+ (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ TAILQ_NEXT((elm), field) = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
+ TAILQ_FIRST((head))->field.tqe_prev = \
+ &TAILQ_NEXT((elm), field); \
+ else \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+ TAILQ_FIRST((head)) = (elm); \
+ (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ TAILQ_NEXT((elm), field) = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
+} while (0)
+
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ if ((TAILQ_NEXT((elm), field)) != NULL) \
+ TAILQ_NEXT((elm), field)->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else { \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ } \
+ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
+} while (0)
+
+/** Some usefull macros */
+
+#define APXHANDLE_SPINLOCK(h) \
+ APXMACRO_BEGIN \
+ while (InterlockedCompareExchange(&((h)->lvSpin), 1, 0) != 0) { \
+ Sleep(10); \
+ SwitchToThread(); \
+ } \
+ APXMACRO_END
+
+#define APXHANDLE_SPINUNLOCK(h) \
+ APXMACRO_BEGIN \
+ InterlockedExchange(&((h)->lvSpin), 0); \
+ APXMACRO_END
+
+#define APX_SPINLOCK(lock) \
+ APXMACRO_BEGIN \
+ while (InterlockedCompareExchange(&(lock), 1, 0) != 0) \
+ SwitchToThread(); \
+ APXMACRO_END
+
+#define APX_SPINUNLOCK(lock) \
+ APXMACRO_BEGIN \
+ InterlockedExchange(&(lock), 0); \
+ APXMACRO_END
+
+/*
+ * Define a union with types which are likely to have the longest
+ * *relevant* CPU-specific memory word alignment restrictions...
+ */
+typedef union APXMEMWORD {
+ void *vp;
+ void (*fp)(void);
+ char *cp;
+ long l;
+ double d;
+} APXMEMWORD;
+
+typedef struct APXCALLHOOK APXCALLHOOK;
+
+struct APXCALLHOOK {
+
+ LPAPXFNCALLBACK fnCallback;
+ TAILQ_ENTRY(APXCALLHOOK) queue;
+};
+
+struct stAPXHANDLE {
+ /** The type of the handle */
+ DWORD dwType;
+ /** Handle Flags */
+ DWORD dwFlags;
+ /** Handle user data size */
+ DWORD dwSize;
+ /** parameters for event callback */
+ WPARAM wParam;
+ LPARAM lParam;
+ UINT uMsg;
+ /** main callback function (using default if not specified) */
+ LPAPXFNCALLBACK fnCallback;
+ /** callback functions hook list */
+ TAILQ_HEAD(_lCallbacks, APXCALLHOOK) lCallbacks;
+ /** allocation pool */
+ APXHANDLE hPool;
+ /** interlocking value */
+ LONG volatile lvSpin;
+
+ /** message event handle */
+ HANDLE hEventHandle;
+ /** message event thread */
+ HANDLE hEventThread;
+ /** message event thread id */
+ DWORD hEventThreadId;
+ /** private local heap */
+ HANDLE hHeap;
+ /** list enty for pool */
+ TAILQ_ENTRY(stAPXHANDLE) queue;
+ /** small userdata pointer */
+ union {
+ LPVOID lpPtr;
+ HANDLE hWinHandle;
+ double dValue;
+ void (*fpValue)();
+ } uData;
+
+ APXMEMWORD stAlign;
+};
+
+#define APXHANDLE_DATA(h) ((void *)((char*)(h) + sizeof(stAPXHANDLE)))
+#define APXHANDLE_SZ sizeof(stAPXHANDLE)
+
+extern APX_OSLEVEL _st_apx_oslevel;
+
+#define APX_GET_OSLEVEL() ((_st_apx_oslevel == APX_WINVER_UNK) ? apxGetOsLevel() : _st_apx_oslevel)
+
+#ifdef _DEBUG
+void ErrorMessage(LPCTSTR szError, BOOL bFatal);
+#else
+#define ErrorMessage(szError, bFatal) ((void)0)
+#endif
+/* zero separated, double zero terminated string */
+struct APXMULTISZ {
+ DWORD dwAllocated; /* length including terminators */
+ DWORD dwInsert; /* next insert position */
+};
+
+typedef struct APXREGENUM {
+ HKEY hServicesKey;
+ DWORD dwIndex; /* current enum index */
+ DWORD cSubKeys; /* number of subkeys */
+ DWORD cbMaxSubKey; /* longest subkey size */
+ DWORD cchMaxClass; /* longest class string */
+ DWORD cValues; /* number of values for key */
+ DWORD cchMaxValue; /* longest value name */
+ DWORD cbMaxValueData; /* longest value data */
+
+} APXREGENUM, *LPAPXREGENUM;
+
+BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry);
+
+BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription);
+BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
+ DWORD dwDescriptionLength);
+BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
+ DWORD dwUserLength);
+
+DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount);
+DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount);
+LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName);
+LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName);
+
+
+#endif /* _PRIVATE_H_INCLUDED_ */
Property changes on: trunk/utils/windows/native/service/procrun/src/private.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/registry.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/registry.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/registry.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,1112 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+static LPCWSTR REGSERVICE_ROOT = L"SYSTEM\\CurrentControlSet\\Services\\";
+static LPCWSTR REGSOFTWARE_ROOT = L"SOFTWARE\\";
+static LPCWSTR REGSERVICE_START = L"Start";
+static LPCWSTR REGSERVICE_USER = L"ObjectName";
+static LPCWSTR REGPARAMS = L"Parameters";
+static LPCWSTR REGDESCRIPTION = L"Description";
+static LPCWSTR REGSEPARATOR = L"\\";
+static LPCWSTR REGAPACHE_ROOT = L"Apache Software Foundation";
+/* predefined java keys */
+static LPCWSTR JRE_REGKEY = L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\";
+static LPCWSTR JDK_REGKEY = L"SOFTWARE\\JavaSoft\\Java Development Kit\\";
+static LPCWSTR JAVA_CURRENT = L"CurrentVersion";
+static LPCWSTR JAVA_RUNTIME = L"RuntimeLib";
+static LPCWSTR JAVA_HOME = L"JAVA_HOME";
+static LPCWSTR JAVAHOME = L"JavaHome";
+static LPCWSTR CONTROL_REGKEY = L"SYSTEM\\CurrentControlSet\\Control";
+static LPCWSTR REGTIMEOUT = L"WaitToKillServiceTimeout";
+
+#define REG_CAN_CREATE(r) \
+ ((r)->samOptions & KEY_CREATE_SUB_KEY)
+
+#define REG_CAN_WRITE(r) \
+ ((r)->samOptions & KEY_SET_VALUE)
+
+
+#define REG_GET_KEY(r, w, k) \
+ APXMACRO_BEGIN \
+ switch(w) { \
+ case APXREG_SOFTWARE: k = (r)->hRootKey; break; \
+ case APXREG_PARAMSOFTWARE: k = (r)->hRparamKey; break; \
+ case APXREG_SERVICE: k = (r)->hServKey; break; \
+ case APXREG_PARAMSERVICE: k = (r)->hSparamKey; break; \
+ case APXREG_USER: k = (r)->hUserKey; break; \
+ case APXREG_PARAMUSER: k = (r)->hUparamKey; break; \
+ default: k = NULL; break; \
+ } APXMACRO_END
+
+
+typedef struct APXREGISTRY APXREGISTRY;
+typedef APXREGISTRY* LPAPXREGISTRY;
+typedef struct APXREGSUBKEY APXREGSUBKEY;
+
+struct APXREGSUBKEY {
+ APXHANDLE hRegistry;
+ HKEY hKey;
+ LPCTSTR syKeyName;
+ TAILQ_ENTRY(APXREGSUBKEY);
+};
+
+struct APXREGISTRY {
+ HKEY hRootKey; /* root key */
+ HKEY hServKey; /* service key */
+ HKEY hUserKey; /* user key */
+ HKEY hCurrKey; /* Current opened key */
+ LPVOID pCurrVal; /* Current value, overwitten on a next call */
+ HKEY hRparamKey; /* root\\Parameters */
+ HKEY hSparamKey; /* service\\Parameters */
+ HKEY hUparamKey; /* service\\Parameters */
+ REGSAM samOptions;
+ /** list enty for opened subkeys */
+ TAILQ_HEAD(_lSubkeys, APXREGSUBKEY) lSubkeys;
+
+};
+
+#define SAFE_CLOSE_KEY(k) \
+ if ((k) != NULL && (k) != INVALID_HANDLE_VALUE) { \
+ RegCloseKey((k)); \
+ (k) = NULL; \
+ }
+
+static BOOL __apxRegistryCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXREGISTRY lpReg;
+
+ lpReg = APXHANDLE_DATA(hObject);
+ switch (uMsg) {
+ case WM_CLOSE:
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ SAFE_CLOSE_KEY(lpReg->hRparamKey);
+ SAFE_CLOSE_KEY(lpReg->hSparamKey);
+ SAFE_CLOSE_KEY(lpReg->hUparamKey);
+ SAFE_CLOSE_KEY(lpReg->hRootKey);
+ SAFE_CLOSE_KEY(lpReg->hServKey);
+ SAFE_CLOSE_KEY(lpReg->hUserKey);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+LPSTR __apxGetRegistrySzA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName)
+{
+ LPSTR szRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+ return NULL;
+ }
+ if (!(szRet = apxPoolAlloc(hPool, dwSize)))
+ return NULL;
+ RegQueryValueExA(hKey, szValueName, NULL, &dwType, (LPBYTE)szRet, &dwSize);
+
+ return szRet;
+}
+
+LPWSTR __apxGetRegistrySzW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
+{
+ LPWSTR wsRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+ return NULL;
+ }
+ if (!(wsRet = apxPoolAlloc(hPool, dwSize * sizeof(WCHAR))))
+ return NULL;
+ RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)wsRet, &dwSize);
+
+ return wsRet;
+}
+
+BOOL __apxGetRegistryStrW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
+ LPWSTR lpRetval, DWORD dwMaxLen)
+{
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize = dwMaxLen;
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)lpRetval, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+ lpRetval = L'\0';
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+LPBYTE __apxGetRegistryBinaryA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName,
+ LPDWORD lpdwLength)
+{
+ LPBYTE lpRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwSize == 0) {
+ return NULL;
+ }
+ if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
+ return NULL;
+ RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpRet, &dwSize);
+ if (lpdwLength)
+ *lpdwLength = dwSize;
+ return lpRet;
+}
+
+LPBYTE __apxGetRegistryBinaryW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
+ LPDWORD lpdwLength)
+{
+ LPBYTE lpRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize;
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
+ if (rc != ERROR_SUCCESS || dwSize == 0) {
+ return NULL;
+ }
+ if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
+ return NULL;
+ RegQueryValueExW(hKey, wsValueName, NULL, &dwType, lpRet, &dwSize);
+ if (lpdwLength)
+ *lpdwLength = dwSize;
+
+ return lpRet;
+}
+
+DWORD __apxGetRegistryDwordW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
+{
+ DWORD dwRet;
+ DWORD rc;
+ DWORD dwType;
+ DWORD dwSize = sizeof(DWORD);
+
+ rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)&dwRet, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
+ return 0xFFFFFFFF;
+ }
+
+ return dwRet;
+}
+
+
+APXHANDLE
+apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired,
+ LPCWSTR szRoot,
+ LPCWSTR szKeyName,
+ DWORD dwOptions)
+{
+ APXHANDLE hRegistry;
+ LPAPXREGISTRY lpReg;
+ /* maximum key length is 512 characters. */
+ WCHAR buff[SIZ_BUFLEN];
+ LONG rc = ERROR_SUCCESS;
+ HKEY hRootKey = NULL;
+ HKEY hUserKey = NULL;
+ HKEY hServKey = NULL;
+ HKEY hRparamKey = NULL;
+ HKEY hSparamKey = NULL;
+ HKEY hUparamKey = NULL;
+
+ if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
+ return NULL;
+ if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
+ return NULL;
+
+ /* make the HKLM\\SOFTWARE key */
+ lstrcpyW(buff, REGSOFTWARE_ROOT);
+ if (szRoot)
+ lstrcatW(buff, szRoot);
+ else
+ lstrcatW(buff, REGAPACHE_ROOT);
+ lstrcatW(buff, REGSEPARATOR);
+ lstrcatW(buff, szKeyName);
+ /* Open or create the root key */
+ if (dwOptions & APXREG_SOFTWARE) {
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, buff, 0, NULL, 0,
+ samDesired, NULL,
+ &hRootKey, NULL);
+ else
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
+ samDesired, &hRootKey);
+ if (rc != ERROR_SUCCESS) {
+ hRootKey = NULL;
+ goto cleanup;
+ }
+ /* Open or create the root parameters key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(hRootKey, REGPARAMS, 0, NULL, 0,
+ samDesired, NULL,
+ &hRparamKey, NULL);
+ else
+ rc = RegOpenKeyExW(hRootKey, REGPARAMS, 0,
+ samDesired, &hRparamKey);
+ if (rc != ERROR_SUCCESS) {
+ hRparamKey = NULL;
+ goto cleanup;
+ }
+ }
+
+ if (dwOptions & APXREG_USER) {
+ /* Open or create the users root key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(HKEY_CURRENT_USER, buff, 0, NULL, 0,
+ samDesired, NULL,
+ &hUserKey, NULL);
+ else
+ rc = RegOpenKeyExW(HKEY_CURRENT_USER, buff, 0,
+ samDesired, &hUserKey);
+ if (rc != ERROR_SUCCESS) {
+ hUserKey = NULL;
+ goto cleanup;
+ }
+ /* Open or create the users parameters key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(hUserKey, REGPARAMS, 0, NULL, 0,
+ samDesired, NULL,
+ &hUparamKey, NULL);
+ else
+ rc = RegOpenKeyExW(hUserKey, REGPARAMS, 0,
+ samDesired, &hUparamKey);
+ if (rc != ERROR_SUCCESS) {
+ hUparamKey = NULL;
+ goto cleanup;
+ }
+ }
+ /* Check if we need a service key */
+ if (dwOptions & APXREG_SERVICE) {
+ lstrcpyW(buff, REGSERVICE_ROOT);
+ lstrcatW(buff, szKeyName);
+ /* Service has to be created allready */
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
+ samDesired, &hServKey);
+ if (rc != ERROR_SUCCESS) {
+ hServKey = NULL;
+ goto cleanup;
+ }
+ /* Open or create the root parameters key */
+ if (samDesired & KEY_CREATE_SUB_KEY)
+ rc = RegCreateKeyExW(hServKey, REGPARAMS, 0, NULL, 0,
+ samDesired, NULL,
+ &hSparamKey, NULL);
+ else
+ rc = RegOpenKeyExW(hServKey, REGPARAMS, 0,
+ samDesired, &hSparamKey);
+ if (rc != ERROR_SUCCESS) {
+ hSparamKey = NULL;
+ goto cleanup;
+ }
+ }
+ hRegistry = apxHandleCreate(hPool, 0,
+ NULL, sizeof(APXREGISTRY),
+ __apxRegistryCallback);
+ if (IS_INVALID_HANDLE(hRegistry))
+ return NULL;
+ hRegistry->dwType = APXHANDLE_TYPE_REGISTRY;
+ lpReg = APXHANDLE_DATA(hRegistry);
+ lpReg->samOptions = samDesired;
+ lpReg->hRootKey = hRootKey;
+ lpReg->hUserKey = hUserKey;
+ lpReg->hServKey = hServKey;
+ lpReg->hRparamKey = hRparamKey;
+ lpReg->hUparamKey = hUparamKey;
+ lpReg->hSparamKey = hSparamKey;
+ TAILQ_INIT(&lpReg->lSubkeys);
+
+ SetLastError(rc);
+ return hRegistry;
+
+cleanup:
+ SAFE_CLOSE_KEY(hRparamKey);
+ SAFE_CLOSE_KEY(hSparamKey);
+ SAFE_CLOSE_KEY(hUparamKey);
+ SAFE_CLOSE_KEY(hRootKey);
+ SAFE_CLOSE_KEY(hServKey);
+ SAFE_CLOSE_KEY(hUserKey);
+
+ SetLastError(rc);
+ return NULL;
+}
+
+APXHANDLE
+apxCreateRegistryA(APXHANDLE hPool, REGSAM samDesired,
+ LPCSTR szRoot,
+ LPCSTR szKeyName,
+ DWORD dwOptions)
+{
+ WCHAR wcRoot[SIZ_RESLEN];
+ WCHAR wcKey[SIZ_RESLEN];
+ LPWSTR wsRoot = NULL;
+ if (szRoot) {
+ AsciiToWide(szRoot, wcRoot);
+ wsRoot = wcRoot;
+ }
+ AsciiToWide(szKeyName, wcKey);
+ return apxCreateRegistryW(hPool, samDesired, wsRoot, wcKey, dwOptions);
+}
+
+LPSTR
+apxRegistryGetStringA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExA(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ lpReg->pCurrVal = __apxGetRegistrySzA(hRegistry->hPool, hKey, szValueName);
+
+ return lpReg->pCurrVal;
+}
+
+LPWSTR
+apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ lpReg->pCurrVal = __apxGetRegistrySzW(hRegistry->hPool, hKey, szValueName);
+
+ return lpReg->pCurrVal;
+}
+
+LPBYTE
+apxRegistryGetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ LPBYTE lpData, LPDWORD lpdwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExA(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (lpData && lpdwLength && *lpdwLength) {
+ DWORD rc, dwType = REG_BINARY;
+ rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
+ if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
+ ErrorMessage(NULL, FALSE);
+ return NULL;
+ }
+ lpReg->pCurrVal = lpData;
+ }
+ else {
+ lpReg->pCurrVal = __apxGetRegistryBinaryA(hRegistry->hPool, hKey, szValueName, lpdwLength);
+ }
+
+ return lpReg->pCurrVal;
+}
+
+LPBYTE
+apxRegistryGetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPBYTE lpData, LPDWORD lpdwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (lpData && lpdwLength && *lpdwLength) {
+ DWORD rc, dwType = REG_BINARY;
+ rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
+ if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
+ return NULL;
+ }
+ lpReg->pCurrVal = lpData;
+ }
+ else {
+ lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
+ }
+ return lpReg->pCurrVal;
+}
+
+DWORD
+apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwRval, rl;
+ DWORD rc, dwType = REG_DWORD;
+
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return 0;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return 0;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return 0;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ rl = sizeof(DWORD);
+ rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (LPBYTE)&dwRval, &rl);
+ if (rc != ERROR_SUCCESS || dwType != REG_DWORD)
+ return 0;
+ else
+ return dwRval;
+}
+
+LPWSTR
+apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPWSTR lpData, LPDWORD lpdwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return NULL;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return NULL;
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return NULL;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (lpData && lpdwLength && *lpdwLength) {
+ DWORD rc, dwType = REG_MULTI_SZ;
+ rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (BYTE *)lpData, lpdwLength);
+ if (rc != ERROR_SUCCESS || dwType != REG_MULTI_SZ) {
+ return NULL;
+ }
+ lpReg->pCurrVal = lpData;
+ }
+ else {
+ lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
+ if (lpReg->pCurrVal && lpdwLength)
+ *lpdwLength = *lpdwLength * sizeof(WCHAR);
+ }
+ return lpReg->pCurrVal;
+}
+
+BOOL
+apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ const LPBYTE lpData, DWORD dwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_BINARY;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExA(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExA(hKey, szValueName, 0, dwType,
+ lpData, dwLength) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ const LPBYTE lpData, DWORD dwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_BINARY;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ lpData, dwLength) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPCWSTR lpData, DWORD dwLength)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_MULTI_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ (const BYTE *)lpData, dwLength) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetStrA(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCSTR szSubkey, LPCSTR szValueName,
+ LPCSTR szValue)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExA(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (!szValue || !lstrlenA(szValue)) {
+ if (RegDeleteValueA(hKey, szValueName) != ERROR_SUCCESS)
+ return FALSE;
+ }
+ else if (RegSetValueExA(hKey, szValueName, 0, dwType,
+ (LPBYTE)szValue, lstrlenA(szValue)) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ LPCWSTR szValue)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (!szValue || !lstrlenW(szValue)) {
+ if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
+ return FALSE;
+ }
+ else if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ (LPBYTE)szValue,
+ lstrlenW(szValue) * sizeof(WCHAR)) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL
+apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName,
+ DWORD dwValue)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_DWORD;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegCreateKeyExW(hKey, szSubkey, 0,
+ NULL, 0, lpReg->samOptions,
+ NULL, &hSub, NULL) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegSetValueExW(hKey, szValueName, 0, dwType,
+ (LPBYTE)&dwValue,
+ sizeof(DWORD)) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+
+BOOL
+apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom,
+ LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+ LPAPXREGISTRY lpReg;
+ HKEY hKey, hSub = NULL;
+ DWORD dwType = REG_SZ;
+ if (IS_INVALID_HANDLE(hRegistry) ||
+ hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+ return FALSE;
+ lpReg = APXHANDLE_DATA(hRegistry);
+
+ REG_GET_KEY(lpReg, dwFrom, hKey);
+ if (!hKey)
+ return FALSE;
+
+ if (szSubkey) {
+ SAFE_CLOSE_KEY(lpReg->hCurrKey);
+ if (RegOpenKeyExW(hKey, szSubkey, 0,
+ lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+ return FALSE;
+ lpReg->hCurrKey = hSub;
+ hKey = hSub;
+ }
+ if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
+ return FALSE;
+
+ return TRUE;
+}
+
+
+BOOL
+apxDeleteRegistryW(LPCWSTR szRoot,
+ LPCWSTR szKeyName,
+ BOOL bDeleteEmpty)
+{
+ WCHAR buff[SIZ_BUFLEN];
+ BOOL rv;
+
+ if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
+ return FALSE;
+ if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
+ return FALSE;
+
+ lstrcpyW(buff, REGSOFTWARE_ROOT);
+ if (szRoot)
+ lstrcatW(buff, szRoot);
+ else
+ lstrcatW(buff, REGAPACHE_ROOT);
+ lstrcatW(buff, REGSEPARATOR);
+ lstrcatW(buff, szKeyName);
+
+ rv = SHDeleteKeyW(HKEY_LOCAL_MACHINE, buff);
+ rv += SHDeleteKeyW(HKEY_CURRENT_USER, buff);
+
+ if (bDeleteEmpty) {
+ lstrcpyW(buff, REGSOFTWARE_ROOT);
+ if (szRoot)
+ lstrcatW(buff, szRoot);
+ else
+ lstrcatW(buff, REGAPACHE_ROOT);
+
+ SHDeleteEmptyKeyW(HKEY_LOCAL_MACHINE, buff);
+ SHDeleteEmptyKeyW(HKEY_CURRENT_USER, buff);
+ }
+ return rv;
+}
+
+BOOL
+apxDeleteRegistryA(LPCSTR szRoot,
+ LPCSTR szKeyName,
+ BOOL bDeleteEmpty)
+{
+ WCHAR wcRoot[SIZ_RESLEN];
+ WCHAR wcKey[SIZ_RESLEN];
+ LPWSTR wsRoot = NULL;
+ if (szRoot) {
+ AsciiToWide(szRoot, wcRoot);
+ wsRoot = wcRoot;
+ }
+ AsciiToWide(szKeyName, wcKey);
+
+ return apxDeleteRegistryW(wsRoot, wcKey, bDeleteEmpty);
+}
+
+
+LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre)
+{
+ LPWSTR wsJhome, off;
+ DWORD err, dwLen;
+ HKEY hKey;
+ WCHAR wsBuf[SIZ_BUFLEN];
+ WCHAR wsKey[SIZ_RESLEN];
+#if 1 /* XXX: Add that customizable using function call arg */
+ if (!bPreferJre && (wsJhome = __apxGetEnvironmentVariableW(hPool, JAVA_HOME)))
+ return wsJhome;
+#endif
+ lstrcpyW(wsKey, JAVA_CURRENT);
+ if (bPreferJre)
+ lstrcpyW(wsBuf, JRE_REGKEY);
+ else
+ lstrcpyW(wsBuf, JDK_REGKEY);
+ dwLen = lstrlenW(wsBuf);
+ off = &wsBuf[dwLen];
+ dwLen = SIZ_RESMAX;
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
+ (LPBYTE)off,
+ &dwLen)) != ERROR_SUCCESS) {
+ RegCloseKey(hKey);
+ return NULL;
+ }
+ RegCloseKey(hKey);
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
+ if (wsJhome)
+ SetEnvironmentVariableW(JAVA_HOME, wsJhome);
+ RegCloseKey(hKey);
+
+ return wsJhome;
+}
+
+LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool)
+{
+ LPWSTR wsRtlib, off;
+ DWORD err, dwLen = SIZ_RESLEN;
+ HKEY hKey;
+ WCHAR wsBuf[SIZ_BUFLEN];
+
+ lstrcpyW(wsBuf, JRE_REGKEY);
+
+ dwLen = lstrlenW(wsBuf);
+ off = &wsBuf[dwLen];
+ dwLen = SIZ_RESLEN;
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL,
+ (LPBYTE)off,
+ &dwLen)) != ERROR_SUCCESS) {
+ RegCloseKey(hKey);
+ return NULL;
+ }
+ RegCloseKey(hKey);
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return NULL;
+ }
+ wsRtlib = __apxGetRegistrySzW(hPool, hKey, JAVA_RUNTIME);
+ RegCloseKey(hKey);
+
+ return wsRtlib;
+}
+
+/* Service Registry helper functions */
+
+BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry)
+{
+ DWORD rc, dwLength = SIZ_RESLEN;
+
+ if (IS_INVALID_HANDLE(lpEnum->hServicesKey)) {
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, REGSERVICE_ROOT, 0,
+ KEY_READ, &(lpEnum->hServicesKey));
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+ rc = RegQueryInfoKeyW(lpEnum->hServicesKey,
+ NULL,
+ NULL,
+ NULL,
+ &lpEnum->cSubKeys,
+ &lpEnum->cbMaxSubKey,
+ &lpEnum->cchMaxClass,
+ &lpEnum->cValues,
+ &lpEnum->cchMaxValue,
+ &lpEnum->cbMaxValueData,
+ NULL,
+ NULL);
+ /* TODO: add dynamic maxsubkey length */
+ if (rc != ERROR_SUCCESS || lpEnum->cbMaxSubKey > SIZ_RESLEN) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ }
+ if (lpEnum->dwIndex >= lpEnum->cSubKeys) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ rc = RegEnumKeyExW(lpEnum->hServicesKey,
+ lpEnum->dwIndex++,
+ lpEntry->szServiceName,
+ &dwLength,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ if (rc != ERROR_SUCCESS) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ else {
+ HKEY hKey;
+ rc = RegOpenKeyExW(lpEnum->hServicesKey, lpEntry->szServiceName,
+ 0, KEY_READ, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+ return FALSE;
+ }
+ __apxGetRegistryStrW(NULL, hKey, REGDESCRIPTION,
+ lpEntry->szServiceDescription, SIZ_DESLEN);
+ __apxGetRegistryStrW(NULL, hKey, REGSERVICE_USER,
+ lpEntry->szObjectName, SIZ_RESLEN);
+ lpEntry->dwStart = __apxGetRegistryDwordW(NULL, hKey, REGSERVICE_START);
+ RegCloseKey(hKey);
+
+ }
+ return TRUE;
+}
+
+/* We could use the ChangeServiceConfig2 on WIN2K+
+ * For now use the registry.
+ */
+BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription)
+{
+ HKEY hKey;
+ WCHAR wcName[SIZ_RESLEN];
+ DWORD rc;
+
+ if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ return FALSE;
+ lstrcpyW(wcName, REGSERVICE_ROOT);
+ lstrcatW(wcName, szServiceName);
+
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_WRITE, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ rc = RegSetValueExW(hKey, REGDESCRIPTION, 0, REG_SZ, (CONST BYTE *)szDescription,
+ lstrlenW(szDescription) * sizeof(WCHAR));
+ SAFE_CLOSE_KEY(hKey);
+
+ return rc = ERROR_SUCCESS;
+}
+
+BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
+ DWORD dwDescriptionLength)
+{
+ HKEY hKey;
+ WCHAR wcName[SIZ_RESLEN];
+ DWORD rc, l = dwDescriptionLength * sizeof(WCHAR);
+ DWORD t = REG_SZ;
+ if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ return FALSE;
+ lstrcpyW(wcName, REGSERVICE_ROOT);
+ lstrcatW(wcName, szServiceName);
+
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+ rc = RegQueryValueExW(hKey, REGDESCRIPTION, NULL, &t, (BYTE *)szDescription,
+ &l);
+ SAFE_CLOSE_KEY(hKey);
+ if (rc == ERROR_SUCCESS && t == REG_SZ)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
+ DWORD dwUserLength)
+{
+ HKEY hKey;
+ WCHAR wcName[SIZ_RESLEN];
+ DWORD rc, l = dwUserLength * sizeof(WCHAR);
+ DWORD t = REG_SZ;
+ if (lstrlenW(szServiceName) > SIZ_RESMAX)
+ return FALSE;
+ lstrcpyW(wcName, REGSERVICE_ROOT);
+ lstrcatW(wcName, szServiceName);
+
+ rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
+ if (rc != ERROR_SUCCESS) {
+ return FALSE;
+ }
+ rc = RegQueryValueExW(hKey, REGSERVICE_USER, NULL, &t, (BYTE *)szUser,
+ &l);
+ SAFE_CLOSE_KEY(hKey);
+ if (rc == ERROR_SUCCESS && t == REG_SZ)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+DWORD apxGetMaxServiceTimeout(APXHANDLE hPool)
+{
+ DWORD maxTimeout = 20000;
+ LPWSTR wsMaxTimeout;
+ DWORD err;
+ HKEY hKey;
+ WCHAR wsBuf[SIZ_BUFLEN];
+
+ lstrcpyW(wsBuf, CONTROL_REGKEY);
+
+ if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+ 0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+ return maxTimeout;
+ }
+ wsMaxTimeout = __apxGetRegistrySzW(hPool, hKey, REGTIMEOUT);
+ RegCloseKey(hKey);
+
+ if (wsMaxTimeout[0]) {
+ maxTimeout = (DWORD)apxAtoulW(wsMaxTimeout);
+ }
+ apxFree(wsMaxTimeout);
+
+ return maxTimeout;
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/registry.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/rprocess.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/rprocess.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/rprocess.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,939 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define CHILD_RUNNING 0x0001
+#define CHILD_INITIALIZED 0x0002
+#define CHILD_MAINTREAD_FINISHED 0x0004
+#define PROC_INITIALIZED 0x0008
+#define CHILD_TERMINATE_CODE 19640323 /* Could be any value like my birthday ;-)*/
+
+DYNOLAD_TYPE_DECLARE(CreateRemoteThread,
+ __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES,
+ DWORD, LPTHREAD_START_ROUTINE,
+ LPVOID, DWORD, LPDWORD);
+
+DYNOLAD_TYPE_DECLARE(ExitProcess, __stdcall, void)(UINT);
+
+#define CHECK_IF_ACTIVE(proc) \
+ APXMACRO_BEGIN \
+ DWORD __st; \
+ if (!GetExitCodeProcess((proc)->stProcInfo.hProcess, &__st) || \
+ (__st != STILL_ACTIVE)) \
+ goto cleanup; \
+ APXMACRO_END
+
+#define SAVE_STD_HANDLES(p) \
+ APXMACRO_BEGIN \
+ if ((p)->bSaveHandles) { \
+ (p)->hParentStdSave[0] = GetStdHandle(STD_INPUT_HANDLE); \
+ (p)->hParentStdSave[1] = GetStdHandle(STD_OUTPUT_HANDLE); \
+ (p)->hParentStdSave[2] = GetStdHandle(STD_ERROR_HANDLE); \
+ } APXMACRO_END
+
+#define RESTORE_STD_HANDLES(p) \
+ APXMACRO_BEGIN \
+ if ((p)->bSaveHandles) { \
+ SetStdHandle(STD_INPUT_HANDLE, (p)->hParentStdSave[0]); \
+ SetStdHandle(STD_OUTPUT_HANDLE, (p)->hParentStdSave[1]); \
+ SetStdHandle(STD_ERROR_HANDLE, (p)->hParentStdSave[2]); \
+ } APXMACRO_END
+
+#define REDIRECT_STD_HANDLES(p) \
+ APXMACRO_BEGIN \
+ if ((p)->bSaveHandles) { \
+ SetStdHandle(STD_INPUT_HANDLE, (p)->hChildStdInp); \
+ SetStdHandle(STD_OUTPUT_HANDLE, (p)->hChildStdOut); \
+ SetStdHandle(STD_ERROR_HANDLE, (p)->hChildStdErr); \
+ } APXMACRO_END
+
+typedef struct APXPROCESS {
+ DWORD dwChildStatus;
+ DWORD dwOptions;
+ PROCESS_INFORMATION stProcInfo;
+ /* Size of chars for ANSI/Unicode programs */
+ DWORD chSize;
+ /* application working path */
+ LPWSTR szWorkingPath;
+ /* executable name */
+ LPWSTR szApplicationExec;
+ /* command line (first arg is program name for argv[0]) */
+ LPWSTR szCommandLine;
+ LPWSTR lpEnvironment;
+ /* set of child inherited pipes */
+ HANDLE hChildStdInp;
+ HANDLE hChildStdOut;
+ HANDLE hChildStdErr;
+ /* parent ends of child pipes */
+ HANDLE hChildInpWr;
+ HANDLE hChildOutRd;
+ HANDLE hChildErrRd;
+ /* Saved console pipes */
+ HANDLE hParentStdSave[3];
+ HANDLE hWorkerThreads[3];
+ HANDLE hUserToken;
+ HANDLE hCurrentProcess;
+ BOOL bSaveHandles;
+ /** callback function */
+ LPAPXFNCALLBACK fnUserCallback;
+ LPSECURITY_ATTRIBUTES lpSA;
+ LPVOID lpSD;
+ BYTE bSD[SECURITY_DESCRIPTOR_MIN_LENGTH];
+ BYTE bSA[sizeof(SECURITY_ATTRIBUTES)];
+
+} APXPROCESS, *LPAPXPROCESS;
+
+/** Process worker thread
+ * Monitors the process thread
+ */
+static DWORD WINAPI __apxProcWorkerThread(LPVOID lpParameter)
+{
+ APXHANDLE hProcess = (APXHANDLE)lpParameter;
+ LPAPXPROCESS lpProc;
+ DWORD dwExitCode = 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ /* Wait util a process has finished its initialization.
+ */
+ WaitForInputIdle(lpProc->stProcInfo.hProcess, INFINITE);
+ lpProc->dwChildStatus |= CHILD_INITIALIZED;
+ /* Wait until the child process exits */
+ if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
+ INFINITE) == WAIT_OBJECT_0) {
+ lpProc->dwChildStatus |= CHILD_MAINTREAD_FINISHED;
+#if 0
+ if (hProcess->fnCallback)
+ (*hProcess->fnCallback)(hProcess, WM_QUIT, (WPARAM)dwExitCode, 0);
+ lpProc->dwChildStatus &= ~CHILD_RUNNING;
+ GetExitCodeProcess(lpProc->stProcInfo.hProcess, &dwExitCode);
+
+ /* Close that handle */
+#endif
+ }
+ ExitThread(0);
+ return 0;
+}
+
+static DWORD WINAPI __apxProcStdoutThread(LPVOID lpParameter)
+{
+ APXHANDLE hProcess = (APXHANDLE)lpParameter;
+ LPAPXPROCESS lpProc;
+ APXCALLHOOK *lpCall;
+ INT ch;
+ DWORD dwReaded;
+ lpProc = APXHANDLE_DATA(hProcess);
+ while (lpProc->dwChildStatus & CHILD_RUNNING) {
+ ch = 0;
+ if (!ReadFile(lpProc->hChildOutRd, &ch, lpProc->chSize,
+ &dwReaded, NULL) || !dwReaded) {
+
+ break;
+ }
+ if (lpProc->fnUserCallback)
+ (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
+ TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
+ }
+ dwReaded = 0;
+ SwitchToThread();
+ }
+ ExitThread(0);
+ return 0;
+}
+
+static DWORD WINAPI __apxProcStderrThread(LPVOID lpParameter)
+{
+ APXHANDLE hProcess = (APXHANDLE)lpParameter;
+ LPAPXPROCESS lpProc;
+ APXCALLHOOK *lpCall;
+ INT ch;
+ DWORD dwReaded;
+ lpProc = APXHANDLE_DATA(hProcess);
+ while (lpProc->dwChildStatus & CHILD_RUNNING) {
+ if (!ReadFile(lpProc->hChildErrRd, &ch, lpProc->chSize,
+ &dwReaded, NULL) || !dwReaded) {
+
+ break;
+ }
+ if (lpProc->fnUserCallback)
+ (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
+ TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
+ (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
+ }
+
+ dwReaded = 0;
+ SwitchToThread();
+ }
+
+ ExitThread(0);
+ return 0;
+}
+
+static DWORD __apxProcessPutc(LPAPXPROCESS lpProc, INT ch, DWORD dwSize)
+{
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ DWORD wr = 0;
+ if (WriteFile(lpProc->hChildInpWr, &ch, dwSize, &wr, NULL) &&
+ wr == dwSize) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static DWORD __apxProcessPuts(LPAPXPROCESS lpProc, LPCTSTR szString)
+{
+ DWORD l, n = 0;
+ l = lstrlen(szString) * lpProc->chSize;
+ if (lpProc->dwChildStatus & CHILD_RUNNING && l) {
+ DWORD wr = 0;
+ while (TRUE) {
+ if (WriteFile(lpProc->hChildInpWr, szString, l,
+ &wr, NULL)) {
+ n += wr;
+ if (wr < l) {
+ l -= wr;
+ szString += wr;
+ }
+ else {
+ /* Flush the buffer */
+ FlushFileBuffers(lpProc->hChildInpWr);
+ break;
+ }
+ }
+ else
+ break;
+ }
+ }
+
+ return n;
+}
+
+static DWORD __apxProcessWrite(LPAPXPROCESS lpProc, LPCVOID lpData, DWORD dwLen)
+{
+ LPBYTE buf = (LPBYTE)lpData;
+ DWORD n = 0;
+ if (!lpData || !dwLen)
+ return 0;
+
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ DWORD wr = 0;
+ while (lpProc->dwChildStatus & CHILD_RUNNING) {
+ if (WriteFile(lpProc->hChildInpWr, buf, dwLen,
+ &wr, NULL)) {
+ n += wr;
+ if (wr < dwLen) {
+ dwLen -= wr;
+ buf += wr;
+ }
+ else
+ break;
+ }
+ else
+ break;
+ }
+ }
+
+ return n;
+}
+
+/** Helper functions */
+static BOOL __apxProcCreateChildPipes(LPAPXPROCESS lpProc)
+{
+ BOOL rv = FALSE;
+
+ if (!CreatePipe(&(lpProc->hChildStdInp),
+ &(lpProc->hChildInpWr),
+ lpProc->lpSA, 0)) {
+ ErrorMessage(NULL, FALSE);
+ goto cleanup;
+ }
+ if (!SetHandleInformation(lpProc->hChildInpWr,
+ HANDLE_FLAG_INHERIT, 0)) {
+ ErrorMessage(NULL, FALSE);
+ goto cleanup;
+ }
+
+ if (!CreatePipe(&(lpProc->hChildOutRd),
+ &(lpProc->hChildStdOut),
+ lpProc->lpSA, 0)) {
+ ErrorMessage(NULL, FALSE);
+ goto cleanup;
+ }
+
+ if (!SetHandleInformation(lpProc->hChildOutRd,
+ HANDLE_FLAG_INHERIT, 0)) {
+ ErrorMessage(NULL, FALSE);
+ goto cleanup;
+ }
+
+ if (!CreatePipe(&(lpProc->hChildErrRd),
+ &(lpProc->hChildStdErr),
+ lpProc->lpSA, 0)) {
+ ErrorMessage(NULL, FALSE);
+ goto cleanup;
+ }
+
+ if (!SetHandleInformation(lpProc->hChildErrRd,
+ HANDLE_FLAG_INHERIT, 0)) {
+ ErrorMessage(NULL, FALSE);
+ goto cleanup;
+ }
+ rv = TRUE;
+cleanup:
+
+ return rv;
+}
+
+/* Close the process.
+ * Create the remote thread and call the ExitProcess
+ * Terminate the process, if all of the above fails.
+ */
+static BOOL __apxProcessClose(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+ DYNLOAD_FPTR_DECLARE(CreateRemoteThread);
+ DYNLOAD_FPTR_DECLARE(ExitProcess);
+
+ UINT uExitCode = CHILD_TERMINATE_CODE; /* Could be any value like my birthday ;-)*/
+ HANDLE hDup, hRemote;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ CHECK_IF_ACTIVE(lpProc);
+
+ /* Try to close the child's stdin first */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ /* Wait 1 sec for child process to
+ * recognize that the stdin has been closed.
+ */
+ if (WaitForSingleObject(lpProc->stProcInfo.hProcess, 1000) == WAIT_OBJECT_0)
+ goto cleanup;
+
+ CHECK_IF_ACTIVE(lpProc);
+
+ /* Try to create the remote thread in the child address space */
+ DYNLOAD_FPTR_ADDRESS(CreateRemoteThread, KERNEL32);
+ if (DuplicateHandle(lpProc->hCurrentProcess,
+ lpProc->stProcInfo.hProcess,
+ lpProc->hCurrentProcess,
+ &hDup,
+ PROCESS_ALL_ACCESS,
+ FALSE, 0)) {
+ DYNLOAD_FPTR_ADDRESS(ExitProcess, KERNEL32);
+ /* Now call the ExitProcess from inside the client
+ * This will safely unload all the dll's.
+ */
+ hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup,
+ NULL, 0,
+ (LPTHREAD_START_ROUTINE)DYNLOAD_FPTR(ExitProcess),
+ (PVOID)&uExitCode, 0, NULL);
+ if (!IS_INVALID_HANDLE(hRemote)) {
+ if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
+ 2000) == WAIT_OBJECT_0) {
+
+ }
+ else {
+ TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
+ }
+ CloseHandle(hRemote);
+ }
+ CloseHandle(hDup);
+ goto cleanup;
+ }
+
+ TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
+
+cleanup:
+ /* Close the process handle */
+ SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
+ lpProc->dwChildStatus &= ~CHILD_RUNNING;
+ return TRUE;
+}
+
+static BOOL __apxProcessCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXPROCESS lpProc;
+
+ lpProc = APXHANDLE_DATA(hObject);
+ /* Call the user supplied callback first */
+ if (lpProc->fnUserCallback)
+ (*lpProc->fnUserCallback)(hObject, uMsg, wParam, lParam);
+ switch (uMsg) {
+ case WM_CLOSE:
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ __apxProcessClose(hObject);
+ /* Wait for all worker threads to exit */
+ WaitForMultipleObjects(3, lpProc->hWorkerThreads, TRUE, INFINITE);
+ }
+ SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
+
+ /* Close parent side of the pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
+ SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
+
+ SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[0]);
+ SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[1]);
+ SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[2]);
+ SAFE_CLOSE_HANDLE(lpProc->hUserToken);
+ apxFree(lpProc->szApplicationExec);
+ apxFree(lpProc->szCommandLine);
+ apxFree(lpProc->szWorkingPath);
+ RESTORE_STD_HANDLES(lpProc);
+ SAFE_CLOSE_HANDLE(lpProc->hCurrentProcess);
+ if (lpProc->lpEnvironment)
+ FreeEnvironmentStringsW(lpProc->lpEnvironment);
+
+ case WM_QUIT:
+ /* The process has finished
+ * This is a WorkerThread message
+ */
+ lpProc->dwChildStatus &= ~CHILD_RUNNING;
+ break;
+ case WM_CHAR:
+ __apxProcessPutc(lpProc, (INT)lParam, lpProc->chSize);
+ break;
+ case WM_SETTEXT:
+ if (wParam)
+ __apxProcessWrite(lpProc, (LPCVOID)lParam, (DWORD)wParam);
+ else
+ __apxProcessPuts(lpProc, (LPCTSTR)lParam);
+ break;
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+/** Create the process but don't start it
+ *
+ APXHANDLE
+apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCWSTR szUsername, LPCWSTR szPassword,
+ BOOL bLogonAsService)
+{
+ APXHANDLE hProcess;
+ LPAPXPROCESS lpProc;
+ HANDLE hUserToken = NULL;
+ if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
+ HANDLE hUser;
+#ifndef _UNICODE
+ WCHAR wsUsername[256];
+ WCHAR wsPassword[256];
+ AsciiToWide(szUsername, wsUsername);
+ AsciiToWide(szPassword, wsPassword);
+#else
+ LPCWSTR wsUsername = szUsername;
+ LPCWSTR wsPassword = szPassword;
+#endif
+
+ */
+
+
+ APXHANDLE
+apxCreateProcessA(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCSTR szUsername, LPCSTR szPassword,
+ BOOL bLogonAsService)
+{
+
+ if (szUsername && szPassword) {
+ WCHAR wsUsername[256];
+ WCHAR wsPassword[256];
+ AsciiToWide(szUsername, wsUsername);
+ AsciiToWide(szPassword, wsPassword);
+ return apxCreateProcessW(hPool, dwOptions, fnCallback,
+ wsUsername, wsPassword, bLogonAsService);
+ }
+ else
+ return apxCreateProcessW(hPool, dwOptions, fnCallback,
+ NULL, NULL, bLogonAsService);
+}
+
+APXHANDLE
+apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+ LPAPXFNCALLBACK fnCallback,
+ LPCWSTR szUsername, LPCWSTR szPassword,
+ BOOL bLogonAsService)
+{
+ APXHANDLE hProcess;
+ LPAPXPROCESS lpProc;
+ HANDLE hUserToken = NULL;
+ /* CreateProcessAsUser is supported only on NT */
+ if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
+ HANDLE hUser;
+ if (!LogonUserW(szUsername,
+ NULL,
+ szPassword,
+ bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
+ LOGON32_PROVIDER_DEFAULT,
+ &hUser)) {
+ /* Logon Failed */
+ ErrorMessage(NULL, TRUE);
+ return NULL;
+ }
+ if (!DuplicateTokenEx(hUser,
+ TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
+ NULL,
+ SecurityImpersonation,
+ TokenPrimary,
+ &hUserToken)) {
+ CloseHandle(hUser);
+ /* Failed to duplicate the user token */
+ ErrorMessage(NULL, TRUE);
+ return NULL;
+ }
+ if (!ImpersonateLoggedOnUser(hUserToken)) {
+ CloseHandle(hUser);
+ CloseHandle(hUserToken);
+ /* failed to impersonate the logged user */
+ ErrorMessage(NULL, TRUE);
+ return NULL;
+ }
+ CloseHandle(hUser);
+ }
+
+ hProcess = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT,
+ NULL, sizeof(APXPROCESS),
+ __apxProcessCallback);
+ if (IS_INVALID_HANDLE(hProcess))
+ return NULL;
+ hProcess->dwType = APXHANDLE_TYPE_PROCESS;
+ lpProc = APXHANDLE_DATA(hProcess);
+ lpProc->dwOptions = dwOptions;
+ lpProc->fnUserCallback = fnCallback;
+ lpProc->hUserToken = hUserToken;
+ /* set the CHAR length */
+ if (dwOptions & CREATE_UNICODE_ENVIRONMENT)
+ lpProc->chSize = sizeof(WCHAR);
+ else
+ lpProc->chSize = sizeof(CHAR);
+#if 1
+ DuplicateHandle(GetCurrentProcess(),
+ GetCurrentProcess(),
+ GetCurrentProcess(),
+ &lpProc->hCurrentProcess,
+ PROCESS_ALL_ACCESS,
+ FALSE,
+ 0);
+#else
+ lpProc->hCurrentProcess = GetCurrentProcess();
+#endif
+ lpProc->lpSD = &lpProc->bSD;
+
+ InitializeSecurityDescriptor(lpProc->lpSD, SECURITY_DESCRIPTOR_REVISION);
+ SetSecurityDescriptorDacl(lpProc->lpSD, -1, 0, 0);
+
+ lpProc->lpSA = (LPSECURITY_ATTRIBUTES)&lpProc->bSA[0];
+ lpProc->lpSA->nLength = sizeof (SECURITY_ATTRIBUTES);
+ lpProc->lpSA->lpSecurityDescriptor = lpProc->lpSD;
+ lpProc->lpSA->bInheritHandle = TRUE;
+
+ return hProcess;
+}
+
+static WCHAR _desktop_name[] =
+ {'W', 'i', 'n', 's', 't', 'a', '0', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', 0};
+
+BOOL
+apxProcessExecute(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+ STARTUPINFOW si;
+ DWORD id;
+ BOOL bS = FALSE;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ /* don't allow multiple execute calls on the same object */
+ if (lpProc->dwChildStatus & PROC_INITIALIZED)
+ return FALSE;
+ lpProc->bSaveHandles = TRUE;
+ SAVE_STD_HANDLES(lpProc);
+ if (!__apxProcCreateChildPipes(lpProc))
+ goto cleanup;
+ REDIRECT_STD_HANDLES(lpProc);
+ AplZeroMemory(&si, sizeof(STARTUPINFO));
+
+ si.cb = sizeof(STARTUPINFO);
+ si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+ /* Set the redirected handles */
+ si.hStdOutput = lpProc->hChildStdOut;
+ si.hStdError = lpProc->hChildStdErr;
+ si.hStdInput = lpProc->hChildStdInp;
+
+ if (lpProc->lpEnvironment)
+ FreeEnvironmentStringsW(lpProc->lpEnvironment);
+ lpProc->lpEnvironment = GetEnvironmentStringsW();
+
+ if (!IS_INVALID_HANDLE(lpProc->hUserToken)) {
+ si.lpDesktop = _desktop_name;
+ bS = CreateProcessAsUserW(lpProc->hUserToken,
+ lpProc->szApplicationExec,
+ lpProc->szCommandLine,
+ lpProc->lpSA,
+ NULL,
+ TRUE,
+ CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
+ lpProc->lpEnvironment,
+ lpProc->szWorkingPath,
+ &si,
+ &(lpProc->stProcInfo));
+ }
+ else {
+ OutputDebugStringW(lpProc->szApplicationExec);
+ OutputDebugStringW(lpProc->szCommandLine);
+
+ bS = CreateProcessW(lpProc->szApplicationExec,
+ lpProc->szCommandLine,
+ lpProc->lpSA,
+ NULL,
+ TRUE,
+ CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
+ lpProc->lpEnvironment,
+ lpProc->szWorkingPath,
+ &si,
+ &(lpProc->stProcInfo));
+ }
+ /* Close unused sides of pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdOut);
+ SAFE_CLOSE_HANDLE(lpProc->hChildStdErr);
+ if (!bS)
+ goto cleanup;
+ /* Set the running flag */
+ lpProc->dwChildStatus |= (CHILD_RUNNING | PROC_INITIALIZED);
+
+ lpProc->hWorkerThreads[0] = CreateThread(NULL, 0, __apxProcStdoutThread,
+ hProcess, 0, &id);
+ lpProc->hWorkerThreads[1] = CreateThread(NULL, 0, __apxProcStderrThread,
+ hProcess, 0, &id);
+ ResumeThread(lpProc->stProcInfo.hThread);
+ lpProc->hWorkerThreads[2] = CreateThread(NULL, 0, __apxProcWorkerThread,
+ hProcess, 0, &id);
+
+ SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hThread);
+ /* Close child handles first */
+ return TRUE;
+cleanup:
+ /* Close parent side of the pipes */
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
+ SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
+
+ return FALSE;
+}
+
+BOOL
+apxProcessSetExecutableA(APXHANDLE hProcess, LPCSTR szName)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szApplicationExec);
+ lpProc->szApplicationExec = apxPoolWStrdupA(hProcess->hPool, szName);
+ OutputDebugStringW(lpProc->szApplicationExec);
+ return lpProc->szApplicationExec != NULL;
+}
+
+BOOL
+apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szApplicationExec);
+ lpProc->szApplicationExec = apxPoolStrdupW(hProcess->hPool, szName);
+ OutputDebugStringW(lpProc->szApplicationExec);
+ return lpProc->szApplicationExec != NULL;
+}
+
+BOOL
+apxProcessSetCommandLineA(APXHANDLE hProcess, LPCSTR szCmdline)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szCommandLine);
+ lpProc->szCommandLine = apxPoolWStrdupA(hProcess->hPool, szCmdline);
+
+ return lpProc->szCommandLine != NULL;
+}
+
+BOOL
+apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szCommandLine);
+ lpProc->szCommandLine = apxPoolStrdupW(hProcess->hPool, szCmdline);
+
+ return lpProc->szCommandLine != NULL;
+}
+
+BOOL
+apxProcessSetWorkingPathA(APXHANDLE hProcess, LPCSTR szPath)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szWorkingPath);
+ lpProc->szWorkingPath = apxPoolWStrdupA(hProcess->hPool, szPath);
+
+ return lpProc->szWorkingPath != NULL;
+}
+
+BOOL
+apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szWorkingPath);
+ if (!szPath) {
+ /* Clear the WorkingPath */
+ lpProc->szWorkingPath = NULL;
+ return TRUE;
+ }
+ lpProc->szWorkingPath = apxPoolWStrdupW(hProcess->hPool, szPath);
+
+ return lpProc->szWorkingPath != NULL;
+}
+
+DWORD
+apxProcessPutcA(APXHANDLE hProcess, INT ch)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ return __apxProcessPutc(lpProc, ch, sizeof(CHAR));
+}
+
+DWORD
+apxProcessPutcW(APXHANDLE hProcess, INT ch)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ return __apxProcessPutc(lpProc, ch, sizeof(WCHAR));
+}
+
+DWORD
+apxProcessPutsA(APXHANDLE hProcess, LPCSTR szString)
+{
+ LPAPXPROCESS lpProc;
+ DWORD len;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
+ return 0;
+ lpProc = APXHANDLE_DATA(hProcess);
+ len = lstrlenA(szString);
+ len = __apxProcessWrite(lpProc, szString, len);
+ if (len) {
+ FlushFileBuffers(lpProc->hChildInpWr);
+ return len;
+ }
+ else
+ return 0;
+}
+
+DWORD
+apxProcessPutsW(APXHANDLE hProcess, LPCWSTR szString)
+{
+ LPAPXPROCESS lpProc;
+ DWORD len;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
+ return 0;
+ lpProc = APXHANDLE_DATA(hProcess);
+ len = lstrlenW(szString);
+ len = __apxProcessWrite(lpProc, szString, len * 2);
+ if (len) {
+ FlushFileBuffers(lpProc->hChildInpWr);
+ return (len / sizeof(WCHAR));
+ }
+ else
+ return 0;
+}
+
+DWORD
+apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen)
+{
+ LPAPXPROCESS lpProc;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return 0;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ return __apxProcessWrite(lpProc, lpData, dwLen);
+}
+
+BOOL
+apxProcessFlushStdin(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ return FlushFileBuffers(lpProc->hChildInpWr);
+ }
+
+ return FALSE;
+}
+
+VOID
+apxProcessCloseInputStream(APXHANDLE hProcess)
+{
+ if (hProcess->dwType == APXHANDLE_TYPE_PROCESS) {
+ LPAPXPROCESS lpProc = APXHANDLE_DATA(hProcess);
+ if (lpProc->dwChildStatus & CHILD_RUNNING)
+ SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+ }
+}
+
+DWORD
+apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds, BOOL bKill)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return WAIT_ABANDONED;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ if (lpProc->dwChildStatus & CHILD_RUNNING) {
+ DWORD rv = WaitForMultipleObjects(3, lpProc->hWorkerThreads,
+ TRUE, dwMilliseconds);
+ if (rv == WAIT_TIMEOUT && bKill) {
+ __apxProcessCallback(hProcess, WM_CLOSE, 0, 0);
+ }
+ return rv;
+ }
+ else
+ return WAIT_OBJECT_0;
+}
+
+BOOL
+apxProcessRunning(APXHANDLE hProcess)
+{
+ LPAPXPROCESS lpProc;
+
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+
+ return (lpProc->dwChildStatus & CHILD_RUNNING);
+}
+
+static LPWSTR __apxStrQuote(LPWSTR lpDest, LPCWSTR szSrc)
+{
+ LPWSTR p;
+ BOOL q = FALSE;
+
+ /* Find if string has embeded spaces
+ */
+ for (p = (LPWSTR)szSrc; *p; p++) {
+ if (*p == L' ' || *p == '\t' ||
+ *p == '"' || *p == '\\') {
+ q = TRUE;
+ break;
+ }
+ }
+ p = lpDest;
+ if (q) *p++ = L'"';
+ while (*szSrc) {
+ if (*szSrc == '"' || *szSrc == '\\')
+ *p++ = L'\\';
+ *p++ = *szSrc++;
+ }
+ if (q) *p++ = L'"';
+ return p;
+}
+
+BOOL
+apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle,
+ DWORD dwArgc, LPCWSTR *lpArgs)
+{
+ LPAPXPROCESS lpProc;
+ DWORD i, l = 0;
+ LPWSTR p;
+ if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+ return FALSE;
+
+ lpProc = APXHANDLE_DATA(hProcess);
+ apxFree(lpProc->szCommandLine);
+
+ l = lstrlenW(szTitle) + 3;
+ for (i = 0; i < (DWORD)lstrlenW(szTitle); i++) {
+ if (szTitle[i] == L'"')
+ ++l;
+ }
+ for (i = 0; i < dwArgc; i++) {
+ int x, q = 0;
+ l += (lstrlenW(lpArgs[i]) + 3);
+ for (x = 0; x < lstrlenW(lpArgs[i]); x++) {
+ if (lpArgs[i][x] == L'"')
+ ++q;
+ }
+ l += q;
+ }
+ p = lpProc->szCommandLine = apxPoolAlloc(hProcess->hPool, l * sizeof(WCHAR));
+ p = __apxStrQuote(p, szTitle);
+ for (i = 0; i < dwArgc; i++) {
+ *p++ = L' ';
+ p = __apxStrQuote(p, lpArgs[i]);
+ }
+ *p = L'\0';
+ OutputDebugStringW(lpProc->szCommandLine);
+ return lpProc->szCommandLine != NULL;
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/rprocess.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/service.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/service.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/service.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,565 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define SAFE_CLOSE_SCH(h) \
+ if ((h) != NULL && (h) != INVALID_HANDLE_VALUE) { \
+ CloseServiceHandle((h)); \
+ (h) = NULL; \
+ }
+
+#define CHANGE_SERVICE(h, b, u, p, d) \
+ ChangeServiceConfigW(h, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, \
+ SERVICE_NO_CHANGE,b,NULL,NULL,NULL, \
+ u,p,d)
+
+typedef struct APXSERVICE {
+ /* Are we a service manager or we are the service itself */
+ BOOL bManagerMode;
+ /* Handle to the current service */
+ SC_HANDLE hService;
+ /* Handle of the Service manager */
+ SC_HANDLE hManager;
+ APXSERVENTRY stServiceEntry;
+
+} APXSERVICE, *LPAPXSERVICE;
+
+static BOOL __apxIsValidServiceName(LPCWSTR szServiceName)
+{
+ do {
+ if (!IsCharAlphaNumericW(*szServiceName)) {
+ apxDisplayError(TRUE, NULL, 0, "NonAlpha %d", *szServiceName);
+ return FALSE;
+ }
+ } while( *(++szServiceName));
+ return TRUE;
+}
+
+static BOOL __apxServiceCallback(APXHANDLE hObject, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LPAPXSERVICE lpService;
+
+ lpService = APXHANDLE_DATA(hObject);
+ switch (uMsg) {
+ case WM_CLOSE:
+ apxFree(lpService->stServiceEntry.lpConfig);
+ lpService->stServiceEntry.lpConfig = NULL;
+ SAFE_CLOSE_SCH(lpService->hService);
+ SAFE_CLOSE_SCH(lpService->hManager);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+APXHANDLE
+apxCreateService(APXHANDLE hPool, DWORD dwOptions, BOOL bManagerMode)
+{
+ APXHANDLE hService;
+ LPAPXSERVICE lpService;
+ SC_HANDLE hManager;
+
+ if (!(hManager = OpenSCManager(NULL, NULL, dwOptions))) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+ hService = apxHandleCreate(hPool, 0,
+ NULL, sizeof(APXSERVICE),
+ __apxServiceCallback);
+ if (IS_INVALID_HANDLE(hService)) {
+ apxLogWrite(APXLOG_MARK_ERROR "Failed to Create Handle for Service");
+ return NULL;
+ }
+ hService->dwType = APXHANDLE_TYPE_SERVICE;
+ lpService = APXHANDLE_DATA(hService);
+ lpService->hManager = hManager;
+ lpService->bManagerMode = bManagerMode;
+
+ return hService;
+}
+
+BOOL
+apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
+{
+ LPAPXSERVICE lpService;
+ DWORD dwNeeded;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+
+ /* Close any previous instance
+ * Same handle can manage multiple services
+ */
+ SAFE_CLOSE_SCH(lpService->hService);
+ *lpService->stServiceEntry.szServiceDescription = L'\0';
+ *lpService->stServiceEntry.szObjectName = L'\0';
+ apxFree(lpService->stServiceEntry.lpConfig);
+ lpService->stServiceEntry.lpConfig = NULL;
+ /* Open the service */
+ lpService->hService = OpenServiceW(lpService->hManager,
+ szServiceName,
+ dwOptions);
+
+ if (IS_INVALID_HANDLE(lpService->hService)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
+ if (!apxGetServiceDescriptionW(szServiceName,
+ lpService->stServiceEntry.szServiceDescription,
+ SIZ_DESLEN)) {
+ apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service description");
+ lpService->stServiceEntry.szServiceDescription[0] = L'\0';
+ }
+ if (!apxGetServiceUserW(szServiceName,
+ lpService->stServiceEntry.szObjectName,
+ SIZ_RESLEN)) {
+ apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service user name");
+ lpService->stServiceEntry.szObjectName[0] = L'\0';
+ }
+ if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {
+ if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ }
+ /* TODO: Check GetLastError ERROR_INSUFFICIENT_BUFFER */
+ lpService->stServiceEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+ dwNeeded);
+ return QueryServiceConfigW(lpService->hService,
+ lpService->stServiceEntry.lpConfig,
+ dwNeeded, &dwNeeded);
+}
+
+LPAPXSERVENTRY
+apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return NULL;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return NULL;
+
+ if (bRequeryStatus && !QueryServiceStatus(lpService->hService,
+ &(lpService->stServiceEntry.stServiceStatus))) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return NULL;
+ }
+
+ return &lpService->stServiceEntry;
+}
+
+/* Set the service names etc...
+ * If the ImagePath contains a space, it must be quoted
+ */
+BOOL
+apxServiceSetNames(APXHANDLE hService,
+ LPCWSTR szImagePath,
+ LPCWSTR szDisplayName,
+ LPCWSTR szDescription,
+ LPCWSTR szUsername,
+ LPCWSTR szPassword)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServiceOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ if (!CHANGE_SERVICE(lpService->hService,
+ szImagePath,
+ szUsername,
+ szPassword,
+ szDisplayName)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ if (szDescription) {
+ return apxSetServiceDescriptionW(lpService->stServiceEntry.szServiceName,
+ szDescription);
+ }
+ return TRUE;
+}
+
+BOOL
+apxServiceSetOptions(APXHANDLE hService,
+ DWORD dwServiceType,
+ DWORD dwStartType,
+ DWORD dwErrorControl)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServixeOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ return ChangeServiceConfig(lpService->hService, dwServiceType,
+ dwStartType, dwErrorControl,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL);
+}
+
+BOOL
+apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
+ LPAPXFNCALLBACK fnControlCallback,
+ LPVOID lpCbData)
+{
+ LPAPXSERVICE lpService;
+ SERVICE_STATUS stStatus;
+ DWORD dwPending = 0;
+ DWORD dwState = 0;
+ DWORD dwTick = 0;
+ DWORD dwWait, dwCheck, dwStart;
+ BOOL bStatus;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServixeOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ switch (dwControl) {
+ case SERVICE_CONTROL_CONTINUE:
+ dwPending = SERVICE_START_PENDING;
+ dwState = SERVICE_RUNNING;
+ break;
+ case SERVICE_CONTROL_STOP:
+ dwPending = SERVICE_STOP_PENDING;
+ dwState = SERVICE_STOPPED;
+ break;
+ case SERVICE_CONTROL_PAUSE:
+ dwPending = SERVICE_PAUSE_PENDING;
+ dwState = SERVICE_PAUSED;
+ break;
+ default:
+ break;
+ }
+ /* user defined controls */
+ if (dwControl > 127 && dwControl < 224) {
+ /* 128 ... 159 start signals
+ * 160 ... 191 stop signals
+ * 192 ... 223 pause signals
+ */
+ switch (dwControl & 0xE0) {
+ case 0x80:
+ case 0x90:
+ dwPending = SERVICE_START_PENDING;
+ dwState = SERVICE_RUNNING;
+ break;
+ case 0xA0:
+ case 0xB0:
+ dwPending = SERVICE_STOP_PENDING;
+ dwState = SERVICE_STOPPED;
+ break;
+ case 0xC0:
+ case 0xD0:
+ dwPending = SERVICE_PAUSE_PENDING;
+ dwState = SERVICE_PAUSED;
+ break;
+ default:
+ break;
+ }
+ }
+ if (!dwPending && !dwState)
+ return FALSE;
+ /* Now lets control */
+ if (!QueryServiceStatus(lpService->hService, &stStatus)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+ return FALSE;
+ }
+ /* signal that we are about to control the service */
+ if (fnControlCallback)
+ (*fnControlCallback)(lpCbData, uMsg, (WPARAM)1, (LPARAM)dwState);
+ if (dwControl == SERVICE_CONTROL_CONTINUE &&
+ stStatus.dwCurrentState != SERVICE_PAUSED)
+ bStatus = StartService(lpService->hService, 0, NULL);
+ else
+ bStatus = ControlService(lpService->hService, dwControl, &stStatus);
+ dwStart = GetTickCount();
+ dwCheck = stStatus.dwCheckPoint;
+ if (bStatus) {
+ Sleep(100); /* Initial Sleep period */
+ while (QueryServiceStatus(lpService->hService, &stStatus)) {
+ if (stStatus.dwCurrentState == dwPending) {
+ /* Do not wait longer than the wait hint. A good interval is
+ * one tenth the wait hint, but no less than 1 second and no
+ * more than 10 seconds.
+ */
+ dwWait = stStatus.dwWaitHint / 10;
+
+ if( dwWait < 1000 )
+ dwWait = 1000;
+ else if ( dwWait > 10000 )
+ dwWait = 10000;
+ /* Signal to the callback that we are pending
+ * break if callback returns false.
+ */
+ if (fnControlCallback) {
+ if (!(*fnControlCallback)(lpCbData, uMsg, (WPARAM)2,
+ (LPARAM)dwTick++))
+ break;
+ }
+ Sleep(dwWait);
+ if (stStatus.dwCheckPoint > dwCheck) {
+ /* The service is making progress. */
+ dwStart = GetTickCount();
+ dwCheck = stStatus.dwCheckPoint;
+ }
+ else {
+ if(GetTickCount() - dwStart > stStatus.dwWaitHint) {
+ /* No progress made within the wait hint */
+ break;
+ }
+ }
+ }
+ else
+ break;
+ }
+ }
+ /* signal that we are done with controling the service */
+ if (fnControlCallback)
+ (*fnControlCallback)(lpCbData, uMsg, (WPARAM)3, (LPARAM)0);
+ /* Check if we are in the desired state */
+ Sleep(1000);
+
+ if (QueryServiceStatus(lpService->hService, &stStatus)) {
+ if (fnControlCallback)
+ (*fnControlCallback)(lpCbData, uMsg, (WPARAM)4,
+ (LPARAM)&stStatus);
+ if (stStatus.dwCurrentState == dwState)
+ return TRUE;
+
+ }
+
+ return FALSE;
+}
+
+BOOL
+apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
+ LPCWSTR szDisplayName, LPCWSTR szImagePath,
+ LPCWSTR lpDependencies, DWORD dwServiceType,
+ DWORD dwStartType)
+{
+ LPAPXSERVICE lpService;
+
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ if (IS_INVALID_HANDLE(lpService->hManager))
+ return FALSE;
+ if (!__apxIsValidServiceName(szServiceName))
+ return FALSE;
+ /* Close any previous instance
+ * Same handle can install multiple services
+ */
+ SAFE_CLOSE_SCH(lpService->hService);
+
+ apxFree(lpService->stServiceEntry.lpConfig);
+ lpService->stServiceEntry.lpConfig = NULL;
+ AplZeroMemory(&lpService->stServiceEntry, sizeof(APXSERVENTRY));
+
+ lpService->hService = CreateServiceW(lpService->hManager,
+ szServiceName,
+ szDisplayName,
+ SERVICE_ALL_ACCESS,
+ dwServiceType,
+ dwStartType,
+ SERVICE_ERROR_NORMAL,
+ szImagePath,
+ NULL,
+ NULL,
+ lpDependencies,
+ NULL,
+ NULL);
+
+ if (IS_INVALID_HANDLE(lpService->hService)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+
+ ErrorMessage(NULL, FALSE);
+ return FALSE;
+ }
+ else {
+ lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
+ lpService->stServiceEntry.dwStart = dwStartType;
+ return TRUE;
+ }
+}
+
+BOOL
+apxServiceDelete(APXHANDLE hService)
+{
+ LPAPXSERVICE lpService;
+ SERVICE_STATUS stStatus;
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+ return FALSE;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Manager mode cannot handle services */
+ if (lpService->bManagerMode)
+ return FALSE;
+ /* Check if the ServiceOpen has been called */
+ if (IS_INVALID_HANDLE(lpService->hService))
+ return FALSE;
+ if (QueryServiceStatus(lpService->hService, &stStatus)) {
+ BOOL rv;
+ if (stStatus.dwCurrentState != SERVICE_STOPPED)
+ apxServiceControl(hService, SERVICE_CONTROL_STOP, 0, NULL, NULL);
+ rv = DeleteService(lpService->hService);
+ SAFE_CLOSE_SCH(lpService->hService);
+ SAFE_CLOSE_SCH(lpService->hManager);
+
+ return rv;
+ }
+ return FALSE;
+}
+
+/* Browse the services */
+DWORD
+apxServiceBrowse(APXHANDLE hService,
+ LPCWSTR szIncludeNamePattern,
+ LPCWSTR szIncludeImagePattern,
+ LPCWSTR szExcludeNamePattern,
+ LPCWSTR szExcludeImagePattern,
+ UINT uMsg,
+ LPAPXFNCALLBACK fnDisplayCallback,
+ LPVOID lpCbData)
+{
+ DWORD nFound = 0;
+ APXREGENUM stEnum;
+ LPAPXSERVICE lpService;
+ SC_LOCK hLock;
+ if (hService->dwType != APXHANDLE_TYPE_SERVICE || !fnDisplayCallback)
+ return 0;
+
+ lpService = APXHANDLE_DATA(hService);
+ /* Only the manager mode can browse services */
+ if (!lpService->bManagerMode ||
+ IS_INVALID_HANDLE(lpService->hManager))
+ return 0;
+ hLock = LockServiceDatabase(lpService->hManager);
+ if (IS_INVALID_HANDLE(hLock)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
+
+ ErrorMessage(NULL, FALSE);
+ return 0;
+ }
+ AplZeroMemory(&stEnum, sizeof(APXREGENUM));
+
+ while (TRUE) {
+ APXSERVENTRY stEntry;
+ BOOL rv;
+ AplZeroMemory(&stEntry, sizeof(APXSERVENTRY));
+ rv = apxRegistryEnumServices(&stEnum, &stEntry);
+
+ if (rv) {
+ INT fm = -1;
+ SC_HANDLE hSrv = NULL;
+ DWORD dwNeeded = 0;
+ hSrv = OpenServiceW(lpService->hManager,
+ stEntry.szServiceName,
+ GENERIC_READ);
+ if (!IS_INVALID_HANDLE(hSrv)) {
+ QueryServiceConfigW(hSrv, NULL, 0, &dwNeeded);
+ stEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+ dwNeeded);
+ /* Call the QueryServiceConfig againg with allocated config */
+ if (QueryServiceConfigW(hSrv, stEntry.lpConfig, dwNeeded, &dwNeeded)) {
+ /* Make that customizable so that kernel mode drivers can be
+ * displayed and maintained. For now skip the
+ * filesystem and device drivers.
+ * XXX: Do we need that customizable after all?
+ */
+ if ((stEntry.lpConfig->dwServiceType &
+ ~SERVICE_INTERACTIVE_PROCESS) & SERVICE_WIN32)
+ fm = 0;
+
+ if (!fm && szIncludeNamePattern) {
+ fm = apxMultiStrMatchW(stEntry.szServiceName,
+ szIncludeNamePattern, L';', TRUE);
+ }
+ if (!fm && szExcludeNamePattern) {
+ fm = !apxMultiStrMatchW(stEntry.szServiceName,
+ szExcludeNamePattern, L';', TRUE);
+ }
+ if (!fm && szIncludeImagePattern) {
+ fm = apxMultiStrMatchW(stEntry.lpConfig->lpBinaryPathName,
+ szIncludeImagePattern, L';', TRUE);
+ }
+ if (!fm && szExcludeImagePattern) {
+ fm = !apxMultiStrMatchW(stEntry.szServiceName,
+ szExcludeImagePattern, L';', TRUE);
+ }
+ if (!fm) {
+ QueryServiceStatus(hSrv, &(stEntry.stServiceStatus));
+ /* WIN2K + extended service info */
+ if (_st_apx_oslevel >= 4) {
+ DWORD dwNeed;
+ QueryServiceStatusEx(hSrv, SC_STATUS_PROCESS_INFO,
+ (LPBYTE)(&(stEntry.stStatusProcess)),
+ sizeof(SERVICE_STATUS_PROCESS),
+ &dwNeed);
+ }
+ /* finaly call the provided callback */
+ rv = (*fnDisplayCallback)(lpCbData, uMsg,
+ (WPARAM)&stEntry,
+ (LPARAM)nFound++);
+ }
+ }
+ /* release the skipped service config */
+ if (fm) {
+ apxFree(stEntry.lpConfig);
+ }
+ }
+ SAFE_CLOSE_SCH(hSrv);
+ }
+ if (!rv)
+ break;
+ }
+
+ UnlockServiceDatabase(hLock);
+ return nFound;
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/service.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/utils/windows/native/service/procrun/src/utils.c
===================================================================
--- trunk/utils/windows/native/service/procrun/src/utils.c (rev 0)
+++ trunk/utils/windows/native/service/procrun/src/utils.c 2008-02-19 20:18:46 UTC (rev 1384)
@@ -0,0 +1,1037 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+APX_OSLEVEL _st_apx_oslevel = APX_WINVER_UNK;
+
+/* Apache's APR stripped Os level detection */
+APX_OSLEVEL apxGetOsLevel()
+{
+ if (_st_apx_oslevel == APX_WINVER_UNK) {
+ static OSVERSIONINFO oslev;
+ oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&oslev);
+
+ if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+ if (oslev.dwMajorVersion < 4)
+ _st_apx_oslevel = APX_WINVER_UNSUP;
+ else if (oslev.dwMajorVersion == 4)
+ _st_apx_oslevel = APX_WINVER_NT_4;
+ else if (oslev.dwMajorVersion == 5) {
+ if (oslev.dwMinorVersion == 0)
+ _st_apx_oslevel = APX_WINVER_2000;
+ else
+ _st_apx_oslevel = APX_WINVER_XP;
+ }
+ else
+ _st_apx_oslevel = APX_WINVER_XP;
+ }
+#ifndef WINNT
+ else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+ if (oslev.dwMinorVersion < 10)
+ _st_apx_oslevel = APX_WINVER_95;
+ else if (oslev.dwMinorVersion < 90)
+ _st_apx_oslevel = APX_WINVER_98;
+ else
+ _st_apx_oslevel = APX_WINVER_ME;
+ }
+#endif
+#ifdef _WIN32_WCE
+ else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE) {
+ if (oslev.dwMajorVersion < 3)
+ _st_apx_oslevel = APX_WINVER_UNSUP;
+ else
+ _st_apx_oslevel = APX_WINVER_CE_3;
+ }
+#endif
+ else
+ _st_apx_oslevel = APX_WINVER_UNSUP;
+ }
+
+ if (_st_apx_oslevel < APX_WINVER_UNSUP)
+ return APX_WINVER_UNK;
+ else
+ return _st_apx_oslevel;
+}
+
+LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName)
+{
+ LPWSTR wsRet;
+ DWORD rc;
+
+ rc = GetEnvironmentVariableW(wsName, NULL, 0);
+ if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+ return NULL;
+
+ if (!(wsRet = apxPoolAlloc(hPool, (rc + 1) * sizeof(WCHAR))))
+ return NULL;
+ if (!GetEnvironmentVariableW(wsName, wsRet, rc)) {
+ apxFree(wsRet);
+ ErrorMessage(NULL, FALSE);
+ return NULL;
+ }
+ return wsRet;
+}
+
+LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName)
+{
+ LPSTR szRet;
+ DWORD rc;
+
+ rc = GetEnvironmentVariableA(szName, NULL, 0);
+ if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+ return NULL;
+
+ if (!(szRet = apxPoolAlloc(hPool, rc + 1)))
+ return NULL;
+ if (!GetEnvironmentVariableA(szName, szRet, rc)) {
+ apxFree(szRet);
+ ErrorMessage(NULL, FALSE);
+ return NULL;
+ }
+ return szRet;
+}
+
+
+LPWSTR AsciiToWide(LPCSTR s, LPWSTR ws)
+{
+ LPWSTR pszSave = ws;
+
+ if (!s) {
+ *ws = L'\0';
+ return pszSave;
+ }
+ do {
+ *ws++ = (WCHAR)*s;
+ } while (*s++);
+ return pszSave;
+}
+
+LPSTR WideToAscii(LPCWSTR ws, LPSTR s)
+{
+ LPSTR pszSave = s;
+
+ if (!ws) {
+ *s = '\0';
+ return pszSave;
+ }
+ do {
+ *s++ = (CHAR)*ws;
+ } while( *ws++);
+ return pszSave;
+}
+
+LPSTR WideToUTF8(LPCWSTR ws)
+{
+
+ LPSTR s;
+ int cch = WideCharToMultiByte(CP_UTF8, 0, ws, -1, NULL, 0, NULL, NULL);
+ s = (LPSTR)apxAlloc(cch);
+ if (!WideCharToMultiByte(CP_UTF8, 0, ws, -1, s, cch, NULL, NULL)) {
+ apxFree(s);
+ return NULL;
+ }
+ return s;
+}
+
+LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s)
+{
+ LPSTR pszSave = s;
+
+ if (ws) {
+ do {
+ *s++ = (CHAR)*ws;
+ ws++;
+ } while( *ws || *(ws + 1));
+ }
+ /* double terminate */
+ *s++ = '\0';
+ *s = '\0';
+ return pszSave;
+}
+
+LPSTR MzWideToUTF8(LPCWSTR ws)
+{
+ LPSTR str;
+ LPSTR s;
+ LPCWSTR p = ws;
+ int cch = 0;
+
+ for ( ; p && *p; p++) {
+ int len = WideCharToMultiByte(CP_UTF8, 0, p, -1, NULL, 0, NULL, NULL);
+ if (len > 0)
+ cch += len;
+ while (*p)
+ p++;
+ }
+ cch ++;
+ str = s = (LPSTR)apxAlloc(cch + 1);
+
+ p = ws;
+ for ( ; p && *p; p++) {
+ int len = WideCharToMultiByte(CP_UTF8, 0, p, -1, s, cch, NULL, NULL);
+ if (len > 0) {
+ s = s + len;
+ cch -= len;
+ }
+ while (*p)
+ p++;
+ }
+ /* double terminate */
+ *s = '\0';
+ return str;
+}
+
+#ifdef _DEBUG
+
+void ErrorMessage(LPCTSTR szError, BOOL bFatal)
+{
+ LPVOID lpMsgBuf = NULL;
+ UINT nType;
+ int nRet;
+ DWORD dwErr = GetLastError();
+ if (bFatal)
+ nType = MB_ICONERROR | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL;
+ else
+ nType = MB_ICONEXCLAMATION | MB_OK;
+ if (szError) {
+ nRet = MessageBox(NULL, szError, TEXT("Application Error"), nType);
+ }
+ else {
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwErr,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
+ (LPTSTR) &lpMsgBuf, 0, NULL);
+ nRet = MessageBox(NULL, (LPCTSTR)lpMsgBuf,
+ TEXT("Application System Error"), nType);
+ LocalFree(lpMsgBuf);
+ }
+ if (bFatal && (nRet == IDCANCEL || nRet == IDABORT)) {
+ ExitProcess(dwErr);
+ }
+}
+#endif /* _DEBUG */
+
+DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount)
+{
+ LPCSTR p = lpStr;
+ if (lpdwCount)
+ *lpdwCount = 0;
+ for ( ; p && *p; p++) {
+ if (lpdwCount)
+ *lpdwCount += 1;
+ while (*p)
+ p++;
+ }
+ return (DWORD)(p - lpStr);
+}
+
+DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount)
+{
+ LPCWSTR p = lpStr;
+ if (lpdwCount)
+ *lpdwCount = 0;
+ for ( ; p && *p; p++) {
+ if (lpdwCount)
+ *lpdwCount += 1;
+ while (*p)
+ p++;
+ }
+ return (DWORD)((p - lpStr));
+}
+
+LPWSTR apxMultiSzCombine(APXHANDLE hPool, LPCWSTR lpStrA, LPCWSTR lpStrB,
+ LPDWORD lpdwLength)
+{
+ LPWSTR rv;
+ DWORD la = 0, lb = 0;
+ if (!lpStrA && !lpStrB)
+ return NULL; /* Nothing to do if both are NULL */
+
+ la = __apxGetMultiSzLengthW(lpStrA, NULL);
+ lb = __apxGetMultiSzLengthW(lpStrB, NULL);
+
+ rv = apxPoolCalloc(hPool, (la + lb + 1) * sizeof(WCHAR));
+ if (la) {
+ AplMoveMemory(rv, lpStrA, la * sizeof(WCHAR));
+ }
+ if (lb) {
+ AplMoveMemory(&rv[la], lpStrB, lb * sizeof(WCHAR));
+ }
+ if (*lpdwLength)
+ *lpdwLength = (la + lb + 1) * sizeof(WCHAR);
+ return rv;
+}
+
+BOOL
+apxSetEnvironmentVariable(APXHANDLE hPool, LPCTSTR szName, LPCTSTR szValue,
+ BOOL bAppend)
+{
+ LPTSTR szNew = (LPTSTR)szValue;
+
+ if (bAppend) {
+ DWORD l = GetEnvironmentVariable(szName, NULL, 0);
+ if (l > 0) {
+ BOOL rv;
+ if (IS_INVALID_HANDLE(hPool))
+ szNew = apxAlloc(l + lstrlen(szValue) + 3);
+ else
+ szNew = apxPoolAlloc(hPool, l + lstrlen(szValue) + 3);
+ GetEnvironmentVariable(szName, szNew, l + 1);
+ lstrcat(szNew, TEXT(";"));
+ lstrcat(szNew, szValue);
+ rv = SetEnvironmentVariable(szName, szNew);
+ apxFree(szNew);
+ return rv;
+ }
+ }
+ return SetEnvironmentVariable(szName, szNew);
+}
+
+
+/** Convert null separated double null terimated string to LPTSTR array)
+ * returns array size
+ */
+DWORD
+apxMultiSzToArrayW(APXHANDLE hPool, LPCWSTR lpString, LPWSTR **lppArray)
+{
+ DWORD i, n, l;
+ char *buff;
+ LPWSTR p;
+
+ l = __apxGetMultiSzLengthW(lpString, &n);
+ if (!n || !l)
+ return 0;
+ if (IS_INVALID_HANDLE(hPool))
+ buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
+ else
+ buff = apxAlloc((n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
+
+ *lppArray = (LPWSTR *)buff;
+ p = (LPWSTR)(buff + (n + 2) * sizeof(LPWSTR));
+ AplCopyMemory(p, lpString, (l + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+ for (i = 0; i < n; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ (*lppArray)[++i] = NULL;
+
+ return n;
+}
+
+DWORD
+apxMultiSzToArrayA(APXHANDLE hPool, LPCSTR lpString, LPSTR **lppArray)
+{
+ DWORD i, n, l;
+ char *buff;
+ LPSTR p;
+
+ l = __apxGetMultiSzLengthA(lpString, &n);
+ if (!n || !l)
+ return 0;
+ if (IS_INVALID_HANDLE(hPool))
+ buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPTSTR) + (l + 1));
+ else
+ buff = apxAlloc((n + 2) * sizeof(LPSTR) + (l + 1) * sizeof(CHAR));
+
+ *lppArray = (LPSTR *)buff;
+ p = (LPSTR)(buff + (n + 2) * sizeof(LPSTR));
+ AplCopyMemory(p, lpString, (l + 1) * sizeof(CHAR) + sizeof(CHAR));
+ for (i = 0; i < n; i++) {
+ (*lppArray)[i] = p;
+ while (*p)
+ p++;
+ p++;
+ }
+ (*lppArray)[++i] = NULL;
+
+ return n;
+}
+
+#define QSTR_BOUNDARY 127
+#define QSTR_ALIGN(size) \
+ (((size) + QSTR_BOUNDARY + sizeof(APXMULTISZ) + 2) & ~(QSTR_BOUNDARY))
+
+#define QSTR_SIZE(size) \
+ ((QSTR_ALIGN(size)) - sizeof(APXMULTISZ))
+
+#define QSTR_DATA(q) ((char *)(q) + sizeof(APXMULTISZ))
+
+#if 0
+LPAPXMULTISZ apxMultiSzStrdup(LPCTSTR szSrc)
+{
+ LPAPXMULTISZ q;
+
+ if (szSrc) {
+ DWORD l = lstrlen(szSrc);
+ q = (LPAPXMULTISZ)apxAlloc(QSTR_ALIGN(l));
+ q->dwAllocated = QSTR_SIZE(l);
+ q->dwInsert = l + 1;
+ AplMoveMemory(QSTR_DATA(q), szSrc, l);
+ RtlZeroMemory(QSTR_DATA(q) + l, q->dwAllocated - l);
+ }
+ else {
+ q = (LPAPXMULTISZ)apxCalloc(QSTR_ALIGN(0));
+ q->dwAllocated = QSTR_SIZE(0);
+ }
+
+ return q;
+}
+
+LPTSTR apxMultiSzStrcat(LPAPXMULTISZ lpmSz, LPCTSTR szSrc)
+{
+ DWORD l = lstrlen(szSrc);
+ LPTSTR p;
+
+ if (lpmSz->dwInsert + l + 2 > lpmSz->dwAllocated) {
+ if ((lpmSz = (LPAPXMULTISZ )apxRealloc(lpmSz, QSTR_ALIGN(lpmSz->dwInsert + l))) == NULL)
+ return NULL;
+
+ lpmSz->dwAllocated = QSTR_SIZE(lpmSz->dwInsert + l);
+ AplZeroMemory(QSTR_DATA(lpmSz) + lpmSz->dwInsert + l,
+ lpmSz->dwAllocated - (lpmSz->dwInsert + l));
+ }
+ p = (LPTSTR)QSTR_DATA(lpmSz) + lpmSz->dwInsert;
+ AplMoveMemory(p, szSrc, l);
+
+ lpmSz->dwInsert += (l + 1);
+ return p;
+}
+
+DWORD apxMultiSzLen(LPAPXMULTISZ lpmSz)
+{
+ if (lpmSz->dwInsert)
+ return lpmSz->dwInsert - 1;
+ else
+ return 0;
+}
+
+LPCTSTR apxMultiSzGet(LPAPXMULTISZ lpmSz)
+{
+ return (LPCTSTR)QSTR_DATA(lpmSz);
+}
+#endif
+
+LPTSTR apxStrCharRemove(LPTSTR szString, TCHAR chSkip)
+{
+ LPTSTR p = szString;
+ LPTSTR q = szString;
+ while (*p) {
+ if(*p != chSkip)
+ *q++ = *p;
+ ++p;
+ }
+ *q = TEXT('\0');
+
+ return szString;
+}
+
+DWORD apxStrCharRemoveA(LPSTR szString, CHAR chSkip)
+{
+ LPSTR p = szString;
+ LPSTR q = szString;
+ DWORD c = 0;
+ while (*p) {
+ if(*p != chSkip)
+ *q++ = *p;
+ else
+ ++c;
+ ++p;
+ }
+ *q = '\0';
+
+ return c;
+}
+
+DWORD apxStrCharRemoveW(LPWSTR szString, WCHAR chSkip)
+{
+ LPWSTR p = szString;
+ LPWSTR q = szString;
+ DWORD c = 0;
+ while (*p) {
+ if(*p != chSkip)
+ *q++ = *p;
+ else
+ ++c;
+ ++p;
+ }
+ *q = L'\0';
+
+ return c;
+}
+
+void
+apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith)
+{
+ LPSTR p = szString;
+ LPSTR q = szString;
+ while (*p) {
+ if(*p == chReplace)
+ *q++ = chReplaceWith;
+ else
+ *q++ = *p;
+ ++p;
+ }
+ *q = '\0';
+}
+
+void
+apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith)
+{
+ LPWSTR p = szString;
+ LPWSTR q = szString;
+ while (*p) {
+ if(*p == chReplace)
+ *q++ = chReplaceWith;
+ else
+ *q++ = *p;
+ ++p;
+ }
+ *q = L'\0';
+}
+
+static const LPCTSTR _st_hex = TEXT("0123456789abcdef");
+#define XTOABUFFER_SIZE (sizeof(ULONG) * 2 + 2)
+#define UTOABUFFER_SIZE (sizeof(ULONG_PTR) * 2 + 2)
+#define LO_NIBLE(x) ((BYTE)((x) & 0x0000000F))
+
+BOOL apxUltohex(ULONG n, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+ LPTSTR p;
+ DWORD i;
+ *lpBuff = 0;
+ if (dwBuffLength < XTOABUFFER_SIZE)
+ return FALSE;
+ p = lpBuff + XTOABUFFER_SIZE;
+ *p-- = 0;
+ for (i = 0; i < sizeof(ULONG) * 2; i++) {
+ *p-- = _st_hex[LO_NIBLE(n)];
+ n = n >> 4;
+ }
+ *p-- = TEXT('x');
+ *p = TEXT('0');
+ return TRUE;
+}
+
+BOOL apxUptohex(ULONG_PTR n, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+ LPTSTR p;
+ DWORD i;
+ *lpBuff = 0;
+ if (dwBuffLength < UTOABUFFER_SIZE)
+ return FALSE;
+ p = lpBuff + UTOABUFFER_SIZE;
+ *p-- = 0;
+ for (i = 0; i < sizeof(ULONG_PTR) * 2; i++) {
+ *p-- = _st_hex[LO_NIBLE(n)];
+ n = n >> 4;
+ }
+ *p-- = TEXT('x');
+ *p = TEXT('0');
+ return TRUE;
+}
+
+ULONG apxStrToul(LPCTSTR szNum)
+{
+ ULONG rv = 0;
+ DWORD sh = 0;
+ LPCTSTR p = szNum;
+ ++p;
+ while (*p && (*p != TEXT('x')) && (*(p - 1) != TEXT('0')))
+ p++;
+ if (*p != 'x')
+ return 0;
+ /* go to the last digit */
+ while (*(p + 1)) p++;
+
+ /* go back to 'x' */
+ while (*p != TEXT('x')) {
+ ULONG v = 0;
+ switch (*p--) {
+ case TEXT('0'): v = 0UL; break;
+ case TEXT('1'): v = 1UL; break;
+ case TEXT('2'): v = 2UL; break;
+ case TEXT('3'): v = 3UL; break;
+ case TEXT('4'): v = 4UL; break;
+ case TEXT('5'): v = 5UL; break;
+ case TEXT('6'): v = 6UL; break;
+ case TEXT('7'): v = 7UL; break;
+ case TEXT('8'): v = 8UL; break;
+ case TEXT('9'): v = 9UL; break;
+ case TEXT('a'): case TEXT('A'): v = 10UL; break;
+ case TEXT('b'): case TEXT('B'): v = 11UL; break;
+ case TEXT('c'): case TEXT('C'): v = 12UL; break;
+ case TEXT('d'): case TEXT('D'): v = 13UL; break;
+ case TEXT('e'): case TEXT('E'): v = 14UL; break;
+ case TEXT('f'): case TEXT('F'): v = 15UL; break;
+ default:
+ return 0;
+ break;
+ }
+ rv |= rv + (v << sh);
+ sh += 4;
+ }
+ return rv;
+}
+
+ULONG apxStrToulW(LPCWSTR szNum)
+{
+ ULONG rv = 0;
+ DWORD sh = 0;
+ LPCWSTR p = szNum;
+ ++p;
+ while (*p && (*p != L'x') && (*(p - 1) != L'0'))
+ p++;
+ if (*p != L'x')
+ return 0;
+ /* go to the last digit */
+ while (*(p + 1)) p++;
+
+ /* go back to 'x' */
+ while (*p != L'x') {
+ ULONG v = 0;
+ switch (*p--) {
+ case L'0': v = 0UL; break;
+ case L'1': v = 1UL; break;
+ case L'2': v = 2UL; break;
+ case L'3': v = 3UL; break;
+ case L'4': v = 4UL; break;
+ case L'5': v = 5UL; break;
+ case L'6': v = 6UL; break;
+ case L'7': v = 7UL; break;
+ case L'8': v = 8UL; break;
+ case L'9': v = 9UL; break;
+ case L'a': case L'A': v = 10UL; break;
+ case L'b': case L'B': v = 11UL; break;
+ case L'c': case L'C': v = 12UL; break;
+ case L'd': case L'D': v = 13UL; break;
+ case L'e': case L'E': v = 14UL; break;
+ case L'f': case L'F': v = 15UL; break;
+ default:
+ return 0;
+ break;
+ }
+ rv |= rv + (v << sh);
+ sh += 4;
+ }
+ return rv;
+}
+
+ULONG apxAtoulW(LPCWSTR szNum)
+{
+ ULONG rv = 0;
+ DWORD sh = 1;
+ int s = 1;
+ LPCWSTR p = szNum;
+
+ /* go to the last digit */
+ if (!p || !*p)
+ return 0;
+ if (*p == L'-') {
+ s = -1;
+ ++p;
+ }
+ while (*(p + 1)) p++;
+
+ /* go back */
+ while (p >= szNum) {
+ ULONG v = 0;
+ switch (*p--) {
+ case L'0': v = 0UL; break;
+ case L'1': v = 1UL; break;
+ case L'2': v = 2UL; break;
+ case L'3': v = 3UL; break;
+ case L'4': v = 4UL; break;
+ case L'5': v = 5UL; break;
+ case L'6': v = 6UL; break;
+ case L'7': v = 7UL; break;
+ case L'8': v = 8UL; break;
+ case L'9': v = 9UL; break;
+ default:
+ return rv * s;
+ break;
+ }
+ rv = rv + (v * sh);
+ sh = sh * 10;
+ }
+ return rv * s;
+}
+
+/* Make the unique system resource name from prefix and process id
+ *
+ */
+BOOL
+apxMakeResourceName(LPCTSTR szPrefix, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+ DWORD pl = lstrlen(szPrefix);
+ if (dwBuffLength < (pl + 11))
+ return FALSE;
+ lstrcpy(lpBuff, szPrefix);
+ return apxUltohex(GetCurrentProcessId(), lpBuff + pl, dwBuffLength - pl);
+}
+/** apxStrMatchA ANSI string pattern matching
+ * Match = 0, NoMatch = 1, Abort = -1
+ * Based loosely on sections of wildmat.c by Rich Salz
+ */
+INT apxStrMatchA(LPCSTR szString, LPCSTR szPattern, BOOL bIgnoreCase)
+{
+ int x, y;
+
+ for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
+ if (!szPattern[x] && (szPattern[y] != '*' || szPattern[y] != '?'))
+ return -1;
+ if (szPattern[y] == '*') {
+ while (szPattern[++y] == '*');
+ if (!szPattern[y])
+ return 0;
+ while (szString[x]) {
+ INT rc;
+ if ((rc = apxStrMatchA(&szString[x++], &szPattern[y],
+ bIgnoreCase)) != 1)
+ return rc;
+ }
+ return -1;
+ }
+ else if (szPattern[y] != '?') {
+ if (bIgnoreCase) {
+ if (CharLowerA((LPSTR)((SIZE_T)szString[x])) !=
+ CharLowerA((LPSTR)((SIZE_T)szPattern[y])))
+ return 1;
+ }
+ else {
+ if (szString[x] != szPattern[y])
+ return 1;
+ }
+ }
+ }
+ return (szString[x] != '\0');
+}
+
+INT apxStrMatchW(LPCWSTR szString, LPCWSTR szPattern, BOOL bIgnoreCase)
+{
+ int x, y;
+
+ for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
+ if (!szPattern[x] && (szPattern[y] != L'*' || szPattern[y] != L'?'))
+ return -1;
+ if (szPattern[y] == L'*') {
+ while (szPattern[++y] == L'*');
+ if (!szPattern[y])
+ return 0;
+ while (szString[x]) {
+ INT rc;
+ if ((rc = apxStrMatchW(&szString[x++], &szPattern[y],
+ bIgnoreCase)) != 1)
+ return rc;
+ }
+ return -1;
+ }
+ else if (szPattern[y] != L'?') {
+ if (bIgnoreCase) {
+ if (CharLowerW((LPWSTR)((SIZE_T)szString[x])) !=
+ CharLowerW((LPWSTR)((SIZE_T)szPattern[y])))
+ return 1;
+ }
+ else {
+ if (szString[x] != szPattern[y])
+ return 1;
+ }
+ }
+ }
+ return (szString[x] != L'\0');
+}
+
+INT apxMultiStrMatchW(LPCWSTR szString, LPCWSTR szPattern,
+ WCHAR chSeparator, BOOL bIgnoreCase)
+{
+ WCHAR szM[SIZ_HUGLEN];
+ DWORD i = 0;
+ LPCWSTR p = szPattern;
+ INT m = -1;
+
+ if (chSeparator == 0)
+ return apxStrMatchW(szString, szPattern, bIgnoreCase);
+ while (*p != L'\0') {
+ if (*p == chSeparator) {
+ m = apxStrMatchW(szString, szM, bIgnoreCase);
+ if (m == 0)
+ return 0;
+ p++;
+ i = 0;
+ szM[0] = L'\0';
+ }
+ else {
+ if (i < SIZ_HUGMAX)
+ szM[i++] = *p++;
+ else
+ return -1;
+ }
+ }
+ szM[i] = L'\0';
+ if (szM[0])
+ return apxStrMatchW(szString, szM, bIgnoreCase);
+ else
+ return m;
+}
+
+LPSTR apxArrayToMultiSzA(APXHANDLE hPool, DWORD nArgs, LPCSTR *lpArgs)
+{
+ DWORD i, l = 0;
+ LPSTR lpSz, p;
+ if (!nArgs)
+ return NULL;
+ for (i = 0; i < nArgs; i++)
+ l += lstrlenA(lpArgs[i]);
+ l += (nArgs + 2);
+
+ p = lpSz = (LPSTR)apxPoolAlloc(hPool, l);
+ for (i = 0; i < nArgs; i++) {
+ lstrcpyA(p, lpArgs[i]);
+ p += lstrlenA(lpArgs[i]);
+ *p++ = '\0';
+ }
+ *p++ = '\0';
+ *p++ = '\0';
+ return lpSz;
+}
+
+void apxStrQuoteInplaceW(LPWSTR szString)
+{
+ LPWSTR p = szString;
+ BOOL needsQuote = FALSE;
+ while (*p) {
+ if (*p++ == L' ') {
+ needsQuote = TRUE;
+ break;
+ }
+ }
+ if (needsQuote) {
+ DWORD l = lstrlenW(szString);
+ AplMoveMemory(&szString[1], szString, l * sizeof(WCHAR));
+ szString[0] = L'"';
+ szString[++l] = L'"';
+ szString[++l] = L'\0';
+ }
+}
+
+DWORD apxStrUnQuoteInplaceA(LPSTR szString)
+{
+ LPSTR p = szString;
+ BOOL needsQuote = FALSE;
+ BOOL inQuote = FALSE;
+ while (*p) {
+ if (*p == '"') {
+ if (inQuote)
+ break;
+ else
+ inQuote = TRUE;
+ }
+ else if (*p == ' ') {
+ if (inQuote) {
+ needsQuote = TRUE;
+ break;
+ }
+ }
+ ++p;
+ }
+ if (!needsQuote)
+ return apxStrCharRemoveA(szString, '"');
+ else
+ return 0;
+}
+
+DWORD apxStrUnQuoteInplaceW(LPWSTR szString)
+{
+ LPWSTR p = szString;
+ BOOL needsQuote = FALSE;
+ BOOL inQuote = FALSE;
+ while (*p) {
+ if (*p == L'"') {
+ if (inQuote)
+ break;
+ else
+ inQuote = TRUE;
+ }
+ else if (*p == L' ') {
+ if (inQuote) {
+ needsQuote = TRUE;
+ break;
+ }
+ }
+ ++p;
+ }
+ if (!needsQuote)
+ return apxStrCharRemoveW(szString, L'"');
+ else
+ return 0;
+}
+
+LPWSTR
+apxMszToCRLFW(APXHANDLE hPool, LPCWSTR szStr)
+{
+ DWORD l, c;
+ LPWSTR rv, b;
+ LPCWSTR p = szStr;
+
+ l = __apxGetMultiSzLengthW(szStr, &c);
+ b = rv = apxPoolCalloc(hPool, (l + c + 2) * sizeof(WCHAR));
+
+ while (c > 0) {
+ if (*p)
+ *b++ = *p;
+ else {
+ *b++ = L'\r';
+ *b++ = L'\n';
+ c--;
+ }
+ p++;
+ }
+ return rv;
+}
+
+LPWSTR
+apxCRLFToMszW(APXHANDLE hPool, LPCWSTR szStr, LPDWORD lpdwBytes)
+{
+ DWORD l, c, n = 0;
+ LPWSTR rv, b;
+
+ l = lstrlenW(szStr);
+ b = rv = apxPoolCalloc(hPool, (l + 2) * sizeof(WCHAR));
+ for (c = 0; c < l; c++) {
+ if (szStr[c] == L'\r') {
+ *b++ = '\0';
+ n++;
+ }
+ else if (szStr[c] != L'\n') {
+ *b++ = szStr[c];
+ n++;
+ }
+ }
+ if (lpdwBytes)
+ *lpdwBytes = (n + 2) * sizeof(WCHAR);
+ return rv;
+}
+
+LPSTR
+apxExpandStrA(APXHANDLE hPool, LPCSTR szString)
+{
+ LPCSTR p = szString;
+ while (*p) {
+ if (*p == '%') {
+ p = szString;
+ break;
+ }
+ ++p;
+ }
+ if (p != szString)
+ return apxPoolStrdupA(hPool, szString);
+ else {
+ DWORD l = ExpandEnvironmentStringsA(szString, NULL, 0);
+ if (l) {
+ LPSTR rv = apxPoolAlloc(hPool, l);
+ l = ExpandEnvironmentStringsA(szString, rv, l);
+ if (l)
+ return rv;
+ else {
+ apxFree(rv);
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+ }
+}
+
+LPWSTR
+apxExpandStrW(APXHANDLE hPool, LPCWSTR szString)
+{
+ LPCWSTR p = szString;
+ while (*p) {
+ if (*p == L'%') {
+ p = szString;
+ break;
+ }
+ ++p;
+ }
+ if (p != szString)
+ return apxPoolStrdupW(hPool, szString);
+ else {
+ DWORD l = ExpandEnvironmentStringsW(szString, NULL, 0);
+ if (l) {
+ LPWSTR rv = apxPoolAlloc(hPool, l * sizeof(WCHAR));
+ l = ExpandEnvironmentStringsW(szString, rv, l);
+ if (l)
+ return rv;
+ else {
+ apxFree(rv);
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+ }
+}
+
+/* To share the semaphores with other processes, we need a NULL ACL
+ * Code from MS KB Q106387
+ */
+PSECURITY_ATTRIBUTES GetNullACL()
+{
+ PSECURITY_DESCRIPTOR pSD;
+ PSECURITY_ATTRIBUTES sa;
+
+ sa = (PSECURITY_ATTRIBUTES) LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES));
+ sa->nLength = sizeof(sizeof(SECURITY_ATTRIBUTES));
+
+ pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
+ sa->lpSecurityDescriptor = pSD;
+
+ if (pSD == NULL || sa == NULL) {
+ return NULL;
+ }
+ SetLastError(0);
+ if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
+ || GetLastError()) {
+ LocalFree( pSD );
+ LocalFree( sa );
+ return NULL;
+ }
+ if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)
+ || GetLastError()) {
+ LocalFree( pSD );
+ LocalFree( sa );
+ return NULL;
+ }
+
+ sa->bInheritHandle = FALSE;
+ return sa;
+}
+
+
+void CleanNullACL(void *sa)
+{
+ if (sa) {
+ LocalFree(((PSECURITY_ATTRIBUTES)sa)->lpSecurityDescriptor);
+ LocalFree(sa);
+ }
+}
Property changes on: trunk/utils/windows/native/service/procrun/src/utils.c
___________________________________________________________________
Name: svn:eol-style
+ native
16 years, 10 months
JBoss Native SVN: r1383 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2008-02-07 02:49:22 -0500 (Thu, 07 Feb 2008)
New Revision: 1383
Modified:
trunk/build/unix/build.sh
Log:
Use EULA file from licenses directory
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2008-02-06 16:42:48 UTC (rev 1382)
+++ trunk/build/unix/build.sh 2008-02-07 07:49:22 UTC (rev 1383)
@@ -867,7 +867,7 @@
fi
# General part
- cp JBossORG-EULA.txt ${package_output_dir}
+ cp -rp licenses ${package_output_dir}
# Build the binary distribution tarball
buildtar ${package_output_dir} "*" ${dst_dir} ${package_build_name}
@@ -1014,7 +1014,6 @@
# Copy other files
cp ../NMAKEcommon.inc $package_src_dir
-cp ../../JBossORG-EULA.txt $package_src_dir
svn export --force ../../licenses $package_src_dir/licenses
if $has_apr; then
16 years, 11 months
JBoss Native SVN: r1382 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-02-06 11:42:48 -0500 (Wed, 06 Feb 2008)
New Revision: 1382
Modified:
trunk/build/unix/build.sh
Log:
It can't work without gnu patch.
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2008-02-06 13:53:19 UTC (rev 1381)
+++ trunk/build/unix/build.sh 2008-02-06 16:42:48 UTC (rev 1382)
@@ -168,8 +168,8 @@
# Check for some gnu mandadory tools.
patch=`util/find_gnu.sh patch`
if [ "x" = "x${patch}" ]; then
- patch=patch
- echo "Warning missing gnu patch command"
+ echo "Error missing gnu patch command"
+ exit 1
fi
export patch
16 years, 11 months
JBoss Native SVN: r1381 - trunk/build/unix/util.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-02-06 08:53:19 -0500 (Wed, 06 Feb 2008)
New Revision: 1381
Modified:
trunk/build/unix/util/confssl.sh
Log:
Make a "cleaner" test.
Modified: trunk/build/unix/util/confssl.sh
===================================================================
--- trunk/build/unix/util/confssl.sh 2008-02-06 13:19:35 UTC (rev 1380)
+++ trunk/build/unix/util/confssl.sh 2008-02-06 13:53:19 UTC (rev 1381)
@@ -40,7 +40,7 @@
cat <<EOF >> ${base}/${root}/opt/jboss/httpd/httpd/conf/httpd.conf
LoadModule jk_module /opt/jboss/httpd/lib/httpd/modules/mod_ssl.so
Listen ${IPLOCAL}:443
-<VirtualHost _default_:443>
+<VirtualHost ${IPLOCAL}:443>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /opt/jboss/httpd/httpd/conf/server.crt
16 years, 11 months
JBoss Native SVN: r1380 - trunk/httpd/httpd-2.2/modules/jk.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-02-06 08:19:35 -0500 (Wed, 06 Feb 2008)
New Revision: 1380
Modified:
trunk/httpd/httpd-2.2/modules/jk/configure.in
Log:
Add check for sys/filio.h
Modified: trunk/httpd/httpd-2.2/modules/jk/configure.in
===================================================================
--- trunk/httpd/httpd-2.2/modules/jk/configure.in 2008-02-06 12:36:07 UTC (rev 1379)
+++ trunk/httpd/httpd-2.2/modules/jk/configure.in 2008-02-06 13:19:35 UTC (rev 1380)
@@ -116,5 +116,8 @@
dnl check for flock function.
AC_CHECK_FUNC(flock, AC_DEFINE(HAVE_FLOCK,1,[Have flock()]))
+dnl check for filio.h used on Solaris to define FIONREAD ioctl.
+AC_CHECK_HEADERS(sys/filio.h)
+
AC_OUTPUT([common/jk_types.h
])
16 years, 11 months
JBoss Native SVN: r1379 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-02-06 07:36:07 -0500 (Wed, 06 Feb 2008)
New Revision: 1379
Modified:
trunk/build/unix/buildbin.rhel-httpd.sh
Log:
Add -m64 on PPC64.
Modified: trunk/build/unix/buildbin.rhel-httpd.sh
===================================================================
--- trunk/build/unix/buildbin.rhel-httpd.sh 2008-02-06 10:49:23 UTC (rev 1378)
+++ trunk/build/unix/buildbin.rhel-httpd.sh 2008-02-06 12:36:07 UTC (rev 1379)
@@ -140,6 +140,12 @@
add_conf="$add_conf --enable-experimental-libtool --enable-shared"
;;
esac
+case ${BUILD_CPU} in
+ ppc64)
+ # XXX: It is also in build.sh but not exported.
+ add_conf="${add_conf} CFLAGS=-m64"
+ ;;
+esac
echo "Building prefork and mpm"
# Build everything and the kitchen sink with the prefork build
16 years, 11 months
JBoss Native SVN: r1378 - trunk/build/unix/data.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-02-06 05:49:23 -0500 (Wed, 06 Feb 2008)
New Revision: 1378
Added:
trunk/build/unix/data/rhel-httpd.apr.linux2
Modified:
trunk/build/unix/data/rhel-httpd.apr
Log:
The apr-0.9.7-deepbind.patch is a linux specific one.
Modified: trunk/build/unix/data/rhel-httpd.apr
===================================================================
--- trunk/build/unix/data/rhel-httpd.apr 2008-02-06 10:21:21 UTC (rev 1377)
+++ trunk/build/unix/data/rhel-httpd.apr 2008-02-06 10:49:23 UTC (rev 1378)
@@ -1 +1 @@
-apr-1.2.7-pkgconf.patch
+apr-1.2.7-pkgconf.patch apr-0.9.7-deepbind.patch
Added: trunk/build/unix/data/rhel-httpd.apr.linux2
===================================================================
--- trunk/build/unix/data/rhel-httpd.apr.linux2 (rev 0)
+++ trunk/build/unix/data/rhel-httpd.apr.linux2 2008-02-06 10:49:23 UTC (rev 1378)
@@ -0,0 +1 @@
+apr-1.2.7-pkgconf.patch
16 years, 11 months
JBoss Native SVN: r1377 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2008-02-06 05:21:21 -0500 (Wed, 06 Feb 2008)
New Revision: 1377
Modified:
trunk/build/unix/build.sh
Log:
Add licenses directory to the packages
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2008-02-06 10:07:43 UTC (rev 1376)
+++ trunk/build/unix/build.sh 2008-02-06 10:21:21 UTC (rev 1377)
@@ -1015,6 +1015,8 @@
# Copy other files
cp ../NMAKEcommon.inc $package_src_dir
cp ../../JBossORG-EULA.txt $package_src_dir
+svn export --force ../../licenses $package_src_dir/licenses
+
if $has_apr; then
cp ../../srclib/apr/NMAKEmakefile $package_src_dir/srclib/apr-${apr_version}/
fi
16 years, 11 months