Project

General

Profile

0003-flickr-fix-ui-storage.patch

jean-luc Le Corre, 06/24/2019 10:07 AM

View differences:

src/imageio/storage/flickr.c
82 82
  GtkBox *create_box;                               // Create album options...
83 83
  GtkWidget *permission_list, *album_list;
84 84
  gboolean authenticated;
85
  char *user_token;
86
  char *user_token_secret;
87
  char *user_nsid;
88
  char *user_name;
85 89
  /* List of albums */
86 90
  _flickr_album_t **albums;
87 91
  /** Current Flickr context for the gui */
......
118 122
  g_free(ctx->album_summary);
119 123
  if(ctx->current_album != NULL)
120 124
  {
121
    free(ctx->current_album->id);
122
    free(ctx->current_album->title);
123
    free(ctx->current_album->summary);
124
    free(ctx->current_album);
125
    }
126
  curl_free(ctx->curl);
125
    g_free(ctx->current_album->id);
126
    g_free(ctx->current_album->title);
127
    g_free(ctx->current_album->summary);
128
    g_free(ctx->current_album);
129
  }
130
  g_free(ctx->user_token);
131
  g_free(ctx->user_token_secret);
132
  g_free(ctx->user_nsid);
133
  g_free(ctx->user_name);
134
  curl_easy_cleanup(ctx->curl);
127 135
  g_free(ctx);
136
  ctx = NULL ;
128 137
}
129 138

  
130

  
131 139
static size_t curl_write_data_cb(void *ptr, size_t size, size_t nmemb, void *data)
132 140
{
133 141
  GString *string = (GString *)data;
......
135 143
  return size * nmemb;
136 144
}
137 145

  
146
static _flickr_api_context_t *_flickr_api_init(dt_storage_flickr_gui_data_t *ui) 
147
{
148
  _flickr_api_context_t *ctx = (_flickr_api_context_t *)g_malloc0(sizeof(_flickr_api_context_t));
149
  ctx->error_occured=FALSE;
150
  ctx->curl = curl_easy_init();
151
  curl_easy_setopt(ctx->curl, CURLOPT_VERBOSE, 0L);
152
  curl_easy_setopt(ctx->curl, CURLOPT_WRITEFUNCTION, curl_write_data_cb);
153
  curl_easy_setopt(ctx->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
154
  curl_easy_setopt(ctx->curl, CURLOPT_FOLLOWLOCATION, 1L);
155
  ctx->user_token = g_strdup(ui->user_token);
156
  ctx->user_token_secret = g_strdup(ui->user_token_secret);
157
  ctx->user_nsid = g_strdup(ui->user_nsid);
158
  ctx->user_name = g_strdup(ui->user_name);  
159
  ctx->needsReauthentication = FALSE;
160
  ctx->current_album = NULL;
161
  ctx->album_title = NULL;
162
  ctx->album_summary = NULL;
163
  return ctx ;
164
}
165

  
166

  
138 167
static char *getParameterValue(const char *parameter, const char *buffer)
139 168
{
140 169
  char value[128];
......
217 246
  curl_easy_setopt(ctx->curl, CURLOPT_URL, signed_checkUrl);
218 247
  curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, response);
219 248
  res = curl_easy_perform(ctx->curl);
220
  free(signed_checkUrl);
249
  g_free(signed_checkUrl);
221 250
  if (res == CURLE_OK)
222 251
  {
223 252
    parser = json_parser_new();
......
312 341
  char *flickr_user_token_secret = NULL;
313 342
  char *flickr_user_nsid = NULL;
314 343
  char *flickr_user_name = NULL;
315
  _flickr_api_context_t *ctx = (_flickr_api_context_t *)g_malloc0(sizeof(_flickr_api_context_t));
316
  ctx->error_occured=FALSE;
344
  _flickr_api_context_t *ctx = _flickr_api_init(ui) ;
317 345
  GString *response = g_string_new("");
318 346
  ctx->curl = curl_easy_init();
319 347
  curl_easy_setopt(ctx->curl, CURLOPT_VERBOSE, 0L);
......
321 349
  curl_easy_setopt(ctx->curl, CURLOPT_WRITEFUNCTION, curl_write_data_cb);
322 350
  curl_easy_setopt(ctx->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
323 351
  curl_easy_setopt(ctx->curl, CURLOPT_FOLLOWLOCATION, 1L);
324
  //curl_easy_setopt(ctx->curl, CURLOPT_TIMEOUT, 20L);
352
  curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, response);
325 353

  
326 354
  if(!ui->authenticated)
327 355
  {
......
341 369
        ctx->user_token_secret = g_strdup(_user_token_secret);
342 370
        ctx->user_nsid = g_strdup(_user_nsid);
343 371
        ctx->user_name = g_strdup(_username);
372
        ui->user_token = g_strdup(_user_token);
373
        ui->user_token_secret = g_strdup(_user_token_secret);
374
        ui->user_nsid = g_strdup(_user_nsid);
375
        ui->user_name = g_strdup(_username);        
344 376
        perms = flickr_check_token(ctx);
345 377
      }
346 378
      g_free(_username);
......
349 381
    g_free(_user_token_secret);
350 382
    g_free(_user_nsid);
351 383
  }
384
  else 
385
  {
386
    ctx->user_token = g_strdup(ui->user_token);
387
    ctx->user_token_secret = g_strdup(ui->user_token_secret);
388
    ctx->user_nsid = g_strdup(ui->user_nsid);
389
    ctx->user_name = g_strdup(ui->user_name);  
390
    perms = flickr_check_token(ctx);
391
  }
352 392

  
353 393
  if(perms)
354 394
  {
355
    free(perms);
395
    g_free(perms);
396
    ui->flickr_api = ctx;
356 397
    return ctx;
357 398
  }
358 399
  else if(!ctx->error_occured)
......
369 410
    curl_easy_setopt(ctx->curl, CURLOPT_URL, signed_request_token_url);
370 411
    curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, response);
