2011-04-14 20:37:47 +02:00
|
|
|
/*
|
2011-05-09 20:11:40 +02:00
|
|
|
* $Id: opj_server.c 53 2011-05-09 16:55:39Z kaori $
|
2011-04-14 20:37:47 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
|
|
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
2011-09-30 17:31:06 +02:00
|
|
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
|
|
|
* Copyright (c) 2011, Lucian Corlaciu, GSoC
|
2011-04-14 20:37:47 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
* \brief opj_server is a JPIP server program, which supports HTTP connection, JPT-stream, session, channels, and cache model managements.
|
|
|
|
*
|
|
|
|
* \section req Requirements
|
|
|
|
* FastCGI development kit (http://www.fastcgi.com).
|
|
|
|
*
|
|
|
|
* \section impinst Implementing instructions
|
|
|
|
* Launch opj_server from the server terminal:\n
|
|
|
|
* % spawn-fcgi -f ./opj_server -p 3000 -n
|
|
|
|
*
|
|
|
|
* Note: JP2 files are stored in the working directory of opj_server\n
|
|
|
|
* Check README for the JP2 Encoding\n
|
|
|
|
*
|
|
|
|
* We tested this software with a virtual server running on the same Linux machine as the clients.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2011-10-20 01:29:57 +02:00
|
|
|
#include "openjpip.h"
|
2011-04-14 20:37:47 +02:00
|
|
|
|
2011-08-25 19:13:04 +02:00
|
|
|
#ifndef QUIT_SIGNAL
|
|
|
|
#define QUIT_SIGNAL "quitJPIP"
|
|
|
|
#endif
|
2011-04-14 20:37:47 +02:00
|
|
|
|
2012-03-02 11:46:04 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
WSADATA initialisation_win32;
|
2012-03-02 12:09:16 +01:00
|
|
|
#endif /*_WIN32*/
|
2012-03-02 11:46:04 +01:00
|
|
|
|
2011-08-24 13:26:39 +02:00
|
|
|
int main(void)
|
|
|
|
{
|
2011-10-20 01:29:57 +02:00
|
|
|
server_record_t *server_record;
|
2012-03-02 12:09:16 +01:00
|
|
|
#ifdef SERVER
|
|
|
|
char *query_string;
|
|
|
|
#endif
|
2011-10-20 01:29:57 +02:00
|
|
|
|
2012-03-02 11:46:04 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
|
|
|
|
if( erreur!=0)
|
|
|
|
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
|
|
|
|
else
|
|
|
|
fprintf( stderr, "Initialisation Winsock\n");
|
2012-03-02 12:09:16 +01:00
|
|
|
#endif /*_WIN32*/
|
2012-03-02 11:46:04 +01:00
|
|
|
|
|
|
|
server_record = init_JPIPserver( 60000, 0);
|
2011-10-20 01:29:57 +02:00
|
|
|
|
2011-08-24 13:26:39 +02:00
|
|
|
#ifdef SERVER
|
|
|
|
while(FCGI_Accept() >= 0)
|
|
|
|
#else
|
|
|
|
|
|
|
|
char query_string[128];
|
2011-09-01 15:32:42 +02:00
|
|
|
while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
|
2011-08-24 13:26:39 +02:00
|
|
|
#endif
|
|
|
|
{
|
2012-03-02 12:09:16 +01:00
|
|
|
QR_t *qr;
|
|
|
|
bool parse_status;
|
2011-08-24 13:26:39 +02:00
|
|
|
|
|
|
|
#ifdef SERVER
|
|
|
|
query_string = getenv("QUERY_STRING");
|
2012-03-02 12:09:16 +01:00
|
|
|
#endif /*SERVER*/
|
2011-08-25 19:13:04 +02:00
|
|
|
|
|
|
|
if( strcmp( query_string, QUIT_SIGNAL) == 0)
|
|
|
|
break;
|
2011-08-24 13:26:39 +02:00
|
|
|
|
2011-10-20 01:29:57 +02:00
|
|
|
qr = parse_querystring( query_string);
|
|
|
|
|
2012-03-02 11:58:43 +01:00
|
|
|
parse_status = process_JPIPrequest( server_record, qr);
|
|
|
|
|
2011-08-24 13:26:39 +02:00
|
|
|
#ifndef SERVER
|
2011-10-20 01:29:57 +02:00
|
|
|
local_log( true, true, parse_status, false, qr, server_record);
|
2011-08-24 13:26:39 +02:00
|
|
|
#endif
|
2011-10-20 01:29:57 +02:00
|
|
|
|
2012-03-02 11:46:04 +01:00
|
|
|
if( parse_status)
|
2012-03-02 12:09:16 +01:00
|
|
|
send_responsedata( server_record, qr);
|
2012-03-02 11:58:43 +01:00
|
|
|
else{
|
2012-03-02 11:46:04 +01:00
|
|
|
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
|
2012-03-02 12:09:16 +01:00
|
|
|
fprintf( FCGI_stdout, "\r\n");
|
|
|
|
}
|
2012-03-02 11:46:04 +01:00
|
|
|
|
2011-10-20 01:29:57 +02:00
|
|
|
end_QRprocess( server_record, &qr);
|
2011-08-24 13:26:39 +02:00
|
|
|
}
|
2011-08-25 19:13:04 +02:00
|
|
|
|
|
|
|
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
|
2011-08-24 13:26:39 +02:00
|
|
|
|
2011-10-20 01:29:57 +02:00
|
|
|
terminate_JPIPserver( &server_record);
|
2011-08-24 13:26:39 +02:00
|
|
|
|
2012-03-02 11:46:04 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
if( WSACleanup() != 0){
|
|
|
|
fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
|
|
|
|
}else{
|
|
|
|
fprintf( stderr, "\nWSACleanup OK\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-24 13:26:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|