Skip to content

Commit

Permalink
cppcheck const fixes (arkime#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
awick authored Feb 7, 2024
1 parent 4c47f55 commit e1ccc2c
Show file tree
Hide file tree
Showing 37 changed files with 197 additions and 196 deletions.
8 changes: 4 additions & 4 deletions capture/arkime.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ typedef int (* ArkimeCanQuitFunc) ();
#define ARKIME_GIO_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)

gint arkime_watch_fd(gint fd, GIOCondition cond, ArkimeWatchFd_func func, gpointer data);
uint8_t *arkime_js0n_get(uint8_t *data, uint32_t len, const char *key, uint32_t *olen);
char *arkime_js0n_get_str(uint8_t *data, uint32_t len, const char *key);
const uint8_t *arkime_js0n_get(const uint8_t *data, uint32_t len, const char *key, uint32_t *olen);
char *arkime_js0n_get_str(const uint8_t *data, uint32_t len, const char *key);

gboolean arkime_string_add(void *hashv, char *string, gpointer uw, gboolean copy);

Expand Down Expand Up @@ -1053,7 +1053,7 @@ gboolean arkime_http_is_arkime(uint32_t hash, uint8_t *sessionId);


void arkime_session_id (uint8_t *sessionId, uint32_t addr1, uint16_t port1, uint32_t addr2, uint16_t port2);
void arkime_session_id6 (uint8_t *sessionId, uint8_t *addr1, uint16_t port1, uint8_t *addr2, uint16_t port2);
void arkime_session_id6 (uint8_t *sessionId, const uint8_t *addr1, uint16_t port1, const uint8_t *addr2, uint16_t port2);
char *arkime_session_id_string (uint8_t *sessionId, char *buf);
char *arkime_session_pretty_string (ArkimeSession_t *session, char *buf, int len);

Expand Down Expand Up @@ -1305,7 +1305,7 @@ char *arkime_yara_version();
*/

void arkime_field_init();
void arkime_field_define_json(uint8_t *expression, int expression_len, uint8_t *data, int data_len);
void arkime_field_define_json(const uint8_t *expression, int expression_len, const uint8_t *data, int data_len);
int arkime_field_define_text(char *text, int *shortcut);
int arkime_field_define_text_full(char *field, char *text, int *shortcut);
int arkime_field_define(char *group, char *kind, char *expression, char *friendlyName, char *dbField, char *help, ArkimeFieldType type, int flags, ...);
Expand Down
49 changes: 25 additions & 24 deletions capture/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ LOCAL void arkime_db_load_stats()
size_t data_len;
uint32_t len;
uint32_t source_len;
uint8_t *source = 0;
const uint8_t *source = 0;

char stats_key[200];
int stats_key_len = 0;
Expand Down Expand Up @@ -1866,7 +1866,7 @@ uint32_t arkime_db_get_sequence_number_sync(char *name)
uint8_t *data = arkime_http_send_sync(esServer, "POST", key, key_len, "{}", 2, NULL, &data_len, NULL);

uint32_t version_len;
uint8_t *version = arkime_js0n_get(data, data_len, "_version", &version_len);
const uint8_t *version = arkime_js0n_get(data, data_len, "_version", &version_len);

if (!version_len || !version) {
LOG("ERROR - Couldn't fetch sequence: %d %.*s", (int)data_len, (int)data_len, data);
Expand Down Expand Up @@ -1900,7 +1900,7 @@ LOCAL void arkime_db_load_file_num()
size_t data_len;
uint8_t *data;
uint32_t found_len;
uint8_t *found = 0;
const uint8_t *found = 0;

/* First see if we have the new style number or not */
key_len = snprintf(key, sizeof(key), "/%ssequence/_doc/fn-%s", config.prefix, config.nodeName);
Expand Down Expand Up @@ -2094,11 +2094,11 @@ char *arkime_db_create_file_full(time_t firstPacket, const char *name, uint64_t
va_list args;
va_start(args, id);
while (1) {
char *field = va_arg(args, char *);
const char *field = va_arg(args, char *);
if (!field)
break;

char *value = va_arg(args, char *);
const char *value = va_arg(args, char *);
if (!value)
break;

Expand Down Expand Up @@ -2168,31 +2168,31 @@ LOCAL void arkime_db_check()
}

uint32_t template_len;
uint8_t *template = 0;
const uint8_t *template = 0;

template = arkime_js0n_get(data, data_len, tname, &template_len);
if(!template || template_len == 0) {
LOGEXIT("ERROR - Couldn't load version information, database might be down or out of date. Run \"db/db.pl host:port upgrade\"");
}

uint32_t mappings_len;
uint8_t *mappings = 0;
const uint8_t *mappings = 0;

mappings = arkime_js0n_get(template, template_len, "mappings", &mappings_len);
if(!mappings || mappings_len == 0) {
LOGEXIT("ERROR - Couldn't load version information, database might be down or out of date. Run \"db/db.pl host:port upgrade\"");
}

uint32_t meta_len;
uint8_t *meta = 0;
const uint8_t *meta = 0;

meta = arkime_js0n_get(mappings, mappings_len, "_meta", &meta_len);
if(!meta || meta_len == 0) {
LOGEXIT("ERROR - Couldn't load version information, database might be down or out of date. Run \"db/db.pl host:port upgrade\"");
}

uint32_t version_len = 0;
uint8_t *version = 0;
const uint8_t *version = 0;

version = arkime_js0n_get(meta, meta_len, "molochDbVersion", &version_len);

Expand Down Expand Up @@ -2249,8 +2249,9 @@ LOCAL void arkime_db_load_rir(const char *name)
}

while(fgets(line, sizeof(line), fp)) {
int cnt = 0, quote = 0, num = 0;
char *ptr, *start;
int cnt = 0, quote = 0, num = 0;
const char *start;
char *ptr;

for (start = ptr = line; *ptr != 0; ptr++) {
if (*ptr == '"') {
Expand Down Expand Up @@ -2323,7 +2324,7 @@ LOCAL void arkime_db_load_oui(const char *name)
CONFIGEXIT("OUI file %s bad line '%s'", name, line);
}

char *str = NULL;
const char *str = NULL;
if (parts[2]) {
if (parts[2][0])
str = parts[2];
Expand Down Expand Up @@ -2376,7 +2377,7 @@ LOCAL void arkime_db_load_oui(const char *name)
/******************************************************************************/
void arkime_db_oui_lookup(int field, ArkimeSession_t *session, const uint8_t *mac)
{
patricia_node_t *node;
const patricia_node_t *node;

if (!ouiTree)
return;
Expand All @@ -2402,7 +2403,7 @@ LOCAL void arkime_db_load_fields()
}

uint32_t hits_len;
uint8_t *hits = 0;
const uint8_t *hits = 0;
hits = arkime_js0n_get(data, data_len, "hits", &hits_len);
if (!hits) {
LOGEXIT("ERROR - Couldn't download %sfields, database (%s) might be down or not initialized.", config.prefix, config.elasticsearch);
Expand All @@ -2411,7 +2412,7 @@ LOCAL void arkime_db_load_fields()
}

uint32_t ahits_len;
uint8_t *ahits = 0;
const uint8_t *ahits = 0;
ahits = arkime_js0n_get(hits, hits_len, "hits", &ahits_len);

if (!ahits) {
Expand All @@ -2426,11 +2427,11 @@ LOCAL void arkime_db_load_fields()
int i;
for (i = 0; out[i]; i += 2) {
uint32_t id_len;
uint8_t *id = 0;
const uint8_t *id = 0;
id = arkime_js0n_get(ahits + out[i], out[i + 1], "_id", &id_len);

uint32_t source_len;
uint8_t *source = 0;
const uint8_t *source = 0;
source = arkime_js0n_get(ahits + out[i], out[i + 1], "_source", &source_len);
if (!source) {
continue;
Expand Down Expand Up @@ -2567,15 +2568,15 @@ gboolean arkime_db_file_exists(const char *filename, uint32_t *outputId)
uint8_t *data = arkime_http_get(esServer, key, key_len, &data_len);

uint32_t hits_len;
uint8_t *hits = arkime_js0n_get(data, data_len, "hits", &hits_len);
const uint8_t *hits = arkime_js0n_get(data, data_len, "hits", &hits_len);

if (!hits_len || !hits) {
free(data);
return FALSE;
}

uint32_t total_len;
uint8_t *total = arkime_js0n_get(hits, hits_len, "total", &total_len);
const uint8_t *total = arkime_js0n_get(hits, hits_len, "total", &total_len);

if (!total_len || !total) {
free(data);
Expand All @@ -2591,16 +2592,16 @@ gboolean arkime_db_file_exists(const char *filename, uint32_t *outputId)
hits = arkime_js0n_get(data, data_len, "hits", &hits_len);

uint32_t hit_len;
uint8_t *hit = arkime_js0n_get(hits, hits_len, "hits", &hit_len);
const uint8_t *hit = arkime_js0n_get(hits, hits_len, "hits", &hit_len);

uint32_t source_len;
uint8_t *source = 0;
const uint8_t *source = 0;

/* Remove array wrapper */
source = arkime_js0n_get(hit + 1, hit_len - 2, "_source", &source_len);

uint32_t len;
uint8_t *value;
const uint8_t *value;

if ((value = arkime_js0n_get(source, source_len, "num", &len))) {
*outputId = atoi((char *)value);
Expand Down Expand Up @@ -2679,8 +2680,8 @@ void arkime_db_init()

static char *headers[4] = {"Content-Type: application/json", "Expect:", NULL, NULL};

char *elasticsearchAPIKey = arkime_config_str(NULL, "elasticsearchAPIKey", NULL);
char *elasticsearchBasicAuth = arkime_config_str(NULL, "elasticsearchBasicAuth", NULL);
const char *elasticsearchAPIKey = arkime_config_str(NULL, "elasticsearchAPIKey", NULL);
const char *elasticsearchBasicAuth = arkime_config_str(NULL, "elasticsearchBasicAuth", NULL);
if (elasticsearchAPIKey) {
static char auth[1024];
snprintf(auth, sizeof(auth), "Authorization: ApiKey %s", elasticsearchAPIKey);
Expand Down
16 changes: 8 additions & 8 deletions capture/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ LOCAL void arkime_field_free_info(ArkimeFieldInfo_t *info)
ARKIME_TYPE_FREE(ArkimeFieldInfo_t, info);
}
/******************************************************************************/
void arkime_field_define_json(uint8_t *expression, int expression_len, uint8_t *data, int data_len)
void arkime_field_define_json(const uint8_t *expression, int expression_len, const uint8_t *data, int data_len)
{
ArkimeFieldInfo_t *info = ARKIME_TYPE_ALLOC0(ArkimeFieldInfo_t);
int i;
Expand Down Expand Up @@ -225,7 +225,7 @@ int arkime_field_define_text_full(char *field, char *text, int *shortcut)

char groupbuf[100];
if (!group) {
char *dot = strchr(field, '.');
const char *dot = strchr(field, '.');
if (dot) {
if (dot - field >= (int)sizeof(groupbuf) - 1)
LOGEXIT("ERROR - field '%s' too long", field);
Expand Down Expand Up @@ -321,15 +321,15 @@ int arkime_field_define(char *group, char *kind, char *expression, char *friendl
ArkimeFieldInfo_t *minfo = 0;
HASH_FIND(d_, fieldsByDb, dbField, minfo);

char *category = NULL;
char *transform = NULL;
char *aliases = NULL;
const char *category = NULL;
const char *transform = NULL;
const char *aliases = NULL;
va_list args;
va_start(args, flags);
while(1) {
char *field = va_arg(args, char *);
const char *field = va_arg(args, char *);
if (!field) break;
char *value = va_arg(args, char *);
const char *value = va_arg(args, char *);
if (strcmp(field, "category") == 0 && value) {
category = value;
} else if (strcmp(field, "transform") == 0 && value) {
Expand Down Expand Up @@ -404,7 +404,7 @@ int arkime_field_define(char *group, char *kind, char *expression, char *friendl
config.fields[minfo->pos] = minfo;

// Change leading part to dbGroup
char *firstdot = strchr(minfo->dbField, '.');
const char *firstdot = strchr(minfo->dbField, '.');
if (firstdot) {
minfo->dbGroupNum = arkime_field_group_num(minfo->dbField, (firstdot - minfo->dbField) + 1);
minfo->dbGroup = minfo->dbField;
Expand Down
2 changes: 1 addition & 1 deletion capture/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ LOCAL void arkime_http_add_request(ArkimeHttpServer_t *server, ArkimeHttpRequest
request->snamePos = server->snamesPos;
server->snamesPos = (server->snamesPos + 1) % server->snamesCnt;

char *host = server->snames[request->snamePos].name;
const char *host = server->snames[request->snamePos].name;
snprintf(request->url, sizeof(request->url), "%s%s", host, request->key);

curl_easy_setopt(request->easy, CURLOPT_URL, request->url);
Expand Down
36 changes: 18 additions & 18 deletions capture/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ gboolean arkime_debug_flag()
/******************************************************************************/
gboolean arkime_cmdline_option(const gchar *option_name, const gchar *input, gpointer UNUSED(data), GError **UNUSED(error))
{
char *equal = strchr(input, '=');
const char *equal = strchr(input, '=');
if (!equal)
CONFIGEXIT("The option %s requires a '=' in value '%s'", option_name, input);

Expand Down Expand Up @@ -184,7 +184,7 @@ void parse_args(int argc, char **argv)
unsigned zver = ZSTD_versionNumber();
printf("zstd: %u.%u.%u\n", zver / (100 * 100), (zver / 100) % 100, zver % 100);
#endif
nghttp2_info *ngver = nghttp2_version(0);
const nghttp2_info *ngver = nghttp2_version(0);
printf("nghttp2: %s\n", ngver->version_str);

exit(0);
Expand All @@ -203,7 +203,7 @@ void parse_args(int argc, char **argv)
if (!config.hostName) {
config.hostName = malloc(256);
gethostname(config.hostName, 256);
char *dot = strchr(config.hostName, '.');
const char *dot = strchr(config.hostName, '.');
if (!dot) {
char domainname[256];
if (getdomainname(domainname, 255) == 0 && strlen(domainname) > 0 && strcmp(domainname, "(none)") != 0) {
Expand Down Expand Up @@ -346,13 +346,13 @@ void reload(int UNUSED(sig))
/******************************************************************************/
void arkime_check_file_permissions(char *filename)
{
char path[PATH_MAX];
struct stat stats;
char *token;
char *save_ptr;
char tmpFilename[PATH_MAX];
struct group *gr;
struct passwd *pw;
char path[PATH_MAX];
struct stat stats;
const char *token;
char *save_ptr;
char tmpFilename[PATH_MAX];
const struct group *gr;
const struct passwd *pw;

if (strlen (filename) >= PATH_MAX) {
// filename bigger than path buffer, skip check
Expand Down Expand Up @@ -425,7 +425,7 @@ uint32_t arkime_get_next_powerof2(uint32_t v)
return v;
}
/******************************************************************************/
uint8_t *arkime_js0n_get(uint8_t *data, uint32_t len, const char *key, uint32_t *olen)
const uint8_t *arkime_js0n_get(const uint8_t *data, uint32_t len, const char *key, uint32_t *olen)
{
uint32_t key_len = strlen(key);
int i;
Expand All @@ -448,10 +448,10 @@ uint8_t *arkime_js0n_get(uint8_t *data, uint32_t len, const char *key, uint32_t
return 0;
}
/******************************************************************************/
char *arkime_js0n_get_str(uint8_t *data, uint32_t len, const char *key)
char *arkime_js0n_get_str(const uint8_t *data, uint32_t len, const char *key)
{
uint32_t value_len;
uint8_t *value = 0;
const uint8_t *value = 0;

value = arkime_js0n_get(data, len, key, &value_len);
if (!value)
Expand Down Expand Up @@ -548,16 +548,16 @@ uint32_t arkime_string_hash_len(const void *key, int len)
/******************************************************************************/
int arkime_string_cmp(const void *keyv, const void *elementv)
{
char *key = (char *)keyv;
ArkimeString_t *element = (ArkimeString_t *)elementv;
const char *key = (char *)keyv;
const ArkimeString_t *element = (ArkimeString_t *)elementv;

return strcmp(key, element->str) == 0;
}
/******************************************************************************/
int arkime_string_ncmp(const void *keyv, const void *elementv)
{
char *key = (char *)keyv;
ArkimeString_t *element = (ArkimeString_t *)elementv;
const char *key = (char *)keyv;
const ArkimeString_t *element = (ArkimeString_t *)elementv;

return strncmp(key, element->str, element->len) == 0;
}
Expand All @@ -571,7 +571,7 @@ uint32_t arkime_int_hash(const void *key)
int arkime_int_cmp(const void *keyv, const void *elementv)
{
uint32_t key = (uint32_t)((long)keyv);
ArkimeInt_t *element = (ArkimeInt_t *)elementv;
const ArkimeInt_t *element = (ArkimeInt_t *)elementv;

return key == element->i_hash;
}
Expand Down
Loading

0 comments on commit e1ccc2c

Please sign in to comment.