371 412
    res = curl_easy_perform(ctx->curl);
372
    free(signed_request_token_url) ;
413
    g_free(signed_request_token_url) ;
373 414
    if (res == CURLE_OK)
374 415
    {
375 416
      char *err = NULL ;
376 417
      err = getParameterValue("oauth_problem",response->str);
377 418
      if (err) {
378 419
        dt_control_log(_("Flickr request_token failed"));
379
        free(err);
420
        g_free(err);
380 421
        g_string_free(response, TRUE);
381
        free(ctx);
422
        g_free(ctx);
382 423
        return NULL ;
383 424
      }
384 425
      auth_key = getParameterValue("oauth_token",response->str);
......
387 428
    else
388 429
    {
389 430
      g_string_free(response, TRUE);
390
      free(ctx);
431
      g_free(ctx);
391 432
      return NULL ;
392 433
    }
393 434
    g_string_free(response, TRUE);
......
418 459
    curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, response);
419 460
    res = curl_easy_perform(ctx->curl);
420 461
    g_string_free(get_perm_token_url, TRUE);
421
    free(signed_get_perm_token_url) ;
462
    g_free(signed_get_perm_token_url) ;
422 463
    if (res == CURLE_OK)
423 464
    {
424 465
      char *err = NULL ;
......
435 476
      flickr_user_token_secret = getParameterValue("oauth_token_secret",response->str);
436 477
      flickr_user_nsid = getParameterValue("user_nsid",response->str);
437 478
      flickr_user_name = getParameterValue("username",response->str);
438
      ctx->user_token = strdup(flickr_user_token);
439
      ctx->user_token_secret = strdup(flickr_user_token_secret);
440
      ctx->user_nsid = strdup(flickr_user_nsid);
441
      ctx->user_name = strdup(flickr_user_name);
479
      ctx->user_token = g_strdup(flickr_user_token);
480
      ctx->user_token_secret = g_strdup(flickr_user_token_secret);
481
      ctx->user_nsid = g_strdup(flickr_user_nsid);
482
      ctx->user_name = g_strdup(flickr_user_name);
483
      ui->user_token = g_strdup(flickr_user_token);
484
      ui->user_token_secret = g_strdup(flickr_user_token_secret);
485
      ui->user_nsid = g_strdup(flickr_user_nsid);
486
      ui->user_name = g_strdup(flickr_user_name);
442 487
      ui->authenticated = TRUE;
443 488
      ui->flickr_api = ctx;
444 489
      // override the user entry with the account he actually used to log in to flickr
445 490
      gtk_entry_set_text(ui->user_entry, flickr_user_name);
446
      free(oauth_verifier);
491
      g_free(oauth_verifier);
447 492
      g_string_free(response, TRUE);
448 493
      ui->flickr_api->needsReauthentication = FALSE;
449 494
    }
450 495
    else
