devel/src/PKIFX509/PKIFNameMemoryHelper.cpp

Go to the documentation of this file.
00001 
00009 #include "PKIFNameMemoryHelper.h"
00010 #include "PKIFCommonErrors.h"
00011 #include "ASN1Errors.h"
00012 #include "ToolkitUtils.h"
00013 
00021 PKIFNameMemoryHelper::PKIFNameMemoryHelper():pCACX509V3Name(NULL),pCACX509V3RDN(NULL), pCACX509V3GN(NULL)
00022 {
00023 }
00031 void FreeAsn1OpenType(
00033     ASN1OpenType* asn1ot)
00034 {
00035     if(NULL != asn1ot)
00036     {
00037         if(NULL != asn1ot->data)
00038         {
00039             delete asn1ot->data;
00040         }
00041         delete asn1ot;
00042     }
00043 }
00044 
00045 //for CACX509V3TempRDN, CACX509V3RDNSequence, CACX509V3DistinguishedName
00053 void FreeASN1RTDListOfASN1OpenTypes(
00055     DList* asn1rtdlist)
00056 {
00057     //asn1rtdlist is a ptr to an DList list of encoded CACX509V3RelativeDistinguishedName(s)
00058     if(NULL != asn1rtdlist)
00059     {
00060         if(NULL != asn1rtdlist->head)
00061         {
00062             DListNode* cur = NULL, *tmp = NULL;
00063             cur = asn1rtdlist->head;
00064             while(NULL != cur)
00065             {
00066                 FreeAsn1OpenType((ASN1OpenType*)cur->data);
00067                 tmp = cur->next;
00068                 delete cur;
00069                 cur = tmp;
00070             }
00071         }
00072         delete[] asn1rtdlist;
00073     }
00074 }
00075 //for CACX509V3TempRDN, CACX509V3RDNSequence, CACX509V3DistinguishedName
00083 void FreeCACX509V3RelativeDistinguishedName(
00085     DList* asn1rtdlist)
00086 {
00087     //asn1rtdlist is and DList of CACX509V3AttributeTypeAndValue(s)
00088     if(NULL != asn1rtdlist)
00089     {
00090         DListNode* cur = asn1rtdlist->head, *tmp = NULL;
00091         while(NULL != cur)
00092         {
00093             if(NULL != cur->data)
00094             {
00095                 CACX509V3AttributeTypeAndValue* atadv = (CACX509V3AttributeTypeAndValue*)cur->data;
00096                 if(NULL != atadv->value.data)
00097                 {
00098                     delete atadv->value.data;
00099                 }
00100                 delete atadv;
00101             }
00102             
00103             tmp = cur->next;
00104             delete cur;
00105             cur = tmp;
00106         }
00107         delete[] asn1rtdlist;
00108     }
00109 }
00117 void FreeCACX509V3Name(
00119     CACX509V3Name* pCACX509V3Name)
00120 {
00121     if(NULL != pCACX509V3Name) 
00122     {
00123         if(NULL != pCACX509V3Name->u.rdnSequence)
00124         {
00125             FreeASN1RTDListOfASN1OpenTypes(pCACX509V3Name->u.rdnSequence);
00126         }
00127         delete pCACX509V3Name;      
00128     }
00129 }
00130 
00131 //unused - commented out 8/26/2004
00132 //void FreeCACX509V3TempRDN(CACX509V3TempRDN* pCACX509V3TempRDN)
00133 //{
00134 //  if(NULL != pCACX509V3TempRDN)
00135 //  {
00136 //      DListNode* cur = pCACX509V3TempRDN->head;
00137 //      while(NULL != cur)
00138 //      {
00139 //          ASN1OpenType* tmpasn1ot = NULL;
00140 //          tmpasn1ot = (ASN1OpenType*)cur->data;
00141 //          if(NULL != tmpasn1ot)
00142 //          {
00143 //              if(NULL != tmpasn1ot->data)
00144 //              {
00145 //                  delete tmpasn1ot->data;
00146 //              }
00147 //              delete tmpasn1ot;
00148 //          }
00149 //          cur = cur->next;
00150 //          delete cur->prev;
00151 //      }
00152 //      delete[] pCACX509V3TempRDN;
00153 //  }
00154 //}
00162 void FreeCACX509V3GeneralName(
00164     CACX509V3GeneralName* pCACX509V3GN)
00165 {
00166     if(NULL != pCACX509V3GN)
00167     {
00168         switch(pCACX509V3GN->t)
00169         {
00170             case T_CACX509V3GeneralName_otherName:
00171                 if(NULL != pCACX509V3GN->u.otherName)
00172                 {
00173                     if(NULL != pCACX509V3GN->u.otherName->data)
00174                     {
00175                         delete pCACX509V3GN->u.otherName->data;
00176                     }
00177                     delete pCACX509V3GN->u.otherName;
00178                 }
00179                 break;
00180 
00181             case T_CACX509V3GeneralName_rfc822Name:
00182                 if(NULL != pCACX509V3GN->u.rfc822Name)
00183                 {
00184                     delete pCACX509V3GN->u.rfc822Name;
00185                 }
00186                 break;
00187 
00188             case T_CACX509V3GeneralName_dNSName:
00189                 if(NULL != pCACX509V3GN->u.dNSName)
00190                 {
00191                     delete pCACX509V3GN->u.dNSName;
00192                 }
00193                 break;
00194 
00195             case T_CACX509V3GeneralName_x400Address:
00196                 if(NULL != pCACX509V3GN->u.x400Address)
00197                 {
00198                     if(NULL != pCACX509V3GN->u.otherName->data)
00199                     {
00200                         delete pCACX509V3GN->u.x400Address->data;
00201                     }
00202                     delete pCACX509V3GN->u.x400Address;
00203                 }
00204                 break;
00205 
00206             case T_CACX509V3GeneralName_directoryName:
00207                 if(NULL != pCACX509V3GN->u.directoryName)
00208                 {
00209                     if(NULL != pCACX509V3GN->u.directoryName->u.rdnSequence)
00210                     {
00211                         FreeASN1RTDListOfASN1OpenTypes(pCACX509V3GN->u.directoryName->u.rdnSequence);
00212                         //FreeCACX509V3TempRDN(pCACX509V3GN->u.directoryName->u.tempRDN);
00213                     }
00214                     delete pCACX509V3GN->u.directoryName;
00215                 }
00216                 break;
00217 
00218             case T_CACX509V3GeneralName_ediPartyName:
00219                 //XXX-DEFER implement me
00220                 break;
00221 
00222             case T_CACX509V3GeneralName_uniformResourceIdentifier:
00223                 if(NULL != pCACX509V3GN->u.uniformResourceIdentifier)
00224                 {
00225                     delete pCACX509V3GN->u.uniformResourceIdentifier;
00226                 }
00227                 break;
00228 
00229             case T_CACX509V3GeneralName_iPAddress:
00230                 if(NULL != pCACX509V3GN->u.iPAddress)
00231                 {
00232                     if(NULL != pCACX509V3GN->u.iPAddress->data)
00233                     {
00234                         delete pCACX509V3GN->u.iPAddress->data;
00235                     }
00236                     delete pCACX509V3GN->u.iPAddress;
00237                 }
00238                 break;
00239 
00240             case T_CACX509V3GeneralName_registeredID:
00241                 if(NULL != pCACX509V3GN->u.registeredID)
00242                 {
00243                     delete pCACX509V3GN->u.registeredID;
00244                 }
00245                 break;
00246 
00247             default:
00248                 {
00249                     //log this... leak unavoidable
00250                     LOG_STRING_ERROR("Failed to free contents of CACX509V3GeneralName, unrecognized name type.", TOOLKIT_UTILS, COMMON_INVALID_INPUT, NULL);
00251                 }
00252         }
00253     }
00254 
00255     delete pCACX509V3GN;
00256 }
00264 PKIFNameMemoryHelper::~PKIFNameMemoryHelper()
00265 {
00266     // clean up memory
00267     if(pCACX509V3Name)
00268     {
00269         FreeCACX509V3Name(pCACX509V3Name);
00270     }
00271 
00272     if(pCACX509V3RDN)
00273     {   
00274         FreeCACX509V3RelativeDistinguishedName(pCACX509V3RDN);
00275     }
00276 
00277     if(pCACX509V3GN)
00278     {
00279         FreeCACX509V3GeneralName(pCACX509V3GN);
00280     }
00281 }
00282 

Generated on Mon Nov 15 11:15:55 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6