diff --git a/applications/jpip/CHANGES b/applications/jpip/CHANGES index 13dfe69b..0fc3fa2c 100644 --- a/applications/jpip/CHANGES +++ b/applications/jpip/CHANGES @@ -5,9 +5,13 @@ What's New for OpenJPIP ! : changed + : added +August 25, 2011 ++ [kaori] added tid request support to JPIP client ++ [kaori] added quit JPIP server request + August 24, 2011 + [kaori] added cachemodel_manager, which had been managed in target_manager previously -+ [kaori] added tid request support ++ [kaori] added tid request support to JPIP server August 16, 2011 * [antonin] fixed cmake support for openjpip diff --git a/applications/jpip/README b/applications/jpip/README index 363ce1d0..28410745 100644 --- a/applications/jpip/README +++ b/applications/jpip/README @@ -90,6 +90,11 @@ Server: 2. Launch opj_server from the server terminal: % spawn-fcgi -f ./opj_server -p 3000 -n + + For shutting down JPIP server: + %GET http://hostname/myFCGI?quitJPIP + Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting) + Requst message "quitJPIP" can be changed in Makfile, modify -DQUIT_SIGNAL=\"quitJPIP\" Client: 1. Launch image decoding server, and keep it alive as long as image viewers are open diff --git a/applications/jpip/libopenjpip/target_manager.c b/applications/jpip/libopenjpip/target_manager.c index 1117551d..6aea9aec 100644 --- a/applications/jpip/libopenjpip/target_manager.c +++ b/applications/jpip/libopenjpip/target_manager.c @@ -101,8 +101,6 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname) target->next=NULL; - fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", target->tid); - if( targetlist->first) // there are one or more entries targetlist->last->next = target; else // first entry @@ -220,9 +218,6 @@ target_param_t * search_targetBytid( char tid[], targetlist_param_t *targetlist) foundtarget = foundtarget->next; } - fprintf( FCGI_stdout, "Status: 404\r\n"); - fprintf( FCGI_stdout, "Reason: tid %s not found\r\n", tid); - return NULL; } diff --git a/applications/jpip/opj_client/opj_dec_server/cache_manager.c b/applications/jpip/opj_client/opj_dec_server/cache_manager.c index 4d58f835..6a7b92c9 100644 --- a/applications/jpip/opj_client/opj_dec_server/cache_manager.c +++ b/applications/jpip/opj_client/opj_dec_server/cache_manager.c @@ -61,12 +61,13 @@ void delete_cachelist(cachelist_param_t **cachelist) free( *cachelist); } -cache_param_t * gene_cache( char *targetname, int csn, char *cid) +cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid) { cache_param_t *cache; cache = (cache_param_t *)malloc( sizeof(cache_param_t)); strcpy( cache->filename, targetname); + strcpy( cache->tid, tid); cache->csn = csn; cache->cid = (char **)malloc( sizeof(char *)); *cache->cid = (char *)malloc( MAX_LENOFCID); @@ -175,6 +176,14 @@ void add_cachecid( char *cid, cache_param_t *cache) cache->numOfcid ++; } +void update_cachetid( char *tid, cache_param_t *cache) +{ + if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){ + fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename); + strcpy( cache->tid, tid); + } +} + void remove_cidInCache( char *cid, cache_param_t *cache); void remove_cachecid( char *cid, cachelist_param_t *cachelist) @@ -225,6 +234,7 @@ void print_cache( cache_param_t *cache) fprintf( stdout,"cache\n"); fprintf( stdout,"\t filename: %s\n", cache->filename); + fprintf( stdout,"\t tid: %s\n", cache->tid); fprintf( stdout,"\t csn: %d\n", cache->csn); fprintf( stdout,"\t cid:"); diff --git a/applications/jpip/opj_client/opj_dec_server/cache_manager.h b/applications/jpip/opj_client/opj_dec_server/cache_manager.h index 44450134..ad35de80 100644 --- a/applications/jpip/opj_client/opj_dec_server/cache_manager.h +++ b/applications/jpip/opj_client/opj_dec_server/cache_manager.h @@ -37,9 +37,13 @@ //! maximum length of target name #define MAX_LENOFTARGET 128 +//! maximum length of target identifier +#define MAX_LENOFTID 30 + //! cache parameters typedef struct cache_param{ char filename[MAX_LENOFTARGET]; //!< file name + char tid[MAX_LENOFTID]; //!< taregt identifier int csn; //!< codestream number char **cid; //!< dynamic array of channel identifiers int numOfcid; //!< number of cids @@ -74,10 +78,11 @@ void delete_cachelist(cachelist_param_t **cachelist); * * @param[in] targetname target file name * @param[in] csn codestream number + * @param[in] tid target identifier * @param[in] cid channel identifier * @return pointer to the generated cache */ -cache_param_t * gene_cache( char *targetname, int csn, char *cid); +cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid); /** * delete a cache @@ -132,6 +137,16 @@ cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist); */ void add_cachecid( char *cid, cache_param_t *cache); + +/** + * update tid of a cache + * + * @param[in] tid target identifier + * @param[in] cache cache pointer + */ +void update_cachetid( char *tid, cache_param_t *cache); + + /** * remove cid in cache * diff --git a/applications/jpip/opj_client/opj_dec_server/imgsock_manager.c b/applications/jpip/opj_client/opj_dec_server/imgsock_manager.c index 567b81ca..19599a9a 100644 --- a/applications/jpip/opj_client/opj_dec_server/imgsock_manager.c +++ b/applications/jpip/opj_client/opj_dec_server/imgsock_manager.c @@ -94,7 +94,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket) { int receive_size; char buf[BUF_LEN]; - char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "CID request", "CID destroy", "JP2 save", "QUIT"}; + char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "TID request", "CID request", "CID destroy", "JP2 save", "QUIT"}; int i; receive_size = receive_line( connected_socket, buf); @@ -106,7 +106,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket) for( i=0; i server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n cidstring\\n) bytelengthvalue\\n data \n + * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n tidstring\\n cidstring\\n) bytelengthvalue\\n data \n * server -> client: 1 or 0 (of 1Byte response signal) * *\section sec2 PNM request @@ -140,25 +150,31 @@ int receive_line(SOCKET connected_socket, char *buf); * client -> server: XML request\\n \n * server -> client: XML (3Byte) length (2Byte Big endian) data * - *\section sec4 CID request + *\section sec4 TID request + * Get target ID of target image + * + * client -> server: TID request\\n targetname\\n \n + * server -> client: TID (3Byte) length (1Byte) tiddata + * + *\section sec5 CID request * Get Channel ID of identical target image * * client -> server: CID request\\n targetname\\n \n * server -> client: CID (3Byte) length (1Byte) ciddata * - *\section sec5 CID destroy + *\section sec6 CID destroy * Close Channel ID * * client -> server: CID destroy\\n ciddata \n * server -> client: 1 or 0 (of 1Byte response signal) * - *\section sec6 JP2 save + *\section sec7 JP2 save * Save in JP2 file format * * client -> server: JP2 save\\n ciddata \n * server -> client: 1 or 0 (of 1Byte response signal) * - *\section sec7 QUIT + *\section sec8 QUIT * Quit the opj_dec_server program * * client -> server: quit or QUIT diff --git a/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c b/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c index 9779d93b..c8c3c695 100644 --- a/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c +++ b/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c @@ -99,6 +99,14 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par */ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist); +/** + * handle TargetID request message + * + * @param[in] connected_socket socket descriptor + * @param[in] cachelist cache list pointer + */ +void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist); + /** * handle ChannelID request message * @@ -163,6 +171,10 @@ int main(int argc, char *argv[]){ case XMLREQ: handle_XMLreqMSG( connected_socket, jpipstream, cachelist); break; + + case TIDREQ: + handle_TIDreqMSG( connected_socket, cachelist); + break; case CIDREQ: handle_CIDreqMSG( connected_socket, cachelist); @@ -183,7 +195,7 @@ int main(int argc, char *argv[]){ break; } - printf("cut the connection. listening to port\n"); + printf("\t end of the connection\n\n"); if( closesocket(connected_socket) != 0){ perror("close"); return -1; @@ -221,10 +233,10 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist Byte_t *newjpipstream; int newstreamlen = 0; cache_param_t *cache; - char target[MAX_LENOFTARGET], cid[MAX_LENOFCID]; + char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID]; metadatalist_param_t *metadatalist; - newjpipstream = receive_JPIPstream( connected_socket, target, cid, &newstreamlen); + newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen); parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue); @@ -235,11 +247,13 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist); // cid registration - if( target[0] != 0 && cid[0] != 0){ - if((cache = search_cache( target, cachelist))) + if( target[0] != 0 && tid[0] != 0 && cid[0] != 0){ + if((cache = search_cache( target, cachelist))){ add_cachecid( cid, cache); + update_cachetid( tid, cache); + } else{ - cache = gene_cache( target, msgqueue->last->csn, cid); + cache = gene_cache( target, msgqueue->last->csn, tid, cid); insert_cache_into_list( cache, cachelist); } } @@ -294,6 +308,22 @@ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_pa free( xmlstream); } +void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist) +{ + char target[MAX_LENOFTARGET], *tid = NULL; + cache_param_t *cache; + int tidlen = 0; + + receive_line( connected_socket, target); + cache = search_cache( target, cachelist); + + if( cache){ + tid = cache->tid; + tidlen = strlen(tid); + } + send_TIDstream( connected_socket, tid, tidlen); +} + void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist) { char target[MAX_LENOFTARGET], *cid = NULL; diff --git a/applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110824.jar b/applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110825.jar similarity index 54% rename from applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110824.jar rename to applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110825.jar index b821db33..67b68b67 100644 Binary files a/applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110824.jar and b/applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110825.jar differ diff --git a/applications/jpip/opj_client/opj_viewer/dist/opj_viewer.jar b/applications/jpip/opj_client/opj_viewer/dist/opj_viewer.jar index 031f9e68..ce826b27 120000 --- a/applications/jpip/opj_client/opj_viewer/dist/opj_viewer.jar +++ b/applications/jpip/opj_client/opj_viewer/dist/opj_viewer.jar @@ -1 +1 @@ -opj_viewer-20110824.jar \ No newline at end of file +opj_viewer-20110825.jar \ No newline at end of file diff --git a/applications/jpip/opj_client/opj_viewer/src/ImageManager.java b/applications/jpip/opj_client/opj_viewer/src/ImageManager.java index a0eb625a..62166f8a 100644 --- a/applications/jpip/opj_client/opj_viewer/src/ImageManager.java +++ b/applications/jpip/opj_client/opj_viewer/src/ImageManager.java @@ -50,16 +50,19 @@ public class ImageManager extends JPIPHttpClient String refcid = ImgdecClient.query_cid( j2kfilename); byte[] jpipstream; - if( refcid == null) - jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true); + if( refcid == null){ + String reftid = ImgdecClient.query_tid( j2kfilename); + if( reftid == null) + jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true); + else + jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, true); + } else jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, true); System.err.println( "decoding to PNM image"); - pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, cid, fw, fh); + pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh); System.err.println( " done"); - - // System.out.println( "fw: " + fw + " fh: " + fh + "pnm w: "); return pnmimage.createROIImage( rx, ry, rw, rh); } diff --git a/applications/jpip/opj_client/opj_viewer/src/ImgdecClient.java b/applications/jpip/opj_client/opj_viewer/src/ImgdecClient.java index 7466aa86..85fba612 100644 --- a/applications/jpip/opj_client/opj_viewer/src/ImgdecClient.java +++ b/applications/jpip/opj_client/opj_viewer/src/ImgdecClient.java @@ -40,9 +40,9 @@ public class ImgdecClient{ return get_PNMstream( cid, fw, fh); } - public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String cid, int fw, int fh) + public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh) { - send_JPIPstream( jpipstream, j2kfilename, cid); + send_JPIPstream( jpipstream, j2kfilename, tid, cid); return get_PNMstream( cid, fw, fh); } @@ -56,7 +56,7 @@ public class ImgdecClient{ System.err.println("Sending " + jpipstream.length + "Data Bytes to decodingServer"); os.writeBytes("JPIP-stream\n"); - os.writeBytes("version 1.1\n"); + os.writeBytes("version 1.2\n"); os.writeBytes( jpipstream.length + "\n"); os.write( jpipstream, 0, jpipstream.length); @@ -71,7 +71,7 @@ public class ImgdecClient{ } } - public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String cid) + public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid) { try{ Socket imgdecSocket = new Socket( "localhost", 5000); @@ -85,8 +85,12 @@ public class ImgdecClient{ System.err.println("Sending " + length + "Data Bytes to decodingServer"); os.writeBytes("JPIP-stream\n"); - os.writeBytes("version 1.1\n"); + os.writeBytes("version 1.2\n"); os.writeBytes( j2kfilename + "\n"); + if( tid == null) + os.writeBytes( "0\n"); + else + os.writeBytes( tid + "\n"); os.writeBytes( cid + "\n"); os.writeBytes( length + "\n"); os.write( jpipstream, 0, length); @@ -189,7 +193,27 @@ public class ImgdecClient{ public static String query_cid( String j2kfilename) { - String cid = null; + int []retmsglabel = new int[3]; + retmsglabel[0] = 67; + retmsglabel[1] = 73; + retmsglabel[2] = 68; + + return query_id( "CID request", j2kfilename, retmsglabel); + } + + public static String query_tid( String j2kfilename) + { + int []retmsglabel = new int[3]; + retmsglabel[0] = 84; + retmsglabel[1] = 73; + retmsglabel[2] = 68; + + return query_id( "TID request", j2kfilename, retmsglabel); + } + + public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel) + { + String id = null; try{ Socket imgdecSocket = new Socket( "localhost", 5000); @@ -197,23 +221,23 @@ public class ImgdecClient{ DataInputStream is = new DataInputStream( imgdecSocket.getInputStream()); byte []header = new byte[4]; - os.writeBytes("CID request\n"); + os.writeBytes( reqmsghead + "\n"); os.writeBytes( j2kfilename + "\n"); read_stream( is, header, 4); - if( header[0] == 67 && header[1] == 73 && header[2] == 68){ + if( header[0] == retmsglabel[0] && header[1] == retmsglabel[1] && header[2] == retmsglabel[2]){ int length = header[3]&0xff; if( length > 0){ - byte []ciddata = new byte[ length]; - read_stream( is, ciddata, length); - cid = new String( ciddata); + byte []iddata = new byte[ length]; + read_stream( is, iddata, length); + id = new String( iddata); } } else - System.err.println("Error in query_cid(), not starting with CID"); + System.err.println("Error in query_id("+ reqmsghead + "), wrong to start with " + header); } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); @@ -221,7 +245,7 @@ public class ImgdecClient{ System.err.println("IOException: " + e); } - return cid; + return id; } public static void read_stream( DataInputStream is, byte []stream, int length) diff --git a/applications/jpip/opj_client/opj_viewer/src/JPIPHttpClient.java b/applications/jpip/opj_client/opj_viewer/src/JPIPHttpClient.java index 466370b6..cfd3db4c 100644 --- a/applications/jpip/opj_client/opj_viewer/src/JPIPHttpClient.java +++ b/applications/jpip/opj_client/opj_viewer/src/JPIPHttpClient.java @@ -77,45 +77,57 @@ public class JPIPHttpClient public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid) { - return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false); + return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false); } public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid) { - return requestViewWindow( null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false); + return requestViewWindow( null, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false); } public byte[] requestViewWindow( String target, int reqfw, int reqfh) { - return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, false); + return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, false); } public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew) { if( cid == null) // 1 channel allocation only - return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew); + return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew); + else + return null; + } + + public byte[] requestViewWindow( String target, String reqtid, int reqfw, int reqfh, boolean reqcnew) + { + if( cid == null) // 1 channel allocation only + return requestViewWindow( target, reqtid, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew); else return null; } public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh) { - return requestViewWindow( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false); + return requestViewWindow( target, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false); } public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew) { - return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew); + return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew); } - public byte[] requestViewWindow( String target, - int reqfw, int reqfh, - int reqrx, int reqry, - int reqrw, int reqrh, - String reqcid, boolean reqcnew) + public byte[] requestViewWindow( String target, + String reqtid, + int reqfw, int reqfh, + int reqrx, int reqry, + int reqrw, int reqrh, + String reqcid, boolean reqcnew) { - String urlstring = const_urlstring( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew); + if( reqtid != null) + tid = reqtid; + + String urlstring = const_urlstring( target, reqtid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew); return GETrequest( urlstring); } @@ -151,7 +163,14 @@ public class JPIPHttpClient Map> headers = urlconn.getHeaderFields(); java.util.List hvaluelist; - + + String status = headers.get(null).get(0); + + System.err.println( status); + if( !status.contains("OK")) + System.err.println( headers.get("Reason")); + System.err.println( headers.get("Content-type")); + if(( hvaluelist = headers.get("JPIP-fsiz")) != null){ String hvalueline = hvaluelist.get(0); fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue(); @@ -242,7 +261,8 @@ public class JPIPHttpClient return jpipstream; } - private String const_urlstring( String target, + private String const_urlstring( String target, + String reqtid, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, @@ -258,6 +278,11 @@ public class JPIPHttpClient urlstring = urlstring.concat( "&"); urlstring = urlstring.concat( "target=" + target); } + if( reqtid != null){ + if( !urlstring.endsWith("?")) + urlstring = urlstring.concat( "&"); + urlstring = urlstring.concat( "tid=" + reqtid); + } if( reqfw != -1 && reqfh != -1){ if( !urlstring.endsWith("?")) urlstring = urlstring.concat( "&"); diff --git a/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110824.jar b/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110825.jar similarity index 63% rename from applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110824.jar rename to applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110825.jar index b5ad639d..4028b664 100644 Binary files a/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110824.jar and b/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110825.jar differ diff --git a/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces.jar b/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces.jar index 0362316b..0f5d3dc9 120000 --- a/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces.jar +++ b/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces.jar @@ -1 +1 @@ -opj_viewer_xerces-20110824.jar \ No newline at end of file +opj_viewer_xerces-20110825.jar \ No newline at end of file diff --git a/applications/jpip/opj_server/Makefile.am b/applications/jpip/opj_server/Makefile.am index acc635fc..9fa75b79 100644 --- a/applications/jpip/opj_server/Makefile.am +++ b/applications/jpip/opj_server/Makefile.am @@ -9,7 +9,8 @@ opj_server_CPPFLAGS = \ -I$(top_srcdir)/applications/jpip/libopenjpip \ -I$(top_builddir)/applications/jpip/libopenjpip \ @FCGI_CFLAGS@ \ --DSERVER +-DSERVER \ +-DQUIT_SIGNAL=\"quitJPIP\" opj_server_CFLAGS = opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm opj_server_SOURCES = \ diff --git a/applications/jpip/opj_server/Makefile.nix b/applications/jpip/opj_server/Makefile.nix index 238a686b..3df9a6ee 100644 --- a/applications/jpip/opj_server/Makefile.nix +++ b/applications/jpip/opj_server/Makefile.nix @@ -1,7 +1,7 @@ LIBDIR = ../libopenjpip LIBFNAME = $(LIBDIR)/libopenjpip_server.a -CFLAGS = -O3 -Wall -m32 -DSERVER -I$(LIBDIR) +CFLAGS = -O3 -Wall -m32 -DSERVER -DQUIT_SIGNAL=\"quitJPIP\" -I$(LIBDIR) LDFLAGS = -L$(LIBDIR) -lm -lfcgi -lopenjpip_server ALL = opj_server diff --git a/applications/jpip/opj_server/opj_server.c b/applications/jpip/opj_server/opj_server.c index 93fffc7e..936b54ce 100644 --- a/applications/jpip/opj_server/opj_server.c +++ b/applications/jpip/opj_server/opj_server.c @@ -55,6 +55,9 @@ #include "imgreg_manager.h" #include "msgqueue_manager.h" +#ifndef QUIT_SIGNAL +#define QUIT_SIGNAL "quitJPIP" +#endif #ifdef SERVER #include "fcgi_stdio.h" @@ -102,6 +105,9 @@ int main(void) #ifdef SERVER query_string = getenv("QUERY_STRING"); #endif //SERVER + + if( strcmp( query_string, QUIT_SIGNAL) == 0) + break; fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n"); @@ -130,6 +136,8 @@ int main(void) delete_msgqueue( &msgqueue); } + + fprintf( FCGI_stderr, "JPIP server terminated by a client request\n"); delete_sessionlist( &sessionlist); delete_targetlist( &targetlist); @@ -216,9 +224,11 @@ bool parse_JPIPrequest( query_param_t query_param, session_param_t *cursession = NULL; channel_param_t *curchannel = NULL; - if( !identify_target( query_param, targetlist, &target)) - return false; - + if( query_param.target[0] != '\0' || query_param.tid[0] != '\0'){ + if( !identify_target( query_param, targetlist, &target)) + return false; + } + if( query_param.cid[0] != '\0'){ if( !associate_channel( query_param, sessionlist, &cursession, &curchannel)) return false; @@ -241,32 +251,30 @@ bool parse_JPIPrequest( query_param_t query_param, bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target) { + if( query_param.tid[0] !='\0' && strcmp( query_param.tid, "0") != 0 ){ + if( query_param.cid[0] != '\0'){ + fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n"); + fprintf( FCGI_stdout, "Status: 400\r\n"); + return false; + } + if( ( *target = search_targetBytid( query_param.tid, targetlist))) + return true; + } + if( query_param.target[0] !='\0') if( !( *target = search_target( query_param.target, targetlist))) if(!( *target = gene_target( targetlist, query_param.target))) return false; - if( query_param.tid[0] !='\0'){ - if( strcmp( query_param.tid, "0") != 0 ){ - if( query_param.cid[0] != '\0'){ - fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n"); - fprintf( FCGI_stdout, "Status: 400\r\n"); - return false; - } - if( !( *target = search_targetBytid( query_param.tid, targetlist))) - return false; - } - else{ - if( *target) - fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid); - else{ - fprintf( FCGI_stdout, "Reason: target not specified\r\n"); - fprintf( FCGI_stdout, "Status: 400\r\n"); - return false; - } - } + if( *target){ + fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid); + return true; + } + else{ + fprintf( FCGI_stdout, "Reason: target not found\r\n"); + fprintf( FCGI_stdout, "Status: 400\r\n"); + return false; } - return true; } bool associate_channel( query_param_t query_param,