Sfoglia il codice sorgente

Merge pull request #477 from mslehto/stdbool

Use C99 boolean
Daniel-Constantin Mierla 9 anni fa
parent
commit
8d2a7a9d9c

+ 34 - 38
modules/nat_traversal/nat_traversal.c

@@ -34,6 +34,7 @@
    traversal for SIP signaling. 
    traversal for SIP signaling. 
  */
  */
 
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
@@ -98,12 +99,7 @@ MODULE_VERSION
 #define STR_HAS_IPREFIX(str, prefix) ((str).len>(prefix).len && strncasecmp((prefix).s, (str).s, (prefix).len)==0)
 #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 {
 typedef enum {
     NTNone=0,
     NTNone=0,
@@ -162,7 +158,7 @@ typedef struct Dialog_Param {
     char *caller_uri;
     char *caller_uri;
     char *callee_uri;
     char *callee_uri;
     time_t expire;
     time_t expire;
-    Bool confirmed;
+    bool confirmed;
     gen_lock_t lock;
     gen_lock_t lock;
     struct {
     struct {
         char **uri;
         char **uri;
@@ -194,9 +190,9 @@ static int NAT_Keepalive(struct sip_msg *msg);
 static int FixContact(struct sip_msg *msg);
 static int FixContact(struct sip_msg *msg);
 static int ClientNatTest(struct sip_msg *msg, unsigned int tests);
 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);
 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 HashTable *nat_table = NULL;
 
 
-static Bool keepalive_disabled = False;
+static bool keepalive_disabled = false;
 
 
 static unsigned int keepalive_interval = 60;
 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 tm_binds  tm_api;
 struct dlg_binds dlg_api;
 struct dlg_binds dlg_api;
-Bool have_dlg_api = False;
+bool have_dlg_api = false;
 
 
 static int dialog_flag = -1;
 static int dialog_flag = -1;
 static unsigned dialog_default_timeout = 12*3600;  // 12 hours
 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)
 NAT_Contact_match(NAT_Contact *contact, const char *uri)
 {
 {
     return strcmp(contact->uri, uri)==0;
     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
 // 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)
 Dialog_Param_has_candidate(Dialog_Param *param, char *candidate)
 {
 {
     int i;
     int i;
 
 
     for (i=0; i<param->callee_candidates.count; i++) {
     for (i=0; i<param->callee_candidates.count; i++) {
         if (strcmp(candidate, param->callee_candidates.uri[i])==0) {
         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
 // 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)
 Dialog_Param_add_candidate(Dialog_Param *param, char *candidate)
 {
 {
     char **new_uri, *new_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*));
         new_uri = shm_realloc(param->callee_candidates.uri, new_size * sizeof(char*));
         if (!new_uri) {
         if (!new_uri) {
             LM_ERR("failed to grow callee_candidates uri list\n");
             LM_ERR("failed to grow callee_candidates uri list\n");
-            return False;
+            return false;
         }
         }
         param->callee_candidates.uri = new_uri;
         param->callee_candidates.uri = new_uri;
         param->callee_candidates.size = new_size;
         param->callee_candidates.size = new_size;
@@ -712,13 +708,13 @@ Dialog_Param_add_candidate(Dialog_Param *param, char *candidate)
     new_candidate = shm_strdup(candidate);
     new_candidate = shm_strdup(candidate);
     if (!new_candidate) {
     if (!new_candidate) {
         LM_ERR("cannot allocate shared memory for new candidate uri\n");
         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.uri[param->callee_candidates.count] = new_candidate;
     param->callee_candidates.count++;
     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)
 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)
     if ((parse_headers(msg, HDR_CONTACT_F, 0) == -1) || !msg->contact)
-        return False;
+        return false;
 
 
     if (!msg->contact->parsed && parse_contact(msg->contact) < 0) {
     if (!msg->contact->parsed && parse_contact(msg->contact) < 0) {
         LM_ERR("cannot parse the Contact header\n");
         LM_ERR("cannot parse the Contact header\n");
-        return False;
+        return false;
     }
     }
 
 
     *_c = ((contact_body_t*)msg->contact->parsed)->contacts;
     *_c = ((contact_body_t*)msg->contact->parsed)->contacts;
 
 
     if (*_c == NULL) {
     if (*_c == NULL) {
-        return False;
+        return false;
     }
     }
 
 
     if (parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) {
     if (parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) {
         LM_ERR("cannot parse the Contact URI\n");
         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
 // Test if address of signaling is different from address in 1st Via field
-static Bool
+static bool
 test_source_address(struct sip_msg *msg)
 test_source_address(struct sip_msg *msg)
 {
 {
-    Bool different_ip, different_port;
+    bool different_ip, different_port;
     int via1_port;
     int via1_port;
 
 
     different_ip = received_via_test(msg);
     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
 // Test if Contact field contains a private IP address as defined in RFC1918
-static Bool
+static bool
 test_private_contact(struct sip_msg *msg)
 test_private_contact(struct sip_msg *msg)
 {
 {
     struct sip_uri uri;
     struct sip_uri uri;
     contact_t* contact;
     contact_t* contact;
 
 
     if (!get_contact_uri(msg, &uri, &contact))
     if (!get_contact_uri(msg, &uri, &contact))
-        return False;
+        return false;
 
 
     return is_private_address(&(uri.host));
     return is_private_address(&(uri.host));
 }
 }
 
 
 
 
 // Test if top Via field contains a private IP address as defined in RFC1918
 // 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)
 test_private_via(struct sip_msg *msg)
 {
 {
     return is_private_address(&(msg->via1->host));
     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;
     param_t *expires_param;
     time_t now, expire=0;
     time_t now, expire=0;
     unsigned exp;
     unsigned exp;
-    Bool matched;
+    bool matched;
 
 
     if (!request->contact)
     if (!request->contact)
         return 0;
         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 (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) {
                 if (!r_hdr->parsed && parse_contact(r_hdr) < 0) {
                     LM_ERR("failed to parse the Contact header body in reply\n");
                     LM_ERR("failed to parse the Contact header body in reply\n");
                     continue;
                     continue;
@@ -946,7 +942,7 @@ get_register_expire(struct sip_msg *request, struct sip_msg *reply)
                         expires_param = r_contact->expires;
                         expires_param = r_contact->expires;
                         if (expires_param && expires_param->body.len && str2int(&expires_param->body, &exp) == 0)
                         if (expires_param && expires_param->body.len && str2int(&expires_param->body, &exp) == 0)
                             expire = max(expire, exp);
                             expire = max(expire, exp);
-                        matched = True;
+                        matched = true;
                         break;
                         break;
                     }
                     }
                 }
                 }
@@ -1092,7 +1088,7 @@ __dialog_confirmed(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params
 
 
     lock_get(&param->lock);
     lock_get(&param->lock);
 
 
-    param->confirmed = True;
+    param->confirmed = true;
 
 
     callee_uri = get_source_uri(_params->rpl);
     callee_uri = get_source_uri(_params->rpl);
 
 
@@ -1684,7 +1680,7 @@ restore_keepalive_state(void)
 
 
     res = fscanf(f, STATE_FILE_HEADER); // skip header
     res = fscanf(f, STATE_FILE_HEADER); // skip header
 
 
-    while (True) {
+    while (true) {
         res = fscanf(f, "%63s %63s %ld %ld", uri, socket, &rtime, &stime);
         res = fscanf(f, "%63s %63s %ld %ld", uri, socket, &rtime, &stime);
         if (res == EOF) {
         if (res == EOF) {
             if (ferror(f))
             if (ferror(f))
@@ -1734,7 +1730,7 @@ mod_init(void)
 
 
     if (keepalive_interval <= 0) {
     if (keepalive_interval <= 0) {
         LM_NOTICE("keepalive functionality is disabled from the configuration\n");
         LM_NOTICE("keepalive functionality is disabled from the configuration\n");
-        keepalive_disabled = True;
+        keepalive_disabled = true;
         return 0;
         return 0;
     }
     }
 
 
@@ -1764,7 +1760,7 @@ mod_init(void)
         param = find_param_export(find_module_by_name("dialog"),
         param = find_param_export(find_module_by_name("dialog"),
 				"dlg_flag", INT_PARAM, &type);
 				"dlg_flag", INT_PARAM, &type);
         if (param) {
         if (param) {
-		have_dlg_api = True;
+		have_dlg_api = true;
 
 
 		dialog_flag = *param;
 		dialog_flag = *param;
 
 

+ 19 - 19
modules/statsd/lib_statsd.c

@@ -24,13 +24,13 @@ static StatsConnection statsd_connection = {
     "8125"
     "8125"
 };
 };
 
 
-int statsd_connect(void){
+bool statsd_connect(void){
 
 
     struct addrinfo *serverAddr;
     struct addrinfo *serverAddr;
     int rc, error;
     int rc, error;
 
 
     if (statsd_socket.sock > 0){
     if (statsd_socket.sock > 0){
-        return True;
+        return true;
     }
     }
 
 
     error = getaddrinfo(
     error = getaddrinfo(
@@ -41,62 +41,62 @@ int statsd_connect(void){
         LM_ERR(
         LM_ERR(
             "Statsd: could not initiate server information (%s)\n",
             "Statsd: could not initiate server information (%s)\n",
             gai_strerror(error));
             gai_strerror(error));
-        return False;
+        return false;
     }
     }
 
 
     statsd_socket.sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
     statsd_socket.sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if (statsd_socket.sock == 0 ){
     if (statsd_socket.sock == 0 ){
         LM_ERR("Statsd: could not initiate a connect to statsd\n");
         LM_ERR("Statsd: could not initiate a connect to statsd\n");
-        return False;
+        return false;
     }
     }
 
 
     rc = connect(
     rc = connect(
         statsd_socket.sock, serverAddr->ai_addr, serverAddr->ai_addrlen);
         statsd_socket.sock, serverAddr->ai_addr, serverAddr->ai_addrlen);
     if (rc < 0){
     if (rc < 0){
         LM_ERR("Statsd: could not initiate a connect to statsd\n");
         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;
     int send_result;
 
 
     if (!statsd_connect()){
     if (!statsd_connect()){
-        return False;
+        return false;
     }
     }
 
 
     send_result = send(statsd_socket.sock, command, strlen(command), 0);
     send_result = send(statsd_socket.sock, command, strlen(command), 0);
     if ( send_result < 0){
     if ( send_result < 0){
         LM_ERR("could not send the correct info to statsd (%i| %s)\n",
         LM_ERR("could not send the correct info to statsd (%i| %s)\n",
             send_result, strerror(errno));
             send_result, strerror(errno));
-        return True;
+        return true;
     }
     }
     LM_DBG("Sent to statsd (%s)", command);
     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* end = 0;
    char command[254];
    char command[254];
    int val;
    int val;
    val = strtol(value, &end, 0);
    val = strtol(value, &end, 0);
    if (*end){
    if (*end){
        LM_ERR("statsd_count could not  use the provide value(%s)\n", value);
        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);
    snprintf(command, sizeof command, "%s:%i|s\n", key, val);
    return send_command(command);
    return send_command(command);
 }
 }
 
 
 
 
-int statsd_gauge(char *key, char *value){
+bool statsd_gauge(char *key, char *value){
    char command[254];
    char command[254];
    snprintf(command, sizeof command, "%s:%s|g\n", key, value);
    snprintf(command, sizeof command, "%s:%s|g\n", key, value);
    return send_command(command);
    return send_command(command);
 }
 }
 
 
-int statsd_count(char *key, char *value){
+bool statsd_count(char *key, char *value){
    char* end = 0;
    char* end = 0;
    char command[254];
    char command[254];
    int val;
    int val;
@@ -104,19 +104,19 @@ int statsd_count(char *key, char *value){
    val = strtol(value, &end, 0);
    val = strtol(value, &end, 0);
    if (*end){
    if (*end){
        LM_ERR("statsd_count could not  use the provide value(%s)\n", value);
        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);
    snprintf(command, sizeof command, "%s:%i|c\n", key, val);
    return send_command(command);
    return send_command(command);
 }
 }
 
 
-int statsd_timing(char *key, int value){
+bool statsd_timing(char *key, int value){
    char command[254];
    char command[254];
    snprintf(command, sizeof command, "%s:%i|ms\n", key, value);
    snprintf(command, sizeof command, "%s:%i|ms\n", key, value);
    return send_command(command);
    return send_command(command);
 }
 }
 
 
-int statsd_init(char *ip, char *port){
+bool statsd_init(char *ip, char *port){
 
 
     if (ip != NULL){
     if (ip != NULL){
         statsd_connection.ip = ip;
         statsd_connection.ip = ip;
@@ -127,7 +127,7 @@ int statsd_init(char *ip, char *port){
     return statsd_connect();
     return statsd_connect();
 }
 }
 
 
-int statsd_destroy(void){
+bool statsd_destroy(void){
     statsd_socket.sock = 0;
     statsd_socket.sock = 0;
-    return True;
+    return true;
 }
 }

+ 9 - 11
modules/statsd/lib_statsd.h

@@ -1,8 +1,6 @@
+#include <stdbool.h>
 
 
 #define BUFFER_SIZE 8192
 #define BUFFER_SIZE 8192
-typedef int Bool;
-#define True 1
-#define False 0
 
 
 typedef struct StatsConnection{
 typedef struct StatsConnection{
     char *ip;
     char *ip;
@@ -17,11 +15,11 @@ typedef struct StatsdSocket {
     char data[BUFFER_SIZE]; // buffer for the answer data
     char data[BUFFER_SIZE]; // buffer for the answer data
 } StatsdSocket;
 } 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);