mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-22 14:36:21 +00:00
Moved release module into common
This commit is contained in:
54
src/common.c
54
src/common.c
@@ -26,6 +26,8 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/easy.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -33,6 +35,15 @@
|
||||
// and page size is at least 4KB
|
||||
#define READ_BUF_SIZE 4088
|
||||
|
||||
struct curl_data_t
|
||||
{
|
||||
char *buffer;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
|
||||
|
||||
|
||||
// backwards compatibility for GLib version < 2.28
|
||||
void
|
||||
p_slist_free_full(GSList *items, GDestroyNotify free_func)
|
||||
@@ -193,3 +204,46 @@ octet_compare(unsigned char *str1, unsigned char *str2)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *
|
||||
release_get_latest()
|
||||
{
|
||||
char *url = "http://www.profanity.im/profanity_version.txt";
|
||||
|
||||
CURL *handle = curl_easy_init();
|
||||
struct curl_data_t output;
|
||||
output.buffer = NULL;
|
||||
output.size = 0;
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_URL, url);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, _data_callback);
|
||||
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 2);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&output);
|
||||
|
||||
curl_easy_perform(handle);
|
||||
curl_easy_cleanup(handle);
|
||||
|
||||
if (output.buffer != NULL) {
|
||||
output.buffer[output.size++] = '\0';
|
||||
return output.buffer;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
{
|
||||
size_t realsize = size * nmemb;
|
||||
struct curl_data_t *mem = (struct curl_data_t *) data;
|
||||
mem->buffer = realloc(mem->buffer, mem->size + realsize + 1);
|
||||
|
||||
if ( mem->buffer )
|
||||
{
|
||||
memcpy( &( mem->buffer[ mem->size ] ), ptr, realsize );
|
||||
mem->size += realsize;
|
||||
mem->buffer[ mem->size ] = 0;
|
||||
}
|
||||
|
||||
return realsize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user