Diff of /trunk/src/gcvote.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 159 by harbaum, Wed Nov 4 20:28:54 2009 UTC revision 160 by harbaum, Thu Nov 5 07:00:52 2009 UTC
# Line 237  static gboolean gcvote_result_handler(gp Line 237  static gboolean gcvote_result_handler(gp
237    return FALSE;    return FALSE;
238  }  }
239    
240    static void gcvotes_free(gcvote_t *votes) {
241      while(votes) {
242        gcvote_t *next = votes->next;
243        if(votes->id) g_free(votes->id);
244        g_free(votes);
245        votes = next;
246      }
247    }
248    
249  void gcvote_save(appdata_t *appdata, cache_t *cache, curl_mem_t *mem) {  void gcvote_save(appdata_t *appdata, cache_t *cache, curl_mem_t *mem) {
250    if(!mem->len || !mem->ptr) return;    if(!mem->len || !mem->ptr) return;
251    
# Line 324  static void *worker_thread(void *ptr) { Line 333  static void *worker_thread(void *ptr) {
333    
334    /* then cleanup the formpost chain */    /* then cleanup the formpost chain */
335    curl_formfree(formpost);    curl_formfree(formpost);
336    
337    printf("gcvote: worker thread done\n");    printf("gcvote: worker thread done\n");
338    gcvote_request_free(request);    gcvote_request_free(request);
339    
# Line 367  gcvote_request_t *gcvote_request(appdata Line 376  gcvote_request_t *gcvote_request(appdata
376    return request;    return request;
377  }  }
378    
379    vote_t *gcvote_restore(appdata_t *appdata, cache_t *cache) {
380      /* load data from disk */
381      char *filename = g_strdup_printf("%s%s/gcvote.xml",
382                                       appdata->image_path,
383                                       cache->id);
384    
385      printf("gcvote: trying to restore from %s\n", filename);
386    
387      /* no such file? */
388      if(!g_file_test(filename, G_FILE_TEST_EXISTS)) {
389        printf("gcvote: no such file\n");
390        free(filename);
391        return NULL;
392      }
393    
394      LIBXML_TEST_VERSION;
395      xmlDoc *doc = xmlReadFile(filename, NULL, 0);
396    
397      if(doc == NULL) {
398        printf("gcvote: error, could not parse file %s\n", filename);
399        free(filename);
400        return NULL;
401      }
402    
403      free(filename);
404    
405      /* in this case this will sure only return one result */
406      gcvote_t *votes = parse_doc(doc);
407    
408      if(!votes) {
409        printf("gcvote: error, no vote found\n");
410        free(filename);
411        return NULL;
412      }
413    
414      vote_t *vote = g_new0(vote_t, 1);
415      vote->quality = votes->quality;
416      vote->votes = votes->votes;
417    
418      printf("gcvote: found vote %d/%d\n", vote->quality, vote->votes);
419    
420      gcvotes_free(votes);
421    
422      return vote;
423    }

Legend:
Removed from v.159  
changed lines
  Added in v.160