diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-07-07 13:53:30 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-07-07 13:53:30 +0200 |
commit | a4cadf78faabc157e5db00e42302d495bba432c0 (patch) | |
tree | 6ff212e24fe750b04b37ca66c418fe366c5e5fd4 /src/tools | |
parent | 28fde3cd0129202d586cb4c24877a3e3f55ca582 (diff) | |
download | profani-tty-a4cadf78faabc157e5db00e42302d495bba432c0.tar.gz |
Revert "Apply coding style"
This reverts commit 9b55f2dec0ea27a9ce4856e303425e12f866cea2. Sorting the includes creates some problems.
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/autocomplete.c | 135 | ||||
-rw-r--r-- | src/tools/autocomplete.h | 32 | ||||
-rw-r--r-- | src/tools/bookmark_ignore.c | 28 | ||||
-rw-r--r-- | src/tools/bookmark_ignore.h | 8 | ||||
-rw-r--r-- | src/tools/clipboard.c | 12 | ||||
-rw-r--r-- | src/tools/clipboard.h | 2 | ||||
-rw-r--r-- | src/tools/http_upload.c | 108 | ||||
-rw-r--r-- | src/tools/http_upload.h | 21 | ||||
-rw-r--r-- | src/tools/parser.c | 88 | ||||
-rw-r--r-- | src/tools/parser.h | 12 | ||||
-rw-r--r-- | src/tools/tinyurl.c | 28 | ||||
-rw-r--r-- | src/tools/tinyurl.h | 4 |
12 files changed, 238 insertions, 240 deletions
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index ef81afe9..2f8cde3e 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -33,25 +33,24 @@ * */ -#include <glib.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <glib.h> #include "common.h" #include "tools/autocomplete.h" #include "tools/parser.h" #include "ui/ui.h" -struct autocomplete_t -{ - GList* items; - GList* last_found; - gchar* search_str; +struct autocomplete_t { + GList *items; + GList *last_found; + gchar *search_str; }; -static gchar* _search_next(Autocomplete ac, GList* curr, gboolean quote); -static gchar* _search_prev(Autocomplete ac, GList* curr, gboolean quote); +static gchar* _search_next(Autocomplete ac, GList *curr, gboolean quote); +static gchar* _search_prev(Autocomplete ac, GList *curr, gboolean quote); Autocomplete autocomplete_new(void) @@ -106,10 +105,10 @@ autocomplete_length(Autocomplete ac) } void -autocomplete_update(Autocomplete ac, char** items) +autocomplete_update(Autocomplete ac, char **items) { - gchar* last_found = NULL; - gchar* search_str = NULL; + gchar *last_found = NULL; + gchar *search_str = NULL; if (ac->last_found) { last_found = strdup(ac->last_found->data); @@ -135,11 +134,11 @@ autocomplete_update(Autocomplete ac, char** items) } void -autocomplete_add_reverse(Autocomplete ac, const char* item) +autocomplete_add_reverse(Autocomplete ac, const char *item) { if (ac) { - char* item_cpy; - GList* curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); + char *item_cpy; + GList *curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); // if item already exists if (curr) { @@ -152,11 +151,11 @@ autocomplete_add_reverse(Autocomplete ac, const char* item) } void -autocomplete_add(Autocomplete ac, const char* item) +autocomplete_add(Autocomplete ac, const char *item) { if (ac) { - char* item_cpy; - GList* curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); + char *item_cpy; + GList *curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); // if item already exists if (curr) { @@ -169,7 +168,7 @@ autocomplete_add(Autocomplete ac, const char* item) } void -autocomplete_add_all(Autocomplete ac, char** items) +autocomplete_add_all(Autocomplete ac, char **items) { int i = 0; for (i = 0; i < g_strv_length(items); i++) { @@ -178,10 +177,10 @@ autocomplete_add_all(Autocomplete ac, char** items) } void -autocomplete_remove(Autocomplete ac, const char* const item) +autocomplete_remove(Autocomplete ac, const char *const item) { if (ac) { - GList* curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); + GList *curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); if (!curr) { return; @@ -200,7 +199,7 @@ autocomplete_remove(Autocomplete ac, const char* const item) } void -autocomplete_remove_all(Autocomplete ac, char** items) +autocomplete_remove_all(Autocomplete ac, char **items) { int i = 0; for (i = 0; i < g_strv_length(items); i++) { @@ -211,10 +210,10 @@ autocomplete_remove_all(Autocomplete ac, char** items) GList* autocomplete_create_list(Autocomplete ac) { - GList* copy = NULL; - GList* curr = ac->items; + GList *copy = NULL; + GList *curr = ac->items; - while (curr) { + while(curr) { copy = g_list_append(copy, strdup(curr->data)); curr = g_list_next(curr); } @@ -223,11 +222,11 @@ autocomplete_create_list(Autocomplete ac) } gboolean -autocomplete_contains(Autocomplete ac, const char* value) +autocomplete_contains(Autocomplete ac, const char *value) { - GList* curr = ac->items; + GList *curr = ac->items; - while (curr) { + while(curr) { if (strcmp(curr->data, value) == 0) { return TRUE; } @@ -238,9 +237,9 @@ autocomplete_contains(Autocomplete ac, const char* value) } gchar* -autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote, gboolean previous) +autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote, gboolean previous) { - gchar* found = NULL; + gchar *found = NULL; // no autocomplete to search if (!ac) { @@ -263,7 +262,7 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote, return found; - // subsequent search attempt + // subsequent search attempt } else { if (previous) { // search from here-1 to beginning @@ -301,10 +300,10 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote, } char* -autocomplete_param_with_func(const char* const input, char* command, autocomplete_func func, gboolean previous, void* context) +autocomplete_param_with_func(const char *const input, char *command, autocomplete_func func, gboolean previous, void *context) { - GString* auto_msg = NULL; - char* result = NULL; + GString *auto_msg = NULL; + char *result = NULL; char command_cpy[strlen(command) + 2]; sprintf(command_cpy, "%s ", command); int len = strlen(command_cpy); @@ -313,12 +312,12 @@ autocomplete_param_with_func(const char* const input, char* command, autocomplet int i; int inp_len = strlen(input); char prefix[inp_len]; - for (i = len; i < inp_len; i++) { - prefix[i - len] = input[i]; + for(i = len; i < inp_len; i++) { + prefix[i-len] = input[i]; } prefix[inp_len - len] = '\0'; - char* found = func(prefix, previous, context); + char *found = func(prefix, previous, context); if (found) { auto_msg = g_string_new(command_cpy); g_string_append(auto_msg, found); @@ -332,23 +331,23 @@ autocomplete_param_with_func(const char* const input, char* command, autocomplet } char* -autocomplete_param_with_ac(const char* const input, char* command, Autocomplete ac, gboolean quote, gboolean previous) +autocomplete_param_with_ac(const char *const input, char *command, Autocomplete ac, gboolean quote, gboolean previous) { - GString* auto_msg = NULL; - char* result = NULL; - char* command_cpy = malloc(strlen(command) + 2); + GString *auto_msg = NULL; + char *result = NULL; + char *command_cpy = malloc(strlen(command) + 2); sprintf(command_cpy, "%s ", command); int len = strlen(command_cpy); int inp_len = strlen(input); if (strncmp(input, command_cpy, len) == 0) { int i; char prefix[inp_len]; - for (i = len; i < inp_len; i++) { - prefix[i - len] = input[i]; + for(i = len; i < inp_len; i++) { + prefix[i-len] = input[i]; } prefix[inp_len - len] = '\0'; - char* found = autocomplete_complete(ac, prefix, quote, previous); + char *found = autocomplete_complete(ac, prefix, quote, previous); if (found) { auto_msg = g_string_new(command_cpy); g_string_append(auto_msg, found); @@ -363,22 +362,22 @@ autocomplete_param_with_ac(const char* const input, char* command, Autocomplete } char* -autocomplete_param_no_with_func(const char* const input, char* command, int arg_number, autocomplete_func func, gboolean previous, void* context) +autocomplete_param_no_with_func(const char *const input, char *command, int arg_number, autocomplete_func func, gboolean previous, void *context) { if (strncmp(input, command, strlen(command)) == 0) { - GString* result_str = NULL; + GString *result_str = NULL; // count tokens properly int num_tokens = count_tokens(input); // if correct number of tokens, then candidate for autocompletion of last param if (num_tokens == arg_number) { - gchar* start_str = get_start(input, arg_number); - gchar* comp_str = g_strdup(&input[strlen(start_str)]); + gchar *start_str = get_start(input, arg_number); + gchar *comp_str = g_strdup(&input[strlen(start_str)]); // autocomplete param if (comp_str) { - char* found = func(comp_str, previous, context); + char *found = func(comp_str, previous, context); if (found) { result_str = g_string_new(""); g_string_append(result_str, start_str); @@ -387,7 +386,7 @@ autocomplete_param_no_with_func(const char* const input, char* command, int arg_ free(start_str); free(comp_str); - char* result = result_str->str; + char *result = result_str->str; g_string_free(result_str, FALSE); return result; @@ -406,7 +405,7 @@ void autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize) { if (autocomplete_length(ac) > maxsize) { - GList* last = g_list_last(ac->items); + GList *last = g_list_last(ac->items); if (last) { free(last->data); ac->items = g_list_delete_link(ac->items, last); @@ -415,15 +414,15 @@ autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize) } static gchar* -_search_next(Autocomplete ac, GList* curr, gboolean quote) +_search_next(Autocomplete ac, GList *curr, gboolean quote) { - gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL); - gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1); + gchar *search_str_ascii = g_str_to_ascii(ac->search_str, NULL); + gchar *search_str_lower = g_ascii_strdown(search_str_ascii, -1); g_free(search_str_ascii); - while (curr) { - gchar* curr_ascii = g_str_to_ascii(curr->data, NULL); - gchar* curr_lower = g_ascii_strdown(curr_ascii, -1); + while(curr) { + gchar *curr_ascii = g_str_to_ascii(curr->data, NULL); + gchar *curr_lower = g_ascii_strdown(curr_ascii, -1); g_free(curr_ascii); // match found @@ -434,18 +433,18 @@ _search_next(Autocomplete ac, GList* curr, gboolean quote) // if contains space, quote before returning if (quote && g_strrstr(curr->data, " ")) { - GString* quoted = g_string_new("\""); + GString *quoted = g_string_new("\""); g_string_append(quoted, curr->data); g_string_append(quoted, "\""); - gchar* result = quoted->str; + gchar *result = quoted->str; g_string_free(quoted, FALSE); g_free(search_str_lower); g_free(curr_lower); return result; - // otherwise just return the string + // otherwise just return the string } else { g_free(search_str_lower); g_free(curr_lower); @@ -462,15 +461,15 @@ _search_next(Autocomplete ac, GList* curr, gboolean quote) } static gchar* -_search_prev(Autocomplete ac, GList* curr, gboolean quote) +_search_prev(Autocomplete ac, GList *curr, gboolean quote) { - gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL); - gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1); + gchar *search_str_ascii = g_str_to_ascii(ac->search_str, NULL); + gchar *search_str_lower = g_ascii_strdown(search_str_ascii, -1); g_free(search_str_ascii); - while (curr) { - gchar* curr_ascii = g_str_to_ascii(curr->data, NULL); - gchar* curr_lower = g_ascii_strdown(curr_ascii, -1); + while(curr) { + gchar *curr_ascii = g_str_to_ascii(curr->data, NULL); + gchar *curr_lower = g_ascii_strdown(curr_ascii, -1); g_free(curr_ascii); // match found @@ -481,18 +480,18 @@ _search_prev(Autocomplete ac, GList* curr, gboolean quote) // if contains space, quote before returning if (quote && g_strrstr(curr->data, " ")) { - GString* quoted = g_string_new("\""); + GString *quoted = g_string_new("\""); g_string_append(quoted, curr->data); g_string_append(quoted, "\""); - gchar* result = quoted->str; + gchar *result = quoted->str; g_string_free(quoted, FALSE); g_free(search_str_lower); g_free(curr_lower); return result; - // otherwise just return the string + // otherwise just return the string } else { g_free(search_str_lower); g_free(curr_lower); diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index 697a551f..6f4fe9c7 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -38,8 +38,8 @@ #include <glib.h> -typedef char* (*autocomplete_func)(const char* const, gboolean, void*); -typedef struct autocomplete_t* Autocomplete; +typedef char* (*autocomplete_func)(const char *const, gboolean, void *); +typedef struct autocomplete_t *Autocomplete; // allocate new autocompleter with no items Autocomplete autocomplete_new(void); @@ -50,31 +50,31 @@ void autocomplete_clear(Autocomplete ac); // free all memory used by the autocompleter void autocomplete_free(Autocomplete ac); -void autocomplete_add(Autocomplete ac, const char* item); -void autocomplete_add_all(Autocomplete ac, char** items); -void autocomplete_update(Autocomplete ac, char** items); -void autocomplete_remove(Autocomplete ac, const char* const item); -void autocomplete_remove_all(Autocomplete ac, char** items); -void autocomplete_add_reverse(Autocomplete ac, const char* item); +void autocomplete_add(Autocomplete ac, const char *item); +void autocomplete_add_all(Autocomplete ac, char **items); +void autocomplete_update(Autocomplete ac, char **items); +void autocomplete_remove(Autocomplete ac, const char *const item); +void autocomplete_remove_all(Autocomplete ac, char **items); +void autocomplete_add_reverse(Autocomplete ac, const char *item); // find the next item prefixed with search string -gchar* autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote, gboolean previous); +gchar* autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote, gboolean previous); GList* autocomplete_create_list(Autocomplete ac); gint autocomplete_length(Autocomplete ac); -char* autocomplete_param_with_func(const char* const input, char* command, - autocomplete_func func, gboolean previous, void* context); +char* autocomplete_param_with_func(const char *const input, char *command, + autocomplete_func func, gboolean previous, void *context); -char* autocomplete_param_with_ac(const char* const input, char* command, - Autocomplete ac, gboolean quote, gboolean previous); +char* autocomplete_param_with_ac(const char *const input, char *command, + Autocomplete ac, gboolean quote, gboolean previous); -char* autocomplete_param_no_with_func(const char* const input, char* command, - int arg_number, autocomplete_func func, gboolean previous, void* context); +char* autocomplete_param_no_with_func(const char *const input, char *command, + int arg_number, autocomplete_func func, gboolean previous, void *context); void autocomplete_reset(Autocomplete ac); -gboolean autocomplete_contains(Autocomplete ac, const char* value); +gboolean autocomplete_contains(Autocomplete ac, const char *value); void autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize); #endif diff --git a/src/tools/bookmark_ignore.c b/src/tools/bookmark_ignore.c index 7c97dfc8..09053e5b 100644 --- a/src/tools/bookmark_ignore.c +++ b/src/tools/bookmark_ignore.c @@ -35,22 +35,22 @@ #include "config.h" -#include "config/files.h" -#include "config/preferences.h" #include <glib.h> #include <glib/gstdio.h> #include <stdlib.h> #include <string.h> +#include "config/files.h" +#include "config/preferences.h" #include "log.h" -static GKeyFile* bookmark_ignore_keyfile = NULL; -static char* account_jid = NULL; +static GKeyFile *bookmark_ignore_keyfile = NULL; +static char *account_jid = NULL; static void _bookmark_ignore_load() { - char* bi_loc; + char *bi_loc; bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE); @@ -68,9 +68,9 @@ static void _bookmark_save() { gsize g_data_size; - gchar* g_bookmark_ignore_data = g_key_file_to_data(bookmark_ignore_keyfile, &g_data_size, NULL); + gchar *g_bookmark_ignore_data = g_key_file_to_data(bookmark_ignore_keyfile, &g_data_size, NULL); - char* bi_loc; + char *bi_loc; bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE); g_file_set_contents(bi_loc, g_bookmark_ignore_data, g_data_size, NULL); @@ -81,9 +81,9 @@ _bookmark_save() } void -bookmark_ignore_on_connect(const char* const barejid) +bookmark_ignore_on_connect(const char *const barejid) { - if (bookmark_ignore_keyfile == NULL) { + if(bookmark_ignore_keyfile == NULL) { _bookmark_ignore_load(); account_jid = strdup(barejid); } @@ -98,26 +98,26 @@ bookmark_ignore_on_disconnect() } gboolean -bookmark_ignored(Bookmark* bookmark) +bookmark_ignored(Bookmark *bookmark) { return g_key_file_get_boolean(bookmark_ignore_keyfile, account_jid, bookmark->barejid, NULL); } -gchar** -bookmark_ignore_list(gsize* len) +gchar ** +bookmark_ignore_list(gsize *len) { return g_key_file_get_keys(bookmark_ignore_keyfile, account_jid, len, NULL); } void -bookmark_ignore_add(const char* const barejid) +bookmark_ignore_add(const char *const barejid) { g_key_file_set_boolean(bookmark_ignore_keyfile, account_jid, barejid, TRUE); _bookmark_save(); } void -bookmark_ignore_remove(const char* const barejid) +bookmark_ignore_remove(const char *const barejid) { g_key_file_remove_key(bookmark_ignore_keyfile, account_jid, barejid, NULL); _bookmark_save(); diff --git a/src/tools/bookmark_ignore.h b/src/tools/bookmark_ignore.h index a618ea6b..9b0fda36 100644 --- a/src/tools/bookmark_ignore.h +++ b/src/tools/bookmark_ignore.h @@ -38,9 +38,9 @@ void bookmark_ignore_on_connect(); void bookmark_ignore_on_disconnect(); -gboolean bookmark_ignored(Bookmark* bookmark); -gchar** bookmark_ignore_list(gsize* len); -void bookmark_ignore_add(const char* const barejid); -void bookmark_ignore_remove(const char* const barejid); +gboolean bookmark_ignored(Bookmark *bookmark); +gchar ** bookmark_ignore_list(gsize *len); +void bookmark_ignore_add(const char *const barejid); +void bookmark_ignore_remove(const char *const barejid); #endif diff --git a/src/tools/clipboard.c b/src/tools/clipboard.c index 9485a4ad..9454915c 100644 --- a/src/tools/clipboard.c +++ b/src/tools/clipboard.c @@ -36,8 +36,8 @@ #include "config.h" #ifdef HAVE_GTK -#include <glib.h> #include <gtk/gtk.h> +#include <glib.h> #include <stdlib.h> #include "log.h" @@ -50,15 +50,13 @@ void clipboard_init(int argc, char **argv) { } */ -char* -clipboard_get(void) -{ - gchar* clip; +char *clipboard_get(void) { + gchar *clip; - GtkClipboard* cl = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); + GtkClipboard *cl = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gtk_clipboard_clear(cl); - if (cl == NULL) { + if(cl==NULL) { log_error("Could not get clipboard"); return NULL; } diff --git a/src/tools/clipboard.h b/src/tools/clipboard.h index addb60e0..d6cfee9a 100644 --- a/src/tools/clipboard.h +++ b/src/tools/clipboard.h @@ -37,7 +37,7 @@ #define UI_CLIPBOARD_H #ifdef HAVE_GTK -char* clipboard_get(void); +char *clipboard_get(void); #endif #endif diff --git a/src/tools/http_upload.c b/src/tools/http_upload.c index d50ef618..f52706e5 100644 --- a/src/tools/http_upload.c +++ b/src/tools/http_upload.c @@ -37,41 +37,40 @@ #include "config.h" -#include <assert.h> -#include <curl/curl.h> -#include <gio/gio.h> -#include <pthread.h> -#include <stdio.h> #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> +#include <curl/curl.h> +#include <gio/gio.h> +#include <pthread.h> +#include <assert.h> -#include "common.h" -#include "config/preferences.h" -#include "event/client_events.h" #include "profanity.h" +#include "event/client_events.h" #include "tools/http_upload.h" +#include "config/preferences.h" #include "ui/ui.h" #include "ui/window.h" +#include "common.h" -#define FALLBACK_MIMETYPE "application/octet-stream" +#define FALLBACK_MIMETYPE "application/octet-stream" #define FALLBACK_CONTENTTYPE_HEADER "Content-Type: application/octet-stream" -#define FALLBACK_MSG "" -#define FILE_HEADER_BYTES 512 +#define FALLBACK_MSG "" +#define FILE_HEADER_BYTES 512 -struct curl_data_t -{ - char* buffer; +struct curl_data_t { + char *buffer; size_t size; }; -GSList* upload_processes = NULL; +GSList *upload_processes = NULL; static int -_xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) +_xferinfo(void *userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { - HTTPUpload* upload = (HTTPUpload*)userdata; + HTTPUpload *upload = (HTTPUpload *)userdata; pthread_mutex_lock(&lock); @@ -92,7 +91,7 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot ulperc = (100 * ulnow) / ultotal; } - char* msg; + char *msg; if (asprintf(&msg, "Uploading '%s': %d%%", upload->filename, ulperc) == -1) { msg = strdup(FALLBACK_MSG); } @@ -106,39 +105,40 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot #if LIBCURL_VERSION_NUM < 0x072000 static int -_older_progress(void* p, double dltotal, double dlnow, double ultotal, double ulnow) +_older_progress(void *p, double dltotal, double dlnow, double ultotal, double ulnow) { return _xferinfo(p, (curl_off_t)dltotal, (curl_off_t)dlnow, (curl_off_t)ultotal, (curl_off_t)ulnow); } #endif static size_t -_data_callback(void* ptr, size_t size, size_t nmemb, void* data) +_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; + 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); + if (mem->buffer) + { + memcpy( &( mem->buffer[ mem->size ] ), ptr, realsize ); mem->size += realsize; - mem->buffer[mem->size] = 0; + mem->buffer[ mem->size ] = 0; } return realsize; } -void* -http_file_put(void* userdata) +void * +http_file_put(void *userdata) { - HTTPUpload* upload = (HTTPUpload*)userdata; + HTTPUpload *upload = (HTTPUpload *)userdata; - FILE* fd = NULL; + FILE *fd = NULL; - char* err = NULL; - char* content_type_header; + char *err = NULL; + char *content_type_header; - CURL* curl; + CURL *curl; CURLcode res; upload->cancel = 0; @@ -152,7 +152,7 @@ http_file_put(void* userdata) win_print_http_upload(upload->window, msg, upload->put_url); free(msg); - char* cert_path = prefs_get_string(PREF_TLS_CERTPATH); + char *cert_path = prefs_get_string(PREF_TLS_CERTPATH); pthread_mutex_unlock(&lock); curl_global_init(CURL_GLOBAL_ALL); @@ -161,7 +161,7 @@ http_file_put(void* userdata) curl_easy_setopt(curl, CURLOPT_URL, upload->put_url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - struct curl_slist* headers = NULL; + struct curl_slist *headers = NULL; if (asprintf(&content_type_header, "Content-Type: %s", upload->mime_type) == -1) { content_type_header = strdup(FALLBACK_CONTENTTYPE_HEADER); } @@ -169,20 +169,20 @@ http_file_put(void* userdata) headers = curl_slist_append(headers, "Expect:"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); -#if LIBCURL_VERSION_NUM >= 0x072000 + #if LIBCURL_VERSION_NUM >= 0x072000 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, _xferinfo); curl_easy_setopt(curl, CURLOPT_XFERINFODATA, upload); -#else + #else curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, _older_progress); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, upload); -#endif + #endif curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); struct curl_data_t output; output.buffer = NULL; output.size = 0; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _data_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&output); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&output); curl_easy_setopt(curl, CURLOPT_USERAGENT, "profanity"); @@ -218,11 +218,11 @@ http_file_put(void* userdata) } } -#if 0 + #if 0 printf("HTTP Status: %lu\n", http_code); printf("%s\n", output.buffer); printf("%lu bytes retrieved\n", (long)output.size); -#endif + #endif } end: @@ -239,7 +239,7 @@ end: g_free(cert_path); if (err) { - char* msg; + char *msg; if (upload->cancel) { if (asprintf(&msg, "Uploading '%s' failed: Upload was canceled", upload->filename) == -1) { msg = strdup(FALLBACK_MSG); @@ -265,21 +265,21 @@ end: switch (upload->window->type) { case WIN_CHAT: { - ProfChatWin* chatwin = (ProfChatWin*)(upload->window); + ProfChatWin *chatwin = (ProfChatWin*)(upload->window); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); cl_ev_send_msg(chatwin, upload->get_url, upload->get_url); break; } case WIN_PRIVATE: { - ProfPrivateWin* privatewin = (ProfPrivateWin*)(upload->window); + ProfPrivateWin *privatewin = (ProfPrivateWin*)(upload->window); assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); cl_ev_send_priv_msg(privatewin, upload->get_url, upload->get_url); break; } case WIN_MUC: { - ProfMucWin* mucwin = (ProfMucWin*)(upload->window); + ProfMucWin *mucwin = (ProfMucWin*)(upload->window); assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); cl_ev_send_muc_msg(mucwin, upload->get_url, upload->get_url); break; @@ -305,29 +305,29 @@ end: char* file_mime_type(const char* const file_name) { - char* out_mime_type; + char *out_mime_type; char file_header[FILE_HEADER_BYTES]; - FILE* fd; + FILE *fd; if (!(fd = fopen(file_name, "rb"))) { return strdup(FALLBACK_MIMETYPE); } size_t file_header_size = fread(file_header, 1, FILE_HEADER_BYTES, fd); fclose(fd); - char* content_type = g_content_type_guess(file_name, (unsigned char*)file_header, file_header_size, NULL); + char *content_type = g_content_type_guess(file_name, (unsigned char*)file_header, file_header_size, NULL); if (content_type != NULL) { - char* mime_type = g_content_type_get_mime_type(content_type); + char *mime_type = g_content_type_get_mime_type(content_type); out_mime_type = strdup(mime_type); g_free(mime_type); - } else { + } + else { return strdup(FALLBACK_MIMETYPE); } g_free(content_type); return out_mime_type; } -off_t -file_size(const char* const filename) +off_t file_size(const char* const filename) { struct stat st; stat(filename, &st); @@ -335,11 +335,11 @@ file_size(const char* const filename) } void -http_upload_cancel_processes(ProfWin* window) +http_upload_cancel_processes(ProfWin *window) { - GSList* upload_process = upload_processes; + GSList *upload_process = upload_processes; while (upload_process) { - HTTPUpload* upload = upload_process->data; + HTTPUpload *upload = upload_process->data; if (upload->window == window) { upload->cancel = 1; break; @@ -349,7 +349,7 @@ http_upload_cancel_processes(ProfWin* window) } void -http_upload_add_upload(HTTPUpload* upload) +http_upload_add_upload(HTTPUpload *upload) { upload_processes = g_slist_append(upload_processes, upload); } diff --git a/src/tools/http_upload.h b/src/tools/http_upload.h index dc15b33f..60b1ea82 100644 --- a/src/tools/http_upload.h +++ b/src/tools/http_upload.h @@ -40,30 +40,29 @@ #define SOCKET int #endif -#include <curl/curl.h> #include <sys/select.h> +#include <curl/curl.h> #include "ui/win_types.h" -typedef struct http_upload_t -{ - char* filename; +typedef struct http_upload_t { + char *filename; off_t filesize; curl_off_t bytes_sent; - char* mime_type; - char* get_url; - char* put_url; - ProfWin* window; + char *mime_type; + char *get_url; + char *put_url; + ProfWin *window; pthread_t worker; int cancel; } HTTPUpload; -void* http_file_put(void* userdata); +void* http_file_put(void *userdata); char* file_mime_type(const char* const file_name); off_t file_size(const char* const file_name); -void http_upload_cancel_processes(ProfWin* window); -void http_upload_add_upload(HTTPUpload* upload); +void http_upload_cancel_processes(ProfWin *window); +void http_upload_add_upload(HTTPUpload *upload); #endif diff --git a/src/tools/parser.c b/src/tools/parser.c index 2099a071..fb21571c 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -63,7 +63,7 @@ * */ gchar** -parse_args(const char* const inp, int min, int max, gboolean* result) +parse_args(const char *const inp, int min, int max, gboolean *result) { if (inp == NULL) { *result = FALSE; @@ -71,31 +71,31 @@ parse_args(const char* const inp, int min, int max, gboolean* result) } // copy and strip input of leading/trailing whitespace - char* copy = strdup(inp); + char *copy = strdup(inp); g_strstrip(copy); int inp_size = g_utf8_strlen(copy, -1); gboolean in_token = FALSE; gboolean in_quotes = FALSE; - char* token_start = ©[0]; + char *token_start = ©[0]; int token_size = 0; - GSList* tokens = NULL; + GSList *tokens = NULL; // add tokens to GSList int i; for (i = 0; i < inp_size; i++) { - gchar* curr_ch = g_utf8_offset_to_pointer(copy, i); + gchar *curr_ch = g_utf8_offset_to_pointer(copy, i); gunichar curr_uni = g_utf8_get_char(curr_ch); if (!in_token) { - if (curr_uni == ' ') { + if (curr_uni == ' ') { continue; } else { in_token = TRUE; if (curr_uni == '"') { in_quotes = TRUE; i++; - gchar* next_ch = g_utf8_next_char(curr_ch); + gchar *next_ch = g_utf8_next_char(curr_ch); gunichar next_uni = g_utf8_get_char(next_ch); token_start = next_ch; token_size += g_unichar_to_utf8(next_uni, NULL); @@ -108,7 +108,7 @@ parse_args(const char* const inp, int min, int max, gboolean* result) if (in_quotes) { if (curr_uni == '"') { tokens = g_slist_append(tokens, g_strndup(token_start, - token_size)); + token_size)); token_size = 0; in_token = FALSE; in_quotes = FALSE; @@ -118,7 +118,7 @@ parse_args(const char* const inp, int min, int max, gboolean* result) } else { if (curr_uni == ' ') { tokens = g_slist_append(tokens, g_strndup(token_start, - token_size)); + token_size)); token_size = 0; in_token = FALSE; } else { @@ -141,19 +141,19 @@ parse_args(const char* const inp, int min, int max, gboolean* result) *result = FALSE; return NULL; - // if min allowed is 0 and 0 found, return empty char* array + // if min allowed is 0 and 0 found, return empty char* array } else if (min == 0 && num == 0) { g_slist_free_full(tokens, free); - gchar** args = malloc((num + 1) * sizeof(*args)); + gchar **args = malloc((num + 1) * sizeof(*args)); args[0] = NULL; g_free(copy); *result = TRUE; return args; - // otherwise return args array + // otherwise return args array } else { - gchar** args = malloc((num + 1) * sizeof(*args)); - GSList* token = tokens; + gchar **args = malloc((num + 1) * sizeof(*args)); + GSList *token = tokens; token = g_slist_next(token); int arg_count = 0; @@ -197,7 +197,7 @@ parse_args(const char* const inp, int min, int max, gboolean* result) * */ gchar** -parse_args_with_freetext(const char* const inp, int min, int max, gboolean* result) +parse_args_with_freetext(const char *const inp, int min, int max, gboolean *result) { if (inp == NULL) { *result = FALSE; @@ -205,22 +205,22 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu } // copy and strip input of leading/trailing whitepsace - char* copy = strdup(inp); + char *copy = strdup(inp); g_strstrip(copy); int inp_size = g_utf8_strlen(copy, -1); gboolean in_token = FALSE; gboolean in_freetext = FALSE; gboolean in_quotes = FALSE; - char* token_start = ©[0]; + char *token_start = ©[0]; int token_size = 0; int num_tokens = 0; - GSList* tokens = NULL; + GSList *tokens = NULL; // add tokens to GSList int i; for (i = 0; i < inp_size; i++) { - gchar* curr_ch = g_utf8_offset_to_pointer(copy, i); + gchar *curr_ch = g_utf8_offset_to_pointer(copy, i); gunichar curr_uni = g_utf8_get_char(curr_ch); if (!in_token) { @@ -234,13 +234,13 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu } else if (curr_uni == '"') { in_quotes = TRUE; i++; - gchar* next_ch = g_utf8_next_char(curr_ch); + gchar *next_ch = g_utf8_next_char(curr_ch); gunichar next_uni = g_utf8_get_char(next_ch); token_start = next_ch; token_size += g_unichar_to_utf8(next_uni, NULL); } if (curr_uni == '"') { - gchar* next_ch = g_utf8_next_char(curr_ch); + gchar *next_ch = g_utf8_next_char(curr_ch); token_start = next_ch; } else { token_start = curr_ch; @@ -251,7 +251,7 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu if (in_quotes) { if (curr_uni == '"') { tokens = g_slist_append(tokens, g_strndup(token_start, - token_size)); + token_size)); token_size = 0; in_token = FALSE; in_quotes = FALSE; @@ -265,7 +265,7 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu token_size += g_unichar_to_utf8(curr_uni, NULL); } else if (curr_uni == ' ') { tokens = g_slist_append(tokens, g_strndup(token_start, - token_size)); + token_size)); token_size = 0; in_token = FALSE; } else if (curr_uni != '"') { @@ -289,18 +289,18 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu *result = FALSE; return NULL; - // if min allowed is 0 and 0 found, return empty char* array + // if min allowed is 0 and 0 found, return empty char* array } else if (min == 0 && num == 0) { g_slist_free_full(tokens, free); - gchar** args = malloc((num + 1) * sizeof(*args)); + gchar **args = malloc((num + 1) * sizeof(*args)); args[0] = NULL; *result = TRUE; return args; - // otherwise return args array + // otherwise return args array } else { - gchar** args = malloc((num + 1) * sizeof(*args)); - GSList* token = tokens; + gchar **args = malloc((num + 1) * sizeof(*args)); + GSList *token = tokens; token = g_slist_next(token); int arg_count = 0; @@ -317,7 +317,7 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu } int -count_tokens(const char* const string) +count_tokens(const char *const string) { int length = g_utf8_strlen(string, -1); gboolean in_quotes = FALSE; @@ -328,7 +328,7 @@ count_tokens(const char* const string) num_tokens++; for (i = 0; i < length; i++) { - gchar* curr_ch = g_utf8_offset_to_pointer(string, i); + gchar *curr_ch = g_utf8_offset_to_pointer(string, i); gunichar curr_uni = g_utf8_get_char(curr_ch); if (curr_uni == ' ') { @@ -348,12 +348,12 @@ count_tokens(const char* const string) } char* -get_start(const char* const string, int tokens) +get_start(const char *const string, int tokens) { - GString* result = g_string_new(""); + GString *result = g_string_new(""); int length = g_utf8_strlen(string, -1); gboolean in_quotes = FALSE; - char* result_str = NULL; + char *result_str = NULL; int num_tokens = 0; int i = 0; @@ -361,11 +361,11 @@ get_start(const char* const string, int tokens) num_tokens++; for (i = 0; i < length; i++) { - gchar* curr_ch = g_utf8_offset_to_pointer(string, i); + gchar *curr_ch = g_utf8_offset_to_pointer(string, i); gunichar curr_uni = g_utf8_get_char(curr_ch); if (num_tokens < tokens) { - gchar* uni_char = malloc(7); + gchar *uni_char = malloc(7); int len = g_unichar_to_utf8(curr_uni, uni_char); uni_char[len] = '\0'; g_string_append(result, uni_char); @@ -391,15 +391,15 @@ get_start(const char* const string, int tokens) } GHashTable* -parse_options(gchar** args, gchar** opt_keys, gboolean* res) +parse_options(gchar **args, gchar **opt_keys, gboolean *res) { - GList* keys = NULL; + GList *keys = NULL; int i; for (i = 0; i < g_strv_length(opt_keys); i++) { keys = g_list_append(keys, opt_keys[i]); } - GHashTable* options = NULL; + GHashTable *options = NULL; // no options found, success if (args[0] == NULL) { @@ -411,8 +411,8 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res) // validate options int curr; - GList* found_keys = NULL; - for (curr = 0; curr < g_strv_length(args); curr += 2) { + GList *found_keys = NULL; + for (curr = 0; curr < g_strv_length(args); curr+= 2) { // check if option valid if (g_list_find_custom(keys, args[curr], (GCompareFunc)g_strcmp0) == NULL) { *res = FALSE; @@ -430,7 +430,7 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res) } // check value given - if (args[curr + 1] == NULL) { + if (args[curr+1] == NULL) { *res = FALSE; g_list_free(found_keys); g_list_free(keys); @@ -445,15 +445,15 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res) // create map options = g_hash_table_new(g_str_hash, g_str_equal); *res = TRUE; - for (curr = 0; curr < g_strv_length(args); curr += 2) { - g_hash_table_insert(options, args[curr], args[curr + 1]); + for (curr = 0; curr < g_strv_length(args); curr+=2) { + g_hash_table_insert(options, args[curr], args[curr+1]); } return options; } void -options_destroy(GHashTable* options) +options_destroy(GHashTable *options) { if (options) { g_hash_table_destroy(options); diff --git a/src/tools/parser.h b/src/tools/parser.h index d1b6f7bf..4787b148 100644 --- a/src/tools/parser.h +++ b/src/tools/parser.h @@ -38,11 +38,11 @@ #include <glib.h> -gchar** parse_args(const char* const inp, int min, int max, gboolean* result); -gchar** parse_args_with_freetext(const char* const inp, int min, int max, gboolean* result); -int count_tokens(const char* const string); -char* get_start(const char* const string, int tokens); -GHashTable* parse_options(gchar** args, gchar** keys, gboolean* res); -void options_destroy(GHashTable* options); +gchar** parse_args(const char *const inp, int min, int max, gboolean *result); +gchar** parse_args_with_freetext(const char *const inp, int min, int max, gboolean *result); +int count_tokens(const char *const string); +char* get_start(const char *const string, int tokens); +GHashTable* parse_options(gchar **args, gchar **keys, gboolean *res); +void options_destroy(GHashTable *options); #endif diff --git a/src/tools/tinyurl.c b/src/tools/tinyurl.c index 41ff43ec..955ce030 100644 --- a/src/tools/tinyurl.c +++ b/src/tools/tinyurl.c @@ -43,32 +43,33 @@ struct curl_data_t { - char* buffer; + char *buffer; size_t size; }; -static size_t _data_callback(void* ptr, size_t size, size_t nmemb, void* data); +static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data); gboolean -tinyurl_valid(char* url) +tinyurl_valid(char *url) { - return (g_str_has_prefix(url, "http://") || g_str_has_prefix(url, "https://")); + return (g_str_has_prefix(url, "http://") || + g_str_has_prefix(url, "https://")); } char* -tinyurl_get(char* url) +tinyurl_get(char *url) { - GString* full_url = g_string_new("http://tinyurl.com/api-create.php?url="); + GString *full_url = g_string_new("http://tinyurl.com/api-create.php?url="); g_string_append(full_url, url); - CURL* handle = curl_easy_init(); + CURL *handle = curl_easy_init(); struct curl_data_t output; output.buffer = NULL; output.size = 0; curl_easy_setopt(handle, CURLOPT_URL, full_url->str); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, _data_callback); - curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void*)&output); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&output); curl_easy_perform(handle); curl_easy_cleanup(handle); @@ -84,16 +85,17 @@ tinyurl_get(char* url) } static size_t -_data_callback(void* ptr, size_t size, size_t nmemb, void* data) +_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; + 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); + if ( mem->buffer ) + { + memcpy( &( mem->buffer[ mem->size ] ), ptr, realsize ); mem->size += realsize; - mem->buffer[mem->size] = 0; + mem->buffer[ mem->size ] = 0; } return realsize; diff --git a/src/tools/tinyurl.h b/src/tools/tinyurl.h index 67222cd0..14ac6e35 100644 --- a/src/tools/tinyurl.h +++ b/src/tools/tinyurl.h @@ -38,7 +38,7 @@ #include <glib.h> -gboolean tinyurl_valid(char* url); -char* tinyurl_get(char* url); +gboolean tinyurl_valid(char *url); +char* tinyurl_get(char *url); #endif |