Added kim_selection_hints_create_from_stream and
authorAlexandra Ellwood <lxs@mit.edu>
Sun, 28 Sep 2008 20:53:12 +0000 (20:53 +0000)
committerAlexandra Ellwood <lxs@mit.edu>
Sun, 28 Sep 2008 20:53:12 +0000 (20:53 +0000)
kim_selection_hints_write_to_stream for client/server
communication.

ticket: 6055

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20770 dc483132-0cff-0310-8789-dd5450dbe970

src/kim/agent/mac/ServerDemux.m
src/kim/lib/kim.exports
src/kim/lib/kim_options.c
src/kim/lib/kim_options_private.h
src/kim/lib/kim_selection_hints.c
src/kim/lib/kim_selection_hints_private.h
src/kim/lib/mac/kim_os_ui_gui.c

index 7c2e4f0842f5f320e01b6cda110c9590f4f3bdea..d7cfec94944949e9bb508f59cb9dafc5c21e50f4 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #import "ServerDemux.h"
+#import "kim_selection_hints_private.h"
 
 // ---------------------------------------------------------------------------
 
@@ -189,7 +190,8 @@ static int32_t kim_handle_request_select_identity (mach_port_t   in_client_port,
     kim_selection_hints hints = NULL;
     
     if (!err) {
-        //err = kim_os_selection_hints_read (out_hints, in_request_stream);
+        err = kim_selection_hints_create_from_stream (&hints, 
+                                                      in_request_stream);
     }    
     
     if (!err) {
index fea6bf8139cb45e6be202bec70a4bbc2dd29e564..8a2c6c32a3e411de0377b99635bac9732fa7aaf2 100644 (file)
@@ -55,6 +55,9 @@ kim_selection_hints_remember_identity
 kim_selection_hints_forget_identity
 kim_selection_hints_free
 
+# Used by KerberosAgent
+kim_selection_hints_create_from_stream
+
 kim_preferences_create
 kim_preferences_copy
 kim_preferences_set_options
index a5470f413b2d9b6065deba3feee1081091e8eb7e..89272b6358afaa2750bf51e7d6064836cdd8c097 100644 (file)
@@ -136,7 +136,7 @@ kim_error kim_options_copy (kim_options *out_options,
             }
         }
     }
-        
+    
     if (!err) {
         *out_options = options;
         options = NULL;
@@ -484,7 +484,7 @@ krb5_get_init_creds_opt *kim_options_init_cred_options (kim_options in_options)
                                                   addresses);
         addresses = NULL;
     }
-
+    
     if (addresses) { krb5_free_addresses (in_options->init_cred_context, 
                                           addresses); }
     
@@ -508,8 +508,125 @@ void kim_options_free (kim_options *io_options)
             }
             krb5_free_context ((*io_options)->init_cred_context);
         }
-
+        
         free (*io_options);
         *io_options = NULL;
     }
 }
