#include "fs.h"
#include "libcurl.h"
#include "thread.h"
-
+#include "com_list.h"
#include "image.h"
#include "jpeg.h"
#include "image_png.h"
size_t bytes_received; // for buffer
double bytes_received_curl; // for throttling
double bytes_sent_curl; // for throttling
- struct downloadinfo_s *next, *prev;
+ llist_t list;
qbool forthismap;
double maxspeed;
curl_slist *slist; // http headers
const char *extraheaders;
}
downloadinfo;
-static downloadinfo *downloads = NULL;
+LIST_HEAD(downloads);
static int numdownloads = 0;
static qbool noclear = false;
if(noclear)
return;
if (curl_mutex) Thread_LockMutex(curl_mutex);
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
di->forthismap = false;
Curl_CommandWhenError(NULL);
Curl_CommandWhenDone(NULL);
CLEAR_AND_RETRY();
}
- if(di->prev)
- di->prev->next = di->next;
- else
- downloads = di->next;
- if(di->next)
- di->next->prev = di->prev;
+ List_Delete(&di->list);
--numdownloads;
if(di->forthismap)
if(numdownloads < cl_curl_maxdownloads.integer)
{
downloadinfo *di;
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
{
if(!di->started)
{
downloadinfo *di;
if(!curl_dll)
return NULL;
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
if(!strcasecmp(di->filename, filename))
return di;
return NULL;
void Curl_Cancel_ToMemory(curl_callback_t callback, void *cbdata)
{
- downloadinfo *di;
+ downloadinfo *di, *ndi;
if(!curl_dll)
return;
- for(di = downloads; di; )
+ List_For_Each_Entry_Safe(di, ndi, &downloads, list)
{
if(di->callback == callback && di->callback_data == cbdata)
{
di->callback = curl_quiet_callback; // do NOT call the callback
Curl_EndDownload(di, CURL_DOWNLOAD_ABORTED, CURLE_OK, NULL);
- di = downloads;
}
- else
- di = di->next;
}
}
di->bytes_received_curl = 0;
di->bytes_sent_curl = 0;
di->extraheaders = extraheaders;
- di->next = downloads;
- di->prev = NULL;
- if(di->next)
- di->next->prev = di;
-
di->buffer = buf;
di->buffersize = bufsize;
if(callback == NULL)
di->postbufsize = 0;
}
- downloads = di;
- if (curl_mutex) Thread_UnlockMutex(curl_mutex);
+ List_Add(&di->list, &downloads);
+
+ if (curl_mutex)
+ Thread_UnlockMutex(curl_mutex);
+
return true;
}
}
Curl_CheckCommandWhenDone();
- if(!downloads)
+ if(List_Is_Empty(&downloads))
{
if (curl_mutex) Thread_UnlockMutex(curl_mutex);
return;
}
while(mc == CURLM_CALL_MULTI_PERFORM);
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
{
double b = 0;
if(di->curle)
// use the slowest allowing download to derive the maxspeed... this CAN
// be done better, but maybe later
maxspeed = cl_curl_maxspeed.value;
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
if(di->maxspeed > 0)
if(di->maxspeed < maxspeed || maxspeed <= 0)
maxspeed = di->maxspeed;
if (curl_mutex) Thread_LockMutex(curl_mutex);
- while(downloads)
+ while(!List_Is_Empty(&downloads))
{
- Curl_EndDownload(downloads, CURL_DOWNLOAD_ABORTED, CURLE_OK, NULL);
+ Curl_EndDownload(List_First_Entry(&downloads, downloadinfo, list), CURL_DOWNLOAD_ABORTED, CURLE_OK, NULL);
// INVARIANT: downloads will point to the next download after that!
}
if(!curl_dll)
return false;
- return downloads != NULL;
+ return !List_Is_Empty(&downloads);
}
/*
{
if (curl_mutex) Thread_LockMutex(curl_mutex);
Con_Print("Currently running downloads:\n");
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
{
double speed, percent;
Con_Printf(" %s -> %s ", CleanURL(di->url, urlbuf, sizeof(urlbuf)), di->filename);
if (curl_mutex) Thread_LockMutex(curl_mutex);
i = 0;
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
++i;
downinfo = (Curl_downloadinfo_t *) Z_Malloc(sizeof(*downinfo) * i);
i = 0;
- for(di = downloads; di; di = di->next)
+ List_For_Each_Entry(di, &downloads, list)
{
// do not show infobars for background downloads
if(developer.integer <= 0)