| 611 | |
| 612 | |
| 613 | int add_rule2hash(dpl_node_t * rule, dp_connection_list_t *conn, int index) |
| 614 | { |
| 615 | dpl_id_p crt_idp; |
| 616 | dpl_index_p indexp; |
| 617 | int new_id, bucket = 0; |
| 618 | |
| 619 | if(!conn){ |
| 620 | LM_ERR("data not allocated\n"); |
| 621 | return -1; |
| 622 | } |
| 623 | |
| 624 | new_id = 0; |
| 625 | |
| 626 | crt_idp = select_dpid(conn, rule->dpid, index); |
| 627 | /*didn't find a dpl_id*/ |
| 628 | if(!crt_idp){ |
| 629 | crt_idp = shm_malloc(sizeof(dpl_id_t) + (DP_INDEX_HASH_SIZE+1) * sizeof(dpl_index_t)); |
| 630 | if(!crt_idp){ |
| 631 | LM_ERR("out of shm memory (crt_idp)\n"); |
| 632 | return -1; |
| 633 | } |
| 634 | memset(crt_idp, 0, sizeof(dpl_id_t) + (DP_INDEX_HASH_SIZE+1) * sizeof(dpl_index_t)); |
| 635 | crt_idp->dp_id = rule->dpid; |
| 636 | crt_idp->rule_hash = (dpl_index_t*)(crt_idp + 1); |
| 637 | new_id = 1; |
| 638 | LM_DBG("new dpl_id %i\n", rule->dpid); |
| 639 | } |
| 640 | |
| 641 | switch (rule->matchop) { |
| 642 | case REGEX_OP: |
| 643 | indexp = &crt_idp->rule_hash[DP_INDEX_HASH_SIZE]; |
| 644 | break; |
| 645 | |
| 646 | case EQUAL_OP: |
| 647 | if (rule->match_exp.s == NULL || rule->match_exp.len == 0) { |
| 648 | LM_ERR("NULL matching expressions in database not accepted!!!\n"); |
| 649 | return -1; |
| 650 | } |
| 651 | bucket = core_case_hash(&rule->match_exp, NULL, DP_INDEX_HASH_SIZE); |
| 652 | |
| 653 | indexp = &crt_idp->rule_hash[bucket]; |
| 654 | break; |
| 655 | |
| 656 | default: |
| 657 | LM_ERR("SKIPPED RULE. Unsupported match operator (%d).\n", |
| 658 | rule->matchop); |
| 659 | goto err; |
| 660 | } |
| 661 | |
| 662 | /* Add the new rule to the corresponding bucket */ |
| 663 | |
| 664 | rule->next = 0; |
| 665 | if(!indexp->first_rule) |
| 666 | indexp->first_rule = rule; |
| 667 | |
| 668 | if(indexp->last_rule) |
| 669 | indexp->last_rule->next = rule; |
| 670 |
no test coverage detected