+
+#pragma mark -
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_options_write_to_stream (kim_options   in_options,
+                                       k5_ipc_stream io_stream)
+{
+    kim_error err = KIM_NO_ERROR;
+    
+    if (!err && !in_options) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int64 (io_stream, in_options->start_time);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int64 (io_stream, in_options->lifetime);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int32 (io_stream, in_options->renewable);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int64 (io_stream, 
+                                         in_options->renewal_lifetime);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int32 (io_stream, in_options->forwardable);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int32 (io_stream, in_options->proxiable);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_write_int32 (io_stream, in_options->addressless);
+    }
+    
+    if (!err) {
+        kim_string service_name = (in_options->service_name ?
+                                   in_options->service_name : "");
+        err = k5_ipc_stream_write_string (io_stream, service_name);
+    }
+    
+    
+    
+    return check_error (err);    
+}
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_options_create_from_stream (kim_options   *out_options,
+                                          k5_ipc_stream  io_stream)
+{
+    kim_error err = KIM_NO_ERROR;
+    kim_options options = NULL;
+    
+    if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    if (!err && !io_stream  ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    
+    if (!err) {
+        err = kim_options_allocate (&options);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int64 (io_stream, &options->start_time);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int64 (io_stream, &options->lifetime);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int32 (io_stream, &options->renewable);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int64 (io_stream, 
+                                        &options->renewal_lifetime);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int32 (io_stream, &options->forwardable);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int32 (io_stream, &options->proxiable);
+    }
+    
+    if (!err) {
+        err = k5_ipc_stream_read_int32 (io_stream, &options->addressless);
+    }
+    
+    if (!err) {
+        char *service_name = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &service_name);
+        
+        if (!err) {
+            err = kim_string_copy (&options->service_name, service_name);
+        }
+        
+        k5_ipc_stream_free_string (service_name);
+    }
+    
+    if (!err) {
+        *out_options = options;
+        options = NULL;
+    }
+    
+    kim_options_free (&options);
+    
+    return check_error (err);    
+}
index 5c49e41f2c9f70371b7ef69626a52cf9693bd422..6feddc5071be2dc5619b411c2d71bb129bb05c8c 100644 (file)
@@ -28,6 +28,7 @@
 #define KIM_OPTIONS_PRIVATE_H
 
 #include <kim/kim.h>
+#include "k5-ipc_stream.h"
 
 kim_error kim_options_create_empty (kim_options *out_options);
 
@@ -37,4 +38,11 @@ char *kim_options_service_name (kim_options in_options);
 
 kim_time kim_options_start_time (kim_options in_options);
 
+
+kim_error kim_options_write_to_stream (kim_options   in_options,
+                                       k5_ipc_stream io_stream);
+
+kim_error kim_options_create_from_stream (kim_options   *out_options,
+                                          k5_ipc_stream  io_stream);
+
 #endif /* KIM_OPTIONS_PRIVATE_H */
index 6903afb868d7194977eddbcb02b122ac6d7016a1..8cb98f683c9a03d6de97868c7c8d75077861853e 100644 (file)
@@ -556,3 +556,191 @@ void kim_selection_hints_free (kim_selection_hints *io_selection_hints)
     }
 }
 
