samedi 2 novembre 2019

curl_slist->next is never null so while loop gets stuck

I am working on a C++ library that does an API request using curl. I'm having an issue where I am trying to process the cookies that are returned in the response using curl_slist and curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);.

It looks like its a linked list so I have a current and next attributes and I'm checking when next is NULL I should break out of the loop but for some reason its getting stuck in the loop, looks like its doing the same cookie over and over again but can't see why.

struct curl_slist* cookies;
curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);

int i = 1;
std::vector<CookieObj> cookieObjects;
struct curl_slist* current = cookies;
if (current != NULL)
{
    string cookieString = string(current->data);
    CookieObj cookieObj = storeCookie(cookieString);
    cookieObjects.push_back(cookieObj);

    while (current->next != NULL)
    {
        string cookieString = string(current->data);
        CookieObj cookieObj = this->storeCookie(cookieString);
        cookieObjects.push_back(cookieObj);
        current = cookies->next;

        i++;
    }

Aucun commentaire:

Enregistrer un commentaire