| 1 | /********************************************************************************************************* |
| 2 | * Software License Agreement (BSD License) * |
| 3 | * Author: Sebastien Decugis <[email protected]> * |
| 4 | * * |
| 5 | * Copyright (c) 2013, WIDE Project and NICT * |
| 6 | * All rights reserved. * |
| 7 | * * |
| 8 | * Redistribution and use of this software in source and binary forms, with or without modification, are * |
| 9 | * permitted provided that the following conditions are met: * |
| 10 | * * |
| 11 | * * Redistributions of source code must retain the above * |
| 12 | * copyright notice, this list of conditions and the * |
| 13 | * following disclaimer. * |
| 14 | * * |
| 15 | * * Redistributions in binary form must reproduce the above * |
| 16 | * copyright notice, this list of conditions and the * |
| 17 | * following disclaimer in the documentation and/or other * |
| 18 | * materials provided with the distribution. * |
| 19 | * * |
| 20 | * * Neither the name of the WIDE Project or NICT nor the * |
| 21 | * names of its contributors may be used to endorse or * |
| 22 | * promote products derived from this software without * |
| 23 | * specific prior written permission of WIDE Project and * |
| 24 | * NICT. * |
| 25 | * * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
| 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
| 28 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
| 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
| 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
| 32 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
| 33 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
| 34 | *********************************************************************************************************/ |
| 35 | |
| 36 | #include "fdproto-internal.h"cxx . . $ `<file>/lib/freeDiameter-1.2.1/libfdproto/fdproto-internal.h`/ |
| 37 | |
| 38 | /* Initialize a list element */ |
| 39 | void fd_list_initcxx . . $ fd_list_init(a68d7934af8ecc50). ( struct fd_listcxx . . $ fd_list# * list, void * obj ) |
| 40 | { |
| 41 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(list, 0, sizeof(struct fd_listcxx . . $ fd_list#)); |
| 42 | list->nextcxx . . $ fd_list#next. = list; |
| 43 | list->prevcxx . . $ fd_list#prev. = list; |
| 44 | list->headcxx . . $ fd_list#head. = list; |
| 45 | list->ocxx . . $ fd_list#o. = obj; |
| 46 | } |
| 47 | |
| 48 | #define CHECK_SINGLEcxx . . $ `lib/freeDiameter-1.2.1/libfdproto/lists.c:48:9`!( li ) { \ |
| 49 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!( ((struct fd_list *)(li))->next == (li) ); \ |
| 50 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!( ((struct fd_list *)(li))->prev == (li) ); \ |
| 51 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!( ((struct fd_list *)(li))->head == (li) ); \ |
| 52 | } |
| 53 | |
| 54 | /* insert after a reference, checks done */ |
| 55 | static void list_insert_aftercxx . . $ list_insert_after(3eafa2e8bb09a989).( struct fd_listcxx . . $ fd_list# * ref, struct fd_listcxx . . $ fd_list# * item ) |
| 56 | { |
| 57 | item->prevcxx . . $ fd_list#prev. = ref; |
| 58 | item->nextcxx . . $ fd_list#next. = ref->nextcxx . . $ fd_list#next.; |
| 59 | item->headcxx . . $ fd_list#head. = ref->headcxx . . $ fd_list#head.; |
| 60 | ref->nextcxx . . $ fd_list#next.->prevcxx . . $ fd_list#prev. = item; |
| 61 | ref->nextcxx . . $ fd_list#next. = item; |
| 62 | } |
| 63 | |
| 64 | /* insert after a reference */ |
| 65 | void fd_list_insert_aftercxx . . $ fd_list_insert_after(3eafa2e8bb09a989). ( struct fd_listcxx . . $ fd_list# * ref, struct fd_listcxx . . $ fd_list# * item ) |
| 66 | { |
| 67 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 68 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(ref != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 69 | CHECK_SINGLEcxx . . $ `lib/freeDiameter-1.2.1/libfdproto/lists.c:48:9`! ( item ); |
| 70 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(ref->head != item); |
| 71 | list_insert_aftercxx . . $ list_insert_after(3eafa2e8bb09a989).(ref, item); |
| 72 | } |
| 73 | |
| 74 | /* Move all elements of list senti at the end of list ref */ |
| 75 | void fd_list_move_endcxx . . $ fd_list_move_end(3eafa2e8bb09a989).(struct fd_listcxx . . $ fd_list# * ref, struct fd_listcxx . . $ fd_list# * senti) |
| 76 | { |
| 77 | struct fd_listcxx . . $ fd_list# * li; |
| 78 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(ref->head == ref); |
| 79 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(senti->head == senti); |
| 80 | |
| 81 | if (senti->nextcxx . . $ fd_list#next. == senti) |
| 82 | return; |
| 83 | |
| 84 | for (li = senti->nextcxx . . $ fd_list#next.; li != senti; li = li->nextcxx . . $ fd_list#next.) |
| 85 | li->headcxx . . $ fd_list#head. = ref; |
| 86 | |
| 87 | senti->nextcxx . . $ fd_list#next.->prevcxx . . $ fd_list#prev. = ref->prevcxx . . $ fd_list#prev.; |
| 88 | ref->prevcxx . . $ fd_list#prev.->nextcxx . . $ fd_list#next. = senti->nextcxx . . $ fd_list#next.; |
| 89 | senti->prevcxx . . $ fd_list#prev.->nextcxx . . $ fd_list#next. = ref; |
| 90 | ref->prevcxx . . $ fd_list#prev. = senti->prevcxx . . $ fd_list#prev.; |
| 91 | senti->prevcxx . . $ fd_list#prev. = senti; |
| 92 | senti->nextcxx . . $ fd_list#next. = senti; |
| 93 | } |
| 94 | |
| 95 | /* insert before a reference, checks done */ |
| 96 | static void list_insert_beforecxx . . $ list_insert_before(3eafa2e8bb09a989). ( struct fd_listcxx . . $ fd_list# * ref, struct fd_listcxx . . $ fd_list# * item ) |
| 97 | { |
| 98 | item->prevcxx . . $ fd_list#prev. = ref->prevcxx . . $ fd_list#prev.; |
| 99 | item->nextcxx . . $ fd_list#next. = ref; |
| 100 | item->headcxx . . $ fd_list#head. = ref->headcxx . . $ fd_list#head.; |
| 101 | ref->prevcxx . . $ fd_list#prev.->nextcxx . . $ fd_list#next. = item; |
| 102 | ref->prevcxx . . $ fd_list#prev. = item; |
| 103 | } |
| 104 | |
| 105 | /* insert before a reference */ |
| 106 | void fd_list_insert_beforecxx . . $ fd_list_insert_before(3eafa2e8bb09a989). ( struct fd_listcxx . . $ fd_list# * ref, struct fd_listcxx . . $ fd_list# * item ) |
| 107 | { |
| 108 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 109 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(ref != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 110 | CHECK_SINGLEcxx . . $ `lib/freeDiameter-1.2.1/libfdproto/lists.c:48:9`! ( item ); |
| 111 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(ref->head != item); |
| 112 | list_insert_beforecxx . . $ list_insert_before(3eafa2e8bb09a989).(ref, item); |
| 113 | } |
| 114 | |
| 115 | /* Insert an item in an ordered list -- ordering function provided. If duplicate object found, it is returned in ref_duplicate */ |
| 116 | int fd_list_insert_orderedcxx . . $ fd_list_insert_ordered(4cab3f83d2d2f80a).( struct fd_listcxx . . $ fd_list# * head, struct fd_listcxx . . $ fd_list# * item, int (*cmp_fct)(void *, void *), void ** ref_duplicate) |
| 117 | { |
| 118 | struct fd_listcxx . . $ fd_list# * ptr = head; |
| 119 | int cmp; |
| 120 | |
| 121 | /* Some debug sanity checks */ |
| 122 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(head != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 123 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 124 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(cmp_fct != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 125 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(head->head == head); |
| 126 | CHECK_SINGLEcxx . . $ `lib/freeDiameter-1.2.1/libfdproto/lists.c:48:9`! ( item ); |
| 127 | |
| 128 | /* loop in the list */ |
| 129 | while (ptr->nextcxx . . $ fd_list#next. != head) |
| 130 | { |
| 131 | /* Compare the object to insert with the next object in list */ |
| 132 | cmp = cmp_fct( item->ocxx . . $ fd_list#o., ptr->nextcxx . . $ fd_list#next.->ocxx . . $ fd_list#o. ); |
| 133 | if (!cmp) { |
| 134 | /* An element with the same key already exists */ |
| 135 | if (ref_duplicate != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 136 | *ref_duplicate = ptr->nextcxx . . $ fd_list#next.->ocxx . . $ fd_list#o.; |
| 137 | return EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!; |
| 138 | } |
| 139 | |
| 140 | if (cmp < 0) |
| 141 | break; /* We must insert the element here */ |
| 142 | |
| 143 | ptr = ptr->nextcxx . . $ fd_list#next.; |
| 144 | } |
| 145 | |
| 146 | /* Now insert the element between ptr and ptr->next */ |
| 147 | list_insert_aftercxx . . $ list_insert_after(3eafa2e8bb09a989).( ptr, item ); |
| 148 | |
| 149 | /* Ok */ |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | /* Unlink an object */ |
| 154 | void fd_list_unlinkcxx . . $ fd_list_unlink(a0ae291b675747fa). ( struct fd_listcxx . . $ fd_list# * item ) |
| 155 | { |
| 156 | ASSERTcxx . . $ `lib/freeDiameter-1.2.1/include/freeDiameter/libfdproto.h:267:9`!(item != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 157 | if (item->headcxx . . $ fd_list#head. == item) |
| 158 | return; |
| 159 | /* unlink */ |
| 160 | item->nextcxx . . $ fd_list#next.->prevcxx . . $ fd_list#prev. = item->prevcxx . . $ fd_list#prev.; |
| 161 | item->prevcxx . . $ fd_list#prev.->nextcxx . . $ fd_list#next. = item->nextcxx . . $ fd_list#next.; |
| 162 | /* sanitize */ |
| 163 | item->nextcxx . . $ fd_list#next. = item; |
| 164 | item->prevcxx . . $ fd_list#prev. = item; |
| 165 | item->headcxx . . $ fd_list#head. = item; |
| 166 | } |
| 167 | |
| 168 |