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