Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /apps/web/imgsrv/imgsrv.c [9d6280] .. [45d5e8] Maximize Restore

  Switch to side-by-side view

--- a/apps/web/imgsrv/imgsrv.c
+++ b/apps/web/imgsrv/imgsrv.c
@@ -18,6 +18,9 @@
 *! -----------------------------------------------------------------------------**
 *!
 *!  $Log: imgsrv.c,v $
+*!  Revision 1.4  2009/10/12 19:20:23  elphel
+*!  Added "Content-Disposition" support to suggest filenames to save images
+*!
 *!  Revision 1.3  2009/02/25 17:47:51  spectr_rain
 *!  removed deprecated dependency
 *!
@@ -163,12 +166,13 @@
 
 const char url_args[]="This server supports sequence of commands entered in the URL (separated by \"/\", case sensitive )\n"
                       "executing them from left to right as they appear in the URL\n"
-                      "img -      send image at the current pointer (if it is first command - use last acquired image, if none availabe - send 1x1 gif)\n"
-                      "bimg -     same as above, but save the whole image in the memory before sending - useful to avoid overruns with slow connection \n"
-                      "mimg[n] -  send images as a multipart JPEG (all commands after will be ignored), possible to specify optional fps reduction\n"
-                      "           i.e. mimg4 - skip 3 frames for each frame output (1/4 fps) \n"
-                      "bmimg[n] - same as above, buffered\n"
-                      "pointers - send XML-formatted data about frames available in the camera circular buffer)\n\n"
+                      "img -         send image at the current pointer (if it is first command - use last acquired image, if none availabe - send 1x1 gif)\n"
+                      "bimg -        same as above, but save the whole image in the memory before sending - useful to avoid overruns with slow connection \n"
+                      "simg, sbimg - similar to img, bimg but will imemdiately suggest to save instead of opening image in the browser\n"
+                      "mimg[n] -     send images as a multipart JPEG (all commands after will be ignored), possible to specify optional fps reduction\n"
+                      "              i.e. mimg4 - skip 3 frames for each frame output (1/4 fps) \n"
+                      "bmimg[n] -    same as above, buffered\n"
+                      "pointers -    send XML-formatted data about frames available in the camera circular buffer)\n\n"
                       "Any of the 5 commands above can appear only once in the URL string, the second instance will be ignored. If none of the 5\n"
                       "are present in the URL 1x1 pixel gif will be returned to the client after executing the URL command.\n\n"
                       "torp -   set frame pointer to global read pointer, maintained by the camera driver. If frame at that pointer\n"
@@ -185,7 +189,8 @@
                       "save   - save current frame pointer as a global read pointer that holds it values between server requests.\n"
                       "         This pointer is shared between all the clients and applications that use it.\n"
                       "wait   - Wait until there will be a frame at current pointer ready\n";
-int  sendImage (int bufferImageData, int fd_circ, int use_Exif);
+//int  sendImage(int bufferImageData, int fd_circ, int use_Exif);
+int  sendImage(int bufferImageData, int fd_circ, int use_Exif, int saveImage);
 void sendBuffer(void * buffer, int len);
 void listener_loop(int port);
 void errorMsgXML(char * msg);
@@ -660,7 +665,7 @@
 //! read pointer in fd_circ should be at the start of the frame to be sent
 //! mmap will be opened in this function
 
-int  sendImage (int bufferImageData, int fd_circ, int use_Exif) {
+int  sendImage(int bufferImageData, int fd_circ, int use_Exif, int saveImage) {
    const char HeadFileName[]="/dev/jpeghead";
    const char ExifFileName[]="/dev/exif_exif";
    int  exifDataSize=0;
@@ -759,6 +764,9 @@
        close(fd_exif);
    }
    printf("Content-Type: image/jpeg\n");
+   if (saveImage) printf("Content-Disposition: attachment; filename=\"elphelimg_%ld.jpeg\"\n",frame_params.timestamp_sec); /// does not open, asks for filename to save
+   else           printf("Content-Disposition: inline; filename=\"elphelimg_%ld.jpeg\"\n",frame_params.timestamp_sec);  /// opens in browser, asks to save on right-click
+
    if (bufferImageData) { /*! Buffer the whole file before sending over the network to make sure it will not be corrupted if the circular buffer will be overrun) */
      l=head_size+exifDataSize;
 /*! JPEG image data may be split in two segments (rolled over buffer end) - process both variants */
@@ -822,6 +830,7 @@
    int this_p; //! current frame pointer (bytes)
    int rslt;
    int buf_images=0;
+   int suggest_save_images=0;
    char buf [1024];
    int len=0;
    char * cp, *cp1, *cp2;
@@ -899,7 +908,7 @@
 //!if the first caracter is digit,it is a file pointer
         if (strchr("0123456789",cp1[0])) {
           this_p= lseek(fd_circ,strtol(cp1, NULL, 10),SEEK_SET);
-        } else if ((strcmp(cp1, "img")==0) || (strcmp(cp1, "bimg")==0)) {
+        } else if ((strcmp(cp1, "img")==0) || (strcmp(cp1, "bimg")==0) || (strcmp(cp1, "simg")==0) || (strcmp(cp1, "sbimg")==0)) {
           if (sent2socket>0) break; //! image/xmldata was already sent to socket, ignore
           if (lseek(fd_circ,LSEEK_CIRC_READY,SEEK_END)<0) //! here passes OK, some not ready error is later, in sendimage (make it return different numbers)
             rslt=out1x1gif();
@@ -908,8 +917,9 @@
            printf("Server: Elphel Imgsrv\n");
            printf("Expires: 0\n");
            printf("Pragma: no-cache\n");
-           buf_images= (strcmp(cp1, "img")==0)?0:1;
-           rslt=sendImage (buf_images, fd_circ, exif_enable); //! verify driver that file pointer did not move
+           buf_images= ((strcmp(cp1, "img")==0) || (strcmp(cp1, "simg")==0))?0:1;
+           suggest_save_images=((strcmp(cp1, "simg")==0) || (strcmp(cp1, "sbimg")==0))?1:0;
+           rslt=sendImage(buf_images, fd_circ, exif_enable, suggest_save_images); //! verify driver that file pointer did not move
           }
           sent2socket=1;
           if (rslt<0) {
@@ -927,7 +937,6 @@
           if (lseek(fd_circ,LSEEK_CIRC_READY,SEEK_END)<0) //! here passes OK, some not ready error is later, in sendimage (make it return different numbers)
             rslt=out1x1gif();
           else {
-//int  sendImage (int bufferImageData, int fd_circ, int use_Exif)
 //TODO:
            buf_images= (strncmp(cp1, "mimg",4)==0)?0:1;
            cp2=cp1+(buf_images?5:4);
@@ -942,7 +951,7 @@
            rslt=0;
            while (rslt>=0) {
              printf("\n--ElphelMultipartJPEGBoundary\n");
-             rslt=sendImage (buf_images, fd_circ, exif_enable); //! verify driver that file pointer did not move
+             rslt=sendImage(buf_images, fd_circ, exif_enable, 0); //! verify driver that file pointer did not move
              fflush(stdout);
              if (rslt>=0) for (skip=0;skip<slow;skip++) {
                this_p=lseek(fd_circ,LSEEK_CIRC_NEXT, SEEK_END);