]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
llist: add Curl_llist_append()
authorStefan Eissing <stefan@eissing.org>
Wed, 10 Apr 2024 09:51:08 +0000 (11:51 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 11 Apr 2024 07:00:51 +0000 (09:00 +0200)
- use for better readability in all places where the "insert_next"
  actually performs an append to the list
- add some tests in unit1300

Closes #13336

lib/altsvc.c
lib/conncache.c
lib/ftplistparser.c
lib/hash.c
lib/headers.c
lib/hsts.c
lib/llist.c
lib/llist.h
lib/multi.c
lib/multihandle.h
tests/unit/unit1300.c

index c12d7bda199d2a435a9ebddbf93456391d95a9f0..4fc4fe60f0b54bde3d2b07236cc9055666b8ddb6 100644 (file)
@@ -191,7 +191,7 @@ static CURLcode altsvc_add(struct altsvcinfo *asi, char *line)
       as->expires = expires;
       as->prio = prio;
       as->persist = persist ? 1 : 0;
-      Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
+      Curl_llist_append(&asi->list, as, &as->node);
     }
   }
 
@@ -643,7 +643,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
                account. [See RFC 7838 section 3.1] */
             as->expires = maxage + time(NULL);
             as->persist = persist;
-            Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
+            Curl_llist_append(&asi->list, as, &as->node);
             infof(data, "Added alt-svc: %s:%d over %s", dsthost, dstport,
                   Curl_alpnid2str(dstalpnid));
           }
index 0d2609085847d443d3003217bd905e3dd6827135..11dd8e8ca9dd8d2435b2fb68b455985a1af4b8ee 100644 (file)
@@ -68,8 +68,7 @@ static void bundle_destroy(struct connectbundle *bundle)
 static void bundle_add_conn(struct connectbundle *bundle,
                             struct connectdata *conn)
 {
-  Curl_llist_insert_next(&bundle->conn_list, bundle->conn_list.tail, conn,
-                         &conn->bundle_node);
+  Curl_llist_append(&bundle->conn_list, conn, &conn->bundle_node);
   conn->bundle = bundle;
   bundle->num_connections++;
 }
index 82f1ea00d3c601342d083059204f9c03c9942804..448f3a43aba0dc828555a9ee3d177b365e88c43e 100644 (file)
@@ -349,7 +349,7 @@ static CURLcode ftp_pl_insert_finfo(struct Curl_easy *data,
   Curl_set_in_callback(data, false);
 
   if(add) {
-    Curl_llist_insert_next(llist, llist->tail, finfo, &infop->list);
+    Curl_llist_append(llist, finfo, &infop->list);
   }
   else {
     Curl_fileinfo_cleanup(infop);
index 30f28e2352a93de579aabd9f6e9e74ef0f9106e4..772c03b5ca081d51b1b86d5c6fbe60776091606d 100644 (file)
@@ -132,7 +132,7 @@ Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
 
   he = mk_hash_element(key, key_len, p);
   if(he) {
-    Curl_llist_insert_next(l, l->tail, he, &he->list);
+    Curl_llist_append(l, he, &he->list);
     ++h->size;
     return p; /* return the new entry */
   }
index ea8a7aa98db514878e0e9f5477dbd2ed05de2a0a..ef947492de4abf4420985a8787d63b6cb92493d5 100644 (file)
@@ -264,8 +264,7 @@ static CURLcode unfold_value(struct Curl_easy *data, const char *value,
   newhs->value[olen + vlen] = 0; /* null-terminate at newline */
 
   /* insert this node into the list of headers */
-  Curl_llist_insert_next(&data->state.httphdrs, data->state.httphdrs.tail,
-                         newhs, &newhs->node);
+  Curl_llist_append(&data->state.httphdrs, newhs, &newhs->node);
   data->state.prevhead = newhs;
   return CURLE_OK;
 }
@@ -328,8 +327,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header,
     hs->request = data->state.requests;
 
     /* insert this node into the list of headers */
-    Curl_llist_insert_next(&data->state.httphdrs, data->state.httphdrs.tail,
-                           hs, &hs->node);
+    Curl_llist_append(&data->state.httphdrs, hs, &hs->node);
     data->state.prevhead = hs;
   }
   else
index 607755e6ba48ba6177464c9c399f28f8c9cb51e6..d006e688693d29f485ad049f738d2c6291505952 100644 (file)
@@ -140,7 +140,7 @@ static CURLcode hsts_create(struct hsts *h,
     sts->host = duphost;
     sts->expires = expires;
     sts->includeSubDomains = subdomains;
-    Curl_llist_insert_next(&h->list, h->list.tail, sts, &sts->node);
+    Curl_llist_append(&h->list, sts, &sts->node);
   }
   return CURLE_OK;
 }
index 5b6b0336da268ac2f1453bf0d4560ec1eb017a21..716f0cd57624ff00ab793306bd493a6d9df7d3f8 100644 (file)
@@ -88,6 +88,22 @@ Curl_llist_insert_next(struct Curl_llist *list, struct Curl_llist_element *e,
   ++list->size;
 }
 
+/*
+ * Curl_llist_append()
+ *
+ * Adds a new list element to the end of the list.
+ *
+ * The 'ne' argument should be a pointer into the object to store.
+ *
+ * @unittest: 1300
+ */
+void
+Curl_llist_append(struct Curl_llist *list, const void *p,
+                  struct Curl_llist_element *ne)
+{
+  Curl_llist_insert_next(list, list->tail, p, ne);
+}
+
 /*
  * @unittest: 1300
  */
