diff --git a/src/base64.c b/src/base64.c index 1547ca8446..029cddca22 100644 --- a/src/base64.c +++ b/src/base64.c @@ -38,8 +38,7 @@ * On success, the encoded nul-terminated data, as a string is returned. */ char * base64_encode (const void *buf, size_t size) { - static const char base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; char *str = (char *) xmalloc ((size + 3) * 4 / 3 + 1); diff --git a/src/bin2c.c b/src/bin2c.c index d82e6f8963..d6b23bc3de 100644 --- a/src/bin2c.c +++ b/src/bin2c.c @@ -84,7 +84,7 @@ main (int argc, char *argv[]) { #ifdef USE_BZ2 // allocate for bz2. - bz2_size = (file_size + file_size / 100 + 1) + 600; // as per the documentation + bz2_size = (file_size + file_size / 100 + 1) + 600; // as per the documentation if ((bz2_buf = malloc (bz2_size)) == NULL) { fprintf (stderr, "Unable to malloc bin2c.c buffer\n"); diff --git a/src/bitmap.h b/src/bitmap.h index 071e42837d..651c367adc 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -31,7 +31,7 @@ #ifndef BITMAP_H_INCLUDED #define BITMAP_H_INCLUDED -#include /* for CHAR_BIT */ +#include /* for CHAR_BIT */ typedef uint32_t word_t; // I want to change this, from uint32_t to uint64_t enum { BITS_PER_WORD = sizeof (word_t) * CHAR_BIT }; diff --git a/src/browsers.c b/src/browsers.c index f5ad8a6411..b2fb4c31c4 100644 --- a/src/browsers.c +++ b/src/browsers.c @@ -245,15 +245,15 @@ static const char *browsers[][2] = { {"MauiBot", "Crawlers"}, {"Cloud", "Crawlers"}, {"stagefright", "Crawlers"}, - {"ZoteroTranslationServer", "Cralwers"}, /* Nodeja Zotero Translation Server https://github.com/zotero/translation-server */ + {"ZoteroTranslationServer", "Cralwers"}, /* Nodeja Zotero Translation Server https://github.com/zotero/translation-server */ /* HTTP Library or HTTP Server User Agents - Suggest New Category */ - {"axios", "HTTP Library"}, /* NodeJS axios axios-http.com */ - {"lua-resty-http", "HTTP Library"}, /* Nginx lua-resty-http module */ + {"axios", "HTTP Library"}, /* NodeJS axios axios-http.com */ + {"lua-resty-http", "HTTP Library"}, /* Nginx lua-resty-http module */ /* Citation Services */ - {"Citoid", "Citation"}, /* MediaWiki Citoid Citation Service https://www.mediawiki.org/wiki/Citoid */ - {"EasyBib", "Citation"}, /* Easybib Citation https://easybib.com */ + {"Citoid", "Citation"}, /* MediaWiki Citoid Citation Service https://www.mediawiki.org/wiki/Citoid */ + {"EasyBib", "Citation"}, /* Easybib Citation https://easybib.com */ /* Podcast fetchers */ {"Downcast", "Podcasts"}, @@ -293,12 +293,12 @@ static const char *browsers[][2] = { {"Uptime-Kuma", "Uptime"}, /* Performance and Caching - Suggest a new category */ - {"ShortPixel", "Performance"}, /* Image Optimization */ - {"WP Rocket", "Caching"}, /* Preloading Cache for WordPress Plugin */ + {"ShortPixel", "Performance"}, /* Image Optimization */ + {"WP Rocket", "Caching"}, /* Preloading Cache for WordPress Plugin */ /* Security - Suggest a new category */ - {"Barracuda Sentinel", "Security"}, /* Barricuda spear fishing service */ - {"ACI Site Scanner", "Security"}, /* Can't confirm specific vendor */ + {"Barracuda Sentinel", "Security"}, /* Barricuda spear fishing service */ + {"ACI Site Scanner", "Security"}, /* Can't confirm specific vendor */ {"Mozilla", "Others"} diff --git a/src/commons.c b/src/commons.c index 44f076a077..731c18fe48 100644 --- a/src/commons.c +++ b/src/commons.c @@ -400,8 +400,7 @@ verify_panels (void) { if (!conf.log_format) return; - if (!strstr (conf.log_format, "%v") && ignore_panel_idx < TOTAL_MODULES && - !conf.fname_as_vhost) { + if (!strstr (conf.log_format, "%v") && ignore_panel_idx < TOTAL_MODULES && !conf.fname_as_vhost) { if (str_inarray ("VIRTUAL_HOSTS", conf.ignore_panels, ignore_panel_idx) < 0) remove_module (VIRTUAL_HOSTS); } diff --git a/src/commons.h b/src/commons.h index db1e315c16..7d32026d2b 100644 --- a/src/commons.h +++ b/src/commons.h @@ -62,7 +62,7 @@ extern struct tm now_tm; /* real-time */ #define MAX_CHOICES_RT 50 /* max default items when date-spec = min */ -#define MAX_CHOICES_MINUTE 1440 /* 24hrs */ +#define MAX_CHOICES_MINUTE 1440 /* 24hrs */ /* date and time length - e.g., 2016/12/12 12:12:12 -0600 */ #define DATE_TIME 25 + 1 diff --git a/src/csv.c b/src/csv.c index 94d19a2075..1918a1977e 100644 --- a/src/csv.c +++ b/src/csv.c @@ -175,7 +175,7 @@ print_csv_sub_items (FILE *fp, GHolder *h, int idx, GPercTotals totals) { set_data_metrics (iter->metrics, &nmetrics, totals); fprintf (fp, "\"%d\",", i); /* idx */ - fprintf (fp, "\"%d\",", idx); /* parent idx */ + fprintf (fp, "\"%d\",", idx); /* parent idx */ fprintf (fp, "\"%s\",", module_to_id (h->module)); /* output metrics */ @@ -196,7 +196,7 @@ print_csv_data (FILE *fp, GHolder *h, GPercTotals totals) { set_data_metrics (h->items[i].metrics, &nmetrics, totals); fprintf (fp, "\"%d\",", i); /* idx */ - fprintf (fp, ","); /* no parent */ + fprintf (fp, ","); /* no parent */ fprintf (fp, "\"%s\",", module_to_id (h->module)); /* output metrics */ diff --git a/src/gdashboard.c b/src/gdashboard.c index 17d73d86c5..bf7f19e892 100644 --- a/src/gdashboard.c +++ b/src/gdashboard.c @@ -59,9 +59,9 @@ reset_find (void) { find_t.look_in_sub = 0; find_t.module = 0; - find_t.next_idx = 0; /* next total index */ - find_t.next_parent_idx = 0; /* next parent index */ - find_t.next_sub_idx = 0; /* next sub item index */ + find_t.next_idx = 0; /* next total index */ + find_t.next_parent_idx = 0; /* next parent index */ + find_t.next_sub_idx = 0; /* next sub item index */ find_t.pattern = NULL; } @@ -879,8 +879,7 @@ render_header (WINDOW *win, GDashModule *data, GModule cur_module, int *y) { k = data->module + 1; ind = cur_module == data->module ? '>' : ' '; - func = cur_module == data->module && - conf.hl_header ? color_panel_active : color_panel_header; + func = cur_module == data->module && conf.hl_header ? color_panel_active : color_panel_header; hd = xmalloc (snprintf (NULL, 0, "%c %d - %s", ind, k, data->head) + 1); sprintf (hd, "%c %d - %s", ind, k, data->head); @@ -1061,8 +1060,7 @@ render_cols (WINDOW *win, GDashModule *data, int *y) { /* Iterate over all dashboard data and render its content. */ static void -render_content (WINDOW *win, GDashModule *data, int *y, int *offset, - int *total, GScroll *gscroll) { +render_content (WINDOW *win, GDashModule *data, int *y, int *offset, int *total, GScroll *gscroll) { GModule module = data->module; int i, j, size, h, w, data_pos = get_data_pos_rows (); @@ -1388,8 +1386,7 @@ set_dash_metrics (GDash **dash, GMetrics *metrics, GModule module, * If no items on the sub list, the function returns. * On success, sub list data is set into the dashboard structure. */ static void -add_sub_item_to_dash (GDash **dash, GHolderItem item, GModule module, GPercTotals totals, - int *i) { +add_sub_item_to_dash (GDash **dash, GHolderItem item, GModule module, GPercTotals totals, int *i) { GSubList *sub_list = item.sub_list; GSubItem *iter; diff --git a/src/gdashboard.h b/src/gdashboard.h index 3a3e902477..34c170076f 100644 --- a/src/gdashboard.h +++ b/src/gdashboard.h @@ -38,23 +38,23 @@ #include "ui.h" -#define DASH_HEAD_POS 0 /* position of header line */ -#define DASH_EMPTY_POS 1 /* empty line position */ -#define DASH_COLS_POS 2 /* position of column names */ -#define DASH_DASHES_POS 3 /* position of dashes under column names */ -#define DASH_DATA_POS 4 /* data line position */ +#define DASH_HEAD_POS 0 /* position of header line */ +#define DASH_EMPTY_POS 1 /* empty line position */ +#define DASH_COLS_POS 2 /* position of column names */ +#define DASH_DASHES_POS 3 /* position of dashes under column names */ +#define DASH_DATA_POS 4 /* data line position */ -#define DASH_NON_DATA 5 /* number of rows without data stats */ -#define DASH_COL_ROWS 2 /* number of rows for column values + dashed lines */ +#define DASH_NON_DATA 5 /* number of rows without data stats */ +#define DASH_COL_ROWS 2 /* number of rows for column values + dashed lines */ -#define DASH_COLLAPSED 12 /* number of rows per panel (collapsed) */ -#define DASH_EXPANDED 32 /* number of rows per panel (expanded) */ +#define DASH_COLLAPSED 12 /* number of rows per panel (collapsed) */ +#define DASH_EXPANDED 32 /* number of rows per panel (expanded) */ -#define DASH_INIT_X 1 /* start position (x-axis) */ +#define DASH_INIT_X 1 /* start position (x-axis) */ -#define DASH_BW_LEN 11 /* max bandwidth string length, e.g., 151.69 MiB */ -#define DASH_SRV_TM_LEN 9 /* max time served length, e.g., 483.00 us */ -#define DASH_SPACE 1 /* space between columns (metrics) */ +#define DASH_BW_LEN 11 /* max bandwidth string length, e.g., 151.69 MiB */ +#define DASH_SRV_TM_LEN 9 /* max time served length, e.g., 483.00 us */ +#define DASH_SPACE 1 /* space between columns (metrics) */ /* Common render data line fields */ typedef struct GDashRender_ { diff --git a/src/gdns.h b/src/gdns.h index deebaa93a6..d84743e745 100644 --- a/src/gdns.h +++ b/src/gdns.h @@ -45,7 +45,7 @@ typedef struct GDnsQueue_ { int tail; /* index to tail of queue */ int size; /* queue size */ int capacity; /* length at most */ - char buffer[QUEUE_SIZE][H_SIZE]; /* data item */ + char buffer[QUEUE_SIZE][H_SIZE]; /* data item */ } GDnsQueue; extern GDnsThread gdns_thread; diff --git a/src/geoip1.h b/src/geoip1.h index a9ff589b2a..38e3e4a13d 100644 --- a/src/geoip1.h +++ b/src/geoip1.h @@ -36,10 +36,10 @@ #include "commons.h" -#define CITY_LEN 47 + 1 /* max string length for a city */ -#define CONTINENT_LEN 47 + 1 /* max string length for a country */ -#define COUNTRY_LEN 48 + 3 /* Country + two-letter Code */ -#define ASN_LEN 64 + 6 /* ASN + 5 digit/16-bit number/code */ +#define CITY_LEN 47 + 1 /* max string length for a city */ +#define CONTINENT_LEN 47 + 1 /* max string length for a country */ +#define COUNTRY_LEN 48 + 3 /* Country + two-letter Code */ +#define ASN_LEN 64 + 6 /* ASN + 5 digit/16-bit number/code */ /* Type of IP */ typedef enum { diff --git a/src/gholder.c b/src/gholder.c index a80cfd3315..0565fb5884 100644 --- a/src/gholder.c +++ b/src/gholder.c @@ -599,8 +599,7 @@ set_root_metrics (GRawDataItem item, GModule module, datatype type, GMetrics **n /* Set all root panel data, including sub list items. */ static void -add_root_to_holder (GRawDataItem item, GHolder *h, datatype type, - GO_UNUSED const GPanel *panel) { +add_root_to_holder (GRawDataItem item, GHolder *h, datatype type, GO_UNUSED const GPanel *panel) { GSubList *sub_list; GMetrics *metrics, *nmetrics; char *root = NULL; @@ -639,8 +638,7 @@ add_root_to_holder (GRawDataItem item, GHolder *h, datatype type, h->items[idx].metrics->bw.nbw += nmetrics->bw.nbw; h->items[idx].metrics->hits += nmetrics->hits; h->items[idx].metrics->visitors += nmetrics->visitors; - h->items[idx].metrics->avgts.nts = - h->items[idx].metrics->cumts.nts / h->items[idx].metrics->hits; + h->items[idx].metrics->avgts.nts = h->items[idx].metrics->cumts.nts / h->items[idx].metrics->hits; if (nmetrics->maxts.nts > h->items[idx].metrics->maxts.nts) h->items[idx].metrics->maxts.nts = nmetrics->maxts.nts; diff --git a/src/gkmhash.c b/src/gkmhash.c index 1ab3a7520a..d4ae563dd1 100644 --- a/src/gkmhash.c +++ b/src/gkmhash.c @@ -447,8 +447,7 @@ ht_insert_keymap (GModule module, uint32_t date, uint32_t key, uint32_t *ckey) { * On error, -1 is returned. * On success 0 is returned */ int -ht_insert_rootmap (GModule module, uint32_t date, uint32_t key, const char *value, - uint32_t ckey) { +ht_insert_rootmap (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { khash_t (is32) * hash = get_hash (module, date, MTRC_ROOTMAP); khash_t (is32) * cache = get_hash_from_cache (module, MTRC_ROOTMAP); char *dupval = NULL; @@ -471,8 +470,7 @@ ht_insert_rootmap (GModule module, uint32_t date, uint32_t key, const char *valu * On error, -1 is returned. * On success 0 is returned */ int -ht_insert_datamap (GModule module, uint32_t date, uint32_t key, const char *value, - uint32_t ckey) { +ht_insert_datamap (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { khash_t (is32) * hash = get_hash (module, date, MTRC_DATAMAP); khash_t (is32) * cache = get_hash_from_cache (module, MTRC_DATAMAP); char *dupval = NULL; @@ -614,8 +612,7 @@ ht_insert_maxts (GModule module, uint32_t date, uint32_t key, uint64_t value, ui * On error, or if key exists, -1 is returned. * On success 0 is returned */ int -ht_insert_method (GModule module, uint32_t date, uint32_t key, const char *value, - uint32_t ckey) { +ht_insert_method (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { GKDB *db = get_db_instance (DB_INSTANCE); khash_t (ii08) * hash = get_hash (module, date, MTRC_METHODS); khash_t (ii08) * cache = get_hash_from_cache (module, MTRC_METHODS); @@ -640,8 +637,7 @@ ht_insert_method (GModule module, uint32_t date, uint32_t key, const char *value * On error, or if key exists, -1 is returned. * On success 0 is returned */ int -ht_insert_protocol (GModule module, uint32_t date, uint32_t key, const char *value, - uint32_t ckey) { +ht_insert_protocol (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { GKDB *db = get_db_instance (DB_INSTANCE); khash_t (ii08) * hash = get_hash (module, date, MTRC_PROTOCOLS); khash_t (ii08) * cache = get_hash_from_cache (module, MTRC_PROTOCOLS); @@ -1190,8 +1186,7 @@ ins_cache_map (GModule module, GSMetric metric, uint32_t key) { } static int -ins_cache_ii08 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, - uint32_t ckey) { +ins_cache_ii08 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { khash_t (ii08) * hash = get_hash_from_store (store, module, metric); khash_t (ii08) * cache = get_hash_from_cache (module, metric); khint_t k; @@ -1202,8 +1197,7 @@ ins_cache_ii08 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t } static int -ins_cache_is32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, - uint32_t ckey) { +ins_cache_is32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { khash_t (is32) * hash = get_hash_from_store (store, module, metric); khash_t (is32) * cache = get_hash_from_cache (module, metric); khint_t k; @@ -1214,8 +1208,7 @@ ins_cache_is32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t } static int -inc_cache_ii32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, - uint32_t ckey) { +inc_cache_ii32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { khash_t (ii32) * hash = get_hash_from_store (store, module, metric); khash_t (ii32) * cache = get_hash_from_cache (module, metric); khint_t k; @@ -1226,8 +1219,7 @@ inc_cache_ii32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t } static int -max_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, - uint32_t ckey) { +max_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { khash_t (iu64) * hash = get_hash_from_store (store, module, metric); khash_t (iu64) * cache = get_hash_from_cache (module, metric); khint_t k; @@ -1241,8 +1233,7 @@ max_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t } static int -inc_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, - uint32_t ckey) { +inc_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { khash_t (iu64) * hash = get_hash_from_store (store, module, metric); khash_t (iu64) * cache = get_hash_from_cache (module, metric); khint_t k; diff --git a/src/gmenu.c b/src/gmenu.c index 583d794d5b..e758fdb74d 100644 --- a/src/gmenu.c +++ b/src/gmenu.c @@ -64,8 +64,7 @@ new_gmenu (WINDOW *parent, int h, int w, int y, int x) { /* Render actual menu item */ static void -draw_menu_item (GMenu *menu, char *s, int x, int y, int w, int checked, - GColors *(*func) (void)) { +draw_menu_item (GMenu *menu, char *s, int x, int y, int w, int checked, GColors *(*func) (void)) { char check, *lbl = NULL; if (menu->selectable) { diff --git a/src/goaccess.c b/src/goaccess.c index eeac4f24df..f038653464 100644 --- a/src/goaccess.c +++ b/src/goaccess.c @@ -351,8 +351,8 @@ allocate_data_by_module (GModule module, int col_data) { size = holder[module].idx > col_data ? col_data : holder[module].idx; } - dash->module[module].alloc_data = size; /* data allocated */ - dash->module[module].ht_size = holder[module].ht_size; /* hash table size */ + dash->module[module].alloc_data = size; /* data allocated */ + dash->module[module].ht_size = holder[module].ht_size; /* hash table size */ dash->module[module].idx_data = 0; dash->module[module].pos_y = 0; @@ -901,7 +901,7 @@ tail_loop_html (Logs *logs) { break; for (i = 0, ret = 0; i < logs->size; ++i) - ret |= perform_tail_follow (&logs->glog[i]); /* 0.2 secs */ + ret |= perform_tail_follow (&logs->glog[i]); /* 0.2 secs */ if (1 == ret) tail_html (); @@ -999,7 +999,7 @@ render_sort_dialog (void) { static void term_tail_logs (Logs *logs) { - struct timespec ts = {.tv_sec = 0,.tv_nsec = 200000000 }; /* 0.2 seconds */ + struct timespec ts = {.tv_sec = 0,.tv_nsec = 200000000 }; /* 0.2 seconds */ uint32_t offset = 0; int i, ret; @@ -1182,13 +1182,13 @@ get_keys (Logs *logs) { expand_current_module (); display_content (main_win, dash, &gscroll); break; - case KEY_DOWN: /* scroll main dashboard */ + case KEY_DOWN: /* scroll main dashboard */ if ((gscroll.dash + main_win_height) < dash->total_alloc) { gscroll.dash++; display_content (main_win, dash, &gscroll); } break; - case KEY_MOUSE: /* handles mouse events */ + case KEY_MOUSE: /* handles mouse events */ if (expand_on_mouse_click () == 0) render_screens (offset); break; diff --git a/src/gstorage.c b/src/gstorage.c index 6ffaf9e3f2..9ac7b0923a 100644 --- a/src/gstorage.c +++ b/src/gstorage.c @@ -727,16 +727,14 @@ insert_maxts (GModule module, GKeyData *kdata, uint64_t ts) { static void insert_method (GModule module, GKeyData *kdata, const char *data) { - ht_insert_method (module, kdata->numdate, kdata->data_nkey, data ? data : "---", - kdata->cdnkey); + ht_insert_method (module, kdata->numdate, kdata->data_nkey, data ? data : "---", kdata->cdnkey); } /* A wrapper call to insert a method given an uint32_t key and string * value. */ static void insert_protocol (GModule module, GKeyData *kdata, const char *data) { - ht_insert_protocol (module, kdata->numdate, kdata->data_nkey, data ? data : "---", - kdata->cdnkey); + ht_insert_protocol (module, kdata->numdate, kdata->data_nkey, data ? data : "---", kdata->cdnkey); } /* A wrapper call to insert an agent for a hostname given an uint32_t @@ -1390,8 +1388,7 @@ static int include_uniq (GLogItem *logitem) { int u = conf.client_err_to_unique_count; - if (!logitem->status || (logitem->status / 100) != 4 || - (u && (logitem->status / 100) == '4')) + if (!logitem->status || (logitem->status / 100) != 4 || (u && (logitem->status / 100) == '4')) return 1; return 0; } diff --git a/src/gwsocket.c b/src/gwsocket.c index c46a36ac4e..14380b83bc 100644 --- a/src/gwsocket.c +++ b/src/gwsocket.c @@ -180,8 +180,8 @@ read_fifo (GWSReader *gwsreader, void (*f) (int)) { return 0; } - readh = gwsreader->hlen; /* read from header so far */ - need = HDR_SIZE - readh; /* need to read */ + readh = gwsreader->hlen; /* read from header so far */ + need = HDR_SIZE - readh; /* need to read */ if (need > 0) { if ((bytes = ws_read_fifo (fd, gwsreader->hdr, &gwsreader->hlen, readh, need)) < 0) return 0; @@ -202,8 +202,8 @@ read_fifo (GWSReader *gwsreader, void (*f) (int)) { (*pa)->data = xcalloc (size + 1, sizeof (char)); } - readh = (*pa)->len; /* read from payload so far */ - need = (*pa)->size - readh; /* need to read */ + readh = (*pa)->len; /* read from payload so far */ + need = (*pa)->size - readh; /* need to read */ if (need > 0) { if ((bytes = ws_read_fifo (fd, (*pa)->data, &(*pa)->len, readh, need)) < 0) return 0; diff --git a/src/json.c b/src/json.c index 99a88d1eb1..6d56f4f52d 100644 --- a/src/json.c +++ b/src/json.c @@ -62,8 +62,7 @@ static int nlines = 0; /* escape HTML in JSON data values */ static int escape_html_output = 0; -static void print_json_data (GJSON * json, GHolder * h, GPercTotals totals, - const struct GPanel_ *); +static void print_json_data (GJSON * json, GHolder * h, GPercTotals totals, const struct GPanel_ *); static void print_json_host_items (GJSON * json, GHolderItem * item, GPercTotals totals, int size, int iisp); static void print_json_sub_items (GJSON * json, GHolderItem * item, @@ -152,7 +151,7 @@ set_json_buffer (GJSON *json, int len) { newlen = INIT_BUF_SIZE; } else { newlen = json->size; - newlen += newlen / 2; /* resize by 3/2 */ + newlen += newlen / 2; /* resize by 3/2 */ } if (newlen < need) @@ -173,7 +172,8 @@ set_json_buffer (GJSON *json, int len) { * * On success, data is outputted. */ __attribute__((format (printf, 2, 3))) - static void pjson (GJSON *json, const char *fmt, ...) { +static void +pjson (GJSON *json, const char *fmt, ...) { int len = 0; va_list args; @@ -189,7 +189,7 @@ __attribute__((format (printf, 2, 3))) vsprintf (json->buf + json->offset, fmt, args); va_end (args); json->offset += len; - } +} /* A wrapper function to output a formatted string to a file pointer. * @@ -240,13 +240,11 @@ escape_json_other (GJSON *json, const char **s) { char buf[8]; snprintf (buf, sizeof buf, "\\u%04x", **s); pjson (json, "%s", buf); - } else if ((uint8_t) ** s == 0xe2 && (uint8_t) * (*s + 1) == 0x80 && - (uint8_t) * (*s + 2) == 0xa8) { + } else if ((uint8_t) ** s == 0xe2 && (uint8_t) * (*s + 1) == 0x80 && (uint8_t) * (*s + 2) == 0xa8) { /* Line separator (U+2028) - 0xE2 0x80 0xA8 */ pjson (json, "\\u2028"); *s += 2; - } else if ((uint8_t) ** s == 0xe2 && (uint8_t) * (*s + 1) == 0x80 && - (uint8_t) * (*s + 2) == 0xa9) { + } else if ((uint8_t) ** s == 0xe2 && (uint8_t) * (*s + 1) == 0x80 && (uint8_t) * (*s + 2) == 0xa9) { /* Paragraph separator (U+2019) - 0xE2 0x80 0xA9 */ pjson (json, "\\u2029"); *s += 2; diff --git a/src/khash.h b/src/khash.h index 1ce5860463..a62df430db 100644 --- a/src/khash.h +++ b/src/khash.h @@ -439,13 +439,14 @@ __attribute__((no_sanitize ("unsigned-integer-overflow"))) __attribute__((no_sanitize ("unsigned-shift-base"))) #endif #endif - static kh_inline khint_t __ac_X31_hash_string (const char *s) { +static kh_inline khint_t +__ac_X31_hash_string (const char *s) { khint_t h = (khint_t) * s; if (h) for (++s; *s; ++s) h = (h << 5) - h + (khint_t) * s; return h; - } +} /*! @function @abstract Another interface to const char* hash function diff --git a/src/options.h b/src/options.h index bd35c9e18e..93fc1d7b7c 100644 --- a/src/options.h +++ b/src/options.h @@ -32,7 +32,7 @@ #define CYN "\x1B[36m" #define RESET "\x1B[0m" -#define HTML_REFRESH 1 /* in seconds */ +#define HTML_REFRESH 1 /* in seconds */ void add_dash_filename (void); void cmd_help (void) __attribute__((noreturn)); diff --git a/src/output.c b/src/output.c index 616e05e218..c01d6aab80 100644 --- a/src/output.c +++ b/src/output.c @@ -536,8 +536,7 @@ print_conn_def (FILE *fp) { fpopen_obj (fp, sp); fpskeysval (fp, "url", (conf.ws_url ? conf.ws_url : ""), sp, 0); fpskeyival (fp, "port", (conf.port ? atoi (conf.port) : 7890), sp, 0); - fpskeyival (fp, "ping_interval", (conf.ping_interval ? atoi (conf.ping_interval) : 0), sp, - 1); + fpskeyival (fp, "ping_interval", (conf.ping_interval ? atoi (conf.ping_interval) : 0), sp, 1); fpclose_obj (fp, sp, 1); fprintf (fp, external_assets ? ";\n" : ""); @@ -887,8 +886,7 @@ print_def_asn (FILE *fp, int sp) { .lbl = MTRC_ASB_LBL, .datatype = "string", .hlregex = "{" - "\\\"^(\\\\\\\\d+)\\\": \\\"$1\\\"," - "\\\"^(AS\\\\\\\\d+)\\\": \\\"$1\\\"" "}", + "\\\"^(\\\\\\\\d+)\\\": \\\"$1\\\"," "\\\"^(AS\\\\\\\\d+)\\\": \\\"$1\\\"" "}", }; if (!conf.has_geoasn) @@ -941,16 +939,16 @@ print_def_data (FILE *fp, GModule module, int sp) { .metakey = "unique", .metalbl = "Total", .metatype = "numeric", - .hlregex = "{" "\\\"^(1\\\\\\\\d{2}|1xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 2xx Success */ - "\\\"^(2\\\\\\\\d{2}|2xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 2xx Success */ - "\\\"^(3\\\\\\\\d{2}|3xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 3xx Success */ - "\\\"^(4\\\\\\\\d{2}|4xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 4xx Success */ - "\\\"^(5\\\\\\\\d{2}|5xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 5xx Success */ - "\\\"^(0\\\\\\\\d{2}|0xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 5xx Success */ - "\\\"^(AS\\\\\\\\d+)\\\": \\\"$1\\\"," /* AS9823 Google */ - "\\\"^(\\\\\\\\d+:)\\\": \\\"$1\\\"," /* 01234: Data */ - "\\\"(\\\\\\\\d+)|(:\\\\\\\\d+)|(:\\\\\\\\d+:\\\\\\\\d+)\\\": \\\"$1$2\\\"," /* 12/May/2022:12:34 */ - "\\\"^([A-Z]{2})(\\\\\\\\s.*$)\\\": \\\"$1$2\\\"" /* US United States */ + .hlregex = "{" "\\\"^(1\\\\\\\\d{2}|1xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 2xx Success */ + "\\\"^(2\\\\\\\\d{2}|2xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 2xx Success */ + "\\\"^(3\\\\\\\\d{2}|3xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 3xx Success */ + "\\\"^(4\\\\\\\\d{2}|4xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 4xx Success */ + "\\\"^(5\\\\\\\\d{2}|5xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 5xx Success */ + "\\\"^(0\\\\\\\\d{2}|0xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 5xx Success */ + "\\\"^(AS\\\\\\\\d+)\\\": \\\"$1\\\"," /* AS9823 Google */ + "\\\"^(\\\\\\\\d+:)\\\": \\\"$1\\\"," /* 01234: Data */ + "\\\"(\\\\\\\\d+)|(:\\\\\\\\d+)|(:\\\\\\\\d+:\\\\\\\\d+)\\\": \\\"$1$2\\\"," /* 12/May/2022:12:34 */ + "\\\"^([A-Z]{2})(\\\\\\\\s.*$)\\\": \\\"$1$2\\\"" /* US United States */ "}", }; diff --git a/src/output.h b/src/output.h index 6dbcb57200..ac96967a0c 100644 --- a/src/output.h +++ b/src/output.h @@ -34,7 +34,7 @@ #ifndef OUTPUT_H_INCLUDED #define OUTPUT_H_INCLUDED -#define MAX_PLOTS 5 /* number of metrics we can plot */ +#define MAX_PLOTS 5 /* number of metrics we can plot */ #define FILENAME_JS "goaccess.js" #define FILENAME_CSS "goaccess.css" diff --git a/src/parser.c b/src/parser.c index 7a80f83713..9009dc0446 100644 --- a/src/parser.c +++ b/src/parser.c @@ -144,16 +144,14 @@ set_glog (Logs *logs, const char *filename) { logs->size = newlen; } - fn = xstrdup (filename); /* ensure fn is a string */ + fn = xstrdup (filename); /* ensure fn is a string */ glog = logs->glog; glog[logs->idx].errors = xcalloc (MAX_LOG_ERRORS, sizeof (char *)); glog[logs->idx].props.filename = xstrdup (fn); glog[logs->idx].props.fname = xstrdup (basename (fn)); if (!glog->pipe && conf.fname_as_vhost) { - if (! - (fvh = - regex_extract_string (glog[logs->idx].props.fname, conf.fname_as_vhost, 1, &err))) + if (!(fvh = regex_extract_string (glog[logs->idx].props.fname, conf.fname_as_vhost, 1, &err))) FATAL ("%s %s[%s]", err, glog[logs->idx].props.fname, conf.fname_as_vhost); glog[logs->idx].fname_as_vhost = fvh; } @@ -1134,7 +1132,7 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) bandw = 0; logitem->resp_size = bandw; - __sync_bool_compare_and_swap (&conf.bandwidth, 0, 1); /* set flag */ + __sync_bool_compare_and_swap (&conf.bandwidth, 0, 1); /* set flag */ free (tkn); break; /* referrer */ @@ -1203,7 +1201,7 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char logitem->serve_time = (serve_secs > 0) ? serve_secs * MILS : 0; /* Determine if time-served data was stored on-disk. */ - __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ free (tkn); break; /* time taken to serve the request, in seconds with a milliseconds @@ -1226,7 +1224,7 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char logitem->serve_time = (serve_secs > 0) ? serve_secs * SECS : 0; /* Determine if time-served data was stored on-disk. */ - __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ free (tkn); break; /* time taken to serve the request, in microseconds */ @@ -1243,7 +1241,7 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char logitem->serve_time = serve_time; /* Determine if time-served data was stored on-disk. */ - __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ free (tkn); break; /* time taken to serve the request, in nanoseconds */ @@ -1262,7 +1260,7 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char logitem->serve_time = (serve_time > 0) ? serve_time / MILS : 0; /* Determine if time-served data was stored on-disk. */ - __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ free (tkn); break; /* UMS: Krypto (TLS) "ECDHE-RSA-AES128-GCM-SHA256" */ @@ -1564,8 +1562,7 @@ output_logerrors (void) { if (!glog->log_erridx) continue; - fprintf (stderr, "==%d== GoAccess - version %s - %s %s\n", pid, GO_VERSION, __DATE__, - __TIME__); + fprintf (stderr, "==%d== GoAccess - version %s - %s %s\n", pid, GO_VERSION, __DATE__, __TIME__); fprintf (stderr, "==%d== Config file: %s\n", pid, conf.iconfigfile ? : NO_CONFIG_FILE); fprintf (stderr, "==%d== https://goaccess.io - \n", pid); fprintf (stderr, "==%d== Released under the MIT License.\n", pid); @@ -1868,9 +1865,9 @@ static int atomic_lpts_update (GLog *glog, GLogItem *logitem) { int64_t oldts = 0, newts = 0; /* atomic update loop */ - newts = mktime (&logitem->dt); // Get timestamp from logitem->dt + newts = mktime (&logitem->dt); // Get timestamp from logitem->dt while (!__sync_bool_compare_and_swap (&glog->lp.ts, oldts, newts)) { - oldts = glog->lp.ts; /* Reread glog->lp.ts if CAS failed */ + oldts = glog->lp.ts; /* Reread glog->lp.ts if CAS failed */ if (oldts >= newts) { break; /* No need to update if oldts is already greater */ } @@ -1999,8 +1996,7 @@ read_lines_thread (void *arg) { /* ensure we don't process more than we should when testing for log format, * else free chunk and stop processing threads */ if (!job->test || (job->test && job->cnt < conf.num_tests)) - job->logitems[i] = - read_line (job->glog, job->lines[i], &job->test, &job->cnt, job->dry_run); + job->logitems[i] = read_line (job->glog, job->lines[i], &job->test, &job->cnt, job->dry_run); else conf.stop_processing = 1; @@ -2220,7 +2216,7 @@ read_lines (FILE *fp, GLog *glog, int dry_run) { /* flip from block A/B to B/A */ if (conf.jobs > 1) b = b ^ 1; - } // while (1) + } // while (1) /* After eof, process last data */ for (b = 0; b < 2; b++) { diff --git a/src/parser.h b/src/parser.h index 94c1936e35..c911ed2c74 100644 --- a/src/parser.h +++ b/src/parser.h @@ -32,15 +32,15 @@ #define KEY_FOUND 1 #define KEY_NOT_FOUND -1 -#define LINE_BUFFER 4096 /* read at most this num of chars */ -#define NUM_TESTS 20 /* test this many lines from the log */ +#define LINE_BUFFER 4096 /* read at most this num of chars */ +#define NUM_TESTS 20 /* test this many lines from the log */ #define MAX_LOG_ERRORS 20 #define READ_BYTES 4096u -#define MAX_BATCH_LINES 8192u /* max number of lines to read per batch before a reflow */ +#define MAX_BATCH_LINES 8192u /* max number of lines to read per batch before a reflow */ #define LINE_LEN 23 #define ERROR_LEN 255 -#define REF_SITE_LEN 511 /* maximum length of a referring site */ +#define REF_SITE_LEN 511 /* maximum length of a referring site */ #define CACHE_STATUS_LEN 7 #define HASH_HEX 64 diff --git a/src/pdjson.c b/src/pdjson.c index b34281ca5a..0b75871964 100644 --- a/src/pdjson.c +++ b/src/pdjson.c @@ -574,7 +574,7 @@ read_number (json_stream *json, int c) { return JSON_NUMBER; } if (c == '.') { - json->source.get (&json->source); // consume . + json->source.get (&json->source); // consume . if (pushchar (json, c) != 0) return JSON_ERROR; if (read_digits (json) != 0) @@ -583,7 +583,7 @@ read_number (json_stream *json, int c) { /* Check for exponent. */ c = json->source.peek (&json->source); if (c == 'e' || c == 'E') { - json->source.get (&json->source); // consume e/E + json->source.get (&json->source); // consume e/E if (pushchar (json, c) != 0) return JSON_ERROR; c = json->source.peek (&json->source); diff --git a/src/settings.c b/src/settings.c index d39fa9088e..0296c9168e 100644 --- a/src/settings.c +++ b/src/settings.c @@ -707,7 +707,7 @@ set_date_num_format (void) { } flen = strlen (fdate) + 1; - flen = MAX (MIN_DATENUM_FMT_LEN, flen); /* at least %Y%m%d + 1 */ + flen = MAX (MIN_DATENUM_FMT_LEN, flen); /* at least %Y%m%d + 1 */ buf = xcalloc (flen, sizeof (char)); /* always add a %Y */ @@ -933,18 +933,18 @@ set_time_format_str (const char *oarg) { /* Determine if some global flags were set through log-format. */ static void contains_specifier (void) { - conf.serve_usecs = conf.bandwidth = 0; /* flag */ + conf.serve_usecs = conf.bandwidth = 0; /* flag */ if (!conf.log_format) return; if (strstr (conf.log_format, "%b")) conf.bandwidth = 1; /* flag */ if (strstr (conf.log_format, "%D")) - conf.serve_usecs = 1; /* flag */ + conf.serve_usecs = 1; /* flag */ if (strstr (conf.log_format, "%T")) - conf.serve_usecs = 1; /* flag */ + conf.serve_usecs = 1; /* flag */ if (strstr (conf.log_format, "%L")) - conf.serve_usecs = 1; /* flag */ + conf.serve_usecs = 1; /* flag */ } /* Attempt to set the log format given a command line option argument. @@ -962,14 +962,14 @@ set_log_format_str (const char *oarg) { if (type == -1 && is_json_log_format (oarg)) { conf.is_json_log_format = 1; conf.log_format = unescape_str (oarg); - contains_specifier (); /* set flag */ + contains_specifier (); /* set flag */ return; } /* type not found, use whatever was given by the user then */ if (type == -1) { conf.log_format = unescape_str (oarg); - contains_specifier (); /* set flag */ + contains_specifier (); /* set flag */ return; } @@ -983,7 +983,7 @@ set_log_format_str (const char *oarg) { conf.is_json_log_format = 1; conf.log_format = unescape_str (fmt); - contains_specifier (); /* set flag */ + contains_specifier (); /* set flag */ /* assume we are using the default date/time formats */ set_time_format_str (oarg); diff --git a/src/sha1.c b/src/sha1.c index 76af713511..5af8cdb3c5 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -212,7 +212,7 @@ SHA1Final (uint8_t digest[20], SHA1_CTX *context) { while ((context->count[0] & 504) != 448) { SHA1Update (context, (uint8_t *) "\0", 1); } - SHA1Update (context, finalcount, 8); /* Should cause a SHA1Transform() */ + SHA1Update (context, finalcount, 8); /* Should cause a SHA1Transform() */ for (i = 0; i < 20; i++) { digest[i] = (uint8_t) ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); @@ -223,7 +223,7 @@ SHA1Final (uint8_t digest[20], SHA1_CTX *context) { memset (context->state, 0, 20); memset (context->count, 0, 8); memset (&finalcount, 0, 8); -#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ +#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ SHA1Transform (context->state, context->buffer); #endif } diff --git a/src/sort.c b/src/sort.c index 6006ead22d..cb3d0feb06 100644 --- a/src/sort.c +++ b/src/sort.c @@ -350,15 +350,16 @@ cmp_mthd_desc (const void *a, const void *b) { #if defined(__clang__) && defined(__clang_major__) && (__clang_major__ >= 4) __attribute__((no_sanitize ("implicit-conversion", "unsigned-integer-overflow"))) #endif - int cmp_ui32_asc (const void *a, const void *b) { - const uint32_t *ia = (const uint32_t *) a; // casting pointer types +int +cmp_ui32_asc (const void *a, const void *b) { + const uint32_t *ia = (const uint32_t *) a; // casting pointer types const uint32_t *ib = (const uint32_t *) b; return *ia - *ib; - } +} int cmp_ui32_desc (const void *a, const void *b) { - const uint32_t *ia = (const uint32_t *) a; // casting pointer types + const uint32_t *ia = (const uint32_t *) a; // casting pointer types const uint32_t *ib = (const uint32_t *) b; return *ib - *ia; } diff --git a/src/sort.h b/src/sort.h index f73a78f082..06ed02092c 100644 --- a/src/sort.h +++ b/src/sort.h @@ -40,9 +40,9 @@ #define SORT_MAX_OPTS 11 /* See GEnum for mapping */ -#define SORT_FIELD_LEN 11 + 1 /* longest metric name */ -#define SORT_MODULE_LEN 15 + 1 /* longest module name */ -#define SORT_ORDER_LEN 4 + 1 /* length of ASC or DESC */ +#define SORT_FIELD_LEN 11 + 1 /* longest metric name */ +#define SORT_MODULE_LEN 15 + 1 /* longest module name */ +#define SORT_ORDER_LEN 4 + 1 /* length of ASC or DESC */ /* Enumerated sorting metrics */ typedef enum GSortField_ { diff --git a/src/tpl.c b/src/tpl.c index b5c3f697ca..fd6dfb5a3b 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -26,22 +26,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /*static const char id[]="$Id: tpl.c 192 2009-04-24 10:35:30Z thanson $";*/ -#include /* malloc */ -#include /* va_list */ -#include /* memcpy, memset, strchr */ -#include /* printf (tpl_hook.oops default function) */ +#include /* malloc */ +#include /* va_list */ +#include /* memcpy, memset, strchr */ +#include /* printf (tpl_hook.oops default function) */ #ifndef _WIN32 -#include /* for ftruncate */ +#include /* for ftruncate */ #else #include #define ftruncate(x,y) _chsize(x,y) #endif -#include /* for 'open' */ -#include /* for 'open' */ +#include /* for 'open' */ +#include /* for 'open' */ #include #ifndef _WIN32 -#include /* uint32_t, uint64_t, etc */ +#include /* uint32_t, uint64_t, etc */ #else typedef unsigned short ushort; typedef __int16 int16_t; @@ -57,9 +57,9 @@ typedef unsigned __int64 uint64_t; #endif #if ( defined __CYGWIN__ || defined __MINGW32__ || defined _WIN32 ) -#include "win/mman.h" /* mmap */ +#include "win/mman.h" /* mmap */ #else -#include /* mmap */ +#include /* mmap */ #endif #include "tpl.h" @@ -85,10 +85,10 @@ typedef unsigned __int64 uint64_t; #define fatal_oom() tpl_hook.fatal("out of memory\n") /* bit flags (internal). preceded by the external flags in tpl.h */ -#define TPL_WRONLY (1 << 9) /* app has initiated tpl packing */ -#define TPL_RDONLY (1 << 10) /* tpl was loaded (for unpacking) */ -#define TPL_XENDIAN (1 << 11) /* swap endianness when unpacking */ -#define TPL_OLD_STRING_FMT (1 << 12) /* tpl has strings in 1.2 format */ +#define TPL_WRONLY (1 << 9) /* app has initiated tpl packing */ +#define TPL_RDONLY (1 << 10) /* tpl was loaded (for unpacking) */ +#define TPL_XENDIAN (1 << 11) /* swap endianness when unpacking */ +#define TPL_OLD_STRING_FMT (1 << 12) /* tpl has strings in 1.2 format */ /* values for the flags byte that appears after the magic prefix */ #define TPL_SUPPORTED_BITFLAGS 3 @@ -236,7 +236,7 @@ tpl_hook_t tpl_hook = { static const char tpl_fmt_chars[] = "AS($)BiucsfIUjv#"; /* valid format chars */ /* valid within S(...) */ /* static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()"; */ -static const char tpl_datapeek_ok_chars[] = "iucsfIUjv"; /* valid in datapeek */ +static const char tpl_datapeek_ok_chars[] = "iucsfIUjv"; /* valid in datapeek */ static const struct tpl_type_t tpl_types[] = { /* [TPL_TYPE_ROOT] = */ {'r', 0}, /* [TPL_TYPE_INT32] = */ {'i', sizeof (int32_t)}, @@ -354,9 +354,9 @@ tpl_map_va (char *fmt, va_list ap) { memset ((tpl_root_data *) root->data, 0, sizeof (tpl_root_data)); /* set up root nodes special ser_osz to reflect overhead of preamble */ - root->ser_osz = sizeof (uint32_t); /* tpl leading length */ - root->ser_osz += strlen (fmt) + 1; /* fmt + NUL-terminator */ - root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */ + root->ser_osz = sizeof (uint32_t); /* tpl leading length */ + root->ser_osz += strlen (fmt) + 1; /* fmt + NUL-terminator */ + root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */ parent = root; @@ -418,7 +418,7 @@ tpl_map_va (char *fmt, va_list ap) { n->type = TPL_TYPE_STR; if (in_structure) { if (ordinal == 1) { - iter_start_node = n; /* for S(...)# iteration */ + iter_start_node = n; /* for S(...)# iteration */ struct_widest_node = n; } if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) { @@ -439,7 +439,7 @@ tpl_map_va (char *fmt, va_list ap) { /* apply a 'num' to preceding atom */ if (!parent->children) goto fail; - preceding = parent->children->prev; /* first child's prev is 'last child' */ + preceding = parent->children->prev; /* first child's prev is 'last child' */ t = preceding->type; applies_to_struct = (*(c - 1) == ')') ? 1 : 0; if (!applies_to_struct) { @@ -466,7 +466,7 @@ tpl_map_va (char *fmt, va_list ap) { /* increment c to skip contiguous # so its points to last one */ c = peek - 1; /* differentiate atom-# from struct-# by noting preceding rparen */ - if (applies_to_struct) { /* insert # node to induce looping */ + if (applies_to_struct) { /* insert # node to induce looping */ n = tpl_node_new (parent); n->type = TPL_TYPE_POUND; n->num = pound_prod; @@ -501,9 +501,9 @@ tpl_map_va (char *fmt, va_list ap) { } root->ser_osz += (sizeof (uint32_t) * num_contig_fxlens); - j = ((tpl_root_data *) root->data)->num_fxlens; /* before incrementing */ + j = ((tpl_root_data *) root->data)->num_fxlens; /* before incrementing */ (((tpl_root_data *) root->data)->num_fxlens) += num_contig_fxlens; - num_fxlens = ((tpl_root_data *) root->data)->num_fxlens; /* new value */ + num_fxlens = ((tpl_root_data *) root->data)->num_fxlens; /* new value */ fxlens = ((tpl_root_data *) root->data)->fxlens; fxlens = tpl_hook.realloc (fxlens, sizeof (int) * num_fxlens); if (!fxlens) @@ -559,8 +559,8 @@ tpl_map_va (char *fmt, va_list ap) { if (in_structure) goto fail; expect_lparen = 1; - ordinal = 1; /* index upcoming atoms in S(..) */ - in_structure = 1 + lparen_level; /* so we can tell where S fmt ends */ + ordinal = 1; /* index upcoming atoms in S(..) */ + in_structure = 1 + lparen_level; /* so we can tell where S fmt ends */ struct_addr = (char *) va_arg (ap, void *); break; case '$': /* nested structure */ @@ -579,12 +579,11 @@ tpl_map_va (char *fmt, va_list ap) { in_nested_structure--; else if (in_structure && (in_structure - 1 == lparen_level)) { /* calculate delta between contiguous structures in array */ - struct_next = calc_field_addr (parent, struct_widest_node->type, - struct_addr, ordinal++); + struct_next = calc_field_addr (parent, struct_widest_node->type, struct_addr, ordinal++); inter_elt_len = struct_next - struct_addr; in_structure = 0; } else - parent = parent->parent; /* rparen ends A() type, not S() type */ + parent = parent->parent; /* rparen ends A() type, not S() type */ break; case '(': if (!expect_lparen) @@ -644,7 +643,7 @@ tpl_free_keep_map (tpl_node *r) { c = r->children; if (c) { - while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ + while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ switch (c->type) { case TPL_TYPE_BIN: /* free any binary buffer hanging from tpl_bin */ @@ -652,7 +651,7 @@ tpl_free_keep_map (tpl_node *r) { if ((*((tpl_bin **) (c->data)))->addr) { tpl_hook.free ((*((tpl_bin **) (c->data)))->addr); } - *((tpl_bin **) c->data) = NULL; /* reset tpl_bin */ + *((tpl_bin **) c->data) = NULL; /* reset tpl_bin */ } find_next_node = 1; break; @@ -681,7 +680,7 @@ tpl_free_keep_map (tpl_node *r) { case TPL_TYPE_ARY: c->ser_osz = 0; /* zero out the serialization output size */ - sz = ((tpl_atyp *) (c->data))->sz; /* save sz to use below */ + sz = ((tpl_atyp *) (c->data))->sz; /* save sz to use below */ tpl_free_atyp (c, c->data); /* make new atyp */ @@ -689,7 +688,7 @@ tpl_free_keep_map (tpl_node *r) { if (!c->data) fatal_oom (); ((tpl_atyp *) (c->data))->num = 0; - ((tpl_atyp *) (c->data))->sz = sz; /* restore bb datum sz */ + ((tpl_atyp *) (c->data))->sz = sz; /* restore bb datum sz */ ((tpl_atyp *) (c->data))->bb = NULL; ((tpl_atyp *) (c->data))->bbtail = NULL; ((tpl_atyp *) (c->data))->cur = NULL; @@ -711,7 +710,7 @@ tpl_free_keep_map (tpl_node *r) { looking = 0; } else { if (c->type == TPL_TYPE_ROOT) - break; /* root node */ + break; /* root node */ else { nxtc = c->parent; c = nxtc; @@ -722,7 +721,7 @@ tpl_free_keep_map (tpl_node *r) { } } - ((tpl_root_data *) (r->data))->flags = 0; /* reset flags */ + ((tpl_root_data *) (r->data))->flags = 0; /* reset flags */ } TPL_API void @@ -742,7 +741,7 @@ tpl_free (tpl_node *r) { c = r->children; if (c) { - while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ + while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ switch (c->type) { case TPL_TYPE_BIN: /* free any binary buffer hanging from tpl_bin */ @@ -750,9 +749,9 @@ tpl_free (tpl_node *r) { if ((*((tpl_bin **) (c->data)))->sz != 0) { tpl_hook.free ((*((tpl_bin **) (c->data)))->addr); } - tpl_hook.free (*((tpl_bin **) c->data)); /* free tpl_bin */ + tpl_hook.free (*((tpl_bin **) c->data)); /* free tpl_bin */ } - tpl_hook.free (c->data); /* free tpl_bin* */ + tpl_hook.free (c->data); /* free tpl_bin* */ find_next_node = 1; break; case TPL_TYPE_STR: @@ -790,9 +789,9 @@ tpl_free (tpl_node *r) { case TPL_TYPE_ARY: tpl_free_atyp (c, c->data); if (c->children) - c = c->children; /* normal case */ + c = c->children; /* normal case */ else - find_next_node = 1; /* edge case, handle bad format A() */ + find_next_node = 1; /* edge case, handle bad format A() */ break; default: tpl_hook.fatal ("unsupported format character\n"); @@ -810,7 +809,7 @@ tpl_free (tpl_node *r) { looking = 0; } else { if (c->type == TPL_TYPE_ROOT) - break; /* root node */ + break; /* root node */ else { nxtc = c->parent; tpl_hook.free (c); @@ -831,7 +830,7 @@ tpl_free (tpl_node *r) { if (((tpl_root_data *) (r->data))->num_fxlens > 0) { tpl_hook.free (((tpl_root_data *) (r->data))->fxlens); } - tpl_hook.free (r->data); /* tpl_root_data */ + tpl_hook.free (r->data); /* tpl_root_data */ tpl_hook.free (r); } @@ -914,7 +913,7 @@ tpl_dump_atyp (tpl_node *n, tpl_atyp *at, void *dv) { size_t itermax; /* handle 'A' nodes */ - dv = tpl_cpv (dv, &at->num, sizeof (uint32_t)); /* array len */ + dv = tpl_cpv (dv, &at->num, sizeof (uint32_t)); /* array len */ for (bb = at->bb; bb; bb = bb->next) { datav = bb->data; c = n->children; @@ -933,7 +932,7 @@ tpl_dump_atyp (tpl_node *n, tpl_atyp *at, void *dv) { break; case TPL_TYPE_BIN: /* dump the buffer length followed by the buffer */ - memcpy (&binp, datav, sizeof (tpl_bin *)); /* cp to aligned */ + memcpy (&binp, datav, sizeof (tpl_bin *)); /* cp to aligned */ slen = binp->sz; dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); dv = tpl_cpv (dv, binp->addr, slen); @@ -942,7 +941,7 @@ tpl_dump_atyp (tpl_node *n, tpl_atyp *at, void *dv) { case TPL_TYPE_STR: /* dump the string length followed by the string */ for (i = 0; i < c->num; i++) { - memcpy (&strp, datav, sizeof (char *)); /* cp to aligned */ + memcpy (&strp, datav, sizeof (char *)); /* cp to aligned */ slen = strp ? (strlen (strp) + 1) : 0; dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); if (slen > 1) @@ -951,7 +950,7 @@ tpl_dump_atyp (tpl_node *n, tpl_atyp *at, void *dv) { } break; case TPL_TYPE_ARY: - memcpy (&atypp, datav, sizeof (tpl_atyp *)); /* cp to aligned */ + memcpy (&atypp, datav, sizeof (tpl_atyp *)); /* cp to aligned */ dv = tpl_dump_atyp (c, atypp, dv); datav = (void *) ((uintptr_t) datav + sizeof (void *)); break; @@ -962,7 +961,7 @@ tpl_dump_atyp (tpl_node *n, tpl_atyp *at, void *dv) { if (++(pd->iternum) < itermax) { c = pd->iter_start_node; continue; - } else { /* loop complete. */ + } else { /* loop complete. */ pd->iternum = 0; } break; @@ -991,7 +990,7 @@ tpl_ser_osz (tpl_node *n) { tpl_hook.fatal ("internal error: tpl_ser_osz on non-root node\n"); } - sz = n->ser_osz; /* start with fixed overhead, already stored */ + sz = n->ser_osz; /* start with fixed overhead, already stored */ c = n->children; while (c) { switch (c->type) { @@ -1006,19 +1005,19 @@ tpl_ser_osz (tpl_node *n) { sz += tpl_types[c->type].sz * c->num; break; case TPL_TYPE_BIN: - sz += sizeof (uint32_t); /* binary buf len */ - memcpy (&binp, c->data, sizeof (tpl_bin *)); /* cp to aligned */ + sz += sizeof (uint32_t); /* binary buf len */ + memcpy (&binp, c->data, sizeof (tpl_bin *)); /* cp to aligned */ sz += binp->sz; break; case TPL_TYPE_STR: for (i = 0; i < c->num; i++) { - sz += sizeof (uint32_t); /* string len */ - memcpy (&strp, &((char **) c->data)[i], sizeof (char *)); /* cp to aligned */ + sz += sizeof (uint32_t); /* string len */ + memcpy (&strp, &((char **) c->data)[i], sizeof (char *)); /* cp to aligned */ sz += strp ? strlen (strp) : 0; } break; case TPL_TYPE_ARY: - sz += sizeof (uint32_t); /* array len */ + sz += sizeof (uint32_t); /* array len */ sz += c->ser_osz; /* bubbled-up child array ser_osz */ break; case TPL_TYPE_POUND: @@ -1057,7 +1056,7 @@ tpl_dump (tpl_node *r, int mode, ...) { size_t sz, *sz_out, pa_sz; struct stat sbuf; - if (((tpl_root_data *) (r->data))->flags & TPL_RDONLY) { /* unusual */ + if (((tpl_root_data *) (r->data))->flags & TPL_RDONLY) { /* unusual */ tpl_hook.oops ("error: tpl_dump called for a loaded tpl\n"); return -1; } @@ -1161,12 +1160,12 @@ tpl_dump_to_mem (tpl_node *r, void *addr, size_t sz) { sz32 = sz; dv = addr; - dv = tpl_cpv (dv, TPL_MAGIC, 3); /* copy tpl magic prefix */ + dv = tpl_cpv (dv, TPL_MAGIC, 3); /* copy tpl magic prefix */ dv = tpl_cpv (dv, &flags, 1); /* copy flags byte */ - dv = tpl_cpv (dv, &sz32, sizeof (uint32_t)); /* overall length (inclusive) */ - dv = tpl_cpv (dv, fmt, strlen (fmt) + 1); /* copy format with NUL-term */ + dv = tpl_cpv (dv, &sz32, sizeof (uint32_t)); /* overall length (inclusive) */ + dv = tpl_cpv (dv, fmt, strlen (fmt) + 1); /* copy format with NUL-term */ fxlens = tpl_fxlens (r, &num_fxlens); - dv = tpl_cpv (dv, fxlens, num_fxlens * sizeof (uint32_t)); /* fmt # lengths */ + dv = tpl_cpv (dv, fxlens, num_fxlens * sizeof (uint32_t)); /* fmt # lengths */ /* serialize the tpl content, iterating over direct children of root */ c = r->children; @@ -1184,16 +1183,16 @@ tpl_dump_to_mem (tpl_node *r, void *addr, size_t sz) { break; case TPL_TYPE_BIN: slen = (*(tpl_bin **) (c->data))->sz; - dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); /* buffer len */ + dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); /* buffer len */ dv = tpl_cpv (dv, (*(tpl_bin **) (c->data))->addr, slen); /* buf */ break; case TPL_TYPE_STR: for (i = 0; i < c->num; i++) { char *str = ((char **) c->data)[i]; slen = str ? strlen (str) + 1 : 0; - dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); /* string len */ + dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); /* string len */ if (slen > 1) - dv = tpl_cpv (dv, str, slen - 1); /*string */ + dv = tpl_cpv (dv, str, slen - 1); /*string */ } break; case TPL_TYPE_ARY: @@ -1262,13 +1261,13 @@ tpl_sanity (tpl_node *r, int excess_ok) { dv = d; if (bufsz < (4 + sizeof (uint32_t) + 1)) - return ERR_NOT_MINSIZE; /* min sz: magic+flags+len+nul */ + return ERR_NOT_MINSIZE; /* min sz: magic+flags+len+nul */ if (memcmp (dv, TPL_MAGIC, 3) != 0) - return ERR_MAGIC_MISMATCH; /* missing tpl magic prefix */ + return ERR_MAGIC_MISMATCH; /* missing tpl magic prefix */ if (tpl_needs_endian_swap (dv)) ((tpl_root_data *) (r->data))->flags |= TPL_XENDIAN; dv = (void *) ((uintptr_t) dv + 3); - memcpy (&intlflags, dv, sizeof (char)); /* extract flags */ + memcpy (&intlflags, dv, sizeof (char)); /* extract flags */ if (intlflags & ~TPL_SUPPORTED_BITFLAGS) return ERR_UNSUPPORTED_FLAGS; /* TPL1.3 stores strings with a "length+1" prefix to discern NULL strings from @@ -1278,7 +1277,7 @@ tpl_sanity (tpl_node *r, int excess_ok) { ((tpl_root_data *) (r->data))->flags |= TPL_OLD_STRING_FMT; } dv = (void *) ((uintptr_t) dv + 1); - memcpy (&intlsz, dv, sizeof (uint32_t)); /* extract internal size */ + memcpy (&intlsz, dv, sizeof (uint32_t)); /* extract internal size */ if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) tpl_byteswap (&intlsz, sizeof (uint32_t)); if (!excess_ok && (intlsz != bufsz)) @@ -1299,7 +1298,7 @@ tpl_sanity (tpl_node *r, int excess_ok) { } if (!found_nul) return ERR_FMT_MISSING_NUL; /* runaway format string */ - dv = (void *) ((uintptr_t) dv + 1); /* advance to octothorpe lengths buffer */ + dv = (void *) ((uintptr_t) dv + 1); /* advance to octothorpe lengths buffer */ /* compare the map format to the format of this tpl image */ mapfmt = tpl_fmt (r); @@ -1312,7 +1311,7 @@ tpl_sanity (tpl_node *r, int excess_ok) { return ERR_INCONSISTENT_SZ4; fxlens = tpl_fxlens (r, &num_fxlens); /* mapped fxlens */ while (num_fxlens--) { - memcpy (&flen, dv, sizeof (uint32_t)); /* stored flen */ + memcpy (&flen, dv, sizeof (uint32_t)); /* stored flen */ if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) tpl_byteswap (&flen, sizeof (uint32_t)); if (flen != *fxlens) @@ -1322,29 +1321,29 @@ tpl_sanity (tpl_node *r, int excess_ok) { } /* dv now points to beginning of data */ - rc = tpl_serlen (r, r, dv, &serlen); /* get computed serlen of data part */ + rc = tpl_serlen (r, r, dv, &serlen); /* get computed serlen of data part */ if (rc == -1) - return ERR_INCONSISTENT_SZ2; /* internal inconsistency in tpl image */ - serlen += ((uintptr_t) dv - (uintptr_t) d); /* add back serlen of preamble part */ + return ERR_INCONSISTENT_SZ2; /* internal inconsistency in tpl image */ + serlen += ((uintptr_t) dv - (uintptr_t) d); /* add back serlen of preamble part */ if (excess_ok && (bufsz < serlen)) return ERR_INCONSISTENT_SZ3; if (!excess_ok && (serlen != bufsz)) - return ERR_INCONSISTENT_SZ3; /* buffer/internal sz exceeds serlen */ + return ERR_INCONSISTENT_SZ3; /* buffer/internal sz exceeds serlen */ return 0; } static void * tpl_find_data_start (void *d) { int octothorpes = 0; - d = (void *) ((uintptr_t) d + 4); /* skip TPL_MAGIC and flags byte */ - d = (void *) ((uintptr_t) d + 4); /* skip int32 overall len */ + d = (void *) ((uintptr_t) d + 4); /* skip TPL_MAGIC and flags byte */ + d = (void *) ((uintptr_t) d + 4); /* skip int32 overall len */ while (*(char *) d != '\0') { if (*(char *) d == '#') octothorpes++; d = (void *) ((uintptr_t) d + 1); } - d = (void *) ((uintptr_t) d + 1); /* skip NUL */ - d = (void *) ((uintptr_t) d + (octothorpes * sizeof (uint32_t))); /* skip # array lens */ + d = (void *) ((uintptr_t) d + 1); /* skip NUL */ + d = (void *) ((uintptr_t) d + (octothorpes * sizeof (uint32_t))); /* skip # array lens */ return d; } @@ -1422,7 +1421,7 @@ tpl_peek (int mode, ...) { if ((((char *) dv)[3] & TPL_FL_NULLSTRINGS) == 0) old_string_format = 1; dv = (void *) ((uintptr_t) dv + 4); - memcpy (&intlsz, dv, sizeof (uint32_t)); /* extract internal size */ + memcpy (&intlsz, dv, sizeof (uint32_t)); /* extract internal size */ if (xendian) tpl_byteswap (&intlsz, sizeof (uint32_t)); if (intlsz != sz) @@ -1441,7 +1440,7 @@ tpl_peek (int mode, ...) { } if (!found_nul) goto fail; /* runaway format string */ - fmt_len = (char *) dv - fmt; /* include space for \0 */ + fmt_len = (char *) dv - fmt; /* include space for \0 */ fmt_cpy = tpl_hook.malloc (fmt_len); if (fmt_cpy == NULL) { fatal_oom (); @@ -1471,20 +1470,20 @@ tpl_peek (int mode, ...) { /* if caller requested, peek into the specified data elements */ if (mode & TPL_DATAPEEK) { - first_atom = strspn (fmt, "S()"); /* skip any leading S() */ + first_atom = strspn (fmt, "S()"); /* skip any leading S() */ datapeek_flen = strlen (datapeek_f); if (strspn (datapeek_f, tpl_datapeek_ok_chars) < datapeek_flen) { tpl_hook.oops ("invalid TPL_DATAPEEK format: %s\n", datapeek_f); tpl_hook.free (fmt_cpy); - fmt_cpy = NULL; /* fail */ + fmt_cpy = NULL; /* fail */ goto fail; } if (strncmp (&fmt[first_atom], datapeek_f, datapeek_flen) != 0) { tpl_hook.oops ("TPL_DATAPEEK format mismatches tpl image\n"); tpl_hook.free (fmt_cpy); - fmt_cpy = NULL; /* fail */ + fmt_cpy = NULL; /* fail */ goto fail; } @@ -1496,22 +1495,22 @@ tpl_peek (int mode, ...) { if ((uintptr_t) dv - (uintptr_t) addr + sizeof (uint32_t) > sz) { tpl_hook.oops ("tpl_peek: tpl has insufficient length\n"); tpl_hook.free (fmt_cpy); - fmt_cpy = NULL; /* fail */ + fmt_cpy = NULL; /* fail */ goto fail; } - memcpy (&datapeek_ssz, dv, sizeof (uint32_t)); /* get slen */ + memcpy (&datapeek_ssz, dv, sizeof (uint32_t)); /* get slen */ if (xendian) tpl_byteswap (&datapeek_ssz, sizeof (uint32_t)); if (old_string_format) datapeek_ssz++; - dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); /* adv. to str */ + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); /* adv. to str */ if (datapeek_ssz == 0) datapeek_s = NULL; else { if ((uintptr_t) dv - (uintptr_t) addr + datapeek_ssz - 1 > sz) { tpl_hook.oops ("tpl_peek: tpl has insufficient length\n"); tpl_hook.free (fmt_cpy); - fmt_cpy = NULL; /* fail */ + fmt_cpy = NULL; /* fail */ goto fail; } datapeek_s = tpl_hook.malloc (datapeek_ssz); @@ -1527,7 +1526,7 @@ tpl_peek (int mode, ...) { if ((uintptr_t) dv - (uintptr_t) addr + datapeek_csz > sz) { tpl_hook.oops ("tpl_peek: tpl has insufficient length\n"); tpl_hook.free (fmt_cpy); - fmt_cpy = NULL; /* fail */ + fmt_cpy = NULL; /* fail */ goto fail; } memcpy (datapeek_p, dv, datapeek_csz); @@ -1676,7 +1675,7 @@ tpl_load (tpl_node *r, int mode, ...) { /* this applies to TPL_MEM or TPL_FILE */ if (tpl_needs_endian_swap (((tpl_root_data *) (r->data))->mmap.text)) ((tpl_root_data *) (r->data))->flags |= TPL_XENDIAN; - tpl_unpackA0 (r); /* prepare root A nodes for use */ + tpl_unpackA0 (r); /* prepare root A nodes for use */ return 0; } @@ -1726,15 +1725,15 @@ tpl_free_atyp (tpl_node *n, tpl_atyp *atyp) { case TPL_TYPE_BIN: memcpy (&binp, dv, sizeof (tpl_bin *)); /* cp to aligned */ if (binp->addr) - tpl_hook.free (binp->addr); /* free buf */ - tpl_hook.free (binp); /* free tpl_bin */ + tpl_hook.free (binp->addr); /* free buf */ + tpl_hook.free (binp); /* free tpl_bin */ dv = (void *) ((uintptr_t) dv + sizeof (tpl_bin *)); break; case TPL_TYPE_STR: for (i = 0; i < c->num; i++) { - memcpy (&strp, dv, sizeof (char *)); /* cp to aligned */ + memcpy (&strp, dv, sizeof (char *)); /* cp to aligned */ if (strp) - tpl_hook.free (strp); /* free string */ + tpl_hook.free (strp); /* free string */ dv = (void *) ((uintptr_t) dv + sizeof (char *)); } break; @@ -1745,13 +1744,13 @@ tpl_free_atyp (tpl_node *n, tpl_atyp *atyp) { if (++(pd->iternum) < itermax) { c = pd->iter_start_node; continue; - } else { /* loop complete. */ + } else { /* loop complete. */ pd->iternum = 0; } break; case TPL_TYPE_ARY: - memcpy (&atypp, dv, sizeof (tpl_atyp *)); /* cp to aligned */ - tpl_free_atyp (c, atypp); /* free atyp */ + memcpy (&atypp, dv, sizeof (tpl_atyp *)); /* cp to aligned */ + tpl_free_atyp (c, atypp); /* free atyp */ dv = (void *) ((uintptr_t) dv + sizeof (void *)); break; default: @@ -1855,7 +1854,7 @@ tpl_serlen (tpl_node *r, tpl_node *n, void *dv, size_t *serlen) { if (++(pd->iternum) < itermax) { c = pd->iter_start_node; continue; - } else { /* loop complete. */ + } else { /* loop complete. */ pd->iternum = 0; } break; @@ -1876,7 +1875,7 @@ tpl_mmap_output_file (char *filename, size_t sz, void **text_out) { int fd, perms; #ifndef _WIN32 - perms = S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH; /* ug+w o+r */ + perms = S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH; /* ug+w o+r */ fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, perms); #else perms = _S_IWRITE; @@ -2003,8 +2002,8 @@ tpl_pack (tpl_node *r, int i) { *(tpl_bin **) (child->data) = NULL; } if (n->type == TPL_TYPE_ARY) { - n->ser_osz += sizeof (uint32_t); /* binary buf len word */ - n->ser_osz += bin->sz; /* binary buf */ + n->ser_osz += sizeof (uint32_t); /* binary buf len word */ + n->ser_osz += bin->sz; /* binary buf */ } break; case TPL_TYPE_STR: @@ -2018,7 +2017,7 @@ tpl_pack (tpl_node *r, int i) { str = tpl_hook.malloc (slen); if (!str) fatal_oom (); - memcpy (str, caddr, slen); /* include \0 */ + memcpy (str, caddr, slen); /* include \0 */ } else { str = NULL; } @@ -2032,9 +2031,9 @@ tpl_pack (tpl_node *r, int i) { *cdata = NULL; } if (n->type == TPL_TYPE_ARY) { - n->ser_osz += sizeof (uint32_t); /* string len word */ + n->ser_osz += sizeof (uint32_t); /* string len word */ if (slen > 1) - n->ser_osz += slen - 1; /* string (without nul) */ + n->ser_osz += slen - 1; /* string (without nul) */ } } break; @@ -2053,9 +2052,9 @@ tpl_pack (tpl_node *r, int i) { } /* parent is array? then bubble up child array's ser_osz */ if (n->type == TPL_TYPE_ARY) { - n->ser_osz += sizeof (uint32_t); /* array len word */ - n->ser_osz += child->ser_osz; /* child array ser_osz */ - child->ser_osz = 0; /* reset child array ser_osz */ + n->ser_osz += sizeof (uint32_t); /* array len word */ + n->ser_osz += child->ser_osz; /* child array ser_osz */ + child->ser_osz = 0; /* reset child array ser_osz */ } break; @@ -2194,7 +2193,7 @@ tpl_unpack (tpl_node *r, int i) { if (((tpl_root_data *) (r->data))->flags & TPL_OLD_STRING_FMT) slen += 1; dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); - if (slen) { /* slen includes \0 */ + if (slen) { /* slen includes \0 */ str = (char *) tpl_hook.malloc (slen); if (!str) fatal_oom (); @@ -2441,7 +2440,7 @@ tpl_gather_blocking (int fd, void **img, size_t *sz) { fatal_oom (); } - memcpy (*img, preamble, 8); /* copy preamble to output buffer */ + memcpy (*img, preamble, 8); /* copy preamble to output buffer */ i = 8; do { rc = read (fd, &((*(char **) img)[i]), tpllen - i); @@ -2478,9 +2477,9 @@ tpl_gather_nonblocking (int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data rc = read (fd, buf, TPL_GATHER_BUFLEN); if (rc == -1) { if (errno == EINTR) - continue; /* got signal during read, ignore */ + continue; /* got signal during read, ignore */ if (errno == EAGAIN) - return 1; /* nothing to read right now */ + return 1; /* nothing to read right now */ else { tpl_hook.oops ("tpl_gather failed: %s\n", strerror (errno)); if (*gs) { @@ -2488,7 +2487,7 @@ tpl_gather_nonblocking (int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data tpl_hook.free (*gs); *gs = NULL; } - return -1; /* error, caller should close fd */ + return -1; /* error, caller should close fd */ } } else if (rc == 0) { if (*gs) { @@ -2507,7 +2506,7 @@ tpl_gather_nonblocking (int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data tpl_hook.free ((*gs)); *gs = NULL; tpl_hook.oops ("tpl exceeds max length %zu\n", tpl_hook.gather_max); - return -2; /* error, caller should close fd */ + return -2; /* error, caller should close fd */ } if ((img = tpl_hook.realloc ((*gs)->img, catlen)) == NULL) { fatal_oom (); @@ -2529,14 +2528,14 @@ tpl_gather_nonblocking (int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data tpl_hook.free (img); tpl_hook.free (*gs); *gs = NULL; - return -3; /* error, caller should close fd */ + return -3; /* error, caller should close fd */ } memcpy (&tpllen, &tpl[4], 4); if (tpl_needs_endian_swap (tpl)) tpl_byteswap (&tpllen, 4); if (tpl + tpllen <= img + catlen) { - cbrc = (cb) (tpl, tpllen, data); /* invoke cb for tpl image */ - tpl += tpllen; /* point to next tpl image */ + cbrc = (cb) (tpl, tpllen, data); /* invoke cb for tpl image */ + tpl += tpllen; /* point to next tpl image */ if (cbrc < 0) keep_looping = 0; else @@ -2600,7 +2599,7 @@ tpl_gather_mem (char *buf, size_t len, tpl_gather_t **gs, tpl_gather_cb *cb, voi tpl_hook.free ((*gs)); *gs = NULL; tpl_hook.oops ("tpl exceeds max length %zu\n", tpl_hook.gather_max); - return -2; /* error, caller should stop accepting input from source */ + return -2; /* error, caller should stop accepting input from source */ } if ((img = tpl_hook.realloc ((*gs)->img, catlen)) == NULL) { fatal_oom (); @@ -2622,14 +2621,14 @@ tpl_gather_mem (char *buf, size_t len, tpl_gather_t **gs, tpl_gather_cb *cb, voi tpl_hook.free (img); tpl_hook.free (*gs); *gs = NULL; - return -3; /* error, caller should stop accepting input from source */ + return -3; /* error, caller should stop accepting input from source */ } memcpy (&tpllen, &tpl[4], 4); if (tpl_needs_endian_swap (tpl)) tpl_byteswap (&tpllen, 4); if (tpl + tpllen <= img + catlen) { - cbrc = (cb) (tpl, tpllen, data); /* invoke cb for tpl image */ - tpl += tpllen; /* point to next tpl image */ + cbrc = (cb) (tpl, tpllen, data); /* invoke cb for tpl image */ + tpl += tpllen; /* point to next tpl image */ if (cbrc < 0) keep_looping = 0; else diff --git a/src/tpl.h b/src/tpl.h index d32b0ec8ba..cdf7264dbc 100644 --- a/src/tpl.h +++ b/src/tpl.h @@ -24,9 +24,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef TPL_H #define TPL_H -#include /* size_t */ +#include /* size_t */ -#include /* va_list */ +#include /* va_list */ #ifdef __INTEL_COMPILER #include @@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef _MSC_VER typedef unsigned int uint32_t; #else -#include /* uint32_t */ +#include /* uint32_t */ #endif #if defined __cplusplus @@ -97,7 +97,7 @@ extern "C" { int num; /* length of type if it's a C array */ size_t ser_osz; /* serialization output size for subtree */ struct tpl_node *children; /* my children; linked-list */ - struct tpl_node *next, *prev; /* my siblings (next child of my parent) */ + struct tpl_node *next, *prev; /* my siblings (next child of my parent) */ struct tpl_node *parent; /* my parent */ } tpl_node; @@ -117,16 +117,16 @@ extern "C" { typedef int (tpl_gather_cb) (void *img, size_t sz, void *data); /* Prototypes */ - TPL_API tpl_node *tpl_map (char *fmt, ...); /* define tpl using format */ + TPL_API tpl_node *tpl_map (char *fmt, ...); /* define tpl using format */ TPL_API void tpl_free (tpl_node * r); /* free a tpl map */ - TPL_API int tpl_pack (tpl_node * r, int i); /* pack the n'th packable */ + TPL_API int tpl_pack (tpl_node * r, int i); /* pack the n'th packable */ TPL_API int tpl_unpack (tpl_node * r, int i); /* unpack the n'th packable */ - TPL_API int tpl_dump (tpl_node * r, int mode, ...); /* serialize to mem/file */ - TPL_API int tpl_load (tpl_node * r, int mode, ...); /* set mem/file to unpack */ - TPL_API int tpl_Alen (tpl_node * r, int i); /* array len of packable i */ - TPL_API char *tpl_peek (int mode, ...); /* sneak peek at format string */ - TPL_API int tpl_gather (int mode, ...); /* non-blocking image gather */ - TPL_API int tpl_jot (int mode, ...); /* quick write a simple tpl */ + TPL_API int tpl_dump (tpl_node * r, int mode, ...); /* serialize to mem/file */ + TPL_API int tpl_load (tpl_node * r, int mode, ...); /* set mem/file to unpack */ + TPL_API int tpl_Alen (tpl_node * r, int i); /* array len of packable i */ + TPL_API char *tpl_peek (int mode, ...); /* sneak peek at format string */ + TPL_API int tpl_gather (int mode, ...); /* non-blocking image gather */ + TPL_API int tpl_jot (int mode, ...); /* quick write a simple tpl */ TPL_API tpl_node *tpl_map_va (char *fmt, va_list ap); diff --git a/src/ui.c b/src/ui.c index c2a58c502a..279cf95f37 100644 --- a/src/ui.c +++ b/src/ui.c @@ -34,7 +34,7 @@ #define STDIN_FILENO 0 #ifndef _BSD_SOURCE -#define _BSD_SOURCE /* include stuff from 4.3 BSD */ +#define _BSD_SOURCE /* include stuff from 4.3 BSD */ #endif #ifndef _DEFAULT_SOURCE #define _DEFAULT_SOURCE @@ -935,10 +935,10 @@ load_agent_list (WINDOW *main_win, char *addr) { return; getmaxyx (stdscr, y, x); - list_h = y / 2; /* list window - height */ - list_w = x - 4; /* list window - width */ - menu_h = list_h - AGENTS_MENU_Y - 1; /* menu window - height */ - menu_w = list_w - AGENTS_MENU_X - AGENTS_MENU_X; /* menu window - width */ + list_h = y / 2; /* list window - height */ + list_w = x - 4; /* list window - width */ + menu_h = list_h - AGENTS_MENU_Y - 1; /* menu window - height */ + menu_w = list_w - AGENTS_MENU_X - AGENTS_MENU_X; /* menu window - width */ win = newwin (list_h, list_w, (y - list_h) / 2, (x - list_w) / 2); keypad (win, TRUE); diff --git a/src/ui.h b/src/ui.h index faaf077f30..dbfb617884 100644 --- a/src/ui.h +++ b/src/ui.h @@ -49,18 +49,18 @@ #include "commons.h" /* Global UI defaults */ -#define MIN_HEIGHT 8 /* minimum window height */ -#define MIN_WIDTH 0 /* minimum window width */ -#define MAX_HEIGHT_FOOTER 1 /* height of the footer window */ -#define MAX_HEIGHT_HEADER 7 /* height of the header window */ -#define OVERALL_NUM_COLS 4 /* number of columns on the overall stats win */ +#define MIN_HEIGHT 8 /* minimum window height */ +#define MIN_WIDTH 0 /* minimum window width */ +#define MAX_HEIGHT_FOOTER 1 /* height of the footer window */ +#define MAX_HEIGHT_HEADER 7 /* height of the header window */ +#define OVERALL_NUM_COLS 4 /* number of columns on the overall stats win */ /* Spinner Label Format */ #define SPIN_FMT "%s" #define SPIN_FMTM "[%s %s] {%'"PRIu64"} @ {%'lld/s}" -#define SPIN_LBL 256 /* max length of the progress spinner */ +#define SPIN_LBL 256 /* max length of the progress spinner */ -#define SPIN_UPDATE_INTERVAL 100000000 /* in nanoseconds */ +#define SPIN_UPDATE_INTERVAL 100000000 /* in nanoseconds */ /* Module JSON keys */ #define VISITORS_ID "visitors" diff --git a/src/util.c b/src/util.c index d96dc4c33b..8fd9833b95 100644 --- a/src/util.c +++ b/src/util.c @@ -192,7 +192,7 @@ djb2 (const unsigned char *str) { int c; while ((c = *str++)) - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ return hash; } @@ -582,8 +582,7 @@ set_tz (void) { snprintf (tz, TZ_NAME_LEN, "TZ=%s", conf.tz_name); if ((putenv (tz)) != 0) { int old_errno = errno; - LOG_DEBUG (("Can't set TZ env variable %s: %s: %d\n", tz, strerror (old_errno), - old_errno)); + LOG_DEBUG (("Can't set TZ env variable %s: %s: %d\n", tz, strerror (old_errno), old_errno)); goto release; } diff --git a/src/websocket.c b/src/websocket.c index 4665e6800d..5411520d82 100644 --- a/src/websocket.c +++ b/src/websocket.c @@ -1608,7 +1608,7 @@ ws_get_handshake (WSClient *client, WSServer *server) { } client->headers->buflen += bytes; - buf[client->headers->buflen] = '\0'; /* null-terminate */ + buf[client->headers->buflen] = '\0'; /* null-terminate */ /* Must have a \r\n\r\n */ if (strstr (buf, "\r\n\r\n") == NULL) { @@ -1822,7 +1822,7 @@ ws_handle_ping (WSClient *client) { ws_send_frame (client, WS_OPCODE_PONG, buf, len); - (*msg)->buflen = 0; /* done with the current frame's payload */ + (*msg)->buflen = 0; /* done with the current frame's payload */ /* Control frame injected in the middle of a fragmented message. */ if (!(*msg)->fragmented) { ws_free_message (client); @@ -2005,8 +2005,8 @@ ws_get_frm_header (WSClient *client) { frm = &client->frame; /* Read the first 2 bytes for basic frame info */ - readh = (*frm)->buflen; /* read from header so far */ - need = 2 - readh; /* need to read */ + readh = (*frm)->buflen; /* read from header so far */ + need = 2 - readh; /* need to read */ if (need > 0) { if ((bytes = ws_read_header (client, (*frm), readh, need)) < 1) return bytes; @@ -2020,8 +2020,8 @@ ws_get_frm_header (WSClient *client) { ws_set_extended_header_size ((*frm)->buf, &extended); /* read the extended header */ - readh = (*frm)->buflen; /* read from header so far */ - need = (extended + offset) - readh; /* read from header field so far */ + readh = (*frm)->buflen; /* read from header so far */ + need = (extended + offset) - readh; /* read from header field so far */ if (need > 0) { if ((bytes = ws_read_header (client, (*frm), readh, need)) < 1) return bytes; @@ -2031,7 +2031,7 @@ ws_get_frm_header (WSClient *client) { offset += extended; /* read the masking key */ - readh = (*frm)->buflen; /* read from header so far */ + readh = (*frm)->buflen; /* read from header so far */ need = (4 + offset) - readh; if (need > 0) { if ((bytes = ws_read_header (client, (*frm), readh, need)) < 1) @@ -2104,8 +2104,8 @@ ws_get_frm_payload (WSClient *client, WSServer *server) { return ws_set_status (client, WS_ERR | WS_CLOSE, 0); } - readh = (*msg)->buflen; /* read from so far */ - need = (*frm)->payloadlen - readh; /* need to read */ + readh = (*msg)->buflen; /* read from so far */ + need = (*frm)->payloadlen - readh; /* need to read */ if (need > 0) { if ((bytes = ws_read_payload (client, (*msg), (*msg)->payloadsz, need)) < 0) return bytes; @@ -2646,8 +2646,8 @@ handle_strict_fifo (WSServer *server) { char *ptr = NULL; uint32_t listener = 0, type = 0, size = 0; - readh = pi->hlen; /* read from header so far */ - need = HDR_SIZE - readh; /* need to read */ + readh = pi->hlen; /* read from header so far */ + need = HDR_SIZE - readh; /* need to read */ if (need > 0) { if ((bytes = ws_read_fifo (pi->fd, pi->hdr, &pi->hlen, readh, need)) < 0) return; @@ -2675,8 +2675,8 @@ handle_strict_fifo (WSServer *server) { (*pa)->data = xcalloc (size, sizeof (char)); } - readh = (*pa)->len; /* read from payload so far */ - need = (*pa)->size - readh; /* need to read */ + readh = (*pa)->len; /* read from payload so far */ + need = (*pa)->size - readh; /* need to read */ if (need > 0) { if ((bytes = ws_read_fifo (pi->fd, (*pa)->data, &(*pa)->len, readh, need)) < 0) return; @@ -2712,7 +2712,7 @@ handle_fixed_fifo (WSServer *server) { if ((bytes = read (pi->fd, buf, PIPE_BUF - 1)) < 0) return; - buf[bytes] = '\0'; /* null-terminate */ + buf[bytes] = '\0'; /* null-terminate */ if (ws_validate_string (buf, bytes) != 0) return; diff --git a/src/websocket.h b/src/websocket.h index f386d3b006..2846d6b527 100644 --- a/src/websocket.h +++ b/src/websocket.h @@ -104,15 +104,15 @@ /* packet header is 3 unit32_t : type, size, listener */ #define HDR_SIZE 3 * 4 -#define WS_MAX_FRM_SZ 1048576 /* 1 MiB max frame size */ -#define WS_THROTTLE_THLD 2097152 /* 2 MiB throttle threshold */ -#define WS_MAX_HEAD_SZ 8192 /* a reasonable size for request headers */ +#define WS_MAX_FRM_SZ 1048576 /* 1 MiB max frame size */ +#define WS_THROTTLE_THLD 2097152 /* 2 MiB throttle threshold */ +#define WS_MAX_HEAD_SZ 8192 /* a reasonable size for request headers */ #define WS_MAGIC_STR "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" #define WS_PAYLOAD_EXT16 126 #define WS_PAYLOAD_EXT64 127 #define WS_PAYLOAD_FULL 125 -#define WS_FRM_HEAD_SZ 16 /* frame header size */ +#define WS_FRM_HEAD_SZ 16 /* frame header size */ #define WS_FRM_FIN(x) (((x) >> 7) & 0x01) #define WS_FRM_MASK(x) (((x) >> 7) & 0x01) @@ -220,7 +220,7 @@ typedef struct WSMessage_ { typedef struct WSClient_ { /* socket data */ int listener; /* socket */ - char remote_ip[INET6_ADDRSTRLEN]; /* client IP */ + char remote_ip[INET6_ADDRSTRLEN]; /* client IP */ WSQueue *sockqueue; /* sending buffer */ WSHeaders *headers; /* HTTP headers */