qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject qpid-proton git commit: NO-JIRA: Fixed use of strdup and strcasecmp in new code - Changed solution for strcasecmp/strncasecmp to use internal implementation rather than something similar but not exact.
Date Thu, 07 May 2015 19:02:51 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master cb4f9b9ff -> beaea0c1c


NO-JIRA: Fixed use of strdup and strcasecmp in new code
- Changed solution for strcasecmp/strncasecmp to use internal
  implementation rather than something similar but not exact.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/beaea0c1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/beaea0c1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/beaea0c1

Branch: refs/heads/master
Commit: beaea0c1cc8237786ba62efae1c84d03bdcf0e80
Parents: cb4f9b9
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Thu May 7 14:51:26 2015 -0400
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Thu May 7 14:51:26 2015 -0400

----------------------------------------------------------------------
 proton-c/src/platform.h         |  3 ---
 proton-c/src/sasl/cyrus_sasl.c  |  4 ++--
 proton-c/src/sasl/none_sasl.c   |  6 +++---
 proton-c/src/sasl/sasl.c        | 12 ++++++------
 proton-c/src/ssl/openssl.c      |  8 ++++----
 proton-c/src/util.c             | 31 +++++++++++++++++--------------
 proton-c/src/util.h             | 10 +++++-----
 proton-c/src/windows/schannel.c | 11 +++++------
 8 files changed, 42 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/platform.h
----------------------------------------------------------------------
diff --git a/proton-c/src/platform.h b/proton-c/src/platform.h
index b27e056..6962493 100644
--- a/proton-c/src/platform.h
+++ b/proton-c/src/platform.h
@@ -85,9 +85,6 @@ int64_t pn_i_atoll(const char* num);
 int pn_i_snprintf(char *buf, size_t count, const char *fmt, ...);
 int pn_i_vsnprintf(char *buf, size_t count, const char *fmt, va_list ap);
 
-#define strcasecmp(A,B) (!pni_eq_nocase(A,B))
-#define strncasecmp(A,B,C) (!pni_eq_n_nocase(A,B,C))
-
 #if !defined(S_ISDIR)
 # define S_ISDIR(X) ((X) & _S_IFDIR)
 #endif

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/sasl/cyrus_sasl.c
----------------------------------------------------------------------
diff --git a/proton-c/src/sasl/cyrus_sasl.c b/proton-c/src/sasl/cyrus_sasl.c
index fbbeeb1..c6010e2 100644
--- a/proton-c/src/sasl/cyrus_sasl.c
+++ b/proton-c/src/sasl/cyrus_sasl.c
@@ -79,7 +79,7 @@ int pni_sasl_impl_list_mechs(pn_transport_t *transport, char **mechlist)
     int r = sasl_listmech(cyrus_conn, NULL, "", " ", "", &result, NULL, &count);
     if (pni_check_sasl_result(cyrus_conn, r, transport)) {
       if (result && *result) {
-        *mechlist = strdup(result);
+        *mechlist = pn_strdup(result);
       }
     }
   }
