From 06ecfef1f36a9e3d5d95ba1b8ec3dd209e296efd Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 28 Jan 2013 20:07:25 +0000 Subject: Moved release module into common --- Makefile.am | 2 +- src/common.c | 54 ++++++++++++++++++++++++++++++++++++++ src/common.h | 1 + src/release.c | 79 -------------------------------------------------------- src/release.h | 30 --------------------- src/ui_windows.c | 1 - 6 files changed, 56 insertions(+), 111 deletions(-) delete mode 100644 src/release.c delete mode 100644 src/release.h diff --git a/Makefile.am b/Makefile.am index 91e23827..d702610d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/common.c b/src/common.c index f0e14f45..d535ff32 100644 --- a/src/common.c +++ b/src/common.c @@ -26,6 +26,8 @@ #include #include +#include +#include #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; +} diff --git a/src/common.h b/src/common.h index 419b290f..075b5d7d 100644 --- a/src/common.h +++ b/src/common.h @@ -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 diff --git a/src/release.c b/src/release.c deleted file mode 100644 index 6316a9cd..00000000 --- a/src/release.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * release.c - * - * Copyright (C) 2012, 2013 James Booth - * - * 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 . - * - */ - -#include -#include - -#include -#include -#include - -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; -} diff --git a/src/release.h b/src/release.h deleted file mode 100644 index 6bbf7551..00000000 --- a/src/release.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * release.h - * - * Copyright (C) 2012, 2013 James Booth - * - * 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 . - * - */ - -#ifndef RELEASE_H -#define RELEASE_H - -#include - -char * release_get_latest(void); - -#endif diff --git a/src/ui_windows.c b/src/ui_windows.c index ae47c85b..a78a99c9 100644 --- a/src/ui_windows.c +++ b/src/ui_windows.c @@ -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" -- cgit 1.4.1-2-gfad0