Remove superfluous variable juggling in the base64 decoding of the input token.
[gssweb.git] / json_gssapi / src / commands / GSSInitSecContext.cpp
index 7688c1e..68cd43a 100644 (file)
@@ -139,7 +139,6 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   /* Variables */
   std::string key;
   std::string token;
-  size_t len;
   
   /* Error checking */
   if ( params->isNull() )
@@ -152,7 +151,9 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   // claimant_cred_handle
 
   // context_handle
-  if ( ! params->get("context_handle").isNull() )
+  if (!(params->get("context_handle").isNull() ||
+       (params->get("context_handle").isString() &&
+        std::string("") == params->get("context_handle").string())))
   {
     this->context_handle = GSS_C_NO_CONTEXT;
     if (params->get("context_handle").isString())
@@ -166,7 +167,11 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   }
   
   // target_name
-  if ( ! params->get("target_name").isNull() )
+  if (! (  params->get("target_name").isNull() ||
+          (params->get("target_name").isString() &&
+           std::string("") == params->get("target_name").string())
+       )
+     )
   {
     this->target_name = GSS_C_NO_NAME;
     if (params->get("target_name").isString())
@@ -182,7 +187,13 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   }
   
   // mech_type  
-  if ( ! params->get("mech_type").isNull() )
+  if (! ( params->get("mech_type").isNull() ||
+         (
+           params->get("mech_type").isString() &&
+           std::string("") == params->get("mech_type").string()
+         )
+       )
+     )
   {
     key.clear();
     if (params->get("mech_type").isString())
@@ -195,22 +206,20 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   }
   
   // req_flags
-  if ( !params->get("req_flags").isNull() )
+  if (!params->get("req_flags").isNull() )
     this->req_flags = params->get("req_flags").integer();
 
   // time_req
-  if ( !params->get("time_req").isNull() )
+  if (!params->get("time_req").isNull() )
     this->time_req = params->get("time_req").integer();
 
-  // input_chennel_bindings
-
   // input_token
-  if ( ! params->get("input_token").isNull() )
+  if (! (params->get("input_token").isNull() ||
+        (params->get("input_token").isString() &&
+         std::string("") == params->get("input_token").string())))
   {
     token = params->get("input_token").string();
-    token = (char *)base64_decode(token, &len);
-    this->input_token.value = (void *)token.c_str();
-    this->input_token.length = token.length();
+    this->input_token.value = base64_decode(token, &this->input_token.length);
   }
 
   /* Cleanup */
@@ -270,7 +279,7 @@ JSONObject *GSSInitSecContext::toJSON()
 {
   /* Variables */
   // MRW -- values should be scoped to the class, so execute can set error values?
-  std::string output_str;
+  std::string output_str((char *)output_token.value, output_token.length);
   JSONObject *values = new JSONObject();
   
   /* Error checking */
@@ -283,7 +292,7 @@ JSONObject *GSSInitSecContext::toJSON()
   values->set("context_handle", this->contextKey.c_str());
   values->set("actual_mech_type", this->getActualMechType().toString().c_str());
   // MRW -- is output_token.value guaranteed to be null-terminated?
-  output_str = (char *)output_token.value;
+  //output_str = (char *)output_token.value;
   values->set("output_token", base64_encode(output_str));
   values->set("ret_flags", this->ret_flags);
   values->set("time_rec", this->time_rec);