451 496
    {
452
      free(oauth_verifier);
497
      g_free(oauth_verifier);
453 498
      g_string_free(response, TRUE);
454 499
      ctx->error_occured = TRUE ;
455 500
      return NULL ;
......
501 546
  curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, response);
502 547
  res = curl_easy_perform(ctx->curl);
503 548
  g_string_free(photosetInfo_url, TRUE);
504
  free(signed_photosetInfo_url);
549
  g_free(signed_photosetInfo_url);
505 550
  if (res !=CURLE_OK)
506 551
  {
507 552
    g_string_free(response, TRUE);
......
582 627
    curl_mime_name(field, vals[0]);
583 628
    uval = g_uri_unescape_string(vals[1],NULL) ;   // mandatory : signature
584 629
    curl_mime_data(field, uval , CURL_ZERO_TERMINATED);
585
    g_strfreev(vals);
586
    free(uval);
630
    g_strfreev(vals) ;
631
    g_free(uval);
587 632
    g++ ;
588 633
  }
589
  free(postargs);
634
  g_free(postargs);
590 635
  g_strfreev(params);
591 636
  field = curl_mime_addpart(form);
592 637
  curl_mime_name(field, "photo");
......
596 641
  res = curl_easy_perform(ctx->curl);
597 642
  curl_easy_setopt(ctx->curl, CURLOPT_POST, 0); // reset to default
598 643
  curl_mime_free(form);
599
  free(signed_upload_url);
644
  g_free(signed_upload_url);
600 645
  g_string_free(upload_url, TRUE);
601 646
  if (res == CURLE_OK)
602 647
  {
......
691 736
    curl_mime_name(field, vals[0]);
692 737
    uval = g_uri_unescape_string(vals[1],NULL) ;   // mandatory : signature
693 738
    curl_mime_data(field, uval , CURL_ZERO_TERMINATED);
694
    free(uval);
739
    g_free(uval);
695 740
    g_strfreev(vals);
696 741
    g++ ;
697 742
  }
698 743
  g_strfreev(params);
699
  free(postargs);
744
  g_free(postargs);
700 745
  curl_easy_setopt(ctx->curl, CURLOPT_MIMEPOST, form);
701 746
  res = curl_easy_perform(ctx->curl);
702 747
  curl_easy_setopt(ctx->curl, CURLOPT_POST, 0); // reset to default
703 748
  curl_mime_free(form);
704
  free(signed_rest_url);
749
  g_free(signed_rest_url);
705 750
  g_string_free(rest_url, TRUE);
706 751
  if (res == CURLE_OK)
707 752
  {
......
762 807
    uval = g_uri_unescape_string(vals[1],NULL) ;   // mandatory : signature
763 808
    curl_mime_data(field, uval , CURL_ZERO_TERMINATED);
764 809
    g_strfreev(vals);
765
    free(uval);
810
    g_free(uval);
766 811
    g++ ;
767 812
  }
768 813
  g_strfreev(params);
769
  free(postargs);
814
  g_free(postargs);
770 815
  curl_easy_setopt(ctx->curl, CURLOPT_MIMEPOST, form);
771 816
  res = curl_easy_perform(ctx->curl);
772 817
  curl_easy_setopt(ctx->curl, CURLOPT_POST, 0); // reset to default
773 818
  curl_mime_free(form);
774 819
  g_string_free(rest_url, TRUE);
775
  free(signed_rest_url);
820
  g_free(signed_rest_url);
776 821
  if (res == CURLE_OK)
