void sll_destroy( struct simpleLinkedList *element ) { if( element && ( element != NULL ) ) { o_log(SQLDEBUG, "preparing to delete element: %x, with prev=%x, and next=%x", element, element->prev, element->next); sll_destroy( sll_getNext( element ) ); sll_delete( element ); } }
struct simpleLinkedList *sll_searchKeys( struct simpleLinkedList *element, const char *key ) { if( element && ( element != NULL ) ) { if( element->key && ( element->key != NULL ) && ( 0 == strcmp(element->key, key) ) ) { return element; } return sll_searchKeys( sll_getNext( element ), key ); } return NULL; }
// Delete session that have not been accessed since 'oldest_allowed' void clear_sessions_older_than( time_t oldest_allowed ) { struct simpleLinkedList *session = NULL; struct simpleLinkedList *sess_data = NULL; int session_expiration_count = 0; session = sll_findFirstElement( sessions ); while( session != NULL ) { struct simpleLinkedList *this_session = session; session = sll_getNext( session ); if( 0 == strcmp( this_session->key, "placeholder" ) ) continue; struct session_data *sessions_element = (struct session_data *)this_session->data; if( sessions_element->last_accessed < oldest_allowed ) { for( sess_data = sll_findFirstElement( sessions_element->session_container ) ; sess_data != NULL ; sess_data = sll_getNext( sess_data ) ) { free( sess_data->key ); free( sess_data->data ); } sll_destroy( sll_findFirstElement( sessions_element->session_container ) ); sessions_element->session_container = NULL; free( sessions_element ); this_session->data = NULL; o_log( DEBUGM, "Deleting session: %s", this_session->key ); free( this_session->key ); this_session->key = NULL; sll_delete( this_session ); session_expiration_count++; } } if( session_expiration_count >= 1 ) { o_log( DEBUGM, "Expired %d sessions", session_expiration_count); } }
extern char *internalGetScannerDetails(char *device, char *lang) { char *answer = NULL; SANE_Status status; char *deviceList = o_strdup("");; int hlp = 0, resolution = 300, minRes=50, maxRes=50, phashAvailable=0; char *resolution_s, *maxRes_s, *minRes_s; SANE_Handle *openDeviceHandle; o_log(DEBUGM, "sane_open of \"%s\"", device); status = sane_open (device, (SANE_Handle)&openDeviceHandle); if(status != SANE_STATUS_GOOD) { o_log(ERROR, "Could not open: '%s' with error: %s", device, sane_strstatus(status)); free(deviceList); return NULL; } // // Find resolution ranges // for (hlp = 0; hlp < 9999; hlp++) { const SANE_Option_Descriptor *sod; sod = sane_get_option_descriptor (openDeviceHandle, hlp); if (sod == NULL) break; // Just a placeholder if (sod->type == SANE_TYPE_GROUP || sod->name == NULL || hlp == 0) continue; if ( 0 == strcmp(sod->name, SANE_NAME_SCAN_RESOLUTION) ) { // Some kind of sliding range if (sod->constraint_type == SANE_CONSTRAINT_RANGE) { o_log(DEBUGM, "Resolution setting detected as 'range'"); // Fixed resolution if (sod->type == SANE_TYPE_FIXED) maxRes = (int)SANE_UNFIX (sod->constraint.range->max); else maxRes = sod->constraint.range->max; } // A fixed list of options else if (sod->constraint_type == SANE_CONSTRAINT_WORD_LIST) { int lastIndex = sod->constraint.word_list[0]; o_log(DEBUGM, "Resolution setting detected as 'word list': lastIndex = %d",lastIndex); // maxRes = sod->constraint.word_list[lastIndex]; // resolution list cannot be treated as low to high ordered list // remark: impl capability to select scan resolution in webInterface int n=0; maxRes = 0; for (n=1; n<=lastIndex; n++ ) { o_log(DEBUGM, "index results %d --> %d", n ,(int)sod->constraint.word_list[n]); if ( maxRes < sod->constraint.word_list[n] ) { maxRes=sod->constraint.word_list[n]; } } } break; // we've found our resolution - no need to search more } } o_log(DEBUGM, "Determined max resultion to be %d", maxRes); // Define a default if(resolution >= maxRes) resolution = maxRes; if(resolution <= minRes) resolution = minRes; o_log(DEBUGM, "sane_cancel"); sane_cancel(openDeviceHandle); o_log(DEBUGM, "sane_close"); sane_close(openDeviceHandle); // // What languages can we OCR for? // char *availableLangs = o_strdup(""); #ifdef CAN_OCR struct simpleLinkedList *languages = getOCRAvailableLanguages(); while (languages != NULL ) { if ( checkOCRLanguage( languages->data ) == 0 ) { o_concatf(&availableLangs, "<lang>%s</lang>", languages->data); } languages = sll_getNext(languages); } sll_destroy( languages ); #endif /* CAN_OCR */ // // Can we give the option of doing 'find simmilar'? // #ifdef CAN_PHASH phashAvailable = 1; #endif /* CAN_PHASH */ // Build Reply // resolution_s = itoa(resolution,10); maxRes_s = itoa(maxRes,10); minRes_s = itoa(minRes,10); o_concatf(&deviceList, "<Resolution><max>%s</max><min>%s</min><default>%s</default></Resolution><OCRLanguages>%s</OCRLanguages><phash>%d</phash>", maxRes_s, minRes_s, resolution_s, availableLangs, phashAvailable); free(maxRes_s); free(minRes_s); free(resolution_s); free(availableLangs); // The escaped string placeholder will be interprited in the sane dispatcher client answer = o_printf("<?xml version='1.0' encoding='utf-8'?>\n<Response><ScannerDetails>%s</ScannerDetails></Response>", deviceList); free(deviceList); return answer; }