Skip to content

Commit 1bcd853

Browse files
committed
Fixed wrong cookie behavior in itksnap-wt
1 parent 8871cfc commit 1bcd853

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

GUI/Model/DistributedSegmentationModel.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ DistributedSegmentationModel::AsyncCheckStatus(std::string url, std::string toke
662662
bool status_login;
663663
if(token.size() > 0)
664664
{
665-
rc.SetReceiveCookieMode(true);
665+
rc.SetReceiveCookieMode(true);
666666
status_login = rc.Post("api/login?format=json", "token=%s", token.c_str());
667667
}
668668
else

Logic/WorkspaceAPI/RESTClient.cxx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ RESTClient<ServerTraits>::SetOutputFile(FILE *outfile)
127127

128128
template <typename ServerTraits>
129129
void
130-
RESTClient<ServerTraits>::SetupCookies(bool read_only)
130+
RESTClient<ServerTraits>::SetupCookies(bool receive_cookie_mode)
131131
{
132-
m_Traits.SetupCookies(
133-
m_SharedData ? m_SharedData->GetShare() : nullptr, m_Curl, GetServerURL().c_str(), read_only);
132+
m_Traits.SetupCookies(m_SharedData ? m_SharedData->GetShare() : nullptr,
133+
m_Curl,
134+
GetServerURL().c_str(),
135+
receive_cookie_mode);
134136
}
135137

136138
template <typename ServerTraits>
@@ -148,7 +150,7 @@ RESTClient<ServerTraits>::Authenticate(const char *token)
148150
curl_easy_setopt(m_Curl, CURLOPT_POSTFIELDS, post_buffer);
149151

150152
// Set up the cookie jar to receive cookies
151-
SetupCookies(false);
153+
SetupCookies(true);
152154

153155
// Capture output
154156
m_Output.clear();
@@ -300,6 +302,7 @@ RESTClient<ServerTraits>::PostVA(const char *rel_url, const char *post_string, s
300302
}
301303

302304
// Make request
305+
// std::cout << "curl request to: " << url << " with data " << post_filled << std::endl;
303306
CURLcode res = curl_easy_perform(m_Curl);
304307

305308
if (res != CURLE_OK)
@@ -718,7 +721,7 @@ DSSServerTraits::SetServerURL(const char *baseurl)
718721
}
719722

720723
void
721-
DSSServerTraits::SetupCookies(void *share, void *handle, const char *url, bool read_only)
724+
DSSServerTraits::SetupCookies(void *share, void *handle, const char *url, bool receive_cookie_mode)
722725
{
723726
// MD5 encode the server
724727
char hex_code[33];
@@ -730,10 +733,16 @@ DSSServerTraits::SetupCookies(void *share, void *handle, const char *url, bool r
730733
itksysMD5_Delete(md5);
731734

732735
string cookie_jar = GetDataDirectory() + "/cookie_" + hex_code + ".jar";
733-
if(read_only)
734-
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, cookie_jar.c_str());
735-
else
736+
if(receive_cookie_mode)
737+
{
738+
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, nullptr);
736739
curl_easy_setopt(handle, CURLOPT_COOKIEJAR, cookie_jar.c_str());
740+
}
741+
else
742+
{
743+
curl_easy_setopt(handle, CURLOPT_COOKIEJAR, nullptr);
744+
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, cookie_jar.c_str());
745+
}
737746
}
738747

739748
string
@@ -787,11 +796,11 @@ DLSServerTraits::SetServerURL(const char *baseurl)
787796
}
788797

789798
void
790-
DLSServerTraits::SetupCookies(void *share, void *handle, const char *url, bool read_only)
799+
DLSServerTraits::SetupCookies(void *share, void *handle, const char *url, bool receive_cookie_mode)
791800
{
792801
if (share)
793802
{
794-
if(read_only)
803+
if (receive_cookie_mode)
795804
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, "");
796805
else
797806
curl_easy_setopt(handle, CURLOPT_COOKIEJAR, "");

Logic/WorkspaceAPI/RESTClient.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DSSServerTraits
5656

5757
void SetServerURL(const char *baseurl);
5858
std::string GetServerURL();
59-
void SetupCookies(void* share, void *handle, const char *url, bool read_only);
59+
void SetupCookies(void *share, void *handle, const char *url, bool receive_cookie_mode);
6060

6161
protected:
6262
static std::string GetDataDirectory();
@@ -78,7 +78,7 @@ class DLSServerTraits
7878

7979
std::string GetServerURL();
8080

81-
void SetupCookies(void* share, void *handle, const char *url, bool read_only);
81+
void SetupCookies(void* share, void *handle, const char *url, bool receive_cookie_mode);
8282

8383
protected:
8484
std::string m_ServerURL;
@@ -265,7 +265,7 @@ class RESTClient
265265

266266
static size_t WriteToFileCallback(void *contents, size_t size, size_t nmemb, void *userp);
267267

268-
void SetupCookies(bool read_only);
268+
void SetupCookies(bool receive_cookie_mode);
269269
};
270270

271271

0 commit comments

Comments
 (0)