Refactor some code:
authorDerek Atkins <derek@ihtfp.com>
Tue, 18 Nov 2003 19:21:46 +0000 (19:21 +0000)
committerDerek Atkins <derek@ihtfp.com>
Tue, 18 Nov 2003 19:21:46 +0000 (19:21 +0000)
  - a higher-level API to obtain an RPC Handle to the shar

apache-2.0/mod_shib.cpp
shib-target/shib-rpchandle.cpp
shib-target/shib-target.h
shib-target/shibrpc-server.cpp

index 11c6b66..d455ab0 100644 (file)
@@ -360,12 +360,10 @@ extern "C" int shib_check_user(request_rec* r)
     }
     
     // Get an RPC handle and build the SHIRE object.
-    RPCHandle* rpc_handle = (RPCHandle*)rpc_handle_key->getData();
-    if (!rpc_handle)
-    {
-        rpc_handle = new RPCHandle(shib_target_sockname(), SHIBRPC_PROG, SHIBRPC_VERS_1);
-        rpc_handle_key->setData(rpc_handle);
-    }
+    RPCHandle* rpc_handle =
+      RPCHandle::get_handle(rpc_handle_key, shib_target_sockname(),
+                           SHIBRPC_PROG, SHIBRPC_VERS_1);
+
     SHIRE shire(rpc_handle, dc->config, shire_url);
 
     // We're in charge, so check for cookie.
@@ -520,13 +518,10 @@ extern "C" int shib_shire_handler (request_rec* r)
   markupProcessor.insert("requestURL", targeturl);
   
     // Get an RPC handle and build the SHIRE object.
-    RPCHandle* rpc_handle = (RPCHandle*)rpc_handle_key->getData();
-    if (!rpc_handle)
-    {
-        rpc_handle = new RPCHandle(shib_target_sockname(), SHIBRPC_PROG, SHIBRPC_VERS_1);
-        rpc_handle_key->setData(rpc_handle);
-    }
-    SHIRE shire(rpc_handle, config, shire_url);
+  RPCHandle* rpc_handle =
+    RPCHandle::get_handle(rpc_handle_key, shib_target_sockname(),
+                         SHIBRPC_PROG, SHIBRPC_VERS_1);
+  SHIRE shire(rpc_handle, config, shire_url);
 
   // Process SHIRE POST
 
@@ -730,12 +725,9 @@ extern "C" int shib_auth_checker(request_rec *r)
     dc->rm_config.checkIPAddress = (has_tag ? ShibINI::boolean (tag) : false);
 
     // Get an RPC handle and build the RM object.
-    RPCHandle* rpc_handle = (RPCHandle*)rpc_handle_key->getData();
-    if (!rpc_handle)
-    {
-        rpc_handle = new RPCHandle(shib_target_sockname(), SHIBRPC_PROG, SHIBRPC_VERS_1);
-        rpc_handle_key->setData(rpc_handle);
-    }
+    RPCHandle* rpc_handle =
+      RPCHandle::get_handle(rpc_handle_key, shib_target_sockname(),
+                           SHIBRPC_PROG, SHIBRPC_VERS_1);
     RM rm(rpc_handle, dc->rm_config);
 
     vector<SAMLAssertion*> assertions;
index cc6b42f..9843b15 100644 (file)
@@ -210,3 +210,17 @@ void RPCHandle::disconnect(void)
     m_priv->m_clnt = NULL;
   }
 }
+
+RPCHandle* RPCHandle::get_handle(ThreadKey* key,
+                                ShibSockName shar, u_long program,
+                                u_long version)
+{
+  RPCHandle* retval = (RPCHandle*)key->getData();
+  if (!retval)
+  {
+    retval = new RPCHandle(shar, program, version);
+    key->setData(retval);
+  }
+
+  return retval;
+}
index 56ee8d0..e04d053 100644 (file)
@@ -61,6 +61,7 @@
 #ifdef __cplusplus
 # include <saml/saml.h>
 # include <shib/shib.h>
+# include <shib/shib-threads.h>
 #endif
 
 #ifdef WIN32