@@ -157,7 +157,7 @@ bool pni_process_mechanisms(pn_transport_t *transport, const char *mechs)
     switch (result) {
         case SASL_OK:
         case SASL_CONTINUE:
-          sasl->selected_mechanism = strdup(mech_selected);
+          sasl->selected_mechanism = pn_strdup(mech_selected);
           return true;
         case SASL_NOMECH:
         default:

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/sasl/none_sasl.c
----------------------------------------------------------------------
diff --git a/proton-c/src/sasl/none_sasl.c b/proton-c/src/sasl/none_sasl.c
index 6900654..15d8476 100644
--- a/proton-c/src/sasl/none_sasl.c
+++ b/proton-c/src/sasl/none_sasl.c
@@ -63,7 +63,7 @@ bool pni_process_mechanisms(pn_transport_t *transport, const char *mechs)
   if (found && (found==mechs || found[-1]==' ') && (found[5]==0 || found[5]=='
') &&
       pni_included_mech(transport->sasl->included_mechanisms, pn_bytes(5, found)) &&
       transport->sasl->username && transport->sasl->password) {
-    transport->sasl->selected_mechanism = strdup(PLAIN);
+    transport->sasl->selected_mechanism = pn_strdup(PLAIN);
     size_t usize = strlen(transport->sasl->username);
     size_t psize = strlen(transport->sasl->password);
     size_t size = usize + psize + 2;
@@ -91,7 +91,7 @@ bool pni_process_mechanisms(pn_transport_t *transport, const char *mechs)
   // Make sure that string is separated and terminated and allowed
   if (found && (found==mechs || found[-1]==' ') && (found[9]==0 || found[9]=='
') &&
       pni_included_mech(transport->sasl->included_mechanisms, pn_bytes(9, found)))
{
-    transport->sasl->selected_mechanism = strdup(ANONYMOUS);
+    transport->sasl->selected_mechanism = pn_strdup(ANONYMOUS);
     if (transport->sasl->username) {
       size_t size = strlen(transport->sasl->username);
       char *iresp = (char *) malloc(size);
@@ -115,7 +115,7 @@ bool pni_process_mechanisms(pn_transport_t *transport, const char *mechs)
 // Server will offer only ANONYMOUS
 int pni_sasl_impl_list_mechs(pn_transport_t *transport, char **mechlist)
 {
-  *mechlist = strdup("ANONYMOUS");
+  *mechlist = pn_strdup("ANONYMOUS");
   return 1;
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/sasl/sasl.c
----------------------------------------------------------------------
diff --git a/proton-c/src/sasl/sasl.c b/proton-c/src/sasl/sasl.c
index 01eeb88..ae3a025 100644
--- a/proton-c/src/sasl/sasl.c
+++ b/proton-c/src/sasl/sasl.c
@@ -24,7 +24,7 @@
 #include "dispatch_actions.h"
 #include "engine/engine-internal.h"
 #include "protocol.h"
-#include "platform.h" // For strncasecmp on Windows
+#include "util.h"
 #include "transport/autodetect.h"
 
 #include <assert.h>
@@ -221,7 +221,7 @@ bool pni_included_mech(const char *included_mech_list, pn_bytes_t s)
     if ((ptrdiff_t)len > end_list-c) return false;
 
     // Is word equal with a space or end of string afterwards?
-    if (strncasecmp(c, s.start, len)==0 && (c[len]==' ' || c[len]==0) ) return true;
+    if (pn_strncasecmp(c, s.start, len)==0 && (c[len]==' ' || c[len]==0) ) return
true;
 
     c = strchr(c, ' ');
     c = c ? c+1 : NULL;
@@ -360,7 +360,7 @@ pn_sasl_t *pn_sasl(pn_transport_t *transport)
     sasl->username = NULL;
     sasl->password = NULL;
     sasl->config_name = sasl->client ? "proton-client" : "proton-server";
-    sasl->config_dir =  sasl_config_path ? strdup(sasl_config_path) : NULL;
+    sasl->config_dir =  sasl_config_path ? pn_strdup(sasl_config_path) : NULL;
     sasl->remote_fqdn = NULL;
     sasl->outcome = PN_SASL_NONE;
     sasl->impl_context = NULL;
@@ -411,7 +411,7 @@ void pni_sasl_set_user_password(pn_transport_t *transport, const char
*user, con
   pni_sasl_t *sasl = transport->sasl;
   sasl->username = user;
   free(sasl->password);
-  sasl->password = password ? strdup(password) : NULL;
+  sasl->password = password ? pn_strdup(password) : NULL;
 }
 
 const char *pn_sasl_get_user(pn_sasl_t *sasl0)
@@ -430,7 +430,7 @@ void pn_sasl_allowed_mechs(pn_sasl_t *sasl0, const char *mechs)
 {
     pni_sasl_t *sasl = get_sasl_internal(sasl0);
     free(sasl->included_mechanisms);
-    sasl->included_mechanisms = mechs ? strdup(mechs) : NULL;
+    sasl->included_mechanisms = mechs ? pn_strdup(mechs) : NULL;
     if (strcmp(mechs, "ANONYMOUS")==0 ) {
       pn_transport_t *transport = get_transport_internal(sasl0);
       pni_sasl_force_anonymous(transport);
@@ -447,7 +447,7 @@ void pn_sasl_config_path(pn_sasl_t *sasl0, const char *dir)
 {
     pni_sasl_t *sasl = get_sasl_internal(sasl0);
     free(sasl->config_dir);
-    sasl->config_dir = strdup(dir);
+    sasl->config_dir = pn_strdup(dir);
 }
 
 void pn_sasl_done(pn_sasl_t *sasl0, pn_sasl_outcome_t outcome)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/ssl/openssl.c
----------------------------------------------------------------------
diff --git a/proton-c/src/ssl/openssl.c b/proton-c/src/ssl/openssl.c
index 42bbd71..2bbdda0 100644
--- a/proton-c/src/ssl/openssl.c
+++ b/proton-c/src/ssl/openssl.c
@@ -230,7 +230,7 @@ static bool match_dns_pattern( const char *hostname,
   int slen = (int) strlen(hostname);
   if (memchr( pattern, '*', plen ) == NULL)
     return (plen == slen &&
-            strncasecmp( pattern, hostname, plen ) == 0);
+            pn_strncasecmp( pattern, hostname, plen ) == 0);
 
   /* dns wildcarded pattern - RFC2818 */
   char plabel[64];   /* max label length < 63 - RFC1034 */
@@ -260,15 +260,15 @@ static bool match_dns_pattern( const char *hostname,
 
     char *star = strchr( plabel, '*' );
     if (!star) {
-      if (strcasecmp( plabel, slabel )) return false;
+      if (pn_strcasecmp( plabel, slabel )) return false;
     } else {
       *star = '\0';
       char *prefix = plabel;
       int prefix_len = strlen(prefix);
       char *suffix = star + 1;
       int suffix_len = strlen(suffix);
-      if (prefix_len && strncasecmp( prefix, slabel, prefix_len )) return false;
-      if (suffix_len && strncasecmp( suffix,
+      if (prefix_len && pn_strncasecmp( prefix, slabel, prefix_len )) return false;
+      if (suffix_len && pn_strncasecmp( suffix,
                                      slabel + (strlen(slabel) - suffix_len),
                                      suffix_len )) return false;
     }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/util.c
----------------------------------------------------------------------
diff --git a/proton-c/src/util.c b/proton-c/src/util.c
index d0aa6b0..2fe7e95 100644
--- a/proton-c/src/util.c
+++ b/proton-c/src/util.c
@@ -212,29 +212,32 @@ void pni_fatal(const char *fmt, ...)
   va_end(ap);
 }
 
-bool pni_eq_nocase(const char *a, const char *b)
+int pn_strcasecmp(const char *a, const char *b)
 {
-    while (*b) {
-        if (tolower(*a++) != tolower(*b++))
-            return false;
-    }
-    return !(*a);
+  char diff;
+  while (*b) {
+    diff = tolower(*a++)-tolower(*b++);
+    if ( diff!=0 ) return diff;
+  }
+  return *a;
 }
 
-bool pni_eq_n_nocase(const char *a, const char *b, int len)
+int pn_strncasecmp(const char* a, const char* b, size_t len)
 {
-  while (*b && len-- > 0 ) {
-    if (tolower(*a++) != tolower(*b++))
-      return false;
-  }
-  return !(*a) && !(*b);
+  char diff;
+  while (*b && len > 0) {
+    diff = tolower(*a++)-tolower(*b++);
+    if ( diff!=0 ) return diff;
+    --len;
+  };
+  return len==0 ? diff : *a;
 }
 
 bool pn_env_bool(const char *name)
 {
   char *v = getenv(name);
-  return v && (pni_eq_nocase(v, "true") || pni_eq_nocase(v, "1") ||
-               pni_eq_nocase(v, "yes") || pni_eq_nocase(v, "on"));
+  return v && (!pn_strcasecmp(v, "true") || !pn_strcasecmp(v, "1") ||
+               !pn_strcasecmp(v, "yes")  || !pn_strcasecmp(v, "on"));
 }
 
 char *pn_strdup(const char *src)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/util.h
----------------------------------------------------------------------
diff --git a/proton-c/src/util.h b/proton-c/src/util.h
index 8406747..8973a07 100644
--- a/proton-c/src/util.h
+++ b/proton-c/src/util.h
@@ -39,11 +39,14 @@ PN_EXTERN ssize_t pn_quote_data(char *dst, size_t capacity, const char
*src, siz
 int pn_quote(pn_string_t *dst, const char *src, size_t size);
 PN_EXTERN void pn_fprint_data(FILE *stream, const char *bytes, size_t size);
 PN_EXTERN void pn_print_data(const char *bytes, size_t size);
-bool pni_eq_nocase(const char *a, const char *b);
-bool pni_eq_n_nocase(const char *a, const char *b, int len);
 bool pn_env_bool(const char *name);
 pn_timestamp_t pn_timestamp_min(pn_timestamp_t a, pn_timestamp_t b);
 
+char *pn_strdup(const char *src);
+char *pn_strndup(const char *src, size_t n);
+int pn_strcasecmp(const char* a, const char* b);
+int pn_strncasecmp(const char* a, const char* b, size_t len);
+
 #define DIE_IFR(EXPR, STRERR)                                           \
   do {                                                                  \
     int __code__ = (EXPR);                                              \
@@ -103,9 +106,6 @@ pn_timestamp_t pn_timestamp_min(pn_timestamp_t a, pn_timestamp_t b);
       LL_TAIL(ROOT, LIST) = (NODE)-> LIST ## _prev;                    \
   }
 
-char *pn_strdup(const char *src);
-char *pn_strndup(const char *src, size_t n);
-
 #define pn_min(X,Y) ((X) > (Y) ? (Y) : (X))
 #define pn_max(X,Y) ((X) < (Y) ? (Y) : (X))
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/beaea0c1/proton-c/src/windows/schannel.c
----------------------------------------------------------------------
diff --git a/proton-c/src/windows/schannel.c b/proton-c/src/windows/schannel.c
index 353ce9b..57d2256 100644
--- a/proton-c/src/windows/schannel.c
+++ b/proton-c/src/windows/schannel.c
@@ -1725,8 +1725,7 @@ static HCERTSTORE open_cert_db(const char *store_name, const char *passwd,
int *
   if (sys_store_type) {
     // Opening a system store, names are not case sensitive.
     // Map confusing GUI name to actual registry store name.
-    if (pni_eq_nocase(store_name, "personal"))
-      store_name= "my";
+    if (!pn_strcasecmp(store_name, "personal")) store_name= "my";
     cert_store = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, NULL,
                                CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG |
                                sys_store_type, store_name);
@@ -1818,7 +1817,7 @@ static bool match_dns_pattern(const char *hostname, const char *pattern,
int ple
   int slen = (int) strlen(hostname);
   if (memchr( pattern, '*', plen ) == NULL)
     return (plen == slen &&
-            strncasecmp( pattern, hostname, plen ) == 0);
+            pn_strncasecmp( pattern, hostname, plen ) == 0);
 
   /* dns wildcarded pattern - RFC2818 */
   char plabel[64];   /* max label length < 63 - RFC1034 */
@@ -1848,15 +1847,15 @@ static bool match_dns_pattern(const char *hostname, const char *pattern,
int ple
 
     char *star = strchr( plabel, '*' );
     if (!star) {
-      if (strcasecmp( plabel, slabel )) return false;
+      if (pn_strcasecmp( plabel, slabel )) return false;
     } else {
       *star = '\0';
       char *prefix = plabel;
       int prefix_len = strlen(prefix);
       char *suffix = star + 1;
       int suffix_len = strlen(suffix);
-      if (prefix_len && strncasecmp( prefix, slabel, prefix_len )) return false;
-      if (suffix_len && strncasecmp( suffix,
+      if (prefix_len && pn_strncasecmp( prefix, slabel, prefix_len )) return false;
+      if (suffix_len && pn_strncasecmp( suffix,
                                      slabel + (strlen(slabel) - suffix_len),
                                      suffix_len )) return false;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message