Fix integer precision warnings
[gssweb.git] / json_gssapi / src / commands / GSSAcquireCred.cpp
index ed86a17..c80db63 100644 (file)
@@ -1,7 +1,34 @@
 /*
- * Copyright (c) 2014 <copyright holder> <email>
+ * Copyright (c) 2014, JANET(UK)
+ * All rights reserved.
  *
- * For license details, see the LICENSE file in the root of this project.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -30,7 +57,7 @@ GSSAcquireCred::~GSSAcquireCred()
 GSSAcquireCred::GSSAcquireCred ( 
     JSONObject *params, 
     gss_acq_cred_type fn
-) : GSSCommand ( params )
+)
 {
   /* Variables */
   /* Error checking */
@@ -55,16 +82,16 @@ bool GSSAcquireCred::loadParameters(JSONObject *params)
   
   /* Main processing */
   // Easy stuff(*params)
-  this->time_req = (*params)["arguments"]["time_req"].integer();
+  this->time_req = (OM_uint32 )(*params)["time_req"].integer();
 
   /**************
    * cred_usage *
    **************/
-  if ( ! params->get("arguments").get("cred_usage").isNull() )
+  if ( ! params->get("cred_usage").isNull() )
   {
-    if (params->get("arguments").get("cred_usage").isString())
+    if (params->get("cred_usage").isString())
     {
-      sCredUsage = params->get("arguments").get("cred_usage").string();
+      sCredUsage = params->get("cred_usage").string();
       if (sCredUsage == "GSS_C_BOTH")
         this->cred_usage = GSS_C_BOTH;
       else if (sCredUsage == "GSS_C_INITIATE")
@@ -73,8 +100,8 @@ bool GSSAcquireCred::loadParameters(JSONObject *params)
         this->cred_usage = GSS_C_ACCEPT;
       else
         throw std::invalid_argument( std::string("Invalid cred_usage type given: ") + sCredUsage );
-    } else if (params->get("arguments").get("cred_usage").isInteger())
-      this->cred_usage = (gss_cred_usage_t)( params->get("arguments").get("cred_usage").integer() );
+    } else if (params->get("cred_usage").isInteger())
+      this->cred_usage = (gss_cred_usage_t)( params->get("cred_usage").integer() );
     else
       throw std::invalid_argument( "Unrecognized argument type for cred_usage." );
       }
@@ -82,15 +109,15 @@ bool GSSAcquireCred::loadParameters(JSONObject *params)
   /*****************
    * desired_mechs *
    *****************/
-  if ( ! params->get("arguments").get("desired_mechs").isNull() )
+  if ( ! params->get("desired_mechs").isNull() )
   {
-    if ( params->get("arguments").get("desired_mechs").isArray() )
+    if ( params->get("desired_mechs").isArray() )
     {
       for (nDesiredMechs = 0; 
-          nDesiredMechs < params->get("arguments").get("desired_mechs").size();
+          nDesiredMechs < params->get("desired_mechs").size();
           nDesiredMechs++)
       {
-        std::string mechStr = params->get("arguments").get("desired_mechs")[nDesiredMechs].string();
+        std::string mechStr = params->get("desired_mechs")[nDesiredMechs].string();
         desiredMechs.addOID( GSSOID(mechStr).toGss() );
       }
     } else
@@ -100,9 +127,9 @@ bool GSSAcquireCred::loadParameters(JSONObject *params)
   /****************
    * desired_name *
    ****************/
-  if ( ! params->get("arguments").get("desired_name").isNull() )
+  if ( ! params->get("desired_name").isNull() )
   {
-    std::string key = params->get("arguments").get("desired_name").string();
+    std::string key = params->get("desired_name").string();
     this->desired_name = GSSNameCache::instance()->retrieve(key);
   }
 
@@ -152,8 +179,6 @@ void GSSAcquireCred::execute()
 /* Desired JSON output:
  * 
  * {
- *   "command": "gss_acquire_cred",
- *   "return_values": {
  *     "major_status": 0,
  *     "minor_status": 0,
  *     "cred_handle": "###########",
@@ -162,15 +187,12 @@ void GSSAcquireCred::execute()
  *       "{ 5 6 7 8 }"
  *     ],
  *     "time_rec": 0
- *   }
  * }
  */
 JSONObject *GSSAcquireCred::toJSON()
 {
   /* Variables */
-  JSONObject *ret = new JSONObject();
   JSONObject *values = new JSONObject();
-//   JSONObject mechs = JSONObject::array();
   JSONObject *temp;
   
   /* Error checking */
@@ -191,12 +213,8 @@ JSONObject *GSSAcquireCred::toJSON()
   temp = this->actualMechs.toJSONValue();
   values->set("actual_mechs", *temp);
   
-  // Put it all together.
-  ret->set("command", "gss_acquire_cred");
-  ret->set("return_values", *values);
-  
   /* Cleanup */
   
   /* Return */
-  return(ret);
+  return(values);
 }