/** * flickcurl_free_photos_list: * @photos_list: photos list object * * Destructor for photos list */ void flickcurl_free_photos_list(flickcurl_photos_list* photos_list) { FLICKCURL_ASSERT_OBJECT_POINTER_RETURN(photos_list, flickcurl_photos_list); if(photos_list->format) free(photos_list->format); if(photos_list->photos) flickcurl_free_photos(photos_list->photos); if(photos_list->content) free(photos_list->content); free(photos_list); }
/* * The photosets are filled dynamically based on which photosets are loaded * (it would be a waste to load all flickr info if not needed). * This method needs to be called in order to fill the photoset cache * with photo information. * Assumes there is a lock initiated */ static int check_photoset_cache(cached_photoset *cps) { flickcurl_photo **fp; unsigned int j; if(!cps) return FAIL; if(!(cps->photo_ht)) { return FAIL; } if(cps->set) { return SUCCESS; } pthread_rwlock_unlock(&cache_lock); /* Release the read lock and lock for writting */ pthread_rwlock_wrlock(&cache_lock); if(cps->set) { return SUCCESS; } /* Are we searching for photos in a photoset or not? */ if( !strcmp( cps->ci.id, "" ) ) { /* Get photos NOT in a photoset */ if(!(fp = flickcurl_photos_getNotInSet(fc, 0, 0, NULL, NULL, 0, "date_taken", -1, -1))) { return FAIL; } } else { /* Add the photos of the photoset into the cache */ if(!(fp = flickcurl_photosets_getPhotos(fc, cps->ci.id, "date_taken", 0, -1, -1))) { return FAIL; } } /* Add photos to photoset cache */ for(j = 0; fp[j]; j++) { cached_photo *cp; struct tm tm = {0}; char *title; char *id; title = fp[j]->fields[PHOTO_FIELD_title].string; id = fp[j]->id; /* Check if dirty version already exists in the database. */ if( (cp = g_hash_table_lookup( cps->photo_ht, title )) ) { if( !strcmp( cp->ci.id, id ) ) { continue; } } else if( (cp = g_hash_table_lookup( cps->photo_ht, id ) ) ) { if( !strcmp( cp->ci.id, id ) ) { continue; } else { /* TODO: Need to figure out what to do here. */ continue; } } if(!(cp = (cached_photo *)malloc(sizeof(cached_photo)))) { return FAIL; } cp->uri = flickcurl_photo_as_source_uri(fp[j], GET_PHOTO_SIZE); cp->ci.name = strdup(title); cp->ci.id = strdup(id); cp->ci.size = 1024; /* Trick so that file managers do not think file is empty... */ cp->ci.dirty = CLEAN; sscanf(fp[j]->fields[PHOTO_FIELD_dates_taken].string, "%4d-%2d-%2d %2d:%2d:%2d", &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday), &(tm.tm_hour), &(tm.tm_min), &(tm.tm_sec)); tm.tm_year = tm.tm_year - 1900; /* Years since 1900 */ tm.tm_mon--; /* Programmers start with 0... */ tm.tm_sec--; tm.tm_min--; tm.tm_hour--; cp->ci.time = mktime(&tm); /* Can't place empty or duplicate names into the hash table. If this is the case, use the photo id instead. */ if(cp->ci.name[0] == '\0' || g_hash_table_lookup(cps->photo_ht, cp->ci.name)) g_hash_table_insert(cps->photo_ht, strdup(cp->ci.id), cp); else g_hash_table_insert(cps->photo_ht, strdup(cp->ci.name), cp); } flickcurl_free_photos(fp); cps->ci.time = time(NULL); cps->ci.size = j; cps->set = CACHE_SET; return SUCCESS; }