--- mnogosearch-3.2.37/configure.in	2006-02-17 12:55:15.000000000 +0200
+++ mnogosearch-my/configure.in	2006-05-07 18:25:34.000000000 +0300
@@ -763,7 +763,36 @@
 [AC_MSG_RESULT([no])]
 )
 
+AC_MSG_CHECKING(for exif)
+AC_ARG_WITH(exif,
+[  --with-exif          enable exif support for JPG images],
+[
+  AC_DEFINE([EXIF], [1], [Define if you want exif support])
+  if test "$withval" = "yes"; then
+    dd="/usr /usr/local"
+  else
+    dd="$withval"
+  fi
 
+  for d in $dd; do
+    if test -f $d/include/libexif/exif-content.h; then
+      path=$d
+      break
+    fi
+  done
+
+  if test "$path" = ""; then
+    AC_MSG_RESULT(no)
+    AC_MSG_ERROR(Invalid exif directory - unable to find exif-content.h)
+  fi
+
+  AC_MSG_RESULT($path)
+  LIBS="$LIBS -L$path/lib -lexif -L$path/X11R6/lib -lfreetype -lz -lMagick -llcms -ltiff -lfreetype -ljpeg -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lpthread -lm"
+  CFLAGS="$CFLAGS -I$path/include/libexif"
+  AC_DEFINE([HAVE_LIBEXIF], [1], [Define if you want EXIF support])
+],
+[AC_MSG_RESULT([no])]
+)
 
 dnl Check for some DBMS backend
 dnl NOTE: we can use several different backend at the same time
--- mnogosearch-3.2.37/src/indexer.c	2006-02-10 14:29:27.000000000 +0200
+++ mnogosearch-my/src/indexer.c	2006-05-10 22:59:06.000000000 +0300
@@ -80,6 +80,10 @@
 #include "udm_id3.h"
 #include "udm_stopwords.h"
 #include "udm_wild.h"
+
+#include <libexif/exif-loader.h>
+#include <magick/ImageMagick.h>
+
 #ifdef HAVE_ZLIB
 #include "udm_store.h"
 #endif
@@ -1305,12 +1309,145 @@
   {
     UdmMP3Parse(Indexer,Doc);
   }
+  else if(!strncasecmp(real_content_type, "image/jpeg",10))
+  {
+    Image *image1,*image2,*img1,*img2;
+    ImageInfo image_info1;
+    ImageInfo image_info2;
+
+    ExceptionInfo e1;
+    ExceptionInfo e2;
+    int i,j;
+    /*
+     * Exif related code is mostly copy&paste from libexif sample code
+     */
+    ExifLoader *l;
+    ExifData *ed;
+    ExifLog *log = NULL;
+    char fname[1024]="/tmp/udmsearchexif.tmp";
+    FILE *f;
+
+    //UdmLog(Indexer,UDM_LOG_ERROR,"JPEG image, trying to recover thumbnail");
+    log = exif_log_new ();
+
+/*
+ * Try to read EXIF data from the file. 
+ * If there is no EXIF data, exit.
+ */
+    l = exif_loader_new ();
+    exif_loader_log (l, log);
+
+    exif_loader_write (l, Doc->Buf.content, Doc->Buf.size);
+
+
+    ed = exif_loader_get_data (l);
+    exif_loader_unref (l);
+    if (!ed) {
+#ifdef DEBUG
+        UdmLog(Indexer,UDM_LOG_ERROR,"'%s' does not "
+            "contain EXIF data!", fname);
+#endif
+	goto end_of_exif;
+    }
+
+    /* No thumbnail? Exit. */
+    if (!ed->data) {
+#ifdef DEBUG
+        UdmLog(Indexer,UDM_LOG_ERROR, "'%s' does not "
+            "contain a thumbnail!",
+            Doc->Buf.content);
+#endif
+        goto end_of_exif;
+    }
+
+    /* In this point we have thumbnail and it is loaded to buffer ed->data with size ed->size */
+    GetImageInfo(&image_info1);
+    GetImageInfo(&image_info2);
+    GetExceptionInfo(&e1);
+    GetExceptionInfo(&e2);
+   
+    image1=BlobToImage ( &image_info1,Doc->Buf.content, Doc->Buf.size,&e1);
+    image2=BlobToImage ( &image_info2,ed->data, ed->size,&e2);
+    if(!image1 || !image2) 
+	goto end_of_exif;
+    img1=ThumbnailImage(image1,30,30,&e1);
+    img2=ThumbnailImage(image2,30,30,&e2);
+    if(!img1 || !img2) 
+	goto end_of_exif;
+#ifdef DEBUG
+    UdmLog(Indexer,UDM_LOG_ERROR,"Images are equal? '%s'\n",IsImagesEqual(img1,img2)?"Yes":"No" );
+    UdmLog(Indexer,UDM_LOG_ERROR,"normalized_mean_error    %lf, images are %s\n",
+        img1->error.normalized_mean_error,
+        img1->error.normalized_mean_error > 0.01 ? "different":"similar");
+    /*
+    UdmLog(Indexer,UDM_LOG_ERROR,"normalized_maximum_error %lf\n",img1->error.normalized_maximum_error);
+    UdmLog(Indexer,UDM_LOG_ERROR,"mean_error_per_pixel     %lf\n",img1->error.mean_error_per_pixel);
+     */
+#else
+    IsImagesEqual(img1,img2);
+#endif
+    /*
+     * If normalized_mean_error is bigger than 0.05 or something like this, images are different
+     */
+
+    if(img1->error.normalized_mean_error > 0.01) {
+	    char buf[16*1024];
+	    f = fopen ("/home/tonu/public_html/exifresults.txt", "a");
+	    if (!f) {
+        	goto end_of_exif;
+	    }
+	    sprintf(buf,"%lf",img1->error.normalized_mean_error);
+	    fwrite (url, 1, strlen(url), f);
+	    fwrite (" ", 1, 1, f);
+	    fwrite (buf, 1, strlen(buf), f);
+	    fwrite ("\n", 1, 1, f);
+	    fclose (f);
+    }
+
+
+
+#ifdef TODO
+    UdmSQLQuery(db, NULL, "INSERT INTO exif "
+	"(url,normalized_mean_error,normalized_maximum_error,mean_error_per_pixel)"
+	" VALUES ('%s',%lf,%lf,%lf)",
+	Doc->CurURL,img1->error.normalized_mean_error,
+	img1->error.normalized_maximum_error,img1->error.mean_error_per_pixel);
+#endif
+    DestroyImages(image1);
+    DestroyImages(image2);
+
+    DestroyImages(img1);
+    DestroyImages(img2);
+    //DestroyImageInfo(&image_info);
+
+#ifdef IF_NEEDED
+    /* Save the thumbnail */
+    f = fopen (fname, "wb");
+    if (!f) {
+#ifdef __GNUC__
+    UdmLog(Indexer,UDM_LOG_ERROR,	
+	"Could not open '%s' for "
+	"writing (%m)!", fname);
+#else
+    UdmLog(Indexer,UDM_LOG_ERROR,
+        "Could not open '%s' for "
+	"writing (%s)!", fname,
+	strerror (errno));
+#endif
+	goto end_of_exif;
+    }
+    fwrite (ed->data, 1, ed->size, f);
+    fclose (f);
+    UdmLog(Indexer,UDM_LOG_ERROR, "Wrote file '%s'.", fname);
+#endif
+  }
   else
   {
     /* Unknown Content-Type  */
     UdmLog(Indexer,UDM_LOG_ERROR,"Unsupported Content-Type '%s'",real_content_type);
     UdmVarListReplaceInt(&Doc->Sections,"Status",UDM_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE);
   }
+end_of_exif:
   return result;
 }
 

