Dear Michal, Dear All, Please find enclosed a win32 patch for UNICODE support, in "diff -cr orig patched" format, applying to stunnel official v502 as found here: https://www.stunnel.org/downloads/stunnel-5.02.tar.gz.
This patch mainly addresses UNICODE compilation issues for Win32 target.
It is a first step in my usual port to WCE system, that I decided to "split" in two steps (to make it more clear for Michal code reviewing) : 1/ fix win32 code to UNICODE support, just for win32 (ie Windows Desktop version) 2/ fix specific WCE issues (to come in the near future)
To compile for Win32 I use VC++ 9.0 Express Edition on an XP sp2 host system.
The present stunnel patch addresses the following issues :
************* I] COMPILATION FAILURES
It is important to state that to detect more type mismatching (that can be error prone at runtime), I delibarately use /WX option on my W32 compiler: this flag takes each warning as an error.
This is very useful for UNICODE clean coding as, without this option, the compiler will just warn when seeing a short* (unicode string) used as a char* (ansi string), which leads to big pb at run time.
1/ vc.mak : I added a trivial support for a new "makew32" command line option to activate UNICODE compilation. So that to compile for W32 WITH UNICODE, one has just to type :
makew32 "UNICODESUPPORT="
(Note : in the MS nmake world, this syntax is equivalent to /DUNICODESUPPORT in eg borland make.)
To compile for ANSI, just type : makew32 on the command line, as usual, with no option.
Added /WX flag for strict type checking (very helpful to track abusive/error prone casts).
Added _CRT_NON_CONFORMING_SWPRINTFS to avoid compilation errors about _stprintf in ui_win_gui.c: MS has changed the prototype of the function and the FLAG is required to activate the old fashion interface that is used in the stunnel code.
2/ makew32.bat : Just added a comment to mention how to call the script to compile for UNICODE.
makew32 "UNICODESUPPORT="
3/ resolver.c : UNICODE strings are required for : LoadLibrary (so use TEXT macro for literals)
4/ ui_win_gui.c UNICODE strings are required for :
GetModuleFileName (see Winmain), SetCurrentDirectory (so that stunnel_exe_path and "c" variable must be TCHAR) so we have to use _tcsrchr instead of strchr, _tcscmp instead of strcmp and TEXT() macro for "c" variable affectation.
_tputenv_s must also be used instead of _putenv_s
SERVICE_NAME literal must be UNICODE because of "serviceTable[0].lpServiceName" struct member used by StartServiceCtrlDispatcher. Also for CreateService, OpenService, RegisterServiceCtrlHandler,
str_printf requires special format spec flag "%ls" for WIDE CHAR strings, and "%hs" for explicit ANSI CHAR strings. It is better, for the symetry of the code, to explicitely state %ls or %hs for each situation.
Prototype error : service_install function HAS DIFFERENT prototypes at the top of the source file and in the body of the source file : the correct prototype, considering the rest of the code using this function, is the... pure ANSI one ...
GetModuleFileNameEx (in enum_windows) requires that window_exe_path be UNICODE (TCHAR).
in edit_config function : ShellExecute requires UNICODE strings
5/ ui_win_cli.c
In main function : UNICODE required by GetModuleFileName and SetCurrentDirectory. then we have to use TCHAR for "c" and stunnel_exe_path variables, and use : _tcsrchr _tputenv_s accordingly.
************* II] OPERATIONAL ERRORS or IMPROVMENTS (at run-time)
1/ MINOR IMPROVMENT : replaced some "default" win3.1 style ugly bold fonts by thinner fonts (as those appearing on the MAIN WINDOW MENU text items). See resources.rc, About and Password dlgboxes :
Explicit use of FONT << 8, "MS Sans Serif" >>
I am not an artist but I think good to have consistant look between menus and dlgboxes, and to look like a little bit different than win3.1...
************************** III] TODO list and WISH LIST list for win32 target :
1/ win32 makefile : _CRT_NON_CONFORMING_SWPRINTFS flag to <<avoid>> in makefile, so that we have to clarify the ui_win_gui.c code on that point
2/ mingw32 makefile : 2.1 add UNICODE flag support in mgw32 makefile. 2.2 check the interest of _CRT_NON_CONFORMING_SWPRINTFS
3/ ui_win_cli.c :
shoudn't we use s_log instead of fprintf(stderr) ?
***************
I hope you will find this patch useful.
More fixes are coming very soon for WCE5.0/WM6 support (my own WCE version is now finished and working, but I have to clean my code a little before submitting it).
Yours sincerely,
Pierre Delaage