- g_assert(cookie_file != NULL);
-
- g_mutex_lock(mutex);
- if (g_file_test(cookie_file, G_FILE_TEST_EXISTS) == FALSE) { /* file not there */
- gchar * name_tmp = NULL;
- FILE * out_file = tmpfile();
- if (out_file == NULL) {
- // Something wrong with previous call (unsuported?)
- name_tmp = g_strdup_printf("%s.tmp", cookie_file);
- out_file = g_fopen(name_tmp, "w+b");
- }
- CURLcode res;
- CURL *curl = curl_easy_init();
- if (vik_verbose)
- curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 );
- curl_easy_setopt(curl, CURLOPT_URL, "http://maps.google.com/"); /* google.com sets "PREF" cookie */
- curl_easy_setopt ( curl, CURLOPT_WRITEDATA, out_file );
- curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
- curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_file);
- res = curl_easy_perform(curl);
- if (res != CURLE_OK) {
- g_warning(_("%s() Curl perform failed: %s"), __PRETTY_FUNCTION__,
- curl_easy_strerror(res));
- g_unlink(cookie_file);
- }
- curl_easy_cleanup(curl);
- fclose(out_file);
- out_file = NULL;
- if (name_tmp != NULL) {
- g_remove(name_tmp);
- g_free(name_tmp);
- name_tmp = NULL;
- }
- }
- g_mutex_unlock(mutex);
-