updated API doc for socket.h
[strongswan.git] / src / charon / sa / mediation_manager.c
index fca53a9..fbdf3ad 100644 (file)
@@ -1,10 +1,3 @@
-/**
- * @file mediation_manager.c
- *
- * @brief Implementation of mediation_manager_t.
- *
- */
-
 /*
  * Copyright (C) 2007 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  * 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 "mediation_manager.h"
 
-#include <pthread.h>
 #include <daemon.h>
+#include <utils/mutex.h>
 #include <utils/linked_list.h>
 #include <processing/jobs/mediation_job.h>
 
@@ -85,7 +80,7 @@ struct private_mediation_manager_t {
         /**
          * Lock for exclusivly accessing the manager.
          */
-        pthread_mutex_t mutex;
+        mutex_t *mutex;
 
         /**
          * Linked list with state entries.
@@ -187,7 +182,7 @@ static void remove_sa(private_mediation_manager_t *this, ike_sa_id_t *ike_sa_id)
        iterator_t *iterator;
        peer_t *peer;
 
-       pthread_mutex_lock(&(this->mutex));
+       this->mutex->lock(this->mutex);
        
        iterator = this->peers->create_iterator(this->peers, TRUE);
        while (iterator->iterate(iterator, (void**)&peer))
@@ -204,7 +199,7 @@ static void remove_sa(private_mediation_manager_t *this, ike_sa_id_t *ike_sa_id)
        }
        iterator->destroy(iterator);
 
-       pthread_mutex_unlock(&(this->mutex));
+       this->mutex->unlock(this->mutex);
 }
 
 /**
@@ -216,7 +211,7 @@ static void update_sa_id(private_mediation_manager_t *this, identification_t *pe
        peer_t *peer;
        bool found = FALSE;
 
-       pthread_mutex_lock(&(this->mutex));
+       this->mutex->lock(this->mutex);
 
        iterator = this->peers->create_iterator(this->peers, TRUE);
        while (iterator->iterate(iterator, (void**)&peer))
@@ -240,15 +235,16 @@ static void update_sa_id(private_mediation_manager_t *this, identification_t *pe
        DBG2(DBG_IKE, "changing registered IKE_SA ID of peer '%D'", peer_id);                   
        peer->ike_sa_id = ike_sa_id ? ike_sa_id->clone(ike_sa_id) : NULL;
        
-       // send callbacks to registered peers
+       /* send callbacks to registered peers */
        identification_t *requester;
        while(peer->requested_by->remove_last(peer->requested_by, (void**)&requester) == SUCCESS)
        {
                job_t *job = (job_t*)mediation_callback_job_create(requester, peer_id);
                charon->processor->queue_job(charon->processor, job);
+               requester->destroy(requester);
        }
        
-       pthread_mutex_unlock(&(this->mutex));
+       this->mutex->unlock(this->mutex);
 }
 
 /**
@@ -260,17 +256,17 @@ static ike_sa_id_t *check(private_mediation_manager_t *this,
        peer_t *peer;
        ike_sa_id_t *ike_sa_id;
 
-       pthread_mutex_lock(&(this->mutex));
+       this->mutex->lock(this->mutex);
 
        if (get_peer_by_id(this, peer_id, &peer) != SUCCESS)
        {
-               pthread_mutex_unlock(&(this->mutex));
+               this->mutex->unlock(this->mutex);
                return NULL;
        }
 
        ike_sa_id = peer->ike_sa_id;
 
-       pthread_mutex_unlock(&(this->mutex));
+       this->mutex->unlock(this->mutex);
 
        return ike_sa_id;
 }
@@ -284,7 +280,7 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
        peer_t *peer;
        ike_sa_id_t *ike_sa_id;
 
-       pthread_mutex_lock(&(this->mutex));
+       this->mutex->lock(this->mutex);
 
        if (get_peer_by_id(this, peer_id, &peer) != SUCCESS)
        {
@@ -295,16 +291,16 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
        
        if (!peer->ike_sa_id)
        {
-               // the peer is not online
+               /* the peer is not online */
                DBG2(DBG_IKE, "requested peer '%D' is offline, registering peer '%D'", peer_id, requester);
                register_peer(peer, requester);
-               pthread_mutex_unlock(&(this->mutex));
+               this->mutex->unlock(this->mutex);
                return NULL;
        }
 
        ike_sa_id = peer->ike_sa_id;
 
-       pthread_mutex_unlock(&(this->mutex));
+       this->mutex->unlock(this->mutex);
 
        return ike_sa_id;
 }
@@ -314,12 +310,12 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
  */
 static void destroy(private_mediation_manager_t *this)
 {
-       pthread_mutex_lock(&(this->mutex));
+       this->mutex->lock(this->mutex);
        
        this->peers->destroy_function(this->peers, (void*)peer_destroy);
        
-       pthread_mutex_unlock(&(this->mutex));   
-       pthread_mutex_destroy(&(this->mutex));
+       this->mutex->unlock(this->mutex);
+       this->mutex->destroy(this->mutex);
        free(this);
 }
 
@@ -337,7 +333,7 @@ mediation_manager_t *mediation_manager_create()
        this->public.check_and_register = (ike_sa_id_t*(*)(mediation_manager_t*,identification_t*,identification_t*))check_and_register;
        
        this->peers = linked_list_create();
-       pthread_mutex_init(&(this->mutex), NULL);
+       this->mutex = mutex_create(MUTEX_DEFAULT);
        
        return (mediation_manager_t*)this;
 }