+#pragma mark - 
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_selection_hints_write_to_stream (kim_selection_hints in_selection_hints,
+                                               k5_ipc_stream       io_stream)
+{
+    kim_error err = KIM_NO_ERROR;
+    
+    if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    if (!err && !io_stream         ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+
+    if (!err) {
+        err = k5_ipc_stream_write_string (io_stream, 
+                                          in_selection_hints->application_identifier);
+    }
+    
+    if (!err) {
+        kim_string explanation = (in_selection_hints->explanation ?
+                                  in_selection_hints->explanation : "");
+        err = k5_ipc_stream_write_string (io_stream, explanation);
+    }
+    
+    if (!err) {
+        err = kim_options_write_to_stream (in_selection_hints->options, io_stream);
+    }
+    
+    if (!err) {
+        kim_string service_identity = (in_selection_hints->service_identity ?
+                                       in_selection_hints->service_identity : "");
+        err = k5_ipc_stream_write_string (io_stream, service_identity);
+    }
+    
+    if (!err) {
+        kim_string client_realm = (in_selection_hints->client_realm ?
+                                   in_selection_hints->client_realm : "");
+        err = k5_ipc_stream_write_string (io_stream, client_realm);
+    }
+    
+    if (!err) {
+        kim_string user = (in_selection_hints->user ?
+                           in_selection_hints->user : "");
+        err = k5_ipc_stream_write_string (io_stream, user);
+    }
+    
+    if (!err) {
+        kim_string service_realm = (in_selection_hints->service_realm ?
+                                    in_selection_hints->service_realm : "");
+        err = k5_ipc_stream_write_string (io_stream, service_realm);
+    }
+    
+    if (!err) {
+        kim_string service = (in_selection_hints->service ?
+                              in_selection_hints->service : "");
+        err = k5_ipc_stream_write_string (io_stream, service);
+    }
+    
+    if (!err) {
+        kim_string server = (in_selection_hints->server ?
+                             in_selection_hints->server : "");
+        err = k5_ipc_stream_write_string (io_stream, server);
+    }
+    
+    return check_error (err);    
+}
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_selection_hints_create_from_stream (kim_selection_hints *out_selection_hints,
+                                                  k5_ipc_stream        io_stream)
+{
+    kim_error err = KIM_NO_ERROR;
+    kim_selection_hints selection_hints = NULL;
+    
+    if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    if (!err && !io_stream          ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+    
+    if (!err) {
+        err = kim_selection_hints_allocate (&selection_hints);
+    }
+    
+    if (!err) {
+        char *application_identifier = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &application_identifier);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->application_identifier, 
+                                   application_identifier);
+        }
+        
+        k5_ipc_stream_free_string (application_identifier);
+    }
+    
+    if (!err) {
+        char *explanation = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &explanation);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->explanation, explanation);
+        }
+        
+        k5_ipc_stream_free_string (explanation);
+    }
+    
+    if (!err) {
+        err = kim_options_create_from_stream (&selection_hints->options, 
+                                              io_stream);
+    }
+    
+    if (!err) {
+        char *service_identity = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &service_identity);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->service_identity, 
+                                   service_identity);
+        }
+        
+        k5_ipc_stream_free_string (service_identity);
+    }
+    
+    if (!err) {
+        char *client_realm = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &client_realm);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->client_realm, 
+                                   client_realm);
+        }
+        
+        k5_ipc_stream_free_string (client_realm);
+    }
+    
+    if (!err) {
+        char *user = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &user);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->user, user);
+        }
+        
+        k5_ipc_stream_free_string (user);
+    }
+    
+    if (!err) {
+        char *service_realm = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &service_realm);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->service_realm, 
+                                   service_realm);
+        }
+        
+        k5_ipc_stream_free_string (service_realm);
+    }
+    
+    if (!err) {
+        char *service = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &service);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->service, service);
+        }
+        
+        k5_ipc_stream_free_string (service);
+    }
+    
+    if (!err) {
+        char *server = NULL;
+        err = k5_ipc_stream_read_string (io_stream, &server);
+        
+        if (!err) {
+            err = kim_string_copy (&selection_hints->server, server);
+        }
+        
+         k5_ipc_stream_free_string (server);
+    }
+    
+    if (!err) {
+        *out_selection_hints = selection_hints;
+        selection_hints = NULL;
+    }
+    
+    kim_selection_hints_free (&selection_hints);
+    
+    return check_error (err);    
+}
+
index 34694893ef657b0e087057856f60706fd6e8fb5f..50e942e5e0f2fb67bc288d5bab38ac9372b0a202 100644 (file)
@@ -28,6 +28,7 @@
 #define KIM_SELECTION_HINTS_PRIVATE_H
 
 #include <kim/kim.h>
+#include "k5-ipc_stream.h"
 
 typedef struct kim_selection_hints_preference_strings {
     kim_string application_identifier;
@@ -53,5 +54,10 @@ kim_error kim_os_selection_hints_remember_identity (kim_selection_hints in_selec
 
 kim_error kim_os_selection_hints_forget_identity (kim_selection_hints in_selection_hints);
 
+kim_error kim_selection_hints_write_to_stream (kim_selection_hints in_selection_hints,
+                                               k5_ipc_stream       io_stream);
+
+kim_error kim_selection_hints_create_from_stream (kim_selection_hints *out_selection_hints,
+                                                  k5_ipc_stream        in_stream);
 
 #endif /* KIM_SELECTION_HINTS_PRIVATE_H */
index 7559dbed949410d76eb053081a82c9f43529bd30..a011ec25139156e7c8272e7f38aa19c8477bd5bc 100644 (file)
@@ -172,7 +172,7 @@ kim_error kim_os_ui_gui_select_identity (kim_ui_context      *in_context,
     }
     
     if (!err) {
-        //err = kim_os_selection_hints_write (in_hints, request);
+        err = kim_selection_hints_write_to_stream (in_hints, request);
     }
     
     if (!err) {