From 5d2d7237ac0d64689b3ff4d6be256ff4bd74cef7 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Fri, 15 Jan 2016 02:48:11 +0200 Subject: [PATCH 1/2] modules/statsd: use C99 boolean --- modules/statsd/lib_statsd.c | 38 ++++++++++++++++++------------------- modules/statsd/lib_statsd.h | 20 +++++++++---------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/modules/statsd/lib_statsd.c b/modules/statsd/lib_statsd.c index 52820e51b76..6492ef219b9 100644 --- a/modules/statsd/lib_statsd.c +++ b/modules/statsd/lib_statsd.c @@ -24,13 +24,13 @@ static StatsConnection statsd_connection = { "8125" }; -int statsd_connect(void){ +bool statsd_connect(void){ struct addrinfo *serverAddr; int rc, error; if (statsd_socket.sock > 0){ - return True; + return true; } error = getaddrinfo( @@ -41,62 +41,62 @@ int statsd_connect(void){ LM_ERR( "Statsd: could not initiate server information (%s)\n", gai_strerror(error)); - return False; + return false; } statsd_socket.sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (statsd_socket.sock == 0 ){ LM_ERR("Statsd: could not initiate a connect to statsd\n"); - return False; + return false; } rc = connect( statsd_socket.sock, serverAddr->ai_addr, serverAddr->ai_addrlen); if (rc < 0){ LM_ERR("Statsd: could not initiate a connect to statsd\n"); - return False; + return false; } - return True; + return true; } -int send_command(char *command){ +bool send_command(char *command){ int send_result; if (!statsd_connect()){ - return False; + return false; } send_result = send(statsd_socket.sock, command, strlen(command), 0); if ( send_result < 0){ LM_ERR("could not send the correct info to statsd (%i| %s)\n", send_result, strerror(errno)); - return True; + return true; } LM_DBG("Sent to statsd (%s)", command); - return True; + return true; } -int statsd_set(char *key, char *value){ +bool statsd_set(char *key, char *value){ char* end = 0; char command[254]; int val; val = strtol(value, &end, 0); if (*end){ LM_ERR("statsd_count could not use the provide value(%s)\n", value); - return False; + return false; } snprintf(command, sizeof command, "%s:%i|s\n", key, val); return send_command(command); } -int statsd_gauge(char *key, char *value){ +bool statsd_gauge(char *key, char *value){ char command[254]; snprintf(command, sizeof command, "%s:%s|g\n", key, value); return send_command(command); } -int statsd_count(char *key, char *value){ +bool statsd_count(char *key, char *value){ char* end = 0; char command[254]; int val; @@ -104,19 +104,19 @@ int statsd_count(char *key, char *value){ val = strtol(value, &end, 0); if (*end){ LM_ERR("statsd_count could not use the provide value(%s)\n", value); - return False; + return false; } snprintf(command, sizeof command, "%s:%i|c\n", key, val); return send_command(command); } -int statsd_timing(char *key, int value){ +bool statsd_timing(char *key, int value){ char command[254]; snprintf(command, sizeof command, "%s:%i|ms\n", key, value); return send_command(command); } -int statsd_init(char *ip, char *port){ +bool statsd_init(char *ip, char *port){ if (ip != NULL){ statsd_connection.ip = ip; @@ -127,7 +127,7 @@ int statsd_init(char *ip, char *port){ return statsd_connect(); } -int statsd_destroy(void){ +bool statsd_destroy(void){ statsd_socket.sock = 0; - return True; + return true; } diff --git a/modules/statsd/lib_statsd.h b/modules/statsd/lib_statsd.h index b7d178e9c25..d3064c21ea2 100644 --- a/modules/statsd/lib_statsd.h +++ b/modules/statsd/lib_statsd.h @@ -1,8 +1,6 @@ +#include #define BUFFER_SIZE 8192 -typedef int Bool; -#define True 1 -#define False 0 typedef struct StatsConnection{ char *ip; @@ -17,11 +15,11 @@ typedef struct StatsdSocket { char data[BUFFER_SIZE]; // buffer for the answer data } StatsdSocket; -int statsd_connect(void); -int send_command(char *command); -int statsd_set(char *key, char *value); -int statsd_gauge(char *key, char *value); -int statsd_count(char *key, char *value); -int statsd_timing(char *key, int value); -int statsd_init(char *ip, char *port); -int statsd_destroy(void); +bool statsd_connect(void); +bool send_command(char *command); +bool statsd_set(char *key, char *value); +bool statsd_gauge(char *key, char *value); +bool statsd_count(char *key, char *value); +bool statsd_timing(char *key, int value); +bool statsd_init(char *ip, char *port); +bool statsd_destroy(void); From 648d95e126a13986684db94136dc47d69a7cc27c Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Fri, 15 Jan 2016 02:48:39 +0200 Subject: [PATCH 2/2] modules/nat_traversal: use C99 boolean --- modules/nat_traversal/nat_traversal.c | 72 +++++++++++++-------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/modules/nat_traversal/nat_traversal.c b/modules/nat_traversal/nat_traversal.c index 67b65fad04c..0acdd1725d1 100644 --- a/modules/nat_traversal/nat_traversal.c +++ b/modules/nat_traversal/nat_traversal.c @@ -34,6 +34,7 @@ traversal for SIP signaling. */ +#include #include #include #include @@ -98,12 +99,7 @@ MODULE_VERSION #define STR_HAS_IPREFIX(str, prefix) ((str).len>(prefix).len && strncasecmp((prefix).s, (str).s, (prefix).len)==0) -typedef int Bool; -#define True 1 -#define False 0 - - -typedef Bool (*NatTestFunction)(struct sip_msg *msg); +typedef bool (*NatTestFunction)(struct sip_msg *msg); typedef enum { NTNone=0, @@ -162,7 +158,7 @@ typedef struct Dialog_Param { char *caller_uri; char *callee_uri; time_t expire; - Bool confirmed; + bool confirmed; gen_lock_t lock; struct { char **uri; @@ -194,9 +190,9 @@ static int NAT_Keepalive(struct sip_msg *msg); static int FixContact(struct sip_msg *msg); static int ClientNatTest(struct sip_msg *msg, unsigned int tests); -static Bool test_private_contact(struct sip_msg *msg); -static Bool test_source_address(struct sip_msg *msg); -static Bool test_private_via(struct sip_msg *msg); +static bool test_private_contact(struct sip_msg *msg); +static bool test_source_address(struct sip_msg *msg); +static bool test_private_via(struct sip_msg *msg); static INLINE char* shm_strdup(char *source); @@ -215,7 +211,7 @@ static int pv_get_source_uri(struct sip_msg *msg, pv_param_t *param, pv_value_t // static HashTable *nat_table = NULL; -static Bool keepalive_disabled = False; +static bool keepalive_disabled = false; static unsigned int keepalive_interval = 60; @@ -225,7 +221,7 @@ static Keepalive_Params keepalive_params = {"NOTIFY", NULL, "", "", 0, 0, ""}; struct tm_binds tm_api; struct dlg_binds dlg_api; -Bool have_dlg_api = False; +bool have_dlg_api = false; static int dialog_flag = -1; static unsigned dialog_default_timeout = 12*3600; // 12 hours @@ -466,7 +462,7 @@ NAT_Contact_del(NAT_Contact *contact) } -static Bool +static bool NAT_Contact_match(NAT_Contact *contact, const char *uri) { return strcmp(contact->uri, uri)==0; @@ -674,24 +670,24 @@ Dialog_Param_del(Dialog_Param *param) // This function assumes the caller has locked the Dialog_Param while operating on it // -static Bool +static bool Dialog_Param_has_candidate(Dialog_Param *param, char *candidate) { int i; for (i=0; icallee_candidates.count; i++) { if (strcmp(candidate, param->callee_candidates.uri[i])==0) { - return True; + return true; } } - return False; + return false; } // This function assumes the caller has locked the Dialog_Param while operating on it // -static Bool +static bool Dialog_Param_add_candidate(Dialog_Param *param, char *candidate) { char **new_uri, *new_candidate; @@ -703,7 +699,7 @@ Dialog_Param_add_candidate(Dialog_Param *param, char *candidate) new_uri = shm_realloc(param->callee_candidates.uri, new_size * sizeof(char*)); if (!new_uri) { LM_ERR("failed to grow callee_candidates uri list\n"); - return False; + return false; } param->callee_candidates.uri = new_uri; param->callee_candidates.size = new_size; @@ -712,13 +708,13 @@ Dialog_Param_add_candidate(Dialog_Param *param, char *candidate) new_candidate = shm_strdup(candidate); if (!new_candidate) { LM_ERR("cannot allocate shared memory for new candidate uri\n"); - return False; + return false; } param->callee_candidates.uri[param->callee_candidates.count] = new_candidate; param->callee_candidates.count++; - return True; + return true; } @@ -774,30 +770,30 @@ shm_strdup(char *source) } -static Bool +static bool get_contact_uri(struct sip_msg* msg, struct sip_uri *uri, contact_t **_c) { if ((parse_headers(msg, HDR_CONTACT_F, 0) == -1) || !msg->contact) - return False; + return false; if (!msg->contact->parsed && parse_contact(msg->contact) < 0) { LM_ERR("cannot parse the Contact header\n"); - return False; + return false; } *_c = ((contact_body_t*)msg->contact->parsed)->contacts; if (*_c == NULL) { - return False; + return false; } if (parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) { LM_ERR("cannot parse the Contact URI\n"); - return False; + return false; } - return True; + return true; } @@ -828,10 +824,10 @@ rfc1918address(str *address) // Test if address of signaling is different from address in 1st Via field -static Bool +static bool test_source_address(struct sip_msg *msg) { - Bool different_ip, different_port; + bool different_ip, different_port; int via1_port; different_ip = received_via_test(msg); @@ -843,21 +839,21 @@ test_source_address(struct sip_msg *msg) // Test if Contact field contains a private IP address as defined in RFC1918 -static Bool +static bool test_private_contact(struct sip_msg *msg) { struct sip_uri uri; contact_t* contact; if (!get_contact_uri(msg, &uri, &contact)) - return False; + return false; return is_private_address(&(uri.host)); } // Test if top Via field contains a private IP address as defined in RFC1918 -static Bool +static bool test_private_via(struct sip_msg *msg) { return is_private_address(&(msg->via1->host)); @@ -898,7 +894,7 @@ get_register_expire(struct sip_msg *request, struct sip_msg *reply) param_t *expires_param; time_t now, expire=0; unsigned exp; - Bool matched; + bool matched; if (!request->contact) return 0; @@ -935,7 +931,7 @@ get_register_expire(struct sip_msg *request, struct sip_msg *reply) } for (contact=contact_body->contacts; contact; contact=contact->next) { - for (r_hdr=reply->contact, matched=False; r_hdr && !matched; r_hdr=next_sibling_hdr(r_hdr)) { + for (r_hdr=reply->contact, matched=false; r_hdr && !matched; r_hdr=next_sibling_hdr(r_hdr)) { if (!r_hdr->parsed && parse_contact(r_hdr) < 0) { LM_ERR("failed to parse the Contact header body in reply\n"); continue; @@ -946,7 +942,7 @@ get_register_expire(struct sip_msg *request, struct sip_msg *reply) expires_param = r_contact->expires; if (expires_param && expires_param->body.len && str2int(&expires_param->body, &exp) == 0) expire = max(expire, exp); - matched = True; + matched = true; break; } } @@ -1092,7 +1088,7 @@ __dialog_confirmed(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params lock_get(¶m->lock); - param->confirmed = True; + param->confirmed = true; callee_uri = get_source_uri(_params->rpl); @@ -1684,7 +1680,7 @@ restore_keepalive_state(void) res = fscanf(f, STATE_FILE_HEADER); // skip header - while (True) { + while (true) { res = fscanf(f, "%63s %63s %ld %ld", uri, socket, &rtime, &stime); if (res == EOF) { if (ferror(f)) @@ -1734,7 +1730,7 @@ mod_init(void) if (keepalive_interval <= 0) { LM_NOTICE("keepalive functionality is disabled from the configuration\n"); - keepalive_disabled = True; + keepalive_disabled = true; return 0; } @@ -1764,7 +1760,7 @@ mod_init(void) param = find_param_export(find_module_by_name("dialog"), "dlg_flag", INT_PARAM, &type); if (param) { - have_dlg_api = True; + have_dlg_api = true; dialog_flag = *param;