added -avoid-version to LDFLAGS, plugins are not versioned
[strongswan.git] / src / charon / plugins / stroke / stroke_ca.c
index 11de241..fab06e6 100644 (file)
@@ -12,8 +12,6 @@
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
- *
- * $Id$
  */
 
 #include "stroke_ca.h"
@@ -38,9 +36,9 @@ struct private_stroke_ca_t {
        stroke_ca_t public;
        
        /**
-        * mutex to lock access to list
+        * read-write lock to lists
         */
-       mutex_t *mutex;
+       rwlock_t *lock;
        
        /**
         * list of starters CA sections and its certificates (ca_section_t)
@@ -134,7 +132,7 @@ typedef struct {
  */
 static void cdp_data_destroy(cdp_data_t *data)
 {
-       data->this->mutex->unlock(data->this->mutex);
+       data->this->lock->unlock(data->this->lock);
        free(data);
 }
 
@@ -234,7 +232,7 @@ static enumerator_t *create_cdp_enumerator(private_stroke_ca_t *this,
        data->type = type;
        data->id = id;
        
-       this->mutex->lock(this->mutex);
+       this->lock->read_lock(this->lock);
        return enumerator_create_nested(this->sections->create_enumerator(this->sections),
                        (type == CERT_X509) ? (void*)create_inner_cdp_hashandurl : (void*)create_inner_cdp,
                        data, (void*)cdp_data_destroy);
@@ -276,9 +274,9 @@ static void add(private_stroke_ca_t *this, stroke_msg_t *msg)
                {
                        ca->certuribase = strdup(msg->add_ca.certuribase);
                }
-               this->mutex->lock(this->mutex);
+               this->lock->write_lock(this->lock);
                this->sections->insert_last(this->sections, ca);
-               this->mutex->unlock(this->mutex);
+               this->lock->unlock(this->lock);
                DBG1(DBG_CFG, "added ca '%s'", msg->add_ca.name);
        }
 }
@@ -291,7 +289,7 @@ static void del(private_stroke_ca_t *this, stroke_msg_t *msg)
        enumerator_t *enumerator;
        ca_section_t *ca = NULL;
        
-       this->mutex->lock(this->mutex);
+       this->lock->write_lock(this->lock);
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, &ca))
        {
@@ -303,7 +301,7 @@ static void del(private_stroke_ca_t *this, stroke_msg_t *msg)
                ca = NULL;
        }
        enumerator->destroy(enumerator);
-       this->mutex->unlock(this->mutex);
+       this->lock->unlock(this->lock);
        if (ca == NULL)
        {
                DBG1(DBG_CFG, "no ca named '%s' found\n", msg->del_ca.name);
@@ -354,7 +352,7 @@ static void check_for_hash_and_url(private_stroke_ca_t *this, certificate_t* cer
                return;
        }
        
-       this->mutex->lock(this->mutex);
+       this->lock->write_lock(this->lock);
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, (void**)&section))
        {
@@ -370,7 +368,7 @@ static void check_for_hash_and_url(private_stroke_ca_t *this, certificate_t* cer
                }
        }
        enumerator->destroy(enumerator);
-       this->mutex->unlock(this->mutex);
+       this->lock->unlock(this->lock);
        
        hasher->destroy(hasher);
 }
@@ -384,7 +382,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
        ca_section_t *section;
        enumerator_t *enumerator;
        
-       this->mutex->lock(this->mutex);
+       this->lock->read_lock(this->lock);
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, (void**)&section))
        {
@@ -398,23 +396,26 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
                        first = FALSE;
                }
                fprintf(out, "\n");
-               fprintf(out, "  authname:    \"%D\"\n", cert->get_subject(cert));
+               fprintf(out, "  authname:    \"%Y\"\n", cert->get_subject(cert));
 
                /* list authkey and keyid */
                if (public)
                {
-                       fprintf(out, "  authkey:      %D\n",
+                       fprintf(out, "  authkey:      %Y\n",
                                        public->get_id(public, ID_PUBKEY_SHA1));
-                       fprintf(out, "  keyid:        %D\n",
+                       fprintf(out, "  keyid:        %Y\n",
                                        public->get_id(public, ID_PUBKEY_INFO_SHA1));
                        public->destroy(public);
                }
                list_uris(section->crl, "  crluris:     ", out);
                list_uris(section->ocsp, "  ocspuris:    ", out);
-               fprintf(out, "  certuribase: '%s'\n", section->certuribase);
+               if (section->certuribase)
+               {
+                       fprintf(out, "  certuribase: '%s'\n", section->certuribase);
+               }
        }
        enumerator->destroy(enumerator);
-       this->mutex->unlock(this->mutex);
+       this->lock->unlock(this->lock);
 }
 
 /**
@@ -423,7 +424,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
 static void destroy(private_stroke_ca_t *this)
 {
        this->sections->destroy_function(this->sections, (void*)ca_section_destroy);
-       this->mutex->destroy(this->mutex);
+       this->lock->destroy(this->lock);
        free(this);
 }
 
@@ -446,7 +447,7 @@ stroke_ca_t *stroke_ca_create(stroke_cred_t *cred)
        this->public.destroy = (void(*)(stroke_ca_t*))destroy;
        
        this->sections = linked_list_create();
-       this->mutex = mutex_create(MUTEX_RECURSIVE);
+       this->lock = rwlock_create(RWLOCK_DEFAULT);
        this->cred = cred;
        
        return &this->public;