]> granicus.if.org Git - curl/commitdiff
digest: Use boolean based success code for Curl_sasl_digest_get_pair()
authorSteve Holme <steve_holme@hotmail.com>
Sat, 12 Mar 2016 17:25:15 +0000 (17:25 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Sat, 12 Mar 2016 17:25:15 +0000 (17:25 +0000)
Rather than use a 0 and 1 integer base result code use a TRUE / FALSE
based success code.

lib/curl_sasl.c
lib/curl_sasl.h
lib/curl_sasl_sspi.c

index 242fd58ea9359ff0ad4756d705de63d07d3d2c98..dd2f26276442e4342ea8c8428a92ae0c461c16e5 100644 (file)
@@ -92,13 +92,8 @@ const struct {
 #endif
 
 #if !defined(CURL_DISABLE_CRYPTO_AUTH)
-/*
- * Returns 0 on success and then the buffers are filled in fine.
- *
- * Non-zero means failure to parse.
- */
-int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
-                              const char **endptr)
+bool Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
+                               const char **endptr)
 {
   int c;
   bool starts_with_quote = FALSE;
@@ -110,7 +105,7 @@ int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
 
   if('=' != *str++)
     /* eek, no match */
-    return 1;
+    return FALSE;
 
   if('\"' == *str) {
     /* this starts with a quote so it must end with one as well! */
@@ -129,6 +124,7 @@ int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
         continue;
       }
       break;
+
     case ',':
       if(!starts_with_quote) {
         /* this signals the end of the content if we didn't get a starting
@@ -137,11 +133,13 @@ int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
         continue;
       }
       break;
+
     case '\r':
     case '\n':
       /* end of string */
       c = 0;
       continue;
+
     case '\"':
       if(!escape && starts_with_quote) {
         /* end of string */
@@ -150,14 +148,15 @@ int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
       }
       break;
     }
+
     escape = FALSE;
     *content++ = *str;
   }
-  *content = 0;
 
+  *content = 0;
   *endptr = str;
 
-  return 0; /* all is fine! */
+  return TRUE;
 }
 #endif
 
@@ -780,7 +779,7 @@ CURLcode Curl_sasl_decode_digest_http_message(const char *chlg,
       chlg++;
 
     /* Extract a value=content pair */
-    if(!Curl_sasl_digest_get_pair(chlg, value, content, &chlg)) {
+    if(Curl_sasl_digest_get_pair(chlg, value, content, &chlg)) {
       if(Curl_raw_equal(value, "nonce")) {
         free(digest->nonce);
         digest->nonce = strdup(content);
index 468e0fe73c41b0fdcc67937f3bd59aa7a46b9f8e..2175e03d47dd12d8c0074917d6ccce13e7088f9c 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -149,8 +149,8 @@ char *Curl_sasl_build_gssapi_spn(const char *service, const char *instance);
 
 #ifndef CURL_DISABLE_CRYPTO_AUTH
 /* This is used to extract the realm from a challenge message */
-int Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
-                              const char **endptr);
+bool Curl_sasl_digest_get_pair(const char *str, char *value, char *content,
+                               const char **endptr);
 
 /* This is used to generate a base64 encoded DIGEST-MD5 response message */
 CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
index f090a0e1e49dda1c5e109f08057a321e29cccb7d..7603e3bd050bad1c9d04f1489ea96156ac60c55b 100644 (file)
@@ -304,7 +304,7 @@ CURLcode Curl_override_sspi_http_realm(const char *chlg,
         chlg++;
 
       /* Extract a value=content pair */
-      if(!Curl_sasl_digest_get_pair(chlg, value, content, &chlg)) {
+      if(Curl_sasl_digest_get_pair(chlg, value, content, &chlg)) {
         if(Curl_raw_equal(value, "realm")) {
 
           /* Setup identity's domain and length */