int main(int argc, char **argv) { URL_FILE *handle; char buffer[BUFSIZE]; if(argc > 1) strcpy(BASE,argv[1]); else { fprintf(stderr, "Usage: %s BaseURL\n",argv[0]); exit(1); } handle = url_fopen(BASE, "r"); if (!handle) { fprintf(stderr,"couldn't url_fopen() %s\n", BASE); return 2; } while(!url_feof(handle)) { url_fgets(buffer,sizeof(buffer),handle); strlower(buffer); fputs(buffer,stdout); char *cur, link[BUFSIZE], full_link[BUFSIZE]; cur = buffer; while ((cur = nextURL(cur)) != NULL) { getURL(cur, link, BUFSIZE-1); normalise(link, full_link, BUFSIZE-1); printf("%s\n",full_link); cur += strlen(link); } } url_fclose(handle); return 0; }
void TileSocialProfile::parseFBPhotos(const CCURLRequest::RequestState state, const char *requestURL, const char *response, const int priority, const bool refreshing, const char *previousPhotoID) { // If we're refreshing, ignore any previous requests if( taggedPhotosRefreshing ) { if( refreshing == false ) { return; } if( previousPhotoID != NULL ) { return; } taggedPhotosRefreshing = false; taggedPhotos.deleteObjects(); } // If our download has failed, exit.. if( state < CCURLRequest::succeeded ) { DEBUGLOG( "Failed to download photos list\n" ); if( photosDownloadedCallback != NULL ) { photosDownloadedCallback->run(); } return; } CCList<PhotoData> downloadedPhotoData; json_error_t error; json_t *root = json_loads( response, 0, &error ); if( root ) { { json_t *jsonData = json_object_get( root, "data" ); if( json_is_array( jsonData ) ) { const uint length = json_array_size( jsonData ); for( uint i=0; i<length; ++i ) { json_t *jsonObject = json_array_get( jsonData, i ); json_t *jsonPhotoID = json_object_get( jsonObject, "id" ); json_t *jsonThumbnailURL = json_object_get( jsonObject, "picture" ); json_t *jsonPhotoURL = json_object_get( jsonObject, "source" ); if( jsonPhotoID == NULL || jsonThumbnailURL == NULL || jsonPhotoURL == NULL ) { continue; } const char *jsonStringPhotoID = json_string_value( jsonPhotoID ); const char *jsonStringThumbnailURL = json_string_value( jsonThumbnailURL ); const char *jsonStringPhotoURL = json_string_value( jsonPhotoURL ); ASSERT( jsonStringPhotoID != NULL && jsonStringThumbnailURL != NULL && jsonStringPhotoURL != NULL ); downloadedPhotoData.add( new PhotoData( jsonStringPhotoID, jsonStringThumbnailURL, jsonStringPhotoURL ) ); } } } // Find the current index into our photos list int photoIndex = 0; if( previousPhotoID != NULL ) { for( int i=0; i<taggedPhotos.length; ++i ) { CCText &photoID = taggedPhotos.list[i]->photoID; if( CCText::Equals( photoID.buffer, previousPhotoID ) ) { photoIndex = i+1; break; } } } for( int i=0; i<downloadedPhotoData.length; ++i ) { PhotoData &downloadedData = *downloadedPhotoData.list[i]; bool found = false; if( photoIndex < taggedPhotos.length ) { CCText &downloadedPhotoID = downloadedData.photoID; CCText ¤tPhotoID = taggedPhotos.list[photoIndex]->photoID; if( CCText::Equals( currentPhotoID.buffer, downloadedPhotoID.buffer ) ) { found = true; } } if( found == false ) { PhotoData *newPhoto = new PhotoData( downloadedData.photoID.buffer, downloadedData.thumbnailURL.buffer, downloadedData.photoURL.buffer ); taggedPhotos.add( newPhoto ); taggedPhotos.reinsert( newPhoto, photoIndex ); // Load in these images in the background CCFBApi::RequestPhotoURL( this, downloadedData.photoID.buffer, downloadedData.thumbnailURL.buffer, true, 0 ); CCFBApi::RequestPhotoURL( this, downloadedData.photoID.buffer, downloadedData.photoURL.buffer, false, 0 ); } photoIndex++; } if( photosDownloadedCallback != NULL ) { photosDownloadedCallback->run(); } { json_t *jsonObject = json_object_get( root, "paging" ); //json_t *jsonPrevious = json_object_get( jsonObject, "previous" ); //const char *jsonStringPrevious = json_string_value( jsonPrevious ); json_t *jsonNext = json_object_get( jsonObject, "next" ); const char *jsonStringNext = json_string_value( jsonNext ); CCText url( jsonStringNext ); if( url.length > 0 ) { CCText currentURL( requestURL ); currentURL.splitBetween( currentURL, "until=", "&" ); CCText nextURL( url.buffer ); nextURL.splitBetween( nextURL, "until=", "&" ); if( CCText::Equals( currentURL.buffer, nextURL.buffer ) == false ) { CCFBApi::RequestFBURL( new FBPhotosCallback( this, priority, refreshing, downloadedPhotoData.last()->photoID.buffer ), url.buffer, priority, refreshing, 1.0f ); } else { DEBUGLOG( "TileSocial::Repeat URL %s \n", requestURL ); } } } json_decref( root ); } downloadedPhotoData.deleteObjectsAndList(); }