| 2829 | */ |
| 2830 | |
| 2831 | char *tr_parse_sparam(char *p, str *in, tr_param_t **tp, int skip_param_ws) |
| 2832 | { |
| 2833 | char *p0, *ps; |
| 2834 | pv_spec_t *spec = NULL; |
| 2835 | str s; |
| 2836 | |
| 2837 | while (is_in_str(p, in) && is_ws(*p)) p++; |
| 2838 | |
| 2839 | if (*p == PV_MARKER) { /* pseudo-variable */ |
| 2840 | spec = pkg_malloc(sizeof(pv_spec_t)); |
| 2841 | if (spec == NULL) { |
| 2842 | LM_ERR("no more private memory!\n"); |
| 2843 | goto error; |
| 2844 | } |
| 2845 | s.s = p; |
| 2846 | s.len = in->s + in->len - p; |
| 2847 | p0 = pv_parse_spec(&s, spec); |
| 2848 | if (p0 == NULL) { |
| 2849 | LM_ERR("invalid spec in substr transformation: %.*s!\n", |
| 2850 | in->len, in->s); |
| 2851 | goto error; |
| 2852 | } |
| 2853 | p = p0; |
| 2854 | *tp = pkg_malloc(sizeof(tr_param_t)); |
| 2855 | if (*tp == NULL) { |
| 2856 | LM_ERR("no more private memory!\n"); |
| 2857 | goto error; |
| 2858 | } |
| 2859 | memset(*tp, 0, sizeof(tr_param_t)); |
| 2860 | (*tp)->type = TR_PARAM_SPEC; |
| 2861 | (*tp)->v.data = (void*)spec; |
| 2862 | |
| 2863 | return p; |
| 2864 | } else { /* string */ |
| 2865 | ps = p; |
| 2866 | while (is_in_str(p, in) && (skip_param_ws || !is_ws(*p))) { |
| 2867 | if ((*p == TR_PARAM_MARKER || *p == TR_RBRACKET) && |
| 2868 | (p - 1 < ps || *(p - 1) != '\\')) |
| 2869 | break; |
| 2870 | p++; |
| 2871 | } |
| 2872 | |
| 2873 | if (*p == '\0') { |
| 2874 | LM_ERR("invalid param in transformation: %.*s!!\n", |
| 2875 | in->len, in->s); |
| 2876 | goto error; |
| 2877 | } |
| 2878 | *tp = pkg_malloc(sizeof(tr_param_t)); |
| 2879 | if (*tp == NULL) { |
| 2880 | LM_ERR("no more private memory!\n"); |
| 2881 | goto error; |
| 2882 | } |
| 2883 | memset(*tp, 0, sizeof(tr_param_t)); |
| 2884 | (*tp)->type = TR_PARAM_STRING; |
| 2885 | (*tp)->v.s.s = ps; |
| 2886 | (*tp)->v.s.len = p - ps; |
| 2887 | |
| 2888 | return p; |
no test coverage detected