1aeba1f1421158cf12d9201d41ab852bc6911d09
[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 #include <cache/GSSNameCache.h>
11 #include <datamodel/GSSDisplayStatus.h>
12
13
14 typedef OM_uint32 (*gss_imp_name_type)(
15     OM_uint32 *,        /* minor_status */
16     gss_buffer_t,       /* input_name_buffer */
17     gss_OID,            /* input_name_type(used to be const) */
18     gss_name_t *);      /* output_name */
19
20
21
22 void GSSImportName::execute()
23 {
24   /* Variables */
25   gss_name_t name;
26   std::string key;
27
28   /* Error checking */
29   /* Setup */
30
31   /* Main */
32   retVal = function(&minor_status, inputName.toGss(), inputNameType.toGss(), &name);
33 //   if ( GSS_ERROR(this->retVal) )
34 //   {
35     JSONObject errors;
36     GSSDisplayStatus ds(retVal, minor_status, inputNameType.toGss());
37     errors.set("major_status_message", ds.getMajorMessage().c_str());
38     errors.set("minor_status_message", ds.getMinorMessage().c_str());
39     values->set("errors", errors);
40 //   }
41   
42   
43   
44   this->outputName.setValue(name);
45   key = GSSNameCache::instance()->store(this->outputName);
46 //   std::cout << "Storing key: " << key << std::endl;
47   this->outputName.setKey(key);
48   /* Cleanup */
49   /* Return */
50   
51 }
52
53 /* Example output:
54  * 
55  *   {
56  *     "major_status": 0,
57  *     "minor_status": 0,
58  *     "gss_name": "base64_encoded_string"
59  *   }
60  * 
61  */
62 JSONObject *GSSImportName::toJSON()
63 {
64   /* Variables */
65   /* Error checking */
66   
67   /* Setup */
68   
69   /* Main */
70   values->set("major_status", this->retVal);
71   values->set("minor_status", this->minor_status);
72   values->set("gss_name", this->outputName.getKey().c_str() );
73   
74   /* Cleanup */
75   
76   /* Return */
77   return(values);
78 }
79
80 GSSImportName::GSSImportName ( gss_imp_name_type fn )
81 {
82   // defaults
83   function = fn;
84   inputName = string("");
85   inputNameType.setValue(GSSBuffer( string("{ 1 2 840 113554 1 2 1 4 }") ));
86   values = new JSONObject();
87 }
88
89 GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
90 {
91   /* Variables */
92   /* Error checking */
93   /* Setup */
94   /* Main */
95   values = new JSONObject();
96   loadParameters(params);
97   function = fn;
98   /* Cleanup */
99   /* Return */
100   
101 }
102
103 bool GSSImportName::loadParameters(JSONObject *params)
104 {
105   /* Variables */
106   
107   /* Error checking */
108   /* Setup */
109   // Should I zeroOut?
110   
111   /* Main processing */
112   // Easy stuff(*params)
113   if ( params->isNull() )
114     return true;
115   
116   if ( !params->get("input_name").isNull() )
117   {
118     if ( params->get("input_name").isString() )
119     {
120       std::string input_name = params->get("input_name").string();
121       this->inputName.setValue( input_name );
122     }
123   }
124   
125   if ( !params->get("input_name_type").isNull() )
126   {
127     if ( params->get("input_name_type").isString() )
128     {
129       std::string input_name_type = params->get("input_name_type").string();
130       this->inputNameType.setValue( input_name_type );
131     }
132   }
133   
134   /* Cleanup */
135   /* Return */
136   return true;
137 }
138
139
140
141
142 /* Variables */
143 /* Error checking */
144 /* Setup */
145 /* Main */
146 /* Cleanup */
147 /* Return */