1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Moved release module into common

This commit is contained in:
James Booth 2013-01-28 20:07:25 +00:00
parent 6c3b42cd24
commit 06ecfef1f3
6 changed files with 56 additions and 111 deletions

View File

@ -7,7 +7,7 @@ profanity_SOURCES = src/command.c src/contact.c src/command_history.c src/xmpp.h
src/history.c src/ui.h src/common.h src/ contact_list.h src/xmpp_conn.c \
src/main.c src/profanity.h src/history.h src/chat_log.c \
src/chat_log.h src/tinyurl.c src/tinyurl.h src/chat_session.c \
src/chat_session.h src/release.c src/release.h src/muc.c \
src/chat_session.h src/muc.c \
src/muc.h src/xmpp_stanza.c src/command_parser.c \
src/theme.c src/theme.h src/window.c src/window.h \
src/files.c src/files.h src/accounts.c src/accounts.h \

View File

@ -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;
}

View File

@ -58,5 +58,6 @@ int str_contains(char str[], int size, char ch);
char* encode_xml(const char * const xml);
char * prof_getline(FILE *stream);
int octet_compare(unsigned char *str1, unsigned char *str2);
char* release_get_latest(void);
#endif

View File

@ -1,79 +0,0 @@
/*
* release.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <curl/curl.h>
#include <curl/easy.h>
struct curl_data_t
{
char *buffer;
size_t size;
};
static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
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;
}

View File

@ -1,30 +0,0 @@
/*
* release.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef RELEASE_H
#define RELEASE_H
#include <glib.h>
char * release_get_latest(void);
#endif

View File

@ -53,7 +53,6 @@
#include "jid.h"
#include "log.h"
#include "preferences.h"
#include "release.h"
#include "muc.h"
#include "theme.h"
#include "ui.h"