Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / binding / impl / SAMLArtifact.cpp
index 520e83d..49e84d8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2009 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 /**
  * SAMLArtifact.cpp
  * 
- * Base class for SAML 1.x and 2.0 artifacts 
+ * Base class for SAML 1.x and 2.0 artifacts.
  */
 
 #include "internal.h"
 #include "binding/SAMLArtifact.h"
 
 #include <xercesc/util/Base64.hpp>
+#include <xsec/framework/XSECDefs.hpp>
+#include <xmltooling/unicode.h>
 
 using namespace opensaml;
 using namespace xmltooling;
@@ -31,12 +33,12 @@ using namespace std;
 
 namespace opensaml {
     namespace saml1p {
-        SAML_DLLLOCAL PluginManager<SAMLArtifact,const char*>::Factory SAMLArtifactType0001Factory; 
-        SAML_DLLLOCAL PluginManager<SAMLArtifact,const char*>::Factory SAMLArtifactType0002Factory; 
+        SAML_DLLLOCAL PluginManager<SAMLArtifact,string,const char*>::Factory SAMLArtifactType0001Factory; 
+        SAML_DLLLOCAL PluginManager<SAMLArtifact,string,const char*>::Factory SAMLArtifactType0002Factory; 
     };
 
     namespace saml2p {
-        SAML_DLLLOCAL PluginManager<SAMLArtifact,const char*>::Factory SAML2ArtifactType0004Factory; 
+        SAML_DLLLOCAL PluginManager<SAMLArtifact,string,const char*>::Factory SAML2ArtifactType0004Factory; 
     };
 };
 
@@ -56,28 +58,63 @@ void SAML_API opensaml::registerSAMLArtifacts()
 
 const unsigned int SAMLArtifact::TYPECODE_LENGTH = 2;
 
+SAMLArtifact::SAMLArtifact()
+{
+}
+
+SAMLArtifact::~SAMLArtifact()
+{
+}
+
+SAMLArtifact::SAMLArtifact(const SAMLArtifact& src) : m_raw(src.m_raw)
+{
+}
+
 // Basic constructor just decodes the string and saves it off.
 // Subclasses will handle pulling it apart.
 
 SAMLArtifact::SAMLArtifact(const char* s)
 {
-    unsigned int len=0;
+    xsecsize_t len=0;
     XMLByte* decoded=Base64::decode(reinterpret_cast<const XMLByte*>(s),&len);
     if (!decoded)
         throw ArtifactException("Unable to decode base64 artifact.");
     XMLByte* ptr=decoded;
     while (len--)
         m_raw+= *ptr++;
+#ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
     XMLString::release(&decoded);
+#else
+    XMLString::release((char**)&decoded);
+#endif
+}
+
+string SAMLArtifact::getBytes() const
+{
+    return m_raw;
+}
+
+string SAMLArtifact::getTypeCode() const
+{
+    return m_raw.substr(0,TYPECODE_LENGTH);
+}
+
+string SAMLArtifact::getRemainingArtifact() const
+{
+    return m_raw.substr(TYPECODE_LENGTH);
 }
 
 string SAMLArtifact::encode() const
 {
-    unsigned int len=0;
+    xsecsize_t len=0;
     XMLByte* out=Base64::encode(reinterpret_cast<const XMLByte*>(m_raw.data()),m_raw.size(),&len);
     if (out) {
         string ret(reinterpret_cast<char*>(out),len);
+#ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
         XMLString::release(&out);
+#else
+        XMLString::release((char**)&out);
+#endif
         return ret;
     }
     return string();
@@ -86,7 +123,7 @@ string SAMLArtifact::encode() const
 SAMLArtifact* SAMLArtifact::parse(const char* s)
 {
     // Decode and extract the type code first.
-    unsigned int len=0;
+    xsecsize_t len=0;
     XMLByte* decoded=Base64::decode(reinterpret_cast<const XMLByte*>(s),&len);
     if (!decoded)
         throw ArtifactException("Artifact parser unable to decode base64-encoded artifact.");
@@ -94,11 +131,21 @@ SAMLArtifact* SAMLArtifact::parse(const char* s)
     string type;
     type+= decoded[0];
     type+= decoded[1];
+#ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
     XMLString::release(&decoded);
+#else
+    XMLString::release((char**)&decoded);
+#endif
     
     return SAMLConfig::getConfig().SAMLArtifactManager.newPlugin(type,s);
 }
 
+SAMLArtifact* SAMLArtifact::parse(const XMLCh* s)
+{
+    auto_ptr_char temp(s);
+    return parse(temp.get());
+}
+
 string SAMLArtifact::toHex(const string& s)
 {
     static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};