]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Convert struct advertisement_state_machine to use struct dl_list
authorJouni Malinen <j@w1.fi>
Sat, 19 Dec 2009 12:46:52 +0000 (14:46 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 19 Dec 2009 12:46:52 +0000 (14:46 +0200)
src/wps/wps_upnp.c
src/wps/wps_upnp_i.h
src/wps/wps_upnp_ssdp.c

index 67722a23a3489cd1c08c21d4c7c44231aa7e23cc..60c4c0d797a006be2760b406457b1a624c89d34f 100644 (file)
@@ -907,6 +907,15 @@ fail:
 }
 
 
+static void upnp_wps_free_msearchreply(struct dl_list *head)
+{
+       struct advertisement_state_machine *a, *tmp;
+       dl_list_for_each_safe(a, tmp, head, struct advertisement_state_machine,
+                             list)
+               msearchreply_state_machine_stop(a);
+}
+
+
 static void upnp_wps_free_subscriptions(struct dl_list *head)
 {
        struct subscription *s, *tmp;
@@ -928,8 +937,7 @@ void upnp_wps_device_stop(struct upnp_wps_device_sm *sm)
 
        wpa_printf(MSG_DEBUG, "WPS UPnP: Stop device");
        web_listener_stop(sm);
-       while (sm->msearch_replies)
-               msearchreply_state_machine_stop(sm->msearch_replies);
+       upnp_wps_free_msearchreply(&sm->msearch_replies);
        upnp_wps_free_subscriptions(&sm->subscriptions);
 
        advertisement_state_machine_stop(sm, 1);
@@ -1058,6 +1066,7 @@ upnp_wps_device_init(struct upnp_wps_device_ctx *ctx, struct wps_context *wps,
        sm->ctx = ctx;
        sm->wps = wps;
        sm->priv = priv;
+       dl_list_init(&sm->msearch_replies);
        dl_list_init(&sm->subscriptions);
 
        return sm;
index 213f8a13e365010a319b070e43d1908169b65183..cdabb6a1d3034fa25eb4b12cd2a295d762e7429f 100644 (file)
@@ -31,7 +31,6 @@
 #define MULTICAST_MAX_READ 1600 /* max bytes we'll read for UPD request */
 
 
-struct subscription;
 struct upnp_wps_device_sm;
 struct wps_registrar;
 
@@ -50,9 +49,7 @@ enum advertisement_type_enum {
  * separate packets and spread out in time to avoid congestion.
  */
 struct advertisement_state_machine {
-       /* double-linked list */
-       struct advertisement_state_machine *next;
-       struct advertisement_state_machine *prev;
+       struct dl_list list;
        struct upnp_wps_device_sm *sm; /* parent */
        enum advertisement_type_enum type;
        int state;
@@ -127,8 +124,7 @@ struct upnp_wps_device_sm {
        int ssdp_sd_registered; /* nonzero if we must unregister */
        unsigned advertise_count; /* how many advertisements done */
        struct advertisement_state_machine advertisement;
-       struct advertisement_state_machine *msearch_replies;
-       int n_msearch_replies; /* no. of pending M-SEARCH replies */
+       struct dl_list msearch_replies;
        int web_port; /* our port that others get xml files from */
        struct http_server *web_srv;
        /* Note: subscriptions are kept in expiry order */
index d48bfdb2f4c3895e65e0b908cc64070da1b733be..9b324885dcdcd270ffec28f893589109fac05daf 100644 (file)
@@ -385,18 +385,9 @@ static void msearchreply_state_machine_handler(void *eloop_data,
  */
 void msearchreply_state_machine_stop(struct advertisement_state_machine *a)
 {
-       struct upnp_wps_device_sm *sm = a->sm;
        wpa_printf(MSG_DEBUG, "WPS UPnP: M-SEARCH stop");
-       if (a->next == a) {
-               sm->msearch_replies = NULL;
-       } else {
-               if (sm->msearch_replies == a)
-                       sm->msearch_replies = a->next;
-               a->next->prev = a->prev;
-               a->prev->next = a->next;
-       }
+       dl_list_del(&a->list);
        os_free(a);
-       sm->n_msearch_replies--;
 }
 
 
@@ -476,10 +467,12 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm,
        struct advertisement_state_machine *a;
        int next_timeout_sec;
        int next_timeout_msec;
+       int replies;
 
+       replies = dl_list_len(&sm->msearch_replies);
        wpa_printf(MSG_DEBUG, "WPS UPnP: M-SEARCH reply start (%d "
-                  "outstanding)", sm->n_msearch_replies);
-       if (sm->n_msearch_replies >= MAX_MSEARCH) {
+                  "outstanding)", replies);
+       if (replies >= MAX_MSEARCH) {
                wpa_printf(MSG_INFO, "WPS UPnP: Too many outstanding "
                           "M-SEARCH replies");
                return;
@@ -503,15 +496,7 @@ static void msearchreply_state_machine_start(struct upnp_wps_device_sm *sm,
                goto fail;
        }
        /* Remember for future cleanup */
-       if (sm->msearch_replies) {
-               a->next = sm->msearch_replies;
-               a->prev = a->next->prev;
-               a->prev->next = a;
-               a->next->prev = a;
-       } else {
-               sm->msearch_replies = a->next = a->prev = a;
-       }
-       sm->n_msearch_replies++;
+       dl_list_add(&sm->msearch_replies, &a->list);
        return;
 
 fail: