Example #1
0
char *dateHuman(char *a, char *b, char *c, const char *LOCAL_no_date_set) {

    // This will need to be converted, to use current users 'lang' LOCALE

    char *m;

    if( 0 != strcmp(a, "NULL") && 0 != strcmp(b, "NULL") && 0 != strcmp(c, "NULL")) {
        if(strlen(b) == 1) {
            m = o_strdup("0");
            conCat(&m, b);
            free(b);
            b = m;
        }
        if(strlen(c) == 1) {
            m = o_strdup("0");
            conCat(&m, c);
            free(c);
            c = m;
        }
        conCat(&a, "/");
        conCat(&a, b);
        conCat(&a, "/");
        conCat(&a, c);
        free(b);
        free(c);
        return a;
    }
    else {
        free(a);
        free(b);
        free(c);
        return o_strdup(LOCAL_no_date_set);
    }
}
Example #2
0
void o_concatf(char **mainStr, const char *fmt, ...) {

    va_list inargs;
    char *str;

    va_start(inargs, fmt);
    str = i_printf(fmt, inargs);
    va_end(inargs);

    conCat(mainStr, str);
    free(str);

}
Example #3
0
void addFileExt(char **fname, int ftype) {

    char *ext;

    if(ftype == SCAN_FILETYPE) ext = o_strdup(".jpg");
    else if(ftype == PDF_FILETYPE) ext = o_strdup(".pdf");
    else if(ftype == ODF_FILETYPE) ext = o_strdup(".odt");
    else if(ftype == JPG_FILETYPE) ext = o_strdup(".jpg");
    else ext = o_strdup(".WILLNEVERHAPPEN");

    conCat(fname, ext);
    free(ext);
}
Example #4
0
void xmlAllNodeGetContent(xmlNode *parent, char **str) {

  xmlNode *node = parent->children; //childs;
  char *text;

  while(node != 0) {
    if (node->type == XML_TEXT_NODE) {
      text = o_printf("%s ", (char *)xmlNodeGetContent(node));
      conCat(str, text);
      free(text);
    }
    xmlAllNodeGetContent(node, str);
    node = node->next;
  }
}
Example #5
0
extern void log_option (SANE_Int index, const SANE_Option_Descriptor *option) {
    char *string;
    SANE_Word i;
    SANE_Int cap;
    
    string = o_strdup("");
    o_concatf (&string, "Option %d:", index);
    
    if (option->name)    
        o_concatf (&string, " name='%s'", option->name);
    
    if (option->title)
        o_concatf (&string, " title='%s'", option->title);

    switch (option->type) {
    case SANE_TYPE_BOOL:
        conCat(&string, " type=bool");
        break;
    case SANE_TYPE_INT:
        conCat(&string, " type=int");
        break;
    case SANE_TYPE_FIXED:
        conCat(&string, " type=fixed");        
        break;
    case SANE_TYPE_STRING:
        conCat(&string, " type=string");        
        break;
    case SANE_TYPE_BUTTON:
        conCat(&string, " type=button");        
        break;
    case SANE_TYPE_GROUP:
        conCat(&string, " type=group");
        break;
    default:
        o_concatf (&string, " type=%d", option->type);
        break;
    }
    
    o_concatf (&string, " size=%d", option->size);

    switch (option->unit) {
    case SANE_UNIT_NONE:
        break;
    case SANE_UNIT_PIXEL:
        conCat(&string, " unit=pixels");
        break;
    case SANE_UNIT_BIT:
        conCat(&string, " unit=bits");
        break;
    case SANE_UNIT_MM:
        conCat(&string, " unit=mm");
        break;
    case SANE_UNIT_DPI:
        conCat(&string, " unit=dpi");
        break;
    case SANE_UNIT_PERCENT:
        conCat(&string, " unit=percent");
        break;
    case SANE_UNIT_MICROSECOND:
        conCat(&string, " unit=microseconds");
        break;
    default:
        o_concatf (&string, " unit=%d", option->unit);
        break;
    }

    switch (option->constraint_type) {
    case SANE_CONSTRAINT_RANGE:
        if (option->type == SANE_TYPE_FIXED)
            o_concatf (&string, " min=%f, max=%f, quant=%d",
                                    SANE_UNFIX (option->constraint.range->min), SANE_UNFIX (option->constraint.range->max),
                                    option->constraint.range->quant);
        else
            o_concatf (&string, " min=%d, max=%d, quant=%d",
                                    option->constraint.range->min, option->constraint.range->max,
                                    option->constraint.range->quant);
        break;
    case SANE_CONSTRAINT_WORD_LIST:
        conCat(&string, " values=[");
        for (i = 0; i < option->constraint.word_list[0]; i++) {
            if (i != 0)
                conCat(&string, ", ");
            if (option->type == SANE_TYPE_INT)
                o_concatf (&string, "%d", option->constraint.word_list[i+1]);
            else
                o_concatf (&string, "%f", SANE_UNFIX (option->constraint.word_list[i+1]));
        }
        conCat(&string, "]");
        break;
    case SANE_CONSTRAINT_STRING_LIST:
        conCat(&string, " values=[");
        for (i = 0; option->constraint.string_list[i]; i++) {
            if (i != 0)
                conCat(&string, ", ");
            o_concatf (&string, "\"%s\"", option->constraint.string_list[i]);
        }
        conCat(&string, "]");
        break;
    default:
        break;
    }
    
    cap = option->cap;
    if (cap) {
        struct {
            SANE_Int cap;
            const char *name;
        } caps[] = {
            { SANE_CAP_SOFT_SELECT,     "soft-select"},
            { SANE_CAP_HARD_SELECT,     "hard-select"},
            { SANE_CAP_SOFT_DETECT,     "soft-detect"},
            { SANE_CAP_EMULATED,        "emulated"},
            { SANE_CAP_AUTOMATIC,       "automatic"},
            { SANE_CAP_INACTIVE,        "inactive"},
            { SANE_CAP_ADVANCED,        "advanced"},
            { 0,                        NULL}
        };
        int i, n = 0;
        
        conCat(&string, " cap=");
        for (i = 0; caps[i].cap > 0; i++) {
            if (cap & caps[i].cap) {
                cap &= ~caps[i].cap;
                if (n != 0)
                    conCat(&string, ",");
                conCat(&string, caps[i].name);
                n++;
            }
        }
        /* Unknown capabilities */
        if (cap) {
            if (n != 0)
                conCat(&string, ",");
            o_concatf (&string, "%x", cap);
        }
    }

    o_log(DEBUGM, "%s", string);
    free(string);

//    if (option->desc)
//      o_log(DEBUGM, "  Description: %s", option->desc);
}
Example #6
0
char *uploadfile(char *filename, char *lookForSimilar, char *lang) {

#ifndef CAN_MAGIC
  o_log(ERROR, "Unable to determin the file type, aborting.");
  return NULL;
#else

  int width = 0, height = 0, itype = PLACE_HOLDER;
  char *final_filename, *ocrText = NULL, *tmp;
#ifdef CAN_PDF
  char *thumbext = NULL;
#else
#ifdef CAN_READODF
  char *thumbext = NULL;
#endif /* CAN_READODF */
#endif /* CAN_PDF */
  char *docid;
  char *ftype;
  char *datafile;
  char *thumbfile = NULL;
  PIX *pix;

  datafile = o_printf("/tmp/%s.dat", filename);
  magic_t cookie = magic_open(MAGIC_MIME_TYPE);
  magic_load( cookie, NULL );
  const char *t = magic_file( cookie, datafile );
  ftype = o_strdup( t );
  o_log( ERROR, "Uploaded file looks to be of type: %s", ftype );
  magic_close( cookie );

  // --------------------------------------
  if( 0 == strcmp("application/pdf", ftype) ) {
    itype = PDF_FILETYPE;
#ifdef CAN_PDF
    thumbfile = o_printf("/tmp/%s.thumb", filename);
    ocrText = parse_pdf( datafile, thumbfile ); // pdf_plug.cc [create thumbnail and return body text] 
    thumbext = o_strdup("jpg");
#endif /* CAN_PDF */
    o_log( INFORMATION, "Processed PDF");
  }

  // --------------------------------------
  else if( 0 == strcmp("application/vnd.oasis.opendocument.text", ftype) ) {
    itype = ODF_FILETYPE;
#ifdef CAN_READODF
    thumbfile = o_printf("/tmp/%s.thumb", filename);
    get_odf_Thumb( datafile, thumbfile );
    ocrText = get_odf_Text( datafile ); // odf_plug.c 
    thumbext = o_strdup("png");
#endif /* CAN_READODF */
    o_log( INFORMATION, "Processed ODF doc");
  }

  // --------------------------------------
  else if( 0 == strcmp("image/jpeg", ftype) ) {
    itype = JPG_FILETYPE;
#ifdef CAN_OCR
    PIX *pix_l;
    if ( ( pix_l = pixRead( datafile ) ) == NULL) {
      o_log(ERROR, "Could not load the image data into a PIX");
      return NULL;
    }
    int depth;
    pixGetDimensions( pix_l, &width, &height, &depth );
    o_log(INFORMATION, "Convertion process: Loaded (depth: %d)", depth );
    pix = pixScaleRGBToGrayFast( pix_l, 1, COLOR_GREEN );
    pixDestroy( &pix_l );
    if (pix == NULL ) {
      o_log(ERROR,"Conversion process failed pixScaleRGBToGrayFast! skip ocr");
    }
    else {
      o_log(INFORMATION, "Convertion process: Reduced depth to %d", pixGetDepth(pix));
      ocrText = getTextFromImage(pix, 0, "eng");
    }
#endif /* CAN_OCR */
    o_log( INFORMATION, "Processed JPG doc");
  }

  // --------------------------------------
  else {
    free( ftype );
    free( datafile );
    o_log(ERROR, "unknown file type.");
    return NULL;
  }
  free( ftype );

  // Set a default OCR text string
  if( ocrText == NULL ) {
    ocrText = o_strdup( getString("LOCAL_ocr_default_text", lang ) );
  }

  // Save the record to the DB
  o_log(DEBUGM, "Saving doc import record");
  docid = addNewFileDoc(itype, width, height, ocrText); // ocrText get freed in this method

  // Move the main datafile to the file store location
  final_filename = o_printf("%s/scans/%s", BASE_DIR, docid); // none image imported docs, are stored with no "_x" postfix.
  if( itype == JPG_FILETYPE ) {
    conCat(&final_filename, "_1");
  }
  addFileExt(&final_filename, itype);

  fcopy(datafile, final_filename);
  o_log( DEBUGM, "Moved data file");
  // The original file will be unlinked by the HTTPD process
  free(datafile);

  // Move any thumbnail image to the file store location
  if( thumbfile ) {
    free(final_filename); // This currently holds the main PDG or ODF file.
    final_filename = o_printf("%s/scans/%s_thumb.%s", BASE_DIR, docid, thumbext); // any thumbnails are postfixed with "_thumb"
    fcopy(thumbfile, final_filename);
    o_log( DEBUGM, "Moved thumbnail file");
    unlink(thumbfile);
    free(thumbfile);
    free(thumbext);

#ifdef CAN_PHASH
    o_log( DEBUGM, "About to perform pHash on file");
    unsigned long long hash = getImagePhash_fn( final_filename );
    savePhash( atoi(docid), hash );
#endif /* CAN_PHASH */
  }
  else {
#ifdef CAN_PHASH
    o_log( DEBUGM, "About to perform pHash on pix");
    unsigned long long hash = getImagePhash_px( pix );
    savePhash( atoi(docid), hash );
#endif /* CAN_PHASH */
    pixDestroy( &pix );
  }
  free(final_filename);

  // Should we look for a similar doc, on opening?
  char *findSim = "";
#ifdef CAN_PHASH
  if( lookForSimilar != (void *)NULL ) {
    findSim = "&findSimilar=1";
  }
#endif /*  CAN_PHASH */

  // Open the document for editing.
  tmp = o_printf("<html><HEAD><META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=/opendias/docDetail.html?docid=%s%s\"></HEAD><body></body></html>", docid, findSim);
  free(docid);

  return tmp;
#endif /* CAN_MAGIC */
}