added -avoid-version to LDFLAGS, plugins are not versioned
[strongswan.git] / src / charon / plugins / stroke / stroke_ca.c
index 8569f49..fab06e6 100644 (file)
  * 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.
  * 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$
  */
 
  */
 
-#define _GNU_SOURCE
-#include <pthread.h>
-
 #include "stroke_ca.h"
 #include "stroke_cred.h"
 
 #include "stroke_ca.h"
 #include "stroke_cred.h"
 
+#include <utils/mutex.h>
 #include <utils/linked_list.h>
 #include <crypto/hashers/hasher.h>
 
 #include <utils/linked_list.h>
 #include <crypto/hashers/hasher.h>
 
@@ -42,7 +38,7 @@ struct private_stroke_ca_t {
        /**
         * read-write lock to lists
         */
        /**
         * read-write lock to lists
         */
-       pthread_rwlock_t lock;
+       rwlock_t *lock;
        
        /**
         * list of starters CA sections and its certificates (ca_section_t)
        
        /**
         * list of starters CA sections and its certificates (ca_section_t)
@@ -136,7 +132,7 @@ typedef struct {
  */
 static void cdp_data_destroy(cdp_data_t *data)
 {
  */
 static void cdp_data_destroy(cdp_data_t *data)
 {
-       pthread_rwlock_unlock(&data->this->lock);
+       data->this->lock->unlock(data->this->lock);
        free(data);
 }
 
        free(data);
 }
 
@@ -236,7 +232,7 @@ static enumerator_t *create_cdp_enumerator(private_stroke_ca_t *this,
        data->type = type;
        data->id = id;
        
        data->type = type;
        data->id = id;
        
-       pthread_rwlock_rdlock(&this->lock);
+       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);
        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);
@@ -278,9 +274,9 @@ static void add(private_stroke_ca_t *this, stroke_msg_t *msg)
                {
                        ca->certuribase = strdup(msg->add_ca.certuribase);
                }
                {
                        ca->certuribase = strdup(msg->add_ca.certuribase);
                }
-               pthread_rwlock_wrlock(&this->lock);
+               this->lock->write_lock(this->lock);
                this->sections->insert_last(this->sections, ca);
                this->sections->insert_last(this->sections, ca);
-               pthread_rwlock_unlock(&this->lock);
+               this->lock->unlock(this->lock);
                DBG1(DBG_CFG, "added ca '%s'", msg->add_ca.name);
        }
 }
                DBG1(DBG_CFG, "added ca '%s'", msg->add_ca.name);
        }
 }
@@ -293,7 +289,7 @@ static void del(private_stroke_ca_t *this, stroke_msg_t *msg)
        enumerator_t *enumerator;
        ca_section_t *ca = NULL;
        
        enumerator_t *enumerator;
        ca_section_t *ca = NULL;
        
-       pthread_rwlock_wrlock(&this->lock);
+       this->lock->write_lock(this->lock);
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, &ca))
        {
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, &ca))
        {
@@ -305,7 +301,7 @@ static void del(private_stroke_ca_t *this, stroke_msg_t *msg)
                ca = NULL;
        }
        enumerator->destroy(enumerator);
                ca = NULL;
        }
        enumerator->destroy(enumerator);
-       pthread_rwlock_unlock(&this->lock);
+       this->lock->unlock(this->lock);
        if (ca == NULL)
        {
                DBG1(DBG_CFG, "no ca named '%s' found\n", msg->del_ca.name);
        if (ca == NULL)
        {
                DBG1(DBG_CFG, "no ca named '%s' found\n", msg->del_ca.name);
@@ -356,7 +352,7 @@ static void check_for_hash_and_url(private_stroke_ca_t *this, certificate_t* cer
                return;
        }
        
                return;
        }
        
-       pthread_rwlock_wrlock(&this->lock);
+       this->lock->write_lock(this->lock);
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, (void**)&section))
        {
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, (void**)&section))
        {
@@ -372,7 +368,7 @@ static void check_for_hash_and_url(private_stroke_ca_t *this, certificate_t* cer
                }
        }
        enumerator->destroy(enumerator);
                }
        }
        enumerator->destroy(enumerator);
-       pthread_rwlock_unlock(&this->lock);
+       this->lock->unlock(this->lock);
        
        hasher->destroy(hasher);
 }
        
        hasher->destroy(hasher);
 }
@@ -386,7 +382,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
        ca_section_t *section;
        enumerator_t *enumerator;
        
        ca_section_t *section;
        enumerator_t *enumerator;
        
-       pthread_rwlock_rdlock(&this->lock);
+       this->lock->read_lock(this->lock);
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, (void**)&section))
        {
        enumerator = this->sections->create_enumerator(this->sections);
        while (enumerator->enumerate(enumerator, (void**)&section))
        {
@@ -400,14 +396,14 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
                        first = FALSE;
                }
                fprintf(out, "\n");
                        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)
                {
 
                /* list authkey and keyid */
                if (public)
                {
-                       fprintf(out, "  authkey:      %D\n",
+                       fprintf(out, "  authkey:      %Y\n",
                                        public->get_id(public, ID_PUBKEY_SHA1));
                                        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);
                }
                                        public->get_id(public, ID_PUBKEY_INFO_SHA1));
                        public->destroy(public);
                }
@@ -419,7 +415,7 @@ static void list(private_stroke_ca_t *this, stroke_msg_t *msg, FILE *out)
                }
        }
        enumerator->destroy(enumerator);
                }
        }
        enumerator->destroy(enumerator);
-       pthread_rwlock_unlock(&this->lock);
+       this->lock->unlock(this->lock);
 }
 
 /**
 }
 
 /**
@@ -428,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);
 static void destroy(private_stroke_ca_t *this)
 {
        this->sections->destroy_function(this->sections, (void*)ca_section_destroy);
-       pthread_rwlock_destroy(&this->lock);
+       this->lock->destroy(this->lock);
        free(this);
 }
 
        free(this);
 }
 
@@ -451,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->public.destroy = (void(*)(stroke_ca_t*))destroy;
        
        this->sections = linked_list_create();
-       pthread_rwlock_init(&this->lock, NULL);
+       this->lock = rwlock_create(RWLOCK_DEFAULT);
        this->cred = cred;
        
        return &this->public;
        this->cred = cred;
        
        return &this->public;