777 822
  {
778 823
    JsonParser *parser = json_parser_new();
......
807 852
static void flickr_entry_changed(GtkEntry *entry, gpointer data)
808 853
{
809 854
  dt_storage_flickr_gui_data_t *ui = (dt_storage_flickr_gui_data_t *)data;
855

  
810 856
  if(ui->flickr_api != NULL)
811 857
  {
812 858
    if(strcmp(ui->flickr_api->user_name, gtk_entry_get_text(ui->user_entry)) != 0) // dt set user_name after auth.
......
835 881
  curl_easy_setopt(ctx->curl, CURLOPT_URL, signed_photoset_url);
836 882
  curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, response);
837 883
  res = curl_easy_perform(ctx->curl);
838
  free(signed_photoset_url);
884
  g_free(signed_photoset_url);
839 885
  g_string_free(photoset_url, TRUE);
840 886
  if(res != CURLE_OK)
841 887
  {
......
853 899
    {
854 900
      nb_albums = json_array_get_length(jsalbums) ;
855 901
      albums = g_malloc0( (nb_albums + 1) * sizeof(_flickr_album_t *));
856
      for (i = 0, k=0 ; i < nb_albums; i++)
902
      for (i = 0, k = 0 ; i < nb_albums; i++)
857 903
      {
858 904
        JsonObject *obj = json_array_get_object_element(jsalbums, i);
859 905
        if (obj == NULL) continue ;
......
861 907
        JsonObject *otitle = json_object_get_object_member(obj, "title");
862 908
        const char *name = json_object_get_string_member(otitle, "_content");
863 909
        const int photos = json_object_get_int_member(obj, "photos");
864
        if (strcmp(name, "Auto Upload") != 0) {  // not allowed for upload by fliclr 
910
        if (strcmp(name, "Auto Upload") != 0) // not allowed for upload by flickr 
911
        {  
865 912
          albums[k] = g_malloc0(sizeof(_flickr_album_t));
866 913
          albums[k]->id = g_strdup(id);
867 914
          albums[k]->title = g_strdup(name);
......
910 957
  {
911 958
    for(i=0; ui->albums[i]; i++)
912 959
    {
913
      free(ui->albums[i]->id) ;
914
      free(ui->albums[i]->title) ;
915
      free(ui->albums[i]);
960
      g_free(ui->albums[i]->id) ;
961
      g_free(ui->albums[i]->title) ;
962
      g_free(ui->albums[i]);
916 963
    }
917
    free(ui->albums);
964
    g_free(ui->albums);
918 965
  }
919 966
  ui->albums = flickr_photosets_getList(ui->flickr_api);
920 967
  if(ui->albums)
......
1116 1163
  {
1117 1164
    for(int i=0; ui->albums[i]; i++)
1118 1165
    {
1119
      free(ui->albums[i]->id) ;
1120
      free(ui->albums[i]->title) ;
1121
      free(ui->albums[i]);
1166
      g_free(ui->albums[i]->id) ;
1167
      g_free(ui->albums[i]->title) ;
1168
      g_free(ui->albums[i]);
1122 1169
    }
1123
    free(ui->albums);
1170
    g_free(ui->albums);
1124 1171
  }
1172
  g_free(ui->user_token);
1173
  g_free(ui->user_token_secret);
1174
  g_free(ui->user_nsid);
1175
  g_free(ui->user_name);
1125 1176
  g_free(self->gui_data);
1126 1177
}
1127 1178

  
......
1228 1279
    else
1229 1280
    {
1230 1281
      p->flickr_api->current_album = flickr_photoset_getInfo(p->flickr_api, photoset_id);
1231
      free(photoset_id);
1282
      g_free(photoset_id);
1232 1283
    }
1233 1284

  
1234 1285
  }
......
1249 1300
      p->flickr_api->new_album = FALSE;
1250 1301
    }
1251 1302
  }
1252
  free(photo_id);
1303
  g_free(photo_id);
1253 1304

  
1254 1305
cleanup:
1255 1306

  
......
1288 1339
  d->hash = 1;
1289 1340

  
1290 1341
  // fill d from controls in ui
1291
  if(ui->flickr_api && ui->flickr_api->needsReauthentication == FALSE)
1342
  if(ui->flickr_api)
1292 1343
  {
1293 1344
    // We are authenticated and off to actually export images..
1294
    d->flickr_api = ui->flickr_api;
1345
    d->flickr_api = _flickr_api_init(ui);
1295 1346
    int index = dt_bauhaus_combobox_get(ui->album_list);
1296 1347
    if(index >= 0)
1297 1348
    {
......
1360 1411
    }
1361 1412

  
1362 1413
    // Let UI forget about this api context and recreate a new one for further usage...
1363
    // ui->flickr_api = _flickr_api_authenticate(ui);   
1414
    if (ui->flickr_api->needsReauthentication == TRUE)
1415
    {
1416
      ui->flickr_api = _flickr_api_authenticate(ui);
1417
    }
1364 1418
    if(ui->flickr_api)
1365 1419
    {
1366 1420
      set_status(ui, _("authenticated"), "#7fe07f");
......
1409 1463

  
1410 1464
  _flickr_api_free(d->flickr_api); // TODO
1411 1465

  
1412
  free(params);
1466
  g_free(d);
1413 1467
}
1414 1468

  
1415 1469
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
1416
- 
Go to top