Move util_ files into utils directory, move main.cpp into src
[gssweb.git] / json_gssapi / src / commands / GSSImportName.cpp
index 5284009..9b9ae42 100644 (file)
@@ -1,27 +1,78 @@
 /*
- * Copyright (c) 2014 <copyright holder> <email>
- * 
- * For license details, see the LICENSE file in the root of this project.
- * 
+ * Copyright (c) 2014, JANET(UK)
+ * All rights reserved.
+ *
+ * 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.
+ *
  */
 
 #include "GSSImportName.h"
 #include "GSSException.h"
+#include <cache/GSSNameCache.h>
+#include <datamodel/GSSDisplayStatus.h>
+
 
 void GSSImportName::execute()
 {
-  this->outputName = GSSName(inputName, inputNameType, function);
-  this->retVal = this->outputName.getMajorStatus();
-  this->minor_status = this->outputName.getMinorStatus();
-  this->outputName.setKey("constant for now");
+  /* Variables */
+  gss_name_t name;
+  std::string key;
+
+  /* Error checking */
+  /* Setup */
+
+  /* Main */
+  retVal = function(&minor_status, inputName.toGss(), inputNameType.toGss(), &name);
+  JSONObject errors;
+  GSSDisplayStatus ds(retVal, minor_status, inputNameType.toGss());
+  errors.set("major_status_message", ds.getMajorMessage().c_str());
+  errors.set("minor_status_message", ds.getMinorMessage().c_str());
+  values->set("errors", errors);
+  this->outputName.setValue(name);
+  key = GSSNameCache::instance()->store(this->outputName);
+  this->outputName.setKey(key);
+  /* Cleanup */
+  /* Return */
 }
 
+/* Example output:
+ * 
+ *   {
+ *     "major_status": 0,
+ *     "minor_status": 0,
+ *     "gss_name": "base64_encoded_string"
+ *   }
+ * 
+ */
 JSONObject *GSSImportName::toJSON()
 {
   /* Variables */
-  JSONObject *ret = new JSONObject();
-  JSONObject *values = new JSONObject();
-  
   /* Error checking */
   
   /* Setup */
@@ -30,21 +81,29 @@ JSONObject *GSSImportName::toJSON()
   values->set("major_status", this->retVal);
   values->set("minor_status", this->minor_status);
   values->set("gss_name", this->outputName.getKey().c_str() );
-  ret->set("command", "gss_import_name");
-  ret->set("return_values", *values);
   
   /* Cleanup */
   
   /* Return */
-  return(ret);
+  return(values);
 }
 
-GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
+GSSImportName::GSSImportName ( gss_imp_name_type fn )
+{
+  // defaults
+  function = fn;
+  inputName = string("");
+  inputNameType.setValue(GSSBuffer( string("{ 1 2 840 113554 1 2 1 4 }") ));
+  values = new JSONObject();
+}
+
+GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn)
 {
   /* Variables */
   /* Error checking */
   /* Setup */
   /* Main */
+  values = new JSONObject();
   loadParameters(params);
   function = fn;
   /* Cleanup */
@@ -58,27 +117,27 @@ bool GSSImportName::loadParameters(JSONObject *params)
   
   /* Error checking */
   /* Setup */
-  // Should I zeroOut?
+  // Should I zeroOut?  MRW -- do initialize here for null inputs
   
   /* Main processing */
   // Easy stuff(*params)
-  if ( params->get("arguments").isNull() )
+  if ( params->isNull() )
     return true;
   
-  if ( !params->get("arguments").get("input_name").isNull() )
+  if ( !params->get("input_name").isNull() )
   {
-    if ( params->get("arguments").get("input_name").isString() )
+    if ( params->get("input_name").isString() )
     {
-      std::string input_name = params->get("arguments").get("input_name").string();
+      std::string input_name = params->get("input_name").string();
       this->inputName.setValue( input_name );
     }
   }
   
-  if ( !params->get("arguments").get("input_name_type").isNull() )
+  if ( !params->get("input_name_type").isNull() )
   {
-    if ( params->get("arguments").get("input_name_type").isString() )
+    if ( params->get("input_name_type").isString() )
     {
-      std::string input_name_type = params->get("arguments").get("input_name_type").string();
+      std::string input_name_type = params->get("input_name_type").string();
       this->inputNameType.setValue( input_name_type );
     }
   }
@@ -87,39 +146,3 @@ bool GSSImportName::loadParameters(JSONObject *params)
   /* Return */
   return true;
 }
-
-
-//   /***********
-//    * QOP_REQ *
-//    ***********/
-//   if ( ! params->get("arguments").get("qop_req").isNull() )
-//   {
-//     if (params->get("arguments").get("qop_req").isString())
-//     {
-//       sQopReq = params->get("arguments").get("qop_req").string();
-//       if (sQopReq == "GSS_C_QOP_DEFAULT")
-//         this->qop_req = GSS_C_QOP_DEFAULT;
-//       else
-//         throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
-//     } else if (params->get("arguments").get("qop_req").isInteger())
-//       this->qop_req = (gss_cred_usage_t)( params->get("arguments").get("qop_req").integer() );
-//     else
-//       throw std::invalid_argument( "Unrecognized argument type for qop_req." );
-//   }
-//   
-//   /*****************
-//    * input_message *
-//    *****************/
-//   if ( ! params->get("arguments").get("input_message").isNull() )
-//   {
-//     sInputMessage = params->get("arguments").get("input_message").string();
-//     this->inputMessage.setValue(sInputMessage);
-//   }
-
-
-/* Variables */
-/* Error checking */
-/* Setup */
-/* Main */
-/* Cleanup */
-/* Return */