2009-01-26 23:32 UTC+0100 Viktor Szakats (harbour.01 syenar hu)

+ contrib/examples/uhttpd/hbmk_vc.bat
     + Added MSVC make file.

   * contrib/examples/uhttpd/socket.c
     ! Made it compile with MSVC.
     ! Added SVN header.

   * contrib/examples/uhttpd/uhttpd.prg
   + contrib/examples/uhttpd/uhttpdc.c
     + C level stuff moved to separate file.

   ; NOTE: I'm getting an "Argument error: +" when browse
           to http://localhost:8082 (using Chrome if that matters).
This commit is contained in:
Viktor Szakats
2009-01-26 22:35:42 +00:00
parent 5374dbd09f
commit 7ee0421038
5 changed files with 292 additions and 149 deletions

View File

@@ -8,6 +8,21 @@
2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
*/
2009-01-26 23:32 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
+ contrib/examples/uhttpd/hbmk_vc.bat
+ Added MSVC make file.
* contrib/examples/uhttpd/socket.c
! Made it compile with MSVC.
! Added SVN header.
* contrib/examples/uhttpd/uhttpd.prg
+ contrib/examples/uhttpd/uhttpdc.c
+ C level stuff moved to separate file.
; NOTE: I'm getting an "Argument error: +" when browse
to http://localhost:8082 (using Chrome if that matters).
2009-01-26 22:57 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
* source/rdd/usrrdd/example/exhsx.prg
! Removed HSXRDD references. It seems to work without them.

View File

@@ -0,0 +1,78 @@
@echo off
cls
rem
rem $Id$
rem
SET UHTTP_INET_SUPPORT=no
SET UHTTP_INET_DEF=
SET UHTTP_INET_SOCKET=
SET UHTTP_GD_SUPPORT=yes
SET UHTTP_GD_DEF=
SET UHTTP_GD_LIBS=
:PARAM_CHECK
if "%1". == "--without-gd". goto PARAM_GD
if "%1". == "--with-inet". goto PARAM_INET
GOTO GO_ON
:PARAM_GD
SET UHTTP_GD_SUPPORT=no
shift
goto PARAM_CHECK
:PARAM_INET
SET UHTTP_INET_SUPPORT=yes
shift
goto PARAM_CHECK
:GO_ON
echo.
echo.Building uHTTPD server
echo.
if %UHTTP_GD_SUPPORT%.==yes. echo.Lib GD support enabled
if %UHTTP_GD_SUPPORT%.==no. echo.Lib GD support disabled
echo.
if %UHTTP_INET_SUPPORT%.==yes. echo.HB_INET socket
if %UHTTP_INET_SUPPORT%.==no. echo.Mindaugas socket
echo.
if %UHTTP_GD_SUPPORT%.==yes. SET UHTTP_GD_DEF=-DGD_SUPPORT
if %UHTTP_GD_SUPPORT%.==yes. SET UHTTP_GD_LIBS=hbgd.lib bgd.lib
if %UHTTP_INET_SUPPORT%.==yes. SET UHTTP_INET_DEF=-DUSE_HB_INET
if %UHTTP_INET_SUPPORT%.==no. SET UHTTP_INET_SOCKET=socket.c
..\..\..\bin\harbour uhttpd /n /es2 /w3 /i..\..\..\include %UHTTP_GD_DEF% %UHTTP_INET_DEF%
if errorlevel 1 goto DOERROR
cl -nologo -O2 -W3 -I..\..\..\include uhttpd.c uhttpdc.c %UHTTP_INET_SOCKET% /link /subsystem:windows /libpath:..\..\..\lib hbcpage.lib hbdebug.lib hbvmmt.lib hbrtl.lib gtwin.lib hblang.lib hbrdd.lib hbmacro.lib hbpp.lib rddntx.lib rddcdx.lib rddfpt.lib hbsix.lib hbcommon.lib hbpcre.lib hbzlib.lib user32.lib wsock32.lib advapi32.lib hbct.lib gdi32.lib hbwin.lib hbhsx.lib gtwvt.lib %UHTTP_GD_LIBS% xhb.lib
if errorlevel 1 goto DOERROR
:CLEAN
del *.obj
del uhttpd.c
if not exist uhttpd.exe goto :EXIT
if %UHTTP_GD_SUPPORT%.==no. goto BUILD_OK
if not exist bgd.dll goto NOBGD
:BUILD_OK
echo.Build complete.
goto EXIT
:DOERROR
echo.Build error
goto EXIT
:NOBGD
echo.ATTENTION! This program needs bgd.dll
echo.Please download it from:
echo.http://www.libgd.org/releases/gd-latest-win32.zip
:EXIT
SET UHTTP_INET_SUPPORT=
SET UHTTP_INET_DEF=
SET UHTTP_INET_SOCKET=
SET UHTTP_GD_SUPPORT=
SET UHTTP_GD_DEF=
SET UHTTP_GD_LIBS=

