[trunk] Merge rev 1068 into trunk
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Fri, 2 Mar 2012 10:58:43 +0000 (10:58 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Fri, 2 Mar 2012 10:58:43 +0000 (10:58 +0000)
applications/jpip/CHANGES
applications/jpip/README
applications/jpip/doc/jpip_architect.png
applications/jpip/libopenjpip/cachemodel_manager.c
applications/jpip/libopenjpip/channel_manager.c
applications/jpip/libopenjpip/target_manager.c
applications/jpip/libopenjpip/target_manager.h
applications/jpip/mainpage.h
applications/jpip/util/opj_server.c

index e60bf58b779b022a8abd3d69dea1272e662ebb30..b5c2c791a5f3aa2075ab70289ee4c7f9f6d139da 100644 (file)
@@ -10,6 +10,7 @@ November 30, 2011
 
 November 16, 2011
 * [kaori] fixed opj_server execusion error (instant terminating) with autotool, cmake still need to be fixed
++ [kaori] new feature to target JP2 files from www (libcurl required)
 
 November 8, 2011
 ! [kaori] updated main page of doxygen
index 7e9514695883139346df9fe9c23a4cabc36c6028..dde8ddc70ae92e3b4e695debfd2f9d5a8e70ca8f 100644 (file)
@@ -1,5 +1,5 @@
 ========================================================================
-                    OpenJPIP software 2.0 ReadMe
+                    OpenJPIP software 2.1 ReadMe
 
 OpenJPEG:
 http://www.openjpeg.org
@@ -26,13 +26,14 @@ OpenJPIP software is an implementation of JPEG 2000 Part9: Interactivity tools,
 ( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html)
 The current implementation uses some results from the 2KAN project (http://www.2kan.org).
 
-First Version 2.0 covers:
+Version 2.1 covers:
  - JPT-stream (Tile) and JPP-stream (Precinct) media types
  - Session, channels, cache model managements
  - JPIP over HTTP, HTTP requests and TCP return
  - Indexing JPEG 2000 files
  - Embedding XML formatted metadata
  - Region Of Interest (ROI) requests
+ - Access to JP2 files with their URL
 
 ----------
 2. License
@@ -46,8 +47,8 @@ Neither the author, nor the university accept any responsibility for any kind of
 3. System requirements
 ----------
 
- - OpenJPEG library (currently assumes it is installed on the system => will not use the one built higher in the directory structure)
  - FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
+ - libcURL library
  - Java application launcher at client
 <Optional>
  - Xerces2 java XML parser on the client for accessing embedded image metadata (http://xerces.apache.org/xerces2-j)
@@ -106,7 +107,7 @@ Client:
     % java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [stateless/session] [jptstream/jppstream] [tcp/udp]
     ( The arguments 
       - http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
-      - JP2_filename.jp2 is the name of a JP2 file available on the server.
+      - path/filename.jp2 is the server local path or URL of a JP2 file
       - request type stateless for no caching, session (default) for caching
       - return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream
       - auxiliary return protocol, tcp or udp (udp is not implemented yet), if not given, return data is filled in http chunk
index 035a4b65e7a7446b649de57c2aedd8f0d6a772c4..5375bf91f1305181ddcddcd0ab2fe63b9a2446ee 100644 (file)
Binary files a/applications/jpip/doc/jpip_architect.png and b/applications/jpip/doc/jpip_architect.png differ
index 70b58c878a10566362fd80f664d3d24434e74ef3..62566268e44ffe3eedc367a57bf82230a83c7abf 100644 (file)
@@ -118,7 +118,7 @@ void print_cachemodel( cachemodel_param_t cachemodel)
 
   target = cachemodel.target;
   
-  fprintf( logstream, "target: %s\n", target->filename);
+  fprintf( logstream, "target: %s\n", target->targetname);
   fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
 
   fprintf( logstream, "\t tile part model:\n");
index a2620fe6e7ac34c944f08a88ee13370d5854d79f..240cdd9b297e4ce444b364eb9925a0c9041cda2b 100644 (file)
@@ -150,7 +150,7 @@ void print_allchannel( channellist_param_t *channellist)
 
   ptr = channellist->first;
   while( ptr != NULL){
-    fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->filename);
+    fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->targetname);
     ptr=ptr->next;
   }
 }
index e2f7627b97f2f3369cac16cdbe5f20e8a66ded42..d98576ecec90a5071d6448654fb44ae3ea58ecd8 100644 (file)
@@ -36,6 +36,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
+#include <curl/curl.h>
 #include "target_manager.h"
 
 #ifdef SERVER
@@ -64,24 +65,26 @@ targetlist_param_t * gene_targetlist()
 /**
  * open jp2 format image file
  *
- * @param[in] filename file name (.jp2)
- * @return             file descriptor
+ * @param[in]  filepath file name (.jp2)
+ * @param[out] tmpfname new file name if filepath is a URL
+ * @return              file descriptor
  */
-int open_jp2file( char filename[]);
+int open_jp2file( char filepath[], char tmpfname[]);
 
 target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
 {
   target_param_t *target;
   int fd;
   index_param_t *jp2idx;
+  char tmpfname[MAX_LENOFTID];
   static int last_csn = 0;
-
+  
   if( targetpath[0]=='\0'){
     fprintf( FCGI_stderr, "Error: exception, no targetpath in gene_target()\n");
     return NULL;
   }
 
-  if((fd = open_jp2file( targetpath)) == -1){
+  if((fd = open_jp2file( targetpath, tmpfname)) == -1){
     fprintf( FCGI_stdout, "Status: 404\r\n"); 
     return NULL;
   }
@@ -93,7 +96,7 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
 
   target = (target_param_t *)malloc( sizeof(target_param_t));
   snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
-  target->filename = strdup( targetpath); 
+  target->targetname = strdup( targetpath); 
   target->fd = fd;
 #ifdef SERVER
   if( tmpfname[0])
@@ -145,12 +148,12 @@ void delete_target( target_param_t **target)
 
   if( (*target)->codeidx)
     delete_index ( &(*target)->codeidx);
-
+  
 #ifndef SERVER
-  fprintf( logstream, "local log: target: %s deleted\n", (*target)->filename);
+  fprintf( logstream, "local log: target: %s deleted\n", (*target)->targetname);
 #endif
 
-  free( (*target)->filename);
+  free( (*target)->targetname);
 
   free(*target);
 }
@@ -193,7 +196,7 @@ void print_target( target_param_t *target)
   fprintf( logstream, "target:\n");
   fprintf( logstream, "\t tid=%s\n", target->tid);
   fprintf( logstream, "\t csn=%d\n", target->csn);
-  fprintf( logstream, "\t target=%s\n\n", target->filename);
+  fprintf( logstream, "\t target=%s\n\n", target->targetname);
 }
 
 void print_alltarget( targetlist_param_t *targetlist)
@@ -215,7 +218,7 @@ target_param_t * search_target( char targetname[], targetlist_param_t *targetlis
   
   while( foundtarget != NULL){
     
-    if( strcmp( targetname, foundtarget->filename) == 0)
+    if( strcmp( targetname, foundtarget->targetname) == 0)
       return foundtarget;
       
     foundtarget = foundtarget->next;
@@ -252,18 +255,26 @@ int open_jp2file( char filepath[], char tmpfname[])
     if( (fd = open_remotefile( filepath, tmpfname)) == -1)
       return -1;
   }
+  else{
+    tmpfname[0] = 0;
+    if( (fd = open( filepath, O_RDONLY)) == -1){
+      fprintf( FCGI_stdout, "Reason: Target %s not found\r\n", filepath);
+      return -1;
+    }
+  }
   // Check resource is a JP family file.
   if( lseek( fd, 0, SEEK_SET)==-1){
     close(fd);
-    fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filename);
+    fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filepath);
     return -1;
   }
   
   data = (char *)malloc( 12); // size of header