@@ -209,6 +210,12 @@ namespace shibtarget {
     void       release(void);  /* unlocks the HANDLE */
     void       disconnect(void); /* disconnects */
 
+    // A simple function to get a handle
+    // Note that it does not check that an existing handle matches the request.
+    static RPCHandle* get_handle(shibboleth::ThreadKey* key,
+                                ShibSockName shar, u_long program,
+                                u_long version);
+
   private:
     RPCHandleInternal *m_priv;
   };
@@ -259,6 +266,44 @@ namespace shibtarget {
     RPCErrorPriv* m_priv;
   };
 
+  // The ShibTargetError is used by the high-level SHIRE and RM methods
+  // to notify the handlers of high-level errors.
+
+  class ShibMLPPriv;
+  class SHIBTARGET_EXPORTS ShibMLP {
+  public:
+    ShibMLP();
+    ~ShibMLP();
+
+    void insert (const std::string& key, const std::string& value);
+    void insert (const std::string& key, const char* value) {
+      std::string v = value;
+      insert (key, v);
+    }
+    void insert (const char* key, const std::string& value) {
+      std::string k = key;
+      insert (k, value);
+    }
+    void insert (const char* key, const char* value) {
+      std::string k = key, v = value;
+      insert(k,v);
+    }
+    void insert (RPCError& e);
+
+    void clear () { m_map.clear(); }
+
+    std::string run (std::istream& s) const;
+    std::string run (const std::string& input) const;
+    std::string run (const char* input) const {
+      std::string i = input;
+      return run(i);
+    }
+
+  private:
+    ShibMLPPriv *m_priv;
+    std::map<std::string,std::string> m_map;
+  };
+
   class SHIBTARGET_EXPORTS SHIREConfig
   {
   public:
@@ -268,6 +313,7 @@ namespace shibtarget {
   };
 
   class SHIREPriv;
+  class SHIBTARGET_EXPORTS ShibINI;
   class SHIBTARGET_EXPORTS SHIRE
   {
   public:
@@ -277,6 +323,11 @@ namespace shibtarget {
     RPCError* sessionIsValid(const char* cookie, const char* ip, const char* url);
     RPCError* sessionCreate(const char* post, const char* ip,
                             std::string &cookie);
+
+    //ShibTargetResponse* is_valid(ShibINI& ini, const char* serverName,
+    //                  const char *cookie, const char *target_url);
+    //ShibTargetResponse* create();
+
   private:
     SHIREPriv *m_priv;
   };
@@ -399,41 +450,6 @@ namespace shibtarget {
     void init(std::string& file, bool case_sensitive);
   };
 
-  class ShibMLPPriv;
-  class SHIBTARGET_EXPORTS ShibMLP {
-  public:
-    ShibMLP();
-    ~ShibMLP();
-
-    void insert (const std::string& key, const std::string& value);
-    void insert (const std::string& key, const char* value) {
-      std::string v = value;
-      insert (key, v);
-    }
-    void insert (const char* key, const std::string& value) {
-      std::string k = key;
-      insert (k, value);
-    }
-    void insert (const char* key, const char* value) {
-      std::string k = key, v = value;
-      insert(k,v);
-    }
-    void insert (RPCError& e);
-
-    void clear () { m_map.clear(); }
-
-    std::string run (std::istream& s) const;
-    std::string run (const std::string& input) const;
-    std::string run (const char* input) const {
-      std::string i = input;
-      return run(i);
-    }
-
-  private:
-    ShibMLPPriv *m_priv;
-    std::map<std::string,std::string> m_map;
-  };
-
   class SHIBTARGET_EXPORTS ShibTargetConfig
   {
   public:
index 073474a..ba7d85a 100644 (file)
@@ -93,8 +93,8 @@ void set_rpc_status(ShibRpcError *error, ShibRpcStatus status,
 {
   error->status = status;
   if (status) {
-    error->ShibRpcError_u.e.error = strdup(msg);
-    error->ShibRpcError_u.e.origin = strdup(origin);
+    error->ShibRpcError_u.e.error = strdup(msg ? msg : "");
+    error->ShibRpcError_u.e.origin = strdup(origin ? origin : "");
   }
 }