View File

@@ -1,21 +1,31 @@
#include <windows.h>
/*
* $Id$
*/
#include "hbapi.h"
#include "hbapiitm.h"
#if defined( HB_OS_WIN_32 )
#define _WINSOCKAPI_ /* Prevents inclusion of winsock.h in windows.h */
#define HB_SOCKET_T SOCKET
#include <winsock2.h>
#include <windows.h>
#endif
/*
Function naming:
The intention of this library is to be as close as possible to the original
socket implementation. This supposed to be valid for function names also,
but some of the names are very platform dependent, ex., WSA*() functions.
select() function name is reserved for standard Harbour's function, so,
socket implementation. This supposed to be valid for function names also,
but some of the names are very platform dependent, ex., WSA*() functions.
select() function name is reserved for standard Harbour's function, so,
socket_*() prefix was used:
socket_init() - WSAStartup()
socket_exit() - WSACleanup()
socket_error() - WSALastError()
socket_select() - select()
Finally I renamed all functions to have socket_*() prefix to be more "prefix
compatible" and not to occupy a general function names like send(), bind(),
Finally I renamed all functions to have socket_*() prefix to be more "prefix
compatible" and not to occupy a general function names like send(), bind(),
accept(), listen(), etc.:
socket_create() - socket()
socket_close() - closesocket()
@@ -31,11 +41,11 @@
Types mapping:
SOCKET
UINT_PTR in Windows, let's map it to pointer type, and INVALID_SOCKET value to NIL
SOCKET
UINT_PTR in Windows, let's map it to pointer type, and INVALID_SOCKET value to NIL
struct sockaddr
It is not only IP addresses, also can be IPX, etc. All network-host byte order
struct sockaddr
It is not only IP addresses, also can be IPX, etc. All network-host byte order
conversion should be hidden from Harbour API. So, let's map to:
{ adress_familly, ... }
AF_INET: { AF_INET, cAddr, nPort }
@@ -121,7 +131,7 @@ static PHB_ITEM hb_itemPutSockaddr( PHB_ITEM pItem, const struct sockaddr* saddr
{
hb_arrayNew( pItem, 3 );
hb_arraySetNI( pItem, 1, saddr->sa_family );
hb_arraySetC( pItem, 2, inet_ntoa( ( ( struct sockaddr_in* ) saddr )->sin_addr ) );
hb_arraySetC( pItem, 2, inet_ntoa( ( ( struct sockaddr_in* ) saddr )->sin_addr ) );
hb_arraySetNI( pItem, 3, ntohs( ( ( struct sockaddr_in* ) saddr )->sin_port ) );
}
else
@@ -134,7 +144,7 @@ static PHB_ITEM hb_itemPutSockaddr( PHB_ITEM pItem, const struct sockaddr* saddr
}
HB_FUNC ( SOCKET_INIT )
HB_FUNC ( SOCKET_INIT )
{
WSADATA wsad;
@@ -143,33 +153,33 @@ HB_FUNC ( SOCKET_INIT )
}
HB_FUNC ( SOCKET_EXIT )
HB_FUNC ( SOCKET_EXIT )
{
hb_retni( WSACleanup() );
}
HB_FUNC ( SOCKET_ERROR )
HB_FUNC ( SOCKET_ERROR )
{
hb_retni( WSAGetLastError() );
}
HB_FUNC ( SOCKET_CREATE )
HB_FUNC ( SOCKET_CREATE )
{
hb_retsocket( socket( hb_parnidef( 1, PF_INET ),
hb_parnidef( 2, SOCK_STREAM ),
hb_retsocket( socket( hb_parnidef( 1, PF_INET ),
hb_parnidef( 2, SOCK_STREAM ),
hb_parnidef( 3, IPPROTO_TCP ) ) );
}
HB_FUNC ( SOCKET_CLOSE )
HB_FUNC ( SOCKET_CLOSE )
{
hb_retni( closesocket( hb_parsocket( 1 ) ) );
}
HB_FUNC ( SOCKET_BIND )
HB_FUNC ( SOCKET_BIND )
{
struct sockaddr sa;
@@ -178,13 +188,13 @@ HB_FUNC ( SOCKET_BIND )
}
HB_FUNC ( SOCKET_LISTEN )
HB_FUNC ( SOCKET_LISTEN )
{
hb_retni( listen( hb_parsocket( 1 ), hb_parnidef( 2, 10 ) ) );
}
HB_FUNC ( SOCKET_ACCEPT )
HB_FUNC ( SOCKET_ACCEPT )
{
struct sockaddr saddr;
int iSize = sizeof( struct sockaddr );
@@ -198,20 +208,20 @@ HB_FUNC ( SOCKET_ACCEPT )
}
HB_FUNC ( SOCKET_SHUTDOWN )
HB_FUNC ( SOCKET_SHUTDOWN )
{
hb_retni( shutdown( hb_parsocket( 1 ), hb_parnidef( 2, SD_BOTH ) ) );
}
HB_FUNC ( SOCKET_RECV )
HB_FUNC ( SOCKET_RECV )
{
int iLen, iRet;
char* pBuf;
iLen = hb_parni( 3 );
if( iLen > 65536 || iLen <= 0 )
if( iLen > 65536 || iLen <= 0 )
iLen = 4096;
pBuf = ( char* ) hb_xgrab( ( ULONG ) iLen );
@@ -222,13 +232,13 @@ HB_FUNC ( SOCKET_RECV )
}
HB_FUNC ( SOCKET_SEND )
HB_FUNC ( SOCKET_SEND )
{
hb_retni( send( hb_parsocket( 1 ), hb_parc( 2 ), hb_parclen( 2 ), hb_parni( 3, 0 ) ) );
}
HB_FUNC ( SOCKET_SELECT )
HB_FUNC ( SOCKET_SELECT )
{
fd_set setread, setwrite, seterror;
BOOL bRead = 0, bWrite = 0, bError = 0;
@@ -302,14 +312,14 @@ HB_FUNC ( SOCKET_SELECT )
if( lTimeout == -1 )
{
iRet = select( maxsocket + 1, bRead ? &setread : NULL, bWrite ? &setwrite: NULL,
iRet = select( maxsocket + 1, bRead ? &setread : NULL, bWrite ? &setwrite: NULL,
bError ? &seterror : NULL, NULL );
}
else
{
tv.tv_sec = lTimeout / 1000;
tv.tv_usec = ( lTimeout % 1000 ) * 1000;
iRet = select( maxsocket + 1, bRead ? &setread : NULL, bWrite ? &setwrite: NULL,
iRet = select( maxsocket + 1, bRead ? &setread : NULL, bWrite ? &setwrite: NULL,
bError ? &seterror : NULL, &tv );
}
@@ -325,7 +335,7 @@ HB_FUNC ( SOCKET_SELECT )
socket = hb_itemGetSocket( hb_arrayGetItemPtr( pArray, ulIndex ) );
if( socket != INVALID_SOCKET )
{
if( FD_ISSET( socket, &setread ) )
if( FD_ISSET( socket, &setread ) )
{
hb_arraySetForward( pItem, ++ulCount, hb_itemPutSocket( NULL, socket ) );
}
@@ -346,7 +356,7 @@ HB_FUNC ( SOCKET_SELECT )
socket = hb_itemGetSocket( hb_arrayGetItemPtr( pArray, ulIndex ) );
if( socket != INVALID_SOCKET )
{
if( FD_ISSET( socket, &setwrite ) )
if( FD_ISSET( socket, &setwrite ) )
{
hb_arraySetForward( pItem, ++ulCount, hb_itemPutSocket( NULL, socket ) );
}
@@ -367,7 +377,7 @@ HB_FUNC ( SOCKET_SELECT )
socket = hb_itemGetSocket( hb_arrayGetItemPtr( pArray, ulIndex ) );
if( socket != INVALID_SOCKET )
{
if( FD_ISSET( socket, &seterror ) )
if( FD_ISSET( socket, &seterror ) )
{
hb_arraySetForward( pItem, ++ulCount, hb_itemPutSocket( NULL, socket ) );
}
@@ -380,11 +390,11 @@ HB_FUNC ( SOCKET_SELECT )
}
HB_FUNC ( SOCKET_GETSOCKNAME )
HB_FUNC ( SOCKET_GETSOCKNAME )
{
struct sockaddr saddr;
int iSize = sizeof( struct sockaddr );
hb_retni( getsockname( hb_parsocket( 1 ), &saddr, &iSize ) );
if( ISBYREF( 2 ) )
{
@@ -393,11 +403,11 @@ HB_FUNC ( SOCKET_GETSOCKNAME )
}
HB_FUNC ( SOCKET_GETPEERNAME )
HB_FUNC ( SOCKET_GETPEERNAME )
{
struct sockaddr saddr;
int iSize = sizeof( struct sockaddr );
hb_retni( getpeername( hb_parsocket( 1 ), &saddr, &iSize ) );
if( ISBYREF( 2 ) )
{
@@ -406,11 +416,10 @@ HB_FUNC ( SOCKET_GETPEERNAME )
}
HB_FUNC ( CONNECT )
HB_FUNC ( CONNECT )
{
struct sockaddr sa;
hb_itemGetSockaddr( hb_param( 2, HB_IT_ANY ), &sa );
hb_retni( connect( hb_parsocket( 1 ), &sa, sizeof( struct sockaddr ) ) );
}

View File

@@ -1947,114 +1947,3 @@ STATIC FUNCTION ParseIni( cConfig )
ENDIF
RETURN hDefault
//------------------------------------------------------------------------------
// C FUNCTIONS
//------------------------------------------------------------------------------
#PRAGMA BEGINDUMP
#ifdef __WIN32__
#include <windows.h>
#include "hbapi.h"
#include "hbvm.h"
BOOL win_SysRefresh( int iMsec )
{
int iQuit = (int) FALSE;
HANDLE hDummyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// Begin the operation and continue until it is complete
// or until the user clicks the mouse or presses a key.
while (MsgWaitForMultipleObjects(1, &hDummyEvent, FALSE, ( iMsec == 0, INFINITE, iMsec ), QS_ALLINPUT | QS_ALLPOSTMESSAGE) == WAIT_OBJECT_0 + 1)
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
switch(msg.message)
{
case WM_QUIT:
{
iQuit = (int) msg.wParam;
goto stopLoop;
}
//case WM_LBUTTONDOWN:
//case WM_RBUTTONDOWN:
//case WM_KEYDOWN:
//case WM_LBUTTONUP:
//case WM_RBUTTONUP:
//case WM_KEYUP:
// //
// // Perform any required cleanup.
// //
// break;
// //exit;
//
default:
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (!iQuit)
{
goto stopLoop;
}
}
stopLoop:
CloseHandle( hDummyEvent );
return iQuit;
}
HB_FUNC_STATIC( WIN_SYSREFRESH )
{
hb_retl( win_SysRefresh( ( ISNIL( 1 ) ? 0 : hb_parni( 1 ) ) ) );
}
HB_FUNC_STATIC( WIN_SETENV )
{
hb_retl( SetEnvironmentVariable( hb_parc( 1 ), hb_parc( 2 ) ) );
}
HB_FUNC_STATIC( WIN_TIMEZONEBIAS )
{
TIME_ZONE_INFORMATION tzInfo;
//LONG lBias;
int nLen;
char *szRet = (char *) hb_xgrab( 6 );
if ( GetTimeZoneInformation( &tzInfo ) == TIME_ZONE_ID_INVALID )
{
tzInfo.Bias = 0;
}
else
{
tzInfo.Bias = -tzInfo.Bias;
}
hb_snprintf( szRet, 6, "%+03d%02d",
(int)( tzInfo.Bias / 60 ),
(int)( tzInfo.Bias % 60 > 0 ? - tzInfo.Bias % 60 : tzInfo.Bias % 60 ) );
nLen = strlen( szRet );
if ( nLen < 6 )
{
szRet = (char *) hb_xrealloc( szRet, nLen + 1 );
}
hb_retclen_buffer( szRet, nLen );
}
#endif
#PRAGMA ENDDUMP

View File

@@ -0,0 +1,152 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* uHTTPD (Micro HTTP server) [C helper functions]
*
* Copyright 2009 Francesco Saverio Giudice <info / at / fsgiudice.com>
* Copyright 2008 Mindaugas Kavaliauskas (dbtopas at dbtopas.lt)
* www - http://www.harbour-project.org
*
* Credits:
* Based on first version posted from Mindaugas Kavaliauskas on
* developers NG on December 15th, 2008 whom give my thanks to have
* shared initial work.
* Francesco.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#define HB_OS_WIN_32_USED
#include "hbapi.h"
#if defined( HB_OS_WIN_32 )
BOOL win_SysRefresh( int iMsec )
{
int iQuit = ( int ) FALSE;
HANDLE hDummyEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
/* Begin the operation and continue until it is complete
or until the user clicks the mouse or presses a key. */
while( MsgWaitForMultipleObjects( 1, &hDummyEvent, FALSE, ( iMsec == 0, INFINITE, iMsec ), QS_ALLINPUT | QS_ALLPOSTMESSAGE) == WAIT_OBJECT_0 + 1 )
{
MSG msg;
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
switch( msg.message )
{
case WM_QUIT:
{
iQuit = ( int ) msg.wParam;
goto stopLoop;
}
#if 0
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_KEYDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_KEYUP:
/* Perform any required cleanup. */
break;
/* exit; */
#endif
default:
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
if( ! iQuit )
{
goto stopLoop;
}
}
stopLoop:
CloseHandle( hDummyEvent );
return iQuit;
}
HB_FUNC( WIN_SYSREFRESH )
{
hb_retl( win_SysRefresh( ( ISNIL( 1 ) ? 0 : hb_parni( 1 ) ) ) );
}
HB_FUNC( WIN_SETENV )
{
hb_retl( SetEnvironmentVariable( hb_parc( 1 ), hb_parc( 2 ) ) );
}
HB_FUNC( WIN_TIMEZONEBIAS )
{
TIME_ZONE_INFORMATION tzInfo;
int nLen;
char * szRet = ( char * ) hb_xgrab( 6 );
if( GetTimeZoneInformation( &tzInfo ) == TIME_ZONE_ID_INVALID )
tzInfo.Bias = 0;
else
tzInfo.Bias = -tzInfo.Bias;
hb_snprintf( szRet, 6, "%+03d%02d",
( int )( tzInfo.Bias / 60 ),
( int )( tzInfo.Bias % 60 > 0 ? - tzInfo.Bias % 60 : tzInfo.Bias % 60 ) );
nLen = strlen( szRet );
if( nLen < 6 )
szRet = ( char * ) hb_xrealloc( szRet, nLen + 1 );
hb_retclen_buffer( szRet, nLen );
}
#endif