| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#include "app_acct.h" |
| 39 |
|
| 40 |
|
| 41 |
int acct_rec_prepare(struct acct_record_list * records) |
| 42 |
{ |
| 43 |
struct fd_list * li; |
| 44 |
TRACE_ENTRY("%p", records); |
| 45 |
CHECK_PARAMS( records && acct_config ); |
| 46 |
|
| 47 |
|
| 48 |
memset(records, 0, sizeof(struct acct_record_list)); |
| 49 |
fd_list_init(&records->all, records); |
| 50 |
fd_list_init(&records->unmaped, records); |
| 51 |
|
| 52 |
|
| 53 |
for (li = acct_config->avps.next; li != &acct_config->avps; li = li->next) { |
| 54 |
struct acct_conf_avp * a = (struct acct_conf_avp *)li; |
| 55 |
struct acct_record_item * new; |
| 56 |
int i = a->multi ? 1 : 0; |
| 57 |
|
| 58 |
do { |
| 59 |
CHECK_MALLOC( new = malloc(sizeof(struct acct_record_item)) ); |
| 60 |
memset(new, 0, sizeof(struct acct_record_item)); |
| 61 |
fd_list_init(&new->chain, new); |
| 62 |
fd_list_init(&new->unmapd, new); |
| 63 |
new->param = a; |
| 64 |
new->index = i; |
| 65 |
fd_list_insert_before(&records->all, &new->chain); |
| 66 |
fd_list_insert_before(&records->unmaped, &new->unmapd); |
| 67 |
records->nball++; |
| 68 |
records->nbunmap++; |
| 69 |
i++; |
| 70 |
} while (i <= a->multi); |
| 71 |
} |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
int acct_rec_map(struct acct_record_list * records, struct msg * msg) |
| 78 |
{ |
| 79 |
struct avp * avp; |
| 80 |
|
| 81 |
TRACE_ENTRY("%p %p", records, msg); |
| 82 |
|
| 83 |
|
| 84 |
CHECK_FCT( fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
| 85 |
while (avp) { |
| 86 |
struct fd_list * li; |
| 87 |
struct dict_object * model; |
| 88 |
|
| 89 |
CHECK_FCT( fd_msg_model(avp, &model) ); |
| 90 |
if (model != NULL) { |
| 91 |
|
| 92 |
|
| 93 |
for (li = records->unmaped.next; li != &records->unmaped; li = li->next) { |
| 94 |
struct acct_record_item * r = (struct acct_record_item *)(li->o); |
| 95 |
if (r->param->avpobj == model) { |
| 96 |
|
| 97 |
struct avp_hdr * h; |
| 98 |
CHECK_FCT( fd_msg_avp_hdr( avp, &h ) ); |
| 99 |
r->value = h->avp_value; |
| 100 |
fd_list_unlink(&r->unmapd); |
| 101 |
records->nbunmap -= 1; |
| 102 |
break; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
if (FD_IS_LIST_EMPTY(&records->unmaped)) |
| 108 |
break; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) ); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
return 0; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
int acct_rec_validate(struct acct_record_list * records) |
| 121 |
{ |
| 122 |
struct fd_list * li; |
| 123 |
TRACE_ENTRY("%p", records); |
| 124 |
CHECK_PARAMS( records ); |
| 125 |
|
| 126 |
|
| 127 |
if (records->nball == records->nbunmap) { |
| 128 |
fd_log_debug("The received ACR does not contain any AVP from the configuration file." |
| 129 |
" This is an invalid situation. Please fix your configuration file." |
| 130 |
" One way to ensure this does not happen is to include Session-Id in the database."); |
| 131 |
acct_rec_empty(records); |
| 132 |
return EINVAL; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
for (li = records->unmaped.next; li != &records->unmaped; li = li->next) { |
| 137 |
struct acct_record_item * r = (struct acct_record_item *)(li->o); |
| 138 |
if (r->param->required && (r->index <= 1)) { |
| 139 |
fd_log_debug("The received ACR does not contain the required AVP '%s'.", r->param->avpname); |
| 140 |
acct_rec_empty(records); |
| 141 |
return EINVAL; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
return 0; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
void acct_rec_empty(struct acct_record_list * records) |
| 151 |
{ |
| 152 |
TRACE_ENTRY("%p", records); |
| 153 |
CHECK_PARAMS_DO( records, return ); |
| 154 |
|
| 155 |
while (!FD_IS_LIST_EMPTY(&records->all)) { |
| 156 |
struct acct_record_item * r = (struct acct_record_item *)(records->all.next); |
| 157 |
fd_list_unlink( &r->chain ); |
| 158 |
fd_list_unlink( &r->unmapd ); |
| 159 |
free(r); |
| 160 |
} |
| 161 |
} |