diff --git a/app/dmapi.f90 b/app/dmapi.f90 index 9527549..6e21211 100644 --- a/app/dmapi.f90 +++ b/app/dmapi.f90 @@ -87,7 +87,7 @@ program dmapi if (dm_is_error(rc)) call dm_stop(STOP_FAILURE) ! Run event loop. - do while (dm_fcgi_accept() /= E_NONE) + do while (dm_fcgi_accept() == E_NONE) call dm_cgi_env(env) call dm_cgi_router_dispatch(router, env, code) @@ -1332,11 +1332,14 @@ subroutine route_root(env) ! Check database availability. if (.not. dm_file_exists(db_beat)) then - rc = E_NOT_FOUND; message = 'beat database not found' + rc = E_NOT_FOUND + message = 'beat database not found' else if (.not. dm_file_exists(db_log)) then - rc = E_NOT_FOUND; message = 'log database not found' + rc = E_NOT_FOUND + message = 'log database not found' else if (.not. dm_file_exists(db_observ)) then - rc = E_NOT_FOUND; message = 'observation database not found' + rc = E_NOT_FOUND + message = 'observation database not found' else message = 'online' end if diff --git a/src/dm_cgi.f90 b/src/dm_cgi.f90 index 32a9803..537acbc 100644 --- a/src/dm_cgi.f90 +++ b/src/dm_cgi.f90 @@ -132,13 +132,15 @@ integer function dm_cgi_content(env, content) result(rc) rc = E_EMPTY if (env%content_length == 0) return - rc = E_READ nc = int(env%content_length, kind=c_size_t) sz = c_read(STDIN_FILENO, c_loc(content), nc) - if (sz == 0) return rc = E_EOF + if (sz == 0) return + + rc = E_READ if (sz /= nc) return + rc = E_NONE end function dm_cgi_content diff --git a/src/dm_fcgi.f90 b/src/dm_fcgi.f90 index 9ad2a59..f532495 100644 --- a/src/dm_fcgi.f90 +++ b/src/dm_fcgi.f90 @@ -59,21 +59,23 @@ integer function dm_fcgi_content(env, content) result(rc) character(len=:), allocatable, intent(out) :: content !! Returned request body. integer :: stat - integer(kind=i8) :: i + integer(kind=i8) :: i, n + + n = env%content_length fcgi_block: block rc = E_EMPTY - if (env%content_length == 0) exit fcgi_block + if (n == 0) exit fcgi_block rc = E_BOUNDS - if (env%content_length < 0) exit fcgi_block + if (n < 0) exit fcgi_block rc = E_ALLOC - allocate (character(len=env%content_length) :: content, stat=stat) + allocate (character(len=n) :: content, stat=stat) if (stat /= 0) exit fcgi_block rc = E_NONE - do i = 1, env%content_length + do i = 1, n content(i:i) = achar(fcgi_getchar()) end do