Mercurial > hg > freeDiameter
diff extensions/rt_redirect/redir_out.c @ 1259:82280e745a89
Remove whitespace at end of line.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Mon, 24 Mar 2014 13:13:38 +0100 |
parents | 581bbd48524a |
children | 4f6f61e67599 |
line wrap: on
line diff
--- a/extensions/rt_redirect/redir_out.c Tue Feb 11 14:47:02 2014 +0100 +++ b/extensions/rt_redirect/redir_out.c Mon Mar 24 13:13:38 2014 +0100 @@ -40,17 +40,17 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchdata * data, int * nodata) { TRACE_ENTRY("%d %p %p %p", type, msg, data, nodata); - + /* Initialize the data area */ memset(data, 0, sizeof(union matchdata)); *nodata = 0; - + /* Now, find the appropriate information, depending on type */ switch (type) { case DONT_CACHE: data->message.msg = msg; break; - + case ALL_SESSION: { /* Get the sid from the message */ @@ -64,7 +64,7 @@ } } break; - + case ALL_REALM: { /* Search the Destination-Realm in the message */ @@ -81,7 +81,7 @@ } } break; - + case REALM_AND_APPLICATION: { /* Search the Destination-Realm of the message */ @@ -95,7 +95,7 @@ CHECK_FCT( fd_msg_avp_hdr( dr, &ahdr ) ); data->realm_app.s = ahdr->avp_value->os.data; data->realm_app.l = ahdr->avp_value->os.len; - + /* and then the application */ { struct msg_hdr * hdr; @@ -106,7 +106,7 @@ } } break; - + case ALL_APPLICATION: { /* Retrieve the application from the message */ @@ -115,11 +115,11 @@ data->app.a = hdr->msg_appl; } break; - + case ALL_HOST: /* This is more complex, we need to match with all candidates in each rule, it'll be done later */ break; - + case ALL_USER: { /* Search the User-Name of the message */ @@ -136,7 +136,7 @@ } } break; - + default: ASSERT(0); return EINVAL; @@ -152,22 +152,22 @@ struct fd_list * lic, *lirh; struct rtd_candidate * c_oh = NULL; int cmp; - + TRACE_ENTRY("%p %p %p", e, msg, candidates); ASSERT( e && msg && candidates ); - + if (FD_IS_LIST_EMPTY(candidates)) { TRACE_DEBUG(ANNOYING, "Skip Redirect rule since candidates list is empty"); return 0; } - + /* Now search common peers between e->target_peers_list and candidates */ TRACE_DEBUG(ANNOYING, "Message %p matches a Redirect rule (t:%d, @%p), processing candidates list", msg, e->type, e); - + /* First, decrease the score of the host that we received the previous Redirect from, in case it is in the list */ for (lic = candidates->next; lic != candidates; lic = lic->next) { struct rtd_candidate * cand = (struct rtd_candidate *) lic; - + /* Special case: ALL_HOST rules: we decrease the score of the Origin-Host if present */ if (e->type == ALL_HOST) { cmp = fd_os_almostcasesrch(cand->diamid, cand->diamidlen, e->data.host.s, e->data.host.l, NULL); @@ -178,32 +178,32 @@ continue; } } - + cmp = fd_os_cmp(cand->diamid, cand->diamidlen, e->from.s, e->from.l); if (!cmp) { TRACE_DEBUG(FULL, "Redirect msg %p: peer '%.*s' += %d (previous Redirect received from this peer)", msg, (int)cand->diamidlen, cand->diamid, FD_SCORE_SENT_REDIRECT); cand->score += FD_SCORE_SENT_REDIRECT; } - + } - + if ((e->type == ALL_HOST) && (c_oh == NULL)) { /* The rule does not apply, we're done */ return 0; } - + /* for each candidate, if it is found in the target_peers list, we add the rule's score to this candidate */ for (lic = candidates->next; lic != candidates; lic = lic->next) { /* the candidates list is not guaranteed to be ordered at this time, so we cannot avoid the two imbricated loops */ struct rtd_candidate * cand = (struct rtd_candidate *) lic; - + /* Is this candidate in the "Redirect-Host" list ? We must search caseinsentive here. */ for (lirh = e->target_peers_list.next; lirh != &e->target_peers_list; lirh = lirh->next) { struct redir_host * host = lirh->o; int cont; - + cmp = fd_os_almostcasesrch( cand->diamid, cand->diamidlen, host->id, host->len, &cont ); - + if (cmp == 0) { TRACE_DEBUG(FULL, "Redirect msg %p: peer '%.*s' += %d (rule t:%d @%p)", msg, (int)cand->diamidlen, cand->diamid, redirects_usages[e->type].score, e->type, e); cand->score += redirects_usages[e->type].score; @@ -213,7 +213,7 @@ break; } } - + return 0; } @@ -223,9 +223,9 @@ { int i, ret = 0; struct msg * msg = *pmsg; - + TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); - + for (i = 0; i <= H_U_MAX; i++) { /* Lock the line. We write lock in case of DONT_CACHE so we can directly unlink the entry. read in other cases is sufficient */ if (i == DONT_CACHE) { @@ -233,21 +233,21 @@ } else { CHECK_POSIX( pthread_rwlock_rdlock( &redirects_usages[i].lock ) ); } - + if (!FD_IS_LIST_EMPTY(&redirects_usages[i].sentinel)) { union matchdata data; int nodata; /* The message does not allow to apply this rule, skip */ - + /* Retrieve the data that may match in the message */ CHECK_FCT_DO( ret = get_data_to_match(i, msg, &data, &nodata), goto out ); - + /* If this message may match some of our rules */ if (!nodata) { struct fd_list * li; /* Attempt each rule we have stored */ for (li = redirects_usages[i].sentinel.next; li != &redirects_usages[i].sentinel; li = li->next) { struct redir_entry * e = li->o; - + /* Does it match ? */ if (i != ALL_HOST) { /* this one is an exception, we handle it separately */ int cmp = redir_entry_cmp_key[i](&data, &e->data); @@ -256,27 +256,27 @@ if (cmp < 0) break; } - + /* This rule matches (or we are in ALL_HOST), apply */ CHECK_FCT_DO( ret = apply_rule(e, msg, candidates), goto out ); - + /* If this was a DONT_CACHE rule, we unlink it, so that it will not be used again */ if (i == DONT_CACHE) { li=li->prev; fd_list_unlink( li->next ); - /* We cannot delete here without taking the mutex, which would mean we have first to release the lock... + /* We cannot delete here without taking the mutex, which would mean we have first to release the lock... just let expiry garbage collet the rule */ } } } - + } -out: +out: CHECK_POSIX( pthread_rwlock_unlock( &redirects_usages[i].lock ) ); if (ret) return ret; } - + return 0; }