Changeset 738:d666051658bd in freeDiameter for libfdcore/peers.c
- Timestamp:
- Mar 2, 2011, 6:21:59 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/peers.c
r725 r738 94 94 { 95 95 struct fd_peer *p = NULL; 96 struct fd_list * li ;96 struct fd_list * li, *li_inf; 97 97 int ret = 0; 98 98 … … 143 143 /* Ok, now check if we don't already have an entry with the same Diameter Id, and insert this one */ 144 144 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) ); 145 145 li_inf = &fd_g_peers; 146 146 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 147 147 struct fd_peer * next = (struct fd_peer *)li; 148 int cmp = fd_os_almostcasecmp( p->p_hdr.info.pi_diamid, p->p_hdr.info.pi_diamidlen, 149 next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen ); 150 if (cmp > 0) 151 continue; 152 if (cmp == 0) 148 int cont; 149 int cmp = fd_os_almostcasesrch( p->p_hdr.info.pi_diamid, p->p_hdr.info.pi_diamidlen, 150 next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen, 151 &cont ); 152 if (cmp < 0) 153 li_inf = li; 154 155 if (cmp == 0) { 153 156 ret = EEXIST; 154 break; 157 break; 158 } 159 if (!cont) 160 break; 155 161 } 156 162 … … 162 168 163 169 /* Insert the new element in the list */ 164 fd_list_insert_ before( li, &p->p_hdr.chain );170 fd_list_insert_after( li_inf, &p->p_hdr.chain ); 165 171 } while (0); 166 172 … … 185 191 /* Search in the list */ 186 192 CHECK_POSIX( pthread_rwlock_rdlock(&fd_g_peers_rw) ); 187 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 188 struct fd_peer * next = (struct fd_peer *)li; 189 int cmp; 190 if (igncase) 191 cmp = fd_os_almostcasecmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen ); 192 else 193 cmp = fd_os_cmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen ); 194 if (cmp > 0) 195 continue; 196 if (cmp == 0) 197 *peer = &next->p_hdr; 198 break; 199 } 193 if (igncase) 194 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 195 struct fd_peer * next = (struct fd_peer *)li; 196 int cmp, cont; 197 cmp = fd_os_almostcasesrch( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen, &cont ); 198 if (cmp == 0) { 199 *peer = &next->p_hdr; 200 break; 201 } 202 if (!cont) 203 break; 204 } 205 else 206 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 207 struct fd_peer * next = (struct fd_peer *)li; 208 int cmp = fd_os_cmp( diamid, diamidlen, next->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamidlen ); 209 if (cmp > 0) 210 continue; 211 if (cmp == 0) 212 *peer = &next->p_hdr; 213 break; 214 } 200 215 CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) ); 201 216 … … 429 444 struct avp *avp_oh; 430 445 struct avp_hdr * avp_hdr; 431 struct fd_list * li ;446 struct fd_list * li, *li_inf; 432 447 int found = 0; 433 448 int ret = 0; … … 470 485 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) ); 471 486 487 li_inf = &fd_g_peers; 472 488 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 473 int cmp ;489 int cmp, cont; 474 490 peer = (struct fd_peer *)li->o; 475 cmp = fd_os_almostcasecmp( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen ); 476 if (cmp > 0) 491 cmp = fd_os_almostcasesrch( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, &cont ); 492 if (cmp < 0) { 493 li_inf = li; 477 494 continue; 478 if (cmp == 0) 495 } 496 if (cmp == 0) { 479 497 found = 1; 480 break; 498 break; 499 } 500 if (!cont) 501 break; 481 502 } 482 503 … … 500 521 501 522 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */ 502 fd_list_insert_ before( li, &peer->p_hdr.chain );523 fd_list_insert_after( li_inf, &peer->p_hdr.chain ); 503 524 504 525 /* Start the PSM, which will receive the event bellow */
Note: See TracChangeset
for help on using the changeset viewer.