4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
34 #include "session_manager.h"
35 #include "target_manager.h"
36 #include "query_parser.h"
37 #include "msgqueue_manager.h"
40 #include "cache_manager.h"
41 #include "byte_manager.h"
42 #include "imgsock_manager.h"
44 #include "metadata_manager.h"
45 #include "ihdrbox_manager.h"
46 #include "index_manager.h"
49 #include "fcgi_stdio.h"
50 #define logstream FCGI_stdout
52 #define FCGI_stdout stdout
53 #define FCGI_stderr stderr
54 #define logstream stderr
58 *==========================================================
60 *==========================================================
63 //! Server static records
64 typedef struct server_record{
65 sessionlist_param_t *sessionlist; //!< list of session records
66 targetlist_param_t *targetlist; //!< list of target records
69 //! Query/response data for each client
72 msgqueue_param_t *msgqueue;
76 * Initialize the JPIP server
78 * @return intialized server record pointer
80 server_record_t * init_JPIPserver();
83 * Terminate the JPIP server
85 * @param[in] rec address of deleting server static record pointer
87 void terminate_JPIPserver( server_record_t **rec);
90 * 1st process per client request; parse query string
92 * @param[in] query_string request query string
93 * @return initialized query/response data pointer
95 QR_t * parse_querystring( char *query_string);
98 * 2nd process; process JPIP request and construct message queue
100 * @param[in] rec server static record pointer
101 * @param[in] qr query/response data pointer
102 * @return true if succeed, otherwise false
104 bool process_JPIPrequest( server_record_t *rec, QR_t *qr);
107 * 3rd process; send response data JPT/JPP-stream
109 * @param[in] qr query/response data pointer
111 void send_responsedata( QR_t *qr);
114 * 4th (last) process;
116 * @param[in] rec server static record pinter
117 * @param[in] qr address of query/response data pointer
119 void end_QRprocess( server_record_t *rec, QR_t **qr);
124 * Option for local tests; print out parameter values to logstream (stderr)
126 * @param[in] query true if query parameters are to be printed out
127 * @param[in] messages true if queue of messages is to be printed out
128 * @param[in] sessions true if session list is to be printed out
129 * @param[in] targets true if target list is to be printed out
130 * @param[in] qr query/response data pointer
131 * @param[in] rec server static record pinter
133 void local_log( bool query, bool messages, bool sessions, bool targets, QR_t *qr, server_record_t *rec);
138 *==========================================================
139 * JPIP decoding server API
140 *==========================================================
145 //! Decoding server static records
146 typedef struct dec_server_record{
147 cachelist_param_t *cachelist; //!< cache list
148 Byte_t *jpipstream; //!< JPT/JPP stream
149 int jpipstreamlen; //!< length of jpipstream
150 msgqueue_param_t *msgqueue; //!< parsed message queue of jpipstream
151 SOCKET listening_socket; //!< listenning socket
152 } dec_server_record_t;
155 //! Client socket identifier
156 typedef SOCKET client_t;
159 * Initialize the image decoding server
161 * @return intialized decoding server record pointer
163 dec_server_record_t * init_dec_server();
166 * Terminate the image decoding server
168 * @param[in] rec address of deleting decoding server static record pointer
170 void terminate_dec_server( dec_server_record_t **rec);
173 * Accept client connection
175 * @param[in] rec decoding server static record pointer
176 * @return client socket ID, -1 if failed
178 client_t accept_connection( dec_server_record_t *rec);
181 * Handle client request
183 * @param[in] client client socket ID
184 * @param[in] rec decoding server static record pointer
185 * @return true if succeed
187 bool handle_clientreq( client_t client, dec_server_record_t *rec);
192 *==========================================================
194 *==========================================================
203 //! JPIP decoding parameters
204 typedef struct jpip_dec_param{
205 Byte_t *jpipstream; //!< JPT/JPP-stream
206 Byte8_t jpiplen; //!< length of jpipstream
207 msgqueue_param_t *msgqueue; //!< message queue
208 metadatalist_param_t *metadatalist; //!< metadata list going into JP2 file
209 ihdrbox_param_t *ihdrbox; //!< ihdr box going into JP2 file
210 Byte_t *jp2kstream; //!< J2K codestream or JP2 file codestream
211 Byte8_t jp2klen; //!< length of j2kstream or JP2 file
215 * Initialize jpip decoder
217 * @param[in] jp2 true in case of jp2 file encoding, else j2k file encoding
218 * @return JPIP decoding parameters pointer
220 jpip_dec_param_t * init_jpipdecoder( bool jp2);
223 * Destroy jpip decoding parameters
225 * @param[in] dec address of JPIP decoding parameters pointer
227 void destroy_jpipdecoder( jpip_dec_param_t **dec);
230 * Read jpip codestream from a file
232 * @param[in] fname file name
233 * @param[in] dec JPIP decoding parameters pointer
234 * @return true if succeed
236 bool fread_jpip( char fname[], jpip_dec_param_t *dec);
239 * Decode jpip codestream
241 * @param[in] dec JPIP decoding parameters pointer
243 void decode_jpip( jpip_dec_param_t *dec);
246 * Write J2K/JP2 codestream to a file
248 * @param[in] fname file name
249 * @param[in] dec JPIP decoding parameters pointer
250 * @return true if succeed
252 bool fwrite_jp2k( char fname[], jpip_dec_param_t *dec);
255 * Option; print out parameter values to stderr
257 * @param[in] messages true if queue of messages is to be printed out
258 * @param[in] metadata true if metadata is to be printed out
259 * @param[in] ihdrbox true if image header data is to be printed out
260 * @param[in] dec JPIP decoding parameters pointer
262 void output_log( bool messages, bool metadata, bool ihdrbox, jpip_dec_param_t *dec);
265 * test the format of index (cidx) box in JP2 file
268 //! Redefinition of index parameters
269 typedef index_param_t index_t;
272 * Parse JP2 file and get index information from cidx box inside
274 * @param[in] fd file descriptor of the JP2 file
275 * @return pointer to the generated structure of index parameters
277 index_t * get_index_from_JP2file( int fd);
280 * Destroy index parameters
282 * @param[in,out] idx addressof the index pointer
284 void destroy_index( index_t **idx);
288 * print index parameters
290 * @param[in] index index parameters
292 void output_index( index_t *index);
296 #endif /* !OPENJPIP_H_ */