Пример #1
0
static void
my_set_config_var_handler(void* userdata, const char* key, const char* value)
{
  flickcurl *fc = (flickcurl *)userdata;
  
  if(!strcmp(key, "api_key"))
    flickcurl_set_api_key(fc, value);
  else if(!strcmp(key, "secret"))
    flickcurl_set_shared_secret(fc, value);
  else if(!strcmp(key, "auth_token"))
    flickcurl_set_auth_token(fc, value);
}
Пример #2
0
void
FlickrSource::init(Application & application) throw()
{
    flickrContext_ = FlickrContextPtr(new FlickrContext());
    flickcurl * const fc = flickrContext_->get_flickr_session();

    flickcurl_set_api_key(fc, apiKey.c_str());
    flickcurl_set_shared_secret(fc, sharedSecret.c_str());

    FlickrInitializerPtr flickr_initializer(
        new FlickrInitializer(&application, flickrContext_,
                              get_name(), initEnd_));

    signalInitEnd_
        = initEnd_.connect(
              sigc::bind(
                  sigc::mem_fun(*this,
                                &FlickrSource::on_init_end),
                  flickr_initializer));

    (*flickr_initializer)();
}
Пример #3
0
_flickr_api_context_t static *_flickr_api_authenticate(dt_storage_flickr_gui_data_t *ui)
{
  char *perms = NULL, *frob;
  gchar *token;
  char *flickr_user_token = NULL;
  gint result;
  _flickr_api_context_t *ctx = (_flickr_api_context_t *)g_malloc(sizeof(_flickr_api_context_t));
  memset(ctx,0,sizeof(_flickr_api_context_t));

  flickcurl_init ();
  ctx->fc = flickcurl_new ();
  flickcurl_set_api_key (ctx->fc, API_KEY);
  flickcurl_set_shared_secret (ctx->fc, SHARED_SECRET);
  flickcurl_set_error_handler(ctx->fc, _flickr_api_error_handler, ctx);

  if (!ui->user_token)
  {
    // Retrieve stored auth_key
    // TODO: We should be able to store token for different users
    GHashTable* table = dt_pwstorage_get("flickr");
    gchar * _username = g_strdup( g_hash_table_lookup(table, "username"));
    gchar *_user_token = g_strdup( g_hash_table_lookup(table, "token"));
    g_hash_table_destroy(table);

    if (_username)
    {
      if (!strcmp(_username,gtk_entry_get_text(ui->entry1)))
      {
        flickr_user_token = g_strdup(_user_token);
        perms = flickcurl_auth_checkToken(ctx->fc, flickr_user_token);
      }
      g_free (_username);
    }
    if (_user_token)
      g_free (_user_token);
  }
  else
  {
    flickr_user_token = ui->user_token;
    perms = flickcurl_auth_checkToken(ctx->fc, ui->user_token);
  }


  if (perms)
  {
    ui->user_token = flickr_user_token;
    flickcurl_set_auth_token(ctx->fc, flickr_user_token);
    return ctx;

  }
  else if (!ctx->error_occured)
  {
    frob = flickcurl_auth_getFrob(ctx->fc);
    GError *error = NULL;
    char *sign = g_strdup_printf ("%sapi_key%sfrob%spermswrite", SHARED_SECRET, API_KEY, frob);
    char *sign_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, sign, strlen (sign));
    gchar auth_url[250];
    sprintf(auth_url,"http://flickr.com/services/auth/?api_key=%s&perms=write&frob=%s&api_sig=%s", API_KEY, frob, sign_md5);

    gtk_show_uri (gdk_screen_get_default(), auth_url, gtk_get_current_event_time (), &error);

    g_free(sign);
    g_free(sign_md5);

    // Hold here to let the user interact
    // Show a dialog.
    gchar *text1, *text2;
    text1 = g_strdup(_("step 1: a new window or tab of your browser should have been loaded. you have to login into your flickr account there and authorize darktable to upload photos before continuing."));
    text2 = g_strdup(_("step 2: click the OK button once you are done."));

    GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
    GtkWidget *flickr_auth_dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_INFO,
                                    GTK_BUTTONS_OK_CANCEL,
                                    _("flickr authentication"));
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (flickr_auth_dialog),
        "%s\n\n%s", text1, text2);

    result = gtk_dialog_run (GTK_DIALOG (flickr_auth_dialog));

    gtk_widget_destroy(flickr_auth_dialog);

    g_free (text1);
    g_free (text2);

    switch (result)
    {
      case GTK_RESPONSE_OK:
        token = flickcurl_auth_getToken(ctx->fc, frob);
        g_free(frob);
        // TODO: Handle timeouts errors
        if (token)
        {
          flickr_user_token = g_strdup (token);
        }
        else
        {
          g_free(token);
          _flickr_api_free(ctx);
          return NULL;
        }
        ui->user_token = g_strdup(flickr_user_token);
        flickcurl_set_auth_token(ctx->fc, flickr_user_token);

        /* Add creds to pwstorage */
        GHashTable *table = g_hash_table_new(g_str_hash, g_str_equal);
        gchar* username = g_strdup(gtk_entry_get_text(ui->entry1));

        g_hash_table_insert(table, "username", username);
        g_hash_table_insert(table, "token", flickr_user_token);

        if( !dt_pwstorage_set("flickr", table) )
        {
          dt_print(DT_DEBUG_PWSTORAGE,"[flickr] cannot store username/token\n");
        }

        g_free(flickr_user_token);
        g_hash_table_destroy(table);

        return ctx;
        break;

      default:
        dt_print(DT_DEBUG_PWSTORAGE,"[flickr] user cancelled the login process\n");
        return NULL;
    }
  }

  if (perms)
    free(perms);

  return NULL;
}
Пример #4
0
	ThreadInfo* Init(string Key, string Secret){
		//Creating structure
		ThreadInfo* t = new(ThreadInfo);

		if(!t)
			return 0;

		//Creating cache
		t->CacheData.First = 0;
		t->CacheData.Last = 0;
		t->CacheData.MaxSize = DEFAULT_CACHE_SIZE;
		t->CacheData.Size = 0;

		//creating events
		t->CacheAvailable = CreateMutex(0, false, 0); //cache is available now
		t->ImageAvailable = CreateEvent(0, true, false, 0); //image is not available now
		t->Running = CreateEvent(0, true, false, 0); //thread is created in paused state
		t->Terminate = false;

		//creating flickcurl
		flickcurl_init();
		t->Flickcurl = flickcurl_new();

		if(t->Flickcurl){
			flickcurl_set_api_key(t->Flickcurl, Key.c_str());
			flickcurl_set_shared_secret(t->Flickcurl, Secret.c_str());
		}

		//creating search params with default values
		flickcurl_search_params_init(&t->SearchParams);
		t->SearchParams.user_id = 0;
		t->SearchParams.media = "photos";
		t->SearchParams.license = "1";
		t->WantImage = false;
		t->WantMeta = false;
		t->WantEXIF = false;
		t->WantSize = isMedium;
		t->WorkDir = "";
		t->CurImage = 0;
		t->TotalImages = 0;

		//creating list params
		flickcurl_photos_list_params_init(&t->ListParams);
		t->ListParams.per_page = DEFAULT_LIST_PAGE_SIZE;
		t->ListParams.page = 1;
		t->ResultList = 0;

		//creating curl
		t->Curl = curl_easy_init();
		curl_easy_setopt(t->Curl, CURLOPT_WRITEFUNCTION, WriteFileCallback);
		
		//initializing thread
		t->Thread = _beginthread(ThreadFunc, 0, (void*)t);

		//checking if everything is ok
		if(t->CacheAvailable && t->Running && t->Thread && t->Flickcurl && t->Curl
			&& t->ImageAvailable)
			return t;
		else{
			//killing everything
			Free(t);
			return 0;
		}
	};