52840098491775e7faa6c07f3a03f4e46bd1c6b4
[gssweb.git] / json_gssapi / src / commands / GSSImportName.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  * 
4  * For license details, see the LICENSE file in the root of this project.
5  * 
6  */
7
8 #include "GSSImportName.h"
9 #include "GSSException.h"
10
11 void GSSImportName::execute()
12 {
13   this->outputName = GSSName(inputName, inputNameType, function);
14   this->retVal = this->outputName.getMajorStatus();
15   this->minor_status = this->outputName.getMinorStatus();
16   this->outputName.setKey("constant for now");
17 }
18
19 JSONObject *GSSImportName::toJSON()
20 {
21   /* Variables */
22   JSONObject *ret = new JSONObject();
23   JSONObject *values = new JSONObject();
24   
25   /* Error checking */
26   
27   /* Setup */
28   
29   /* Main */
30   values->set("major_status", this->retVal);
31   values->set("minor_status", this->minor_status);
32   values->set("gss_name", this->outputName.getKey().c_str() );
33   ret->set("command", "gss_import_name");
34   ret->set("return_values", *values);
35   
36   /* Cleanup */
37   
38   /* Return */
39   return(ret);
40 }
41
42 GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
43 {
44   /* Variables */
45   /* Error checking */
46   /* Setup */
47   /* Main */
48   loadParameters(params);
49   function = fn;
50   /* Cleanup */
51   /* Return */
52   
53 }
54
55 bool GSSImportName::loadParameters(JSONObject *params)
56 {
57   /* Variables */
58   
59   /* Error checking */
60   /* Setup */
61   // Should I zeroOut?
62   
63   /* Main processing */
64   // Easy stuff(*params)
65   if ( params->get("arguments").isNull() )
66     return true;
67   
68   if ( !params->get("arguments").get("input_name").isNull() )
69   {
70     if ( params->get("arguments").get("input_name").isString() )
71     {
72       std::string input_name = params->get("arguments").get("input_name").string();
73       this->inputName.setValue( input_name );
74     }
75   }
76   
77   if ( !params->get("arguments").get("input_name_type").isNull() )
78   {
79     if ( params->get("arguments").get("input_name_type").isString() )
80     {
81       std::string input_name_type = params->get("arguments").get("input_name_type").string();
82       this->inputNameType.setValue( input_name_type );
83     }
84   }
85   
86   /* Cleanup */
87   /* Return */
88   return true;
89 }
90
91
92 //   /***********
93 //    * QOP_REQ *
94 //    ***********/
95 //   if ( ! params->get("arguments").get("qop_req").isNull() )
96 //   {
97 //     if (params->get("arguments").get("qop_req").isString())
98 //     {
99 //       sQopReq = params->get("arguments").get("qop_req").string();
100 //       if (sQopReq == "GSS_C_QOP_DEFAULT")
101 //         this->qop_req = GSS_C_QOP_DEFAULT;
102 //       else
103 //         throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
104 //     } else if (params->get("arguments").get("qop_req").isInteger())
105 //       this->qop_req = (gss_cred_usage_t)( params->get("arguments").get("qop_req").integer() );
106 //     else
107 //       throw std::invalid_argument( "Unrecognized argument type for qop_req." );
108 //   }
109 //   
110 //   /*****************
111 //    * input_message *
112 //    *****************/
113 //   if ( ! params->get("arguments").get("input_message").isNull() )
114 //   {
115 //     sInputMessage = params->get("arguments").get("input_message").string();
116 //     this->inputMessage.setValue(sInputMessage);
117 //   }
118
119
120 /* Variables */
121 /* Error checking */
122 /* Setup */
123 /* Main */
124 /* Cleanup */
125 /* Return */