| 746 | |
| 747 | |
| 748 | static inline int get_stat_name(struct sip_msg* msg, pv_name_t *name, |
| 749 | int create, stat_var **stat) |
| 750 | { |
| 751 | pv_value_t pv_val; |
| 752 | str sname, group; |
| 753 | int grp_idx __attribute__((unused)); |
| 754 | |
| 755 | /* is the statistic found ? */ |
| 756 | if (name->type==PV_NAME_INTSTR) { |
| 757 | LM_DBG("stat with name %p still not found\n", name); |
| 758 | /* not yet :( */ |
| 759 | /* do we have at least the name ?? */ |
| 760 | if (name->u.isname.type==0) { |
| 761 | /* name is FMT */ |
| 762 | if (pv_printf_s( msg, (pv_elem_t *)name->u.isname.name.s.s, |
| 763 | &(pv_val.rs) )!=0) { |
| 764 | LM_ERR("failed to get format string value\n"); |
| 765 | return -1; |
| 766 | } |
| 767 | } else { |
| 768 | /* name is string */ |
| 769 | pv_val.rs = name->u.isname.name.s; |
| 770 | } |
| 771 | |
| 772 | if (resolve_stat(&pv_val.rs, &group, &sname, &grp_idx) != 0) { |
| 773 | return E_CFG; |
| 774 | } |
| 775 | |
| 776 | /* lookup for the statistic */ |
| 777 | *stat = __get_stat(&sname, grp_idx); |
| 778 | LM_DBG("stat name %p (%.*s) after lookup is %p\n", |
| 779 | name, pv_val.rs.len, pv_val.rs.s, *stat); |
| 780 | if (*stat==NULL) { |
| 781 | if (!create) |
| 782 | return 0; |
| 783 | LM_DBG("creating statistic <%.*s>\n", pv_val.rs.len, pv_val.rs.s); |
| 784 | if (grp_idx > 0) { |
| 785 | if (__register_dynamic_stat(&group, &sname, stat) != 0) { |
| 786 | LM_ERR("failed to create statistic <%.*s>\n", |
| 787 | pv_val.rs.len, pv_val.rs.s); |
| 788 | return -1; |
| 789 | } |
| 790 | } else { |
| 791 | if (register_dynamic_stat(&sname, stat)!=0) { |
| 792 | LM_ERR("failed to create statistic <%.*s>\n", |
| 793 | pv_val.rs.len, pv_val.rs.s); |
| 794 | return -1; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | /* if name is static string, better link the stat directly |
| 799 | * and discard name */ |
| 800 | if (name->u.isname.type==AVP_NAME_STR) { |
| 801 | LM_DBG("name %p freeing %p\n",name,name->u.isname.name.s.s); |
| 802 | /* it is totally unsafe to free this shm block here, as it is |
| 803 | * referred by the spec from all the processess. Even if we create |
| 804 | * here a small leak (one time only), we do not have a better fix |
| 805 | * until a final review of the specs in pkg and shm mem - bogdan */ |
no test coverage detected