+
   if( read( fd, data, 12) != 12){
     free( data);
     close(fd);
-    fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filename);
+    fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filepath);
     return -1;
   }
     
@@ -271,10 +282,12 @@ int open_jp2file( char filepath[], char tmpfname[])
       *(data + 3) != 12 || strncmp (data + 4, "jP  \r\n\x87\n", 8)){
     free( data);
     close(fd);
-    fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filename);
+    fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filepath);
     return -1;
   } 
+
   free( data);
+
   return fd;
 }
 
index 0202006d61ce4050ebfa0be3d4ca88d336fa7ae9..28dc9ab0772c602807c716f4f861360bf89c6a1f 100644 (file)
@@ -137,9 +137,9 @@ void print_alltarget( targetlist_param_t *targetlist);
 
 
 /**
- * search a target by filename
+ * search a target by target name
  *
- * @param[in] targetname target filename
+ * @param[in] targetname target name
  * @param[in] targetlist target list pointer
  * @return               found target pointer
  */
index a3c4e0ac0557d33a4e82820c57cddde7c78f3d15..1ac921e751b7911d21496b79f26af06f05fa7fc6 100644 (file)
@@ -52,6 +52,7 @@
  * \section reqlibs Required libraries
  *  - OpenJPEG library
  *  - FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
+ *  - libcURL library
  *
  *  We tested this software with a virtual server running on the same Linux machine as the clients.
  *
index bd29fdfd8798dccff9e0da446b1388504f31cae3..a9db87d80050c180c55578eefba1634a33d513a2 100644 (file)
@@ -95,17 +95,18 @@ int main(void)
       
       qr = parse_querystring( query_string);
       
-      if( !(parse_status = process_JPIPrequest( server_record, qr)))
-       fprintf( FCGI_stderr, "Error: JPIP request failed\n");
-
+      parse_status = process_JPIPrequest( server_record, qr);
+      
 #ifndef SERVER
       local_log( true, true, parse_status, false, qr, server_record);
 #endif
             
       if( parse_status)
-       send_responsedata( server_record, qr);
-      else
+       send_responsedata( qr);
+      else{
        fprintf( FCGI_stderr, "Error: JPIP request failed\n");
+  fprintf( FCGI_stdout, "\r\n");
+    }
       
       end_QRprocess( server_record, &qr);
     }