index 320580e33cce225de8838d34718363fd5b51d30c..d75582fa970ef751cee869d3de04398bb548cc6a 100644 (file)
@@ -45,6 +45,8 @@ struct Curl_llist {
 void Curl_llist_init(struct Curl_llist *, Curl_llist_dtor);
 void Curl_llist_insert_next(struct Curl_llist *, struct Curl_llist_element *,
                             const void *, struct Curl_llist_element *node);
+void Curl_llist_append(struct Curl_llist *,
+                       const void *, struct Curl_llist_element *node);
 void Curl_llist_remove(struct Curl_llist *, struct Curl_llist_element *,
                        void *);
 size_t Curl_llist_count(struct Curl_llist *);
index ee2b9cbde178b497c742c368cd9bc178cefa59bb..55c6dfc8b9e4936b7d08cf26f26310ee539bba03 100644 (file)
@@ -374,8 +374,7 @@ static void sh_init(struct Curl_hash *hash, int hashsize)
  */
 static void multi_addmsg(struct Curl_multi *multi, struct Curl_message *msg)
 {
-  Curl_llist_insert_next(&multi->msglist, multi->msglist.tail, msg,
-                         &msg->list);
+  Curl_llist_append(&multi->msglist, msg, &msg->list);
 }
 
 struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
@@ -1002,8 +1001,7 @@ void Curl_attach_connection(struct Curl_easy *data,
   DEBUGASSERT(!data->conn);
   DEBUGASSERT(conn);
   data->conn = conn;
-  Curl_llist_insert_next(&conn->easyq, conn->easyq.tail, data,
-                         &data->conn_queue);
+  Curl_llist_append(&conn->easyq, data, &data->conn_queue);
   if(conn->handler && conn->handler->attach)
     conn->handler->attach(data, conn);
   Curl_conn_ev_data_attach(conn, data);
@@ -1996,8 +1994,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
         multistate(data, MSTATE_PENDING);
 
         /* add this handle to the list of connect-pending handles */
-        Curl_llist_insert_next(&multi->pending, multi->pending.tail, data,
-                               &data->connect_queue);
+        Curl_llist_append(&multi->pending, data, &data->connect_queue);
         /* unlink from the main list */
         unlink_easy(multi, data);
         result = CURLE_OK;
@@ -2720,8 +2717,7 @@ statemachine_end:
       multistate(data, MSTATE_MSGSENT);
 
       /* add this handle to the list of msgsent handles */
-      Curl_llist_insert_next(&multi->msgsent, multi->msgsent.tail, data,
-                             &data->connect_queue);
+      Curl_llist_append(&multi->msgsent, data, &data->connect_queue);
       /* unlink from the main list */
       unlink_easy(multi, data);
       return CURLM_OK;
index 3156c83ad347fe92e8e2c0c79a93cf2bdbd0167d..122f8f6a7cb8122d54e5b8adf4a3bac0e704e478 100644 (file)
@@ -179,7 +179,7 @@ struct Curl_multi {
   BIT(dead); /* a callback returned error, everything needs to crash and
                 burn */
   BIT(xfer_buf_borrowed);      /* xfer_buf is currently being borrowed */
-  BIT(xfer_ulbuf_borrowed);      /* xfer_buf is currently being borrowed */
+  BIT(xfer_ulbuf_borrowed);    /* xfer_ulbuf is currently being borrowed */
 #ifdef DEBUGBUILD
   BIT(warned);                 /* true after user warned of DEBUGBUILD */
 #endif
index 66fb5d02d56e633c16b92e4349d9cbe6fea7c65f..d94cfe17877090a1f86a1dad7d8614ae0f3587fe 100644 (file)
@@ -217,6 +217,54 @@ UNITTEST_START
   fail_unless(llist.tail == NULL,
               "llist tail is not NULL while the llist is empty");
 
+  /**
+   * testing Curl_llist_append
+   * case 1:
+   * list is empty
+   * @assumptions:
+   * 1: the element next to head should be our newly created element
+   * 2: the list tail should different from newly created element
+   */
+  Curl_llist_append(&llist, &unusedData_case1, &case1_list);
+  fail_unless(Curl_llist_count(&llist) == 1,
+              "List size should be 1 after appending a new element");
+  /* test that the list head data holds my unusedData */
+  fail_unless(llist.head->ptr == &unusedData_case1,
+              "head ptr should be first entry");
+  /* same goes for the list tail */
+  fail_unless(llist.tail == llist.head,
+              "tail and head should be the same");
+
+  /**
+   * testing Curl_llist_append
+   * case 2:
+   * list is not empty
+   * @assumptions:
+   * 1: the list head-next should be the newly created element
+   * 2: the list tail should be the newly created element
+   */
+  Curl_llist_append(&llist, &unusedData_case2, &case2_list);
+  fail_unless(llist.head->next->ptr == &unusedData_case2,
+              "the node next to head is not getting set correctly");
+  fail_unless(llist.tail->ptr == &unusedData_case2,
+              "the list tail is not getting set correctly");
+
+  /**
+   * testing Curl_llist_append
+   * case 3:
+   * list is has 2 members
+   * @assumptions:
+   * 1: the list head-next should remain the same
+   * 2: the list tail should be the newly created element
+   */
+  Curl_llist_append(&llist, &unusedData_case3, &case3_list);
+  fail_unless(llist.head->next->ptr == &unusedData_case2,
+              "the node next to head did not stay the same");
+  fail_unless(llist.tail->ptr == &unusedData_case3,
+              "the list tail is not getting set correctly");
+
+
+
   Curl_llist_destroy(&llist, NULL);
   Curl_llist_destroy(&llist_destination, NULL);
 }