Improve documentation

This commit is contained in:
dogeystamp 2021-09-22 18:50:42 -04:00
parent 9f36c4c9c6
commit ac57c3dcca
No known key found for this signature in database
GPG Key ID: 4C53B0126F579F36
3 changed files with 22 additions and 1 deletions

View File

@ -11,6 +11,8 @@
void void
itemAction(itemStruct *item, const char *folder) itemAction(itemStruct *item, const char *folder)
{ {
// Receives a link list of articles to process.
itemStruct *cur = item; itemStruct *cur = item;
unsigned long long int newItems = 0; unsigned long long int newItems = 0;
@ -71,6 +73,8 @@ itemAction(itemStruct *item, const char *folder)
void void
finish(char *url, long responseCode) finish(char *url, long responseCode)
{ {
// Executed after a download finishes
if (responseCode == 200) if (responseCode == 200)
logMsg(4, "Finished downloading %s\n", url); logMsg(4, "Finished downloading %s\n", url);
else if (!responseCode) else if (!responseCode)

11
net.c
View File

@ -12,6 +12,8 @@ static CURLM *multiHandle;
int int
initCurl() initCurl()
{ {
// Initialise the curl handle.
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
multiHandle = curl_multi_init(); multiHandle = curl_multi_init();
@ -21,6 +23,8 @@ initCurl()
static size_t static size_t
writeCallback(void *ptr, size_t size, size_t nmemb, void *data) writeCallback(void *ptr, size_t size, size_t nmemb, void *data)
{ {
// Write blocks of data to the output.
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
outputStruct *mem = (outputStruct*) data; outputStruct *mem = (outputStruct*) data;
@ -40,6 +44,8 @@ writeCallback(void *ptr, size_t size, size_t nmemb, void *data)
int int
createRequest(const char* url, outputStruct *output) createRequest(const char* url, outputStruct *output)
{ {
// Create the curl request for an URL.
CURL *requestHandle = curl_easy_init(); CURL *requestHandle = curl_easy_init();
if (!requestHandle) if (!requestHandle)
@ -75,6 +81,8 @@ createRequest(const char* url, outputStruct *output)
int int
performRequests(void callback(char *, long)) performRequests(void callback(char *, long))
{ {
// Perform all the curl requests.
int runningRequests; int runningRequests;
do { do {
@ -101,7 +109,8 @@ performRequests(void callback(char *, long))
curl_easy_cleanup(requestHandle); curl_easy_cleanup(requestHandle);
} }
} }
// > 0 because curl puts negative numbers when there's broken requests
// > 0 because curl puts negative numbers when there's broken requests
} while (runningRequests > 0); } while (runningRequests > 0);
curl_multi_cleanup(multiHandle); curl_multi_cleanup(multiHandle);

8
xml.c
View File

@ -14,6 +14,8 @@
void void
freeItem(itemStruct *item) freeItem(itemStruct *item)
{ {
// Free the memory used by an article.
char **mems[] = { char **mems[] = {
&item->title, &item->title,
&item->link, &item->link,
@ -42,6 +44,8 @@ parseXml(xmlDocPtr doc,
const char *feedName, const char *feedName,
void itemAction(itemStruct *, const char *)) void itemAction(itemStruct *, const char *))
{ {
// Parse the XML in a single document.
if (!feedName || !feedName[0]) { if (!feedName || !feedName[0]) {
logMsg(1, "Missing feed name, please set one.\n"); logMsg(1, "Missing feed name, please set one.\n");
return 1; return 1;
@ -73,6 +77,7 @@ parseXml(xmlDocPtr doc,
logMsg(1, "Invalid RSS syntax. Skipping...\n"); logMsg(1, "Invalid RSS syntax. Skipping...\n");
} }
// Pointer to an article xml tag
xmlNodePtr cur = channel->children; xmlNodePtr cur = channel->children;
itemStruct *prev = NULL; itemStruct *prev = NULL;
@ -84,6 +89,7 @@ parseXml(xmlDocPtr doc,
if (TAGIS(cur, "item")) { if (TAGIS(cur, "item")) {
itemStruct *item = ecalloc(1, sizeof(itemStruct)); itemStruct *item = ecalloc(1, sizeof(itemStruct));
// Build a linked list of item structs to pass to itemAction()
item->next = prev; item->next = prev;
prev = item; prev = item;
@ -183,6 +189,8 @@ readDoc(char *content,
const char *feedName, const char *feedName,
void itemAction(itemStruct *, const char *)) void itemAction(itemStruct *, const char *))
{ {
// Initialize the XML document, read it, then free it
xmlDocPtr doc; xmlDocPtr doc;
doc = xmlReadMemory(content, strlen(content), "noname.xml", NULL, 0); doc = xmlReadMemory(content, strlen(content), "noname.xml", NULL, 0);